]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- O: kernel-firmware
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.33/arch/alpha/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/alpha/Kconfig
2 --- linux-2.6.33/arch/alpha/Kconfig     2010-02-25 11:51:18.000000000 +0100
3 +++ linux-2.6.33-vs2.3.0.36.30/arch/alpha/Kconfig       2010-02-25 12:02:16.000000000 +0100
4 @@ -675,6 +675,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.33/arch/alpha/kernel/entry.S linux-2.6.33-vs2.3.0.36.30/arch/alpha/kernel/entry.S
14 --- linux-2.6.33/arch/alpha/kernel/entry.S      2009-06-11 17:11:46.000000000 +0200
15 +++ linux-2.6.33-vs2.3.0.36.30/arch/alpha/kernel/entry.S        2010-02-25 12:02:16.000000000 +0100
16 @@ -874,24 +874,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.33/arch/alpha/kernel/osf_sys.c linux-2.6.33-vs2.3.0.36.30/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.33/arch/alpha/kernel/osf_sys.c    2010-02-25 11:51:19.000000000 +0100
50 +++ linux-2.6.33-vs2.3.0.36.30/arch/alpha/kernel/osf_sys.c      2010-02-25 12:02:16.000000000 +0100
51 @@ -865,7 +865,7 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct
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.33/arch/alpha/kernel/ptrace.c linux-2.6.33-vs2.3.0.36.30/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.33/arch/alpha/kernel/ptrace.c     2009-09-10 15:25:14.000000000 +0200
62 +++ linux-2.6.33-vs2.3.0.36.30/arch/alpha/kernel/ptrace.c       2010-02-25 12:02:16.000000000 +0100
63 @@ -14,6 +14,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.33/arch/alpha/kernel/systbls.S linux-2.6.33-vs2.3.0.36.30/arch/alpha/kernel/systbls.S
72 --- linux-2.6.33/arch/alpha/kernel/systbls.S    2010-02-25 11:51:19.000000000 +0100
73 +++ linux-2.6.33-vs2.3.0.36.30/arch/alpha/kernel/systbls.S      2010-02-25 12:02:16.000000000 +0100
74 @@ -446,7 +446,7 @@ sys_call_table:
75         .quad sys_stat64                        /* 425 */
76         .quad sys_lstat64
77         .quad sys_fstat64
78 -       .quad sys_ni_syscall                    /* sys_vserver */
79 +       .quad sys_vserver                       /* sys_vserver */
80         .quad sys_ni_syscall                    /* sys_mbind */
81         .quad sys_ni_syscall                    /* sys_get_mempolicy */
82         .quad sys_ni_syscall                    /* sys_set_mempolicy */
83 diff -NurpP --minimal linux-2.6.33/arch/alpha/kernel/traps.c linux-2.6.33-vs2.3.0.36.30/arch/alpha/kernel/traps.c
84 --- linux-2.6.33/arch/alpha/kernel/traps.c      2009-06-11 17:11:46.000000000 +0200
85 +++ linux-2.6.33-vs2.3.0.36.30/arch/alpha/kernel/traps.c        2010-02-25 12:02:16.000000000 +0100
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.33/arch/alpha/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/alpha/mm/fault.c
97 --- linux-2.6.33/arch/alpha/mm/fault.c  2009-09-10 15:25:14.000000000 +0200
98 +++ linux-2.6.33-vs2.3.0.36.30/arch/alpha/mm/fault.c    2010-02-25 12:02:16.000000000 +0100
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.33/arch/arm/include/asm/tlb.h linux-2.6.33-vs2.3.0.36.30/arch/arm/include/asm/tlb.h
111 --- linux-2.6.33/arch/arm/include/asm/tlb.h     2009-09-10 15:25:15.000000000 +0200
112 +++ linux-2.6.33-vs2.3.0.36.30/arch/arm/include/asm/tlb.h       2010-02-25 12:02:16.000000000 +0100
113 @@ -27,6 +27,7 @@
114  
115  #else /* !CONFIG_MMU */
116  
117 +#include <linux/vs_memory.h>
118  #include <asm/pgalloc.h>
119  
120  /*
121 diff -NurpP --minimal linux-2.6.33/arch/arm/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/arm/Kconfig
122 --- linux-2.6.33/arch/arm/Kconfig       2010-02-25 11:51:19.000000000 +0100
123 +++ linux-2.6.33-vs2.3.0.36.30/arch/arm/Kconfig 2010-02-25 12:02:16.000000000 +0100
124 @@ -1542,6 +1542,8 @@ source "fs/Kconfig"
125  
126  source "arch/arm/Kconfig.debug"
127  
128 +source "kernel/vserver/Kconfig"
129 +
130  source "security/Kconfig"
131  
132  source "crypto/Kconfig"
133 diff -NurpP --minimal linux-2.6.33/arch/arm/kernel/calls.S linux-2.6.33-vs2.3.0.36.30/arch/arm/kernel/calls.S
134 --- linux-2.6.33/arch/arm/kernel/calls.S        2010-02-25 11:51:20.000000000 +0100
135 +++ linux-2.6.33-vs2.3.0.36.30/arch/arm/kernel/calls.S  2010-02-25 12:02:16.000000000 +0100
136 @@ -322,7 +322,7 @@
137  /* 310 */      CALL(sys_request_key)
138                 CALL(sys_keyctl)
139                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
140 -/* vserver */  CALL(sys_ni_syscall)
141 +               CALL(sys_vserver)
142                 CALL(sys_ioprio_set)
143  /* 315 */      CALL(sys_ioprio_get)
144                 CALL(sys_inotify_init)
145 diff -NurpP --minimal linux-2.6.33/arch/arm/kernel/process.c linux-2.6.33-vs2.3.0.36.30/arch/arm/kernel/process.c
146 --- linux-2.6.33/arch/arm/kernel/process.c      2010-02-25 11:51:20.000000000 +0100
147 +++ linux-2.6.33-vs2.3.0.36.30/arch/arm/kernel/process.c        2010-02-25 12:02:16.000000000 +0100
148 @@ -270,7 +270,8 @@ void __show_regs(struct pt_regs *regs)
149  void show_regs(struct pt_regs * regs)
150  {
151         printk("\n");
152 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
153 +       printk("Pid: %d[#%u], comm: %20s\n",
154 +               task_pid_nr(current), current->xid, current->comm);
155         __show_regs(regs);
156         __backtrace();
157  }
158 diff -NurpP --minimal linux-2.6.33/arch/arm/kernel/traps.c linux-2.6.33-vs2.3.0.36.30/arch/arm/kernel/traps.c
159 --- linux-2.6.33/arch/arm/kernel/traps.c        2009-12-03 20:01:50.000000000 +0100
160 +++ linux-2.6.33-vs2.3.0.36.30/arch/arm/kernel/traps.c  2010-02-25 12:02:16.000000000 +0100
161 @@ -234,8 +234,8 @@ static void __die(const char *str, int e
162         sysfs_printk_last_file();
163         print_modules();
164         __show_regs(regs);
165 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
166 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
167 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
168 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
169  
170         if (!user_mode(regs) || in_interrupt()) {
171                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
172 diff -NurpP --minimal linux-2.6.33/arch/avr32/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/avr32/mm/fault.c
173 --- linux-2.6.33/arch/avr32/mm/fault.c  2009-09-10 15:25:20.000000000 +0200
174 +++ linux-2.6.33-vs2.3.0.36.30/arch/avr32/mm/fault.c    2010-02-25 12:02:16.000000000 +0100
175 @@ -216,7 +216,8 @@ out_of_memory:
176                 down_read(&mm->mmap_sem);
177                 goto survive;
178         }
179 -       printk("VM: Killing process %s\n", tsk->comm);
180 +       printk("VM: Killing process %s(%d:#%u)\n",
181 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
182         if (user_mode(regs))
183                 do_group_exit(SIGKILL);
184         goto no_context;
185 diff -NurpP --minimal linux-2.6.33/arch/cris/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/cris/Kconfig
186 --- linux-2.6.33/arch/cris/Kconfig      2009-06-11 17:11:56.000000000 +0200
187 +++ linux-2.6.33-vs2.3.0.36.30/arch/cris/Kconfig        2010-02-25 12:02:16.000000000 +0100
188 @@ -685,6 +685,8 @@ source "drivers/staging/Kconfig"
189  
190  source "arch/cris/Kconfig.debug"
191  
192 +source "kernel/vserver/Kconfig"
193 +
194  source "security/Kconfig"
195  
196  source "crypto/Kconfig"
197 diff -NurpP --minimal linux-2.6.33/arch/cris/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/cris/mm/fault.c
198 --- linux-2.6.33/arch/cris/mm/fault.c   2010-02-25 11:51:26.000000000 +0100
199 +++ linux-2.6.33-vs2.3.0.36.30/arch/cris/mm/fault.c     2010-02-25 12:02:16.000000000 +0100
200 @@ -245,7 +245,8 @@ do_page_fault(unsigned long address, str
201  
202   out_of_memory:
203         up_read(&mm->mmap_sem);
204 -       printk("VM: killing process %s\n", tsk->comm);
205 +       printk("VM: killing process %s(%d:#%u)\n",
206 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
207         if (user_mode(regs))
208                 do_exit(SIGKILL);
209         goto no_context;
210 diff -NurpP --minimal linux-2.6.33/arch/frv/kernel/kernel_thread.S linux-2.6.33-vs2.3.0.36.30/arch/frv/kernel/kernel_thread.S
211 --- linux-2.6.33/arch/frv/kernel/kernel_thread.S        2008-12-25 00:26:37.000000000 +0100
212 +++ linux-2.6.33-vs2.3.0.36.30/arch/frv/kernel/kernel_thread.S  2010-02-25 12:02:16.000000000 +0100
213 @@ -37,7 +37,7 @@ kernel_thread:
214  
215         # start by forking the current process, but with shared VM
216         setlos.p        #__NR_clone,gr7         ; syscall number
217 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
218 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
219         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
220         setlo           #0xe4e4,gr9
221         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
222 diff -NurpP --minimal linux-2.6.33/arch/frv/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/frv/mm/fault.c
223 --- linux-2.6.33/arch/frv/mm/fault.c    2009-09-10 15:25:22.000000000 +0200
224 +++ linux-2.6.33-vs2.3.0.36.30/arch/frv/mm/fault.c      2010-02-25 12:02:16.000000000 +0100
225 @@ -257,7 +257,8 @@ asmlinkage void do_page_fault(int datamm
226   */
227   out_of_memory:
228         up_read(&mm->mmap_sem);
229 -       printk("VM: killing process %s\n", current->comm);
230 +       printk("VM: killing process %s(%d:#%u)\n",
231 +               current->comm, task_pid_nr(current), current->xid);
232         if (user_mode(__frame))
233                 do_group_exit(SIGKILL);
234         goto no_context;
235 diff -NurpP --minimal linux-2.6.33/arch/h8300/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/h8300/Kconfig
236 --- linux-2.6.33/arch/h8300/Kconfig     2010-02-25 11:51:26.000000000 +0100
237 +++ linux-2.6.33-vs2.3.0.36.30/arch/h8300/Kconfig       2010-02-25 12:02:16.000000000 +0100
238 @@ -230,6 +230,8 @@ source "fs/Kconfig"
239  
240  source "arch/h8300/Kconfig.debug"
241  
242 +source "kernel/vserver/Kconfig"
243 +
244  source "security/Kconfig"
245  
246  source "crypto/Kconfig"
247 diff -NurpP --minimal linux-2.6.33/arch/ia64/ia32/ia32_entry.S linux-2.6.33-vs2.3.0.36.30/arch/ia64/ia32/ia32_entry.S
248 --- linux-2.6.33/arch/ia64/ia32/ia32_entry.S    2010-02-25 11:51:26.000000000 +0100
249 +++ linux-2.6.33-vs2.3.0.36.30/arch/ia64/ia32/ia32_entry.S      2010-02-25 12:02:16.000000000 +0100
250 @@ -451,7 +451,7 @@ ia32_syscall_table:
251         data8 sys_tgkill        /* 270 */
252         data8 compat_sys_utimes
253         data8 sys32_fadvise64_64
254 -       data8 sys_ni_syscall
255 +       data8 sys32_vserver
256         data8 sys_ni_syscall
257         data8 sys_ni_syscall    /* 275 */
258         data8 sys_ni_syscall
259 diff -NurpP --minimal linux-2.6.33/arch/ia64/include/asm/tlb.h linux-2.6.33-vs2.3.0.36.30/arch/ia64/include/asm/tlb.h
260 --- linux-2.6.33/arch/ia64/include/asm/tlb.h    2010-02-25 11:51:26.000000000 +0100
261 +++ linux-2.6.33-vs2.3.0.36.30/arch/ia64/include/asm/tlb.h      2010-02-25 12:02:16.000000000 +0100
262 @@ -40,6 +40,7 @@
263  #include <linux/mm.h>
264  #include <linux/pagemap.h>
265  #include <linux/swap.h>
266 +#include <linux/vs_memory.h>
267  
268  #include <asm/pgalloc.h>
269  #include <asm/processor.h>
270 diff -NurpP --minimal linux-2.6.33/arch/ia64/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/ia64/Kconfig
271 --- linux-2.6.33/arch/ia64/Kconfig      2010-02-25 11:51:26.000000000 +0100
272 +++ linux-2.6.33-vs2.3.0.36.30/arch/ia64/Kconfig        2010-02-25 12:02:16.000000000 +0100
273 @@ -682,6 +682,8 @@ source "fs/Kconfig"
274  
275  source "arch/ia64/Kconfig.debug"
276  
277 +source "kernel/vserver/Kconfig"
278 +
279  source "security/Kconfig"
280  
281  source "crypto/Kconfig"
282 diff -NurpP --minimal linux-2.6.33/arch/ia64/kernel/entry.S linux-2.6.33-vs2.3.0.36.30/arch/ia64/kernel/entry.S
283 --- linux-2.6.33/arch/ia64/kernel/entry.S       2010-02-25 11:51:26.000000000 +0100
284 +++ linux-2.6.33-vs2.3.0.36.30/arch/ia64/kernel/entry.S 2010-02-25 12:02:16.000000000 +0100
285 @@ -1753,7 +1753,7 @@ sys_call_table:
286         data8 sys_mq_notify
287         data8 sys_mq_getsetattr
288         data8 sys_kexec_load
289 -       data8 sys_ni_syscall                    // reserved for vserver
290 +       data8 sys_vserver
291         data8 sys_waitid                        // 1270
292         data8 sys_add_key
293         data8 sys_request_key
294 diff -NurpP --minimal linux-2.6.33/arch/ia64/kernel/perfmon.c linux-2.6.33-vs2.3.0.36.30/arch/ia64/kernel/perfmon.c
295 --- linux-2.6.33/arch/ia64/kernel/perfmon.c     2010-02-25 11:51:26.000000000 +0100
296 +++ linux-2.6.33-vs2.3.0.36.30/arch/ia64/kernel/perfmon.c       2010-02-25 12:02:16.000000000 +0100
297 @@ -41,6 +41,7 @@
298  #include <linux/rcupdate.h>
299  #include <linux/completion.h>
300  #include <linux/tracehook.h>
301 +#include <linux/vs_memory.h>
302  
303  #include <asm/errno.h>
304  #include <asm/intrinsics.h>
305 @@ -2367,7 +2368,7 @@ pfm_smpl_buffer_alloc(struct task_struct
306          */
307         insert_vm_struct(mm, vma);
308  
309 -       mm->total_vm  += size >> PAGE_SHIFT;
310 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
311         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
312                                                         vma_pages(vma));
313         up_write(&task->mm->mmap_sem);
314 diff -NurpP --minimal linux-2.6.33/arch/ia64/kernel/process.c linux-2.6.33-vs2.3.0.36.30/arch/ia64/kernel/process.c
315 --- linux-2.6.33/arch/ia64/kernel/process.c     2009-12-03 20:01:56.000000000 +0100
316 +++ linux-2.6.33-vs2.3.0.36.30/arch/ia64/kernel/process.c       2010-02-25 12:02:16.000000000 +0100
317 @@ -110,8 +110,8 @@ show_regs (struct pt_regs *regs)
318         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
319  
320         print_modules();
321 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
322 -                       smp_processor_id(), current->comm);
323 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
324 +                       current->xid, smp_processor_id(), current->comm);
325         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
326                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
327                init_utsname()->release);
328 diff -NurpP --minimal linux-2.6.33/arch/ia64/kernel/ptrace.c linux-2.6.33-vs2.3.0.36.30/arch/ia64/kernel/ptrace.c
329 --- linux-2.6.33/arch/ia64/kernel/ptrace.c      2009-09-10 15:25:22.000000000 +0200
330 +++ linux-2.6.33-vs2.3.0.36.30/arch/ia64/kernel/ptrace.c        2010-02-25 12:02:16.000000000 +0100
331 @@ -22,6 +22,7 @@
332  #include <linux/regset.h>
333  #include <linux/elf.h>
334  #include <linux/tracehook.h>
335 +#include <linux/vs_base.h>
336  
337  #include <asm/pgtable.h>
338  #include <asm/processor.h>
339 diff -NurpP --minimal linux-2.6.33/arch/ia64/kernel/traps.c linux-2.6.33-vs2.3.0.36.30/arch/ia64/kernel/traps.c
340 --- linux-2.6.33/arch/ia64/kernel/traps.c       2008-12-25 00:26:37.000000000 +0100
341 +++ linux-2.6.33-vs2.3.0.36.30/arch/ia64/kernel/traps.c 2010-02-25 12:02:16.000000000 +0100
342 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
343         put_cpu();
344  
345         if (++die.lock_owner_depth < 3) {
346 -               printk("%s[%d]: %s %ld [%d]\n",
347 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
348 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
349 +                       current->comm, task_pid_nr(current), current->xid,
350 +                       str, err, ++die_counter);
351                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
352                     != NOTIFY_STOP)
353                         show_regs(regs);
354 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
355                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
356                                 last.time = current_jiffies + 5 * HZ;
357                                 printk(KERN_WARNING
358 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
359 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
360 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
361 +                                       current->comm, task_pid_nr(current), current->xid,
362 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
363                         }
364                 }
365         }
366 diff -NurpP --minimal linux-2.6.33/arch/ia64/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/ia64/mm/fault.c
367 --- linux-2.6.33/arch/ia64/mm/fault.c   2009-09-10 15:25:23.000000000 +0200
368 +++ linux-2.6.33-vs2.3.0.36.30/arch/ia64/mm/fault.c     2010-02-25 12:02:16.000000000 +0100
369 @@ -10,6 +10,7 @@
370  #include <linux/interrupt.h>
371  #include <linux/kprobes.h>
372  #include <linux/kdebug.h>
373 +#include <linux/vs_memory.h>
374  
375  #include <asm/pgtable.h>
376  #include <asm/processor.h>
377 @@ -281,7 +282,8 @@ ia64_do_page_fault (unsigned long addres
378                 down_read(&mm->mmap_sem);
379                 goto survive;
380         }
381 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
382 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
383 +               current->comm, task_pid_nr(current), current->xid);
384         if (user_mode(regs))
385                 do_group_exit(SIGKILL);
386         goto no_context;
387 diff -NurpP --minimal linux-2.6.33/arch/m32r/kernel/traps.c linux-2.6.33-vs2.3.0.36.30/arch/m32r/kernel/traps.c
388 --- linux-2.6.33/arch/m32r/kernel/traps.c       2009-12-03 20:01:57.000000000 +0100
389 +++ linux-2.6.33-vs2.3.0.36.30/arch/m32r/kernel/traps.c 2010-02-25 12:02:16.000000000 +0100
390 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
391         } else {
392                 printk("SPI: %08lx\n", sp);
393         }
394 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
395 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
396 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
397 +               current->comm, task_pid_nr(current), current->xid,
398 +               0xffff & i, 4096+(unsigned long)current);
399  
400         /*
401          * When in-kernel, we also print out the stack and code at the
402 diff -NurpP --minimal linux-2.6.33/arch/m32r/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/m32r/mm/fault.c
403 --- linux-2.6.33/arch/m32r/mm/fault.c   2009-09-10 15:25:23.000000000 +0200
404 +++ linux-2.6.33-vs2.3.0.36.30/arch/m32r/mm/fault.c     2010-02-25 12:02:16.000000000 +0100
405 @@ -276,7 +276,8 @@ out_of_memory:
406                 down_read(&mm->mmap_sem);
407                 goto survive;
408         }
409 -       printk("VM: killing process %s\n", tsk->comm);
410 +       printk("VM: killing process %s(%d:#%u)\n",
411 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
412         if (error_code & ACE_USERMODE)
413                 do_group_exit(SIGKILL);
414         goto no_context;
415 diff -NurpP --minimal linux-2.6.33/arch/m68k/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/m68k/Kconfig
416 --- linux-2.6.33/arch/m68k/Kconfig      2009-12-03 20:01:57.000000000 +0100
417 +++ linux-2.6.33-vs2.3.0.36.30/arch/m68k/Kconfig        2010-02-25 12:02:16.000000000 +0100
418 @@ -622,6 +622,8 @@ source "fs/Kconfig"
419  
420  source "arch/m68k/Kconfig.debug"
421  
422 +source "kernel/vserver/Kconfig"
423 +
424  source "security/Kconfig"
425  
426  source "crypto/Kconfig"
427 diff -NurpP --minimal linux-2.6.33/arch/m68k/kernel/ptrace.c linux-2.6.33-vs2.3.0.36.30/arch/m68k/kernel/ptrace.c
428 --- linux-2.6.33/arch/m68k/kernel/ptrace.c      2010-02-25 11:51:27.000000000 +0100
429 +++ linux-2.6.33-vs2.3.0.36.30/arch/m68k/kernel/ptrace.c        2010-02-25 12:02:16.000000000 +0100
430 @@ -18,6 +18,7 @@
431  #include <linux/ptrace.h>
432  #include <linux/user.h>
433  #include <linux/signal.h>
434 +#include <linux/vs_base.h>
435  
436  #include <asm/uaccess.h>
437  #include <asm/page.h>
438 @@ -249,6 +250,8 @@ long arch_ptrace(struct task_struct *chi
439                 ret = ptrace_request(child, request, addr, data);
440                 break;
441         }
442 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
443 +               goto out_tsk;
444  
445         return ret;
446  out_eio:
447 diff -NurpP --minimal linux-2.6.33/arch/m68k/kernel/traps.c linux-2.6.33-vs2.3.0.36.30/arch/m68k/kernel/traps.c
448 --- linux-2.6.33/arch/m68k/kernel/traps.c       2009-09-10 15:25:23.000000000 +0200
449 +++ linux-2.6.33-vs2.3.0.36.30/arch/m68k/kernel/traps.c 2010-02-25 12:02:16.000000000 +0100
450 @@ -906,8 +906,8 @@ void show_registers(struct pt_regs *regs
451         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
452                regs->d4, regs->d5, regs->a0, regs->a1);
453  
454 -       printk("Process %s (pid: %d, task=%p)\n",
455 -               current->comm, task_pid_nr(current), current);
456 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
457 +               current->comm, task_pid_nr(current), current->xid, current);
458         addr = (unsigned long)&fp->un;
459         printk("Frame format=%X ", regs->format);
460         switch (regs->format) {
461 diff -NurpP --minimal linux-2.6.33/arch/m68k/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/m68k/mm/fault.c
462 --- linux-2.6.33/arch/m68k/mm/fault.c   2009-09-10 15:25:23.000000000 +0200
463 +++ linux-2.6.33-vs2.3.0.36.30/arch/m68k/mm/fault.c     2010-02-25 12:02:16.000000000 +0100
464 @@ -186,7 +186,8 @@ out_of_memory:
465                 goto survive;
466         }
467  
468 -       printk("VM: killing process %s\n", current->comm);
469 +       printk("VM: killing process %s(%d:#%u)\n",
470 +               current->comm, task_pid_nr(current), current->xid);
471         if (user_mode(regs))
472                 do_group_exit(SIGKILL);
473  
474 diff -NurpP --minimal linux-2.6.33/arch/m68knommu/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/m68knommu/Kconfig
475 --- linux-2.6.33/arch/m68knommu/Kconfig 2010-02-25 11:51:27.000000000 +0100
476 +++ linux-2.6.33-vs2.3.0.36.30/arch/m68knommu/Kconfig   2010-02-25 12:02:16.000000000 +0100
477 @@ -734,6 +734,8 @@ source "fs/Kconfig"
478  
479  source "arch/m68knommu/Kconfig.debug"
480  
481 +source "kernel/vserver/Kconfig"
482 +
483  source "security/Kconfig"
484  
485  source "crypto/Kconfig"
486 diff -NurpP --minimal linux-2.6.33/arch/m68knommu/kernel/traps.c linux-2.6.33-vs2.3.0.36.30/arch/m68knommu/kernel/traps.c
487 --- linux-2.6.33/arch/m68knommu/kernel/traps.c  2009-09-10 15:25:23.000000000 +0200
488 +++ linux-2.6.33-vs2.3.0.36.30/arch/m68knommu/kernel/traps.c    2010-02-25 12:02:16.000000000 +0100
489 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
490         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
491                fp->d4, fp->d5, fp->a0, fp->a1);
492  
493 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
494 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
495 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
496 +               current->comm, task_pid_nr(current), current->xid,
497 +               PAGE_SIZE+(unsigned long)current);
498         show_stack(NULL, (unsigned long *)(fp + 1));
499         add_taint(TAINT_DIE);
500         do_exit(SIGSEGV);
501 diff -NurpP --minimal linux-2.6.33/arch/microblaze/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/microblaze/mm/fault.c
502 --- linux-2.6.33/arch/microblaze/mm/fault.c     2009-09-10 15:25:24.000000000 +0200
503 +++ linux-2.6.33-vs2.3.0.36.30/arch/microblaze/mm/fault.c       2010-02-25 12:02:16.000000000 +0100
504 @@ -279,7 +279,8 @@ out_of_memory:
505                 goto survive;
506         }
507         up_read(&mm->mmap_sem);
508 -       printk(KERN_WARNING "VM: killing process %s\n", current->comm);
509 +       printk(KERN_WARNING "VM: killing process %s(%d:#%u)\n",
510 +               current->comm, task_pid_nr(current), current->xid);
511         if (user_mode(regs))
512                 do_exit(SIGKILL);
513         bad_page_fault(regs, address, SIGKILL);
514 diff -NurpP --minimal linux-2.6.33/arch/mips/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/mips/Kconfig
515 --- linux-2.6.33/arch/mips/Kconfig      2010-02-25 11:51:27.000000000 +0100
516 +++ linux-2.6.33-vs2.3.0.36.30/arch/mips/Kconfig        2010-02-25 12:02:16.000000000 +0100
517 @@ -2220,6 +2220,8 @@ source "fs/Kconfig"
518  
519  source "arch/mips/Kconfig.debug"
520  
521 +source "kernel/vserver/Kconfig"
522 +
523  source "security/Kconfig"
524  
525  source "crypto/Kconfig"
526 diff -NurpP --minimal linux-2.6.33/arch/mips/kernel/ptrace.c linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/ptrace.c
527 --- linux-2.6.33/arch/mips/kernel/ptrace.c      2008-12-25 00:26:37.000000000 +0100
528 +++ linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/ptrace.c        2010-02-25 12:02:16.000000000 +0100
529 @@ -25,6 +25,7 @@
530  #include <linux/security.h>
531  #include <linux/audit.h>
532  #include <linux/seccomp.h>
533 +#include <linux/vs_base.h>
534  
535  #include <asm/byteorder.h>
536  #include <asm/cpu.h>
537 @@ -259,6 +260,9 @@ long arch_ptrace(struct task_struct *chi
538  {
539         int ret;
540  
541 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
542 +               goto out;
543 +
544         switch (request) {
545         /* when I and D space are separate, these will need to be fixed. */
546         case PTRACE_PEEKTEXT: /* read word at location addr. */
547 diff -NurpP --minimal linux-2.6.33/arch/mips/kernel/scall32-o32.S linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/scall32-o32.S
548 --- linux-2.6.33/arch/mips/kernel/scall32-o32.S 2010-02-25 11:51:28.000000000 +0100
549 +++ linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/scall32-o32.S   2010-02-25 12:02:16.000000000 +0100
550 @@ -525,7 +525,7 @@ einval:     li      v0, -ENOSYS
551         sys     sys_mq_timedreceive     5
552         sys     sys_mq_notify           2       /* 4275 */
553         sys     sys_mq_getsetattr       3
554 -       sys     sys_ni_syscall          0       /* sys_vserver */
555 +       sys     sys_vserver             3
556         sys     sys_waitid              5
557         sys     sys_ni_syscall          0       /* available, was setaltroot */
558         sys     sys_add_key             5       /* 4280 */
559 diff -NurpP --minimal linux-2.6.33/arch/mips/kernel/scall64-64.S linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/scall64-64.S
560 --- linux-2.6.33/arch/mips/kernel/scall64-64.S  2010-02-25 11:51:28.000000000 +0100
561 +++ linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/scall64-64.S    2010-02-25 12:02:16.000000000 +0100
562 @@ -362,7 +362,7 @@ sys_call_table:
563         PTR     sys_mq_timedreceive
564         PTR     sys_mq_notify
565         PTR     sys_mq_getsetattr               /* 5235 */
566 -       PTR     sys_ni_syscall                  /* sys_vserver */
567 +       PTR     sys_vserver
568         PTR     sys_waitid
569         PTR     sys_ni_syscall                  /* available, was setaltroot */
570         PTR     sys_add_key
571 diff -NurpP --minimal linux-2.6.33/arch/mips/kernel/scall64-n32.S linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/scall64-n32.S
572 --- linux-2.6.33/arch/mips/kernel/scall64-n32.S 2010-02-25 11:51:28.000000000 +0100
573 +++ linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/scall64-n32.S   2010-02-25 12:02:16.000000000 +0100
574 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
575         PTR     compat_sys_mq_timedreceive
576         PTR     compat_sys_mq_notify
577         PTR     compat_sys_mq_getsetattr
578 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
579 +       PTR     sys32_vserver                   /* 6240 */
580         PTR     compat_sys_waitid
581         PTR     sys_ni_syscall                  /* available, was setaltroot */
582         PTR     sys_add_key
583 diff -NurpP --minimal linux-2.6.33/arch/mips/kernel/scall64-o32.S linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/scall64-o32.S
584 --- linux-2.6.33/arch/mips/kernel/scall64-o32.S 2010-02-25 11:51:28.000000000 +0100
585 +++ linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/scall64-o32.S   2010-02-25 12:02:16.000000000 +0100
586 @@ -480,7 +480,7 @@ sys_call_table:
587         PTR     compat_sys_mq_timedreceive
588         PTR     compat_sys_mq_notify            /* 4275 */
589         PTR     compat_sys_mq_getsetattr
590 -       PTR     sys_ni_syscall                  /* sys_vserver */
591 +       PTR     sys32_vserver
592         PTR     sys_32_waitid
593         PTR     sys_ni_syscall                  /* available, was setaltroot */
594         PTR     sys_add_key                     /* 4280 */
595 diff -NurpP --minimal linux-2.6.33/arch/mips/kernel/traps.c linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/traps.c
596 --- linux-2.6.33/arch/mips/kernel/traps.c       2010-02-25 11:51:28.000000000 +0100
597 +++ linux-2.6.33-vs2.3.0.36.30/arch/mips/kernel/traps.c 2010-02-25 12:02:16.000000000 +0100
598 @@ -333,9 +333,10 @@ void show_registers(const struct pt_regs
599  
600         __show_regs(regs);
601         print_modules();
602 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
603 -              current->comm, current->pid, current_thread_info(), current,
604 -             field, current_thread_info()->tp_value);
605 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
606 +               current->comm, task_pid_nr(current), current->xid,
607 +               current_thread_info(), current,
608 +               field, current_thread_info()->tp_value);
609         if (cpu_has_userlocal) {
610                 unsigned long tls;
611  
612 diff -NurpP --minimal linux-2.6.33/arch/mn10300/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/mn10300/mm/fault.c
613 --- linux-2.6.33/arch/mn10300/mm/fault.c        2009-09-10 15:25:39.000000000 +0200
614 +++ linux-2.6.33-vs2.3.0.36.30/arch/mn10300/mm/fault.c  2010-02-25 12:02:16.000000000 +0100
615 @@ -339,7 +339,8 @@ no_context:
616  out_of_memory:
617         up_read(&mm->mmap_sem);
618         monitor_signal(regs);
619 -       printk(KERN_ALERT "VM: killing process %s\n", tsk->comm);
620 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
621 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
622         if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR)
623                 do_exit(SIGKILL);
624         goto no_context;
625 diff -NurpP --minimal linux-2.6.33/arch/parisc/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/parisc/Kconfig
626 --- linux-2.6.33/arch/parisc/Kconfig    2010-02-25 11:51:29.000000000 +0100
627 +++ linux-2.6.33-vs2.3.0.36.30/arch/parisc/Kconfig      2010-02-25 12:02:16.000000000 +0100
628 @@ -293,6 +293,8 @@ source "fs/Kconfig"
629  
630  source "arch/parisc/Kconfig.debug"
631  
632 +source "kernel/vserver/Kconfig"
633 +
634  source "security/Kconfig"
635  
636  source "crypto/Kconfig"
637 diff -NurpP --minimal linux-2.6.33/arch/parisc/kernel/syscall_table.S linux-2.6.33-vs2.3.0.36.30/arch/parisc/kernel/syscall_table.S
638 --- linux-2.6.33/arch/parisc/kernel/syscall_table.S     2010-02-25 11:51:29.000000000 +0100
639 +++ linux-2.6.33-vs2.3.0.36.30/arch/parisc/kernel/syscall_table.S       2010-02-25 12:02:16.000000000 +0100
640 @@ -361,7 +361,7 @@
641         ENTRY_COMP(mbind)               /* 260 */
642         ENTRY_COMP(get_mempolicy)
643         ENTRY_COMP(set_mempolicy)
644 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
645 +       ENTRY_DIFF(vserver)
646         ENTRY_SAME(add_key)
647         ENTRY_SAME(request_key)         /* 265 */
648         ENTRY_SAME(keyctl)
649 diff -NurpP --minimal linux-2.6.33/arch/parisc/kernel/traps.c linux-2.6.33-vs2.3.0.36.30/arch/parisc/kernel/traps.c
650 --- linux-2.6.33/arch/parisc/kernel/traps.c     2009-09-10 15:25:40.000000000 +0200
651 +++ linux-2.6.33-vs2.3.0.36.30/arch/parisc/kernel/traps.c       2010-02-25 12:02:16.000000000 +0100
652 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
653                 if (err == 0)
654                         return; /* STFU */
655  
656 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
657 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
658 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
659 +                       current->comm, task_pid_nr(current), current->xid,
660 +                       str, err, regs->iaoq[0]);
661  #ifdef PRINT_USER_FAULTS
662                 /* XXX for debugging only */
663                 show_regs(regs);
664 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
665                 pdc_console_restart();
666         
667         if (err)
668 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
669 -                       current->comm, task_pid_nr(current), str, err);
670 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
671 +                       current->comm, task_pid_nr(current), current->xid, str, err);
672  
673         /* Wot's wrong wif bein' racy? */
674         if (current->thread.flags & PARISC_KERNEL_DEATH) {
675 diff -NurpP --minimal linux-2.6.33/arch/parisc/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/parisc/mm/fault.c
676 --- linux-2.6.33/arch/parisc/mm/fault.c 2009-09-10 15:25:40.000000000 +0200
677 +++ linux-2.6.33-vs2.3.0.36.30/arch/parisc/mm/fault.c   2010-02-25 12:02:16.000000000 +0100
678 @@ -237,8 +237,9 @@ bad_area:
679  
680  #ifdef PRINT_USER_FAULTS
681                 printk(KERN_DEBUG "\n");
682 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
683 -                   task_pid_nr(tsk), tsk->comm, code, address);
684 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
685 +                   "command='%s' type=%lu address=0x%08lx\n",
686 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
687                 if (vma) {
688                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
689                                         vma->vm_start, vma->vm_end);
690 @@ -264,7 +265,8 @@ no_context:
691  
692    out_of_memory:
693         up_read(&mm->mmap_sem);
694 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
695 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
696 +               current->comm, current->pid, current->xid);
697         if (user_mode(regs))
698                 do_group_exit(SIGKILL);
699         goto no_context;
700 diff -NurpP --minimal linux-2.6.33/arch/powerpc/include/asm/unistd.h linux-2.6.33-vs2.3.0.36.30/arch/powerpc/include/asm/unistd.h
701 --- linux-2.6.33/arch/powerpc/include/asm/unistd.h      2009-12-03 20:02:01.000000000 +0100
702 +++ linux-2.6.33-vs2.3.0.36.30/arch/powerpc/include/asm/unistd.h        2010-02-25 12:02:16.000000000 +0100
703 @@ -275,7 +275,7 @@
704  #endif
705  #define __NR_rtas              255
706  #define __NR_sys_debug_setcontext 256
707 -/* Number 257 is reserved for vserver */
708 +#define __NR_vserver           257
709  #define __NR_migrate_pages     258
710  #define __NR_mbind             259
711  #define __NR_get_mempolicy     260
712 diff -NurpP --minimal linux-2.6.33/arch/powerpc/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/powerpc/Kconfig
713 --- linux-2.6.33/arch/powerpc/Kconfig   2010-02-25 11:51:29.000000000 +0100
714 +++ linux-2.6.33-vs2.3.0.36.30/arch/powerpc/Kconfig     2010-02-25 12:02:16.000000000 +0100
715 @@ -968,6 +968,8 @@ source "lib/Kconfig"
716  
717  source "arch/powerpc/Kconfig.debug"
718  
719 +source "kernel/vserver/Kconfig"
720 +
721  source "security/Kconfig"
722  
723  config KEYS_COMPAT
724 diff -NurpP --minimal linux-2.6.33/arch/powerpc/kernel/irq.c linux-2.6.33-vs2.3.0.36.30/arch/powerpc/kernel/irq.c
725 --- linux-2.6.33/arch/powerpc/kernel/irq.c      2010-02-25 11:51:31.000000000 +0100
726 +++ linux-2.6.33-vs2.3.0.36.30/arch/powerpc/kernel/irq.c        2010-02-25 12:02:16.000000000 +0100
727 @@ -54,6 +54,7 @@
728  #include <linux/pci.h>
729  #include <linux/debugfs.h>
730  #include <linux/perf_event.h>
731 +// #include <linux/vs_context.h>
732  
733  #include <asm/uaccess.h>
734  #include <asm/system.h>
735 diff -NurpP --minimal linux-2.6.33/arch/powerpc/kernel/process.c linux-2.6.33-vs2.3.0.36.30/arch/powerpc/kernel/process.c
736 --- linux-2.6.33/arch/powerpc/kernel/process.c  2010-02-25 11:51:31.000000000 +0100
737 +++ linux-2.6.33-vs2.3.0.36.30/arch/powerpc/kernel/process.c    2010-02-25 12:02:16.000000000 +0100
738 @@ -519,8 +519,9 @@ void show_regs(struct pt_regs * regs)
739  #else
740                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
741  #endif
742 -       printk("TASK = %p[%d] '%s' THREAD: %p",
743 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
744 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
745 +              current, task_pid_nr(current), current->xid,
746 +              current->comm, task_thread_info(current));
747  
748  #ifdef CONFIG_SMP
749         printk(" CPU: %d", raw_smp_processor_id());
750 diff -NurpP --minimal linux-2.6.33/arch/powerpc/kernel/traps.c linux-2.6.33-vs2.3.0.36.30/arch/powerpc/kernel/traps.c
751 --- linux-2.6.33/arch/powerpc/kernel/traps.c    2010-02-25 11:51:31.000000000 +0100
752 +++ linux-2.6.33-vs2.3.0.36.30/arch/powerpc/kernel/traps.c      2010-02-25 12:02:16.000000000 +0100
753 @@ -918,8 +918,9 @@ void nonrecoverable_exception(struct pt_
754  
755  void trace_syscall(struct pt_regs *regs)
756  {
757 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
758 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
759 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
760 +              current, task_pid_nr(current), current->xid,
761 +              regs->nip, regs->link, regs->gpr[0],
762                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
763  }
764  
765 diff -NurpP --minimal linux-2.6.33/arch/powerpc/kernel/vdso.c linux-2.6.33-vs2.3.0.36.30/arch/powerpc/kernel/vdso.c
766 --- linux-2.6.33/arch/powerpc/kernel/vdso.c     2010-02-25 11:51:31.000000000 +0100
767 +++ linux-2.6.33-vs2.3.0.36.30/arch/powerpc/kernel/vdso.c       2010-02-25 12:02:16.000000000 +0100
768 @@ -23,6 +23,7 @@
769  #include <linux/security.h>
770  #include <linux/bootmem.h>
771  #include <linux/lmb.h>
772 +#include <linux/vs_memory.h>
773  
774  #include <asm/pgtable.h>
775  #include <asm/system.h>
776 diff -NurpP --minimal linux-2.6.33/arch/powerpc/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/powerpc/mm/fault.c
777 --- linux-2.6.33/arch/powerpc/mm/fault.c        2010-02-25 11:51:31.000000000 +0100
778 +++ linux-2.6.33-vs2.3.0.36.30/arch/powerpc/mm/fault.c  2010-02-25 12:02:16.000000000 +0100
779 @@ -364,7 +364,8 @@ out_of_memory:
780                 down_read(&mm->mmap_sem);
781                 goto survive;
782         }
783 -       printk("VM: killing process %s\n", current->comm);
784 +       printk("VM: killing process %s(%d:#%u)\n",
785 +               current->comm, current->pid, current->xid);
786         if (user_mode(regs))
787                 do_group_exit(SIGKILL);
788         return SIGKILL;
789 diff -NurpP --minimal linux-2.6.33/arch/s390/include/asm/tlb.h linux-2.6.33-vs2.3.0.36.30/arch/s390/include/asm/tlb.h
790 --- linux-2.6.33/arch/s390/include/asm/tlb.h    2009-09-10 15:25:43.000000000 +0200
791 +++ linux-2.6.33-vs2.3.0.36.30/arch/s390/include/asm/tlb.h      2010-02-25 12:02:16.000000000 +0100
792 @@ -23,6 +23,8 @@
793  
794  #include <linux/mm.h>
795  #include <linux/swap.h>
796 +#include <linux/vs_memory.h>
797 +
798  #include <asm/processor.h>
799  #include <asm/pgalloc.h>
800  #include <asm/smp.h>
801 diff -NurpP --minimal linux-2.6.33/arch/s390/include/asm/unistd.h linux-2.6.33-vs2.3.0.36.30/arch/s390/include/asm/unistd.h
802 --- linux-2.6.33/arch/s390/include/asm/unistd.h 2010-02-25 11:51:32.000000000 +0100
803 +++ linux-2.6.33-vs2.3.0.36.30/arch/s390/include/asm/unistd.h   2010-02-25 12:02:16.000000000 +0100
804 @@ -202,7 +202,7 @@
805  #define __NR_clock_gettime     (__NR_timer_create+6)
806  #define __NR_clock_getres      (__NR_timer_create+7)
807  #define __NR_clock_nanosleep   (__NR_timer_create+8)
808 -/* Number 263 is reserved for vserver */
809 +#define __NR_vserver           263
810  #define __NR_statfs64          265
811  #define __NR_fstatfs64         266
812  #define __NR_remap_file_pages  267
813 diff -NurpP --minimal linux-2.6.33/arch/s390/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/s390/Kconfig
814 --- linux-2.6.33/arch/s390/Kconfig      2010-02-25 11:51:32.000000000 +0100
815 +++ linux-2.6.33-vs2.3.0.36.30/arch/s390/Kconfig        2010-02-25 12:02:16.000000000 +0100
816 @@ -629,6 +629,8 @@ source "fs/Kconfig"
817  
818  source "arch/s390/Kconfig.debug"
819  
820 +source "kernel/vserver/Kconfig"
821 +
822  source "security/Kconfig"
823  
824  source "crypto/Kconfig"
825 diff -NurpP --minimal linux-2.6.33/arch/s390/kernel/ptrace.c linux-2.6.33-vs2.3.0.36.30/arch/s390/kernel/ptrace.c
826 --- linux-2.6.33/arch/s390/kernel/ptrace.c      2010-02-25 11:51:32.000000000 +0100
827 +++ linux-2.6.33-vs2.3.0.36.30/arch/s390/kernel/ptrace.c        2010-02-25 12:02:16.000000000 +0100
828 @@ -36,6 +36,7 @@
829  #include <linux/regset.h>
830  #include <linux/tracehook.h>
831  #include <linux/seccomp.h>
832 +#include <linux/vs_base.h>
833  #include <trace/syscall.h>
834  #include <asm/compat.h>
835  #include <asm/segment.h>
836 diff -NurpP --minimal linux-2.6.33/arch/s390/kernel/syscalls.S linux-2.6.33-vs2.3.0.36.30/arch/s390/kernel/syscalls.S
837 --- linux-2.6.33/arch/s390/kernel/syscalls.S    2009-12-03 20:02:03.000000000 +0100
838 +++ linux-2.6.33-vs2.3.0.36.30/arch/s390/kernel/syscalls.S      2010-02-25 12:02:16.000000000 +0100
839 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
840  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
841  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
842  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
843 -NI_SYSCALL                                                     /* reserved for vserver */
844 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
845  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
846  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
847  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
848 diff -NurpP --minimal linux-2.6.33/arch/sh/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/sh/Kconfig
849 --- linux-2.6.33/arch/sh/Kconfig        2010-02-25 11:51:32.000000000 +0100
850 +++ linux-2.6.33-vs2.3.0.36.30/arch/sh/Kconfig  2010-02-25 12:02:16.000000000 +0100
851 @@ -860,6 +860,8 @@ source "fs/Kconfig"
852  
853  source "arch/sh/Kconfig.debug"
854  
855 +source "kernel/vserver/Kconfig"
856 +
857  source "security/Kconfig"
858  
859  source "crypto/Kconfig"
860 diff -NurpP --minimal linux-2.6.33/arch/sh/kernel/irq.c linux-2.6.33-vs2.3.0.36.30/arch/sh/kernel/irq.c
861 --- linux-2.6.33/arch/sh/kernel/irq.c   2010-02-25 11:51:33.000000000 +0100
862 +++ linux-2.6.33-vs2.3.0.36.30/arch/sh/kernel/irq.c     2010-02-25 12:02:16.000000000 +0100
863 @@ -12,6 +12,7 @@
864  #include <linux/kernel_stat.h>
865  #include <linux/seq_file.h>
866  #include <linux/ftrace.h>
867 +// #include <linux/vs_context.h>
868  #include <asm/processor.h>
869  #include <asm/machvec.h>
870  #include <asm/uaccess.h>
871 diff -NurpP --minimal linux-2.6.33/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.33-vs2.3.0.36.30/arch/sh/kernel/vsyscall/vsyscall.c
872 --- linux-2.6.33/arch/sh/kernel/vsyscall/vsyscall.c     2009-03-24 14:18:42.000000000 +0100
873 +++ linux-2.6.33-vs2.3.0.36.30/arch/sh/kernel/vsyscall/vsyscall.c       2010-02-25 12:02:16.000000000 +0100
874 @@ -19,6 +19,7 @@
875  #include <linux/elf.h>
876  #include <linux/sched.h>
877  #include <linux/err.h>
878 +#include <linux/vs_memory.h>
879  
880  /*
881   * Should the kernel map a VDSO page into processes and pass its
882 diff -NurpP --minimal linux-2.6.33/arch/sh/mm/fault_32.c linux-2.6.33-vs2.3.0.36.30/arch/sh/mm/fault_32.c
883 --- linux-2.6.33/arch/sh/mm/fault_32.c  2009-12-03 20:02:14.000000000 +0100
884 +++ linux-2.6.33-vs2.3.0.36.30/arch/sh/mm/fault_32.c    2010-02-25 12:02:16.000000000 +0100
885 @@ -292,7 +292,8 @@ out_of_memory:
886                 down_read(&mm->mmap_sem);
887                 goto survive;
888         }
889 -       printk("VM: killing process %s\n", tsk->comm);
890 +       printk("VM: killing process %s(%d:#%u)\n",
891 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
892         if (user_mode(regs))
893                 do_group_exit(SIGKILL);
894         goto no_context;
895 diff -NurpP --minimal linux-2.6.33/arch/sh/mm/tlbflush_64.c linux-2.6.33-vs2.3.0.36.30/arch/sh/mm/tlbflush_64.c
896 --- linux-2.6.33/arch/sh/mm/tlbflush_64.c       2009-12-03 20:02:14.000000000 +0100
897 +++ linux-2.6.33-vs2.3.0.36.30/arch/sh/mm/tlbflush_64.c 2010-02-25 12:02:16.000000000 +0100
898 @@ -306,7 +306,8 @@ out_of_memory:
899                 down_read(&mm->mmap_sem);
900                 goto survive;
901         }
902 -       printk("VM: killing process %s\n", tsk->comm);
903 +       printk("VM: killing process %s(%d:#%u)\n",
904 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
905         if (user_mode(regs))
906                 do_group_exit(SIGKILL);
907         goto no_context;
908 diff -NurpP --minimal linux-2.6.33/arch/sparc/include/asm/tlb_64.h linux-2.6.33-vs2.3.0.36.30/arch/sparc/include/asm/tlb_64.h
909 --- linux-2.6.33/arch/sparc/include/asm/tlb_64.h        2009-09-10 15:25:45.000000000 +0200
910 +++ linux-2.6.33-vs2.3.0.36.30/arch/sparc/include/asm/tlb_64.h  2010-02-25 12:02:16.000000000 +0100
911 @@ -3,6 +3,7 @@
912  
913  #include <linux/swap.h>
914  #include <linux/pagemap.h>
915 +#include <linux/vs_memory.h>
916  #include <asm/pgalloc.h>
917  #include <asm/tlbflush.h>
918  #include <asm/mmu_context.h>
919 diff -NurpP --minimal linux-2.6.33/arch/sparc/include/asm/unistd.h linux-2.6.33-vs2.3.0.36.30/arch/sparc/include/asm/unistd.h
920 --- linux-2.6.33/arch/sparc/include/asm/unistd.h        2010-02-25 11:51:34.000000000 +0100
921 +++ linux-2.6.33-vs2.3.0.36.30/arch/sparc/include/asm/unistd.h  2010-02-25 12:02:16.000000000 +0100
922 @@ -335,7 +335,7 @@
923  #define __NR_timer_getoverrun  264
924  #define __NR_timer_delete      265
925  #define __NR_timer_create      266
926 -/* #define __NR_vserver                267 Reserved for VSERVER */
927 +#define __NR_vserver           267
928  #define __NR_io_setup          268
929  #define __NR_io_destroy                269
930  #define __NR_io_submit         270
931 diff -NurpP --minimal linux-2.6.33/arch/sparc/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/sparc/Kconfig
932 --- linux-2.6.33/arch/sparc/Kconfig     2010-02-25 11:51:33.000000000 +0100
933 +++ linux-2.6.33-vs2.3.0.36.30/arch/sparc/Kconfig       2010-02-25 12:02:16.000000000 +0100
934 @@ -561,6 +561,8 @@ source "fs/Kconfig"
935  
936  source "arch/sparc/Kconfig.debug"
937  
938 +source "kernel/vserver/Kconfig"
939 +
940  source "security/Kconfig"
941  
942  source "crypto/Kconfig"
943 diff -NurpP --minimal linux-2.6.33/arch/sparc/kernel/systbls_32.S linux-2.6.33-vs2.3.0.36.30/arch/sparc/kernel/systbls_32.S
944 --- linux-2.6.33/arch/sparc/kernel/systbls_32.S 2010-02-25 11:51:34.000000000 +0100
945 +++ linux-2.6.33-vs2.3.0.36.30/arch/sparc/kernel/systbls_32.S   2010-02-25 12:02:16.000000000 +0100
946 @@ -70,7 +70,7 @@ sys_call_table:
947  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
948  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
949  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
950 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
951 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
952  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
953  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
954  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
955 diff -NurpP --minimal linux-2.6.33/arch/sparc/kernel/systbls_64.S linux-2.6.33-vs2.3.0.36.30/arch/sparc/kernel/systbls_64.S
956 --- linux-2.6.33/arch/sparc/kernel/systbls_64.S 2010-02-25 11:51:34.000000000 +0100
957 +++ linux-2.6.33-vs2.3.0.36.30/arch/sparc/kernel/systbls_64.S   2010-02-25 12:02:16.000000000 +0100
958 @@ -71,7 +71,7 @@ sys_call_table32:
959  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
960         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
961  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
962 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
963 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
964  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
965         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
966  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
967 @@ -146,7 +146,7 @@ sys_call_table:
968  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
969         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
970  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
971 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
972 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
973  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
974         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
975  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
976 diff -NurpP --minimal linux-2.6.33/arch/x86/ia32/ia32entry.S linux-2.6.33-vs2.3.0.36.30/arch/x86/ia32/ia32entry.S
977 --- linux-2.6.33/arch/x86/ia32/ia32entry.S      2010-02-25 11:51:34.000000000 +0100
978 +++ linux-2.6.33-vs2.3.0.36.30/arch/x86/ia32/ia32entry.S        2010-02-25 12:02:16.000000000 +0100
979 @@ -777,7 +777,7 @@ ia32_sys_call_table:
980         .quad sys_tgkill                /* 270 */
981         .quad compat_sys_utimes
982         .quad sys32_fadvise64_64
983 -       .quad quiet_ni_syscall  /* sys_vserver */
984 +       .quad sys32_vserver
985         .quad sys_mbind
986         .quad compat_sys_get_mempolicy  /* 275 */
987         .quad sys_set_mempolicy
988 diff -NurpP --minimal linux-2.6.33/arch/x86/include/asm/unistd_64.h linux-2.6.33-vs2.3.0.36.30/arch/x86/include/asm/unistd_64.h
989 --- linux-2.6.33/arch/x86/include/asm/unistd_64.h       2010-02-25 11:51:34.000000000 +0100
990 +++ linux-2.6.33-vs2.3.0.36.30/arch/x86/include/asm/unistd_64.h 2010-02-25 12:02:16.000000000 +0100
991 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
992  #define __NR_utimes                            235
993  __SYSCALL(__NR_utimes, sys_utimes)
994  #define __NR_vserver                           236
995 -__SYSCALL(__NR_vserver, sys_ni_syscall)
996 +__SYSCALL(__NR_vserver, sys_vserver)
997  #define __NR_mbind                             237
998  __SYSCALL(__NR_mbind, sys_mbind)
999  #define __NR_set_mempolicy                     238
1000 diff -NurpP --minimal linux-2.6.33/arch/x86/Kconfig linux-2.6.33-vs2.3.0.36.30/arch/x86/Kconfig
1001 --- linux-2.6.33/arch/x86/Kconfig       2010-02-25 11:51:34.000000000 +0100
1002 +++ linux-2.6.33-vs2.3.0.36.30/arch/x86/Kconfig 2010-02-25 12:02:16.000000000 +0100
1003 @@ -2083,6 +2083,8 @@ source "fs/Kconfig"
1004  
1005  source "arch/x86/Kconfig.debug"
1006  
1007 +source "kernel/vserver/Kconfig"
1008 +
1009  source "security/Kconfig"
1010  
1011  source "crypto/Kconfig"
1012 diff -NurpP --minimal linux-2.6.33/arch/x86/kernel/syscall_table_32.S linux-2.6.33-vs2.3.0.36.30/arch/x86/kernel/syscall_table_32.S
1013 --- linux-2.6.33/arch/x86/kernel/syscall_table_32.S     2010-02-25 11:51:35.000000000 +0100
1014 +++ linux-2.6.33-vs2.3.0.36.30/arch/x86/kernel/syscall_table_32.S       2010-02-25 12:02:16.000000000 +0100
1015 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1016         .long sys_tgkill        /* 270 */
1017         .long sys_utimes
1018         .long sys_fadvise64_64
1019 -       .long sys_ni_syscall    /* sys_vserver */
1020 +       .long sys_vserver
1021         .long sys_mbind
1022         .long sys_get_mempolicy
1023         .long sys_set_mempolicy
1024 diff -NurpP --minimal linux-2.6.33/arch/xtensa/mm/fault.c linux-2.6.33-vs2.3.0.36.30/arch/xtensa/mm/fault.c
1025 --- linux-2.6.33/arch/xtensa/mm/fault.c 2009-09-10 15:25:48.000000000 +0200
1026 +++ linux-2.6.33-vs2.3.0.36.30/arch/xtensa/mm/fault.c   2010-02-25 12:02:16.000000000 +0100
1027 @@ -151,7 +151,8 @@ out_of_memory:
1028                 down_read(&mm->mmap_sem);
1029                 goto survive;
1030         }
1031 -       printk("VM: killing process %s\n", current->comm);
1032 +       printk("VM: killing process %s(%d:#%u)\n",
1033 +               current->comm, task_pid_nr(current), current->xid);
1034         if (user_mode(regs))
1035                 do_group_exit(SIGKILL);
1036         bad_page_fault(regs, address, SIGKILL);
1037 diff -NurpP --minimal linux-2.6.33/Documentation/scheduler/sched-cfs-hard-limits.txt linux-2.6.33-vs2.3.0.36.30/Documentation/scheduler/sched-cfs-hard-limits.txt
1038 --- linux-2.6.33/Documentation/scheduler/sched-cfs-hard-limits.txt      1970-01-01 01:00:00.000000000 +0100
1039 +++ linux-2.6.33-vs2.3.0.36.30/Documentation/scheduler/sched-cfs-hard-limits.txt        2010-02-25 12:02:16.000000000 +0100
1040 @@ -0,0 +1,48 @@
1041 +CPU HARD LIMITS FOR CFS GROUPS
1042 +==============================
1043 +
1044 +1. Overview
1045 +2. Interface
1046 +3. Examples
1047 +
1048 +1. Overview
1049 +-----------
1050 +
1051 +CFS is a proportional share scheduler which tries to divide the CPU time
1052 +proportionately between tasks or groups of tasks (task group/cgroup) depending
1053 +on the priority/weight of the task or shares assigned to groups of tasks.
1054 +In CFS, a task/task group can get more than its share of CPU if there are
1055 +enough idle CPU cycles available in the system, due to the work conserving
1056 +nature of the scheduler. However in certain scenarios (like pay-per-use),
1057 +it is desirable not to provide extra time to a group even in the presence
1058 +of idle CPU cycles. This is where hard limiting can be of use.
1059 +
1060 +Hard limits for task groups can be set by specifying how much CPU runtime a
1061 +group can consume within a given period. If the group consumes more CPU time
1062 +than the runtime in a given period, it gets throttled. None of the tasks of
1063 +the throttled group gets to run until the runtime of the group gets refreshed
1064 +at the beginning of the next period.
1065 +
1066 +2. Interface
1067 +------------
1068 +
1069 +Hard limit feature adds 2 cgroup files for CFS group scheduler:
1070 +
1071 +cfs_runtime_us: Hard limit for the group in microseconds.
1072 +
1073 +cfs_period_us: Time period in microseconds within which hard limits is
1074 +enforced.
1075 +
1076 +A group gets created with default values for runtime (infinite runtime which
1077 +means hard limits disabled) and period (0.5s). Each group can set its own
1078 +values for runtime and period independent of other groups in the system.
1079 +
1080 +3. Examples
1081 +-----------
1082 +
1083 +# mount -t cgroup -ocpu none /cgroups/
1084 +# cd /cgroups
1085 +# mkdir 1
1086 +# cd 1/
1087 +# echo 250000 > cfs_runtime_us /* set a 250ms runtime or limit */
1088 +# echo 500000 > cfs_period_us /* set a 500ms period */
1089 diff -NurpP --minimal linux-2.6.33/Documentation/vserver/debug.txt linux-2.6.33-vs2.3.0.36.30/Documentation/vserver/debug.txt
1090 --- linux-2.6.33/Documentation/vserver/debug.txt        1970-01-01 01:00:00.000000000 +0100
1091 +++ linux-2.6.33-vs2.3.0.36.30/Documentation/vserver/debug.txt  2010-02-25 12:02:16.000000000 +0100
1092 @@ -0,0 +1,154 @@
1093 +
1094 +debug_cvirt:
1095 +
1096 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
1097 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
1098 +
1099 +debug_dlim:
1100 +
1101 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
1102 +       "FREE  (%p,#%d)%c inode"
1103 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
1104 +       "FREE  (%p,#%d)%c %lld bytes"
1105 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
1106 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
1107 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
1108 +       "rcu_free_dl_info(%p)"
1109 + 4  10 "alloc_dl_info(%p,%d) = %p"
1110 +       "dealloc_dl_info(%p)"
1111 +       "get_dl_info(%p[#%d.%d])"
1112 +       "put_dl_info(%p[#%d.%d])"
1113 + 5  20 "alloc_dl_info(%p,%d)*"
1114 + 6  40 "__hash_dl_info: %p[#%d]"
1115 +       "__unhash_dl_info: %p[#%d]"
1116 + 7  80 "locate_dl_info(%p,#%d) = %p"
1117 +
1118 +debug_misc:
1119 +
1120 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
1121 +       "new_dqhash: %p [#0x%08x]"
1122 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
1123 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
1124 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
1125 +       "vroot_get_real_bdev not set"
1126 + 1   2 "cow_break_link(»%s«)"
1127 +       "temp copy Â»%s«"
1128 + 2   4 "dentry_open(new): %p"
1129 +       "dentry_open(old): %p"
1130 +       "lookup_create(new): %p"
1131 +       "old path Â»%s«"
1132 +       "path_lookup(old): %d"
1133 +       "vfs_create(new): %d"
1134 +       "vfs_rename: %d"
1135 +       "vfs_sendfile: %d"
1136 + 3   8 "fput(new_file=%p[#%d])"
1137 +       "fput(old_file=%p[#%d])"
1138 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
1139 +       "vx_info_kill(%p[#%d],%d,%d)*"
1140 + 5  20 "vs_reboot(%p[#%d],%d)"
1141 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
1142 +
1143 +debug_net:
1144 +
1145 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
1146 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
1147 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
1148 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
1149 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
1150 + 6  40 "sk,egf: %p [#%d] (from %d)"
1151 +       "sk,egn: %p [#%d] (from %d)"
1152 +       "sk,req: %p [#%d] (from %d)"
1153 +       "sk: %p [#%d] (from %d)"
1154 +       "tw: %p [#%d] (from %d)"
1155 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
1156 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
1157 +
1158 +debug_nid:
1159 +
1160 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
1161 +       "alloc_nx_info(%d) = %p"
1162 +       "create_nx_info(%d) (dynamic rejected)"
1163 +       "create_nx_info(%d) = %p (already there)"
1164 +       "create_nx_info(%d) = %p (new)"
1165 +       "dealloc_nx_info(%p)"
1166 + 1   2 "alloc_nx_info(%d)*"
1167 +       "create_nx_info(%d)*"
1168 + 2   4 "get_nx_info(%p[#%d.%d])"
1169 +       "put_nx_info(%p[#%d.%d])"
1170 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
1171 +       "clr_nx_info(%p[#%d.%d])"
1172 +       "init_nx_info(%p[#%d.%d])"
1173 +       "release_nx_info(%p[#%d.%d.%d]) %p"
1174 +       "set_nx_info(%p[#%d.%d])"
1175 + 4  10 "__hash_nx_info: %p[#%d]"
1176 +       "__nx_dynamic_id: [#%d]"
1177 +       "__unhash_nx_info: %p[#%d.%d.%d]"
1178 + 5  20 "moved task %p into nxi:%p[#%d]"
1179 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
1180 +       "task_get_nx_info(%p)"
1181 + 6  40 "nx_clear_persistent(%p[#%d])"
1182 +
1183 +debug_quota:
1184 +
1185 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
1186 + 1   2 "quota_sync_dqh(%p,%d)"
1187 +       "sync_dquots(%p,%d)"
1188 +       "sync_dquots_dqh(%p,%d)"
1189 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
1190 +
1191 +debug_switch:
1192 +
1193 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
1194 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
1195 + 4  10 "%s: (%s %s) returned %s with %d"
1196 +
1197 +debug_tag:
1198 +
1199 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
1200 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1201 +
1202 +debug_xid:
1203 +
1204 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1205 +       "alloc_vx_info(%d) = %p"
1206 +       "alloc_vx_info(%d)*"
1207 +       "create_vx_info(%d) (dynamic rejected)"
1208 +       "create_vx_info(%d) = %p (already there)"
1209 +       "create_vx_info(%d) = %p (new)"
1210 +       "dealloc_vx_info(%p)"
1211 +       "loc_vx_info(%d) = %p (found)"
1212 +       "loc_vx_info(%d) = %p (new)"
1213 +       "loc_vx_info(%d) = %p (not available)"
1214 + 1   2 "create_vx_info(%d)*"
1215 +       "loc_vx_info(%d)*"
1216 + 2   4 "get_vx_info(%p[#%d.%d])"
1217 +       "put_vx_info(%p[#%d.%d])"
1218 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1219 +       "clr_vx_info(%p[#%d.%d])"
1220 +       "init_vx_info(%p[#%d.%d])"
1221 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1222 +       "set_vx_info(%p[#%d.%d])"
1223 + 4  10 "__hash_vx_info: %p[#%d]"
1224 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1225 +       "__vx_dynamic_id: [#%d]"
1226 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1227 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1228 +       "moved task %p into vxi:%p[#%d]"
1229 +       "task_get_vx_info(%p)"
1230 +       "vx_migrate_task(%p,%p[#%d.%d])"
1231 + 6  40 "vx_clear_persistent(%p[#%d])"
1232 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1233 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1234 +       "vx_set_persistent(%p[#%d])"
1235 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1236 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1237 +
1238 +
1239 +debug_limit:
1240 +
1241 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1242 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1243 +
1244 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1245 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1246 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1247 diff -NurpP --minimal linux-2.6.33/drivers/block/Kconfig linux-2.6.33-vs2.3.0.36.30/drivers/block/Kconfig
1248 --- linux-2.6.33/drivers/block/Kconfig  2010-02-25 11:51:36.000000000 +0100
1249 +++ linux-2.6.33-vs2.3.0.36.30/drivers/block/Kconfig    2010-02-25 12:02:16.000000000 +0100
1250 @@ -273,6 +273,13 @@ config BLK_DEV_CRYPTOLOOP
1251  
1252  source "drivers/block/drbd/Kconfig"
1253  
1254 +config BLK_DEV_VROOT
1255 +       tristate "Virtual Root device support"
1256 +       depends on QUOTACTL
1257 +       ---help---
1258 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1259 +         partition within a virtual server without compromising security.
1260 +
1261  config BLK_DEV_NBD
1262         tristate "Network block device support"
1263         depends on NET
1264 diff -NurpP --minimal linux-2.6.33/drivers/block/loop.c linux-2.6.33-vs2.3.0.36.30/drivers/block/loop.c
1265 --- linux-2.6.33/drivers/block/loop.c   2009-12-03 20:02:19.000000000 +0100
1266 +++ linux-2.6.33-vs2.3.0.36.30/drivers/block/loop.c     2010-02-25 12:02:16.000000000 +0100
1267 @@ -74,6 +74,7 @@
1268  #include <linux/gfp.h>
1269  #include <linux/kthread.h>
1270  #include <linux/splice.h>
1271 +#include <linux/vs_context.h>
1272  
1273  #include <asm/uaccess.h>
1274  
1275 @@ -812,6 +813,7 @@ static int loop_set_fd(struct loop_devic
1276         lo->lo_blocksize = lo_blocksize;
1277         lo->lo_device = bdev;
1278         lo->lo_flags = lo_flags;
1279 +       lo->lo_xid = vx_current_xid();
1280         lo->lo_backing_file = file;
1281         lo->transfer = transfer_none;
1282         lo->ioctl = NULL;
1283 @@ -937,6 +939,7 @@ static int loop_clr_fd(struct loop_devic
1284         lo->lo_encrypt_key_size = 0;
1285         lo->lo_flags = 0;
1286         lo->lo_thread = NULL;
1287 +       lo->lo_xid = 0;
1288         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1289         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1290         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1291 @@ -971,7 +974,7 @@ loop_set_status(struct loop_device *lo, 
1292  
1293         if (lo->lo_encrypt_key_size &&
1294             lo->lo_key_owner != uid &&
1295 -           !capable(CAP_SYS_ADMIN))
1296 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1297                 return -EPERM;
1298         if (lo->lo_state != Lo_bound)
1299                 return -ENXIO;
1300 @@ -1055,7 +1058,8 @@ loop_get_status(struct loop_device *lo, 
1301         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1302         info->lo_encrypt_type =
1303                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1304 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1305 +       if (lo->lo_encrypt_key_size &&
1306 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1307                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1308                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1309                        lo->lo_encrypt_key_size);
1310 @@ -1399,6 +1403,9 @@ static int lo_open(struct block_device *
1311  {
1312         struct loop_device *lo = bdev->bd_disk->private_data;
1313  
1314 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1315 +               return -EACCES;
1316 +
1317         mutex_lock(&lo->lo_ctl_mutex);
1318         lo->lo_refcnt++;
1319         mutex_unlock(&lo->lo_ctl_mutex);
1320 diff -NurpP --minimal linux-2.6.33/drivers/block/Makefile linux-2.6.33-vs2.3.0.36.30/drivers/block/Makefile
1321 --- linux-2.6.33/drivers/block/Makefile 2010-02-25 11:51:36.000000000 +0100
1322 +++ linux-2.6.33-vs2.3.0.36.30/drivers/block/Makefile   2010-02-25 12:02:16.000000000 +0100
1323 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1324  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1325  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1326  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1327 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1328  
1329  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1330  obj-$(CONFIG_BLK_DEV_DRBD)     += drbd/
1331 diff -NurpP --minimal linux-2.6.33/drivers/block/vroot.c linux-2.6.33-vs2.3.0.36.30/drivers/block/vroot.c
1332 --- linux-2.6.33/drivers/block/vroot.c  1970-01-01 01:00:00.000000000 +0100
1333 +++ linux-2.6.33-vs2.3.0.36.30/drivers/block/vroot.c    2010-02-25 12:02:16.000000000 +0100
1334 @@ -0,0 +1,281 @@
1335 +/*
1336 + *  linux/drivers/block/vroot.c
1337 + *
1338 + *  written by Herbert Pötzl, 9/11/2002
1339 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1340 + *
1341 + *  based on the loop.c code by Theodore Ts'o.
1342 + *
1343 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1344 + * Redistribution of this file is permitted under the
1345 + * GNU General Public License.
1346 + *
1347 + */
1348 +
1349 +#include <linux/module.h>
1350 +#include <linux/moduleparam.h>
1351 +#include <linux/file.h>
1352 +#include <linux/major.h>
1353 +#include <linux/blkdev.h>
1354 +
1355 +#include <linux/vroot.h>
1356 +#include <linux/vs_context.h>
1357 +
1358 +
1359 +static int max_vroot = 8;
1360 +
1361 +static struct vroot_device *vroot_dev;
1362 +static struct gendisk **disks;
1363 +
1364 +
1365 +static int vroot_set_dev(
1366 +       struct vroot_device *vr,
1367 +       struct block_device *bdev,
1368 +       unsigned int arg)
1369 +{
1370 +       struct block_device *real_bdev;
1371 +       struct file *file;
1372 +       struct inode *inode;
1373 +       int error;
1374 +
1375 +       error = -EBUSY;
1376 +       if (vr->vr_state != Vr_unbound)
1377 +               goto out;
1378 +
1379 +       error = -EBADF;
1380 +       file = fget(arg);
1381 +       if (!file)
1382 +               goto out;
1383 +
1384 +       error = -EINVAL;
1385 +       inode = file->f_dentry->d_inode;
1386 +
1387 +
1388 +       if (S_ISBLK(inode->i_mode)) {
1389 +               real_bdev = inode->i_bdev;
1390 +               vr->vr_device = real_bdev;
1391 +               __iget(real_bdev->bd_inode);
1392 +       } else
1393 +               goto out_fput;
1394 +
1395 +       vxdprintk(VXD_CBIT(misc, 0),
1396 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1397 +               vr->vr_number, VXD_DEV(real_bdev));
1398 +
1399 +       vr->vr_state = Vr_bound;
1400 +       error = 0;
1401 +
1402 + out_fput:
1403 +       fput(file);
1404 + out:
1405 +       return error;
1406 +}
1407 +
1408 +static int vroot_clr_dev(
1409 +       struct vroot_device *vr,
1410 +       struct block_device *bdev)
1411 +{
1412 +       struct block_device *real_bdev;
1413 +
1414 +       if (vr->vr_state != Vr_bound)
1415 +               return -ENXIO;
1416 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1417 +               return -EBUSY;
1418 +
1419 +       real_bdev = vr->vr_device;
1420 +
1421 +       vxdprintk(VXD_CBIT(misc, 0),
1422 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1423 +               vr->vr_number, VXD_DEV(real_bdev));
1424 +
1425 +       bdput(real_bdev);
1426 +       vr->vr_state = Vr_unbound;
1427 +       vr->vr_device = NULL;
1428 +       return 0;
1429 +}
1430 +
1431 +
1432 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1433 +       unsigned int cmd, unsigned long arg)
1434 +{
1435 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1436 +       int err;
1437 +
1438 +       down(&vr->vr_ctl_mutex);
1439 +       switch (cmd) {
1440 +       case VROOT_SET_DEV:
1441 +               err = vroot_set_dev(vr, bdev, arg);
1442 +               break;
1443 +       case VROOT_CLR_DEV:
1444 +               err = vroot_clr_dev(vr, bdev);
1445 +               break;
1446 +       default:
1447 +               err = -EINVAL;
1448 +               break;
1449 +       }
1450 +       up(&vr->vr_ctl_mutex);
1451 +       return err;
1452 +}
1453 +
1454 +static int vr_open(struct block_device *bdev, fmode_t mode)
1455 +{
1456 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1457 +
1458 +       down(&vr->vr_ctl_mutex);
1459 +       vr->vr_refcnt++;
1460 +       up(&vr->vr_ctl_mutex);
1461 +       return 0;
1462 +}
1463 +
1464 +static int vr_release(struct gendisk *disk, fmode_t mode)
1465 +{
1466 +       struct vroot_device *vr = disk->private_data;
1467 +
1468 +       down(&vr->vr_ctl_mutex);
1469 +       --vr->vr_refcnt;
1470 +       up(&vr->vr_ctl_mutex);
1471 +       return 0;
1472 +}
1473 +
1474 +static struct block_device_operations vr_fops = {
1475 +       .owner =        THIS_MODULE,
1476 +       .open =         vr_open,
1477 +       .release =      vr_release,
1478 +       .ioctl =        vr_ioctl,
1479 +};
1480 +
1481 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1482 +{
1483 +       struct inode *inode = bdev->bd_inode;
1484 +       struct vroot_device *vr;
1485 +       struct block_device *real_bdev;
1486 +       int minor = iminor(inode);
1487 +
1488 +       vr = &vroot_dev[minor];
1489 +       real_bdev = vr->vr_device;
1490 +
1491 +       vxdprintk(VXD_CBIT(misc, 0),
1492 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1493 +               vr->vr_number, VXD_DEV(real_bdev));
1494 +
1495 +       if (vr->vr_state != Vr_bound)
1496 +               return ERR_PTR(-ENXIO);
1497 +
1498 +       __iget(real_bdev->bd_inode);
1499 +       return real_bdev;
1500 +}
1501 +
1502 +/*
1503 + * And now the modules code and kernel interface.
1504 + */
1505 +
1506 +module_param(max_vroot, int, 0);
1507 +
1508 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1509 +MODULE_LICENSE("GPL");
1510 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1511 +
1512 +MODULE_AUTHOR ("Herbert Pötzl");
1513 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1514 +
1515 +
1516 +int __init vroot_init(void)
1517 +{
1518 +       int err, i;
1519 +
1520 +       if (max_vroot < 1 || max_vroot > 256) {
1521 +               max_vroot = MAX_VROOT_DEFAULT;
1522 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1523 +                       "(must be between 1 and 256), "
1524 +                       "using default (%d)\n", max_vroot);
1525 +       }
1526 +
1527 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1528 +               return -EIO;
1529 +
1530 +       err = -ENOMEM;
1531 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1532 +       if (!vroot_dev)
1533 +               goto out_mem1;
1534 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1535 +
1536 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1537 +       if (!disks)
1538 +               goto out_mem2;
1539 +
1540 +       for (i = 0; i < max_vroot; i++) {
1541 +               disks[i] = alloc_disk(1);
1542 +               if (!disks[i])
1543 +                       goto out_mem3;
1544 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1545 +               if (!disks[i]->queue)
1546 +                       goto out_mem3;
1547 +       }
1548 +
1549 +       for (i = 0; i < max_vroot; i++) {
1550 +               struct vroot_device *vr = &vroot_dev[i];
1551 +               struct gendisk *disk = disks[i];
1552 +
1553 +               memset(vr, 0, sizeof(*vr));
1554 +               init_MUTEX(&vr->vr_ctl_mutex);
1555 +               vr->vr_number = i;
1556 +               disk->major = VROOT_MAJOR;
1557 +               disk->first_minor = i;
1558 +               disk->fops = &vr_fops;
1559 +               sprintf(disk->disk_name, "vroot%d", i);
1560 +               disk->private_data = vr;
1561 +       }
1562 +
1563 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1564 +       if (err)
1565 +               goto out_mem3;
1566 +
1567 +       for (i = 0; i < max_vroot; i++)
1568 +               add_disk(disks[i]);
1569 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1570 +       return 0;
1571 +
1572 +out_mem3:
1573 +       while (i--)
1574 +               put_disk(disks[i]);
1575 +       kfree(disks);
1576 +out_mem2:
1577 +       kfree(vroot_dev);
1578 +out_mem1:
1579 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1580 +       printk(KERN_ERR "vroot: ran out of memory\n");
1581 +       return err;
1582 +}
1583 +
1584 +void vroot_exit(void)
1585 +{
1586 +       int i;
1587 +
1588 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1589 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1590 +
1591 +       for (i = 0; i < max_vroot; i++) {
1592 +               del_gendisk(disks[i]);
1593 +               put_disk(disks[i]);
1594 +       }
1595 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1596 +
1597 +       kfree(disks);
1598 +       kfree(vroot_dev);
1599 +}
1600 +
1601 +module_init(vroot_init);
1602 +module_exit(vroot_exit);
1603 +
1604 +#ifndef MODULE
1605 +
1606 +static int __init max_vroot_setup(char *str)
1607 +{
1608 +       max_vroot = simple_strtol(str, NULL, 0);
1609 +       return 1;
1610 +}
1611 +
1612 +__setup("max_vroot=", max_vroot_setup);
1613 +
1614 +#endif
1615 +
1616 diff -NurpP --minimal linux-2.6.33/drivers/char/sysrq.c linux-2.6.33-vs2.3.0.36.30/drivers/char/sysrq.c
1617 --- linux-2.6.33/drivers/char/sysrq.c   2010-02-25 11:51:37.000000000 +0100
1618 +++ linux-2.6.33-vs2.3.0.36.30/drivers/char/sysrq.c     2010-02-25 12:02:16.000000000 +0100
1619 @@ -38,6 +38,7 @@
1620  #include <linux/workqueue.h>
1621  #include <linux/hrtimer.h>
1622  #include <linux/oom.h>
1623 +#include <linux/vserver/debug.h>
1624  
1625  #include <asm/ptrace.h>
1626  #include <asm/irq_regs.h>
1627 @@ -391,6 +392,21 @@ static struct sysrq_key_op sysrq_unrt_op
1628         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1629  };
1630  
1631 +
1632 +#ifdef CONFIG_VSERVER_DEBUG
1633 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1634 +{
1635 +       dump_vx_info_inactive((key == 'x')?0:1);
1636 +}
1637 +
1638 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1639 +       .handler        = sysrq_handle_vxinfo,
1640 +       .help_msg       = "conteXt",
1641 +       .action_msg     = "Show Context Info",
1642 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1643 +};
1644 +#endif
1645 +
1646  /* Key Operations table and lock */
1647  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1648  
1649 @@ -445,7 +461,11 @@ static struct sysrq_key_op *sysrq_key_ta
1650         NULL,                           /* v */
1651         &sysrq_showstate_blocked_op,    /* w */
1652         /* x: May be registered on ppc/powerpc for xmon */
1653 +#ifdef CONFIG_VSERVER_DEBUG
1654 +       &sysrq_showvxinfo_op,           /* x */
1655 +#else
1656         NULL,                           /* x */
1657 +#endif
1658         /* y: May be registered on sparc64 for global register dump */
1659         NULL,                           /* y */
1660         &sysrq_ftrace_dump_op,          /* z */
1661 @@ -460,6 +480,8 @@ static int sysrq_key_table_key2index(int
1662                 retval = key - '0';
1663         else if ((key >= 'a') && (key <= 'z'))
1664                 retval = key + 10 - 'a';
1665 +       else if ((key >= 'A') && (key <= 'Z'))
1666 +               retval = key + 10 - 'A';
1667         else
1668                 retval = -1;
1669         return retval;
1670 diff -NurpP --minimal linux-2.6.33/drivers/char/tty_io.c linux-2.6.33-vs2.3.0.36.30/drivers/char/tty_io.c
1671 --- linux-2.6.33/drivers/char/tty_io.c  2010-02-25 11:51:37.000000000 +0100
1672 +++ linux-2.6.33-vs2.3.0.36.30/drivers/char/tty_io.c    2010-02-25 12:02:16.000000000 +0100
1673 @@ -106,6 +106,7 @@
1674  
1675  #include <linux/kmod.h>
1676  #include <linux/nsproxy.h>
1677 +#include <linux/vs_pid.h>
1678  
1679  #undef TTY_DEBUG_HANGUP
1680  
1681 @@ -1989,7 +1990,8 @@ static int tiocsti(struct tty_struct *tt
1682         char ch, mbz = 0;
1683         struct tty_ldisc *ld;
1684  
1685 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1686 +       if (((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) ||
1687 +               !vx_ccaps(VXC_TIOCSTI))
1688                 return -EPERM;
1689         if (get_user(ch, p))
1690                 return -EFAULT;
1691 @@ -2277,6 +2279,7 @@ static int tiocspgrp(struct tty_struct *
1692                 return -ENOTTY;
1693         if (get_user(pgrp_nr, p))
1694                 return -EFAULT;
1695 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1696         if (pgrp_nr < 0)
1697                 return -EINVAL;
1698         rcu_read_lock();
1699 diff -NurpP --minimal linux-2.6.33/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.33-vs2.3.0.36.30/drivers/infiniband/hw/ipath/ipath_user_pages.c
1700 --- linux-2.6.33/drivers/infiniband/hw/ipath/ipath_user_pages.c 2009-12-03 20:02:23.000000000 +0100
1701 +++ linux-2.6.33-vs2.3.0.36.30/drivers/infiniband/hw/ipath/ipath_user_pages.c   2010-02-25 12:02:16.000000000 +0100
1702 @@ -34,6 +34,7 @@
1703  #include <linux/mm.h>
1704  #include <linux/device.h>
1705  #include <linux/sched.h>
1706 +#include <linux/vs_memory.h>
1707  
1708  #include "ipath_kernel.h"
1709  
1710 @@ -62,7 +63,8 @@ static int __get_user_pages(unsigned lon
1711         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1712                 PAGE_SHIFT;
1713  
1714 -       if (num_pages > lock_limit) {
1715 +       if (num_pages > lock_limit ||
1716 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1717                 ret = -ENOMEM;
1718                 goto bail;
1719         }
1720 @@ -79,7 +81,7 @@ static int __get_user_pages(unsigned lon
1721                         goto bail_release;
1722         }
1723  
1724 -       current->mm->locked_vm += num_pages;
1725 +       vx_vmlocked_add(current->mm, num_pages);
1726  
1727         ret = 0;
1728         goto bail;
1729 @@ -178,7 +180,7 @@ void ipath_release_user_pages(struct pag
1730  
1731         __ipath_release_user_pages(p, num_pages, 1);
1732  
1733 -       current->mm->locked_vm -= num_pages;
1734 +       vx_vmlocked_sub(current->mm, num_pages);
1735  
1736         up_write(&current->mm->mmap_sem);
1737  }
1738 @@ -195,7 +197,7 @@ static void user_pages_account(struct wo
1739                 container_of(_work, struct ipath_user_pages_work, work);
1740  
1741         down_write(&work->mm->mmap_sem);
1742 -       work->mm->locked_vm -= work->num_pages;
1743 +       vx_vmlocked_sub(work->mm, work->num_pages);
1744         up_write(&work->mm->mmap_sem);
1745         mmput(work->mm);
1746         kfree(work);
1747 diff -NurpP --minimal linux-2.6.33/drivers/md/dm.c linux-2.6.33-vs2.3.0.36.30/drivers/md/dm.c
1748 --- linux-2.6.33/drivers/md/dm.c        2010-02-25 11:51:41.000000000 +0100
1749 +++ linux-2.6.33-vs2.3.0.36.30/drivers/md/dm.c  2010-02-25 12:10:11.000000000 +0100
1750 @@ -19,6 +19,7 @@
1751  #include <linux/slab.h>
1752  #include <linux/idr.h>
1753  #include <linux/hdreg.h>
1754 +#include <linux/vs_base.h>
1755  
1756  #include <trace/events/block.h>
1757  
1758 @@ -119,6 +120,7 @@ struct mapped_device {
1759         rwlock_t map_lock;
1760         atomic_t holders;
1761         atomic_t open_count;
1762 +       xid_t xid;
1763  
1764         unsigned long flags;
1765  
1766 @@ -337,6 +339,7 @@ int dm_deleting_md(struct mapped_device 
1767  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1768  {
1769         struct mapped_device *md;
1770 +       int ret = -ENXIO;
1771  
1772         spin_lock(&_minor_lock);
1773  
1774 @@ -345,18 +348,19 @@ static int dm_blk_open(struct block_devi
1775                 goto out;
1776  
1777         if (test_bit(DMF_FREEING, &md->flags) ||
1778 -           dm_deleting_md(md)) {
1779 -               md = NULL;
1780 +           dm_deleting_md(md))
1781 +               goto out;
1782 +
1783 +       ret = -EACCES;
1784 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1785                 goto out;
1786 -       }
1787  
1788         dm_get(md);
1789         atomic_inc(&md->open_count);
1790 -
1791 +       ret = 0;
1792  out:
1793         spin_unlock(&_minor_lock);
1794 -
1795 -       return md ? 0 : -ENXIO;
1796 +       return ret;
1797  }
1798  
1799  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1800 @@ -574,6 +578,14 @@ int dm_set_geometry(struct mapped_device
1801         return 0;
1802  }
1803  
1804 +/*
1805 + * Get the xid associated with a dm device
1806 + */
1807 +xid_t dm_get_xid(struct mapped_device *md)
1808 +{
1809 +       return md->xid;
1810 +}
1811 +
1812  /*-----------------------------------------------------------------
1813   * CRUD START:
1814   *   A more elegant soln is in the works that uses the queue
1815 @@ -1886,6 +1898,7 @@ static struct mapped_device *alloc_dev(i
1816         INIT_LIST_HEAD(&md->uevent_list);
1817         spin_lock_init(&md->uevent_lock);
1818  
1819 +       md->xid = vx_current_xid();
1820         md->queue = blk_init_queue(dm_request_fn, NULL);
1821         if (!md->queue)
1822                 goto bad_queue;
1823 diff -NurpP --minimal linux-2.6.33/drivers/md/dm.h linux-2.6.33-vs2.3.0.36.30/drivers/md/dm.h
1824 --- linux-2.6.33/drivers/md/dm.h        2010-02-25 11:51:41.000000000 +0100
1825 +++ linux-2.6.33-vs2.3.0.36.30/drivers/md/dm.h  2010-02-25 12:02:16.000000000 +0100
1826 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1827  struct dm_table;
1828  struct dm_md_mempools;
1829  
1830 +xid_t dm_get_xid(struct mapped_device *md);
1831 +
1832  /*-----------------------------------------------------------------
1833   * Internal table functions.
1834   *---------------------------------------------------------------*/
1835 diff -NurpP --minimal linux-2.6.33/drivers/md/dm-ioctl.c linux-2.6.33-vs2.3.0.36.30/drivers/md/dm-ioctl.c
1836 --- linux-2.6.33/drivers/md/dm-ioctl.c  2010-02-25 11:51:41.000000000 +0100
1837 +++ linux-2.6.33-vs2.3.0.36.30/drivers/md/dm-ioctl.c    2010-02-25 12:02:16.000000000 +0100
1838 @@ -16,6 +16,7 @@
1839  #include <linux/dm-ioctl.h>
1840  #include <linux/hdreg.h>
1841  #include <linux/compat.h>
1842 +#include <linux/vs_context.h>
1843  
1844  #include <asm/uaccess.h>
1845  
1846 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1847         unsigned int h = hash_str(str);
1848  
1849         list_for_each_entry (hc, _name_buckets + h, name_list)
1850 -               if (!strcmp(hc->name, str)) {
1851 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1852 +                       !strcmp(hc->name, str)) {
1853                         dm_get(hc->md);
1854                         return hc;
1855                 }
1856 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1857         unsigned int h = hash_str(str);
1858  
1859         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1860 -               if (!strcmp(hc->uuid, str)) {
1861 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1862 +                       !strcmp(hc->uuid, str)) {
1863                         dm_get(hc->md);
1864                         return hc;
1865                 }
1866 @@ -363,6 +366,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1867  
1868  static int remove_all(struct dm_ioctl *param, size_t param_size)
1869  {
1870 +       if (!vx_check(0, VS_ADMIN))
1871 +               return -EPERM;
1872 +
1873         dm_hash_remove_all(1);
1874         param->data_size = 0;
1875         return 0;
1876 @@ -410,6 +416,8 @@ static int list_devices(struct dm_ioctl 
1877          */
1878         for (i = 0; i < NUM_BUCKETS; i++) {
1879                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1880 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1881 +                               continue;
1882                         needed += sizeof(struct dm_name_list);
1883                         needed += strlen(hc->name) + 1;
1884                         needed += ALIGN_MASK;
1885 @@ -433,6 +441,8 @@ static int list_devices(struct dm_ioctl 
1886          */
1887         for (i = 0; i < NUM_BUCKETS; i++) {
1888                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1889 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1890 +                               continue;
1891                         if (old_nl)
1892                                 old_nl->next = (uint32_t) ((void *) nl -
1893                                                            (void *) old_nl);
1894 @@ -667,10 +677,11 @@ static struct hash_cell *__find_device_h
1895         if (!md)
1896                 goto out;
1897  
1898 -       mdptr = dm_get_mdptr(md);
1899 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1900 +               mdptr = dm_get_mdptr(md);
1901 +
1902         if (!mdptr)
1903                 dm_put(md);
1904 -
1905  out:
1906         return mdptr;
1907  }
1908 @@ -1508,8 +1519,8 @@ static int ctl_ioctl(uint command, struc
1909         ioctl_fn fn = NULL;
1910         size_t param_size;
1911  
1912 -       /* only root can play with this */
1913 -       if (!capable(CAP_SYS_ADMIN))
1914 +       /* only root and certain contexts can play with this */
1915 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1916                 return -EACCES;
1917  
1918         if (_IOC_TYPE(command) != DM_IOCTL)
1919 diff -NurpP --minimal linux-2.6.33/drivers/net/tun.c linux-2.6.33-vs2.3.0.36.30/drivers/net/tun.c
1920 --- linux-2.6.33/drivers/net/tun.c      2010-02-25 11:51:53.000000000 +0100
1921 +++ linux-2.6.33-vs2.3.0.36.30/drivers/net/tun.c        2010-02-25 12:02:16.000000000 +0100
1922 @@ -61,6 +61,7 @@
1923  #include <linux/crc32.h>
1924  #include <linux/nsproxy.h>
1925  #include <linux/virtio_net.h>
1926 +#include <linux/vs_network.h>
1927  #include <net/net_namespace.h>
1928  #include <net/netns/generic.h>
1929  #include <net/rtnetlink.h>
1930 @@ -102,6 +103,7 @@ struct tun_struct {
1931         unsigned int            flags;
1932         uid_t                   owner;
1933         gid_t                   group;
1934 +       nid_t                   nid;
1935  
1936         struct net_device       *dev;
1937         struct fasync_struct    *fasync;
1938 @@ -816,6 +818,7 @@ static void tun_setup(struct net_device 
1939  
1940         tun->owner = -1;
1941         tun->group = -1;
1942 +       tun->nid = current->nid;
1943  
1944         dev->ethtool_ops = &tun_ethtool_ops;
1945         dev->destructor = tun_free_netdev;
1946 @@ -932,7 +935,7 @@ static int tun_set_iff(struct net *net, 
1947  
1948                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1949                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1950 -                   !capable(CAP_NET_ADMIN))
1951 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1952                         return -EPERM;
1953                 err = security_tun_dev_attach(tun->socket.sk);
1954                 if (err < 0)
1955 @@ -946,7 +949,7 @@ static int tun_set_iff(struct net *net, 
1956                 char *name;
1957                 unsigned long flags = 0;
1958  
1959 -               if (!capable(CAP_NET_ADMIN))
1960 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1961                         return -EPERM;
1962                 err = security_tun_dev_create();
1963                 if (err < 0)
1964 @@ -1013,6 +1016,9 @@ static int tun_set_iff(struct net *net, 
1965  
1966                 sk->sk_destruct = tun_sock_destruct;
1967  
1968 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1969 +                       return -EPERM;
1970 +
1971                 err = tun_attach(tun, file);
1972                 if (err < 0)
1973                         goto failed;
1974 @@ -1202,6 +1208,16 @@ static long __tun_chr_ioctl(struct file 
1975                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1976                 break;
1977  
1978 +       case TUNSETNID:
1979 +               if (!capable(CAP_CONTEXT))
1980 +                       return -EPERM;
1981 +
1982 +               /* Set nid owner of the device */
1983 +               tun->nid = (nid_t) arg;
1984 +
1985 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1986 +               break;
1987 +
1988         case TUNSETLINK:
1989                 /* Only allow setting the type when the interface is down */
1990                 if (tun->dev->flags & IFF_UP) {
1991 diff -NurpP --minimal linux-2.6.33/fs/attr.c linux-2.6.33-vs2.3.0.36.30/fs/attr.c
1992 --- linux-2.6.33/fs/attr.c      2009-12-03 20:02:51.000000000 +0100
1993 +++ linux-2.6.33-vs2.3.0.36.30/fs/attr.c        2010-02-25 12:02:16.000000000 +0100
1994 @@ -14,6 +14,9 @@
1995  #include <linux/fcntl.h>
1996  #include <linux/quotaops.h>
1997  #include <linux/security.h>
1998 +#include <linux/proc_fs.h>
1999 +#include <linux/devpts_fs.h>
2000 +#include <linux/vs_tag.h>
2001  
2002  /* Taken over from the old code... */
2003  
2004 @@ -55,6 +58,10 @@ int inode_change_ok(const struct inode *
2005                 if (!is_owner_or_cap(inode))
2006                         goto error;
2007         }
2008 +
2009 +       if (dx_permission(inode, MAY_WRITE))
2010 +               goto error;
2011 +
2012  fine:
2013         retval = 0;
2014  error:
2015 @@ -120,6 +127,8 @@ int inode_setattr(struct inode * inode, 
2016                 inode->i_uid = attr->ia_uid;
2017         if (ia_valid & ATTR_GID)
2018                 inode->i_gid = attr->ia_gid;
2019 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2020 +               inode->i_tag = attr->ia_tag;
2021         if (ia_valid & ATTR_ATIME)
2022                 inode->i_atime = timespec_trunc(attr->ia_atime,
2023                                                 inode->i_sb->s_time_gran);
2024 @@ -214,7 +223,8 @@ int notify_change(struct dentry * dentry
2025                 error = inode_change_ok(inode, attr);
2026                 if (!error) {
2027                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2028 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2029 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2030 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2031                                 error = vfs_dq_transfer(inode, attr) ?
2032                                         -EDQUOT : 0;
2033                         if (!error)
2034 diff -NurpP --minimal linux-2.6.33/fs/binfmt_aout.c linux-2.6.33-vs2.3.0.36.30/fs/binfmt_aout.c
2035 --- linux-2.6.33/fs/binfmt_aout.c       2010-02-25 11:52:04.000000000 +0100
2036 +++ linux-2.6.33-vs2.3.0.36.30/fs/binfmt_aout.c 2010-02-25 12:02:16.000000000 +0100
2037 @@ -24,6 +24,7 @@
2038  #include <linux/binfmts.h>
2039  #include <linux/personality.h>
2040  #include <linux/init.h>
2041 +#include <linux/vs_memory.h>
2042  
2043  #include <asm/system.h>
2044  #include <asm/uaccess.h>
2045 diff -NurpP --minimal linux-2.6.33/fs/binfmt_elf.c linux-2.6.33-vs2.3.0.36.30/fs/binfmt_elf.c
2046 --- linux-2.6.33/fs/binfmt_elf.c        2010-02-25 11:52:04.000000000 +0100
2047 +++ linux-2.6.33-vs2.3.0.36.30/fs/binfmt_elf.c  2010-02-25 12:02:16.000000000 +0100
2048 @@ -31,6 +31,7 @@
2049  #include <linux/random.h>
2050  #include <linux/elf.h>
2051  #include <linux/utsname.h>
2052 +#include <linux/vs_memory.h>
2053  #include <asm/uaccess.h>
2054  #include <asm/param.h>
2055  #include <asm/page.h>
2056 diff -NurpP --minimal linux-2.6.33/fs/binfmt_flat.c linux-2.6.33-vs2.3.0.36.30/fs/binfmt_flat.c
2057 --- linux-2.6.33/fs/binfmt_flat.c       2010-02-25 11:52:04.000000000 +0100
2058 +++ linux-2.6.33-vs2.3.0.36.30/fs/binfmt_flat.c 2010-02-25 12:02:16.000000000 +0100
2059 @@ -35,6 +35,7 @@
2060  #include <linux/init.h>
2061  #include <linux/flat.h>
2062  #include <linux/syscalls.h>
2063 +#include <linux/vs_memory.h>
2064  
2065  #include <asm/byteorder.h>
2066  #include <asm/system.h>
2067 diff -NurpP --minimal linux-2.6.33/fs/binfmt_som.c linux-2.6.33-vs2.3.0.36.30/fs/binfmt_som.c
2068 --- linux-2.6.33/fs/binfmt_som.c        2010-02-25 11:52:04.000000000 +0100
2069 +++ linux-2.6.33-vs2.3.0.36.30/fs/binfmt_som.c  2010-02-25 12:02:16.000000000 +0100
2070 @@ -28,6 +28,7 @@
2071  #include <linux/shm.h>
2072  #include <linux/personality.h>
2073  #include <linux/init.h>
2074 +#include <linux/vs_memory.h>
2075  
2076  #include <asm/uaccess.h>
2077  #include <asm/pgtable.h>
2078 diff -NurpP --minimal linux-2.6.33/fs/block_dev.c linux-2.6.33-vs2.3.0.36.30/fs/block_dev.c
2079 --- linux-2.6.33/fs/block_dev.c 2010-02-25 11:52:04.000000000 +0100
2080 +++ linux-2.6.33-vs2.3.0.36.30/fs/block_dev.c   2010-02-25 12:02:16.000000000 +0100
2081 @@ -26,6 +26,7 @@
2082  #include <linux/namei.h>
2083  #include <linux/log2.h>
2084  #include <linux/kmemleak.h>
2085 +#include <linux/vs_device.h>
2086  #include <asm/uaccess.h>
2087  #include "internal.h"
2088  
2089 @@ -566,6 +567,7 @@ struct block_device *bdget(dev_t dev)
2090                 bdev->bd_invalidated = 0;
2091                 inode->i_mode = S_IFBLK;
2092                 inode->i_rdev = dev;
2093 +               inode->i_mdev = dev;
2094                 inode->i_bdev = bdev;
2095                 inode->i_data.a_ops = &def_blk_aops;
2096                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2097 @@ -612,6 +614,11 @@ EXPORT_SYMBOL(bdput);
2098  static struct block_device *bd_acquire(struct inode *inode)
2099  {
2100         struct block_device *bdev;
2101 +       dev_t mdev;
2102 +
2103 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2104 +               return NULL;
2105 +       inode->i_mdev = mdev;
2106  
2107         spin_lock(&bdev_lock);
2108         bdev = inode->i_bdev;
2109 @@ -622,7 +629,7 @@ static struct block_device *bd_acquire(s
2110         }
2111         spin_unlock(&bdev_lock);
2112  
2113 -       bdev = bdget(inode->i_rdev);
2114 +       bdev = bdget(mdev);
2115         if (bdev) {
2116                 spin_lock(&bdev_lock);
2117                 if (!inode->i_bdev) {
2118 diff -NurpP --minimal linux-2.6.33/fs/btrfs/ctree.h linux-2.6.33-vs2.3.0.36.30/fs/btrfs/ctree.h
2119 --- linux-2.6.33/fs/btrfs/ctree.h       2010-02-25 11:52:04.000000000 +0100
2120 +++ linux-2.6.33-vs2.3.0.36.30/fs/btrfs/ctree.h 2010-02-25 12:02:16.000000000 +0100
2121 @@ -547,11 +547,14 @@ struct btrfs_inode_item {
2122         /* modification sequence number for NFS */
2123         __le64 sequence;
2124  
2125 +       __le16 tag;
2126         /*
2127          * a little future expansion, for more than this we can
2128          * just grow the inode item and version it
2129          */
2130 -       __le64 reserved[4];
2131 +       __le16 reserved16;
2132 +       __le32 reserved32;
2133 +       __le64 reserved[3];
2134         struct btrfs_timespec atime;
2135         struct btrfs_timespec ctime;
2136         struct btrfs_timespec mtime;
2137 @@ -1163,6 +1166,8 @@ struct btrfs_root {
2138  #define BTRFS_MOUNT_DISCARD            (1 << 10)
2139  #define BTRFS_MOUNT_FORCE_COMPRESS      (1 << 11)
2140  
2141 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2142 +
2143  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2144  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2145  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2146 @@ -1182,6 +1187,10 @@ struct btrfs_root {
2147  #define BTRFS_INODE_NOATIME            (1 << 9)
2148  #define BTRFS_INODE_DIRSYNC            (1 << 10)
2149  
2150 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2151 +#define BTRFS_INODE_BARRIER            (1 << 25)
2152 +#define BTRFS_INODE_COW                        (1 << 26)
2153 +
2154  
2155  /* some macros to generate set/get funcs for the struct fields.  This
2156   * assumes there is a lefoo_to_cpu for every type, so lets make a simple
2157 @@ -1384,6 +1393,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2158  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2159  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2160  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2161 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2162  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2163  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2164  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2165 @@ -2357,6 +2367,7 @@ extern const struct dentry_operations bt
2166  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2167  void btrfs_update_iflags(struct inode *inode);
2168  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2169 +int btrfs_sync_flags(struct inode *inode, int, int);
2170  
2171  /* file.c */
2172  int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync);
2173 diff -NurpP --minimal linux-2.6.33/fs/btrfs/disk-io.c linux-2.6.33-vs2.3.0.36.30/fs/btrfs/disk-io.c
2174 --- linux-2.6.33/fs/btrfs/disk-io.c     2010-02-25 11:52:04.000000000 +0100
2175 +++ linux-2.6.33-vs2.3.0.36.30/fs/btrfs/disk-io.c       2010-02-25 12:02:16.000000000 +0100
2176 @@ -1726,6 +1726,9 @@ struct btrfs_root *open_ctree(struct sup
2177                 goto fail_iput;
2178         }
2179  
2180 +       if (btrfs_test_opt(tree_root, TAGGED))
2181 +               sb->s_flags |= MS_TAGGED;
2182 +
2183         features = btrfs_super_incompat_flags(disk_super) &
2184                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2185         if (features) {
2186 diff -NurpP --minimal linux-2.6.33/fs/btrfs/inode.c linux-2.6.33-vs2.3.0.36.30/fs/btrfs/inode.c
2187 --- linux-2.6.33/fs/btrfs/inode.c       2010-02-25 11:52:04.000000000 +0100
2188 +++ linux-2.6.33-vs2.3.0.36.30/fs/btrfs/inode.c 2010-02-25 12:02:16.000000000 +0100
2189 @@ -36,6 +36,8 @@
2190  #include <linux/xattr.h>
2191  #include <linux/posix_acl.h>
2192  #include <linux/falloc.h>
2193 +#include <linux/vs_tag.h>
2194 +
2195  #include "compat.h"
2196  #include "ctree.h"
2197  #include "disk-io.h"
2198 @@ -2264,6 +2266,8 @@ static void btrfs_read_locked_inode(stru
2199         int maybe_acls;
2200         u64 alloc_group_block;
2201         u32 rdev;
2202 +       uid_t uid;
2203 +       gid_t gid;
2204         int ret;
2205  
2206         path = btrfs_alloc_path();
2207 @@ -2280,8 +2284,13 @@ static void btrfs_read_locked_inode(stru
2208  
2209         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2210         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2211 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2212 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2213 +
2214 +       uid = btrfs_inode_uid(leaf, inode_item);
2215 +       gid = btrfs_inode_gid(leaf, inode_item);
2216 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2217 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2218 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2219 +               btrfs_inode_tag(leaf, inode_item));
2220         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2221  
2222         tspec = btrfs_inode_atime(inode_item);
2223 @@ -2363,8 +2372,15 @@ static void fill_inode_item(struct btrfs
2224                             struct btrfs_inode_item *item,
2225                             struct inode *inode)
2226  {
2227 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2228 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2229 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2230 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2231 +
2232 +       btrfs_set_inode_uid(leaf, item, uid);
2233 +       btrfs_set_inode_gid(leaf, item, gid);
2234 +#ifdef CONFIG_TAGGING_INTERN
2235 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2236 +#endif
2237 +
2238         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2239         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2240         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2241 @@ -4154,6 +4170,7 @@ static struct inode *btrfs_new_inode(str
2242         } else
2243                 inode->i_gid = current_fsgid();
2244  
2245 +       inode->i_tag = dx_current_fstag(root->fs_info->sb);
2246         inode->i_mode = mode;
2247         inode->i_ino = objectid;
2248         inode_set_bytes(inode, 0);
2249 @@ -5955,6 +5972,7 @@ static const struct inode_operations btr
2250         .listxattr      = btrfs_listxattr,
2251         .removexattr    = btrfs_removexattr,
2252         .permission     = btrfs_permission,
2253 +       .sync_flags     = btrfs_sync_flags,
2254  };
2255  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2256         .lookup         = btrfs_lookup,
2257 @@ -6030,6 +6048,7 @@ static const struct inode_operations btr
2258         .permission     = btrfs_permission,
2259         .fallocate      = btrfs_fallocate,
2260         .fiemap         = btrfs_fiemap,
2261 +       .sync_flags     = btrfs_sync_flags,
2262  };
2263  static const struct inode_operations btrfs_special_inode_operations = {
2264         .getattr        = btrfs_getattr,
2265 diff -NurpP --minimal linux-2.6.33/fs/btrfs/ioctl.c linux-2.6.33-vs2.3.0.36.30/fs/btrfs/ioctl.c
2266 --- linux-2.6.33/fs/btrfs/ioctl.c       2010-02-25 11:52:04.000000000 +0100
2267 +++ linux-2.6.33-vs2.3.0.36.30/fs/btrfs/ioctl.c 2010-02-25 12:02:16.000000000 +0100
2268 @@ -67,10 +67,13 @@ static unsigned int btrfs_flags_to_ioctl
2269  {
2270         unsigned int iflags = 0;
2271  
2272 -       if (flags & BTRFS_INODE_SYNC)
2273 -               iflags |= FS_SYNC_FL;
2274         if (flags & BTRFS_INODE_IMMUTABLE)
2275                 iflags |= FS_IMMUTABLE_FL;
2276 +       if (flags & BTRFS_INODE_IXUNLINK)
2277 +               iflags |= FS_IXUNLINK_FL;
2278 +
2279 +       if (flags & BTRFS_INODE_SYNC)
2280 +               iflags |= FS_SYNC_FL;
2281         if (flags & BTRFS_INODE_APPEND)
2282                 iflags |= FS_APPEND_FL;
2283         if (flags & BTRFS_INODE_NODUMP)
2284 @@ -80,28 +83,78 @@ static unsigned int btrfs_flags_to_ioctl
2285         if (flags & BTRFS_INODE_DIRSYNC)
2286                 iflags |= FS_DIRSYNC_FL;
2287  
2288 +       if (flags & BTRFS_INODE_BARRIER)
2289 +               iflags |= FS_BARRIER_FL;
2290 +       if (flags & BTRFS_INODE_COW)
2291 +               iflags |= FS_COW_FL;
2292         return iflags;
2293  }
2294  
2295  /*
2296 - * Update inode->i_flags based on the btrfs internal flags.
2297 + * Update inode->i_(v)flags based on the btrfs internal flags.
2298   */
2299  void btrfs_update_iflags(struct inode *inode)
2300  {
2301         struct btrfs_inode *ip = BTRFS_I(inode);
2302  
2303 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2304 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2305 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2306  
2307 -       if (ip->flags & BTRFS_INODE_SYNC)
2308 -               inode->i_flags |= S_SYNC;
2309         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2310                 inode->i_flags |= S_IMMUTABLE;
2311 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2312 +               inode->i_flags |= S_IXUNLINK;
2313 +
2314 +       if (ip->flags & BTRFS_INODE_SYNC)
2315 +               inode->i_flags |= S_SYNC;
2316         if (ip->flags & BTRFS_INODE_APPEND)
2317                 inode->i_flags |= S_APPEND;
2318         if (ip->flags & BTRFS_INODE_NOATIME)
2319                 inode->i_flags |= S_NOATIME;
2320         if (ip->flags & BTRFS_INODE_DIRSYNC)
2321                 inode->i_flags |= S_DIRSYNC;
2322 +
2323 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2324 +
2325 +       if (ip->flags & BTRFS_INODE_BARRIER)
2326 +               inode->i_vflags |= V_BARRIER;
2327 +       if (ip->flags & BTRFS_INODE_COW)
2328 +               inode->i_vflags |= V_COW;
2329 +}
2330 +
2331 +/*
2332 + * Update btrfs internal flags from inode->i_(v)flags.
2333 + */
2334 +void btrfs_update_flags(struct inode *inode)
2335 +{
2336 +       struct btrfs_inode *ip = BTRFS_I(inode);
2337 +
2338 +       unsigned int flags = inode->i_flags;
2339 +       unsigned int vflags = inode->i_vflags;
2340 +
2341 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2342 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2343 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2344 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2345 +
2346 +       if (flags & S_IMMUTABLE)
2347 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2348 +       if (flags & S_IXUNLINK)
2349 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2350 +
2351 +       if (flags & S_SYNC)
2352 +               ip->flags |= BTRFS_INODE_SYNC;
2353 +       if (flags & S_APPEND)
2354 +               ip->flags |= BTRFS_INODE_APPEND;
2355 +       if (flags & S_NOATIME)
2356 +               ip->flags |= BTRFS_INODE_NOATIME;
2357 +       if (flags & S_DIRSYNC)
2358 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2359 +
2360 +       if (vflags & V_BARRIER)
2361 +               ip->flags |= BTRFS_INODE_BARRIER;
2362 +       if (vflags & V_COW)
2363 +               ip->flags |= BTRFS_INODE_COW;
2364  }
2365  
2366  /*
2367 @@ -119,7 +172,7 @@ void btrfs_inherit_iflags(struct inode *
2368         flags = BTRFS_I(dir)->flags;
2369  
2370         if (S_ISREG(inode->i_mode))
2371 -               flags &= ~BTRFS_INODE_DIRSYNC;
2372 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2373         else if (!S_ISDIR(inode->i_mode))
2374                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2375  
2376 @@ -127,6 +180,30 @@ void btrfs_inherit_iflags(struct inode *
2377         btrfs_update_iflags(inode);
2378  }
2379  
2380 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2381 +{
2382 +       struct btrfs_inode *ip = BTRFS_I(inode);
2383 +       struct btrfs_root *root = ip->root;
2384 +       struct btrfs_trans_handle *trans;
2385 +       int ret;
2386 +
2387 +       trans = btrfs_join_transaction(root, 1);
2388 +       BUG_ON(!trans);
2389 +
2390 +       inode->i_flags = flags;
2391 +       inode->i_vflags = vflags;
2392 +       btrfs_update_flags(inode);
2393 +
2394 +       ret = btrfs_update_inode(trans, root, inode);
2395 +       BUG_ON(ret);
2396 +
2397 +       btrfs_update_iflags(inode);
2398 +       inode->i_ctime = CURRENT_TIME;
2399 +       btrfs_end_transaction(trans, root);
2400 +
2401 +       return 0;
2402 +}
2403 +
2404  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2405  {
2406         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2407 @@ -149,6 +226,7 @@ static int btrfs_ioctl_setflags(struct f
2408         if (copy_from_user(&flags, arg, sizeof(flags)))
2409                 return -EFAULT;
2410  
2411 +       /* maybe add FS_IXUNLINK_FL ? */
2412         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2413                       FS_NOATIME_FL | FS_NODUMP_FL | \
2414                       FS_SYNC_FL | FS_DIRSYNC_FL))
2415 @@ -161,7 +239,8 @@ static int btrfs_ioctl_setflags(struct f
2416  
2417         flags = btrfs_mask_flags(inode->i_mode, flags);
2418         oldflags = btrfs_flags_to_ioctl(ip->flags);
2419 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2420 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2421 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2422                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2423                         ret = -EPERM;
2424                         goto out_unlock;
2425 @@ -172,14 +251,19 @@ static int btrfs_ioctl_setflags(struct f
2426         if (ret)
2427                 goto out_unlock;
2428  
2429 -       if (flags & FS_SYNC_FL)
2430 -               ip->flags |= BTRFS_INODE_SYNC;
2431 -       else
2432 -               ip->flags &= ~BTRFS_INODE_SYNC;
2433         if (flags & FS_IMMUTABLE_FL)
2434                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2435         else
2436                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2437 +       if (flags & FS_IXUNLINK_FL)
2438 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2439 +       else
2440 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2441 +
2442 +       if (flags & FS_SYNC_FL)
2443 +               ip->flags |= BTRFS_INODE_SYNC;
2444 +       else
2445 +               ip->flags &= ~BTRFS_INODE_SYNC;
2446         if (flags & FS_APPEND_FL)
2447                 ip->flags |= BTRFS_INODE_APPEND;
2448         else
2449 diff -NurpP --minimal linux-2.6.33/fs/btrfs/super.c linux-2.6.33-vs2.3.0.36.30/fs/btrfs/super.c
2450 --- linux-2.6.33/fs/btrfs/super.c       2010-02-25 11:52:04.000000000 +0100
2451 +++ linux-2.6.33-vs2.3.0.36.30/fs/btrfs/super.c 2010-02-25 15:33:43.000000000 +0100
2452 @@ -68,7 +68,7 @@ enum {
2453         Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl,
2454         Opt_compress, Opt_compress_force, Opt_notreelog, Opt_ratio,
2455         Opt_flushoncommit,
2456 -       Opt_discard, Opt_err,
2457 +       Opt_tag, Opt_notag, Opt_tagid, Opt_discard, Opt_err,
2458  };
2459  
2460  static match_table_t tokens = {
2461 @@ -92,6 +92,9 @@ static match_table_t tokens = {
2462         {Opt_flushoncommit, "flushoncommit"},
2463         {Opt_ratio, "metadata_ratio=%d"},
2464         {Opt_discard, "discard"},
2465 +       {Opt_tag, "tag"},
2466 +       {Opt_notag, "notag"},
2467 +       {Opt_tagid, "tagid=%u"},
2468         {Opt_err, NULL},
2469  };
2470  
2471 @@ -270,6 +273,22 @@ int btrfs_parse_options(struct btrfs_roo
2472                 case Opt_discard:
2473                         btrfs_set_opt(info->mount_opt, DISCARD);
2474                         break;
2475 +#ifndef CONFIG_TAGGING_NONE
2476 +               case Opt_tag:
2477 +                       printk(KERN_INFO "btrfs: use tagging\n");
2478 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2479 +                       break;
2480 +               case Opt_notag:
2481 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2482 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2483 +                       break;
2484 +#endif
2485 +#ifdef CONFIG_PROPAGATE
2486 +               case Opt_tagid:
2487 +                       /* use args[0] */
2488 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2489 +                       break;
2490 +#endif
2491                 case Opt_err:
2492                         printk(KERN_INFO "btrfs: unrecognized mount option "
2493                                "'%s'\n", p);
2494 @@ -591,6 +610,12 @@ static int btrfs_remount(struct super_bl
2495         if (ret)
2496                 return -EINVAL;
2497  
2498 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2499 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2500 +                       sb->s_id);
2501 +               return -EINVAL;
2502 +       }
2503 +
2504         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2505                 return 0;
2506  
2507 diff -NurpP --minimal linux-2.6.33/fs/char_dev.c linux-2.6.33-vs2.3.0.36.30/fs/char_dev.c
2508 --- linux-2.6.33/fs/char_dev.c  2009-12-03 20:02:51.000000000 +0100
2509 +++ linux-2.6.33-vs2.3.0.36.30/fs/char_dev.c    2010-02-25 12:02:16.000000000 +0100
2510 @@ -20,6 +20,8 @@
2511  #include <linux/cdev.h>
2512  #include <linux/mutex.h>
2513  #include <linux/backing-dev.h>
2514 +#include <linux/vs_context.h>
2515 +#include <linux/vs_device.h>
2516  
2517  #include "internal.h"
2518  
2519 @@ -368,14 +370,21 @@ static int chrdev_open(struct inode *ino
2520         struct cdev *p;
2521         struct cdev *new = NULL;
2522         int ret = 0;
2523 +       dev_t mdev;
2524 +
2525 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2526 +               return -EPERM;
2527 +       inode->i_mdev = mdev;
2528  
2529         spin_lock(&cdev_lock);
2530         p = inode->i_cdev;
2531         if (!p) {
2532                 struct kobject *kobj;
2533                 int idx;
2534 +
2535                 spin_unlock(&cdev_lock);
2536 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2537 +
2538 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2539                 if (!kobj)
2540                         return -ENXIO;
2541                 new = container_of(kobj, struct cdev, kobj);
2542 diff -NurpP --minimal linux-2.6.33/fs/dcache.c linux-2.6.33-vs2.3.0.36.30/fs/dcache.c
2543 --- linux-2.6.33/fs/dcache.c    2010-02-25 11:52:05.000000000 +0100
2544 +++ linux-2.6.33-vs2.3.0.36.30/fs/dcache.c      2010-02-25 12:02:16.000000000 +0100
2545 @@ -33,6 +33,7 @@
2546  #include <linux/bootmem.h>
2547  #include <linux/fs_struct.h>
2548  #include <linux/hardirq.h>
2549 +#include <linux/vs_limit.h>
2550  #include "internal.h"
2551  
2552  int sysctl_vfs_cache_pressure __read_mostly = 100;
2553 @@ -230,6 +231,8 @@ repeat:
2554                 return;
2555         }
2556  
2557 +       vx_dentry_dec(dentry);
2558 +
2559         /*
2560          * AV: ->d_delete() is _NOT_ allowed to block now.
2561          */
2562 @@ -321,6 +324,7 @@ static inline struct dentry * __dget_loc
2563  {
2564         atomic_inc(&dentry->d_count);
2565         dentry_lru_del_init(dentry);
2566 +       vx_dentry_inc(dentry);
2567         return dentry;
2568  }
2569  
2570 @@ -919,6 +923,9 @@ struct dentry *d_alloc(struct dentry * p
2571         struct dentry *dentry;
2572         char *dname;
2573  
2574 +       if (!vx_dentry_avail(1))
2575 +               return NULL;
2576 +
2577         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2578         if (!dentry)
2579                 return NULL;
2580 @@ -964,6 +971,7 @@ struct dentry *d_alloc(struct dentry * p
2581         if (parent)
2582                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2583         dentry_stat.nr_dentry++;
2584 +       vx_dentry_inc(dentry);
2585         spin_unlock(&dcache_lock);
2586  
2587         return dentry;
2588 @@ -1408,6 +1416,7 @@ struct dentry * __d_lookup(struct dentry
2589                 }
2590  
2591                 atomic_inc(&dentry->d_count);
2592 +               vx_dentry_inc(dentry);
2593                 found = dentry;
2594                 spin_unlock(&dentry->d_lock);
2595                 break;
2596 diff -NurpP --minimal linux-2.6.33/fs/devpts/inode.c linux-2.6.33-vs2.3.0.36.30/fs/devpts/inode.c
2597 --- linux-2.6.33/fs/devpts/inode.c      2010-02-25 11:52:05.000000000 +0100
2598 +++ linux-2.6.33-vs2.3.0.36.30/fs/devpts/inode.c        2010-02-25 12:02:16.000000000 +0100
2599 @@ -24,6 +24,7 @@
2600  #include <linux/parser.h>
2601  #include <linux/fsnotify.h>
2602  #include <linux/seq_file.h>
2603 +#include <linux/vs_base.h>
2604  
2605  #define DEVPTS_DEFAULT_MODE 0600
2606  /*
2607 @@ -35,6 +36,20 @@
2608  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2609  #define PTMX_MINOR     2
2610  
2611 +static int devpts_permission(struct inode *inode, int mask)
2612 +{
2613 +       int ret = -EACCES;
2614 +
2615 +       /* devpts is xid tagged */
2616 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2617 +               ret = generic_permission(inode, mask, NULL);
2618 +       return ret;
2619 +}
2620 +
2621 +static struct inode_operations devpts_file_inode_operations = {
2622 +       .permission     = devpts_permission,
2623 +};
2624 +
2625  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2626  static DEFINE_MUTEX(allocated_ptys_lock);
2627  
2628 @@ -262,6 +277,25 @@ static int devpts_show_options(struct se
2629         return 0;
2630  }
2631  
2632 +static int devpts_filter(struct dentry *de)
2633 +{
2634 +       /* devpts is xid tagged */
2635 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2636 +}
2637 +
2638 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2639 +{
2640 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2641 +}
2642 +
2643 +static struct file_operations devpts_dir_operations = {
2644 +       .open           = dcache_dir_open,
2645 +       .release        = dcache_dir_close,
2646 +       .llseek         = dcache_dir_lseek,
2647 +       .read           = generic_read_dir,
2648 +       .readdir        = devpts_readdir,
2649 +};
2650 +
2651  static const struct super_operations devpts_sops = {
2652         .statfs         = simple_statfs,
2653         .remount_fs     = devpts_remount,
2654 @@ -301,12 +335,15 @@ devpts_fill_super(struct super_block *s,
2655         inode = new_inode(s);
2656         if (!inode)
2657                 goto free_fsi;
2658 +
2659         inode->i_ino = 1;
2660         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2661         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2662         inode->i_op = &simple_dir_inode_operations;
2663 -       inode->i_fop = &simple_dir_operations;
2664 +       inode->i_fop = &devpts_dir_operations;
2665         inode->i_nlink = 2;
2666 +       /* devpts is xid tagged */
2667 +       inode->i_tag = (tag_t)vx_current_xid();
2668  
2669         s->s_root = d_alloc_root(inode);
2670         if (s->s_root)
2671 @@ -497,6 +534,9 @@ int devpts_pty_new(struct inode *ptmx_in
2672         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2673         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2674         init_special_inode(inode, S_IFCHR|opts->mode, device);
2675 +       /* devpts is xid tagged */
2676 +       inode->i_tag = (tag_t)vx_current_xid();
2677 +       inode->i_op = &devpts_file_inode_operations;
2678         inode->i_private = tty;
2679         tty->driver_data = inode;
2680  
2681 diff -NurpP --minimal linux-2.6.33/fs/exec.c linux-2.6.33-vs2.3.0.36.30/fs/exec.c
2682 --- linux-2.6.33/fs/exec.c      2010-02-25 11:52:05.000000000 +0100
2683 +++ linux-2.6.33-vs2.3.0.36.30/fs/exec.c        2010-02-25 12:02:16.000000000 +0100
2684 @@ -250,7 +250,9 @@ static int __bprm_mm_init(struct linux_b
2685         if (err)
2686                 goto err;
2687  
2688 -       mm->stack_vm = mm->total_vm = 1;
2689 +       mm->total_vm = 0;
2690 +       vx_vmpages_inc(mm);
2691 +       mm->stack_vm = 1;
2692         up_write(&mm->mmap_sem);
2693         bprm->p = vma->vm_end - sizeof(void *);
2694         return 0;
2695 @@ -1503,7 +1505,7 @@ static int format_corename(char *corenam
2696                         /* UNIX time of coredump */
2697                         case 't': {
2698                                 struct timeval tv;
2699 -                               do_gettimeofday(&tv);
2700 +                               vx_gettimeofday(&tv);
2701                                 rc = snprintf(out_ptr, out_end - out_ptr,
2702                                               "%lu", tv.tv_sec);
2703                                 if (rc > out_end - out_ptr)
2704 diff -NurpP --minimal linux-2.6.33/fs/ext2/balloc.c linux-2.6.33-vs2.3.0.36.30/fs/ext2/balloc.c
2705 --- linux-2.6.33/fs/ext2/balloc.c       2009-06-11 17:13:03.000000000 +0200
2706 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext2/balloc.c 2010-02-25 12:02:16.000000000 +0100
2707 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2708                         start = 0;
2709                 end = EXT2_BLOCKS_PER_GROUP(sb);
2710         }
2711 -
2712         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2713  
2714  repeat:
2715 diff -NurpP --minimal linux-2.6.33/fs/ext2/ext2.h linux-2.6.33-vs2.3.0.36.30/fs/ext2/ext2.h
2716 --- linux-2.6.33/fs/ext2/ext2.h 2010-02-25 11:52:05.000000000 +0100
2717 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext2/ext2.h   2010-02-25 12:02:16.000000000 +0100
2718 @@ -131,6 +131,7 @@ extern int ext2_fiemap(struct inode *ino
2719  int __ext2_write_begin(struct file *file, struct address_space *mapping,
2720                 loff_t pos, unsigned len, unsigned flags,
2721                 struct page **pagep, void **fsdata);
2722 +extern int ext2_sync_flags(struct inode *, int, int);
2723  
2724  /* ioctl.c */
2725  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2726 diff -NurpP --minimal linux-2.6.33/fs/ext2/file.c linux-2.6.33-vs2.3.0.36.30/fs/ext2/file.c
2727 --- linux-2.6.33/fs/ext2/file.c 2010-02-25 11:52:05.000000000 +0100
2728 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext2/file.c   2010-02-25 12:02:16.000000000 +0100
2729 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2730         .setattr        = ext2_setattr,
2731         .check_acl      = ext2_check_acl,
2732         .fiemap         = ext2_fiemap,
2733 +       .sync_flags     = ext2_sync_flags,
2734  };
2735 diff -NurpP --minimal linux-2.6.33/fs/ext2/ialloc.c linux-2.6.33-vs2.3.0.36.30/fs/ext2/ialloc.c
2736 --- linux-2.6.33/fs/ext2/ialloc.c       2009-06-11 17:13:03.000000000 +0200
2737 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext2/ialloc.c 2010-02-25 12:02:16.000000000 +0100
2738 @@ -17,6 +17,7 @@
2739  #include <linux/backing-dev.h>
2740  #include <linux/buffer_head.h>
2741  #include <linux/random.h>
2742 +#include <linux/vs_tag.h>
2743  #include "ext2.h"
2744  #include "xattr.h"
2745  #include "acl.h"
2746 @@ -560,6 +561,7 @@ got:
2747         } else
2748                 inode->i_gid = current_fsgid();
2749         inode->i_mode = mode;
2750 +       inode->i_tag = dx_current_fstag(sb);
2751  
2752         inode->i_ino = ino;
2753         inode->i_blocks = 0;
2754 diff -NurpP --minimal linux-2.6.33/fs/ext2/inode.c linux-2.6.33-vs2.3.0.36.30/fs/ext2/inode.c
2755 --- linux-2.6.33/fs/ext2/inode.c        2010-02-25 11:52:05.000000000 +0100
2756 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext2/inode.c  2010-02-25 12:02:16.000000000 +0100
2757 @@ -33,6 +33,7 @@
2758  #include <linux/mpage.h>
2759  #include <linux/fiemap.h>
2760  #include <linux/namei.h>
2761 +#include <linux/vs_tag.h>
2762  #include "ext2.h"
2763  #include "acl.h"
2764  #include "xip.h"
2765 @@ -1042,7 +1043,7 @@ void ext2_truncate(struct inode *inode)
2766                 return;
2767         if (ext2_inode_is_fast_symlink(inode))
2768                 return;
2769 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2770 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2771                 return;
2772  
2773         blocksize = inode->i_sb->s_blocksize;
2774 @@ -1180,36 +1181,61 @@ void ext2_set_inode_flags(struct inode *
2775  {
2776         unsigned int flags = EXT2_I(inode)->i_flags;
2777  
2778 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2779 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2780 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2781 +
2782 +
2783 +       if (flags & EXT2_IMMUTABLE_FL)
2784 +               inode->i_flags |= S_IMMUTABLE;
2785 +       if (flags & EXT2_IXUNLINK_FL)
2786 +               inode->i_flags |= S_IXUNLINK;
2787 +
2788         if (flags & EXT2_SYNC_FL)
2789                 inode->i_flags |= S_SYNC;
2790         if (flags & EXT2_APPEND_FL)
2791                 inode->i_flags |= S_APPEND;
2792 -       if (flags & EXT2_IMMUTABLE_FL)
2793 -               inode->i_flags |= S_IMMUTABLE;
2794         if (flags & EXT2_NOATIME_FL)
2795                 inode->i_flags |= S_NOATIME;
2796         if (flags & EXT2_DIRSYNC_FL)
2797                 inode->i_flags |= S_DIRSYNC;
2798 +
2799 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2800 +
2801 +       if (flags & EXT2_BARRIER_FL)
2802 +               inode->i_vflags |= V_BARRIER;
2803 +       if (flags & EXT2_COW_FL)
2804 +               inode->i_vflags |= V_COW;
2805  }
2806  
2807  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2808  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2809  {
2810         unsigned int flags = ei->vfs_inode.i_flags;
2811 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2812 +
2813 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2814 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2815 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2816 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2817 +
2818 +       if (flags & S_IMMUTABLE)
2819 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2820 +       if (flags & S_IXUNLINK)
2821 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2822  
2823 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2824 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2825         if (flags & S_SYNC)
2826                 ei->i_flags |= EXT2_SYNC_FL;
2827         if (flags & S_APPEND)
2828                 ei->i_flags |= EXT2_APPEND_FL;
2829 -       if (flags & S_IMMUTABLE)
2830 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2831         if (flags & S_NOATIME)
2832                 ei->i_flags |= EXT2_NOATIME_FL;
2833         if (flags & S_DIRSYNC)
2834                 ei->i_flags |= EXT2_DIRSYNC_FL;
2835 +
2836 +       if (vflags & V_BARRIER)
2837 +               ei->i_flags |= EXT2_BARRIER_FL;
2838 +       if (vflags & V_COW)
2839 +               ei->i_flags |= EXT2_COW_FL;
2840  }
2841  
2842  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2843 @@ -1219,6 +1245,8 @@ struct inode *ext2_iget (struct super_bl
2844         struct ext2_inode *raw_inode;
2845         struct inode *inode;
2846         long ret = -EIO;
2847 +       uid_t uid;
2848 +       gid_t gid;
2849         int n;
2850  
2851         inode = iget_locked(sb, ino);
2852 @@ -1237,12 +1265,17 @@ struct inode *ext2_iget (struct super_bl
2853         }
2854  
2855         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2856 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2857 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2858 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2859 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2860         if (!(test_opt (inode->i_sb, NO_UID32))) {
2861 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2862 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2863 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2864 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2865         }
2866 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2867 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2868 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2869 +               le16_to_cpu(raw_inode->i_raw_tag));
2870 +
2871         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2872         inode->i_size = le32_to_cpu(raw_inode->i_size);
2873         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2874 @@ -1340,8 +1373,8 @@ int ext2_write_inode(struct inode *inode
2875         struct ext2_inode_info *ei = EXT2_I(inode);
2876         struct super_block *sb = inode->i_sb;
2877         ino_t ino = inode->i_ino;
2878 -       uid_t uid = inode->i_uid;
2879 -       gid_t gid = inode->i_gid;
2880 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2881 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2882         struct buffer_head * bh;
2883         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2884         int n;
2885 @@ -1377,6 +1410,9 @@ int ext2_write_inode(struct inode *inode
2886                 raw_inode->i_uid_high = 0;
2887                 raw_inode->i_gid_high = 0;
2888         }
2889 +#ifdef CONFIG_TAGGING_INTERN
2890 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2891 +#endif
2892         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2893         raw_inode->i_size = cpu_to_le32(inode->i_size);
2894         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2895 @@ -1458,7 +1494,8 @@ int ext2_setattr(struct dentry *dentry, 
2896         if (error)
2897                 return error;
2898         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2899 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2900 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2901 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2902                 error = vfs_dq_transfer(inode, iattr) ? -EDQUOT : 0;
2903                 if (error)
2904                         return error;
2905 diff -NurpP --minimal linux-2.6.33/fs/ext2/ioctl.c linux-2.6.33-vs2.3.0.36.30/fs/ext2/ioctl.c
2906 --- linux-2.6.33/fs/ext2/ioctl.c        2009-09-10 15:26:21.000000000 +0200
2907 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext2/ioctl.c  2010-02-25 12:02:16.000000000 +0100
2908 @@ -17,6 +17,16 @@
2909  #include <asm/uaccess.h>
2910  
2911  
2912 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2913 +{
2914 +       inode->i_flags = flags;
2915 +       inode->i_vflags = vflags;
2916 +       ext2_get_inode_flags(EXT2_I(inode));
2917 +       inode->i_ctime = CURRENT_TIME_SEC;
2918 +       mark_inode_dirty(inode);
2919 +       return 0;
2920 +}
2921 +
2922  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2923  {
2924         struct inode *inode = filp->f_dentry->d_inode;
2925 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2926  
2927                 flags = ext2_mask_flags(inode->i_mode, flags);
2928  
2929 +               if (IS_BARRIER(inode)) {
2930 +                       vxwprintk_task(1, "messing with the barrier.");
2931 +                       return -EACCES;
2932 +               }
2933 +
2934                 mutex_lock(&inode->i_mutex);
2935                 /* Is it quota file? Do not allow user to mess with it */
2936                 if (IS_NOQUOTA(inode)) {
2937 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2938                  *
2939                  * This test looks nicer. Thanks to Pauline Middelink
2940                  */
2941 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2942 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2943 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2944 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2945                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2946                                 mutex_unlock(&inode->i_mutex);
2947                                 ret = -EPERM;
2948 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2949                         }
2950                 }
2951  
2952 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2953 +               flags &= EXT2_FL_USER_MODIFIABLE;
2954                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2955                 ei->i_flags = flags;
2956                 mutex_unlock(&inode->i_mutex);
2957 diff -NurpP --minimal linux-2.6.33/fs/ext2/namei.c linux-2.6.33-vs2.3.0.36.30/fs/ext2/namei.c
2958 --- linux-2.6.33/fs/ext2/namei.c        2009-12-03 20:02:51.000000000 +0100
2959 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext2/namei.c  2010-02-25 12:02:16.000000000 +0100
2960 @@ -31,6 +31,7 @@
2961   */
2962  
2963  #include <linux/pagemap.h>
2964 +#include <linux/vs_tag.h>
2965  #include "ext2.h"
2966  #include "xattr.h"
2967  #include "acl.h"
2968 @@ -74,6 +75,7 @@ static struct dentry *ext2_lookup(struct
2969                                 return ERR_PTR(-EIO);
2970                         } else {
2971                                 return ERR_CAST(inode);
2972 +               dx_propagate_tag(nd, inode);
2973                         }
2974                 }
2975         }
2976 @@ -401,6 +403,7 @@ const struct inode_operations ext2_dir_i
2977  #endif
2978         .setattr        = ext2_setattr,
2979         .check_acl      = ext2_check_acl,
2980 +       .sync_flags     = ext2_sync_flags,
2981  };
2982  
2983  const struct inode_operations ext2_special_inode_operations = {
2984 diff -NurpP --minimal linux-2.6.33/fs/ext2/super.c linux-2.6.33-vs2.3.0.36.30/fs/ext2/super.c
2985 --- linux-2.6.33/fs/ext2/super.c        2010-02-25 11:52:05.000000000 +0100
2986 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext2/super.c  2010-02-25 12:02:16.000000000 +0100
2987 @@ -382,7 +382,8 @@ enum {
2988         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2989         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2990         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2991 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2992 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2993 +       Opt_tag, Opt_notag, Opt_tagid
2994  };
2995  
2996  static const match_table_t tokens = {
2997 @@ -410,6 +411,9 @@ static const match_table_t tokens = {
2998         {Opt_acl, "acl"},
2999         {Opt_noacl, "noacl"},
3000         {Opt_xip, "xip"},
3001 +       {Opt_tag, "tag"},
3002 +       {Opt_notag, "notag"},
3003 +       {Opt_tagid, "tagid=%u"},
3004         {Opt_grpquota, "grpquota"},
3005         {Opt_ignore, "noquota"},
3006         {Opt_quota, "quota"},
3007 @@ -480,6 +484,20 @@ static int parse_options(char *options, 
3008                 case Opt_nouid32:
3009                         set_opt (sbi->s_mount_opt, NO_UID32);
3010                         break;
3011 +#ifndef CONFIG_TAGGING_NONE
3012 +               case Opt_tag:
3013 +                       set_opt (sbi->s_mount_opt, TAGGED);
3014 +                       break;
3015 +               case Opt_notag:
3016 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3017 +                       break;
3018 +#endif
3019 +#ifdef CONFIG_PROPAGATE
3020 +               case Opt_tagid:
3021 +                       /* use args[0] */
3022 +                       set_opt (sbi->s_mount_opt, TAGGED);
3023 +                       break;
3024 +#endif
3025                 case Opt_nocheck:
3026                         clear_opt (sbi->s_mount_opt, CHECK);
3027                         break;
3028 @@ -836,6 +854,8 @@ static int ext2_fill_super(struct super_
3029         if (!parse_options((char *) data, sb))
3030                 goto failed_mount;
3031  
3032 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3033 +               sb->s_flags |= MS_TAGGED;
3034         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3035                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3036                  MS_POSIXACL : 0);
3037 @@ -1229,6 +1249,14 @@ static int ext2_remount (struct super_bl
3038                 goto restore_opts;
3039         }
3040  
3041 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3042 +               !(sb->s_flags & MS_TAGGED)) {
3043 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3044 +                      sb->s_id);
3045 +               err = -EINVAL;
3046 +               goto restore_opts;
3047 +       }
3048 +
3049         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3050                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3051  
3052 diff -NurpP --minimal linux-2.6.33/fs/ext3/file.c linux-2.6.33-vs2.3.0.36.30/fs/ext3/file.c
3053 --- linux-2.6.33/fs/ext3/file.c 2009-12-03 20:02:51.000000000 +0100
3054 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext3/file.c   2010-02-25 12:02:16.000000000 +0100
3055 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
3056  #endif
3057         .check_acl      = ext3_check_acl,
3058         .fiemap         = ext3_fiemap,
3059 +       .sync_flags     = ext3_sync_flags,
3060  };
3061  
3062 diff -NurpP --minimal linux-2.6.33/fs/ext3/ialloc.c linux-2.6.33-vs2.3.0.36.30/fs/ext3/ialloc.c
3063 --- linux-2.6.33/fs/ext3/ialloc.c       2009-09-10 15:26:21.000000000 +0200
3064 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext3/ialloc.c 2010-02-25 12:02:16.000000000 +0100
3065 @@ -23,6 +23,7 @@
3066  #include <linux/buffer_head.h>
3067  #include <linux/random.h>
3068  #include <linux/bitops.h>
3069 +#include <linux/vs_tag.h>
3070  
3071  #include <asm/byteorder.h>
3072  
3073 @@ -548,6 +549,7 @@ got:
3074         } else
3075                 inode->i_gid = current_fsgid();
3076         inode->i_mode = mode;
3077 +       inode->i_tag = dx_current_fstag(sb);
3078  
3079         inode->i_ino = ino;
3080         /* This is the optimal IO size (for stat), not the fs block size */
3081 diff -NurpP --minimal linux-2.6.33/fs/ext3/inode.c linux-2.6.33-vs2.3.0.36.30/fs/ext3/inode.c
3082 --- linux-2.6.33/fs/ext3/inode.c        2010-02-25 11:52:05.000000000 +0100
3083 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext3/inode.c  2010-02-25 12:02:16.000000000 +0100
3084 @@ -38,6 +38,7 @@
3085  #include <linux/bio.h>
3086  #include <linux/fiemap.h>
3087  #include <linux/namei.h>
3088 +#include <linux/vs_tag.h>
3089  #include "xattr.h"
3090  #include "acl.h"
3091  
3092 @@ -2343,7 +2344,7 @@ static void ext3_free_branches(handle_t 
3093  
3094  int ext3_can_truncate(struct inode *inode)
3095  {
3096 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3097 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3098                 return 0;
3099         if (S_ISREG(inode->i_mode))
3100                 return 1;
3101 @@ -2728,36 +2729,60 @@ void ext3_set_inode_flags(struct inode *
3102  {
3103         unsigned int flags = EXT3_I(inode)->i_flags;
3104  
3105 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3106 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3107 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3108 +
3109 +       if (flags & EXT3_IMMUTABLE_FL)
3110 +               inode->i_flags |= S_IMMUTABLE;
3111 +       if (flags & EXT3_IXUNLINK_FL)
3112 +               inode->i_flags |= S_IXUNLINK;
3113 +
3114         if (flags & EXT3_SYNC_FL)
3115                 inode->i_flags |= S_SYNC;
3116         if (flags & EXT3_APPEND_FL)
3117                 inode->i_flags |= S_APPEND;
3118 -       if (flags & EXT3_IMMUTABLE_FL)
3119 -               inode->i_flags |= S_IMMUTABLE;
3120         if (flags & EXT3_NOATIME_FL)
3121                 inode->i_flags |= S_NOATIME;
3122         if (flags & EXT3_DIRSYNC_FL)
3123                 inode->i_flags |= S_DIRSYNC;
3124 +
3125 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3126 +
3127 +       if (flags & EXT3_BARRIER_FL)
3128 +               inode->i_vflags |= V_BARRIER;
3129 +       if (flags & EXT3_COW_FL)
3130 +               inode->i_vflags |= V_COW;
3131  }
3132  
3133  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3134  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3135  {
3136         unsigned int flags = ei->vfs_inode.i_flags;
3137 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3138 +
3139 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3140 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3141 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3142 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3143 +
3144 +       if (flags & S_IMMUTABLE)
3145 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3146 +       if (flags & S_IXUNLINK)
3147 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3148  
3149 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3150 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3151         if (flags & S_SYNC)
3152                 ei->i_flags |= EXT3_SYNC_FL;
3153         if (flags & S_APPEND)
3154                 ei->i_flags |= EXT3_APPEND_FL;
3155 -       if (flags & S_IMMUTABLE)
3156 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3157         if (flags & S_NOATIME)
3158                 ei->i_flags |= EXT3_NOATIME_FL;
3159         if (flags & S_DIRSYNC)
3160                 ei->i_flags |= EXT3_DIRSYNC_FL;
3161 +
3162 +       if (vflags & V_BARRIER)
3163 +               ei->i_flags |= EXT3_BARRIER_FL;
3164 +       if (vflags & V_COW)
3165 +               ei->i_flags |= EXT3_COW_FL;
3166  }
3167  
3168  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3169 @@ -2771,6 +2796,8 @@ struct inode *ext3_iget(struct super_blo
3170         transaction_t *transaction;
3171         long ret;
3172         int block;
3173 +       uid_t uid;
3174 +       gid_t gid;
3175  
3176         inode = iget_locked(sb, ino);
3177         if (!inode)
3178 @@ -2787,12 +2814,17 @@ struct inode *ext3_iget(struct super_blo
3179         bh = iloc.bh;
3180         raw_inode = ext3_raw_inode(&iloc);
3181         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3182 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3183 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3184 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3185 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3186         if(!(test_opt (inode->i_sb, NO_UID32))) {
3187 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3188 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3189 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3190 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3191         }
3192 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3193 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3194 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3195 +               le16_to_cpu(raw_inode->i_raw_tag));
3196 +
3197         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3198         inode->i_size = le32_to_cpu(raw_inode->i_size);
3199         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3200 @@ -2947,6 +2979,8 @@ static int ext3_do_update_inode(handle_t
3201         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3202         struct ext3_inode_info *ei = EXT3_I(inode);
3203         struct buffer_head *bh = iloc->bh;
3204 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3205 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3206         int err = 0, rc, block;
3207  
3208  again:
3209 @@ -2961,29 +2995,32 @@ again:
3210         ext3_get_inode_flags(ei);
3211         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3212         if(!(test_opt(inode->i_sb, NO_UID32))) {
3213 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3214 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3215 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3216 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3217  /*
3218   * Fix up interoperability with old kernels. Otherwise, old inodes get
3219   * re-used with the upper 16 bits of the uid/gid intact
3220   */
3221                 if(!ei->i_dtime) {
3222                         raw_inode->i_uid_high =
3223 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3224 +                               cpu_to_le16(high_16_bits(uid));
3225                         raw_inode->i_gid_high =
3226 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3227 +                               cpu_to_le16(high_16_bits(gid));
3228                 } else {
3229                         raw_inode->i_uid_high = 0;
3230                         raw_inode->i_gid_high = 0;
3231                 }
3232         } else {
3233                 raw_inode->i_uid_low =
3234 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3235 +                       cpu_to_le16(fs_high2lowuid(uid));
3236                 raw_inode->i_gid_low =
3237 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3238 +                       cpu_to_le16(fs_high2lowgid(gid));
3239                 raw_inode->i_uid_high = 0;
3240                 raw_inode->i_gid_high = 0;
3241         }
3242 +#ifdef CONFIG_TAGGING_INTERN
3243 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3244 +#endif
3245         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3246         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3247         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3248 @@ -3141,7 +3178,8 @@ int ext3_setattr(struct dentry *dentry, 
3249                 return error;
3250  
3251         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3252 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3253 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3254 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3255                 handle_t *handle;
3256  
3257                 /* (user+group)*(old+new) structure, inode write (sb,
3258 @@ -3163,6 +3201,8 @@ int ext3_setattr(struct dentry *dentry, 
3259                         inode->i_uid = attr->ia_uid;
3260                 if (attr->ia_valid & ATTR_GID)
3261                         inode->i_gid = attr->ia_gid;
3262 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3263 +                       inode->i_tag = attr->ia_tag;
3264                 error = ext3_mark_inode_dirty(handle, inode);
3265                 ext3_journal_stop(handle);
3266         }
3267 diff -NurpP --minimal linux-2.6.33/fs/ext3/ioctl.c linux-2.6.33-vs2.3.0.36.30/fs/ext3/ioctl.c
3268 --- linux-2.6.33/fs/ext3/ioctl.c        2009-06-11 17:13:03.000000000 +0200
3269 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext3/ioctl.c  2010-02-25 12:02:16.000000000 +0100
3270 @@ -8,6 +8,7 @@
3271   */
3272  
3273  #include <linux/fs.h>
3274 +#include <linux/mount.h>
3275  #include <linux/jbd.h>
3276  #include <linux/capability.h>
3277  #include <linux/ext3_fs.h>
3278 @@ -17,6 +18,34 @@
3279  #include <linux/compat.h>
3280  #include <asm/uaccess.h>
3281  
3282 +
3283 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3284 +{
3285 +       handle_t *handle = NULL;
3286 +       struct ext3_iloc iloc;
3287 +       int err;
3288 +
3289 +       handle = ext3_journal_start(inode, 1);
3290 +       if (IS_ERR(handle))
3291 +               return PTR_ERR(handle);
3292 +
3293 +       if (IS_SYNC(inode))
3294 +               handle->h_sync = 1;
3295 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3296 +       if (err)
3297 +               goto flags_err;
3298 +
3299 +       inode->i_flags = flags;
3300 +       inode->i_vflags = vflags;
3301 +       ext3_get_inode_flags(EXT3_I(inode));
3302 +       inode->i_ctime = CURRENT_TIME_SEC;
3303 +
3304 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3305 +flags_err:
3306 +       ext3_journal_stop(handle);
3307 +       return err;
3308 +}
3309 +
3310  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3311  {
3312         struct inode *inode = filp->f_dentry->d_inode;
3313 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3314  
3315                 flags = ext3_mask_flags(inode->i_mode, flags);
3316  
3317 +               if (IS_BARRIER(inode)) {
3318 +                       vxwprintk_task(1, "messing with the barrier.");
3319 +                       return -EACCES;
3320 +               }
3321 +
3322                 mutex_lock(&inode->i_mutex);
3323  
3324                 /* Is it quota file? Do not allow user to mess with it */
3325 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3326                  *
3327                  * This test looks nicer. Thanks to Pauline Middelink
3328                  */
3329 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3330 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3331 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3332 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3333                         if (!capable(CAP_LINUX_IMMUTABLE))
3334                                 goto flags_out;
3335                 }
3336 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3337                 if (err)
3338                         goto flags_err;
3339  
3340 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3341 +               flags &= EXT3_FL_USER_MODIFIABLE;
3342                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3343                 ei->i_flags = flags;
3344  
3345 diff -NurpP --minimal linux-2.6.33/fs/ext3/namei.c linux-2.6.33-vs2.3.0.36.30/fs/ext3/namei.c
3346 --- linux-2.6.33/fs/ext3/namei.c        2010-02-25 11:52:05.000000000 +0100
3347 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext3/namei.c  2010-02-25 12:02:16.000000000 +0100
3348 @@ -36,6 +36,7 @@
3349  #include <linux/quotaops.h>
3350  #include <linux/buffer_head.h>
3351  #include <linux/bio.h>
3352 +#include <linux/vs_tag.h>
3353  
3354  #include "namei.h"
3355  #include "xattr.h"
3356 @@ -912,6 +913,7 @@ restart:
3357                                 if (bh)
3358                                         ll_rw_block(READ_META, 1, &bh);
3359                         }
3360 +               dx_propagate_tag(nd, inode);
3361                 }
3362                 if ((bh = bh_use[ra_ptr++]) == NULL)
3363                         goto next;
3364 @@ -2448,6 +2450,7 @@ const struct inode_operations ext3_dir_i
3365         .removexattr    = generic_removexattr,
3366  #endif
3367         .check_acl      = ext3_check_acl,
3368 +       .sync_flags     = ext3_sync_flags,
3369  };
3370  
3371  const struct inode_operations ext3_special_inode_operations = {
3372 diff -NurpP --minimal linux-2.6.33/fs/ext3/super.c linux-2.6.33-vs2.3.0.36.30/fs/ext3/super.c
3373 --- linux-2.6.33/fs/ext3/super.c        2010-02-25 11:52:05.000000000 +0100
3374 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext3/super.c  2010-02-25 13:29:21.000000000 +0100
3375 @@ -817,7 +817,7 @@ enum {
3376         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3377         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3378         Opt_noquota, Opt_ignore, Opt_barrier, Opt_err, Opt_resize,
3379 -       Opt_usrquota, Opt_grpquota
3380 +       Opt_usrquota, Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3381  };
3382  
3383  static const match_table_t tokens = {
3384 @@ -872,6 +872,9 @@ static const match_table_t tokens = {
3385         {Opt_usrquota, "usrquota"},
3386         {Opt_barrier, "barrier=%u"},
3387         {Opt_resize, "resize"},
3388 +       {Opt_tag, "tag"},
3389 +       {Opt_notag, "notag"},
3390 +       {Opt_tagid, "tagid=%u"},
3391         {Opt_err, NULL},
3392  };
3393  
3394 @@ -964,6 +967,20 @@ static int parse_options (char *options,
3395                 case Opt_nouid32:
3396                         set_opt (sbi->s_mount_opt, NO_UID32);
3397                         break;
3398 +#ifndef CONFIG_TAGGING_NONE
3399 +               case Opt_tag:
3400 +                       set_opt (sbi->s_mount_opt, TAGGED);
3401 +                       break;
3402 +               case Opt_notag:
3403 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3404 +                       break;
3405 +#endif
3406 +#ifdef CONFIG_PROPAGATE
3407 +               case Opt_tagid:
3408 +                       /* use args[0] */
3409 +                       set_opt (sbi->s_mount_opt, TAGGED);
3410 +                       break;
3411 +#endif
3412                 case Opt_nocheck:
3413                         clear_opt (sbi->s_mount_opt, CHECK);
3414                         break;
3415 @@ -1693,6 +1710,9 @@ static int ext3_fill_super (struct super
3416                             NULL, 0))
3417                 goto failed_mount;
3418  
3419 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3420 +               sb->s_flags |= MS_TAGGED;
3421 +
3422         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3423                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3424  
3425 @@ -2564,6 +2584,14 @@ static int ext3_remount (struct super_bl
3426         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3427                 ext3_abort(sb, __func__, "Abort forced by user");
3428  
3429 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3430 +               !(sb->s_flags & MS_TAGGED)) {
3431 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3432 +                       sb->s_id);
3433 +               err = -EINVAL;
3434 +               goto restore_opts;
3435 +       }
3436 +
3437         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3438                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3439  
3440 diff -NurpP --minimal linux-2.6.33/fs/ext4/ext4.h linux-2.6.33-vs2.3.0.36.30/fs/ext4/ext4.h
3441 --- linux-2.6.33/fs/ext4/ext4.h 2010-02-25 11:52:05.000000000 +0100
3442 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext4/ext4.h   2010-02-25 12:02:16.000000000 +0100
3443 @@ -284,8 +284,12 @@ struct flex_groups {
3444  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
3445  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
3446  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3447 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3448  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3449  
3450 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3451 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3452 +
3453  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3454  #define EXT4_FL_USER_MODIFIABLE                0x000B80FF /* User modifiable flags */
3455  
3456 @@ -472,7 +476,8 @@ struct ext4_inode {
3457                         __le16  l_i_file_acl_high;
3458                         __le16  l_i_uid_high;   /* these 2 fields */
3459                         __le16  l_i_gid_high;   /* were reserved2[0] */
3460 -                       __u32   l_i_reserved2;
3461 +                       __le16  l_i_tag;        /* Context Tag */
3462 +                       __u16   l_i_reserved2;
3463                 } linux2;
3464                 struct {
3465                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3466 @@ -586,6 +591,7 @@ do {                                                                               \
3467  #define i_gid_low      i_gid
3468  #define i_uid_high     osd2.linux2.l_i_uid_high
3469  #define i_gid_high     osd2.linux2.l_i_gid_high
3470 +#define i_raw_tag      osd2.linux2.l_i_tag
3471  #define i_reserved2    osd2.linux2.l_i_reserved2
3472  
3473  #elif defined(__GNU__)
3474 @@ -760,6 +766,7 @@ struct ext4_inode_info {
3475  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3476  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3477  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3478 +#define EXT4_MOUNT_TAGGED              0x400000 /* Enable Context Tags */
3479  #define EXT4_MOUNT_JOURNAL_CHECKSUM    0x800000 /* Journal checksums */
3480  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
3481  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3482 @@ -1750,6 +1757,7 @@ extern int ext4_get_blocks(handle_t *han
3483                            struct buffer_head *bh, int flags);
3484  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3485                         __u64 start, __u64 len);
3486 +extern int ext4_sync_flags(struct inode *, int, int);
3487  /* move_extent.c */
3488  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3489                              __u64 start_orig, __u64 start_donor,
3490 diff -NurpP --minimal linux-2.6.33/fs/ext4/file.c linux-2.6.33-vs2.3.0.36.30/fs/ext4/file.c
3491 --- linux-2.6.33/fs/ext4/file.c 2009-12-03 20:02:51.000000000 +0100
3492 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext4/file.c   2010-02-25 12:02:16.000000000 +0100
3493 @@ -161,5 +161,6 @@ const struct inode_operations ext4_file_
3494         .check_acl      = ext4_check_acl,
3495         .fallocate      = ext4_fallocate,
3496         .fiemap         = ext4_fiemap,
3497 +       .sync_flags     = ext4_sync_flags,
3498  };
3499  
3500 diff -NurpP --minimal linux-2.6.33/fs/ext4/ialloc.c linux-2.6.33-vs2.3.0.36.30/fs/ext4/ialloc.c
3501 --- linux-2.6.33/fs/ext4/ialloc.c       2009-12-03 20:02:51.000000000 +0100
3502 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext4/ialloc.c 2010-02-25 12:02:16.000000000 +0100
3503 @@ -22,6 +22,7 @@
3504  #include <linux/random.h>
3505  #include <linux/bitops.h>
3506  #include <linux/blkdev.h>
3507 +#include <linux/vs_tag.h>
3508  #include <asm/byteorder.h>
3509  
3510  #include "ext4.h"
3511 @@ -995,6 +996,7 @@ got:
3512         } else
3513                 inode->i_gid = current_fsgid();
3514         inode->i_mode = mode;
3515 +       inode->i_tag = dx_current_fstag(sb);
3516  
3517         inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb);
3518         /* This is the optimal IO size (for stat), not the fs block size */
3519 diff -NurpP --minimal linux-2.6.33/fs/ext4/inode.c linux-2.6.33-vs2.3.0.36.30/fs/ext4/inode.c
3520 --- linux-2.6.33/fs/ext4/inode.c        2010-02-25 11:52:05.000000000 +0100
3521 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext4/inode.c  2010-02-25 12:02:16.000000000 +0100
3522 @@ -38,6 +38,7 @@
3523  #include <linux/uio.h>
3524  #include <linux/bio.h>
3525  #include <linux/workqueue.h>
3526 +#include <linux/vs_tag.h>
3527  
3528  #include "ext4_jbd2.h"
3529  #include "xattr.h"
3530 @@ -4376,7 +4377,7 @@ static void ext4_free_branches(handle_t 
3531  
3532  int ext4_can_truncate(struct inode *inode)
3533  {
3534 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3535 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3536                 return 0;
3537         if (S_ISREG(inode->i_mode))
3538                 return 1;
3539 @@ -4727,36 +4728,60 @@ void ext4_set_inode_flags(struct inode *
3540  {
3541         unsigned int flags = EXT4_I(inode)->i_flags;
3542  
3543 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3544 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3545 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3546 +
3547 +       if (flags & EXT4_IMMUTABLE_FL)
3548 +               inode->i_flags |= S_IMMUTABLE;
3549 +       if (flags & EXT4_IXUNLINK_FL)
3550 +               inode->i_flags |= S_IXUNLINK;
3551 +
3552         if (flags & EXT4_SYNC_FL)
3553                 inode->i_flags |= S_SYNC;
3554         if (flags & EXT4_APPEND_FL)
3555                 inode->i_flags |= S_APPEND;
3556 -       if (flags & EXT4_IMMUTABLE_FL)
3557 -               inode->i_flags |= S_IMMUTABLE;
3558         if (flags & EXT4_NOATIME_FL)
3559                 inode->i_flags |= S_NOATIME;
3560         if (flags & EXT4_DIRSYNC_FL)
3561                 inode->i_flags |= S_DIRSYNC;
3562 +
3563 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3564 +
3565 +       if (flags & EXT4_BARRIER_FL)
3566 +               inode->i_vflags |= V_BARRIER;
3567 +       if (flags & EXT4_COW_FL)
3568 +               inode->i_vflags |= V_COW;
3569  }
3570  
3571  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3572  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3573  {
3574         unsigned int flags = ei->vfs_inode.i_flags;
3575 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3576 +
3577 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3578 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3579 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3580 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3581 +
3582 +       if (flags & S_IMMUTABLE)
3583 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3584 +       if (flags & S_IXUNLINK)
3585 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3586  
3587 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3588 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3589         if (flags & S_SYNC)
3590                 ei->i_flags |= EXT4_SYNC_FL;
3591         if (flags & S_APPEND)
3592                 ei->i_flags |= EXT4_APPEND_FL;
3593 -       if (flags & S_IMMUTABLE)
3594 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3595         if (flags & S_NOATIME)
3596                 ei->i_flags |= EXT4_NOATIME_FL;
3597         if (flags & S_DIRSYNC)
3598                 ei->i_flags |= EXT4_DIRSYNC_FL;
3599 +
3600 +       if (vflags & V_BARRIER)
3601 +               ei->i_flags |= EXT4_BARRIER_FL;
3602 +       if (vflags & V_COW)
3603 +               ei->i_flags |= EXT4_COW_FL;
3604  }
3605  
3606  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3607 @@ -4791,6 +4816,8 @@ struct inode *ext4_iget(struct super_blo
3608         journal_t *journal = EXT4_SB(sb)->s_journal;
3609         long ret;
3610         int block;
3611 +       uid_t uid;
3612 +       gid_t gid;
3613  
3614         inode = iget_locked(sb, ino);
3615         if (!inode)
3616 @@ -4806,12 +4833,16 @@ struct inode *ext4_iget(struct super_blo
3617                 goto bad_inode;
3618         raw_inode = ext4_raw_inode(&iloc);
3619         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3620 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3621 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3622 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3623 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3624         if (!(test_opt(inode->i_sb, NO_UID32))) {
3625 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3626 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3627 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3628 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3629         }
3630 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3631 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3632 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3633 +               le16_to_cpu(raw_inode->i_raw_tag));
3634         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3635  
3636         ei->i_state = 0;
3637 @@ -5033,6 +5064,8 @@ static int ext4_do_update_inode(handle_t
3638         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3639         struct ext4_inode_info *ei = EXT4_I(inode);
3640         struct buffer_head *bh = iloc->bh;
3641 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3642 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3643         int err = 0, rc, block;
3644  
3645         /* For fields not not tracking in the in-memory inode,
3646 @@ -5043,29 +5076,32 @@ static int ext4_do_update_inode(handle_t
3647         ext4_get_inode_flags(ei);
3648         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3649         if (!(test_opt(inode->i_sb, NO_UID32))) {
3650 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3651 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3652 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3653 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3654  /*
3655   * Fix up interoperability with old kernels. Otherwise, old inodes get
3656   * re-used with the upper 16 bits of the uid/gid intact
3657   */
3658                 if (!ei->i_dtime) {
3659                         raw_inode->i_uid_high =
3660 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3661 +                               cpu_to_le16(high_16_bits(uid));
3662                         raw_inode->i_gid_high =
3663 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3664 +                               cpu_to_le16(high_16_bits(gid));
3665                 } else {
3666                         raw_inode->i_uid_high = 0;
3667                         raw_inode->i_gid_high = 0;
3668                 }
3669         } else {
3670                 raw_inode->i_uid_low =
3671 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3672 +                       cpu_to_le16(fs_high2lowuid(uid));
3673                 raw_inode->i_gid_low =
3674 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3675 +                       cpu_to_le16(fs_high2lowgid(gid));
3676                 raw_inode->i_uid_high = 0;
3677                 raw_inode->i_gid_high = 0;
3678         }
3679 +#ifdef CONFIG_TAGGING_INTERN
3680 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3681 +#endif
3682         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3683  
3684         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3685 @@ -5250,7 +5286,8 @@ int ext4_setattr(struct dentry *dentry, 
3686                 return error;
3687  
3688         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3689 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3690 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3691 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3692                 handle_t *handle;
3693  
3694                 /* (user+group)*(old+new) structure, inode write (sb,
3695 @@ -5272,6 +5309,8 @@ int ext4_setattr(struct dentry *dentry, 
3696                         inode->i_uid = attr->ia_uid;
3697                 if (attr->ia_valid & ATTR_GID)
3698                         inode->i_gid = attr->ia_gid;
3699 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3700 +                       inode->i_tag = attr->ia_tag;
3701                 error = ext4_mark_inode_dirty(handle, inode);
3702                 ext4_journal_stop(handle);
3703         }
3704 diff -NurpP --minimal linux-2.6.33/fs/ext4/ioctl.c linux-2.6.33-vs2.3.0.36.30/fs/ext4/ioctl.c
3705 --- linux-2.6.33/fs/ext4/ioctl.c        2010-02-25 11:52:05.000000000 +0100
3706 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext4/ioctl.c  2010-02-25 12:02:16.000000000 +0100
3707 @@ -14,10 +14,39 @@
3708  #include <linux/compat.h>
3709  #include <linux/mount.h>
3710  #include <linux/file.h>
3711 +#include <linux/vs_tag.h>
3712  #include <asm/uaccess.h>
3713  #include "ext4_jbd2.h"
3714  #include "ext4.h"
3715  
3716 +
3717 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3718 +{
3719 +       handle_t *handle = NULL;
3720 +       struct ext4_iloc iloc;
3721 +       int err;
3722 +
3723 +       handle = ext4_journal_start(inode, 1);
3724 +       if (IS_ERR(handle))
3725 +               return PTR_ERR(handle);
3726 +
3727 +       if (IS_SYNC(inode))
3728 +               ext4_handle_sync(handle);
3729 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3730 +       if (err)
3731 +               goto flags_err;
3732 +
3733 +       inode->i_flags = flags;
3734 +       inode->i_vflags = vflags;
3735 +       ext4_get_inode_flags(EXT4_I(inode));
3736 +       inode->i_ctime = ext4_current_time(inode);
3737 +
3738 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3739 +flags_err:
3740 +       ext4_journal_stop(handle);
3741 +       return err;
3742 +}
3743 +
3744  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3745  {
3746         struct inode *inode = filp->f_dentry->d_inode;
3747 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3748  
3749                 flags = ext4_mask_flags(inode->i_mode, flags);
3750  
3751 +               if (IS_BARRIER(inode)) {
3752 +                       vxwprintk_task(1, "messing with the barrier.");
3753 +                       return -EACCES;
3754 +               }
3755 +
3756                 err = -EPERM;
3757                 mutex_lock(&inode->i_mutex);
3758                 /* Is it quota file? Do not allow user to mess with it */
3759 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3760                  *
3761                  * This test looks nicer. Thanks to Pauline Middelink
3762                  */
3763 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3764 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3765 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3766 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3767                         if (!capable(CAP_LINUX_IMMUTABLE))
3768                                 goto flags_out;
3769                 }
3770 diff -NurpP --minimal linux-2.6.33/fs/ext4/namei.c linux-2.6.33-vs2.3.0.36.30/fs/ext4/namei.c
3771 --- linux-2.6.33/fs/ext4/namei.c        2010-02-25 11:52:05.000000000 +0100
3772 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext4/namei.c  2010-02-25 12:02:16.000000000 +0100
3773 @@ -34,6 +34,7 @@
3774  #include <linux/quotaops.h>
3775  #include <linux/buffer_head.h>
3776  #include <linux/bio.h>
3777 +#include <linux/vs_tag.h>
3778  #include "ext4.h"
3779  #include "ext4_jbd2.h"
3780  
3781 @@ -941,6 +942,7 @@ restart:
3782                                 if (bh)
3783                                         ll_rw_block(READ_META, 1, &bh);
3784                         }
3785 +               dx_propagate_tag(nd, inode);
3786                 }
3787                 if ((bh = bh_use[ra_ptr++]) == NULL)
3788                         goto next;
3789 @@ -2533,6 +2535,7 @@ const struct inode_operations ext4_dir_i
3790  #endif
3791         .check_acl      = ext4_check_acl,
3792         .fiemap         = ext4_fiemap,
3793 +       .sync_flags     = ext4_sync_flags,
3794  };
3795  
3796  const struct inode_operations ext4_special_inode_operations = {
3797 diff -NurpP --minimal linux-2.6.33/fs/ext4/super.c linux-2.6.33-vs2.3.0.36.30/fs/ext4/super.c
3798 --- linux-2.6.33/fs/ext4/super.c        2010-02-25 11:52:05.000000000 +0100
3799 +++ linux-2.6.33-vs2.3.0.36.30/fs/ext4/super.c  2010-02-25 12:02:16.000000000 +0100
3800 @@ -1110,6 +1110,7 @@ enum {
3801         Opt_block_validity, Opt_noblock_validity,
3802         Opt_inode_readahead_blks, Opt_journal_ioprio,
3803         Opt_discard, Opt_nodiscard,
3804 +       Opt_tag, Opt_notag, Opt_tagid
3805  };
3806  
3807  static const match_table_t tokens = {
3808 @@ -1178,6 +1179,9 @@ static const match_table_t tokens = {
3809         {Opt_noauto_da_alloc, "noauto_da_alloc"},
3810         {Opt_discard, "discard"},
3811         {Opt_nodiscard, "nodiscard"},
3812 +       {Opt_tag, "tag"},
3813 +       {Opt_notag, "notag"},
3814 +       {Opt_tagid, "tagid=%u"},
3815         {Opt_err, NULL},
3816  };
3817  
3818 @@ -1275,6 +1279,20 @@ static int parse_options(char *options, 
3819                 case Opt_nouid32:
3820                         set_opt(sbi->s_mount_opt, NO_UID32);
3821                         break;
3822 +#ifndef CONFIG_TAGGING_NONE
3823 +               case Opt_tag:
3824 +                       set_opt (sbi->s_mount_opt, TAGGED);
3825 +                       break;
3826 +               case Opt_notag:
3827 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3828 +                       break;
3829 +#endif
3830 +#ifdef CONFIG_PROPAGATE
3831 +               case Opt_tagid:
3832 +                       /* use args[0] */
3833 +                       set_opt (sbi->s_mount_opt, TAGGED);
3834 +                       break;
3835 +#endif
3836                 case Opt_debug:
3837                         set_opt(sbi->s_mount_opt, DEBUG);
3838                         break;
3839 @@ -2476,6 +2494,9 @@ static int ext4_fill_super(struct super_
3840                            &journal_ioprio, NULL, 0))
3841                 goto failed_mount;
3842  
3843 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3844 +               sb->s_flags |= MS_TAGGED;
3845 +
3846         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3847                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3848  
3849 @@ -3513,6 +3534,14 @@ static int ext4_remount(struct super_blo
3850         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3851                 ext4_abort(sb, __func__, "Abort forced by user");
3852  
3853 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3854 +               !(sb->s_flags & MS_TAGGED)) {
3855 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3856 +                       sb->s_id);
3857 +               err = -EINVAL;
3858 +               goto restore_opts;
3859 +       }
3860 +
3861         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3862                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3863  
3864 diff -NurpP --minimal linux-2.6.33/fs/fcntl.c linux-2.6.33-vs2.3.0.36.30/fs/fcntl.c
3865 --- linux-2.6.33/fs/fcntl.c     2010-02-25 11:52:05.000000000 +0100
3866 +++ linux-2.6.33-vs2.3.0.36.30/fs/fcntl.c       2010-02-25 12:02:16.000000000 +0100
3867 @@ -19,6 +19,7 @@
3868  #include <linux/signal.h>
3869  #include <linux/rcupdate.h>
3870  #include <linux/pid_namespace.h>
3871 +#include <linux/vs_limit.h>
3872  
3873  #include <asm/poll.h>
3874  #include <asm/siginfo.h>
3875 @@ -102,6 +103,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3876  
3877         if (tofree)
3878                 filp_close(tofree, files);
3879 +       else
3880 +               vx_openfd_inc(newfd);   /* fd was unused */
3881  
3882         return newfd;
3883  
3884 @@ -426,6 +429,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3885         filp = fget(fd);
3886         if (!filp)
3887                 goto out;
3888 +       if (!vx_files_avail(1))
3889 +               goto out;
3890  
3891         err = security_file_fcntl(filp, cmd, arg);
3892         if (err) {
3893 diff -NurpP --minimal linux-2.6.33/fs/file.c linux-2.6.33-vs2.3.0.36.30/fs/file.c
3894 --- linux-2.6.33/fs/file.c      2009-12-03 20:02:51.000000000 +0100
3895 +++ linux-2.6.33-vs2.3.0.36.30/fs/file.c        2010-02-25 12:02:16.000000000 +0100
3896 @@ -20,6 +20,7 @@
3897  #include <linux/spinlock.h>
3898  #include <linux/rcupdate.h>
3899  #include <linux/workqueue.h>
3900 +#include <linux/vs_limit.h>
3901  
3902  struct fdtable_defer {
3903         spinlock_t lock;
3904 @@ -368,6 +369,8 @@ struct files_struct *dup_fd(struct files
3905                 struct file *f = *old_fds++;
3906                 if (f) {
3907                         get_file(f);
3908 +                       /* TODO: sum it first for check and performance */
3909 +                       vx_openfd_inc(open_files - i);
3910                 } else {
3911                         /*
3912                          * The fd may be claimed in the fd bitmap but not yet
3913 @@ -476,6 +479,7 @@ repeat:
3914         else
3915                 FD_CLR(fd, fdt->close_on_exec);
3916         error = fd;
3917 +       vx_openfd_inc(fd);
3918  #if 1
3919         /* Sanity check */
3920         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3921 diff -NurpP --minimal linux-2.6.33/fs/file_table.c linux-2.6.33-vs2.3.0.36.30/fs/file_table.c
3922 --- linux-2.6.33/fs/file_table.c        2010-02-25 11:52:05.000000000 +0100
3923 +++ linux-2.6.33-vs2.3.0.36.30/fs/file_table.c  2010-02-25 13:28:39.000000000 +0100
3924 @@ -22,6 +22,8 @@
3925  #include <linux/sysctl.h>
3926  #include <linux/percpu_counter.h>
3927  #include <linux/ima.h>
3928 +#include <linux/vs_limit.h>
3929 +#include <linux/vs_context.h>
3930  
3931  #include <asm/atomic.h>
3932  
3933 @@ -133,6 +135,8 @@ struct file *get_empty_filp(void)
3934         spin_lock_init(&f->f_lock);
3935         eventpoll_init_file(f);
3936         /* f->f_version: 0 */
3937 +       f->f_xid = vx_current_xid();
3938 +       vx_files_inc(f);
3939         return f;
3940  
3941  over:
3942 @@ -258,6 +262,8 @@ void __fput(struct file *file)
3943                 cdev_put(inode->i_cdev);
3944         fops_put(file->f_op);
3945         put_pid(file->f_owner.pid);
3946 +       vx_files_dec(file);
3947 +       file->f_xid = 0;
3948         file_kill(file);
3949         if (file->f_mode & FMODE_WRITE)
3950                 drop_file_write_access(file);
3951 @@ -325,6 +331,8 @@ void put_filp(struct file *file)
3952  {
3953         if (atomic_long_dec_and_test(&file->f_count)) {
3954                 security_file_free(file);
3955 +               vx_files_dec(file);
3956 +               file->f_xid = 0;
3957                 file_kill(file);
3958                 file_free(file);
3959         }
3960 diff -NurpP --minimal linux-2.6.33/fs/fs_struct.c linux-2.6.33-vs2.3.0.36.30/fs/fs_struct.c
3961 --- linux-2.6.33/fs/fs_struct.c 2009-06-11 17:13:04.000000000 +0200
3962 +++ linux-2.6.33-vs2.3.0.36.30/fs/fs_struct.c   2010-02-25 12:02:16.000000000 +0100
3963 @@ -4,6 +4,7 @@
3964  #include <linux/path.h>
3965  #include <linux/slab.h>
3966  #include <linux/fs_struct.h>
3967 +#include <linux/vserver/global.h>
3968  
3969  /*
3970   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
3971 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
3972  {
3973         path_put(&fs->root);
3974         path_put(&fs->pwd);
3975 +       atomic_dec(&vs_global_fs);
3976         kmem_cache_free(fs_cachep, fs);
3977  }
3978  
3979 @@ -112,6 +114,7 @@ struct fs_struct *copy_fs_struct(struct 
3980                 fs->pwd = old->pwd;
3981                 path_get(&old->pwd);
3982                 read_unlock(&old->lock);
3983 +               atomic_inc(&vs_global_fs);
3984         }
3985         return fs;
3986  }
3987 diff -NurpP --minimal linux-2.6.33/fs/gfs2/file.c linux-2.6.33-vs2.3.0.36.30/fs/gfs2/file.c
3988 --- linux-2.6.33/fs/gfs2/file.c 2010-02-25 11:52:05.000000000 +0100
3989 +++ linux-2.6.33-vs2.3.0.36.30/fs/gfs2/file.c   2010-02-25 12:02:16.000000000 +0100
3990 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
3991         [7] = GFS2_DIF_NOATIME,
3992         [12] = GFS2_DIF_EXHASH,
3993         [14] = GFS2_DIF_INHERIT_JDATA,
3994 +       [27] = GFS2_DIF_IXUNLINK,
3995 +       [26] = GFS2_DIF_BARRIER,
3996 +       [29] = GFS2_DIF_COW,
3997  };
3998  
3999  static const u32 gfs2_to_fsflags[32] = {
4000 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
4001         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4002         [gfs2fl_ExHash] = FS_INDEX_FL,
4003         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4004 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4005 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4006 +       [gfs2fl_Cow] = FS_COW_FL,
4007  };
4008  
4009  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4010 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
4011  {
4012         struct gfs2_inode *ip = GFS2_I(inode);
4013         unsigned int flags = inode->i_flags;
4014 +       unsigned int vflags = inode->i_vflags;
4015 +
4016 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4017 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4018  
4019 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4020         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4021                 flags |= S_IMMUTABLE;
4022 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4023 +               flags |= S_IXUNLINK;
4024 +
4025         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4026                 flags |= S_APPEND;
4027         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4028 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
4029         if (ip->i_diskflags & GFS2_DIF_SYNC)
4030                 flags |= S_SYNC;
4031         inode->i_flags = flags;
4032 +
4033 +       vflags &= ~(V_BARRIER | V_COW);
4034 +
4035 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4036 +               vflags |= V_BARRIER;
4037 +       if (ip->i_diskflags & GFS2_DIF_COW)
4038 +               vflags |= V_COW;
4039 +       inode->i_vflags = vflags;
4040 +}
4041 +
4042 +void gfs2_get_inode_flags(struct inode *inode)
4043 +{
4044 +       struct gfs2_inode *ip = GFS2_I(inode);
4045 +       unsigned int flags = inode->i_flags;
4046 +       unsigned int vflags = inode->i_vflags;
4047 +
4048 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4049 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4050 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4051 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4052 +
4053 +       if (flags & S_IMMUTABLE)
4054 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4055 +       if (flags & S_IXUNLINK)
4056 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4057 +
4058 +       if (flags & S_APPEND)
4059 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4060 +       if (flags & S_NOATIME)
4061 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4062 +       if (flags & S_SYNC)
4063 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4064 +
4065 +       if (vflags & V_BARRIER)
4066 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4067 +       if (vflags & V_COW)
4068 +               ip->i_diskflags |= GFS2_DIF_COW;
4069  }
4070  
4071  /* Flags that can be set by user space */
4072 @@ -286,6 +335,37 @@ static int gfs2_set_flags(struct file *f
4073         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4074  }
4075  
4076 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4077 +{
4078 +       struct gfs2_inode *ip = GFS2_I(inode);
4079 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4080 +       struct buffer_head *bh;
4081 +       struct gfs2_holder gh;
4082 +       int error;
4083 +
4084 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4085 +       if (error)
4086 +               return error;
4087 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4088 +       if (error)
4089 +               goto out;
4090 +       error = gfs2_meta_inode_buffer(ip, &bh);
4091 +       if (error)
4092 +               goto out_trans_end;
4093 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4094 +       inode->i_flags = flags;
4095 +       inode->i_vflags = vflags;
4096 +       gfs2_get_inode_flags(inode);
4097 +       gfs2_dinode_out(ip, bh->b_data);
4098 +       brelse(bh);
4099 +       gfs2_set_aops(inode);
4100 +out_trans_end:
4101 +       gfs2_trans_end(sdp);
4102 +out:
4103 +       gfs2_glock_dq_uninit(&gh);
4104 +       return error;
4105 +}
4106 +
4107  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4108  {
4109         switch(cmd) {
4110 diff -NurpP --minimal linux-2.6.33/fs/gfs2/inode.h linux-2.6.33-vs2.3.0.36.30/fs/gfs2/inode.h
4111 --- linux-2.6.33/fs/gfs2/inode.h        2009-09-10 15:26:22.000000000 +0200
4112 +++ linux-2.6.33-vs2.3.0.36.30/fs/gfs2/inode.h  2010-02-25 12:02:16.000000000 +0100
4113 @@ -109,6 +109,7 @@ extern const struct file_operations gfs2
4114  extern const struct file_operations gfs2_dir_fops_nolock;
4115  
4116  extern void gfs2_set_inode_flags(struct inode *inode);
4117 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4118   
4119  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4120  extern const struct file_operations gfs2_file_fops;
4121 diff -NurpP --minimal linux-2.6.33/fs/gfs2/ops_inode.c linux-2.6.33-vs2.3.0.36.30/fs/gfs2/ops_inode.c
4122 --- linux-2.6.33/fs/gfs2/ops_inode.c    2010-02-25 11:52:05.000000000 +0100
4123 +++ linux-2.6.33-vs2.3.0.36.30/fs/gfs2/ops_inode.c      2010-02-25 12:02:16.000000000 +0100
4124 @@ -1403,6 +1403,7 @@ const struct inode_operations gfs2_file_
4125         .listxattr = gfs2_listxattr,
4126         .removexattr = gfs2_removexattr,
4127         .fiemap = gfs2_fiemap,
4128 +       .sync_flags = gfs2_sync_flags,
4129  };
4130  
4131  const struct inode_operations gfs2_dir_iops = {
4132 @@ -1423,6 +1424,7 @@ const struct inode_operations gfs2_dir_i
4133         .listxattr = gfs2_listxattr,
4134         .removexattr = gfs2_removexattr,
4135         .fiemap = gfs2_fiemap,
4136 +       .sync_flags = gfs2_sync_flags,
4137  };
4138  
4139  const struct inode_operations gfs2_symlink_iops = {
4140 diff -NurpP --minimal linux-2.6.33/fs/hfsplus/ioctl.c linux-2.6.33-vs2.3.0.36.30/fs/hfsplus/ioctl.c
4141 --- linux-2.6.33/fs/hfsplus/ioctl.c     2008-12-25 00:26:37.000000000 +0100
4142 +++ linux-2.6.33-vs2.3.0.36.30/fs/hfsplus/ioctl.c       2010-02-25 12:02:16.000000000 +0100
4143 @@ -17,6 +17,7 @@
4144  #include <linux/mount.h>
4145  #include <linux/sched.h>
4146  #include <linux/xattr.h>
4147 +#include <linux/mount.h>
4148  #include <asm/uaccess.h>
4149  #include "hfsplus_fs.h"
4150  
4151 diff -NurpP --minimal linux-2.6.33/fs/inode.c linux-2.6.33-vs2.3.0.36.30/fs/inode.c
4152 --- linux-2.6.33/fs/inode.c     2010-02-25 11:52:05.000000000 +0100
4153 +++ linux-2.6.33-vs2.3.0.36.30/fs/inode.c       2010-02-25 12:02:16.000000000 +0100
4154 @@ -132,6 +132,9 @@ int inode_init_always(struct super_block
4155         struct address_space *const mapping = &inode->i_data;
4156  
4157         inode->i_sb = sb;
4158 +
4159 +       /* essential because of inode slab reuse */
4160 +       inode->i_tag = 0;
4161         inode->i_blkbits = sb->s_blocksize_bits;
4162         inode->i_flags = 0;
4163         atomic_set(&inode->i_count, 1);
4164 @@ -152,6 +155,7 @@ int inode_init_always(struct super_block
4165         inode->i_bdev = NULL;
4166         inode->i_cdev = NULL;
4167         inode->i_rdev = 0;
4168 +       inode->i_mdev = 0;
4169         inode->dirtied_when = 0;
4170  
4171         if (security_inode_alloc(inode))
4172 @@ -297,6 +301,8 @@ void __iget(struct inode *inode)
4173         inodes_stat.nr_unused--;
4174  }
4175  
4176 +EXPORT_SYMBOL_GPL(__iget);
4177 +
4178  /**
4179   * clear_inode - clear an inode
4180   * @inode: inode to clear
4181 @@ -1601,9 +1607,11 @@ void init_special_inode(struct inode *in
4182         if (S_ISCHR(mode)) {
4183                 inode->i_fop = &def_chr_fops;
4184                 inode->i_rdev = rdev;
4185 +               inode->i_mdev = rdev;
4186         } else if (S_ISBLK(mode)) {
4187                 inode->i_fop = &def_blk_fops;
4188                 inode->i_rdev = rdev;
4189 +               inode->i_mdev = rdev;
4190         } else if (S_ISFIFO(mode))
4191                 inode->i_fop = &def_fifo_fops;
4192         else if (S_ISSOCK(mode))
4193 diff -NurpP --minimal linux-2.6.33/fs/ioctl.c linux-2.6.33-vs2.3.0.36.30/fs/ioctl.c
4194 --- linux-2.6.33/fs/ioctl.c     2009-12-03 20:02:52.000000000 +0100
4195 +++ linux-2.6.33-vs2.3.0.36.30/fs/ioctl.c       2010-02-25 12:02:16.000000000 +0100
4196 @@ -16,6 +16,9 @@
4197  #include <linux/writeback.h>
4198  #include <linux/buffer_head.h>
4199  #include <linux/falloc.h>
4200 +#include <linux/proc_fs.h>
4201 +#include <linux/vserver/inode.h>
4202 +#include <linux/vs_tag.h>
4203  
4204  #include <asm/ioctls.h>
4205  
4206 diff -NurpP --minimal linux-2.6.33/fs/ioprio.c linux-2.6.33-vs2.3.0.36.30/fs/ioprio.c
4207 --- linux-2.6.33/fs/ioprio.c    2009-03-24 14:22:26.000000000 +0100
4208 +++ linux-2.6.33-vs2.3.0.36.30/fs/ioprio.c      2010-02-25 12:02:16.000000000 +0100
4209 @@ -26,6 +26,7 @@
4210  #include <linux/syscalls.h>
4211  #include <linux/security.h>
4212  #include <linux/pid_namespace.h>
4213 +#include <linux/vs_base.h>
4214  
4215  int set_task_ioprio(struct task_struct *task, int ioprio)
4216  {
4217 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4218                         else
4219                                 pgrp = find_vpid(who);
4220                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4221 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4222 +                                       continue;
4223                                 ret = set_task_ioprio(p, ioprio);
4224                                 if (ret)
4225                                         break;
4226 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4227                         else
4228                                 pgrp = find_vpid(who);
4229                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4230 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4231 +                                       continue;
4232                                 tmpio = get_task_ioprio(p);
4233                                 if (tmpio < 0)
4234                                         continue;
4235 diff -NurpP --minimal linux-2.6.33/fs/jfs/acl.c linux-2.6.33-vs2.3.0.36.30/fs/jfs/acl.c
4236 --- linux-2.6.33/fs/jfs/acl.c   2009-12-03 20:02:52.000000000 +0100
4237 +++ linux-2.6.33-vs2.3.0.36.30/fs/jfs/acl.c     2010-02-25 12:02:16.000000000 +0100
4238 @@ -216,7 +216,8 @@ int jfs_setattr(struct dentry *dentry, s
4239                 return rc;
4240  
4241         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4242 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4243 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4244 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4245                 if (vfs_dq_transfer(inode, iattr))
4246                         return -EDQUOT;
4247         }
4248 diff -NurpP --minimal linux-2.6.33/fs/jfs/file.c linux-2.6.33-vs2.3.0.36.30/fs/jfs/file.c
4249 --- linux-2.6.33/fs/jfs/file.c  2009-12-03 20:02:52.000000000 +0100
4250 +++ linux-2.6.33-vs2.3.0.36.30/fs/jfs/file.c    2010-02-25 12:02:16.000000000 +0100
4251 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4252         .setattr        = jfs_setattr,
4253         .check_acl      = jfs_check_acl,
4254  #endif
4255 +       .sync_flags     = jfs_sync_flags,
4256  };
4257  
4258  const struct file_operations jfs_file_operations = {
4259 diff -NurpP --minimal linux-2.6.33/fs/jfs/ioctl.c linux-2.6.33-vs2.3.0.36.30/fs/jfs/ioctl.c
4260 --- linux-2.6.33/fs/jfs/ioctl.c 2008-12-25 00:26:37.000000000 +0100
4261 +++ linux-2.6.33-vs2.3.0.36.30/fs/jfs/ioctl.c   2010-02-25 12:02:16.000000000 +0100
4262 @@ -11,6 +11,7 @@
4263  #include <linux/mount.h>
4264  #include <linux/time.h>
4265  #include <linux/sched.h>
4266 +#include <linux/mount.h>
4267  #include <asm/current.h>
4268  #include <asm/uaccess.h>
4269  
4270 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4271  }
4272  
4273  
4274 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4275 +{
4276 +       inode->i_flags = flags;
4277 +       inode->i_vflags = vflags;
4278 +       jfs_get_inode_flags(JFS_IP(inode));
4279 +       inode->i_ctime = CURRENT_TIME_SEC;
4280 +       mark_inode_dirty(inode);
4281 +       return 0;
4282 +}
4283 +
4284  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4285  {
4286         struct inode *inode = filp->f_dentry->d_inode;
4287 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4288                 if (!S_ISDIR(inode->i_mode))
4289                         flags &= ~JFS_DIRSYNC_FL;
4290  
4291 +               if (IS_BARRIER(inode)) {
4292 +                       vxwprintk_task(1, "messing with the barrier.");
4293 +                       return -EACCES;
4294 +               }
4295 +
4296                 /* Is it quota file? Do not allow user to mess with it */
4297                 if (IS_NOQUOTA(inode)) {
4298                         err = -EPERM;
4299 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4300                  * the relevant capability.
4301                  */
4302                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4303 -                       ((flags ^ oldflags) &
4304 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4305 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4306 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4307                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4308                                 mutex_unlock(&inode->i_mutex);
4309                                 err = -EPERM;
4310 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4311                         }
4312                 }
4313  
4314 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4315 +               flags &= JFS_FL_USER_MODIFIABLE;
4316                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4317                 jfs_inode->mode2 = flags;
4318  
4319 diff -NurpP --minimal linux-2.6.33/fs/jfs/jfs_dinode.h linux-2.6.33-vs2.3.0.36.30/fs/jfs/jfs_dinode.h
4320 --- linux-2.6.33/fs/jfs/jfs_dinode.h    2008-12-25 00:26:37.000000000 +0100
4321 +++ linux-2.6.33-vs2.3.0.36.30/fs/jfs/jfs_dinode.h      2010-02-25 12:02:16.000000000 +0100
4322 @@ -161,9 +161,13 @@ struct dinode {
4323  
4324  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4325  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4326 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4327  
4328 -#define JFS_FL_USER_VISIBLE    0x03F80000
4329 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4330 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4331 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4332 +
4333 +#define JFS_FL_USER_VISIBLE    0x07F80000
4334 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4335  #define JFS_FL_INHERIT         0x03C80000
4336  
4337  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4338 diff -NurpP --minimal linux-2.6.33/fs/jfs/jfs_filsys.h linux-2.6.33-vs2.3.0.36.30/fs/jfs/jfs_filsys.h
4339 --- linux-2.6.33/fs/jfs/jfs_filsys.h    2008-12-25 00:26:37.000000000 +0100
4340 +++ linux-2.6.33-vs2.3.0.36.30/fs/jfs/jfs_filsys.h      2010-02-25 12:02:16.000000000 +0100
4341 @@ -263,6 +263,7 @@
4342  #define JFS_NAME_MAX   255
4343  #define JFS_PATH_MAX   BPSIZE
4344  
4345 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4346  
4347  /*
4348   *     file system state (superblock state)
4349 diff -NurpP --minimal linux-2.6.33/fs/jfs/jfs_imap.c linux-2.6.33-vs2.3.0.36.30/fs/jfs/jfs_imap.c
4350 --- linux-2.6.33/fs/jfs/jfs_imap.c      2009-09-10 15:26:22.000000000 +0200
4351 +++ linux-2.6.33-vs2.3.0.36.30/fs/jfs/jfs_imap.c        2010-02-25 12:02:16.000000000 +0100
4352 @@ -45,6 +45,7 @@
4353  #include <linux/buffer_head.h>
4354  #include <linux/pagemap.h>
4355  #include <linux/quotaops.h>
4356 +#include <linux/vs_tag.h>
4357  
4358  #include "jfs_incore.h"
4359  #include "jfs_inode.h"
4360 @@ -3059,6 +3060,8 @@ static int copy_from_dinode(struct dinod
4361  {
4362         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4363         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4364 +       uid_t uid;
4365 +       gid_t gid;
4366  
4367         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4368         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4369 @@ -3079,14 +3082,18 @@ static int copy_from_dinode(struct dinod
4370         }
4371         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4372  
4373 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4374 +       uid = le32_to_cpu(dip->di_uid);
4375 +       gid = le32_to_cpu(dip->di_gid);
4376 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4377 +
4378 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4379         if (sbi->uid == -1)
4380                 ip->i_uid = jfs_ip->saved_uid;
4381         else {
4382                 ip->i_uid = sbi->uid;
4383         }
4384  
4385 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4386 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4387         if (sbi->gid == -1)
4388                 ip->i_gid = jfs_ip->saved_gid;
4389         else {
4390 @@ -3151,14 +3158,12 @@ static void copy_to_dinode(struct dinode
4391         dip->di_size = cpu_to_le64(ip->i_size);
4392         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4393         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4394 -       if (sbi->uid == -1)
4395 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4396 -       else
4397 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4398 -       if (sbi->gid == -1)
4399 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4400 -       else
4401 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4402 +
4403 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4404 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4405 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4406 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4407 +
4408         jfs_get_inode_flags(jfs_ip);
4409         /*
4410          * mode2 is only needed for storing the higher order bits.
4411 diff -NurpP --minimal linux-2.6.33/fs/jfs/jfs_inode.c linux-2.6.33-vs2.3.0.36.30/fs/jfs/jfs_inode.c
4412 --- linux-2.6.33/fs/jfs/jfs_inode.c     2009-06-11 17:13:05.000000000 +0200
4413 +++ linux-2.6.33-vs2.3.0.36.30/fs/jfs/jfs_inode.c       2010-02-25 12:02:16.000000000 +0100
4414 @@ -18,6 +18,7 @@
4415  
4416  #include <linux/fs.h>
4417  #include <linux/quotaops.h>
4418 +#include <linux/vs_tag.h>
4419  #include "jfs_incore.h"
4420  #include "jfs_inode.h"
4421  #include "jfs_filsys.h"
4422 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4423  {
4424         unsigned int flags = JFS_IP(inode)->mode2;
4425  
4426 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4427 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4428 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4429 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4430  
4431         if (flags & JFS_IMMUTABLE_FL)
4432                 inode->i_flags |= S_IMMUTABLE;
4433 +       if (flags & JFS_IXUNLINK_FL)
4434 +               inode->i_flags |= S_IXUNLINK;
4435 +
4436 +       if (flags & JFS_SYNC_FL)
4437 +               inode->i_flags |= S_SYNC;
4438         if (flags & JFS_APPEND_FL)
4439                 inode->i_flags |= S_APPEND;
4440         if (flags & JFS_NOATIME_FL)
4441                 inode->i_flags |= S_NOATIME;
4442         if (flags & JFS_DIRSYNC_FL)
4443                 inode->i_flags |= S_DIRSYNC;
4444 -       if (flags & JFS_SYNC_FL)
4445 -               inode->i_flags |= S_SYNC;
4446 +
4447 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4448 +
4449 +       if (flags & JFS_BARRIER_FL)
4450 +               inode->i_vflags |= V_BARRIER;
4451 +       if (flags & JFS_COW_FL)
4452 +               inode->i_vflags |= V_COW;
4453  }
4454  
4455  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4456  {
4457         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4458 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4459 +
4460 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4461 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4462 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4463 +                          JFS_BARRIER_FL | JFS_COW_FL);
4464  
4465 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4466 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4467         if (flags & S_IMMUTABLE)
4468                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4469 +       if (flags & S_IXUNLINK)
4470 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4471 +
4472         if (flags & S_APPEND)
4473                 jfs_ip->mode2 |= JFS_APPEND_FL;
4474         if (flags & S_NOATIME)
4475 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4476                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4477         if (flags & S_SYNC)
4478                 jfs_ip->mode2 |= JFS_SYNC_FL;
4479 +
4480 +       if (vflags & V_BARRIER)
4481 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4482 +       if (vflags & V_COW)
4483 +               jfs_ip->mode2 |= JFS_COW_FL;
4484  }
4485  
4486  /*
4487 @@ -105,6 +128,7 @@ struct inode *ialloc(struct inode *paren
4488                         mode |= S_ISGID;
4489         } else
4490                 inode->i_gid = current_fsgid();
4491 +       inode->i_tag = dx_current_fstag(sb);
4492  
4493         /*
4494          * New inodes need to save sane values on disk when
4495 diff -NurpP --minimal linux-2.6.33/fs/jfs/jfs_inode.h linux-2.6.33-vs2.3.0.36.30/fs/jfs/jfs_inode.h
4496 --- linux-2.6.33/fs/jfs/jfs_inode.h     2009-06-11 17:13:05.000000000 +0200
4497 +++ linux-2.6.33-vs2.3.0.36.30/fs/jfs/jfs_inode.h       2010-02-25 12:02:16.000000000 +0100
4498 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4499  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4500         int fh_len, int fh_type);
4501  extern void jfs_set_inode_flags(struct inode *);
4502 +extern int jfs_sync_flags(struct inode *, int, int);
4503  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4504  
4505  extern const struct address_space_operations jfs_aops;
4506 diff -NurpP --minimal linux-2.6.33/fs/jfs/namei.c linux-2.6.33-vs2.3.0.36.30/fs/jfs/namei.c
4507 --- linux-2.6.33/fs/jfs/namei.c 2009-12-03 20:02:52.000000000 +0100
4508 +++ linux-2.6.33-vs2.3.0.36.30/fs/jfs/namei.c   2010-02-25 12:02:16.000000000 +0100
4509 @@ -21,6 +21,7 @@
4510  #include <linux/ctype.h>
4511  #include <linux/quotaops.h>
4512  #include <linux/exportfs.h>
4513 +#include <linux/vs_tag.h>
4514  #include "jfs_incore.h"
4515  #include "jfs_superblock.h"
4516  #include "jfs_inode.h"
4517 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4518                 return ERR_CAST(ip);
4519         }
4520  
4521 +       dx_propagate_tag(nd, ip);
4522         dentry = d_splice_alias(ip, dentry);
4523  
4524         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4525 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4526         .setattr        = jfs_setattr,
4527         .check_acl      = jfs_check_acl,
4528  #endif
4529 +       .sync_flags     = jfs_sync_flags,
4530  };
4531  
4532  const struct file_operations jfs_dir_operations = {
4533 diff -NurpP --minimal linux-2.6.33/fs/jfs/super.c linux-2.6.33-vs2.3.0.36.30/fs/jfs/super.c
4534 --- linux-2.6.33/fs/jfs/super.c 2010-02-25 11:52:05.000000000 +0100
4535 +++ linux-2.6.33-vs2.3.0.36.30/fs/jfs/super.c   2010-02-25 12:02:16.000000000 +0100
4536 @@ -192,7 +192,8 @@ static void jfs_put_super(struct super_b
4537  enum {
4538         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4539         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4540 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4541 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4542 +       Opt_tag, Opt_notag, Opt_tagid
4543  };
4544  
4545  static const match_table_t tokens = {
4546 @@ -202,6 +203,10 @@ static const match_table_t tokens = {
4547         {Opt_resize, "resize=%u"},
4548         {Opt_resize_nosize, "resize"},
4549         {Opt_errors, "errors=%s"},
4550 +       {Opt_tag, "tag"},
4551 +       {Opt_notag, "notag"},
4552 +       {Opt_tagid, "tagid=%u"},
4553 +       {Opt_tag, "tagxid"},
4554         {Opt_ignore, "noquota"},
4555         {Opt_ignore, "quota"},
4556         {Opt_usrquota, "usrquota"},
4557 @@ -336,6 +341,20 @@ static int parse_options(char *options, 
4558                         }
4559                         break;
4560                 }
4561 +#ifndef CONFIG_TAGGING_NONE
4562 +               case Opt_tag:
4563 +                       *flag |= JFS_TAGGED;
4564 +                       break;
4565 +               case Opt_notag:
4566 +                       *flag &= JFS_TAGGED;
4567 +                       break;
4568 +#endif
4569 +#ifdef CONFIG_PROPAGATE
4570 +               case Opt_tagid:
4571 +                       /* use args[0] */
4572 +                       *flag |= JFS_TAGGED;
4573 +                       break;
4574 +#endif
4575                 default:
4576                         printk("jfs: Unrecognized mount option \"%s\" "
4577                                         " or missing value\n", p);
4578 @@ -366,6 +385,12 @@ static int jfs_remount(struct super_bloc
4579         if (!parse_options(data, sb, &newLVSize, &flag)) {
4580                 return -EINVAL;
4581         }
4582 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4583 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4584 +                       sb->s_id);
4585 +               return -EINVAL;
4586 +       }
4587 +
4588         lock_kernel();
4589         if (newLVSize) {
4590                 if (sb->s_flags & MS_RDONLY) {
4591 @@ -449,6 +474,9 @@ static int jfs_fill_super(struct super_b
4592  #ifdef CONFIG_JFS_POSIX_ACL
4593         sb->s_flags |= MS_POSIXACL;
4594  #endif
4595 +       /* map mount option tagxid */
4596 +       if (sbi->flag & JFS_TAGGED)
4597 +               sb->s_flags |= MS_TAGGED;
4598  
4599         if (newLVSize) {
4600                 printk(KERN_ERR "resize option for remount only\n");
4601 diff -NurpP --minimal linux-2.6.33/fs/libfs.c linux-2.6.33-vs2.3.0.36.30/fs/libfs.c
4602 --- linux-2.6.33/fs/libfs.c     2010-02-25 11:52:05.000000000 +0100
4603 +++ linux-2.6.33-vs2.3.0.36.30/fs/libfs.c       2010-02-25 12:02:16.000000000 +0100
4604 @@ -127,7 +127,8 @@ static inline unsigned char dt_type(stru
4605   * both impossible due to the lock on directory.
4606   */
4607  
4608 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4609 +static inline int do_dcache_readdir_filter(struct file *filp,
4610 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4611  {
4612         struct dentry *dentry = filp->f_path.dentry;
4613         struct dentry *cursor = filp->private_data;
4614 @@ -160,6 +161,8 @@ int dcache_readdir(struct file * filp, v
4615                                 next = list_entry(p, struct dentry, d_u.d_child);
4616                                 if (d_unhashed(next) || !next->d_inode)
4617                                         continue;
4618 +                               if (filter && !filter(next))
4619 +                                       continue;
4620  
4621                                 spin_unlock(&dcache_lock);
4622                                 if (filldir(dirent, next->d_name.name, 
4623 @@ -178,6 +181,18 @@ int dcache_readdir(struct file * filp, v
4624         return 0;
4625  }
4626  
4627 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4628 +{
4629 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4630 +}
4631 +
4632 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4633 +       int (*filter)(struct dentry *))
4634 +{
4635 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4636 +}
4637 +
4638 +
4639  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4640  {
4641         return -EISDIR;
4642 @@ -841,6 +856,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4643  EXPORT_SYMBOL(dcache_dir_lseek);
4644  EXPORT_SYMBOL(dcache_dir_open);
4645  EXPORT_SYMBOL(dcache_readdir);
4646 +EXPORT_SYMBOL(dcache_readdir_filter);
4647  EXPORT_SYMBOL(generic_read_dir);
4648  EXPORT_SYMBOL(get_sb_pseudo);
4649  EXPORT_SYMBOL(simple_write_begin);
4650 diff -NurpP --minimal linux-2.6.33/fs/locks.c linux-2.6.33-vs2.3.0.36.30/fs/locks.c
4651 --- linux-2.6.33/fs/locks.c     2009-12-03 20:02:52.000000000 +0100
4652 +++ linux-2.6.33-vs2.3.0.36.30/fs/locks.c       2010-02-25 12:02:16.000000000 +0100
4653 @@ -127,6 +127,8 @@
4654  #include <linux/time.h>
4655  #include <linux/rcupdate.h>
4656  #include <linux/pid_namespace.h>
4657 +#include <linux/vs_base.h>
4658 +#include <linux/vs_limit.h>
4659  
4660  #include <asm/uaccess.h>
4661  
4662 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4663  /* Allocate an empty lock structure. */
4664  static struct file_lock *locks_alloc_lock(void)
4665  {
4666 +       if (!vx_locks_avail(1))
4667 +               return NULL;
4668         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4669  }
4670  
4671 @@ -174,6 +178,7 @@ static void locks_free_lock(struct file_
4672         BUG_ON(!list_empty(&fl->fl_block));
4673         BUG_ON(!list_empty(&fl->fl_link));
4674  
4675 +       vx_locks_dec(fl);
4676         locks_release_private(fl);
4677         kmem_cache_free(filelock_cache, fl);
4678  }
4679 @@ -194,6 +199,7 @@ void locks_init_lock(struct file_lock *f
4680         fl->fl_start = fl->fl_end = 0;
4681         fl->fl_ops = NULL;
4682         fl->fl_lmops = NULL;
4683 +       fl->fl_xid = -1;
4684  }
4685  
4686  EXPORT_SYMBOL(locks_init_lock);
4687 @@ -248,6 +254,7 @@ void locks_copy_lock(struct file_lock *n
4688         new->fl_file = fl->fl_file;
4689         new->fl_ops = fl->fl_ops;
4690         new->fl_lmops = fl->fl_lmops;
4691 +       new->fl_xid = fl->fl_xid;
4692  
4693         locks_copy_private(new, fl);
4694  }
4695 @@ -286,6 +293,11 @@ static int flock_make_lock(struct file *
4696         fl->fl_flags = FL_FLOCK;
4697         fl->fl_type = type;
4698         fl->fl_end = OFFSET_MAX;
4699 +
4700 +       vxd_assert(filp->f_xid == vx_current_xid(),
4701 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4702 +       fl->fl_xid = filp->f_xid;
4703 +       vx_locks_inc(fl);
4704         
4705         *lock = fl;
4706         return 0;
4707 @@ -451,6 +463,7 @@ static int lease_init(struct file *filp,
4708  
4709         fl->fl_owner = current->files;
4710         fl->fl_pid = current->tgid;
4711 +       fl->fl_xid = vx_current_xid();
4712  
4713         fl->fl_file = filp;
4714         fl->fl_flags = FL_LEASE;
4715 @@ -470,6 +483,11 @@ static struct file_lock *lease_alloc(str
4716         if (fl == NULL)
4717                 return ERR_PTR(error);
4718  
4719 +       fl->fl_xid = vx_current_xid();
4720 +       if (filp)
4721 +               vxd_assert(filp->f_xid == fl->fl_xid,
4722 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4723 +       vx_locks_inc(fl);
4724         error = lease_init(filp, type, fl);
4725         if (error) {
4726                 locks_free_lock(fl);
4727 @@ -770,6 +788,7 @@ static int flock_lock_file(struct file *
4728         if (found)
4729                 cond_resched();
4730  
4731 +       new_fl->fl_xid = -1;
4732  find_conflict:
4733         for_each_lock(inode, before) {
4734                 struct file_lock *fl = *before;
4735 @@ -790,6 +809,7 @@ find_conflict:
4736                 goto out;
4737         locks_copy_lock(new_fl, request);
4738         locks_insert_lock(before, new_fl);
4739 +       vx_locks_inc(new_fl);
4740         new_fl = NULL;
4741         error = 0;
4742  
4743 @@ -800,7 +820,8 @@ out:
4744         return error;
4745  }
4746  
4747 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4748 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4749 +       struct file_lock *conflock, xid_t xid)
4750  {
4751         struct file_lock *fl;
4752         struct file_lock *new_fl = NULL;
4753 @@ -810,6 +831,8 @@ static int __posix_lock_file(struct inod
4754         struct file_lock **before;
4755         int error, added = 0;
4756  
4757 +       vxd_assert(xid == vx_current_xid(),
4758 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4759         /*
4760          * We may need two file_lock structures for this operation,
4761          * so we get them in advance to avoid races.
4762 @@ -820,7 +843,11 @@ static int __posix_lock_file(struct inod
4763             (request->fl_type != F_UNLCK ||
4764              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4765                 new_fl = locks_alloc_lock();
4766 +               new_fl->fl_xid = xid;
4767 +               vx_locks_inc(new_fl);
4768                 new_fl2 = locks_alloc_lock();
4769 +               new_fl2->fl_xid = xid;
4770 +               vx_locks_inc(new_fl2);
4771         }
4772  
4773         lock_kernel();
4774 @@ -1019,7 +1046,8 @@ static int __posix_lock_file(struct inod
4775  int posix_lock_file(struct file *filp, struct file_lock *fl,
4776                         struct file_lock *conflock)
4777  {
4778 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4779 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4780 +               fl, conflock, filp->f_xid);
4781  }
4782  EXPORT_SYMBOL(posix_lock_file);
4783  
4784 @@ -1109,7 +1137,7 @@ int locks_mandatory_area(int read_write,
4785         fl.fl_end = offset + count - 1;
4786  
4787         for (;;) {
4788 -               error = __posix_lock_file(inode, &fl, NULL);
4789 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4790                 if (error != FILE_LOCK_DEFERRED)
4791                         break;
4792                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4793 @@ -1424,6 +1452,7 @@ int generic_setlease(struct file *filp, 
4794  
4795         locks_copy_lock(new_fl, lease);
4796         locks_insert_lock(before, new_fl);
4797 +       vx_locks_inc(new_fl);
4798  
4799         *flp = new_fl;
4800         return 0;
4801 @@ -1779,6 +1808,11 @@ int fcntl_setlk(unsigned int fd, struct 
4802         if (file_lock == NULL)
4803                 return -ENOLCK;
4804  
4805 +       vxd_assert(filp->f_xid == vx_current_xid(),
4806 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4807 +       file_lock->fl_xid = filp->f_xid;
4808 +       vx_locks_inc(file_lock);
4809 +
4810         /*
4811          * This might block, so we do it before checking the inode.
4812          */
4813 @@ -1897,6 +1931,11 @@ int fcntl_setlk64(unsigned int fd, struc
4814         if (file_lock == NULL)
4815                 return -ENOLCK;
4816  
4817 +       vxd_assert(filp->f_xid == vx_current_xid(),
4818 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4819 +       file_lock->fl_xid = filp->f_xid;
4820 +       vx_locks_inc(file_lock);
4821 +
4822         /*
4823          * This might block, so we do it before checking the inode.
4824          */
4825 @@ -2162,8 +2201,11 @@ static int locks_show(struct seq_file *f
4826  
4827         lock_get_status(f, fl, (long)f->private, "");
4828  
4829 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4830 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4831 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4832 +                       continue;
4833                 lock_get_status(f, bfl, (long)f->private, " ->");
4834 +       }
4835  
4836         f->private++;
4837         return 0;
4838 diff -NurpP --minimal linux-2.6.33/fs/namei.c linux-2.6.33-vs2.3.0.36.30/fs/namei.c
4839 --- linux-2.6.33/fs/namei.c     2010-02-25 11:52:05.000000000 +0100
4840 +++ linux-2.6.33-vs2.3.0.36.30/fs/namei.c       2010-02-25 15:31:15.000000000 +0100
4841 @@ -33,6 +33,14 @@
4842  #include <linux/fcntl.h>
4843  #include <linux/device_cgroup.h>
4844  #include <linux/fs_struct.h>
4845 +#include <linux/proc_fs.h>
4846 +#include <linux/vserver/inode.h>
4847 +#include <linux/vs_base.h>
4848 +#include <linux/vs_tag.h>
4849 +#include <linux/vs_cowbl.h>
4850 +#include <linux/vs_device.h>
4851 +#include <linux/vs_context.h>
4852 +#include <linux/pid_namespace.h>
4853  #include <asm/uaccess.h>
4854  
4855  #include "internal.h"
4856 @@ -167,6 +175,77 @@ void putname(const char *name)
4857  EXPORT_SYMBOL(putname);
4858  #endif
4859  
4860 +static inline int dx_barrier(const struct inode *inode)
4861 +{
4862 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4863 +               vxwprintk_task(1, "did hit the barrier.");
4864 +               return 1;
4865 +       }
4866 +       return 0;
4867 +}
4868 +
4869 +static int __dx_permission(const struct inode *inode, int mask)
4870 +{
4871 +       if (dx_barrier(inode))
4872 +               return -EACCES;
4873 +
4874 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4875 +               /* devpts is xid tagged */
4876 +               if (S_ISDIR(inode->i_mode) ||
4877 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4878 +                       return 0;
4879 +       }
4880 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4881 +               struct proc_dir_entry *de = PDE(inode);
4882 +
4883 +               if (de && !vx_hide_check(0, de->vx_flags))
4884 +                       goto out;
4885 +
4886 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4887 +                       struct pid *pid;
4888 +                       struct task_struct *tsk;
4889 +
4890 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4891 +                           vx_flags(VXF_STATE_SETUP, 0))
4892 +                               return 0;
4893 +
4894 +                       pid = PROC_I(inode)->pid;
4895 +                       if (!pid)
4896 +                               goto out;
4897 +
4898 +                       tsk = pid_task(pid, PIDTYPE_PID);
4899 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4900 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4901 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4902 +                               return 0;
4903 +               }
4904 +               else {
4905 +                       /* FIXME: Should we block some entries here? */
4906 +                       return 0;
4907 +               }
4908 +       }
4909 +       else {
4910 +               if (dx_notagcheck(inode->i_sb) ||
4911 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4912 +                            DX_IDENT))
4913 +                       return 0;
4914 +       }
4915 +
4916 +out:
4917 +       return -EACCES;
4918 +}
4919 +
4920 +int dx_permission(const struct inode *inode, int mask)
4921 +{
4922 +       int ret = __dx_permission(inode, mask);
4923 +       if (unlikely(ret)) {
4924 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4925 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4926 +                       inode->i_ino);
4927 +       }
4928 +       return ret;
4929 +}
4930 +
4931  /*
4932   * This does basic POSIX ACL permission checking
4933   */
4934 @@ -267,10 +346,14 @@ int inode_permission(struct inode *inode
4935                 /*
4936                  * Nobody gets write access to an immutable file.
4937                  */
4938 -               if (IS_IMMUTABLE(inode))
4939 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4940                         return -EACCES;
4941         }
4942  
4943 +       retval = dx_permission(inode, mask);
4944 +       if (retval)
4945 +               return retval;
4946 +
4947         if (inode->i_op->permission)
4948                 retval = inode->i_op->permission(inode, mask);
4949         else
4950 @@ -465,6 +548,9 @@ static int exec_permission(struct inode 
4951  {
4952         int ret;
4953  
4954 +       if (dx_barrier(inode))
4955 +               return -EACCES;
4956 +
4957         if (inode->i_op->permission) {
4958                 ret = inode->i_op->permission(inode, MAY_EXEC);
4959                 if (!ret)
4960 @@ -694,7 +780,8 @@ static __always_inline void follow_dotdo
4961  
4962                 if (nd->path.dentry == nd->root.dentry &&
4963                     nd->path.mnt == nd->root.mnt) {
4964 -                       break;
4965 +                       /* for sane '/' avoid follow_mount() */
4966 +                       return;
4967                 }
4968                 spin_lock(&dcache_lock);
4969                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4970 @@ -730,7 +817,7 @@ static int do_lookup(struct nameidata *n
4971  {
4972         struct vfsmount *mnt = nd->path.mnt;
4973         struct dentry *dentry, *parent;
4974 -       struct inode *dir;
4975 +       struct inode *dir, *inode;
4976         /*
4977          * See if the low-level filesystem might want
4978          * to use its own hash..
4979 @@ -746,12 +833,26 @@ static int do_lookup(struct nameidata *n
4980                 goto need_lookup;
4981         if (dentry->d_op && dentry->d_op->d_revalidate)
4982                 goto need_revalidate;
4983 +
4984 +       inode = dentry->d_inode;
4985 +       if (!inode)
4986 +               goto done;
4987 +
4988 +       if (__dx_permission(inode, MAY_ACCESS))
4989 +               goto hidden;
4990  done:
4991         path->mnt = mnt;
4992         path->dentry = dentry;
4993         __follow_mount(path);
4994         return 0;
4995  
4996 +hidden:
4997 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s/%.*s«.",
4998 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
4999 +               vxd_path(&nd->path), name->len, name->name);
5000 +       dput(dentry);
5001 +       return -ENOENT;
5002 +
5003  need_lookup:
5004         parent = nd->path.dentry;
5005         dir = parent->d_inode;
5006 @@ -1355,7 +1456,7 @@ static int may_delete(struct inode *dir,
5007         if (IS_APPEND(dir))
5008                 return -EPERM;
5009         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5010 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5011 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5012                 return -EPERM;
5013         if (isdir) {
5014                 if (!S_ISDIR(victim->d_inode->i_mode))
5015 @@ -1495,6 +1596,14 @@ int may_open(struct path *path, int acc_
5016                 break;
5017         }
5018  
5019 +#ifdef CONFIG_VSERVER_COWBL
5020 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5021 +               if (IS_COW_LINK(inode))
5022 +                       return -EMLINK;
5023 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5024 +               mark_inode_dirty(inode);
5025 +       }
5026 +#endif
5027         error = inode_permission(inode, acc_mode);
5028         if (error)
5029                 return error;
5030 @@ -1621,6 +1730,11 @@ struct file *do_filp_open(int dfd, const
5031         int flag = open_to_namei_flags(open_flag);
5032         int force_reval = 0;
5033  
5034 +#ifdef CONFIG_VSERVER_COWBL
5035 +       int rflag = flag;
5036 +       int rmode = mode;
5037 +restart:
5038 +#endif
5039         /*
5040          * O_SYNC is implemented as __O_SYNC|O_DSYNC.  As many places only
5041          * check for O_DSYNC if the need any syncing at all we enforce it's
5042 @@ -1799,6 +1913,25 @@ ok:
5043                         goto exit;
5044         }
5045         error = may_open(&nd.path, acc_mode, flag);
5046 +#ifdef CONFIG_VSERVER_COWBL
5047 +       if (error == -EMLINK) {
5048 +               struct dentry *dentry;
5049 +               dentry = cow_break_link(pathname);
5050 +               if (IS_ERR(dentry)) {
5051 +                       error = PTR_ERR(dentry);
5052 +                       goto exit_cow;
5053 +               }
5054 +               dput(dentry);
5055 +               if (will_truncate)
5056 +                       mnt_drop_write(nd.path.mnt);
5057 +               release_open_intent(&nd);
5058 +               path_put(&nd.path);
5059 +               flag = rflag;
5060 +               mode = rmode;
5061 +               goto restart;
5062 +       }
5063 +exit_cow:
5064 +#endif
5065         if (error) {
5066                 if (will_truncate)
5067                         mnt_drop_write(nd.path.mnt);
5068 @@ -1982,9 +2115,17 @@ int vfs_mknod(struct inode *dir, struct 
5069         if (error)
5070                 return error;
5071  
5072 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5073 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5074 +               goto okay;
5075 +
5076 +       if (!capable(CAP_MKNOD))
5077                 return -EPERM;
5078  
5079 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5080 +               return -EPERM;
5081 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5082 +               return -EPERM;
5083 +okay:
5084         if (!dir->i_op->mknod)
5085                 return -EPERM;
5086  
5087 @@ -2451,7 +2592,7 @@ int vfs_link(struct dentry *old_dentry, 
5088         /*
5089          * A link to an append-only or immutable file cannot be created.
5090          */
5091 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5092 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5093                 return -EPERM;
5094         if (!dir->i_op->link)
5095                 return -EPERM;
5096 @@ -2824,6 +2965,219 @@ int vfs_follow_link(struct nameidata *nd
5097         return __vfs_follow_link(nd, link);
5098  }
5099  
5100 +
5101 +#ifdef CONFIG_VSERVER_COWBL
5102 +
5103 +#include <linux/file.h>
5104 +
5105 +static inline
5106 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5107 +{
5108 +       loff_t ppos = 0;
5109 +
5110 +       return do_splice_direct(in, &ppos, out, len, 0);
5111 +}
5112 +
5113 +struct dentry *cow_break_link(const char *pathname)
5114 +{
5115 +       int ret, mode, pathlen, redo = 0;
5116 +       struct nameidata old_nd, dir_nd;
5117 +       struct path old_path, new_path;
5118 +       struct dentry *dir, *res = NULL;
5119 +       struct file *old_file;
5120 +       struct file *new_file;
5121 +       char *to, *path, pad='\251';
5122 +       loff_t size;
5123 +
5124 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5125 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5126 +       ret = -ENOMEM;
5127 +       if (!path)
5128 +               goto out;
5129 +
5130 +       /* old_nd will have refs to dentry and mnt */
5131 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5132 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5133 +       if (ret < 0)
5134 +               goto out_free_path;
5135 +
5136 +       old_path = old_nd.path;
5137 +       mode = old_path.dentry->d_inode->i_mode;
5138 +
5139 +       to = d_path(&old_path, path, PATH_MAX-2);
5140 +       pathlen = strlen(to);
5141 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5142 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5143 +               old_path.dentry->d_name.len);
5144 +
5145 +       to[pathlen + 1] = 0;
5146 +retry:
5147 +       to[pathlen] = pad--;
5148 +       ret = -EMLINK;
5149 +       if (pad <= '\240')
5150 +               goto out_rel_old;
5151 +
5152 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5153 +       /* dir_nd will have refs to dentry and mnt */
5154 +       ret = path_lookup(to,
5155 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5156 +       vxdprintk(VXD_CBIT(misc, 2),
5157 +               "path_lookup(new): %d", ret);
5158 +       if (ret < 0)
5159 +               goto retry;
5160 +
5161 +       /* this puppy downs the inode mutex */
5162 +       new_path.dentry = lookup_create(&dir_nd, 0);
5163 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5164 +               vxdprintk(VXD_CBIT(misc, 2),
5165 +                       "lookup_create(new): %p", new_path.dentry);
5166 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5167 +               path_put(&dir_nd.path);
5168 +               goto retry;
5169 +       }
5170 +       vxdprintk(VXD_CBIT(misc, 2),
5171 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5172 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5173 +               new_path.dentry->d_name.len);
5174 +       dir = dir_nd.path.dentry;
5175 +
5176 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5177 +       vxdprintk(VXD_CBIT(misc, 2),
5178 +               "vfs_create(new): %d", ret);
5179 +       if (ret == -EEXIST) {
5180 +               mutex_unlock(&dir->d_inode->i_mutex);
5181 +               dput(new_path.dentry);
5182 +               path_put(&dir_nd.path);
5183 +               goto retry;
5184 +       }
5185 +       else if (ret < 0)
5186 +               goto out_unlock_new;
5187 +
5188 +       /* drop out early, ret passes ENOENT */
5189 +       ret = -ENOENT;
5190 +       if ((redo = d_unhashed(old_path.dentry)))
5191 +               goto out_unlock_new;
5192 +
5193 +       new_path.mnt = dir_nd.path.mnt;
5194 +       dget(old_path.dentry);
5195 +       mntget(old_path.mnt);
5196 +       /* this one cleans up the dentry/mnt in case of failure */
5197 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5198 +               O_RDONLY, current_cred());
5199 +       vxdprintk(VXD_CBIT(misc, 2),
5200 +               "dentry_open(old): %p", old_file);
5201 +       if (!old_file || IS_ERR(old_file)) {
5202 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5203 +               goto out_unlock_new;
5204 +       }
5205 +
5206 +       dget(new_path.dentry);
5207 +       mntget(new_path.mnt);
5208 +       /* this one cleans up the dentry/mnt in case of failure */
5209 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5210 +               O_WRONLY, current_cred());
5211 +       vxdprintk(VXD_CBIT(misc, 2),
5212 +               "dentry_open(new): %p", new_file);
5213 +
5214 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5215 +       if (!new_file || IS_ERR(new_file))
5216 +               goto out_fput_old;
5217 +
5218 +       size = i_size_read(old_file->f_dentry->d_inode);
5219 +       ret = do_cow_splice(old_file, new_file, size);
5220 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5221 +       if (ret < 0) {
5222 +               goto out_fput_both;
5223 +       } else if (ret < size) {
5224 +               ret = -ENOSPC;
5225 +               goto out_fput_both;
5226 +       } else {
5227 +               struct inode *old_inode = old_path.dentry->d_inode;
5228 +               struct inode *new_inode = new_path.dentry->d_inode;
5229 +               struct iattr attr = {
5230 +                       .ia_uid = old_inode->i_uid,
5231 +                       .ia_gid = old_inode->i_gid,
5232 +                       .ia_valid = ATTR_UID | ATTR_GID
5233 +                       };
5234 +
5235 +               ret = inode_setattr(new_inode, &attr);
5236 +               if (ret)
5237 +                       goto out_fput_both;
5238 +       }
5239 +
5240 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5241 +
5242 +       /* drop out late */
5243 +       ret = -ENOENT;
5244 +       if ((redo = d_unhashed(old_path.dentry)))
5245 +               goto out_unlock;
5246 +
5247 +       vxdprintk(VXD_CBIT(misc, 2),
5248 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5249 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5250 +               new_path.dentry->d_name.len,
5251 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5252 +               old_path.dentry->d_name.len);
5253 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5254 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5255 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5256 +       res = new_path.dentry;
5257 +
5258 +out_unlock:
5259 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5260 +
5261 +out_fput_both:
5262 +       vxdprintk(VXD_CBIT(misc, 3),
5263 +               "fput(new_file=%p[#%ld])", new_file,
5264 +               atomic_long_read(&new_file->f_count));
5265 +       fput(new_file);
5266 +
5267 +out_fput_old:
5268 +       vxdprintk(VXD_CBIT(misc, 3),
5269 +               "fput(old_file=%p[#%ld])", old_file,
5270 +               atomic_long_read(&old_file->f_count));
5271 +       fput(old_file);
5272 +
5273 +out_unlock_new:
5274 +       mutex_unlock(&dir->d_inode->i_mutex);
5275 +       if (!ret)
5276 +               goto out_redo;
5277 +
5278 +       /* error path cleanup */
5279 +       vfs_unlink(dir->d_inode, new_path.dentry);
5280 +       dput(new_path.dentry);
5281 +
5282 +out_redo:
5283 +       if (!redo)
5284 +               goto out_rel_both;
5285 +       /* lookup dentry once again */
5286 +       path_put(&old_nd.path);
5287 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5288 +       if (ret)
5289 +               goto out_rel_both;
5290 +
5291 +       new_path.dentry = old_nd.path.dentry;
5292 +       vxdprintk(VXD_CBIT(misc, 2),
5293 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5294 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5295 +               new_path.dentry->d_name.len);
5296 +       dget(new_path.dentry);
5297 +       res = new_path.dentry;
5298 +
5299 +out_rel_both:
5300 +       path_put(&dir_nd.path);
5301 +out_rel_old:
5302 +       path_put(&old_nd.path);
5303 +out_free_path:
5304 +       kfree(path);
5305 +out:
5306 +       if (ret)
5307 +               res = ERR_PTR(ret);
5308 +       return res;
5309 +}
5310 +
5311 +#endif
5312 +
5313  /* get the link contents into pagecache */
5314  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5315  {
5316 diff -NurpP --minimal linux-2.6.33/fs/namespace.c linux-2.6.33-vs2.3.0.36.30/fs/namespace.c
5317 --- linux-2.6.33/fs/namespace.c 2010-02-25 11:52:05.000000000 +0100
5318 +++ linux-2.6.33-vs2.3.0.36.30/fs/namespace.c   2010-02-25 12:02:16.000000000 +0100
5319 @@ -29,6 +29,11 @@
5320  #include <linux/log2.h>
5321  #include <linux/idr.h>
5322  #include <linux/fs_struct.h>
5323 +#include <linux/vs_base.h>
5324 +#include <linux/vs_context.h>
5325 +#include <linux/vs_tag.h>
5326 +#include <linux/vserver/space.h>
5327 +#include <linux/vserver/global.h>
5328  #include <asm/uaccess.h>
5329  #include <asm/unistd.h>
5330  #include "pnode.h"
5331 @@ -567,6 +572,7 @@ static struct vfsmount *clone_mnt(struct
5332                 mnt->mnt_root = dget(root);
5333                 mnt->mnt_mountpoint = mnt->mnt_root;
5334                 mnt->mnt_parent = mnt;
5335 +               mnt->mnt_tag = old->mnt_tag;
5336  
5337                 if (flag & CL_SLAVE) {
5338                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5339 @@ -661,6 +667,31 @@ static inline void mangle(struct seq_fil
5340         seq_escape(m, s, " \t\n\\");
5341  }
5342  
5343 +static int mnt_is_reachable(struct vfsmount *mnt)
5344 +{
5345 +       struct path root;
5346 +       struct dentry *point;
5347 +       int ret;
5348 +
5349 +       if (mnt == mnt->mnt_ns->root)
5350 +               return 1;
5351 +
5352 +       spin_lock(&vfsmount_lock);
5353 +       root = current->fs->root;
5354 +       point = root.dentry;
5355 +
5356 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5357 +               point = mnt->mnt_mountpoint;
5358 +               mnt = mnt->mnt_parent;
5359 +       }
5360 +
5361 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5362 +
5363 +       spin_unlock(&vfsmount_lock);
5364 +
5365 +       return ret;
5366 +}
5367 +
5368  /*
5369   * Simple .show_options callback for filesystems which don't want to
5370   * implement more complex mount option showing.
5371 @@ -748,6 +779,8 @@ static int show_sb_opts(struct seq_file 
5372                 { MS_SYNCHRONOUS, ",sync" },
5373                 { MS_DIRSYNC, ",dirsync" },
5374                 { MS_MANDLOCK, ",mand" },
5375 +               { MS_TAGGED, ",tag" },
5376 +               { MS_NOTAGCHECK, ",notagcheck" },
5377                 { 0, NULL }
5378         };
5379         const struct proc_fs_info *fs_infop;
5380 @@ -795,10 +828,20 @@ static int show_vfsmnt(struct seq_file *
5381         int err = 0;
5382         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5383  
5384 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5385 -       seq_putc(m, ' ');
5386 -       seq_path(m, &mnt_path, " \t\n\\");
5387 -       seq_putc(m, ' ');
5388 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5389 +               return SEQ_SKIP;
5390 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5391 +               return SEQ_SKIP;
5392 +
5393 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5394 +               mnt == current->fs->root.mnt) {
5395 +               seq_puts(m, "/dev/root / ");
5396 +       } else {
5397 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5398 +               seq_putc(m, ' ');
5399 +               seq_path(m, &mnt_path, " \t\n\\");
5400 +               seq_putc(m, ' ');
5401 +       }
5402         show_type(m, mnt->mnt_sb);
5403         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5404         err = show_sb_opts(m, mnt->mnt_sb);
5405 @@ -828,6 +871,11 @@ static int show_mountinfo(struct seq_fil
5406         struct path root = p->root;
5407         int err = 0;
5408  
5409 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5410 +               return SEQ_SKIP;
5411 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5412 +               return SEQ_SKIP;
5413 +
5414         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5415                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5416         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5417 @@ -886,17 +934,27 @@ static int show_vfsstat(struct seq_file 
5418         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5419         int err = 0;
5420  
5421 -       /* device */
5422 -       if (mnt->mnt_devname) {
5423 -               seq_puts(m, "device ");
5424 -               mangle(m, mnt->mnt_devname);
5425 -       } else
5426 -               seq_puts(m, "no device");
5427 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5428 +               return SEQ_SKIP;
5429 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5430 +               return SEQ_SKIP;
5431  
5432 -       /* mount point */
5433 -       seq_puts(m, " mounted on ");
5434 -       seq_path(m, &mnt_path, " \t\n\\");
5435 -       seq_putc(m, ' ');
5436 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5437 +               mnt == current->fs->root.mnt) {
5438 +               seq_puts(m, "device /dev/root mounted on / ");
5439 +       } else {
5440 +               /* device */
5441 +               if (mnt->mnt_devname) {
5442 +                       seq_puts(m, "device ");
5443 +                       mangle(m, mnt->mnt_devname);
5444 +               } else
5445 +                       seq_puts(m, "no device");
5446 +
5447 +               /* mount point */
5448 +               seq_puts(m, " mounted on ");
5449 +               seq_path(m, &mnt_path, " \t\n\\");
5450 +               seq_putc(m, ' ');
5451 +       }
5452  
5453         /* file system type */
5454         seq_puts(m, "with fstype ");
5455 @@ -1132,7 +1190,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5456                 goto dput_and_out;
5457  
5458         retval = -EPERM;
5459 -       if (!capable(CAP_SYS_ADMIN))
5460 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5461                 goto dput_and_out;
5462  
5463         retval = do_umount(path.mnt, flags);
5464 @@ -1158,7 +1216,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5465  
5466  static int mount_is_safe(struct path *path)
5467  {
5468 -       if (capable(CAP_SYS_ADMIN))
5469 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5470                 return 0;
5471         return -EPERM;
5472  #ifdef notyet
5473 @@ -1422,7 +1480,7 @@ static int do_change_type(struct path *p
5474         int type = flag & ~MS_REC;
5475         int err = 0;
5476  
5477 -       if (!capable(CAP_SYS_ADMIN))
5478 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5479                 return -EPERM;
5480  
5481         if (path->dentry != path->mnt->mnt_root)
5482 @@ -1449,11 +1507,13 @@ static int do_change_type(struct path *p
5483   * do loopback mount.
5484   */
5485  static int do_loopback(struct path *path, char *old_name,
5486 -                               int recurse)
5487 +       tag_t tag, unsigned long flags, int mnt_flags)
5488  {
5489         struct path old_path;
5490         struct vfsmount *mnt = NULL;
5491         int err = mount_is_safe(path);
5492 +       int recurse = flags & MS_REC;
5493 +
5494         if (err)
5495                 return err;
5496         if (!old_name || !*old_name)
5497 @@ -1487,6 +1547,7 @@ static int do_loopback(struct path *path
5498                 spin_unlock(&vfsmount_lock);
5499                 release_mounts(&umount_list);
5500         }
5501 +       mnt->mnt_flags = mnt_flags;
5502  
5503  out:
5504         up_write(&namespace_sem);
5505 @@ -1517,12 +1578,12 @@ static int change_mount_flags(struct vfs
5506   * on it - tough luck.
5507   */
5508  static int do_remount(struct path *path, int flags, int mnt_flags,
5509 -                     void *data)
5510 +       void *data, xid_t xid)
5511  {
5512         int err;
5513         struct super_block *sb = path->mnt->mnt_sb;
5514  
5515 -       if (!capable(CAP_SYS_ADMIN))
5516 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5517                 return -EPERM;
5518  
5519         if (!check_mnt(path->mnt))
5520 @@ -1568,7 +1629,7 @@ static int do_move_mount(struct path *pa
5521         struct path old_path, parent_path;
5522         struct vfsmount *p;
5523         int err = 0;
5524 -       if (!capable(CAP_SYS_ADMIN))
5525 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5526                 return -EPERM;
5527         if (!old_name || !*old_name)
5528                 return -EINVAL;
5529 @@ -1650,7 +1711,7 @@ static int do_new_mount(struct path *pat
5530                 return -EINVAL;
5531  
5532         /* we need capabilities... */
5533 -       if (!capable(CAP_SYS_ADMIN))
5534 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5535                 return -EPERM;
5536  
5537         lock_kernel();
5538 @@ -1916,6 +1977,7 @@ long do_mount(char *dev_name, char *dir_
5539         struct path path;
5540         int retval = 0;
5541         int mnt_flags = 0;
5542 +       tag_t tag = 0;
5543  
5544         /* Discard magic */
5545         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5546 @@ -1943,6 +2005,12 @@ long do_mount(char *dev_name, char *dir_
5547         if (!(flags & MS_NOATIME))
5548                 mnt_flags |= MNT_RELATIME;
5549  
5550 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5551 +               /* FIXME: bind and re-mounts get the tag flag? */
5552 +               if (flags & (MS_BIND|MS_REMOUNT))
5553 +                       flags |= MS_TAGID;
5554 +       }
5555 +
5556         /* Separate the per-mountpoint flags */
5557         if (flags & MS_NOSUID)
5558                 mnt_flags |= MNT_NOSUID;
5559 @@ -1959,15 +2027,17 @@ long do_mount(char *dev_name, char *dir_
5560         if (flags & MS_RDONLY)
5561                 mnt_flags |= MNT_READONLY;
5562  
5563 +       if (!capable(CAP_SYS_ADMIN))
5564 +               mnt_flags |= MNT_NODEV;
5565         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5566                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5567                    MS_STRICTATIME);
5568  
5569         if (flags & MS_REMOUNT)
5570                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5571 -                                   data_page);
5572 +                                   data_page, tag);
5573         else if (flags & MS_BIND)
5574 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5575 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5576         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5577                 retval = do_change_type(&path, flags);
5578         else if (flags & MS_MOVE)
5579 @@ -2046,6 +2116,7 @@ static struct mnt_namespace *dup_mnt_ns(
5580                 q = next_mnt(q, new_ns->root);
5581         }
5582         up_write(&namespace_sem);
5583 +       atomic_inc(&vs_global_mnt_ns);
5584  
5585         if (rootmnt)
5586                 mntput(rootmnt);
5587 @@ -2190,9 +2261,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5588         down_write(&namespace_sem);
5589         mutex_lock(&old.dentry->d_inode->i_mutex);
5590         error = -EINVAL;
5591 -       if (IS_MNT_SHARED(old.mnt) ||
5592 +       if ((IS_MNT_SHARED(old.mnt) ||
5593                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5594 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5595 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5596 +               !vx_flags(VXF_STATE_SETUP, 0))
5597                 goto out2;
5598         if (!check_mnt(root.mnt))
5599                 goto out2;
5600 @@ -2328,6 +2400,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5601         spin_unlock(&vfsmount_lock);
5602         up_write(&namespace_sem);
5603         release_mounts(&umount_list);
5604 +       atomic_dec(&vs_global_mnt_ns);
5605         kfree(ns);
5606  }
5607  EXPORT_SYMBOL(put_mnt_ns);
5608 diff -NurpP --minimal linux-2.6.33/fs/nfs/client.c linux-2.6.33-vs2.3.0.36.30/fs/nfs/client.c
5609 --- linux-2.6.33/fs/nfs/client.c        2010-02-25 11:52:05.000000000 +0100
5610 +++ linux-2.6.33-vs2.3.0.36.30/fs/nfs/client.c  2010-02-25 12:02:16.000000000 +0100
5611 @@ -738,6 +738,9 @@ static int nfs_init_server_rpcclient(str
5612         if (server->flags & NFS_MOUNT_SOFT)
5613                 server->client->cl_softrtry = 1;
5614  
5615 +       server->client->cl_tag = 0;
5616 +       if (server->flags & NFS_MOUNT_TAGGED)
5617 +               server->client->cl_tag = 1;
5618         return 0;
5619  }
5620  
5621 @@ -909,6 +912,10 @@ static void nfs_server_set_fsinfo(struct
5622                 server->acdirmin = server->acdirmax = 0;
5623         }
5624  
5625 +       /* FIXME: needs fsinfo
5626 +       if (server->flags & NFS_MOUNT_TAGGED)
5627 +               sb->s_flags |= MS_TAGGED;       */
5628 +
5629         server->maxfilesize = fsinfo->maxfilesize;
5630  
5631         /* We're airborne Set socket buffersize */
5632 diff -NurpP --minimal linux-2.6.33/fs/nfs/dir.c linux-2.6.33-vs2.3.0.36.30/fs/nfs/dir.c
5633 --- linux-2.6.33/fs/nfs/dir.c   2010-02-25 11:52:05.000000000 +0100
5634 +++ linux-2.6.33-vs2.3.0.36.30/fs/nfs/dir.c     2010-02-25 12:02:16.000000000 +0100
5635 @@ -33,6 +33,7 @@
5636  #include <linux/namei.h>
5637  #include <linux/mount.h>
5638  #include <linux/sched.h>
5639 +#include <linux/vs_tag.h>
5640  
5641  #include "nfs4_fs.h"
5642  #include "delegation.h"
5643 @@ -949,6 +950,7 @@ static struct dentry *nfs_lookup(struct 
5644         if (IS_ERR(res))
5645                 goto out_unblock_sillyrename;
5646  
5647 +       dx_propagate_tag(nd, inode);
5648  no_entry:
5649         res = d_materialise_unique(dentry, inode);
5650         if (res != NULL) {
5651 diff -NurpP --minimal linux-2.6.33/fs/nfs/inode.c linux-2.6.33-vs2.3.0.36.30/fs/nfs/inode.c
5652 --- linux-2.6.33/fs/nfs/inode.c 2010-02-25 11:52:05.000000000 +0100
5653 +++ linux-2.6.33-vs2.3.0.36.30/fs/nfs/inode.c   2010-02-25 12:02:16.000000000 +0100
5654 @@ -36,6 +36,7 @@
5655  #include <linux/vfs.h>
5656  #include <linux/inet.h>
5657  #include <linux/nfs_xdr.h>
5658 +#include <linux/vs_tag.h>
5659  
5660  #include <asm/system.h>
5661  #include <asm/uaccess.h>
5662 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5663         if (inode->i_state & I_NEW) {
5664                 struct nfs_inode *nfsi = NFS_I(inode);
5665                 unsigned long now = jiffies;
5666 +               uid_t uid;
5667 +               gid_t gid;
5668  
5669                 /* We set i_ino for the few things that still rely on it,
5670                  * such as stat(2) */
5671 @@ -327,8 +330,8 @@ nfs_fhget(struct super_block *sb, struct
5672                 nfsi->change_attr = 0;
5673                 inode->i_size = 0;
5674                 inode->i_nlink = 0;
5675 -               inode->i_uid = -2;
5676 -               inode->i_gid = -2;
5677 +               uid = -2;
5678 +               gid = -2;
5679                 inode->i_blocks = 0;
5680                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5681  
5682 @@ -365,13 +368,13 @@ nfs_fhget(struct super_block *sb, struct
5683                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5684                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5685                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5686 -                       inode->i_uid = fattr->uid;
5687 +                       uid = fattr->uid;
5688                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5689                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5690                                 | NFS_INO_INVALID_ACCESS
5691                                 | NFS_INO_INVALID_ACL;
5692                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5693 -                       inode->i_gid = fattr->gid;
5694 +                       gid = fattr->gid;
5695                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5696                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5697                                 | NFS_INO_INVALID_ACCESS
5698 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5699                          */
5700                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5701                 }
5702 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5703 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5704 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5705 +                               /* maybe fattr->xid someday */
5706 +
5707                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5708                 nfsi->attrtimeo_timestamp = now;
5709                 nfsi->access_cache = RB_ROOT;
5710 @@ -496,6 +504,8 @@ void nfs_setattr_update_inode(struct ino
5711                         inode->i_uid = attr->ia_uid;
5712                 if ((attr->ia_valid & ATTR_GID) != 0)
5713                         inode->i_gid = attr->ia_gid;
5714 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5715 +                       inode->i_tag = attr->ia_tag;
5716                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5717                 spin_unlock(&inode->i_lock);
5718         }
5719 @@ -906,6 +916,9 @@ static int nfs_check_inode_attributes(st
5720         struct nfs_inode *nfsi = NFS_I(inode);
5721         loff_t cur_size, new_isize;
5722         unsigned long invalid = 0;
5723 +       uid_t uid;
5724 +       gid_t gid;
5725 +       tag_t tag;
5726  
5727  
5728         /* Has the inode gone and changed behind our back? */
5729 @@ -929,13 +942,18 @@ static int nfs_check_inode_attributes(st
5730                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5731         }
5732  
5733 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5734 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5735 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5736 +
5737         /* Have any file permissions changed? */
5738         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5739                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5740 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5741 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5742                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5743 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5744 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5745                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5746 +               /* maybe check for tag too? */
5747  
5748         /* Has the link count changed? */
5749         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5750 @@ -1150,6 +1168,9 @@ static int nfs_update_inode(struct inode
5751         unsigned long invalid = 0;
5752         unsigned long now = jiffies;
5753         unsigned long save_cache_validity;
5754 +       uid_t uid;
5755 +       gid_t gid;
5756 +       tag_t tag;
5757  
5758         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5759                         __func__, inode->i_sb->s_id, inode->i_ino,
5760 @@ -1252,6 +1273,9 @@ static int nfs_update_inode(struct inode
5761                                 | NFS_INO_REVAL_PAGECACHE
5762                                 | NFS_INO_REVAL_FORCED);
5763  
5764 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5765 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5766 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5767  
5768         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5769                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5770 @@ -1273,9 +1297,9 @@ static int nfs_update_inode(struct inode
5771                                 | NFS_INO_REVAL_FORCED);
5772  
5773         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5774 -               if (inode->i_uid != fattr->uid) {
5775 +               if (uid != fattr->uid) {
5776                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5777 -                       inode->i_uid = fattr->uid;
5778 +                       uid = fattr->uid;
5779                 }
5780         } else if (server->caps & NFS_CAP_OWNER)
5781                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5782 @@ -1284,9 +1308,9 @@ static int nfs_update_inode(struct inode
5783                                 | NFS_INO_REVAL_FORCED);
5784  
5785         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5786 -               if (inode->i_gid != fattr->gid) {
5787 +               if (gid != fattr->gid) {
5788                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5789 -                       inode->i_gid = fattr->gid;
5790 +                       gid = fattr->gid;
5791                 }
5792         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5793                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5794 @@ -1294,6 +1318,10 @@ static int nfs_update_inode(struct inode
5795                                 | NFS_INO_INVALID_ACL
5796                                 | NFS_INO_REVAL_FORCED);
5797  
5798 +       inode->i_uid = uid;
5799 +       inode->i_gid = gid;
5800 +       inode->i_tag = tag;
5801 +
5802         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5803                 if (inode->i_nlink != fattr->nlink) {
5804                         invalid |= NFS_INO_INVALID_ATTR;
5805 diff -NurpP --minimal linux-2.6.33/fs/nfs/nfs3xdr.c linux-2.6.33-vs2.3.0.36.30/fs/nfs/nfs3xdr.c
5806 --- linux-2.6.33/fs/nfs/nfs3xdr.c       2009-12-03 20:02:52.000000000 +0100
5807 +++ linux-2.6.33-vs2.3.0.36.30/fs/nfs/nfs3xdr.c 2010-02-25 12:02:16.000000000 +0100
5808 @@ -21,6 +21,7 @@
5809  #include <linux/nfs3.h>
5810  #include <linux/nfs_fs.h>
5811  #include <linux/nfsacl.h>
5812 +#include <linux/vs_tag.h>
5813  #include "internal.h"
5814  
5815  #define NFSDBG_FACILITY                NFSDBG_XDR
5816 @@ -176,7 +177,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5817  }
5818  
5819  static inline __be32 *
5820 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5821 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5822  {
5823         if (attr->ia_valid & ATTR_MODE) {
5824                 *p++ = xdr_one;
5825 @@ -184,15 +185,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5826         } else {
5827                 *p++ = xdr_zero;
5828         }
5829 -       if (attr->ia_valid & ATTR_UID) {
5830 +       if (attr->ia_valid & ATTR_UID ||
5831 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5832                 *p++ = xdr_one;
5833 -               *p++ = htonl(attr->ia_uid);
5834 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5835         } else {
5836                 *p++ = xdr_zero;
5837         }
5838 -       if (attr->ia_valid & ATTR_GID) {
5839 +       if (attr->ia_valid & ATTR_GID ||
5840 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5841                 *p++ = xdr_one;
5842 -               *p++ = htonl(attr->ia_gid);
5843 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5844         } else {
5845                 *p++ = xdr_zero;
5846         }
5847 @@ -279,7 +282,8 @@ static int
5848  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5849  {
5850         p = xdr_encode_fhandle(p, args->fh);
5851 -       p = xdr_encode_sattr(p, args->sattr);
5852 +       p = xdr_encode_sattr(p, args->sattr,
5853 +               req->rq_task->tk_client->cl_tag);
5854         *p++ = htonl(args->guard);
5855         if (args->guard)
5856                 p = xdr_encode_time3(p, &args->guardtime);
5857 @@ -384,7 +388,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5858                 *p++ = args->verifier[0];
5859                 *p++ = args->verifier[1];
5860         } else
5861 -               p = xdr_encode_sattr(p, args->sattr);
5862 +               p = xdr_encode_sattr(p, args->sattr,
5863 +                       req->rq_task->tk_client->cl_tag);
5864  
5865         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5866         return 0;
5867 @@ -398,7 +403,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5868  {
5869         p = xdr_encode_fhandle(p, args->fh);
5870         p = xdr_encode_array(p, args->name, args->len);
5871 -       p = xdr_encode_sattr(p, args->sattr);
5872 +       p = xdr_encode_sattr(p, args->sattr,
5873 +               req->rq_task->tk_client->cl_tag);
5874         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5875         return 0;
5876  }
5877 @@ -411,7 +417,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5878  {
5879         p = xdr_encode_fhandle(p, args->fromfh);
5880         p = xdr_encode_array(p, args->fromname, args->fromlen);
5881 -       p = xdr_encode_sattr(p, args->sattr);
5882 +       p = xdr_encode_sattr(p, args->sattr,
5883 +               req->rq_task->tk_client->cl_tag);
5884         *p++ = htonl(args->pathlen);
5885         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5886  
5887 @@ -429,7 +436,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5888         p = xdr_encode_fhandle(p, args->fh);
5889         p = xdr_encode_array(p, args->name, args->len);
5890         *p++ = htonl(args->type);
5891 -       p = xdr_encode_sattr(p, args->sattr);
5892 +       p = xdr_encode_sattr(p, args->sattr,
5893 +               req->rq_task->tk_client->cl_tag);
5894         if (args->type == NF3CHR || args->type == NF3BLK) {
5895                 *p++ = htonl(MAJOR(args->rdev));
5896                 *p++ = htonl(MINOR(args->rdev));
5897 diff -NurpP --minimal linux-2.6.33/fs/nfs/nfsroot.c linux-2.6.33-vs2.3.0.36.30/fs/nfs/nfsroot.c
5898 --- linux-2.6.33/fs/nfs/nfsroot.c       2009-09-10 15:26:23.000000000 +0200
5899 +++ linux-2.6.33-vs2.3.0.36.30/fs/nfs/nfsroot.c 2010-02-25 12:02:16.000000000 +0100
5900 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
5901  enum {
5902         /* Options that take integer arguments */
5903         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
5904 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
5905 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
5906         /* Options that take no arguments */
5907         Opt_soft, Opt_hard, Opt_intr,
5908         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
5909         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
5910 -       Opt_acl, Opt_noacl,
5911 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
5912         /* Error token */
5913         Opt_err
5914  };
5915 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
5916         {Opt_tcp, "tcp"},
5917         {Opt_acl, "acl"},
5918         {Opt_noacl, "noacl"},
5919 +       {Opt_tag, "tag"},
5920 +       {Opt_notag, "notag"},
5921 +       {Opt_tagid, "tagid=%u"},
5922         {Opt_err, NULL}
5923         
5924  };
5925 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
5926                         case Opt_noacl:
5927                                 nfs_data.flags |= NFS_MOUNT_NOACL;
5928                                 break;
5929 +#ifndef CONFIG_TAGGING_NONE
5930 +                       case Opt_tag:
5931 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5932 +                               break;
5933 +                       case Opt_notag:
5934 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
5935 +                               break;
5936 +#endif
5937 +#ifdef CONFIG_PROPAGATE
5938 +                       case Opt_tagid:
5939 +                               /* use args[0] */
5940 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5941 +                               break;
5942 +#endif
5943                         default:
5944                                 printk(KERN_WARNING "Root-NFS: unknown "
5945                                         "option: %s\n", p);
5946 diff -NurpP --minimal linux-2.6.33/fs/nfs/super.c linux-2.6.33-vs2.3.0.36.30/fs/nfs/super.c
5947 --- linux-2.6.33/fs/nfs/super.c 2010-02-25 11:52:05.000000000 +0100
5948 +++ linux-2.6.33-vs2.3.0.36.30/fs/nfs/super.c   2010-02-25 12:02:16.000000000 +0100
5949 @@ -53,6 +53,7 @@
5950  #include <linux/nfs_xdr.h>
5951  #include <linux/magic.h>
5952  #include <linux/parser.h>
5953 +#include <linux/vs_tag.h>
5954  
5955  #include <asm/system.h>
5956  #include <asm/uaccess.h>
5957 @@ -585,6 +586,7 @@ static void nfs_show_mount_options(struc
5958                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5959                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5960                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5961 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5962                 { 0, NULL, NULL }
5963         };
5964         const struct proc_nfs_info *nfs_infop;
5965 diff -NurpP --minimal linux-2.6.33/fs/nfsd/auth.c linux-2.6.33-vs2.3.0.36.30/fs/nfsd/auth.c
5966 --- linux-2.6.33/fs/nfsd/auth.c 2010-02-25 11:52:05.000000000 +0100
5967 +++ linux-2.6.33-vs2.3.0.36.30/fs/nfsd/auth.c   2010-02-25 13:17:41.000000000 +0100
5968 @@ -1,6 +1,7 @@
5969  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5970  
5971  #include <linux/sched.h>
5972 +#include <linux/vs_tag.h>
5973  #include "nfsd.h"
5974  #include "auth.h"
5975  
5976 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5977  
5978         new->fsuid = rqstp->rq_cred.cr_uid;
5979         new->fsgid = rqstp->rq_cred.cr_gid;
5980 +       /* FIXME: this desperately needs a tag :)
5981 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5982 +                       */
5983  
5984         rqgi = rqstp->rq_cred.cr_group_info;
5985  
5986 diff -NurpP --minimal linux-2.6.33/fs/nfsd/nfs3xdr.c linux-2.6.33-vs2.3.0.36.30/fs/nfsd/nfs3xdr.c
5987 --- linux-2.6.33/fs/nfsd/nfs3xdr.c      2010-02-25 11:52:05.000000000 +0100
5988 +++ linux-2.6.33-vs2.3.0.36.30/fs/nfsd/nfs3xdr.c        2010-02-25 13:18:45.000000000 +0100
5989 @@ -7,6 +7,7 @@
5990   */
5991  
5992  #include <linux/namei.h>
5993 +#include <linux/vs_tag.h>
5994  #include "xdr3.h"
5995  #include "auth.h"
5996  
5997 @@ -95,6 +96,8 @@ static __be32 *
5998  decode_sattr3(__be32 *p, struct iattr *iap)
5999  {
6000         u32     tmp;
6001 +       uid_t   uid = 0;
6002 +       gid_t   gid = 0;
6003  
6004         iap->ia_valid = 0;
6005  
6006 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6007         }
6008         if (*p++) {
6009                 iap->ia_valid |= ATTR_UID;
6010 -               iap->ia_uid = ntohl(*p++);
6011 +               uid = ntohl(*p++);
6012         }
6013         if (*p++) {
6014                 iap->ia_valid |= ATTR_GID;
6015 -               iap->ia_gid = ntohl(*p++);
6016 +               gid = ntohl(*p++);
6017         }
6018 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6019 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6020 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6021         if (*p++) {
6022                 u64     newsize;
6023  
6024 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6025         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6026         *p++ = htonl((u32) stat->mode);
6027         *p++ = htonl((u32) stat->nlink);
6028 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6029 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6030 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6031 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6032 +               stat->uid, stat->tag)));
6033 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6034 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6035 +               stat->gid, stat->tag)));
6036         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6037                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6038         } else {
6039 diff -NurpP --minimal linux-2.6.33/fs/nfsd/nfs4xdr.c linux-2.6.33-vs2.3.0.36.30/fs/nfsd/nfs4xdr.c
6040 --- linux-2.6.33/fs/nfsd/nfs4xdr.c      2010-02-25 11:52:05.000000000 +0100
6041 +++ linux-2.6.33-vs2.3.0.36.30/fs/nfsd/nfs4xdr.c        2010-02-25 12:02:16.000000000 +0100
6042 @@ -46,6 +46,7 @@
6043  #include <linux/nfsd_idmap.h>
6044  #include <linux/nfs4_acl.h>
6045  #include <linux/sunrpc/svcauth_gss.h>
6046 +#include <linux/vs_tag.h>
6047  
6048  #include "xdr4.h"
6049  #include "vfs.h"
6050 @@ -2042,14 +2043,18 @@ out_acl:
6051                 WRITE32(stat.nlink);
6052         }
6053         if (bmval1 & FATTR4_WORD1_OWNER) {
6054 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6055 +               status = nfsd4_encode_user(rqstp,
6056 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6057 +                       stat.uid, stat.tag), &p, &buflen);
6058                 if (status == nfserr_resource)
6059                         goto out_resource;
6060                 if (status)
6061                         goto out;
6062         }
6063         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6064 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6065 +               status = nfsd4_encode_group(rqstp,
6066 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6067 +                       stat.gid, stat.tag), &p, &buflen);
6068                 if (status == nfserr_resource)
6069                         goto out_resource;
6070                 if (status)
6071 diff -NurpP --minimal linux-2.6.33/fs/nfsd/nfsxdr.c linux-2.6.33-vs2.3.0.36.30/fs/nfsd/nfsxdr.c
6072 --- linux-2.6.33/fs/nfsd/nfsxdr.c       2010-02-25 11:52:05.000000000 +0100
6073 +++ linux-2.6.33-vs2.3.0.36.30/fs/nfsd/nfsxdr.c 2010-02-25 13:18:10.000000000 +0100
6074 @@ -6,6 +6,7 @@
6075  
6076  #include "xdr.h"
6077  #include "auth.h"
6078 +#include <linux/vs_tag.h>
6079  
6080  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6081  
6082 @@ -88,6 +89,8 @@ static __be32 *
6083  decode_sattr(__be32 *p, struct iattr *iap)
6084  {
6085         u32     tmp, tmp1;
6086 +       uid_t   uid = 0;
6087 +       gid_t   gid = 0;
6088  
6089         iap->ia_valid = 0;
6090  
6091 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6092         }
6093         if ((tmp = ntohl(*p++)) != (u32)-1) {
6094                 iap->ia_valid |= ATTR_UID;
6095 -               iap->ia_uid = tmp;
6096 +               uid = tmp;
6097         }
6098         if ((tmp = ntohl(*p++)) != (u32)-1) {
6099                 iap->ia_valid |= ATTR_GID;
6100 -               iap->ia_gid = tmp;
6101 +               gid = tmp;
6102         }
6103 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6104 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6105 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6106         if ((tmp = ntohl(*p++)) != (u32)-1) {
6107                 iap->ia_valid |= ATTR_SIZE;
6108                 iap->ia_size = tmp;
6109 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6110         *p++ = htonl(nfs_ftypes[type >> 12]);
6111         *p++ = htonl((u32) stat->mode);
6112         *p++ = htonl((u32) stat->nlink);
6113 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6114 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6115 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6116 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6117 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6118 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6119  
6120         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6121                 *p++ = htonl(NFS_MAXPATHLEN);
6122 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/dlm/dlmfs.c linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/dlm/dlmfs.c
6123 --- linux-2.6.33/fs/ocfs2/dlm/dlmfs.c   2009-12-03 20:02:53.000000000 +0100
6124 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/dlm/dlmfs.c     2010-02-25 12:02:16.000000000 +0100
6125 @@ -43,6 +43,7 @@
6126  #include <linux/init.h>
6127  #include <linux/string.h>
6128  #include <linux/backing-dev.h>
6129 +#include <linux/vs_tag.h>
6130  
6131  #include <asm/uaccess.h>
6132  
6133 @@ -342,6 +343,7 @@ static struct inode *dlmfs_get_root_inod
6134                 inode->i_mode = mode;
6135                 inode->i_uid = current_fsuid();
6136                 inode->i_gid = current_fsgid();
6137 +               inode->i_tag = dx_current_fstag(sb);
6138                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6139                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6140                 inc_nlink(inode);
6141 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6142         inode->i_mode = mode;
6143         inode->i_uid = current_fsuid();
6144         inode->i_gid = current_fsgid();
6145 +       inode->i_tag = dx_current_fstag(sb);
6146         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6147         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6148  
6149 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/dlmglue.c linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/dlmglue.c
6150 --- linux-2.6.33/fs/ocfs2/dlmglue.c     2010-02-25 11:52:06.000000000 +0100
6151 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/dlmglue.c       2010-02-25 12:02:16.000000000 +0100
6152 @@ -2023,6 +2023,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6153         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6154         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6155         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6156 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6157         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6158         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6159         lvb->lvb_iatime_packed  =
6160 @@ -2077,6 +2078,7 @@ static void ocfs2_refresh_inode_from_lvb
6161  
6162         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6163         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6164 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6165         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6166         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6167         ocfs2_unpack_timespec(&inode->i_atime,
6168 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/dlmglue.h linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/dlmglue.h
6169 --- linux-2.6.33/fs/ocfs2/dlmglue.h     2009-12-03 20:02:53.000000000 +0100
6170 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/dlmglue.h       2010-02-25 12:02:16.000000000 +0100
6171 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6172         __be16       lvb_inlink;
6173         __be32       lvb_iattr;
6174         __be32       lvb_igeneration;
6175 -       __be32       lvb_reserved2;
6176 +       __be16       lvb_itag;
6177 +       __be16       lvb_reserved2;
6178  };
6179  
6180  #define OCFS2_QINFO_LVB_VERSION 1
6181 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/file.c linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/file.c
6182 --- linux-2.6.33/fs/ocfs2/file.c        2010-02-25 11:52:06.000000000 +0100
6183 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/file.c  2010-02-25 12:02:16.000000000 +0100
6184 @@ -960,13 +960,15 @@ int ocfs2_setattr(struct dentry *dentry,
6185                 mlog(0, "uid change: %d\n", attr->ia_uid);
6186         if (attr->ia_valid & ATTR_GID)
6187                 mlog(0, "gid change: %d\n", attr->ia_gid);
6188 +       if (attr->ia_valid & ATTR_TAG)
6189 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6190         if (attr->ia_valid & ATTR_SIZE)
6191                 mlog(0, "size change...\n");
6192         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6193                 mlog(0, "time change...\n");
6194  
6195  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6196 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6197 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6198         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6199                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6200                 return 0;
6201 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/inode.c linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/inode.c
6202 --- linux-2.6.33/fs/ocfs2/inode.c       2010-02-25 11:52:06.000000000 +0100
6203 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/inode.c 2010-02-25 12:02:16.000000000 +0100
6204 @@ -29,6 +29,7 @@
6205  #include <linux/highmem.h>
6206  #include <linux/pagemap.h>
6207  #include <linux/quotaops.h>
6208 +#include <linux/vs_tag.h>
6209  
6210  #include <asm/byteorder.h>
6211  
6212 @@ -79,11 +80,13 @@ void ocfs2_set_inode_flags(struct inode 
6213  {
6214         unsigned int flags = OCFS2_I(inode)->ip_attr;
6215  
6216 -       inode->i_flags &= ~(S_IMMUTABLE |
6217 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6218                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6219  
6220         if (flags & OCFS2_IMMUTABLE_FL)
6221                 inode->i_flags |= S_IMMUTABLE;
6222 +       if (flags & OCFS2_IXUNLINK_FL)
6223 +               inode->i_flags |= S_IXUNLINK;
6224  
6225         if (flags & OCFS2_SYNC_FL)
6226                 inode->i_flags |= S_SYNC;
6227 @@ -93,25 +96,44 @@ void ocfs2_set_inode_flags(struct inode 
6228                 inode->i_flags |= S_NOATIME;
6229         if (flags & OCFS2_DIRSYNC_FL)
6230                 inode->i_flags |= S_DIRSYNC;
6231 +
6232 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6233 +
6234 +       if (flags & OCFS2_BARRIER_FL)
6235 +               inode->i_vflags |= V_BARRIER;
6236 +       if (flags & OCFS2_COW_FL)
6237 +               inode->i_vflags |= V_COW;
6238  }
6239  
6240  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6241  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6242  {
6243         unsigned int flags = oi->vfs_inode.i_flags;
6244 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6245 +
6246 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6247 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6248 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6249 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6250 +
6251 +       if (flags & S_IMMUTABLE)
6252 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6253 +       if (flags & S_IXUNLINK)
6254 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6255  
6256 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6257 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6258         if (flags & S_SYNC)
6259                 oi->ip_attr |= OCFS2_SYNC_FL;
6260         if (flags & S_APPEND)
6261                 oi->ip_attr |= OCFS2_APPEND_FL;
6262 -       if (flags & S_IMMUTABLE)
6263 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6264         if (flags & S_NOATIME)
6265                 oi->ip_attr |= OCFS2_NOATIME_FL;
6266         if (flags & S_DIRSYNC)
6267                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6268 +
6269 +       if (vflags & V_BARRIER)
6270 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6271 +       if (vflags & V_COW)
6272 +               oi->ip_attr |= OCFS2_COW_FL;
6273  }
6274  
6275  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6276 @@ -246,6 +268,8 @@ void ocfs2_populate_inode(struct inode *
6277         struct super_block *sb;
6278         struct ocfs2_super *osb;
6279         int use_plocks = 1;
6280 +       uid_t uid;
6281 +       gid_t gid;
6282  
6283         mlog_entry("(0x%p, size:%llu)\n", inode,
6284                    (unsigned long long)le64_to_cpu(fe->i_size));
6285 @@ -277,8 +301,12 @@ void ocfs2_populate_inode(struct inode *
6286         inode->i_generation = le32_to_cpu(fe->i_generation);
6287         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6288         inode->i_mode = le16_to_cpu(fe->i_mode);
6289 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6290 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6291 +       uid = le32_to_cpu(fe->i_uid);
6292 +       gid = le32_to_cpu(fe->i_gid);
6293 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6294 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6295 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6296 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6297  
6298         /* Fast symlinks will have i_size but no allocated clusters. */
6299         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6300 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/inode.h linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/inode.h
6301 --- linux-2.6.33/fs/ocfs2/inode.h       2009-12-03 20:02:53.000000000 +0100
6302 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/inode.h 2010-02-25 12:02:16.000000000 +0100
6303 @@ -150,6 +150,7 @@ struct buffer_head *ocfs2_bread(struct i
6304  
6305  void ocfs2_set_inode_flags(struct inode *inode);
6306  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6307 +int ocfs2_sync_flags(struct inode *inode, int, int);
6308  
6309  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6310  {
6311 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/ioctl.c linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/ioctl.c
6312 --- linux-2.6.33/fs/ocfs2/ioctl.c       2010-02-25 11:52:06.000000000 +0100
6313 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/ioctl.c 2010-02-25 12:02:16.000000000 +0100
6314 @@ -43,7 +43,41 @@ static int ocfs2_get_inode_attr(struct i
6315         return status;
6316  }
6317  
6318 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6319 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6320 +{
6321 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6322 +       struct buffer_head *bh = NULL;
6323 +       handle_t *handle = NULL;
6324 +       int status;
6325 +
6326 +       status = ocfs2_inode_lock(inode, &bh, 1);
6327 +       if (status < 0) {
6328 +               mlog_errno(status);
6329 +               return status;
6330 +       }
6331 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6332 +       if (IS_ERR(handle)) {
6333 +               status = PTR_ERR(handle);
6334 +               mlog_errno(status);
6335 +               goto bail_unlock;
6336 +       }
6337 +
6338 +       inode->i_flags = flags;
6339 +       inode->i_vflags = vflags;
6340 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6341 +
6342 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6343 +       if (status < 0)
6344 +               mlog_errno(status);
6345 +
6346 +       ocfs2_commit_trans(osb, handle);
6347 +bail_unlock:
6348 +       ocfs2_inode_unlock(inode, 1);
6349 +       brelse(bh);
6350 +       return status;
6351 +}
6352 +
6353 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6354                                 unsigned mask)
6355  {
6356         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6357 @@ -68,6 +102,11 @@ static int ocfs2_set_inode_attr(struct i
6358         if (!S_ISDIR(inode->i_mode))
6359                 flags &= ~OCFS2_DIRSYNC_FL;
6360  
6361 +       if (IS_BARRIER(inode)) {
6362 +               vxwprintk_task(1, "messing with the barrier.");
6363 +               goto bail_unlock;
6364 +       }
6365 +
6366         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6367         if (IS_ERR(handle)) {
6368                 status = PTR_ERR(handle);
6369 @@ -109,6 +148,7 @@ bail:
6370         return status;
6371  }
6372  
6373 +
6374  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6375  {
6376         struct inode *inode = filp->f_path.dentry->d_inode;
6377 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/namei.c linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/namei.c
6378 --- linux-2.6.33/fs/ocfs2/namei.c       2010-02-25 11:52:06.000000000 +0100
6379 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/namei.c 2010-02-25 12:02:16.000000000 +0100
6380 @@ -41,6 +41,7 @@
6381  #include <linux/slab.h>
6382  #include <linux/highmem.h>
6383  #include <linux/quotaops.h>
6384 +#include <linux/vs_tag.h>
6385  
6386  #define MLOG_MASK_PREFIX ML_NAMEI
6387  #include <cluster/masklog.h>
6388 @@ -481,6 +482,7 @@ static int ocfs2_mknod_locked(struct ocf
6389         u64 fe_blkno = 0;
6390         u16 suballoc_bit;
6391         u16 feat;
6392 +       tag_t tag;
6393  
6394         *new_fe_bh = NULL;
6395  
6396 @@ -524,8 +526,11 @@ static int ocfs2_mknod_locked(struct ocf
6397         fe->i_blkno = cpu_to_le64(fe_blkno);
6398         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6399         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6400 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6401 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6402 +
6403 +       tag = dx_current_fstag(osb->sb);
6404 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6405 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6406 +       inode->i_tag = tag;
6407         fe->i_mode = cpu_to_le16(inode->i_mode);
6408         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6409                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6410 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/ocfs2_fs.h linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/ocfs2_fs.h
6411 --- linux-2.6.33/fs/ocfs2/ocfs2_fs.h    2010-02-25 11:52:06.000000000 +0100
6412 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/ocfs2_fs.h      2010-02-25 12:02:16.000000000 +0100
6413 @@ -231,18 +231,23 @@
6414  #define OCFS2_HAS_REFCOUNT_FL   (0x0010)
6415  
6416  /* Inode attributes, keep in sync with EXT2 */
6417 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6418 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6419 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6420 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6421 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6422 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6423 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6424 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6425 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6426 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6427 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6428 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6429 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6430 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6431 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6432 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6433 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6434  
6435 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6436 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6437 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6438 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6439 +
6440 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6441 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6442 +
6443 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6444 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6445  
6446  /*
6447   * Extent record flags (e_node.leaf.flags)
6448 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/ocfs2.h linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/ocfs2.h
6449 --- linux-2.6.33/fs/ocfs2/ocfs2.h       2010-02-25 11:52:06.000000000 +0100
6450 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/ocfs2.h 2010-02-25 13:22:33.000000000 +0100
6451 @@ -254,6 +254,7 @@ enum ocfs2_mount_options
6452                                                    control lists */
6453         OCFS2_MOUNT_USRQUOTA = 1 << 10, /* We support user quotas */
6454         OCFS2_MOUNT_GRPQUOTA = 1 << 11, /* We support group quotas */
6455 +       OCFS2_MOUNT_TAGGED = 1 << 12, /* use tagging */
6456  };
6457  
6458  #define OCFS2_OSB_SOFT_RO                      0x0001
6459 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/super.c linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/super.c
6460 --- linux-2.6.33/fs/ocfs2/super.c       2010-02-25 11:52:06.000000000 +0100
6461 +++ linux-2.6.33-vs2.3.0.36.30/fs/ocfs2/super.c 2010-02-25 13:23:24.000000000 +0100
6462 @@ -175,6 +175,7 @@ enum {
6463         Opt_noacl,
6464         Opt_usrquota,
6465         Opt_grpquota,
6466 +       Opt_tag, Opt_notag, Opt_tagid,
6467         Opt_err,
6468  };
6469  
6470 @@ -201,6 +202,9 @@ static const match_table_t tokens = {
6471         {Opt_noacl, "noacl"},
6472         {Opt_usrquota, "usrquota"},
6473         {Opt_grpquota, "grpquota"},
6474 +       {Opt_tag, "tag"},
6475 +       {Opt_notag, "notag"},
6476 +       {Opt_tagid, "tagid=%u"},
6477         {Opt_err, NULL}
6478  };
6479  
6480 @@ -608,6 +612,13 @@ static int ocfs2_remount(struct super_bl
6481                 goto out;
6482         }
6483  
6484 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6485 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6486 +               ret = -EINVAL;
6487 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6488 +               goto out;
6489 +       }
6490 +
6491         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6492             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6493                 ret = -EINVAL;
6494 @@ -1138,6 +1149,9 @@ static int ocfs2_fill_super(struct super
6495  
6496         ocfs2_complete_mount_recovery(osb);
6497  
6498 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6499 +               sb->s_flags |= MS_TAGGED;
6500 +
6501         if (ocfs2_mount_local(osb))
6502                 snprintf(nodestr, sizeof(nodestr), "local");
6503         else
6504 @@ -1429,6 +1443,20 @@ static int ocfs2_parse_options(struct su
6505                         mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
6506                         mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
6507                         break;
6508 +#ifndef CONFIG_TAGGING_NONE
6509 +               case Opt_tag:
6510 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6511 +                       break;
6512 +               case Opt_notag:
6513 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6514 +                       break;
6515 +#endif
6516 +#ifdef CONFIG_PROPAGATE
6517 +               case Opt_tagid:
6518 +                       /* use args[0] */
6519 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6520 +                       break;
6521 +#endif
6522                 default:
6523                         mlog(ML_ERROR,
6524                              "Unrecognized mount option \"%s\" "
6525 diff -NurpP --minimal linux-2.6.33/fs/open.c linux-2.6.33-vs2.3.0.36.30/fs/open.c
6526 --- linux-2.6.33/fs/open.c      2010-02-25 11:52:06.000000000 +0100
6527 +++ linux-2.6.33-vs2.3.0.36.30/fs/open.c        2010-02-25 13:17:13.000000000 +0100
6528 @@ -31,6 +31,10 @@
6529  #include <linux/falloc.h>
6530  #include <linux/fs_struct.h>
6531  #include <linux/ima.h>
6532 +#include <linux/vs_base.h>
6533 +#include <linux/vs_limit.h>
6534 +#include <linux/vs_tag.h>
6535 +#include <linux/vs_cowbl.h>
6536  
6537  #include "internal.h"
6538  
6539 @@ -39,16 +43,20 @@ int vfs_statfs(struct dentry *dentry, st
6540         int retval = -ENODEV;
6541  
6542         if (dentry) {
6543 +               struct super_block *sb = dentry->d_sb;
6544 +
6545                 retval = -ENOSYS;
6546 -               if (dentry->d_sb->s_op->statfs) {
6547 +               if (sb->s_op->statfs) {
6548                         memset(buf, 0, sizeof(*buf));
6549                         retval = security_sb_statfs(dentry);
6550                         if (retval)
6551                                 return retval;
6552 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6553 +                       retval = sb->s_op->statfs(dentry, buf);
6554                         if (retval == 0 && buf->f_frsize == 0)
6555                                 buf->f_frsize = buf->f_bsize;
6556                 }
6557 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6558 +                       vx_vsi_statfs(sb, buf);
6559         }
6560         return retval;
6561  }
6562 @@ -650,6 +658,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6563         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6564         if (error)
6565                 goto out;
6566 +
6567 +       error = cow_check_and_break(&path);
6568 +       if (error)
6569 +               goto dput_and_out;
6570         inode = path.dentry->d_inode;
6571  
6572         error = mnt_want_write(path.mnt);
6573 @@ -687,11 +699,11 @@ static int chown_common(struct path *pat
6574         newattrs.ia_valid =  ATTR_CTIME;
6575         if (user != (uid_t) -1) {
6576                 newattrs.ia_valid |= ATTR_UID;
6577 -               newattrs.ia_uid = user;
6578 +               newattrs.ia_uid = dx_map_uid(user);
6579         }
6580         if (group != (gid_t) -1) {
6581                 newattrs.ia_valid |= ATTR_GID;
6582 -               newattrs.ia_gid = group;
6583 +               newattrs.ia_gid = dx_map_gid(group);
6584         }
6585         if (!S_ISDIR(inode->i_mode))
6586                 newattrs.ia_valid |=
6587 @@ -716,6 +728,10 @@ SYSCALL_DEFINE3(chown, const char __user
6588         error = mnt_want_write(path.mnt);
6589         if (error)
6590                 goto out_release;
6591 +#ifdef CONFIG_VSERVER_COWBL
6592 +       error = cow_check_and_break(&path);
6593 +       if (!error)
6594 +#endif
6595         error = chown_common(&path, user, group);
6596         mnt_drop_write(path.mnt);
6597  out_release:
6598 @@ -741,6 +757,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6599         error = mnt_want_write(path.mnt);
6600         if (error)
6601                 goto out_release;
6602 +#ifdef CONFIG_VSERVER_COWBL
6603 +       error = cow_check_and_break(&path);
6604 +       if (!error)
6605 +#endif
6606         error = chown_common(&path, user, group);
6607         mnt_drop_write(path.mnt);
6608  out_release:
6609 @@ -760,6 +780,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6610         error = mnt_want_write(path.mnt);
6611         if (error)
6612                 goto out_release;
6613 +#ifdef CONFIG_VSERVER_COWBL
6614 +       error = cow_check_and_break(&path);
6615 +       if (!error)
6616 +#endif
6617         error = chown_common(&path, user, group);
6618         mnt_drop_write(path.mnt);
6619  out_release:
6620 @@ -1006,6 +1030,7 @@ static void __put_unused_fd(struct files
6621         __FD_CLR(fd, fdt->open_fds);
6622         if (fd < files->next_fd)
6623                 files->next_fd = fd;
6624 +       vx_openfd_dec(fd);
6625  }
6626  
6627  void put_unused_fd(unsigned int fd)
6628 diff -NurpP --minimal linux-2.6.33/fs/proc/array.c linux-2.6.33-vs2.3.0.36.30/fs/proc/array.c
6629 --- linux-2.6.33/fs/proc/array.c        2010-02-25 11:52:06.000000000 +0100
6630 +++ linux-2.6.33-vs2.3.0.36.30/fs/proc/array.c  2010-02-25 12:02:16.000000000 +0100
6631 @@ -83,6 +83,8 @@
6632  #include <linux/ptrace.h>
6633  #include <linux/tracehook.h>
6634  #include <linux/swapops.h>
6635 +#include <linux/vs_context.h>
6636 +#include <linux/vs_network.h>
6637  
6638  #include <asm/pgtable.h>
6639  #include <asm/processor.h>
6640 @@ -172,6 +174,9 @@ static inline void task_state(struct seq
6641         rcu_read_lock();
6642         ppid = pid_alive(p) ?
6643                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6644 +       if (unlikely(vx_current_initpid(p->pid)))
6645 +               ppid = 0;
6646 +
6647         tpid = 0;
6648         if (pid_alive(p)) {
6649                 struct task_struct *tracer = tracehook_tracer_task(p);
6650 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6651  }
6652  
6653  static void render_cap_t(struct seq_file *m, const char *header,
6654 -                       kernel_cap_t *a)
6655 +                       struct vx_info *vxi, kernel_cap_t *a)
6656  {
6657         unsigned __capi;
6658  
6659 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6660         cap_bset        = cred->cap_bset;
6661         rcu_read_unlock();
6662  
6663 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6664 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6665 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6666 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6667 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6668 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6669 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6670 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6671 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6672  }
6673  
6674  static inline void task_context_switch_counts(struct seq_file *m,
6675 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6676         seq_printf(m, "\n");
6677  }
6678  
6679 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6680 +                       struct pid *pid, struct task_struct *task)
6681 +{
6682 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6683 +                       "Count:\t%u\n"
6684 +                       "uts:\t%p(%c)\n"
6685 +                       "ipc:\t%p(%c)\n"
6686 +                       "mnt:\t%p(%c)\n"
6687 +                       "pid:\t%p(%c)\n"
6688 +                       "net:\t%p(%c)\n",
6689 +                       task->nsproxy,
6690 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6691 +                       atomic_read(&task->nsproxy->count),
6692 +                       task->nsproxy->uts_ns,
6693 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6694 +                       task->nsproxy->ipc_ns,
6695 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6696 +                       task->nsproxy->mnt_ns,
6697 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6698 +                       task->nsproxy->pid_ns,
6699 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6700 +                       task->nsproxy->net_ns,
6701 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6702 +       return 0;
6703 +}
6704 +
6705 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6706 +{
6707 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6708 +               return;
6709 +
6710 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6711 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6712 +}
6713 +
6714 +
6715  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6716                         struct pid *pid, struct task_struct *task)
6717  {
6718 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6719         task_cap(m, task);
6720         task_cpus_allowed(m, task);
6721         cpuset_task_status_allowed(m, task);
6722 +       task_vs_id(m, task);
6723  #if defined(CONFIG_S390)
6724         task_show_regs(m, task);
6725  #endif
6726 @@ -465,6 +508,17 @@ static int do_task_stat(struct seq_file 
6727         /* convert nsec -> ticks */
6728         start_time = nsec_to_clock_t(start_time);
6729  
6730 +       /* fixup start time for virt uptime */
6731 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6732 +               unsigned long long bias =
6733 +                       current->vx_info->cvirt.bias_clock;
6734 +
6735 +               if (start_time > bias)
6736 +                       start_time -= bias;
6737 +               else
6738 +                       start_time = 0;
6739 +       }
6740 +
6741         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6742  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6743  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6744 diff -NurpP --minimal linux-2.6.33/fs/proc/base.c linux-2.6.33-vs2.3.0.36.30/fs/proc/base.c
6745 --- linux-2.6.33/fs/proc/base.c 2010-02-25 11:52:06.000000000 +0100
6746 +++ linux-2.6.33-vs2.3.0.36.30/fs/proc/base.c   2010-02-25 12:02:16.000000000 +0100
6747 @@ -81,6 +81,8 @@
6748  #include <linux/elf.h>
6749  #include <linux/pid_namespace.h>
6750  #include <linux/fs_struct.h>
6751 +#include <linux/vs_context.h>
6752 +#include <linux/vs_network.h>
6753  #include "internal.h"
6754  
6755  /* NOTE:
6756 @@ -1047,12 +1049,17 @@ static ssize_t oom_adjust_write(struct f
6757                 return -ESRCH;
6758         }
6759  
6760 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6761 +       if (oom_adjust < task->signal->oom_adj &&
6762 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6763                 unlock_task_sighand(task, &flags);
6764                 put_task_struct(task);
6765                 return -EACCES;
6766         }
6767  
6768 +       /* prevent guest processes from circumventing the oom killer */
6769 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6770 +               oom_adjust = OOM_ADJUST_MIN;
6771 +
6772         task->signal->oom_adj = oom_adjust;
6773  
6774         unlock_task_sighand(task, &flags);
6775 @@ -1092,7 +1099,7 @@ static ssize_t proc_loginuid_write(struc
6776         ssize_t length;
6777         uid_t loginuid;
6778  
6779 -       if (!capable(CAP_AUDIT_CONTROL))
6780 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6781                 return -EPERM;
6782  
6783         if (current != pid_task(proc_pid(inode), PIDTYPE_PID))
6784 @@ -1523,6 +1530,8 @@ static struct inode *proc_pid_make_inode
6785                 inode->i_gid = cred->egid;
6786                 rcu_read_unlock();
6787         }
6788 +       /* procfs is xid tagged */
6789 +       inode->i_tag = (tag_t)vx_task_xid(task);
6790         security_task_to_inode(task, inode);
6791  
6792  out:
6793 @@ -2073,6 +2082,13 @@ static struct dentry *proc_pident_lookup
6794         if (!task)
6795                 goto out_no_task;
6796  
6797 +       /* TODO: maybe we can come up with a generic approach? */
6798 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6799 +               (dentry->d_name.len == 5) &&
6800 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6801 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6802 +               goto out;
6803 +
6804         /*
6805          * Yes, it does not scale. And it should not. Don't add
6806          * new entries into /proc/<tgid>/ without very good reasons.
6807 @@ -2478,7 +2494,7 @@ out_iput:
6808  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6809  {
6810         struct dentry *error;
6811 -       struct task_struct *task = get_proc_task(dir);
6812 +       struct task_struct *task = get_proc_task_real(dir);
6813         const struct pid_entry *p, *last;
6814  
6815         error = ERR_PTR(-ENOENT);
6816 @@ -2568,6 +2584,9 @@ static int proc_pid_personality(struct s
6817  static const struct file_operations proc_task_operations;
6818  static const struct inode_operations proc_task_inode_operations;
6819  
6820 +extern int proc_pid_vx_info(struct task_struct *, char *);
6821 +extern int proc_pid_nx_info(struct task_struct *, char *);
6822 +
6823  static const struct pid_entry tgid_base_stuff[] = {
6824         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6825         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6826 @@ -2627,6 +2646,8 @@ static const struct pid_entry tgid_base_
6827  #ifdef CONFIG_CGROUPS
6828         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6829  #endif
6830 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6831 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6832         INF("oom_score",  S_IRUGO, proc_oom_score),
6833         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6834  #ifdef CONFIG_AUDITSYSCALL
6835 @@ -2642,6 +2663,7 @@ static const struct pid_entry tgid_base_
6836  #ifdef CONFIG_TASK_IO_ACCOUNTING
6837         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6838  #endif
6839 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6840  };
6841  
6842  static int proc_tgid_base_readdir(struct file * filp,
6843 @@ -2833,7 +2855,7 @@ retry:
6844         iter.task = NULL;
6845         pid = find_ge_pid(iter.tgid, ns);
6846         if (pid) {
6847 -               iter.tgid = pid_nr_ns(pid, ns);
6848 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6849                 iter.task = pid_task(pid, PIDTYPE_PID);
6850                 /* What we to know is if the pid we have find is the
6851                  * pid of a thread_group_leader.  Testing for task
6852 @@ -2863,7 +2885,7 @@ static int proc_pid_fill_cache(struct fi
6853         struct tgid_iter iter)
6854  {
6855         char name[PROC_NUMBUF];
6856 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6857 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6858         return proc_fill_cache(filp, dirent, filldir, name, len,
6859                                 proc_pid_instantiate, iter.task, NULL);
6860  }
6861 @@ -2872,7 +2894,7 @@ static int proc_pid_fill_cache(struct fi
6862  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6863  {
6864         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6865 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6866 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6867         struct tgid_iter iter;
6868         struct pid_namespace *ns;
6869  
6870 @@ -2892,6 +2914,8 @@ int proc_pid_readdir(struct file * filp,
6871              iter.task;
6872              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6873                 filp->f_pos = iter.tgid + TGID_OFFSET;
6874 +               if (!vx_proc_task_visible(iter.task))
6875 +                       continue;
6876                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6877                         put_task_struct(iter.task);
6878                         goto out;
6879 @@ -3039,6 +3063,8 @@ static struct dentry *proc_task_lookup(s
6880         tid = name_to_int(dentry);
6881         if (tid == ~0U)
6882                 goto out;
6883 +       if (vx_current_initpid(tid))
6884 +               goto out;
6885  
6886         ns = dentry->d_sb->s_fs_info;
6887         rcu_read_lock();
6888 diff -NurpP --minimal linux-2.6.33/fs/proc/generic.c linux-2.6.33-vs2.3.0.36.30/fs/proc/generic.c
6889 --- linux-2.6.33/fs/proc/generic.c      2010-02-25 11:52:06.000000000 +0100
6890 +++ linux-2.6.33-vs2.3.0.36.30/fs/proc/generic.c        2010-02-25 13:20:40.000000000 +0100
6891 @@ -20,6 +20,7 @@
6892  #include <linux/bitops.h>
6893  #include <linux/spinlock.h>
6894  #include <linux/completion.h>
6895 +#include <linux/vserver/inode.h>
6896  #include <asm/uaccess.h>
6897  
6898  #include "internal.h"
6899 @@ -425,6 +426,8 @@ struct dentry *proc_lookup_de(struct pro
6900         for (de = de->subdir; de ; de = de->next) {
6901                 if (de->namelen != dentry->d_name.len)
6902                         continue;
6903 +                       if (!vx_hide_check(0, de->vx_flags))
6904 +                               continue;
6905                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6906                         unsigned int ino;
6907  
6908 @@ -433,6 +436,8 @@ struct dentry *proc_lookup_de(struct pro
6909                         spin_unlock(&proc_subdir_lock);
6910                         error = -EINVAL;
6911                         inode = proc_get_inode(dir->i_sb, ino, de);
6912 +                               /* generic proc entries belong to the host */
6913 +                               inode->i_tag = 0;
6914                         goto out_unlock;
6915                 }
6916         }
6917 @@ -510,6 +515,8 @@ int proc_readdir_de(struct proc_dir_entr
6918  
6919                                 /* filldir passes info to user space */
6920                                 pde_get(de);
6921 +                               if (!vx_hide_check(0, de->vx_flags))
6922 +                                       goto skip;
6923                                 spin_unlock(&proc_subdir_lock);
6924                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6925                                             de->low_ino, de->mode >> 12) < 0) {
6926 @@ -517,6 +524,7 @@ int proc_readdir_de(struct proc_dir_entr
6927                                         goto out;
6928                                 }
6929                                 spin_lock(&proc_subdir_lock);
6930 +                       skip:
6931                                 filp->f_pos++;
6932                                 next = de->next;
6933                                 pde_put(de);
6934 @@ -631,6 +639,7 @@ static struct proc_dir_entry *__proc_cre
6935         ent->nlink = nlink;
6936         atomic_set(&ent->count, 1);
6937         ent->pde_users = 0;
6938 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6939         spin_lock_init(&ent->pde_unload_lock);
6940         ent->pde_unload_completion = NULL;
6941         INIT_LIST_HEAD(&ent->pde_openers);
6942 @@ -654,7 +663,8 @@ struct proc_dir_entry *proc_symlink(cons
6943                                 kfree(ent->data);
6944                                 kfree(ent);
6945                                 ent = NULL;
6946 -                       }
6947 +                       } else
6948 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6949                 } else {
6950                         kfree(ent);
6951                         ent = NULL;
6952 diff -NurpP --minimal linux-2.6.33/fs/proc/inode.c linux-2.6.33-vs2.3.0.36.30/fs/proc/inode.c
6953 --- linux-2.6.33/fs/proc/inode.c        2010-02-25 11:52:06.000000000 +0100
6954 +++ linux-2.6.33-vs2.3.0.36.30/fs/proc/inode.c  2010-02-25 12:02:16.000000000 +0100
6955 @@ -436,6 +436,8 @@ struct inode *proc_get_inode(struct supe
6956                         inode->i_uid = de->uid;
6957                         inode->i_gid = de->gid;
6958                 }
6959 +               if (de->vx_flags)
6960 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6961                 if (de->size)
6962                         inode->i_size = de->size;
6963                 if (de->nlink)
6964 diff -NurpP --minimal linux-2.6.33/fs/proc/internal.h linux-2.6.33-vs2.3.0.36.30/fs/proc/internal.h
6965 --- linux-2.6.33/fs/proc/internal.h     2010-02-25 11:52:06.000000000 +0100
6966 +++ linux-2.6.33-vs2.3.0.36.30/fs/proc/internal.h       2010-02-25 12:02:16.000000000 +0100
6967 @@ -10,6 +10,7 @@
6968   */
6969  
6970  #include <linux/proc_fs.h>
6971 +#include <linux/vs_pid.h>
6972  
6973  extern struct proc_dir_entry proc_root;
6974  #ifdef CONFIG_PROC_SYSCTL
6975 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6976                                 struct pid *pid, struct task_struct *task);
6977  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6978                                 struct pid *pid, struct task_struct *task);
6979 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6980 +                               struct pid *pid, struct task_struct *task);
6981 +
6982  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6983  
6984  extern const struct file_operations proc_maps_operations;
6985 @@ -68,11 +72,16 @@ static inline struct pid *proc_pid(struc
6986         return PROC_I(inode)->pid;
6987  }
6988  
6989 -static inline struct task_struct *get_proc_task(struct inode *inode)
6990 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6991  {
6992         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6993  }
6994  
6995 +static inline struct task_struct *get_proc_task(struct inode *inode)
6996 +{
6997 +       return vx_get_proc_task(inode, proc_pid(inode));
6998 +}
6999 +
7000  static inline int proc_fd(struct inode *inode)
7001  {
7002         return PROC_I(inode)->fd;
7003 diff -NurpP --minimal linux-2.6.33/fs/proc/loadavg.c linux-2.6.33-vs2.3.0.36.30/fs/proc/loadavg.c
7004 --- linux-2.6.33/fs/proc/loadavg.c      2009-09-10 15:26:23.000000000 +0200
7005 +++ linux-2.6.33-vs2.3.0.36.30/fs/proc/loadavg.c        2010-02-25 12:02:16.000000000 +0100
7006 @@ -12,15 +12,27 @@
7007  
7008  static int loadavg_proc_show(struct seq_file *m, void *v)
7009  {
7010 +       unsigned long running;
7011 +       unsigned int threads;
7012         unsigned long avnrun[3];
7013  
7014         get_avenrun(avnrun, FIXED_1/200, 0);
7015  
7016 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7017 +               struct vx_info *vxi = current_vx_info();
7018 +
7019 +               running = atomic_read(&vxi->cvirt.nr_running);
7020 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7021 +       } else {
7022 +               running = nr_running();
7023 +               threads = nr_threads;
7024 +       }
7025 +
7026         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7027                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7028                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7029                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7030 -               nr_running(), nr_threads,
7031 +               running, threads,
7032                 task_active_pid_ns(current)->last_pid);
7033         return 0;
7034  }
7035 diff -NurpP --minimal linux-2.6.33/fs/proc/meminfo.c linux-2.6.33-vs2.3.0.36.30/fs/proc/meminfo.c
7036 --- linux-2.6.33/fs/proc/meminfo.c      2009-12-03 20:02:53.000000000 +0100
7037 +++ linux-2.6.33-vs2.3.0.36.30/fs/proc/meminfo.c        2010-02-25 12:02:16.000000000 +0100
7038 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7039         allowed = ((totalram_pages - hugetlb_total_pages())
7040                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7041  
7042 -       cached = global_page_state(NR_FILE_PAGES) -
7043 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7044 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7045                         total_swapcache_pages - i.bufferram;
7046         if (cached < 0)
7047                 cached = 0;
7048 diff -NurpP --minimal linux-2.6.33/fs/proc/root.c linux-2.6.33-vs2.3.0.36.30/fs/proc/root.c
7049 --- linux-2.6.33/fs/proc/root.c 2009-06-11 17:13:07.000000000 +0200
7050 +++ linux-2.6.33-vs2.3.0.36.30/fs/proc/root.c   2010-02-25 12:02:16.000000000 +0100
7051 @@ -18,9 +18,14 @@
7052  #include <linux/bitops.h>
7053  #include <linux/mount.h>
7054  #include <linux/pid_namespace.h>
7055 +#include <linux/vserver/inode.h>
7056  
7057  #include "internal.h"
7058  
7059 +struct proc_dir_entry *proc_virtual;
7060 +
7061 +extern void proc_vx_init(void);
7062 +
7063  static int proc_test_super(struct super_block *sb, void *data)
7064  {
7065         return sb->s_fs_info == data;
7066 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
7067  #endif
7068         proc_mkdir("bus", NULL);
7069         proc_sys_init();
7070 +       proc_vx_init();
7071  }
7072  
7073  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7074 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7075         .proc_iops      = &proc_root_inode_operations, 
7076         .proc_fops      = &proc_root_operations,
7077         .parent         = &proc_root,
7078 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7079  };
7080  
7081  int pid_ns_prepare_proc(struct pid_namespace *ns)
7082 diff -NurpP --minimal linux-2.6.33/fs/proc/uptime.c linux-2.6.33-vs2.3.0.36.30/fs/proc/uptime.c
7083 --- linux-2.6.33/fs/proc/uptime.c       2009-12-03 20:02:53.000000000 +0100
7084 +++ linux-2.6.33-vs2.3.0.36.30/fs/proc/uptime.c 2010-02-25 12:02:16.000000000 +0100
7085 @@ -4,22 +4,22 @@
7086  #include <linux/sched.h>
7087  #include <linux/seq_file.h>
7088  #include <linux/time.h>
7089 -#include <linux/kernel_stat.h>
7090 +#include <linux/vserver/cvirt.h>
7091  #include <asm/cputime.h>
7092  
7093  static int uptime_proc_show(struct seq_file *m, void *v)
7094  {
7095         struct timespec uptime;
7096         struct timespec idle;
7097 -       int i;
7098 -       cputime_t idletime = cputime_zero;
7099 -
7100 -       for_each_possible_cpu(i)
7101 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7102 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7103  
7104         do_posix_clock_monotonic_gettime(&uptime);
7105         monotonic_to_bootbased(&uptime);
7106         cputime_to_timespec(idletime, &idle);
7107 +
7108 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7109 +               vx_vsi_uptime(&uptime, &idle);
7110 +
7111         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7112                         (unsigned long) uptime.tv_sec,
7113                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7114 diff -NurpP --minimal linux-2.6.33/fs/quota/quota.c linux-2.6.33-vs2.3.0.36.30/fs/quota/quota.c
7115 --- linux-2.6.33/fs/quota/quota.c       2010-02-25 11:52:06.000000000 +0100
7116 +++ linux-2.6.33-vs2.3.0.36.30/fs/quota/quota.c 2010-02-25 13:25:13.000000000 +0100
7117 @@ -18,6 +18,7 @@
7118  #include <linux/capability.h>
7119  #include <linux/quotaops.h>
7120  #include <linux/types.h>
7121 +#include <linux/vs_context.h>
7122  #include <net/netlink.h>
7123  #include <net/genetlink.h>
7124  
7125 @@ -85,11 +86,11 @@ static int generic_quotactl_valid(struct
7126         if (cmd == Q_GETQUOTA) {
7127                 if (((type == USRQUOTA && current_euid() != id) ||
7128                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7129 -                   !capable(CAP_SYS_ADMIN))
7130 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7131                         return -EPERM;
7132         }
7133         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7134 -               if (!capable(CAP_SYS_ADMIN))
7135 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7136                         return -EPERM;
7137  
7138         return 0;
7139 @@ -137,10 +138,10 @@ static int xqm_quotactl_valid(struct sup
7140         if (cmd == Q_XGETQUOTA) {
7141                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7142                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7143 -                    !capable(CAP_SYS_ADMIN))
7144 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7145                         return -EPERM;
7146         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7147 -               if (!capable(CAP_SYS_ADMIN))
7148 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7149                         return -EPERM;
7150         }
7151  
7152 @@ -353,6 +354,46 @@ static int do_quotactl(struct super_bloc
7153         return 0;
7154  }
7155  
7156 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7157 +
7158 +#include <linux/vroot.h>
7159 +#include <linux/major.h>
7160 +#include <linux/module.h>
7161 +#include <linux/kallsyms.h>
7162 +#include <linux/vserver/debug.h>
7163 +
7164 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7165 +
7166 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7167 +
7168 +int register_vroot_grb(vroot_grb_func *func) {
7169 +       int ret = -EBUSY;
7170 +
7171 +       spin_lock(&vroot_grb_lock);
7172 +       if (!vroot_get_real_bdev) {
7173 +               vroot_get_real_bdev = func;
7174 +               ret = 0;
7175 +       }
7176 +       spin_unlock(&vroot_grb_lock);
7177 +       return ret;
7178 +}
7179 +EXPORT_SYMBOL(register_vroot_grb);
7180 +
7181 +int unregister_vroot_grb(vroot_grb_func *func) {
7182 +       int ret = -EINVAL;
7183 +
7184 +       spin_lock(&vroot_grb_lock);
7185 +       if (vroot_get_real_bdev) {
7186 +               vroot_get_real_bdev = NULL;
7187 +               ret = 0;
7188 +       }
7189 +       spin_unlock(&vroot_grb_lock);
7190 +       return ret;
7191 +}
7192 +EXPORT_SYMBOL(unregister_vroot_grb);
7193 +
7194 +#endif
7195 +
7196  /*
7197   * look up a superblock on which quota ops will be performed
7198   * - use the name of a block device to find the superblock thereon
7199 @@ -370,6 +411,22 @@ static struct super_block *quotactl_bloc
7200         putname(tmp);
7201         if (IS_ERR(bdev))
7202                 return ERR_CAST(bdev);
7203 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7204 +       if (bdev && bdev->bd_inode &&
7205 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7206 +               struct block_device *bdnew = (void *)-EINVAL;
7207 +
7208 +               if (vroot_get_real_bdev)
7209 +                       bdnew = vroot_get_real_bdev(bdev);
7210 +               else
7211 +                       vxdprintk(VXD_CBIT(misc, 0),
7212 +                                       "vroot_get_real_bdev not set");
7213 +               bdput(bdev);
7214 +               if (IS_ERR(bdnew))
7215 +                       return ERR_PTR(PTR_ERR(bdnew));
7216 +               bdev = bdnew;
7217 +       }
7218 +#endif
7219         sb = get_super(bdev);
7220         bdput(bdev);
7221         if (!sb)
7222 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/file.c linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/file.c
7223 --- linux-2.6.33/fs/reiserfs/file.c     2010-02-25 11:52:06.000000000 +0100
7224 +++ linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/file.c       2010-02-25 12:02:16.000000000 +0100
7225 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7226         .listxattr = reiserfs_listxattr,
7227         .removexattr = reiserfs_removexattr,
7228         .permission = reiserfs_permission,
7229 +       .sync_flags = reiserfs_sync_flags,
7230  };
7231 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/inode.c linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/inode.c
7232 --- linux-2.6.33/fs/reiserfs/inode.c    2010-02-25 11:52:06.000000000 +0100
7233 +++ linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/inode.c      2010-02-25 12:02:16.000000000 +0100
7234 @@ -18,6 +18,7 @@
7235  #include <linux/writeback.h>
7236  #include <linux/quotaops.h>
7237  #include <linux/swap.h>
7238 +#include <linux/vs_tag.h>
7239  
7240  int reiserfs_commit_write(struct file *f, struct page *page,
7241                           unsigned from, unsigned to);
7242 @@ -1121,6 +1122,8 @@ static void init_inode(struct inode *ino
7243         struct buffer_head *bh;
7244         struct item_head *ih;
7245         __u32 rdev;
7246 +       uid_t uid;
7247 +       gid_t gid;
7248         //int version = ITEM_VERSION_1;
7249  
7250         bh = PATH_PLAST_BUFFER(path);
7251 @@ -1142,12 +1145,13 @@ static void init_inode(struct inode *ino
7252                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7253                 unsigned long blocks;
7254  
7255 +               uid = sd_v1_uid(sd);
7256 +               gid = sd_v1_gid(sd);
7257 +
7258                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7259                 set_inode_sd_version(inode, STAT_DATA_V1);
7260                 inode->i_mode = sd_v1_mode(sd);
7261                 inode->i_nlink = sd_v1_nlink(sd);
7262 -               inode->i_uid = sd_v1_uid(sd);
7263 -               inode->i_gid = sd_v1_gid(sd);
7264                 inode->i_size = sd_v1_size(sd);
7265                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7266                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7267 @@ -1189,11 +1193,12 @@ static void init_inode(struct inode *ino
7268                 // (directories and symlinks)
7269                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7270  
7271 +               uid    = sd_v2_uid(sd);
7272 +               gid    = sd_v2_gid(sd);
7273 +
7274                 inode->i_mode = sd_v2_mode(sd);
7275                 inode->i_nlink = sd_v2_nlink(sd);
7276 -               inode->i_uid = sd_v2_uid(sd);
7277                 inode->i_size = sd_v2_size(sd);
7278 -               inode->i_gid = sd_v2_gid(sd);
7279                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7280                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7281                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7282 @@ -1223,6 +1228,10 @@ static void init_inode(struct inode *ino
7283                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7284         }
7285  
7286 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7287 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7288 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7289 +
7290         pathrelse(path);
7291         if (S_ISREG(inode->i_mode)) {
7292                 inode->i_op = &reiserfs_file_inode_operations;
7293 @@ -1245,13 +1254,15 @@ static void init_inode(struct inode *ino
7294  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7295  {
7296         struct stat_data *sd_v2 = (struct stat_data *)sd;
7297 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7298 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7299         __u16 flags;
7300  
7301 +       set_sd_v2_uid(sd_v2, uid);
7302 +       set_sd_v2_gid(sd_v2, gid);
7303         set_sd_v2_mode(sd_v2, inode->i_mode);
7304         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7305 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7306         set_sd_v2_size(sd_v2, size);
7307 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7308         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7309         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7310         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7311 @@ -2852,14 +2863,19 @@ int reiserfs_commit_write(struct file *f
7312  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7313  {
7314         if (reiserfs_attrs(inode->i_sb)) {
7315 -               if (sd_attrs & REISERFS_SYNC_FL)
7316 -                       inode->i_flags |= S_SYNC;
7317 -               else
7318 -                       inode->i_flags &= ~S_SYNC;
7319                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7320                         inode->i_flags |= S_IMMUTABLE;
7321                 else
7322                         inode->i_flags &= ~S_IMMUTABLE;
7323 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7324 +                       inode->i_flags |= S_IXUNLINK;
7325 +               else
7326 +                       inode->i_flags &= ~S_IXUNLINK;
7327 +
7328 +               if (sd_attrs & REISERFS_SYNC_FL)
7329 +                       inode->i_flags |= S_SYNC;
7330 +               else
7331 +                       inode->i_flags &= ~S_SYNC;
7332                 if (sd_attrs & REISERFS_APPEND_FL)
7333                         inode->i_flags |= S_APPEND;
7334                 else
7335 @@ -2872,6 +2888,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7336                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7337                 else
7338                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7339 +
7340 +               if (sd_attrs & REISERFS_BARRIER_FL)
7341 +                       inode->i_vflags |= V_BARRIER;
7342 +               else
7343 +                       inode->i_vflags &= ~V_BARRIER;
7344 +               if (sd_attrs & REISERFS_COW_FL)
7345 +                       inode->i_vflags |= V_COW;
7346 +               else
7347 +                       inode->i_vflags &= ~V_COW;
7348         }
7349  }
7350  
7351 @@ -2882,6 +2907,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7352                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7353                 else
7354                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7355 +               if (inode->i_flags & S_IXUNLINK)
7356 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7357 +               else
7358 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7359 +
7360                 if (inode->i_flags & S_SYNC)
7361                         *sd_attrs |= REISERFS_SYNC_FL;
7362                 else
7363 @@ -2894,6 +2924,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7364                         *sd_attrs |= REISERFS_NOTAIL_FL;
7365                 else
7366                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7367 +
7368 +               if (inode->i_vflags & V_BARRIER)
7369 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7370 +               else
7371 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7372 +               if (inode->i_vflags & V_COW)
7373 +                       *sd_attrs |= REISERFS_COW_FL;
7374 +               else
7375 +                       *sd_attrs &= ~REISERFS_COW_FL;
7376         }
7377  }
7378  
7379 @@ -3115,9 +3154,11 @@ int reiserfs_setattr(struct dentry *dent
7380         }
7381  
7382         error = inode_change_ok(inode, attr);
7383 +
7384         if (!error) {
7385                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7386 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7387 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7388 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7389                         error = reiserfs_chown_xattrs(inode, attr);
7390  
7391                         if (!error) {
7392 @@ -3147,6 +3188,9 @@ int reiserfs_setattr(struct dentry *dent
7393                                         inode->i_uid = attr->ia_uid;
7394                                 if (attr->ia_valid & ATTR_GID)
7395                                         inode->i_gid = attr->ia_gid;
7396 +                               if ((attr->ia_valid & ATTR_TAG) &&
7397 +                                       IS_TAGGED(inode))
7398 +                                       inode->i_tag = attr->ia_tag;
7399                                 mark_inode_dirty(inode);
7400                                 error =
7401                                     journal_end(&th, inode->i_sb, jbegin_count);
7402 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/ioctl.c linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/ioctl.c
7403 --- linux-2.6.33/fs/reiserfs/ioctl.c    2010-02-25 11:52:06.000000000 +0100
7404 +++ linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/ioctl.c      2010-02-25 13:21:56.000000000 +0100
7405 @@ -7,11 +7,27 @@
7406  #include <linux/mount.h>
7407  #include <linux/reiserfs_fs.h>
7408  #include <linux/time.h>
7409 +#include <linux/mount.h>
7410  #include <asm/uaccess.h>
7411  #include <linux/pagemap.h>
7412  #include <linux/smp_lock.h>
7413  #include <linux/compat.h>
7414  
7415 +
7416 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7417 +{
7418 +       __u16 sd_attrs = 0;
7419 +
7420 +       inode->i_flags = flags;
7421 +       inode->i_vflags = vflags;
7422 +
7423 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7424 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7425 +       inode->i_ctime = CURRENT_TIME_SEC;
7426 +       mark_inode_dirty(inode);
7427 +       return 0;
7428 +}
7429 +
7430  /*
7431   * reiserfs_ioctl - handler for ioctl for inode
7432   * supported commands:
7433 @@ -23,7 +39,7 @@
7434  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7435  {
7436         struct inode *inode = filp->f_path.dentry->d_inode;
7437 -       unsigned int flags;
7438 +       unsigned int flags, oldflags;
7439         int err = 0;
7440  
7441         reiserfs_write_lock(inode->i_sb);
7442 @@ -48,6 +64,7 @@ long reiserfs_ioctl(struct file *filp, u
7443  
7444                 flags = REISERFS_I(inode)->i_attrs;
7445                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7446 +               flags &= REISERFS_FL_USER_VISIBLE;
7447                 err = put_user(flags, (int __user *)arg);
7448                 break;
7449         case REISERFS_IOC_SETFLAGS:{
7450 @@ -68,6 +85,10 @@ long reiserfs_ioctl(struct file *filp, u
7451                                 err = -EFAULT;
7452                                 goto setflags_out;
7453                         }
7454 +                       if (IS_BARRIER(inode)) {
7455 +                               vxwprintk_task(1, "messing with the barrier.");
7456 +                               return -EACCES;
7457 +                       }
7458                         /*
7459                          * Is it quota file? Do not allow user to mess with it
7460                          */
7461 @@ -92,6 +113,10 @@ long reiserfs_ioctl(struct file *filp, u
7462                                         goto setflags_out;
7463                                 }
7464                         }
7465 +
7466 +                       oldflags = REISERFS_I(inode)->i_attrs;
7467 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7468 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7469                         sd_attrs_to_i_attrs(flags, inode);
7470                         REISERFS_I(inode)->i_attrs = flags;
7471                         inode->i_ctime = CURRENT_TIME_SEC;
7472 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/namei.c linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/namei.c
7473 --- linux-2.6.33/fs/reiserfs/namei.c    2010-02-25 11:52:06.000000000 +0100
7474 +++ linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/namei.c      2010-02-25 12:02:16.000000000 +0100
7475 @@ -17,6 +17,7 @@
7476  #include <linux/reiserfs_acl.h>
7477  #include <linux/reiserfs_xattr.h>
7478  #include <linux/quotaops.h>
7479 +#include <linux/vs_tag.h>
7480  
7481  #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; }
7482  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7483 @@ -361,6 +362,7 @@ static struct dentry *reiserfs_lookup(st
7484         if (retval == IO_ERROR) {
7485                 return ERR_PTR(-EIO);
7486         }
7487 +               dx_propagate_tag(nd, inode);
7488  
7489         return d_splice_alias(inode, dentry);
7490  }
7491 @@ -577,6 +579,7 @@ static int new_inode_init(struct inode *
7492         } else {
7493                 inode->i_gid = current_fsgid();
7494         }
7495 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7496         vfs_dq_init(inode);
7497         return 0;
7498  }
7499 @@ -1524,6 +1527,7 @@ const struct inode_operations reiserfs_d
7500         .listxattr = reiserfs_listxattr,
7501         .removexattr = reiserfs_removexattr,
7502         .permission = reiserfs_permission,
7503 +       .sync_flags = reiserfs_sync_flags,
7504  };
7505  
7506  /*
7507 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/super.c linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/super.c
7508 --- linux-2.6.33/fs/reiserfs/super.c    2010-02-25 11:52:06.000000000 +0100
7509 +++ linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/super.c      2010-02-25 12:02:16.000000000 +0100
7510 @@ -887,6 +887,14 @@ static int reiserfs_parse_options(struct
7511                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7512                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7513  #endif
7514 +#ifndef CONFIG_TAGGING_NONE
7515 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7516 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7517 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7518 +#endif
7519 +#ifdef CONFIG_PROPAGATE
7520 +               {"tag",.arg_required = 'T',.values = NULL},
7521 +#endif
7522  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7523                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7524                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7525 @@ -1196,6 +1204,14 @@ static int reiserfs_remount(struct super
7526         handle_quota_files(s, qf_names, &qfmt);
7527  #endif
7528  
7529 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7530 +               !(s->s_flags & MS_TAGGED)) {
7531 +               reiserfs_warning(s, "super-vs01",
7532 +                       "reiserfs: tagging not permitted on remount.");
7533 +               err = -EINVAL;
7534 +               goto out_err;
7535 +       }
7536 +
7537         handle_attrs(s);
7538  
7539         /* Add options that are safe here */
7540 @@ -1674,6 +1690,10 @@ static int reiserfs_fill_super(struct su
7541                 goto error;
7542         }
7543  
7544 +       /* map mount option tagxid */
7545 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7546 +               s->s_flags |= MS_TAGGED;
7547 +
7548         rs = SB_DISK_SUPER_BLOCK(s);
7549         /* Let's do basic sanity check to verify that underlying device is not
7550            smaller than the filesystem. If the check fails then abort and scream,
7551 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/xattr.c linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/xattr.c
7552 --- linux-2.6.33/fs/reiserfs/xattr.c    2010-02-25 11:52:06.000000000 +0100
7553 +++ linux-2.6.33-vs2.3.0.36.30/fs/reiserfs/xattr.c      2010-02-25 12:02:16.000000000 +0100
7554 @@ -39,6 +39,7 @@
7555  #include <linux/namei.h>
7556  #include <linux/errno.h>
7557  #include <linux/fs.h>
7558 +#include <linux/mount.h>
7559  #include <linux/file.h>
7560  #include <linux/pagemap.h>
7561  #include <linux/xattr.h>
7562 diff -NurpP --minimal linux-2.6.33/fs/stat.c linux-2.6.33-vs2.3.0.36.30/fs/stat.c
7563 --- linux-2.6.33/fs/stat.c      2010-02-25 11:52:06.000000000 +0100
7564 +++ linux-2.6.33-vs2.3.0.36.30/fs/stat.c        2010-02-25 12:02:16.000000000 +0100
7565 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7566         stat->nlink = inode->i_nlink;
7567         stat->uid = inode->i_uid;
7568         stat->gid = inode->i_gid;
7569 +       stat->tag = inode->i_tag;
7570         stat->rdev = inode->i_rdev;
7571         stat->atime = inode->i_atime;
7572         stat->mtime = inode->i_mtime;
7573 diff -NurpP --minimal linux-2.6.33/fs/super.c linux-2.6.33-vs2.3.0.36.30/fs/super.c
7574 --- linux-2.6.33/fs/super.c     2010-02-25 11:52:06.000000000 +0100
7575 +++ linux-2.6.33-vs2.3.0.36.30/fs/super.c       2010-02-25 12:02:16.000000000 +0100
7576 @@ -37,6 +37,9 @@
7577  #include <linux/kobject.h>
7578  #include <linux/mutex.h>
7579  #include <linux/file.h>
7580 +#include <linux/devpts_fs.h>
7581 +#include <linux/proc_fs.h>
7582 +#include <linux/vs_context.h>
7583  #include <asm/uaccess.h>
7584  #include "internal.h"
7585  
7586 @@ -914,12 +917,18 @@ struct vfsmount *
7587  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7588  {
7589         struct vfsmount *mnt;
7590 +       struct super_block *sb;
7591         char *secdata = NULL;
7592         int error;
7593  
7594         if (!type)
7595                 return ERR_PTR(-ENODEV);
7596  
7597 +       error = -EPERM;
7598 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7599 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7600 +               goto out;
7601 +
7602         error = -ENOMEM;
7603         mnt = alloc_vfsmnt(name);
7604         if (!mnt)
7605 @@ -938,9 +947,17 @@ vfs_kern_mount(struct file_system_type *
7606         error = type->get_sb(type, flags, name, data, mnt);
7607         if (error < 0)
7608                 goto out_free_secdata;
7609 -       BUG_ON(!mnt->mnt_sb);
7610  
7611 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7612 +       sb = mnt->mnt_sb;
7613 +       BUG_ON(!sb);
7614 +
7615 +       error = -EPERM;
7616 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7617 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7618 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7619 +               goto out_sb;
7620 +
7621 +       error = security_sb_kern_mount(sb, flags, secdata);
7622         if (error)
7623                 goto out_sb;
7624  
7625 diff -NurpP --minimal linux-2.6.33/fs/sysfs/mount.c linux-2.6.33-vs2.3.0.36.30/fs/sysfs/mount.c
7626 --- linux-2.6.33/fs/sysfs/mount.c       2009-06-11 17:13:08.000000000 +0200
7627 +++ linux-2.6.33-vs2.3.0.36.30/fs/sysfs/mount.c 2010-02-25 12:02:16.000000000 +0100
7628 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7629  
7630         sb->s_blocksize = PAGE_CACHE_SIZE;
7631         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7632 -       sb->s_magic = SYSFS_MAGIC;
7633 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7634         sb->s_op = &sysfs_ops;
7635         sb->s_time_gran = 1;
7636         sysfs_sb = sb;
7637 diff -NurpP --minimal linux-2.6.33/fs/utimes.c linux-2.6.33-vs2.3.0.36.30/fs/utimes.c
7638 --- linux-2.6.33/fs/utimes.c    2009-03-24 14:22:37.000000000 +0100
7639 +++ linux-2.6.33-vs2.3.0.36.30/fs/utimes.c      2010-02-25 12:02:16.000000000 +0100
7640 @@ -8,6 +8,8 @@
7641  #include <linux/stat.h>
7642  #include <linux/utime.h>
7643  #include <linux/syscalls.h>
7644 +#include <linux/mount.h>
7645 +#include <linux/vs_cowbl.h>
7646  #include <asm/uaccess.h>
7647  #include <asm/unistd.h>
7648  
7649 diff -NurpP --minimal linux-2.6.33/fs/xattr.c linux-2.6.33-vs2.3.0.36.30/fs/xattr.c
7650 --- linux-2.6.33/fs/xattr.c     2010-02-25 11:52:06.000000000 +0100
7651 +++ linux-2.6.33-vs2.3.0.36.30/fs/xattr.c       2010-02-25 12:02:16.000000000 +0100
7652 @@ -18,6 +18,7 @@
7653  #include <linux/module.h>
7654  #include <linux/fsnotify.h>
7655  #include <linux/audit.h>
7656 +#include <linux/mount.h>
7657  #include <asm/uaccess.h>
7658  
7659  
7660 diff -NurpP --minimal linux-2.6.33/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.33-vs2.3.0.36.30/fs/xfs/linux-2.6/xfs_ioctl.c
7661 --- linux-2.6.33/fs/xfs/linux-2.6/xfs_ioctl.c   2010-02-25 11:52:06.000000000 +0100
7662 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/linux-2.6/xfs_ioctl.c     2010-02-25 12:02:16.000000000 +0100
7663 @@ -34,7 +34,6 @@
7664  #include "xfs_dir2_sf.h"
7665  #include "xfs_dinode.h"
7666  #include "xfs_inode.h"
7667 -#include "xfs_ioctl.h"
7668  #include "xfs_btree.h"
7669  #include "xfs_ialloc.h"
7670  #include "xfs_rtalloc.h"
7671 @@ -743,6 +742,10 @@ xfs_merge_ioc_xflags(
7672                 xflags |= XFS_XFLAG_IMMUTABLE;
7673         else
7674                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7675 +       if (flags & FS_IXUNLINK_FL)
7676 +               xflags |= XFS_XFLAG_IXUNLINK;
7677 +       else
7678 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7679         if (flags & FS_APPEND_FL)
7680                 xflags |= XFS_XFLAG_APPEND;
7681         else
7682 @@ -771,6 +774,8 @@ xfs_di2lxflags(
7683  
7684         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7685                 flags |= FS_IMMUTABLE_FL;
7686 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7687 +               flags |= FS_IXUNLINK_FL;
7688         if (di_flags & XFS_DIFLAG_APPEND)
7689                 flags |= FS_APPEND_FL;
7690         if (di_flags & XFS_DIFLAG_SYNC)
7691 @@ -829,6 +834,8 @@ xfs_set_diflags(
7692         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7693         if (xflags & XFS_XFLAG_IMMUTABLE)
7694                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7695 +       if (xflags & XFS_XFLAG_IXUNLINK)
7696 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7697         if (xflags & XFS_XFLAG_APPEND)
7698                 di_flags |= XFS_DIFLAG_APPEND;
7699         if (xflags & XFS_XFLAG_SYNC)
7700 @@ -871,6 +878,10 @@ xfs_diflags_to_linux(
7701                 inode->i_flags |= S_IMMUTABLE;
7702         else
7703                 inode->i_flags &= ~S_IMMUTABLE;
7704 +       if (xflags & XFS_XFLAG_IXUNLINK)
7705 +               inode->i_flags |= S_IXUNLINK;
7706 +       else
7707 +               inode->i_flags &= ~S_IXUNLINK;
7708         if (xflags & XFS_XFLAG_APPEND)
7709                 inode->i_flags |= S_APPEND;
7710         else
7711 @@ -1347,10 +1358,18 @@ xfs_file_ioctl(
7712         case XFS_IOC_FSGETXATTRA:
7713                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7714         case XFS_IOC_FSSETXATTR:
7715 +               if (IS_BARRIER(inode)) {
7716 +                       vxwprintk_task(1, "messing with the barrier.");
7717 +                       return -XFS_ERROR(EACCES);
7718 +               }
7719                 return xfs_ioc_fssetxattr(ip, filp, arg);
7720         case XFS_IOC_GETXFLAGS:
7721                 return xfs_ioc_getxflags(ip, arg);
7722         case XFS_IOC_SETXFLAGS:
7723 +               if (IS_BARRIER(inode)) {
7724 +                       vxwprintk_task(1, "messing with the barrier.");
7725 +                       return -XFS_ERROR(EACCES);
7726 +               }
7727                 return xfs_ioc_setxflags(ip, filp, arg);
7728  
7729         case XFS_IOC_FSSETDM: {
7730 diff -NurpP --minimal linux-2.6.33/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.33-vs2.3.0.36.30/fs/xfs/linux-2.6/xfs_ioctl.h
7731 --- linux-2.6.33/fs/xfs/linux-2.6/xfs_ioctl.h   2009-03-24 14:22:37.000000000 +0100
7732 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/linux-2.6/xfs_ioctl.h     2010-02-25 12:02:16.000000000 +0100
7733 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7734         void __user             *uhandle,
7735         u32                     hlen);
7736  
7737 +extern int
7738 +xfs_sync_flags(
7739 +       struct inode            *inode,
7740 +       int                     flags,
7741 +       int                     vflags);
7742 +
7743  extern long
7744  xfs_file_ioctl(
7745         struct file             *filp,
7746 diff -NurpP --minimal linux-2.6.33/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.33-vs2.3.0.36.30/fs/xfs/linux-2.6/xfs_iops.c
7747 --- linux-2.6.33/fs/xfs/linux-2.6/xfs_iops.c    2010-02-25 11:52:06.000000000 +0100
7748 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/linux-2.6/xfs_iops.c      2010-02-25 12:02:16.000000000 +0100
7749 @@ -36,6 +36,7 @@
7750  #include "xfs_attr_sf.h"
7751  #include "xfs_dinode.h"
7752  #include "xfs_inode.h"
7753 +#include "xfs_ioctl.h"
7754  #include "xfs_bmap.h"
7755  #include "xfs_btree.h"
7756  #include "xfs_ialloc.h"
7757 @@ -56,6 +57,7 @@
7758  #include <linux/security.h>
7759  #include <linux/falloc.h>
7760  #include <linux/fiemap.h>
7761 +#include <linux/vs_tag.h>
7762  
7763  /*
7764   * Bring the timestamps in the XFS inode uptodate.
7765 @@ -496,6 +498,7 @@ xfs_vn_getattr(
7766         stat->nlink = ip->i_d.di_nlink;
7767         stat->uid = ip->i_d.di_uid;
7768         stat->gid = ip->i_d.di_gid;
7769 +       stat->tag = ip->i_d.di_tag;
7770         stat->ino = ip->i_ino;
7771         stat->atime = inode->i_atime;
7772         stat->mtime = inode->i_mtime;
7773 @@ -687,6 +690,7 @@ static const struct inode_operations xfs
7774         .listxattr              = xfs_vn_listxattr,
7775         .fallocate              = xfs_vn_fallocate,
7776         .fiemap                 = xfs_vn_fiemap,
7777 +       .sync_flags             = xfs_sync_flags,
7778  };
7779  
7780  static const struct inode_operations xfs_dir_inode_operations = {
7781 @@ -712,6 +716,7 @@ static const struct inode_operations xfs
7782         .getxattr               = generic_getxattr,
7783         .removexattr            = generic_removexattr,
7784         .listxattr              = xfs_vn_listxattr,
7785 +       .sync_flags             = xfs_sync_flags,
7786  };
7787  
7788  static const struct inode_operations xfs_dir_ci_inode_operations = {
7789 @@ -761,6 +766,10 @@ xfs_diflags_to_iflags(
7790                 inode->i_flags |= S_IMMUTABLE;
7791         else
7792                 inode->i_flags &= ~S_IMMUTABLE;
7793 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7794 +               inode->i_flags |= S_IXUNLINK;
7795 +       else
7796 +               inode->i_flags &= ~S_IXUNLINK;
7797         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7798                 inode->i_flags |= S_APPEND;
7799         else
7800 @@ -773,6 +782,15 @@ xfs_diflags_to_iflags(
7801                 inode->i_flags |= S_NOATIME;
7802         else
7803                 inode->i_flags &= ~S_NOATIME;
7804 +
7805 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7806 +               inode->i_vflags |= V_BARRIER;
7807 +       else
7808 +               inode->i_vflags &= ~V_BARRIER;
7809 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7810 +               inode->i_vflags |= V_COW;
7811 +       else
7812 +               inode->i_vflags &= ~V_COW;
7813  }
7814  
7815  /*
7816 @@ -801,6 +819,7 @@ xfs_setup_inode(
7817         inode->i_nlink  = ip->i_d.di_nlink;
7818         inode->i_uid    = ip->i_d.di_uid;
7819         inode->i_gid    = ip->i_d.di_gid;
7820 +       inode->i_tag    = ip->i_d.di_tag;
7821  
7822         switch (inode->i_mode & S_IFMT) {
7823         case S_IFBLK:
7824 diff -NurpP --minimal linux-2.6.33/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.33-vs2.3.0.36.30/fs/xfs/linux-2.6/xfs_linux.h
7825 --- linux-2.6.33/fs/xfs/linux-2.6/xfs_linux.h   2010-02-25 11:52:06.000000000 +0100
7826 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/linux-2.6/xfs_linux.h     2010-02-25 12:02:16.000000000 +0100
7827 @@ -118,6 +118,7 @@
7828  
7829  #define current_cpu()          (raw_smp_processor_id())
7830  #define current_pid()          (current->pid)
7831 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
7832  #define current_test_flags(f)  (current->flags & (f))
7833  #define current_set_flags_nested(sp, f)                \
7834                 (*(sp) = current->flags, current->flags |= (f))
7835 diff -NurpP --minimal linux-2.6.33/fs/xfs/linux-2.6/xfs_super.c linux-2.6.33-vs2.3.0.36.30/fs/xfs/linux-2.6/xfs_super.c
7836 --- linux-2.6.33/fs/xfs/linux-2.6/xfs_super.c   2010-02-25 11:52:06.000000000 +0100
7837 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/linux-2.6/xfs_super.c     2010-02-25 12:02:16.000000000 +0100
7838 @@ -118,6 +118,9 @@ mempool_t *xfs_ioend_pool;
7839  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
7840  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
7841  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
7842 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7843 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7844 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7845  
7846  /*
7847   * Table driven mount option parser.
7848 @@ -126,10 +129,14 @@ mempool_t *xfs_ioend_pool;
7849   * in the future, too.
7850   */
7851  enum {
7852 +       Opt_tag, Opt_notag,
7853         Opt_barrier, Opt_nobarrier, Opt_err
7854  };
7855  
7856  static const match_table_t tokens = {
7857 +       {Opt_tag, "tagxid"},
7858 +       {Opt_tag, "tag"},
7859 +       {Opt_notag, "notag"},
7860         {Opt_barrier, "barrier"},
7861         {Opt_nobarrier, "nobarrier"},
7862         {Opt_err, NULL}
7863 @@ -383,6 +390,19 @@ xfs_parseargs(
7864                 } else if (!strcmp(this_char, "irixsgid")) {
7865                         cmn_err(CE_WARN,
7866         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7867 +#ifndef CONFIG_TAGGING_NONE
7868 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7869 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7870 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7871 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7872 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7873 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7874 +#endif
7875 +#ifdef CONFIG_PROPAGATE
7876 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7877 +                       /* use value */
7878 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7879 +#endif
7880                 } else {
7881                         cmn_err(CE_WARN,
7882                                 "XFS: unknown mount option [%s].", this_char);
7883 @@ -1290,6 +1310,16 @@ xfs_fs_remount(
7884                 case Opt_nobarrier:
7885                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7886                         break;
7887 +               case Opt_tag:
7888 +                       if (!(sb->s_flags & MS_TAGGED)) {
7889 +                               printk(KERN_INFO
7890 +                                       "XFS: %s: tagging not permitted on remount.\n",
7891 +                                       sb->s_id);
7892 +                               return -EINVAL;
7893 +                       }
7894 +                       break;
7895 +               case Opt_notag:
7896 +                       break;
7897                 default:
7898                         /*
7899                          * Logically we would return an error here to prevent
7900 @@ -1497,6 +1527,9 @@ xfs_fs_fill_super(
7901  
7902         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
7903  
7904 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7905 +               sb->s_flags |= MS_TAGGED;
7906 +
7907         sb->s_magic = XFS_SB_MAGIC;
7908         sb->s_blocksize = mp->m_sb.sb_blocksize;
7909         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
7910 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_dinode.h linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_dinode.h
7911 --- linux-2.6.33/fs/xfs/xfs_dinode.h    2009-06-11 17:13:09.000000000 +0200
7912 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_dinode.h      2010-02-25 12:02:16.000000000 +0100
7913 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
7914         __be32          di_gid;         /* owner's group id */
7915         __be32          di_nlink;       /* number of links to file */
7916         __be16          di_projid;      /* owner's project id */
7917 -       __u8            di_pad[8];      /* unused, zeroed space */
7918 +       __be16          di_tag;         /* context tagging */
7919 +       __be16          di_vflags;      /* vserver specific flags */
7920 +       __u8            di_pad[4];      /* unused, zeroed space */
7921         __be16          di_flushiter;   /* incremented on flush */
7922         xfs_timestamp_t di_atime;       /* time last accessed */
7923         xfs_timestamp_t di_mtime;       /* time last modified */
7924 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
7925  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7926  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7927  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7928 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7929 +
7930  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7931  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7932  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7933 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
7934  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7935  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7936  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7937 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7938  
7939  #ifdef CONFIG_XFS_RT
7940  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7941 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
7942          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7943          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7944          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7945 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7946 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7947 +        XFS_DIFLAG_IXUNLINK)
7948 +
7949 +#define XFS_DIVFLAG_BARRIER    0x01
7950 +#define XFS_DIVFLAG_COW                0x02
7951  
7952  #endif /* __XFS_DINODE_H__ */
7953 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_fs.h linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_fs.h
7954 --- linux-2.6.33/fs/xfs/xfs_fs.h        2009-12-03 20:02:53.000000000 +0100
7955 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_fs.h  2010-02-25 12:02:16.000000000 +0100
7956 @@ -67,6 +67,9 @@ struct fsxattr {
7957  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7958  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7959  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7960 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7961 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7962 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7963  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7964  
7965  /*
7966 @@ -292,7 +295,8 @@ typedef struct xfs_bstat {
7967         __s32           bs_extents;     /* number of extents            */
7968         __u32           bs_gen;         /* generation count             */
7969         __u16           bs_projid;      /* project id                   */
7970 -       unsigned char   bs_pad[14];     /* pad space, unused            */
7971 +       __u16           bs_tag;         /* context tagging              */
7972 +       unsigned char   bs_pad[12];     /* pad space, unused            */
7973         __u32           bs_dmevmask;    /* DMIG event mask              */
7974         __u16           bs_dmstate;     /* DMIG state info              */
7975         __u16           bs_aextents;    /* attribute number of extents  */
7976 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_ialloc.c linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_ialloc.c
7977 --- linux-2.6.33/fs/xfs/xfs_ialloc.c    2010-02-25 11:52:06.000000000 +0100
7978 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_ialloc.c      2010-02-25 12:02:16.000000000 +0100
7979 @@ -41,7 +41,6 @@
7980  #include "xfs_error.h"
7981  #include "xfs_bmap.h"
7982  
7983 -
7984  /*
7985   * Allocation group level functions.
7986   */
7987 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_inode.c linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_inode.c
7988 --- linux-2.6.33/fs/xfs/xfs_inode.c     2010-02-25 11:52:06.000000000 +0100
7989 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_inode.c       2010-02-25 12:02:16.000000000 +0100
7990 @@ -249,6 +249,7 @@ xfs_inotobp(
7991         return 0;
7992  }
7993  
7994 +#include <linux/vs_tag.h>
7995  
7996  /*
7997   * This routine is called to map an inode to the buffer containing
7998 @@ -654,15 +655,25 @@ xfs_iformat_btree(
7999  STATIC void
8000  xfs_dinode_from_disk(
8001         xfs_icdinode_t          *to,
8002 -       xfs_dinode_t            *from)
8003 +       xfs_dinode_t            *from,
8004 +       int tagged)
8005  {
8006 +       uint32_t uid, gid, tag;
8007 +
8008         to->di_magic = be16_to_cpu(from->di_magic);
8009         to->di_mode = be16_to_cpu(from->di_mode);
8010         to->di_version = from ->di_version;
8011         to->di_format = from->di_format;
8012         to->di_onlink = be16_to_cpu(from->di_onlink);
8013 -       to->di_uid = be32_to_cpu(from->di_uid);
8014 -       to->di_gid = be32_to_cpu(from->di_gid);
8015 +
8016 +       uid = be32_to_cpu(from->di_uid);
8017 +       gid = be32_to_cpu(from->di_gid);
8018 +       tag = be16_to_cpu(from->di_tag);
8019 +
8020 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8021 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8022 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8023 +
8024         to->di_nlink = be32_to_cpu(from->di_nlink);
8025         to->di_projid = be16_to_cpu(from->di_projid);
8026         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8027 @@ -683,21 +694,26 @@ xfs_dinode_from_disk(
8028         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8029         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8030         to->di_flags    = be16_to_cpu(from->di_flags);
8031 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8032         to->di_gen      = be32_to_cpu(from->di_gen);
8033  }
8034  
8035  void
8036  xfs_dinode_to_disk(
8037         xfs_dinode_t            *to,
8038 -       xfs_icdinode_t          *from)
8039 +       xfs_icdinode_t          *from,
8040 +       int tagged)
8041  {
8042         to->di_magic = cpu_to_be16(from->di_magic);
8043         to->di_mode = cpu_to_be16(from->di_mode);
8044         to->di_version = from ->di_version;
8045         to->di_format = from->di_format;
8046         to->di_onlink = cpu_to_be16(from->di_onlink);
8047 -       to->di_uid = cpu_to_be32(from->di_uid);
8048 -       to->di_gid = cpu_to_be32(from->di_gid);
8049 +
8050 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8051 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8052 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8053 +
8054         to->di_nlink = cpu_to_be32(from->di_nlink);
8055         to->di_projid = cpu_to_be16(from->di_projid);
8056         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8057 @@ -718,12 +734,14 @@ xfs_dinode_to_disk(
8058         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8059         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8060         to->di_flags = cpu_to_be16(from->di_flags);
8061 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8062         to->di_gen = cpu_to_be32(from->di_gen);
8063  }
8064  
8065  STATIC uint
8066  _xfs_dic2xflags(
8067 -       __uint16_t              di_flags)
8068 +       __uint16_t              di_flags,
8069 +       __uint16_t              di_vflags)
8070  {
8071         uint                    flags = 0;
8072  
8073 @@ -734,6 +752,8 @@ _xfs_dic2xflags(
8074                         flags |= XFS_XFLAG_PREALLOC;
8075                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8076                         flags |= XFS_XFLAG_IMMUTABLE;
8077 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8078 +                       flags |= XFS_XFLAG_IXUNLINK;
8079                 if (di_flags & XFS_DIFLAG_APPEND)
8080                         flags |= XFS_XFLAG_APPEND;
8081                 if (di_flags & XFS_DIFLAG_SYNC)
8082 @@ -758,6 +778,10 @@ _xfs_dic2xflags(
8083                         flags |= XFS_XFLAG_FILESTREAM;
8084         }
8085  
8086 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8087 +               flags |= FS_BARRIER_FL;
8088 +       if (di_vflags & XFS_DIVFLAG_COW)
8089 +               flags |= FS_COW_FL;
8090         return flags;
8091  }
8092  
8093 @@ -767,7 +791,7 @@ xfs_ip2xflags(
8094  {
8095         xfs_icdinode_t          *dic = &ip->i_d;
8096  
8097 -       return _xfs_dic2xflags(dic->di_flags) |
8098 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8099                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8100  }
8101  
8102 @@ -775,7 +799,8 @@ uint
8103  xfs_dic2xflags(
8104         xfs_dinode_t            *dip)
8105  {
8106 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8107 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8108 +                               be16_to_cpu(dip->di_vflags)) |
8109                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8110  }
8111  
8112 @@ -811,7 +836,6 @@ xfs_iread(
8113         if (error)
8114                 return error;
8115         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8116 -
8117         /*
8118          * If we got something that isn't an inode it means someone
8119          * (nfs or dmi) has a stale handle.
8120 @@ -836,7 +860,8 @@ xfs_iread(
8121          * Otherwise, just get the truly permanent information.
8122          */
8123         if (dip->di_mode) {
8124 -               xfs_dinode_from_disk(&ip->i_d, dip);
8125 +               xfs_dinode_from_disk(&ip->i_d, dip,
8126 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8127                 error = xfs_iformat(ip, dip);
8128                 if (error)  {
8129  #ifdef DEBUG
8130 @@ -1036,6 +1061,7 @@ xfs_ialloc(
8131         ASSERT(ip->i_d.di_nlink == nlink);
8132         ip->i_d.di_uid = current_fsuid();
8133         ip->i_d.di_gid = current_fsgid();
8134 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8135         ip->i_d.di_projid = prid;
8136         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8137  
8138 @@ -1096,6 +1122,7 @@ xfs_ialloc(
8139         ip->i_d.di_dmevmask = 0;
8140         ip->i_d.di_dmstate = 0;
8141         ip->i_d.di_flags = 0;
8142 +       ip->i_d.di_vflags = 0;
8143         flags = XFS_ILOG_CORE;
8144         switch (mode & S_IFMT) {
8145         case S_IFIFO:
8146 @@ -2136,6 +2163,7 @@ xfs_ifree(
8147         }
8148         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8149         ip->i_d.di_flags = 0;
8150 +       ip->i_d.di_vflags = 0;
8151         ip->i_d.di_dmevmask = 0;
8152         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8153         ip->i_df.if_ext_max =
8154 @@ -3116,7 +3144,8 @@ xfs_iflush_int(
8155          * because if the inode is dirty at all the core must
8156          * be.
8157          */
8158 -       xfs_dinode_to_disk(dip, &ip->i_d);
8159 +       xfs_dinode_to_disk(dip, &ip->i_d,
8160 +               mp->m_flags & XFS_MOUNT_TAGGED);
8161  
8162         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8163         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8164 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_inode.h linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_inode.h
8165 --- linux-2.6.33/fs/xfs/xfs_inode.h     2010-02-25 11:52:06.000000000 +0100
8166 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_inode.h       2010-02-25 12:02:16.000000000 +0100
8167 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8168         __uint32_t      di_gid;         /* owner's group id */
8169         __uint32_t      di_nlink;       /* number of links to file */
8170         __uint16_t      di_projid;      /* owner's project id */
8171 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8172 +       __uint16_t      di_tag;         /* context tagging */
8173 +       __uint16_t      di_vflags;      /* vserver specific flags */
8174 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8175         __uint16_t      di_flushiter;   /* incremented on flush */
8176         xfs_ictimestamp_t di_atime;     /* time last accessed */
8177         xfs_ictimestamp_t di_mtime;     /* time last modified */
8178 @@ -521,7 +523,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8179  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8180                           struct xfs_inode *, xfs_daddr_t, uint);
8181  void           xfs_dinode_to_disk(struct xfs_dinode *,
8182 -                                  struct xfs_icdinode *);
8183 +                                  struct xfs_icdinode *, int);
8184  void           xfs_idestroy_fork(struct xfs_inode *, int);
8185  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8186  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8187 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_itable.c linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_itable.c
8188 --- linux-2.6.33/fs/xfs/xfs_itable.c    2009-12-03 20:02:54.000000000 +0100
8189 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_itable.c      2010-02-25 12:02:16.000000000 +0100
8190 @@ -84,6 +84,7 @@ xfs_bulkstat_one_iget(
8191         buf->bs_mode = dic->di_mode;
8192         buf->bs_uid = dic->di_uid;
8193         buf->bs_gid = dic->di_gid;
8194 +       buf->bs_tag = dic->di_tag;
8195         buf->bs_size = dic->di_size;
8196  
8197         /*
8198 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_log_recover.c linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_log_recover.c
8199 --- linux-2.6.33/fs/xfs/xfs_log_recover.c       2010-02-25 11:52:06.000000000 +0100
8200 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_log_recover.c 2010-02-25 12:02:16.000000000 +0100
8201 @@ -2462,7 +2462,8 @@ xlog_recover_do_inode_trans(
8202         }
8203  
8204         /* The core is in in-core format */
8205 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8206 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8207 +               mp->m_flags & XFS_MOUNT_TAGGED);
8208  
8209         /* the rest is in on-disk format */
8210         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8211 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_mount.h linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_mount.h
8212 --- linux-2.6.33/fs/xfs/xfs_mount.h     2010-02-25 11:52:06.000000000 +0100
8213 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_mount.h       2010-02-25 12:02:16.000000000 +0100
8214 @@ -298,6 +298,7 @@ typedef struct xfs_mount {
8215                                                    allocator */
8216  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8217  
8218 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8219  
8220  /*
8221   * Default minimum read and write sizes.
8222 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_vnodeops.c linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_vnodeops.c
8223 --- linux-2.6.33/fs/xfs/xfs_vnodeops.c  2010-02-25 11:52:06.000000000 +0100
8224 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_vnodeops.c    2010-02-25 13:24:14.000000000 +0100
8225 @@ -55,6 +55,80 @@
8226  #include "xfs_vnodeops.h"
8227  #include "xfs_trace.h"
8228  
8229 +
8230 +STATIC void
8231 +xfs_get_inode_flags(
8232 +       xfs_inode_t     *ip)
8233 +{
8234 +       struct inode    *inode = VFS_I(ip);
8235 +       unsigned int    flags = inode->i_flags;
8236 +       unsigned int    vflags = inode->i_vflags;
8237 +
8238 +       if (flags & S_IMMUTABLE)
8239 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8240 +       else
8241 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8242 +       if (flags & S_IXUNLINK)
8243 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8244 +       else
8245 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8246 +
8247 +       if (vflags & V_BARRIER)
8248 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8249 +       else
8250 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8251 +       if (vflags & V_COW)
8252 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8253 +       else
8254 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8255 +}
8256 +
8257 +int
8258 +xfs_sync_flags(
8259 +       struct inode            *inode,
8260 +       int                     flags,
8261 +       int                     vflags)
8262 +{
8263 +       struct xfs_inode        *ip = XFS_I(inode);
8264 +       struct xfs_mount        *mp = ip->i_mount;
8265 +       struct xfs_trans        *tp;
8266 +       unsigned int            lock_flags = 0;
8267 +       int                     code;
8268 +
8269 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8270 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8271 +       if (code)
8272 +               goto error_out;
8273 +
8274 +       lock_flags = XFS_ILOCK_EXCL;
8275 +       xfs_ilock(ip, lock_flags);
8276 +
8277 +       xfs_trans_ijoin(tp, ip, lock_flags);
8278 +       xfs_trans_ihold(tp, ip);
8279 +
8280 +       inode->i_flags = flags;
8281 +       inode->i_vflags = vflags;
8282 +       xfs_get_inode_flags(ip);
8283 +
8284 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8285 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8286 +
8287 +       XFS_STATS_INC(xs_ig_attrchg);
8288 +
8289 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8290 +               xfs_trans_set_sync(tp);
8291 +       code = xfs_trans_commit(tp, 0);
8292 +       xfs_iunlock(ip, lock_flags);
8293 +       return code;
8294 +
8295 +error_out:
8296 +       xfs_trans_cancel(tp, 0);
8297 +       if (lock_flags)
8298 +               xfs_iunlock(ip, lock_flags);
8299 +       return code;
8300 +}
8301 +
8302 +
8303  int
8304  xfs_setattr(
8305         struct xfs_inode        *ip,
8306 @@ -70,6 +144,7 @@ xfs_setattr(
8307         uint                    commit_flags=0;
8308         uid_t                   uid=0, iuid=0;
8309         gid_t                   gid=0, igid=0;
8310 +       tag_t                   tag=0, itag=0;
8311         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8312         int                     need_iolock = 1;
8313  
8314 @@ -162,7 +237,7 @@ xfs_setattr(
8315         /*
8316          * Change file ownership.  Must be the owner or privileged.
8317          */
8318 -       if (mask & (ATTR_UID|ATTR_GID)) {
8319 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8320                 /*
8321                  * These IDs could have changed since we last looked at them.
8322                  * But, we're assured that if the ownership did change
8323 @@ -171,8 +246,10 @@ xfs_setattr(
8324                  */
8325                 iuid = ip->i_d.di_uid;
8326                 igid = ip->i_d.di_gid;
8327 +               itag = ip->i_d.di_tag;
8328                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8329                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8330 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8331  
8332                 /*
8333                  * Do a quota reservation only if uid/gid is actually
8334 @@ -180,7 +257,8 @@ xfs_setattr(
8335                  */
8336                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8337                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8338 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8339 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8340 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8341                         ASSERT(tp);
8342                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8343                                                 capable(CAP_FOWNER) ?
8344 @@ -341,7 +419,7 @@ xfs_setattr(
8345         /*
8346          * Change file ownership.  Must be the owner or privileged.
8347          */
8348 -       if (mask & (ATTR_UID|ATTR_GID)) {
8349 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8350                 /*
8351                  * CAP_FSETID overrides the following restrictions:
8352                  *
8353 @@ -357,6 +435,10 @@ xfs_setattr(
8354                  * Change the ownerships and register quota modifications
8355                  * in the transaction.
8356                  */
8357 +               if (itag != tag) {
8358 +                       ip->i_d.di_tag = tag;
8359 +                       inode->i_tag = tag;
8360 +               }
8361                 if (iuid != uid) {
8362                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8363                                 ASSERT(mask & ATTR_UID);
8364 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_vnodeops.h linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_vnodeops.h
8365 --- linux-2.6.33/fs/xfs/xfs_vnodeops.h  2010-02-25 11:52:06.000000000 +0100
8366 +++ linux-2.6.33-vs2.3.0.36.30/fs/xfs/xfs_vnodeops.h    2010-02-25 12:02:16.000000000 +0100
8367 @@ -14,6 +14,7 @@ struct xfs_inode;
8368  struct xfs_iomap;
8369  
8370  
8371 +int xfs_sync_xflags(struct xfs_inode *ip);
8372  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8373  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8374  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8375 diff -NurpP --minimal linux-2.6.33/include/asm-generic/tlb.h linux-2.6.33-vs2.3.0.36.30/include/asm-generic/tlb.h
8376 --- linux-2.6.33/include/asm-generic/tlb.h      2009-09-10 15:26:24.000000000 +0200
8377 +++ linux-2.6.33-vs2.3.0.36.30/include/asm-generic/tlb.h        2010-02-25 12:02:16.000000000 +0100
8378 @@ -14,6 +14,7 @@
8379  #define _ASM_GENERIC__TLB_H
8380  
8381  #include <linux/swap.h>
8382 +#include <linux/vs_memory.h>
8383  #include <asm/pgalloc.h>
8384  #include <asm/tlbflush.h>
8385  
8386 diff -NurpP --minimal linux-2.6.33/include/linux/capability.h linux-2.6.33-vs2.3.0.36.30/include/linux/capability.h
8387 --- linux-2.6.33/include/linux/capability.h     2010-02-25 11:52:07.000000000 +0100
8388 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/capability.h       2010-02-25 12:02:16.000000000 +0100
8389 @@ -283,6 +283,7 @@ struct cpu_vfs_cap_data {
8390     arbitrary SCSI commands */
8391  /* Allow setting encryption key on loopback filesystem */
8392  /* Allow setting zone reclaim policy */
8393 +/* Allow the selection of a security context */
8394  
8395  #define CAP_SYS_ADMIN        21
8396  
8397 @@ -355,7 +356,13 @@ struct cpu_vfs_cap_data {
8398  
8399  #define CAP_MAC_ADMIN        33
8400  
8401 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8402 +/* Allow context manipulations */
8403 +/* Allow changing context info on files */
8404 +
8405 +#define CAP_CONTEXT         34
8406 +
8407 +
8408 +#define CAP_LAST_CAP         CAP_CONTEXT
8409  
8410  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8411  
8412 diff -NurpP --minimal linux-2.6.33/include/linux/devpts_fs.h linux-2.6.33-vs2.3.0.36.30/include/linux/devpts_fs.h
8413 --- linux-2.6.33/include/linux/devpts_fs.h      2008-12-25 00:26:37.000000000 +0100
8414 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/devpts_fs.h        2010-02-25 12:02:16.000000000 +0100
8415 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8416  
8417  #endif
8418  
8419 -
8420  #endif /* _LINUX_DEVPTS_FS_H */
8421 diff -NurpP --minimal linux-2.6.33/include/linux/ext2_fs.h linux-2.6.33-vs2.3.0.36.30/include/linux/ext2_fs.h
8422 --- linux-2.6.33/include/linux/ext2_fs.h        2010-02-25 11:52:07.000000000 +0100
8423 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/ext2_fs.h  2010-02-25 12:02:16.000000000 +0100
8424 @@ -189,8 +189,12 @@ struct ext2_group_desc
8425  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8426  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8427  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8428 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8429  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8430  
8431 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8432 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8433 +
8434  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8435  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8436  
8437 @@ -274,7 +278,8 @@ struct ext2_inode {
8438                         __u16   i_pad1;
8439                         __le16  l_i_uid_high;   /* these 2 fields    */
8440                         __le16  l_i_gid_high;   /* were reserved2[0] */
8441 -                       __u32   l_i_reserved2;
8442 +                       __le16  l_i_tag;        /* Context Tag */
8443 +                       __u16   l_i_reserved2;
8444                 } linux2;
8445                 struct {
8446                         __u8    h_i_frag;       /* Fragment number */
8447 @@ -303,6 +308,7 @@ struct ext2_inode {
8448  #define i_gid_low      i_gid
8449  #define i_uid_high     osd2.linux2.l_i_uid_high
8450  #define i_gid_high     osd2.linux2.l_i_gid_high
8451 +#define i_raw_tag      osd2.linux2.l_i_tag
8452  #define i_reserved2    osd2.linux2.l_i_reserved2
8453  #endif
8454  
8455 @@ -347,6 +353,7 @@ struct ext2_inode {
8456  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8457  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8458  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8459 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8460  
8461  
8462  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8463 diff -NurpP --minimal linux-2.6.33/include/linux/ext3_fs.h linux-2.6.33-vs2.3.0.36.30/include/linux/ext3_fs.h
8464 --- linux-2.6.33/include/linux/ext3_fs.h        2010-02-25 11:52:07.000000000 +0100
8465 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/ext3_fs.h  2010-02-25 12:02:16.000000000 +0100
8466 @@ -173,10 +173,14 @@ struct ext3_group_desc
8467  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8468  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8469  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8470 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8471  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8472  
8473 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8474 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8475 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8476 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8477 +
8478 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8479 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8480  
8481  /* Flags that should be inherited by new inodes from their parent. */
8482  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8483 @@ -320,7 +324,8 @@ struct ext3_inode {
8484                         __u16   i_pad1;
8485                         __le16  l_i_uid_high;   /* these 2 fields    */
8486                         __le16  l_i_gid_high;   /* were reserved2[0] */
8487 -                       __u32   l_i_reserved2;
8488 +                       __le16  l_i_tag;        /* Context Tag */
8489 +                       __u16   l_i_reserved2;
8490                 } linux2;
8491                 struct {
8492                         __u8    h_i_frag;       /* Fragment number */
8493 @@ -351,6 +356,7 @@ struct ext3_inode {
8494  #define i_gid_low      i_gid
8495  #define i_uid_high     osd2.linux2.l_i_uid_high
8496  #define i_gid_high     osd2.linux2.l_i_gid_high
8497 +#define i_raw_tag      osd2.linux2.l_i_tag
8498  #define i_reserved2    osd2.linux2.l_i_reserved2
8499  
8500  #elif defined(__GNU__)
8501 @@ -414,6 +420,7 @@ struct ext3_inode {
8502  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8503  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8504                                                   * error in ordered mode */
8505 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8506  
8507  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8508  #ifndef _LINUX_EXT2_FS_H
8509 @@ -892,6 +899,7 @@ extern void ext3_get_inode_flags(struct 
8510  extern void ext3_set_aops(struct inode *inode);
8511  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8512                        u64 start, u64 len);
8513 +extern int ext3_sync_flags(struct inode *, int, int);
8514  
8515  /* ioctl.c */
8516  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8517 diff -NurpP --minimal linux-2.6.33/include/linux/fs.h linux-2.6.33-vs2.3.0.36.30/include/linux/fs.h
8518 --- linux-2.6.33/include/linux/fs.h     2010-02-25 11:52:07.000000000 +0100
8519 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/fs.h       2010-02-25 13:36:54.000000000 +0100
8520 @@ -206,6 +206,9 @@ struct inodes_stat_t {
8521  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8522  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8523  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8524 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8525 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8526 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8527  #define MS_ACTIVE      (1<<30)
8528  #define MS_NOUSER      (1<<31)
8529  
8530 @@ -232,6 +235,14 @@ struct inodes_stat_t {
8531  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8532  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8533  #define S_PRIVATE      512     /* Inode is fs-internal */
8534 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8535 +
8536 +/* Linux-VServer related Inode flags */
8537 +
8538 +#define V_VALID                1
8539 +#define V_XATTR                2
8540 +#define V_BARRIER      4       /* Barrier for chroot() */
8541 +#define V_COW          8       /* Copy on Write */
8542  
8543  /*
8544   * Note that nosuid etc flags are inode-specific: setting some file-system
8545 @@ -254,12 +265,15 @@ struct inodes_stat_t {
8546  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8547                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8548  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8549 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8550 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8551 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8552 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8553 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8554  
8555  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8556  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8557  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8558 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8559 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8560  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8561  
8562  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8563 @@ -267,6 +281,16 @@ struct inodes_stat_t {
8564  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8565  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8566  
8567 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8568 +
8569 +#ifdef CONFIG_VSERVER_COWBL
8570 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8571 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8572 +#else
8573 +#  define IS_COW(inode)                (0)
8574 +#  define IS_COW_LINK(inode)   (0)
8575 +#endif
8576 +
8577  /* the read-only stuff doesn't really belong here, but any other place is
8578     probably as bad and I don't want to create yet another include file. */
8579  
8580 @@ -349,11 +373,14 @@ struct inodes_stat_t {
8581  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8582  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8583  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8584 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8585  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8586  
8587 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8588 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8589 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8590 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8591  
8592 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8593 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8594  
8595  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8596  #define SYNC_FILE_RANGE_WRITE          2
8597 @@ -435,6 +462,7 @@ typedef void (dio_iodone_t)(struct kiocb
8598  #define ATTR_KILL_PRIV (1 << 14)
8599  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8600  #define ATTR_TIMES_SET (1 << 16)
8601 +#define ATTR_TAG       (1 << 17)
8602  
8603  /*
8604   * This is the Inode Attributes structure, used for notify_change().  It
8605 @@ -450,6 +478,7 @@ struct iattr {
8606         umode_t         ia_mode;
8607         uid_t           ia_uid;
8608         gid_t           ia_gid;
8609 +       tag_t           ia_tag;
8610         loff_t          ia_size;
8611         struct timespec ia_atime;
8612         struct timespec ia_mtime;
8613 @@ -463,6 +492,9 @@ struct iattr {
8614         struct file     *ia_file;
8615  };
8616  
8617 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8618 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8619 +
8620  /*
8621   * Includes for diskquotas.
8622   */
8623 @@ -728,7 +760,9 @@ struct inode {
8624         unsigned int            i_nlink;
8625         uid_t                   i_uid;
8626         gid_t                   i_gid;
8627 +       tag_t                   i_tag;
8628         dev_t                   i_rdev;
8629 +       dev_t                   i_mdev;
8630         unsigned int            i_blkbits;
8631         u64                     i_version;
8632         loff_t                  i_size;
8633 @@ -775,7 +809,8 @@ struct inode {
8634         unsigned long           i_state;
8635         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8636  
8637 -       unsigned int            i_flags;
8638 +       unsigned short          i_flags;
8639 +       unsigned short          i_vflags;
8640  
8641         atomic_t                i_writecount;
8642  #ifdef CONFIG_SECURITY
8643 @@ -863,12 +898,12 @@ static inline void i_size_write(struct i
8644  
8645  static inline unsigned iminor(const struct inode *inode)
8646  {
8647 -       return MINOR(inode->i_rdev);
8648 +       return MINOR(inode->i_mdev);
8649  }
8650  
8651  static inline unsigned imajor(const struct inode *inode)
8652  {
8653 -       return MAJOR(inode->i_rdev);
8654 +       return MAJOR(inode->i_mdev);
8655  }
8656  
8657  extern struct block_device *I_BDEV(struct inode *inode);
8658 @@ -927,6 +962,7 @@ struct file {
8659         loff_t                  f_pos;
8660         struct fown_struct      f_owner;
8661         const struct cred       *f_cred;
8662 +       xid_t                   f_xid;
8663         struct file_ra_state    f_ra;
8664  
8665         u64                     f_version;
8666 @@ -1068,6 +1104,7 @@ struct file_lock {
8667         struct file *fl_file;
8668         loff_t fl_start;
8669         loff_t fl_end;
8670 +       xid_t fl_xid;
8671  
8672         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8673         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8674 @@ -1529,6 +1566,7 @@ struct inode_operations {
8675         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8676         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8677         int (*removexattr) (struct dentry *, const char *);
8678 +       int (*sync_flags) (struct inode *, int, int);
8679         void (*truncate_range)(struct inode *, loff_t, loff_t);
8680         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8681                           loff_t len);
8682 @@ -1549,6 +1587,7 @@ extern ssize_t vfs_readv(struct file *, 
8683                 unsigned long, loff_t *);
8684  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8685                 unsigned long, loff_t *);
8686 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8687  
8688  struct super_operations {
8689         struct inode *(*alloc_inode)(struct super_block *sb);
8690 @@ -2331,6 +2370,7 @@ extern int dcache_dir_open(struct inode 
8691  extern int dcache_dir_close(struct inode *, struct file *);
8692  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8693  extern int dcache_readdir(struct file *, void *, filldir_t);
8694 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8695  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8696  extern int simple_statfs(struct dentry *, struct kstatfs *);
8697  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8698 diff -NurpP --minimal linux-2.6.33/include/linux/gfs2_ondisk.h linux-2.6.33-vs2.3.0.36.30/include/linux/gfs2_ondisk.h
8699 --- linux-2.6.33/include/linux/gfs2_ondisk.h    2010-02-25 11:52:07.000000000 +0100
8700 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/gfs2_ondisk.h      2010-02-25 12:02:16.000000000 +0100
8701 @@ -239,6 +239,9 @@ enum {
8702         gfs2fl_NoAtime          = 7,
8703         gfs2fl_Sync             = 8,
8704         gfs2fl_System           = 9,
8705 +       gfs2fl_IXUnlink         = 16,
8706 +       gfs2fl_Barrier          = 17,
8707 +       gfs2fl_Cow              = 18,
8708         gfs2fl_TruncInProg      = 29,
8709         gfs2fl_InheritDirectio  = 30,
8710         gfs2fl_InheritJdata     = 31,
8711 @@ -255,6 +258,9 @@ enum {
8712  #define GFS2_DIF_NOATIME               0x00000080
8713  #define GFS2_DIF_SYNC                  0x00000100
8714  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8715 +#define GFS2_DIF_IXUNLINK              0x00010000
8716 +#define GFS2_DIF_BARRIER               0x00020000
8717 +#define GFS2_DIF_COW                   0x00040000
8718  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8719  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8720  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8721 diff -NurpP --minimal linux-2.6.33/include/linux/if_tun.h linux-2.6.33-vs2.3.0.36.30/include/linux/if_tun.h
8722 --- linux-2.6.33/include/linux/if_tun.h 2009-12-03 20:02:55.000000000 +0100
8723 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/if_tun.h   2010-02-25 12:02:16.000000000 +0100
8724 @@ -48,6 +48,7 @@
8725  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8726  #define TUNGETSNDBUF   _IOR('T', 211, int)
8727  #define TUNSETSNDBUF   _IOW('T', 212, int)
8728 +#define TUNSETNID     _IOW('T', 215, int)
8729  
8730  /* TUNSETIFF ifr flags */
8731  #define IFF_TUN                0x0001
8732 diff -NurpP --minimal linux-2.6.33/include/linux/init_task.h linux-2.6.33-vs2.3.0.36.30/include/linux/init_task.h
8733 --- linux-2.6.33/include/linux/init_task.h      2010-02-25 11:52:07.000000000 +0100
8734 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/init_task.h        2010-02-25 12:02:16.000000000 +0100
8735 @@ -180,6 +180,10 @@ extern struct cred init_cred;
8736         INIT_FTRACE_GRAPH                                               \
8737         INIT_TRACE_RECURSION                                            \
8738         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8739 +       .xid            = 0,                                            \
8740 +       .vx_info        = NULL,                                         \
8741 +       .nid            = 0,                                            \
8742 +       .nx_info        = NULL,                                         \
8743  }
8744  
8745  
8746 diff -NurpP --minimal linux-2.6.33/include/linux/ipc.h linux-2.6.33-vs2.3.0.36.30/include/linux/ipc.h
8747 --- linux-2.6.33/include/linux/ipc.h    2009-12-03 20:02:55.000000000 +0100
8748 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/ipc.h      2010-02-25 12:02:16.000000000 +0100
8749 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8750         key_t           key;
8751         uid_t           uid;
8752         gid_t           gid;
8753 +       xid_t           xid;
8754         uid_t           cuid;
8755         gid_t           cgid;
8756         mode_t          mode; 
8757 diff -NurpP --minimal linux-2.6.33/include/linux/Kbuild linux-2.6.33-vs2.3.0.36.30/include/linux/Kbuild
8758 --- linux-2.6.33/include/linux/Kbuild   2010-02-25 11:52:07.000000000 +0100
8759 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/Kbuild     2010-02-25 12:02:16.000000000 +0100
8760 @@ -383,5 +383,8 @@ unifdef-y += xattr.h
8761  unifdef-y += xfrm.h
8762  
8763  objhdr-y += version.h
8764 +
8765 +header-y += vserver/
8766  header-y += wimax.h
8767  header-y += wimax/
8768 +
8769 diff -NurpP --minimal linux-2.6.33/include/linux/loop.h linux-2.6.33-vs2.3.0.36.30/include/linux/loop.h
8770 --- linux-2.6.33/include/linux/loop.h   2009-09-10 15:26:25.000000000 +0200
8771 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/loop.h     2010-02-25 12:02:16.000000000 +0100
8772 @@ -45,6 +45,7 @@ struct loop_device {
8773         struct loop_func_table *lo_encryption;
8774         __u32           lo_init[2];
8775         uid_t           lo_key_owner;   /* Who set the key */
8776 +       xid_t           lo_xid;
8777         int             (*ioctl)(struct loop_device *, int cmd, 
8778                                  unsigned long arg); 
8779  
8780 diff -NurpP --minimal linux-2.6.33/include/linux/magic.h linux-2.6.33-vs2.3.0.36.30/include/linux/magic.h
8781 --- linux-2.6.33/include/linux/magic.h  2009-12-03 20:02:55.000000000 +0100
8782 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/magic.h    2010-02-25 12:02:16.000000000 +0100
8783 @@ -3,7 +3,7 @@
8784  
8785  #define ADFS_SUPER_MAGIC       0xadf5
8786  #define AFFS_SUPER_MAGIC       0xadff
8787 -#define AFS_SUPER_MAGIC                0x5346414F
8788 +#define AFS_SUPER_MAGIC                0x5346414F
8789  #define AUTOFS_SUPER_MAGIC     0x0187
8790  #define CODA_SUPER_MAGIC       0x73757245
8791  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8792 @@ -38,6 +38,7 @@
8793  #define NFS_SUPER_MAGIC                0x6969
8794  #define OPENPROM_SUPER_MAGIC   0x9fa1
8795  #define PROC_SUPER_MAGIC       0x9fa0
8796 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8797  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8798  
8799  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8800 diff -NurpP --minimal linux-2.6.33/include/linux/major.h linux-2.6.33-vs2.3.0.36.30/include/linux/major.h
8801 --- linux-2.6.33/include/linux/major.h  2009-09-10 15:26:25.000000000 +0200
8802 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/major.h    2010-02-25 12:02:16.000000000 +0100
8803 @@ -15,6 +15,7 @@
8804  #define HD_MAJOR               IDE0_MAJOR
8805  #define PTY_SLAVE_MAJOR                3
8806  #define TTY_MAJOR              4
8807 +#define VROOT_MAJOR            4
8808  #define TTYAUX_MAJOR           5
8809  #define LP_MAJOR               6
8810  #define VCS_MAJOR              7
8811 diff -NurpP --minimal linux-2.6.33/include/linux/memcontrol.h linux-2.6.33-vs2.3.0.36.30/include/linux/memcontrol.h
8812 --- linux-2.6.33/include/linux/memcontrol.h     2010-02-25 11:52:07.000000000 +0100
8813 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/memcontrol.h       2010-02-25 12:02:16.000000000 +0100
8814 @@ -76,6 +76,13 @@ int task_in_mem_cgroup(struct task_struc
8815  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
8816  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8817  
8818 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8819 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8820 +
8821 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8822 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8823 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8824 +
8825  static inline
8826  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8827  {
8828 diff -NurpP --minimal linux-2.6.33/include/linux/mm_types.h linux-2.6.33-vs2.3.0.36.30/include/linux/mm_types.h
8829 --- linux-2.6.33/include/linux/mm_types.h       2010-02-25 11:52:07.000000000 +0100
8830 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/mm_types.h 2010-02-25 12:02:16.000000000 +0100
8831 @@ -250,6 +250,7 @@ struct mm_struct {
8832  
8833         /* Architecture-specific MM context */
8834         mm_context_t context;
8835 +       struct vx_info *mm_vx_info;
8836  
8837         /* Swap token stuff */
8838         /*
8839 diff -NurpP --minimal linux-2.6.33/include/linux/mount.h linux-2.6.33-vs2.3.0.36.30/include/linux/mount.h
8840 --- linux-2.6.33/include/linux/mount.h  2009-09-10 15:26:25.000000000 +0200
8841 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/mount.h    2010-02-25 12:02:16.000000000 +0100
8842 @@ -36,6 +36,9 @@ struct mnt_namespace;
8843  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
8844  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
8845  
8846 +#define MNT_TAGID      0x10000
8847 +#define MNT_NOTAG      0x20000
8848 +
8849  struct vfsmount {
8850         struct list_head mnt_hash;
8851         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8852 @@ -70,6 +73,7 @@ struct vfsmount {
8853  #else
8854         int mnt_writers;
8855  #endif
8856 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8857  };
8858  
8859  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
8860 diff -NurpP --minimal linux-2.6.33/include/linux/net.h linux-2.6.33-vs2.3.0.36.30/include/linux/net.h
8861 --- linux-2.6.33/include/linux/net.h    2010-02-25 11:52:07.000000000 +0100
8862 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/net.h      2010-02-25 12:02:16.000000000 +0100
8863 @@ -70,6 +70,7 @@ struct net;
8864  #define SOCK_NOSPACE           2
8865  #define SOCK_PASSCRED          3
8866  #define SOCK_PASSSEC           4
8867 +#define SOCK_USER_SOCKET       5
8868  
8869  #ifndef ARCH_HAS_SOCKET_TYPES
8870  /**
8871 diff -NurpP --minimal linux-2.6.33/include/linux/nfs_mount.h linux-2.6.33-vs2.3.0.36.30/include/linux/nfs_mount.h
8872 --- linux-2.6.33/include/linux/nfs_mount.h      2009-03-24 14:22:43.000000000 +0100
8873 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/nfs_mount.h        2010-02-25 12:02:16.000000000 +0100
8874 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8875  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8876  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8877  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8878 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8879 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8880 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8881  
8882  /* The following are for internal use only */
8883  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8884 diff -NurpP --minimal linux-2.6.33/include/linux/nsproxy.h linux-2.6.33-vs2.3.0.36.30/include/linux/nsproxy.h
8885 --- linux-2.6.33/include/linux/nsproxy.h        2009-06-11 17:13:17.000000000 +0200
8886 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/nsproxy.h  2010-02-25 12:02:16.000000000 +0100
8887 @@ -3,6 +3,7 @@
8888  
8889  #include <linux/spinlock.h>
8890  #include <linux/sched.h>
8891 +#include <linux/vserver/debug.h>
8892  
8893  struct mnt_namespace;
8894  struct uts_namespace;
8895 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8896  }
8897  
8898  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8899 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8900  void exit_task_namespaces(struct task_struct *tsk);
8901  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8902  void free_nsproxy(struct nsproxy *ns);
8903  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
8904         struct fs_struct *);
8905  
8906 -static inline void put_nsproxy(struct nsproxy *ns)
8907 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8908 +
8909 +static inline void __get_nsproxy(struct nsproxy *ns,
8910 +       const char *_file, int _line)
8911  {
8912 -       if (atomic_dec_and_test(&ns->count)) {
8913 -               free_nsproxy(ns);
8914 -       }
8915 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8916 +               ns, atomic_read(&ns->count), _file, _line);
8917 +       atomic_inc(&ns->count);
8918  }
8919  
8920 -static inline void get_nsproxy(struct nsproxy *ns)
8921 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8922 +
8923 +static inline void __put_nsproxy(struct nsproxy *ns,
8924 +       const char *_file, int _line)
8925  {
8926 -       atomic_inc(&ns->count);
8927 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8928 +               ns, atomic_read(&ns->count), _file, _line);
8929 +       if (atomic_dec_and_test(&ns->count)) {
8930 +               free_nsproxy(ns);
8931 +       }
8932  }
8933  
8934  #ifdef CONFIG_CGROUP_NS
8935 diff -NurpP --minimal linux-2.6.33/include/linux/pid.h linux-2.6.33-vs2.3.0.36.30/include/linux/pid.h
8936 --- linux-2.6.33/include/linux/pid.h    2009-03-24 14:22:43.000000000 +0100
8937 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/pid.h      2010-02-25 12:02:16.000000000 +0100
8938 @@ -8,7 +8,8 @@ enum pid_type
8939         PIDTYPE_PID,
8940         PIDTYPE_PGID,
8941         PIDTYPE_SID,
8942 -       PIDTYPE_MAX
8943 +       PIDTYPE_MAX,
8944 +       PIDTYPE_REALPID
8945  };
8946  
8947  /*
8948 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
8949  }
8950  
8951  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8952 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8953  pid_t pid_vnr(struct pid *pid);
8954  
8955  #define do_each_pid_task(pid, type, task)                              \
8956 diff -NurpP --minimal linux-2.6.33/include/linux/proc_fs.h linux-2.6.33-vs2.3.0.36.30/include/linux/proc_fs.h
8957 --- linux-2.6.33/include/linux/proc_fs.h        2009-12-03 20:02:56.000000000 +0100
8958 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/proc_fs.h  2010-02-25 12:02:16.000000000 +0100
8959 @@ -56,6 +56,7 @@ struct proc_dir_entry {
8960         nlink_t nlink;
8961         uid_t uid;
8962         gid_t gid;
8963 +       int vx_flags;
8964         loff_t size;
8965         const struct inode_operations *proc_iops;
8966         /*
8967 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
8968  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
8969  #endif
8970  
8971 +struct vx_info;
8972 +struct nx_info;
8973 +
8974  union proc_op {
8975         int (*proc_get_link)(struct inode *, struct path *);
8976         int (*proc_read)(struct task_struct *task, char *page);
8977         int (*proc_show)(struct seq_file *m,
8978                 struct pid_namespace *ns, struct pid *pid,
8979                 struct task_struct *task);
8980 +       int (*proc_vs_read)(char *page);
8981 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8982 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8983  };
8984  
8985  struct ctl_table_header;
8986 @@ -263,6 +270,7 @@ struct ctl_table;
8987  
8988  struct proc_inode {
8989         struct pid *pid;
8990 +       int vx_flags;
8991         int fd;
8992         union proc_op op;
8993         struct proc_dir_entry *pde;
8994 diff -NurpP --minimal linux-2.6.33/include/linux/quotaops.h linux-2.6.33-vs2.3.0.36.30/include/linux/quotaops.h
8995 --- linux-2.6.33/include/linux/quotaops.h       2009-12-03 20:02:56.000000000 +0100
8996 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/quotaops.h 2010-02-25 12:02:16.000000000 +0100
8997 @@ -8,6 +8,7 @@
8998  #define _LINUX_QUOTAOPS_
8999  
9000  #include <linux/fs.h>
9001 +#include <linux/vs_dlimit.h>
9002  
9003  static inline struct quota_info *sb_dqopt(struct super_block *sb)
9004  {
9005 @@ -154,10 +155,14 @@ static inline void vfs_dq_init(struct in
9006   * a transaction (deadlocks possible otherwise) */
9007  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9008  {
9009 +       if (dl_alloc_space(inode, nr))
9010 +               return 1;
9011         if (sb_any_quota_active(inode->i_sb)) {
9012                 /* Used space is updated in alloc_space() */
9013 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
9014 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) {
9015 +                       dl_free_space(inode, nr);
9016                         return 1;
9017 +               }
9018         }
9019         else
9020                 inode_add_bytes(inode, nr);
9021 @@ -174,10 +179,14 @@ static inline int vfs_dq_prealloc_space(
9022  
9023  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9024  {
9025 +       if (dl_alloc_space(inode, nr))
9026 +               return 1;
9027         if (sb_any_quota_active(inode->i_sb)) {
9028                 /* Used space is updated in alloc_space() */
9029 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
9030 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) {
9031 +                       dl_free_space(inode, nr);
9032                         return 1;
9033 +               }
9034         }
9035         else
9036                 inode_add_bytes(inode, nr);
9037 @@ -194,20 +203,28 @@ static inline int vfs_dq_alloc_space(str
9038  
9039  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9040  {
9041 +       if (dl_reserve_space(inode, nr))
9042 +               return 1;
9043         if (sb_any_quota_active(inode->i_sb)) {
9044                 /* Used space is updated in alloc_space() */
9045 -               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
9046 +               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA) {
9047 +                       dl_release_space(inode, nr);
9048                         return 1;
9049 +               }
9050         }
9051         return 0;
9052  }
9053  
9054  static inline int vfs_dq_alloc_inode(struct inode *inode)
9055  {
9056 +       if (dl_alloc_inode(inode))
9057 +               return 1;
9058         if (sb_any_quota_active(inode->i_sb)) {
9059                 vfs_dq_init(inode);
9060 -               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
9061 +               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
9062 +                       dl_free_inode(inode);
9063                         return 1;
9064 +               }
9065         }
9066         return 0;
9067  }
9068 @@ -217,9 +234,13 @@ static inline int vfs_dq_alloc_inode(str
9069   */
9070  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9071  {
9072 +       if (dl_claim_space(inode, nr))
9073 +               return 1;
9074         if (sb_any_quota_active(inode->i_sb)) {
9075 -               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
9076 +               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA) {
9077 +                       dl_release_space(inode, nr);
9078                         return 1;
9079 +               }
9080         } else
9081                 inode_add_bytes(inode, nr);
9082  
9083 @@ -235,6 +256,7 @@ void vfs_dq_release_reservation_space(st
9084  {
9085         if (sb_any_quota_active(inode->i_sb))
9086                 inode->i_sb->dq_op->release_rsv(inode, nr);
9087 +       dl_release_space(inode, nr);
9088  }
9089  
9090  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9091 @@ -243,6 +265,7 @@ static inline void vfs_dq_free_space_nod
9092                 inode->i_sb->dq_op->free_space(inode, nr);
9093         else
9094                 inode_sub_bytes(inode, nr);
9095 +       dl_free_space(inode, nr);
9096  }
9097  
9098  static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
9099 @@ -255,6 +278,7 @@ static inline void vfs_dq_free_inode(str
9100  {
9101         if (sb_any_quota_active(inode->i_sb))
9102                 inode->i_sb->dq_op->free_inode(inode, 1);
9103 +       dl_free_inode(inode);
9104  }
9105  
9106  /* Cannot be called inside a transaction */
9107 @@ -358,6 +382,8 @@ static inline int vfs_dq_transfer(struct
9108  
9109  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9110  {
9111 +       if (dl_alloc_space(inode, nr))
9112 +               return 1;
9113         inode_add_bytes(inode, nr);
9114         return 0;
9115  }
9116 @@ -371,6 +397,8 @@ static inline int vfs_dq_prealloc_space(
9117  
9118  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9119  {
9120 +       if (dl_alloc_space(inode, nr))
9121 +               return 1;
9122         inode_add_bytes(inode, nr);
9123         return 0;
9124  }
9125 @@ -384,22 +412,28 @@ static inline int vfs_dq_alloc_space(str
9126  
9127  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9128  {
9129 +       if (dl_reserve_space(inode, nr))
9130 +               return 1;
9131         return 0;
9132  }
9133  
9134  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9135  {
9136 +       if (dl_claim_space(inode, nr))
9137 +               return 1;
9138         return vfs_dq_alloc_space(inode, nr);
9139  }
9140  
9141  static inline
9142  int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
9143  {
9144 +       dl_release_space(inode, nr);
9145         return 0;
9146  }
9147  
9148  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9149  {
9150 +       dl_free_space(inode, nr);
9151         inode_sub_bytes(inode, nr);
9152  }
9153  
9154 diff -NurpP --minimal linux-2.6.33/include/linux/reboot.h linux-2.6.33-vs2.3.0.36.30/include/linux/reboot.h
9155 --- linux-2.6.33/include/linux/reboot.h 2008-12-25 00:26:37.000000000 +0100
9156 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/reboot.h   2010-02-25 12:02:16.000000000 +0100
9157 @@ -33,6 +33,7 @@
9158  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9159  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9160  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9161 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9162  
9163  
9164  #ifdef __KERNEL__
9165 diff -NurpP --minimal linux-2.6.33/include/linux/reiserfs_fs.h linux-2.6.33-vs2.3.0.36.30/include/linux/reiserfs_fs.h
9166 --- linux-2.6.33/include/linux/reiserfs_fs.h    2010-02-25 11:52:07.000000000 +0100
9167 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/reiserfs_fs.h      2010-02-25 12:02:16.000000000 +0100
9168 @@ -977,6 +977,11 @@ struct stat_data_v1 {
9169  #define REISERFS_COMPR_FL     FS_COMPR_FL
9170  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9171  
9172 +/* unfortunately reiserfs sdattr is only 16 bit */
9173 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9174 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9175 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9176 +
9177  /* persistent flags that file inherits from the parent directory */
9178  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9179                                 REISERFS_SYNC_FL |      \
9180 @@ -986,6 +991,9 @@ struct stat_data_v1 {
9181                                 REISERFS_COMPR_FL |     \
9182                                 REISERFS_NOTAIL_FL )
9183  
9184 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9185 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9186 +
9187  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9188     address blocks) */
9189  struct stat_data {
9190 @@ -2071,6 +2079,7 @@ static inline void reiserfs_update_sd(st
9191  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9192  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9193  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9194 +int reiserfs_sync_flags(struct inode *inode, int, int);
9195  
9196  /* namei.c */
9197  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9198 diff -NurpP --minimal linux-2.6.33/include/linux/reiserfs_fs_sb.h linux-2.6.33-vs2.3.0.36.30/include/linux/reiserfs_fs_sb.h
9199 --- linux-2.6.33/include/linux/reiserfs_fs_sb.h 2010-02-25 11:52:07.000000000 +0100
9200 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/reiserfs_fs_sb.h   2010-02-25 12:02:16.000000000 +0100
9201 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9202         REISERFS_EXPOSE_PRIVROOT,
9203         REISERFS_BARRIER_NONE,
9204         REISERFS_BARRIER_FLUSH,
9205 +       REISERFS_TAGGED,
9206  
9207         /* Actions on error */
9208         REISERFS_ERROR_PANIC,
9209 diff -NurpP --minimal linux-2.6.33/include/linux/sched.h linux-2.6.33-vs2.3.0.36.30/include/linux/sched.h
9210 --- linux-2.6.33/include/linux/sched.h  2010-02-25 11:52:07.000000000 +0100
9211 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/sched.h    2010-02-25 12:02:16.000000000 +0100
9212 @@ -401,25 +401,28 @@ static inline void arch_pick_mmap_layout
9213   * The mm counters are not protected by its page_table_lock,
9214   * so must be incremented atomically.
9215   */
9216 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9217 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9218 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9219 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9220 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9221 +#define __set_mm_counter(mm, member, value) \
9222 +       atomic_long_set(&(mm)->_##member, value)
9223 +#define get_mm_counter(mm, member) \
9224 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9225  
9226  #else  /* !USE_SPLIT_PTLOCKS */
9227  /*
9228   * The mm counters are protected by its page_table_lock,
9229   * so can be incremented directly.
9230   */
9231 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9232 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9233  #define get_mm_counter(mm, member) ((mm)->_##member)
9234 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9235 -#define inc_mm_counter(mm, member) (mm)->_##member++
9236 -#define dec_mm_counter(mm, member) (mm)->_##member--
9237  
9238  #endif /* !USE_SPLIT_PTLOCKS */
9239  
9240 +#define set_mm_counter(mm, member, value) \
9241 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9242 +#define add_mm_counter(mm, member, value) \
9243 +       vx_ ## member ## pages_add((mm), (value))
9244 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9245 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9246 +
9247  #define get_mm_rss(mm)                                 \
9248         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9249  #define update_hiwater_rss(mm) do {                    \
9250 @@ -1200,6 +1203,12 @@ struct sched_entity {
9251         u64                     nr_wakeups_affine_attempts;
9252         u64                     nr_wakeups_passive;
9253         u64                     nr_wakeups_idle;
9254 +#ifdef CONFIG_CFS_HARD_LIMITS
9255 +       u64                     throttle_start;
9256 +       u64                     throttle_max;
9257 +       u64                     throttle_count;
9258 +       u64                     throttle_sum;
9259 +#endif
9260  #endif
9261  
9262  #ifdef CONFIG_FAIR_GROUP_SCHED
9263 @@ -1412,6 +1421,14 @@ struct task_struct {
9264  #endif
9265         seccomp_t seccomp;
9266  
9267 +/* vserver context data */
9268 +       struct vx_info *vx_info;
9269 +       struct nx_info *nx_info;
9270 +
9271 +       xid_t xid;
9272 +       nid_t nid;
9273 +       tag_t tag;
9274 +
9275  /* Thread group tracking */
9276         u32 parent_exec_id;
9277         u32 self_exec_id;
9278 @@ -1645,6 +1662,11 @@ struct pid_namespace;
9279  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9280                         struct pid_namespace *ns);
9281  
9282 +#include <linux/vserver/base.h>
9283 +#include <linux/vserver/context.h>
9284 +#include <linux/vserver/debug.h>
9285 +#include <linux/vserver/pid.h>
9286 +
9287  static inline pid_t task_pid_nr(struct task_struct *tsk)
9288  {
9289         return tsk->pid;
9290 @@ -1658,7 +1680,8 @@ static inline pid_t task_pid_nr_ns(struc
9291  
9292  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9293  {
9294 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9295 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9296 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9297  }
9298  
9299  
9300 @@ -1671,7 +1694,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9301  
9302  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9303  {
9304 -       return pid_vnr(task_tgid(tsk));
9305 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9306  }
9307  
9308  
9309 diff -NurpP --minimal linux-2.6.33/include/linux/shmem_fs.h linux-2.6.33-vs2.3.0.36.30/include/linux/shmem_fs.h
9310 --- linux-2.6.33/include/linux/shmem_fs.h       2010-02-25 11:52:08.000000000 +0100
9311 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/shmem_fs.h 2010-02-25 12:02:16.000000000 +0100
9312 @@ -8,6 +8,9 @@
9313  
9314  #define SHMEM_NR_DIRECT 16
9315  
9316 +#define TMPFS_SUPER_MAGIC      0x01021994
9317 +
9318 +
9319  struct shmem_inode_info {
9320         spinlock_t              lock;
9321         unsigned long           flags;
9322 diff -NurpP --minimal linux-2.6.33/include/linux/stat.h linux-2.6.33-vs2.3.0.36.30/include/linux/stat.h
9323 --- linux-2.6.33/include/linux/stat.h   2008-12-25 00:26:37.000000000 +0100
9324 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/stat.h     2010-02-25 12:02:16.000000000 +0100
9325 @@ -66,6 +66,7 @@ struct kstat {
9326         unsigned int    nlink;
9327         uid_t           uid;
9328         gid_t           gid;
9329 +       tag_t           tag;
9330         dev_t           rdev;
9331         loff_t          size;
9332         struct timespec  atime;
9333 diff -NurpP --minimal linux-2.6.33/include/linux/sunrpc/auth.h linux-2.6.33-vs2.3.0.36.30/include/linux/sunrpc/auth.h
9334 --- linux-2.6.33/include/linux/sunrpc/auth.h    2009-12-03 20:02:56.000000000 +0100
9335 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/sunrpc/auth.h      2010-02-25 12:02:16.000000000 +0100
9336 @@ -25,6 +25,7 @@
9337  struct auth_cred {
9338         uid_t   uid;
9339         gid_t   gid;
9340 +       tag_t   tag;
9341         struct group_info *group_info;
9342         unsigned char machine_cred : 1;
9343  };
9344 diff -NurpP --minimal linux-2.6.33/include/linux/sunrpc/clnt.h linux-2.6.33-vs2.3.0.36.30/include/linux/sunrpc/clnt.h
9345 --- linux-2.6.33/include/linux/sunrpc/clnt.h    2009-12-03 20:02:56.000000000 +0100
9346 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/sunrpc/clnt.h      2010-02-25 12:02:16.000000000 +0100
9347 @@ -49,7 +49,8 @@ struct rpc_clnt {
9348         unsigned int            cl_softrtry : 1,/* soft timeouts */
9349                                 cl_discrtry : 1,/* disconnect before retry */
9350                                 cl_autobind : 1,/* use getport() */
9351 -                               cl_chatty   : 1;/* be verbose */
9352 +                               cl_chatty   : 1,/* be verbose */
9353 +                               cl_tag      : 1;/* context tagging */
9354  
9355         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9356         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9357 diff -NurpP --minimal linux-2.6.33/include/linux/syscalls.h linux-2.6.33-vs2.3.0.36.30/include/linux/syscalls.h
9358 --- linux-2.6.33/include/linux/syscalls.h       2010-02-25 11:52:08.000000000 +0100
9359 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/syscalls.h 2010-02-25 12:02:16.000000000 +0100
9360 @@ -496,6 +496,8 @@ asmlinkage long sys_symlink(const char _
9361  asmlinkage long sys_unlink(const char __user *pathname);
9362  asmlinkage long sys_rename(const char __user *oldname,
9363                                 const char __user *newname);
9364 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9365 +                               umode_t mode);
9366  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9367  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9368  
9369 diff -NurpP --minimal linux-2.6.33/include/linux/sysctl.h linux-2.6.33-vs2.3.0.36.30/include/linux/sysctl.h
9370 --- linux-2.6.33/include/linux/sysctl.h 2010-02-25 11:52:08.000000000 +0100
9371 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/sysctl.h   2010-02-25 12:02:16.000000000 +0100
9372 @@ -60,6 +60,7 @@ enum
9373         CTL_ABI=9,              /* Binary emulation */
9374         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9375         CTL_ARLAN=254,          /* arlan wireless driver */
9376 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9377         CTL_S390DBF=5677,       /* s390 debug */
9378         CTL_SUNRPC=7249,        /* sunrpc debug */
9379         CTL_PM=9899,            /* frv power management */
9380 @@ -94,6 +95,7 @@ enum
9381  
9382         KERN_PANIC=15,          /* int: panic timeout */
9383         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9384 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9385  
9386         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9387         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9388 diff -NurpP --minimal linux-2.6.33/include/linux/sysfs.h linux-2.6.33-vs2.3.0.36.30/include/linux/sysfs.h
9389 --- linux-2.6.33/include/linux/sysfs.h  2010-02-25 11:52:08.000000000 +0100
9390 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/sysfs.h    2010-02-25 12:02:16.000000000 +0100
9391 @@ -17,6 +17,8 @@
9392  #include <linux/list.h>
9393  #include <asm/atomic.h>
9394  
9395 +#define SYSFS_SUPER_MAGIC      0x62656572
9396 +
9397  struct kobject;
9398  struct module;
9399  
9400 diff -NurpP --minimal linux-2.6.33/include/linux/time.h linux-2.6.33-vs2.3.0.36.30/include/linux/time.h
9401 --- linux-2.6.33/include/linux/time.h   2010-02-25 11:52:08.000000000 +0100
9402 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/time.h     2010-02-25 12:02:16.000000000 +0100
9403 @@ -238,6 +238,9 @@ static __always_inline void timespec_add
9404         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9405         a->tv_nsec = ns;
9406  }
9407 +
9408 +#include <linux/vs_time.h>
9409 +
9410  #endif /* __KERNEL__ */
9411  
9412  #define NFDBITS                        __NFDBITS
9413 diff -NurpP --minimal linux-2.6.33/include/linux/types.h linux-2.6.33-vs2.3.0.36.30/include/linux/types.h
9414 --- linux-2.6.33/include/linux/types.h  2009-09-10 15:26:26.000000000 +0200
9415 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/types.h    2010-02-25 12:02:16.000000000 +0100
9416 @@ -37,6 +37,9 @@ typedef __kernel_uid32_t      uid_t;
9417  typedef __kernel_gid32_t       gid_t;
9418  typedef __kernel_uid16_t        uid16_t;
9419  typedef __kernel_gid16_t        gid16_t;
9420 +typedef unsigned int           xid_t;
9421 +typedef unsigned int           nid_t;
9422 +typedef unsigned int           tag_t;
9423  
9424  typedef unsigned long          uintptr_t;
9425  
9426 diff -NurpP --minimal linux-2.6.33/include/linux/vroot.h linux-2.6.33-vs2.3.0.36.30/include/linux/vroot.h
9427 --- linux-2.6.33/include/linux/vroot.h  1970-01-01 01:00:00.000000000 +0100
9428 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vroot.h    2010-02-25 12:02:16.000000000 +0100
9429 @@ -0,0 +1,51 @@
9430 +
9431 +/*
9432 + * include/linux/vroot.h
9433 + *
9434 + * written by Herbert Pötzl, 9/11/2002
9435 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9436 + *
9437 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9438 + * Redistribution of this file is permitted under the
9439 + * GNU General Public License.
9440 + */
9441 +
9442 +#ifndef _LINUX_VROOT_H
9443 +#define _LINUX_VROOT_H
9444 +
9445 +
9446 +#ifdef __KERNEL__
9447 +
9448 +/* Possible states of device */
9449 +enum {
9450 +       Vr_unbound,
9451 +       Vr_bound,
9452 +};
9453 +
9454 +struct vroot_device {
9455 +       int             vr_number;
9456 +       int             vr_refcnt;
9457 +
9458 +       struct semaphore        vr_ctl_mutex;
9459 +       struct block_device    *vr_device;
9460 +       int                     vr_state;
9461 +};
9462 +
9463 +
9464 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9465 +
9466 +extern int register_vroot_grb(vroot_grb_func *);
9467 +extern int unregister_vroot_grb(vroot_grb_func *);
9468 +
9469 +#endif /* __KERNEL__ */
9470 +
9471 +#define MAX_VROOT_DEFAULT      8
9472 +
9473 +/*
9474 + * IOCTL commands --- we will commandeer 0x56 ('V')
9475 + */
9476 +
9477 +#define VROOT_SET_DEV          0x5600
9478 +#define VROOT_CLR_DEV          0x5601
9479 +
9480 +#endif /* _LINUX_VROOT_H */
9481 diff -NurpP --minimal linux-2.6.33/include/linux/vs_base.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_base.h
9482 --- linux-2.6.33/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
9483 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_base.h  2010-02-25 12:02:16.000000000 +0100
9484 @@ -0,0 +1,10 @@
9485 +#ifndef _VS_BASE_H
9486 +#define _VS_BASE_H
9487 +
9488 +#include "vserver/base.h"
9489 +#include "vserver/check.h"
9490 +#include "vserver/debug.h"
9491 +
9492 +#else
9493 +#warning duplicate inclusion
9494 +#endif
9495 diff -NurpP --minimal linux-2.6.33/include/linux/vs_context.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_context.h
9496 --- linux-2.6.33/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
9497 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_context.h       2010-02-25 12:02:16.000000000 +0100
9498 @@ -0,0 +1,242 @@
9499 +#ifndef _VS_CONTEXT_H
9500 +#define _VS_CONTEXT_H
9501 +
9502 +#include "vserver/base.h"
9503 +#include "vserver/check.h"
9504 +#include "vserver/context.h"
9505 +#include "vserver/history.h"
9506 +#include "vserver/debug.h"
9507 +
9508 +#include <linux/sched.h>
9509 +
9510 +
9511 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9512 +
9513 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9514 +       const char *_file, int _line, void *_here)
9515 +{
9516 +       if (!vxi)
9517 +               return NULL;
9518 +
9519 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9520 +               vxi, vxi ? vxi->vx_id : 0,
9521 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9522 +               _file, _line);
9523 +       __vxh_get_vx_info(vxi, _here);
9524 +
9525 +       atomic_inc(&vxi->vx_usecnt);
9526 +       return vxi;
9527 +}
9528 +
9529 +
9530 +extern void free_vx_info(struct vx_info *);
9531 +
9532 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9533 +
9534 +static inline void __put_vx_info(struct vx_info *vxi,
9535 +       const char *_file, int _line, void *_here)
9536 +{
9537 +       if (!vxi)
9538 +               return;
9539 +
9540 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9541 +               vxi, vxi ? vxi->vx_id : 0,
9542 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9543 +               _file, _line);
9544 +       __vxh_put_vx_info(vxi, _here);
9545 +
9546 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9547 +               free_vx_info(vxi);
9548 +}
9549 +
9550 +
9551 +#define init_vx_info(p, i) \
9552 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9553 +
9554 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9555 +       const char *_file, int _line, void *_here)
9556 +{
9557 +       if (vxi) {
9558 +               vxlprintk(VXD_CBIT(xid, 3),
9559 +                       "init_vx_info(%p[#%d.%d])",
9560 +                       vxi, vxi ? vxi->vx_id : 0,
9561 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9562 +                       _file, _line);
9563 +               __vxh_init_vx_info(vxi, vxp, _here);
9564 +
9565 +               atomic_inc(&vxi->vx_usecnt);
9566 +       }
9567 +       *vxp = vxi;
9568 +}
9569 +
9570 +
9571 +#define set_vx_info(p, i) \
9572 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9573 +
9574 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9575 +       const char *_file, int _line, void *_here)
9576 +{
9577 +       struct vx_info *vxo;
9578 +
9579 +       if (!vxi)
9580 +               return;
9581 +
9582 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9583 +               vxi, vxi ? vxi->vx_id : 0,
9584 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9585 +               _file, _line);
9586 +       __vxh_set_vx_info(vxi, vxp, _here);
9587 +
9588 +       atomic_inc(&vxi->vx_usecnt);
9589 +       vxo = xchg(vxp, vxi);
9590 +       BUG_ON(vxo);
9591 +}
9592 +
9593 +
9594 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9595 +
9596 +static inline void __clr_vx_info(struct vx_info **vxp,
9597 +       const char *_file, int _line, void *_here)
9598 +{
9599 +       struct vx_info *vxo;
9600 +
9601 +       vxo = xchg(vxp, NULL);
9602 +       if (!vxo)
9603 +               return;
9604 +
9605 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9606 +               vxo, vxo ? vxo->vx_id : 0,
9607 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9608 +               _file, _line);
9609 +       __vxh_clr_vx_info(vxo, vxp, _here);
9610 +
9611 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9612 +               free_vx_info(vxo);
9613 +}
9614 +
9615 +
9616 +#define claim_vx_info(v, p) \
9617 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9618 +
9619 +static inline void __claim_vx_info(struct vx_info *vxi,
9620 +       struct task_struct *task,
9621 +       const char *_file, int _line, void *_here)
9622 +{
9623 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9624 +               vxi, vxi ? vxi->vx_id : 0,
9625 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9626 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9627 +               task, _file, _line);
9628 +       __vxh_claim_vx_info(vxi, task, _here);
9629 +
9630 +       atomic_inc(&vxi->vx_tasks);
9631 +}
9632 +
9633 +
9634 +extern void unhash_vx_info(struct vx_info *);
9635 +
9636 +#define release_vx_info(v, p) \
9637 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9638 +
9639 +static inline void __release_vx_info(struct vx_info *vxi,
9640 +       struct task_struct *task,
9641 +       const char *_file, int _line, void *_here)
9642 +{
9643 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9644 +               vxi, vxi ? vxi->vx_id : 0,
9645 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9646 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9647 +               task, _file, _line);
9648 +       __vxh_release_vx_info(vxi, task, _here);
9649 +
9650 +       might_sleep();
9651 +
9652 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9653 +               unhash_vx_info(vxi);
9654 +}
9655 +
9656 +
9657 +#define task_get_vx_info(p) \
9658 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9659 +
9660 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9661 +       const char *_file, int _line, void *_here)
9662 +{
9663 +       struct vx_info *vxi;
9664 +
9665 +       task_lock(p);
9666 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9667 +               p, _file, _line);
9668 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9669 +       task_unlock(p);
9670 +       return vxi;
9671 +}
9672 +
9673 +
9674 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9675 +{
9676 +       if (waitqueue_active(&vxi->vx_wait))
9677 +               wake_up_interruptible(&vxi->vx_wait);
9678 +}
9679 +
9680 +
9681 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9682 +
9683 +static inline void __enter_vx_info(struct vx_info *vxi,
9684 +       struct vx_info_save *vxis, const char *_file, int _line)
9685 +{
9686 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9687 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9688 +               current->xid, current->vx_info, _file, _line);
9689 +       vxis->vxi = xchg(&current->vx_info, vxi);
9690 +       vxis->xid = current->xid;
9691 +       current->xid = vxi ? vxi->vx_id : 0;
9692 +}
9693 +
9694 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9695 +
9696 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9697 +       const char *_file, int _line)
9698 +{
9699 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9700 +               vxis, vxis->xid, vxis->vxi, current,
9701 +               current->xid, current->vx_info, _file, _line);
9702 +       (void)xchg(&current->vx_info, vxis->vxi);
9703 +       current->xid = vxis->xid;
9704 +}
9705 +
9706 +
9707 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9708 +{
9709 +       vxis->vxi = xchg(&current->vx_info, NULL);
9710 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9711 +}
9712 +
9713 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9714 +{
9715 +       (void)xchg(&current->xid, vxis->xid);
9716 +       (void)xchg(&current->vx_info, vxis->vxi);
9717 +}
9718 +
9719 +#define task_is_init(p) \
9720 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9721 +
9722 +static inline int __task_is_init(struct task_struct *p,
9723 +       const char *_file, int _line, void *_here)
9724 +{
9725 +       int is_init = is_global_init(p);
9726 +
9727 +       task_lock(p);
9728 +       if (p->vx_info)
9729 +               is_init = p->vx_info->vx_initpid == p->pid;
9730 +       task_unlock(p);
9731 +       return is_init;
9732 +}
9733 +
9734 +extern void exit_vx_info(struct task_struct *, int);
9735 +extern void exit_vx_info_early(struct task_struct *, int);
9736 +
9737 +
9738 +#else
9739 +#warning duplicate inclusion
9740 +#endif
9741 diff -NurpP --minimal linux-2.6.33/include/linux/vs_cowbl.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_cowbl.h
9742 --- linux-2.6.33/include/linux/vs_cowbl.h       1970-01-01 01:00:00.000000000 +0100
9743 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_cowbl.h 2010-02-25 12:02:16.000000000 +0100
9744 @@ -0,0 +1,47 @@
9745 +#ifndef _VS_COWBL_H
9746 +#define _VS_COWBL_H
9747 +
9748 +#include <linux/fs.h>
9749 +#include <linux/dcache.h>
9750 +#include <linux/namei.h>
9751 +
9752 +extern struct dentry *cow_break_link(const char *pathname);
9753 +
9754 +static inline int cow_check_and_break(struct path *path)
9755 +{
9756 +       struct inode *inode = path->dentry->d_inode;
9757 +       int error = 0;
9758 +
9759 +       /* do we need this check? */
9760 +       if (IS_RDONLY(inode))
9761 +               return -EROFS;
9762 +
9763 +       if (IS_COW(inode)) {
9764 +               if (IS_COW_LINK(inode)) {
9765 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9766 +                       char *pp, *buf;
9767 +
9768 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9769 +                       if (!buf) {
9770 +                               return -ENOMEM;
9771 +                       }
9772 +                       pp = d_path(path, buf, PATH_MAX);
9773 +                       new_dentry = cow_break_link(pp);
9774 +                       kfree(buf);
9775 +                       if (!IS_ERR(new_dentry)) {
9776 +                               path->dentry = new_dentry;
9777 +                               dput(old_dentry);
9778 +                       } else
9779 +                               error = PTR_ERR(new_dentry);
9780 +               } else {
9781 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9782 +                       inode->i_ctime = CURRENT_TIME;
9783 +                       mark_inode_dirty(inode);
9784 +               }
9785 +       }
9786 +       return error;
9787 +}
9788 +
9789 +#else
9790 +#warning duplicate inclusion
9791 +#endif
9792 diff -NurpP --minimal linux-2.6.33/include/linux/vs_cvirt.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_cvirt.h
9793 --- linux-2.6.33/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
9794 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_cvirt.h 2010-02-25 12:02:16.000000000 +0100
9795 @@ -0,0 +1,50 @@
9796 +#ifndef _VS_CVIRT_H
9797 +#define _VS_CVIRT_H
9798 +
9799 +#include "vserver/cvirt.h"
9800 +#include "vserver/context.h"
9801 +#include "vserver/base.h"
9802 +#include "vserver/check.h"
9803 +#include "vserver/debug.h"
9804 +
9805 +
9806 +static inline void vx_activate_task(struct task_struct *p)
9807 +{
9808 +       struct vx_info *vxi;
9809 +
9810 +       if ((vxi = p->vx_info)) {
9811 +               vx_update_load(vxi);
9812 +               atomic_inc(&vxi->cvirt.nr_running);
9813 +       }
9814 +}
9815 +
9816 +static inline void vx_deactivate_task(struct task_struct *p)
9817 +{
9818 +       struct vx_info *vxi;
9819 +
9820 +       if ((vxi = p->vx_info)) {
9821 +               vx_update_load(vxi);
9822 +               atomic_dec(&vxi->cvirt.nr_running);
9823 +       }
9824 +}
9825 +
9826 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9827 +{
9828 +       struct vx_info *vxi;
9829 +
9830 +       if ((vxi = p->vx_info))
9831 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9832 +}
9833 +
9834 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9835 +{
9836 +       struct vx_info *vxi;
9837 +
9838 +       if ((vxi = p->vx_info))
9839 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9840 +}
9841 +
9842 +
9843 +#else
9844 +#warning duplicate inclusion
9845 +#endif
9846 diff -NurpP --minimal linux-2.6.33/include/linux/vs_device.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_device.h
9847 --- linux-2.6.33/include/linux/vs_device.h      1970-01-01 01:00:00.000000000 +0100
9848 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_device.h        2010-02-25 12:02:16.000000000 +0100
9849 @@ -0,0 +1,45 @@
9850 +#ifndef _VS_DEVICE_H
9851 +#define _VS_DEVICE_H
9852 +
9853 +#include "vserver/base.h"
9854 +#include "vserver/device.h"
9855 +#include "vserver/debug.h"
9856 +
9857 +
9858 +#ifdef CONFIG_VSERVER_DEVICE
9859 +
9860 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9861 +
9862 +#define vs_device_perm(v, d, m, p) \
9863 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9864 +
9865 +#else
9866 +
9867 +static inline
9868 +int vs_map_device(struct vx_info *vxi,
9869 +       dev_t device, dev_t *target, umode_t mode)
9870 +{
9871 +       if (target)
9872 +               *target = device;
9873 +       return ~0;
9874 +}
9875 +
9876 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9877 +
9878 +#endif
9879 +
9880 +
9881 +#define vs_map_chrdev(d, t, p) \
9882 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9883 +#define vs_map_blkdev(d, t, p) \
9884 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9885 +
9886 +#define vs_chrdev_perm(d, p) \
9887 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9888 +#define vs_blkdev_perm(d, p) \
9889 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9890 +
9891 +
9892 +#else
9893 +#warning duplicate inclusion
9894 +#endif
9895 diff -NurpP --minimal linux-2.6.33/include/linux/vs_dlimit.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_dlimit.h
9896 --- linux-2.6.33/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
9897 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_dlimit.h        2010-02-25 12:02:16.000000000 +0100
9898 @@ -0,0 +1,216 @@
9899 +#ifndef _VS_DLIMIT_H
9900 +#define _VS_DLIMIT_H
9901 +
9902 +#include <linux/fs.h>
9903 +
9904 +#include "vserver/dlimit.h"
9905 +#include "vserver/base.h"
9906 +#include "vserver/debug.h"
9907 +
9908 +
9909 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9910 +
9911 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9912 +       const char *_file, int _line)
9913 +{
9914 +       if (!dli)
9915 +               return NULL;
9916 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9917 +               dli, dli ? dli->dl_tag : 0,
9918 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9919 +               _file, _line);
9920 +       atomic_inc(&dli->dl_usecnt);
9921 +       return dli;
9922 +}
9923 +
9924 +
9925 +#define free_dl_info(i) \
9926 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9927 +
9928 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9929 +
9930 +static inline void __put_dl_info(struct dl_info *dli,
9931 +       const char *_file, int _line)
9932 +{
9933 +       if (!dli)
9934 +               return;
9935 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9936 +               dli, dli ? dli->dl_tag : 0,
9937 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9938 +               _file, _line);
9939 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9940 +               free_dl_info(dli);
9941 +}
9942 +
9943 +
9944 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9945 +
9946 +static inline int __dl_alloc_space(struct super_block *sb,
9947 +       tag_t tag, dlsize_t nr, const char *file, int line)
9948 +{
9949 +       struct dl_info *dli = NULL;
9950 +       int ret = 0;
9951 +
9952 +       if (nr == 0)
9953 +               goto out;
9954 +       dli = locate_dl_info(sb, tag);
9955 +       if (!dli)
9956 +               goto out;
9957 +
9958 +       spin_lock(&dli->dl_lock);
9959 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9960 +       if (!ret)
9961 +               dli->dl_space_used += nr;
9962 +       spin_unlock(&dli->dl_lock);
9963 +       put_dl_info(dli);
9964 +out:
9965 +       vxlprintk(VXD_CBIT(dlim, 1),
9966 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9967 +               sb, tag, __dlimit_char(dli), (long long)nr,
9968 +               ret, file, line);
9969 +       return ret;
9970 +}
9971 +
9972 +static inline void __dl_free_space(struct super_block *sb,
9973 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9974 +{
9975 +       struct dl_info *dli = NULL;
9976 +
9977 +       if (nr == 0)
9978 +               goto out;
9979 +       dli = locate_dl_info(sb, tag);
9980 +       if (!dli)
9981 +               goto out;
9982 +
9983 +       spin_lock(&dli->dl_lock);
9984 +       if (dli->dl_space_used > nr)
9985 +               dli->dl_space_used -= nr;
9986 +       else
9987 +               dli->dl_space_used = 0;
9988 +       spin_unlock(&dli->dl_lock);
9989 +       put_dl_info(dli);
9990 +out:
9991 +       vxlprintk(VXD_CBIT(dlim, 1),
9992 +               "FREE  (%p,#%d)%c %lld bytes",
9993 +               sb, tag, __dlimit_char(dli), (long long)nr,
9994 +               _file, _line);
9995 +}
9996 +
9997 +static inline int __dl_alloc_inode(struct super_block *sb,
9998 +       tag_t tag, const char *_file, int _line)
9999 +{
10000 +       struct dl_info *dli;
10001 +       int ret = 0;
10002 +
10003 +       dli = locate_dl_info(sb, tag);
10004 +       if (!dli)
10005 +               goto out;
10006 +
10007 +       spin_lock(&dli->dl_lock);
10008 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
10009 +       if (!ret)
10010 +               dli->dl_inodes_used++;
10011 +       spin_unlock(&dli->dl_lock);
10012 +       put_dl_info(dli);
10013 +out:
10014 +       vxlprintk(VXD_CBIT(dlim, 0),
10015 +               "ALLOC (%p,#%d)%c inode (%d)",
10016 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10017 +       return ret;
10018 +}
10019 +
10020 +static inline void __dl_free_inode(struct super_block *sb,
10021 +       tag_t tag, const char *_file, int _line)
10022 +{
10023 +       struct dl_info *dli;
10024 +
10025 +       dli = locate_dl_info(sb, tag);
10026 +       if (!dli)
10027 +               goto out;
10028 +
10029 +       spin_lock(&dli->dl_lock);
10030 +       if (dli->dl_inodes_used > 1)
10031 +               dli->dl_inodes_used--;
10032 +       else
10033 +               dli->dl_inodes_used = 0;
10034 +       spin_unlock(&dli->dl_lock);
10035 +       put_dl_info(dli);
10036 +out:
10037 +       vxlprintk(VXD_CBIT(dlim, 0),
10038 +               "FREE  (%p,#%d)%c inode",
10039 +               sb, tag, __dlimit_char(dli), _file, _line);
10040 +}
10041 +
10042 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10043 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10044 +       const char *_file, int _line)
10045 +{
10046 +       struct dl_info *dli;
10047 +       uint64_t broot, bfree;
10048 +
10049 +       dli = locate_dl_info(sb, tag);
10050 +       if (!dli)
10051 +               return;
10052 +
10053 +       spin_lock(&dli->dl_lock);
10054 +       broot = (dli->dl_space_total -
10055 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10056 +               >> sb->s_blocksize_bits;
10057 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10058 +                       >> sb->s_blocksize_bits;
10059 +       spin_unlock(&dli->dl_lock);
10060 +
10061 +       vxlprintk(VXD_CBIT(dlim, 2),
10062 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10063 +               (long long)bfree, (long long)broot,
10064 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10065 +               _file, _line);
10066 +       if (free_blocks) {
10067 +               if (*free_blocks > bfree)
10068 +                       *free_blocks = bfree;
10069 +       }
10070 +       if (root_blocks) {
10071 +               if (*root_blocks > broot)
10072 +                       *root_blocks = broot;
10073 +       }
10074 +       put_dl_info(dli);
10075 +}
10076 +
10077 +#define dl_prealloc_space(in, bytes) \
10078 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10079 +               __FILE__, __LINE__ )
10080 +
10081 +#define dl_alloc_space(in, bytes) \
10082 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10083 +               __FILE__, __LINE__ )
10084 +
10085 +#define dl_reserve_space(in, bytes) \
10086 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10087 +               __FILE__, __LINE__ )
10088 +
10089 +#define dl_claim_space(in, bytes) (0)
10090 +
10091 +#define dl_release_space(in, bytes) \
10092 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10093 +               __FILE__, __LINE__ )
10094 +
10095 +#define dl_free_space(in, bytes) \
10096 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10097 +               __FILE__, __LINE__ )
10098 +
10099 +
10100 +
10101 +#define dl_alloc_inode(in) \
10102 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10103 +
10104 +#define dl_free_inode(in) \
10105 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10106 +
10107 +
10108 +#define dl_adjust_block(sb, tag, fb, rb) \
10109 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10110 +
10111 +
10112 +#else
10113 +#warning duplicate inclusion
10114 +#endif
10115 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/base.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/base.h
10116 --- linux-2.6.33/include/linux/vserver/base.h   1970-01-01 01:00:00.000000000 +0100
10117 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/base.h     2010-02-25 12:02:16.000000000 +0100
10118 @@ -0,0 +1,170 @@
10119 +#ifndef _VX_BASE_H
10120 +#define _VX_BASE_H
10121 +
10122 +
10123 +/* context state changes */
10124 +
10125 +enum {
10126 +       VSC_STARTUP = 1,
10127 +       VSC_SHUTDOWN,
10128 +
10129 +       VSC_NETUP,
10130 +       VSC_NETDOWN,
10131 +};
10132 +
10133 +
10134 +
10135 +#define vx_task_xid(t) ((t)->xid)
10136 +
10137 +#define vx_current_xid() vx_task_xid(current)
10138 +
10139 +#define current_vx_info() (current->vx_info)
10140 +
10141 +
10142 +#define nx_task_nid(t) ((t)->nid)
10143 +
10144 +#define nx_current_nid() nx_task_nid(current)
10145 +
10146 +#define current_nx_info() (current->nx_info)
10147 +
10148 +
10149 +/* generic flag merging */
10150 +
10151 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10152 +
10153 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10154 +
10155 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10156 +
10157 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10158 +
10159 +
10160 +/* context flags */
10161 +
10162 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10163 +
10164 +#define vx_current_flags()     __vx_flags(current_vx_info())
10165 +
10166 +#define vx_info_flags(v, m, f) \
10167 +       vs_check_flags(__vx_flags(v), m, f)
10168 +
10169 +#define task_vx_flags(t, m, f) \
10170 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10171 +
10172 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10173 +
10174 +
10175 +/* context caps */
10176 +
10177 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10178 +
10179 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10180 +
10181 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10182 +
10183 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10184 +
10185 +
10186 +
10187 +/* network flags */
10188 +
10189 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10190 +
10191 +#define nx_current_flags()     __nx_flags(current_nx_info())
10192 +
10193 +#define nx_info_flags(n, m, f) \
10194 +       vs_check_flags(__nx_flags(n), m, f)
10195 +
10196 +#define task_nx_flags(t, m, f) \
10197 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10198 +
10199 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10200 +
10201 +
10202 +/* network caps */
10203 +
10204 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10205 +
10206 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10207 +
10208 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10209 +
10210 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10211 +
10212 +
10213 +/* context mask capabilities */
10214 +
10215 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10216 +
10217 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10218 +
10219 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10220 +
10221 +
10222 +/* context bcap mask */
10223 +
10224 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10225 +
10226 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10227 +
10228 +
10229 +/* mask given bcaps */
10230 +
10231 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10232 +
10233 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10234 +
10235 +
10236 +/* masked cap_bset */
10237 +
10238 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10239 +
10240 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10241 +
10242 +#if 0
10243 +#define vx_info_mbcap(v, b) \
10244 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10245 +       vx_info_bcaps(v, b) : (b))
10246 +
10247 +#define task_vx_mbcap(t, b) \
10248 +       vx_info_mbcap((t)->vx_info, (t)->b)
10249 +
10250 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10251 +#endif
10252 +
10253 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10254 +
10255 +#define vx_capable(b, c) (capable(b) || \
10256 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10257 +
10258 +#define nx_capable(b, c) (capable(b) || \
10259 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10260 +
10261 +#define vx_task_initpid(t, n) \
10262 +       ((t)->vx_info && \
10263 +       ((t)->vx_info->vx_initpid == (n)))
10264 +
10265 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10266 +
10267 +
10268 +/* context unshare mask */
10269 +
10270 +#define __vx_umask(v)          ((v)->vx_umask)
10271 +
10272 +#define vx_current_umask()     __vx_umask(current_vx_info())
10273 +
10274 +#define vx_can_unshare(b, f) (capable(b) || \
10275 +       (cap_raised(current_cap(), b) && \
10276 +       !((f) & ~vx_current_umask())))
10277 +
10278 +
10279 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10280 +
10281 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10282 +
10283 +
10284 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10285 +
10286 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10287 +
10288 +#endif
10289 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cacct_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cacct_cmd.h
10290 --- linux-2.6.33/include/linux/vserver/cacct_cmd.h      1970-01-01 01:00:00.000000000 +0100
10291 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cacct_cmd.h        2010-02-25 12:02:16.000000000 +0100
10292 @@ -0,0 +1,23 @@
10293 +#ifndef _VX_CACCT_CMD_H
10294 +#define _VX_CACCT_CMD_H
10295 +
10296 +
10297 +/* virtual host info name commands */
10298 +
10299 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10300 +
10301 +struct vcmd_sock_stat_v0 {
10302 +       uint32_t field;
10303 +       uint32_t count[3];
10304 +       uint64_t total[3];
10305 +};
10306 +
10307 +
10308 +#ifdef __KERNEL__
10309 +
10310 +#include <linux/compiler.h>
10311 +
10312 +extern int vc_sock_stat(struct vx_info *, void __user *);
10313 +
10314 +#endif /* __KERNEL__ */
10315 +#endif /* _VX_CACCT_CMD_H */
10316 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cacct_def.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cacct_def.h
10317 --- linux-2.6.33/include/linux/vserver/cacct_def.h      1970-01-01 01:00:00.000000000 +0100
10318 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cacct_def.h        2010-02-25 12:02:16.000000000 +0100
10319 @@ -0,0 +1,43 @@
10320 +#ifndef _VX_CACCT_DEF_H
10321 +#define _VX_CACCT_DEF_H
10322 +
10323 +#include <asm/atomic.h>
10324 +#include <linux/vserver/cacct.h>
10325 +
10326 +
10327 +struct _vx_sock_acc {
10328 +       atomic_long_t count;
10329 +       atomic_long_t total;
10330 +};
10331 +
10332 +/* context sub struct */
10333 +
10334 +struct _vx_cacct {
10335 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10336 +       atomic_t slab[8];
10337 +       atomic_t page[6][8];
10338 +};
10339 +
10340 +#ifdef CONFIG_VSERVER_DEBUG
10341 +
10342 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10343 +{
10344 +       int i, j;
10345 +
10346 +       printk("\t_vx_cacct:");
10347 +       for (i = 0; i < 6; i++) {
10348 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10349 +
10350 +               printk("\t [%d] =", i);
10351 +               for (j = 0; j < 3; j++) {
10352 +                       printk(" [%d] = %8lu, %8lu", j,
10353 +                               atomic_long_read(&ptr[j].count),
10354 +                               atomic_long_read(&ptr[j].total));
10355 +               }
10356 +               printk("\n");
10357 +       }
10358 +}
10359 +
10360 +#endif
10361 +
10362 +#endif /* _VX_CACCT_DEF_H */
10363 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cacct.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cacct.h
10364 --- linux-2.6.33/include/linux/vserver/cacct.h  1970-01-01 01:00:00.000000000 +0100
10365 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cacct.h    2010-02-25 12:02:16.000000000 +0100
10366 @@ -0,0 +1,15 @@
10367 +#ifndef _VX_CACCT_H
10368 +#define _VX_CACCT_H
10369 +
10370 +
10371 +enum sock_acc_field {
10372 +       VXA_SOCK_UNSPEC = 0,
10373 +       VXA_SOCK_UNIX,
10374 +       VXA_SOCK_INET,
10375 +       VXA_SOCK_INET6,
10376 +       VXA_SOCK_PACKET,
10377 +       VXA_SOCK_OTHER,
10378 +       VXA_SOCK_SIZE   /* array size */
10379 +};
10380 +
10381 +#endif /* _VX_CACCT_H */
10382 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cacct_int.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cacct_int.h
10383 --- linux-2.6.33/include/linux/vserver/cacct_int.h      1970-01-01 01:00:00.000000000 +0100
10384 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cacct_int.h        2010-02-25 12:02:16.000000000 +0100
10385 @@ -0,0 +1,21 @@
10386 +#ifndef _VX_CACCT_INT_H
10387 +#define _VX_CACCT_INT_H
10388 +
10389 +
10390 +#ifdef __KERNEL__
10391 +
10392 +static inline
10393 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10394 +{
10395 +       return atomic_long_read(&cacct->sock[type][pos].count);
10396 +}
10397 +
10398 +
10399 +static inline
10400 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10401 +{
10402 +       return atomic_long_read(&cacct->sock[type][pos].total);
10403 +}
10404 +
10405 +#endif /* __KERNEL__ */
10406 +#endif /* _VX_CACCT_INT_H */
10407 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/check.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/check.h
10408 --- linux-2.6.33/include/linux/vserver/check.h  1970-01-01 01:00:00.000000000 +0100
10409 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/check.h    2010-02-25 12:02:16.000000000 +0100
10410 @@ -0,0 +1,89 @@
10411 +#ifndef _VS_CHECK_H
10412 +#define _VS_CHECK_H
10413 +
10414 +
10415 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10416 +
10417 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10418 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10419 +#else
10420 +#define MIN_D_CONTEXT  65536
10421 +#endif
10422 +
10423 +/* check conditions */
10424 +
10425 +#define VS_ADMIN       0x0001
10426 +#define VS_WATCH       0x0002
10427 +#define VS_HIDE                0x0004
10428 +#define VS_HOSTID      0x0008
10429 +
10430 +#define VS_IDENT       0x0010
10431 +#define VS_EQUIV       0x0020
10432 +#define VS_PARENT      0x0040
10433 +#define VS_CHILD       0x0080
10434 +
10435 +#define VS_ARG_MASK    0x00F0
10436 +
10437 +#define VS_DYNAMIC     0x0100
10438 +#define VS_STATIC      0x0200
10439 +
10440 +#define VS_ATR_MASK    0x0F00
10441 +
10442 +#ifdef CONFIG_VSERVER_PRIVACY
10443 +#define VS_ADMIN_P     (0)
10444 +#define VS_WATCH_P     (0)
10445 +#else
10446 +#define VS_ADMIN_P     VS_ADMIN
10447 +#define VS_WATCH_P     VS_WATCH
10448 +#endif
10449 +
10450 +#define VS_HARDIRQ     0x1000
10451 +#define VS_SOFTIRQ     0x2000
10452 +#define VS_IRQ         0x4000
10453 +
10454 +#define VS_IRQ_MASK    0xF000
10455 +
10456 +#include <linux/hardirq.h>
10457 +
10458 +/*
10459 + * check current context for ADMIN/WATCH and
10460 + * optionally against supplied argument
10461 + */
10462 +static inline int __vs_check(int cid, int id, unsigned int mode)
10463 +{
10464 +       if (mode & VS_ARG_MASK) {
10465 +               if ((mode & VS_IDENT) && (id == cid))
10466 +                       return 1;
10467 +       }
10468 +       if (mode & VS_ATR_MASK) {
10469 +               if ((mode & VS_DYNAMIC) &&
10470 +                       (id >= MIN_D_CONTEXT) &&
10471 +                       (id <= MAX_S_CONTEXT))
10472 +                       return 1;
10473 +               if ((mode & VS_STATIC) &&
10474 +                       (id > 1) && (id < MIN_D_CONTEXT))
10475 +                       return 1;
10476 +       }
10477 +       if (mode & VS_IRQ_MASK) {
10478 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10479 +                       return 1;
10480 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10481 +                       return 1;
10482 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10483 +                       return 1;
10484 +       }
10485 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10486 +               ((mode & VS_WATCH) && (cid == 1)) ||
10487 +               ((mode & VS_HOSTID) && (id == 0)));
10488 +}
10489 +
10490 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10491 +
10492 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10493 +
10494 +
10495 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10496 +
10497 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10498 +
10499 +#endif
10500 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/context_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/context_cmd.h
10501 --- linux-2.6.33/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
10502 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/context_cmd.h      2010-02-25 12:02:16.000000000 +0100
10503 @@ -0,0 +1,145 @@
10504 +#ifndef _VX_CONTEXT_CMD_H
10505 +#define _VX_CONTEXT_CMD_H
10506 +
10507 +
10508 +/* vinfo commands */
10509 +
10510 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10511 +
10512 +#ifdef __KERNEL__
10513 +extern int vc_task_xid(uint32_t);
10514 +
10515 +#endif /* __KERNEL__ */
10516 +
10517 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10518 +
10519 +struct vcmd_vx_info_v0 {
10520 +       uint32_t xid;
10521 +       uint32_t initpid;
10522 +       /* more to come */
10523 +};
10524 +
10525 +#ifdef __KERNEL__
10526 +extern int vc_vx_info(struct vx_info *, void __user *);
10527 +
10528 +#endif /* __KERNEL__ */
10529 +
10530 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10531 +
10532 +struct vcmd_ctx_stat_v0 {
10533 +       uint32_t usecnt;
10534 +       uint32_t tasks;
10535 +       /* more to come */
10536 +};
10537 +
10538 +#ifdef __KERNEL__
10539 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10540 +
10541 +#endif /* __KERNEL__ */
10542 +
10543 +/* context commands */
10544 +
10545 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10546 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10547 +
10548 +struct vcmd_ctx_create {
10549 +       uint64_t flagword;
10550 +};
10551 +
10552 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10553 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10554 +
10555 +struct vcmd_ctx_migrate {
10556 +       uint64_t flagword;
10557 +};
10558 +
10559 +#ifdef __KERNEL__
10560 +extern int vc_ctx_create(uint32_t, void __user *);
10561 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10562 +
10563 +#endif /* __KERNEL__ */
10564 +
10565 +
10566 +/* flag commands */
10567 +
10568 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10569 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10570 +
10571 +struct vcmd_ctx_flags_v0 {
10572 +       uint64_t flagword;
10573 +       uint64_t mask;
10574 +};
10575 +
10576 +#ifdef __KERNEL__
10577 +extern int vc_get_cflags(struct vx_info *, void __user *);
10578 +extern int vc_set_cflags(struct vx_info *, void __user *);
10579 +
10580 +#endif /* __KERNEL__ */
10581 +
10582 +
10583 +/* context caps commands */
10584 +
10585 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10586 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10587 +
10588 +struct vcmd_ctx_caps_v1 {
10589 +       uint64_t ccaps;
10590 +       uint64_t cmask;
10591 +};
10592 +
10593 +#ifdef __KERNEL__
10594 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10595 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10596 +
10597 +#endif /* __KERNEL__ */
10598 +
10599 +
10600 +/* bcaps commands */
10601 +
10602 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10603 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10604 +
10605 +struct vcmd_bcaps {
10606 +       uint64_t bcaps;
10607 +       uint64_t bmask;
10608 +};
10609 +
10610 +#ifdef __KERNEL__
10611 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10612 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10613 +
10614 +#endif /* __KERNEL__ */
10615 +
10616 +
10617 +/* umask commands */
10618 +
10619 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10620 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10621 +
10622 +struct vcmd_umask {
10623 +       uint64_t umask;
10624 +       uint64_t mask;
10625 +};
10626 +
10627 +#ifdef __KERNEL__
10628 +extern int vc_get_umask(struct vx_info *, void __user *);
10629 +extern int vc_set_umask(struct vx_info *, void __user *);
10630 +
10631 +#endif /* __KERNEL__ */
10632 +
10633 +
10634 +/* OOM badness */
10635 +
10636 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10637 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10638 +
10639 +struct vcmd_badness_v0 {
10640 +       int64_t bias;
10641 +};
10642 +
10643 +#ifdef __KERNEL__
10644 +extern int vc_get_badness(struct vx_info *, void __user *);
10645 +extern int vc_set_badness(struct vx_info *, void __user *);
10646 +
10647 +#endif /* __KERNEL__ */
10648 +#endif /* _VX_CONTEXT_CMD_H */
10649 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/context.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/context.h
10650 --- linux-2.6.33/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
10651 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/context.h  2010-02-25 12:02:16.000000000 +0100
10652 @@ -0,0 +1,183 @@
10653 +#ifndef _VX_CONTEXT_H
10654 +#define _VX_CONTEXT_H
10655 +
10656 +#include <linux/types.h>
10657 +#include <linux/capability.h>
10658 +
10659 +
10660 +/* context flags */
10661 +
10662 +#define VXF_INFO_SCHED         0x00000002
10663 +#define VXF_INFO_NPROC         0x00000004
10664 +#define VXF_INFO_PRIVATE       0x00000008
10665 +
10666 +#define VXF_INFO_INIT          0x00000010
10667 +#define VXF_INFO_HIDE          0x00000020
10668 +#define VXF_INFO_ULIMIT                0x00000040
10669 +#define VXF_INFO_NSPACE                0x00000080
10670 +
10671 +#define VXF_SCHED_HARD         0x00000100
10672 +#define VXF_SCHED_PRIO         0x00000200
10673 +#define VXF_SCHED_PAUSE                0x00000400
10674 +
10675 +#define VXF_VIRT_MEM           0x00010000
10676 +#define VXF_VIRT_UPTIME                0x00020000
10677 +#define VXF_VIRT_CPU           0x00040000
10678 +#define VXF_VIRT_LOAD          0x00080000
10679 +#define VXF_VIRT_TIME          0x00100000
10680 +
10681 +#define VXF_HIDE_MOUNT         0x01000000
10682 +/* was VXF_HIDE_NETIF          0x02000000 */
10683 +#define VXF_HIDE_VINFO         0x04000000
10684 +
10685 +#define VXF_STATE_SETUP                (1ULL << 32)
10686 +#define VXF_STATE_INIT         (1ULL << 33)
10687 +#define VXF_STATE_ADMIN                (1ULL << 34)
10688 +
10689 +#define VXF_SC_HELPER          (1ULL << 36)
10690 +#define VXF_REBOOT_KILL                (1ULL << 37)
10691 +#define VXF_PERSISTENT         (1ULL << 38)
10692 +
10693 +#define VXF_FORK_RSS           (1ULL << 48)
10694 +#define VXF_PROLIFIC           (1ULL << 49)
10695 +
10696 +#define VXF_IGNEG_NICE         (1ULL << 52)
10697 +
10698 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10699 +
10700 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10701 +
10702 +
10703 +/* context migration */
10704 +
10705 +#define VXM_SET_INIT           0x00000001
10706 +#define VXM_SET_REAPER         0x00000002
10707 +
10708 +/* context caps */
10709 +
10710 +#define VXC_CAP_MASK           0x00000000
10711 +
10712 +#define VXC_SET_UTSNAME                0x00000001
10713 +#define VXC_SET_RLIMIT         0x00000002
10714 +#define VXC_FS_SECURITY                0x00000004
10715 +#define VXC_TIOCSTI            0x00000010
10716 +
10717 +/* was VXC_RAW_ICMP            0x00000100 */
10718 +#define VXC_SYSLOG             0x00001000
10719 +#define VXC_OOM_ADJUST         0x00002000
10720 +#define VXC_AUDIT_CONTROL      0x00004000
10721 +
10722 +#define VXC_SECURE_MOUNT       0x00010000
10723 +#define VXC_SECURE_REMOUNT     0x00020000
10724 +#define VXC_BINARY_MOUNT       0x00040000
10725 +
10726 +#define VXC_QUOTA_CTL          0x00100000
10727 +#define VXC_ADMIN_MAPPER       0x00200000
10728 +#define VXC_ADMIN_CLOOP                0x00400000
10729 +
10730 +#define VXC_KTHREAD            0x01000000
10731 +#define VXC_NAMESPACE          0x02000000
10732 +
10733 +
10734 +#ifdef __KERNEL__
10735 +
10736 +#include <linux/list.h>
10737 +#include <linux/spinlock.h>
10738 +#include <linux/rcupdate.h>
10739 +
10740 +#include "limit_def.h"
10741 +#include "sched_def.h"
10742 +#include "cvirt_def.h"
10743 +#include "cacct_def.h"
10744 +#include "device_def.h"
10745 +
10746 +#define VX_SPACES      2
10747 +
10748 +struct _vx_info_pc {
10749 +       struct _vx_sched_pc sched_pc;
10750 +       struct _vx_cvirt_pc cvirt_pc;
10751 +};
10752 +
10753 +struct vx_info {
10754 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10755 +       xid_t vx_id;                            /* context id */
10756 +       atomic_t vx_usecnt;                     /* usage count */
10757 +       atomic_t vx_tasks;                      /* tasks count */
10758 +       struct vx_info *vx_parent;              /* parent context */
10759 +       int vx_state;                           /* context state */
10760 +
10761 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10762 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10763 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10764 +
10765 +       uint64_t vx_flags;                      /* context flags */
10766 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10767 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10768 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10769 +
10770 +       struct task_struct *vx_reaper;          /* guest reaper process */
10771 +       pid_t vx_initpid;                       /* PID of guest init */
10772 +       int64_t vx_badness_bias;                /* OOM points bias */
10773 +
10774 +       struct _vx_limit limit;                 /* vserver limits */
10775 +       struct _vx_sched sched;                 /* vserver scheduler */
10776 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10777 +       struct _vx_cacct cacct;                 /* context accounting */
10778 +
10779 +       struct _vx_device dmap;                 /* default device map targets */
10780 +
10781 +#ifndef CONFIG_SMP
10782 +       struct _vx_info_pc info_pc;             /* per cpu data */
10783 +#else
10784 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10785 +#endif
10786 +
10787 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10788 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10789 +       int exit_code;                          /* last process exit code */
10790 +
10791 +       char vx_name[65];                       /* vserver name */
10792 +};
10793 +
10794 +#ifndef CONFIG_SMP
10795 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10796 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10797 +#else
10798 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10799 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10800 +#endif
10801 +
10802 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10803 +
10804 +
10805 +struct vx_info_save {
10806 +       struct vx_info *vxi;
10807 +       xid_t xid;
10808 +};
10809 +
10810 +
10811 +/* status flags */
10812 +
10813 +#define VXS_HASHED     0x0001
10814 +#define VXS_PAUSED     0x0010
10815 +#define VXS_SHUTDOWN   0x0100
10816 +#define VXS_HELPER     0x1000
10817 +#define VXS_RELEASED   0x8000
10818 +
10819 +
10820 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10821 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10822 +
10823 +extern struct vx_info *lookup_vx_info(int);
10824 +extern struct vx_info *lookup_or_create_vx_info(int);
10825 +
10826 +extern int get_xid_list(int, unsigned int *, int);
10827 +extern int xid_is_hashed(xid_t);
10828 +
10829 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10830 +
10831 +extern long vs_state_change(struct vx_info *, unsigned int);
10832 +
10833 +
10834 +#endif /* __KERNEL__ */
10835 +#endif /* _VX_CONTEXT_H */
10836 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cvirt_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cvirt_cmd.h
10837 --- linux-2.6.33/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
10838 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cvirt_cmd.h        2010-02-25 12:02:16.000000000 +0100
10839 @@ -0,0 +1,53 @@
10840 +#ifndef _VX_CVIRT_CMD_H
10841 +#define _VX_CVIRT_CMD_H
10842 +
10843 +
10844 +/* virtual host info name commands */
10845 +
10846 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10847 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10848 +
10849 +struct vcmd_vhi_name_v0 {
10850 +       uint32_t field;
10851 +       char name[65];
10852 +};
10853 +
10854 +
10855 +enum vhi_name_field {
10856 +       VHIN_CONTEXT = 0,
10857 +       VHIN_SYSNAME,
10858 +       VHIN_NODENAME,
10859 +       VHIN_RELEASE,
10860 +       VHIN_VERSION,
10861 +       VHIN_MACHINE,
10862 +       VHIN_DOMAINNAME,
10863 +};
10864 +
10865 +
10866 +#ifdef __KERNEL__
10867 +
10868 +#include <linux/compiler.h>
10869 +
10870 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10871 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10872 +
10873 +#endif /* __KERNEL__ */
10874 +
10875 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10876 +
10877 +struct vcmd_virt_stat_v0 {
10878 +       uint64_t offset;
10879 +       uint64_t uptime;
10880 +       uint32_t nr_threads;
10881 +       uint32_t nr_running;
10882 +       uint32_t nr_uninterruptible;
10883 +       uint32_t nr_onhold;
10884 +       uint32_t nr_forks;
10885 +       uint32_t load[3];
10886 +};
10887 +
10888 +#ifdef __KERNEL__
10889 +extern int vc_virt_stat(struct vx_info *, void __user *);
10890 +
10891 +#endif /* __KERNEL__ */
10892 +#endif /* _VX_CVIRT_CMD_H */
10893 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cvirt_def.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cvirt_def.h
10894 --- linux-2.6.33/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
10895 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cvirt_def.h        2010-02-25 12:02:16.000000000 +0100
10896 @@ -0,0 +1,80 @@
10897 +#ifndef _VX_CVIRT_DEF_H
10898 +#define _VX_CVIRT_DEF_H
10899 +
10900 +#include <linux/jiffies.h>
10901 +#include <linux/spinlock.h>
10902 +#include <linux/wait.h>
10903 +#include <linux/time.h>
10904 +#include <asm/atomic.h>
10905 +
10906 +
10907 +struct _vx_usage_stat {
10908 +       uint64_t user;
10909 +       uint64_t nice;
10910 +       uint64_t system;
10911 +       uint64_t softirq;
10912 +       uint64_t irq;
10913 +       uint64_t idle;
10914 +       uint64_t iowait;
10915 +};
10916 +
10917 +struct _vx_syslog {
10918 +       wait_queue_head_t log_wait;
10919 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10920 +
10921 +       unsigned long log_start;        /* next char to be read by syslog() */
10922 +       unsigned long con_start;        /* next char to be sent to consoles */
10923 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10924 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10925 +
10926 +       char log_buf[1024];
10927 +};
10928 +
10929 +
10930 +/* context sub struct */
10931 +
10932 +struct _vx_cvirt {
10933 +       atomic_t nr_threads;            /* number of current threads */
10934 +       atomic_t nr_running;            /* number of running threads */
10935 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10936 +
10937 +       atomic_t nr_onhold;             /* processes on hold */
10938 +       uint32_t onhold_last;           /* jiffies when put on hold */
10939 +
10940 +       struct timeval bias_tv;         /* time offset to the host */
10941 +       struct timespec bias_idle;
10942 +       struct timespec bias_uptime;    /* context creation point */
10943 +       uint64_t bias_clock;            /* offset in clock_t */
10944 +
10945 +       spinlock_t load_lock;           /* lock for the load averages */
10946 +       atomic_t load_updates;          /* nr of load updates done so far */
10947 +       uint32_t load_last;             /* last time load was calculated */
10948 +       uint32_t load[3];               /* load averages 1,5,15 */
10949 +
10950 +       atomic_t total_forks;           /* number of forks so far */
10951 +
10952 +       struct _vx_syslog syslog;
10953 +};
10954 +
10955 +struct _vx_cvirt_pc {
10956 +       struct _vx_usage_stat cpustat;
10957 +};
10958 +
10959 +
10960 +#ifdef CONFIG_VSERVER_DEBUG
10961 +
10962 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10963 +{
10964 +       printk("\t_vx_cvirt:\n");
10965 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10966 +               atomic_read(&cvirt->nr_threads),
10967 +               atomic_read(&cvirt->nr_running),
10968 +               atomic_read(&cvirt->nr_uninterruptible),
10969 +               atomic_read(&cvirt->nr_onhold));
10970 +       /* add rest here */
10971 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10972 +}
10973 +
10974 +#endif
10975 +
10976 +#endif /* _VX_CVIRT_DEF_H */
10977 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cvirt.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cvirt.h
10978 --- linux-2.6.33/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
10979 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/cvirt.h    2010-02-25 12:02:16.000000000 +0100
10980 @@ -0,0 +1,20 @@
10981 +#ifndef _VX_CVIRT_H
10982 +#define _VX_CVIRT_H
10983 +
10984 +
10985 +#ifdef __KERNEL__
10986 +
10987 +struct timespec;
10988 +
10989 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10990 +
10991 +
10992 +struct vx_info;
10993 +
10994 +void vx_update_load(struct vx_info *);
10995 +
10996 +
10997 +int vx_do_syslog(int, char __user *, int);
10998 +
10999 +#endif /* __KERNEL__ */
11000 +#endif /* _VX_CVIRT_H */
11001 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/debug_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/debug_cmd.h
11002 --- linux-2.6.33/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
11003 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/debug_cmd.h        2010-02-25 12:02:16.000000000 +0100
11004 @@ -0,0 +1,58 @@
11005 +#ifndef _VX_DEBUG_CMD_H
11006 +#define _VX_DEBUG_CMD_H
11007 +
11008 +
11009 +/* debug commands */
11010 +
11011 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11012 +
11013 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11014 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11015 +
11016 +struct  vcmd_read_history_v0 {
11017 +       uint32_t index;
11018 +       uint32_t count;
11019 +       char __user *data;
11020 +};
11021 +
11022 +struct  vcmd_read_monitor_v0 {
11023 +       uint32_t index;
11024 +       uint32_t count;
11025 +       char __user *data;
11026 +};
11027 +
11028 +
11029 +#ifdef __KERNEL__
11030 +
11031 +#ifdef CONFIG_COMPAT
11032 +
11033 +#include <asm/compat.h>
11034 +
11035 +struct vcmd_read_history_v0_x32 {
11036 +       uint32_t index;
11037 +       uint32_t count;
11038 +       compat_uptr_t data_ptr;
11039 +};
11040 +
11041 +struct vcmd_read_monitor_v0_x32 {
11042 +       uint32_t index;
11043 +       uint32_t count;
11044 +       compat_uptr_t data_ptr;
11045 +};
11046 +
11047 +#endif  /* CONFIG_COMPAT */
11048 +
11049 +extern int vc_dump_history(uint32_t);
11050 +
11051 +extern int vc_read_history(uint32_t, void __user *);
11052 +extern int vc_read_monitor(uint32_t, void __user *);
11053 +
11054 +#ifdef CONFIG_COMPAT
11055 +
11056 +extern int vc_read_history_x32(uint32_t, void __user *);
11057 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11058 +
11059 +#endif  /* CONFIG_COMPAT */
11060 +
11061 +#endif /* __KERNEL__ */
11062 +#endif /* _VX_DEBUG_CMD_H */
11063 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/debug.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/debug.h
11064 --- linux-2.6.33/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
11065 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/debug.h    2010-02-25 12:02:16.000000000 +0100
11066 @@ -0,0 +1,127 @@
11067 +#ifndef _VX_DEBUG_H
11068 +#define _VX_DEBUG_H
11069 +
11070 +
11071 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11072 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11073 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11074 +
11075 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11076 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11077 +#define VXF_DEV                "%p[%lu,%d:%d]"
11078 +
11079 +
11080 +#define vxd_path(p)                                            \
11081 +       ({ static char _buffer[PATH_MAX];                       \
11082 +          d_path(p, _buffer, sizeof(_buffer)); })
11083 +
11084 +#define vxd_cond_path(n)                                       \
11085 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11086 +
11087 +
11088 +#ifdef CONFIG_VSERVER_DEBUG
11089 +
11090 +extern unsigned int vx_debug_switch;
11091 +extern unsigned int vx_debug_xid;
11092 +extern unsigned int vx_debug_nid;
11093 +extern unsigned int vx_debug_tag;
11094 +extern unsigned int vx_debug_net;
11095 +extern unsigned int vx_debug_limit;
11096 +extern unsigned int vx_debug_cres;
11097 +extern unsigned int vx_debug_dlim;
11098 +extern unsigned int vx_debug_quota;
11099 +extern unsigned int vx_debug_cvirt;
11100 +extern unsigned int vx_debug_space;
11101 +extern unsigned int vx_debug_misc;
11102 +
11103 +
11104 +#define VX_LOGLEVEL    "vxD: "
11105 +#define VX_PROC_FMT    "%p: "
11106 +#define VX_PROCESS     current
11107 +
11108 +#define vxdprintk(c, f, x...)                                  \
11109 +       do {                                                    \
11110 +               if (c)                                          \
11111 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11112 +                               VX_PROCESS , ##x);              \
11113 +       } while (0)
11114 +
11115 +#define vxlprintk(c, f, x...)                                  \
11116 +       do {                                                    \
11117 +               if (c)                                          \
11118 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11119 +       } while (0)
11120 +
11121 +#define vxfprintk(c, f, x...)                                  \
11122 +       do {                                                    \
11123 +               if (c)                                          \
11124 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11125 +       } while (0)
11126 +
11127 +
11128 +struct vx_info;
11129 +
11130 +void dump_vx_info(struct vx_info *, int);
11131 +void dump_vx_info_inactive(int);
11132 +
11133 +#else  /* CONFIG_VSERVER_DEBUG */
11134 +
11135 +#define vx_debug_switch 0
11136 +#define vx_debug_xid   0
11137 +#define vx_debug_nid   0
11138 +#define vx_debug_tag   0
11139 +#define vx_debug_net   0
11140 +#define vx_debug_limit 0
11141 +#define vx_debug_cres  0
11142 +#define vx_debug_dlim  0
11143 +#define vx_debug_cvirt 0
11144 +
11145 +#define vxdprintk(x...) do { } while (0)
11146 +#define vxlprintk(x...) do { } while (0)
11147 +#define vxfprintk(x...) do { } while (0)
11148 +
11149 +#endif /* CONFIG_VSERVER_DEBUG */
11150 +
11151 +
11152 +#ifdef CONFIG_VSERVER_WARN
11153 +
11154 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11155 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11156 +#define VX_WARN_XID    "[xid #%u] "
11157 +#define VX_WARN_NID    "[nid #%u] "
11158 +#define VX_WARN_TAG    "[tag #%u] "
11159 +
11160 +#define vxwprintk(c, f, x...)                                  \
11161 +       do {                                                    \
11162 +               if (c)                                          \
11163 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11164 +       } while (0)
11165 +
11166 +#else  /* CONFIG_VSERVER_WARN */
11167 +
11168 +#define vxwprintk(x...) do { } while (0)
11169 +
11170 +#endif /* CONFIG_VSERVER_WARN */
11171 +
11172 +#define vxwprintk_task(c, f, x...)                             \
11173 +       vxwprintk(c, VX_WARN_TASK f,                            \
11174 +               current->comm, current->pid,                    \
11175 +               current->xid, current->nid, current->tag, ##x)
11176 +#define vxwprintk_xid(c, f, x...)                              \
11177 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11178 +#define vxwprintk_nid(c, f, x...)                              \
11179 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11180 +#define vxwprintk_tag(c, f, x...)                              \
11181 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11182 +
11183 +#ifdef CONFIG_VSERVER_DEBUG
11184 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11185 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11186 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11187 +#else
11188 +#define vxd_assert_lock(l)     do { } while (0)
11189 +#define vxd_assert(c, f, x...) do { } while (0)
11190 +#endif
11191 +
11192 +
11193 +#endif /* _VX_DEBUG_H */
11194 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/device_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/device_cmd.h
11195 --- linux-2.6.33/include/linux/vserver/device_cmd.h     1970-01-01 01:00:00.000000000 +0100
11196 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/device_cmd.h       2010-02-25 12:02:16.000000000 +0100
11197 @@ -0,0 +1,44 @@
11198 +#ifndef _VX_DEVICE_CMD_H
11199 +#define _VX_DEVICE_CMD_H
11200 +
11201 +
11202 +/*  device vserver commands */
11203 +
11204 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11205 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11206 +
11207 +struct vcmd_set_mapping_v0 {
11208 +       const char __user *device;
11209 +       const char __user *target;
11210 +       uint32_t flags;
11211 +};
11212 +
11213 +
11214 +#ifdef __KERNEL__
11215 +
11216 +#ifdef CONFIG_COMPAT
11217 +
11218 +#include <asm/compat.h>
11219 +
11220 +struct vcmd_set_mapping_v0_x32 {
11221 +       compat_uptr_t device_ptr;
11222 +       compat_uptr_t target_ptr;
11223 +       uint32_t flags;
11224 +};
11225 +
11226 +#endif /* CONFIG_COMPAT */
11227 +
11228 +#include <linux/compiler.h>
11229 +
11230 +extern int vc_set_mapping(struct vx_info *, void __user *);
11231 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11232 +
11233 +#ifdef CONFIG_COMPAT
11234 +
11235 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11236 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11237 +
11238 +#endif /* CONFIG_COMPAT */
11239 +
11240 +#endif /* __KERNEL__ */
11241 +#endif /* _VX_DEVICE_CMD_H */
11242 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/device_def.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/device_def.h
11243 --- linux-2.6.33/include/linux/vserver/device_def.h     1970-01-01 01:00:00.000000000 +0100
11244 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/device_def.h       2010-02-25 12:02:16.000000000 +0100
11245 @@ -0,0 +1,17 @@
11246 +#ifndef _VX_DEVICE_DEF_H
11247 +#define _VX_DEVICE_DEF_H
11248 +
11249 +#include <linux/types.h>
11250 +
11251 +struct vx_dmap_target {
11252 +       dev_t target;
11253 +       uint32_t flags;
11254 +};
11255 +
11256 +struct _vx_device {
11257 +#ifdef CONFIG_VSERVER_DEVICE
11258 +       struct vx_dmap_target targets[2];
11259 +#endif
11260 +};
11261 +
11262 +#endif /* _VX_DEVICE_DEF_H */
11263 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/device.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/device.h
11264 --- linux-2.6.33/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
11265 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/device.h   2010-02-25 12:02:16.000000000 +0100
11266 @@ -0,0 +1,15 @@
11267 +#ifndef _VX_DEVICE_H
11268 +#define _VX_DEVICE_H
11269 +
11270 +
11271 +#define DATTR_CREATE   0x00000001
11272 +#define DATTR_OPEN     0x00000002
11273 +
11274 +#define DATTR_REMAP    0x00000010
11275 +
11276 +#define DATTR_MASK     0x00000013
11277 +
11278 +
11279 +#else  /* _VX_DEVICE_H */
11280 +#warning duplicate inclusion
11281 +#endif /* _VX_DEVICE_H */
11282 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/dlimit_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/dlimit_cmd.h
11283 --- linux-2.6.33/include/linux/vserver/dlimit_cmd.h     1970-01-01 01:00:00.000000000 +0100
11284 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/dlimit_cmd.h       2010-02-25 12:02:16.000000000 +0100
11285 @@ -0,0 +1,109 @@
11286 +#ifndef _VX_DLIMIT_CMD_H
11287 +#define _VX_DLIMIT_CMD_H
11288 +
11289 +
11290 +/*  dlimit vserver commands */
11291 +
11292 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11293 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11294 +
11295 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11296 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11297 +
11298 +struct vcmd_ctx_dlimit_base_v0 {
11299 +       const char __user *name;
11300 +       uint32_t flags;
11301 +};
11302 +
11303 +struct vcmd_ctx_dlimit_v0 {
11304 +       const char __user *name;
11305 +       uint32_t space_used;                    /* used space in kbytes */
11306 +       uint32_t space_total;                   /* maximum space in kbytes */
11307 +       uint32_t inodes_used;                   /* used inodes */
11308 +       uint32_t inodes_total;                  /* maximum inodes */
11309 +       uint32_t reserved;                      /* reserved for root in % */
11310 +       uint32_t flags;
11311 +};
11312 +
11313 +#define CDLIM_UNSET            ((uint32_t)0UL)
11314 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11315 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11316 +
11317 +#define DLIME_UNIT     0
11318 +#define DLIME_KILO     1
11319 +#define DLIME_MEGA     2
11320 +#define DLIME_GIGA     3
11321 +
11322 +#define DLIMF_SHIFT    0x10
11323 +
11324 +#define DLIMS_USED     0
11325 +#define DLIMS_TOTAL    2
11326 +
11327 +static inline
11328 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11329 +{
11330 +       int exp = (flags & DLIMF_SHIFT) ?
11331 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11332 +       return ((uint64_t)val) << (10 * exp);
11333 +}
11334 +
11335 +static inline
11336 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11337 +{
11338 +       int exp = 0;
11339 +
11340 +       if (*flags & DLIMF_SHIFT) {
11341 +               while (val > (1LL << 32) && (exp < 3)) {
11342 +                       val >>= 10;
11343 +                       exp++;
11344 +               }
11345 +               *flags &= ~(DLIME_GIGA << shift);
11346 +               *flags |= exp << shift;
11347 +       } else
11348 +               val >>= 10;
11349 +       return val;
11350 +}
11351 +
11352 +#ifdef __KERNEL__
11353 +
11354 +#ifdef CONFIG_COMPAT
11355 +
11356 +#include <asm/compat.h>
11357 +
11358 +struct vcmd_ctx_dlimit_base_v0_x32 {
11359 +       compat_uptr_t name_ptr;
11360 +       uint32_t flags;
11361 +};
11362 +
11363 +struct vcmd_ctx_dlimit_v0_x32 {
11364 +       compat_uptr_t name_ptr;
11365 +       uint32_t space_used;                    /* used space in kbytes */
11366 +       uint32_t space_total;                   /* maximum space in kbytes */
11367 +       uint32_t inodes_used;                   /* used inodes */
11368 +       uint32_t inodes_total;                  /* maximum inodes */
11369 +       uint32_t reserved;                      /* reserved for root in % */
11370 +       uint32_t flags;
11371 +};
11372 +
11373 +#endif /* CONFIG_COMPAT */
11374 +
11375 +#include <linux/compiler.h>
11376 +
11377 +extern int vc_add_dlimit(uint32_t, void __user *);
11378 +extern int vc_rem_dlimit(uint32_t, void __user *);
11379 +
11380 +extern int vc_set_dlimit(uint32_t, void __user *);
11381 +extern int vc_get_dlimit(uint32_t, void __user *);
11382 +
11383 +#ifdef CONFIG_COMPAT
11384 +
11385 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11386 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11387 +
11388 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11389 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11390 +
11391 +#endif /* CONFIG_COMPAT */
11392 +
11393 +#endif /* __KERNEL__ */
11394 +#endif /* _VX_DLIMIT_CMD_H */
11395 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/dlimit.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/dlimit.h
11396 --- linux-2.6.33/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
11397 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/dlimit.h   2010-02-25 12:02:16.000000000 +0100
11398 @@ -0,0 +1,54 @@
11399 +#ifndef _VX_DLIMIT_H
11400 +#define _VX_DLIMIT_H
11401 +
11402 +#include "switch.h"
11403 +
11404 +
11405 +#ifdef __KERNEL__
11406 +
11407 +/*      keep in sync with CDLIM_INFINITY       */
11408 +
11409 +#define DLIM_INFINITY          (~0ULL)
11410 +
11411 +#include <linux/spinlock.h>
11412 +#include <linux/rcupdate.h>
11413 +
11414 +struct super_block;
11415 +
11416 +struct dl_info {
11417 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11418 +       struct rcu_head dl_rcu;                 /* the rcu head */
11419 +       tag_t dl_tag;                           /* context tag */
11420 +       atomic_t dl_usecnt;                     /* usage count */
11421 +       atomic_t dl_refcnt;                     /* reference count */
11422 +
11423 +       struct super_block *dl_sb;              /* associated superblock */
11424 +
11425 +       spinlock_t dl_lock;                     /* protect the values */
11426 +
11427 +       unsigned long long dl_space_used;       /* used space in bytes */
11428 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11429 +       unsigned long dl_inodes_used;           /* used inodes */
11430 +       unsigned long dl_inodes_total;          /* maximum inodes */
11431 +
11432 +       unsigned int dl_nrlmult;                /* non root limit mult */
11433 +};
11434 +
11435 +struct rcu_head;
11436 +
11437 +extern void rcu_free_dl_info(struct rcu_head *);
11438 +extern void unhash_dl_info(struct dl_info *);
11439 +
11440 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11441 +
11442 +
11443 +struct kstatfs;
11444 +
11445 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11446 +
11447 +typedef uint64_t dlsize_t;
11448 +
11449 +#endif /* __KERNEL__ */
11450 +#else  /* _VX_DLIMIT_H */
11451 +#warning duplicate inclusion
11452 +#endif /* _VX_DLIMIT_H */
11453 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/global.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/global.h
11454 --- linux-2.6.33/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
11455 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/global.h   2010-02-25 12:02:16.000000000 +0100
11456 @@ -0,0 +1,19 @@
11457 +#ifndef _VX_GLOBAL_H
11458 +#define _VX_GLOBAL_H
11459 +
11460 +
11461 +extern atomic_t vx_global_ctotal;
11462 +extern atomic_t vx_global_cactive;
11463 +
11464 +extern atomic_t nx_global_ctotal;
11465 +extern atomic_t nx_global_cactive;
11466 +
11467 +extern atomic_t vs_global_nsproxy;
11468 +extern atomic_t vs_global_fs;
11469 +extern atomic_t vs_global_mnt_ns;
11470 +extern atomic_t vs_global_uts_ns;
11471 +extern atomic_t vs_global_user_ns;
11472 +extern atomic_t vs_global_pid_ns;
11473 +
11474 +
11475 +#endif /* _VX_GLOBAL_H */
11476 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/history.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/history.h
11477 --- linux-2.6.33/include/linux/vserver/history.h        1970-01-01 01:00:00.000000000 +0100
11478 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/history.h  2010-02-25 12:02:16.000000000 +0100
11479 @@ -0,0 +1,197 @@
11480 +#ifndef _VX_HISTORY_H
11481 +#define _VX_HISTORY_H
11482 +
11483 +
11484 +enum {
11485 +       VXH_UNUSED = 0,
11486 +       VXH_THROW_OOPS = 1,
11487 +
11488 +       VXH_GET_VX_INFO,
11489 +       VXH_PUT_VX_INFO,
11490 +       VXH_INIT_VX_INFO,
11491 +       VXH_SET_VX_INFO,
11492 +       VXH_CLR_VX_INFO,
11493 +       VXH_CLAIM_VX_INFO,
11494 +       VXH_RELEASE_VX_INFO,
11495 +       VXH_ALLOC_VX_INFO,
11496 +       VXH_DEALLOC_VX_INFO,
11497 +       VXH_HASH_VX_INFO,
11498 +       VXH_UNHASH_VX_INFO,
11499 +       VXH_LOC_VX_INFO,
11500 +       VXH_LOOKUP_VX_INFO,
11501 +       VXH_CREATE_VX_INFO,
11502 +};
11503 +
11504 +struct _vxhe_vxi {
11505 +       struct vx_info *ptr;
11506 +       unsigned xid;
11507 +       unsigned usecnt;
11508 +       unsigned tasks;
11509 +};
11510 +
11511 +struct _vxhe_set_clr {
11512 +       void *data;
11513 +};
11514 +
11515 +struct _vxhe_loc_lookup {
11516 +       unsigned arg;
11517 +};
11518 +
11519 +struct _vx_hist_entry {
11520 +       void *loc;
11521 +       unsigned short seq;
11522 +       unsigned short type;
11523 +       struct _vxhe_vxi vxi;
11524 +       union {
11525 +               struct _vxhe_set_clr sc;
11526 +               struct _vxhe_loc_lookup ll;
11527 +       };
11528 +};
11529 +
11530 +#ifdef CONFIG_VSERVER_HISTORY
11531 +
11532 +extern unsigned volatile int vxh_active;
11533 +
11534 +struct _vx_hist_entry *vxh_advance(void *loc);
11535 +
11536 +
11537 +static inline
11538 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11539 +{
11540 +       entry->vxi.ptr = vxi;
11541 +       if (vxi) {
11542 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11543 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11544 +               entry->vxi.xid = vxi->vx_id;
11545 +       }
11546 +}
11547 +
11548 +
11549 +#define        __HERE__ current_text_addr()
11550 +
11551 +#define __VXH_BODY(__type, __data, __here)     \
11552 +       struct _vx_hist_entry *entry;           \
11553 +                                               \
11554 +       preempt_disable();                      \
11555 +       entry = vxh_advance(__here);            \
11556 +       __data;                                 \
11557 +       entry->type = __type;                   \
11558 +       preempt_enable();
11559 +
11560 +
11561 +       /* pass vxi only */
11562 +
11563 +#define __VXH_SMPL                             \
11564 +       __vxh_copy_vxi(entry, vxi)
11565 +
11566 +static inline
11567 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11568 +{
11569 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11570 +}
11571 +
11572 +       /* pass vxi and data (void *) */
11573 +
11574 +#define __VXH_DATA                             \
11575 +       __vxh_copy_vxi(entry, vxi);             \
11576 +       entry->sc.data = data
11577 +
11578 +static inline
11579 +void   __vxh_data(struct vx_info *vxi, void *data,
11580 +                       int __type, void *__here)
11581 +{
11582 +       __VXH_BODY(__type, __VXH_DATA, __here)
11583 +}
11584 +
11585 +       /* pass vxi and arg (long) */
11586 +
11587 +#define __VXH_LONG                             \
11588 +       __vxh_copy_vxi(entry, vxi);             \
11589 +       entry->ll.arg = arg
11590 +
11591 +static inline
11592 +void   __vxh_long(struct vx_info *vxi, long arg,
11593 +                       int __type, void *__here)
11594 +{
11595 +       __VXH_BODY(__type, __VXH_LONG, __here)
11596 +}
11597 +
11598 +
11599 +static inline
11600 +void   __vxh_throw_oops(void *__here)
11601 +{
11602 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11603 +       /* prevent further acquisition */
11604 +       vxh_active = 0;
11605 +}
11606 +
11607 +
11608 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11609 +
11610 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11611 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11612 +
11613 +#define __vxh_init_vx_info(v, d, h) \
11614 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11615 +#define __vxh_set_vx_info(v, d, h) \
11616 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11617 +#define __vxh_clr_vx_info(v, d, h) \
11618 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11619 +
11620 +#define __vxh_claim_vx_info(v, d, h) \
11621 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11622 +#define __vxh_release_vx_info(v, d, h) \
11623 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11624 +
11625 +#define vxh_alloc_vx_info(v) \
11626 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11627 +#define vxh_dealloc_vx_info(v) \
11628 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11629 +
11630 +#define vxh_hash_vx_info(v) \
11631 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11632 +#define vxh_unhash_vx_info(v) \
11633 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11634 +
11635 +#define vxh_loc_vx_info(v, l) \
11636 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11637 +#define vxh_lookup_vx_info(v, l) \
11638 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11639 +#define vxh_create_vx_info(v, l) \
11640 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11641 +
11642 +extern void vxh_dump_history(void);
11643 +
11644 +
11645 +#else  /* CONFIG_VSERVER_HISTORY */
11646 +
11647 +#define        __HERE__        0
11648 +
11649 +#define vxh_throw_oops()               do { } while (0)
11650 +
11651 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11652 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11653 +
11654 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11655 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11656 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11657 +
11658 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11659 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11660 +
11661 +#define vxh_alloc_vx_info(v)           do { } while (0)
11662 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11663 +
11664 +#define vxh_hash_vx_info(v)            do { } while (0)
11665 +#define vxh_unhash_vx_info(v)          do { } while (0)
11666 +
11667 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11668 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11669 +#define vxh_create_vx_info(v, l)       do { } while (0)
11670 +
11671 +#define vxh_dump_history()             do { } while (0)
11672 +
11673 +
11674 +#endif /* CONFIG_VSERVER_HISTORY */
11675 +
11676 +#endif /* _VX_HISTORY_H */
11677 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/inode_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/inode_cmd.h
11678 --- linux-2.6.33/include/linux/vserver/inode_cmd.h      1970-01-01 01:00:00.000000000 +0100
11679 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/inode_cmd.h        2010-02-25 12:02:16.000000000 +0100
11680 @@ -0,0 +1,59 @@
11681 +#ifndef _VX_INODE_CMD_H
11682 +#define _VX_INODE_CMD_H
11683 +
11684 +
11685 +/*  inode vserver commands */
11686 +
11687 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11688 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11689 +
11690 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11691 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11692 +
11693 +struct vcmd_ctx_iattr_v1 {
11694 +       const char __user *name;
11695 +       uint32_t tag;
11696 +       uint32_t flags;
11697 +       uint32_t mask;
11698 +};
11699 +
11700 +struct vcmd_ctx_fiattr_v0 {
11701 +       uint32_t tag;
11702 +       uint32_t flags;
11703 +       uint32_t mask;
11704 +};
11705 +
11706 +
11707 +#ifdef __KERNEL__
11708 +
11709 +
11710 +#ifdef CONFIG_COMPAT
11711 +
11712 +#include <asm/compat.h>
11713 +
11714 +struct vcmd_ctx_iattr_v1_x32 {
11715 +       compat_uptr_t name_ptr;
11716 +       uint32_t tag;
11717 +       uint32_t flags;
11718 +       uint32_t mask;
11719 +};
11720 +
11721 +#endif /* CONFIG_COMPAT */
11722 +
11723 +#include <linux/compiler.h>
11724 +
11725 +extern int vc_get_iattr(void __user *);
11726 +extern int vc_set_iattr(void __user *);
11727 +
11728 +extern int vc_fget_iattr(uint32_t, void __user *);
11729 +extern int vc_fset_iattr(uint32_t, void __user *);
11730 +
11731 +#ifdef CONFIG_COMPAT
11732 +
11733 +extern int vc_get_iattr_x32(void __user *);
11734 +extern int vc_set_iattr_x32(void __user *);
11735 +
11736 +#endif /* CONFIG_COMPAT */
11737 +
11738 +#endif /* __KERNEL__ */
11739 +#endif /* _VX_INODE_CMD_H */
11740 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/inode.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/inode.h
11741 --- linux-2.6.33/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
11742 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/inode.h    2010-02-25 12:02:16.000000000 +0100
11743 @@ -0,0 +1,39 @@
11744 +#ifndef _VX_INODE_H
11745 +#define _VX_INODE_H
11746 +
11747 +
11748 +#define IATTR_TAG      0x01000000
11749 +
11750 +#define IATTR_ADMIN    0x00000001
11751 +#define IATTR_WATCH    0x00000002
11752 +#define IATTR_HIDE     0x00000004
11753 +#define IATTR_FLAGS    0x00000007
11754 +
11755 +#define IATTR_BARRIER  0x00010000
11756 +#define IATTR_IXUNLINK 0x00020000
11757 +#define IATTR_IMMUTABLE 0x00040000
11758 +#define IATTR_COW      0x00080000
11759 +
11760 +#ifdef __KERNEL__
11761 +
11762 +
11763 +#ifdef CONFIG_VSERVER_PROC_SECURE
11764 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11765 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11766 +#else
11767 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11768 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11769 +#endif
11770 +
11771 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11772 +
11773 +#endif /* __KERNEL__ */
11774 +
11775 +/* inode ioctls */
11776 +
11777 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11778 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11779 +
11780 +#else  /* _VX_INODE_H */
11781 +#warning duplicate inclusion
11782 +#endif /* _VX_INODE_H */
11783 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/Kbuild linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/Kbuild
11784 --- linux-2.6.33/include/linux/vserver/Kbuild   1970-01-01 01:00:00.000000000 +0100
11785 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/Kbuild     2010-02-25 12:02:16.000000000 +0100
11786 @@ -0,0 +1,8 @@
11787 +
11788 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11789 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11790 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11791 +       debug_cmd.h device_cmd.h
11792 +
11793 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11794 +
11795 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/limit_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/limit_cmd.h
11796 --- linux-2.6.33/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
11797 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/limit_cmd.h        2010-02-25 12:02:16.000000000 +0100
11798 @@ -0,0 +1,71 @@
11799 +#ifndef _VX_LIMIT_CMD_H
11800 +#define _VX_LIMIT_CMD_H
11801 +
11802 +
11803 +/*  rlimit vserver commands */
11804 +
11805 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11806 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11807 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11808 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11809 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11810 +
11811 +struct vcmd_ctx_rlimit_v0 {
11812 +       uint32_t id;
11813 +       uint64_t minimum;
11814 +       uint64_t softlimit;
11815 +       uint64_t maximum;
11816 +};
11817 +
11818 +struct vcmd_ctx_rlimit_mask_v0 {
11819 +       uint32_t minimum;
11820 +       uint32_t softlimit;
11821 +       uint32_t maximum;
11822 +};
11823 +
11824 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11825 +
11826 +struct vcmd_rlimit_stat_v0 {
11827 +       uint32_t id;
11828 +       uint32_t hits;
11829 +       uint64_t value;
11830 +       uint64_t minimum;
11831 +       uint64_t maximum;
11832 +};
11833 +
11834 +#define CRLIM_UNSET            (0ULL)
11835 +#define CRLIM_INFINITY         (~0ULL)
11836 +#define CRLIM_KEEP             (~1ULL)
11837 +
11838 +#ifdef __KERNEL__
11839 +
11840 +#ifdef CONFIG_IA32_EMULATION
11841 +
11842 +struct vcmd_ctx_rlimit_v0_x32 {
11843 +       uint32_t id;
11844 +       uint64_t minimum;
11845 +       uint64_t softlimit;
11846 +       uint64_t maximum;
11847 +} __attribute__ ((packed));
11848 +
11849 +#endif /* CONFIG_IA32_EMULATION */
11850 +
11851 +#include <linux/compiler.h>
11852 +
11853 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11854 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11855 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11856 +extern int vc_reset_hits(struct vx_info *, void __user *);
11857 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11858 +
11859 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11860 +
11861 +#ifdef CONFIG_IA32_EMULATION
11862 +
11863 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11864 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11865 +
11866 +#endif /* CONFIG_IA32_EMULATION */
11867 +
11868 +#endif /* __KERNEL__ */
11869 +#endif /* _VX_LIMIT_CMD_H */
11870 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/limit_def.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/limit_def.h
11871 --- linux-2.6.33/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
11872 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/limit_def.h        2010-02-25 12:02:16.000000000 +0100
11873 @@ -0,0 +1,47 @@
11874 +#ifndef _VX_LIMIT_DEF_H
11875 +#define _VX_LIMIT_DEF_H
11876 +
11877 +#include <asm/atomic.h>
11878 +#include <asm/resource.h>
11879 +
11880 +#include "limit.h"
11881 +
11882 +
11883 +struct _vx_res_limit {
11884 +       rlim_t soft;            /* Context soft limit */
11885 +       rlim_t hard;            /* Context hard limit */
11886 +
11887 +       rlim_atomic_t rcur;     /* Current value */
11888 +       rlim_t rmin;            /* Context minimum */
11889 +       rlim_t rmax;            /* Context maximum */
11890 +
11891 +       atomic_t lhit;          /* Limit hits */
11892 +};
11893 +
11894 +/* context sub struct */
11895 +
11896 +struct _vx_limit {
11897 +       struct _vx_res_limit res[NUM_LIMITS];
11898 +};
11899 +
11900 +#ifdef CONFIG_VSERVER_DEBUG
11901 +
11902 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11903 +{
11904 +       int i;
11905 +
11906 +       printk("\t_vx_limit:");
11907 +       for (i = 0; i < NUM_LIMITS; i++) {
11908 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11909 +                       i, (unsigned long)__rlim_get(limit, i),
11910 +                       (unsigned long)__rlim_rmin(limit, i),
11911 +                       (unsigned long)__rlim_rmax(limit, i),
11912 +                       (long)__rlim_soft(limit, i),
11913 +                       (long)__rlim_hard(limit, i),
11914 +                       atomic_read(&__rlim_lhit(limit, i)));
11915 +       }
11916 +}
11917 +
11918 +#endif
11919 +
11920 +#endif /* _VX_LIMIT_DEF_H */
11921 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/limit.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/limit.h
11922 --- linux-2.6.33/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
11923 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/limit.h    2010-02-25 12:02:16.000000000 +0100
11924 @@ -0,0 +1,71 @@
11925 +#ifndef _VX_LIMIT_H
11926 +#define _VX_LIMIT_H
11927 +
11928 +#define VLIMIT_NSOCK   16
11929 +#define VLIMIT_OPENFD  17
11930 +#define VLIMIT_ANON    18
11931 +#define VLIMIT_SHMEM   19
11932 +#define VLIMIT_SEMARY  20
11933 +#define VLIMIT_NSEMS   21
11934 +#define VLIMIT_DENTRY  22
11935 +#define VLIMIT_MAPPED  23
11936 +
11937 +
11938 +#ifdef __KERNEL__
11939 +
11940 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11941 +
11942 +/*     keep in sync with CRLIM_INFINITY */
11943 +
11944 +#define        VLIM_INFINITY   (~0ULL)
11945 +
11946 +#include <asm/atomic.h>
11947 +#include <asm/resource.h>
11948 +
11949 +#ifndef RLIM_INFINITY
11950 +#warning RLIM_INFINITY is undefined
11951 +#endif
11952 +
11953 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11954 +
11955 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11956 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11957 +
11958 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11959 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11960 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11961 +
11962 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11963 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11964 +
11965 +typedef atomic_long_t rlim_atomic_t;
11966 +typedef unsigned long rlim_t;
11967 +
11968 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11969 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11970 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11971 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11972 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11973 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11974 +
11975 +
11976 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11977 +#define        VX_VLIM(r) ((long long)(long)(r))
11978 +#define        VX_RLIM(v) ((rlim_t)(v))
11979 +#else
11980 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11981 +               ? VLIM_INFINITY : (long long)(r))
11982 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11983 +               ? RLIM_INFINITY : (rlim_t)(v))
11984 +#endif
11985 +
11986 +struct sysinfo;
11987 +
11988 +void vx_vsi_meminfo(struct sysinfo *);
11989 +void vx_vsi_swapinfo(struct sysinfo *);
11990 +long vx_vsi_cached(struct sysinfo *);
11991 +
11992 +#define NUM_LIMITS     24
11993 +
11994 +#endif /* __KERNEL__ */
11995 +#endif /* _VX_LIMIT_H */
11996 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/limit_int.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/limit_int.h
11997 --- linux-2.6.33/include/linux/vserver/limit_int.h      1970-01-01 01:00:00.000000000 +0100
11998 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/limit_int.h        2010-02-25 12:02:16.000000000 +0100
11999 @@ -0,0 +1,198 @@
12000 +#ifndef _VX_LIMIT_INT_H
12001 +#define _VX_LIMIT_INT_H
12002 +
12003 +#include "context.h"
12004 +
12005 +#ifdef __KERNEL__
12006 +
12007 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12008 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12009 +
12010 +extern const char *vlimit_name[NUM_LIMITS];
12011 +
12012 +static inline void __vx_acc_cres(struct vx_info *vxi,
12013 +       int res, int dir, void *_data, char *_file, int _line)
12014 +{
12015 +       if (VXD_RCRES_COND(res))
12016 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12017 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12018 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12019 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12020 +       if (!vxi)
12021 +               return;
12022 +
12023 +       if (dir > 0)
12024 +               __rlim_inc(&vxi->limit, res);
12025 +       else
12026 +               __rlim_dec(&vxi->limit, res);
12027 +}
12028 +
12029 +static inline void __vx_add_cres(struct vx_info *vxi,
12030 +       int res, int amount, void *_data, char *_file, int _line)
12031 +{
12032 +       if (VXD_RCRES_COND(res))
12033 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12034 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12035 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12036 +                       amount, _data, _file, _line);
12037 +       if (amount == 0)
12038 +               return;
12039 +       if (!vxi)
12040 +               return;
12041 +       __rlim_add(&vxi->limit, res, amount);
12042 +}
12043 +
12044 +static inline
12045 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12046 +{
12047 +       int cond = (value > __rlim_rmax(limit, res));
12048 +
12049 +       if (cond)
12050 +               __rlim_rmax(limit, res) = value;
12051 +       return cond;
12052 +}
12053 +
12054 +static inline
12055 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12056 +{
12057 +       int cond = (value < __rlim_rmin(limit, res));
12058 +
12059 +       if (cond)
12060 +               __rlim_rmin(limit, res) = value;
12061 +       return cond;
12062 +}
12063 +
12064 +static inline
12065 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12066 +{
12067 +       if (!__vx_cres_adjust_max(limit, res, value))
12068 +               __vx_cres_adjust_min(limit, res, value);
12069 +}
12070 +
12071 +
12072 +/*     return values:
12073 +        +1 ... no limit hit
12074 +        -1 ... over soft limit
12075 +         0 ... over hard limit         */
12076 +
12077 +static inline int __vx_cres_avail(struct vx_info *vxi,
12078 +       int res, int num, char *_file, int _line)
12079 +{
12080 +       struct _vx_limit *limit;
12081 +       rlim_t value;
12082 +
12083 +       if (VXD_RLIMIT_COND(res))
12084 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12085 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12086 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12087 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12088 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12089 +                       num, _file, _line);
12090 +       if (!vxi)
12091 +               return 1;
12092 +
12093 +       limit = &vxi->limit;
12094 +       value = __rlim_get(limit, res);
12095 +
12096 +       if (!__vx_cres_adjust_max(limit, res, value))
12097 +               __vx_cres_adjust_min(limit, res, value);
12098 +
12099 +       if (num == 0)
12100 +               return 1;
12101 +
12102 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12103 +               return -1;
12104 +       if (value + num <= __rlim_soft(limit, res))
12105 +               return -1;
12106 +
12107 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12108 +               return 1;
12109 +       if (value + num <= __rlim_hard(limit, res))
12110 +               return 1;
12111 +
12112 +       __rlim_hit(limit, res);
12113 +       return 0;
12114 +}
12115 +
12116 +
12117 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12118 +
12119 +static inline
12120 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12121 +{
12122 +       rlim_t value, sum = 0;
12123 +       int res;
12124 +
12125 +       while ((res = *array++)) {
12126 +               value = __rlim_get(limit, res);
12127 +               __vx_cres_fixup(limit, res, value);
12128 +               sum += value;
12129 +       }
12130 +       return sum;
12131 +}
12132 +
12133 +static inline
12134 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12135 +{
12136 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12137 +       int res = *array;
12138 +
12139 +       if (value == __rlim_get(limit, res))
12140 +               return value;
12141 +
12142 +       __rlim_set(limit, res, value);
12143 +       /* now adjust min/max */
12144 +       if (!__vx_cres_adjust_max(limit, res, value))
12145 +               __vx_cres_adjust_min(limit, res, value);
12146 +
12147 +       return value;
12148 +}
12149 +
12150 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12151 +       const int *array, int num, char *_file, int _line)
12152 +{
12153 +       struct _vx_limit *limit;
12154 +       rlim_t value = 0;
12155 +       int res;
12156 +
12157 +       if (num == 0)
12158 +               return 1;
12159 +       if (!vxi)
12160 +               return 1;
12161 +
12162 +       limit = &vxi->limit;
12163 +       res = *array;
12164 +       value = __vx_cres_array_sum(limit, array + 1);
12165 +
12166 +       __rlim_set(limit, res, value);
12167 +       __vx_cres_fixup(limit, res, value);
12168 +
12169 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12170 +}
12171 +
12172 +
12173 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12174 +{
12175 +       rlim_t value;
12176 +       int res;
12177 +
12178 +       /* complex resources first */
12179 +       if ((id < 0) || (id == RLIMIT_RSS))
12180 +               __vx_cres_array_fixup(limit, VLA_RSS);
12181 +
12182 +       for (res = 0; res < NUM_LIMITS; res++) {
12183 +               if ((id > 0) && (res != id))
12184 +                       continue;
12185 +
12186 +               value = __rlim_get(limit, res);
12187 +               __vx_cres_fixup(limit, res, value);
12188 +
12189 +               /* not supposed to happen, maybe warn? */
12190 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12191 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12192 +       }
12193 +}
12194 +
12195 +
12196 +#endif /* __KERNEL__ */
12197 +#endif /* _VX_LIMIT_INT_H */
12198 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/monitor.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/monitor.h
12199 --- linux-2.6.33/include/linux/vserver/monitor.h        1970-01-01 01:00:00.000000000 +0100
12200 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/monitor.h  2010-02-25 12:02:16.000000000 +0100
12201 @@ -0,0 +1,96 @@
12202 +#ifndef _VX_MONITOR_H
12203 +#define _VX_MONITOR_H
12204 +
12205 +#include <linux/types.h>
12206 +
12207 +enum {
12208 +       VXM_UNUSED = 0,
12209 +
12210 +       VXM_SYNC = 0x10,
12211 +
12212 +       VXM_UPDATE = 0x20,
12213 +       VXM_UPDATE_1,
12214 +       VXM_UPDATE_2,
12215 +
12216 +       VXM_RQINFO_1 = 0x24,
12217 +       VXM_RQINFO_2,
12218 +
12219 +       VXM_ACTIVATE = 0x40,
12220 +       VXM_DEACTIVATE,
12221 +       VXM_IDLE,
12222 +
12223 +       VXM_HOLD = 0x44,
12224 +       VXM_UNHOLD,
12225 +
12226 +       VXM_MIGRATE = 0x48,
12227 +       VXM_RESCHED,
12228 +
12229 +       /* all other bits are flags */
12230 +       VXM_SCHED = 0x80,
12231 +};
12232 +
12233 +struct _vxm_update_1 {
12234 +       uint32_t tokens_max;
12235 +       uint32_t fill_rate;
12236 +       uint32_t interval;
12237 +};
12238 +
12239 +struct _vxm_update_2 {
12240 +       uint32_t tokens_min;
12241 +       uint32_t fill_rate;
12242 +       uint32_t interval;
12243 +};
12244 +
12245 +struct _vxm_rqinfo_1 {
12246 +       uint16_t running;
12247 +       uint16_t onhold;
12248 +       uint16_t iowait;
12249 +       uint16_t uintr;
12250 +       uint32_t idle_tokens;
12251 +};
12252 +
12253 +struct _vxm_rqinfo_2 {
12254 +       uint32_t norm_time;
12255 +       uint32_t idle_time;
12256 +       uint32_t idle_skip;
12257 +};
12258 +
12259 +struct _vxm_sched {
12260 +       uint32_t tokens;
12261 +       uint32_t norm_time;
12262 +       uint32_t idle_time;
12263 +};
12264 +
12265 +struct _vxm_task {
12266 +       uint16_t pid;
12267 +       uint16_t state;
12268 +};
12269 +
12270 +struct _vxm_event {
12271 +       uint32_t jif;
12272 +       union {
12273 +               uint32_t seq;
12274 +               uint32_t sec;
12275 +       };
12276 +       union {
12277 +               uint32_t tokens;
12278 +               uint32_t nsec;
12279 +               struct _vxm_task tsk;
12280 +       };
12281 +};
12282 +
12283 +struct _vx_mon_entry {
12284 +       uint16_t type;
12285 +       uint16_t xid;
12286 +       union {
12287 +               struct _vxm_event ev;
12288 +               struct _vxm_sched sd;
12289 +               struct _vxm_update_1 u1;
12290 +               struct _vxm_update_2 u2;
12291 +               struct _vxm_rqinfo_1 q1;
12292 +               struct _vxm_rqinfo_2 q2;
12293 +       };
12294 +};
12295 +
12296 +
12297 +#endif /* _VX_MONITOR_H */
12298 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/network_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/network_cmd.h
12299 --- linux-2.6.33/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
12300 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/network_cmd.h      2010-02-25 12:02:16.000000000 +0100
12301 @@ -0,0 +1,150 @@
12302 +#ifndef _VX_NETWORK_CMD_H
12303 +#define _VX_NETWORK_CMD_H
12304 +
12305 +
12306 +/* vinfo commands */
12307 +
12308 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12309 +
12310 +#ifdef __KERNEL__
12311 +extern int vc_task_nid(uint32_t);
12312 +
12313 +#endif /* __KERNEL__ */
12314 +
12315 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12316 +
12317 +struct vcmd_nx_info_v0 {
12318 +       uint32_t nid;
12319 +       /* more to come */
12320 +};
12321 +
12322 +#ifdef __KERNEL__
12323 +extern int vc_nx_info(struct nx_info *, void __user *);
12324 +
12325 +#endif /* __KERNEL__ */
12326 +
12327 +#include <linux/in.h>
12328 +#include <linux/in6.h>
12329 +
12330 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12331 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12332 +
12333 +struct  vcmd_net_create {
12334 +       uint64_t flagword;
12335 +};
12336 +
12337 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12338 +
12339 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12340 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12341 +
12342 +struct vcmd_net_addr_v0 {
12343 +       uint16_t type;
12344 +       uint16_t count;
12345 +       struct in_addr ip[4];
12346 +       struct in_addr mask[4];
12347 +};
12348 +
12349 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12350 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12351 +
12352 +struct vcmd_net_addr_ipv4_v1 {
12353 +       uint16_t type;
12354 +       uint16_t flags;
12355 +       struct in_addr ip;
12356 +       struct in_addr mask;
12357 +};
12358 +
12359 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12360 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12361 +
12362 +struct vcmd_net_addr_ipv6_v1 {
12363 +       uint16_t type;
12364 +       uint16_t flags;
12365 +       uint32_t prefix;
12366 +       struct in6_addr ip;
12367 +       struct in6_addr mask;
12368 +};
12369 +
12370 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12371 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12372 +
12373 +struct vcmd_match_ipv4_v0 {
12374 +       uint16_t type;
12375 +       uint16_t flags;
12376 +       uint16_t parent;
12377 +       uint16_t prefix;
12378 +       struct in_addr ip;
12379 +       struct in_addr ip2;
12380 +       struct in_addr mask;
12381 +};
12382 +
12383 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12384 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12385 +
12386 +struct vcmd_match_ipv6_v0 {
12387 +       uint16_t type;
12388 +       uint16_t flags;
12389 +       uint16_t parent;
12390 +       uint16_t prefix;
12391 +       struct in6_addr ip;
12392 +       struct in6_addr ip2;
12393 +       struct in6_addr mask;
12394 +};
12395 +
12396 +
12397 +#ifdef __KERNEL__
12398 +extern int vc_net_create(uint32_t, void __user *);
12399 +extern int vc_net_migrate(struct nx_info *, void __user *);
12400 +
12401 +extern int vc_net_add(struct nx_info *, void __user *);
12402 +extern int vc_net_remove(struct nx_info *, void __user *);
12403 +
12404 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12405 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12406 +
12407 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12408 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12409 +
12410 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12411 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12412 +
12413 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12414 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12415 +
12416 +#endif /* __KERNEL__ */
12417 +
12418 +
12419 +/* flag commands */
12420 +
12421 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12422 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12423 +
12424 +struct vcmd_net_flags_v0 {
12425 +       uint64_t flagword;
12426 +       uint64_t mask;
12427 +};
12428 +
12429 +#ifdef __KERNEL__
12430 +extern int vc_get_nflags(struct nx_info *, void __user *);
12431 +extern int vc_set_nflags(struct nx_info *, void __user *);
12432 +
12433 +#endif /* __KERNEL__ */
12434 +
12435 +
12436 +/* network caps commands */
12437 +
12438 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12439 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12440 +
12441 +struct vcmd_net_caps_v0 {
12442 +       uint64_t ncaps;
12443 +       uint64_t cmask;
12444 +};
12445 +
12446 +#ifdef __KERNEL__
12447 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12448 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12449 +
12450 +#endif /* __KERNEL__ */
12451 +#endif /* _VX_CONTEXT_CMD_H */
12452 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/network.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/network.h
12453 --- linux-2.6.33/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
12454 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/network.h  2010-02-25 12:02:16.000000000 +0100
12455 @@ -0,0 +1,146 @@
12456 +#ifndef _VX_NETWORK_H
12457 +#define _VX_NETWORK_H
12458 +
12459 +#include <linux/types.h>
12460 +
12461 +
12462 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12463 +
12464 +
12465 +/* network flags */
12466 +
12467 +#define NXF_INFO_PRIVATE       0x00000008
12468 +
12469 +#define NXF_SINGLE_IP          0x00000100
12470 +#define NXF_LBACK_REMAP                0x00000200
12471 +#define NXF_LBACK_ALLOW                0x00000400
12472 +
12473 +#define NXF_HIDE_NETIF         0x02000000
12474 +#define NXF_HIDE_LBACK         0x04000000
12475 +
12476 +#define NXF_STATE_SETUP                (1ULL << 32)
12477 +#define NXF_STATE_ADMIN                (1ULL << 34)
12478 +
12479 +#define NXF_SC_HELPER          (1ULL << 36)
12480 +#define NXF_PERSISTENT         (1ULL << 38)
12481 +
12482 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12483 +
12484 +
12485 +#define        NXF_INIT_SET            (__nxf_init_set())
12486 +
12487 +static inline uint64_t __nxf_init_set(void) {
12488 +       return    NXF_STATE_ADMIN
12489 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12490 +               | NXF_LBACK_REMAP
12491 +               | NXF_HIDE_LBACK
12492 +#endif
12493 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12494 +               | NXF_SINGLE_IP
12495 +#endif
12496 +               | NXF_HIDE_NETIF;
12497 +}
12498 +
12499 +
12500 +/* network caps */
12501 +
12502 +#define NXC_TUN_CREATE         0x00000001
12503 +
12504 +#define NXC_RAW_ICMP           0x00000100
12505 +
12506 +
12507 +/* address types */
12508 +
12509 +#define NXA_TYPE_IPV4          0x0001
12510 +#define NXA_TYPE_IPV6          0x0002
12511 +
12512 +#define NXA_TYPE_NONE          0x0000
12513 +#define NXA_TYPE_ANY           0x00FF
12514 +
12515 +#define NXA_TYPE_ADDR          0x0010
12516 +#define NXA_TYPE_MASK          0x0020
12517 +#define NXA_TYPE_RANGE         0x0040
12518 +
12519 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12520 +
12521 +#define NXA_MOD_BCAST          0x0100
12522 +#define NXA_MOD_LBACK          0x0200
12523 +
12524 +#define NXA_LOOPBACK           0x1000
12525 +
12526 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12527 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12528 +
12529 +#ifdef __KERNEL__
12530 +
12531 +#include <linux/list.h>
12532 +#include <linux/spinlock.h>
12533 +#include <linux/rcupdate.h>
12534 +#include <linux/in.h>
12535 +#include <linux/in6.h>
12536 +#include <asm/atomic.h>
12537 +
12538 +struct nx_addr_v4 {
12539 +       struct nx_addr_v4 *next;
12540 +       struct in_addr ip[2];
12541 +       struct in_addr mask;
12542 +       uint16_t type;
12543 +       uint16_t flags;
12544 +};
12545 +
12546 +struct nx_addr_v6 {
12547 +       struct nx_addr_v6 *next;
12548 +       struct in6_addr ip;
12549 +       struct in6_addr mask;
12550 +       uint32_t prefix;
12551 +       uint16_t type;
12552 +       uint16_t flags;
12553 +};
12554 +
12555 +struct nx_info {
12556 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12557 +       nid_t nx_id;                    /* vnet id */
12558 +       atomic_t nx_usecnt;             /* usage count */
12559 +       atomic_t nx_tasks;              /* tasks count */
12560 +       int nx_state;                   /* context state */
12561 +
12562 +       uint64_t nx_flags;              /* network flag word */
12563 +       uint64_t nx_ncaps;              /* network capabilities */
12564 +
12565 +       struct in_addr v4_lback;        /* Loopback address */
12566 +       struct in_addr v4_bcast;        /* Broadcast address */
12567 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12568 +#ifdef CONFIG_IPV6
12569 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12570 +#endif
12571 +       char nx_name[65];               /* network context name */
12572 +};
12573 +
12574 +
12575 +/* status flags */
12576 +
12577 +#define NXS_HASHED      0x0001
12578 +#define NXS_SHUTDOWN    0x0100
12579 +#define NXS_RELEASED    0x8000
12580 +
12581 +extern struct nx_info *lookup_nx_info(int);
12582 +
12583 +extern int get_nid_list(int, unsigned int *, int);
12584 +extern int nid_is_hashed(nid_t);
12585 +
12586 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12587 +
12588 +extern long vs_net_change(struct nx_info *, unsigned int);
12589 +
12590 +struct sock;
12591 +
12592 +
12593 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12594 +#ifdef  CONFIG_IPV6
12595 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12596 +#else
12597 +#define NX_IPV6(n)     (0)
12598 +#endif
12599 +
12600 +#endif /* __KERNEL__ */
12601 +#endif /* _VX_NETWORK_H */
12602 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/percpu.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/percpu.h
12603 --- linux-2.6.33/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
12604 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/percpu.h   2010-02-25 12:02:16.000000000 +0100
12605 @@ -0,0 +1,14 @@
12606 +#ifndef _VX_PERCPU_H
12607 +#define _VX_PERCPU_H
12608 +
12609 +#include "cvirt_def.h"
12610 +#include "sched_def.h"
12611 +
12612 +struct _vx_percpu {
12613 +       struct _vx_cvirt_pc cvirt;
12614 +       struct _vx_sched_pc sched;
12615 +};
12616 +
12617 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12618 +
12619 +#endif /* _VX_PERCPU_H */
12620 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/pid.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/pid.h
12621 --- linux-2.6.33/include/linux/vserver/pid.h    1970-01-01 01:00:00.000000000 +0100
12622 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/pid.h      2010-02-25 12:02:16.000000000 +0100
12623 @@ -0,0 +1,51 @@
12624 +#ifndef _VSERVER_PID_H
12625 +#define _VSERVER_PID_H
12626 +
12627 +/* pid faking stuff */
12628 +
12629 +#define vx_info_map_pid(v, p) \
12630 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12631 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12632 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12633 +#define vx_map_tgid(p) vx_map_pid(p)
12634 +
12635 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12636 +       const char *func, const char *file, int line)
12637 +{
12638 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12639 +               vxfprintk(VXD_CBIT(cvirt, 2),
12640 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12641 +                       vxi, (long long)vxi->vx_flags, pid,
12642 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12643 +                       func, file, line);
12644 +               if (pid == 0)
12645 +                       return 0;
12646 +               if (pid == vxi->vx_initpid)
12647 +                       return 1;
12648 +       }
12649 +       return pid;
12650 +}
12651 +
12652 +#define vx_info_rmap_pid(v, p) \
12653 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12654 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12655 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12656 +
12657 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12658 +       const char *func, const char *file, int line)
12659 +{
12660 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12661 +               vxfprintk(VXD_CBIT(cvirt, 2),
12662 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12663 +                       vxi, (long long)vxi->vx_flags, pid,
12664 +                       (pid == 1) ? vxi->vx_initpid : pid,
12665 +                       func, file, line);
12666 +               if ((pid == 1) && vxi->vx_initpid)
12667 +                       return vxi->vx_initpid;
12668 +               if (pid == vxi->vx_initpid)
12669 +                       return ~0U;
12670 +       }
12671 +       return pid;
12672 +}
12673 +
12674 +#endif
12675 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/sched_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/sched_cmd.h
12676 --- linux-2.6.33/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
12677 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/sched_cmd.h        2010-02-25 12:02:16.000000000 +0100
12678 @@ -0,0 +1,108 @@
12679 +#ifndef _VX_SCHED_CMD_H
12680 +#define _VX_SCHED_CMD_H
12681 +
12682 +
12683 +/*  sched vserver commands */
12684 +
12685 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12686 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12687 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12688 +
12689 +struct vcmd_set_sched_v2 {
12690 +       int32_t fill_rate;
12691 +       int32_t interval;
12692 +       int32_t tokens;
12693 +       int32_t tokens_min;
12694 +       int32_t tokens_max;
12695 +       uint64_t cpu_mask;
12696 +};
12697 +
12698 +struct vcmd_set_sched_v3 {
12699 +       uint32_t set_mask;
12700 +       int32_t fill_rate;
12701 +       int32_t interval;
12702 +       int32_t tokens;
12703 +       int32_t tokens_min;
12704 +       int32_t tokens_max;
12705 +       int32_t priority_bias;
12706 +};
12707 +
12708 +struct vcmd_set_sched_v4 {
12709 +       uint32_t set_mask;
12710 +       int32_t fill_rate;
12711 +       int32_t interval;
12712 +       int32_t tokens;
12713 +       int32_t tokens_min;
12714 +       int32_t tokens_max;
12715 +       int32_t prio_bias;
12716 +       int32_t cpu_id;
12717 +       int32_t bucket_id;
12718 +};
12719 +
12720 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12721 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12722 +
12723 +struct vcmd_sched_v5 {
12724 +       uint32_t mask;
12725 +       int32_t cpu_id;
12726 +       int32_t bucket_id;
12727 +       int32_t fill_rate[2];
12728 +       int32_t interval[2];
12729 +       int32_t tokens;
12730 +       int32_t tokens_min;
12731 +       int32_t tokens_max;
12732 +       int32_t prio_bias;
12733 +};
12734 +
12735 +#define VXSM_FILL_RATE         0x0001
12736 +#define VXSM_INTERVAL          0x0002
12737 +#define VXSM_FILL_RATE2                0x0004
12738 +#define VXSM_INTERVAL2         0x0008
12739 +#define VXSM_TOKENS            0x0010
12740 +#define VXSM_TOKENS_MIN                0x0020
12741 +#define VXSM_TOKENS_MAX                0x0040
12742 +#define VXSM_PRIO_BIAS         0x0100
12743 +
12744 +#define VXSM_IDLE_TIME         0x0200
12745 +#define VXSM_FORCE             0x0400
12746 +
12747 +#define        VXSM_V3_MASK            0x0173
12748 +#define        VXSM_SET_MASK           0x01FF
12749 +
12750 +#define VXSM_CPU_ID            0x1000
12751 +#define VXSM_BUCKET_ID         0x2000
12752 +
12753 +#define VXSM_MSEC              0x4000
12754 +
12755 +#define SCHED_KEEP             (-2)    /* only for v2 */
12756 +
12757 +#ifdef __KERNEL__
12758 +
12759 +#include <linux/compiler.h>
12760 +
12761 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12762 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12763 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12764 +extern int vc_set_sched(struct vx_info *, void __user *);
12765 +extern int vc_get_sched(struct vx_info *, void __user *);
12766 +
12767 +#endif /* __KERNEL__ */
12768 +
12769 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12770 +
12771 +struct vcmd_sched_info {
12772 +       int32_t cpu_id;
12773 +       int32_t bucket_id;
12774 +       uint64_t user_msec;
12775 +       uint64_t sys_msec;
12776 +       uint64_t hold_msec;
12777 +       uint32_t token_usec;
12778 +       int32_t vavavoom;
12779 +};
12780 +
12781 +#ifdef __KERNEL__
12782 +
12783 +extern int vc_sched_info(struct vx_info *, void __user *);
12784 +
12785 +#endif /* __KERNEL__ */
12786 +#endif /* _VX_SCHED_CMD_H */
12787 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/sched_def.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/sched_def.h
12788 --- linux-2.6.33/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
12789 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/sched_def.h        2010-02-25 12:02:16.000000000 +0100
12790 @@ -0,0 +1,68 @@
12791 +#ifndef _VX_SCHED_DEF_H
12792 +#define _VX_SCHED_DEF_H
12793 +
12794 +#include <linux/spinlock.h>
12795 +#include <linux/jiffies.h>
12796 +#include <linux/cpumask.h>
12797 +#include <asm/atomic.h>
12798 +#include <asm/param.h>
12799 +
12800 +
12801 +/* context sub struct */
12802 +
12803 +struct _vx_sched {
12804 +       spinlock_t tokens_lock;         /* lock for token bucket */
12805 +
12806 +       int tokens;                     /* number of CPU tokens */
12807 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12808 +       int interval[2];                /* Divisor:   per Y jiffies   */
12809 +       int tokens_min;                 /* Limit:     minimum for unhold */
12810 +       int tokens_max;                 /* Limit:     no more than N tokens */
12811 +
12812 +       int prio_bias;                  /* bias offset for priority */
12813 +
12814 +       unsigned update_mask;           /* which features should be updated */
12815 +       cpumask_t update;               /* CPUs which should update */
12816 +};
12817 +
12818 +struct _vx_sched_pc {
12819 +       int tokens;                     /* number of CPU tokens */
12820 +       int flags;                      /* bucket flags */
12821 +
12822 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12823 +       int interval[2];                /* Divisor:   per Y jiffies   */
12824 +       int tokens_min;                 /* Limit:     minimum for unhold */
12825 +       int tokens_max;                 /* Limit:     no more than N tokens */
12826 +
12827 +       int prio_bias;                  /* bias offset for priority */
12828 +       int vavavoom;                   /* last calculated vavavoom */
12829 +
12830 +       unsigned long norm_time;        /* last time accounted */
12831 +       unsigned long idle_time;        /* non linear time for fair sched */
12832 +       unsigned long token_time;       /* token time for accounting */
12833 +       unsigned long onhold;           /* jiffies when put on hold */
12834 +
12835 +       uint64_t user_ticks;            /* token tick events */
12836 +       uint64_t sys_ticks;             /* token tick events */
12837 +       uint64_t hold_ticks;            /* token ticks paused */
12838 +};
12839 +
12840 +
12841 +#define VXSF_ONHOLD    0x0001
12842 +#define VXSF_IDLE_TIME 0x0100
12843 +
12844 +#ifdef CONFIG_VSERVER_DEBUG
12845 +
12846 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12847 +{
12848 +       printk("\t_vx_sched:\n");
12849 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12850 +               sched->fill_rate[0], sched->interval[0],
12851 +               sched->fill_rate[1], sched->interval[1],
12852 +               sched->tokens_min, sched->tokens_max);
12853 +       printk("\t priority = %4d\n", sched->prio_bias);
12854 +}
12855 +
12856 +#endif
12857 +
12858 +#endif /* _VX_SCHED_DEF_H */
12859 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/sched.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/sched.h
12860 --- linux-2.6.33/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
12861 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/sched.h    2010-02-25 12:02:16.000000000 +0100
12862 @@ -0,0 +1,26 @@
12863 +#ifndef _VX_SCHED_H
12864 +#define _VX_SCHED_H
12865 +
12866 +
12867 +#ifdef __KERNEL__
12868 +
12869 +struct timespec;
12870 +
12871 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12872 +
12873 +
12874 +struct vx_info;
12875 +
12876 +void vx_update_load(struct vx_info *);
12877 +
12878 +
12879 +int vx_tokens_recalc(struct _vx_sched_pc *,
12880 +       unsigned long *, unsigned long *, int [2]);
12881 +
12882 +void vx_update_sched_param(struct _vx_sched *sched,
12883 +       struct _vx_sched_pc *sched_pc);
12884 +
12885 +#endif /* __KERNEL__ */
12886 +#else  /* _VX_SCHED_H */
12887 +#warning duplicate inclusion
12888 +#endif /* _VX_SCHED_H */
12889 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/signal_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/signal_cmd.h
12890 --- linux-2.6.33/include/linux/vserver/signal_cmd.h     1970-01-01 01:00:00.000000000 +0100
12891 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/signal_cmd.h       2010-02-25 12:02:16.000000000 +0100
12892 @@ -0,0 +1,43 @@
12893 +#ifndef _VX_SIGNAL_CMD_H
12894 +#define _VX_SIGNAL_CMD_H
12895 +
12896 +
12897 +/*  signalling vserver commands */
12898 +
12899 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12900 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12901 +
12902 +struct vcmd_ctx_kill_v0 {
12903 +       int32_t pid;
12904 +       int32_t sig;
12905 +};
12906 +
12907 +struct vcmd_wait_exit_v0 {
12908 +       int32_t reboot_cmd;
12909 +       int32_t exit_code;
12910 +};
12911 +
12912 +#ifdef __KERNEL__
12913 +
12914 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12915 +extern int vc_wait_exit(struct vx_info *, void __user *);
12916 +
12917 +#endif /* __KERNEL__ */
12918 +
12919 +/*  process alteration commands */
12920 +
12921 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12922 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12923 +
12924 +struct vcmd_pflags_v0 {
12925 +       uint32_t flagword;
12926 +       uint32_t mask;
12927 +};
12928 +
12929 +#ifdef __KERNEL__
12930 +
12931 +extern int vc_get_pflags(uint32_t pid, void __user *);
12932 +extern int vc_set_pflags(uint32_t pid, void __user *);
12933 +
12934 +#endif /* __KERNEL__ */
12935 +#endif /* _VX_SIGNAL_CMD_H */
12936 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/signal.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/signal.h
12937 --- linux-2.6.33/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
12938 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/signal.h   2010-02-25 12:02:16.000000000 +0100
12939 @@ -0,0 +1,14 @@
12940 +#ifndef _VX_SIGNAL_H
12941 +#define _VX_SIGNAL_H
12942 +
12943 +
12944 +#ifdef __KERNEL__
12945 +
12946 +struct vx_info;
12947 +
12948 +int vx_info_kill(struct vx_info *, int, int);
12949 +
12950 +#endif /* __KERNEL__ */
12951 +#else  /* _VX_SIGNAL_H */
12952 +#warning duplicate inclusion
12953 +#endif /* _VX_SIGNAL_H */
12954 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/space_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/space_cmd.h
12955 --- linux-2.6.33/include/linux/vserver/space_cmd.h      1970-01-01 01:00:00.000000000 +0100
12956 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/space_cmd.h        2010-02-25 12:02:16.000000000 +0100
12957 @@ -0,0 +1,38 @@
12958 +#ifndef _VX_SPACE_CMD_H
12959 +#define _VX_SPACE_CMD_H
12960 +
12961 +
12962 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12963 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12964 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12965 +
12966 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12967 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12968 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12969 +
12970 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12971 +
12972 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12973 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12974 +
12975 +
12976 +struct vcmd_space_mask_v1 {
12977 +       uint64_t mask;
12978 +};
12979 +
12980 +struct vcmd_space_mask_v2 {
12981 +       uint64_t mask;
12982 +       uint32_t index;
12983 +};
12984 +
12985 +
12986 +#ifdef __KERNEL__
12987 +
12988 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12989 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12990 +extern int vc_enter_space(struct vx_info *, void __user *);
12991 +extern int vc_set_space(struct vx_info *, void __user *);
12992 +extern int vc_get_space_mask(void __user *, int);
12993 +
12994 +#endif /* __KERNEL__ */
12995 +#endif /* _VX_SPACE_CMD_H */
12996 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/space.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/space.h
12997 --- linux-2.6.33/include/linux/vserver/space.h  1970-01-01 01:00:00.000000000 +0100
12998 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/space.h    2010-02-25 12:02:16.000000000 +0100
12999 @@ -0,0 +1,12 @@
13000 +#ifndef _VX_SPACE_H
13001 +#define _VX_SPACE_H
13002 +
13003 +#include <linux/types.h>
13004 +
13005 +struct vx_info;
13006 +
13007 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13008 +
13009 +#else  /* _VX_SPACE_H */
13010 +#warning duplicate inclusion
13011 +#endif /* _VX_SPACE_H */
13012 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/switch.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/switch.h
13013 --- linux-2.6.33/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
13014 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/switch.h   2010-02-25 12:02:16.000000000 +0100
13015 @@ -0,0 +1,98 @@
13016 +#ifndef _VX_SWITCH_H
13017 +#define _VX_SWITCH_H
13018 +
13019 +#include <linux/types.h>
13020 +
13021 +
13022 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13023 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13024 +#define VC_VERSION(c)          ((c) & 0xFFF)
13025 +
13026 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13027 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13028 +
13029 +/*
13030 +
13031 +  Syscall Matrix V2.8
13032 +
13033 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13034 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13035 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13036 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13037 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13038 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13039 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13040 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13041 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13042 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13043 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13044 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13045 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13046 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13047 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13048 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13049 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13050 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13051 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13052 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13053 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13054 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13055 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13056 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13057 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13058 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13059 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13060 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13061 +
13062 +*/
13063 +
13064 +#define VC_CAT_VERSION         0
13065 +
13066 +#define VC_CAT_VSETUP          1
13067 +#define VC_CAT_VHOST           2
13068 +
13069 +#define VC_CAT_DEVICE          6
13070 +
13071 +#define VC_CAT_VPROC           9
13072 +#define VC_CAT_PROCALT         10
13073 +#define VC_CAT_PROCMIG         11
13074 +#define VC_CAT_PROCTRL         12
13075 +
13076 +#define VC_CAT_SCHED           14
13077 +#define VC_CAT_MEMCTRL         20
13078 +
13079 +#define VC_CAT_VNET            25
13080 +#define VC_CAT_NETALT          26
13081 +#define VC_CAT_NETMIG          27
13082 +#define VC_CAT_NETCTRL         28
13083 +
13084 +#define VC_CAT_TAGMIG          35
13085 +#define VC_CAT_DLIMIT          36
13086 +#define VC_CAT_INODE           38
13087 +
13088 +#define VC_CAT_VSTAT           40
13089 +#define VC_CAT_VINFO           46
13090 +#define VC_CAT_EVENT           48
13091 +
13092 +#define VC_CAT_FLAGS           52
13093 +#define VC_CAT_VSPACE          54
13094 +#define VC_CAT_DEBUG           56
13095 +#define VC_CAT_RLIMIT          60
13096 +
13097 +#define VC_CAT_SYSTEST         61
13098 +#define VC_CAT_COMPAT          63
13099 +
13100 +/*  query version */
13101 +
13102 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13103 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13104 +
13105 +
13106 +#ifdef __KERNEL__
13107 +
13108 +#include <linux/errno.h>
13109 +
13110 +#endif /* __KERNEL__ */
13111 +
13112 +#endif /* _VX_SWITCH_H */
13113 +
13114 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/tag_cmd.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/tag_cmd.h
13115 --- linux-2.6.33/include/linux/vserver/tag_cmd.h        1970-01-01 01:00:00.000000000 +0100
13116 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/tag_cmd.h  2010-02-25 12:02:16.000000000 +0100
13117 @@ -0,0 +1,22 @@
13118 +#ifndef _VX_TAG_CMD_H
13119 +#define _VX_TAG_CMD_H
13120 +
13121 +
13122 +/* vinfo commands */
13123 +
13124 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13125 +
13126 +#ifdef __KERNEL__
13127 +extern int vc_task_tag(uint32_t);
13128 +
13129 +#endif /* __KERNEL__ */
13130 +
13131 +/* context commands */
13132 +
13133 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13134 +
13135 +#ifdef __KERNEL__
13136 +extern int vc_tag_migrate(uint32_t);
13137 +
13138 +#endif /* __KERNEL__ */
13139 +#endif /* _VX_TAG_CMD_H */
13140 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/tag.h linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/tag.h
13141 --- linux-2.6.33/include/linux/vserver/tag.h    1970-01-01 01:00:00.000000000 +0100
13142 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vserver/tag.h      2010-02-25 12:02:16.000000000 +0100
13143 @@ -0,0 +1,143 @@
13144 +#ifndef _DX_TAG_H
13145 +#define _DX_TAG_H
13146 +
13147 +#include <linux/types.h>
13148 +
13149 +
13150 +#define DX_TAG(in)     (IS_TAGGED(in))
13151 +
13152 +
13153 +#ifdef CONFIG_TAG_NFSD
13154 +#define DX_TAG_NFSD    1
13155 +#else
13156 +#define DX_TAG_NFSD    0
13157 +#endif
13158 +
13159 +
13160 +#ifdef CONFIG_TAGGING_NONE
13161 +
13162 +#define MAX_UID                0xFFFFFFFF
13163 +#define MAX_GID                0xFFFFFFFF
13164 +
13165 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13166 +
13167 +#define TAGINO_UID(cond, uid, tag)     (uid)
13168 +#define TAGINO_GID(cond, gid, tag)     (gid)
13169 +
13170 +#endif
13171 +
13172 +
13173 +#ifdef CONFIG_TAGGING_GID16
13174 +
13175 +#define MAX_UID                0xFFFFFFFF
13176 +#define MAX_GID                0x0000FFFF
13177 +
13178 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13179 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13180 +
13181 +#define TAGINO_UID(cond, uid, tag)     (uid)
13182 +#define TAGINO_GID(cond, gid, tag)     \
13183 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13184 +
13185 +#endif
13186 +
13187 +
13188 +#ifdef CONFIG_TAGGING_ID24
13189 +
13190 +#define MAX_UID                0x00FFFFFF
13191 +#define MAX_GID                0x00FFFFFF
13192 +
13193 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13194 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13195 +
13196 +#define TAGINO_UID(cond, uid, tag)     \
13197 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13198 +#define TAGINO_GID(cond, gid, tag)     \
13199 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13200 +
13201 +#endif
13202 +
13203 +
13204 +#ifdef CONFIG_TAGGING_UID16
13205 +
13206 +#define MAX_UID                0x0000FFFF
13207 +#define MAX_GID                0xFFFFFFFF
13208 +
13209 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13210 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13211 +
13212 +#define TAGINO_UID(cond, uid, tag)     \
13213 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13214 +#define TAGINO_GID(cond, gid, tag)     (gid)
13215 +
13216 +#endif
13217 +
13218 +
13219 +#ifdef CONFIG_TAGGING_INTERN
13220 +
13221 +#define MAX_UID                0xFFFFFFFF
13222 +#define MAX_GID                0xFFFFFFFF
13223 +
13224 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13225 +       ((cond) ? (tag) : 0)
13226 +
13227 +#define TAGINO_UID(cond, uid, tag)     (uid)
13228 +#define TAGINO_GID(cond, gid, tag)     (gid)
13229 +
13230 +#endif
13231 +
13232 +
13233 +#ifndef CONFIG_TAGGING_NONE
13234 +#define dx_current_fstag(sb)   \
13235 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13236 +#else
13237 +#define dx_current_fstag(sb)   (0)
13238 +#endif
13239 +
13240 +#ifndef CONFIG_TAGGING_INTERN
13241 +#define TAGINO_TAG(cond, tag)  (0)
13242 +#else
13243 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13244 +#endif
13245 +
13246 +#define INOTAG_UID(cond, uid, gid)     \
13247 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13248 +#define INOTAG_GID(cond, uid, gid)     \
13249 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13250 +
13251 +
13252 +static inline uid_t dx_map_uid(uid_t uid)
13253 +{
13254 +       if ((uid > MAX_UID) && (uid != -1))
13255 +               uid = -2;
13256 +       return (uid & MAX_UID);
13257 +}
13258 +
13259 +static inline gid_t dx_map_gid(gid_t gid)
13260 +{
13261 +       if ((gid > MAX_GID) && (gid != -1))
13262 +               gid = -2;
13263 +       return (gid & MAX_GID);
13264 +}
13265 +
13266 +struct peer_tag {
13267 +       int32_t xid;
13268 +       int32_t nid;
13269 +};
13270 +
13271 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13272 +
13273 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13274 +                unsigned long *flags);
13275 +
13276 +#ifdef CONFIG_PROPAGATE
13277 +
13278 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13279 +
13280 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13281 +
13282 +#else
13283 +#define dx_propagate_tag(n, i) do { } while (0)
13284 +#endif
13285 +
13286 +#endif /* _DX_TAG_H */
13287 diff -NurpP --minimal linux-2.6.33/include/linux/vs_inet6.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_inet6.h
13288 --- linux-2.6.33/include/linux/vs_inet6.h       1970-01-01 01:00:00.000000000 +0100
13289 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_inet6.h 2010-02-25 14:47:08.000000000 +0100
13290 @@ -0,0 +1,246 @@
13291 +#ifndef _VS_INET6_H
13292 +#define _VS_INET6_H
13293 +
13294 +#include "vserver/base.h"
13295 +#include "vserver/network.h"
13296 +#include "vserver/debug.h"
13297 +
13298 +#include <net/ipv6.h>
13299 +
13300 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13301 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13302 +
13303 +
13304 +#ifdef CONFIG_IPV6
13305 +
13306 +static inline
13307 +int v6_addr_match(struct nx_addr_v6 *nxa,
13308 +       const struct in6_addr *addr, uint16_t mask)
13309 +{
13310 +       int ret = 0;
13311 +
13312 +       switch (nxa->type & mask) {
13313 +       case NXA_TYPE_MASK:
13314 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13315 +               break;
13316 +       case NXA_TYPE_ADDR:
13317 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13318 +               break;
13319 +       case NXA_TYPE_ANY:
13320 +               ret = 1;
13321 +               break;
13322 +       }
13323 +       vxdprintk(VXD_CBIT(net, 0),
13324 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13325 +               nxa, NXAV6(nxa), addr, mask, ret);
13326 +       return ret;
13327 +}
13328 +
13329 +static inline
13330 +int v6_addr_in_nx_info(struct nx_info *nxi,
13331 +       const struct in6_addr *addr, uint16_t mask)
13332 +{
13333 +       struct nx_addr_v6 *nxa;
13334 +       int ret = 1;
13335 +
13336 +       if (!nxi)
13337 +               goto out;
13338 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13339 +               if (v6_addr_match(nxa, addr, mask))
13340 +                       goto out;
13341 +       ret = 0;
13342 +out:
13343 +       vxdprintk(VXD_CBIT(net, 0),
13344 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13345 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13346 +       return ret;
13347 +}
13348 +
13349 +static inline
13350 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13351 +{
13352 +       /* FIXME: needs full range checks */
13353 +       return v6_addr_match(nxa, &addr->ip, mask);
13354 +}
13355 +
13356 +static inline
13357 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13358 +{
13359 +       struct nx_addr_v6 *ptr;
13360 +
13361 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13362 +               if (v6_nx_addr_match(ptr, nxa, mask))
13363 +                       return 1;
13364 +       return 0;
13365 +}
13366 +
13367 +
13368 +/*
13369 + *     Check if a given address matches for a socket
13370 + *
13371 + *     nxi:            the socket's nx_info if any
13372 + *     addr:           to be verified address
13373 + */
13374 +static inline
13375 +int v6_sock_addr_match (
13376 +       struct nx_info *nxi,
13377 +       struct inet_sock *inet,
13378 +       struct in6_addr *addr)
13379 +{
13380 +       struct sock *sk = &inet->sk;
13381 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13382 +
13383 +       if (!ipv6_addr_any(addr) &&
13384 +               ipv6_addr_equal(saddr, addr))
13385 +               return 1;
13386 +       if (ipv6_addr_any(saddr))
13387 +               return v6_addr_in_nx_info(nxi, addr, -1);
13388 +       return 0;
13389 +}
13390 +
13391 +/*
13392 + *     check if address is covered by socket
13393 + *
13394 + *     sk:     the socket to check against
13395 + *     addr:   the address in question (must be != 0)
13396 + */
13397 +
13398 +static inline
13399 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13400 +{
13401 +       struct nx_info *nxi = sk->sk_nx_info;
13402 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13403 +
13404 +       vxdprintk(VXD_CBIT(net, 5),
13405 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13406 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13407 +               (sk->sk_socket?sk->sk_socket->flags:0));
13408 +
13409 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13410 +               return v6_addr_match(nxa, saddr, -1);
13411 +       } else if (nxi) {               /* match against nx_info */
13412 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13413 +       } else {                        /* unrestricted any socket */
13414 +               return 1;
13415 +       }
13416 +}
13417 +
13418 +
13419 +/* inet related checks and helpers */
13420 +
13421 +
13422 +struct in_ifaddr;
13423 +struct net_device;
13424 +struct sock;
13425 +
13426 +
13427 +#include <linux/netdevice.h>
13428 +#include <linux/inetdevice.h>
13429 +#include <net/inet_timewait_sock.h>
13430 +
13431 +
13432 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13433 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13434 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13435 +
13436 +
13437 +
13438 +static inline
13439 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13440 +{
13441 +       if (!nxi)
13442 +               return 1;
13443 +       if (!ifa)
13444 +               return 0;
13445 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13446 +}
13447 +
13448 +static inline
13449 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13450 +{
13451 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13452 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13453 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13454 +
13455 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13456 +               return 1;
13457 +       if (v6_ifa_in_nx_info(ifa, nxi))
13458 +               return 1;
13459 +       return 0;
13460 +}
13461 +
13462 +
13463 +struct nx_v6_sock_addr {
13464 +       struct in6_addr saddr;  /* Address used for validation */
13465 +       struct in6_addr baddr;  /* Address used for socket bind */
13466 +};
13467 +
13468 +static inline
13469 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13470 +       struct nx_v6_sock_addr *nsa)
13471 +{
13472 +       // struct sock *sk = &inet->sk;
13473 +       // struct nx_info *nxi = sk->sk_nx_info;
13474 +       struct in6_addr saddr = addr->sin6_addr;
13475 +       struct in6_addr baddr = saddr;
13476 +
13477 +       nsa->saddr = saddr;
13478 +       nsa->baddr = baddr;
13479 +       return 0;
13480 +}
13481 +
13482 +static inline
13483 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13484 +{
13485 +       // struct sock *sk = &inet->sk;
13486 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13487 +
13488 +       // *saddr = nsa->baddr;
13489 +       // inet->inet_saddr = nsa->baddr;
13490 +}
13491 +
13492 +static inline
13493 +int nx_info_has_v6(struct nx_info *nxi)
13494 +{
13495 +       if (!nxi)
13496 +               return 1;
13497 +       if (NX_IPV6(nxi))
13498 +               return 1;
13499 +       return 0;
13500 +}
13501 +
13502 +#else /* CONFIG_IPV6 */
13503 +
13504 +static inline
13505 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13506 +{
13507 +       return 1;
13508 +}
13509 +
13510 +
13511 +static inline
13512 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13513 +{
13514 +       return 1;
13515 +}
13516 +
13517 +static inline
13518 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13519 +{
13520 +       return 1;
13521 +}
13522 +
13523 +static inline
13524 +int nx_info_has_v6(struct nx_info *nxi)
13525 +{
13526 +       return 0;
13527 +}
13528 +
13529 +#endif /* CONFIG_IPV6 */
13530 +
13531 +#define current_nx_info_has_v6() \
13532 +       nx_info_has_v6(current_nx_info())
13533 +
13534 +#else
13535 +#warning duplicate inclusion
13536 +#endif
13537 diff -NurpP --minimal linux-2.6.33/include/linux/vs_inet.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_inet.h
13538 --- linux-2.6.33/include/linux/vs_inet.h        1970-01-01 01:00:00.000000000 +0100
13539 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_inet.h  2010-02-25 14:45:44.000000000 +0100
13540 @@ -0,0 +1,342 @@
13541 +#ifndef _VS_INET_H
13542 +#define _VS_INET_H
13543 +
13544 +#include "vserver/base.h"
13545 +#include "vserver/network.h"
13546 +#include "vserver/debug.h"
13547 +
13548 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13549 +
13550 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13551 +                       NIPQUAD((a)->mask), (a)->type
13552 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13553 +
13554 +
13555 +static inline
13556 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13557 +{
13558 +       __be32 ip = nxa->ip[0].s_addr;
13559 +       __be32 mask = nxa->mask.s_addr;
13560 +       __be32 bcast = ip | ~mask;
13561 +       int ret = 0;
13562 +
13563 +       switch (nxa->type & tmask) {
13564 +       case NXA_TYPE_MASK:
13565 +               ret = (ip == (addr & mask));
13566 +               break;
13567 +       case NXA_TYPE_ADDR:
13568 +               ret = 3;
13569 +               if (addr == ip)
13570 +                       break;
13571 +               /* fall through to broadcast */
13572 +       case NXA_MOD_BCAST:
13573 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13574 +               break;
13575 +       case NXA_TYPE_RANGE:
13576 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13577 +                       (nxa->ip[1].s_addr > addr));
13578 +               break;
13579 +       case NXA_TYPE_ANY:
13580 +               ret = 2;
13581 +               break;
13582 +       }
13583 +
13584 +       vxdprintk(VXD_CBIT(net, 0),
13585 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13586 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13587 +       return ret;
13588 +}
13589 +
13590 +static inline
13591 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13592 +{
13593 +       struct nx_addr_v4 *nxa;
13594 +       int ret = 1;
13595 +
13596 +       if (!nxi)
13597 +               goto out;
13598 +
13599 +       ret = 2;
13600 +       /* allow 127.0.0.1 when remapping lback */
13601 +       if ((tmask & NXA_LOOPBACK) &&
13602 +               (addr == IPI_LOOPBACK) &&
13603 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13604 +               goto out;
13605 +       ret = 3;
13606 +       /* check for lback address */
13607 +       if ((tmask & NXA_MOD_LBACK) &&
13608 +               (nxi->v4_lback.s_addr == addr))
13609 +               goto out;
13610 +       ret = 4;
13611 +       /* check for broadcast address */
13612 +       if ((tmask & NXA_MOD_BCAST) &&
13613 +               (nxi->v4_bcast.s_addr == addr))
13614 +               goto out;
13615 +       ret = 5;
13616 +       /* check for v4 addresses */
13617 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13618 +               if (v4_addr_match(nxa, addr, tmask))
13619 +                       goto out;
13620 +       ret = 0;
13621 +out:
13622 +       vxdprintk(VXD_CBIT(net, 0),
13623 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13624 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13625 +       return ret;
13626 +}
13627 +
13628 +static inline
13629 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13630 +{
13631 +       /* FIXME: needs full range checks */
13632 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13633 +}
13634 +
13635 +static inline
13636 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13637 +{
13638 +       struct nx_addr_v4 *ptr;
13639 +
13640 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13641 +               if (v4_nx_addr_match(ptr, nxa, mask))
13642 +                       return 1;
13643 +       return 0;
13644 +}
13645 +
13646 +#include <net/inet_sock.h>
13647 +
13648 +/*
13649 + *     Check if a given address matches for a socket
13650 + *
13651 + *     nxi:            the socket's nx_info if any
13652 + *     addr:           to be verified address
13653 + */
13654 +static inline
13655 +int v4_sock_addr_match (
13656 +       struct nx_info *nxi,
13657 +       struct inet_sock *inet,
13658 +       __be32 addr)
13659 +{
13660 +       __be32 saddr = inet->inet_rcv_saddr;
13661 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13662 +
13663 +       if (addr && (saddr == addr || bcast == addr))
13664 +               return 1;
13665 +       if (!saddr)
13666 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13667 +       return 0;
13668 +}
13669 +
13670 +
13671 +/* inet related checks and helpers */
13672 +
13673 +
13674 +struct in_ifaddr;
13675 +struct net_device;
13676 +struct sock;
13677 +
13678 +#ifdef CONFIG_INET
13679 +
13680 +#include <linux/netdevice.h>
13681 +#include <linux/inetdevice.h>
13682 +#include <net/inet_sock.h>
13683 +#include <net/inet_timewait_sock.h>
13684 +
13685 +
13686 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13687 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13688 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13689 +
13690 +
13691 +/*
13692 + *     check if address is covered by socket
13693 + *
13694 + *     sk:     the socket to check against
13695 + *     addr:   the address in question (must be != 0)
13696 + */
13697 +
13698 +static inline
13699 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13700 +{
13701 +       struct nx_info *nxi = sk->sk_nx_info;
13702 +       __be32 saddr = inet_rcv_saddr(sk);
13703 +
13704 +       vxdprintk(VXD_CBIT(net, 5),
13705 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13706 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13707 +               (sk->sk_socket?sk->sk_socket->flags:0));
13708 +
13709 +       if (saddr) {            /* direct address match */
13710 +               return v4_addr_match(nxa, saddr, -1);
13711 +       } else if (nxi) {       /* match against nx_info */
13712 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13713 +       } else {                /* unrestricted any socket */
13714 +               return 1;
13715 +       }
13716 +}
13717 +
13718 +
13719 +
13720 +static inline
13721 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13722 +{
13723 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13724 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13725 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13726 +
13727 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13728 +               return 1;
13729 +       if (dev_in_nx_info(dev, nxi))
13730 +               return 1;
13731 +       return 0;
13732 +}
13733 +
13734 +
13735 +static inline
13736 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13737 +{
13738 +       if (!nxi)
13739 +               return 1;
13740 +       if (!ifa)
13741 +               return 0;
13742 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13743 +}
13744 +
13745 +static inline
13746 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13747 +{
13748 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13749 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13750 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13751 +
13752 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13753 +               return 1;
13754 +       if (v4_ifa_in_nx_info(ifa, nxi))
13755 +               return 1;
13756 +       return 0;
13757 +}
13758 +
13759 +
13760 +struct nx_v4_sock_addr {
13761 +       __be32 saddr;   /* Address used for validation */
13762 +       __be32 baddr;   /* Address used for socket bind */
13763 +};
13764 +
13765 +static inline
13766 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13767 +       struct nx_v4_sock_addr *nsa)
13768 +{
13769 +       struct sock *sk = &inet->sk;
13770 +       struct nx_info *nxi = sk->sk_nx_info;
13771 +       __be32 saddr = addr->sin_addr.s_addr;
13772 +       __be32 baddr = saddr;
13773 +
13774 +       vxdprintk(VXD_CBIT(net, 3),
13775 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13776 +               sk, sk->sk_nx_info, sk->sk_socket,
13777 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13778 +               NIPQUAD(saddr));
13779 +
13780 +       if (nxi) {
13781 +               if (saddr == INADDR_ANY) {
13782 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13783 +                               baddr = nxi->v4.ip[0].s_addr;
13784 +               } else if (saddr == IPI_LOOPBACK) {
13785 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13786 +                               baddr = nxi->v4_lback.s_addr;
13787 +               } else {        /* normal address bind */
13788 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13789 +                               return -EADDRNOTAVAIL;
13790 +               }
13791 +       }
13792 +
13793 +       vxdprintk(VXD_CBIT(net, 3),
13794 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13795 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13796 +
13797 +       nsa->saddr = saddr;
13798 +       nsa->baddr = baddr;
13799 +       return 0;
13800 +}
13801 +
13802 +static inline
13803 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13804 +{
13805 +       inet->inet_saddr = nsa->baddr;
13806 +       inet->inet_rcv_saddr = nsa->baddr;
13807 +}
13808 +
13809 +
13810 +/*
13811 + *      helper to simplify inet_lookup_listener
13812 + *
13813 + *      nxi:   the socket's nx_info if any
13814 + *      addr:  to be verified address
13815 + *      saddr: socket address
13816 + */
13817 +static inline int v4_inet_addr_match (
13818 +       struct nx_info *nxi,
13819 +       __be32 addr,
13820 +       __be32 saddr)
13821 +{
13822 +       if (addr && (saddr == addr))
13823 +               return 1;
13824 +       if (!saddr)
13825 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13826 +       return 0;
13827 +}
13828 +
13829 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13830 +{
13831 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13832 +               (addr == nxi->v4_lback.s_addr))
13833 +               return IPI_LOOPBACK;
13834 +       return addr;
13835 +}
13836 +
13837 +static inline
13838 +int nx_info_has_v4(struct nx_info *nxi)
13839 +{
13840 +       if (!nxi)
13841 +               return 1;
13842 +       if (NX_IPV4(nxi))
13843 +               return 1;
13844 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13845 +               return 1;
13846 +       return 0;
13847 +}
13848 +
13849 +#else /* CONFIG_INET */
13850 +
13851 +static inline
13852 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13853 +{
13854 +       return 1;
13855 +}
13856 +
13857 +static inline
13858 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13859 +{
13860 +       return 1;
13861 +}
13862 +
13863 +static inline
13864 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13865 +{
13866 +       return 1;
13867 +}
13868 +
13869 +static inline
13870 +int nx_info_has_v4(struct nx_info *nxi)
13871 +{
13872 +       return 0;
13873 +}
13874 +
13875 +#endif /* CONFIG_INET */
13876 +
13877 +#define current_nx_info_has_v4() \
13878 +       nx_info_has_v4(current_nx_info())
13879 +
13880 +#else
13881 +// #warning duplicate inclusion
13882 +#endif
13883 diff -NurpP --minimal linux-2.6.33/include/linux/vs_limit.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_limit.h
13884 --- linux-2.6.33/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
13885 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_limit.h 2010-02-25 12:02:16.000000000 +0100
13886 @@ -0,0 +1,140 @@
13887 +#ifndef _VS_LIMIT_H
13888 +#define _VS_LIMIT_H
13889 +
13890 +#include "vserver/limit.h"
13891 +#include "vserver/base.h"
13892 +#include "vserver/context.h"
13893 +#include "vserver/debug.h"
13894 +#include "vserver/context.h"
13895 +#include "vserver/limit_int.h"
13896 +
13897 +
13898 +#define vx_acc_cres(v, d, p, r) \
13899 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13900 +
13901 +#define vx_acc_cres_cond(x, d, p, r) \
13902 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13903 +       r, d, p, __FILE__, __LINE__)
13904 +
13905 +
13906 +#define vx_add_cres(v, a, p, r) \
13907 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13908 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13909 +
13910 +#define vx_add_cres_cond(x, a, p, r) \
13911 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13912 +       r, a, p, __FILE__, __LINE__)
13913 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13914 +
13915 +
13916 +/* process and file limits */
13917 +
13918 +#define vx_nproc_inc(p) \
13919 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13920 +
13921 +#define vx_nproc_dec(p) \
13922 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13923 +
13924 +#define vx_files_inc(f) \
13925 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13926 +
13927 +#define vx_files_dec(f) \
13928 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13929 +
13930 +#define vx_locks_inc(l) \
13931 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13932 +
13933 +#define vx_locks_dec(l) \
13934 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13935 +
13936 +#define vx_openfd_inc(f) \
13937 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13938 +
13939 +#define vx_openfd_dec(f) \
13940 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
13941 +
13942 +
13943 +#define vx_cres_avail(v, n, r) \
13944 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13945 +
13946 +
13947 +#define vx_nproc_avail(n) \
13948 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
13949 +
13950 +#define vx_files_avail(n) \
13951 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
13952 +
13953 +#define vx_locks_avail(n) \
13954 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
13955 +
13956 +#define vx_openfd_avail(n) \
13957 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
13958 +
13959 +
13960 +/* dentry limits */
13961 +
13962 +#define vx_dentry_inc(d) do {                                          \
13963 +       if (atomic_read(&d->d_count) == 1)                              \
13964 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
13965 +       } while (0)
13966 +
13967 +#define vx_dentry_dec(d) do {                                          \
13968 +       if (atomic_read(&d->d_count) == 0)                              \
13969 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
13970 +       } while (0)
13971 +
13972 +#define vx_dentry_avail(n) \
13973 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
13974 +
13975 +
13976 +/* socket limits */
13977 +
13978 +#define vx_sock_inc(s) \
13979 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13980 +
13981 +#define vx_sock_dec(s) \
13982 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13983 +
13984 +#define vx_sock_avail(n) \
13985 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
13986 +
13987 +
13988 +/* ipc resource limits */
13989 +
13990 +#define vx_ipcmsg_add(v, u, a) \
13991 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13992 +
13993 +#define vx_ipcmsg_sub(v, u, a) \
13994 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13995 +
13996 +#define vx_ipcmsg_avail(v, a) \
13997 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13998 +
13999 +
14000 +#define vx_ipcshm_add(v, k, a) \
14001 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14002 +
14003 +#define vx_ipcshm_sub(v, k, a) \
14004 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14005 +
14006 +#define vx_ipcshm_avail(v, a) \
14007 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14008 +
14009 +
14010 +#define vx_semary_inc(a) \
14011 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
14012 +
14013 +#define vx_semary_dec(a) \
14014 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
14015 +
14016 +
14017 +#define vx_nsems_add(a,n) \
14018 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14019 +
14020 +#define vx_nsems_sub(a,n) \
14021 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14022 +
14023 +
14024 +#else
14025 +#warning duplicate inclusion
14026 +#endif
14027 diff -NurpP --minimal linux-2.6.33/include/linux/vs_memory.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_memory.h
14028 --- linux-2.6.33/include/linux/vs_memory.h      1970-01-01 01:00:00.000000000 +0100
14029 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_memory.h        2010-02-25 12:02:16.000000000 +0100
14030 @@ -0,0 +1,159 @@
14031 +#ifndef _VS_MEMORY_H
14032 +#define _VS_MEMORY_H
14033 +
14034 +#include "vserver/limit.h"
14035 +#include "vserver/base.h"
14036 +#include "vserver/context.h"
14037 +#include "vserver/debug.h"
14038 +#include "vserver/context.h"
14039 +#include "vserver/limit_int.h"
14040 +
14041 +
14042 +#define __acc_add_long(a, v)   (*(v) += (a))
14043 +#define __acc_inc_long(v)      (++*(v))
14044 +#define __acc_dec_long(v)      (--*(v))
14045 +
14046 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14047 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14048 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14049 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14050 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14051 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14052 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14053 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14054 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14055 +
14056 +
14057 +#define vx_acc_page(m, d, v, r) do {                                   \
14058 +       if ((d) > 0)                                                    \
14059 +               __acc_inc_long(&(m)->v);                                \
14060 +       else                                                            \
14061 +               __acc_dec_long(&(m)->v);                                \
14062 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14063 +} while (0)
14064 +
14065 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14066 +       if ((d) > 0)                                                    \
14067 +               __acc_inc_atomic(&(m)->v);                              \
14068 +       else                                                            \
14069 +               __acc_dec_atomic(&(m)->v);                              \
14070 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14071 +} while (0)
14072 +
14073 +
14074 +#define vx_acc_pages(m, p, v, r) do {                                  \
14075 +       unsigned long __p = (p);                                        \
14076 +       __acc_add_long(__p, &(m)->v);                                   \
14077 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14078 +} while (0)
14079 +
14080 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14081 +       unsigned long __p = (p);                                        \
14082 +       __acc_add_atomic(__p, &(m)->v);                                 \
14083 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14084 +} while (0)
14085 +
14086 +
14087 +
14088 +#define vx_acc_vmpage(m, d) \
14089 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14090 +#define vx_acc_vmlpage(m, d) \
14091 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14092 +#define vx_acc_file_rsspage(m, d) \
14093 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14094 +#define vx_acc_anon_rsspage(m, d) \
14095 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14096 +
14097 +#define vx_acc_vmpages(m, p) \
14098 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14099 +#define vx_acc_vmlpages(m, p) \
14100 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14101 +#define vx_acc_file_rsspages(m, p) \
14102 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14103 +#define vx_acc_anon_rsspages(m, p) \
14104 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14105 +
14106 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14107 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14108 +
14109 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14110 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14111 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14112 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14113 +
14114 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14115 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14116 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14117 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14118 +
14119 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14120 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14121 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14122 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14123 +
14124 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14125 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14126 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14127 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14128 +
14129 +
14130 +#define vx_pages_avail(m, p, r) \
14131 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14132 +
14133 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14134 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14135 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14136 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14137 +
14138 +#define vx_rss_avail(m, p) \
14139 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14140 +
14141 +
14142 +enum {
14143 +       VXPT_UNKNOWN = 0,
14144 +       VXPT_ANON,
14145 +       VXPT_NONE,
14146 +       VXPT_FILE,
14147 +       VXPT_SWAP,
14148 +       VXPT_WRITE
14149 +};
14150 +
14151 +#if 0
14152 +#define        vx_page_fault(mm, vma, type, ret)
14153 +#else
14154 +
14155 +static inline
14156 +void __vx_page_fault(struct mm_struct *mm,
14157 +       struct vm_area_struct *vma, int type, int ret)
14158 +{
14159 +       struct vx_info *vxi = mm->mm_vx_info;
14160 +       int what;
14161 +/*
14162 +       static char *page_type[6] =
14163 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14164 +       static char *page_what[4] =
14165 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14166 +*/
14167 +
14168 +       if (!vxi)
14169 +               return;
14170 +
14171 +       what = (ret & 0x3);
14172 +
14173 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14174 +               type, what, ret, page_type[type], page_what[what]);
14175 +*/
14176 +       if (ret & VM_FAULT_WRITE)
14177 +               what |= 0x4;
14178 +       atomic_inc(&vxi->cacct.page[type][what]);
14179 +}
14180 +
14181 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14182 +#endif
14183 +
14184 +
14185 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14186 +
14187 +#else
14188 +#warning duplicate inclusion
14189 +#endif
14190 diff -NurpP --minimal linux-2.6.33/include/linux/vs_network.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_network.h
14191 --- linux-2.6.33/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
14192 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_network.h       2010-02-25 12:02:16.000000000 +0100
14193 @@ -0,0 +1,169 @@
14194 +#ifndef _NX_VS_NETWORK_H
14195 +#define _NX_VS_NETWORK_H
14196 +
14197 +#include "vserver/context.h"
14198 +#include "vserver/network.h"
14199 +#include "vserver/base.h"
14200 +#include "vserver/check.h"
14201 +#include "vserver/debug.h"
14202 +
14203 +#include <linux/sched.h>
14204 +
14205 +
14206 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14207 +
14208 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14209 +       const char *_file, int _line)
14210 +{
14211 +       if (!nxi)
14212 +               return NULL;
14213 +
14214 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14215 +               nxi, nxi ? nxi->nx_id : 0,
14216 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14217 +               _file, _line);
14218 +
14219 +       atomic_inc(&nxi->nx_usecnt);
14220 +       return nxi;
14221 +}
14222 +
14223 +
14224 +extern void free_nx_info(struct nx_info *);
14225 +
14226 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14227 +
14228 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14229 +{
14230 +       if (!nxi)
14231 +               return;
14232 +
14233 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14234 +               nxi, nxi ? nxi->nx_id : 0,
14235 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14236 +               _file, _line);
14237 +
14238 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14239 +               free_nx_info(nxi);
14240 +}
14241 +
14242 +
14243 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14244 +
14245 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14246 +               const char *_file, int _line)
14247 +{
14248 +       if (nxi) {
14249 +               vxlprintk(VXD_CBIT(nid, 3),
14250 +                       "init_nx_info(%p[#%d.%d])",
14251 +                       nxi, nxi ? nxi->nx_id : 0,
14252 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14253 +                       _file, _line);
14254 +
14255 +               atomic_inc(&nxi->nx_usecnt);
14256 +       }
14257 +       *nxp = nxi;
14258 +}
14259 +
14260 +
14261 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14262 +
14263 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14264 +       const char *_file, int _line)
14265 +{
14266 +       struct nx_info *nxo;
14267 +
14268 +       if (!nxi)
14269 +               return;
14270 +
14271 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14272 +               nxi, nxi ? nxi->nx_id : 0,
14273 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14274 +               _file, _line);
14275 +
14276 +       atomic_inc(&nxi->nx_usecnt);
14277 +       nxo = xchg(nxp, nxi);
14278 +       BUG_ON(nxo);
14279 +}
14280 +
14281 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14282 +
14283 +static inline void __clr_nx_info(struct nx_info **nxp,
14284 +       const char *_file, int _line)
14285 +{
14286 +       struct nx_info *nxo;
14287 +
14288 +       nxo = xchg(nxp, NULL);
14289 +       if (!nxo)
14290 +               return;
14291 +
14292 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14293 +               nxo, nxo ? nxo->nx_id : 0,
14294 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14295 +               _file, _line);
14296 +
14297 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14298 +               free_nx_info(nxo);
14299 +}
14300 +
14301 +
14302 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14303 +
14304 +static inline void __claim_nx_info(struct nx_info *nxi,
14305 +       struct task_struct *task, const char *_file, int _line)
14306 +{
14307 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14308 +               nxi, nxi ? nxi->nx_id : 0,
14309 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14310 +               nxi?atomic_read(&nxi->nx_tasks):0,
14311 +               task, _file, _line);
14312 +
14313 +       atomic_inc(&nxi->nx_tasks);
14314 +}
14315 +
14316 +
14317 +extern void unhash_nx_info(struct nx_info *);
14318 +
14319 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14320 +
14321 +static inline void __release_nx_info(struct nx_info *nxi,
14322 +       struct task_struct *task, const char *_file, int _line)
14323 +{
14324 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14325 +               nxi, nxi ? nxi->nx_id : 0,
14326 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14327 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14328 +               task, _file, _line);
14329 +
14330 +       might_sleep();
14331 +
14332 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14333 +               unhash_nx_info(nxi);
14334 +}
14335 +
14336 +
14337 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14338 +
14339 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14340 +       const char *_file, int _line)
14341 +{
14342 +       struct nx_info *nxi;
14343 +
14344 +       task_lock(p);
14345 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14346 +               p, _file, _line);
14347 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14348 +       task_unlock(p);
14349 +       return nxi;
14350 +}
14351 +
14352 +
14353 +static inline void exit_nx_info(struct task_struct *p)
14354 +{
14355 +       if (p->nx_info)
14356 +               release_nx_info(p->nx_info, p);
14357 +}
14358 +
14359 +
14360 +#else
14361 +#warning duplicate inclusion
14362 +#endif
14363 diff -NurpP --minimal linux-2.6.33/include/linux/vs_pid.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_pid.h
14364 --- linux-2.6.33/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
14365 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_pid.h   2010-02-25 12:02:16.000000000 +0100
14366 @@ -0,0 +1,95 @@
14367 +#ifndef _VS_PID_H
14368 +#define _VS_PID_H
14369 +
14370 +#include "vserver/base.h"
14371 +#include "vserver/check.h"
14372 +#include "vserver/context.h"
14373 +#include "vserver/debug.h"
14374 +#include "vserver/pid.h"
14375 +#include <linux/pid_namespace.h>
14376 +
14377 +
14378 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14379 +
14380 +static inline
14381 +int vx_proc_task_visible(struct task_struct *task)
14382 +{
14383 +       if ((task->pid == 1) &&
14384 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14385 +               /* show a blend through init */
14386 +               goto visible;
14387 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14388 +               goto visible;
14389 +       return 0;
14390 +visible:
14391 +       return 1;
14392 +}
14393 +
14394 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14395 +
14396 +#if 0
14397 +
14398 +static inline
14399 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14400 +{
14401 +       struct task_struct *task = find_task_by_real_pid(pid);
14402 +
14403 +       if (task && !vx_proc_task_visible(task)) {
14404 +               vxdprintk(VXD_CBIT(misc, 6),
14405 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14406 +                       task, task->xid, task->pid,
14407 +                       current, current->xid, current->pid);
14408 +               task = NULL;
14409 +       }
14410 +       return task;
14411 +}
14412 +
14413 +#endif
14414 +
14415 +static inline
14416 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14417 +{
14418 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14419 +
14420 +       if (task && !vx_proc_task_visible(task)) {
14421 +               vxdprintk(VXD_CBIT(misc, 6),
14422 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14423 +                       task, task->xid, task->pid,
14424 +                       current, current->xid, current->pid);
14425 +               put_task_struct(task);
14426 +               task = NULL;
14427 +       }
14428 +       return task;
14429 +}
14430 +
14431 +#if 0
14432 +
14433 +static inline
14434 +struct task_struct *vx_child_reaper(struct task_struct *p)
14435 +{
14436 +       struct vx_info *vxi = p->vx_info;
14437 +       struct task_struct *reaper = child_reaper(p);
14438 +
14439 +       if (!vxi)
14440 +               goto out;
14441 +
14442 +       BUG_ON(!p->vx_info->vx_reaper);
14443 +
14444 +       /* child reaper for the guest reaper */
14445 +       if (vxi->vx_reaper == p)
14446 +               goto out;
14447 +
14448 +       reaper = vxi->vx_reaper;
14449 +out:
14450 +       vxdprintk(VXD_CBIT(xid, 7),
14451 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14452 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14453 +       return reaper;
14454 +}
14455 +
14456 +#endif
14457 +
14458 +
14459 +#else
14460 +#warning duplicate inclusion
14461 +#endif
14462 diff -NurpP --minimal linux-2.6.33/include/linux/vs_sched.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_sched.h
14463 --- linux-2.6.33/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
14464 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_sched.h 2010-02-25 12:02:16.000000000 +0100
14465 @@ -0,0 +1,110 @@
14466 +#ifndef _VS_SCHED_H
14467 +#define _VS_SCHED_H
14468 +
14469 +#include "vserver/base.h"
14470 +#include "vserver/context.h"
14471 +#include "vserver/sched.h"
14472 +
14473 +
14474 +#define VAVAVOOM_RATIO          50
14475 +
14476 +#define MAX_PRIO_BIAS           20
14477 +#define MIN_PRIO_BIAS          -20
14478 +
14479 +
14480 +#ifdef CONFIG_VSERVER_HARDCPU
14481 +
14482 +/*
14483 + * effective_prio - return the priority that is based on the static
14484 + * priority but is modified by bonuses/penalties.
14485 + *
14486 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14487 + * into a -4 ... 0 ... +4 bonus/penalty range.
14488 + *
14489 + * Additionally, we scale another amount based on the number of
14490 + * CPU tokens currently held by the context, if the process is
14491 + * part of a context (and the appropriate SCHED flag is set).
14492 + * This ranges from -5 ... 0 ... +15, quadratically.
14493 + *
14494 + * So, the total bonus is -9 .. 0 .. +19
14495 + * We use ~50% of the full 0...39 priority range so that:
14496 + *
14497 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14498 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14499 + *    unless that context is far exceeding its CPU allocation.
14500 + *
14501 + * Both properties are important to certain workloads.
14502 + */
14503 +static inline
14504 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14505 +{
14506 +       int vavavoom, max;
14507 +
14508 +       /* lots of tokens = lots of vavavoom
14509 +        *      no tokens = no vavavoom      */
14510 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14511 +               max = sched_pc->tokens_max;
14512 +               vavavoom = max - vavavoom;
14513 +               max = max * max;
14514 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14515 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14516 +               return vavavoom;
14517 +       }
14518 +       return 0;
14519 +}
14520 +
14521 +
14522 +static inline
14523 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14524 +{
14525 +       struct vx_info *vxi = p->vx_info;
14526 +       struct _vx_sched_pc *sched_pc;
14527 +
14528 +       if (!vxi)
14529 +               return prio;
14530 +
14531 +       sched_pc = &vx_cpu(vxi, sched_pc);
14532 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14533 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14534 +
14535 +               sched_pc->vavavoom = vavavoom;
14536 +               prio += vavavoom;
14537 +       }
14538 +       prio += sched_pc->prio_bias;
14539 +       return prio;
14540 +}
14541 +
14542 +#else /* !CONFIG_VSERVER_HARDCPU */
14543 +
14544 +static inline
14545 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14546 +{
14547 +       struct vx_info *vxi = p->vx_info;
14548 +
14549 +       if (vxi)
14550 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14551 +       return prio;
14552 +}
14553 +
14554 +#endif /* CONFIG_VSERVER_HARDCPU */
14555 +
14556 +
14557 +static inline void vx_account_user(struct vx_info *vxi,
14558 +       cputime_t cputime, int nice)
14559 +{
14560 +       if (!vxi)
14561 +               return;
14562 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14563 +}
14564 +
14565 +static inline void vx_account_system(struct vx_info *vxi,
14566 +       cputime_t cputime, int idle)
14567 +{
14568 +       if (!vxi)
14569 +               return;
14570 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14571 +}
14572 +
14573 +#else
14574 +#warning duplicate inclusion
14575 +#endif
14576 diff -NurpP --minimal linux-2.6.33/include/linux/vs_socket.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_socket.h
14577 --- linux-2.6.33/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
14578 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_socket.h        2010-02-25 12:02:16.000000000 +0100
14579 @@ -0,0 +1,67 @@
14580 +#ifndef _VS_SOCKET_H
14581 +#define _VS_SOCKET_H
14582 +
14583 +#include "vserver/debug.h"
14584 +#include "vserver/base.h"
14585 +#include "vserver/cacct.h"
14586 +#include "vserver/context.h"
14587 +#include "vserver/tag.h"
14588 +
14589 +
14590 +/* socket accounting */
14591 +
14592 +#include <linux/socket.h>
14593 +
14594 +static inline int vx_sock_type(int family)
14595 +{
14596 +       switch (family) {
14597 +       case PF_UNSPEC:
14598 +               return VXA_SOCK_UNSPEC;
14599 +       case PF_UNIX:
14600 +               return VXA_SOCK_UNIX;
14601 +       case PF_INET:
14602 +               return VXA_SOCK_INET;
14603 +       case PF_INET6:
14604 +               return VXA_SOCK_INET6;
14605 +       case PF_PACKET:
14606 +               return VXA_SOCK_PACKET;
14607 +       default:
14608 +               return VXA_SOCK_OTHER;
14609 +       }
14610 +}
14611 +
14612 +#define vx_acc_sock(v, f, p, s) \
14613 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14614 +
14615 +static inline void __vx_acc_sock(struct vx_info *vxi,
14616 +       int family, int pos, int size, char *file, int line)
14617 +{
14618 +       if (vxi) {
14619 +               int type = vx_sock_type(family);
14620 +
14621 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14622 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14623 +       }
14624 +}
14625 +
14626 +#define vx_sock_recv(sk, s) \
14627 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14628 +#define vx_sock_send(sk, s) \
14629 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14630 +#define vx_sock_fail(sk, s) \
14631 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14632 +
14633 +
14634 +#define sock_vx_init(s) do {           \
14635 +       (s)->sk_xid = 0;                \
14636 +       (s)->sk_vx_info = NULL;         \
14637 +       } while (0)
14638 +
14639 +#define sock_nx_init(s) do {           \
14640 +       (s)->sk_nid = 0;                \
14641 +       (s)->sk_nx_info = NULL;         \
14642 +       } while (0)
14643 +
14644 +#else
14645 +#warning duplicate inclusion
14646 +#endif
14647 diff -NurpP --minimal linux-2.6.33/include/linux/vs_tag.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_tag.h
14648 --- linux-2.6.33/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
14649 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_tag.h   2010-02-25 12:02:16.000000000 +0100
14650 @@ -0,0 +1,47 @@
14651 +#ifndef _VS_TAG_H
14652 +#define _VS_TAG_H
14653 +
14654 +#include <linux/vserver/tag.h>
14655 +
14656 +/* check conditions */
14657 +
14658 +#define DX_ADMIN       0x0001
14659 +#define DX_WATCH       0x0002
14660 +#define DX_HOSTID      0x0008
14661 +
14662 +#define DX_IDENT       0x0010
14663 +
14664 +#define DX_ARG_MASK    0x0010
14665 +
14666 +
14667 +#define dx_task_tag(t) ((t)->tag)
14668 +
14669 +#define dx_current_tag() dx_task_tag(current)
14670 +
14671 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14672 +
14673 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14674 +
14675 +
14676 +/*
14677 + * check current context for ADMIN/WATCH and
14678 + * optionally against supplied argument
14679 + */
14680 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14681 +{
14682 +       if (mode & DX_ARG_MASK) {
14683 +               if ((mode & DX_IDENT) && (id == cid))
14684 +                       return 1;
14685 +       }
14686 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14687 +               ((mode & DX_WATCH) && (cid == 1)) ||
14688 +               ((mode & DX_HOSTID) && (id == 0)));
14689 +}
14690 +
14691 +struct inode;
14692 +int dx_permission(const struct inode *inode, int mask);
14693 +
14694 +
14695 +#else
14696 +#warning duplicate inclusion
14697 +#endif
14698 diff -NurpP --minimal linux-2.6.33/include/linux/vs_time.h linux-2.6.33-vs2.3.0.36.30/include/linux/vs_time.h
14699 --- linux-2.6.33/include/linux/vs_time.h        1970-01-01 01:00:00.000000000 +0100
14700 +++ linux-2.6.33-vs2.3.0.36.30/include/linux/vs_time.h  2010-02-25 12:02:16.000000000 +0100
14701 @@ -0,0 +1,19 @@
14702 +#ifndef _VS_TIME_H
14703 +#define _VS_TIME_H
14704 +
14705 +
14706 +/* time faking stuff */
14707 +
14708 +#ifdef CONFIG_VSERVER_VTIME
14709 +
14710 +extern void vx_gettimeofday(struct timeval *tv);
14711 +extern int vx_settimeofday(struct timespec *ts);
14712 +
14713 +#else
14714 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14715 +#define        vx_settimeofday(t)      do_settimeofday(t)
14716 +#endif
14717 +
14718 +#else
14719 +#warning duplicate inclusion
14720 +#endif
14721 diff -NurpP --minimal linux-2.6.33/include/net/addrconf.h linux-2.6.33-vs2.3.0.36.30/include/net/addrconf.h
14722 --- linux-2.6.33/include/net/addrconf.h 2009-12-03 20:02:57.000000000 +0100
14723 +++ linux-2.6.33-vs2.3.0.36.30/include/net/addrconf.h   2010-02-25 12:02:16.000000000 +0100
14724 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14725                                                struct net_device *dev,
14726                                                const struct in6_addr *daddr,
14727                                                unsigned int srcprefs,
14728 -                                              struct in6_addr *saddr);
14729 +                                              struct in6_addr *saddr,
14730 +                                              struct nx_info *nxi);
14731  extern int                     ipv6_get_lladdr(struct net_device *dev,
14732                                                 struct in6_addr *addr,
14733                                                 unsigned char banned_flags);
14734 diff -NurpP --minimal linux-2.6.33/include/net/af_unix.h linux-2.6.33-vs2.3.0.36.30/include/net/af_unix.h
14735 --- linux-2.6.33/include/net/af_unix.h  2008-12-25 00:26:37.000000000 +0100
14736 +++ linux-2.6.33-vs2.3.0.36.30/include/net/af_unix.h    2010-02-25 12:02:16.000000000 +0100
14737 @@ -4,6 +4,7 @@
14738  #include <linux/socket.h>
14739  #include <linux/un.h>
14740  #include <linux/mutex.h>
14741 +#include <linux/vs_base.h>
14742  #include <net/sock.h>
14743  
14744  extern void unix_inflight(struct file *fp);
14745 diff -NurpP --minimal linux-2.6.33/include/net/inet_timewait_sock.h linux-2.6.33-vs2.3.0.36.30/include/net/inet_timewait_sock.h
14746 --- linux-2.6.33/include/net/inet_timewait_sock.h       2010-02-25 11:52:08.000000000 +0100
14747 +++ linux-2.6.33-vs2.3.0.36.30/include/net/inet_timewait_sock.h 2010-02-25 12:02:16.000000000 +0100
14748 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14749  #define tw_hash                        __tw_common.skc_hash
14750  #define tw_prot                        __tw_common.skc_prot
14751  #define tw_net                 __tw_common.skc_net
14752 +#define tw_xid                 __tw_common.skc_xid
14753 +#define tw_vx_info             __tw_common.skc_vx_info
14754 +#define tw_nid                 __tw_common.skc_nid
14755 +#define tw_nx_info             __tw_common.skc_nx_info
14756         int                     tw_timeout;
14757         volatile unsigned char  tw_substate;
14758         /* 3 bits hole, try to pack */
14759 diff -NurpP --minimal linux-2.6.33/include/net/route.h linux-2.6.33-vs2.3.0.36.30/include/net/route.h
14760 --- linux-2.6.33/include/net/route.h    2010-02-25 11:52:08.000000000 +0100
14761 +++ linux-2.6.33-vs2.3.0.36.30/include/net/route.h      2010-02-25 12:02:16.000000000 +0100
14762 @@ -132,6 +132,9 @@ static inline void ip_rt_put(struct rtab
14763                 dst_release(&rt->u.dst);
14764  }
14765  
14766 +#include <linux/vs_base.h>
14767 +#include <linux/vs_inet.h>
14768 +
14769  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14770  
14771  extern const __u8 ip_tos2prio[16];
14772 @@ -141,6 +144,9 @@ static inline char rt_tos2priority(u8 to
14773         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14774  }
14775  
14776 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14777 +       struct rtable **, struct flowi *);
14778 +
14779  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14780                                    __be32 src, u32 tos, int oif, u8 protocol,
14781                                    __be16 sport, __be16 dport, struct sock *sk,
14782 @@ -158,11 +164,24 @@ static inline int ip_route_connect(struc
14783  
14784         int err;
14785         struct net *net = sock_net(sk);
14786 +       struct nx_info *nx_info = current_nx_info();
14787  
14788         if (inet_sk(sk)->transparent)
14789                 fl.flags |= FLOWI_FLAG_ANYSRC;
14790  
14791 -       if (!dst || !src) {
14792 +       if (sk)
14793 +               nx_info = sk->sk_nx_info;
14794 +
14795 +       vxdprintk(VXD_CBIT(net, 4),
14796 +               "ip_route_connect(%p) %p,%p;%lx",
14797 +               sk, nx_info, sk->sk_socket,
14798 +               (sk->sk_socket?sk->sk_socket->flags:0));
14799 +
14800 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14801 +       if (err)
14802 +               return err;
14803 +
14804 +       if (!fl.fl4_dst || !fl.fl4_src) {
14805                 err = __ip_route_output_key(net, rp, &fl);
14806                 if (err)
14807                         return err;
14808 diff -NurpP --minimal linux-2.6.33/include/net/sock.h linux-2.6.33-vs2.3.0.36.30/include/net/sock.h
14809 --- linux-2.6.33/include/net/sock.h     2010-02-25 11:52:08.000000000 +0100
14810 +++ linux-2.6.33-vs2.3.0.36.30/include/net/sock.h       2010-02-25 12:02:16.000000000 +0100
14811 @@ -149,6 +149,10 @@ struct sock_common {
14812  #ifdef CONFIG_NET_NS
14813         struct net              *skc_net;
14814  #endif
14815 +       xid_t                   skc_xid;
14816 +       struct vx_info          *skc_vx_info;
14817 +       nid_t                   skc_nid;
14818 +       struct nx_info          *skc_nx_info;
14819  };
14820  
14821  /**
14822 @@ -236,6 +240,10 @@ struct sock {
14823  #define sk_bind_node           __sk_common.skc_bind_node
14824  #define sk_prot                        __sk_common.skc_prot
14825  #define sk_net                 __sk_common.skc_net
14826 +#define sk_xid                 __sk_common.skc_xid
14827 +#define sk_vx_info             __sk_common.skc_vx_info
14828 +#define sk_nid                 __sk_common.skc_nid
14829 +#define sk_nx_info             __sk_common.skc_nx_info
14830         kmemcheck_bitfield_begin(flags);
14831         unsigned int            sk_shutdown  : 2,
14832                                 sk_no_check  : 2,
14833 diff -NurpP --minimal linux-2.6.33/init/Kconfig linux-2.6.33-vs2.3.0.36.30/init/Kconfig
14834 --- linux-2.6.33/init/Kconfig   2010-02-25 11:52:09.000000000 +0100
14835 +++ linux-2.6.33-vs2.3.0.36.30/init/Kconfig     2010-02-25 12:02:16.000000000 +0100
14836 @@ -496,6 +496,19 @@ config CGROUP_SCHED
14837  
14838  endchoice
14839  
14840 +config CFS_HARD_LIMITS
14841 +       bool "Hard Limits for CFS Group Scheduler"
14842 +       depends on EXPERIMENTAL
14843 +       depends on FAIR_GROUP_SCHED && CGROUP_SCHED
14844 +       default n
14845 +       help
14846 +         This option enables hard limiting of CPU time obtained by
14847 +         a fair task group. Use this if you want to throttle a group of tasks
14848 +         based on its CPU usage. For more details refer to
14849 +         Documentation/scheduler/sched-cfs-hard-limits.txt
14850 +
14851 +         Say N if unsure.
14852 +
14853  menuconfig CGROUPS
14854         boolean "Control Group support"
14855         help
14856 diff -NurpP --minimal linux-2.6.33/init/main.c linux-2.6.33-vs2.3.0.36.30/init/main.c
14857 --- linux-2.6.33/init/main.c    2010-02-25 11:52:09.000000000 +0100
14858 +++ linux-2.6.33-vs2.3.0.36.30/init/main.c      2010-02-25 12:02:16.000000000 +0100
14859 @@ -70,6 +70,7 @@
14860  #include <linux/sfi.h>
14861  #include <linux/shmem_fs.h>
14862  #include <trace/boot.h>
14863 +#include <linux/vserver/percpu.h>
14864  
14865  #include <asm/io.h>
14866  #include <asm/bugs.h>
14867 diff -NurpP --minimal linux-2.6.33/ipc/mqueue.c linux-2.6.33-vs2.3.0.36.30/ipc/mqueue.c
14868 --- linux-2.6.33/ipc/mqueue.c   2010-02-25 11:52:09.000000000 +0100
14869 +++ linux-2.6.33-vs2.3.0.36.30/ipc/mqueue.c     2010-02-25 12:21:21.000000000 +0100
14870 @@ -32,6 +32,8 @@
14871  #include <linux/nsproxy.h>
14872  #include <linux/pid.h>
14873  #include <linux/ipc_namespace.h>
14874 +#include <linux/vs_context.h>
14875 +#include <linux/vs_limit.h>
14876  
14877  #include <net/sock.h>
14878  #include "util.h"
14879 @@ -65,6 +67,7 @@ struct mqueue_inode_info {
14880         struct sigevent notify;
14881         struct pid* notify_owner;
14882         struct user_struct *user;       /* user who created, for accounting */
14883 +       struct vx_info *vxi;
14884         struct sock *notify_sock;
14885         struct sk_buff *notify_cookie;
14886  
14887 @@ -124,6 +127,7 @@ static struct inode *mqueue_get_inode(st
14888                 if (S_ISREG(mode)) {
14889                         struct mqueue_inode_info *info;
14890                         struct task_struct *p = current;
14891 +                       struct vx_info *vxi = p->vx_info;
14892                         unsigned long mq_bytes, mq_msg_tblsz;
14893  
14894                         inode->i_fop = &mqueue_file_operations;
14895 @@ -138,6 +142,7 @@ static struct inode *mqueue_get_inode(st
14896                         info->notify_owner = NULL;
14897                         info->qsize = 0;
14898                         info->user = NULL;      /* set when all is ok */
14899 +                       info->vxi = NULL;
14900                         memset(&info->attr, 0, sizeof(info->attr));
14901                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14902                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14903 @@ -152,22 +157,26 @@ static struct inode *mqueue_get_inode(st
14904                         spin_lock(&mq_lock);
14905                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14906                             u->mq_bytes + mq_bytes >
14907 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14908 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14909 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14910                                 spin_unlock(&mq_lock);
14911                                 goto out_inode;
14912                         }
14913                         u->mq_bytes += mq_bytes;
14914 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14915                         spin_unlock(&mq_lock);
14916  
14917                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14918                         if (!info->messages) {
14919                                 spin_lock(&mq_lock);
14920                                 u->mq_bytes -= mq_bytes;
14921 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14922                                 spin_unlock(&mq_lock);
14923                                 goto out_inode;
14924                         }
14925                         /* all is ok */
14926                         info->user = get_uid(u);
14927 +                       info->vxi = get_vx_info(vxi);
14928                 } else if (S_ISDIR(mode)) {
14929                         inc_nlink(inode);
14930                         /* Some things misbehave if size == 0 on a directory */
14931 @@ -268,8 +277,11 @@ static void mqueue_delete_inode(struct i
14932                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14933         user = info->user;
14934         if (user) {
14935 +               struct vx_info *vxi = info->vxi;
14936 +
14937                 spin_lock(&mq_lock);
14938                 user->mq_bytes -= mq_bytes;
14939 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14940                 /*
14941                  * get_ns_from_inode() ensures that the
14942                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14943 @@ -279,6 +291,7 @@ static void mqueue_delete_inode(struct i
14944                 if (ipc_ns)
14945                         ipc_ns->mq_queues_count--;
14946                 spin_unlock(&mq_lock);
14947 +               put_vx_info(vxi);
14948                 free_uid(user);
14949         }
14950         if (ipc_ns)
14951 diff -NurpP --minimal linux-2.6.33/ipc/msg.c linux-2.6.33-vs2.3.0.36.30/ipc/msg.c
14952 --- linux-2.6.33/ipc/msg.c      2010-02-25 11:52:09.000000000 +0100
14953 +++ linux-2.6.33-vs2.3.0.36.30/ipc/msg.c        2010-02-25 12:02:16.000000000 +0100
14954 @@ -38,6 +38,7 @@
14955  #include <linux/rwsem.h>
14956  #include <linux/nsproxy.h>
14957  #include <linux/ipc_namespace.h>
14958 +#include <linux/vs_base.h>
14959  
14960  #include <asm/current.h>
14961  #include <asm/uaccess.h>
14962 @@ -191,6 +192,7 @@ static int newque(struct ipc_namespace *
14963  
14964         msq->q_perm.mode = msgflg & S_IRWXUGO;
14965         msq->q_perm.key = key;
14966 +       msq->q_perm.xid = vx_current_xid();
14967  
14968         msq->q_perm.security = NULL;
14969         retval = security_msg_queue_alloc(msq);
14970 diff -NurpP --minimal linux-2.6.33/ipc/namespace.c linux-2.6.33-vs2.3.0.36.30/ipc/namespace.c
14971 --- linux-2.6.33/ipc/namespace.c        2009-09-10 15:26:27.000000000 +0200
14972 +++ linux-2.6.33-vs2.3.0.36.30/ipc/namespace.c  2010-02-25 12:02:16.000000000 +0100
14973 @@ -11,6 +11,8 @@
14974  #include <linux/slab.h>
14975  #include <linux/fs.h>
14976  #include <linux/mount.h>
14977 +#include <linux/vs_base.h>
14978 +#include <linux/vserver/global.h>
14979  
14980  #include "util.h"
14981  
14982 diff -NurpP --minimal linux-2.6.33/ipc/sem.c linux-2.6.33-vs2.3.0.36.30/ipc/sem.c
14983 --- linux-2.6.33/ipc/sem.c      2010-02-25 11:52:09.000000000 +0100
14984 +++ linux-2.6.33-vs2.3.0.36.30/ipc/sem.c        2010-02-25 12:02:16.000000000 +0100
14985 @@ -83,6 +83,8 @@
14986  #include <linux/rwsem.h>
14987  #include <linux/nsproxy.h>
14988  #include <linux/ipc_namespace.h>
14989 +#include <linux/vs_base.h>
14990 +#include <linux/vs_limit.h>
14991  
14992  #include <asm/uaccess.h>
14993  #include "util.h"
14994 @@ -257,6 +259,7 @@ static int newary(struct ipc_namespace *
14995  
14996         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14997         sma->sem_perm.key = key;
14998 +       sma->sem_perm.xid = vx_current_xid();
14999  
15000         sma->sem_perm.security = NULL;
15001         retval = security_sem_alloc(sma);
15002 @@ -272,6 +275,9 @@ static int newary(struct ipc_namespace *
15003                 return id;
15004         }
15005         ns->used_sems += nsems;
15006 +       /* FIXME: obsoleted? */
15007 +       vx_semary_inc(sma);
15008 +       vx_nsems_add(sma, nsems);
15009  
15010         sma->sem_base = (struct sem *) &sma[1];
15011  
15012 @@ -595,6 +601,9 @@ static void freeary(struct ipc_namespace
15013         sem_unlock(sma);
15014  
15015         ns->used_sems -= sma->sem_nsems;
15016 +       /* FIXME: obsoleted? */
15017 +       vx_nsems_sub(sma, sma->sem_nsems);
15018 +       vx_semary_dec(sma);
15019         security_sem_free(sma);
15020         ipc_rcu_putref(sma);
15021  }
15022 diff -NurpP --minimal linux-2.6.33/ipc/shm.c linux-2.6.33-vs2.3.0.36.30/ipc/shm.c
15023 --- linux-2.6.33/ipc/shm.c      2010-02-25 11:52:09.000000000 +0100
15024 +++ linux-2.6.33-vs2.3.0.36.30/ipc/shm.c        2010-02-25 12:23:04.000000000 +0100
15025 @@ -39,6 +39,8 @@
15026  #include <linux/nsproxy.h>
15027  #include <linux/mount.h>
15028  #include <linux/ipc_namespace.h>
15029 +#include <linux/vs_context.h>
15030 +#include <linux/vs_limit.h>
15031  
15032  #include <asm/uaccess.h>
15033  
15034 @@ -169,7 +171,12 @@ static void shm_open(struct vm_area_stru
15035   */
15036  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15037  {
15038 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15039 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15040 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15041 +
15042 +       vx_ipcshm_sub(vxi, shp, numpages);
15043 +       ns->shm_tot -= numpages;
15044 +
15045         shm_rmid(ns, shp);
15046         shm_unlock(shp);
15047         if (!is_file_hugepages(shp->shm_file))
15048 @@ -179,6 +186,7 @@ static void shm_destroy(struct ipc_names
15049                                                 shp->mlock_user);
15050         fput (shp->shm_file);
15051         security_shm_free(shp);
15052 +       put_vx_info(vxi);
15053         ipc_rcu_putref(shp);
15054  }
15055  
15056 @@ -352,11 +360,15 @@ static int newseg(struct ipc_namespace *
15057         if (ns->shm_tot + numpages > ns->shm_ctlall)
15058                 return -ENOSPC;
15059  
15060 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
15061 +               return -ENOSPC;
15062 +
15063         shp = ipc_rcu_alloc(sizeof(*shp));
15064         if (!shp)
15065                 return -ENOMEM;
15066  
15067         shp->shm_perm.key = key;
15068 +       shp->shm_perm.xid = vx_current_xid();
15069         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15070         shp->mlock_user = NULL;
15071  
15072 @@ -410,6 +422,7 @@ static int newseg(struct ipc_namespace *
15073         ns->shm_tot += numpages;
15074         error = shp->shm_perm.id;
15075         shm_unlock(shp);
15076 +       vx_ipcshm_add(current_vx_info(), key, numpages);
15077         return error;
15078  
15079  no_id:
15080 diff -NurpP --minimal linux-2.6.33/kernel/capability.c linux-2.6.33-vs2.3.0.36.30/kernel/capability.c
15081 --- linux-2.6.33/kernel/capability.c    2010-02-25 11:52:09.000000000 +0100
15082 +++ linux-2.6.33-vs2.3.0.36.30/kernel/capability.c      2010-02-25 12:02:16.000000000 +0100
15083 @@ -14,6 +14,7 @@
15084  #include <linux/security.h>
15085  #include <linux/syscalls.h>
15086  #include <linux/pid_namespace.h>
15087 +#include <linux/vs_context.h>
15088  #include <asm/uaccess.h>
15089  #include "cred-internals.h"
15090  
15091 @@ -120,6 +121,7 @@ static int cap_validate_magic(cap_user_h
15092         return 0;
15093  }
15094  
15095 +
15096  /*
15097   * The only thing that can change the capabilities of the current
15098   * process is the current process. As such, we can't be in this code
15099 @@ -290,6 +292,8 @@ error:
15100         return ret;
15101  }
15102  
15103 +#include <linux/vserver/base.h>
15104 +
15105  /**
15106   * capable - Determine if the current task has a superior capability in effect
15107   * @cap: The capability to be tested for
15108 @@ -302,6 +306,9 @@ error:
15109   */
15110  int capable(int cap)
15111  {
15112 +       /* here for now so we don't require task locking */
15113 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15114 +               return 0;
15115         if (unlikely(!cap_valid(cap))) {
15116                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15117                 BUG();
15118 diff -NurpP --minimal linux-2.6.33/kernel/compat.c linux-2.6.33-vs2.3.0.36.30/kernel/compat.c
15119 --- linux-2.6.33/kernel/compat.c        2009-09-10 15:26:27.000000000 +0200
15120 +++ linux-2.6.33-vs2.3.0.36.30/kernel/compat.c  2010-02-25 12:02:16.000000000 +0100
15121 @@ -902,7 +902,7 @@ asmlinkage long compat_sys_time(compat_t
15122         compat_time_t i;
15123         struct timeval tv;
15124  
15125 -       do_gettimeofday(&tv);
15126 +       vx_gettimeofday(&tv);
15127         i = tv.tv_sec;
15128  
15129         if (tloc) {
15130 @@ -927,7 +927,7 @@ asmlinkage long compat_sys_stime(compat_
15131         if (err)
15132                 return err;
15133  
15134 -       do_settimeofday(&tv);
15135 +       vx_settimeofday(&tv);
15136         return 0;
15137  }
15138  
15139 diff -NurpP --minimal linux-2.6.33/kernel/exit.c linux-2.6.33-vs2.3.0.36.30/kernel/exit.c
15140 --- linux-2.6.33/kernel/exit.c  2010-02-25 11:52:09.000000000 +0100
15141 +++ linux-2.6.33-vs2.3.0.36.30/kernel/exit.c    2010-02-25 12:02:16.000000000 +0100
15142 @@ -48,6 +48,10 @@
15143  #include <linux/fs_struct.h>
15144  #include <linux/init_task.h>
15145  #include <linux/perf_event.h>
15146 +#include <linux/vs_limit.h>
15147 +#include <linux/vs_context.h>
15148 +#include <linux/vs_network.h>
15149 +#include <linux/vs_pid.h>
15150  #include <trace/events/sched.h>
15151  #include <linux/hw_breakpoint.h>
15152  
15153 @@ -489,9 +493,11 @@ static void close_files(struct files_str
15154                                         filp_close(file, files);
15155                                         cond_resched();
15156                                 }
15157 +                               vx_openfd_dec(i);
15158                         }
15159                         i++;
15160                         set >>= 1;
15161 +                       cond_resched();
15162                 }
15163         }
15164  }
15165 @@ -1019,11 +1025,16 @@ NORET_TYPE void do_exit(long code)
15166  
15167         validate_creds_for_do_exit(tsk);
15168  
15169 +       /* needs to stay after exit_notify() */
15170 +       exit_vx_info(tsk, code);
15171 +       exit_nx_info(tsk);
15172 +
15173         preempt_disable();
15174         exit_rcu();
15175         /* causes final put_task_struct in finish_task_switch(). */
15176         tsk->state = TASK_DEAD;
15177         schedule();
15178 +       printk("bad task: %p [%lx]\n", current, current->state);
15179         BUG();
15180         /* Avoid "noreturn function does return".  */
15181         for (;;)
15182 diff -NurpP --minimal linux-2.6.33/kernel/fork.c linux-2.6.33-vs2.3.0.36.30/kernel/fork.c
15183 --- linux-2.6.33/kernel/fork.c  2010-02-25 11:52:09.000000000 +0100
15184 +++ linux-2.6.33-vs2.3.0.36.30/kernel/fork.c    2010-02-25 12:23:31.000000000 +0100
15185 @@ -65,6 +65,10 @@
15186  #include <linux/perf_event.h>
15187  #include <linux/posix-timers.h>
15188  #include <linux/user-return-notifier.h>
15189 +#include <linux/vs_context.h>
15190 +#include <linux/vs_network.h>
15191 +#include <linux/vs_limit.h>
15192 +#include <linux/vs_memory.h>
15193  
15194  #include <asm/pgtable.h>
15195  #include <asm/pgalloc.h>
15196 @@ -152,6 +156,8 @@ void free_task(struct task_struct *tsk)
15197         account_kernel_stack(tsk->stack, -1);
15198         free_thread_info(tsk->stack);
15199         rt_mutex_debug_task_free(tsk);
15200 +       clr_vx_info(&tsk->vx_info);
15201 +       clr_nx_info(&tsk->nx_info);
15202         ftrace_graph_exit_task(tsk);
15203         free_task_struct(tsk);
15204  }
15205 @@ -298,6 +304,8 @@ static int dup_mmap(struct mm_struct *mm
15206         mm->free_area_cache = oldmm->mmap_base;
15207         mm->cached_hole_size = ~0UL;
15208         mm->map_count = 0;
15209 +       __set_mm_counter(mm, file_rss, 0);
15210 +       __set_mm_counter(mm, anon_rss, 0);
15211         cpumask_clear(mm_cpumask(mm));
15212         mm->mm_rb = RB_ROOT;
15213         rb_link = &mm->mm_rb.rb_node;
15214 @@ -312,7 +320,7 @@ static int dup_mmap(struct mm_struct *mm
15215  
15216                 if (mpnt->vm_flags & VM_DONTCOPY) {
15217                         long pages = vma_pages(mpnt);
15218 -                       mm->total_vm -= pages;
15219 +                       vx_vmpages_sub(mm, pages);
15220                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15221                                                                 -pages);
15222                         continue;
15223 @@ -454,8 +462,8 @@ static struct mm_struct * mm_init(struct
15224                 (current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
15225         mm->core_state = NULL;
15226         mm->nr_ptes = 0;
15227 -       set_mm_counter(mm, file_rss, 0);
15228 -       set_mm_counter(mm, anon_rss, 0);
15229 +       __set_mm_counter(mm, file_rss, 0);
15230 +       __set_mm_counter(mm, anon_rss, 0);
15231         spin_lock_init(&mm->page_table_lock);
15232         mm->free_area_cache = TASK_UNMAPPED_BASE;
15233         mm->cached_hole_size = ~0UL;
15234 @@ -465,6 +473,7 @@ static struct mm_struct * mm_init(struct
15235         if (likely(!mm_alloc_pgd(mm))) {
15236                 mm->def_flags = 0;
15237                 mmu_notifier_mm_init(mm);
15238 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15239                 return mm;
15240         }
15241  
15242 @@ -498,6 +507,7 @@ void __mmdrop(struct mm_struct *mm)
15243         mm_free_pgd(mm);
15244         destroy_context(mm);
15245         mmu_notifier_mm_destroy(mm);
15246 +       clr_vx_info(&mm->mm_vx_info);
15247         free_mm(mm);
15248  }
15249  EXPORT_SYMBOL_GPL(__mmdrop);
15250 @@ -633,6 +643,7 @@ struct mm_struct *dup_mm(struct task_str
15251                 goto fail_nomem;
15252  
15253         memcpy(mm, oldmm, sizeof(*mm));
15254 +       mm->mm_vx_info = NULL;
15255  
15256         /* Initializing for Swap token stuff */
15257         mm->token_priority = 0;
15258 @@ -671,6 +682,7 @@ fail_nocontext:
15259          * If init_new_context() failed, we cannot use mmput() to free the mm
15260          * because it calls destroy_context()
15261          */
15262 +       clr_vx_info(&mm->mm_vx_info);
15263         mm_free_pgd(mm);
15264         free_mm(mm);
15265         return NULL;
15266 @@ -985,6 +997,8 @@ static struct task_struct *copy_process(
15267         int retval;
15268         struct task_struct *p;
15269         int cgroup_callbacks_done = 0;
15270 +       struct vx_info *vxi;
15271 +       struct nx_info *nxi;
15272  
15273         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15274                 return ERR_PTR(-EINVAL);
15275 @@ -1031,12 +1045,28 @@ static struct task_struct *copy_process(
15276         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15277         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15278  #endif
15279 +       init_vx_info(&p->vx_info, current_vx_info());
15280 +       init_nx_info(&p->nx_info, current_nx_info());
15281 +
15282 +       /* check vserver memory */
15283 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15284 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15285 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15286 +               else
15287 +                       goto bad_fork_free;
15288 +       }
15289 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15290 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15291 +                       goto bad_fork_cleanup_vm;
15292 +       }
15293         retval = -EAGAIN;
15294 +       if (!vx_nproc_avail(1))
15295 +               goto bad_fork_cleanup_vm;
15296         if (atomic_read(&p->real_cred->user->processes) >=
15297                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15298                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15299                     p->real_cred->user != INIT_USER)
15300 -                       goto bad_fork_free;
15301 +                       goto bad_fork_cleanup_vm;
15302         }
15303  
15304         retval = copy_creds(p, clone_flags);
15305 @@ -1297,6 +1327,18 @@ static struct task_struct *copy_process(
15306  
15307         total_forks++;
15308         spin_unlock(&current->sighand->siglock);
15309 +
15310 +       /* p is copy of current */
15311 +       vxi = p->vx_info;
15312 +       if (vxi) {
15313 +               claim_vx_info(vxi, p);
15314 +               atomic_inc(&vxi->cvirt.nr_threads);
15315 +               atomic_inc(&vxi->cvirt.total_forks);
15316 +               vx_nproc_inc(p);
15317 +       }
15318 +       nxi = p->nx_info;
15319 +       if (nxi)
15320 +               claim_nx_info(nxi, p);
15321         write_unlock_irq(&tasklist_lock);
15322         proc_fork_connector(p);
15323         cgroup_post_fork(p);
15324 @@ -1339,6 +1381,9 @@ bad_fork_cleanup_cgroup:
15325  bad_fork_cleanup_count:
15326         atomic_dec(&p->cred->user->processes);
15327         exit_creds(p);
15328 +bad_fork_cleanup_vm:
15329 +       if (p->mm && !(clone_flags & CLONE_VM))
15330 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15331  bad_fork_free:
15332         free_task(p);
15333  fork_out:
15334 diff -NurpP --minimal linux-2.6.33/kernel/kthread.c linux-2.6.33-vs2.3.0.36.30/kernel/kthread.c
15335 --- linux-2.6.33/kernel/kthread.c       2010-02-25 11:52:09.000000000 +0100
15336 +++ linux-2.6.33-vs2.3.0.36.30/kernel/kthread.c 2010-02-25 12:02:16.000000000 +0100
15337 @@ -14,6 +14,7 @@
15338  #include <linux/file.h>
15339  #include <linux/module.h>
15340  #include <linux/mutex.h>
15341 +#include <linux/vs_pid.h>
15342  #include <trace/events/sched.h>
15343  
15344  static DEFINE_SPINLOCK(kthread_create_lock);
15345 diff -NurpP --minimal linux-2.6.33/kernel/Makefile linux-2.6.33-vs2.3.0.36.30/kernel/Makefile
15346 --- linux-2.6.33/kernel/Makefile        2010-02-25 11:52:09.000000000 +0100
15347 +++ linux-2.6.33-vs2.3.0.36.30/kernel/Makefile  2010-02-25 12:02:16.000000000 +0100
15348 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
15349  CFLAGS_REMOVE_perf_event.o = -pg
15350  endif
15351  
15352 +obj-y += vserver/
15353  obj-$(CONFIG_FREEZER) += freezer.o
15354  obj-$(CONFIG_PROFILING) += profile.o
15355  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15356 diff -NurpP --minimal linux-2.6.33/kernel/nsproxy.c linux-2.6.33-vs2.3.0.36.30/kernel/nsproxy.c
15357 --- linux-2.6.33/kernel/nsproxy.c       2009-09-10 15:26:28.000000000 +0200
15358 +++ linux-2.6.33-vs2.3.0.36.30/kernel/nsproxy.c 2010-02-25 12:02:16.000000000 +0100
15359 @@ -19,6 +19,8 @@
15360  #include <linux/mnt_namespace.h>
15361  #include <linux/utsname.h>
15362  #include <linux/pid_namespace.h>
15363 +#include <linux/vserver/global.h>
15364 +#include <linux/vserver/debug.h>
15365  #include <net/net_namespace.h>
15366  #include <linux/ipc_namespace.h>
15367  
15368 @@ -31,8 +33,11 @@ static inline struct nsproxy *create_nsp
15369         struct nsproxy *nsproxy;
15370  
15371         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15372 -       if (nsproxy)
15373 +       if (nsproxy) {
15374                 atomic_set(&nsproxy->count, 1);
15375 +               atomic_inc(&vs_global_nsproxy);
15376 +       }
15377 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15378         return nsproxy;
15379  }
15380  
15381 @@ -41,41 +46,52 @@ static inline struct nsproxy *create_nsp
15382   * Return the newly created nsproxy.  Do not attach this to the task,
15383   * leave it to the caller to do proper locking and attach it to task.
15384   */
15385 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15386 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15387 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15388 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15389  {
15390         struct nsproxy *new_nsp;
15391         int err;
15392  
15393 +       vxdprintk(VXD_CBIT(space, 4),
15394 +               "unshare_namespaces(0x%08lx,%p,%p)",
15395 +               flags, orig, new_fs);
15396 +
15397         new_nsp = create_nsproxy();
15398         if (!new_nsp)
15399                 return ERR_PTR(-ENOMEM);
15400  
15401 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15402 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15403         if (IS_ERR(new_nsp->mnt_ns)) {
15404                 err = PTR_ERR(new_nsp->mnt_ns);
15405                 goto out_ns;
15406         }
15407  
15408 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15409 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15410         if (IS_ERR(new_nsp->uts_ns)) {
15411                 err = PTR_ERR(new_nsp->uts_ns);
15412                 goto out_uts;
15413         }
15414  
15415 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15416 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15417         if (IS_ERR(new_nsp->ipc_ns)) {
15418                 err = PTR_ERR(new_nsp->ipc_ns);
15419                 goto out_ipc;
15420         }
15421  
15422 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15423 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15424         if (IS_ERR(new_nsp->pid_ns)) {
15425                 err = PTR_ERR(new_nsp->pid_ns);
15426                 goto out_pid;
15427         }
15428  
15429 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15430 +       /* disabled now?
15431 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15432 +       if (IS_ERR(new_nsp->user_ns)) {
15433 +               err = PTR_ERR(new_nsp->user_ns);
15434 +               goto out_user;
15435 +       } */
15436 +
15437 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15438         if (IS_ERR(new_nsp->net_ns)) {
15439                 err = PTR_ERR(new_nsp->net_ns);
15440                 goto out_net;
15441 @@ -100,6 +116,38 @@ out_ns:
15442         return ERR_PTR(err);
15443  }
15444  
15445 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15446 +                       struct fs_struct *new_fs)
15447 +{
15448 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15449 +}
15450 +
15451 +/*
15452 + * copies the nsproxy, setting refcount to 1, and grabbing a
15453 + * reference to all contained namespaces.
15454 + */
15455 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15456 +{
15457 +       struct nsproxy *ns = create_nsproxy();
15458 +
15459 +       if (ns) {
15460 +               memcpy(ns, orig, sizeof(struct nsproxy));
15461 +               atomic_set(&ns->count, 1);
15462 +
15463 +               if (ns->mnt_ns)
15464 +                       get_mnt_ns(ns->mnt_ns);
15465 +               if (ns->uts_ns)
15466 +                       get_uts_ns(ns->uts_ns);
15467 +               if (ns->ipc_ns)
15468 +                       get_ipc_ns(ns->ipc_ns);
15469 +               if (ns->pid_ns)
15470 +                       get_pid_ns(ns->pid_ns);
15471 +               if (ns->net_ns)
15472 +                       get_net(ns->net_ns);
15473 +       }
15474 +       return ns;
15475 +}
15476 +
15477  /*
15478   * called from clone.  This now handles copy for nsproxy and all
15479   * namespaces therein.
15480 @@ -107,9 +155,12 @@ out_ns:
15481  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15482  {
15483         struct nsproxy *old_ns = tsk->nsproxy;
15484 -       struct nsproxy *new_ns;
15485 +       struct nsproxy *new_ns = NULL;
15486         int err = 0;
15487  
15488 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15489 +               flags, tsk, old_ns);
15490 +
15491         if (!old_ns)
15492                 return 0;
15493  
15494 @@ -119,7 +170,7 @@ int copy_namespaces(unsigned long flags,
15495                                 CLONE_NEWPID | CLONE_NEWNET)))
15496                 return 0;
15497  
15498 -       if (!capable(CAP_SYS_ADMIN)) {
15499 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15500                 err = -EPERM;
15501                 goto out;
15502         }
15503 @@ -146,6 +197,9 @@ int copy_namespaces(unsigned long flags,
15504  
15505  out:
15506         put_nsproxy(old_ns);
15507 +       vxdprintk(VXD_CBIT(space, 3),
15508 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15509 +               flags, tsk, old_ns, err, new_ns);
15510         return err;
15511  }
15512  
15513 @@ -159,7 +213,9 @@ void free_nsproxy(struct nsproxy *ns)
15514                 put_ipc_ns(ns->ipc_ns);
15515         if (ns->pid_ns)
15516                 put_pid_ns(ns->pid_ns);
15517 -       put_net(ns->net_ns);
15518 +       if (ns->net_ns)
15519 +               put_net(ns->net_ns);
15520 +       atomic_dec(&vs_global_nsproxy);
15521         kmem_cache_free(nsproxy_cachep, ns);
15522  }
15523  
15524 @@ -172,11 +228,15 @@ int unshare_nsproxy_namespaces(unsigned 
15525  {
15526         int err = 0;
15527  
15528 +       vxdprintk(VXD_CBIT(space, 4),
15529 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15530 +               unshare_flags, current->nsproxy);
15531 +
15532         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15533                                CLONE_NEWNET)))
15534                 return 0;
15535  
15536 -       if (!capable(CAP_SYS_ADMIN))
15537 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15538                 return -EPERM;
15539  
15540         *new_nsp = create_new_namespaces(unshare_flags, current,
15541 diff -NurpP --minimal linux-2.6.33/kernel/pid.c linux-2.6.33-vs2.3.0.36.30/kernel/pid.c
15542 --- linux-2.6.33/kernel/pid.c   2010-02-25 11:52:09.000000000 +0100
15543 +++ linux-2.6.33-vs2.3.0.36.30/kernel/pid.c     2010-02-25 12:02:16.000000000 +0100
15544 @@ -36,6 +36,7 @@
15545  #include <linux/pid_namespace.h>
15546  #include <linux/init_task.h>
15547  #include <linux/syscalls.h>
15548 +#include <linux/vs_pid.h>
15549  
15550  #define pid_hashfn(nr, ns)     \
15551         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15552 @@ -305,7 +306,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15553  
15554  struct pid *find_vpid(int nr)
15555  {
15556 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15557 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15558  }
15559  EXPORT_SYMBOL_GPL(find_vpid);
15560  
15561 @@ -365,6 +366,9 @@ void transfer_pid(struct task_struct *ol
15562  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15563  {
15564         struct task_struct *result = NULL;
15565 +
15566 +       if (type == PIDTYPE_REALPID)
15567 +               type = PIDTYPE_PID;
15568         if (pid) {
15569                 struct hlist_node *first;
15570                 first = rcu_dereference(pid->tasks[type].first);
15571 @@ -380,7 +384,7 @@ EXPORT_SYMBOL(pid_task);
15572   */
15573  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15574  {
15575 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15576 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15577  }
15578  
15579  struct task_struct *find_task_by_vpid(pid_t vnr)
15580 @@ -422,7 +426,7 @@ struct pid *find_get_pid(pid_t nr)
15581  }
15582  EXPORT_SYMBOL_GPL(find_get_pid);
15583  
15584 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15585 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15586  {
15587         struct upid *upid;
15588         pid_t nr = 0;
15589 @@ -435,6 +439,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15590         return nr;
15591  }
15592  
15593 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15594 +{
15595 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15596 +}
15597 +
15598  pid_t pid_vnr(struct pid *pid)
15599  {
15600         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15601 diff -NurpP --minimal linux-2.6.33/kernel/pid_namespace.c linux-2.6.33-vs2.3.0.36.30/kernel/pid_namespace.c
15602 --- linux-2.6.33/kernel/pid_namespace.c 2009-12-03 20:02:58.000000000 +0100
15603 +++ linux-2.6.33-vs2.3.0.36.30/kernel/pid_namespace.c   2010-02-25 12:02:16.000000000 +0100
15604 @@ -13,6 +13,7 @@
15605  #include <linux/syscalls.h>
15606  #include <linux/err.h>
15607  #include <linux/acct.h>
15608 +#include <linux/vserver/global.h>
15609  
15610  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15611  
15612 @@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_
15613                 goto out_free_map;
15614  
15615         kref_init(&ns->kref);
15616 +       atomic_inc(&vs_global_pid_ns);
15617         ns->level = level;
15618         ns->parent = get_pid_ns(parent_pid_ns);
15619  
15620 @@ -111,6 +113,7 @@ static void destroy_pid_namespace(struct
15621  
15622         for (i = 0; i < PIDMAP_ENTRIES; i++)
15623                 kfree(ns->pidmap[i].page);
15624 +       atomic_dec(&vs_global_pid_ns);
15625         kmem_cache_free(pid_ns_cachep, ns);
15626  }
15627  
15628 diff -NurpP --minimal linux-2.6.33/kernel/posix-timers.c linux-2.6.33-vs2.3.0.36.30/kernel/posix-timers.c
15629 --- linux-2.6.33/kernel/posix-timers.c  2009-12-03 20:02:58.000000000 +0100
15630 +++ linux-2.6.33-vs2.3.0.36.30/kernel/posix-timers.c    2010-02-25 12:02:16.000000000 +0100
15631 @@ -46,6 +46,7 @@
15632  #include <linux/wait.h>
15633  #include <linux/workqueue.h>
15634  #include <linux/module.h>
15635 +#include <linux/vs_context.h>
15636  
15637  /*
15638   * Management arrays for POSIX timers.  Timers are kept in slab memory
15639 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15640  {
15641         struct task_struct *task;
15642         int shared, ret = -1;
15643 +
15644         /*
15645          * FIXME: if ->sigq is queued we can race with
15646          * dequeue_signal()->do_schedule_next_timer().
15647 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15648         rcu_read_lock();
15649         task = pid_task(timr->it_pid, PIDTYPE_PID);
15650         if (task) {
15651 +               struct vx_info_save vxis;
15652 +               struct vx_info *vxi;
15653 +
15654 +               vxi = get_vx_info(task->vx_info);
15655 +               enter_vx_info(vxi, &vxis);
15656                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15657                 ret = send_sigqueue(timr->sigq, task, shared);
15658 +               leave_vx_info(&vxis);
15659 +               put_vx_info(vxi);
15660         }
15661         rcu_read_unlock();
15662 +
15663         /* If we failed to send the signal the timer stops. */
15664         return ret > 0;
15665  }
15666 diff -NurpP --minimal linux-2.6.33/kernel/printk.c linux-2.6.33-vs2.3.0.36.30/kernel/printk.c
15667 --- linux-2.6.33/kernel/printk.c        2010-02-25 11:52:09.000000000 +0100
15668 +++ linux-2.6.33-vs2.3.0.36.30/kernel/printk.c  2010-02-25 13:11:15.000000000 +0100
15669 @@ -35,6 +35,7 @@
15670  #include <linux/kexec.h>
15671  #include <linux/ratelimit.h>
15672  #include <linux/kmsg_dump.h>
15673 +#include <linux/vs_cvirt.h>
15674  
15675  #include <asm/uaccess.h>
15676  
15677 @@ -278,18 +279,13 @@ int do_syslog(int type, char __user *buf
15678         unsigned i, j, limit, count;
15679         int do_clear = 0;
15680         char c;
15681 -       int error = 0;
15682 +       int error;
15683  
15684         error = security_syslog(type);
15685         if (error)
15686                 return error;
15687  
15688 -       switch (type) {
15689 -       case 0:         /* Close log */
15690 -               break;
15691 -       case 1:         /* Open log */
15692 -               break;
15693 -       case 2:         /* Read from log */
15694 +       if ((type >= 2) && (type <= 4)) {
15695                 error = -EINVAL;
15696                 if (!buf || len < 0)
15697                         goto out;
15698 @@ -300,6 +296,16 @@ int do_syslog(int type, char __user *buf
15699                         error = -EFAULT;
15700                         goto out;
15701                 }
15702 +       }
15703 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15704 +               return vx_do_syslog(type, buf, len);
15705 +
15706 +       switch (type) {
15707 +       case 0:         /* Close log */
15708 +               break;
15709 +       case 1:         /* Open log */
15710 +               break;
15711 +       case 2:         /* Read from log */
15712                 error = wait_event_interruptible(log_wait,
15713                                                         (log_start - log_end));
15714                 if (error)
15715 @@ -324,16 +330,6 @@ int do_syslog(int type, char __user *buf
15716                 do_clear = 1;
15717                 /* FALL THRU */
15718         case 3:         /* Read last kernel messages */
15719 -               error = -EINVAL;
15720 -               if (!buf || len < 0)
15721 -                       goto out;
15722 -               error = 0;
15723 -               if (!len)
15724 -                       goto out;
15725 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15726 -                       error = -EFAULT;
15727 -                       goto out;
15728 -               }
15729                 count = len;
15730                 if (count > log_buf_len)
15731                         count = log_buf_len;
15732 diff -NurpP --minimal linux-2.6.33/kernel/ptrace.c linux-2.6.33-vs2.3.0.36.30/kernel/ptrace.c
15733 --- linux-2.6.33/kernel/ptrace.c        2009-12-03 20:02:58.000000000 +0100
15734 +++ linux-2.6.33-vs2.3.0.36.30/kernel/ptrace.c  2010-02-25 12:02:16.000000000 +0100
15735 @@ -22,6 +22,7 @@
15736  #include <linux/pid_namespace.h>
15737  #include <linux/syscalls.h>
15738  #include <linux/uaccess.h>
15739 +#include <linux/vs_context.h>
15740  
15741  
15742  /*
15743 @@ -151,6 +152,11 @@ int __ptrace_may_access(struct task_stru
15744                 dumpable = get_dumpable(task->mm);
15745         if (!dumpable && !capable(CAP_SYS_PTRACE))
15746                 return -EPERM;
15747 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15748 +               return -EPERM;
15749 +       if (!vx_check(task->xid, VS_IDENT) &&
15750 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15751 +               return -EACCES;
15752  
15753         return security_ptrace_access_check(task, mode);
15754  }
15755 @@ -621,6 +627,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15756                 goto out;
15757         }
15758  
15759 +       ret = -EPERM;
15760 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15761 +               goto out_put_task_struct;
15762 +
15763         if (request == PTRACE_ATTACH) {
15764                 ret = ptrace_attach(child);
15765                 /*
15766 diff -NurpP --minimal linux-2.6.33/kernel/sched.c linux-2.6.33-vs2.3.0.36.30/kernel/sched.c
15767 --- linux-2.6.33/kernel/sched.c 2010-02-25 11:52:09.000000000 +0100
15768 +++ linux-2.6.33-vs2.3.0.36.30/kernel/sched.c   2010-02-25 14:42:44.000000000 +0100
15769 @@ -71,6 +71,8 @@
15770  #include <linux/debugfs.h>
15771  #include <linux/ctype.h>
15772  #include <linux/ftrace.h>
15773 +#include <linux/vs_sched.h>
15774 +#include <linux/vs_cvirt.h>
15775  
15776  #include <asm/tlb.h>
15777  #include <asm/irq_regs.h>
15778 @@ -3009,9 +3011,17 @@ EXPORT_SYMBOL(avenrun);
15779   */
15780  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15781  {
15782 -       loads[0] = (avenrun[0] + offset) << shift;
15783 -       loads[1] = (avenrun[1] + offset) << shift;
15784 -       loads[2] = (avenrun[2] + offset) << shift;
15785 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15786 +               struct vx_info *vxi = current_vx_info();
15787 +
15788 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15789 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15790 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15791 +       } else {
15792 +               loads[0] = (avenrun[0] + offset) << shift;
15793 +               loads[1] = (avenrun[1] + offset) << shift;
15794 +               loads[2] = (avenrun[2] + offset) << shift;
15795 +       }
15796  }
15797  
15798  static unsigned long
15799 @@ -5046,16 +5056,19 @@ void account_user_time(struct task_struc
15800                        cputime_t cputime_scaled)
15801  {
15802         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15803 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15804         cputime64_t tmp;
15805 +       int nice = (TASK_NICE(p) > 0);
15806  
15807         /* Add user time to process. */
15808         p->utime = cputime_add(p->utime, cputime);
15809         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15810 +       vx_account_user(vxi, cputime, nice);
15811         account_group_user_time(p, cputime);
15812  
15813         /* Add user time to cpustat. */
15814         tmp = cputime_to_cputime64(cputime);
15815 -       if (TASK_NICE(p) > 0)
15816 +       if (nice)
15817                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15818         else
15819                 cpustat->user = cputime64_add(cpustat->user, tmp);
15820 @@ -5106,6 +5119,7 @@ void account_system_time(struct task_str
15821                          cputime_t cputime, cputime_t cputime_scaled)
15822  {
15823         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15824 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15825         cputime64_t tmp;
15826  
15827         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15828 @@ -5116,6 +5130,7 @@ void account_system_time(struct task_str
15829         /* Add system time to process. */
15830         p->stime = cputime_add(p->stime, cputime);
15831         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15832 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15833         account_group_system_time(p, cputime);
15834  
15835         /* Add system time to cpustat. */
15836 @@ -6180,7 +6195,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15837                 nice = 19;
15838  
15839         if (increment < 0 && !can_nice(current, nice))
15840 -               return -EPERM;
15841 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15842  
15843         retval = security_task_setnice(current, nice);
15844         if (retval)
15845 diff -NurpP --minimal linux-2.6.33/kernel/sched_debug.c linux-2.6.33-vs2.3.0.36.30/kernel/sched_debug.c
15846 --- linux-2.6.33/kernel/sched_debug.c   2010-02-25 11:52:09.000000000 +0100
15847 +++ linux-2.6.33-vs2.3.0.36.30/kernel/sched_debug.c     2010-02-25 12:02:16.000000000 +0100
15848 @@ -80,6 +80,11 @@ static void print_cfs_group_stats(struct
15849         PN(se->wait_max);
15850         PN(se->wait_sum);
15851         P(se->wait_count);
15852 +#ifdef CONFIG_CFS_HARD_LIMITS
15853 +       PN(se->throttle_max);
15854 +       PN(se->throttle_sum);
15855 +       P(se->throttle_count);
15856 +#endif
15857  #endif
15858         P(se->load.weight);
15859  #undef PN
15860 @@ -214,6 +219,16 @@ void print_cfs_rq(struct seq_file *m, in
15861  #ifdef CONFIG_SMP
15862         SEQ_printf(m, "  .%-30s: %lu\n", "shares", cfs_rq->shares);
15863  #endif
15864 +#ifdef CONFIG_CFS_HARD_LIMITS
15865 +       spin_lock_irqsave(&rq->lock, flags);
15866 +       SEQ_printf(m, "  .%-30s: %d\n", "cfs_throttled",
15867 +                       cfs_rq->cfs_throttled);
15868 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_time",
15869 +                       SPLIT_NS(cfs_rq->cfs_time));
15870 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_runtime",
15871 +                       SPLIT_NS(cfs_rq->cfs_runtime));
15872 +       spin_unlock_irqrestore(&rq->lock, flags);
15873 +#endif /* CONFIG_CFS_HARD_LIMITS */
15874         print_cfs_group_stats(m, cpu, cfs_rq->tg);
15875  #endif
15876  }
15877 @@ -320,7 +335,7 @@ static int sched_debug_show(struct seq_f
15878         u64 now = ktime_to_ns(ktime_get());
15879         int cpu;
15880  
15881 -       SEQ_printf(m, "Sched Debug Version: v0.09, %s %.*s\n",
15882 +       SEQ_printf(m, "Sched Debug Version: v0.10, %s %.*s\n",
15883                 init_utsname()->release,
15884                 (int)strcspn(init_utsname()->version, " "),
15885                 init_utsname()->version);
15886 diff -NurpP --minimal linux-2.6.33/kernel/sched_fair.c linux-2.6.33-vs2.3.0.36.30/kernel/sched_fair.c
15887 --- linux-2.6.33/kernel/sched_fair.c    2010-02-25 11:52:09.000000000 +0100
15888 +++ linux-2.6.33-vs2.3.0.36.30/kernel/sched_fair.c      2010-02-25 14:42:58.000000000 +0100
15889 @@ -794,6 +794,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15890         check_spread(cfs_rq, se);
15891         if (se != cfs_rq->curr)
15892                 __enqueue_entity(cfs_rq, se);
15893 +
15894 +       if (entity_is_task(se))
15895 +               vx_activate_task(task_of(se));
15896  }
15897  
15898  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
15899 @@ -837,6 +840,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15900  
15901         if (se != cfs_rq->curr)
15902                 __dequeue_entity(cfs_rq, se);
15903 +       if (entity_is_task(se))
15904 +               vx_deactivate_task(task_of(se));
15905         account_entity_dequeue(cfs_rq, se);
15906         update_min_vruntime(cfs_rq);
15907  
15908 diff -NurpP --minimal linux-2.6.33/kernel/signal.c linux-2.6.33-vs2.3.0.36.30/kernel/signal.c
15909 --- linux-2.6.33/kernel/signal.c        2010-02-25 11:52:09.000000000 +0100
15910 +++ linux-2.6.33-vs2.3.0.36.30/kernel/signal.c  2010-02-25 13:10:38.000000000 +0100
15911 @@ -28,6 +28,8 @@
15912  #include <linux/freezer.h>
15913  #include <linux/pid_namespace.h>
15914  #include <linux/nsproxy.h>
15915 +#include <linux/vs_context.h>
15916 +#include <linux/vs_pid.h>
15917  #define CREATE_TRACE_POINTS
15918  #include <trace/events/signal.h>
15919  
15920 @@ -629,9 +631,18 @@ static int check_kill_permission(int sig
15921         struct pid *sid;
15922         int error;
15923  
15924 +       vxdprintk(VXD_CBIT(misc, 7),
15925 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15926 +               sig, info, t, vx_task_xid(t), t->pid);
15927 +
15928         if (!valid_signal(sig))
15929                 return -EINVAL;
15930  
15931 +/*     FIXME: needed? if so, why?
15932 +       if ((info != SEND_SIG_NOINFO) &&
15933 +               (is_si_special(info) || !si_fromuser(info)))
15934 +               goto skip;      */
15935 +
15936         if (!si_fromuser(info))
15937                 return 0;
15938  
15939 @@ -659,6 +670,20 @@ static int check_kill_permission(int sig
15940                 }
15941         }
15942  
15943 +       error = -EPERM;
15944 +       if (t->pid == 1 && current->xid)
15945 +               return error;
15946 +
15947 +       error = -ESRCH;
15948 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15949 +                 loops, maybe ENOENT or EACCES? */
15950 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15951 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15952 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15953 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15954 +               return error;
15955 +       }
15956 +skip:
15957         return security_task_kill(t, info, sig, 0);
15958  }
15959  
15960 @@ -1147,7 +1172,7 @@ int kill_pid_info(int sig, struct siginf
15961         rcu_read_lock();
15962  retry:
15963         p = pid_task(pid, PIDTYPE_PID);
15964 -       if (p) {
15965 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15966                 error = group_send_sig_info(sig, info, p);
15967                 if (unlikely(error == -ESRCH))
15968                         /*
15969 @@ -1187,7 +1212,7 @@ int kill_pid_info_as_uid(int sig, struct
15970  
15971         rcu_read_lock();
15972         p = pid_task(pid, PIDTYPE_PID);
15973 -       if (!p) {
15974 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15975                 ret = -ESRCH;
15976                 goto out_unlock;
15977         }
15978 @@ -1242,8 +1267,10 @@ static int kill_something_info(int sig, 
15979                 struct task_struct * p;
15980  
15981                 for_each_process(p) {
15982 -                       if (task_pid_vnr(p) > 1 &&
15983 -                                       !same_thread_group(p, current)) {
15984 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15985 +                               task_pid_vnr(p) > 1 &&
15986 +                               !same_thread_group(p, current) &&
15987 +                               !vx_current_initpid(p->pid)) {
15988                                 int err = group_send_sig_info(sig, info, p);
15989                                 ++count;
15990                                 if (err != -EPERM)
15991 @@ -1910,6 +1937,11 @@ relock:
15992                                 !sig_kernel_only(signr))
15993                         continue;
15994  
15995 +               /* virtual init is protected against user signals */
15996 +               if ((info->si_code == SI_USER) &&
15997 +                       vx_current_initpid(current->pid))
15998 +                       continue;
15999 +
16000                 if (sig_kernel_stop(signr)) {
16001                         /*
16002                          * The default action is to stop all threads in
16003 diff -NurpP --minimal linux-2.6.33/kernel/softirq.c linux-2.6.33-vs2.3.0.36.30/kernel/softirq.c
16004 --- linux-2.6.33/kernel/softirq.c       2010-02-25 11:52:09.000000000 +0100
16005 +++ linux-2.6.33-vs2.3.0.36.30/kernel/softirq.c 2010-02-25 12:02:16.000000000 +0100
16006 @@ -24,6 +24,7 @@
16007  #include <linux/ftrace.h>
16008  #include <linux/smp.h>
16009  #include <linux/tick.h>
16010 +#include <linux/vs_context.h>
16011  
16012  #define CREATE_TRACE_POINTS
16013  #include <trace/events/irq.h>
16014 diff -NurpP --minimal linux-2.6.33/kernel/sys.c linux-2.6.33-vs2.3.0.36.30/kernel/sys.c
16015 --- linux-2.6.33/kernel/sys.c   2010-02-25 11:52:09.000000000 +0100
16016 +++ linux-2.6.33-vs2.3.0.36.30/kernel/sys.c     2010-02-25 13:13:03.000000000 +0100
16017 @@ -40,6 +40,7 @@
16018  #include <linux/syscalls.h>
16019  #include <linux/kprobes.h>
16020  #include <linux/user_namespace.h>
16021 +#include <linux/vs_pid.h>
16022  
16023  #include <asm/uaccess.h>
16024  #include <asm/io.h>
16025 @@ -129,7 +130,10 @@ static int set_one_prio(struct task_stru
16026                 goto out;
16027         }
16028         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
16029 -               error = -EACCES;
16030 +               if (vx_flags(VXF_IGNEG_NICE, 0))
16031 +                       error = 0;
16032 +               else
16033 +                       error = -EACCES;
16034                 goto out;
16035         }
16036         no_nice = security_task_setnice(p, niceval);
16037 @@ -179,6 +183,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
16038                         else
16039                                 pgrp = task_pgrp(current);
16040                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16041 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16042 +                                       continue;
16043                                 error = set_one_prio(p, niceval, error);
16044                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
16045                         break;
16046 @@ -242,6 +248,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
16047                         else
16048                                 pgrp = task_pgrp(current);
16049                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16050 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16051 +                                       continue;
16052                                 niceval = 20 - task_nice(p);
16053                                 if (niceval > retval)
16054                                         retval = niceval;
16055 @@ -355,6 +363,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
16056  
16057  static DEFINE_MUTEX(reboot_mutex);
16058  
16059 +long vs_reboot(unsigned int, void __user *);
16060 +
16061  /*
16062   * Reboot system call: for obvious reasons only root may call it,
16063   * and even root needs to set up some magic numbers in the registers
16064 @@ -387,6 +397,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
16065         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
16066                 cmd = LINUX_REBOOT_CMD_HALT;
16067  
16068 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16069 +               return vs_reboot(cmd, arg);
16070 +
16071         mutex_lock(&reboot_mutex);
16072         switch (cmd) {
16073         case LINUX_REBOOT_CMD_RESTART:
16074 @@ -1136,7 +1149,7 @@ SYSCALL_DEFINE2(sethostname, char __user
16075         int errno;
16076         char tmp[__NEW_UTS_LEN];
16077  
16078 -       if (!capable(CAP_SYS_ADMIN))
16079 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16080                 return -EPERM;
16081         if (len < 0 || len > __NEW_UTS_LEN)
16082                 return -EINVAL;
16083 @@ -1185,7 +1198,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
16084         int errno;
16085         char tmp[__NEW_UTS_LEN];
16086  
16087 -       if (!capable(CAP_SYS_ADMIN))
16088 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16089                 return -EPERM;
16090         if (len < 0 || len > __NEW_UTS_LEN)
16091                 return -EINVAL;
16092 @@ -1254,7 +1267,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
16093                 return -EINVAL;
16094         old_rlim = current->signal->rlim + resource;
16095         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
16096 -           !capable(CAP_SYS_RESOURCE))
16097 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
16098                 return -EPERM;
16099         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
16100                 return -EPERM;
16101 diff -NurpP --minimal linux-2.6.33/kernel/sysctl_binary.c linux-2.6.33-vs2.3.0.36.30/kernel/sysctl_binary.c
16102 --- linux-2.6.33/kernel/sysctl_binary.c 2010-02-25 11:52:09.000000000 +0100
16103 +++ linux-2.6.33-vs2.3.0.36.30/kernel/sysctl_binary.c   2010-02-25 12:40:06.000000000 +0100
16104 @@ -71,6 +71,7 @@ static const struct bin_table bin_kern_t
16105  
16106         { CTL_INT,      KERN_PANIC,                     "panic" },
16107         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
16108 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
16109  
16110         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
16111         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
16112 diff -NurpP --minimal linux-2.6.33/kernel/sysctl.c linux-2.6.33-vs2.3.0.36.30/kernel/sysctl.c
16113 --- linux-2.6.33/kernel/sysctl.c        2010-02-25 11:52:09.000000000 +0100
16114 +++ linux-2.6.33-vs2.3.0.36.30/kernel/sysctl.c  2010-02-25 14:43:48.000000000 +0100
16115 @@ -123,6 +123,7 @@ static int ngroups_max = NGROUPS_MAX;
16116  extern char modprobe_path[];
16117  extern int modules_disabled;
16118  #endif
16119 +extern char vshelper_path[];
16120  #ifdef CONFIG_CHR_DEV_SG
16121  extern int sg_big_buff;
16122  #endif
16123 @@ -553,6 +554,13 @@ static struct ctl_table kern_table[] = {
16124                 .proc_handler   = proc_dostring,
16125         },
16126  #endif
16127 +       {
16128 +               .procname       = "vshelper",
16129 +               .data           = &vshelper_path,
16130 +               .maxlen         = 256,
16131 +               .mode           = 0644,
16132 +               .proc_handler   = &proc_dostring,
16133 +       },
16134  #ifdef CONFIG_CHR_DEV_SG
16135         {
16136                 .procname       = "sg-big-buff",
16137 diff -NurpP --minimal linux-2.6.33/kernel/time.c linux-2.6.33-vs2.3.0.36.30/kernel/time.c
16138 --- linux-2.6.33/kernel/time.c  2010-02-25 11:52:09.000000000 +0100
16139 +++ linux-2.6.33-vs2.3.0.36.30/kernel/time.c    2010-02-25 12:02:16.000000000 +0100
16140 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
16141  SYSCALL_DEFINE1(time, time_t __user *, tloc)
16142  {
16143         time_t i = get_seconds();
16144 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
16145  
16146         if (tloc) {
16147                 if (put_user(i,tloc))
16148 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
16149         if (err)
16150                 return err;
16151  
16152 -       do_settimeofday(&tv);
16153 +       vx_settimeofday(&tv);
16154         return 0;
16155  }
16156  
16157 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
16158  {
16159         if (likely(tv != NULL)) {
16160                 struct timeval ktv;
16161 -               do_gettimeofday(&ktv);
16162 +               vx_gettimeofday(&ktv);
16163                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
16164                         return -EFAULT;
16165         }
16166 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
16167                 /* SMP safe, again the code in arch/foo/time.c should
16168                  * globally block out interrupts when it runs.
16169                  */
16170 -               return do_settimeofday(tv);
16171 +               return vx_settimeofday(tv);
16172         }
16173         return 0;
16174  }
16175 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
16176  {
16177         struct timeval x;
16178  
16179 -       do_gettimeofday(&x);
16180 +       vx_gettimeofday(&x);
16181         tv->tv_sec = x.tv_sec;
16182         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
16183  }
16184 diff -NurpP --minimal linux-2.6.33/kernel/timer.c linux-2.6.33-vs2.3.0.36.30/kernel/timer.c
16185 --- linux-2.6.33/kernel/timer.c 2010-02-25 11:52:09.000000000 +0100
16186 +++ linux-2.6.33-vs2.3.0.36.30/kernel/timer.c   2010-02-25 12:02:16.000000000 +0100
16187 @@ -39,6 +39,10 @@
16188  #include <linux/kallsyms.h>
16189  #include <linux/perf_event.h>
16190  #include <linux/sched.h>
16191 +#include <linux/vs_base.h>
16192 +#include <linux/vs_cvirt.h>
16193 +#include <linux/vs_pid.h>
16194 +#include <linux/vserver/sched.h>
16195  
16196  #include <asm/uaccess.h>
16197  #include <asm/unistd.h>
16198 @@ -1252,12 +1256,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
16199  
16200  #endif
16201  
16202 -#ifndef __alpha__
16203 -
16204 -/*
16205 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
16206 - * should be moved into arch/i386 instead?
16207 - */
16208  
16209  /**
16210   * sys_getpid - return the thread group id of the current process
16211 @@ -1286,10 +1284,23 @@ SYSCALL_DEFINE0(getppid)
16212         rcu_read_lock();
16213         pid = task_tgid_vnr(current->real_parent);
16214         rcu_read_unlock();
16215 +       return vx_map_pid(pid);
16216 +}
16217  
16218 -       return pid;
16219 +#ifdef __alpha__
16220 +
16221 +/*
16222 + * The Alpha uses getxpid, getxuid, and getxgid instead.
16223 + */
16224 +
16225 +asmlinkage long do_getxpid(long *ppid)
16226 +{
16227 +       *ppid = sys_getppid();
16228 +       return sys_getpid();
16229  }
16230  
16231 +#else /* _alpha_ */
16232 +
16233  SYSCALL_DEFINE0(getuid)
16234  {
16235         /* Only we change this so SMP safe */
16236 diff -NurpP --minimal linux-2.6.33/kernel/user.c linux-2.6.33-vs2.3.0.36.30/kernel/user.c
16237 --- linux-2.6.33/kernel/user.c  2009-12-03 20:02:58.000000000 +0100
16238 +++ linux-2.6.33-vs2.3.0.36.30/kernel/user.c    2010-02-25 12:02:16.000000000 +0100
16239 @@ -251,10 +251,10 @@ static struct kobj_type uids_ktype = {
16240   *
16241   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
16242   */
16243 -static int uids_user_create(struct user_struct *up)
16244 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
16245  {
16246         struct kobject *kobj = &up->kobj;
16247 -       int error;
16248 +       int error = 0;
16249  
16250         memset(kobj, 0, sizeof(struct kobject));
16251         if (up->user_ns != &init_user_ns)
16252 @@ -282,7 +282,7 @@ int __init uids_sysfs_init(void)
16253         if (!uids_kset)
16254                 return -ENOMEM;
16255  
16256 -       return uids_user_create(&root_user);
16257 +       return uids_user_create(NULL, &root_user);
16258  }
16259  
16260  /* delayed work function to remove sysfs directory for a user and free up
16261 @@ -353,7 +353,8 @@ static struct user_struct *uid_hash_find
16262  }
16263  
16264  int uids_sysfs_init(void) { return 0; }
16265 -static inline int uids_user_create(struct user_struct *up) { return 0; }
16266 +static inline int uids_user_create(struct user_namespace *ns,
16267 +       struct user_struct *up) { return 0; }
16268  static inline void uids_mutex_lock(void) { }
16269  static inline void uids_mutex_unlock(void) { }
16270  
16271 @@ -450,7 +451,7 @@ struct user_struct *alloc_uid(struct use
16272  
16273                 new->user_ns = get_user_ns(ns);
16274  
16275 -               if (uids_user_create(new))
16276 +               if (uids_user_create(ns, new))
16277                         goto out_destoy_sched;
16278  
16279                 /*
16280 diff -NurpP --minimal linux-2.6.33/kernel/user_namespace.c linux-2.6.33-vs2.3.0.36.30/kernel/user_namespace.c
16281 --- linux-2.6.33/kernel/user_namespace.c        2009-03-24 14:22:45.000000000 +0100
16282 +++ linux-2.6.33-vs2.3.0.36.30/kernel/user_namespace.c  2010-02-25 12:02:16.000000000 +0100
16283 @@ -10,6 +10,7 @@
16284  #include <linux/slab.h>
16285  #include <linux/user_namespace.h>
16286  #include <linux/cred.h>
16287 +#include <linux/vserver/global.h>
16288  
16289  /*
16290   * Create a new user namespace, deriving the creator from the user in the
16291 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
16292                 return -ENOMEM;
16293  
16294         kref_init(&ns->kref);
16295 +       atomic_inc(&vs_global_user_ns);
16296  
16297         for (n = 0; n < UIDHASH_SZ; ++n)
16298                 INIT_HLIST_HEAD(ns->uidhash_table + n);
16299 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
16300         struct user_namespace *ns =
16301                 container_of(kref, struct user_namespace, kref);
16302  
16303 +       /* FIXME: maybe move into destroyer? */
16304 +       atomic_dec(&vs_global_user_ns);
16305         INIT_WORK(&ns->destroyer, free_user_ns_work);
16306         schedule_work(&ns->destroyer);
16307  }
16308 diff -NurpP --minimal linux-2.6.33/kernel/utsname.c linux-2.6.33-vs2.3.0.36.30/kernel/utsname.c
16309 --- linux-2.6.33/kernel/utsname.c       2009-09-10 15:26:28.000000000 +0200
16310 +++ linux-2.6.33-vs2.3.0.36.30/kernel/utsname.c 2010-02-25 12:02:16.000000000 +0100
16311 @@ -14,14 +14,17 @@
16312  #include <linux/utsname.h>
16313  #include <linux/err.h>
16314  #include <linux/slab.h>
16315 +#include <linux/vserver/global.h>
16316  
16317  static struct uts_namespace *create_uts_ns(void)
16318  {
16319         struct uts_namespace *uts_ns;
16320  
16321         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
16322 -       if (uts_ns)
16323 +       if (uts_ns) {
16324                 kref_init(&uts_ns->kref);
16325 +               atomic_inc(&vs_global_uts_ns);
16326 +       }
16327         return uts_ns;
16328  }
16329  
16330 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
16331         struct uts_namespace *ns;
16332  
16333         ns = container_of(kref, struct uts_namespace, kref);
16334 +       atomic_dec(&vs_global_uts_ns);
16335         kfree(ns);
16336  }
16337 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cacct.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cacct.c
16338 --- linux-2.6.33/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
16339 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cacct.c   2010-02-25 12:02:16.000000000 +0100
16340 @@ -0,0 +1,42 @@
16341 +/*
16342 + *  linux/kernel/vserver/cacct.c
16343 + *
16344 + *  Virtual Server: Context Accounting
16345 + *
16346 + *  Copyright (C) 2006-2007 Herbert Pötzl
16347 + *
16348 + *  V0.01  added accounting stats
16349 + *
16350 + */
16351 +
16352 +#include <linux/types.h>
16353 +#include <linux/vs_context.h>
16354 +#include <linux/vserver/cacct_cmd.h>
16355 +#include <linux/vserver/cacct_int.h>
16356 +
16357 +#include <asm/errno.h>
16358 +#include <asm/uaccess.h>
16359 +
16360 +
16361 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16362 +{
16363 +       struct vcmd_sock_stat_v0 vc_data;
16364 +       int j, field;
16365 +
16366 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16367 +               return -EFAULT;
16368 +
16369 +       field = vc_data.field;
16370 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16371 +               return -EINVAL;
16372 +
16373 +       for (j = 0; j < 3; j++) {
16374 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16375 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16376 +       }
16377 +
16378 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16379 +               return -EFAULT;
16380 +       return 0;
16381 +}
16382 +
16383 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cacct_init.h linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cacct_init.h
16384 --- linux-2.6.33/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
16385 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cacct_init.h      2010-02-25 12:02:16.000000000 +0100
16386 @@ -0,0 +1,25 @@
16387 +
16388 +
16389 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16390 +{
16391 +       int i, j;
16392 +
16393 +
16394 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16395 +               for (j = 0; j < 3; j++) {
16396 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16397 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16398 +               }
16399 +       }
16400 +       for (i = 0; i < 8; i++)
16401 +               atomic_set(&cacct->slab[i], 0);
16402 +       for (i = 0; i < 5; i++)
16403 +               for (j = 0; j < 4; j++)
16404 +                       atomic_set(&cacct->page[i][j], 0);
16405 +}
16406 +
16407 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16408 +{
16409 +       return;
16410 +}
16411 +
16412 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cacct_proc.h linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cacct_proc.h
16413 --- linux-2.6.33/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
16414 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cacct_proc.h      2010-02-25 12:02:16.000000000 +0100
16415 @@ -0,0 +1,53 @@
16416 +#ifndef _VX_CACCT_PROC_H
16417 +#define _VX_CACCT_PROC_H
16418 +
16419 +#include <linux/vserver/cacct_int.h>
16420 +
16421 +
16422 +#define VX_SOCKA_TOP   \
16423 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16424 +
16425 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16426 +{
16427 +       int i, j, length = 0;
16428 +       static char *type[VXA_SOCK_SIZE] = {
16429 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16430 +       };
16431 +
16432 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16433 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16434 +               length += sprintf(buffer + length, "%s:", type[i]);
16435 +               for (j = 0; j < 3; j++) {
16436 +                       length += sprintf(buffer + length,
16437 +                               "\t%10lu/%-10lu",
16438 +                               vx_sock_count(cacct, i, j),
16439 +                               vx_sock_total(cacct, i, j));
16440 +               }
16441 +               buffer[length++] = '\n';
16442 +       }
16443 +
16444 +       length += sprintf(buffer + length, "\n");
16445 +       length += sprintf(buffer + length,
16446 +               "slab:\t %8u %8u %8u %8u\n",
16447 +               atomic_read(&cacct->slab[1]),
16448 +               atomic_read(&cacct->slab[4]),
16449 +               atomic_read(&cacct->slab[0]),
16450 +               atomic_read(&cacct->slab[2]));
16451 +
16452 +       length += sprintf(buffer + length, "\n");
16453 +       for (i = 0; i < 5; i++) {
16454 +               length += sprintf(buffer + length,
16455 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16456 +                       atomic_read(&cacct->page[i][0]),
16457 +                       atomic_read(&cacct->page[i][1]),
16458 +                       atomic_read(&cacct->page[i][2]),
16459 +                       atomic_read(&cacct->page[i][3]),
16460 +                       atomic_read(&cacct->page[i][4]),
16461 +                       atomic_read(&cacct->page[i][5]),
16462 +                       atomic_read(&cacct->page[i][6]),
16463 +                       atomic_read(&cacct->page[i][7]));
16464 +       }
16465 +       return length;
16466 +}
16467 +
16468 +#endif /* _VX_CACCT_PROC_H */
16469 diff -NurpP --minimal linux-2.6.33/kernel/vserver/context.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/context.c
16470 --- linux-2.6.33/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
16471 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/context.c 2010-02-25 12:02:16.000000000 +0100
16472 @@ -0,0 +1,1057 @@
16473 +/*
16474 + *  linux/kernel/vserver/context.c
16475 + *
16476 + *  Virtual Server: Context Support
16477 + *
16478 + *  Copyright (C) 2003-2007  Herbert Pötzl
16479 + *
16480 + *  V0.01  context helper
16481 + *  V0.02  vx_ctx_kill syscall command
16482 + *  V0.03  replaced context_info calls
16483 + *  V0.04  redesign of struct (de)alloc
16484 + *  V0.05  rlimit basic implementation
16485 + *  V0.06  task_xid and info commands
16486 + *  V0.07  context flags and caps
16487 + *  V0.08  switch to RCU based hash
16488 + *  V0.09  revert to non RCU for now
16489 + *  V0.10  and back to working RCU hash
16490 + *  V0.11  and back to locking again
16491 + *  V0.12  referenced context store
16492 + *  V0.13  separate per cpu data
16493 + *  V0.14  changed vcmds to vxi arg
16494 + *  V0.15  added context stat
16495 + *  V0.16  have __create claim() the vxi
16496 + *  V0.17  removed older and legacy stuff
16497 + *
16498 + */
16499 +
16500 +#include <linux/slab.h>
16501 +#include <linux/types.h>
16502 +#include <linux/security.h>
16503 +#include <linux/pid_namespace.h>
16504 +
16505 +#include <linux/vserver/context.h>
16506 +#include <linux/vserver/network.h>
16507 +#include <linux/vserver/debug.h>
16508 +#include <linux/vserver/limit.h>
16509 +#include <linux/vserver/limit_int.h>
16510 +#include <linux/vserver/space.h>
16511 +#include <linux/init_task.h>
16512 +#include <linux/fs_struct.h>
16513 +
16514 +#include <linux/vs_context.h>
16515 +#include <linux/vs_limit.h>
16516 +#include <linux/vs_pid.h>
16517 +#include <linux/vserver/context_cmd.h>
16518 +
16519 +#include "cvirt_init.h"
16520 +#include "cacct_init.h"
16521 +#include "limit_init.h"
16522 +#include "sched_init.h"
16523 +
16524 +
16525 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16526 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16527 +
16528 +
16529 +/*     now inactive context structures */
16530 +
16531 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16532 +
16533 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
16534 +
16535 +
16536 +/*     __alloc_vx_info()
16537 +
16538 +       * allocate an initialized vx_info struct
16539 +       * doesn't make it visible (hash)                        */
16540 +
16541 +static struct vx_info *__alloc_vx_info(xid_t xid)
16542 +{
16543 +       struct vx_info *new = NULL;
16544 +       int cpu, index;
16545 +
16546 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16547 +
16548 +       /* would this benefit from a slab cache? */
16549 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16550 +       if (!new)
16551 +               return 0;
16552 +
16553 +       memset(new, 0, sizeof(struct vx_info));
16554 +#ifdef CONFIG_SMP
16555 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16556 +       if (!new->ptr_pc)
16557 +               goto error;
16558 +#endif
16559 +       new->vx_id = xid;
16560 +       INIT_HLIST_NODE(&new->vx_hlist);
16561 +       atomic_set(&new->vx_usecnt, 0);
16562 +       atomic_set(&new->vx_tasks, 0);
16563 +       new->vx_parent = NULL;
16564 +       new->vx_state = 0;
16565 +       init_waitqueue_head(&new->vx_wait);
16566 +
16567 +       /* prepare reaper */
16568 +       get_task_struct(init_pid_ns.child_reaper);
16569 +       new->vx_reaper = init_pid_ns.child_reaper;
16570 +       new->vx_badness_bias = 0;
16571 +
16572 +       /* rest of init goes here */
16573 +       vx_info_init_limit(&new->limit);
16574 +       vx_info_init_sched(&new->sched);
16575 +       vx_info_init_cvirt(&new->cvirt);
16576 +       vx_info_init_cacct(&new->cacct);
16577 +
16578 +       /* per cpu data structures */
16579 +       for_each_possible_cpu(cpu) {
16580 +               vx_info_init_sched_pc(
16581 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16582 +               vx_info_init_cvirt_pc(
16583 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16584 +       }
16585 +
16586 +       new->vx_flags = VXF_INIT_SET;
16587 +       cap_set_init_eff(new->vx_bcaps);
16588 +       new->vx_ccaps = 0;
16589 +       new->vx_umask = 0;
16590 +
16591 +       new->reboot_cmd = 0;
16592 +       new->exit_code = 0;
16593 +
16594 +       // preconfig fs entries
16595 +       for (index = 0; index < VX_SPACES; index++) {
16596 +               write_lock(&init_fs.lock);
16597 +               init_fs.users++;
16598 +               write_unlock(&init_fs.lock);
16599 +               new->vx_fs[index] = &init_fs;
16600 +       }
16601 +
16602 +       vxdprintk(VXD_CBIT(xid, 0),
16603 +               "alloc_vx_info(%d) = %p", xid, new);
16604 +       vxh_alloc_vx_info(new);
16605 +       atomic_inc(&vx_global_ctotal);
16606 +       return new;
16607 +#ifdef CONFIG_SMP
16608 +error:
16609 +       kfree(new);
16610 +       return 0;
16611 +#endif
16612 +}
16613 +
16614 +/*     __dealloc_vx_info()
16615 +
16616 +       * final disposal of vx_info                             */
16617 +
16618 +static void __dealloc_vx_info(struct vx_info *vxi)
16619 +{
16620 +       struct vx_info_save vxis;
16621 +       int cpu;
16622 +
16623 +       vxdprintk(VXD_CBIT(xid, 0),
16624 +               "dealloc_vx_info(%p)", vxi);
16625 +       vxh_dealloc_vx_info(vxi);
16626 +
16627 +#ifdef CONFIG_VSERVER_WARN
16628 +       enter_vx_info(vxi, &vxis);
16629 +       vx_info_exit_limit(&vxi->limit);
16630 +       vx_info_exit_sched(&vxi->sched);
16631 +       vx_info_exit_cvirt(&vxi->cvirt);
16632 +       vx_info_exit_cacct(&vxi->cacct);
16633 +
16634 +       for_each_possible_cpu(cpu) {
16635 +               vx_info_exit_sched_pc(
16636 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16637 +               vx_info_exit_cvirt_pc(
16638 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16639 +       }
16640 +       leave_vx_info(&vxis);
16641 +#endif
16642 +
16643 +       vxi->vx_id = -1;
16644 +       vxi->vx_state |= VXS_RELEASED;
16645 +
16646 +#ifdef CONFIG_SMP
16647 +       free_percpu(vxi->ptr_pc);
16648 +#endif
16649 +       kfree(vxi);
16650 +       atomic_dec(&vx_global_ctotal);
16651 +}
16652 +
16653 +static void __shutdown_vx_info(struct vx_info *vxi)
16654 +{
16655 +       struct nsproxy *nsproxy;
16656 +       struct fs_struct *fs;
16657 +       int index, kill;
16658 +
16659 +       might_sleep();
16660 +
16661 +       vxi->vx_state |= VXS_SHUTDOWN;
16662 +       vs_state_change(vxi, VSC_SHUTDOWN);
16663 +
16664 +       for (index = 0; index < VX_SPACES; index++) {
16665 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
16666 +               if (nsproxy)
16667 +                       put_nsproxy(nsproxy);
16668 +
16669 +               fs = xchg(&vxi->vx_fs[index], NULL);
16670 +               write_lock(&fs->lock);
16671 +               kill = !--fs->users;
16672 +               write_unlock(&fs->lock);
16673 +               if (kill)
16674 +                       free_fs_struct(fs);
16675 +       }
16676 +}
16677 +
16678 +/* exported stuff */
16679 +
16680 +void free_vx_info(struct vx_info *vxi)
16681 +{
16682 +       unsigned long flags;
16683 +       unsigned index;
16684 +
16685 +       /* check for reference counts first */
16686 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16687 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16688 +
16689 +       /* context must not be hashed */
16690 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16691 +
16692 +       /* context shutdown is mandatory */
16693 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16694 +
16695 +       /* nsproxy and fs check */
16696 +       for (index = 0; index < VX_SPACES; index++) {
16697 +               BUG_ON(vxi->vx_nsproxy[index]);
16698 +               BUG_ON(vxi->vx_fs[index]);
16699 +       }
16700 +
16701 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16702 +       hlist_del(&vxi->vx_hlist);
16703 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16704 +
16705 +       __dealloc_vx_info(vxi);
16706 +}
16707 +
16708 +
16709 +/*     hash table for vx_info hash */
16710 +
16711 +#define VX_HASH_SIZE   13
16712 +
16713 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16714 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16715 +
16716 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
16717 +
16718 +
16719 +static inline unsigned int __hashval(xid_t xid)
16720 +{
16721 +       return (xid % VX_HASH_SIZE);
16722 +}
16723 +
16724 +
16725 +
16726 +/*     __hash_vx_info()
16727 +
16728 +       * add the vxi to the global hash table
16729 +       * requires the hash_lock to be held                     */
16730 +
16731 +static inline void __hash_vx_info(struct vx_info *vxi)
16732 +{
16733 +       struct hlist_head *head;
16734 +
16735 +       vxd_assert_lock(&vx_info_hash_lock);
16736 +       vxdprintk(VXD_CBIT(xid, 4),
16737 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16738 +       vxh_hash_vx_info(vxi);
16739 +
16740 +       /* context must not be hashed */
16741 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16742 +
16743 +       vxi->vx_state |= VXS_HASHED;
16744 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16745 +       hlist_add_head(&vxi->vx_hlist, head);
16746 +       atomic_inc(&vx_global_cactive);
16747 +}
16748 +
16749 +/*     __unhash_vx_info()
16750 +
16751 +       * remove the vxi from the global hash table
16752 +       * requires the hash_lock to be held                     */
16753 +
16754 +static inline void __unhash_vx_info(struct vx_info *vxi)
16755 +{
16756 +       unsigned long flags;
16757 +
16758 +       vxd_assert_lock(&vx_info_hash_lock);
16759 +       vxdprintk(VXD_CBIT(xid, 4),
16760 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16761 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16762 +       vxh_unhash_vx_info(vxi);
16763 +
16764 +       /* context must be hashed */
16765 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16766 +       /* but without tasks */
16767 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16768 +
16769 +       vxi->vx_state &= ~VXS_HASHED;
16770 +       hlist_del_init(&vxi->vx_hlist);
16771 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16772 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16773 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16774 +       atomic_dec(&vx_global_cactive);
16775 +}
16776 +
16777 +
16778 +/*     __lookup_vx_info()
16779 +
16780 +       * requires the hash_lock to be held
16781 +       * doesn't increment the vx_refcnt                       */
16782 +
16783 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16784 +{
16785 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16786 +       struct hlist_node *pos;
16787 +       struct vx_info *vxi;
16788 +
16789 +       vxd_assert_lock(&vx_info_hash_lock);
16790 +       hlist_for_each(pos, head) {
16791 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16792 +
16793 +               if (vxi->vx_id == xid)
16794 +                       goto found;
16795 +       }
16796 +       vxi = NULL;
16797 +found:
16798 +       vxdprintk(VXD_CBIT(xid, 0),
16799 +               "__lookup_vx_info(#%u): %p[#%u]",
16800 +               xid, vxi, vxi ? vxi->vx_id : 0);
16801 +       vxh_lookup_vx_info(vxi, xid);
16802 +       return vxi;
16803 +}
16804 +
16805 +
16806 +/*     __create_vx_info()
16807 +
16808 +       * create the requested context
16809 +       * get(), claim() and hash it                            */
16810 +
16811 +static struct vx_info *__create_vx_info(int id)
16812 +{
16813 +       struct vx_info *new, *vxi = NULL;
16814 +
16815 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16816 +
16817 +       if (!(new = __alloc_vx_info(id)))
16818 +               return ERR_PTR(-ENOMEM);
16819 +
16820 +       /* required to make dynamic xids unique */
16821 +       spin_lock(&vx_info_hash_lock);
16822 +
16823 +       /* static context requested */
16824 +       if ((vxi = __lookup_vx_info(id))) {
16825 +               vxdprintk(VXD_CBIT(xid, 0),
16826 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16827 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16828 +                       vxi = ERR_PTR(-EBUSY);
16829 +               else
16830 +                       vxi = ERR_PTR(-EEXIST);
16831 +               goto out_unlock;
16832 +       }
16833 +       /* new context */
16834 +       vxdprintk(VXD_CBIT(xid, 0),
16835 +               "create_vx_info(%d) = %p (new)", id, new);
16836 +       claim_vx_info(new, NULL);
16837 +       __hash_vx_info(get_vx_info(new));
16838 +       vxi = new, new = NULL;
16839 +
16840 +out_unlock:
16841 +       spin_unlock(&vx_info_hash_lock);
16842 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16843 +       if (new)
16844 +               __dealloc_vx_info(new);
16845 +       return vxi;
16846 +}
16847 +
16848 +
16849 +/*     exported stuff                                          */
16850 +
16851 +
16852 +void unhash_vx_info(struct vx_info *vxi)
16853 +{
16854 +       __shutdown_vx_info(vxi);
16855 +       spin_lock(&vx_info_hash_lock);
16856 +       __unhash_vx_info(vxi);
16857 +       spin_unlock(&vx_info_hash_lock);
16858 +       __wakeup_vx_info(vxi);
16859 +}
16860 +
16861 +
16862 +/*     lookup_vx_info()
16863 +
16864 +       * search for a vx_info and get() it
16865 +       * negative id means current                             */
16866 +
16867 +struct vx_info *lookup_vx_info(int id)
16868 +{
16869 +       struct vx_info *vxi = NULL;
16870 +
16871 +       if (id < 0) {
16872 +               vxi = get_vx_info(current_vx_info());
16873 +       } else if (id > 1) {
16874 +               spin_lock(&vx_info_hash_lock);
16875 +               vxi = get_vx_info(__lookup_vx_info(id));
16876 +               spin_unlock(&vx_info_hash_lock);
16877 +       }
16878 +       return vxi;
16879 +}
16880 +
16881 +/*     xid_is_hashed()
16882 +
16883 +       * verify that xid is still hashed                       */
16884 +
16885 +int xid_is_hashed(xid_t xid)
16886 +{
16887 +       int hashed;
16888 +
16889 +       spin_lock(&vx_info_hash_lock);
16890 +       hashed = (__lookup_vx_info(xid) != NULL);
16891 +       spin_unlock(&vx_info_hash_lock);
16892 +       return hashed;
16893 +}
16894 +
16895 +#ifdef CONFIG_PROC_FS
16896 +
16897 +/*     get_xid_list()
16898 +
16899 +       * get a subset of hashed xids for proc
16900 +       * assumes size is at least one                          */
16901 +
16902 +int get_xid_list(int index, unsigned int *xids, int size)
16903 +{
16904 +       int hindex, nr_xids = 0;
16905 +
16906 +       /* only show current and children */
16907 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16908 +               if (index > 0)
16909 +                       return 0;
16910 +               xids[nr_xids] = vx_current_xid();
16911 +               return 1;
16912 +       }
16913 +
16914 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16915 +               struct hlist_head *head = &vx_info_hash[hindex];
16916 +               struct hlist_node *pos;
16917 +
16918 +               spin_lock(&vx_info_hash_lock);
16919 +               hlist_for_each(pos, head) {
16920 +                       struct vx_info *vxi;
16921 +
16922 +                       if (--index > 0)
16923 +                               continue;
16924 +
16925 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16926 +                       xids[nr_xids] = vxi->vx_id;
16927 +                       if (++nr_xids >= size) {
16928 +                               spin_unlock(&vx_info_hash_lock);
16929 +                               goto out;
16930 +                       }
16931 +               }
16932 +               /* keep the lock time short */
16933 +               spin_unlock(&vx_info_hash_lock);
16934 +       }
16935 +out:
16936 +       return nr_xids;
16937 +}
16938 +#endif
16939 +
16940 +#ifdef CONFIG_VSERVER_DEBUG
16941 +
16942 +void   dump_vx_info_inactive(int level)
16943 +{
16944 +       struct hlist_node *entry, *next;
16945 +
16946 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16947 +               struct vx_info *vxi =
16948 +                       list_entry(entry, struct vx_info, vx_hlist);
16949 +
16950 +               dump_vx_info(vxi, level);
16951 +       }
16952 +}
16953 +
16954 +#endif
16955 +
16956 +#if 0
16957 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16958 +{
16959 +       struct user_struct *new_user, *old_user;
16960 +
16961 +       if (!p || !vxi)
16962 +               BUG();
16963 +
16964 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16965 +               return -EACCES;
16966 +
16967 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16968 +       if (!new_user)
16969 +               return -ENOMEM;
16970 +
16971 +       old_user = p->user;
16972 +       if (new_user != old_user) {
16973 +               atomic_inc(&new_user->processes);
16974 +               atomic_dec(&old_user->processes);
16975 +               p->user = new_user;
16976 +       }
16977 +       free_uid(old_user);
16978 +       return 0;
16979 +}
16980 +#endif
16981 +
16982 +#if 0
16983 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16984 +{
16985 +       // p->cap_effective &= vxi->vx_cap_bset;
16986 +       p->cap_effective =
16987 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16988 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16989 +       p->cap_inheritable =
16990 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16991 +       // p->cap_permitted &= vxi->vx_cap_bset;
16992 +       p->cap_permitted =
16993 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16994 +}
16995 +#endif
16996 +
16997 +
16998 +#include <linux/file.h>
16999 +#include <linux/fdtable.h>
17000 +
17001 +static int vx_openfd_task(struct task_struct *tsk)
17002 +{
17003 +       struct files_struct *files = tsk->files;
17004 +       struct fdtable *fdt;
17005 +       const unsigned long *bptr;
17006 +       int count, total;
17007 +
17008 +       /* no rcu_read_lock() because of spin_lock() */
17009 +       spin_lock(&files->file_lock);
17010 +       fdt = files_fdtable(files);
17011 +       bptr = fdt->open_fds->fds_bits;
17012 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
17013 +       for (total = 0; count > 0; count--) {
17014 +               if (*bptr)
17015 +                       total += hweight_long(*bptr);
17016 +               bptr++;
17017 +       }
17018 +       spin_unlock(&files->file_lock);
17019 +       return total;
17020 +}
17021 +
17022 +
17023 +/*     for *space compatibility */
17024 +
17025 +asmlinkage long sys_unshare(unsigned long);
17026 +
17027 +/*
17028 + *     migrate task to new context
17029 + *     gets vxi, puts old_vxi on change
17030 + *     optionally unshares namespaces (hack)
17031 + */
17032 +
17033 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17034 +{
17035 +       struct vx_info *old_vxi;
17036 +       int ret = 0;
17037 +
17038 +       if (!p || !vxi)
17039 +               BUG();
17040 +
17041 +       vxdprintk(VXD_CBIT(xid, 5),
17042 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17043 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17044 +
17045 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17046 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17047 +               return -EACCES;
17048 +
17049 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17050 +               return -EFAULT;
17051 +
17052 +       old_vxi = task_get_vx_info(p);
17053 +       if (old_vxi == vxi)
17054 +               goto out;
17055 +
17056 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17057 +       {
17058 +               int openfd;
17059 +
17060 +               task_lock(p);
17061 +               openfd = vx_openfd_task(p);
17062 +
17063 +               if (old_vxi) {
17064 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17065 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17066 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17067 +                       /* FIXME: what about the struct files here? */
17068 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17069 +                       /* account for the executable */
17070 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17071 +               }
17072 +               atomic_inc(&vxi->cvirt.nr_threads);
17073 +               atomic_inc(&vxi->cvirt.nr_running);
17074 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17075 +               /* FIXME: what about the struct files here? */
17076 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17077 +               /* account for the executable */
17078 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17079 +
17080 +               if (old_vxi) {
17081 +                       release_vx_info(old_vxi, p);
17082 +                       clr_vx_info(&p->vx_info);
17083 +               }
17084 +               claim_vx_info(vxi, p);
17085 +               set_vx_info(&p->vx_info, vxi);
17086 +               p->xid = vxi->vx_id;
17087 +
17088 +               vxdprintk(VXD_CBIT(xid, 5),
17089 +                       "moved task %p into vxi:%p[#%d]",
17090 +                       p, vxi, vxi->vx_id);
17091 +
17092 +               // vx_mask_cap_bset(vxi, p);
17093 +               task_unlock(p);
17094 +
17095 +               /* hack for *spaces to provide compatibility */
17096 +               if (unshare) {
17097 +                       struct nsproxy *old_nsp, *new_nsp;
17098 +
17099 +                       ret = unshare_nsproxy_namespaces(
17100 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17101 +                               &new_nsp, NULL);
17102 +                       if (ret)
17103 +                               goto out;
17104 +
17105 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17106 +                       vx_set_space(vxi,
17107 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
17108 +                       put_nsproxy(old_nsp);
17109 +               }
17110 +       }
17111 +out:
17112 +       put_vx_info(old_vxi);
17113 +       return ret;
17114 +}
17115 +
17116 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17117 +{
17118 +       struct task_struct *old_reaper;
17119 +
17120 +       if (!vxi)
17121 +               return -EINVAL;
17122 +
17123 +       vxdprintk(VXD_CBIT(xid, 6),
17124 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17125 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17126 +
17127 +       old_reaper = vxi->vx_reaper;
17128 +       if (old_reaper == p)
17129 +               return 0;
17130 +
17131 +       /* set new child reaper */
17132 +       get_task_struct(p);
17133 +       vxi->vx_reaper = p;
17134 +       put_task_struct(old_reaper);
17135 +       return 0;
17136 +}
17137 +
17138 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17139 +{
17140 +       if (!vxi)
17141 +               return -EINVAL;
17142 +
17143 +       vxdprintk(VXD_CBIT(xid, 6),
17144 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17145 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17146 +
17147 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17148 +       // vxi->vx_initpid = p->tgid;
17149 +       vxi->vx_initpid = p->pid;
17150 +       return 0;
17151 +}
17152 +
17153 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17154 +{
17155 +       vxdprintk(VXD_CBIT(xid, 6),
17156 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17157 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17158 +
17159 +       vxi->exit_code = code;
17160 +       vxi->vx_initpid = 0;
17161 +}
17162 +
17163 +
17164 +void vx_set_persistent(struct vx_info *vxi)
17165 +{
17166 +       vxdprintk(VXD_CBIT(xid, 6),
17167 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
17168 +
17169 +       get_vx_info(vxi);
17170 +       claim_vx_info(vxi, NULL);
17171 +}
17172 +
17173 +void vx_clear_persistent(struct vx_info *vxi)
17174 +{
17175 +       vxdprintk(VXD_CBIT(xid, 6),
17176 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
17177 +
17178 +       release_vx_info(vxi, NULL);
17179 +       put_vx_info(vxi);
17180 +}
17181 +
17182 +void vx_update_persistent(struct vx_info *vxi)
17183 +{
17184 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
17185 +               vx_set_persistent(vxi);
17186 +       else
17187 +               vx_clear_persistent(vxi);
17188 +}
17189 +
17190 +
17191 +/*     task must be current or locked          */
17192 +
17193 +void   exit_vx_info(struct task_struct *p, int code)
17194 +{
17195 +       struct vx_info *vxi = p->vx_info;
17196 +
17197 +       if (vxi) {
17198 +               atomic_dec(&vxi->cvirt.nr_threads);
17199 +               vx_nproc_dec(p);
17200 +
17201 +               vxi->exit_code = code;
17202 +               release_vx_info(vxi, p);
17203 +       }
17204 +}
17205 +
17206 +void   exit_vx_info_early(struct task_struct *p, int code)
17207 +{
17208 +       struct vx_info *vxi = p->vx_info;
17209 +
17210 +       if (vxi) {
17211 +               if (vxi->vx_initpid == p->pid)
17212 +                       vx_exit_init(vxi, p, code);
17213 +               if (vxi->vx_reaper == p)
17214 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
17215 +       }
17216 +}
17217 +
17218 +
17219 +/* vserver syscall commands below here */
17220 +
17221 +/* taks xid and vx_info functions */
17222 +
17223 +#include <asm/uaccess.h>
17224 +
17225 +
17226 +int vc_task_xid(uint32_t id)
17227 +{
17228 +       xid_t xid;
17229 +
17230 +       if (id) {
17231 +               struct task_struct *tsk;
17232 +
17233 +               read_lock(&tasklist_lock);
17234 +               tsk = find_task_by_real_pid(id);
17235 +               xid = (tsk) ? tsk->xid : -ESRCH;
17236 +               read_unlock(&tasklist_lock);
17237 +       } else
17238 +               xid = vx_current_xid();
17239 +       return xid;
17240 +}
17241 +
17242 +
17243 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17244 +{
17245 +       struct vcmd_vx_info_v0 vc_data;
17246 +
17247 +       vc_data.xid = vxi->vx_id;
17248 +       vc_data.initpid = vxi->vx_initpid;
17249 +
17250 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17251 +               return -EFAULT;
17252 +       return 0;
17253 +}
17254 +
17255 +
17256 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17257 +{
17258 +       struct vcmd_ctx_stat_v0 vc_data;
17259 +
17260 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17261 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17262 +
17263 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17264 +               return -EFAULT;
17265 +       return 0;
17266 +}
17267 +
17268 +
17269 +/* context functions */
17270 +
17271 +int vc_ctx_create(uint32_t xid, void __user *data)
17272 +{
17273 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17274 +       struct vx_info *new_vxi;
17275 +       int ret;
17276 +
17277 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17278 +               return -EFAULT;
17279 +
17280 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
17281 +               return -EINVAL;
17282 +
17283 +       new_vxi = __create_vx_info(xid);
17284 +       if (IS_ERR(new_vxi))
17285 +               return PTR_ERR(new_vxi);
17286 +
17287 +       /* initial flags */
17288 +       new_vxi->vx_flags = vc_data.flagword;
17289 +
17290 +       ret = -ENOEXEC;
17291 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17292 +               goto out;
17293 +
17294 +       ret = vx_migrate_task(current, new_vxi, (!data));
17295 +       if (ret)
17296 +               goto out;
17297 +
17298 +       /* return context id on success */
17299 +       ret = new_vxi->vx_id;
17300 +
17301 +       /* get a reference for persistent contexts */
17302 +       if ((vc_data.flagword & VXF_PERSISTENT))
17303 +               vx_set_persistent(new_vxi);
17304 +out:
17305 +       release_vx_info(new_vxi, NULL);
17306 +       put_vx_info(new_vxi);
17307 +       return ret;
17308 +}
17309 +
17310 +
17311 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17312 +{
17313 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17314 +       int ret;
17315 +
17316 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17317 +               return -EFAULT;
17318 +
17319 +       ret = vx_migrate_task(current, vxi, 0);
17320 +       if (ret)
17321 +               return ret;
17322 +       if (vc_data.flagword & VXM_SET_INIT)
17323 +               ret = vx_set_init(vxi, current);
17324 +       if (ret)
17325 +               return ret;
17326 +       if (vc_data.flagword & VXM_SET_REAPER)
17327 +               ret = vx_set_reaper(vxi, current);
17328 +       return ret;
17329 +}
17330 +
17331 +
17332 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17333 +{
17334 +       struct vcmd_ctx_flags_v0 vc_data;
17335 +
17336 +       vc_data.flagword = vxi->vx_flags;
17337 +
17338 +       /* special STATE flag handling */
17339 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17340 +
17341 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17342 +               return -EFAULT;
17343 +       return 0;
17344 +}
17345 +
17346 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17347 +{
17348 +       struct vcmd_ctx_flags_v0 vc_data;
17349 +       uint64_t mask, trigger;
17350 +
17351 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17352 +               return -EFAULT;
17353 +
17354 +       /* special STATE flag handling */
17355 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17356 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17357 +
17358 +       if (vxi == current_vx_info()) {
17359 +               /* if (trigger & VXF_STATE_SETUP)
17360 +                       vx_mask_cap_bset(vxi, current); */
17361 +               if (trigger & VXF_STATE_INIT) {
17362 +                       int ret;
17363 +
17364 +                       ret = vx_set_init(vxi, current);
17365 +                       if (ret)
17366 +                               return ret;
17367 +                       ret = vx_set_reaper(vxi, current);
17368 +                       if (ret)
17369 +                               return ret;
17370 +               }
17371 +       }
17372 +
17373 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17374 +               vc_data.flagword, mask);
17375 +       if (trigger & VXF_PERSISTENT)
17376 +               vx_update_persistent(vxi);
17377 +
17378 +       return 0;
17379 +}
17380 +
17381 +
17382 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17383 +{
17384 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17385 +
17386 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17387 +       return v;
17388 +}
17389 +
17390 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17391 +{
17392 +       kernel_cap_t c = __cap_empty_set;
17393 +
17394 +       c.cap[0] = v & 0xFFFFFFFF;
17395 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17396 +
17397 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17398 +       return c;
17399 +}
17400 +
17401 +
17402 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17403 +{
17404 +       if (bcaps)
17405 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17406 +       if (ccaps)
17407 +               *ccaps = vxi->vx_ccaps;
17408 +
17409 +       return 0;
17410 +}
17411 +
17412 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17413 +{
17414 +       struct vcmd_ctx_caps_v1 vc_data;
17415 +       int ret;
17416 +
17417 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17418 +       if (ret)
17419 +               return ret;
17420 +       vc_data.cmask = ~0ULL;
17421 +
17422 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17423 +               return -EFAULT;
17424 +       return 0;
17425 +}
17426 +
17427 +static int do_set_caps(struct vx_info *vxi,
17428 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17429 +{
17430 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17431 +
17432 +#if 0
17433 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17434 +               bcaps, bmask, ccaps, cmask);
17435 +#endif
17436 +       vxi->vx_bcaps = cap_t_from_caps(
17437 +               vs_mask_flags(bcold, bcaps, bmask));
17438 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17439 +
17440 +       return 0;
17441 +}
17442 +
17443 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17444 +{
17445 +       struct vcmd_ctx_caps_v1 vc_data;
17446 +
17447 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17448 +               return -EFAULT;
17449 +
17450 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17451 +}
17452 +
17453 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17454 +{
17455 +       struct vcmd_bcaps vc_data;
17456 +       int ret;
17457 +
17458 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17459 +       if (ret)
17460 +               return ret;
17461 +       vc_data.bmask = ~0ULL;
17462 +
17463 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17464 +               return -EFAULT;
17465 +       return 0;
17466 +}
17467 +
17468 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17469 +{
17470 +       struct vcmd_bcaps vc_data;
17471 +
17472 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17473 +               return -EFAULT;
17474 +
17475 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17476 +}
17477 +
17478 +
17479 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17480 +{
17481 +       struct vcmd_umask vc_data;
17482 +
17483 +       vc_data.umask = vxi->vx_umask;
17484 +       vc_data.mask = ~0ULL;
17485 +
17486 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17487 +               return -EFAULT;
17488 +       return 0;
17489 +}
17490 +
17491 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17492 +{
17493 +       struct vcmd_umask vc_data;
17494 +
17495 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17496 +               return -EFAULT;
17497 +
17498 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17499 +               vc_data.umask, vc_data.mask);
17500 +       return 0;
17501 +}
17502 +
17503 +
17504 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17505 +{
17506 +       struct vcmd_badness_v0 vc_data;
17507 +
17508 +       vc_data.bias = vxi->vx_badness_bias;
17509 +
17510 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17511 +               return -EFAULT;
17512 +       return 0;
17513 +}
17514 +
17515 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17516 +{
17517 +       struct vcmd_badness_v0 vc_data;
17518 +
17519 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17520 +               return -EFAULT;
17521 +
17522 +       vxi->vx_badness_bias = vc_data.bias;
17523 +       return 0;
17524 +}
17525 +
17526 +#include <linux/module.h>
17527 +
17528 +EXPORT_SYMBOL_GPL(free_vx_info);
17529 +
17530 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cvirt.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cvirt.c
17531 --- linux-2.6.33/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
17532 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cvirt.c   2010-02-25 12:02:16.000000000 +0100
17533 @@ -0,0 +1,304 @@
17534 +/*
17535 + *  linux/kernel/vserver/cvirt.c
17536 + *
17537 + *  Virtual Server: Context Virtualization
17538 + *
17539 + *  Copyright (C) 2004-2007  Herbert Pötzl
17540 + *
17541 + *  V0.01  broken out from limit.c
17542 + *  V0.02  added utsname stuff
17543 + *  V0.03  changed vcmds to vxi arg
17544 + *
17545 + */
17546 +
17547 +#include <linux/types.h>
17548 +#include <linux/utsname.h>
17549 +#include <linux/vs_cvirt.h>
17550 +#include <linux/vserver/switch.h>
17551 +#include <linux/vserver/cvirt_cmd.h>
17552 +
17553 +#include <asm/uaccess.h>
17554 +
17555 +
17556 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17557 +{
17558 +       struct vx_info *vxi = current_vx_info();
17559 +
17560 +       set_normalized_timespec(uptime,
17561 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17562 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17563 +       if (!idle)
17564 +               return;
17565 +       set_normalized_timespec(idle,
17566 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17567 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17568 +       return;
17569 +}
17570 +
17571 +uint64_t vx_idle_jiffies(void)
17572 +{
17573 +       return init_task.utime + init_task.stime;
17574 +}
17575 +
17576 +
17577 +
17578 +static inline uint32_t __update_loadavg(uint32_t load,
17579 +       int wsize, int delta, int n)
17580 +{
17581 +       unsigned long long calc, prev;
17582 +
17583 +       /* just set it to n */
17584 +       if (unlikely(delta >= wsize))
17585 +               return (n << FSHIFT);
17586 +
17587 +       calc = delta * n;
17588 +       calc <<= FSHIFT;
17589 +       prev = (wsize - delta);
17590 +       prev *= load;
17591 +       calc += prev;
17592 +       do_div(calc, wsize);
17593 +       return calc;
17594 +}
17595 +
17596 +
17597 +void vx_update_load(struct vx_info *vxi)
17598 +{
17599 +       uint32_t now, last, delta;
17600 +       unsigned int nr_running, nr_uninterruptible;
17601 +       unsigned int total;
17602 +       unsigned long flags;
17603 +
17604 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17605 +
17606 +       now = jiffies;
17607 +       last = vxi->cvirt.load_last;
17608 +       delta = now - last;
17609 +
17610 +       if (delta < 5*HZ)
17611 +               goto out;
17612 +
17613 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17614 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17615 +       total = nr_running + nr_uninterruptible;
17616 +
17617 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17618 +               60*HZ, delta, total);
17619 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17620 +               5*60*HZ, delta, total);
17621 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17622 +               15*60*HZ, delta, total);
17623 +
17624 +       vxi->cvirt.load_last = now;
17625 +out:
17626 +       atomic_inc(&vxi->cvirt.load_updates);
17627 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17628 +}
17629 +
17630 +
17631 +/*
17632 + * Commands to do_syslog:
17633 + *
17634 + *      0 -- Close the log.  Currently a NOP.
17635 + *      1 -- Open the log. Currently a NOP.
17636 + *      2 -- Read from the log.
17637 + *      3 -- Read all messages remaining in the ring buffer.
17638 + *      4 -- Read and clear all messages remaining in the ring buffer
17639 + *      5 -- Clear ring buffer.
17640 + *      6 -- Disable printk's to console
17641 + *      7 -- Enable printk's to console
17642 + *      8 -- Set level of messages printed to console
17643 + *      9 -- Return number of unread characters in the log buffer
17644 + *     10 -- Return size of the log buffer
17645 + */
17646 +int vx_do_syslog(int type, char __user *buf, int len)
17647 +{
17648 +       int error = 0;
17649 +       int do_clear = 0;
17650 +       struct vx_info *vxi = current_vx_info();
17651 +       struct _vx_syslog *log;
17652 +
17653 +       if (!vxi)
17654 +               return -EINVAL;
17655 +       log = &vxi->cvirt.syslog;
17656 +
17657 +       switch (type) {
17658 +       case 0:         /* Close log */
17659 +       case 1:         /* Open log */
17660 +               break;
17661 +       case 2:         /* Read from log */
17662 +               error = wait_event_interruptible(log->log_wait,
17663 +                       (log->log_start - log->log_end));
17664 +               if (error)
17665 +                       break;
17666 +               spin_lock_irq(&log->logbuf_lock);
17667 +               spin_unlock_irq(&log->logbuf_lock);
17668 +               break;
17669 +       case 4:         /* Read/clear last kernel messages */
17670 +               do_clear = 1;
17671 +               /* fall through */
17672 +       case 3:         /* Read last kernel messages */
17673 +               return 0;
17674 +
17675 +       case 5:         /* Clear ring buffer */
17676 +               return 0;
17677 +
17678 +       case 6:         /* Disable logging to console */
17679 +       case 7:         /* Enable logging to console */
17680 +       case 8:         /* Set level of messages printed to console */
17681 +               break;
17682 +
17683 +       case 9:         /* Number of chars in the log buffer */
17684 +               return 0;
17685 +       case 10:        /* Size of the log buffer */
17686 +               return 0;
17687 +       default:
17688 +               error = -EINVAL;
17689 +               break;
17690 +       }
17691 +       return error;
17692 +}
17693 +
17694 +
17695 +/* virtual host info names */
17696 +
17697 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17698 +{
17699 +       struct nsproxy *nsproxy;
17700 +       struct uts_namespace *uts;
17701 +
17702 +       if (id == VHIN_CONTEXT)
17703 +               return vxi->vx_name;
17704 +
17705 +       nsproxy = vxi->vx_nsproxy[0];
17706 +       if (!nsproxy)
17707 +               return NULL;
17708 +
17709 +       uts = nsproxy->uts_ns;
17710 +       if (!uts)
17711 +               return NULL;
17712 +
17713 +       switch (id) {
17714 +       case VHIN_SYSNAME:
17715 +               return uts->name.sysname;
17716 +       case VHIN_NODENAME:
17717 +               return uts->name.nodename;
17718 +       case VHIN_RELEASE:
17719 +               return uts->name.release;
17720 +       case VHIN_VERSION:
17721 +               return uts->name.version;
17722 +       case VHIN_MACHINE:
17723 +               return uts->name.machine;
17724 +       case VHIN_DOMAINNAME:
17725 +               return uts->name.domainname;
17726 +       default:
17727 +               return NULL;
17728 +       }
17729 +       return NULL;
17730 +}
17731 +
17732 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17733 +{
17734 +       struct vcmd_vhi_name_v0 vc_data;
17735 +       char *name;
17736 +
17737 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17738 +               return -EFAULT;
17739 +
17740 +       name = vx_vhi_name(vxi, vc_data.field);
17741 +       if (!name)
17742 +               return -EINVAL;
17743 +
17744 +       memcpy(name, vc_data.name, 65);
17745 +       return 0;
17746 +}
17747 +
17748 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17749 +{
17750 +       struct vcmd_vhi_name_v0 vc_data;
17751 +       char *name;
17752 +
17753 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17754 +               return -EFAULT;
17755 +
17756 +       name = vx_vhi_name(vxi, vc_data.field);
17757 +       if (!name)
17758 +               return -EINVAL;
17759 +
17760 +       memcpy(vc_data.name, name, 65);
17761 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17762 +               return -EFAULT;
17763 +       return 0;
17764 +}
17765 +
17766 +
17767 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17768 +{
17769 +       struct vcmd_virt_stat_v0 vc_data;
17770 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17771 +       struct timespec uptime;
17772 +
17773 +       do_posix_clock_monotonic_gettime(&uptime);
17774 +       set_normalized_timespec(&uptime,
17775 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17776 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17777 +
17778 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
17779 +       vc_data.uptime = timespec_to_ns(&uptime);
17780 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17781 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17782 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17783 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17784 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17785 +       vc_data.load[0] = cvirt->load[0];
17786 +       vc_data.load[1] = cvirt->load[1];
17787 +       vc_data.load[2] = cvirt->load[2];
17788 +
17789 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17790 +               return -EFAULT;
17791 +       return 0;
17792 +}
17793 +
17794 +
17795 +#ifdef CONFIG_VSERVER_VTIME
17796 +
17797 +/* virtualized time base */
17798 +
17799 +void vx_gettimeofday(struct timeval *tv)
17800 +{
17801 +       struct vx_info *vxi;
17802 +
17803 +       do_gettimeofday(tv);
17804 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17805 +               return;
17806 +
17807 +       vxi = current_vx_info();
17808 +       tv->tv_sec += vxi->cvirt.bias_tv.tv_sec;
17809 +       tv->tv_usec += vxi->cvirt.bias_tv.tv_usec;
17810 +
17811 +       if (tv->tv_usec >= USEC_PER_SEC) {
17812 +               tv->tv_sec++;
17813 +               tv->tv_usec -= USEC_PER_SEC;
17814 +       } else if (tv->tv_usec < 0) {
17815 +               tv->tv_sec--;
17816 +               tv->tv_usec += USEC_PER_SEC;
17817 +       }
17818 +}
17819 +
17820 +int vx_settimeofday(struct timespec *ts)
17821 +{
17822 +       struct timeval tv;
17823 +       struct vx_info *vxi;
17824 +
17825 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17826 +               return do_settimeofday(ts);
17827 +
17828 +       do_gettimeofday(&tv);
17829 +       vxi = current_vx_info();
17830 +       vxi->cvirt.bias_tv.tv_sec = ts->tv_sec - tv.tv_sec;
17831 +       vxi->cvirt.bias_tv.tv_usec =
17832 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
17833 +       return 0;
17834 +}
17835 +
17836 +#endif
17837 +
17838 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cvirt_init.h linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cvirt_init.h
17839 --- linux-2.6.33/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
17840 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cvirt_init.h      2010-02-25 12:02:16.000000000 +0100
17841 @@ -0,0 +1,69 @@
17842 +
17843 +
17844 +extern uint64_t vx_idle_jiffies(void);
17845 +
17846 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17847 +{
17848 +       uint64_t idle_jiffies = vx_idle_jiffies();
17849 +       uint64_t nsuptime;
17850 +
17851 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17852 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17853 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17854 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17855 +       cvirt->bias_tv.tv_sec = 0;
17856 +       cvirt->bias_tv.tv_usec = 0;
17857 +
17858 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17859 +       atomic_set(&cvirt->nr_threads, 0);
17860 +       atomic_set(&cvirt->nr_running, 0);
17861 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17862 +       atomic_set(&cvirt->nr_onhold, 0);
17863 +
17864 +       spin_lock_init(&cvirt->load_lock);
17865 +       cvirt->load_last = jiffies;
17866 +       atomic_set(&cvirt->load_updates, 0);
17867 +       cvirt->load[0] = 0;
17868 +       cvirt->load[1] = 0;
17869 +       cvirt->load[2] = 0;
17870 +       atomic_set(&cvirt->total_forks, 0);
17871 +
17872 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17873 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17874 +       cvirt->syslog.log_start = 0;
17875 +       cvirt->syslog.log_end = 0;
17876 +       cvirt->syslog.con_start = 0;
17877 +       cvirt->syslog.logged_chars = 0;
17878 +}
17879 +
17880 +static inline
17881 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17882 +{
17883 +       // cvirt_pc->cpustat = { 0 };
17884 +}
17885 +
17886 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17887 +{
17888 +       int value;
17889 +
17890 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17891 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17892 +               cvirt, value);
17893 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17894 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17895 +               cvirt, value);
17896 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17897 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17898 +               cvirt, value);
17899 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17900 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17901 +               cvirt, value);
17902 +       return;
17903 +}
17904 +
17905 +static inline
17906 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17907 +{
17908 +       return;
17909 +}
17910 +
17911 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cvirt_proc.h linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cvirt_proc.h
17912 --- linux-2.6.33/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
17913 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/cvirt_proc.h      2010-02-25 12:02:16.000000000 +0100
17914 @@ -0,0 +1,135 @@
17915 +#ifndef _VX_CVIRT_PROC_H
17916 +#define _VX_CVIRT_PROC_H
17917 +
17918 +#include <linux/nsproxy.h>
17919 +#include <linux/mnt_namespace.h>
17920 +#include <linux/ipc_namespace.h>
17921 +#include <linux/utsname.h>
17922 +#include <linux/ipc.h>
17923 +
17924 +
17925 +static inline
17926 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17927 +{
17928 +       struct mnt_namespace *ns;
17929 +       struct uts_namespace *uts;
17930 +       struct ipc_namespace *ipc;
17931 +       struct path path;
17932 +       char *pstr, *root;
17933 +       int length = 0;
17934 +
17935 +       if (!nsproxy)
17936 +               goto out;
17937 +
17938 +       length += sprintf(buffer + length,
17939 +               "NSProxy:\t%p [%p,%p,%p]\n",
17940 +               nsproxy, nsproxy->mnt_ns,
17941 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17942 +
17943 +       ns = nsproxy->mnt_ns;
17944 +       if (!ns)
17945 +               goto skip_ns;
17946 +
17947 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17948 +       if (!pstr)
17949 +               goto skip_ns;
17950 +
17951 +       path.mnt = ns->root;
17952 +       path.dentry = ns->root->mnt_root;
17953 +       root = d_path(&path, pstr, PATH_MAX - 2);
17954 +       length += sprintf(buffer + length,
17955 +               "Namespace:\t%p [#%u]\n"
17956 +               "RootPath:\t%s\n",
17957 +               ns, atomic_read(&ns->count),
17958 +               root);
17959 +       kfree(pstr);
17960 +skip_ns:
17961 +
17962 +       uts = nsproxy->uts_ns;
17963 +       if (!uts)
17964 +               goto skip_uts;
17965 +
17966 +       length += sprintf(buffer + length,
17967 +               "SysName:\t%.*s\n"
17968 +               "NodeName:\t%.*s\n"
17969 +               "Release:\t%.*s\n"
17970 +               "Version:\t%.*s\n"
17971 +               "Machine:\t%.*s\n"
17972 +               "DomainName:\t%.*s\n",
17973 +               __NEW_UTS_LEN, uts->name.sysname,
17974 +               __NEW_UTS_LEN, uts->name.nodename,
17975 +               __NEW_UTS_LEN, uts->name.release,
17976 +               __NEW_UTS_LEN, uts->name.version,
17977 +               __NEW_UTS_LEN, uts->name.machine,
17978 +               __NEW_UTS_LEN, uts->name.domainname);
17979 +skip_uts:
17980 +
17981 +       ipc = nsproxy->ipc_ns;
17982 +       if (!ipc)
17983 +               goto skip_ipc;
17984 +
17985 +       length += sprintf(buffer + length,
17986 +               "SEMS:\t\t%d %d %d %d  %d\n"
17987 +               "MSG:\t\t%d %d %d\n"
17988 +               "SHM:\t\t%lu %lu  %d %d\n",
17989 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17990 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17991 +               ipc->used_sems,
17992 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17993 +               (unsigned long)ipc->shm_ctlmax,
17994 +               (unsigned long)ipc->shm_ctlall,
17995 +               ipc->shm_ctlmni, ipc->shm_tot);
17996 +skip_ipc:
17997 +out:
17998 +       return length;
17999 +}
18000 +
18001 +
18002 +#include <linux/sched.h>
18003 +
18004 +#define LOAD_INT(x) ((x) >> FSHIFT)
18005 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18006 +
18007 +static inline
18008 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18009 +{
18010 +       int length = 0;
18011 +       int a, b, c;
18012 +
18013 +       length += sprintf(buffer + length,
18014 +               "BiasUptime:\t%lu.%02lu\n",
18015 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18016 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18017 +
18018 +       a = cvirt->load[0] + (FIXED_1 / 200);
18019 +       b = cvirt->load[1] + (FIXED_1 / 200);
18020 +       c = cvirt->load[2] + (FIXED_1 / 200);
18021 +       length += sprintf(buffer + length,
18022 +               "nr_threads:\t%d\n"
18023 +               "nr_running:\t%d\n"
18024 +               "nr_unintr:\t%d\n"
18025 +               "nr_onhold:\t%d\n"
18026 +               "load_updates:\t%d\n"
18027 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18028 +               "total_forks:\t%d\n",
18029 +               atomic_read(&cvirt->nr_threads),
18030 +               atomic_read(&cvirt->nr_running),
18031 +               atomic_read(&cvirt->nr_uninterruptible),
18032 +               atomic_read(&cvirt->nr_onhold),
18033 +               atomic_read(&cvirt->load_updates),
18034 +               LOAD_INT(a), LOAD_FRAC(a),
18035 +               LOAD_INT(b), LOAD_FRAC(b),
18036 +               LOAD_INT(c), LOAD_FRAC(c),
18037 +               atomic_read(&cvirt->total_forks));
18038 +       return length;
18039 +}
18040 +
18041 +static inline
18042 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18043 +       char *buffer, int cpu)
18044 +{
18045 +       int length = 0;
18046 +       return length;
18047 +}
18048 +
18049 +#endif /* _VX_CVIRT_PROC_H */
18050 diff -NurpP --minimal linux-2.6.33/kernel/vserver/debug.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/debug.c
18051 --- linux-2.6.33/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
18052 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/debug.c   2010-02-25 12:02:16.000000000 +0100
18053 @@ -0,0 +1,32 @@
18054 +/*
18055 + *  kernel/vserver/debug.c
18056 + *
18057 + *  Copyright (C) 2005-2007 Herbert Pötzl
18058 + *
18059 + *  V0.01  vx_info dump support
18060 + *
18061 + */
18062 +
18063 +#include <linux/module.h>
18064 +
18065 +#include <linux/vserver/context.h>
18066 +
18067 +
18068 +void   dump_vx_info(struct vx_info *vxi, int level)
18069 +{
18070 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18071 +               atomic_read(&vxi->vx_usecnt),
18072 +               atomic_read(&vxi->vx_tasks),
18073 +               vxi->vx_state);
18074 +       if (level > 0) {
18075 +               __dump_vx_limit(&vxi->limit);
18076 +               __dump_vx_sched(&vxi->sched);
18077 +               __dump_vx_cvirt(&vxi->cvirt);
18078 +               __dump_vx_cacct(&vxi->cacct);
18079 +       }
18080 +       printk("---\n");
18081 +}
18082 +
18083 +
18084 +EXPORT_SYMBOL_GPL(dump_vx_info);
18085 +
18086 diff -NurpP --minimal linux-2.6.33/kernel/vserver/device.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/device.c
18087 --- linux-2.6.33/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
18088 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/device.c  2010-02-25 12:02:16.000000000 +0100
18089 @@ -0,0 +1,443 @@
18090 +/*
18091 + *  linux/kernel/vserver/device.c
18092 + *
18093 + *  Linux-VServer: Device Support
18094 + *
18095 + *  Copyright (C) 2006  Herbert Pötzl
18096 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18097 + *
18098 + *  V0.01  device mapping basics
18099 + *  V0.02  added defaults
18100 + *
18101 + */
18102 +
18103 +#include <linux/slab.h>
18104 +#include <linux/rcupdate.h>
18105 +#include <linux/fs.h>
18106 +#include <linux/namei.h>
18107 +#include <linux/hash.h>
18108 +
18109 +#include <asm/errno.h>
18110 +#include <asm/uaccess.h>
18111 +#include <linux/vserver/base.h>
18112 +#include <linux/vserver/debug.h>
18113 +#include <linux/vserver/context.h>
18114 +#include <linux/vserver/device.h>
18115 +#include <linux/vserver/device_cmd.h>
18116 +
18117 +
18118 +#define DMAP_HASH_BITS 4
18119 +
18120 +
18121 +struct vs_mapping {
18122 +       union {
18123 +               struct hlist_node hlist;
18124 +               struct list_head list;
18125 +       } u;
18126 +#define dm_hlist       u.hlist
18127 +#define dm_list                u.list
18128 +       xid_t xid;
18129 +       dev_t device;
18130 +       struct vx_dmap_target target;
18131 +};
18132 +
18133 +
18134 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18135 +
18136 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18137 +
18138 +static struct vx_dmap_target dmap_defaults[2] = {
18139 +       { .flags = DATTR_OPEN },
18140 +       { .flags = DATTR_OPEN },
18141 +};
18142 +
18143 +
18144 +struct kmem_cache *dmap_cachep __read_mostly;
18145 +
18146 +int __init dmap_cache_init(void)
18147 +{
18148 +       dmap_cachep = kmem_cache_create("dmap_cache",
18149 +               sizeof(struct vs_mapping), 0,
18150 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18151 +       return 0;
18152 +}
18153 +
18154 +__initcall(dmap_cache_init);
18155 +
18156 +
18157 +static inline unsigned int __hashval(dev_t dev, int bits)
18158 +{
18159 +       return hash_long((unsigned long)dev, bits);
18160 +}
18161 +
18162 +
18163 +/*     __hash_mapping()
18164 + *     add the mapping to the hash table
18165 + */
18166 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18167 +{
18168 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18169 +       struct hlist_head *head, *hash = dmap_main_hash;
18170 +       int device = vdm->device;
18171 +
18172 +       spin_lock(hash_lock);
18173 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18174 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18175 +
18176 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18177 +       hlist_add_head(&vdm->dm_hlist, head);
18178 +       spin_unlock(hash_lock);
18179 +}
18180 +
18181 +
18182 +static inline int __mode_to_default(umode_t mode)
18183 +{
18184 +       switch (mode) {
18185 +       case S_IFBLK:
18186 +               return 0;
18187 +       case S_IFCHR:
18188 +               return 1;
18189 +       default:
18190 +               BUG();
18191 +       }
18192 +}
18193 +
18194 +
18195 +/*     __set_default()
18196 + *     set a default
18197 + */
18198 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
18199 +       struct vx_dmap_target *vdmt)
18200 +{
18201 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18202 +       spin_lock(hash_lock);
18203 +
18204 +       if (vxi)
18205 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
18206 +       else
18207 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
18208 +
18209 +
18210 +       spin_unlock(hash_lock);
18211 +
18212 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
18213 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
18214 +}
18215 +
18216 +
18217 +/*     __remove_default()
18218 + *     remove a default
18219 + */
18220 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
18221 +{
18222 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18223 +       spin_lock(hash_lock);
18224 +
18225 +       if (vxi)
18226 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18227 +       else    /* remove == reset */
18228 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18229 +
18230 +       spin_unlock(hash_lock);
18231 +       return 0;
18232 +}
18233 +
18234 +
18235 +/*     __find_mapping()
18236 + *     find a mapping in the hash table
18237 + *
18238 + *     caller must hold hash_lock
18239 + */
18240 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18241 +       struct vs_mapping **local, struct vs_mapping **global)
18242 +{
18243 +       struct hlist_head *hash = dmap_main_hash;
18244 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18245 +       struct hlist_node *pos;
18246 +       struct vs_mapping *vdm;
18247 +
18248 +       *local = NULL;
18249 +       if (global)
18250 +               *global = NULL;
18251 +
18252 +       hlist_for_each(pos, head) {
18253 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18254 +
18255 +               if ((vdm->device == device) &&
18256 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18257 +                       if (vdm->xid == xid) {
18258 +                               *local = vdm;
18259 +                               return 1;
18260 +                       } else if (global && vdm->xid == 0)
18261 +                               *global = vdm;
18262 +               }
18263 +       }
18264 +
18265 +       if (global && *global)
18266 +               return 0;
18267 +       else
18268 +               return -ENOENT;
18269 +}
18270 +
18271 +
18272 +/*     __lookup_mapping()
18273 + *     find a mapping and store the result in target and flags
18274 + */
18275 +static inline int __lookup_mapping(struct vx_info *vxi,
18276 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18277 +{
18278 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18279 +       struct vs_mapping *vdm, *global;
18280 +       struct vx_dmap_target *vdmt;
18281 +       int ret = 0;
18282 +       xid_t xid = vxi->vx_id;
18283 +       int index;
18284 +
18285 +       spin_lock(hash_lock);
18286 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18287 +               ret = 1;
18288 +               vdmt = &vdm->target;
18289 +               goto found;
18290 +       }
18291 +
18292 +       index = __mode_to_default(mode);
18293 +       if (vxi && vxi->dmap.targets[index].flags) {
18294 +               ret = 2;
18295 +               vdmt = &vxi->dmap.targets[index];
18296 +       } else if (global) {
18297 +               ret = 3;
18298 +               vdmt = &global->target;
18299 +               goto found;
18300 +       } else {
18301 +               ret = 4;
18302 +               vdmt = &dmap_defaults[index];
18303 +       }
18304 +
18305 +found:
18306 +       if (target && (vdmt->flags & DATTR_REMAP))
18307 +               *target = vdmt->target;
18308 +       else if (target)
18309 +               *target = device;
18310 +       if (flags)
18311 +               *flags = vdmt->flags;
18312 +
18313 +       spin_unlock(hash_lock);
18314 +
18315 +       return ret;
18316 +}
18317 +
18318 +
18319 +/*     __remove_mapping()
18320 + *     remove a mapping from the hash table
18321 + */
18322 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18323 +       umode_t mode)
18324 +{
18325 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18326 +       struct vs_mapping *vdm = NULL;
18327 +       int ret = 0;
18328 +
18329 +       spin_lock(hash_lock);
18330 +
18331 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18332 +               NULL);
18333 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18334 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18335 +       if (ret < 0)
18336 +               goto out;
18337 +       hlist_del(&vdm->dm_hlist);
18338 +
18339 +out:
18340 +       spin_unlock(hash_lock);
18341 +       if (vdm)
18342 +               kmem_cache_free(dmap_cachep, vdm);
18343 +       return ret;
18344 +}
18345 +
18346 +
18347 +
18348 +int vs_map_device(struct vx_info *vxi,
18349 +       dev_t device, dev_t *target, umode_t mode)
18350 +{
18351 +       int ret, flags = DATTR_MASK;
18352 +
18353 +       if (!vxi) {
18354 +               if (target)
18355 +                       *target = device;
18356 +               goto out;
18357 +       }
18358 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18359 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18360 +               device, target ? *target : 0, flags, mode, ret);
18361 +out:
18362 +       return (flags & DATTR_MASK);
18363 +}
18364 +
18365 +
18366 +
18367 +static int do_set_mapping(struct vx_info *vxi,
18368 +       dev_t device, dev_t target, int flags, umode_t mode)
18369 +{
18370 +       if (device) {
18371 +               struct vs_mapping *new;
18372 +
18373 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18374 +               if (!new)
18375 +                       return -ENOMEM;
18376 +
18377 +               INIT_HLIST_NODE(&new->dm_hlist);
18378 +               new->device = device;
18379 +               new->target.target = target;
18380 +               new->target.flags = flags | mode;
18381 +               new->xid = (vxi ? vxi->vx_id : 0);
18382 +
18383 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18384 +               __hash_mapping(vxi, new);
18385 +       } else {
18386 +               struct vx_dmap_target new = {
18387 +                       .target = target,
18388 +                       .flags = flags | mode,
18389 +               };
18390 +               __set_default(vxi, mode, &new);
18391 +       }
18392 +       return 0;
18393 +}
18394 +
18395 +
18396 +static int do_unset_mapping(struct vx_info *vxi,
18397 +       dev_t device, dev_t target, int flags, umode_t mode)
18398 +{
18399 +       int ret = -EINVAL;
18400 +
18401 +       if (device) {
18402 +               ret = __remove_mapping(vxi, device, mode);
18403 +               if (ret < 0)
18404 +                       goto out;
18405 +       } else {
18406 +               ret = __remove_default(vxi, mode);
18407 +               if (ret < 0)
18408 +                       goto out;
18409 +       }
18410 +
18411 +out:
18412 +       return ret;
18413 +}
18414 +
18415 +
18416 +static inline int __user_device(const char __user *name, dev_t *dev,
18417 +       umode_t *mode)
18418 +{
18419 +       struct nameidata nd;
18420 +       int ret;
18421 +
18422 +       if (!name) {
18423 +               *dev = 0;
18424 +               return 0;
18425 +       }
18426 +       ret = user_lpath(name, &nd.path);
18427 +       if (ret)
18428 +               return ret;
18429 +       if (nd.path.dentry->d_inode) {
18430 +               *dev = nd.path.dentry->d_inode->i_rdev;
18431 +               *mode = nd.path.dentry->d_inode->i_mode;
18432 +       }
18433 +       path_put(&nd.path);
18434 +       return 0;
18435 +}
18436 +
18437 +static inline int __mapping_mode(dev_t device, dev_t target,
18438 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18439 +{
18440 +       if (device)
18441 +               *mode = device_mode & S_IFMT;
18442 +       else if (target)
18443 +               *mode = target_mode & S_IFMT;
18444 +       else
18445 +               return -EINVAL;
18446 +
18447 +       /* if both given, device and target mode have to match */
18448 +       if (device && target &&
18449 +               ((device_mode ^ target_mode) & S_IFMT))
18450 +               return -EINVAL;
18451 +       return 0;
18452 +}
18453 +
18454 +
18455 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18456 +       const char __user *target_path, int flags, int set)
18457 +{
18458 +       dev_t device = ~0, target = ~0;
18459 +       umode_t device_mode = 0, target_mode = 0, mode;
18460 +       int ret;
18461 +
18462 +       ret = __user_device(device_path, &device, &device_mode);
18463 +       if (ret)
18464 +               return ret;
18465 +       ret = __user_device(target_path, &target, &target_mode);
18466 +       if (ret)
18467 +               return ret;
18468 +
18469 +       ret = __mapping_mode(device, target,
18470 +               device_mode, target_mode, &mode);
18471 +       if (ret)
18472 +               return ret;
18473 +
18474 +       if (set)
18475 +               return do_set_mapping(vxi, device, target,
18476 +                       flags, mode);
18477 +       else
18478 +               return do_unset_mapping(vxi, device, target,
18479 +                       flags, mode);
18480 +}
18481 +
18482 +
18483 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18484 +{
18485 +       struct vcmd_set_mapping_v0 vc_data;
18486 +
18487 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18488 +               return -EFAULT;
18489 +
18490 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18491 +               vc_data.flags, 1);
18492 +}
18493 +
18494 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18495 +{
18496 +       struct vcmd_set_mapping_v0 vc_data;
18497 +
18498 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18499 +               return -EFAULT;
18500 +
18501 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18502 +               vc_data.flags, 0);
18503 +}
18504 +
18505 +
18506 +#ifdef CONFIG_COMPAT
18507 +
18508 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18509 +{
18510 +       struct vcmd_set_mapping_v0_x32 vc_data;
18511 +
18512 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18513 +               return -EFAULT;
18514 +
18515 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18516 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18517 +}
18518 +
18519 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18520 +{
18521 +       struct vcmd_set_mapping_v0_x32 vc_data;
18522 +
18523 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18524 +               return -EFAULT;
18525 +
18526 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18527 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18528 +}
18529 +
18530 +#endif /* CONFIG_COMPAT */
18531 +
18532 +
18533 diff -NurpP --minimal linux-2.6.33/kernel/vserver/dlimit.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/dlimit.c
18534 --- linux-2.6.33/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
18535 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/dlimit.c  2010-02-25 12:02:16.000000000 +0100
18536 @@ -0,0 +1,529 @@
18537 +/*
18538 + *  linux/kernel/vserver/dlimit.c
18539 + *
18540 + *  Virtual Server: Context Disk Limits
18541 + *
18542 + *  Copyright (C) 2004-2009  Herbert Pötzl
18543 + *
18544 + *  V0.01  initial version
18545 + *  V0.02  compat32 splitup
18546 + *  V0.03  extended interface
18547 + *
18548 + */
18549 +
18550 +#include <linux/statfs.h>
18551 +#include <linux/sched.h>
18552 +#include <linux/namei.h>
18553 +#include <linux/vs_tag.h>
18554 +#include <linux/vs_dlimit.h>
18555 +#include <linux/vserver/dlimit_cmd.h>
18556 +
18557 +#include <asm/uaccess.h>
18558 +
18559 +/*     __alloc_dl_info()
18560 +
18561 +       * allocate an initialized dl_info struct
18562 +       * doesn't make it visible (hash)                        */
18563 +
18564 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18565 +{
18566 +       struct dl_info *new = NULL;
18567 +
18568 +       vxdprintk(VXD_CBIT(dlim, 5),
18569 +               "alloc_dl_info(%p,%d)*", sb, tag);
18570 +
18571 +       /* would this benefit from a slab cache? */
18572 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18573 +       if (!new)
18574 +               return 0;
18575 +
18576 +       memset(new, 0, sizeof(struct dl_info));
18577 +       new->dl_tag = tag;
18578 +       new->dl_sb = sb;
18579 +       INIT_RCU_HEAD(&new->dl_rcu);
18580 +       INIT_HLIST_NODE(&new->dl_hlist);
18581 +       spin_lock_init(&new->dl_lock);
18582 +       atomic_set(&new->dl_refcnt, 0);
18583 +       atomic_set(&new->dl_usecnt, 0);
18584 +
18585 +       /* rest of init goes here */
18586 +
18587 +       vxdprintk(VXD_CBIT(dlim, 4),
18588 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18589 +       return new;
18590 +}
18591 +
18592 +/*     __dealloc_dl_info()
18593 +
18594 +       * final disposal of dl_info                             */
18595 +
18596 +static void __dealloc_dl_info(struct dl_info *dli)
18597 +{
18598 +       vxdprintk(VXD_CBIT(dlim, 4),
18599 +               "dealloc_dl_info(%p)", dli);
18600 +
18601 +       dli->dl_hlist.next = LIST_POISON1;
18602 +       dli->dl_tag = -1;
18603 +       dli->dl_sb = 0;
18604 +
18605 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18606 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18607 +
18608 +       kfree(dli);
18609 +}
18610 +
18611 +
18612 +/*     hash table for dl_info hash */
18613 +
18614 +#define DL_HASH_SIZE   13
18615 +
18616 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18617 +
18618 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
18619 +
18620 +
18621 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18622 +{
18623 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18624 +}
18625 +
18626 +
18627 +
18628 +/*     __hash_dl_info()
18629 +
18630 +       * add the dli to the global hash table
18631 +       * requires the hash_lock to be held                     */
18632 +
18633 +static inline void __hash_dl_info(struct dl_info *dli)
18634 +{
18635 +       struct hlist_head *head;
18636 +
18637 +       vxdprintk(VXD_CBIT(dlim, 6),
18638 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18639 +       get_dl_info(dli);
18640 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18641 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18642 +}
18643 +
18644 +/*     __unhash_dl_info()
18645 +
18646 +       * remove the dli from the global hash table
18647 +       * requires the hash_lock to be held                     */
18648 +
18649 +static inline void __unhash_dl_info(struct dl_info *dli)
18650 +{
18651 +       vxdprintk(VXD_CBIT(dlim, 6),
18652 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18653 +       hlist_del_rcu(&dli->dl_hlist);
18654 +       put_dl_info(dli);
18655 +}
18656 +
18657 +
18658 +/*     __lookup_dl_info()
18659 +
18660 +       * requires the rcu_read_lock()
18661 +       * doesn't increment the dl_refcnt                       */
18662 +
18663 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18664 +{
18665 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18666 +       struct hlist_node *pos;
18667 +       struct dl_info *dli;
18668 +
18669 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18670 +
18671 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18672 +                       return dli;
18673 +               }
18674 +       }
18675 +       return NULL;
18676 +}
18677 +
18678 +
18679 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18680 +{
18681 +       struct dl_info *dli;
18682 +
18683 +       rcu_read_lock();
18684 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18685 +       vxdprintk(VXD_CBIT(dlim, 7),
18686 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18687 +       rcu_read_unlock();
18688 +       return dli;
18689 +}
18690 +
18691 +void rcu_free_dl_info(struct rcu_head *head)
18692 +{
18693 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18694 +       int usecnt, refcnt;
18695 +
18696 +       BUG_ON(!dli || !head);
18697 +
18698 +       usecnt = atomic_read(&dli->dl_usecnt);
18699 +       BUG_ON(usecnt < 0);
18700 +
18701 +       refcnt = atomic_read(&dli->dl_refcnt);
18702 +       BUG_ON(refcnt < 0);
18703 +
18704 +       vxdprintk(VXD_CBIT(dlim, 3),
18705 +               "rcu_free_dl_info(%p)", dli);
18706 +       if (!usecnt)
18707 +               __dealloc_dl_info(dli);
18708 +       else
18709 +               printk("!!! rcu didn't free\n");
18710 +}
18711 +
18712 +
18713 +
18714 +
18715 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18716 +       uint32_t flags, int add)
18717 +{
18718 +       struct path path;
18719 +       int ret;
18720 +
18721 +       ret = user_lpath(name, &path);
18722 +       if (!ret) {
18723 +               struct super_block *sb;
18724 +               struct dl_info *dli;
18725 +
18726 +               ret = -EINVAL;
18727 +               if (!path.dentry->d_inode)
18728 +                       goto out_release;
18729 +               if (!(sb = path.dentry->d_inode->i_sb))
18730 +                       goto out_release;
18731 +
18732 +               if (add) {
18733 +                       dli = __alloc_dl_info(sb, id);
18734 +                       spin_lock(&dl_info_hash_lock);
18735 +
18736 +                       ret = -EEXIST;
18737 +                       if (__lookup_dl_info(sb, id))
18738 +                               goto out_unlock;
18739 +                       __hash_dl_info(dli);
18740 +                       dli = NULL;
18741 +               } else {
18742 +                       spin_lock(&dl_info_hash_lock);
18743 +                       dli = __lookup_dl_info(sb, id);
18744 +
18745 +                       ret = -ESRCH;
18746 +                       if (!dli)
18747 +                               goto out_unlock;
18748 +                       __unhash_dl_info(dli);
18749 +               }
18750 +               ret = 0;
18751 +       out_unlock:
18752 +               spin_unlock(&dl_info_hash_lock);
18753 +               if (add && dli)
18754 +                       __dealloc_dl_info(dli);
18755 +       out_release:
18756 +               path_put(&path);
18757 +       }
18758 +       return ret;
18759 +}
18760 +
18761 +int vc_add_dlimit(uint32_t id, void __user *data)
18762 +{
18763 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18764 +
18765 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18766 +               return -EFAULT;
18767 +
18768 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18769 +}
18770 +
18771 +int vc_rem_dlimit(uint32_t id, void __user *data)
18772 +{
18773 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18774 +
18775 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18776 +               return -EFAULT;
18777 +
18778 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18779 +}
18780 +
18781 +#ifdef CONFIG_COMPAT
18782 +
18783 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18784 +{
18785 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18786 +
18787 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18788 +               return -EFAULT;
18789 +
18790 +       return do_addrem_dlimit(id,
18791 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18792 +}
18793 +
18794 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18795 +{
18796 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18797 +
18798 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18799 +               return -EFAULT;
18800 +
18801 +       return do_addrem_dlimit(id,
18802 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18803 +}
18804 +
18805 +#endif /* CONFIG_COMPAT */
18806 +
18807 +
18808 +static inline
18809 +int do_set_dlimit(uint32_t id, const char __user *name,
18810 +       uint32_t space_used, uint32_t space_total,
18811 +       uint32_t inodes_used, uint32_t inodes_total,
18812 +       uint32_t reserved, uint32_t flags)
18813 +{
18814 +       struct path path;
18815 +       int ret;
18816 +
18817 +       ret = user_lpath(name, &path);
18818 +       if (!ret) {
18819 +               struct super_block *sb;
18820 +               struct dl_info *dli;
18821 +
18822 +               ret = -EINVAL;
18823 +               if (!path.dentry->d_inode)
18824 +                       goto out_release;
18825 +               if (!(sb = path.dentry->d_inode->i_sb))
18826 +                       goto out_release;
18827 +
18828 +               /* sanity checks */
18829 +               if ((reserved != CDLIM_KEEP &&
18830 +                       reserved > 100) ||
18831 +                       (inodes_used != CDLIM_KEEP &&
18832 +                       inodes_used > inodes_total) ||
18833 +                       (space_used != CDLIM_KEEP &&
18834 +                       space_used > space_total))
18835 +                       goto out_release;
18836 +
18837 +               ret = -ESRCH;
18838 +               dli = locate_dl_info(sb, id);
18839 +               if (!dli)
18840 +                       goto out_release;
18841 +
18842 +               spin_lock(&dli->dl_lock);
18843 +
18844 +               if (inodes_used != CDLIM_KEEP)
18845 +                       dli->dl_inodes_used = inodes_used;
18846 +               if (inodes_total != CDLIM_KEEP)
18847 +                       dli->dl_inodes_total = inodes_total;
18848 +               if (space_used != CDLIM_KEEP)
18849 +                       dli->dl_space_used = dlimit_space_32to64(
18850 +                               space_used, flags, DLIMS_USED);
18851 +
18852 +               if (space_total == CDLIM_INFINITY)
18853 +                       dli->dl_space_total = DLIM_INFINITY;
18854 +               else if (space_total != CDLIM_KEEP)
18855 +                       dli->dl_space_total = dlimit_space_32to64(
18856 +                               space_total, flags, DLIMS_TOTAL);
18857 +
18858 +               if (reserved != CDLIM_KEEP)
18859 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18860 +
18861 +               spin_unlock(&dli->dl_lock);
18862 +
18863 +               put_dl_info(dli);
18864 +               ret = 0;
18865 +
18866 +       out_release:
18867 +               path_put(&path);
18868 +       }
18869 +       return ret;
18870 +}
18871 +
18872 +int vc_set_dlimit(uint32_t id, void __user *data)
18873 +{
18874 +       struct vcmd_ctx_dlimit_v0 vc_data;
18875 +
18876 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18877 +               return -EFAULT;
18878 +
18879 +       return do_set_dlimit(id, vc_data.name,
18880 +               vc_data.space_used, vc_data.space_total,
18881 +               vc_data.inodes_used, vc_data.inodes_total,
18882 +               vc_data.reserved, vc_data.flags);
18883 +}
18884 +
18885 +#ifdef CONFIG_COMPAT
18886 +
18887 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18888 +{
18889 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18890 +
18891 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18892 +               return -EFAULT;
18893 +
18894 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18895 +               vc_data.space_used, vc_data.space_total,
18896 +               vc_data.inodes_used, vc_data.inodes_total,
18897 +               vc_data.reserved, vc_data.flags);
18898 +}
18899 +
18900 +#endif /* CONFIG_COMPAT */
18901 +
18902 +
18903 +static inline
18904 +int do_get_dlimit(uint32_t id, const char __user *name,
18905 +       uint32_t *space_used, uint32_t *space_total,
18906 +       uint32_t *inodes_used, uint32_t *inodes_total,
18907 +       uint32_t *reserved, uint32_t *flags)
18908 +{
18909 +       struct path path;
18910 +       int ret;
18911 +
18912 +       ret = user_lpath(name, &path);
18913 +       if (!ret) {
18914 +               struct super_block *sb;
18915 +               struct dl_info *dli;
18916 +
18917 +               ret = -EINVAL;
18918 +               if (!path.dentry->d_inode)
18919 +                       goto out_release;
18920 +               if (!(sb = path.dentry->d_inode->i_sb))
18921 +                       goto out_release;
18922 +
18923 +               ret = -ESRCH;
18924 +               dli = locate_dl_info(sb, id);
18925 +               if (!dli)
18926 +                       goto out_release;
18927 +
18928 +               spin_lock(&dli->dl_lock);
18929 +               *inodes_used = dli->dl_inodes_used;
18930 +               *inodes_total = dli->dl_inodes_total;
18931 +
18932 +               *space_used = dlimit_space_64to32(
18933 +                       dli->dl_space_used, flags, DLIMS_USED);
18934 +
18935 +               if (dli->dl_space_total == DLIM_INFINITY)
18936 +                       *space_total = CDLIM_INFINITY;
18937 +               else
18938 +                       *space_total = dlimit_space_64to32(
18939 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18940 +
18941 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18942 +               spin_unlock(&dli->dl_lock);
18943 +
18944 +               put_dl_info(dli);
18945 +               ret = -EFAULT;
18946 +
18947 +               ret = 0;
18948 +       out_release:
18949 +               path_put(&path);
18950 +       }
18951 +       return ret;
18952 +}
18953 +
18954 +
18955 +int vc_get_dlimit(uint32_t id, void __user *data)
18956 +{
18957 +       struct vcmd_ctx_dlimit_v0 vc_data;
18958 +       int ret;
18959 +
18960 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18961 +               return -EFAULT;
18962 +
18963 +       ret = do_get_dlimit(id, vc_data.name,
18964 +               &vc_data.space_used, &vc_data.space_total,
18965 +               &vc_data.inodes_used, &vc_data.inodes_total,
18966 +               &vc_data.reserved, &vc_data.flags);
18967 +       if (ret)
18968 +               return ret;
18969 +
18970 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18971 +               return -EFAULT;
18972 +       return 0;
18973 +}
18974 +
18975 +#ifdef CONFIG_COMPAT
18976 +
18977 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18978 +{
18979 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18980 +       int ret;
18981 +
18982 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18983 +               return -EFAULT;
18984 +
18985 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18986 +               &vc_data.space_used, &vc_data.space_total,
18987 +               &vc_data.inodes_used, &vc_data.inodes_total,
18988 +               &vc_data.reserved, &vc_data.flags);
18989 +       if (ret)
18990 +               return ret;
18991 +
18992 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18993 +               return -EFAULT;
18994 +       return 0;
18995 +}
18996 +
18997 +#endif /* CONFIG_COMPAT */
18998 +
18999 +
19000 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19001 +{
19002 +       struct dl_info *dli;
19003 +       __u64 blimit, bfree, bavail;
19004 +       __u32 ifree;
19005 +
19006 +       dli = locate_dl_info(sb, dx_current_tag());
19007 +       if (!dli)
19008 +               return;
19009 +
19010 +       spin_lock(&dli->dl_lock);
19011 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19012 +               goto no_ilim;
19013 +
19014 +       /* reduce max inodes available to limit */
19015 +       if (buf->f_files > dli->dl_inodes_total)
19016 +               buf->f_files = dli->dl_inodes_total;
19017 +
19018 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19019 +       /* reduce free inodes to min */
19020 +       if (ifree < buf->f_ffree)
19021 +               buf->f_ffree = ifree;
19022 +
19023 +no_ilim:
19024 +       if (dli->dl_space_total == DLIM_INFINITY)
19025 +               goto no_blim;
19026 +
19027 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19028 +
19029 +       if (dli->dl_space_total < dli->dl_space_used)
19030 +               bfree = 0;
19031 +       else
19032 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19033 +                       >> sb->s_blocksize_bits;
19034 +
19035 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19036 +       if (bavail < dli->dl_space_used)
19037 +               bavail = 0;
19038 +       else
19039 +               bavail = (bavail - dli->dl_space_used)
19040 +                       >> sb->s_blocksize_bits;
19041 +
19042 +       /* reduce max space available to limit */
19043 +       if (buf->f_blocks > blimit)
19044 +               buf->f_blocks = blimit;
19045 +
19046 +       /* reduce free space to min */
19047 +       if (bfree < buf->f_bfree)
19048 +               buf->f_bfree = bfree;
19049 +
19050 +       /* reduce avail space to min */
19051 +       if (bavail < buf->f_bavail)
19052 +               buf->f_bavail = bavail;
19053 +
19054 +no_blim:
19055 +       spin_unlock(&dli->dl_lock);
19056 +       put_dl_info(dli);
19057 +
19058 +       return;
19059 +}
19060 +
19061 +#include <linux/module.h>
19062 +
19063 +EXPORT_SYMBOL_GPL(locate_dl_info);
19064 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19065 +
19066 diff -NurpP --minimal linux-2.6.33/kernel/vserver/helper.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/helper.c
19067 --- linux-2.6.33/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
19068 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/helper.c  2010-02-25 12:02:16.000000000 +0100
19069 @@ -0,0 +1,223 @@
19070 +/*
19071 + *  linux/kernel/vserver/helper.c
19072 + *
19073 + *  Virtual Context Support
19074 + *
19075 + *  Copyright (C) 2004-2007  Herbert Pötzl
19076 + *
19077 + *  V0.01  basic helper
19078 + *
19079 + */
19080 +
19081 +#include <linux/kmod.h>
19082 +#include <linux/reboot.h>
19083 +#include <linux/vs_context.h>
19084 +#include <linux/vs_network.h>
19085 +#include <linux/vserver/signal.h>
19086 +
19087 +
19088 +char vshelper_path[255] = "/sbin/vshelper";
19089 +
19090 +
19091 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19092 +{
19093 +       int ret;
19094 +
19095 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19096 +               printk( KERN_WARNING
19097 +                       "%s: (%s %s) returned %s with %d\n",
19098 +                       name, argv[1], argv[2],
19099 +                       sync ? "sync" : "async", ret);
19100 +       }
19101 +       vxdprintk(VXD_CBIT(switch, 4),
19102 +               "%s: (%s %s) returned %s with %d",
19103 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19104 +       return ret;
19105 +}
19106 +
19107 +/*
19108 + *      vshelper path is set via /proc/sys
19109 + *      invoked by vserver sys_reboot(), with
19110 + *      the following arguments
19111 + *
19112 + *      argv [0] = vshelper_path;
19113 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19114 + *      argv [2] = context identifier
19115 + *
19116 + *      envp [*] = type-specific parameters
19117 + */
19118 +
19119 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19120 +{
19121 +       char id_buf[8], cmd_buf[16];
19122 +       char uid_buf[16], pid_buf[16];
19123 +       int ret;
19124 +
19125 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19126 +       char *envp[] = {"HOME=/", "TERM=linux",
19127 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19128 +                       uid_buf, pid_buf, cmd_buf, 0};
19129 +
19130 +       if (vx_info_state(vxi, VXS_HELPER))
19131 +               return -EAGAIN;
19132 +       vxi->vx_state |= VXS_HELPER;
19133 +
19134 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19135 +
19136 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19137 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
19138 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19139 +
19140 +       switch (cmd) {
19141 +       case LINUX_REBOOT_CMD_RESTART:
19142 +               argv[1] = "restart";
19143 +               break;
19144 +
19145 +       case LINUX_REBOOT_CMD_HALT:
19146 +               argv[1] = "halt";
19147 +               break;
19148 +
19149 +       case LINUX_REBOOT_CMD_POWER_OFF:
19150 +               argv[1] = "poweroff";
19151 +               break;
19152 +
19153 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19154 +               argv[1] = "swsusp";
19155 +               break;
19156 +
19157 +       case LINUX_REBOOT_CMD_OOM:
19158 +               argv[1] = "oom";
19159 +               break;
19160 +
19161 +       default:
19162 +               vxi->vx_state &= ~VXS_HELPER;
19163 +               return 0;
19164 +       }
19165 +
19166 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19167 +       vxi->vx_state &= ~VXS_HELPER;
19168 +       __wakeup_vx_info(vxi);
19169 +       return (ret) ? -EPERM : 0;
19170 +}
19171 +
19172 +
19173 +long vs_reboot(unsigned int cmd, void __user *arg)
19174 +{
19175 +       struct vx_info *vxi = current_vx_info();
19176 +       long ret = 0;
19177 +
19178 +       vxdprintk(VXD_CBIT(misc, 5),
19179 +               "vs_reboot(%p[#%d],%u)",
19180 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19181 +
19182 +       ret = vs_reboot_helper(vxi, cmd, arg);
19183 +       if (ret)
19184 +               return ret;
19185 +
19186 +       vxi->reboot_cmd = cmd;
19187 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19188 +               switch (cmd) {
19189 +               case LINUX_REBOOT_CMD_RESTART:
19190 +               case LINUX_REBOOT_CMD_HALT:
19191 +               case LINUX_REBOOT_CMD_POWER_OFF:
19192 +                       vx_info_kill(vxi, 0, SIGKILL);
19193 +                       vx_info_kill(vxi, 1, SIGKILL);
19194 +               default:
19195 +                       break;
19196 +               }
19197 +       }
19198 +       return 0;
19199 +}
19200 +
19201 +long vs_oom_action(unsigned int cmd)
19202 +{
19203 +       struct vx_info *vxi = current_vx_info();
19204 +       long ret = 0;
19205 +
19206 +       vxdprintk(VXD_CBIT(misc, 5),
19207 +               "vs_oom_action(%p[#%d],%u)",
19208 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19209 +
19210 +       ret = vs_reboot_helper(vxi, cmd, NULL);
19211 +       if (ret)
19212 +               return ret;
19213 +
19214 +       vxi->reboot_cmd = cmd;
19215 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19216 +               vx_info_kill(vxi, 0, SIGKILL);
19217 +               vx_info_kill(vxi, 1, SIGKILL);
19218 +       }
19219 +       return 0;
19220 +}
19221 +
19222 +/*
19223 + *      argv [0] = vshelper_path;
19224 + *      argv [1] = action: "startup", "shutdown"
19225 + *      argv [2] = context identifier
19226 + *
19227 + *      envp [*] = type-specific parameters
19228 + */
19229 +
19230 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19231 +{
19232 +       char id_buf[8], cmd_buf[16];
19233 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19234 +       char *envp[] = {"HOME=/", "TERM=linux",
19235 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19236 +
19237 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19238 +               return 0;
19239 +
19240 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19241 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19242 +
19243 +       switch (cmd) {
19244 +       case VSC_STARTUP:
19245 +               argv[1] = "startup";
19246 +               break;
19247 +       case VSC_SHUTDOWN:
19248 +               argv[1] = "shutdown";
19249 +               break;
19250 +       default:
19251 +               return 0;
19252 +       }
19253 +
19254 +       return do_vshelper(vshelper_path, argv, envp, 1);
19255 +}
19256 +
19257 +
19258 +/*
19259 + *      argv [0] = vshelper_path;
19260 + *      argv [1] = action: "netup", "netdown"
19261 + *      argv [2] = context identifier
19262 + *
19263 + *      envp [*] = type-specific parameters
19264 + */
19265 +
19266 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19267 +{
19268 +       char id_buf[8], cmd_buf[16];
19269 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19270 +       char *envp[] = {"HOME=/", "TERM=linux",
19271 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19272 +
19273 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19274 +               return 0;
19275 +
19276 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19277 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19278 +
19279 +       switch (cmd) {
19280 +       case VSC_NETUP:
19281 +               argv[1] = "netup";
19282 +               break;
19283 +       case VSC_NETDOWN:
19284 +               argv[1] = "netdown";
19285 +               break;
19286 +       default:
19287 +               return 0;
19288 +       }
19289 +
19290 +       return do_vshelper(vshelper_path, argv, envp, 1);
19291 +}
19292 +
19293 diff -NurpP --minimal linux-2.6.33/kernel/vserver/history.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/history.c
19294 --- linux-2.6.33/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
19295 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/history.c 2010-02-25 12:02:16.000000000 +0100
19296 @@ -0,0 +1,258 @@
19297 +/*
19298 + *  kernel/vserver/history.c
19299 + *
19300 + *  Virtual Context History Backtrace
19301 + *
19302 + *  Copyright (C) 2004-2007  Herbert Pötzl
19303 + *
19304 + *  V0.01  basic structure
19305 + *  V0.02  hash/unhash and trace
19306 + *  V0.03  preemption fixes
19307 + *
19308 + */
19309 +
19310 +#include <linux/module.h>
19311 +#include <asm/uaccess.h>
19312 +
19313 +#include <linux/vserver/context.h>
19314 +#include <linux/vserver/debug.h>
19315 +#include <linux/vserver/debug_cmd.h>
19316 +#include <linux/vserver/history.h>
19317 +
19318 +
19319 +#ifdef CONFIG_VSERVER_HISTORY
19320 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19321 +#else
19322 +#define VXH_SIZE       64
19323 +#endif
19324 +
19325 +struct _vx_history {
19326 +       unsigned int counter;
19327 +
19328 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19329 +};
19330 +
19331 +
19332 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19333 +
19334 +unsigned volatile int vxh_active = 1;
19335 +
19336 +static atomic_t sequence = ATOMIC_INIT(0);
19337 +
19338 +
19339 +/*     vxh_advance()
19340 +
19341 +       * requires disabled preemption                          */
19342 +
19343 +struct _vx_hist_entry *vxh_advance(void *loc)
19344 +{
19345 +       unsigned int cpu = smp_processor_id();
19346 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19347 +       struct _vx_hist_entry *entry;
19348 +       unsigned int index;
19349 +
19350 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19351 +       entry = &hist->entry[index];
19352 +
19353 +       entry->seq = atomic_inc_return(&sequence);
19354 +       entry->loc = loc;
19355 +       return entry;
19356 +}
19357 +
19358 +EXPORT_SYMBOL_GPL(vxh_advance);
19359 +
19360 +
19361 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19362 +
19363 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19364 +
19365 +
19366 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19367 +
19368 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19369 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19370 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19371 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19372 +
19373 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19374 +{
19375 +       switch (e->type) {
19376 +       case VXH_THROW_OOPS:
19377 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19378 +               break;
19379 +
19380 +       case VXH_GET_VX_INFO:
19381 +       case VXH_PUT_VX_INFO:
19382 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19383 +                       VXH_LOC_ARGS(e),
19384 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19385 +                       VXH_VXI_ARGS(e));
19386 +               break;
19387 +
19388 +       case VXH_INIT_VX_INFO:
19389 +       case VXH_SET_VX_INFO:
19390 +       case VXH_CLR_VX_INFO:
19391 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19392 +                       VXH_LOC_ARGS(e),
19393 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19394 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19395 +                       VXH_VXI_ARGS(e), e->sc.data);
19396 +               break;
19397 +
19398 +       case VXH_CLAIM_VX_INFO:
19399 +       case VXH_RELEASE_VX_INFO:
19400 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19401 +                       VXH_LOC_ARGS(e),
19402 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19403 +                       VXH_VXI_ARGS(e), e->sc.data);
19404 +               break;
19405 +
19406 +       case VXH_ALLOC_VX_INFO:
19407 +       case VXH_DEALLOC_VX_INFO:
19408 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19409 +                       VXH_LOC_ARGS(e),
19410 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19411 +                       VXH_VXI_ARGS(e));
19412 +               break;
19413 +
19414 +       case VXH_HASH_VX_INFO:
19415 +       case VXH_UNHASH_VX_INFO:
19416 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19417 +                       VXH_LOC_ARGS(e),
19418 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19419 +                       VXH_VXI_ARGS(e));
19420 +               break;
19421 +
19422 +       case VXH_LOC_VX_INFO:
19423 +       case VXH_LOOKUP_VX_INFO:
19424 +       case VXH_CREATE_VX_INFO:
19425 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19426 +                       VXH_LOC_ARGS(e),
19427 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19428 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19429 +                       e->ll.arg, VXH_VXI_ARGS(e));
19430 +               break;
19431 +       }
19432 +}
19433 +
19434 +static void __vxh_dump_history(void)
19435 +{
19436 +       unsigned int i, cpu;
19437 +
19438 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19439 +               atomic_read(&sequence), NR_CPUS);
19440 +
19441 +       for (i = 0; i < VXH_SIZE; i++) {
19442 +               for_each_online_cpu(cpu) {
19443 +                       struct _vx_history *hist =
19444 +                               &per_cpu(vx_history_buffer, cpu);
19445 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19446 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19447 +
19448 +                       vxh_dump_entry(entry, cpu);
19449 +               }
19450 +       }
19451 +}
19452 +
19453 +void   vxh_dump_history(void)
19454 +{
19455 +       vxh_active = 0;
19456 +#ifdef CONFIG_SMP
19457 +       local_irq_enable();
19458 +       smp_send_stop();
19459 +       local_irq_disable();
19460 +#endif
19461 +       __vxh_dump_history();
19462 +}
19463 +
19464 +
19465 +/* vserver syscall commands below here */
19466 +
19467 +
19468 +int vc_dump_history(uint32_t id)
19469 +{
19470 +       vxh_active = 0;
19471 +       __vxh_dump_history();
19472 +       vxh_active = 1;
19473 +
19474 +       return 0;
19475 +}
19476 +
19477 +
19478 +int do_read_history(struct __user _vx_hist_entry *data,
19479 +       int cpu, uint32_t *index, uint32_t *count)
19480 +{
19481 +       int pos, ret = 0;
19482 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19483 +       int end = hist->counter;
19484 +       int start = end - VXH_SIZE + 2;
19485 +       int idx = *index;
19486 +
19487 +       /* special case: get current pos */
19488 +       if (!*count) {
19489 +               *index = end;
19490 +               return 0;
19491 +       }
19492 +
19493 +       /* have we lost some data? */
19494 +       if (idx < start)
19495 +               idx = start;
19496 +
19497 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19498 +               struct _vx_hist_entry *entry =
19499 +                       &hist->entry[idx % VXH_SIZE];
19500 +
19501 +               /* send entry to userspace */
19502 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19503 +               if (ret)
19504 +                       break;
19505 +       }
19506 +       /* save new index and count */
19507 +       *index = idx;
19508 +       *count = pos;
19509 +       return ret ? ret : (*index < end);
19510 +}
19511 +
19512 +int vc_read_history(uint32_t id, void __user *data)
19513 +{
19514 +       struct vcmd_read_history_v0 vc_data;
19515 +       int ret;
19516 +
19517 +       if (id >= NR_CPUS)
19518 +               return -EINVAL;
19519 +
19520 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19521 +               return -EFAULT;
19522 +
19523 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19524 +               id, &vc_data.index, &vc_data.count);
19525 +
19526 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19527 +               return -EFAULT;
19528 +       return ret;
19529 +}
19530 +
19531 +#ifdef CONFIG_COMPAT
19532 +
19533 +int vc_read_history_x32(uint32_t id, void __user *data)
19534 +{
19535 +       struct vcmd_read_history_v0_x32 vc_data;
19536 +       int ret;
19537 +
19538 +       if (id >= NR_CPUS)
19539 +               return -EINVAL;
19540 +
19541 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19542 +               return -EFAULT;
19543 +
19544 +       ret = do_read_history((struct __user _vx_hist_entry *)
19545 +               compat_ptr(vc_data.data_ptr),
19546 +               id, &vc_data.index, &vc_data.count);
19547 +
19548 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19549 +               return -EFAULT;
19550 +       return ret;
19551 +}
19552 +
19553 +#endif /* CONFIG_COMPAT */
19554 +
19555 diff -NurpP --minimal linux-2.6.33/kernel/vserver/inet.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/inet.c
19556 --- linux-2.6.33/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
19557 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/inet.c    2010-02-25 12:02:16.000000000 +0100
19558 @@ -0,0 +1,225 @@
19559 +
19560 +#include <linux/in.h>
19561 +#include <linux/inetdevice.h>
19562 +#include <linux/vs_inet.h>
19563 +#include <linux/vs_inet6.h>
19564 +#include <linux/vserver/debug.h>
19565 +#include <net/route.h>
19566 +#include <net/addrconf.h>
19567 +
19568 +
19569 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19570 +{
19571 +       int ret = 0;
19572 +
19573 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19574 +               ret = 1;
19575 +       else {
19576 +               struct nx_addr_v4 *ptr;
19577 +
19578 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19579 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19580 +                               ret = 1;
19581 +                               break;
19582 +                       }
19583 +               }
19584 +       }
19585 +
19586 +       vxdprintk(VXD_CBIT(net, 2),
19587 +               "nx_v4_addr_conflict(%p,%p): %d",
19588 +               nxi1, nxi2, ret);
19589 +
19590 +       return ret;
19591 +}
19592 +
19593 +
19594 +#ifdef CONFIG_IPV6
19595 +
19596 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19597 +{
19598 +       int ret = 0;
19599 +
19600 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19601 +               ret = 1;
19602 +       else {
19603 +               struct nx_addr_v6 *ptr;
19604 +
19605 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19606 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19607 +                               ret = 1;
19608 +                               break;
19609 +                       }
19610 +               }
19611 +       }
19612 +
19613 +       vxdprintk(VXD_CBIT(net, 2),
19614 +               "nx_v6_addr_conflict(%p,%p): %d",
19615 +               nxi1, nxi2, ret);
19616 +
19617 +       return ret;
19618 +}
19619 +
19620 +#endif
19621 +
19622 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19623 +{
19624 +       struct in_device *in_dev;
19625 +       struct in_ifaddr **ifap;
19626 +       struct in_ifaddr *ifa;
19627 +       int ret = 0;
19628 +
19629 +       if (!dev)
19630 +               goto out;
19631 +       in_dev = in_dev_get(dev);
19632 +       if (!in_dev)
19633 +               goto out;
19634 +
19635 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19636 +               ifap = &ifa->ifa_next) {
19637 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19638 +                       ret = 1;
19639 +                       break;
19640 +               }
19641 +       }
19642 +       in_dev_put(in_dev);
19643 +out:
19644 +       return ret;
19645 +}
19646 +
19647 +
19648 +#ifdef CONFIG_IPV6
19649 +
19650 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19651 +{
19652 +       struct inet6_dev *in_dev;
19653 +       struct inet6_ifaddr **ifap;
19654 +       struct inet6_ifaddr *ifa;
19655 +       int ret = 0;
19656 +
19657 +       if (!dev)
19658 +               goto out;
19659 +       in_dev = in6_dev_get(dev);
19660 +       if (!in_dev)
19661 +               goto out;
19662 +
19663 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19664 +               ifap = &ifa->if_next) {
19665 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19666 +                       ret = 1;
19667 +                       break;
19668 +               }
19669 +       }
19670 +       in6_dev_put(in_dev);
19671 +out:
19672 +       return ret;
19673 +}
19674 +
19675 +#endif
19676 +
19677 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19678 +{
19679 +       int ret = 1;
19680 +
19681 +       if (!nxi)
19682 +               goto out;
19683 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19684 +               goto out;
19685 +#ifdef CONFIG_IPV6
19686 +       ret = 2;
19687 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19688 +               goto out;
19689 +#endif
19690 +       ret = 0;
19691 +out:
19692 +       vxdprintk(VXD_CBIT(net, 3),
19693 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19694 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19695 +       return ret;
19696 +}
19697 +
19698 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
19699 +       struct rtable **rp, struct flowi *fl)
19700 +{
19701 +       if (!nxi)
19702 +               return 0;
19703 +
19704 +       /* FIXME: handle lback only case */
19705 +       if (!NX_IPV4(nxi))
19706 +               return -EPERM;
19707 +
19708 +       vxdprintk(VXD_CBIT(net, 4),
19709 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19710 +               nxi, nxi ? nxi->nx_id : 0,
19711 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
19712 +
19713 +       /* single IP is unconditional */
19714 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19715 +               (fl->fl4_src == INADDR_ANY))
19716 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
19717 +
19718 +       if (fl->fl4_src == INADDR_ANY) {
19719 +               struct nx_addr_v4 *ptr;
19720 +               __be32 found = 0;
19721 +               int err;
19722 +
19723 +               err = __ip_route_output_key(net, rp, fl);
19724 +               if (!err) {
19725 +                       found = (*rp)->rt_src;
19726 +                       ip_rt_put(*rp);
19727 +                       vxdprintk(VXD_CBIT(net, 4),
19728 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19729 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
19730 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19731 +                               goto found;
19732 +               }
19733 +
19734 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19735 +                       __be32 primary = ptr->ip[0].s_addr;
19736 +                       __be32 mask = ptr->mask.s_addr;
19737 +                       __be32 neta = primary & mask;
19738 +
19739 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19740 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19741 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19742 +                               NIPQUAD(mask), NIPQUAD(neta));
19743 +                       if ((found & mask) != neta)
19744 +                               continue;
19745 +
19746 +                       fl->fl4_src = primary;
19747 +                       err = __ip_route_output_key(net, rp, fl);
19748 +                       vxdprintk(VXD_CBIT(net, 4),
19749 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19750 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
19751 +                       if (!err) {
19752 +                               found = (*rp)->rt_src;
19753 +                               ip_rt_put(*rp);
19754 +                               if (found == primary)
19755 +                                       goto found;
19756 +                       }
19757 +               }
19758 +               /* still no source ip? */
19759 +               found = ipv4_is_loopback(fl->fl4_dst)
19760 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19761 +       found:
19762 +               /* assign src ip to flow */
19763 +               fl->fl4_src = found;
19764 +
19765 +       } else {
19766 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
19767 +                       return -EPERM;
19768 +       }
19769 +
19770 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19771 +               if (ipv4_is_loopback(fl->fl4_dst))
19772 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
19773 +               if (ipv4_is_loopback(fl->fl4_src))
19774 +                       fl->fl4_src = nxi->v4_lback.s_addr;
19775 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
19776 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19777 +               return -EPERM;
19778 +
19779 +       return 0;
19780 +}
19781 +
19782 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19783 +
19784 diff -NurpP --minimal linux-2.6.33/kernel/vserver/init.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/init.c
19785 --- linux-2.6.33/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
19786 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/init.c    2010-02-25 12:02:16.000000000 +0100
19787 @@ -0,0 +1,45 @@
19788 +/*
19789 + *  linux/kernel/init.c
19790 + *
19791 + *  Virtual Server Init
19792 + *
19793 + *  Copyright (C) 2004-2007  Herbert Pötzl
19794 + *
19795 + *  V0.01  basic structure
19796 + *
19797 + */
19798 +
19799 +#include <linux/init.h>
19800 +
19801 +int    vserver_register_sysctl(void);
19802 +void   vserver_unregister_sysctl(void);
19803 +
19804 +
19805 +static int __init init_vserver(void)
19806 +{
19807 +       int ret = 0;
19808 +
19809 +#ifdef CONFIG_VSERVER_DEBUG
19810 +       vserver_register_sysctl();
19811 +#endif
19812 +       return ret;
19813 +}
19814 +
19815 +
19816 +static void __exit exit_vserver(void)
19817 +{
19818 +
19819 +#ifdef CONFIG_VSERVER_DEBUG
19820 +       vserver_unregister_sysctl();
19821 +#endif
19822 +       return;
19823 +}
19824 +
19825 +/* FIXME: GFP_ZONETYPES gone
19826 +long vx_slab[GFP_ZONETYPES]; */
19827 +long vx_area;
19828 +
19829 +
19830 +module_init(init_vserver);
19831 +module_exit(exit_vserver);
19832 +
19833 diff -NurpP --minimal linux-2.6.33/kernel/vserver/inode.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/inode.c
19834 --- linux-2.6.33/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
19835 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/inode.c   2010-02-25 12:02:16.000000000 +0100
19836 @@ -0,0 +1,433 @@
19837 +/*
19838 + *  linux/kernel/vserver/inode.c
19839 + *
19840 + *  Virtual Server: File System Support
19841 + *
19842 + *  Copyright (C) 2004-2007  Herbert Pötzl
19843 + *
19844 + *  V0.01  separated from vcontext V0.05
19845 + *  V0.02  moved to tag (instead of xid)
19846 + *
19847 + */
19848 +
19849 +#include <linux/tty.h>
19850 +#include <linux/proc_fs.h>
19851 +#include <linux/devpts_fs.h>
19852 +#include <linux/fs.h>
19853 +#include <linux/file.h>
19854 +#include <linux/mount.h>
19855 +#include <linux/parser.h>
19856 +#include <linux/namei.h>
19857 +#include <linux/vserver/inode.h>
19858 +#include <linux/vserver/inode_cmd.h>
19859 +#include <linux/vs_base.h>
19860 +#include <linux/vs_tag.h>
19861 +
19862 +#include <asm/uaccess.h>
19863 +
19864 +
19865 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19866 +{
19867 +       struct proc_dir_entry *entry;
19868 +
19869 +       if (!in || !in->i_sb)
19870 +               return -ESRCH;
19871 +
19872 +       *flags = IATTR_TAG
19873 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19874 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19875 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19876 +               | (IS_COW(in) ? IATTR_COW : 0);
19877 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19878 +
19879 +       if (S_ISDIR(in->i_mode))
19880 +               *mask |= IATTR_BARRIER;
19881 +
19882 +       if (IS_TAGGED(in)) {
19883 +               *tag = in->i_tag;
19884 +               *mask |= IATTR_TAG;
19885 +       }
19886 +
19887 +       switch (in->i_sb->s_magic) {
19888 +       case PROC_SUPER_MAGIC:
19889 +               entry = PROC_I(in)->pde;
19890 +
19891 +               /* check for specific inodes? */
19892 +               if (entry)
19893 +                       *mask |= IATTR_FLAGS;
19894 +               if (entry)
19895 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19896 +               else
19897 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19898 +               break;
19899 +
19900 +       case DEVPTS_SUPER_MAGIC:
19901 +               *tag = in->i_tag;
19902 +               *mask |= IATTR_TAG;
19903 +               break;
19904 +
19905 +       default:
19906 +               break;
19907 +       }
19908 +       return 0;
19909 +}
19910 +
19911 +int vc_get_iattr(void __user *data)
19912 +{
19913 +       struct path path;
19914 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19915 +       int ret;
19916 +
19917 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19918 +               return -EFAULT;
19919 +
19920 +       ret = user_lpath(vc_data.name, &path);
19921 +       if (!ret) {
19922 +               ret = __vc_get_iattr(path.dentry->d_inode,
19923 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19924 +               path_put(&path);
19925 +       }
19926 +       if (ret)
19927 +               return ret;
19928 +
19929 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19930 +               ret = -EFAULT;
19931 +       return ret;
19932 +}
19933 +
19934 +#ifdef CONFIG_COMPAT
19935 +
19936 +int vc_get_iattr_x32(void __user *data)
19937 +{
19938 +       struct path path;
19939 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19940 +       int ret;
19941 +
19942 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19943 +               return -EFAULT;
19944 +
19945 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19946 +       if (!ret) {
19947 +               ret = __vc_get_iattr(path.dentry->d_inode,
19948 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19949 +               path_put(&path);
19950 +       }
19951 +       if (ret)
19952 +               return ret;
19953 +
19954 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19955 +               ret = -EFAULT;
19956 +       return ret;
19957 +}
19958 +
19959 +#endif /* CONFIG_COMPAT */
19960 +
19961 +
19962 +int vc_fget_iattr(uint32_t fd, void __user *data)
19963 +{
19964 +       struct file *filp;
19965 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19966 +       int ret;
19967 +
19968 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19969 +               return -EFAULT;
19970 +
19971 +       filp = fget(fd);
19972 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19973 +               return -EBADF;
19974 +
19975 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19976 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19977 +
19978 +       fput(filp);
19979 +
19980 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19981 +               ret = -EFAULT;
19982 +       return ret;
19983 +}
19984 +
19985 +
19986 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19987 +{
19988 +       struct inode *in = de->d_inode;
19989 +       int error = 0, is_proc = 0, has_tag = 0;
19990 +       struct iattr attr = { 0 };
19991 +
19992 +       if (!in || !in->i_sb)
19993 +               return -ESRCH;
19994 +
19995 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19996 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19997 +               return -EINVAL;
19998 +
19999 +       has_tag = IS_TAGGED(in) ||
20000 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20001 +       if ((*mask & IATTR_TAG) && !has_tag)
20002 +               return -EINVAL;
20003 +
20004 +       mutex_lock(&in->i_mutex);
20005 +       if (*mask & IATTR_TAG) {
20006 +               attr.ia_tag = *tag;
20007 +               attr.ia_valid |= ATTR_TAG;
20008 +       }
20009 +
20010 +       if (*mask & IATTR_FLAGS) {
20011 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20012 +               unsigned int iflags = PROC_I(in)->vx_flags;
20013 +
20014 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20015 +                       | (*flags & IATTR_FLAGS);
20016 +               PROC_I(in)->vx_flags = iflags;
20017 +               if (entry)
20018 +                       entry->vx_flags = iflags;
20019 +       }
20020 +
20021 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
20022 +               IATTR_BARRIER | IATTR_COW)) {
20023 +               int iflags = in->i_flags;
20024 +               int vflags = in->i_vflags;
20025 +
20026 +               if (*mask & IATTR_IMMUTABLE) {
20027 +                       if (*flags & IATTR_IMMUTABLE)
20028 +                               iflags |= S_IMMUTABLE;
20029 +                       else
20030 +                               iflags &= ~S_IMMUTABLE;
20031 +               }
20032 +               if (*mask & IATTR_IXUNLINK) {
20033 +                       if (*flags & IATTR_IXUNLINK)
20034 +                               iflags |= S_IXUNLINK;
20035 +                       else
20036 +                               iflags &= ~S_IXUNLINK;
20037 +               }
20038 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20039 +                       if (*flags & IATTR_BARRIER)
20040 +                               vflags |= V_BARRIER;
20041 +                       else
20042 +                               vflags &= ~V_BARRIER;
20043 +               }
20044 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
20045 +                       if (*flags & IATTR_COW)
20046 +                               vflags |= V_COW;
20047 +                       else
20048 +                               vflags &= ~V_COW;
20049 +               }
20050 +               if (in->i_op && in->i_op->sync_flags) {
20051 +                       error = in->i_op->sync_flags(in, iflags, vflags);
20052 +                       if (error)
20053 +                               goto out;
20054 +               }
20055 +       }
20056 +
20057 +       if (attr.ia_valid) {
20058 +               if (in->i_op && in->i_op->setattr)
20059 +                       error = in->i_op->setattr(de, &attr);
20060 +               else {
20061 +                       error = inode_change_ok(in, &attr);
20062 +                       if (!error)
20063 +                               error = inode_setattr(in, &attr);
20064 +               }
20065 +       }
20066 +
20067 +out:
20068 +       mutex_unlock(&in->i_mutex);
20069 +       return error;
20070 +}
20071 +
20072 +int vc_set_iattr(void __user *data)
20073 +{
20074 +       struct path path;
20075 +       struct vcmd_ctx_iattr_v1 vc_data;
20076 +       int ret;
20077 +
20078 +       if (!capable(CAP_LINUX_IMMUTABLE))
20079 +               return -EPERM;
20080 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20081 +               return -EFAULT;
20082 +
20083 +       ret = user_lpath(vc_data.name, &path);
20084 +       if (!ret) {
20085 +               ret = __vc_set_iattr(path.dentry,
20086 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20087 +               path_put(&path);
20088 +       }
20089 +
20090 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20091 +               ret = -EFAULT;
20092 +       return ret;
20093 +}
20094 +
20095 +#ifdef CONFIG_COMPAT
20096 +
20097 +int vc_set_iattr_x32(void __user *data)
20098 +{
20099 +       struct path path;
20100 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20101 +       int ret;
20102 +
20103 +       if (!capable(CAP_LINUX_IMMUTABLE))
20104 +               return -EPERM;
20105 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20106 +               return -EFAULT;
20107 +
20108 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20109 +       if (!ret) {
20110 +               ret = __vc_set_iattr(path.dentry,
20111 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20112 +               path_put(&path);
20113 +       }
20114 +
20115 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20116 +               ret = -EFAULT;
20117 +       return ret;
20118 +}
20119 +
20120 +#endif /* CONFIG_COMPAT */
20121 +
20122 +int vc_fset_iattr(uint32_t fd, void __user *data)
20123 +{
20124 +       struct file *filp;
20125 +       struct vcmd_ctx_fiattr_v0 vc_data;
20126 +       int ret;
20127 +
20128 +       if (!capable(CAP_LINUX_IMMUTABLE))
20129 +               return -EPERM;
20130 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20131 +               return -EFAULT;
20132 +
20133 +       filp = fget(fd);
20134 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20135 +               return -EBADF;
20136 +
20137 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20138 +               &vc_data.flags, &vc_data.mask);
20139 +
20140 +       fput(filp);
20141 +
20142 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20143 +               return -EFAULT;
20144 +       return ret;
20145 +}
20146 +
20147 +
20148 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20149 +
20150 +static match_table_t tokens = {
20151 +       {Opt_notagcheck, "notagcheck"},
20152 +#ifdef CONFIG_PROPAGATE
20153 +       {Opt_notag, "notag"},
20154 +       {Opt_tag, "tag"},
20155 +       {Opt_tagid, "tagid=%u"},
20156 +#endif
20157 +       {Opt_err, NULL}
20158 +};
20159 +
20160 +
20161 +static void __dx_parse_remove(char *string, char *opt)
20162 +{
20163 +       char *p = strstr(string, opt);
20164 +       char *q = p;
20165 +
20166 +       if (p) {
20167 +               while (*q != '\0' && *q != ',')
20168 +                       q++;
20169 +               while (*q)
20170 +                       *p++ = *q++;
20171 +               while (*p)
20172 +                       *p++ = '\0';
20173 +       }
20174 +}
20175 +
20176 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20177 +                unsigned long *flags)
20178 +{
20179 +       int set = 0;
20180 +       substring_t args[MAX_OPT_ARGS];
20181 +       int token, option = 0;
20182 +       char *s, *p, *opts;
20183 +
20184 +       if (!string)
20185 +               return 0;
20186 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20187 +       if (!s)
20188 +               return 0;
20189 +
20190 +       opts = s;
20191 +       while ((p = strsep(&opts, ",")) != NULL) {
20192 +               token = match_token(p, tokens, args);
20193 +
20194 +               vxdprintk(VXD_CBIT(tag, 7),
20195 +                       "dx_parse_tag(»%s«): %d:#%d",
20196 +                       p, token, option);
20197 +
20198 +               switch (token) {
20199 +#ifdef CONFIG_PROPAGATE
20200 +               case Opt_tag:
20201 +                       if (tag)
20202 +                               *tag = 0;
20203 +                       if (remove)
20204 +                               __dx_parse_remove(s, "tag");
20205 +                       *mnt_flags |= MNT_TAGID;
20206 +                       set |= MNT_TAGID;
20207 +                       break;
20208 +               case Opt_notag:
20209 +                       if (remove)
20210 +                               __dx_parse_remove(s, "notag");
20211 +                       *mnt_flags |= MNT_NOTAG;
20212 +                       set |= MNT_NOTAG;
20213 +                       break;
20214 +               case Opt_tagid:
20215 +                       if (tag && !match_int(args, &option))
20216 +                               *tag = option;
20217 +                       if (remove)
20218 +                               __dx_parse_remove(s, "tagid");
20219 +                       *mnt_flags |= MNT_TAGID;
20220 +                       set |= MNT_TAGID;
20221 +                       break;
20222 +#endif
20223 +               case Opt_notagcheck:
20224 +                       if (remove)
20225 +                               __dx_parse_remove(s, "notagcheck");
20226 +                       *flags |= MS_NOTAGCHECK;
20227 +                       set |= MS_NOTAGCHECK;
20228 +                       break;
20229 +               }
20230 +       }
20231 +       if (set)
20232 +               strcpy(string, s);
20233 +       kfree(s);
20234 +       return set;
20235 +}
20236 +
20237 +#ifdef CONFIG_PROPAGATE
20238 +
20239 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20240 +{
20241 +       tag_t new_tag = 0;
20242 +       struct vfsmount *mnt;
20243 +       int propagate;
20244 +
20245 +       if (!nd)
20246 +               return;
20247 +       mnt = nd->path.mnt;
20248 +       if (!mnt)
20249 +               return;
20250 +
20251 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20252 +       if (propagate)
20253 +               new_tag = mnt->mnt_tag;
20254 +
20255 +       vxdprintk(VXD_CBIT(tag, 7),
20256 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20257 +               inode, inode->i_ino, inode->i_tag,
20258 +               new_tag, (propagate) ? 1 : 0);
20259 +
20260 +       if (propagate)
20261 +               inode->i_tag = new_tag;
20262 +}
20263 +
20264 +#include <linux/module.h>
20265 +
20266 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20267 +
20268 +#endif /* CONFIG_PROPAGATE */
20269 +
20270 diff -NurpP --minimal linux-2.6.33/kernel/vserver/Kconfig linux-2.6.33-vs2.3.0.36.30/kernel/vserver/Kconfig
20271 --- linux-2.6.33/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
20272 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/Kconfig   2010-02-25 12:02:16.000000000 +0100
20273 @@ -0,0 +1,251 @@
20274 +#
20275 +# Linux VServer configuration
20276 +#
20277 +
20278 +menu "Linux VServer"
20279 +
20280 +config VSERVER_AUTO_LBACK
20281 +       bool    "Automatically Assign Loopback IP"
20282 +       default y
20283 +       help
20284 +         Automatically assign a guest specific loopback
20285 +         IP and add it to the kernel network stack on
20286 +         startup.
20287 +
20288 +config VSERVER_AUTO_SINGLE
20289 +       bool    "Automatic Single IP Special Casing"
20290 +       depends on EXPERIMENTAL
20291 +       default y
20292 +       help
20293 +         This allows network contexts with a single IP to
20294 +         automatically remap 0.0.0.0 bindings to that IP,
20295 +         avoiding further network checks and improving
20296 +         performance.
20297 +
20298 +         (note: such guests do not allow to change the ip
20299 +          on the fly and do not show loopback addresses)
20300 +
20301 +config VSERVER_COWBL
20302 +       bool    "Enable COW Immutable Link Breaking"
20303 +       default y
20304 +       help
20305 +         This enables the COW (Copy-On-Write) link break code.
20306 +         It allows you to treat unified files like normal files
20307 +         when writing to them (which will implicitely break the
20308 +         link and create a copy of the unified file)
20309 +
20310 +config VSERVER_VTIME
20311 +       bool    "Enable Virtualized Guest Time"
20312 +       depends on EXPERIMENTAL
20313 +       default n
20314 +       help
20315 +         This enables per guest time offsets to allow for
20316 +         adjusting the system clock individually per guest.
20317 +         this adds some overhead to the time functions and
20318 +         therefore should not be enabled without good reason.
20319 +
20320 +config VSERVER_DEVICE
20321 +       bool    "Enable Guest Device Mapping"
20322 +       depends on EXPERIMENTAL
20323 +       default n
20324 +       help
20325 +         This enables generic device remapping.
20326 +
20327 +config VSERVER_PROC_SECURE
20328 +       bool    "Enable Proc Security"
20329 +       depends on PROC_FS
20330 +       default y
20331 +       help
20332 +         This configures ProcFS security to initially hide
20333 +         non-process entries for all contexts except the main and
20334 +         spectator context (i.e. for all guests), which is a secure
20335 +         default.
20336 +
20337 +         (note: on 1.2x the entries were visible by default)
20338 +
20339 +config VSERVER_HARDCPU
20340 +       bool    "Enable Hard CPU Limits"
20341 +       default y
20342 +       help
20343 +         Activate the Hard CPU Limits
20344 +
20345 +         This will compile in code that allows the Token Bucket
20346 +         Scheduler to put processes on hold when a context's
20347 +         tokens are depleted (provided that its per-context
20348 +         sched_hard flag is set).
20349 +
20350 +         Processes belonging to that context will not be able
20351 +         to consume CPU resources again until a per-context
20352 +         configured minimum of tokens has been reached.
20353 +
20354 +config VSERVER_IDLETIME
20355 +       bool    "Avoid idle CPUs by skipping Time"
20356 +       depends on VSERVER_HARDCPU
20357 +       default y
20358 +       help
20359 +         This option allows the scheduler to artificially
20360 +         advance time (per cpu) when otherwise the idle
20361 +         task would be scheduled, thus keeping the cpu
20362 +         busy and sharing the available resources among
20363 +         certain contexts.
20364 +
20365 +config VSERVER_IDLELIMIT
20366 +       bool    "Limit the IDLE task"
20367 +       depends on VSERVER_HARDCPU
20368 +       default n
20369 +       help
20370 +         Limit the idle slices, so the the next context
20371 +         will be scheduled as soon as possible.
20372 +
20373 +         This might improve interactivity and latency, but
20374 +         will also marginally increase scheduling overhead.
20375 +
20376 +choice
20377 +       prompt  "Persistent Inode Tagging"
20378 +       default TAGGING_ID24
20379 +       help
20380 +         This adds persistent context information to filesystems
20381 +         mounted with the tagxid option. Tagging is a requirement
20382 +         for per-context disk limits and per-context quota.
20383 +
20384 +
20385 +config TAGGING_NONE
20386 +       bool    "Disabled"
20387 +       help
20388 +         do not store per-context information in inodes.
20389 +
20390 +config TAGGING_UID16
20391 +       bool    "UID16/GID32"
20392 +       help
20393 +         reduces UID to 16 bit, but leaves GID at 32 bit.
20394 +
20395 +config TAGGING_GID16
20396 +       bool    "UID32/GID16"
20397 +       help
20398 +         reduces GID to 16 bit, but leaves UID at 32 bit.
20399 +
20400 +config TAGGING_ID24
20401 +       bool    "UID24/GID24"
20402 +       help
20403 +         uses the upper 8bit from UID and GID for XID tagging
20404 +         which leaves 24bit for UID/GID each, which should be
20405 +         more than sufficient for normal use.
20406 +
20407 +config TAGGING_INTERN
20408 +       bool    "UID32/GID32"
20409 +       help
20410 +         this uses otherwise reserved inode fields in the on
20411 +         disk representation, which limits the use to a few
20412 +         filesystems (currently ext2 and ext3)
20413 +
20414 +endchoice
20415 +
20416 +config TAG_NFSD
20417 +       bool    "Tag NFSD User Auth and Files"
20418 +       default n
20419 +       help
20420 +         Enable this if you do want the in-kernel NFS
20421 +         Server to use the tagging specified above.
20422 +         (will require patched clients too)
20423 +
20424 +config VSERVER_PRIVACY
20425 +       bool    "Honor Privacy Aspects of Guests"
20426 +       default n
20427 +       help
20428 +         When enabled, most context checks will disallow
20429 +         access to structures assigned to a specific context,
20430 +         like ptys or loop devices.
20431 +
20432 +config VSERVER_CONTEXTS
20433 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
20434 +       range 1 65533
20435 +       default "768"   if 64BIT
20436 +       default "256"
20437 +       help
20438 +         This setting will optimize certain data structures
20439 +         and memory allocations according to the expected
20440 +         maximum.
20441 +
20442 +         note: this is not a strict upper limit.
20443 +
20444 +config VSERVER_WARN
20445 +       bool    "VServer Warnings"
20446 +       default y
20447 +       help
20448 +         This enables various runtime warnings, which will
20449 +         notify about potential manipulation attempts or
20450 +         resource shortage. It is generally considered to
20451 +         be a good idea to have that enabled.
20452 +
20453 +config VSERVER_DEBUG
20454 +       bool    "VServer Debugging Code"
20455 +       default n
20456 +       help
20457 +         Set this to yes if you want to be able to activate
20458 +         debugging output at runtime. It adds a very small
20459 +         overhead to all vserver related functions and
20460 +         increases the kernel size by about 20k.
20461 +
20462 +config VSERVER_HISTORY
20463 +       bool    "VServer History Tracing"
20464 +       depends on VSERVER_DEBUG
20465 +       default n
20466 +       help
20467 +         Set this to yes if you want to record the history of
20468 +         linux-vserver activities, so they can be replayed in
20469 +         the event of a kernel panic or oops.
20470 +
20471 +config VSERVER_HISTORY_SIZE
20472 +       int     "Per-CPU History Size (32-65536)"
20473 +       depends on VSERVER_HISTORY
20474 +       range 32 65536
20475 +       default 64
20476 +       help
20477 +         This allows you to specify the number of entries in
20478 +         the per-CPU history buffer.
20479 +
20480 +config VSERVER_MONITOR
20481 +       bool    "VServer Scheduling Monitor"
20482 +       depends on VSERVER_DISABLED
20483 +       default n
20484 +       help
20485 +         Set this to yes if you want to record the scheduling
20486 +         decisions, so that they can be relayed to userspace
20487 +         for detailed analysis.
20488 +
20489 +config VSERVER_MONITOR_SIZE
20490 +       int     "Per-CPU Monitor Queue Size (32-65536)"
20491 +       depends on VSERVER_MONITOR
20492 +       range 32 65536
20493 +       default 1024
20494 +       help
20495 +         This allows you to specify the number of entries in
20496 +         the per-CPU scheduling monitor buffer.
20497 +
20498 +config VSERVER_MONITOR_SYNC
20499 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
20500 +       depends on VSERVER_MONITOR
20501 +       range 0 65536
20502 +       default 256
20503 +       help
20504 +         This allows you to specify the interval in ticks
20505 +         when a time sync entry is inserted.
20506 +
20507 +endmenu
20508 +
20509 +
20510 +config VSERVER
20511 +       bool
20512 +       default y
20513 +       select NAMESPACES
20514 +       select UTS_NS
20515 +       select IPC_NS
20516 +       select USER_NS
20517 +       select SYSVIPC
20518 +
20519 +config VSERVER_SECURITY
20520 +       bool
20521 +       depends on SECURITY
20522 +       default y
20523 +       select SECURITY_CAPABILITIES
20524 +
20525 diff -NurpP --minimal linux-2.6.33/kernel/vserver/limit.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/limit.c
20526 --- linux-2.6.33/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
20527 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/limit.c   2010-02-25 12:02:16.000000000 +0100
20528 @@ -0,0 +1,387 @@
20529 +/*
20530 + *  linux/kernel/vserver/limit.c
20531 + *
20532 + *  Virtual Server: Context Limits
20533 + *
20534 + *  Copyright (C) 2004-2010  Herbert Pötzl
20535 + *
20536 + *  V0.01  broken out from vcontext V0.05
20537 + *  V0.02  changed vcmds to vxi arg
20538 + *  V0.03  added memory cgroup support
20539 + *
20540 + */
20541 +
20542 +#include <linux/sched.h>
20543 +#include <linux/module.h>
20544 +#include <linux/memcontrol.h>
20545 +#include <linux/res_counter.h>
20546 +#include <linux/vs_limit.h>
20547 +#include <linux/vserver/limit.h>
20548 +#include <linux/vserver/limit_cmd.h>
20549 +
20550 +#include <asm/uaccess.h>
20551 +
20552 +
20553 +const char *vlimit_name[NUM_LIMITS] = {
20554 +       [RLIMIT_CPU]            = "CPU",
20555 +       [RLIMIT_RSS]            = "RSS",
20556 +       [RLIMIT_NPROC]          = "NPROC",
20557 +       [RLIMIT_NOFILE]         = "NOFILE",
20558 +       [RLIMIT_MEMLOCK]        = "VML",
20559 +       [RLIMIT_AS]             = "VM",
20560 +       [RLIMIT_LOCKS]          = "LOCKS",
20561 +       [RLIMIT_SIGPENDING]     = "SIGP",
20562 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20563 +
20564 +       [VLIMIT_NSOCK]          = "NSOCK",
20565 +       [VLIMIT_OPENFD]         = "OPENFD",
20566 +       [VLIMIT_ANON]           = "ANON",
20567 +       [VLIMIT_SHMEM]          = "SHMEM",
20568 +       [VLIMIT_DENTRY]         = "DENTRY",
20569 +};
20570 +
20571 +EXPORT_SYMBOL_GPL(vlimit_name);
20572 +
20573 +#define MASK_ENTRY(x)  (1 << (x))
20574 +
20575 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20576 +               /* minimum */
20577 +       0
20578 +       ,       /* softlimit */
20579 +       MASK_ENTRY( RLIMIT_RSS          ) |
20580 +       MASK_ENTRY( VLIMIT_ANON         ) |
20581 +       0
20582 +       ,       /* maximum */
20583 +       MASK_ENTRY( RLIMIT_RSS          ) |
20584 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20585 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20586 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
20587 +       MASK_ENTRY( RLIMIT_AS           ) |
20588 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20589 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20590 +
20591 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20592 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20593 +       MASK_ENTRY( VLIMIT_ANON         ) |
20594 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20595 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20596 +       0
20597 +};
20598 +               /* accounting only */
20599 +uint32_t account_mask =
20600 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20601 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20602 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20603 +       0;
20604 +
20605 +
20606 +static int is_valid_vlimit(int id)
20607 +{
20608 +       uint32_t mask = vlimit_mask.minimum |
20609 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20610 +       return mask & (1 << id);
20611 +}
20612 +
20613 +static int is_accounted_vlimit(int id)
20614 +{
20615 +       if (is_valid_vlimit(id))
20616 +               return 1;
20617 +       return account_mask & (1 << id);
20618 +}
20619 +
20620 +
20621 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20622 +{
20623 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20624 +       return VX_VLIM(limit);
20625 +}
20626 +
20627 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20628 +{
20629 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20630 +       return VX_VLIM(limit);
20631 +}
20632 +
20633 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20634 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20635 +{
20636 +       if (!is_valid_vlimit(id))
20637 +               return -EINVAL;
20638 +
20639 +       if (minimum)
20640 +               *minimum = CRLIM_UNSET;
20641 +       if (softlimit)
20642 +               *softlimit = vc_get_soft(vxi, id);
20643 +       if (maximum)
20644 +               *maximum = vc_get_hard(vxi, id);
20645 +       return 0;
20646 +}
20647 +
20648 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20649 +{
20650 +       struct vcmd_ctx_rlimit_v0 vc_data;
20651 +       int ret;
20652 +
20653 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20654 +               return -EFAULT;
20655 +
20656 +       ret = do_get_rlimit(vxi, vc_data.id,
20657 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20658 +       if (ret)
20659 +               return ret;
20660 +
20661 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20662 +               return -EFAULT;
20663 +       return 0;
20664 +}
20665 +
20666 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20667 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20668 +{
20669 +       if (!is_valid_vlimit(id))
20670 +               return -EINVAL;
20671 +
20672 +       if (maximum != CRLIM_KEEP)
20673 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20674 +       if (softlimit != CRLIM_KEEP)
20675 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20676 +
20677 +       /* clamp soft limit */
20678 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20679 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20680 +
20681 +       return 0;
20682 +}
20683 +
20684 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20685 +{
20686 +       struct vcmd_ctx_rlimit_v0 vc_data;
20687 +
20688 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20689 +               return -EFAULT;
20690 +
20691 +       return do_set_rlimit(vxi, vc_data.id,
20692 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20693 +}
20694 +
20695 +#ifdef CONFIG_IA32_EMULATION
20696 +
20697 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20698 +{
20699 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20700 +
20701 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20702 +               return -EFAULT;
20703 +
20704 +       return do_set_rlimit(vxi, vc_data.id,
20705 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20706 +}
20707 +
20708 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20709 +{
20710 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20711 +       int ret;
20712 +
20713 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20714 +               return -EFAULT;
20715 +
20716 +       ret = do_get_rlimit(vxi, vc_data.id,
20717 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20718 +       if (ret)
20719 +               return ret;
20720 +
20721 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20722 +               return -EFAULT;
20723 +       return 0;
20724 +}
20725 +
20726 +#endif /* CONFIG_IA32_EMULATION */
20727 +
20728 +
20729 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20730 +{
20731 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20732 +               return -EFAULT;
20733 +       return 0;
20734 +}
20735 +
20736 +
20737 +static inline void vx_reset_hits(struct _vx_limit *limit)
20738 +{
20739 +       int lim;
20740 +
20741 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20742 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20743 +       }
20744 +}
20745 +
20746 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20747 +{
20748 +       vx_reset_hits(&vxi->limit);
20749 +       return 0;
20750 +}
20751 +
20752 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20753 +{
20754 +       rlim_t value;
20755 +       int lim;
20756 +
20757 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20758 +               value = __rlim_get(limit, lim);
20759 +               __rlim_rmax(limit, lim) = value;
20760 +               __rlim_rmin(limit, lim) = value;
20761 +       }
20762 +}
20763 +
20764 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20765 +{
20766 +       vx_reset_minmax(&vxi->limit);
20767 +       return 0;
20768 +}
20769 +
20770 +
20771 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20772 +{
20773 +       struct vcmd_rlimit_stat_v0 vc_data;
20774 +       struct _vx_limit *limit = &vxi->limit;
20775 +       int id;
20776 +
20777 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20778 +               return -EFAULT;
20779 +
20780 +       id = vc_data.id;
20781 +       if (!is_accounted_vlimit(id))
20782 +               return -EINVAL;
20783 +
20784 +       vx_limit_fixup(limit, id);
20785 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20786 +       vc_data.value = __rlim_get(limit, id);
20787 +       vc_data.minimum = __rlim_rmin(limit, id);
20788 +       vc_data.maximum = __rlim_rmax(limit, id);
20789 +
20790 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20791 +               return -EFAULT;
20792 +       return 0;
20793 +}
20794 +
20795 +
20796 +void vx_vsi_meminfo(struct sysinfo *val)
20797 +{
20798 +#ifdef CGROUP_MEM_RES_CTLR
20799 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20800 +       u64 res_limit, res_usage;
20801 +
20802 +       if (!mcg)
20803 +               return;
20804 +
20805 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20806 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20807 +
20808 +       if (res_limit != RESOURCE_MAX)
20809 +               val->totalram = (res_limit >> PAGE_SHIFT);
20810 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20811 +       val->bufferram = 0;
20812 +#else
20813 +       struct vx_info *vxi = current_vx_info();
20814 +       unsigned long totalram, freeram;
20815 +       rlim_t v;
20816 +
20817 +       /* we blindly accept the max */
20818 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20819 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
20820 +
20821 +       /* total minus used equals free */
20822 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20823 +       freeram = (v < totalram) ? totalram - v : 0;
20824 +
20825 +       val->totalram = totalram;
20826 +       val->freeram = freeram;
20827 +#endif
20828 +       val->totalhigh = 0;
20829 +       val->freehigh = 0;
20830 +       return;
20831 +}
20832 +
20833 +void vx_vsi_swapinfo(struct sysinfo *val)
20834 +{
20835 +#ifdef CGROUP_MEM_RES_CTLR_SWAP
20836 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20837 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20838 +       s64 swap_limit, swap_usage;
20839 +
20840 +       if (!mcg)
20841 +               return;
20842 +
20843 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20844 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20845 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20846 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20847 +
20848 +       if (res_limit == RESOURCE_MAX)
20849 +               return;
20850 +
20851 +       swap_limit = memsw_limit - res_limit;
20852 +       if (memsw_limit != RESOURCE_MAX)
20853 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20854 +
20855 +       swap_usage = memsw_usage - res_usage;
20856 +       val->freeswap = (swap_usage < swap_limit) ?
20857 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20858 +#else
20859 +       struct vx_info *vxi = current_vx_info();
20860 +       unsigned long totalswap, freeswap;
20861 +       rlim_t v, w;
20862 +
20863 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20864 +       if (v == RLIM_INFINITY) {
20865 +               val->freeswap = val->totalswap;
20866 +               return;
20867 +       }
20868 +
20869 +       /* we blindly accept the max */
20870 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
20871 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
20872 +
20873 +       /* currently 'used' swap */
20874 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20875 +       w -= (w > v) ? v : w;
20876 +
20877 +       /* total minus used equals free */
20878 +       freeswap = (w < totalswap) ? totalswap - w : 0;
20879 +
20880 +       val->totalswap = totalswap;
20881 +       val->freeswap = freeswap;
20882 +#endif
20883 +       return;
20884 +}
20885 +
20886 +long vx_vsi_cached(struct sysinfo *val)
20887 +{
20888 +#ifdef CGROUP_MEM_RES_CTLR
20889 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20890 +
20891 +       return mem_cgroup_stat_read_cache(mcg);
20892 +#else
20893 +       return 0;
20894 +#endif
20895 +}
20896 +
20897 +
20898 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20899 +{
20900 +       struct vx_info *vxi = mm->mm_vx_info;
20901 +       unsigned long points;
20902 +       rlim_t v, w;
20903 +
20904 +       if (!vxi)
20905 +               return 0;
20906 +
20907 +       points = vxi->vx_badness_bias;
20908 +
20909 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20910 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20911 +       points += (v > w) ? (v - w) : 0;
20912 +
20913 +       return points;
20914 +}
20915 +
20916 diff -NurpP --minimal linux-2.6.33/kernel/vserver/limit_init.h linux-2.6.33-vs2.3.0.36.30/kernel/vserver/limit_init.h
20917 --- linux-2.6.33/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
20918 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/limit_init.h      2010-02-25 12:02:16.000000000 +0100
20919 @@ -0,0 +1,31 @@
20920 +
20921 +
20922 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20923 +{
20924 +       int lim;
20925 +
20926 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20927 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20928 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20929 +               __rlim_set(limit, lim, 0);
20930 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20931 +               __rlim_rmin(limit, lim) = 0;
20932 +               __rlim_rmax(limit, lim) = 0;
20933 +       }
20934 +}
20935 +
20936 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20937 +{
20938 +       rlim_t value;
20939 +       int lim;
20940 +
20941 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20942 +               if ((1 << lim) & VLIM_NOCHECK)
20943 +                       continue;
20944 +               value = __rlim_get(limit, lim);
20945 +               vxwprintk_xid(value,
20946 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20947 +                       limit, vlimit_name[lim], lim, (long)value);
20948 +       }
20949 +}
20950 +
20951 diff -NurpP --minimal linux-2.6.33/kernel/vserver/limit_proc.h linux-2.6.33-vs2.3.0.36.30/kernel/vserver/limit_proc.h
20952 --- linux-2.6.33/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
20953 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/limit_proc.h      2010-02-25 12:02:16.000000000 +0100
20954 @@ -0,0 +1,57 @@
20955 +#ifndef _VX_LIMIT_PROC_H
20956 +#define _VX_LIMIT_PROC_H
20957 +
20958 +#include <linux/vserver/limit_int.h>
20959 +
20960 +
20961 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20962 +#define VX_LIMIT_TOP   \
20963 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20964 +
20965 +#define VX_LIMIT_ARG(r)                                \
20966 +       (unsigned long)__rlim_get(limit, r),    \
20967 +       (unsigned long)__rlim_rmin(limit, r),   \
20968 +       (unsigned long)__rlim_rmax(limit, r),   \
20969 +       VX_VLIM(__rlim_soft(limit, r)),         \
20970 +       VX_VLIM(__rlim_hard(limit, r)),         \
20971 +       atomic_read(&__rlim_lhit(limit, r))
20972 +
20973 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20974 +{
20975 +       vx_limit_fixup(limit, -1);
20976 +       return sprintf(buffer, VX_LIMIT_TOP
20977 +               "PROC"  VX_LIMIT_FMT
20978 +               "VM"    VX_LIMIT_FMT
20979 +               "VML"   VX_LIMIT_FMT
20980 +               "RSS"   VX_LIMIT_FMT
20981 +               "ANON"  VX_LIMIT_FMT
20982 +               "RMAP"  VX_LIMIT_FMT
20983 +               "FILES" VX_LIMIT_FMT
20984 +               "OFD"   VX_LIMIT_FMT
20985 +               "LOCKS" VX_LIMIT_FMT
20986 +               "SOCK"  VX_LIMIT_FMT
20987 +               "MSGQ"  VX_LIMIT_FMT
20988 +               "SHM"   VX_LIMIT_FMT
20989 +               "SEMA"  VX_LIMIT_FMT
20990 +               "SEMS"  VX_LIMIT_FMT
20991 +               "DENT"  VX_LIMIT_FMT,
20992 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20993 +               VX_LIMIT_ARG(RLIMIT_AS),
20994 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20995 +               VX_LIMIT_ARG(RLIMIT_RSS),
20996 +               VX_LIMIT_ARG(VLIMIT_ANON),
20997 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20998 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20999 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21000 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21001 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21002 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21003 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21004 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21005 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21006 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21007 +}
21008 +
21009 +#endif /* _VX_LIMIT_PROC_H */
21010 +
21011 +
21012 diff -NurpP --minimal linux-2.6.33/kernel/vserver/Makefile linux-2.6.33-vs2.3.0.36.30/kernel/vserver/Makefile
21013 --- linux-2.6.33/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
21014 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/Makefile  2010-02-25 12:02:16.000000000 +0100
21015 @@ -0,0 +1,18 @@
21016 +#
21017 +# Makefile for the Linux vserver routines.
21018 +#
21019 +
21020 +
21021 +obj-y          += vserver.o
21022 +
21023 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
21024 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
21025 +                  dlimit.o tag.o
21026 +
21027 +vserver-$(CONFIG_INET) += inet.o
21028 +vserver-$(CONFIG_PROC_FS) += proc.o
21029 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
21030 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
21031 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
21032 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
21033 +
21034 diff -NurpP --minimal linux-2.6.33/kernel/vserver/monitor.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/monitor.c
21035 --- linux-2.6.33/kernel/vserver/monitor.c       1970-01-01 01:00:00.000000000 +0100
21036 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/monitor.c 2010-02-25 12:02:16.000000000 +0100
21037 @@ -0,0 +1,138 @@
21038 +/*
21039 + *  kernel/vserver/monitor.c
21040 + *
21041 + *  Virtual Context Scheduler Monitor
21042 + *
21043 + *  Copyright (C) 2006-2007 Herbert Pötzl
21044 + *
21045 + *  V0.01  basic design
21046 + *
21047 + */
21048 +
21049 +#include <linux/module.h>
21050 +#include <linux/jiffies.h>
21051 +#include <asm/uaccess.h>
21052 +#include <asm/atomic.h>
21053 +
21054 +#include <linux/vserver/monitor.h>
21055 +#include <linux/vserver/debug_cmd.h>
21056 +
21057 +
21058 +#ifdef CONFIG_VSERVER_MONITOR
21059 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21060 +#else
21061 +#define VXM_SIZE       64
21062 +#endif
21063 +
21064 +struct _vx_monitor {
21065 +       unsigned int counter;
21066 +
21067 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21068 +};
21069 +
21070 +
21071 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21072 +
21073 +unsigned volatile int vxm_active = 1;
21074 +
21075 +static atomic_t sequence = ATOMIC_INIT(0);
21076 +
21077 +
21078 +/*     vxm_advance()
21079 +
21080 +       * requires disabled preemption                          */
21081 +
21082 +struct _vx_mon_entry *vxm_advance(int cpu)
21083 +{
21084 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21085 +       struct _vx_mon_entry *entry;
21086 +       unsigned int index;
21087 +
21088 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21089 +       entry = &mon->entry[index];
21090 +
21091 +       entry->ev.seq = atomic_inc_return(&sequence);
21092 +       entry->ev.jif = jiffies;
21093 +       return entry;
21094 +}
21095 +
21096 +EXPORT_SYMBOL_GPL(vxm_advance);
21097 +
21098 +
21099 +int do_read_monitor(struct __user _vx_mon_entry *data,
21100 +       int cpu, uint32_t *index, uint32_t *count)
21101 +{
21102 +       int pos, ret = 0;
21103 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21104 +       int end = mon->counter;
21105 +       int start = end - VXM_SIZE + 2;
21106 +       int idx = *index;
21107 +
21108 +       /* special case: get current pos */
21109 +       if (!*count) {
21110 +               *index = end;
21111 +               return 0;
21112 +       }
21113 +
21114 +       /* have we lost some data? */
21115 +       if (idx < start)
21116 +               idx = start;
21117 +
21118 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21119 +               struct _vx_mon_entry *entry =
21120 +                       &mon->entry[idx % VXM_SIZE];
21121 +
21122 +               /* send entry to userspace */
21123 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21124 +               if (ret)
21125 +                       break;
21126 +       }
21127 +       /* save new index and count */
21128 +       *index = idx;
21129 +       *count = pos;
21130 +       return ret ? ret : (*index < end);
21131 +}
21132 +
21133 +int vc_read_monitor(uint32_t id, void __user *data)
21134 +{
21135 +       struct vcmd_read_monitor_v0 vc_data;
21136 +       int ret;
21137 +
21138 +       if (id >= NR_CPUS)
21139 +               return -EINVAL;
21140 +
21141 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21142 +               return -EFAULT;
21143 +
21144 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
21145 +               id, &vc_data.index, &vc_data.count);
21146 +
21147 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21148 +               return -EFAULT;
21149 +       return ret;
21150 +}
21151 +
21152 +#ifdef CONFIG_COMPAT
21153 +
21154 +int vc_read_monitor_x32(uint32_t id, void __user *data)
21155 +{
21156 +       struct vcmd_read_monitor_v0_x32 vc_data;
21157 +       int ret;
21158 +
21159 +       if (id >= NR_CPUS)
21160 +               return -EINVAL;
21161 +
21162 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21163 +               return -EFAULT;
21164 +
21165 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
21166 +               compat_ptr(vc_data.data_ptr),
21167 +               id, &vc_data.index, &vc_data.count);
21168 +
21169 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21170 +               return -EFAULT;
21171 +       return ret;
21172 +}
21173 +
21174 +#endif /* CONFIG_COMPAT */
21175 +
21176 diff -NurpP --minimal linux-2.6.33/kernel/vserver/network.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/network.c
21177 --- linux-2.6.33/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
21178 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/network.c 2010-02-25 12:02:16.000000000 +0100
21179 @@ -0,0 +1,864 @@
21180 +/*
21181 + *  linux/kernel/vserver/network.c
21182 + *
21183 + *  Virtual Server: Network Support
21184 + *
21185 + *  Copyright (C) 2003-2007  Herbert Pötzl
21186 + *
21187 + *  V0.01  broken out from vcontext V0.05
21188 + *  V0.02  cleaned up implementation
21189 + *  V0.03  added equiv nx commands
21190 + *  V0.04  switch to RCU based hash
21191 + *  V0.05  and back to locking again
21192 + *  V0.06  changed vcmds to nxi arg
21193 + *  V0.07  have __create claim() the nxi
21194 + *
21195 + */
21196 +
21197 +#include <linux/err.h>
21198 +#include <linux/slab.h>
21199 +#include <linux/rcupdate.h>
21200 +
21201 +#include <linux/vs_network.h>
21202 +#include <linux/vs_pid.h>
21203 +#include <linux/vserver/network_cmd.h>
21204 +
21205 +
21206 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
21207 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
21208 +
21209 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
21210 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
21211 +
21212 +
21213 +static int __init init_network(void)
21214 +{
21215 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
21216 +               sizeof(struct nx_addr_v4), 0,
21217 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21218 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
21219 +               sizeof(struct nx_addr_v6), 0,
21220 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21221 +       return 0;
21222 +}
21223 +
21224 +
21225 +/*     __alloc_nx_addr_v4()                                    */
21226 +
21227 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
21228 +{
21229 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
21230 +               nx_addr_v4_cachep, GFP_KERNEL);
21231 +
21232 +       if (!IS_ERR(nxa))
21233 +               memset(nxa, 0, sizeof(*nxa));
21234 +       return nxa;
21235 +}
21236 +
21237 +/*     __dealloc_nx_addr_v4()                                  */
21238 +
21239 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
21240 +{
21241 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
21242 +}
21243 +
21244 +/*     __dealloc_nx_addr_v4_all()                              */
21245 +
21246 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
21247 +{
21248 +       while (nxa) {
21249 +               struct nx_addr_v4 *next = nxa->next;
21250 +
21251 +               __dealloc_nx_addr_v4(nxa);
21252 +               nxa = next;
21253 +       }
21254 +}
21255 +
21256 +
21257 +#ifdef CONFIG_IPV6
21258 +
21259 +/*     __alloc_nx_addr_v6()                                    */
21260 +
21261 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
21262 +{
21263 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
21264 +               nx_addr_v6_cachep, GFP_KERNEL);
21265 +
21266 +       if (!IS_ERR(nxa))
21267 +               memset(nxa, 0, sizeof(*nxa));
21268 +       return nxa;
21269 +}
21270 +
21271 +/*     __dealloc_nx_addr_v6()                                  */
21272 +
21273 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
21274 +{
21275 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
21276 +}
21277 +
21278 +/*     __dealloc_nx_addr_v6_all()                              */
21279 +
21280 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
21281 +{
21282 +       while (nxa) {
21283 +               struct nx_addr_v6 *next = nxa->next;
21284 +
21285 +               __dealloc_nx_addr_v6(nxa);
21286 +               nxa = next;
21287 +       }
21288 +}
21289 +
21290 +#endif /* CONFIG_IPV6 */
21291 +
21292 +/*     __alloc_nx_info()
21293 +
21294 +       * allocate an initialized nx_info struct
21295 +       * doesn't make it visible (hash)                        */
21296 +
21297 +static struct nx_info *__alloc_nx_info(nid_t nid)
21298 +{
21299 +       struct nx_info *new = NULL;
21300 +
21301 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
21302 +
21303 +       /* would this benefit from a slab cache? */
21304 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
21305 +       if (!new)
21306 +               return 0;
21307 +
21308 +       memset(new, 0, sizeof(struct nx_info));
21309 +       new->nx_id = nid;
21310 +       INIT_HLIST_NODE(&new->nx_hlist);
21311 +       atomic_set(&new->nx_usecnt, 0);
21312 +       atomic_set(&new->nx_tasks, 0);
21313 +       new->nx_state = 0;
21314 +
21315 +       new->nx_flags = NXF_INIT_SET;
21316 +
21317 +       /* rest of init goes here */
21318 +
21319 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
21320 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
21321 +
21322 +       vxdprintk(VXD_CBIT(nid, 0),
21323 +               "alloc_nx_info(%d) = %p", nid, new);
21324 +       atomic_inc(&nx_global_ctotal);
21325 +       return new;
21326 +}
21327 +
21328 +/*     __dealloc_nx_info()
21329 +
21330 +       * final disposal of nx_info                             */
21331 +
21332 +static void __dealloc_nx_info(struct nx_info *nxi)
21333 +{
21334 +       vxdprintk(VXD_CBIT(nid, 0),
21335 +               "dealloc_nx_info(%p)", nxi);
21336 +
21337 +       nxi->nx_hlist.next = LIST_POISON1;
21338 +       nxi->nx_id = -1;
21339 +
21340 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21341 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21342 +
21343 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
21344 +
21345 +       nxi->nx_state |= NXS_RELEASED;
21346 +       kfree(nxi);
21347 +       atomic_dec(&nx_global_ctotal);
21348 +}
21349 +
21350 +static void __shutdown_nx_info(struct nx_info *nxi)
21351 +{
21352 +       nxi->nx_state |= NXS_SHUTDOWN;
21353 +       vs_net_change(nxi, VSC_NETDOWN);
21354 +}
21355 +
21356 +/*     exported stuff                                          */
21357 +
21358 +void free_nx_info(struct nx_info *nxi)
21359 +{
21360 +       /* context shutdown is mandatory */
21361 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
21362 +
21363 +       /* context must not be hashed */
21364 +       BUG_ON(nxi->nx_state & NXS_HASHED);
21365 +
21366 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21367 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21368 +
21369 +       __dealloc_nx_info(nxi);
21370 +}
21371 +
21372 +
21373 +void __nx_set_lback(struct nx_info *nxi)
21374 +{
21375 +       int nid = nxi->nx_id;
21376 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
21377 +
21378 +       nxi->v4_lback.s_addr = lback;
21379 +}
21380 +
21381 +extern int __nx_inet_add_lback(__be32 addr);
21382 +extern int __nx_inet_del_lback(__be32 addr);
21383 +
21384 +
21385 +/*     hash table for nx_info hash */
21386 +
21387 +#define NX_HASH_SIZE   13
21388 +
21389 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
21390 +
21391 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
21392 +
21393 +
21394 +static inline unsigned int __hashval(nid_t nid)
21395 +{
21396 +       return (nid % NX_HASH_SIZE);
21397 +}
21398 +
21399 +
21400 +
21401 +/*     __hash_nx_info()
21402 +
21403 +       * add the nxi to the global hash table
21404 +       * requires the hash_lock to be held                     */
21405 +
21406 +static inline void __hash_nx_info(struct nx_info *nxi)
21407 +{
21408 +       struct hlist_head *head;
21409 +
21410 +       vxd_assert_lock(&nx_info_hash_lock);
21411 +       vxdprintk(VXD_CBIT(nid, 4),
21412 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
21413 +
21414 +       /* context must not be hashed */
21415 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
21416 +
21417 +       nxi->nx_state |= NXS_HASHED;
21418 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
21419 +       hlist_add_head(&nxi->nx_hlist, head);
21420 +       atomic_inc(&nx_global_cactive);
21421 +}
21422 +
21423 +/*     __unhash_nx_info()
21424 +
21425 +       * remove the nxi from the global hash table
21426 +       * requires the hash_lock to be held                     */
21427 +
21428 +static inline void __unhash_nx_info(struct nx_info *nxi)
21429 +{
21430 +       vxd_assert_lock(&nx_info_hash_lock);
21431 +       vxdprintk(VXD_CBIT(nid, 4),
21432 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
21433 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
21434 +
21435 +       /* context must be hashed */
21436 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
21437 +       /* but without tasks */
21438 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21439 +
21440 +       nxi->nx_state &= ~NXS_HASHED;
21441 +       hlist_del(&nxi->nx_hlist);
21442 +       atomic_dec(&nx_global_cactive);
21443 +}
21444 +
21445 +
21446 +/*     __lookup_nx_info()
21447 +
21448 +       * requires the hash_lock to be held
21449 +       * doesn't increment the nx_refcnt                       */
21450 +
21451 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
21452 +{
21453 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
21454 +       struct hlist_node *pos;
21455 +       struct nx_info *nxi;
21456 +
21457 +       vxd_assert_lock(&nx_info_hash_lock);
21458 +       hlist_for_each(pos, head) {
21459 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21460 +
21461 +               if (nxi->nx_id == nid)
21462 +                       goto found;
21463 +       }
21464 +       nxi = NULL;
21465 +found:
21466 +       vxdprintk(VXD_CBIT(nid, 0),
21467 +               "__lookup_nx_info(#%u): %p[#%u]",
21468 +               nid, nxi, nxi ? nxi->nx_id : 0);
21469 +       return nxi;
21470 +}
21471 +
21472 +
21473 +/*     __create_nx_info()
21474 +
21475 +       * create the requested context
21476 +       * get(), claim() and hash it                            */
21477 +
21478 +static struct nx_info *__create_nx_info(int id)
21479 +{
21480 +       struct nx_info *new, *nxi = NULL;
21481 +
21482 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21483 +
21484 +       if (!(new = __alloc_nx_info(id)))
21485 +               return ERR_PTR(-ENOMEM);
21486 +
21487 +       /* required to make dynamic xids unique */
21488 +       spin_lock(&nx_info_hash_lock);
21489 +
21490 +       /* static context requested */
21491 +       if ((nxi = __lookup_nx_info(id))) {
21492 +               vxdprintk(VXD_CBIT(nid, 0),
21493 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21494 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21495 +                       nxi = ERR_PTR(-EBUSY);
21496 +               else
21497 +                       nxi = ERR_PTR(-EEXIST);
21498 +               goto out_unlock;
21499 +       }
21500 +       /* new context */
21501 +       vxdprintk(VXD_CBIT(nid, 0),
21502 +               "create_nx_info(%d) = %p (new)", id, new);
21503 +       claim_nx_info(new, NULL);
21504 +       __nx_set_lback(new);
21505 +       __hash_nx_info(get_nx_info(new));
21506 +       nxi = new, new = NULL;
21507 +
21508 +out_unlock:
21509 +       spin_unlock(&nx_info_hash_lock);
21510 +       if (new)
21511 +               __dealloc_nx_info(new);
21512 +       return nxi;
21513 +}
21514 +
21515 +
21516 +
21517 +/*     exported stuff                                          */
21518 +
21519 +
21520 +void unhash_nx_info(struct nx_info *nxi)
21521 +{
21522 +       __shutdown_nx_info(nxi);
21523 +       spin_lock(&nx_info_hash_lock);
21524 +       __unhash_nx_info(nxi);
21525 +       spin_unlock(&nx_info_hash_lock);
21526 +}
21527 +
21528 +/*     lookup_nx_info()
21529 +
21530 +       * search for a nx_info and get() it
21531 +       * negative id means current                             */
21532 +
21533 +struct nx_info *lookup_nx_info(int id)
21534 +{
21535 +       struct nx_info *nxi = NULL;
21536 +
21537 +       if (id < 0) {
21538 +               nxi = get_nx_info(current_nx_info());
21539 +       } else if (id > 1) {
21540 +               spin_lock(&nx_info_hash_lock);
21541 +               nxi = get_nx_info(__lookup_nx_info(id));
21542 +               spin_unlock(&nx_info_hash_lock);
21543 +       }
21544 +       return nxi;
21545 +}
21546 +
21547 +/*     nid_is_hashed()
21548 +
21549 +       * verify that nid is still hashed                       */
21550 +
21551 +int nid_is_hashed(nid_t nid)
21552 +{
21553 +       int hashed;
21554 +
21555 +       spin_lock(&nx_info_hash_lock);
21556 +       hashed = (__lookup_nx_info(nid) != NULL);
21557 +       spin_unlock(&nx_info_hash_lock);
21558 +       return hashed;
21559 +}
21560 +
21561 +
21562 +#ifdef CONFIG_PROC_FS
21563 +
21564 +/*     get_nid_list()
21565 +
21566 +       * get a subset of hashed nids for proc
21567 +       * assumes size is at least one                          */
21568 +
21569 +int get_nid_list(int index, unsigned int *nids, int size)
21570 +{
21571 +       int hindex, nr_nids = 0;
21572 +
21573 +       /* only show current and children */
21574 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
21575 +               if (index > 0)
21576 +                       return 0;
21577 +               nids[nr_nids] = nx_current_nid();
21578 +               return 1;
21579 +       }
21580 +
21581 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
21582 +               struct hlist_head *head = &nx_info_hash[hindex];
21583 +               struct hlist_node *pos;
21584 +
21585 +               spin_lock(&nx_info_hash_lock);
21586 +               hlist_for_each(pos, head) {
21587 +                       struct nx_info *nxi;
21588 +
21589 +                       if (--index > 0)
21590 +                               continue;
21591 +
21592 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21593 +                       nids[nr_nids] = nxi->nx_id;
21594 +                       if (++nr_nids >= size) {
21595 +                               spin_unlock(&nx_info_hash_lock);
21596 +                               goto out;
21597 +                       }
21598 +               }
21599 +               /* keep the lock time short */
21600 +               spin_unlock(&nx_info_hash_lock);
21601 +       }
21602 +out:
21603 +       return nr_nids;
21604 +}
21605 +#endif
21606 +
21607 +
21608 +/*
21609 + *     migrate task to new network
21610 + *     gets nxi, puts old_nxi on change
21611 + */
21612 +
21613 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
21614 +{
21615 +       struct nx_info *old_nxi;
21616 +       int ret = 0;
21617 +
21618 +       if (!p || !nxi)
21619 +               BUG();
21620 +
21621 +       vxdprintk(VXD_CBIT(nid, 5),
21622 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21623 +               p, nxi, nxi->nx_id,
21624 +               atomic_read(&nxi->nx_usecnt),
21625 +               atomic_read(&nxi->nx_tasks));
21626 +
21627 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21628 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21629 +               return -EACCES;
21630 +
21631 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21632 +               return -EFAULT;
21633 +
21634 +       /* maybe disallow this completely? */
21635 +       old_nxi = task_get_nx_info(p);
21636 +       if (old_nxi == nxi)
21637 +               goto out;
21638 +
21639 +       task_lock(p);
21640 +       if (old_nxi)
21641 +               clr_nx_info(&p->nx_info);
21642 +       claim_nx_info(nxi, p);
21643 +       set_nx_info(&p->nx_info, nxi);
21644 +       p->nid = nxi->nx_id;
21645 +       task_unlock(p);
21646 +
21647 +       vxdprintk(VXD_CBIT(nid, 5),
21648 +               "moved task %p into nxi:%p[#%d]",
21649 +               p, nxi, nxi->nx_id);
21650 +
21651 +       if (old_nxi)
21652 +               release_nx_info(old_nxi, p);
21653 +       ret = 0;
21654 +out:
21655 +       put_nx_info(old_nxi);
21656 +       return ret;
21657 +}
21658 +
21659 +
21660 +void nx_set_persistent(struct nx_info *nxi)
21661 +{
21662 +       vxdprintk(VXD_CBIT(nid, 6),
21663 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21664 +
21665 +       get_nx_info(nxi);
21666 +       claim_nx_info(nxi, NULL);
21667 +}
21668 +
21669 +void nx_clear_persistent(struct nx_info *nxi)
21670 +{
21671 +       vxdprintk(VXD_CBIT(nid, 6),
21672 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21673 +
21674 +       release_nx_info(nxi, NULL);
21675 +       put_nx_info(nxi);
21676 +}
21677 +
21678 +void nx_update_persistent(struct nx_info *nxi)
21679 +{
21680 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21681 +               nx_set_persistent(nxi);
21682 +       else
21683 +               nx_clear_persistent(nxi);
21684 +}
21685 +
21686 +/* vserver syscall commands below here */
21687 +
21688 +/* taks nid and nx_info functions */
21689 +
21690 +#include <asm/uaccess.h>
21691 +
21692 +
21693 +int vc_task_nid(uint32_t id)
21694 +{
21695 +       nid_t nid;
21696 +
21697 +       if (id) {
21698 +               struct task_struct *tsk;
21699 +
21700 +               read_lock(&tasklist_lock);
21701 +               tsk = find_task_by_real_pid(id);
21702 +               nid = (tsk) ? tsk->nid : -ESRCH;
21703 +               read_unlock(&tasklist_lock);
21704 +       } else
21705 +               nid = nx_current_nid();
21706 +       return nid;
21707 +}
21708 +
21709 +
21710 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21711 +{
21712 +       struct vcmd_nx_info_v0 vc_data;
21713 +
21714 +       vc_data.nid = nxi->nx_id;
21715 +
21716 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21717 +               return -EFAULT;
21718 +       return 0;
21719 +}
21720 +
21721 +
21722 +/* network functions */
21723 +
21724 +int vc_net_create(uint32_t nid, void __user *data)
21725 +{
21726 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21727 +       struct nx_info *new_nxi;
21728 +       int ret;
21729 +
21730 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21731 +               return -EFAULT;
21732 +
21733 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21734 +               return -EINVAL;
21735 +
21736 +       new_nxi = __create_nx_info(nid);
21737 +       if (IS_ERR(new_nxi))
21738 +               return PTR_ERR(new_nxi);
21739 +
21740 +       /* initial flags */
21741 +       new_nxi->nx_flags = vc_data.flagword;
21742 +
21743 +       ret = -ENOEXEC;
21744 +       if (vs_net_change(new_nxi, VSC_NETUP))
21745 +               goto out;
21746 +
21747 +       ret = nx_migrate_task(current, new_nxi);
21748 +       if (ret)
21749 +               goto out;
21750 +
21751 +       /* return context id on success */
21752 +       ret = new_nxi->nx_id;
21753 +
21754 +       /* get a reference for persistent contexts */
21755 +       if ((vc_data.flagword & NXF_PERSISTENT))
21756 +               nx_set_persistent(new_nxi);
21757 +out:
21758 +       release_nx_info(new_nxi, NULL);
21759 +       put_nx_info(new_nxi);
21760 +       return ret;
21761 +}
21762 +
21763 +
21764 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21765 +{
21766 +       return nx_migrate_task(current, nxi);
21767 +}
21768 +
21769 +
21770 +
21771 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21772 +       uint16_t type, uint16_t flags)
21773 +{
21774 +       struct nx_addr_v4 *nxa = &nxi->v4;
21775 +
21776 +       if (NX_IPV4(nxi)) {
21777 +               /* locate last entry */
21778 +               for (; nxa->next; nxa = nxa->next);
21779 +               nxa->next = __alloc_nx_addr_v4();
21780 +               nxa = nxa->next;
21781 +
21782 +               if (IS_ERR(nxa))
21783 +                       return PTR_ERR(nxa);
21784 +       }
21785 +
21786 +       if (nxi->v4.next)
21787 +               /* remove single ip for ip list */
21788 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21789 +
21790 +       nxa->ip[0].s_addr = ip;
21791 +       nxa->ip[1].s_addr = ip2;
21792 +       nxa->mask.s_addr = mask;
21793 +       nxa->type = type;
21794 +       nxa->flags = flags;
21795 +       return 0;
21796 +}
21797 +
21798 +
21799 +int vc_net_add(struct nx_info *nxi, void __user *data)
21800 +{
21801 +       struct vcmd_net_addr_v0 vc_data;
21802 +       int index, ret = 0;
21803 +
21804 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21805 +               return -EFAULT;
21806 +
21807 +       switch (vc_data.type) {
21808 +       case NXA_TYPE_IPV4:
21809 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21810 +                       return -EINVAL;
21811 +
21812 +               index = 0;
21813 +               while (index < vc_data.count) {
21814 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21815 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21816 +                       if (ret)
21817 +                               return ret;
21818 +                       index++;
21819 +               }
21820 +               ret = index;
21821 +               break;
21822 +
21823 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21824 +               nxi->v4_bcast = vc_data.ip[0];
21825 +               ret = 1;
21826 +               break;
21827 +
21828 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21829 +               nxi->v4_lback = vc_data.ip[0];
21830 +               ret = 1;
21831 +               break;
21832 +
21833 +       default:
21834 +               ret = -EINVAL;
21835 +               break;
21836 +       }
21837 +       return ret;
21838 +}
21839 +
21840 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21841 +{
21842 +       struct vcmd_net_addr_v0 vc_data;
21843 +
21844 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21845 +               return -EFAULT;
21846 +
21847 +       switch (vc_data.type) {
21848 +       case NXA_TYPE_ANY:
21849 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21850 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21851 +               break;
21852 +
21853 +       default:
21854 +               return -EINVAL;
21855 +       }
21856 +       return 0;
21857 +}
21858 +
21859 +
21860 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21861 +{
21862 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21863 +
21864 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21865 +               return -EFAULT;
21866 +
21867 +       switch (vc_data.type) {
21868 +       case NXA_TYPE_ADDR:
21869 +       case NXA_TYPE_RANGE:
21870 +       case NXA_TYPE_MASK:
21871 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21872 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21873 +
21874 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21875 +               nxi->v4_bcast = vc_data.ip;
21876 +               break;
21877 +
21878 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21879 +               nxi->v4_lback = vc_data.ip;
21880 +               break;
21881 +
21882 +       default:
21883 +               return -EINVAL;
21884 +       }
21885 +       return 0;
21886 +}
21887 +
21888 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
21889 +{
21890 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21891 +
21892 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21893 +               return -EFAULT;
21894 +
21895 +       switch (vc_data.type) {
21896 +/*     case NXA_TYPE_ADDR:
21897 +               break;          */
21898 +
21899 +       case NXA_TYPE_ANY:
21900 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21901 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21902 +               break;
21903 +
21904 +       default:
21905 +               return -EINVAL;
21906 +       }
21907 +       return 0;
21908 +}
21909 +
21910 +
21911 +#ifdef CONFIG_IPV6
21912 +
21913 +int do_add_v6_addr(struct nx_info *nxi,
21914 +       struct in6_addr *ip, struct in6_addr *mask,
21915 +       uint32_t prefix, uint16_t type, uint16_t flags)
21916 +{
21917 +       struct nx_addr_v6 *nxa = &nxi->v6;
21918 +
21919 +       if (NX_IPV6(nxi)) {
21920 +               /* locate last entry */
21921 +               for (; nxa->next; nxa = nxa->next);
21922 +               nxa->next = __alloc_nx_addr_v6();
21923 +               nxa = nxa->next;
21924 +
21925 +               if (IS_ERR(nxa))
21926 +                       return PTR_ERR(nxa);
21927 +       }
21928 +
21929 +       nxa->ip = *ip;
21930 +       nxa->mask = *mask;
21931 +       nxa->prefix = prefix;
21932 +       nxa->type = type;
21933 +       nxa->flags = flags;
21934 +       return 0;
21935 +}
21936 +
21937 +
21938 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21939 +{
21940 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21941 +
21942 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21943 +               return -EFAULT;
21944 +
21945 +       switch (vc_data.type) {
21946 +       case NXA_TYPE_ADDR:
21947 +       case NXA_TYPE_MASK:
21948 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21949 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21950 +       default:
21951 +               return -EINVAL;
21952 +       }
21953 +       return 0;
21954 +}
21955 +
21956 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21957 +{
21958 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21959 +
21960 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21961 +               return -EFAULT;
21962 +
21963 +       switch (vc_data.type) {
21964 +       case NXA_TYPE_ANY:
21965 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21966 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21967 +               break;
21968 +
21969 +       default:
21970 +               return -EINVAL;
21971 +       }
21972 +       return 0;
21973 +}
21974 +
21975 +#endif /* CONFIG_IPV6 */
21976 +
21977 +
21978 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21979 +{
21980 +       struct vcmd_net_flags_v0 vc_data;
21981 +
21982 +       vc_data.flagword = nxi->nx_flags;
21983 +
21984 +       /* special STATE flag handling */
21985 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21986 +
21987 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21988 +               return -EFAULT;
21989 +       return 0;
21990 +}
21991 +
21992 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21993 +{
21994 +       struct vcmd_net_flags_v0 vc_data;
21995 +       uint64_t mask, trigger;
21996 +
21997 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21998 +               return -EFAULT;
21999 +
22000 +       /* special STATE flag handling */
22001 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22002 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22003 +
22004 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22005 +               vc_data.flagword, mask);
22006 +       if (trigger & NXF_PERSISTENT)
22007 +               nx_update_persistent(nxi);
22008 +
22009 +       return 0;
22010 +}
22011 +
22012 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22013 +{
22014 +       struct vcmd_net_caps_v0 vc_data;
22015 +
22016 +       vc_data.ncaps = nxi->nx_ncaps;
22017 +       vc_data.cmask = ~0ULL;
22018 +
22019 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22020 +               return -EFAULT;
22021 +       return 0;
22022 +}
22023 +
22024 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22025 +{
22026 +       struct vcmd_net_caps_v0 vc_data;
22027 +
22028 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22029 +               return -EFAULT;
22030 +
22031 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22032 +               vc_data.ncaps, vc_data.cmask);
22033 +       return 0;
22034 +}
22035 +
22036 +
22037 +#include <linux/module.h>
22038 +
22039 +module_init(init_network);
22040 +
22041 +EXPORT_SYMBOL_GPL(free_nx_info);
22042 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22043 +
22044 diff -NurpP --minimal linux-2.6.33/kernel/vserver/proc.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/proc.c
22045 --- linux-2.6.33/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
22046 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/proc.c    2010-02-25 12:02:16.000000000 +0100
22047 @@ -0,0 +1,1098 @@
22048 +/*
22049 + *  linux/kernel/vserver/proc.c
22050 + *
22051 + *  Virtual Context Support
22052 + *
22053 + *  Copyright (C) 2003-2007  Herbert Pötzl
22054 + *
22055 + *  V0.01  basic structure
22056 + *  V0.02  adaptation vs1.3.0
22057 + *  V0.03  proc permissions
22058 + *  V0.04  locking/generic
22059 + *  V0.05  next generation procfs
22060 + *  V0.06  inode validation
22061 + *  V0.07  generic rewrite vid
22062 + *  V0.08  remove inode type
22063 + *
22064 + */
22065 +
22066 +#include <linux/proc_fs.h>
22067 +#include <linux/fs_struct.h>
22068 +#include <linux/mount.h>
22069 +#include <asm/unistd.h>
22070 +
22071 +#include <linux/vs_context.h>
22072 +#include <linux/vs_network.h>
22073 +#include <linux/vs_cvirt.h>
22074 +
22075 +#include <linux/in.h>
22076 +#include <linux/inetdevice.h>
22077 +#include <linux/vs_inet.h>
22078 +#include <linux/vs_inet6.h>
22079 +
22080 +#include <linux/vserver/global.h>
22081 +
22082 +#include "cvirt_proc.h"
22083 +#include "cacct_proc.h"
22084 +#include "limit_proc.h"
22085 +#include "sched_proc.h"
22086 +#include "vci_config.h"
22087 +
22088 +
22089 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22090 +{
22091 +       unsigned __capi;
22092 +
22093 +       CAP_FOR_EACH_U32(__capi) {
22094 +               buffer += sprintf(buffer, "%08x",
22095 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22096 +       }
22097 +       return buffer;
22098 +}
22099 +
22100 +
22101 +static struct proc_dir_entry *proc_virtual;
22102 +
22103 +static struct proc_dir_entry *proc_virtnet;
22104 +
22105 +
22106 +/* first the actual feeds */
22107 +
22108 +
22109 +static int proc_vci(char *buffer)
22110 +{
22111 +       return sprintf(buffer,
22112 +               "VCIVersion:\t%04x:%04x\n"
22113 +               "VCISyscall:\t%d\n"
22114 +               "VCIKernel:\t%08x\n",
22115 +               VCI_VERSION >> 16,
22116 +               VCI_VERSION & 0xFFFF,
22117 +               __NR_vserver,
22118 +               vci_kernel_config());
22119 +}
22120 +
22121 +static int proc_virtual_info(char *buffer)
22122 +{
22123 +       return proc_vci(buffer);
22124 +}
22125 +
22126 +static int proc_virtual_status(char *buffer)
22127 +{
22128 +       return sprintf(buffer,
22129 +               "#CTotal:\t%d\n"
22130 +               "#CActive:\t%d\n"
22131 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
22132 +               "#InitTask:\t%d\t%d %d\n",
22133 +               atomic_read(&vx_global_ctotal),
22134 +               atomic_read(&vx_global_cactive),
22135 +               atomic_read(&vs_global_nsproxy),
22136 +               atomic_read(&vs_global_fs),
22137 +               atomic_read(&vs_global_mnt_ns),
22138 +               atomic_read(&vs_global_uts_ns),
22139 +               atomic_read(&nr_ipc_ns),
22140 +               atomic_read(&vs_global_user_ns),
22141 +               atomic_read(&vs_global_pid_ns),
22142 +               atomic_read(&init_task.usage),
22143 +               atomic_read(&init_task.nsproxy->count),
22144 +               init_task.fs->users);
22145 +}
22146 +
22147 +
22148 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
22149 +{
22150 +       int length;
22151 +
22152 +       length = sprintf(buffer,
22153 +               "ID:\t%d\n"
22154 +               "Info:\t%p\n"
22155 +               "Init:\t%d\n"
22156 +               "OOM:\t%lld\n",
22157 +               vxi->vx_id,
22158 +               vxi,
22159 +               vxi->vx_initpid,
22160 +               vxi->vx_badness_bias);
22161 +       return length;
22162 +}
22163 +
22164 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
22165 +{
22166 +       char *orig = buffer;
22167 +
22168 +       buffer += sprintf(buffer,
22169 +               "UseCnt:\t%d\n"
22170 +               "Tasks:\t%d\n"
22171 +               "Flags:\t%016llx\n",
22172 +               atomic_read(&vxi->vx_usecnt),
22173 +               atomic_read(&vxi->vx_tasks),
22174 +               (unsigned long long)vxi->vx_flags);
22175 +
22176 +       buffer += sprintf(buffer, "BCaps:\t");
22177 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22178 +       buffer += sprintf(buffer, "\n");
22179 +
22180 +       buffer += sprintf(buffer,
22181 +               "CCaps:\t%016llx\n"
22182 +               "Spaces:\t%08lx %08lx\n",
22183 +               (unsigned long long)vxi->vx_ccaps,
22184 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
22185 +       return buffer - orig;
22186 +}
22187 +
22188 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
22189 +{
22190 +       return vx_info_proc_limit(&vxi->limit, buffer);
22191 +}
22192 +
22193 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
22194 +{
22195 +       int cpu, length;
22196 +
22197 +       length = vx_info_proc_sched(&vxi->sched, buffer);
22198 +       for_each_online_cpu(cpu) {
22199 +               length += vx_info_proc_sched_pc(
22200 +                       &vx_per_cpu(vxi, sched_pc, cpu),
22201 +                       buffer + length, cpu);
22202 +       }
22203 +       return length;
22204 +}
22205 +
22206 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
22207 +{
22208 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
22209 +}
22210 +
22211 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
22212 +{
22213 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
22214 +}
22215 +
22216 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
22217 +{
22218 +       int cpu, length;
22219 +
22220 +       vx_update_load(vxi);
22221 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
22222 +       for_each_online_cpu(cpu) {
22223 +               length += vx_info_proc_cvirt_pc(
22224 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
22225 +                       buffer + length, cpu);
22226 +       }
22227 +       return length;
22228 +}
22229 +
22230 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
22231 +{
22232 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
22233 +}
22234 +
22235 +
22236 +static int proc_virtnet_info(char *buffer)
22237 +{
22238 +       return proc_vci(buffer);
22239 +}
22240 +
22241 +static int proc_virtnet_status(char *buffer)
22242 +{
22243 +       return sprintf(buffer,
22244 +               "#CTotal:\t%d\n"
22245 +               "#CActive:\t%d\n",
22246 +               atomic_read(&nx_global_ctotal),
22247 +               atomic_read(&nx_global_cactive));
22248 +}
22249 +
22250 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22251 +{
22252 +       struct nx_addr_v4 *v4a;
22253 +#ifdef CONFIG_IPV6
22254 +       struct nx_addr_v6 *v6a;
22255 +#endif
22256 +       int length, i;
22257 +
22258 +       length = sprintf(buffer,
22259 +               "ID:\t%d\n"
22260 +               "Info:\t%p\n"
22261 +               "Bcast:\t" NIPQUAD_FMT "\n"
22262 +               "Lback:\t" NIPQUAD_FMT "\n",
22263 +               nxi->nx_id,
22264 +               nxi,
22265 +               NIPQUAD(nxi->v4_bcast.s_addr),
22266 +               NIPQUAD(nxi->v4_lback.s_addr));
22267 +
22268 +       if (!NX_IPV4(nxi))
22269 +               goto skip_v4;
22270 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22271 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
22272 +                       i, NXAV4(v4a));
22273 +skip_v4:
22274 +#ifdef CONFIG_IPV6
22275 +       if (!NX_IPV6(nxi))
22276 +               goto skip_v6;
22277 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22278 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
22279 +                       i, NXAV6(v6a));
22280 +skip_v6:
22281 +#endif
22282 +       return length;
22283 +}
22284 +
22285 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22286 +{
22287 +       int length;
22288 +
22289 +       length = sprintf(buffer,
22290 +               "UseCnt:\t%d\n"
22291 +               "Tasks:\t%d\n"
22292 +               "Flags:\t%016llx\n"
22293 +               "NCaps:\t%016llx\n",
22294 +               atomic_read(&nxi->nx_usecnt),
22295 +               atomic_read(&nxi->nx_tasks),
22296 +               (unsigned long long)nxi->nx_flags,
22297 +               (unsigned long long)nxi->nx_ncaps);
22298 +       return length;
22299 +}
22300 +
22301 +
22302 +
22303 +/* here the inode helpers */
22304 +
22305 +struct vs_entry {
22306 +       int len;
22307 +       char *name;
22308 +       mode_t mode;
22309 +       struct inode_operations *iop;
22310 +       struct file_operations *fop;
22311 +       union proc_op op;
22312 +};
22313 +
22314 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
22315 +{
22316 +       struct inode *inode = new_inode(sb);
22317 +
22318 +       if (!inode)
22319 +               goto out;
22320 +
22321 +       inode->i_mode = p->mode;
22322 +       if (p->iop)
22323 +               inode->i_op = p->iop;
22324 +       if (p->fop)
22325 +               inode->i_fop = p->fop;
22326 +
22327 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
22328 +       inode->i_flags |= S_IMMUTABLE;
22329 +
22330 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
22331 +
22332 +       inode->i_uid = 0;
22333 +       inode->i_gid = 0;
22334 +       inode->i_tag = 0;
22335 +out:
22336 +       return inode;
22337 +}
22338 +
22339 +static struct dentry *vs_proc_instantiate(struct inode *dir,
22340 +       struct dentry *dentry, int id, void *ptr)
22341 +{
22342 +       struct vs_entry *p = ptr;
22343 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
22344 +       struct dentry *error = ERR_PTR(-EINVAL);
22345 +
22346 +       if (!inode)
22347 +               goto out;
22348 +
22349 +       PROC_I(inode)->op = p->op;
22350 +       PROC_I(inode)->fd = id;
22351 +       d_add(dentry, inode);
22352 +       error = NULL;
22353 +out:
22354 +       return error;
22355 +}
22356 +
22357 +/* Lookups */
22358 +
22359 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
22360 +
22361 +/*
22362 + * Fill a directory entry.
22363 + *
22364 + * If possible create the dcache entry and derive our inode number and
22365 + * file type from dcache entry.
22366 + *
22367 + * Since all of the proc inode numbers are dynamically generated, the inode
22368 + * numbers do not exist until the inode is cache.  This means creating the
22369 + * the dcache entry in readdir is necessary to keep the inode numbers
22370 + * reported by readdir in sync with the inode numbers reported
22371 + * by stat.
22372 + */
22373 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
22374 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
22375 +{
22376 +       struct dentry *child, *dir = filp->f_dentry;
22377 +       struct inode *inode;
22378 +       struct qstr qname;
22379 +       ino_t ino = 0;
22380 +       unsigned type = DT_UNKNOWN;
22381 +
22382 +       qname.name = name;
22383 +       qname.len  = len;
22384 +       qname.hash = full_name_hash(name, len);
22385 +
22386 +       child = d_lookup(dir, &qname);
22387 +       if (!child) {
22388 +               struct dentry *new;
22389 +               new = d_alloc(dir, &qname);
22390 +               if (new) {
22391 +                       child = instantiate(dir->d_inode, new, id, ptr);
22392 +                       if (child)
22393 +                               dput(new);
22394 +                       else
22395 +                               child = new;
22396 +               }
22397 +       }
22398 +       if (!child || IS_ERR(child) || !child->d_inode)
22399 +               goto end_instantiate;
22400 +       inode = child->d_inode;
22401 +       if (inode) {
22402 +               ino = inode->i_ino;
22403 +               type = inode->i_mode >> 12;
22404 +       }
22405 +       dput(child);
22406 +end_instantiate:
22407 +       if (!ino)
22408 +               ino = find_inode_number(dir, &qname);
22409 +       if (!ino)
22410 +               ino = 1;
22411 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
22412 +}
22413 +
22414 +
22415 +
22416 +/* get and revalidate vx_info/xid */
22417 +
22418 +static inline
22419 +struct vx_info *get_proc_vx_info(struct inode *inode)
22420 +{
22421 +       return lookup_vx_info(PROC_I(inode)->fd);
22422 +}
22423 +
22424 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
22425 +{
22426 +       struct inode *inode = dentry->d_inode;
22427 +       xid_t xid = PROC_I(inode)->fd;
22428 +
22429 +       if (!xid || xid_is_hashed(xid))
22430 +               return 1;
22431 +       d_drop(dentry);
22432 +       return 0;
22433 +}
22434 +
22435 +
22436 +/* get and revalidate nx_info/nid */
22437 +
22438 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
22439 +{
22440 +       struct inode *inode = dentry->d_inode;
22441 +       nid_t nid = PROC_I(inode)->fd;
22442 +
22443 +       if (!nid || nid_is_hashed(nid))
22444 +               return 1;
22445 +       d_drop(dentry);
22446 +       return 0;
22447 +}
22448 +
22449 +
22450 +
22451 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22452 +
22453 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22454 +                         size_t count, loff_t *ppos)
22455 +{
22456 +       struct inode *inode = file->f_dentry->d_inode;
22457 +       unsigned long page;
22458 +       ssize_t length = 0;
22459 +
22460 +       if (count > PROC_BLOCK_SIZE)
22461 +               count = PROC_BLOCK_SIZE;
22462 +
22463 +       /* fade that out as soon as stable */
22464 +       WARN_ON(PROC_I(inode)->fd);
22465 +
22466 +       if (!(page = __get_free_page(GFP_KERNEL)))
22467 +               return -ENOMEM;
22468 +
22469 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22470 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22471 +
22472 +       if (length >= 0)
22473 +               length = simple_read_from_buffer(buf, count, ppos,
22474 +                       (char *)page, length);
22475 +
22476 +       free_page(page);
22477 +       return length;
22478 +}
22479 +
22480 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22481 +                         size_t count, loff_t *ppos)
22482 +{
22483 +       struct inode *inode = file->f_dentry->d_inode;
22484 +       struct vx_info *vxi = NULL;
22485 +       xid_t xid = PROC_I(inode)->fd;
22486 +       unsigned long page;
22487 +       ssize_t length = 0;
22488 +
22489 +       if (count > PROC_BLOCK_SIZE)
22490 +               count = PROC_BLOCK_SIZE;
22491 +
22492 +       /* fade that out as soon as stable */
22493 +       WARN_ON(!xid);
22494 +       vxi = lookup_vx_info(xid);
22495 +       if (!vxi)
22496 +               goto out;
22497 +
22498 +       length = -ENOMEM;
22499 +       if (!(page = __get_free_page(GFP_KERNEL)))
22500 +               goto out_put;
22501 +
22502 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22503 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22504 +
22505 +       if (length >= 0)
22506 +               length = simple_read_from_buffer(buf, count, ppos,
22507 +                       (char *)page, length);
22508 +
22509 +       free_page(page);
22510 +out_put:
22511 +       put_vx_info(vxi);
22512 +out:
22513 +       return length;
22514 +}
22515 +
22516 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22517 +                         size_t count, loff_t *ppos)
22518 +{
22519 +       struct inode *inode = file->f_dentry->d_inode;
22520 +       struct nx_info *nxi = NULL;
22521 +       nid_t nid = PROC_I(inode)->fd;
22522 +       unsigned long page;
22523 +       ssize_t length = 0;
22524 +
22525 +       if (count > PROC_BLOCK_SIZE)
22526 +               count = PROC_BLOCK_SIZE;
22527 +
22528 +       /* fade that out as soon as stable */
22529 +       WARN_ON(!nid);
22530 +       nxi = lookup_nx_info(nid);
22531 +       if (!nxi)
22532 +               goto out;
22533 +
22534 +       length = -ENOMEM;
22535 +       if (!(page = __get_free_page(GFP_KERNEL)))
22536 +               goto out_put;
22537 +
22538 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22539 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22540 +
22541 +       if (length >= 0)
22542 +               length = simple_read_from_buffer(buf, count, ppos,
22543 +                       (char *)page, length);
22544 +
22545 +       free_page(page);
22546 +out_put:
22547 +       put_nx_info(nxi);
22548 +out:
22549 +       return length;
22550 +}
22551 +
22552 +
22553 +
22554 +/* here comes the lower level */
22555 +
22556 +
22557 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22558 +       .len  = sizeof(NAME) - 1,       \
22559 +       .name = (NAME),                 \
22560 +       .mode = MODE,                   \
22561 +       .iop  = IOP,                    \
22562 +       .fop  = FOP,                    \
22563 +       .op   = OP,                     \
22564 +}
22565 +
22566 +
22567 +#define DIR(NAME, MODE, OTYPE)                         \
22568 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22569 +               &proc_ ## OTYPE ## _inode_operations,   \
22570 +               &proc_ ## OTYPE ## _file_operations, { } )
22571 +
22572 +#define INF(NAME, MODE, OTYPE)                         \
22573 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22574 +               &proc_vs_info_file_operations,          \
22575 +               { .proc_vs_read = &proc_##OTYPE } )
22576 +
22577 +#define VINF(NAME, MODE, OTYPE)                                \
22578 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22579 +               &proc_vx_info_file_operations,          \
22580 +               { .proc_vxi_read = &proc_##OTYPE } )
22581 +
22582 +#define NINF(NAME, MODE, OTYPE)                                \
22583 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22584 +               &proc_nx_info_file_operations,          \
22585 +               { .proc_nxi_read = &proc_##OTYPE } )
22586 +
22587 +
22588 +static struct file_operations proc_vs_info_file_operations = {
22589 +       .read =         proc_vs_info_read,
22590 +};
22591 +
22592 +static struct file_operations proc_vx_info_file_operations = {
22593 +       .read =         proc_vx_info_read,
22594 +};
22595 +
22596 +static struct dentry_operations proc_xid_dentry_operations = {
22597 +       .d_revalidate = proc_xid_revalidate,
22598 +};
22599 +
22600 +static struct vs_entry vx_base_stuff[] = {
22601 +       VINF("info",    S_IRUGO, vxi_info),
22602 +       VINF("status",  S_IRUGO, vxi_status),
22603 +       VINF("limit",   S_IRUGO, vxi_limit),
22604 +       VINF("sched",   S_IRUGO, vxi_sched),
22605 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
22606 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
22607 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22608 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22609 +       {}
22610 +};
22611 +
22612 +
22613 +
22614 +
22615 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22616 +       struct dentry *dentry, int id, void *ptr)
22617 +{
22618 +       dentry->d_op = &proc_xid_dentry_operations;
22619 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22620 +}
22621 +
22622 +static struct dentry *proc_xid_lookup(struct inode *dir,
22623 +       struct dentry *dentry, struct nameidata *nd)
22624 +{
22625 +       struct vs_entry *p = vx_base_stuff;
22626 +       struct dentry *error = ERR_PTR(-ENOENT);
22627 +
22628 +       for (; p->name; p++) {
22629 +               if (p->len != dentry->d_name.len)
22630 +                       continue;
22631 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22632 +                       break;
22633 +       }
22634 +       if (!p->name)
22635 +               goto out;
22636 +
22637 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22638 +out:
22639 +       return error;
22640 +}
22641 +
22642 +static int proc_xid_readdir(struct file *filp,
22643 +       void *dirent, filldir_t filldir)
22644 +{
22645 +       struct dentry *dentry = filp->f_dentry;
22646 +       struct inode *inode = dentry->d_inode;
22647 +       struct vs_entry *p = vx_base_stuff;
22648 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22649 +       int pos, index;
22650 +       u64 ino;
22651 +
22652 +       pos = filp->f_pos;
22653 +       switch (pos) {
22654 +       case 0:
22655 +               ino = inode->i_ino;
22656 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22657 +                       goto out;
22658 +               pos++;
22659 +               /* fall through */
22660 +       case 1:
22661 +               ino = parent_ino(dentry);
22662 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22663 +                       goto out;
22664 +               pos++;
22665 +               /* fall through */
22666 +       default:
22667 +               index = pos - 2;
22668 +               if (index >= size)
22669 +                       goto out;
22670 +               for (p += index; p->name; p++) {
22671 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22672 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22673 +                               goto out;
22674 +                       pos++;
22675 +               }
22676 +       }
22677 +out:
22678 +       filp->f_pos = pos;
22679 +       return 1;
22680 +}
22681 +
22682 +
22683 +
22684 +static struct file_operations proc_nx_info_file_operations = {
22685 +       .read =         proc_nx_info_read,
22686 +};
22687 +
22688 +static struct dentry_operations proc_nid_dentry_operations = {
22689 +       .d_revalidate = proc_nid_revalidate,
22690 +};
22691 +
22692 +static struct vs_entry nx_base_stuff[] = {
22693 +       NINF("info",    S_IRUGO, nxi_info),
22694 +       NINF("status",  S_IRUGO, nxi_status),
22695 +       {}
22696 +};
22697 +
22698 +
22699 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22700 +       struct dentry *dentry, int id, void *ptr)
22701 +{
22702 +       dentry->d_op = &proc_nid_dentry_operations;
22703 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22704 +}
22705 +
22706 +static struct dentry *proc_nid_lookup(struct inode *dir,
22707 +       struct dentry *dentry, struct nameidata *nd)
22708 +{
22709 +       struct vs_entry *p = nx_base_stuff;
22710 +       struct dentry *error = ERR_PTR(-ENOENT);
22711 +
22712 +       for (; p->name; p++) {
22713 +               if (p->len != dentry->d_name.len)
22714 +                       continue;
22715 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22716 +                       break;
22717 +       }
22718 +       if (!p->name)
22719 +               goto out;
22720 +
22721 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22722 +out:
22723 +       return error;
22724 +}
22725 +
22726 +static int proc_nid_readdir(struct file *filp,
22727 +       void *dirent, filldir_t filldir)
22728 +{
22729 +       struct dentry *dentry = filp->f_dentry;
22730 +       struct inode *inode = dentry->d_inode;
22731 +       struct vs_entry *p = nx_base_stuff;
22732 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22733 +       int pos, index;
22734 +       u64 ino;
22735 +
22736 +       pos = filp->f_pos;
22737 +       switch (pos) {
22738 +       case 0:
22739 +               ino = inode->i_ino;
22740 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22741 +                       goto out;
22742 +               pos++;
22743 +               /* fall through */
22744 +       case 1:
22745 +               ino = parent_ino(dentry);
22746 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22747 +                       goto out;
22748 +               pos++;
22749 +               /* fall through */
22750 +       default:
22751 +               index = pos - 2;
22752 +               if (index >= size)
22753 +                       goto out;
22754 +               for (p += index; p->name; p++) {
22755 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22756 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22757 +                               goto out;
22758 +                       pos++;
22759 +               }
22760 +       }
22761 +out:
22762 +       filp->f_pos = pos;
22763 +       return 1;
22764 +}
22765 +
22766 +
22767 +#define MAX_MULBY10    ((~0U - 9) / 10)
22768 +
22769 +static inline int atovid(const char *str, int len)
22770 +{
22771 +       int vid, c;
22772 +
22773 +       vid = 0;
22774 +       while (len-- > 0) {
22775 +               c = *str - '0';
22776 +               str++;
22777 +               if (c > 9)
22778 +                       return -1;
22779 +               if (vid >= MAX_MULBY10)
22780 +                       return -1;
22781 +               vid *= 10;
22782 +               vid += c;
22783 +               if (!vid)
22784 +                       return -1;
22785 +       }
22786 +       return vid;
22787 +}
22788 +
22789 +/* now the upper level (virtual) */
22790 +
22791 +
22792 +static struct file_operations proc_xid_file_operations = {
22793 +       .read =         generic_read_dir,
22794 +       .readdir =      proc_xid_readdir,
22795 +};
22796 +
22797 +static struct inode_operations proc_xid_inode_operations = {
22798 +       .lookup =       proc_xid_lookup,
22799 +};
22800 +
22801 +static struct vs_entry vx_virtual_stuff[] = {
22802 +       INF("info",     S_IRUGO, virtual_info),
22803 +       INF("status",   S_IRUGO, virtual_status),
22804 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22805 +};
22806 +
22807 +
22808 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22809 +       struct dentry *dentry, struct nameidata *nd)
22810 +{
22811 +       struct vs_entry *p = vx_virtual_stuff;
22812 +       struct dentry *error = ERR_PTR(-ENOENT);
22813 +       int id = 0;
22814 +
22815 +       for (; p->name; p++) {
22816 +               if (p->len != dentry->d_name.len)
22817 +                       continue;
22818 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22819 +                       break;
22820 +       }
22821 +       if (p->name)
22822 +               goto instantiate;
22823 +
22824 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22825 +       if ((id < 0) || !xid_is_hashed(id))
22826 +               goto out;
22827 +
22828 +instantiate:
22829 +       error = proc_xid_instantiate(dir, dentry, id, p);
22830 +out:
22831 +       return error;
22832 +}
22833 +
22834 +static struct file_operations proc_nid_file_operations = {
22835 +       .read =         generic_read_dir,
22836 +       .readdir =      proc_nid_readdir,
22837 +};
22838 +
22839 +static struct inode_operations proc_nid_inode_operations = {
22840 +       .lookup =       proc_nid_lookup,
22841 +};
22842 +
22843 +static struct vs_entry nx_virtnet_stuff[] = {
22844 +       INF("info",     S_IRUGO, virtnet_info),
22845 +       INF("status",   S_IRUGO, virtnet_status),
22846 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22847 +};
22848 +
22849 +
22850 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22851 +       struct dentry *dentry, struct nameidata *nd)
22852 +{
22853 +       struct vs_entry *p = nx_virtnet_stuff;
22854 +       struct dentry *error = ERR_PTR(-ENOENT);
22855 +       int id = 0;
22856 +
22857 +       for (; p->name; p++) {
22858 +               if (p->len != dentry->d_name.len)
22859 +                       continue;
22860 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22861 +                       break;
22862 +       }
22863 +       if (p->name)
22864 +               goto instantiate;
22865 +
22866 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22867 +       if ((id < 0) || !nid_is_hashed(id))
22868 +               goto out;
22869 +
22870 +instantiate:
22871 +       error = proc_nid_instantiate(dir, dentry, id, p);
22872 +out:
22873 +       return error;
22874 +}
22875 +
22876 +
22877 +#define PROC_MAXVIDS 32
22878 +
22879 +int proc_virtual_readdir(struct file *filp,
22880 +       void *dirent, filldir_t filldir)
22881 +{
22882 +       struct dentry *dentry = filp->f_dentry;
22883 +       struct inode *inode = dentry->d_inode;
22884 +       struct vs_entry *p = vx_virtual_stuff;
22885 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22886 +       int pos, index;
22887 +       unsigned int xid_array[PROC_MAXVIDS];
22888 +       char buf[PROC_NUMBUF];
22889 +       unsigned int nr_xids, i;
22890 +       u64 ino;
22891 +
22892 +       pos = filp->f_pos;
22893 +       switch (pos) {
22894 +       case 0:
22895 +               ino = inode->i_ino;
22896 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22897 +                       goto out;
22898 +               pos++;
22899 +               /* fall through */
22900 +       case 1:
22901 +               ino = parent_ino(dentry);
22902 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22903 +                       goto out;
22904 +               pos++;
22905 +               /* fall through */
22906 +       default:
22907 +               index = pos - 2;
22908 +               if (index >= size)
22909 +                       goto entries;
22910 +               for (p += index; p->name; p++) {
22911 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22912 +                               vs_proc_instantiate, 0, p))
22913 +                               goto out;
22914 +                       pos++;
22915 +               }
22916 +       entries:
22917 +               index = pos - size;
22918 +               p = &vx_virtual_stuff[size - 1];
22919 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22920 +               for (i = 0; i < nr_xids; i++) {
22921 +                       int n, xid = xid_array[i];
22922 +                       unsigned int j = PROC_NUMBUF;
22923 +
22924 +                       n = xid;
22925 +                       do
22926 +                               buf[--j] = '0' + (n % 10);
22927 +                       while (n /= 10);
22928 +
22929 +                       if (proc_fill_cache(filp, dirent, filldir,
22930 +                               buf + j, PROC_NUMBUF - j,
22931 +                               vs_proc_instantiate, xid, p))
22932 +                               goto out;
22933 +                       pos++;
22934 +               }
22935 +       }
22936 +out:
22937 +       filp->f_pos = pos;
22938 +       return 0;
22939 +}
22940 +
22941 +static int proc_virtual_getattr(struct vfsmount *mnt,
22942 +       struct dentry *dentry, struct kstat *stat)
22943 +{
22944 +       struct inode *inode = dentry->d_inode;
22945 +
22946 +       generic_fillattr(inode, stat);
22947 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22948 +       return 0;
22949 +}
22950 +
22951 +static struct file_operations proc_virtual_dir_operations = {
22952 +       .read =         generic_read_dir,
22953 +       .readdir =      proc_virtual_readdir,
22954 +};
22955 +
22956 +static struct inode_operations proc_virtual_dir_inode_operations = {
22957 +       .getattr =      proc_virtual_getattr,
22958 +       .lookup =       proc_virtual_lookup,
22959 +};
22960 +
22961 +
22962 +
22963 +
22964 +
22965 +int proc_virtnet_readdir(struct file *filp,
22966 +       void *dirent, filldir_t filldir)
22967 +{
22968 +       struct dentry *dentry = filp->f_dentry;
22969 +       struct inode *inode = dentry->d_inode;
22970 +       struct vs_entry *p = nx_virtnet_stuff;
22971 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22972 +       int pos, index;
22973 +       unsigned int nid_array[PROC_MAXVIDS];
22974 +       char buf[PROC_NUMBUF];
22975 +       unsigned int nr_nids, i;
22976 +       u64 ino;
22977 +
22978 +       pos = filp->f_pos;
22979 +       switch (pos) {
22980 +       case 0:
22981 +               ino = inode->i_ino;
22982 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22983 +                       goto out;
22984 +               pos++;
22985 +               /* fall through */
22986 +       case 1:
22987 +               ino = parent_ino(dentry);
22988 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22989 +                       goto out;
22990 +               pos++;
22991 +               /* fall through */
22992 +       default:
22993 +               index = pos - 2;
22994 +               if (index >= size)
22995 +                       goto entries;
22996 +               for (p += index; p->name; p++) {
22997 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22998 +                               vs_proc_instantiate, 0, p))
22999 +                               goto out;
23000 +                       pos++;
23001 +               }
23002 +       entries:
23003 +               index = pos - size;
23004 +               p = &nx_virtnet_stuff[size - 1];
23005 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23006 +               for (i = 0; i < nr_nids; i++) {
23007 +                       int n, nid = nid_array[i];
23008 +                       unsigned int j = PROC_NUMBUF;
23009 +
23010 +                       n = nid;
23011 +                       do
23012 +                               buf[--j] = '0' + (n % 10);
23013 +                       while (n /= 10);
23014 +
23015 +                       if (proc_fill_cache(filp, dirent, filldir,
23016 +                               buf + j, PROC_NUMBUF - j,
23017 +                               vs_proc_instantiate, nid, p))
23018 +                               goto out;
23019 +                       pos++;
23020 +               }
23021 +       }
23022 +out:
23023 +       filp->f_pos = pos;
23024 +       return 0;
23025 +}
23026 +
23027 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23028 +       struct dentry *dentry, struct kstat *stat)
23029 +{
23030 +       struct inode *inode = dentry->d_inode;
23031 +
23032 +       generic_fillattr(inode, stat);
23033 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23034 +       return 0;
23035 +}
23036 +
23037 +static struct file_operations proc_virtnet_dir_operations = {
23038 +       .read =         generic_read_dir,
23039 +       .readdir =      proc_virtnet_readdir,
23040 +};
23041 +
23042 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23043 +       .getattr =      proc_virtnet_getattr,
23044 +       .lookup =       proc_virtnet_lookup,
23045 +};
23046 +
23047 +
23048 +
23049 +void proc_vx_init(void)
23050 +{
23051 +       struct proc_dir_entry *ent;
23052 +
23053 +       ent = proc_mkdir("virtual", 0);
23054 +       if (ent) {
23055 +               ent->proc_fops = &proc_virtual_dir_operations;
23056 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23057 +       }
23058 +       proc_virtual = ent;
23059 +
23060 +       ent = proc_mkdir("virtnet", 0);
23061 +       if (ent) {
23062 +               ent->proc_fops = &proc_virtnet_dir_operations;
23063 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23064 +       }
23065 +       proc_virtnet = ent;
23066 +}
23067 +
23068 +
23069 +
23070 +
23071 +/* per pid info */
23072 +
23073 +
23074 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23075 +{
23076 +       struct vx_info *vxi;
23077 +       char *orig = buffer;
23078 +
23079 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23080 +
23081 +       vxi = task_get_vx_info(p);
23082 +       if (!vxi)
23083 +               goto out;
23084 +
23085 +       buffer += sprintf(buffer, "BCaps:\t");
23086 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23087 +       buffer += sprintf(buffer, "\n");
23088 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23089 +               (unsigned long long)vxi->vx_ccaps);
23090 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23091 +               (unsigned long long)vxi->vx_flags);
23092 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23093 +
23094 +       put_vx_info(vxi);
23095 +out:
23096 +       return buffer - orig;
23097 +}
23098 +
23099 +
23100 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23101 +{
23102 +       struct nx_info *nxi;
23103 +       struct nx_addr_v4 *v4a;
23104 +#ifdef CONFIG_IPV6
23105 +       struct nx_addr_v6 *v6a;
23106 +#endif
23107 +       char *orig = buffer;
23108 +       int i;
23109 +
23110 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23111 +
23112 +       nxi = task_get_nx_info(p);
23113 +       if (!nxi)
23114 +               goto out;
23115 +
23116 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23117 +               (unsigned long long)nxi->nx_ncaps);
23118 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23119 +               (unsigned long long)nxi->nx_flags);
23120 +
23121 +       buffer += sprintf(buffer,
23122 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23123 +               NIPQUAD(nxi->v4_bcast.s_addr));
23124 +       buffer += sprintf (buffer,
23125 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
23126 +               NIPQUAD(nxi->v4_lback.s_addr));
23127 +       if (!NX_IPV4(nxi))
23128 +               goto skip_v4;
23129 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23130 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
23131 +                       i, NXAV4(v4a));
23132 +skip_v4:
23133 +#ifdef CONFIG_IPV6
23134 +       if (!NX_IPV6(nxi))
23135 +               goto skip_v6;
23136 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23137 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
23138 +                       i, NXAV6(v6a));
23139 +skip_v6:
23140 +#endif
23141 +       put_nx_info(nxi);
23142 +out:
23143 +       return buffer - orig;
23144 +}
23145 +
23146 diff -NurpP --minimal linux-2.6.33/kernel/vserver/sched.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/sched.c
23147 --- linux-2.6.33/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
23148 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/sched.c   2010-02-25 12:02:16.000000000 +0100
23149 @@ -0,0 +1,414 @@
23150 +/*
23151 + *  linux/kernel/vserver/sched.c
23152 + *
23153 + *  Virtual Server: Scheduler Support
23154 + *
23155 + *  Copyright (C) 2004-2007  Herbert Pötzl
23156 + *
23157 + *  V0.01  adapted Sam Vilains version to 2.6.3
23158 + *  V0.02  removed legacy interface
23159 + *  V0.03  changed vcmds to vxi arg
23160 + *  V0.04  removed older and legacy interfaces
23161 + *
23162 + */
23163 +
23164 +#include <linux/vs_context.h>
23165 +#include <linux/vs_sched.h>
23166 +#include <linux/vserver/sched_cmd.h>
23167 +
23168 +#include <asm/uaccess.h>
23169 +
23170 +
23171 +#define vxd_check_range(val, min, max) do {            \
23172 +       vxlprintk((val < min) || (val > max),           \
23173 +               "check_range(%ld,%ld,%ld)",             \
23174 +               (long)val, (long)min, (long)max,        \
23175 +               __FILE__, __LINE__);                    \
23176 +       } while (0)
23177 +
23178 +
23179 +void vx_update_sched_param(struct _vx_sched *sched,
23180 +       struct _vx_sched_pc *sched_pc)
23181 +{
23182 +       unsigned int set_mask = sched->update_mask;
23183 +
23184 +       if (set_mask & VXSM_FILL_RATE)
23185 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
23186 +       if (set_mask & VXSM_INTERVAL)
23187 +               sched_pc->interval[0] = sched->interval[0];
23188 +       if (set_mask & VXSM_FILL_RATE2)
23189 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
23190 +       if (set_mask & VXSM_INTERVAL2)
23191 +               sched_pc->interval[1] = sched->interval[1];
23192 +       if (set_mask & VXSM_TOKENS)
23193 +               sched_pc->tokens = sched->tokens;
23194 +       if (set_mask & VXSM_TOKENS_MIN)
23195 +               sched_pc->tokens_min = sched->tokens_min;
23196 +       if (set_mask & VXSM_TOKENS_MAX)
23197 +               sched_pc->tokens_max = sched->tokens_max;
23198 +       if (set_mask & VXSM_PRIO_BIAS)
23199 +               sched_pc->prio_bias = sched->prio_bias;
23200 +
23201 +       if (set_mask & VXSM_IDLE_TIME)
23202 +               sched_pc->flags |= VXSF_IDLE_TIME;
23203 +       else
23204 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
23205 +
23206 +       /* reset time */
23207 +       sched_pc->norm_time = jiffies;
23208 +}
23209 +
23210 +
23211 +/*
23212 + * recalculate the context's scheduling tokens
23213 + *
23214 + * ret > 0 : number of tokens available
23215 + * ret < 0 : on hold, check delta_min[]
23216 + *          -1 only jiffies
23217 + *          -2 also idle time
23218 + *
23219 + */
23220 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
23221 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
23222 +{
23223 +       long delta;
23224 +       long tokens = 0;
23225 +       int flags = sched_pc->flags;
23226 +
23227 +       /* how much time did pass? */
23228 +       delta = *norm_time - sched_pc->norm_time;
23229 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
23230 +       vxd_check_range(delta, 0, INT_MAX);
23231 +
23232 +       if (delta >= sched_pc->interval[0]) {
23233 +               long tokens, integral;
23234 +
23235 +               /* calc integral token part */
23236 +               tokens = delta / sched_pc->interval[0];
23237 +               integral = tokens * sched_pc->interval[0];
23238 +               tokens *= sched_pc->fill_rate[0];
23239 +#ifdef CONFIG_VSERVER_HARDCPU
23240 +               delta_min[0] = delta - integral;
23241 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
23242 +#endif
23243 +               /* advance time */
23244 +               sched_pc->norm_time += delta;
23245 +
23246 +               /* add tokens */
23247 +               sched_pc->tokens += tokens;
23248 +               sched_pc->token_time += tokens;
23249 +       } else
23250 +               delta_min[0] = delta;
23251 +
23252 +#ifdef CONFIG_VSERVER_IDLETIME
23253 +       if (!(flags & VXSF_IDLE_TIME))
23254 +               goto skip_idle;
23255 +
23256 +       /* how much was the idle skip? */
23257 +       delta = *idle_time - sched_pc->idle_time;
23258 +       vxd_check_range(delta, 0, INT_MAX);
23259 +
23260 +       if (delta >= sched_pc->interval[1]) {
23261 +               long tokens, integral;
23262 +
23263 +               /* calc fair share token part */
23264 +               tokens = delta / sched_pc->interval[1];
23265 +               integral = tokens * sched_pc->interval[1];
23266 +               tokens *= sched_pc->fill_rate[1];
23267 +               delta_min[1] = delta - integral;
23268 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23269 +
23270 +               /* advance idle time */
23271 +               sched_pc->idle_time += integral;
23272 +
23273 +               /* add tokens */
23274 +               sched_pc->tokens += tokens;
23275 +               sched_pc->token_time += tokens;
23276 +       } else
23277 +               delta_min[1] = delta;
23278 +skip_idle:
23279 +#endif
23280 +
23281 +       /* clip at maximum */
23282 +       if (sched_pc->tokens > sched_pc->tokens_max)
23283 +               sched_pc->tokens = sched_pc->tokens_max;
23284 +       tokens = sched_pc->tokens;
23285 +
23286 +       if ((flags & VXSF_ONHOLD)) {
23287 +               /* can we unhold? */
23288 +               if (tokens >= sched_pc->tokens_min) {
23289 +                       flags &= ~VXSF_ONHOLD;
23290 +                       sched_pc->hold_ticks +=
23291 +                               *norm_time - sched_pc->onhold;
23292 +               } else
23293 +                       goto on_hold;
23294 +       } else {
23295 +               /* put on hold? */
23296 +               if (tokens <= 0) {
23297 +                       flags |= VXSF_ONHOLD;
23298 +                       sched_pc->onhold = *norm_time;
23299 +                       goto on_hold;
23300 +               }
23301 +       }
23302 +       sched_pc->flags = flags;
23303 +       return tokens;
23304 +
23305 +on_hold:
23306 +       tokens = sched_pc->tokens_min - tokens;
23307 +       sched_pc->flags = flags;
23308 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
23309 +
23310 +#ifdef CONFIG_VSERVER_HARDCPU
23311 +       /* next interval? */
23312 +       if (!sched_pc->fill_rate[0])
23313 +               delta_min[0] = HZ;
23314 +       else if (tokens > sched_pc->fill_rate[0])
23315 +               delta_min[0] += sched_pc->interval[0] *
23316 +                       tokens / sched_pc->fill_rate[0];
23317 +       else
23318 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
23319 +       vxd_check_range(delta_min[0], 0, INT_MAX);
23320 +
23321 +#ifdef CONFIG_VSERVER_IDLETIME
23322 +       if (!(flags & VXSF_IDLE_TIME))
23323 +               return -1;
23324 +
23325 +       /* next interval? */
23326 +       if (!sched_pc->fill_rate[1])
23327 +               delta_min[1] = HZ;
23328 +       else if (tokens > sched_pc->fill_rate[1])
23329 +               delta_min[1] += sched_pc->interval[1] *
23330 +                       tokens / sched_pc->fill_rate[1];
23331 +       else
23332 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
23333 +       vxd_check_range(delta_min[1], 0, INT_MAX);
23334 +
23335 +       return -2;
23336 +#else
23337 +       return -1;
23338 +#endif /* CONFIG_VSERVER_IDLETIME */
23339 +#else
23340 +       return 0;
23341 +#endif /* CONFIG_VSERVER_HARDCPU */
23342 +}
23343 +
23344 +static inline unsigned long msec_to_ticks(unsigned long msec)
23345 +{
23346 +       return msecs_to_jiffies(msec);
23347 +}
23348 +
23349 +static inline unsigned long ticks_to_msec(unsigned long ticks)
23350 +{
23351 +       return jiffies_to_msecs(ticks);
23352 +}
23353 +
23354 +static inline unsigned long ticks_to_usec(unsigned long ticks)
23355 +{
23356 +       return jiffies_to_usecs(ticks);
23357 +}
23358 +
23359 +
23360 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
23361 +{
23362 +       unsigned int set_mask = data->mask;
23363 +       unsigned int update_mask;
23364 +       int i, cpu;
23365 +
23366 +       /* Sanity check data values */
23367 +       if (data->tokens_max <= 0)
23368 +               data->tokens_max = HZ;
23369 +       if (data->tokens_min < 0)
23370 +               data->tokens_min = HZ / 3;
23371 +       if (data->tokens_min >= data->tokens_max)
23372 +               data->tokens_min = data->tokens_max;
23373 +
23374 +       if (data->prio_bias > MAX_PRIO_BIAS)
23375 +               data->prio_bias = MAX_PRIO_BIAS;
23376 +       if (data->prio_bias < MIN_PRIO_BIAS)
23377 +               data->prio_bias = MIN_PRIO_BIAS;
23378 +
23379 +       spin_lock(&vxi->sched.tokens_lock);
23380 +
23381 +       /* sync up on delayed updates */
23382 +       for_each_cpu_mask(cpu, vxi->sched.update)
23383 +               vx_update_sched_param(&vxi->sched,
23384 +                       &vx_per_cpu(vxi, sched_pc, cpu));
23385 +
23386 +       if (set_mask & VXSM_FILL_RATE)
23387 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
23388 +       if (set_mask & VXSM_FILL_RATE2)
23389 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
23390 +       if (set_mask & VXSM_INTERVAL)
23391 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
23392 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
23393 +       if (set_mask & VXSM_INTERVAL2)
23394 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
23395 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
23396 +       if (set_mask & VXSM_TOKENS)
23397 +               vxi->sched.tokens = data->tokens;
23398 +       if (set_mask & VXSM_TOKENS_MIN)
23399 +               vxi->sched.tokens_min = data->tokens_min;
23400 +       if (set_mask & VXSM_TOKENS_MAX)
23401 +               vxi->sched.tokens_max = data->tokens_max;
23402 +       if (set_mask & VXSM_PRIO_BIAS)
23403 +               vxi->sched.prio_bias = data->prio_bias;
23404 +
23405 +       /* Sanity check rate/interval */
23406 +       for (i = 0; i < 2; i++) {
23407 +               if (data->fill_rate[i] < 0)
23408 +                       data->fill_rate[i] = 0;
23409 +               if (data->interval[i] <= 0)
23410 +                       data->interval[i] = HZ;
23411 +       }
23412 +
23413 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
23414 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
23415 +       vxi->sched.update_mask = update_mask;
23416 +
23417 +#ifdef CONFIG_SMP
23418 +       rmb();
23419 +       if (set_mask & VXSM_CPU_ID) {
23420 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
23421 +               cpus_and(vxi->sched.update, cpu_online_map,
23422 +                       vxi->sched.update);
23423 +       } else
23424 +               vxi->sched.update = cpu_online_map;
23425 +
23426 +       /* forced reload? */
23427 +       if (set_mask & VXSM_FORCE) {
23428 +               for_each_cpu_mask(cpu, vxi->sched.update)
23429 +                       vx_update_sched_param(&vxi->sched,
23430 +                               &vx_per_cpu(vxi, sched_pc, cpu));
23431 +               vxi->sched.update = CPU_MASK_NONE;
23432 +       }
23433 +#else
23434 +       /* on UP we update immediately */
23435 +       vx_update_sched_param(&vxi->sched,
23436 +               &vx_per_cpu(vxi, sched_pc, 0));
23437 +#endif
23438 +
23439 +       spin_unlock(&vxi->sched.tokens_lock);
23440 +       return 0;
23441 +}
23442 +
23443 +
23444 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
23445 +#define COPY_PRI(C) C(prio_bias)
23446 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23447 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
23448 +                   C(fill_rate[1]); C(interval[1]);
23449 +
23450 +#define COPY_VALUE(name) vc_data.name = data->name
23451 +
23452 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
23453 +{
23454 +       struct vcmd_sched_v5 vc_data;
23455 +
23456 +       vc_data.mask = data->set_mask;
23457 +       COPY_IDS(COPY_VALUE);
23458 +       COPY_PRI(COPY_VALUE);
23459 +       COPY_TOK(COPY_VALUE);
23460 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
23461 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
23462 +       return do_set_sched(vxi, &vc_data);
23463 +}
23464 +
23465 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
23466 +{
23467 +       struct vcmd_set_sched_v4 vc_data;
23468 +
23469 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23470 +               return -EFAULT;
23471 +
23472 +       return do_set_sched_v4(vxi, &vc_data);
23473 +}
23474 +
23475 +       /* latest interface is v5 */
23476 +
23477 +int vc_set_sched(struct vx_info *vxi, void __user *data)
23478 +{
23479 +       struct vcmd_sched_v5 vc_data;
23480 +
23481 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23482 +               return -EFAULT;
23483 +
23484 +       return do_set_sched(vxi, &vc_data);
23485 +}
23486 +
23487 +
23488 +#define COPY_PRI(C) C(prio_bias)
23489 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23490 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
23491 +                   C(fill_rate[1]); C(interval[1]);
23492 +
23493 +#define COPY_VALUE(name) vc_data.name = data->name
23494 +
23495 +
23496 +int vc_get_sched(struct vx_info *vxi, void __user *data)
23497 +{
23498 +       struct vcmd_sched_v5 vc_data;
23499 +
23500 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23501 +               return -EFAULT;
23502 +
23503 +       if (vc_data.mask & VXSM_CPU_ID) {
23504 +               int cpu = vc_data.cpu_id;
23505 +               struct _vx_sched_pc *data;
23506 +
23507 +               if (!cpu_possible(cpu))
23508 +                       return -EINVAL;
23509 +
23510 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
23511 +               COPY_TOK(COPY_VALUE);
23512 +               COPY_PRI(COPY_VALUE);
23513 +               COPY_FRI(COPY_VALUE);
23514 +
23515 +               if (data->flags & VXSF_IDLE_TIME)
23516 +                       vc_data.mask |= VXSM_IDLE_TIME;
23517 +       } else {
23518 +               struct _vx_sched *data = &vxi->sched;
23519 +
23520 +               COPY_TOK(COPY_VALUE);
23521 +               COPY_PRI(COPY_VALUE);
23522 +               COPY_FRI(COPY_VALUE);
23523 +       }
23524 +
23525 +       if (vc_data.mask & VXSM_MSEC) {
23526 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
23527 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
23528 +       }
23529 +
23530 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23531 +               return -EFAULT;
23532 +       return 0;
23533 +}
23534 +
23535 +
23536 +int vc_sched_info(struct vx_info *vxi, void __user *data)
23537 +{
23538 +       struct vcmd_sched_info vc_data;
23539 +       int cpu;
23540 +
23541 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23542 +               return -EFAULT;
23543 +
23544 +       cpu = vc_data.cpu_id;
23545 +       if (!cpu_possible(cpu))
23546 +               return -EINVAL;
23547 +
23548 +       if (vxi) {
23549 +               struct _vx_sched_pc *sched_pc =
23550 +                       &vx_per_cpu(vxi, sched_pc, cpu);
23551 +
23552 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
23553 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
23554 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
23555 +               vc_data.vavavoom = sched_pc->vavavoom;
23556 +       }
23557 +       vc_data.token_usec = ticks_to_usec(1);
23558 +
23559 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23560 +               return -EFAULT;
23561 +       return 0;
23562 +}
23563 +
23564 diff -NurpP --minimal linux-2.6.33/kernel/vserver/sched_init.h linux-2.6.33-vs2.3.0.36.30/kernel/vserver/sched_init.h
23565 --- linux-2.6.33/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
23566 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/sched_init.h      2010-02-25 12:02:16.000000000 +0100
23567 @@ -0,0 +1,50 @@
23568 +
23569 +static inline void vx_info_init_sched(struct _vx_sched *sched)
23570 +{
23571 +       static struct lock_class_key tokens_lock_key;
23572 +
23573 +       /* scheduling; hard code starting values as constants */
23574 +       sched->fill_rate[0]     = 1;
23575 +       sched->interval[0]      = 4;
23576 +       sched->fill_rate[1]     = 1;
23577 +       sched->interval[1]      = 8;
23578 +       sched->tokens           = HZ >> 2;
23579 +       sched->tokens_min       = HZ >> 4;
23580 +       sched->tokens_max       = HZ >> 1;
23581 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
23582 +       sched->prio_bias        = 0;
23583 +
23584 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
23585 +}
23586 +
23587 +static inline
23588 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
23589 +{
23590 +       sched_pc->fill_rate[0]  = 1;
23591 +       sched_pc->interval[0]   = 4;
23592 +       sched_pc->fill_rate[1]  = 1;
23593 +       sched_pc->interval[1]   = 8;
23594 +       sched_pc->tokens        = HZ >> 2;
23595 +       sched_pc->tokens_min    = HZ >> 4;
23596 +       sched_pc->tokens_max    = HZ >> 1;
23597 +       sched_pc->prio_bias     = 0;
23598 +       sched_pc->vavavoom      = 0;
23599 +       sched_pc->token_time    = 0;
23600 +       sched_pc->idle_time     = 0;
23601 +       sched_pc->norm_time     = jiffies;
23602 +
23603 +       sched_pc->user_ticks = 0;
23604 +       sched_pc->sys_ticks = 0;
23605 +       sched_pc->hold_ticks = 0;
23606 +}
23607 +
23608 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
23609 +{
23610 +       return;
23611 +}
23612 +
23613 +static inline
23614 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
23615 +{
23616 +       return;
23617 +}
23618 diff -NurpP --minimal linux-2.6.33/kernel/vserver/sched_proc.h linux-2.6.33-vs2.3.0.36.30/kernel/vserver/sched_proc.h
23619 --- linux-2.6.33/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
23620 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/sched_proc.h      2010-02-25 12:02:16.000000000 +0100
23621 @@ -0,0 +1,57 @@
23622 +#ifndef _VX_SCHED_PROC_H
23623 +#define _VX_SCHED_PROC_H
23624 +
23625 +
23626 +static inline
23627 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
23628 +{
23629 +       int length = 0;
23630 +
23631 +       length += sprintf(buffer,
23632 +               "FillRate:\t%8d,%d\n"
23633 +               "Interval:\t%8d,%d\n"
23634 +               "TokensMin:\t%8d\n"
23635 +               "TokensMax:\t%8d\n"
23636 +               "PrioBias:\t%8d\n",
23637 +               sched->fill_rate[0],
23638 +               sched->fill_rate[1],
23639 +               sched->interval[0],
23640 +               sched->interval[1],
23641 +               sched->tokens_min,
23642 +               sched->tokens_max,
23643 +               sched->prio_bias);
23644 +       return length;
23645 +}
23646 +
23647 +static inline
23648 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
23649 +       char *buffer, int cpu)
23650 +{
23651 +       int length = 0;
23652 +
23653 +       length += sprintf(buffer + length,
23654 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
23655 +               (unsigned long long)sched_pc->user_ticks,
23656 +               (unsigned long long)sched_pc->sys_ticks,
23657 +               (unsigned long long)sched_pc->hold_ticks,
23658 +               sched_pc->token_time,
23659 +               sched_pc->idle_time);
23660 +       length += sprintf(buffer + length,
23661 +               " %c%c %d %d %d %d/%d %d/%d",
23662 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
23663 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
23664 +               sched_pc->tokens,
23665 +               sched_pc->tokens_min,
23666 +               sched_pc->tokens_max,
23667 +               sched_pc->fill_rate[0],
23668 +               sched_pc->interval[0],
23669 +               sched_pc->fill_rate[1],
23670 +               sched_pc->interval[1]);
23671 +       length += sprintf(buffer + length,
23672 +               " %d %d\n",
23673 +               sched_pc->prio_bias,
23674 +               sched_pc->vavavoom);
23675 +       return length;
23676 +}
23677 +
23678 +#endif /* _VX_SCHED_PROC_H */
23679 diff -NurpP --minimal linux-2.6.33/kernel/vserver/signal.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/signal.c
23680 --- linux-2.6.33/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
23681 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/signal.c  2010-02-25 12:02:16.000000000 +0100
23682 @@ -0,0 +1,132 @@
23683 +/*
23684 + *  linux/kernel/vserver/signal.c
23685 + *
23686 + *  Virtual Server: Signal Support
23687 + *
23688 + *  Copyright (C) 2003-2007  Herbert Pötzl
23689 + *
23690 + *  V0.01  broken out from vcontext V0.05
23691 + *  V0.02  changed vcmds to vxi arg
23692 + *  V0.03  adjusted siginfo for kill
23693 + *
23694 + */
23695 +
23696 +#include <asm/uaccess.h>
23697 +
23698 +#include <linux/vs_context.h>
23699 +#include <linux/vs_pid.h>
23700 +#include <linux/vserver/signal_cmd.h>
23701 +
23702 +
23703 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
23704 +{
23705 +       int retval, count = 0;
23706 +       struct task_struct *p;
23707 +       struct siginfo *sip = SEND_SIG_PRIV;
23708 +
23709 +       retval = -ESRCH;
23710 +       vxdprintk(VXD_CBIT(misc, 4),
23711 +               "vx_info_kill(%p[#%d],%d,%d)*",
23712 +               vxi, vxi->vx_id, pid, sig);
23713 +       read_lock(&tasklist_lock);
23714 +       switch (pid) {
23715 +       case  0:
23716 +       case -1:
23717 +               for_each_process(p) {
23718 +                       int err = 0;
23719 +
23720 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
23721 +                               (pid && vxi->vx_initpid == p->pid))
23722 +                               continue;
23723 +
23724 +                       err = group_send_sig_info(sig, sip, p);
23725 +                       ++count;
23726 +                       if (err != -EPERM)
23727 +                               retval = err;
23728 +               }
23729 +               break;
23730 +
23731 +       case 1:
23732 +               if (vxi->vx_initpid) {
23733 +                       pid = vxi->vx_initpid;
23734 +                       /* for now, only SIGINT to private init ... */
23735 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
23736 +                               /* ... as long as there are tasks left */
23737 +                               (atomic_read(&vxi->vx_tasks) > 1))
23738 +                               sig = SIGINT;
23739 +               }
23740 +               /* fallthrough */
23741 +       default:
23742 +               p = find_task_by_real_pid(pid);
23743 +               if (p) {
23744 +                       if (vx_task_xid(p) == vxi->vx_id)
23745 +                               retval = group_send_sig_info(sig, sip, p);
23746 +               }
23747 +               break;
23748 +       }
23749 +       read_unlock(&tasklist_lock);
23750 +       vxdprintk(VXD_CBIT(misc, 4),
23751 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
23752 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
23753 +       return retval;
23754 +}
23755 +
23756 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
23757 +{
23758 +       struct vcmd_ctx_kill_v0 vc_data;
23759 +
23760 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23761 +               return -EFAULT;
23762 +
23763 +       /* special check to allow guest shutdown */
23764 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
23765 +               /* forbid killall pid=0 when init is present */
23766 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
23767 +               (vc_data.pid > 1)))
23768 +               return -EACCES;
23769 +
23770 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
23771 +}
23772 +
23773 +
23774 +static int __wait_exit(struct vx_info *vxi)
23775 +{
23776 +       DECLARE_WAITQUEUE(wait, current);
23777 +       int ret = 0;
23778 +
23779 +       add_wait_queue(&vxi->vx_wait, &wait);
23780 +       set_current_state(TASK_INTERRUPTIBLE);
23781 +
23782 +wait:
23783 +       if (vx_info_state(vxi,
23784 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
23785 +               goto out;
23786 +       if (signal_pending(current)) {
23787 +               ret = -ERESTARTSYS;
23788 +               goto out;
23789 +       }
23790 +       schedule();
23791 +       goto wait;
23792 +
23793 +out:
23794 +       set_current_state(TASK_RUNNING);
23795 +       remove_wait_queue(&vxi->vx_wait, &wait);
23796 +       return ret;
23797 +}
23798 +
23799 +
23800 +
23801 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
23802 +{
23803 +       struct vcmd_wait_exit_v0 vc_data;
23804 +       int ret;
23805 +
23806 +       ret = __wait_exit(vxi);
23807 +       vc_data.reboot_cmd = vxi->reboot_cmd;
23808 +       vc_data.exit_code = vxi->exit_code;
23809 +
23810 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23811 +               ret = -EFAULT;
23812 +       return ret;
23813 +}
23814 +
23815 diff -NurpP --minimal linux-2.6.33/kernel/vserver/space.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/space.c
23816 --- linux-2.6.33/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
23817 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/space.c   2010-02-25 12:02:16.000000000 +0100
23818 @@ -0,0 +1,375 @@
23819 +/*
23820 + *  linux/kernel/vserver/space.c
23821 + *
23822 + *  Virtual Server: Context Space Support
23823 + *
23824 + *  Copyright (C) 2003-2007  Herbert Pötzl
23825 + *
23826 + *  V0.01  broken out from context.c 0.07
23827 + *  V0.02  added task locking for namespace
23828 + *  V0.03  broken out vx_enter_namespace
23829 + *  V0.04  added *space support and commands
23830 + *
23831 + */
23832 +
23833 +#include <linux/utsname.h>
23834 +#include <linux/nsproxy.h>
23835 +#include <linux/err.h>
23836 +#include <linux/fs_struct.h>
23837 +#include <asm/uaccess.h>
23838 +
23839 +#include <linux/vs_context.h>
23840 +#include <linux/vserver/space.h>
23841 +#include <linux/vserver/space_cmd.h>
23842 +
23843 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
23844 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
23845 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
23846 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
23847 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
23848 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
23849 +
23850 +
23851 +/* namespace functions */
23852 +
23853 +#include <linux/mnt_namespace.h>
23854 +#include <linux/user_namespace.h>
23855 +#include <linux/pid_namespace.h>
23856 +#include <linux/ipc_namespace.h>
23857 +#include <net/net_namespace.h>
23858 +
23859 +
23860 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
23861 +       .mask = CLONE_FS |
23862 +               CLONE_NEWNS |
23863 +               CLONE_NEWUTS |
23864 +               CLONE_NEWIPC |
23865 +               CLONE_NEWUSER |
23866 +               0
23867 +};
23868 +
23869 +static const struct vcmd_space_mask_v1 space_mask = {
23870 +       .mask = CLONE_FS |
23871 +               CLONE_NEWNS |
23872 +               CLONE_NEWUTS |
23873 +               CLONE_NEWIPC |
23874 +               CLONE_NEWUSER |
23875 +#ifdef CONFIG_PID_NS
23876 +               CLONE_NEWPID |
23877 +#endif
23878 +#ifdef CONFIG_NET_NS
23879 +               CLONE_NEWNET |
23880 +#endif
23881 +               0
23882 +};
23883 +
23884 +static const struct vcmd_space_mask_v1 default_space_mask = {
23885 +       .mask = CLONE_FS |
23886 +               CLONE_NEWNS |
23887 +               CLONE_NEWUTS |
23888 +               CLONE_NEWIPC |
23889 +               CLONE_NEWUSER |
23890 +#ifdef CONFIG_PID_NS
23891 +//             CLONE_NEWPID |
23892 +#endif
23893 +               0
23894 +};
23895 +
23896 +/*
23897 + *     build a new nsproxy mix
23898 + *      assumes that both proxies are 'const'
23899 + *     does not touch nsproxy refcounts
23900 + *     will hold a reference on the result.
23901 + */
23902 +
23903 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
23904 +       struct nsproxy *new_nsproxy, unsigned long mask)
23905 +{
23906 +       struct mnt_namespace *old_ns;
23907 +       struct uts_namespace *old_uts;
23908 +       struct ipc_namespace *old_ipc;
23909 +#ifdef CONFIG_PID_NS
23910 +       struct pid_namespace *old_pid;
23911 +#endif
23912 +#ifdef CONFIG_NET_NS
23913 +       struct net *old_net;
23914 +#endif
23915 +       struct nsproxy *nsproxy;
23916 +
23917 +       nsproxy = copy_nsproxy(old_nsproxy);
23918 +       if (!nsproxy)
23919 +               goto out;
23920 +
23921 +       if (mask & CLONE_NEWNS) {
23922 +               old_ns = nsproxy->mnt_ns;
23923 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
23924 +               if (nsproxy->mnt_ns)
23925 +                       get_mnt_ns(nsproxy->mnt_ns);
23926 +       } else
23927 +               old_ns = NULL;
23928 +
23929 +       if (mask & CLONE_NEWUTS) {
23930 +               old_uts = nsproxy->uts_ns;
23931 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
23932 +               if (nsproxy->uts_ns)
23933 +                       get_uts_ns(nsproxy->uts_ns);
23934 +       } else
23935 +               old_uts = NULL;
23936 +
23937 +       if (mask & CLONE_NEWIPC) {
23938 +               old_ipc = nsproxy->ipc_ns;
23939 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
23940 +               if (nsproxy->ipc_ns)
23941 +                       get_ipc_ns(nsproxy->ipc_ns);
23942 +       } else
23943 +               old_ipc = NULL;
23944 +
23945 +#ifdef CONFIG_PID_NS
23946 +       if (mask & CLONE_NEWPID) {
23947 +               old_pid = nsproxy->pid_ns;
23948 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23949 +               if (nsproxy->pid_ns)
23950 +                       get_pid_ns(nsproxy->pid_ns);
23951 +       } else
23952 +               old_pid = NULL;
23953 +#endif
23954 +#ifdef CONFIG_NET_NS
23955 +       if (mask & CLONE_NEWNET) {
23956 +               old_net = nsproxy->net_ns;
23957 +               nsproxy->net_ns = new_nsproxy->net_ns;
23958 +               if (nsproxy->net_ns)
23959 +                       get_net(nsproxy->net_ns);
23960 +       } else
23961 +               old_net = NULL;
23962 +#endif
23963 +       if (old_ns)
23964 +               put_mnt_ns(old_ns);
23965 +       if (old_uts)
23966 +               put_uts_ns(old_uts);
23967 +       if (old_ipc)
23968 +               put_ipc_ns(old_ipc);
23969 +#ifdef CONFIG_PID_NS
23970 +       if (old_pid)
23971 +               put_pid_ns(old_pid);
23972 +#endif
23973 +#ifdef CONFIG_NET_NS
23974 +       if (old_net)
23975 +               put_net(old_net);
23976 +#endif
23977 +out:
23978 +       return nsproxy;
23979 +}
23980 +
23981 +
23982 +/*
23983 + *     merge two nsproxy structs into a new one.
23984 + *     will hold a reference on the result.
23985 + */
23986 +
23987 +static inline
23988 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
23989 +       struct nsproxy *proxy, unsigned long mask)
23990 +{
23991 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
23992 +
23993 +       if (!proxy)
23994 +               return NULL;
23995 +
23996 +       if (mask) {
23997 +               /* vs_mix_nsproxy returns with reference */
23998 +               return vs_mix_nsproxy(old ? old : &null_proxy,
23999 +                       proxy, mask);
24000 +       }
24001 +       get_nsproxy(proxy);
24002 +       return proxy;
24003 +}
24004 +
24005 +
24006 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24007 +{
24008 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24009 +       struct fs_struct *fs_cur, *fs = NULL;
24010 +       int ret, kill = 0;
24011 +
24012 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24013 +               vxi, vxi->vx_id, mask, index);
24014 +
24015 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24016 +               return -EACCES;
24017 +
24018 +       if (!mask)
24019 +               mask = vxi->vx_nsmask[index];
24020 +
24021 +       if ((mask & vxi->vx_nsmask[index]) != mask)
24022 +               return -EINVAL;
24023 +
24024 +       if (mask & CLONE_FS) {
24025 +               fs = copy_fs_struct(vxi->vx_fs[index]);
24026 +               if (!fs)
24027 +                       return -ENOMEM;
24028 +       }
24029 +       proxy = vxi->vx_nsproxy[index];
24030 +
24031 +       vxdprintk(VXD_CBIT(space, 9),
24032 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
24033 +               vxi, vxi->vx_id, mask, index, proxy, fs);
24034 +
24035 +       task_lock(current);
24036 +       fs_cur = current->fs;
24037 +
24038 +       if (mask & CLONE_FS) {
24039 +               write_lock(&fs_cur->lock);
24040 +               current->fs = fs;
24041 +               kill = !--fs_cur->users;
24042 +               write_unlock(&fs_cur->lock);
24043 +       }
24044 +
24045 +       proxy_cur = current->nsproxy;
24046 +       get_nsproxy(proxy_cur);
24047 +       task_unlock(current);
24048 +
24049 +       if (kill)
24050 +               free_fs_struct(fs_cur);
24051 +
24052 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24053 +       if (IS_ERR(proxy_new)) {
24054 +               ret = PTR_ERR(proxy_new);
24055 +               goto out_put;
24056 +       }
24057 +
24058 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24059 +       ret = 0;
24060 +
24061 +       if (proxy_new)
24062 +               put_nsproxy(proxy_new);
24063 +out_put:
24064 +       if (proxy_cur)
24065 +               put_nsproxy(proxy_cur);
24066 +       return ret;
24067 +}
24068 +
24069 +
24070 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24071 +{
24072 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24073 +       struct fs_struct *fs_vxi, *fs;
24074 +       int ret, kill = 0;
24075 +
24076 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24077 +               vxi, vxi->vx_id, mask, index);
24078 +#if 0
24079 +       if (!mask)
24080 +               mask = default_space_mask.mask;
24081 +#endif
24082 +       if ((mask & space_mask.mask) != mask)
24083 +               return -EINVAL;
24084 +
24085 +       proxy_vxi = vxi->vx_nsproxy[index];
24086 +       fs_vxi = vxi->vx_fs[index];
24087 +
24088 +       if (mask & CLONE_FS) {
24089 +               fs = copy_fs_struct(current->fs);
24090 +               if (!fs)
24091 +                       return -ENOMEM;
24092 +       }
24093 +
24094 +       task_lock(current);
24095 +
24096 +       if (mask & CLONE_FS) {
24097 +               write_lock(&fs_vxi->lock);
24098 +               vxi->vx_fs[index] = fs;
24099 +               kill = !--fs_vxi->users;
24100 +               write_unlock(&fs_vxi->lock);
24101 +       }
24102 +
24103 +       proxy_cur = current->nsproxy;
24104 +       get_nsproxy(proxy_cur);
24105 +       task_unlock(current);
24106 +
24107 +       if (kill)
24108 +               free_fs_struct(fs_vxi);
24109 +
24110 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24111 +       if (IS_ERR(proxy_new)) {
24112 +               ret = PTR_ERR(proxy_new);
24113 +               goto out_put;
24114 +       }
24115 +
24116 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
24117 +       vxi->vx_nsmask[index] |= mask;
24118 +       ret = 0;
24119 +
24120 +       if (proxy_new)
24121 +               put_nsproxy(proxy_new);
24122 +out_put:
24123 +       if (proxy_cur)
24124 +               put_nsproxy(proxy_cur);
24125 +       return ret;
24126 +}
24127 +
24128 +
24129 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
24130 +{
24131 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24132 +
24133 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24134 +               return -EFAULT;
24135 +
24136 +       return vx_enter_space(vxi, vc_data.mask, 0);
24137 +}
24138 +
24139 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24140 +{
24141 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24142 +
24143 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24144 +               return -EFAULT;
24145 +
24146 +       if (vc_data.index >= VX_SPACES)
24147 +               return -EINVAL;
24148 +
24149 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
24150 +}
24151 +
24152 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
24153 +{
24154 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24155 +
24156 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24157 +               return -EFAULT;
24158 +
24159 +       return vx_set_space(vxi, vc_data.mask, 0);
24160 +}
24161 +
24162 +int vc_set_space(struct vx_info *vxi, void __user *data)
24163 +{
24164 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24165 +
24166 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24167 +               return -EFAULT;
24168 +
24169 +       if (vc_data.index >= VX_SPACES)
24170 +               return -EINVAL;
24171 +
24172 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
24173 +}
24174 +
24175 +int vc_get_space_mask(void __user *data, int type)
24176 +{
24177 +       const struct vcmd_space_mask_v1 *mask;
24178 +
24179 +       if (type == 0)
24180 +               mask = &space_mask_v0;
24181 +       else if (type == 1)
24182 +               mask = &space_mask;
24183 +       else
24184 +               mask = &default_space_mask;
24185 +
24186 +       vxdprintk(VXD_CBIT(space, 10),
24187 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24188 +
24189 +       if (copy_to_user(data, mask, sizeof(*mask)))
24190 +               return -EFAULT;
24191 +       return 0;
24192 +}
24193 +
24194 diff -NurpP --minimal linux-2.6.33/kernel/vserver/switch.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/switch.c
24195 --- linux-2.6.33/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
24196 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/switch.c  2010-02-25 12:02:16.000000000 +0100
24197 @@ -0,0 +1,546 @@
24198 +/*
24199 + *  linux/kernel/vserver/switch.c
24200 + *
24201 + *  Virtual Server: Syscall Switch
24202 + *
24203 + *  Copyright (C) 2003-2007  Herbert Pötzl
24204 + *
24205 + *  V0.01  syscall switch
24206 + *  V0.02  added signal to context
24207 + *  V0.03  added rlimit functions
24208 + *  V0.04  added iattr, task/xid functions
24209 + *  V0.05  added debug/history stuff
24210 + *  V0.06  added compat32 layer
24211 + *  V0.07  vcmd args and perms
24212 + *  V0.08  added status commands
24213 + *  V0.09  added tag commands
24214 + *  V0.10  added oom bias
24215 + *  V0.11  added device commands
24216 + *
24217 + */
24218 +
24219 +#include <linux/vs_context.h>
24220 +#include <linux/vs_network.h>
24221 +#include <linux/vserver/switch.h>
24222 +
24223 +#include "vci_config.h"
24224 +
24225 +
24226 +static inline
24227 +int vc_get_version(uint32_t id)
24228 +{
24229 +       return VCI_VERSION;
24230 +}
24231 +
24232 +static inline
24233 +int vc_get_vci(uint32_t id)
24234 +{
24235 +       return vci_kernel_config();
24236 +}
24237 +
24238 +#include <linux/vserver/context_cmd.h>
24239 +#include <linux/vserver/cvirt_cmd.h>
24240 +#include <linux/vserver/cacct_cmd.h>
24241 +#include <linux/vserver/limit_cmd.h>
24242 +#include <linux/vserver/network_cmd.h>
24243 +#include <linux/vserver/sched_cmd.h>
24244 +#include <linux/vserver/debug_cmd.h>
24245 +#include <linux/vserver/inode_cmd.h>
24246 +#include <linux/vserver/dlimit_cmd.h>
24247 +#include <linux/vserver/signal_cmd.h>
24248 +#include <linux/vserver/space_cmd.h>
24249 +#include <linux/vserver/tag_cmd.h>
24250 +#include <linux/vserver/device_cmd.h>
24251 +
24252 +#include <linux/vserver/inode.h>
24253 +#include <linux/vserver/dlimit.h>
24254 +
24255 +
24256 +#ifdef CONFIG_COMPAT
24257 +#define __COMPAT(name, id, data, compat)       \
24258 +       (compat) ? name ## _x32(id, data) : name(id, data)
24259 +#define __COMPAT_NO_ID(name, data, compat)     \
24260 +       (compat) ? name ## _x32(data) : name(data)
24261 +#else
24262 +#define __COMPAT(name, id, data, compat)       \
24263 +       name(id, data)
24264 +#define __COMPAT_NO_ID(name, data, compat)     \
24265 +       name(data)
24266 +#endif
24267 +
24268 +
24269 +static inline
24270 +long do_vcmd(uint32_t cmd, uint32_t id,
24271 +       struct vx_info *vxi, struct nx_info *nxi,
24272 +       void __user *data, int compat)
24273 +{
24274 +       switch (cmd) {
24275 +
24276 +       case VCMD_get_version:
24277 +               return vc_get_version(id);
24278 +       case VCMD_get_vci:
24279 +               return vc_get_vci(id);
24280 +
24281 +       case VCMD_task_xid:
24282 +               return vc_task_xid(id);
24283 +       case VCMD_vx_info:
24284 +               return vc_vx_info(vxi, data);
24285 +
24286 +       case VCMD_task_nid:
24287 +               return vc_task_nid(id);
24288 +       case VCMD_nx_info:
24289 +               return vc_nx_info(nxi, data);
24290 +
24291 +       case VCMD_task_tag:
24292 +               return vc_task_tag(id);
24293 +
24294 +       case VCMD_set_space_v1:
24295 +               return vc_set_space_v1(vxi, data);
24296 +       /* this is version 2 */
24297 +       case VCMD_set_space:
24298 +               return vc_set_space(vxi, data);
24299 +
24300 +       case VCMD_get_space_mask_v0:
24301 +               return vc_get_space_mask(data, 0);
24302 +       /* this is version 1 */
24303 +       case VCMD_get_space_mask:
24304 +               return vc_get_space_mask(data, 1);
24305 +
24306 +       case VCMD_get_space_default:
24307 +               return vc_get_space_mask(data, -1);
24308 +
24309 +#ifdef CONFIG_IA32_EMULATION
24310 +       case VCMD_get_rlimit:
24311 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
24312 +       case VCMD_set_rlimit:
24313 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
24314 +#else
24315 +       case VCMD_get_rlimit:
24316 +               return vc_get_rlimit(vxi, data);
24317 +       case VCMD_set_rlimit:
24318 +               return vc_set_rlimit(vxi, data);
24319 +#endif
24320 +       case VCMD_get_rlimit_mask:
24321 +               return vc_get_rlimit_mask(id, data);
24322 +       case VCMD_reset_hits:
24323 +               return vc_reset_hits(vxi, data);
24324 +       case VCMD_reset_minmax:
24325 +               return vc_reset_minmax(vxi, data);
24326 +
24327 +       case VCMD_get_vhi_name:
24328 +               return vc_get_vhi_name(vxi, data);
24329 +       case VCMD_set_vhi_name:
24330 +               return vc_set_vhi_name(vxi, data);
24331 +
24332 +       case VCMD_ctx_stat:
24333 +               return vc_ctx_stat(vxi, data);
24334 +       case VCMD_virt_stat:
24335 +               return vc_virt_stat(vxi, data);
24336 +       case VCMD_sock_stat:
24337 +               return vc_sock_stat(vxi, data);
24338 +       case VCMD_rlimit_stat:
24339 +               return vc_rlimit_stat(vxi, data);
24340 +
24341 +       case VCMD_set_cflags:
24342 +               return vc_set_cflags(vxi, data);
24343 +       case VCMD_get_cflags:
24344 +               return vc_get_cflags(vxi, data);
24345 +
24346 +       /* this is version 1 */
24347 +       case VCMD_set_ccaps:
24348 +               return vc_set_ccaps(vxi, data);
24349 +       /* this is version 1 */
24350 +       case VCMD_get_ccaps:
24351 +               return vc_get_ccaps(vxi, data);
24352 +       case VCMD_set_bcaps:
24353 +               return vc_set_bcaps(vxi, data);
24354 +       case VCMD_get_bcaps:
24355 +               return vc_get_bcaps(vxi, data);
24356 +
24357 +       case VCMD_set_badness:
24358 +               return vc_set_badness(vxi, data);
24359 +       case VCMD_get_badness:
24360 +               return vc_get_badness(vxi, data);
24361 +
24362 +       case VCMD_set_nflags:
24363 +               return vc_set_nflags(nxi, data);
24364 +       case VCMD_get_nflags:
24365 +               return vc_get_nflags(nxi, data);
24366 +
24367 +       case VCMD_set_ncaps:
24368 +               return vc_set_ncaps(nxi, data);
24369 +       case VCMD_get_ncaps:
24370 +               return vc_get_ncaps(nxi, data);
24371 +
24372 +       case VCMD_set_sched_v4:
24373 +               return vc_set_sched_v4(vxi, data);
24374 +       /* this is version 5 */
24375 +       case VCMD_set_sched:
24376 +               return vc_set_sched(vxi, data);
24377 +       case VCMD_get_sched:
24378 +               return vc_get_sched(vxi, data);
24379 +       case VCMD_sched_info:
24380 +               return vc_sched_info(vxi, data);
24381 +
24382 +       case VCMD_add_dlimit:
24383 +               return __COMPAT(vc_add_dlimit, id, data, compat);
24384 +       case VCMD_rem_dlimit:
24385 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
24386 +       case VCMD_set_dlimit:
24387 +               return __COMPAT(vc_set_dlimit, id, data, compat);
24388 +       case VCMD_get_dlimit:
24389 +               return __COMPAT(vc_get_dlimit, id, data, compat);
24390 +
24391 +       case VCMD_ctx_kill:
24392 +               return vc_ctx_kill(vxi, data);
24393 +
24394 +       case VCMD_wait_exit:
24395 +               return vc_wait_exit(vxi, data);
24396 +
24397 +       case VCMD_get_iattr:
24398 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
24399 +       case VCMD_set_iattr:
24400 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
24401 +
24402 +       case VCMD_fget_iattr:
24403 +               return vc_fget_iattr(id, data);
24404 +       case VCMD_fset_iattr:
24405 +               return vc_fset_iattr(id, data);
24406 +
24407 +       case VCMD_enter_space_v0:
24408 +               return vc_enter_space_v1(vxi, NULL);
24409 +       case VCMD_enter_space_v1:
24410 +               return vc_enter_space_v1(vxi, data);
24411 +       /* this is version 2 */
24412 +       case VCMD_enter_space:
24413 +               return vc_enter_space(vxi, data);
24414 +
24415 +       case VCMD_ctx_create_v0:
24416 +               return vc_ctx_create(id, NULL);
24417 +       case VCMD_ctx_create:
24418 +               return vc_ctx_create(id, data);
24419 +       case VCMD_ctx_migrate_v0:
24420 +               return vc_ctx_migrate(vxi, NULL);
24421 +       case VCMD_ctx_migrate:
24422 +               return vc_ctx_migrate(vxi, data);
24423 +
24424 +       case VCMD_net_create_v0:
24425 +               return vc_net_create(id, NULL);
24426 +       case VCMD_net_create:
24427 +               return vc_net_create(id, data);
24428 +       case VCMD_net_migrate:
24429 +               return vc_net_migrate(nxi, data);
24430 +
24431 +       case VCMD_tag_migrate:
24432 +               return vc_tag_migrate(id);
24433 +
24434 +       case VCMD_net_add:
24435 +               return vc_net_add(nxi, data);
24436 +       case VCMD_net_remove:
24437 +               return vc_net_remove(nxi, data);
24438 +
24439 +       case VCMD_net_add_ipv4:
24440 +               return vc_net_add_ipv4(nxi, data);
24441 +       case VCMD_net_remove_ipv4:
24442 +               return vc_net_remove_ipv4(nxi, data);
24443 +#ifdef CONFIG_IPV6
24444 +       case VCMD_net_add_ipv6:
24445 +               return vc_net_add_ipv6(nxi, data);
24446 +       case VCMD_net_remove_ipv6:
24447 +               return vc_net_remove_ipv6(nxi, data);
24448 +#endif
24449 +/*     case VCMD_add_match_ipv4:
24450 +               return vc_add_match_ipv4(nxi, data);
24451 +       case VCMD_get_match_ipv4:
24452 +               return vc_get_match_ipv4(nxi, data);
24453 +#ifdef CONFIG_IPV6
24454 +       case VCMD_add_match_ipv6:
24455 +               return vc_add_match_ipv6(nxi, data);
24456 +       case VCMD_get_match_ipv6:
24457 +               return vc_get_match_ipv6(nxi, data);
24458 +#endif */
24459 +
24460 +#ifdef CONFIG_VSERVER_DEVICE
24461 +       case VCMD_set_mapping:
24462 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
24463 +       case VCMD_unset_mapping:
24464 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
24465 +#endif
24466 +#ifdef CONFIG_VSERVER_HISTORY
24467 +       case VCMD_dump_history:
24468 +               return vc_dump_history(id);
24469 +       case VCMD_read_history:
24470 +               return __COMPAT(vc_read_history, id, data, compat);
24471 +#endif
24472 +#ifdef CONFIG_VSERVER_MONITOR
24473 +       case VCMD_read_monitor:
24474 +               return __COMPAT(vc_read_monitor, id, data, compat);
24475 +#endif
24476 +       default:
24477 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
24478 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
24479 +       }
24480 +       return -ENOSYS;
24481 +}
24482 +
24483 +
24484 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
24485 +       case VCMD_ ## vcmd: perm = _perm;               \
24486 +               args = _args; flags = _flags; break
24487 +
24488 +
24489 +#define VCA_NONE       0x00
24490 +#define VCA_VXI                0x01
24491 +#define VCA_NXI                0x02
24492 +
24493 +#define VCF_NONE       0x00
24494 +#define VCF_INFO       0x01
24495 +#define VCF_ADMIN      0x02
24496 +#define VCF_ARES       0x06    /* includes admin */
24497 +#define VCF_SETUP      0x08
24498 +
24499 +#define VCF_ZIDOK      0x10    /* zero id okay */
24500 +
24501 +
24502 +static inline
24503 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
24504 +{
24505 +       long ret;
24506 +       int permit = -1, state = 0;
24507 +       int perm = -1, args = 0, flags = 0;
24508 +       struct vx_info *vxi = NULL;
24509 +       struct nx_info *nxi = NULL;
24510 +
24511 +       switch (cmd) {
24512 +       /* unpriviledged commands */
24513 +       __VCMD(get_version,      0, VCA_NONE,   0);
24514 +       __VCMD(get_vci,          0, VCA_NONE,   0);
24515 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
24516 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
24517 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
24518 +       __VCMD(get_space_default,0, VCA_NONE,   0);
24519 +
24520 +       /* info commands */
24521 +       __VCMD(task_xid,         2, VCA_NONE,   0);
24522 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
24523 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
24524 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
24525 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
24526 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
24527 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
24528 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
24529 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
24530 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
24531 +
24532 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
24533 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
24534 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
24535 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
24536 +
24537 +       __VCMD(task_nid,         2, VCA_NONE,   0);
24538 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
24539 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
24540 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
24541 +
24542 +       __VCMD(task_tag,         2, VCA_NONE,   0);
24543 +
24544 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
24545 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
24546 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
24547 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
24548 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
24549 +
24550 +       /* lower admin commands */
24551 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
24552 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
24553 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
24554 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
24555 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
24556 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
24557 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
24558 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
24559 +
24560 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
24561 +       __VCMD(net_create,       5, VCA_NONE,   0);
24562 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
24563 +
24564 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
24565 +
24566 +       /* higher admin commands */
24567 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
24568 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24569 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24570 +
24571 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24572 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24573 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24574 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24575 +
24576 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24577 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24578 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24579 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24580 +
24581 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24582 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24583 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24584 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24585 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24586 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24587 +#ifdef CONFIG_IPV6
24588 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24589 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24590 +#endif
24591 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
24592 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
24593 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
24594 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
24595 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
24596 +
24597 +#ifdef CONFIG_VSERVER_DEVICE
24598 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
24599 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
24600 +#endif
24601 +       /* debug level admin commands */
24602 +#ifdef CONFIG_VSERVER_HISTORY
24603 +       __VCMD(dump_history,     9, VCA_NONE,   0);
24604 +       __VCMD(read_history,     9, VCA_NONE,   0);
24605 +#endif
24606 +#ifdef CONFIG_VSERVER_MONITOR
24607 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
24608 +#endif
24609 +
24610 +       default:
24611 +               perm = -1;
24612 +       }
24613 +
24614 +       vxdprintk(VXD_CBIT(switch, 0),
24615 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
24616 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24617 +               VC_VERSION(cmd), id, data, compat,
24618 +               perm, args, flags);
24619 +
24620 +       ret = -ENOSYS;
24621 +       if (perm < 0)
24622 +               goto out;
24623 +
24624 +       state = 1;
24625 +       if (!capable(CAP_CONTEXT))
24626 +               goto out;
24627 +
24628 +       state = 2;
24629 +       /* moved here from the individual commands */
24630 +       ret = -EPERM;
24631 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
24632 +               goto out;
24633 +
24634 +       state = 3;
24635 +       /* vcmd involves resource management  */
24636 +       ret = -EPERM;
24637 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
24638 +               goto out;
24639 +
24640 +       state = 4;
24641 +       /* various legacy exceptions */
24642 +       switch (cmd) {
24643 +       /* will go away when spectator is a cap */
24644 +       case VCMD_ctx_migrate_v0:
24645 +       case VCMD_ctx_migrate:
24646 +               if (id == 1) {
24647 +                       current->xid = 1;
24648 +                       ret = 1;
24649 +                       goto out;
24650 +               }
24651 +               break;
24652 +
24653 +       /* will go away when spectator is a cap */
24654 +       case VCMD_net_migrate:
24655 +               if (id == 1) {
24656 +                       current->nid = 1;
24657 +                       ret = 1;
24658 +                       goto out;
24659 +               }
24660 +               break;
24661 +       }
24662 +
24663 +       /* vcmds are fine by default */
24664 +       permit = 1;
24665 +
24666 +       /* admin type vcmds require admin ... */
24667 +       if (flags & VCF_ADMIN)
24668 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
24669 +
24670 +       /* ... but setup type vcmds override that */
24671 +       if (!permit && (flags & VCF_SETUP))
24672 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
24673 +
24674 +       state = 5;
24675 +       ret = -EPERM;
24676 +       if (!permit)
24677 +               goto out;
24678 +
24679 +       state = 6;
24680 +       if (!id && (flags & VCF_ZIDOK))
24681 +               goto skip_id;
24682 +
24683 +       ret = -ESRCH;
24684 +       if (args & VCA_VXI) {
24685 +               vxi = lookup_vx_info(id);
24686 +               if (!vxi)
24687 +                       goto out;
24688 +
24689 +               if ((flags & VCF_ADMIN) &&
24690 +                       /* special case kill for shutdown */
24691 +                       (cmd != VCMD_ctx_kill) &&
24692 +                       /* can context be administrated? */
24693 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
24694 +                       ret = -EACCES;
24695 +                       goto out_vxi;
24696 +               }
24697 +       }
24698 +       state = 7;
24699 +       if (args & VCA_NXI) {
24700 +               nxi = lookup_nx_info(id);
24701 +               if (!nxi)
24702 +                       goto out_vxi;
24703 +
24704 +               if ((flags & VCF_ADMIN) &&
24705 +                       /* can context be administrated? */
24706 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
24707 +                       ret = -EACCES;
24708 +                       goto out_nxi;
24709 +               }
24710 +       }
24711 +skip_id:
24712 +       state = 8;
24713 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
24714 +
24715 +out_nxi:
24716 +       if ((args & VCA_NXI) && nxi)
24717 +               put_nx_info(nxi);
24718 +out_vxi:
24719 +       if ((args & VCA_VXI) && vxi)
24720 +               put_vx_info(vxi);
24721 +out:
24722 +       vxdprintk(VXD_CBIT(switch, 1),
24723 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
24724 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24725 +               VC_VERSION(cmd), ret, ret, state, permit);
24726 +       return ret;
24727 +}
24728 +
24729 +asmlinkage long
24730 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
24731 +{
24732 +       return do_vserver(cmd, id, data, 0);
24733 +}
24734 +
24735 +#ifdef CONFIG_COMPAT
24736 +
24737 +asmlinkage long
24738 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
24739 +{
24740 +       return do_vserver(cmd, id, data, 1);
24741 +}
24742 +
24743 +#endif /* CONFIG_COMPAT */
24744 diff -NurpP --minimal linux-2.6.33/kernel/vserver/sysctl.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/sysctl.c
24745 --- linux-2.6.33/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
24746 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/sysctl.c  2010-02-25 15:14:16.000000000 +0100
24747 @@ -0,0 +1,241 @@
24748 +/*
24749 + *  kernel/vserver/sysctl.c
24750 + *
24751 + *  Virtual Context Support
24752 + *
24753 + *  Copyright (C) 2004-2007  Herbert Pötzl
24754 + *
24755 + *  V0.01  basic structure
24756 + *
24757 + */
24758 +
24759 +#include <linux/module.h>
24760 +#include <linux/ctype.h>
24761 +#include <linux/sysctl.h>
24762 +#include <linux/parser.h>
24763 +#include <asm/uaccess.h>
24764 +
24765 +enum {
24766 +       CTL_DEBUG_ERROR         = 0,
24767 +       CTL_DEBUG_SWITCH        = 1,
24768 +       CTL_DEBUG_XID,
24769 +       CTL_DEBUG_NID,
24770 +       CTL_DEBUG_TAG,
24771 +       CTL_DEBUG_NET,
24772 +       CTL_DEBUG_LIMIT,
24773 +       CTL_DEBUG_CRES,
24774 +       CTL_DEBUG_DLIM,
24775 +       CTL_DEBUG_QUOTA,
24776 +       CTL_DEBUG_CVIRT,
24777 +       CTL_DEBUG_SPACE,
24778 +       CTL_DEBUG_MISC,
24779 +};
24780 +
24781 +
24782 +unsigned int vx_debug_switch   = 0;
24783 +unsigned int vx_debug_xid      = 0;
24784 +unsigned int vx_debug_nid      = 0;
24785 +unsigned int vx_debug_tag      = 0;
24786 +unsigned int vx_debug_net      = 0;
24787 +unsigned int vx_debug_limit    = 0;
24788 +unsigned int vx_debug_cres     = 0;
24789 +unsigned int vx_debug_dlim     = 0;
24790 +unsigned int vx_debug_quota    = 0;
24791 +unsigned int vx_debug_cvirt    = 0;
24792 +unsigned int vx_debug_space    = 0;
24793 +unsigned int vx_debug_misc     = 0;
24794 +
24795 +
24796 +static struct ctl_table_header *vserver_table_header;
24797 +static ctl_table vserver_root_table[];
24798 +
24799 +
24800 +void vserver_register_sysctl(void)
24801 +{
24802 +       if (!vserver_table_header) {
24803 +               vserver_table_header = register_sysctl_table(vserver_root_table);
24804 +       }
24805 +
24806 +}
24807 +
24808 +void vserver_unregister_sysctl(void)
24809 +{
24810 +       if (vserver_table_header) {
24811 +               unregister_sysctl_table(vserver_table_header);
24812 +               vserver_table_header = NULL;
24813 +       }
24814 +}
24815 +
24816 +
24817 +static int proc_dodebug(ctl_table *table, int write,
24818 +       void __user *buffer, size_t *lenp, loff_t *ppos)
24819 +{
24820 +       char            tmpbuf[20], *p, c;
24821 +       unsigned int    value;
24822 +       size_t          left, len;
24823 +
24824 +       if ((*ppos && !write) || !*lenp) {
24825 +               *lenp = 0;
24826 +               return 0;
24827 +       }
24828 +
24829 +       left = *lenp;
24830 +
24831 +       if (write) {
24832 +               if (!access_ok(VERIFY_READ, buffer, left))
24833 +                       return -EFAULT;
24834 +               p = (char *)buffer;
24835 +               while (left && __get_user(c, p) >= 0 && isspace(c))
24836 +                       left--, p++;
24837 +               if (!left)
24838 +                       goto done;
24839 +
24840 +               if (left > sizeof(tmpbuf) - 1)
24841 +                       return -EINVAL;
24842 +               if (copy_from_user(tmpbuf, p, left))
24843 +                       return -EFAULT;
24844 +               tmpbuf[left] = '\0';
24845 +
24846 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
24847 +                       value = 10 * value + (*p - '0');
24848 +               if (*p && !isspace(*p))
24849 +                       return -EINVAL;
24850 +               while (left && isspace(*p))
24851 +                       left--, p++;
24852 +               *(unsigned int *)table->data = value;
24853 +       } else {
24854 +               if (!access_ok(VERIFY_WRITE, buffer, left))
24855 +                       return -EFAULT;
24856 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
24857 +               if (len > left)
24858 +                       len = left;
24859 +               if (__copy_to_user(buffer, tmpbuf, len))
24860 +                       return -EFAULT;
24861 +               if ((left -= len) > 0) {
24862 +                       if (put_user('\n', (char *)buffer + len))
24863 +                               return -EFAULT;
24864 +                       left--;
24865 +               }
24866 +       }
24867 +
24868 +done:
24869 +       *lenp -= left;
24870 +       *ppos += *lenp;
24871 +       return 0;
24872 +}
24873 +
24874 +static int zero;
24875 +
24876 +#define        CTL_ENTRY(ctl, name)                            \
24877 +       {                                               \
24878 +               .procname       = #name,                \
24879 +               .data           = &vx_ ## name,         \
24880 +               .maxlen         = sizeof(int),          \
24881 +               .mode           = 0644,                 \
24882 +               .proc_handler   = &proc_dodebug,        \
24883 +               .extra1         = &zero,                \
24884 +               .extra2         = &zero,                \
24885 +       }
24886 +
24887 +static ctl_table vserver_debug_table[] = {
24888 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
24889 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
24890 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
24891 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
24892 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
24893 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
24894 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
24895 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
24896 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
24897 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
24898 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
24899 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
24900 +       { 0 }
24901 +};
24902 +
24903 +static ctl_table vserver_root_table[] = {
24904 +       {
24905 +               .procname       = "vserver",
24906 +               .mode           = 0555,
24907 +               .child          = vserver_debug_table
24908 +       },
24909 +       { 0 }
24910 +};
24911 +
24912 +
24913 +static match_table_t tokens = {
24914 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24915 +       { CTL_DEBUG_XID,        "xid=%x"        },
24916 +       { CTL_DEBUG_NID,        "nid=%x"        },
24917 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24918 +       { CTL_DEBUG_NET,        "net=%x"        },
24919 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24920 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24921 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24922 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24923 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24924 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24925 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24926 +       { CTL_DEBUG_ERROR,      NULL            }
24927 +};
24928 +
24929 +#define        HANDLE_CASE(id, name, val)                              \
24930 +       case CTL_DEBUG_ ## id:                                  \
24931 +               vx_debug_ ## name = val;                        \
24932 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24933 +               break
24934 +
24935 +
24936 +static int __init vs_debug_setup(char *str)
24937 +{
24938 +       char *p;
24939 +       int token;
24940 +
24941 +       printk("vs_debug_setup(%s)\n", str);
24942 +       while ((p = strsep(&str, ",")) != NULL) {
24943 +               substring_t args[MAX_OPT_ARGS];
24944 +               unsigned int value;
24945 +
24946 +               if (!*p)
24947 +                       continue;
24948 +
24949 +               token = match_token(p, tokens, args);
24950 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24951 +
24952 +               switch (token) {
24953 +               HANDLE_CASE(SWITCH, switch, value);
24954 +               HANDLE_CASE(XID,    xid,    value);
24955 +               HANDLE_CASE(NID,    nid,    value);
24956 +               HANDLE_CASE(TAG,    tag,    value);
24957 +               HANDLE_CASE(NET,    net,    value);
24958 +               HANDLE_CASE(LIMIT,  limit,  value);
24959 +               HANDLE_CASE(CRES,   cres,   value);
24960 +               HANDLE_CASE(DLIM,   dlim,   value);
24961 +               HANDLE_CASE(QUOTA,  quota,  value);
24962 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24963 +               HANDLE_CASE(SPACE,  space,  value);
24964 +               HANDLE_CASE(MISC,   misc,   value);
24965 +               default:
24966 +                       return -EINVAL;
24967 +                       break;
24968 +               }
24969 +       }
24970 +       return 1;
24971 +}
24972 +
24973 +__setup("vsdebug=", vs_debug_setup);
24974 +
24975 +
24976 +
24977 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24978 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24979 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24980 +EXPORT_SYMBOL_GPL(vx_debug_net);
24981 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24982 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24983 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24984 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24985 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24986 +EXPORT_SYMBOL_GPL(vx_debug_space);
24987 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24988 +
24989 diff -NurpP --minimal linux-2.6.33/kernel/vserver/tag.c linux-2.6.33-vs2.3.0.36.30/kernel/vserver/tag.c
24990 --- linux-2.6.33/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
24991 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/tag.c     2010-02-25 12:02:16.000000000 +0100
24992 @@ -0,0 +1,63 @@
24993 +/*
24994 + *  linux/kernel/vserver/tag.c
24995 + *
24996 + *  Virtual Server: Shallow Tag Space
24997 + *
24998 + *  Copyright (C) 2007  Herbert Pötzl
24999 + *
25000 + *  V0.01  basic implementation
25001 + *
25002 + */
25003 +
25004 +#include <linux/sched.h>
25005 +#include <linux/vserver/debug.h>
25006 +#include <linux/vs_pid.h>
25007 +#include <linux/vs_tag.h>
25008 +
25009 +#include <linux/vserver/tag_cmd.h>
25010 +
25011 +
25012 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25013 +{
25014 +       if (!p)
25015 +               BUG();
25016 +
25017 +       vxdprintk(VXD_CBIT(tag, 5),
25018 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25019 +
25020 +       task_lock(p);
25021 +       p->tag = tag;
25022 +       task_unlock(p);
25023 +
25024 +       vxdprintk(VXD_CBIT(tag, 5),
25025 +               "moved task %p into [#%d]", p, tag);
25026 +       return 0;
25027 +}
25028 +
25029 +/* vserver syscall commands below here */
25030 +
25031 +/* taks xid and vx_info functions */
25032 +
25033 +
25034 +int vc_task_tag(uint32_t id)
25035 +{
25036 +       tag_t tag;
25037 +
25038 +       if (id) {
25039 +               struct task_struct *tsk;
25040 +               read_lock(&tasklist_lock);
25041 +               tsk = find_task_by_real_pid(id);
25042 +               tag = (tsk) ? tsk->tag : -ESRCH;
25043 +               read_unlock(&tasklist_lock);
25044 +       } else
25045 +               tag = dx_current_tag();
25046 +       return tag;
25047 +}
25048 +
25049 +
25050 +int vc_tag_migrate(uint32_t tag)
25051 +{
25052 +       return dx_migrate_task(current, tag & 0xFFFF);
25053 +}
25054 +
25055 +
25056 diff -NurpP --minimal linux-2.6.33/kernel/vserver/vci_config.h linux-2.6.33-vs2.3.0.36.30/kernel/vserver/vci_config.h
25057 --- linux-2.6.33/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
25058 +++ linux-2.6.33-vs2.3.0.36.30/kernel/vserver/vci_config.h      2010-02-25 12:02:16.000000000 +0100
25059 @@ -0,0 +1,81 @@
25060 +
25061 +/*  interface version */
25062 +
25063 +#define VCI_VERSION            0x00020305
25064 +
25065 +
25066 +enum {
25067 +       VCI_KCBIT_NO_DYNAMIC = 0,
25068 +
25069 +       VCI_KCBIT_PROC_SECURE = 4,
25070 +       VCI_KCBIT_HARDCPU = 5,
25071 +       VCI_KCBIT_IDLELIMIT = 6,
25072 +       VCI_KCBIT_IDLETIME = 7,
25073 +
25074 +       VCI_KCBIT_COWBL = 8,
25075 +       VCI_KCBIT_FULLCOWBL = 9,
25076 +       VCI_KCBIT_SPACES = 10,
25077 +       VCI_KCBIT_NETV2 = 11,
25078 +
25079 +       VCI_KCBIT_DEBUG = 16,
25080 +       VCI_KCBIT_HISTORY = 20,
25081 +       VCI_KCBIT_TAGGED = 24,
25082 +       VCI_KCBIT_PPTAG = 28,
25083 +
25084 +       VCI_KCBIT_MORE = 31,
25085 +};
25086 +
25087 +
25088 +static inline uint32_t vci_kernel_config(void)
25089 +{
25090 +       return
25091 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25092 +
25093 +       /* configured features */
25094 +#ifdef CONFIG_VSERVER_PROC_SECURE
25095 +       (1 << VCI_KCBIT_PROC_SECURE) |
25096 +#endif
25097 +#ifdef CONFIG_VSERVER_HARDCPU
25098 +       (1 << VCI_KCBIT_HARDCPU) |
25099 +#endif
25100 +#ifdef CONFIG_VSERVER_IDLELIMIT
25101 +       (1 << VCI_KCBIT_IDLELIMIT) |
25102 +#endif
25103 +#ifdef CONFIG_VSERVER_IDLETIME
25104 +       (1 << VCI_KCBIT_IDLETIME) |
25105 +#endif
25106 +#ifdef CONFIG_VSERVER_COWBL
25107 +       (1 << VCI_KCBIT_COWBL) |
25108 +       (1 << VCI_KCBIT_FULLCOWBL) |
25109 +#endif
25110 +       (1 << VCI_KCBIT_SPACES) |
25111 +       (1 << VCI_KCBIT_NETV2) |
25112 +
25113 +       /* debug options */
25114 +#ifdef CONFIG_VSERVER_DEBUG
25115 +       (1 << VCI_KCBIT_DEBUG) |
25116 +#endif
25117 +#ifdef CONFIG_VSERVER_HISTORY
25118 +       (1 << VCI_KCBIT_HISTORY) |
25119 +#endif
25120 +
25121 +       /* inode context tagging */
25122 +#if    defined(CONFIG_TAGGING_NONE)
25123 +       (0 << VCI_KCBIT_TAGGED) |
25124 +#elif  defined(CONFIG_TAGGING_UID16)
25125 +       (1 << VCI_KCBIT_TAGGED) |
25126 +#elif  defined(CONFIG_TAGGING_GID16)
25127 +       (2 << VCI_KCBIT_TAGGED) |
25128 +#elif  defined(CONFIG_TAGGING_ID24)
25129 +       (3 << VCI_KCBIT_TAGGED) |
25130 +#elif  defined(CONFIG_TAGGING_INTERN)
25131 +       (4 << VCI_KCBIT_TAGGED) |
25132 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25133 +       (5 << VCI_KCBIT_TAGGED) |
25134 +#else
25135 +       (7 << VCI_KCBIT_TAGGED) |
25136 +#endif
25137 +       (1 << VCI_KCBIT_PPTAG) |
25138 +       0;
25139 +}
25140 +
25141 diff -NurpP --minimal linux-2.6.33/mm/filemap_xip.c linux-2.6.33-vs2.3.0.36.30/mm/filemap_xip.c
25142 --- linux-2.6.33/mm/filemap_xip.c       2009-12-03 20:02:58.000000000 +0100
25143 +++ linux-2.6.33-vs2.3.0.36.30/mm/filemap_xip.c 2010-02-25 12:02:16.000000000 +0100
25144 @@ -17,6 +17,7 @@
25145  #include <linux/sched.h>
25146  #include <linux/seqlock.h>
25147  #include <linux/mutex.h>
25148 +#include <linux/vs_memory.h>
25149  #include <asm/tlbflush.h>
25150  #include <asm/io.h>
25151  
25152 diff -NurpP --minimal linux-2.6.33/mm/fremap.c linux-2.6.33-vs2.3.0.36.30/mm/fremap.c
25153 --- linux-2.6.33/mm/fremap.c    2009-03-24 14:22:45.000000000 +0100
25154 +++ linux-2.6.33-vs2.3.0.36.30/mm/fremap.c      2010-02-25 12:02:16.000000000 +0100
25155 @@ -16,6 +16,7 @@
25156  #include <linux/module.h>
25157  #include <linux/syscalls.h>
25158  #include <linux/mmu_notifier.h>
25159 +#include <linux/vs_memory.h>
25160  
25161  #include <asm/mmu_context.h>
25162  #include <asm/cacheflush.h>
25163 diff -NurpP --minimal linux-2.6.33/mm/hugetlb.c linux-2.6.33-vs2.3.0.36.30/mm/hugetlb.c
25164 --- linux-2.6.33/mm/hugetlb.c   2010-02-25 11:52:09.000000000 +0100
25165 +++ linux-2.6.33-vs2.3.0.36.30/mm/hugetlb.c     2010-02-25 12:16:11.000000000 +0100
25166 @@ -25,6 +25,7 @@
25167  
25168  #include <linux/hugetlb.h>
25169  #include <linux/node.h>
25170 +#include <linux/vs_memory.h>
25171  #include "internal.h"
25172  
25173  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25174 diff -NurpP --minimal linux-2.6.33/mm/memcontrol.c linux-2.6.33-vs2.3.0.36.30/mm/memcontrol.c
25175 --- linux-2.6.33/mm/memcontrol.c        2010-02-25 11:52:09.000000000 +0100
25176 +++ linux-2.6.33-vs2.3.0.36.30/mm/memcontrol.c  2010-02-25 12:02:16.000000000 +0100
25177 @@ -555,6 +555,31 @@ struct mem_cgroup *mem_cgroup_from_task(
25178                                 struct mem_cgroup, css);
25179  }
25180  
25181 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
25182 +{
25183 +       return res_counter_read_u64(&mem->res, member);
25184 +}
25185 +
25186 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
25187 +{
25188 +       return res_counter_read_u64(&mem->memsw, member);
25189 +}
25190 +
25191 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
25192 +{
25193 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_CACHE);
25194 +}
25195 +
25196 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
25197 +{
25198 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_RSS);
25199 +}
25200 +
25201 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
25202 +{
25203 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_FILE_MAPPED);
25204 +}
25205 +
25206  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
25207  {
25208         struct mem_cgroup *mem = NULL;
25209 diff -NurpP --minimal linux-2.6.33/mm/memory.c linux-2.6.33-vs2.3.0.36.30/mm/memory.c
25210 --- linux-2.6.33/mm/memory.c    2010-02-25 11:52:09.000000000 +0100
25211 +++ linux-2.6.33-vs2.3.0.36.30/mm/memory.c      2010-02-25 12:02:16.000000000 +0100
25212 @@ -56,6 +56,7 @@
25213  #include <linux/kallsyms.h>
25214  #include <linux/swapops.h>
25215  #include <linux/elf.h>
25216 +// #include <linux/vs_memory.h>
25217  
25218  #include <asm/io.h>
25219  #include <asm/pgalloc.h>
25220 @@ -651,6 +652,9 @@ static int copy_pte_range(struct mm_stru
25221         int rss[2];
25222         swp_entry_t entry = (swp_entry_t){0};
25223  
25224 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
25225 +               return -ENOMEM;
25226 +
25227  again:
25228         rss[1] = rss[0] = 0;
25229         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
25230 @@ -2670,6 +2674,8 @@ static int do_anonymous_page(struct mm_s
25231         /* Allocate our own private page. */
25232         pte_unmap(page_table);
25233  
25234 +       if (!vx_rss_avail(mm, 1))
25235 +               goto oom;
25236         if (unlikely(anon_vma_prepare(vma)))
25237                 goto oom;
25238         page = alloc_zeroed_user_highpage_movable(vma, address);
25239 @@ -2961,6 +2967,7 @@ static inline int handle_pte_fault(struc
25240  {
25241         pte_t entry;
25242         spinlock_t *ptl;
25243 +       int ret = 0, type = VXPT_UNKNOWN;
25244  
25245         entry = *pte;
25246         if (!pte_present(entry)) {
25247 @@ -2985,9 +2992,12 @@ static inline int handle_pte_fault(struc
25248         if (unlikely(!pte_same(*pte, entry)))
25249                 goto unlock;
25250         if (flags & FAULT_FLAG_WRITE) {
25251 -               if (!pte_write(entry))
25252 -                       return do_wp_page(mm, vma, address,
25253 +               if (!pte_write(entry)) {
25254 +                       ret = do_wp_page(mm, vma, address,
25255                                         pte, pmd, ptl, entry);
25256 +                       type = VXPT_WRITE;
25257 +                       goto out;
25258 +               }
25259                 entry = pte_mkdirty(entry);
25260         }
25261         entry = pte_mkyoung(entry);
25262 @@ -3005,7 +3015,10 @@ static inline int handle_pte_fault(struc
25263         }
25264  unlock:
25265         pte_unmap_unlock(pte, ptl);
25266 -       return 0;
25267 +       ret = 0;
25268 +out:
25269 +       vx_page_fault(mm, vma, type, ret);
25270 +       return ret;
25271  }
25272  
25273  /*
25274 diff -NurpP --minimal linux-2.6.33/mm/mlock.c linux-2.6.33-vs2.3.0.36.30/mm/mlock.c
25275 --- linux-2.6.33/mm/mlock.c     2010-02-25 11:52:09.000000000 +0100
25276 +++ linux-2.6.33-vs2.3.0.36.30/mm/mlock.c       2010-02-25 12:02:16.000000000 +0100
25277 @@ -18,6 +18,7 @@
25278  #include <linux/rmap.h>
25279  #include <linux/mmzone.h>
25280  #include <linux/hugetlb.h>
25281 +#include <linux/vs_memory.h>
25282  
25283  #include "internal.h"
25284  
25285 @@ -398,7 +399,7 @@ success:
25286         nr_pages = (end - start) >> PAGE_SHIFT;
25287         if (!lock)
25288                 nr_pages = -nr_pages;
25289 -       mm->locked_vm += nr_pages;
25290 +       vx_vmlocked_add(mm, nr_pages);
25291  
25292         /*
25293          * vm_flags is protected by the mmap_sem held in write mode.
25294 @@ -471,7 +472,7 @@ static int do_mlock(unsigned long start,
25295  
25296  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
25297  {
25298 -       unsigned long locked;
25299 +       unsigned long locked, grow;
25300         unsigned long lock_limit;
25301         int error = -ENOMEM;
25302  
25303 @@ -484,8 +485,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25304         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
25305         start &= PAGE_MASK;
25306  
25307 -       locked = len >> PAGE_SHIFT;
25308 -       locked += current->mm->locked_vm;
25309 +       grow = len >> PAGE_SHIFT;
25310 +       if (!vx_vmlocked_avail(current->mm, grow))
25311 +               goto out;
25312 +       locked = current->mm->locked_vm + grow;
25313  
25314         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
25315         lock_limit >>= PAGE_SHIFT;
25316 @@ -493,6 +496,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25317         /* check against resource limits */
25318         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
25319                 error = do_mlock(start, len, 1);
25320 +out:
25321         up_write(&current->mm->mmap_sem);
25322         return error;
25323  }
25324 @@ -554,6 +558,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
25325         lock_limit >>= PAGE_SHIFT;
25326  
25327         ret = -ENOMEM;
25328 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
25329 +               goto out;
25330         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
25331             capable(CAP_IPC_LOCK))
25332                 ret = do_mlockall(flags);
25333 @@ -628,8 +634,10 @@ int account_locked_memory(struct mm_stru
25334         if (lim < vm)
25335                 goto out;
25336  
25337 -       mm->total_vm  += pgsz;
25338 -       mm->locked_vm += pgsz;
25339 +       // mm->total_vm  += pgsz;
25340 +       vx_vmpages_add(mm, pgsz);
25341 +       // mm->locked_vm += pgsz;
25342 +       vx_vmlocked_add(mm, pgsz);
25343  
25344         error = 0;
25345   out:
25346 @@ -643,8 +651,10 @@ void refund_locked_memory(struct mm_stru
25347  
25348         down_write(&mm->mmap_sem);
25349  
25350 -       mm->total_vm  -= pgsz;
25351 -       mm->locked_vm -= pgsz;
25352 +       // mm->total_vm  -= pgsz;
25353 +       vx_vmpages_sub(mm, pgsz);
25354 +       // mm->locked_vm -= pgsz;
25355 +       vx_vmlocked_sub(mm, pgsz);
25356  
25357         up_write(&mm->mmap_sem);
25358  }
25359 diff -NurpP --minimal linux-2.6.33/mm/mmap.c linux-2.6.33-vs2.3.0.36.30/mm/mmap.c
25360 --- linux-2.6.33/mm/mmap.c      2010-02-25 11:52:09.000000000 +0100
25361 +++ linux-2.6.33-vs2.3.0.36.30/mm/mmap.c        2010-02-25 12:02:16.000000000 +0100
25362 @@ -1262,7 +1262,8 @@ munmap_back:
25363  out:
25364         perf_event_mmap(vma);
25365  
25366 -       mm->total_vm += len >> PAGE_SHIFT;
25367 +       // mm->total_vm += len >> PAGE_SHIFT;
25368 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25369         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
25370         if (vm_flags & VM_LOCKED) {
25371                 /*
25372 @@ -1271,7 +1272,8 @@ out:
25373                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
25374                 if (nr_pages < 0)
25375                         return nr_pages;        /* vma gone! */
25376 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
25377 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
25378 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
25379         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
25380                 make_pages_present(addr, addr + len);
25381         return addr;
25382 @@ -1626,9 +1628,9 @@ static int acct_stack_growth(struct vm_a
25383                 return -ENOMEM;
25384  
25385         /* Ok, everything looks good - let it rip */
25386 -       mm->total_vm += grow;
25387 +       vx_vmpages_add(mm, grow);
25388         if (vma->vm_flags & VM_LOCKED)
25389 -               mm->locked_vm += grow;
25390 +               vx_vmlocked_add(mm, grow);
25391         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
25392         return 0;
25393  }
25394 @@ -1803,7 +1805,8 @@ static void remove_vma_list(struct mm_st
25395         do {
25396                 long nrpages = vma_pages(vma);
25397  
25398 -               mm->total_vm -= nrpages;
25399 +               // mm->total_vm -= nrpages;
25400 +               vx_vmpages_sub(mm, nrpages);
25401                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
25402                 vma = remove_vma(vma);
25403         } while (vma);
25404 @@ -1995,7 +1998,8 @@ int do_munmap(struct mm_struct *mm, unsi
25405                 struct vm_area_struct *tmp = vma;
25406                 while (tmp && tmp->vm_start < end) {
25407                         if (tmp->vm_flags & VM_LOCKED) {
25408 -                               mm->locked_vm -= vma_pages(tmp);
25409 +                               // mm->locked_vm -= vma_pages(tmp);
25410 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
25411                                 munlock_vma_pages_all(tmp);
25412                         }
25413                         tmp = tmp->vm_next;
25414 @@ -2078,6 +2082,8 @@ unsigned long do_brk(unsigned long addr,
25415                 lock_limit >>= PAGE_SHIFT;
25416                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25417                         return -EAGAIN;
25418 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
25419 +                       return -ENOMEM;
25420         }
25421  
25422         /*
25423 @@ -2104,7 +2110,8 @@ unsigned long do_brk(unsigned long addr,
25424         if (mm->map_count > sysctl_max_map_count)
25425                 return -ENOMEM;
25426  
25427 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
25428 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
25429 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
25430                 return -ENOMEM;
25431  
25432         /* Can we just expand an old private anonymous mapping? */
25433 @@ -2130,10 +2137,13 @@ unsigned long do_brk(unsigned long addr,
25434         vma->vm_page_prot = vm_get_page_prot(flags);
25435         vma_link(mm, vma, prev, rb_link, rb_parent);
25436  out:
25437 -       mm->total_vm += len >> PAGE_SHIFT;
25438 +       // mm->total_vm += len >> PAGE_SHIFT;
25439 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25440 +
25441         if (flags & VM_LOCKED) {
25442                 if (!mlock_vma_pages_range(vma, addr, addr + len))
25443 -                       mm->locked_vm += (len >> PAGE_SHIFT);
25444 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
25445 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
25446         }
25447         return addr;
25448  }
25449 @@ -2177,6 +2187,11 @@ void exit_mmap(struct mm_struct *mm)
25450         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
25451         tlb_finish_mmu(tlb, 0, end);
25452  
25453 +       set_mm_counter(mm, file_rss, 0);
25454 +       set_mm_counter(mm, anon_rss, 0);
25455 +       vx_vmpages_sub(mm, mm->total_vm);
25456 +       vx_vmlocked_sub(mm, mm->locked_vm);
25457 +
25458         /*
25459          * Walk the list again, actually closing and freeing it,
25460          * with preemption enabled, without holding any MM locks.
25461 @@ -2216,7 +2231,8 @@ int insert_vm_struct(struct mm_struct * 
25462         if (__vma && __vma->vm_start < vma->vm_end)
25463                 return -ENOMEM;
25464         if ((vma->vm_flags & VM_ACCOUNT) &&
25465 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
25466 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
25467 +               !vx_vmpages_avail(mm, vma_pages(vma))))
25468                 return -ENOMEM;
25469         vma_link(mm, vma, prev, rb_link, rb_parent);
25470         return 0;
25471 @@ -2292,6 +2308,8 @@ int may_expand_vm(struct mm_struct *mm, 
25472  
25473         if (cur + npages > lim)
25474                 return 0;
25475 +       if (!vx_vmpages_avail(mm, npages))
25476 +               return 0;
25477         return 1;
25478  }
25479  
25480 @@ -2369,7 +2387,7 @@ int install_special_mapping(struct mm_st
25481                 return -ENOMEM;
25482         }
25483  
25484 -       mm->total_vm += len >> PAGE_SHIFT;
25485 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25486  
25487         perf_event_mmap(vma);
25488  
25489 diff -NurpP --minimal linux-2.6.33/mm/mremap.c linux-2.6.33-vs2.3.0.36.30/mm/mremap.c
25490 --- linux-2.6.33/mm/mremap.c    2010-02-25 11:52:09.000000000 +0100
25491 +++ linux-2.6.33-vs2.3.0.36.30/mm/mremap.c      2010-02-25 12:02:16.000000000 +0100
25492 @@ -20,6 +20,7 @@
25493  #include <linux/security.h>
25494  #include <linux/syscalls.h>
25495  #include <linux/mmu_notifier.h>
25496 +#include <linux/vs_memory.h>
25497  
25498  #include <asm/uaccess.h>
25499  #include <asm/cacheflush.h>
25500 @@ -234,7 +235,7 @@ static unsigned long move_vma(struct vm_
25501          * If this were a serious issue, we'd add a flag to do_munmap().
25502          */
25503         hiwater_vm = mm->hiwater_vm;
25504 -       mm->total_vm += new_len >> PAGE_SHIFT;
25505 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
25506         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
25507  
25508         if (do_munmap(mm, old_addr, old_len) < 0) {
25509 @@ -252,7 +253,7 @@ static unsigned long move_vma(struct vm_
25510         }
25511  
25512         if (vm_flags & VM_LOCKED) {
25513 -               mm->locked_vm += new_len >> PAGE_SHIFT;
25514 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
25515                 if (new_len > old_len)
25516                         mlock_vma_pages_range(new_vma, new_addr + old_len,
25517                                                        new_addr + new_len);
25518 @@ -463,10 +464,12 @@ unsigned long do_mremap(unsigned long ad
25519                         vma_adjust(vma, vma->vm_start,
25520                                 addr + new_len, vma->vm_pgoff, NULL);
25521  
25522 -                       mm->total_vm += pages;
25523 +                       // mm->total_vm += pages;
25524 +                       vx_vmpages_add(mm, pages);
25525                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
25526                         if (vma->vm_flags & VM_LOCKED) {
25527 -                               mm->locked_vm += pages;
25528 +                               // mm->locked_vm += pages;
25529 +                               vx_vmlocked_add(mm, pages);
25530                                 mlock_vma_pages_range(vma, addr + old_len,
25531                                                    addr + new_len);
25532                         }
25533 diff -NurpP --minimal linux-2.6.33/mm/nommu.c linux-2.6.33-vs2.3.0.36.30/mm/nommu.c
25534 --- linux-2.6.33/mm/nommu.c     2010-02-25 11:52:09.000000000 +0100
25535 +++ linux-2.6.33-vs2.3.0.36.30/mm/nommu.c       2010-02-25 12:02:16.000000000 +0100
25536 @@ -1349,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file 
25537         /* okay... we have a mapping; now we have to register it */
25538         result = vma->vm_start;
25539  
25540 -       current->mm->total_vm += len >> PAGE_SHIFT;
25541 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
25542  
25543  share:
25544         add_vma_to_mm(current->mm, vma);
25545 @@ -1637,7 +1637,7 @@ void exit_mmap(struct mm_struct *mm)
25546  
25547         kenter("");
25548  
25549 -       mm->total_vm = 0;
25550 +       vx_vmpages_sub(mm, mm->total_vm);
25551  
25552         while ((vma = mm->mmap)) {
25553                 mm->mmap = vma->vm_next;
25554 diff -NurpP --minimal linux-2.6.33/mm/oom_kill.c linux-2.6.33-vs2.3.0.36.30/mm/oom_kill.c
25555 --- linux-2.6.33/mm/oom_kill.c  2010-02-25 11:52:09.000000000 +0100
25556 +++ linux-2.6.33-vs2.3.0.36.30/mm/oom_kill.c    2010-02-25 12:20:14.000000000 +0100
25557 @@ -27,6 +27,9 @@
25558  #include <linux/notifier.h>
25559  #include <linux/memcontrol.h>
25560  #include <linux/security.h>
25561 +#include <linux/reboot.h>
25562 +#include <linux/vs_memory.h>
25563 +#include <linux/vs_context.h>
25564  
25565  int sysctl_panic_on_oom;
25566  int sysctl_oom_kill_allocating_task;
25567 @@ -186,9 +189,21 @@ unsigned long badness(struct task_struct
25568                         points >>= -(oom_adj);
25569         }
25570  
25571 +       /*
25572 +        * add points for context badness and
25573 +        * reduce badness for processes belonging to
25574 +        * a different context
25575 +        */
25576 +
25577 +       points += vx_badness(p, mm);
25578 +
25579 +       if ((vx_current_xid() > 1) &&
25580 +               vx_current_xid() != vx_task_xid(p))
25581 +               points /= 16;
25582 +
25583  #ifdef DEBUG
25584 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
25585 -       p->pid, p->comm, points);
25586 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
25587 +               task_pid_nr(p), p->xid, p->comm, points);
25588  #endif
25589         return points;
25590  }
25591 @@ -249,6 +264,7 @@ static struct task_struct *select_bad_pr
25592         struct task_struct *p;
25593         struct task_struct *chosen = NULL;
25594         struct timespec uptime;
25595 +       unsigned xid = vx_current_xid();
25596         *ppoints = 0;
25597  
25598         do_posix_clock_monotonic_gettime(&uptime);
25599 @@ -261,11 +277,14 @@ static struct task_struct *select_bad_pr
25600                  */
25601                 if (!p->mm)
25602                         continue;
25603 -               /* skip the init task */
25604 -               if (is_global_init(p))
25605 +               /* skip the init task, global and per guest */
25606 +               if (task_is_init(p))
25607                         continue;
25608                 if (mem && !task_in_mem_cgroup(p, mem))
25609                         continue;
25610 +               /* skip other guest and host processes if oom in guest */
25611 +               if (xid && vx_task_xid(p) != xid)
25612 +                       continue;
25613  
25614                 /*
25615                  * This task already has access to memory reserves and is
25616 @@ -397,9 +416,9 @@ static void __oom_kill_task(struct task_
25617         }
25618  
25619         if (verbose)
25620 -               printk(KERN_ERR "Killed process %d (%s) "
25621 +               printk(KERN_ERR "Killed process %s(%d:#%u) "
25622                        "vsz:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
25623 -                      task_pid_nr(p), p->comm,
25624 +                      p->comm, task_pid_nr(p), p->xid,
25625                        K(p->mm->total_vm),
25626                        K(get_mm_counter(p->mm, anon_rss)),
25627                        K(get_mm_counter(p->mm, file_rss)));
25628 @@ -452,8 +471,8 @@ static int oom_kill_process(struct task_
25629                 return 0;
25630         }
25631  
25632 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
25633 -                                       message, task_pid_nr(p), p->comm, points);
25634 +       printk(KERN_ERR "%s: kill process %s(%d:#%u) score %li or a child\n",
25635 +               message, p->comm, task_pid_nr(p), p->xid, points);
25636  
25637         /* Try to kill a child first */
25638         list_for_each_entry(c, &p->children, sibling) {
25639 @@ -554,6 +573,8 @@ void clear_zonelist_oom(struct zonelist 
25640         spin_unlock(&zone_scan_lock);
25641  }
25642  
25643 +long vs_oom_action(unsigned int);
25644 +
25645  /*
25646   * Must be called with tasklist_lock held for read.
25647   */
25648 @@ -580,7 +601,11 @@ retry:
25649         if (!p) {
25650                 read_unlock(&tasklist_lock);
25651                 dump_header(NULL, gfp_mask, order, NULL);
25652 -               panic("Out of memory and no killable processes...\n");
25653 +               /* avoid panic for guest OOM */
25654 +               if (current->xid)
25655 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
25656 +               else
25657 +                       panic("Out of memory and no killable processes...\n");
25658         }
25659  
25660         if (oom_kill_process(p, gfp_mask, order, points, NULL,
25661 diff -NurpP --minimal linux-2.6.33/mm/page_alloc.c linux-2.6.33-vs2.3.0.36.30/mm/page_alloc.c
25662 --- linux-2.6.33/mm/page_alloc.c        2010-02-25 11:52:09.000000000 +0100
25663 +++ linux-2.6.33-vs2.3.0.36.30/mm/page_alloc.c  2010-02-25 12:16:45.000000000 +0100
25664 @@ -49,6 +49,8 @@
25665  #include <linux/debugobjects.h>
25666  #include <linux/kmemleak.h>
25667  #include <linux/memory.h>
25668 +#include <linux/vs_base.h>
25669 +#include <linux/vs_limit.h>
25670  #include <trace/events/kmem.h>
25671  
25672  #include <asm/tlbflush.h>
25673 @@ -2138,6 +2140,9 @@ void si_meminfo(struct sysinfo *val)
25674         val->totalhigh = totalhigh_pages;
25675         val->freehigh = nr_free_highpages();
25676         val->mem_unit = PAGE_SIZE;
25677 +
25678 +       if (vx_flags(VXF_VIRT_MEM, 0))
25679 +               vx_vsi_meminfo(val);
25680  }
25681  
25682  EXPORT_SYMBOL(si_meminfo);
25683 @@ -2158,6 +2163,9 @@ void si_meminfo_node(struct sysinfo *val
25684         val->freehigh = 0;
25685  #endif
25686         val->mem_unit = PAGE_SIZE;
25687 +
25688 +       if (vx_flags(VXF_VIRT_MEM, 0))
25689 +               vx_vsi_meminfo(val);
25690  }
25691  #endif
25692  
25693 diff -NurpP --minimal linux-2.6.33/mm/rmap.c linux-2.6.33-vs2.3.0.36.30/mm/rmap.c
25694 --- linux-2.6.33/mm/rmap.c      2010-02-25 11:52:09.000000000 +0100
25695 +++ linux-2.6.33-vs2.3.0.36.30/mm/rmap.c        2010-02-25 12:02:16.000000000 +0100
25696 @@ -56,6 +56,7 @@
25697  #include <linux/memcontrol.h>
25698  #include <linux/mmu_notifier.h>
25699  #include <linux/migrate.h>
25700 +#include <linux/vs_memory.h>
25701  
25702  #include <asm/tlbflush.h>
25703  
25704 diff -NurpP --minimal linux-2.6.33/mm/shmem.c linux-2.6.33-vs2.3.0.36.30/mm/shmem.c
25705 --- linux-2.6.33/mm/shmem.c     2010-02-25 11:52:09.000000000 +0100
25706 +++ linux-2.6.33-vs2.3.0.36.30/mm/shmem.c       2010-02-25 12:02:16.000000000 +0100
25707 @@ -1788,7 +1788,7 @@ static int shmem_statfs(struct dentry *d
25708  {
25709         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
25710  
25711 -       buf->f_type = TMPFS_MAGIC;
25712 +       buf->f_type = TMPFS_SUPER_MAGIC;
25713         buf->f_bsize = PAGE_CACHE_SIZE;
25714         buf->f_namelen = NAME_MAX;
25715         spin_lock(&sbinfo->stat_lock);
25716 @@ -2358,7 +2358,7 @@ int shmem_fill_super(struct super_block 
25717         sb->s_maxbytes = SHMEM_MAX_BYTES;
25718         sb->s_blocksize = PAGE_CACHE_SIZE;
25719         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
25720 -       sb->s_magic = TMPFS_MAGIC;
25721 +       sb->s_magic = TMPFS_SUPER_MAGIC;
25722         sb->s_op = &shmem_ops;
25723         sb->s_time_gran = 1;
25724  #ifdef CONFIG_TMPFS_POSIX_ACL
25725 diff -NurpP --minimal linux-2.6.33/mm/slab.c linux-2.6.33-vs2.3.0.36.30/mm/slab.c
25726 --- linux-2.6.33/mm/slab.c      2010-02-25 11:52:09.000000000 +0100
25727 +++ linux-2.6.33-vs2.3.0.36.30/mm/slab.c        2010-02-25 12:02:16.000000000 +0100
25728 @@ -431,6 +431,8 @@ static void kmem_list3_init(struct kmem_
25729  #define STATS_INC_FREEMISS(x)  do { } while (0)
25730  #endif
25731  
25732 +#include "slab_vs.h"
25733 +
25734  #if DEBUG
25735  
25736  /*
25737 @@ -3275,6 +3277,7 @@ retry:
25738  
25739         obj = slab_get_obj(cachep, slabp, nodeid);
25740         check_slabp(cachep, slabp);
25741 +       vx_slab_alloc(cachep, flags);
25742         l3->free_objects--;
25743         /* move slabp to correct slabp list: */
25744         list_del(&slabp->list);
25745 @@ -3351,6 +3354,7 @@ __cache_alloc_node(struct kmem_cache *ca
25746         /* ___cache_alloc_node can fall back to other nodes */
25747         ptr = ____cache_alloc_node(cachep, flags, nodeid);
25748    out:
25749 +       vx_slab_alloc(cachep, flags);
25750         local_irq_restore(save_flags);
25751         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
25752         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
25753 @@ -3537,6 +3541,7 @@ static inline void __cache_free(struct k
25754         check_irq_off();
25755         kmemleak_free_recursive(objp, cachep->flags);
25756         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
25757 +       vx_slab_free(cachep);
25758  
25759         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
25760  
25761 diff -NurpP --minimal linux-2.6.33/mm/slab_vs.h linux-2.6.33-vs2.3.0.36.30/mm/slab_vs.h
25762 --- linux-2.6.33/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
25763 +++ linux-2.6.33-vs2.3.0.36.30/mm/slab_vs.h     2010-02-25 12:02:16.000000000 +0100
25764 @@ -0,0 +1,29 @@
25765 +
25766 +#include <linux/vserver/context.h>
25767 +
25768 +#include <linux/vs_context.h>
25769 +
25770 +static inline
25771 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
25772 +{
25773 +       int what = gfp_zone(cachep->gfpflags);
25774 +       struct vx_info *vxi = current_vx_info();
25775 +
25776 +       if (!vxi)
25777 +               return;
25778 +
25779 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
25780 +}
25781 +
25782 +static inline
25783 +void vx_slab_free(struct kmem_cache *cachep)
25784 +{
25785 +       int what = gfp_zone(cachep->gfpflags);
25786 +       struct vx_info *vxi = current_vx_info();
25787 +
25788 +       if (!vxi)
25789 +               return;
25790 +
25791 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
25792 +}
25793 +
25794 diff -NurpP --minimal linux-2.6.33/mm/swapfile.c linux-2.6.33-vs2.3.0.36.30/mm/swapfile.c
25795 --- linux-2.6.33/mm/swapfile.c  2010-02-25 11:52:09.000000000 +0100
25796 +++ linux-2.6.33-vs2.3.0.36.30/mm/swapfile.c    2010-02-25 12:02:16.000000000 +0100
25797 @@ -35,6 +35,8 @@
25798  #include <asm/tlbflush.h>
25799  #include <linux/swapops.h>
25800  #include <linux/page_cgroup.h>
25801 +#include <linux/vs_base.h>
25802 +#include <linux/vs_memory.h>
25803  
25804  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
25805                                  unsigned char);
25806 @@ -1693,6 +1695,16 @@ static int swap_show(struct seq_file *sw
25807  
25808         if (si == SEQ_START_TOKEN) {
25809                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
25810 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
25811 +                       struct sysinfo si;
25812 +
25813 +                       vx_vsi_swapinfo(&si);
25814 +                       if (si.totalswap < (1 << 10))
25815 +                               return 0;
25816 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
25817 +                               "hdv0", "partition", si.totalswap >> 10,
25818 +                               (si.totalswap - si.freeswap) >> 10, -1);
25819 +               }
25820                 return 0;
25821         }
25822  
25823 @@ -2071,6 +2083,8 @@ void si_swapinfo(struct sysinfo *val)
25824         val->freeswap = nr_swap_pages + nr_to_be_unused;
25825         val->totalswap = total_swap_pages + nr_to_be_unused;
25826         spin_unlock(&swap_lock);
25827 +       if (vx_flags(VXF_VIRT_MEM, 0))
25828 +               vx_vsi_swapinfo(val);
25829  }
25830  
25831  /*
25832 diff -NurpP --minimal linux-2.6.33/net/core/dev.c linux-2.6.33-vs2.3.0.36.30/net/core/dev.c
25833 --- linux-2.6.33/net/core/dev.c 2010-02-25 11:52:10.000000000 +0100
25834 +++ linux-2.6.33-vs2.3.0.36.30/net/core/dev.c   2010-02-25 14:02:39.000000000 +0100
25835 @@ -128,6 +128,7 @@
25836  #include <linux/in.h>
25837  #include <linux/jhash.h>
25838  #include <linux/random.h>
25839 +#include <linux/vs_inet.h>
25840  #include <trace/events/napi.h>
25841  
25842  #include "net-sysfs.h"
25843 @@ -593,7 +594,8 @@ struct net_device *__dev_get_by_name(str
25844         struct hlist_head *head = dev_name_hash(net, name);
25845  
25846         hlist_for_each_entry(dev, p, head, name_hlist)
25847 -               if (!strncmp(dev->name, name, IFNAMSIZ))
25848 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
25849 +                   nx_dev_visible(current_nx_info(), dev))
25850                         return dev;
25851  
25852         return NULL;
25853 @@ -619,7 +621,8 @@ struct net_device *dev_get_by_name_rcu(s
25854         struct hlist_head *head = dev_name_hash(net, name);
25855  
25856         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
25857 -               if (!strncmp(dev->name, name, IFNAMSIZ))
25858 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
25859 +                   nx_dev_visible(current_nx_info(), dev))
25860                         return dev;
25861  
25862         return NULL;
25863 @@ -670,7 +673,8 @@ struct net_device *__dev_get_by_index(st
25864         struct hlist_head *head = dev_index_hash(net, ifindex);
25865  
25866         hlist_for_each_entry(dev, p, head, index_hlist)
25867 -               if (dev->ifindex == ifindex)
25868 +               if ((dev->ifindex == ifindex) &&
25869 +                   nx_dev_visible(current_nx_info(), dev))
25870                         return dev;
25871  
25872         return NULL;
25873 @@ -695,7 +699,8 @@ struct net_device *dev_get_by_index_rcu(
25874         struct hlist_head *head = dev_index_hash(net, ifindex);
25875  
25876         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
25877 -               if (dev->ifindex == ifindex)
25878 +               if ((dev->ifindex == ifindex) &&
25879 +                   nx_dev_visible(current_nx_info(), dev))
25880                         return dev;
25881  
25882         return NULL;
25883 @@ -748,10 +753,12 @@ struct net_device *dev_getbyhwaddr(struc
25884  
25885         ASSERT_RTNL();
25886  
25887 -       for_each_netdev(net, dev)
25888 +       for_each_netdev(net, dev) {
25889                 if (dev->type == type &&
25890 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
25891 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
25892 +                   nx_dev_visible(current_nx_info(), dev))
25893                         return dev;
25894 +       }
25895  
25896         return NULL;
25897  }
25898 @@ -762,9 +769,11 @@ struct net_device *__dev_getfirstbyhwtyp
25899         struct net_device *dev;
25900  
25901         ASSERT_RTNL();
25902 -       for_each_netdev(net, dev)
25903 -               if (dev->type == type)
25904 +       for_each_netdev(net, dev) {
25905 +               if ((dev->type == type) &&
25906 +                   nx_dev_visible(current_nx_info(), dev))
25907                         return dev;
25908 +       }
25909  
25910         return NULL;
25911  }
25912 @@ -883,6 +892,8 @@ static int __dev_alloc_name(struct net *
25913                                 continue;
25914                         if (i < 0 || i >= max_netdevices)
25915                                 continue;
25916 +                       if (!nx_dev_visible(current_nx_info(), d))
25917 +                               continue;
25918  
25919                         /*  avoid cases where sscanf is not exact inverse of printf */
25920                         snprintf(buf, IFNAMSIZ, name, i);
25921 @@ -3115,6 +3126,8 @@ static int dev_ifconf(struct net *net, c
25922  
25923         total = 0;
25924         for_each_netdev(net, dev) {
25925 +               if (!nx_dev_visible(current_nx_info(), dev))
25926 +                       continue;
25927                 for (i = 0; i < NPROTO; i++) {
25928                         if (gifconf_list[i]) {
25929                                 int done;
25930 @@ -3185,6 +3198,9 @@ static void dev_seq_printf_stats(struct 
25931  {
25932         const struct net_device_stats *stats = dev_get_stats(dev);
25933  
25934 +       if (!nx_dev_visible(current_nx_info(), dev))
25935 +               return;
25936 +
25937         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
25938                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
25939                    dev->name, stats->rx_bytes, stats->rx_packets,
25940 @@ -5528,7 +5544,6 @@ int dev_change_net_namespace(struct net_
25941         if (dev->dev.parent)
25942                 goto out;
25943  #endif
25944 -
25945         /* Ensure the device has been registrered */
25946         err = -EINVAL;
25947         if (dev->reg_state != NETREG_REGISTERED)
25948 diff -NurpP --minimal linux-2.6.33/net/core/rtnetlink.c linux-2.6.33-vs2.3.0.36.30/net/core/rtnetlink.c
25949 --- linux-2.6.33/net/core/rtnetlink.c   2010-02-25 11:52:10.000000000 +0100
25950 +++ linux-2.6.33-vs2.3.0.36.30/net/core/rtnetlink.c     2010-02-25 13:59:02.000000000 +0100
25951 @@ -695,6 +695,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
25952                 hlist_for_each_entry(dev, node, head, index_hlist) {
25953                         if (idx < s_idx)
25954                                 goto cont;
25955 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
25956 +                               continue;
25957                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
25958                                              NETLINK_CB(cb->skb).pid,
25959                                              cb->nlh->nlmsg_seq, 0,
25960 @@ -1252,6 +1254,9 @@ void rtmsg_ifinfo(int type, struct net_d
25961         struct sk_buff *skb;
25962         int err = -ENOBUFS;
25963  
25964 +       if (!nx_dev_visible(current_nx_info(), dev))
25965 +               return;
25966 +
25967         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
25968         if (skb == NULL)
25969                 goto errout;
25970 diff -NurpP --minimal linux-2.6.33/net/core/sock.c linux-2.6.33-vs2.3.0.36.30/net/core/sock.c
25971 --- linux-2.6.33/net/core/sock.c        2010-02-25 11:52:10.000000000 +0100
25972 +++ linux-2.6.33-vs2.3.0.36.30/net/core/sock.c  2010-02-25 12:02:16.000000000 +0100
25973 @@ -125,6 +125,10 @@
25974  #include <linux/ipsec.h>
25975  
25976  #include <linux/filter.h>
25977 +#include <linux/vs_socket.h>
25978 +#include <linux/vs_limit.h>
25979 +#include <linux/vs_context.h>
25980 +#include <linux/vs_network.h>
25981  
25982  #ifdef CONFIG_INET
25983  #include <net/tcp.h>
25984 @@ -1008,6 +1012,8 @@ static struct sock *sk_prot_alloc(struct
25985                         goto out_free_sec;
25986                 sk_tx_queue_clear(sk);
25987         }
25988 +               sock_vx_init(sk);
25989 +               sock_nx_init(sk);
25990  
25991         return sk;
25992  
25993 @@ -1087,6 +1093,11 @@ static void __sk_free(struct sock *sk)
25994                        __func__, atomic_read(&sk->sk_omem_alloc));
25995  
25996         put_net(sock_net(sk));
25997 +       vx_sock_dec(sk);
25998 +       clr_vx_info(&sk->sk_vx_info);
25999 +       sk->sk_xid = -1;
26000 +       clr_nx_info(&sk->sk_nx_info);
26001 +       sk->sk_nid = -1;
26002         sk_prot_free(sk->sk_prot_creator, sk);
26003  }
26004  
26005 @@ -1134,6 +1145,8 @@ struct sock *sk_clone(const struct sock 
26006  
26007                 /* SANITY */
26008                 get_net(sock_net(newsk));
26009 +               sock_vx_init(newsk);
26010 +               sock_nx_init(newsk);
26011                 sk_node_init(&newsk->sk_node);
26012                 sock_lock_init(newsk);
26013                 bh_lock_sock(newsk);
26014 @@ -1188,6 +1201,12 @@ struct sock *sk_clone(const struct sock 
26015                 smp_wmb();
26016                 atomic_set(&newsk->sk_refcnt, 2);
26017  
26018 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26019 +               newsk->sk_xid = sk->sk_xid;
26020 +               vx_sock_inc(newsk);
26021 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26022 +               newsk->sk_nid = sk->sk_nid;
26023 +
26024                 /*
26025                  * Increment the counter in the same struct proto as the master
26026                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26027 @@ -1910,6 +1929,12 @@ void sock_init_data(struct socket *sock,
26028  
26029         sk->sk_stamp = ktime_set(-1L, 0);
26030  
26031 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
26032 +       sk->sk_xid = vx_current_xid();
26033 +       vx_sock_inc(sk);
26034 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
26035 +       sk->sk_nid = nx_current_nid();
26036 +
26037         /*
26038          * Before updating sk_refcnt, we must commit prior changes to memory
26039          * (Documentation/RCU/rculist_nulls.txt for details)
26040 diff -NurpP --minimal linux-2.6.33/net/ipv4/af_inet.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/af_inet.c
26041 --- linux-2.6.33/net/ipv4/af_inet.c     2010-02-25 11:52:10.000000000 +0100
26042 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/af_inet.c       2010-02-25 15:53:12.000000000 +0100
26043 @@ -115,6 +115,7 @@
26044  #ifdef CONFIG_IP_MROUTE
26045  #include <linux/mroute.h>
26046  #endif
26047 +#include <linux/vs_limit.h>
26048  
26049  
26050  /* The inetsw table contains everything that inet_create needs to
26051 @@ -326,9 +327,13 @@ lookup_protocol:
26052         }
26053  
26054         err = -EPERM;
26055 +       if ((protocol == IPPROTO_ICMP) &&
26056 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
26057 +               goto override;
26058 +
26059         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
26060                 goto out_rcu_unlock;
26061 -
26062 +override:
26063         err = -EAFNOSUPPORT;
26064         if (!inet_netns_ok(net, protocol))
26065                 goto out_rcu_unlock;
26066 @@ -448,6 +453,7 @@ int inet_bind(struct socket *sock, struc
26067         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26068         struct sock *sk = sock->sk;
26069         struct inet_sock *inet = inet_sk(sk);
26070 +       struct nx_v4_sock_addr nsa;
26071         unsigned short snum;
26072         int chk_addr_ret;
26073         int err;
26074 @@ -461,7 +467,11 @@ int inet_bind(struct socket *sock, struc
26075         if (addr_len < sizeof(struct sockaddr_in))
26076                 goto out;
26077  
26078 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26079 +       err = v4_map_sock_addr(inet, addr, &nsa);
26080 +       if (err)
26081 +               goto out;
26082 +
26083 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26084  
26085         /* Not specified by any standard per-se, however it breaks too
26086          * many applications when removed.  It is unfortunate since
26087 @@ -473,7 +483,7 @@ int inet_bind(struct socket *sock, struc
26088         err = -EADDRNOTAVAIL;
26089         if (!sysctl_ip_nonlocal_bind &&
26090             !(inet->freebind || inet->transparent) &&
26091 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26092 +           nsa.saddr != htonl(INADDR_ANY) &&
26093             chk_addr_ret != RTN_LOCAL &&
26094             chk_addr_ret != RTN_MULTICAST &&
26095             chk_addr_ret != RTN_BROADCAST)
26096 @@ -498,7 +508,7 @@ int inet_bind(struct socket *sock, struc
26097         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
26098                 goto out_release_sock;
26099  
26100 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
26101 +       v4_set_sock_addr(inet, &nsa);
26102         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26103                 inet->inet_saddr = 0;  /* Use device */
26104  
26105 @@ -695,11 +705,13 @@ int inet_getname(struct socket *sock, st
26106                      peer == 1))
26107                         return -ENOTCONN;
26108                 sin->sin_port = inet->inet_dport;
26109 -               sin->sin_addr.s_addr = inet->inet_daddr;
26110 +               sin->sin_addr.s_addr =
26111 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
26112         } else {
26113                 __be32 addr = inet->inet_rcv_saddr;
26114                 if (!addr)
26115                         addr = inet->inet_saddr;
26116 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26117                 sin->sin_port = inet->inet_sport;
26118                 sin->sin_addr.s_addr = addr;
26119         }
26120 diff -NurpP --minimal linux-2.6.33/net/ipv4/devinet.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/devinet.c
26121 --- linux-2.6.33/net/ipv4/devinet.c     2010-02-25 11:52:10.000000000 +0100
26122 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/devinet.c       2010-02-25 14:19:58.000000000 +0100
26123 @@ -416,6 +416,7 @@ struct in_device *inetdev_by_index(struc
26124  }
26125  EXPORT_SYMBOL(inetdev_by_index);
26126  
26127 +
26128  /* Called only from RTNL semaphored context. No locks. */
26129  
26130  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26131 @@ -658,6 +659,8 @@ int devinet_ioctl(struct net *net, unsig
26132  
26133         in_dev = __in_dev_get_rtnl(dev);
26134         if (in_dev) {
26135 +               struct nx_info *nxi = current_nx_info();
26136 +
26137                 if (tryaddrmatch) {
26138                         /* Matthias Andree */
26139                         /* compare label and address (4.4BSD style) */
26140 @@ -666,6 +669,8 @@ int devinet_ioctl(struct net *net, unsig
26141                            This is checked above. */
26142                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26143                              ifap = &ifa->ifa_next) {
26144 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26145 +                                       continue;
26146                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26147                                     sin_orig.sin_addr.s_addr ==
26148                                                         ifa->ifa_address) {
26149 @@ -678,9 +683,12 @@ int devinet_ioctl(struct net *net, unsig
26150                    comparing just the label */
26151                 if (!ifa) {
26152                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26153 -                            ifap = &ifa->ifa_next)
26154 +                            ifap = &ifa->ifa_next) {
26155 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26156 +                                       continue;
26157                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26158                                         break;
26159 +                       }
26160                 }
26161         }
26162  
26163 @@ -832,6 +840,8 @@ static int inet_gifconf(struct net_devic
26164                 goto out;
26165  
26166         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
26167 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
26168 +                       continue;
26169                 if (!buf) {
26170                         done += sizeof(ifr);
26171                         continue;
26172 @@ -1180,6 +1190,7 @@ static int inet_dump_ifaddr(struct sk_bu
26173         struct net_device *dev;
26174         struct in_device *in_dev;
26175         struct in_ifaddr *ifa;
26176 +       struct sock *sk = skb->sk;
26177         struct hlist_head *head;
26178         struct hlist_node *node;
26179  
26180 @@ -1202,6 +1213,8 @@ static int inet_dump_ifaddr(struct sk_bu
26181  
26182                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26183                              ifa = ifa->ifa_next, ip_idx++) {
26184 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26185 +                               continue;
26186                                 if (ip_idx < s_ip_idx)
26187                                         continue;
26188                                 if (inet_fill_ifaddr(skb, ifa,
26189 diff -NurpP --minimal linux-2.6.33/net/ipv4/fib_hash.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/fib_hash.c
26190 --- linux-2.6.33/net/ipv4/fib_hash.c    2010-02-25 11:52:10.000000000 +0100
26191 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/fib_hash.c      2010-02-25 12:02:16.000000000 +0100
26192 @@ -1016,7 +1016,7 @@ static int fib_seq_show(struct seq_file 
26193         prefix  = f->fn_key;
26194         mask    = FZ_MASK(iter->zone);
26195         flags   = fib_flag_trans(fa->fa_type, mask, fi);
26196 -       if (fi)
26197 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
26198                 seq_printf(seq,
26199                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
26200                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
26201 diff -NurpP --minimal linux-2.6.33/net/ipv4/inet_connection_sock.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/inet_connection_sock.c
26202 --- linux-2.6.33/net/ipv4/inet_connection_sock.c        2010-02-25 11:52:10.000000000 +0100
26203 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/inet_connection_sock.c  2010-02-25 12:02:16.000000000 +0100
26204 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
26205  }
26206  EXPORT_SYMBOL(inet_get_local_port_range);
26207  
26208 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26209 +{
26210 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
26211 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
26212 +
26213 +       if (inet_v6_ipv6only(sk2))
26214 +               return 0;
26215 +
26216 +       if (sk1_rcv_saddr &&
26217 +           sk2_rcv_saddr &&
26218 +           sk1_rcv_saddr == sk2_rcv_saddr)
26219 +               return 1;
26220 +
26221 +       if (sk1_rcv_saddr &&
26222 +           !sk2_rcv_saddr &&
26223 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26224 +               return 1;
26225 +
26226 +       if (sk2_rcv_saddr &&
26227 +           !sk1_rcv_saddr &&
26228 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26229 +               return 1;
26230 +
26231 +       if (!sk1_rcv_saddr &&
26232 +           !sk2_rcv_saddr &&
26233 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26234 +               return 1;
26235 +
26236 +       return 0;
26237 +}
26238 +
26239  int inet_csk_bind_conflict(const struct sock *sk,
26240                            const struct inet_bind_bucket *tb)
26241  {
26242 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
26243         struct sock *sk2;
26244         struct hlist_node *node;
26245         int reuse = sk->sk_reuse;
26246 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
26247                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26248                         if (!reuse || !sk2->sk_reuse ||
26249                             sk2->sk_state == TCP_LISTEN) {
26250 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26251 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
26252 -                                   sk2_rcv_saddr == sk_rcv_saddr)
26253 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26254                                         break;
26255                         }
26256                 }
26257 diff -NurpP --minimal linux-2.6.33/net/ipv4/inet_diag.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/inet_diag.c
26258 --- linux-2.6.33/net/ipv4/inet_diag.c   2010-02-25 11:52:10.000000000 +0100
26259 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/inet_diag.c     2010-02-25 14:16:01.000000000 +0100
26260 @@ -32,6 +32,8 @@
26261  #include <linux/stddef.h>
26262  
26263  #include <linux/inet_diag.h>
26264 +#include <linux/vs_network.h>
26265 +#include <linux/vs_inet.h>
26266  
26267  static const struct inet_diag_handler **inet_diag_table;
26268  
26269 @@ -118,8 +120,10 @@ static int inet_csk_diag_fill(struct soc
26270  
26271         r->id.idiag_sport = inet->inet_sport;
26272         r->id.idiag_dport = inet->inet_dport;
26273 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
26274 -       r->id.idiag_dst[0] = inet->inet_daddr;
26275 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
26276 +               inet->inet_rcv_saddr);
26277 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
26278 +               inet->inet_daddr);
26279  
26280  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26281         if (r->idiag_family == AF_INET6) {
26282 @@ -204,8 +208,8 @@ static int inet_twsk_diag_fill(struct in
26283         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26284         r->id.idiag_sport     = tw->tw_sport;
26285         r->id.idiag_dport     = tw->tw_dport;
26286 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26287 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26288 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26289 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26290         r->idiag_state        = tw->tw_substate;
26291         r->idiag_timer        = 3;
26292         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26293 @@ -262,6 +266,7 @@ static int inet_diag_get_exact(struct sk
26294         err = -EINVAL;
26295  
26296         if (req->idiag_family == AF_INET) {
26297 +               /* TODO: lback */
26298                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26299                                  req->id.idiag_dport, req->id.idiag_src[0],
26300                                  req->id.idiag_sport, req->id.idiag_if);
26301 @@ -504,6 +509,7 @@ static int inet_csk_diag_dump(struct soc
26302                 } else
26303  #endif
26304                 {
26305 +                       /* TODO: lback */
26306                         entry.saddr = &inet->inet_rcv_saddr;
26307                         entry.daddr = &inet->inet_daddr;
26308                 }
26309 @@ -540,6 +546,7 @@ static int inet_twsk_diag_dump(struct in
26310                 } else
26311  #endif
26312                 {
26313 +                       /* TODO: lback */
26314                         entry.saddr = &tw->tw_rcv_saddr;
26315                         entry.daddr = &tw->tw_daddr;
26316                 }
26317 @@ -586,8 +593,8 @@ static int inet_diag_fill_req(struct sk_
26318  
26319         r->id.idiag_sport = inet->inet_sport;
26320         r->id.idiag_dport = ireq->rmt_port;
26321 -       r->id.idiag_src[0] = ireq->loc_addr;
26322 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26323 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26324 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26325         r->idiag_expires = jiffies_to_msecs(tmo);
26326         r->idiag_rqueue = 0;
26327         r->idiag_wqueue = 0;
26328 @@ -657,6 +664,7 @@ static int inet_diag_dump_reqs(struct sk
26329                                 continue;
26330  
26331                         if (bc) {
26332 +                               /* TODO: lback */
26333                                 entry.saddr =
26334  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26335                                         (entry.family == AF_INET6) ?
26336 @@ -727,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
26337                         sk_nulls_for_each(sk, node, &ilb->head) {
26338                                 struct inet_sock *inet = inet_sk(sk);
26339  
26340 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26341 +                                       continue;
26342                                 if (num < s_num) {
26343                                         num++;
26344                                         continue;
26345 @@ -793,6 +803,8 @@ skip_listen_ht:
26346                 sk_nulls_for_each(sk, node, &head->chain) {
26347                         struct inet_sock *inet = inet_sk(sk);
26348  
26349 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26350 +                               continue;
26351                         if (num < s_num)
26352                                 goto next_normal;
26353                         if (!(r->idiag_states & (1 << sk->sk_state)))
26354 @@ -817,6 +829,8 @@ next_normal:
26355                         inet_twsk_for_each(tw, node,
26356                                     &head->twchain) {
26357  
26358 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26359 +                                       continue;
26360                                 if (num < s_num)
26361                                         goto next_dying;
26362                                 if (r->id.idiag_sport != tw->tw_sport &&
26363 diff -NurpP --minimal linux-2.6.33/net/ipv4/inet_hashtables.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/inet_hashtables.c
26364 --- linux-2.6.33/net/ipv4/inet_hashtables.c     2010-02-25 11:52:10.000000000 +0100
26365 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/inet_hashtables.c       2010-02-25 12:02:16.000000000 +0100
26366 @@ -21,6 +21,7 @@
26367  
26368  #include <net/inet_connection_sock.h>
26369  #include <net/inet_hashtables.h>
26370 +#include <net/route.h>
26371  #include <net/ip.h>
26372  
26373  /*
26374 @@ -134,6 +135,11 @@ static inline int compute_score(struct s
26375                         if (rcv_saddr != daddr)
26376                                 return -1;
26377                         score += 2;
26378 +               } else {
26379 +                       /* block non nx_info ips */
26380 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
26381 +                               daddr, NXA_MASK_BIND))
26382 +                               return -1;
26383                 }
26384                 if (sk->sk_bound_dev_if) {
26385                         if (sk->sk_bound_dev_if != dif)
26386 @@ -151,7 +157,6 @@ static inline int compute_score(struct s
26387   * wildcarded during the search since they can never be otherwise.
26388   */
26389  
26390 -
26391  struct sock *__inet_lookup_listener(struct net *net,
26392                                     struct inet_hashinfo *hashinfo,
26393                                     const __be32 daddr, const unsigned short hnum,
26394 @@ -174,6 +179,7 @@ begin:
26395                         hiscore = score;
26396                 }
26397         }
26398 +
26399         /*
26400          * if the nulls value we got at the end of this lookup is
26401          * not the expected one, we must restart lookup.
26402 diff -NurpP --minimal linux-2.6.33/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/netfilter/nf_nat_helper.c
26403 --- linux-2.6.33/net/ipv4/netfilter/nf_nat_helper.c     2010-02-25 11:52:10.000000000 +0100
26404 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/netfilter/nf_nat_helper.c       2010-02-25 12:02:16.000000000 +0100
26405 @@ -19,6 +19,7 @@
26406  #include <net/route.h>
26407  
26408  #include <linux/netfilter_ipv4.h>
26409 +#include <net/route.h>
26410  #include <net/netfilter/nf_conntrack.h>
26411  #include <net/netfilter/nf_conntrack_helper.h>
26412  #include <net/netfilter/nf_conntrack_ecache.h>
26413 diff -NurpP --minimal linux-2.6.33/net/ipv4/netfilter.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/netfilter.c
26414 --- linux-2.6.33/net/ipv4/netfilter.c   2010-02-25 11:52:10.000000000 +0100
26415 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/netfilter.c     2010-02-25 12:02:16.000000000 +0100
26416 @@ -4,7 +4,7 @@
26417  #include <linux/netfilter_ipv4.h>
26418  #include <linux/ip.h>
26419  #include <linux/skbuff.h>
26420 -#include <net/route.h>
26421 +// #include <net/route.h>
26422  #include <net/xfrm.h>
26423  #include <net/ip.h>
26424  #include <net/netfilter/nf_queue.h>
26425 diff -NurpP --minimal linux-2.6.33/net/ipv4/raw.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/raw.c
26426 --- linux-2.6.33/net/ipv4/raw.c 2010-02-25 11:52:10.000000000 +0100
26427 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/raw.c   2010-02-25 14:07:52.000000000 +0100
26428 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
26429  
26430                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
26431                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
26432 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
26433 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
26434                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
26435                         goto found; /* gotcha */
26436         }
26437 @@ -382,6 +382,12 @@ static int raw_send_hdrinc(struct sock *
26438                 icmp_out_count(net, ((struct icmphdr *)
26439                         skb_transport_header(skb))->type);
26440  
26441 +       err = -EPERM;
26442 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
26443 +               sk->sk_nx_info &&
26444 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
26445 +               goto error_free;
26446 +
26447         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
26448                       dst_output);
26449         if (err > 0)
26450 @@ -562,6 +568,13 @@ static int raw_sendmsg(struct kiocb *ioc
26451                 }
26452  
26453                 security_sk_classify_flow(sk, &fl);
26454 +               if (sk->sk_nx_info) {
26455 +                       err = ip_v4_find_src(sock_net(sk),
26456 +                               sk->sk_nx_info, &rt, &fl);
26457 +
26458 +                       if (err)
26459 +                               goto done;
26460 +               }
26461                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
26462         }
26463         if (err)
26464 @@ -634,17 +647,19 @@ static int raw_bind(struct sock *sk, str
26465  {
26466         struct inet_sock *inet = inet_sk(sk);
26467         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
26468 +       struct nx_v4_sock_addr nsa = { 0 };
26469         int ret = -EINVAL;
26470         int chk_addr_ret;
26471  
26472         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
26473                 goto out;
26474 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26475 +       v4_map_sock_addr(inet, addr, &nsa);
26476 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26477         ret = -EADDRNOTAVAIL;
26478 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
26479 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
26480             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
26481                 goto out;
26482 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
26483 +       v4_set_sock_addr(inet, &nsa);
26484         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26485                 inet->inet_saddr = 0;  /* Use device */
26486         sk_dst_reset(sk);
26487 @@ -696,7 +711,8 @@ static int raw_recvmsg(struct kiocb *ioc
26488         /* Copy the address. */
26489         if (sin) {
26490                 sin->sin_family = AF_INET;
26491 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26492 +               sin->sin_addr.s_addr =
26493 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
26494                 sin->sin_port = 0;
26495                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
26496         }
26497 @@ -874,7 +890,8 @@ static struct sock *raw_get_first(struct
26498                 struct hlist_node *node;
26499  
26500                 sk_for_each(sk, node, &state->h->ht[state->bucket])
26501 -                       if (sock_net(sk) == seq_file_net(seq))
26502 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
26503 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26504                                 goto found;
26505         }
26506         sk = NULL;
26507 @@ -890,7 +907,8 @@ static struct sock *raw_get_next(struct 
26508                 sk = sk_next(sk);
26509  try_again:
26510                 ;
26511 -       } while (sk && sock_net(sk) != seq_file_net(seq));
26512 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
26513 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26514  
26515         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
26516                 sk = sk_head(&state->h->ht[state->bucket]);
26517 @@ -949,7 +967,10 @@ static void raw_sock_seq_show(struct seq
26518  
26519         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
26520                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
26521 -               i, src, srcp, dest, destp, sp->sk_state,
26522 +               i,
26523 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26524 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26525 +               sp->sk_state,
26526                 sk_wmem_alloc_get(sp),
26527                 sk_rmem_alloc_get(sp),
26528                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26529 diff -NurpP --minimal linux-2.6.33/net/ipv4/tcp.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/tcp.c
26530 --- linux-2.6.33/net/ipv4/tcp.c 2010-02-25 11:52:10.000000000 +0100
26531 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/tcp.c   2010-02-25 14:03:32.000000000 +0100
26532 @@ -265,6 +265,7 @@
26533  #include <linux/err.h>
26534  #include <linux/crypto.h>
26535  #include <linux/time.h>
26536 +#include <linux/in.h>
26537  
26538  #include <net/icmp.h>
26539  #include <net/tcp.h>
26540 diff -NurpP --minimal linux-2.6.33/net/ipv4/tcp_ipv4.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/tcp_ipv4.c
26541 --- linux-2.6.33/net/ipv4/tcp_ipv4.c    2010-02-25 11:52:10.000000000 +0100
26542 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/tcp_ipv4.c      2010-02-25 14:08:55.000000000 +0100
26543 @@ -1988,6 +1988,12 @@ static void *listening_get_next(struct s
26544                 req = req->dl_next;
26545                 while (1) {
26546                         while (req) {
26547 +                               vxdprintk(VXD_CBIT(net, 6),
26548 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
26549 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
26550 +                               if (req->sk &&
26551 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
26552 +                                       continue;
26553                                 if (req->rsk_ops->family == st->family) {
26554                                         cur = req;
26555                                         goto out;
26556 @@ -2012,6 +2018,10 @@ get_req:
26557         }
26558  get_sk:
26559         sk_nulls_for_each_from(sk, node) {
26560 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
26561 +                       sk, sk->sk_nid, nx_current_nid());
26562 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26563 +                       continue;
26564                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
26565                         cur = sk;
26566                         goto out;
26567 @@ -2075,6 +2085,11 @@ static void *established_get_first(struc
26568  
26569                 spin_lock_bh(lock);
26570                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
26571 +                       vxdprintk(VXD_CBIT(net, 6),
26572 +                               "sk,egf: %p [#%d] (from %d)",
26573 +                               sk, sk->sk_nid, nx_current_nid());
26574 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26575 +                               continue;
26576                         if (sk->sk_family != st->family ||
26577                             !net_eq(sock_net(sk), net)) {
26578                                 continue;
26579 @@ -2085,6 +2100,11 @@ static void *established_get_first(struc
26580                 st->state = TCP_SEQ_STATE_TIME_WAIT;
26581                 inet_twsk_for_each(tw, node,
26582                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
26583 +                       vxdprintk(VXD_CBIT(net, 6),
26584 +                               "tw: %p [#%d] (from %d)",
26585 +                               tw, tw->tw_nid, nx_current_nid());
26586 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26587 +                               continue;
26588                         if (tw->tw_family != st->family ||
26589                             !net_eq(twsk_net(tw), net)) {
26590                                 continue;
26591 @@ -2113,7 +2133,9 @@ static void *established_get_next(struct
26592                 tw = cur;
26593                 tw = tw_next(tw);
26594  get_tw:
26595 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
26596 +               while (tw && (tw->tw_family != st->family ||
26597 +                       !net_eq(twsk_net(tw), net) ||
26598 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
26599                         tw = tw_next(tw);
26600                 }
26601                 if (tw) {
26602 @@ -2136,6 +2158,11 @@ get_tw:
26603                 sk = sk_nulls_next(sk);
26604  
26605         sk_nulls_for_each_from(sk, node) {
26606 +               vxdprintk(VXD_CBIT(net, 6),
26607 +                       "sk,egn: %p [#%d] (from %d)",
26608 +                       sk, sk->sk_nid, nx_current_nid());
26609 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26610 +                       continue;
26611                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
26612                         goto found;
26613         }
26614 @@ -2287,9 +2314,9 @@ static void get_openreq4(struct sock *sk
26615         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26616                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
26617                 i,
26618 -               ireq->loc_addr,
26619 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
26620                 ntohs(inet_sk(sk)->inet_sport),
26621 -               ireq->rmt_addr,
26622 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
26623                 ntohs(ireq->rmt_port),
26624                 TCP_SYN_RECV,
26625                 0, 0, /* could print option size, but that is af dependent. */
26626 @@ -2341,7 +2368,10 @@ static void get_tcp4_sock(struct sock *s
26627  
26628         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
26629                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
26630 -               i, src, srcp, dest, destp, sk->sk_state,
26631 +               i,
26632 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26633 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26634 +               sk->sk_state,
26635                 tp->write_seq - tp->snd_una,
26636                 rx_queue,
26637                 timer_active,
26638 @@ -2376,7 +2406,10 @@ static void get_timewait4_sock(struct in
26639  
26640         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26641                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
26642 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
26643 +               i,
26644 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26645 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26646 +               tw->tw_substate, 0, 0,
26647                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
26648                 atomic_read(&tw->tw_refcnt), tw, len);
26649  }
26650 diff -NurpP --minimal linux-2.6.33/net/ipv4/tcp_minisocks.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/tcp_minisocks.c
26651 --- linux-2.6.33/net/ipv4/tcp_minisocks.c       2010-02-25 11:52:10.000000000 +0100
26652 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/tcp_minisocks.c 2010-02-25 14:03:06.000000000 +0100
26653 @@ -22,6 +22,9 @@
26654  #include <linux/module.h>
26655  #include <linux/sysctl.h>
26656  #include <linux/workqueue.h>
26657 +#include <linux/vs_limit.h>
26658 +#include <linux/vs_socket.h>
26659 +#include <linux/vs_context.h>
26660  #include <net/tcp.h>
26661  #include <net/inet_common.h>
26662  #include <net/xfrm.h>
26663 @@ -289,6 +292,11 @@ void tcp_time_wait(struct sock *sk, int 
26664                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
26665                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
26666  
26667 +               tw->tw_xid              = sk->sk_xid;
26668 +               tw->tw_vx_info          = NULL;
26669 +               tw->tw_nid              = sk->sk_nid;
26670 +               tw->tw_nx_info          = NULL;
26671 +
26672  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
26673                 if (tw->tw_family == PF_INET6) {
26674                         struct ipv6_pinfo *np = inet6_sk(sk);
26675 diff -NurpP --minimal linux-2.6.33/net/ipv4/udp.c linux-2.6.33-vs2.3.0.36.30/net/ipv4/udp.c
26676 --- linux-2.6.33/net/ipv4/udp.c 2010-02-25 11:52:10.000000000 +0100
26677 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv4/udp.c   2010-02-25 14:18:12.000000000 +0100
26678 @@ -294,14 +294,7 @@ fail:
26679  }
26680  EXPORT_SYMBOL(udp_lib_get_port);
26681  
26682 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26683 -{
26684 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
26685 -
26686 -       return  (!ipv6_only_sock(sk2)  &&
26687 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
26688 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
26689 -}
26690 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
26691  
26692  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
26693                                        unsigned int port)
26694 @@ -336,6 +329,11 @@ static inline int compute_score(struct s
26695                         if (inet->inet_rcv_saddr != daddr)
26696                                 return -1;
26697                         score += 2;
26698 +               } else {
26699 +                       /* block non nx_info ips */
26700 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
26701 +                               daddr, NXA_MASK_BIND))
26702 +                               return -1;
26703                 }
26704                 if (inet->inet_daddr) {
26705                         if (inet->inet_daddr != saddr)
26706 @@ -439,6 +437,7 @@ exact_match:
26707         return result;
26708  }
26709  
26710 +
26711  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
26712   * harder than this. -DaveM
26713   */
26714 @@ -484,6 +483,11 @@ begin:
26715         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
26716                 score = compute_score(sk, net, saddr, hnum, sport,
26717                                       daddr, dport, dif);
26718 +               /* FIXME: disabled?
26719 +               if (score == 9) {
26720 +                       result = sk;
26721 +                       break;
26722 +               } else */
26723                 if (score > badness) {
26724                         result = sk;
26725                         badness = score;
26726 @@ -497,6 +501,7 @@ begin:
26727         if (get_nulls_value(node) != slot)
26728                 goto begin;
26729  
26730 +
26731         if (result) {
26732                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
26733                         result = NULL;
26734 @@ -506,6 +511,7 @@ begin:
26735                         goto begin;
26736                 }
26737         }
26738 +
26739         rcu_read_unlock();
26740         return result;
26741  }
26742 @@ -548,8 +554,7 @@ static inline struct sock *udp_v4_mcast_
26743                     udp_sk(s)->udp_port_hash != hnum ||
26744                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
26745                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
26746 -                   (inet->inet_rcv_saddr &&
26747 -                    inet->inet_rcv_saddr != loc_addr) ||
26748 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
26749                     ipv6_only_sock(s) ||
26750                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
26751                         continue;
26752 @@ -898,8 +903,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
26753                                                { .sport = inet->inet_sport,
26754                                                  .dport = dport } } };
26755                 struct net *net = sock_net(sk);
26756 +               struct nx_info *nxi = sk->sk_nx_info;
26757  
26758                 security_sk_classify_flow(sk, &fl);
26759 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
26760 +               if (err)
26761 +                       goto out;
26762 +
26763                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
26764                 if (err) {
26765                         if (err == -ENETUNREACH)
26766 @@ -1180,7 +1190,8 @@ try_again:
26767         if (sin) {
26768                 sin->sin_family = AF_INET;
26769                 sin->sin_port = udp_hdr(skb)->source;
26770 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26771 +               sin->sin_addr.s_addr = nx_map_sock_lback(
26772 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
26773                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
26774         }
26775         if (inet->cmsg_flags)
26776 @@ -1865,6 +1876,8 @@ static struct sock *udp_get_first(struct
26777                 sk_nulls_for_each(sk, node, &hslot->head) {
26778                         if (!net_eq(sock_net(sk), net))
26779                                 continue;
26780 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26781 +                               continue;
26782                         if (sk->sk_family == state->family)
26783                                 goto found;
26784                 }
26785 @@ -1882,7 +1895,9 @@ static struct sock *udp_get_next(struct 
26786  
26787         do {
26788                 sk = sk_nulls_next(sk);
26789 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
26790 +       } while (sk && (!net_eq(sock_net(sk), net) ||
26791 +               sk->sk_family != state->family ||
26792 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26793  
26794         if (!sk) {
26795                 if (state->bucket <= state->udp_table->mask)
26796 @@ -1989,7 +2004,10 @@ static void udp4_format_sock(struct sock
26797  
26798         seq_printf(f, "%5d: %08X:%04X %08X:%04X"
26799                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
26800 -               bucket, src, srcp, dest, destp, sp->sk_state,
26801 +               bucket,
26802 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26803 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26804 +               sp->sk_state,
26805                 sk_wmem_alloc_get(sp),
26806                 sk_rmem_alloc_get(sp),
26807                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26808 diff -NurpP --minimal linux-2.6.33/net/ipv6/addrconf.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/addrconf.c
26809 --- linux-2.6.33/net/ipv6/addrconf.c    2010-02-25 11:52:10.000000000 +0100
26810 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/addrconf.c      2010-02-25 13:40:38.000000000 +0100
26811 @@ -86,6 +86,8 @@
26812  
26813  #include <linux/proc_fs.h>
26814  #include <linux/seq_file.h>
26815 +#include <linux/vs_network.h>
26816 +#include <linux/vs_inet6.h>
26817  
26818  /* Set to 3 to get tracing... */
26819  #define ACONF_DEBUG 2
26820 @@ -1120,7 +1122,7 @@ out:
26821  
26822  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
26823                        const struct in6_addr *daddr, unsigned int prefs,
26824 -                      struct in6_addr *saddr)
26825 +                      struct in6_addr *saddr, struct nx_info *nxi)
26826  {
26827         struct ipv6_saddr_score scores[2],
26828                                 *score = &scores[0], *hiscore = &scores[1];
26829 @@ -1192,6 +1194,8 @@ int ipv6_dev_get_saddr(struct net *net, 
26830                                                dev->name);
26831                                 continue;
26832                         }
26833 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
26834 +                               continue;
26835  
26836                         score->rule = -1;
26837                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
26838 @@ -2999,7 +3003,10 @@ static void if6_seq_stop(struct seq_file
26839  static int if6_seq_show(struct seq_file *seq, void *v)
26840  {
26841         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
26842 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
26843 +
26844 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
26845 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
26846 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
26847                    &ifp->addr,
26848                    ifp->idev->dev->ifindex,
26849                    ifp->prefix_len,
26850 @@ -3494,6 +3501,11 @@ static int in6_dump_addrs(struct inet6_d
26851         struct ifacaddr6 *ifaca;
26852         int err = 1;
26853         int ip_idx = *p_ip_idx;
26854 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
26855 +
26856 +       /* disable ipv6 on non v6 guests */
26857 +       if (nxi && !nx_info_has_v6(nxi))
26858 +               return skb->len;
26859  
26860         read_lock_bh(&idev->lock);
26861         switch (type) {
26862 @@ -3503,6 +3515,8 @@ static int in6_dump_addrs(struct inet6_d
26863                      ifa = ifa->if_next, ip_idx++) {
26864                         if (ip_idx < s_ip_idx)
26865                                 continue;
26866 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
26867 +                                       continue;
26868                         err = inet6_fill_ifaddr(skb, ifa,
26869                                                 NETLINK_CB(cb->skb).pid,
26870                                                 cb->nlh->nlmsg_seq,
26871 @@ -3518,6 +3532,8 @@ static int in6_dump_addrs(struct inet6_d
26872                      ifmca = ifmca->next, ip_idx++) {
26873                         if (ip_idx < s_ip_idx)
26874                                 continue;
26875 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
26876 +                                       continue;
26877                         err = inet6_fill_ifmcaddr(skb, ifmca,
26878                                                   NETLINK_CB(cb->skb).pid,
26879                                                   cb->nlh->nlmsg_seq,
26880 @@ -3533,6 +3549,8 @@ static int in6_dump_addrs(struct inet6_d
26881                      ifaca = ifaca->aca_next, ip_idx++) {
26882                         if (ip_idx < s_ip_idx)
26883                                 continue;
26884 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
26885 +                                       continue;
26886                         err = inet6_fill_ifacaddr(skb, ifaca,
26887                                                   NETLINK_CB(cb->skb).pid,
26888                                                   cb->nlh->nlmsg_seq,
26889 @@ -3861,6 +3879,11 @@ static int inet6_dump_ifinfo(struct sk_b
26890         struct inet6_dev *idev;
26891         struct hlist_head *head;
26892         struct hlist_node *node;
26893 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
26894 +
26895 +       /* FIXME: maybe disable ipv6 on non v6 guests?
26896 +       if (skb->sk && skb->sk->sk_vx_info)
26897 +               return skb->len; */
26898  
26899         s_h = cb->args[0];
26900         s_idx = cb->args[1];
26901 @@ -3872,6 +3895,8 @@ static int inet6_dump_ifinfo(struct sk_b
26902                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
26903                         if (idx < s_idx)
26904                                 goto cont;
26905 +                       if (!v6_dev_in_nx_info(dev, nxi))
26906 +                               goto cont;
26907                         idev = __in6_dev_get(dev);
26908                         if (!idev)
26909                                 goto cont;
26910 diff -NurpP --minimal linux-2.6.33/net/ipv6/af_inet6.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/af_inet6.c
26911 --- linux-2.6.33/net/ipv6/af_inet6.c    2010-02-25 11:52:10.000000000 +0100
26912 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/af_inet6.c      2010-02-25 15:54:53.000000000 +0100
26913 @@ -41,6 +41,8 @@
26914  #include <linux/netdevice.h>
26915  #include <linux/icmpv6.h>
26916  #include <linux/netfilter_ipv6.h>
26917 +#include <linux/vs_inet.h>
26918 +#include <linux/vs_inet6.h>
26919  
26920  #include <net/ip.h>
26921  #include <net/ipv6.h>
26922 @@ -159,9 +161,12 @@ lookup_protocol:
26923         }
26924  
26925         err = -EPERM;
26926 +       if ((protocol == IPPROTO_ICMPV6) &&
26927 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
26928 +               goto override;
26929         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
26930                 goto out_rcu_unlock;
26931 -
26932 +override:
26933         sock->ops = answer->ops;
26934         answer_prot = answer->prot;
26935         answer_no_check = answer->no_check;
26936 @@ -260,6 +265,7 @@ int inet6_bind(struct socket *sock, stru
26937         struct inet_sock *inet = inet_sk(sk);
26938         struct ipv6_pinfo *np = inet6_sk(sk);
26939         struct net *net = sock_net(sk);
26940 +       struct nx_v6_sock_addr nsa;
26941         __be32 v4addr = 0;
26942         unsigned short snum;
26943         int addr_type = 0;
26944 @@ -271,6 +277,11 @@ int inet6_bind(struct socket *sock, stru
26945  
26946         if (addr_len < SIN6_LEN_RFC2133)
26947                 return -EINVAL;
26948 +
26949 +       err = v6_map_sock_addr(inet, addr, &nsa);
26950 +       if (err)
26951 +               return err;
26952 +
26953         addr_type = ipv6_addr_type(&addr->sin6_addr);
26954         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
26955                 return -EINVAL;
26956 @@ -302,6 +313,7 @@ int inet6_bind(struct socket *sock, stru
26957                 /* Reproduce AF_INET checks to make the bindings consitant */
26958                 v4addr = addr->sin6_addr.s6_addr32[3];
26959                 chk_addr_ret = inet_addr_type(net, v4addr);
26960 +
26961                 if (!sysctl_ip_nonlocal_bind &&
26962                     !(inet->freebind || inet->transparent) &&
26963                     v4addr != htonl(INADDR_ANY) &&
26964 @@ -311,6 +323,10 @@ int inet6_bind(struct socket *sock, stru
26965                         err = -EADDRNOTAVAIL;
26966                         goto out;
26967                 }
26968 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
26969 +                       err = -EADDRNOTAVAIL;
26970 +                       goto out;
26971 +               }
26972         } else {
26973                 if (addr_type != IPV6_ADDR_ANY) {
26974                         struct net_device *dev = NULL;
26975 @@ -337,6 +353,11 @@ int inet6_bind(struct socket *sock, stru
26976                                 }
26977                         }
26978  
26979 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
26980 +                               err = -EADDRNOTAVAIL;
26981 +                               goto out;
26982 +                       }
26983 +
26984                         /* ipv4 addr of the socket is invalid.  Only the
26985                          * unspecified and mapped address have a v4 equivalent.
26986                          */
26987 @@ -352,6 +373,9 @@ int inet6_bind(struct socket *sock, stru
26988                 }
26989         }
26990  
26991 +       /* what's that for? */
26992 +       v6_set_sock_addr(inet, &nsa);
26993 +
26994         inet->inet_rcv_saddr = v4addr;
26995         inet->inet_saddr = v4addr;
26996  
26997 @@ -450,9 +474,11 @@ int inet6_getname(struct socket *sock, s
26998                         return -ENOTCONN;
26999                 sin->sin6_port = inet->inet_dport;
27000                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27001 +               /* FIXME: remap lback? */
27002                 if (np->sndflow)
27003                         sin->sin6_flowinfo = np->flow_label;
27004         } else {
27005 +               /* FIXME: remap lback? */
27006                 if (ipv6_addr_any(&np->rcv_saddr))
27007                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27008                 else
27009 diff -NurpP --minimal linux-2.6.33/net/ipv6/fib6_rules.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/fib6_rules.c
27010 --- linux-2.6.33/net/ipv6/fib6_rules.c  2010-02-25 11:52:10.000000000 +0100
27011 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/fib6_rules.c    2010-02-25 12:02:16.000000000 +0100
27012 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
27013                         if (ipv6_dev_get_saddr(net,
27014                                                ip6_dst_idev(&rt->u.dst)->dev,
27015                                                &flp->fl6_dst, srcprefs,
27016 -                                              &saddr))
27017 +                                              &saddr, NULL))
27018                                 goto again;
27019                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27020                                                r->src.plen))
27021 diff -NurpP --minimal linux-2.6.33/net/ipv6/inet6_hashtables.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/inet6_hashtables.c
27022 --- linux-2.6.33/net/ipv6/inet6_hashtables.c    2010-02-25 11:52:10.000000000 +0100
27023 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/inet6_hashtables.c      2010-02-25 12:02:16.000000000 +0100
27024 @@ -16,6 +16,7 @@
27025  
27026  #include <linux/module.h>
27027  #include <linux/random.h>
27028 +#include <linux/vs_inet6.h>
27029  
27030  #include <net/inet_connection_sock.h>
27031  #include <net/inet_hashtables.h>
27032 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
27033         unsigned int slot = hash & hashinfo->ehash_mask;
27034         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
27035  
27036 -
27037         rcu_read_lock();
27038  begin:
27039         sk_nulls_for_each_rcu(sk, node, &head->chain) {
27040 @@ -94,7 +94,7 @@ begin:
27041                                 sock_put(sk);
27042                                 goto begin;
27043                         }
27044 -               goto out;
27045 +                       goto out;
27046                 }
27047         }
27048         if (get_nulls_value(node) != slot)
27049 @@ -140,6 +140,9 @@ static int inline compute_score(struct s
27050                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27051                                 return -1;
27052                         score++;
27053 +               } else {
27054 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27055 +                               return -1;
27056                 }
27057                 if (sk->sk_bound_dev_if) {
27058                         if (sk->sk_bound_dev_if != dif)
27059 diff -NurpP --minimal linux-2.6.33/net/ipv6/ip6_output.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/ip6_output.c
27060 --- linux-2.6.33/net/ipv6/ip6_output.c  2010-02-25 11:52:10.000000000 +0100
27061 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/ip6_output.c    2010-02-25 12:02:16.000000000 +0100
27062 @@ -933,7 +933,7 @@ static int ip6_dst_lookup_tail(struct so
27063                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
27064                                          &fl->fl6_dst,
27065                                          sk ? inet6_sk(sk)->srcprefs : 0,
27066 -                                        &fl->fl6_src);
27067 +                                        &fl->fl6_src, sk->sk_nx_info);
27068                 if (err)
27069                         goto out_err_release;
27070         }
27071 diff -NurpP --minimal linux-2.6.33/net/ipv6/Kconfig linux-2.6.33-vs2.3.0.36.30/net/ipv6/Kconfig
27072 --- linux-2.6.33/net/ipv6/Kconfig       2010-02-25 11:52:10.000000000 +0100
27073 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/Kconfig 2010-02-25 12:02:16.000000000 +0100
27074 @@ -4,8 +4,8 @@
27075  
27076  #   IPv6 as module will cause a CRASH if you try to unload it
27077  menuconfig IPV6
27078 -       tristate "The IPv6 protocol"
27079 -       default m
27080 +       bool "The IPv6 protocol"
27081 +       default n
27082         ---help---
27083           This is complemental support for the IP version 6.
27084           You will still be able to do traditional IPv4 networking as well.
27085 diff -NurpP --minimal linux-2.6.33/net/ipv6/ndisc.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/ndisc.c
27086 --- linux-2.6.33/net/ipv6/ndisc.c       2010-02-25 11:52:10.000000000 +0100
27087 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/ndisc.c 2010-02-25 12:02:16.000000000 +0100
27088 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
27089         } else {
27090                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27091                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27092 -                                      &tmpaddr))
27093 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
27094                         return;
27095                 src_addr = &tmpaddr;
27096         }
27097 diff -NurpP --minimal linux-2.6.33/net/ipv6/raw.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/raw.c
27098 --- linux-2.6.33/net/ipv6/raw.c 2010-02-25 11:52:11.000000000 +0100
27099 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/raw.c   2010-02-25 12:02:16.000000000 +0100
27100 @@ -29,6 +29,7 @@
27101  #include <linux/icmpv6.h>
27102  #include <linux/netfilter.h>
27103  #include <linux/netfilter_ipv6.h>
27104 +#include <linux/vs_inet6.h>
27105  #include <linux/skbuff.h>
27106  #include <asm/uaccess.h>
27107  #include <asm/ioctls.h>
27108 @@ -282,6 +283,13 @@ static int rawv6_bind(struct sock *sk, s
27109                                 goto out_unlock;
27110                 }
27111  
27112 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27113 +                       err = -EADDRNOTAVAIL;
27114 +                       if (dev)
27115 +                               dev_put(dev);
27116 +                       goto out;
27117 +               }
27118 +
27119                 /* ipv4 addr of the socket is invalid.  Only the
27120                  * unspecified and mapped address have a v4 equivalent.
27121                  */
27122 diff -NurpP --minimal linux-2.6.33/net/ipv6/route.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/route.c
27123 --- linux-2.6.33/net/ipv6/route.c       2010-02-25 11:52:11.000000000 +0100
27124 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/route.c 2010-02-25 12:02:16.000000000 +0100
27125 @@ -2258,7 +2258,8 @@ static int rt6_fill_node(struct net *net
27126                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
27127                 struct in6_addr saddr_buf;
27128                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27129 -                                      dst, 0, &saddr_buf) == 0)
27130 +                       dst, 0, &saddr_buf,
27131 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27132                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27133         }
27134  
27135 diff -NurpP --minimal linux-2.6.33/net/ipv6/tcp_ipv6.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/tcp_ipv6.c
27136 --- linux-2.6.33/net/ipv6/tcp_ipv6.c    2010-02-25 11:52:11.000000000 +0100
27137 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/tcp_ipv6.c      2010-02-25 12:02:16.000000000 +0100
27138 @@ -68,6 +68,7 @@
27139  
27140  #include <linux/crypto.h>
27141  #include <linux/scatterlist.h>
27142 +#include <linux/vs_inet6.h>
27143  
27144  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27145  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27146 @@ -156,8 +157,15 @@ static int tcp_v6_connect(struct sock *s
27147          *      connect() to INADDR_ANY means loopback (BSD'ism).
27148          */
27149  
27150 -       if(ipv6_addr_any(&usin->sin6_addr))
27151 -               usin->sin6_addr.s6_addr[15] = 0x1;
27152 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27153 +               struct nx_info *nxi =  sk->sk_nx_info;
27154 +
27155 +               if (nxi && nx_info_has_v6(nxi))
27156 +                       /* FIXME: remap lback? */
27157 +                       usin->sin6_addr = nxi->v6.ip;
27158 +               else
27159 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27160 +       }
27161  
27162         addr_type = ipv6_addr_type(&usin->sin6_addr);
27163  
27164 diff -NurpP --minimal linux-2.6.33/net/ipv6/udp.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/udp.c
27165 --- linux-2.6.33/net/ipv6/udp.c 2010-02-25 11:52:11.000000000 +0100
27166 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/udp.c   2010-02-25 15:58:22.000000000 +0100
27167 @@ -47,13 +47,14 @@
27168  
27169  #include <linux/proc_fs.h>
27170  #include <linux/seq_file.h>
27171 +#include <linux/vs_inet6.h>
27172  #include "udp_impl.h"
27173  
27174  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27175  {
27176         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27177         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27178 -       __be32 sk1_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
27179 +       __be32 sk_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
27180         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27181         int sk_ipv6only = ipv6_only_sock(sk);
27182         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27183 @@ -61,24 +62,49 @@ int ipv6_rcv_saddr_equal(const struct so
27184         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27185  
27186         /* if both are mapped, treat as IPv4 */
27187 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
27188 -               return (!sk2_ipv6only &&
27189 -                       (!sk1_rcv_saddr || !sk2_rcv_saddr ||
27190 -                         sk1_rcv_saddr == sk2_rcv_saddr));
27191 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
27192 +               if (!sk2_ipv6only &&
27193 +                       (!sk_rcv_saddr || !sk2_rcv_saddr ||
27194 +                         sk_rcv_saddr == sk2_rcv_saddr))
27195 +                       goto vs_v4;
27196 +               else
27197 +                       return 0;
27198 +       }
27199  
27200         if (addr_type2 == IPV6_ADDR_ANY &&
27201             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27202 -               return 1;
27203 +               goto vs;
27204  
27205         if (addr_type == IPV6_ADDR_ANY &&
27206             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27207 -               return 1;
27208 +               goto vs;
27209  
27210         if (sk2_rcv_saddr6 &&
27211             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27212 -               return 1;
27213 +               goto vs;
27214  
27215         return 0;
27216 +
27217 +vs_v4:
27218 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
27219 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
27220 +       if (!sk2_rcv_saddr)
27221 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
27222 +       if (!sk_rcv_saddr)
27223 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
27224 +       return 1;
27225 +vs:
27226 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
27227 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
27228 +       else if (addr_type2 == IPV6_ADDR_ANY)
27229 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
27230 +       else if (addr_type == IPV6_ADDR_ANY) {
27231 +               if (addr_type2 == IPV6_ADDR_MAPPED)
27232 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
27233 +               else
27234 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
27235 +       }
27236 +       return 1;
27237  }
27238  
27239  static unsigned int udp6_portaddr_hash(struct net *net,
27240 @@ -133,6 +159,10 @@ static inline int compute_score(struct s
27241                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27242                                 return -1;
27243                         score++;
27244 +               } else {
27245 +                       /* block non nx_info ips */
27246 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27247 +                               return -1;
27248                 }
27249                 if (!ipv6_addr_any(&np->daddr)) {
27250                         if (!ipv6_addr_equal(&np->daddr, saddr))
27251 diff -NurpP --minimal linux-2.6.33/net/ipv6/xfrm6_policy.c linux-2.6.33-vs2.3.0.36.30/net/ipv6/xfrm6_policy.c
27252 --- linux-2.6.33/net/ipv6/xfrm6_policy.c        2010-02-25 11:52:11.000000000 +0100
27253 +++ linux-2.6.33-vs2.3.0.36.30/net/ipv6/xfrm6_policy.c  2010-02-25 12:02:16.000000000 +0100
27254 @@ -62,7 +62,7 @@ static int xfrm6_get_saddr(struct net *n
27255         dev = ip6_dst_idev(dst)->dev;
27256         ipv6_dev_get_saddr(dev_net(dev), dev,
27257                            (struct in6_addr *)&daddr->a6, 0,
27258 -                          (struct in6_addr *)&saddr->a6);
27259 +                          (struct in6_addr *)&saddr->a6, NULL);
27260         dst_release(dst);
27261         return 0;
27262  }
27263 diff -NurpP --minimal linux-2.6.33/net/netlink/af_netlink.c linux-2.6.33-vs2.3.0.36.30/net/netlink/af_netlink.c
27264 --- linux-2.6.33/net/netlink/af_netlink.c       2010-02-25 11:52:11.000000000 +0100
27265 +++ linux-2.6.33-vs2.3.0.36.30/net/netlink/af_netlink.c 2010-02-25 12:02:16.000000000 +0100
27266 @@ -55,6 +55,9 @@
27267  #include <linux/types.h>
27268  #include <linux/audit.h>
27269  #include <linux/mutex.h>
27270 +#include <linux/vs_context.h>
27271 +#include <linux/vs_network.h>
27272 +#include <linux/vs_limit.h>
27273  
27274  #include <net/net_namespace.h>
27275  #include <net/sock.h>
27276 @@ -1905,6 +1908,8 @@ static struct sock *netlink_seq_socket_i
27277                         sk_for_each(s, node, &hash->table[j]) {
27278                                 if (sock_net(s) != seq_file_net(seq))
27279                                         continue;
27280 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27281 +                                       continue;
27282                                 if (off == pos) {
27283                                         iter->link = i;
27284                                         iter->hash_idx = j;
27285 @@ -1939,7 +1944,8 @@ static void *netlink_seq_next(struct seq
27286         s = v;
27287         do {
27288                 s = sk_next(s);
27289 -       } while (s && sock_net(s) != seq_file_net(seq));
27290 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27291 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27292         if (s)
27293                 return s;
27294  
27295 @@ -1951,7 +1957,8 @@ static void *netlink_seq_next(struct seq
27296  
27297                 for (; j <= hash->mask; j++) {
27298                         s = sk_head(&hash->table[j]);
27299 -                       while (s && sock_net(s) != seq_file_net(seq))
27300 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27301 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27302                                 s = sk_next(s);
27303                         if (s) {
27304                                 iter->link = i;
27305 diff -NurpP --minimal linux-2.6.33/net/sctp/ipv6.c linux-2.6.33-vs2.3.0.36.30/net/sctp/ipv6.c
27306 --- linux-2.6.33/net/sctp/ipv6.c        2010-02-25 11:52:12.000000000 +0100
27307 +++ linux-2.6.33-vs2.3.0.36.30/net/sctp/ipv6.c  2010-02-25 12:02:16.000000000 +0100
27308 @@ -316,7 +316,8 @@ static void sctp_v6_get_saddr(struct sct
27309                                    dst ? ip6_dst_idev(dst)->dev : NULL,
27310                                    &daddr->v6.sin6_addr,
27311                                    inet6_sk(&sk->inet.sk)->srcprefs,
27312 -                                  &saddr->v6.sin6_addr);
27313 +                                  &saddr->v6.sin6_addr,
27314 +                                  asoc->base.sk->sk_nx_info);
27315                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
27316                                   &saddr->v6.sin6_addr);
27317                 return;
27318 diff -NurpP --minimal linux-2.6.33/net/socket.c linux-2.6.33-vs2.3.0.36.30/net/socket.c
27319 --- linux-2.6.33/net/socket.c   2010-02-25 11:52:12.000000000 +0100
27320 +++ linux-2.6.33-vs2.3.0.36.30/net/socket.c     2010-02-25 13:51:25.000000000 +0100
27321 @@ -96,6 +96,10 @@
27322  
27323  #include <net/sock.h>
27324  #include <linux/netfilter.h>
27325 +#include <linux/vs_base.h>
27326 +#include <linux/vs_socket.h>
27327 +#include <linux/vs_inet.h>
27328 +#include <linux/vs_inet6.h>
27329  
27330  #include <linux/if_tun.h>
27331  #include <linux/ipv6_route.h>
27332 @@ -539,7 +543,7 @@ static inline int __sock_sendmsg(struct 
27333                                  struct msghdr *msg, size_t size)
27334  {
27335         struct sock_iocb *si = kiocb_to_siocb(iocb);
27336 -       int err;
27337 +       int err, len;
27338  
27339         si->sock = sock;
27340         si->scm = NULL;
27341 @@ -550,7 +554,22 @@ static inline int __sock_sendmsg(struct 
27342         if (err)
27343                 return err;
27344  
27345 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27346 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27347 +       if (sock->sk) {
27348 +               if (len == size)
27349 +                       vx_sock_send(sock->sk, size);
27350 +               else
27351 +                       vx_sock_fail(sock->sk, size);
27352 +       }
27353 +       vxdprintk(VXD_CBIT(net, 7),
27354 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27355 +               sock, sock->sk,
27356 +               (sock->sk)?sock->sk->sk_nx_info:0,
27357 +               (sock->sk)?sock->sk->sk_vx_info:0,
27358 +               (sock->sk)?sock->sk->sk_xid:0,
27359 +               (sock->sk)?sock->sk->sk_nid:0,
27360 +               (unsigned int)size, len);
27361 +       return len;
27362  }
27363  
27364  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
27365 @@ -667,6 +686,7 @@ static inline int __sock_recvmsg_nosec(s
27366                                        struct msghdr *msg, size_t size, int flags)
27367  {
27368         struct sock_iocb *si = kiocb_to_siocb(iocb);
27369 +       int len;
27370  
27371         si->sock = sock;
27372         si->scm = NULL;
27373 @@ -674,7 +694,18 @@ static inline int __sock_recvmsg_nosec(s
27374         si->size = size;
27375         si->flags = flags;
27376  
27377 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27378 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27379 +       if ((len >= 0) && sock->sk)
27380 +               vx_sock_recv(sock->sk, len);
27381 +       vxdprintk(VXD_CBIT(net, 7),
27382 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27383 +               sock, sock->sk,
27384 +               (sock->sk)?sock->sk->sk_nx_info:0,
27385 +               (sock->sk)?sock->sk->sk_vx_info:0,
27386 +               (sock->sk)?sock->sk->sk_xid:0,
27387 +               (sock->sk)?sock->sk->sk_nid:0,
27388 +               (unsigned int)size, len);
27389 +       return len;
27390  }
27391  
27392  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27393 @@ -1182,6 +1213,13 @@ static int __sock_create(struct net *net
27394         if (type < 0 || type >= SOCK_MAX)
27395                 return -EINVAL;
27396  
27397 +       if (!nx_check(0, VS_ADMIN)) {
27398 +               if (family == PF_INET && !current_nx_info_has_v4())
27399 +                       return -EAFNOSUPPORT;
27400 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27401 +                       return -EAFNOSUPPORT;
27402 +       }
27403 +
27404         /* Compatibility.
27405  
27406            This uglymoron is moved from INET layer to here to avoid
27407 @@ -1314,6 +1352,7 @@ SYSCALL_DEFINE3(socket, int, family, int
27408         if (retval < 0)
27409                 goto out;
27410  
27411 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27412         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27413         if (retval < 0)
27414                 goto out_release;
27415 @@ -1355,10 +1394,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
27416         err = sock_create(family, type, protocol, &sock1);
27417         if (err < 0)
27418                 goto out;
27419 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27420  
27421         err = sock_create(family, type, protocol, &sock2);
27422         if (err < 0)
27423                 goto out_release_1;
27424 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27425  
27426         err = sock1->ops->socketpair(sock1, sock2);
27427         if (err < 0)
27428 diff -NurpP --minimal linux-2.6.33/net/sunrpc/auth.c linux-2.6.33-vs2.3.0.36.30/net/sunrpc/auth.c
27429 --- linux-2.6.33/net/sunrpc/auth.c      2010-02-25 11:52:12.000000000 +0100
27430 +++ linux-2.6.33-vs2.3.0.36.30/net/sunrpc/auth.c        2010-02-25 12:02:16.000000000 +0100
27431 @@ -14,6 +14,7 @@
27432  #include <linux/hash.h>
27433  #include <linux/sunrpc/clnt.h>
27434  #include <linux/spinlock.h>
27435 +#include <linux/vs_tag.h>
27436  
27437  #ifdef RPC_DEBUG
27438  # define RPCDBG_FACILITY       RPCDBG_AUTH
27439 @@ -363,6 +364,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
27440         memset(&acred, 0, sizeof(acred));
27441         acred.uid = cred->fsuid;
27442         acred.gid = cred->fsgid;
27443 +       acred.tag = dx_current_tag();
27444         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
27445  
27446         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
27447 @@ -403,6 +405,7 @@ rpcauth_bind_root_cred(struct rpc_task *
27448         struct auth_cred acred = {
27449                 .uid = 0,
27450                 .gid = 0,
27451 +               .tag = dx_current_tag(),
27452         };
27453         struct rpc_cred *ret;
27454  
27455 diff -NurpP --minimal linux-2.6.33/net/sunrpc/auth_unix.c linux-2.6.33-vs2.3.0.36.30/net/sunrpc/auth_unix.c
27456 --- linux-2.6.33/net/sunrpc/auth_unix.c 2008-12-25 00:26:37.000000000 +0100
27457 +++ linux-2.6.33-vs2.3.0.36.30/net/sunrpc/auth_unix.c   2010-02-25 12:02:16.000000000 +0100
27458 @@ -11,12 +11,14 @@
27459  #include <linux/module.h>
27460  #include <linux/sunrpc/clnt.h>
27461  #include <linux/sunrpc/auth.h>
27462 +#include <linux/vs_tag.h>
27463  
27464  #define NFS_NGROUPS    16
27465  
27466  struct unx_cred {
27467         struct rpc_cred         uc_base;
27468         gid_t                   uc_gid;
27469 +       tag_t                   uc_tag;
27470         gid_t                   uc_gids[NFS_NGROUPS];
27471  };
27472  #define uc_uid                 uc_base.cr_uid
27473 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
27474                 groups = NFS_NGROUPS;
27475  
27476         cred->uc_gid = acred->gid;
27477 +       cred->uc_tag = acred->tag;
27478         for (i = 0; i < groups; i++)
27479                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
27480         if (i < NFS_NGROUPS)
27481 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
27482         unsigned int i;
27483  
27484  
27485 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
27486 +       if (cred->uc_uid != acred->uid ||
27487 +               cred->uc_gid != acred->gid ||
27488 +               cred->uc_tag != acred->tag)
27489                 return 0;
27490  
27491         if (acred->group_info != NULL)
27492 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
27493         struct rpc_clnt *clnt = task->tk_client;
27494         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
27495         __be32          *base, *hold;
27496 -       int             i;
27497 +       int             i, tag;
27498  
27499         *p++ = htonl(RPC_AUTH_UNIX);
27500         base = p++;
27501 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
27502          * Copy the UTS nodename captured when the client was created.
27503          */
27504         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
27505 +       tag = task->tk_client->cl_tag;
27506  
27507 -       *p++ = htonl((u32) cred->uc_uid);
27508 -       *p++ = htonl((u32) cred->uc_gid);
27509 +       *p++ = htonl((u32) TAGINO_UID(tag,
27510 +               cred->uc_uid, cred->uc_tag));
27511 +       *p++ = htonl((u32) TAGINO_GID(tag,
27512 +               cred->uc_gid, cred->uc_tag));
27513         hold = p++;
27514         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
27515                 *p++ = htonl((u32) cred->uc_gids[i]);
27516 diff -NurpP --minimal linux-2.6.33/net/sunrpc/clnt.c linux-2.6.33-vs2.3.0.36.30/net/sunrpc/clnt.c
27517 --- linux-2.6.33/net/sunrpc/clnt.c      2010-02-25 11:52:12.000000000 +0100
27518 +++ linux-2.6.33-vs2.3.0.36.30/net/sunrpc/clnt.c        2010-02-25 12:02:16.000000000 +0100
27519 @@ -33,6 +33,7 @@
27520  #include <linux/utsname.h>
27521  #include <linux/workqueue.h>
27522  #include <linux/in6.h>
27523 +#include <linux/vs_cvirt.h>
27524  
27525  #include <linux/sunrpc/clnt.h>
27526  #include <linux/sunrpc/rpc_pipe_fs.h>
27527 @@ -358,6 +359,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27528         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
27529                 clnt->cl_chatty = 1;
27530  
27531 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27532 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27533 +               clnt->cl_tag = 1; */
27534         return clnt;
27535  }
27536  EXPORT_SYMBOL_GPL(rpc_create);
27537 diff -NurpP --minimal linux-2.6.33/net/unix/af_unix.c linux-2.6.33-vs2.3.0.36.30/net/unix/af_unix.c
27538 --- linux-2.6.33/net/unix/af_unix.c     2010-02-25 11:52:12.000000000 +0100
27539 +++ linux-2.6.33-vs2.3.0.36.30/net/unix/af_unix.c       2010-02-25 12:02:16.000000000 +0100
27540 @@ -114,6 +114,8 @@
27541  #include <linux/mount.h>
27542  #include <net/checksum.h>
27543  #include <linux/security.h>
27544 +#include <linux/vs_context.h>
27545 +#include <linux/vs_limit.h>
27546  
27547  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
27548  static DEFINE_SPINLOCK(unix_table_lock);
27549 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
27550                 if (!net_eq(sock_net(s), net))
27551                         continue;
27552  
27553 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27554 +                       continue;
27555                 if (u->addr->len == len &&
27556                     !memcmp(u->addr->name, sunname, len))
27557                         goto found;
27558 @@ -2115,6 +2119,8 @@ static struct sock *unix_seq_idx(struct 
27559         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
27560                 if (sock_net(s) != seq_file_net(seq))
27561                         continue;
27562 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27563 +                       continue;
27564                 if (off == pos)
27565                         return s;
27566                 ++off;
27567 @@ -2139,7 +2145,8 @@ static void *unix_seq_next(struct seq_fi
27568                 sk = first_unix_socket(&iter->i);
27569         else
27570                 sk = next_unix_socket(&iter->i, sk);
27571 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
27572 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
27573 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
27574                 sk = next_unix_socket(&iter->i, sk);
27575         return sk;
27576  }
27577 diff -NurpP --minimal linux-2.6.33/net/x25/af_x25.c linux-2.6.33-vs2.3.0.36.30/net/x25/af_x25.c
27578 --- linux-2.6.33/net/x25/af_x25.c       2010-02-25 11:52:12.000000000 +0100
27579 +++ linux-2.6.33-vs2.3.0.36.30/net/x25/af_x25.c 2010-02-25 12:02:16.000000000 +0100
27580 @@ -526,7 +526,10 @@ static int x25_create(struct net *net, s
27581  
27582         x25 = x25_sk(sk);
27583  
27584 -       sock_init_data(sock, sk);
27585 +       sk->sk_socket = sock;
27586 +       sk->sk_type = sock->type;
27587 +       sk->sk_sleep = &sock->wait;
27588 +       sock->sk = sk;
27589  
27590         x25_init_timers(sk);
27591  
27592 diff -NurpP --minimal linux-2.6.33/scripts/checksyscalls.sh linux-2.6.33-vs2.3.0.36.30/scripts/checksyscalls.sh
27593 --- linux-2.6.33/scripts/checksyscalls.sh       2009-09-10 15:26:31.000000000 +0200
27594 +++ linux-2.6.33-vs2.3.0.36.30/scripts/checksyscalls.sh 2010-02-25 12:02:16.000000000 +0100
27595 @@ -194,7 +194,6 @@ cat << EOF
27596  #define __IGNORE_afs_syscall
27597  #define __IGNORE_getpmsg
27598  #define __IGNORE_putpmsg
27599 -#define __IGNORE_vserver
27600  EOF
27601  }
27602  
27603 diff -NurpP --minimal linux-2.6.33/security/commoncap.c linux-2.6.33-vs2.3.0.36.30/security/commoncap.c
27604 --- linux-2.6.33/security/commoncap.c   2010-02-25 11:52:12.000000000 +0100
27605 +++ linux-2.6.33-vs2.3.0.36.30/security/commoncap.c     2010-02-25 12:02:16.000000000 +0100
27606 @@ -27,6 +27,7 @@
27607  #include <linux/sched.h>
27608  #include <linux/prctl.h>
27609  #include <linux/securebits.h>
27610 +#include <linux/vs_context.h>
27611  
27612  /*
27613   * If a non-root user executes a setuid-root binary in
27614 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
27615  
27616  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
27617  {
27618 -       NETLINK_CB(skb).eff_cap = current_cap();
27619 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
27620         return 0;
27621  }
27622  
27623 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
27624                 return -EPERM;
27625         return 0;
27626  }
27627 +
27628  EXPORT_SYMBOL(cap_netlink_recv);
27629  
27630  /**
27631 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
27632  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
27633                 int audit)
27634  {
27635 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
27636 +       struct vx_info *vxi = tsk->vx_info;
27637 +
27638 +#if 0
27639 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
27640 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
27641 +               cap_raised(tsk->cap_effective, cap),
27642 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
27643 +#endif
27644 +
27645 +       /* special case SETUP */
27646 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
27647 +               /* FIXME: maybe use cred instead? */
27648 +               cap_raised(tsk->cred->cap_effective, cap))
27649 +               return 0;
27650 +
27651 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
27652  }
27653  
27654  /**
27655 @@ -596,7 +613,7 @@ int cap_inode_removexattr(struct dentry 
27656  
27657         if (!strncmp(name, XATTR_SECURITY_PREFIX,
27658                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
27659 -           !capable(CAP_SYS_ADMIN))
27660 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
27661                 return -EPERM;
27662         return 0;
27663  }
27664 @@ -894,7 +911,8 @@ error:
27665   */
27666  int cap_syslog(int type)
27667  {
27668 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
27669 +       if ((type != 3 && type != 10) &&
27670 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
27671                 return -EPERM;
27672         return 0;
27673  }
27674 @@ -946,3 +964,4 @@ int cap_file_mmap(struct file *file, uns
27675         }
27676         return ret;
27677  }
27678 +
27679 diff -NurpP --minimal linux-2.6.33/security/selinux/hooks.c linux-2.6.33-vs2.3.0.36.30/security/selinux/hooks.c
27680 --- linux-2.6.33/security/selinux/hooks.c       2010-02-25 11:52:12.000000000 +0100
27681 +++ linux-2.6.33-vs2.3.0.36.30/security/selinux/hooks.c 2010-02-25 12:02:16.000000000 +0100
27682 @@ -64,7 +64,6 @@
27683  #include <linux/dccp.h>
27684  #include <linux/quota.h>
27685  #include <linux/un.h>          /* for Unix socket types */
27686 -#include <net/af_unix.h>       /* for Unix socket types */
27687  #include <linux/parser.h>
27688  #include <linux/nfs_mount.h>
27689  #include <net/ipv6.h>
This page took 2.466564 seconds and 4 git commands to generate.