]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- update tuxonice and vserver patches
[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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/Documentation/scheduler/sched-cfs-hard-limits.txt      2010-02-25 16:25:27.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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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/gpu/drm/radeon/r100_reg_safe.h linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/r100_reg_safe.h
1700 --- linux-2.6.33/drivers/gpu/drm/radeon/r100_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1701 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/r100_reg_safe.h 2010-02-27 15:52:40.000000000 +0100
1702 @@ -0,0 +1,28 @@
1703 +static const unsigned r100_reg_safe_bm[102] = {
1704 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1705 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1706 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1707 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1708 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1709 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1710 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1711 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1712 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1713 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1714 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1715 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1716 +       0xFFFFFFCF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1717 +       0xFFFFFF9F, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1718 +       0x38E7FE1F, 0xFFC3FF8E, 0x7FF8FFFF, 0xFFFF803C,
1719 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1720 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFFFF, 0xFFFFFFFF,
1721 +       0x00000000, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF,
1722 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1723 +       0xFFFFFFFF, 0xFFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1724 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1725 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1726 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1727 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1728 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1729 +       0xFFFFFFFF, 0xFFFFFFEF,
1730 +};
1731 diff -NurpP --minimal linux-2.6.33/drivers/gpu/drm/radeon/r200_reg_safe.h linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/r200_reg_safe.h
1732 --- linux-2.6.33/drivers/gpu/drm/radeon/r200_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1733 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/r200_reg_safe.h 2010-02-27 15:52:44.000000000 +0100
1734 @@ -0,0 +1,28 @@
1735 +static const unsigned r200_reg_safe_bm[102] = {
1736 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1737 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1738 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1739 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1740 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1741 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1742 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1743 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1744 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1745 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1746 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1747 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1748 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1749 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1750 +       0xFFE7FE1F, 0xF003FFFF, 0x7EFFFFFF, 0xFFFF803C,
1751 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1752 +       0xFFFFFFFF, 0xFFFFEFCE, 0xFFFEFFFF, 0xFFFFFFFE,
1753 +       0x020E0FF0, 0xFFCC83FD, 0xFFFFFFFF, 0xFFFFFFFF,
1754 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1755 +       0xFFFBFFFF, 0xEFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1756 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1757 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1758 +       0xDFDFDFDF, 0x3FFDDFDF, 0xFFFFFFFF, 0xFFFFFF7F,
1759 +       0xFFFFFFFF, 0x00FFFFFF, 0x00000000, 0x00000000,
1760 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1761 +       0xFFFFFE3F, 0xFFFFFFEF,
1762 +};
1763 diff -NurpP --minimal linux-2.6.33/drivers/gpu/drm/radeon/r300_reg_safe.h linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/r300_reg_safe.h
1764 --- linux-2.6.33/drivers/gpu/drm/radeon/r300_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1765 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/r300_reg_safe.h 2010-02-27 15:52:41.000000000 +0100
1766 @@ -0,0 +1,42 @@
1767 +static const unsigned r300_reg_safe_bm[159] = {
1768 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1769 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1770 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1771 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1772 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1773 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1774 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1775 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1776 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1777 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1778 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1779 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1780 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1781 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1782 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1783 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1784 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1785 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1786 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1787 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1788 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1789 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1790 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1791 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1792 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1793 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1794 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1795 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1796 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1797 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1798 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1799 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1800 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1801 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1802 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1803 +       0x00000000, 0x0000C100, 0x00000000, 0x00000000,
1804 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1805 +       0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0xFF80FFFF,
1806 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1807 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1808 +};
1809 diff -NurpP --minimal linux-2.6.33/drivers/gpu/drm/radeon/r420_reg_safe.h linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/r420_reg_safe.h
1810 --- linux-2.6.33/drivers/gpu/drm/radeon/r420_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1811 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/r420_reg_safe.h 2010-02-27 15:52:41.000000000 +0100
1812 @@ -0,0 +1,42 @@
1813 +static const unsigned r420_reg_safe_bm[159] = {
1814 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1815 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1816 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1817 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1818 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1819 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1820 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1821 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1822 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1823 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1824 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1825 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1826 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1827 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1828 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1829 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1830 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1831 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1832 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1833 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1834 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1835 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1836 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1837 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1838 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1839 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1840 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1841 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1842 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1843 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1844 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1845 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1846 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1847 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1848 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1849 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1850 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1851 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1852 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1853 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1854 +};
1855 diff -NurpP --minimal linux-2.6.33/drivers/gpu/drm/radeon/rn50_reg_safe.h linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/rn50_reg_safe.h
1856 --- linux-2.6.33/drivers/gpu/drm/radeon/rn50_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1857 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/rn50_reg_safe.h 2010-02-27 15:52:40.000000000 +0100
1858 @@ -0,0 +1,28 @@
1859 +static const unsigned rn50_reg_safe_bm[102] = {
1860 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1861 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1862 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1863 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1864 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1865 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1866 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1867 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1868 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1869 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1870 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1871 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1872 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1873 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1874 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1875 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1876 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1877 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1878 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1879 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1880 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1881 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1882 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1883 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1884 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1885 +       0xFFFFFFFF, 0xFFFFFFFF,
1886 +};
1887 diff -NurpP --minimal linux-2.6.33/drivers/gpu/drm/radeon/rs600_reg_safe.h linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/rs600_reg_safe.h
1888 --- linux-2.6.33/drivers/gpu/drm/radeon/rs600_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1889 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/rs600_reg_safe.h        2010-02-27 15:52:42.000000000 +0100
1890 @@ -0,0 +1,57 @@
1891 +static const unsigned rs600_reg_safe_bm[219] = {
1892 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1893 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1894 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1895 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1896 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1897 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1898 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1899 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1900 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1901 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1902 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1903 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1904 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1905 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1906 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1907 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1908 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1909 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1910 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1911 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1912 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1913 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1914 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1915 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1916 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1917 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1918 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1919 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1920 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1921 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1922 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1923 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1924 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1925 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1926 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1927 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1928 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1929 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1930 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1931 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19, 0xFFFFFFFF,
1932 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1933 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1934 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1935 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1936 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1937 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1938 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1939 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1940 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1941 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1942 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1943 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1944 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1945 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1946 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1947 +};
1948 diff -NurpP --minimal linux-2.6.33/drivers/gpu/drm/radeon/rv515_reg_safe.h linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/rv515_reg_safe.h
1949 --- linux-2.6.33/drivers/gpu/drm/radeon/rv515_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1950 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/gpu/drm/radeon/rv515_reg_safe.h        2010-02-27 15:52:42.000000000 +0100
1951 @@ -0,0 +1,57 @@
1952 +static const unsigned rv515_reg_safe_bm[219] = {
1953 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1954 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1955 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1956 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1957 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1958 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1959 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1960 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1961 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1962 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1963 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1964 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1965 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1966 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1967 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1968 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1969 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1970 +       0xF0000038, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1971 +       0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF,
1972 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1973 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1974 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1975 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1976 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1977 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1978 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1979 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1980 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1981 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1982 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1983 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1984 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1985 +       0x1FFFF878, 0xFFFFE000, 0xFFFFFE1E, 0xFFFFFFFF,
1986 +       0x388F8F50, 0xFFF88082, 0xFF0000FC, 0xFAE009FF,
1987 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1988 +       0xFFFF8CFC, 0xFFFFC1FF, 0xFFFFFFFF, 0xFFFFFFFF,
1989 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1990 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF80FFFF,
1991 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1992 +       0x0003FC01, 0x3FFFFCF8, 0xFF800B19, 0xFFDFFFFF,
1993 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1994 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1995 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1996 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1997 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1998 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1999 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2000 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2001 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2002 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2003 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2004 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2005 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2006 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2007 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2008 +};
2009 diff -NurpP --minimal linux-2.6.33/drivers/infiniband/core/addr.c linux-2.6.33-vs2.3.0.36.30.1/drivers/infiniband/core/addr.c
2010 --- linux-2.6.33/drivers/infiniband/core/addr.c 2010-02-25 11:51:39.000000000 +0100
2011 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/infiniband/core/addr.c 2010-02-26 10:39:59.000000000 +0100
2012 @@ -251,7 +251,7 @@ static int addr6_resolve(struct sockaddr
2013  
2014         if (ipv6_addr_any(&fl.fl6_src)) {
2015                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
2016 -                                        &fl.fl6_dst, 0, &fl.fl6_src);
2017 +                                        &fl.fl6_dst, 0, &fl.fl6_src, NULL);
2018                 if (ret)
2019                         goto put;
2020  
2021 diff -NurpP --minimal linux-2.6.33/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.33-vs2.3.0.36.30.1/drivers/infiniband/hw/ipath/ipath_user_pages.c
2022 --- linux-2.6.33/drivers/infiniband/hw/ipath/ipath_user_pages.c 2009-12-03 20:02:23.000000000 +0100
2023 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/infiniband/hw/ipath/ipath_user_pages.c 2010-02-25 12:02:16.000000000 +0100
2024 @@ -34,6 +34,7 @@
2025  #include <linux/mm.h>
2026  #include <linux/device.h>
2027  #include <linux/sched.h>
2028 +#include <linux/vs_memory.h>
2029  
2030  #include "ipath_kernel.h"
2031  
2032 @@ -62,7 +63,8 @@ static int __get_user_pages(unsigned lon
2033         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
2034                 PAGE_SHIFT;
2035  
2036 -       if (num_pages > lock_limit) {
2037 +       if (num_pages > lock_limit ||
2038 +               !vx_vmlocked_avail(current->mm, num_pages)) {
2039                 ret = -ENOMEM;
2040                 goto bail;
2041         }
2042 @@ -79,7 +81,7 @@ static int __get_user_pages(unsigned lon
2043                         goto bail_release;
2044         }
2045  
2046 -       current->mm->locked_vm += num_pages;
2047 +       vx_vmlocked_add(current->mm, num_pages);
2048  
2049         ret = 0;
2050         goto bail;
2051 @@ -178,7 +180,7 @@ void ipath_release_user_pages(struct pag
2052  
2053         __ipath_release_user_pages(p, num_pages, 1);
2054  
2055 -       current->mm->locked_vm -= num_pages;
2056 +       vx_vmlocked_sub(current->mm, num_pages);
2057  
2058         up_write(&current->mm->mmap_sem);
2059  }
2060 @@ -195,7 +197,7 @@ static void user_pages_account(struct wo
2061                 container_of(_work, struct ipath_user_pages_work, work);
2062  
2063         down_write(&work->mm->mmap_sem);
2064 -       work->mm->locked_vm -= work->num_pages;
2065 +       vx_vmlocked_sub(work->mm, work->num_pages);
2066         up_write(&work->mm->mmap_sem);
2067         mmput(work->mm);
2068         kfree(work);
2069 diff -NurpP --minimal linux-2.6.33/drivers/md/dm.c linux-2.6.33-vs2.3.0.36.30.1/drivers/md/dm.c
2070 --- linux-2.6.33/drivers/md/dm.c        2010-02-25 11:51:41.000000000 +0100
2071 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/md/dm.c        2010-02-25 12:10:11.000000000 +0100
2072 @@ -19,6 +19,7 @@
2073  #include <linux/slab.h>
2074  #include <linux/idr.h>
2075  #include <linux/hdreg.h>
2076 +#include <linux/vs_base.h>
2077  
2078  #include <trace/events/block.h>
2079  
2080 @@ -119,6 +120,7 @@ struct mapped_device {
2081         rwlock_t map_lock;
2082         atomic_t holders;
2083         atomic_t open_count;
2084 +       xid_t xid;
2085  
2086         unsigned long flags;
2087  
2088 @@ -337,6 +339,7 @@ int dm_deleting_md(struct mapped_device 
2089  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
2090  {
2091         struct mapped_device *md;
2092 +       int ret = -ENXIO;
2093  
2094         spin_lock(&_minor_lock);
2095  
2096 @@ -345,18 +348,19 @@ static int dm_blk_open(struct block_devi
2097                 goto out;
2098  
2099         if (test_bit(DMF_FREEING, &md->flags) ||
2100 -           dm_deleting_md(md)) {
2101 -               md = NULL;
2102 +           dm_deleting_md(md))
2103 +               goto out;
2104 +
2105 +       ret = -EACCES;
2106 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
2107                 goto out;
2108 -       }
2109  
2110         dm_get(md);
2111         atomic_inc(&md->open_count);
2112 -
2113 +       ret = 0;
2114  out:
2115         spin_unlock(&_minor_lock);
2116 -
2117 -       return md ? 0 : -ENXIO;
2118 +       return ret;
2119  }
2120  
2121  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
2122 @@ -574,6 +578,14 @@ int dm_set_geometry(struct mapped_device
2123         return 0;
2124  }
2125  
2126 +/*
2127 + * Get the xid associated with a dm device
2128 + */
2129 +xid_t dm_get_xid(struct mapped_device *md)
2130 +{
2131 +       return md->xid;
2132 +}
2133 +
2134  /*-----------------------------------------------------------------
2135   * CRUD START:
2136   *   A more elegant soln is in the works that uses the queue
2137 @@ -1886,6 +1898,7 @@ static struct mapped_device *alloc_dev(i
2138         INIT_LIST_HEAD(&md->uevent_list);
2139         spin_lock_init(&md->uevent_lock);
2140  
2141 +       md->xid = vx_current_xid();
2142         md->queue = blk_init_queue(dm_request_fn, NULL);
2143         if (!md->queue)
2144                 goto bad_queue;
2145 diff -NurpP --minimal linux-2.6.33/drivers/md/dm.h linux-2.6.33-vs2.3.0.36.30.1/drivers/md/dm.h
2146 --- linux-2.6.33/drivers/md/dm.h        2010-02-25 11:51:41.000000000 +0100
2147 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/md/dm.h        2010-02-25 12:02:16.000000000 +0100
2148 @@ -41,6 +41,8 @@ struct dm_dev_internal {
2149  struct dm_table;
2150  struct dm_md_mempools;
2151  
2152 +xid_t dm_get_xid(struct mapped_device *md);
2153 +
2154  /*-----------------------------------------------------------------
2155   * Internal table functions.
2156   *---------------------------------------------------------------*/
2157 diff -NurpP --minimal linux-2.6.33/drivers/md/dm-ioctl.c linux-2.6.33-vs2.3.0.36.30.1/drivers/md/dm-ioctl.c
2158 --- linux-2.6.33/drivers/md/dm-ioctl.c  2010-02-25 11:51:41.000000000 +0100
2159 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/md/dm-ioctl.c  2010-02-25 12:02:16.000000000 +0100
2160 @@ -16,6 +16,7 @@
2161  #include <linux/dm-ioctl.h>
2162  #include <linux/hdreg.h>
2163  #include <linux/compat.h>
2164 +#include <linux/vs_context.h>
2165  
2166  #include <asm/uaccess.h>
2167  
2168 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
2169         unsigned int h = hash_str(str);
2170  
2171         list_for_each_entry (hc, _name_buckets + h, name_list)
2172 -               if (!strcmp(hc->name, str)) {
2173 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
2174 +                       !strcmp(hc->name, str)) {
2175                         dm_get(hc->md);
2176                         return hc;
2177                 }
2178 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
2179         unsigned int h = hash_str(str);
2180  
2181         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
2182 -               if (!strcmp(hc->uuid, str)) {
2183 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
2184 +                       !strcmp(hc->uuid, str)) {
2185                         dm_get(hc->md);
2186                         return hc;
2187                 }
2188 @@ -363,6 +366,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
2189  
2190  static int remove_all(struct dm_ioctl *param, size_t param_size)
2191  {
2192 +       if (!vx_check(0, VS_ADMIN))
2193 +               return -EPERM;
2194 +
2195         dm_hash_remove_all(1);
2196         param->data_size = 0;
2197         return 0;
2198 @@ -410,6 +416,8 @@ static int list_devices(struct dm_ioctl 
2199          */
2200         for (i = 0; i < NUM_BUCKETS; i++) {
2201                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2202 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2203 +                               continue;
2204                         needed += sizeof(struct dm_name_list);
2205                         needed += strlen(hc->name) + 1;
2206                         needed += ALIGN_MASK;
2207 @@ -433,6 +441,8 @@ static int list_devices(struct dm_ioctl 
2208          */
2209         for (i = 0; i < NUM_BUCKETS; i++) {
2210                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2211 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2212 +                               continue;
2213                         if (old_nl)
2214                                 old_nl->next = (uint32_t) ((void *) nl -
2215                                                            (void *) old_nl);
2216 @@ -667,10 +677,11 @@ static struct hash_cell *__find_device_h
2217         if (!md)
2218                 goto out;
2219  
2220 -       mdptr = dm_get_mdptr(md);
2221 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
2222 +               mdptr = dm_get_mdptr(md);
2223 +
2224         if (!mdptr)
2225                 dm_put(md);
2226 -
2227  out:
2228         return mdptr;
2229  }
2230 @@ -1508,8 +1519,8 @@ static int ctl_ioctl(uint command, struc
2231         ioctl_fn fn = NULL;
2232         size_t param_size;
2233  
2234 -       /* only root can play with this */
2235 -       if (!capable(CAP_SYS_ADMIN))
2236 +       /* only root and certain contexts can play with this */
2237 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
2238                 return -EACCES;
2239  
2240         if (_IOC_TYPE(command) != DM_IOCTL)
2241 diff -NurpP --minimal linux-2.6.33/drivers/net/tun.c linux-2.6.33-vs2.3.0.36.30.1/drivers/net/tun.c
2242 --- linux-2.6.33/drivers/net/tun.c      2010-02-25 11:51:53.000000000 +0100
2243 +++ linux-2.6.33-vs2.3.0.36.30.1/drivers/net/tun.c      2010-02-25 12:02:16.000000000 +0100
2244 @@ -61,6 +61,7 @@
2245  #include <linux/crc32.h>
2246  #include <linux/nsproxy.h>
2247  #include <linux/virtio_net.h>
2248 +#include <linux/vs_network.h>
2249  #include <net/net_namespace.h>
2250  #include <net/netns/generic.h>
2251  #include <net/rtnetlink.h>
2252 @@ -102,6 +103,7 @@ struct tun_struct {
2253         unsigned int            flags;
2254         uid_t                   owner;
2255         gid_t                   group;
2256 +       nid_t                   nid;
2257  
2258         struct net_device       *dev;
2259         struct fasync_struct    *fasync;
2260 @@ -816,6 +818,7 @@ static void tun_setup(struct net_device 
2261  
2262         tun->owner = -1;
2263         tun->group = -1;
2264 +       tun->nid = current->nid;
2265  
2266         dev->ethtool_ops = &tun_ethtool_ops;
2267         dev->destructor = tun_free_netdev;
2268 @@ -932,7 +935,7 @@ static int tun_set_iff(struct net *net, 
2269  
2270                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
2271                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
2272 -                   !capable(CAP_NET_ADMIN))
2273 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
2274                         return -EPERM;
2275                 err = security_tun_dev_attach(tun->socket.sk);
2276                 if (err < 0)
2277 @@ -946,7 +949,7 @@ static int tun_set_iff(struct net *net, 
2278                 char *name;
2279                 unsigned long flags = 0;
2280  
2281 -               if (!capable(CAP_NET_ADMIN))
2282 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
2283                         return -EPERM;
2284                 err = security_tun_dev_create();
2285                 if (err < 0)
2286 @@ -1013,6 +1016,9 @@ static int tun_set_iff(struct net *net, 
2287  
2288                 sk->sk_destruct = tun_sock_destruct;
2289  
2290 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
2291 +                       return -EPERM;
2292 +
2293                 err = tun_attach(tun, file);
2294                 if (err < 0)
2295                         goto failed;
2296 @@ -1202,6 +1208,16 @@ static long __tun_chr_ioctl(struct file 
2297                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
2298                 break;
2299  
2300 +       case TUNSETNID:
2301 +               if (!capable(CAP_CONTEXT))
2302 +                       return -EPERM;
2303 +
2304 +               /* Set nid owner of the device */
2305 +               tun->nid = (nid_t) arg;
2306 +
2307 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
2308 +               break;
2309 +
2310         case TUNSETLINK:
2311                 /* Only allow setting the type when the interface is down */
2312                 if (tun->dev->flags & IFF_UP) {
2313 diff -NurpP --minimal linux-2.6.33/fs/attr.c linux-2.6.33-vs2.3.0.36.30.1/fs/attr.c
2314 --- linux-2.6.33/fs/attr.c      2009-12-03 20:02:51.000000000 +0100
2315 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/attr.c      2010-02-25 12:02:16.000000000 +0100
2316 @@ -14,6 +14,9 @@
2317  #include <linux/fcntl.h>
2318  #include <linux/quotaops.h>
2319  #include <linux/security.h>
2320 +#include <linux/proc_fs.h>
2321 +#include <linux/devpts_fs.h>
2322 +#include <linux/vs_tag.h>
2323  
2324  /* Taken over from the old code... */
2325  
2326 @@ -55,6 +58,10 @@ int inode_change_ok(const struct inode *
2327                 if (!is_owner_or_cap(inode))
2328                         goto error;
2329         }
2330 +
2331 +       if (dx_permission(inode, MAY_WRITE))
2332 +               goto error;
2333 +
2334  fine:
2335         retval = 0;
2336  error:
2337 @@ -120,6 +127,8 @@ int inode_setattr(struct inode * inode, 
2338                 inode->i_uid = attr->ia_uid;
2339         if (ia_valid & ATTR_GID)
2340                 inode->i_gid = attr->ia_gid;
2341 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2342 +               inode->i_tag = attr->ia_tag;
2343         if (ia_valid & ATTR_ATIME)
2344                 inode->i_atime = timespec_trunc(attr->ia_atime,
2345                                                 inode->i_sb->s_time_gran);
2346 @@ -214,7 +223,8 @@ int notify_change(struct dentry * dentry
2347                 error = inode_change_ok(inode, attr);
2348                 if (!error) {
2349                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2350 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2351 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2352 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2353                                 error = vfs_dq_transfer(inode, attr) ?
2354                                         -EDQUOT : 0;
2355                         if (!error)
2356 diff -NurpP --minimal linux-2.6.33/fs/binfmt_aout.c linux-2.6.33-vs2.3.0.36.30.1/fs/binfmt_aout.c
2357 --- linux-2.6.33/fs/binfmt_aout.c       2010-02-25 11:52:04.000000000 +0100
2358 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/binfmt_aout.c       2010-02-25 12:02:16.000000000 +0100
2359 @@ -24,6 +24,7 @@
2360  #include <linux/binfmts.h>
2361  #include <linux/personality.h>
2362  #include <linux/init.h>
2363 +#include <linux/vs_memory.h>
2364  
2365  #include <asm/system.h>
2366  #include <asm/uaccess.h>
2367 diff -NurpP --minimal linux-2.6.33/fs/binfmt_elf.c linux-2.6.33-vs2.3.0.36.30.1/fs/binfmt_elf.c
2368 --- linux-2.6.33/fs/binfmt_elf.c        2010-02-25 11:52:04.000000000 +0100
2369 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/binfmt_elf.c        2010-02-25 12:02:16.000000000 +0100
2370 @@ -31,6 +31,7 @@
2371  #include <linux/random.h>
2372  #include <linux/elf.h>
2373  #include <linux/utsname.h>
2374 +#include <linux/vs_memory.h>
2375  #include <asm/uaccess.h>
2376  #include <asm/param.h>
2377  #include <asm/page.h>
2378 diff -NurpP --minimal linux-2.6.33/fs/binfmt_flat.c linux-2.6.33-vs2.3.0.36.30.1/fs/binfmt_flat.c
2379 --- linux-2.6.33/fs/binfmt_flat.c       2010-02-25 11:52:04.000000000 +0100
2380 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/binfmt_flat.c       2010-02-25 12:02:16.000000000 +0100
2381 @@ -35,6 +35,7 @@
2382  #include <linux/init.h>
2383  #include <linux/flat.h>
2384  #include <linux/syscalls.h>
2385 +#include <linux/vs_memory.h>
2386  
2387  #include <asm/byteorder.h>
2388  #include <asm/system.h>
2389 diff -NurpP --minimal linux-2.6.33/fs/binfmt_som.c linux-2.6.33-vs2.3.0.36.30.1/fs/binfmt_som.c
2390 --- linux-2.6.33/fs/binfmt_som.c        2010-02-25 11:52:04.000000000 +0100
2391 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/binfmt_som.c        2010-02-25 12:02:16.000000000 +0100
2392 @@ -28,6 +28,7 @@
2393  #include <linux/shm.h>
2394  #include <linux/personality.h>
2395  #include <linux/init.h>
2396 +#include <linux/vs_memory.h>
2397  
2398  #include <asm/uaccess.h>
2399  #include <asm/pgtable.h>
2400 diff -NurpP --minimal linux-2.6.33/fs/block_dev.c linux-2.6.33-vs2.3.0.36.30.1/fs/block_dev.c
2401 --- linux-2.6.33/fs/block_dev.c 2010-02-25 11:52:04.000000000 +0100
2402 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/block_dev.c 2010-02-25 12:02:16.000000000 +0100
2403 @@ -26,6 +26,7 @@
2404  #include <linux/namei.h>
2405  #include <linux/log2.h>
2406  #include <linux/kmemleak.h>
2407 +#include <linux/vs_device.h>
2408  #include <asm/uaccess.h>
2409  #include "internal.h"
2410  
2411 @@ -566,6 +567,7 @@ struct block_device *bdget(dev_t dev)
2412                 bdev->bd_invalidated = 0;
2413                 inode->i_mode = S_IFBLK;
2414                 inode->i_rdev = dev;
2415 +               inode->i_mdev = dev;
2416                 inode->i_bdev = bdev;
2417                 inode->i_data.a_ops = &def_blk_aops;
2418                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2419 @@ -612,6 +614,11 @@ EXPORT_SYMBOL(bdput);
2420  static struct block_device *bd_acquire(struct inode *inode)
2421  {
2422         struct block_device *bdev;
2423 +       dev_t mdev;
2424 +
2425 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2426 +               return NULL;
2427 +       inode->i_mdev = mdev;
2428  
2429         spin_lock(&bdev_lock);
2430         bdev = inode->i_bdev;
2431 @@ -622,7 +629,7 @@ static struct block_device *bd_acquire(s
2432         }
2433         spin_unlock(&bdev_lock);
2434  
2435 -       bdev = bdget(inode->i_rdev);
2436 +       bdev = bdget(mdev);
2437         if (bdev) {
2438                 spin_lock(&bdev_lock);
2439                 if (!inode->i_bdev) {
2440 diff -NurpP --minimal linux-2.6.33/fs/btrfs/ctree.h linux-2.6.33-vs2.3.0.36.30.1/fs/btrfs/ctree.h
2441 --- linux-2.6.33/fs/btrfs/ctree.h       2010-02-25 11:52:04.000000000 +0100
2442 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/btrfs/ctree.h       2010-02-25 12:02:16.000000000 +0100
2443 @@ -547,11 +547,14 @@ struct btrfs_inode_item {
2444         /* modification sequence number for NFS */
2445         __le64 sequence;
2446  
2447 +       __le16 tag;
2448         /*
2449          * a little future expansion, for more than this we can
2450          * just grow the inode item and version it
2451          */
2452 -       __le64 reserved[4];
2453 +       __le16 reserved16;
2454 +       __le32 reserved32;
2455 +       __le64 reserved[3];
2456         struct btrfs_timespec atime;
2457         struct btrfs_timespec ctime;
2458         struct btrfs_timespec mtime;
2459 @@ -1163,6 +1166,8 @@ struct btrfs_root {
2460  #define BTRFS_MOUNT_DISCARD            (1 << 10)
2461  #define BTRFS_MOUNT_FORCE_COMPRESS      (1 << 11)
2462  
2463 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2464 +
2465  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2466  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2467  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2468 @@ -1182,6 +1187,10 @@ struct btrfs_root {
2469  #define BTRFS_INODE_NOATIME            (1 << 9)
2470  #define BTRFS_INODE_DIRSYNC            (1 << 10)
2471  
2472 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2473 +#define BTRFS_INODE_BARRIER            (1 << 25)
2474 +#define BTRFS_INODE_COW                        (1 << 26)
2475 +
2476  
2477  /* some macros to generate set/get funcs for the struct fields.  This
2478   * assumes there is a lefoo_to_cpu for every type, so lets make a simple
2479 @@ -1384,6 +1393,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2480  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2481  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2482  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2483 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2484  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2485  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2486  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2487 @@ -2357,6 +2367,7 @@ extern const struct dentry_operations bt
2488  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2489  void btrfs_update_iflags(struct inode *inode);
2490  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2491 +int btrfs_sync_flags(struct inode *inode, int, int);
2492  
2493  /* file.c */
2494  int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync);
2495 diff -NurpP --minimal linux-2.6.33/fs/btrfs/disk-io.c linux-2.6.33-vs2.3.0.36.30.1/fs/btrfs/disk-io.c
2496 --- linux-2.6.33/fs/btrfs/disk-io.c     2010-02-25 11:52:04.000000000 +0100
2497 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/btrfs/disk-io.c     2010-02-25 12:02:16.000000000 +0100
2498 @@ -1726,6 +1726,9 @@ struct btrfs_root *open_ctree(struct sup
2499                 goto fail_iput;
2500         }
2501  
2502 +       if (btrfs_test_opt(tree_root, TAGGED))
2503 +               sb->s_flags |= MS_TAGGED;
2504 +
2505         features = btrfs_super_incompat_flags(disk_super) &
2506                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2507         if (features) {
2508 diff -NurpP --minimal linux-2.6.33/fs/btrfs/inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/btrfs/inode.c
2509 --- linux-2.6.33/fs/btrfs/inode.c       2010-02-25 11:52:04.000000000 +0100
2510 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/btrfs/inode.c       2010-02-25 12:02:16.000000000 +0100
2511 @@ -36,6 +36,8 @@
2512  #include <linux/xattr.h>
2513  #include <linux/posix_acl.h>
2514  #include <linux/falloc.h>
2515 +#include <linux/vs_tag.h>
2516 +
2517  #include "compat.h"
2518  #include "ctree.h"
2519  #include "disk-io.h"
2520 @@ -2264,6 +2266,8 @@ static void btrfs_read_locked_inode(stru
2521         int maybe_acls;
2522         u64 alloc_group_block;
2523         u32 rdev;
2524 +       uid_t uid;
2525 +       gid_t gid;
2526         int ret;
2527  
2528         path = btrfs_alloc_path();
2529 @@ -2280,8 +2284,13 @@ static void btrfs_read_locked_inode(stru
2530  
2531         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2532         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2533 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2534 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2535 +
2536 +       uid = btrfs_inode_uid(leaf, inode_item);
2537 +       gid = btrfs_inode_gid(leaf, inode_item);
2538 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2539 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2540 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2541 +               btrfs_inode_tag(leaf, inode_item));
2542         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2543  
2544         tspec = btrfs_inode_atime(inode_item);
2545 @@ -2363,8 +2372,15 @@ static void fill_inode_item(struct btrfs
2546                             struct btrfs_inode_item *item,
2547                             struct inode *inode)
2548  {
2549 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2550 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2551 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2552 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2553 +
2554 +       btrfs_set_inode_uid(leaf, item, uid);
2555 +       btrfs_set_inode_gid(leaf, item, gid);
2556 +#ifdef CONFIG_TAGGING_INTERN
2557 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2558 +#endif
2559 +
2560         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2561         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2562         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2563 @@ -4154,6 +4170,7 @@ static struct inode *btrfs_new_inode(str
2564         } else
2565                 inode->i_gid = current_fsgid();
2566  
2567 +       inode->i_tag = dx_current_fstag(root->fs_info->sb);
2568         inode->i_mode = mode;
2569         inode->i_ino = objectid;
2570         inode_set_bytes(inode, 0);
2571 @@ -5955,6 +5972,7 @@ static const struct inode_operations btr
2572         .listxattr      = btrfs_listxattr,
2573         .removexattr    = btrfs_removexattr,
2574         .permission     = btrfs_permission,
2575 +       .sync_flags     = btrfs_sync_flags,
2576  };
2577  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2578         .lookup         = btrfs_lookup,
2579 @@ -6030,6 +6048,7 @@ static const struct inode_operations btr
2580         .permission     = btrfs_permission,
2581         .fallocate      = btrfs_fallocate,
2582         .fiemap         = btrfs_fiemap,
2583 +       .sync_flags     = btrfs_sync_flags,
2584  };
2585  static const struct inode_operations btrfs_special_inode_operations = {
2586         .getattr        = btrfs_getattr,
2587 diff -NurpP --minimal linux-2.6.33/fs/btrfs/ioctl.c linux-2.6.33-vs2.3.0.36.30.1/fs/btrfs/ioctl.c
2588 --- linux-2.6.33/fs/btrfs/ioctl.c       2010-02-25 11:52:04.000000000 +0100
2589 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/btrfs/ioctl.c       2010-02-25 12:02:16.000000000 +0100
2590 @@ -67,10 +67,13 @@ static unsigned int btrfs_flags_to_ioctl
2591  {
2592         unsigned int iflags = 0;
2593  
2594 -       if (flags & BTRFS_INODE_SYNC)
2595 -               iflags |= FS_SYNC_FL;
2596         if (flags & BTRFS_INODE_IMMUTABLE)
2597                 iflags |= FS_IMMUTABLE_FL;
2598 +       if (flags & BTRFS_INODE_IXUNLINK)
2599 +               iflags |= FS_IXUNLINK_FL;
2600 +
2601 +       if (flags & BTRFS_INODE_SYNC)
2602 +               iflags |= FS_SYNC_FL;
2603         if (flags & BTRFS_INODE_APPEND)
2604                 iflags |= FS_APPEND_FL;
2605         if (flags & BTRFS_INODE_NODUMP)
2606 @@ -80,28 +83,78 @@ static unsigned int btrfs_flags_to_ioctl
2607         if (flags & BTRFS_INODE_DIRSYNC)
2608                 iflags |= FS_DIRSYNC_FL;
2609  
2610 +       if (flags & BTRFS_INODE_BARRIER)
2611 +               iflags |= FS_BARRIER_FL;
2612 +       if (flags & BTRFS_INODE_COW)
2613 +               iflags |= FS_COW_FL;
2614         return iflags;
2615  }
2616  
2617  /*
2618 - * Update inode->i_flags based on the btrfs internal flags.
2619 + * Update inode->i_(v)flags based on the btrfs internal flags.
2620   */
2621  void btrfs_update_iflags(struct inode *inode)
2622  {
2623         struct btrfs_inode *ip = BTRFS_I(inode);
2624  
2625 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2626 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2627 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2628  
2629 -       if (ip->flags & BTRFS_INODE_SYNC)
2630 -               inode->i_flags |= S_SYNC;
2631         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2632                 inode->i_flags |= S_IMMUTABLE;
2633 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2634 +               inode->i_flags |= S_IXUNLINK;
2635 +
2636 +       if (ip->flags & BTRFS_INODE_SYNC)
2637 +               inode->i_flags |= S_SYNC;
2638         if (ip->flags & BTRFS_INODE_APPEND)
2639                 inode->i_flags |= S_APPEND;
2640         if (ip->flags & BTRFS_INODE_NOATIME)
2641                 inode->i_flags |= S_NOATIME;
2642         if (ip->flags & BTRFS_INODE_DIRSYNC)
2643                 inode->i_flags |= S_DIRSYNC;
2644 +
2645 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2646 +
2647 +       if (ip->flags & BTRFS_INODE_BARRIER)
2648 +               inode->i_vflags |= V_BARRIER;
2649 +       if (ip->flags & BTRFS_INODE_COW)
2650 +               inode->i_vflags |= V_COW;
2651 +}
2652 +
2653 +/*
2654 + * Update btrfs internal flags from inode->i_(v)flags.
2655 + */
2656 +void btrfs_update_flags(struct inode *inode)
2657 +{
2658 +       struct btrfs_inode *ip = BTRFS_I(inode);
2659 +
2660 +       unsigned int flags = inode->i_flags;
2661 +       unsigned int vflags = inode->i_vflags;
2662 +
2663 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2664 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2665 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2666 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2667 +
2668 +       if (flags & S_IMMUTABLE)
2669 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2670 +       if (flags & S_IXUNLINK)
2671 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2672 +
2673 +       if (flags & S_SYNC)
2674 +               ip->flags |= BTRFS_INODE_SYNC;
2675 +       if (flags & S_APPEND)
2676 +               ip->flags |= BTRFS_INODE_APPEND;
2677 +       if (flags & S_NOATIME)
2678 +               ip->flags |= BTRFS_INODE_NOATIME;
2679 +       if (flags & S_DIRSYNC)
2680 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2681 +
2682 +       if (vflags & V_BARRIER)
2683 +               ip->flags |= BTRFS_INODE_BARRIER;
2684 +       if (vflags & V_COW)
2685 +               ip->flags |= BTRFS_INODE_COW;
2686  }
2687  
2688  /*
2689 @@ -119,7 +172,7 @@ void btrfs_inherit_iflags(struct inode *
2690         flags = BTRFS_I(dir)->flags;
2691  
2692         if (S_ISREG(inode->i_mode))
2693 -               flags &= ~BTRFS_INODE_DIRSYNC;
2694 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2695         else if (!S_ISDIR(inode->i_mode))
2696                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2697  
2698 @@ -127,6 +180,30 @@ void btrfs_inherit_iflags(struct inode *
2699         btrfs_update_iflags(inode);
2700  }
2701  
2702 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2703 +{
2704 +       struct btrfs_inode *ip = BTRFS_I(inode);
2705 +       struct btrfs_root *root = ip->root;
2706 +       struct btrfs_trans_handle *trans;
2707 +       int ret;
2708 +
2709 +       trans = btrfs_join_transaction(root, 1);
2710 +       BUG_ON(!trans);
2711 +
2712 +       inode->i_flags = flags;
2713 +       inode->i_vflags = vflags;
2714 +       btrfs_update_flags(inode);
2715 +
2716 +       ret = btrfs_update_inode(trans, root, inode);
2717 +       BUG_ON(ret);
2718 +
2719 +       btrfs_update_iflags(inode);
2720 +       inode->i_ctime = CURRENT_TIME;
2721 +       btrfs_end_transaction(trans, root);
2722 +
2723 +       return 0;
2724 +}
2725 +
2726  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2727  {
2728         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2729 @@ -149,6 +226,7 @@ static int btrfs_ioctl_setflags(struct f
2730         if (copy_from_user(&flags, arg, sizeof(flags)))
2731                 return -EFAULT;
2732  
2733 +       /* maybe add FS_IXUNLINK_FL ? */
2734         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2735                       FS_NOATIME_FL | FS_NODUMP_FL | \
2736                       FS_SYNC_FL | FS_DIRSYNC_FL))
2737 @@ -161,7 +239,8 @@ static int btrfs_ioctl_setflags(struct f
2738  
2739         flags = btrfs_mask_flags(inode->i_mode, flags);
2740         oldflags = btrfs_flags_to_ioctl(ip->flags);
2741 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2742 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2743 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2744                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2745                         ret = -EPERM;
2746                         goto out_unlock;
2747 @@ -172,14 +251,19 @@ static int btrfs_ioctl_setflags(struct f
2748         if (ret)
2749                 goto out_unlock;
2750  
2751 -       if (flags & FS_SYNC_FL)
2752 -               ip->flags |= BTRFS_INODE_SYNC;
2753 -       else
2754 -               ip->flags &= ~BTRFS_INODE_SYNC;
2755         if (flags & FS_IMMUTABLE_FL)
2756                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2757         else
2758                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2759 +       if (flags & FS_IXUNLINK_FL)
2760 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2761 +       else
2762 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2763 +
2764 +       if (flags & FS_SYNC_FL)
2765 +               ip->flags |= BTRFS_INODE_SYNC;
2766 +       else
2767 +               ip->flags &= ~BTRFS_INODE_SYNC;
2768         if (flags & FS_APPEND_FL)
2769                 ip->flags |= BTRFS_INODE_APPEND;
2770         else
2771 diff -NurpP --minimal linux-2.6.33/fs/btrfs/super.c linux-2.6.33-vs2.3.0.36.30.1/fs/btrfs/super.c
2772 --- linux-2.6.33/fs/btrfs/super.c       2010-02-25 11:52:04.000000000 +0100
2773 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/btrfs/super.c       2010-02-25 15:33:43.000000000 +0100
2774 @@ -68,7 +68,7 @@ enum {
2775         Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl,
2776         Opt_compress, Opt_compress_force, Opt_notreelog, Opt_ratio,
2777         Opt_flushoncommit,
2778 -       Opt_discard, Opt_err,
2779 +       Opt_tag, Opt_notag, Opt_tagid, Opt_discard, Opt_err,
2780  };
2781  
2782  static match_table_t tokens = {
2783 @@ -92,6 +92,9 @@ static match_table_t tokens = {
2784         {Opt_flushoncommit, "flushoncommit"},
2785         {Opt_ratio, "metadata_ratio=%d"},
2786         {Opt_discard, "discard"},
2787 +       {Opt_tag, "tag"},
2788 +       {Opt_notag, "notag"},
2789 +       {Opt_tagid, "tagid=%u"},
2790         {Opt_err, NULL},
2791  };
2792  
2793 @@ -270,6 +273,22 @@ int btrfs_parse_options(struct btrfs_roo
2794                 case Opt_discard:
2795                         btrfs_set_opt(info->mount_opt, DISCARD);
2796                         break;
2797 +#ifndef CONFIG_TAGGING_NONE
2798 +               case Opt_tag:
2799 +                       printk(KERN_INFO "btrfs: use tagging\n");
2800 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2801 +                       break;
2802 +               case Opt_notag:
2803 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2804 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2805 +                       break;
2806 +#endif
2807 +#ifdef CONFIG_PROPAGATE
2808 +               case Opt_tagid:
2809 +                       /* use args[0] */
2810 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2811 +                       break;
2812 +#endif
2813                 case Opt_err:
2814                         printk(KERN_INFO "btrfs: unrecognized mount option "
2815                                "'%s'\n", p);
2816 @@ -591,6 +610,12 @@ static int btrfs_remount(struct super_bl
2817         if (ret)
2818                 return -EINVAL;
2819  
2820 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2821 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2822 +                       sb->s_id);
2823 +               return -EINVAL;
2824 +       }
2825 +
2826         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2827                 return 0;
2828  
2829 diff -NurpP --minimal linux-2.6.33/fs/char_dev.c linux-2.6.33-vs2.3.0.36.30.1/fs/char_dev.c
2830 --- linux-2.6.33/fs/char_dev.c  2009-12-03 20:02:51.000000000 +0100
2831 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/char_dev.c  2010-02-25 12:02:16.000000000 +0100
2832 @@ -20,6 +20,8 @@
2833  #include <linux/cdev.h>
2834  #include <linux/mutex.h>
2835  #include <linux/backing-dev.h>
2836 +#include <linux/vs_context.h>
2837 +#include <linux/vs_device.h>
2838  
2839  #include "internal.h"
2840  
2841 @@ -368,14 +370,21 @@ static int chrdev_open(struct inode *ino
2842         struct cdev *p;
2843         struct cdev *new = NULL;
2844         int ret = 0;
2845 +       dev_t mdev;
2846 +
2847 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2848 +               return -EPERM;
2849 +       inode->i_mdev = mdev;
2850  
2851         spin_lock(&cdev_lock);
2852         p = inode->i_cdev;
2853         if (!p) {
2854                 struct kobject *kobj;
2855                 int idx;
2856 +
2857                 spin_unlock(&cdev_lock);
2858 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2859 +
2860 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2861                 if (!kobj)
2862                         return -ENXIO;
2863                 new = container_of(kobj, struct cdev, kobj);
2864 diff -NurpP --minimal linux-2.6.33/fs/dcache.c linux-2.6.33-vs2.3.0.36.30.1/fs/dcache.c
2865 --- linux-2.6.33/fs/dcache.c    2010-02-25 11:52:05.000000000 +0100
2866 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/dcache.c    2010-02-25 12:02:16.000000000 +0100
2867 @@ -33,6 +33,7 @@
2868  #include <linux/bootmem.h>
2869  #include <linux/fs_struct.h>
2870  #include <linux/hardirq.h>
2871 +#include <linux/vs_limit.h>
2872  #include "internal.h"
2873  
2874  int sysctl_vfs_cache_pressure __read_mostly = 100;
2875 @@ -230,6 +231,8 @@ repeat:
2876                 return;
2877         }
2878  
2879 +       vx_dentry_dec(dentry);
2880 +
2881         /*
2882          * AV: ->d_delete() is _NOT_ allowed to block now.
2883          */
2884 @@ -321,6 +324,7 @@ static inline struct dentry * __dget_loc
2885  {
2886         atomic_inc(&dentry->d_count);
2887         dentry_lru_del_init(dentry);
2888 +       vx_dentry_inc(dentry);
2889         return dentry;
2890  }
2891  
2892 @@ -919,6 +923,9 @@ struct dentry *d_alloc(struct dentry * p
2893         struct dentry *dentry;
2894         char *dname;
2895  
2896 +       if (!vx_dentry_avail(1))
2897 +               return NULL;
2898 +
2899         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2900         if (!dentry)
2901                 return NULL;
2902 @@ -964,6 +971,7 @@ struct dentry *d_alloc(struct dentry * p
2903         if (parent)
2904                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2905         dentry_stat.nr_dentry++;
2906 +       vx_dentry_inc(dentry);
2907         spin_unlock(&dcache_lock);
2908  
2909         return dentry;
2910 @@ -1408,6 +1416,7 @@ struct dentry * __d_lookup(struct dentry
2911                 }
2912  
2913                 atomic_inc(&dentry->d_count);
2914 +               vx_dentry_inc(dentry);
2915                 found = dentry;
2916                 spin_unlock(&dentry->d_lock);
2917                 break;
2918 diff -NurpP --minimal linux-2.6.33/fs/devpts/inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/devpts/inode.c
2919 --- linux-2.6.33/fs/devpts/inode.c      2010-02-25 11:52:05.000000000 +0100
2920 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/devpts/inode.c      2010-02-25 12:02:16.000000000 +0100
2921 @@ -24,6 +24,7 @@
2922  #include <linux/parser.h>
2923  #include <linux/fsnotify.h>
2924  #include <linux/seq_file.h>
2925 +#include <linux/vs_base.h>
2926  
2927  #define DEVPTS_DEFAULT_MODE 0600
2928  /*
2929 @@ -35,6 +36,20 @@
2930  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2931  #define PTMX_MINOR     2
2932  
2933 +static int devpts_permission(struct inode *inode, int mask)
2934 +{
2935 +       int ret = -EACCES;
2936 +
2937 +       /* devpts is xid tagged */
2938 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2939 +               ret = generic_permission(inode, mask, NULL);
2940 +       return ret;
2941 +}
2942 +
2943 +static struct inode_operations devpts_file_inode_operations = {
2944 +       .permission     = devpts_permission,
2945 +};
2946 +
2947  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2948  static DEFINE_MUTEX(allocated_ptys_lock);
2949  
2950 @@ -262,6 +277,25 @@ static int devpts_show_options(struct se
2951         return 0;
2952  }
2953  
2954 +static int devpts_filter(struct dentry *de)
2955 +{
2956 +       /* devpts is xid tagged */
2957 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2958 +}
2959 +
2960 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2961 +{
2962 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2963 +}
2964 +
2965 +static struct file_operations devpts_dir_operations = {
2966 +       .open           = dcache_dir_open,
2967 +       .release        = dcache_dir_close,
2968 +       .llseek         = dcache_dir_lseek,
2969 +       .read           = generic_read_dir,
2970 +       .readdir        = devpts_readdir,
2971 +};
2972 +
2973  static const struct super_operations devpts_sops = {
2974         .statfs         = simple_statfs,
2975         .remount_fs     = devpts_remount,
2976 @@ -301,12 +335,15 @@ devpts_fill_super(struct super_block *s,
2977         inode = new_inode(s);
2978         if (!inode)
2979                 goto free_fsi;
2980 +
2981         inode->i_ino = 1;
2982         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2983         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2984         inode->i_op = &simple_dir_inode_operations;
2985 -       inode->i_fop = &simple_dir_operations;
2986 +       inode->i_fop = &devpts_dir_operations;
2987         inode->i_nlink = 2;
2988 +       /* devpts is xid tagged */
2989 +       inode->i_tag = (tag_t)vx_current_xid();
2990  
2991         s->s_root = d_alloc_root(inode);
2992         if (s->s_root)
2993 @@ -497,6 +534,9 @@ int devpts_pty_new(struct inode *ptmx_in
2994         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2995         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2996         init_special_inode(inode, S_IFCHR|opts->mode, device);
2997 +       /* devpts is xid tagged */
2998 +       inode->i_tag = (tag_t)vx_current_xid();
2999 +       inode->i_op = &devpts_file_inode_operations;
3000         inode->i_private = tty;
3001         tty->driver_data = inode;
3002  
3003 diff -NurpP --minimal linux-2.6.33/fs/exec.c linux-2.6.33-vs2.3.0.36.30.1/fs/exec.c
3004 --- linux-2.6.33/fs/exec.c      2010-02-25 11:52:05.000000000 +0100
3005 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/exec.c      2010-02-25 12:02:16.000000000 +0100
3006 @@ -250,7 +250,9 @@ static int __bprm_mm_init(struct linux_b
3007         if (err)
3008                 goto err;
3009  
3010 -       mm->stack_vm = mm->total_vm = 1;
3011 +       mm->total_vm = 0;
3012 +       vx_vmpages_inc(mm);
3013 +       mm->stack_vm = 1;
3014         up_write(&mm->mmap_sem);
3015         bprm->p = vma->vm_end - sizeof(void *);
3016         return 0;
3017 @@ -1503,7 +1505,7 @@ static int format_corename(char *corenam
3018                         /* UNIX time of coredump */
3019                         case 't': {
3020                                 struct timeval tv;
3021 -                               do_gettimeofday(&tv);
3022 +                               vx_gettimeofday(&tv);
3023                                 rc = snprintf(out_ptr, out_end - out_ptr,
3024                                               "%lu", tv.tv_sec);
3025                                 if (rc > out_end - out_ptr)
3026 diff -NurpP --minimal linux-2.6.33/fs/ext2/balloc.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/balloc.c
3027 --- linux-2.6.33/fs/ext2/balloc.c       2009-06-11 17:13:03.000000000 +0200
3028 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/balloc.c       2010-02-25 12:02:16.000000000 +0100
3029 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
3030                         start = 0;
3031                 end = EXT2_BLOCKS_PER_GROUP(sb);
3032         }
3033 -
3034         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
3035  
3036  repeat:
3037 diff -NurpP --minimal linux-2.6.33/fs/ext2/ext2.h linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/ext2.h
3038 --- linux-2.6.33/fs/ext2/ext2.h 2010-02-25 11:52:05.000000000 +0100
3039 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/ext2.h 2010-02-25 12:02:16.000000000 +0100
3040 @@ -131,6 +131,7 @@ extern int ext2_fiemap(struct inode *ino
3041  int __ext2_write_begin(struct file *file, struct address_space *mapping,
3042                 loff_t pos, unsigned len, unsigned flags,
3043                 struct page **pagep, void **fsdata);
3044 +extern int ext2_sync_flags(struct inode *, int, int);
3045  
3046  /* ioctl.c */
3047  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
3048 diff -NurpP --minimal linux-2.6.33/fs/ext2/file.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/file.c
3049 --- linux-2.6.33/fs/ext2/file.c 2010-02-25 11:52:05.000000000 +0100
3050 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/file.c 2010-02-25 12:02:16.000000000 +0100
3051 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
3052         .setattr        = ext2_setattr,
3053         .check_acl      = ext2_check_acl,
3054         .fiemap         = ext2_fiemap,
3055 +       .sync_flags     = ext2_sync_flags,
3056  };
3057 diff -NurpP --minimal linux-2.6.33/fs/ext2/ialloc.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/ialloc.c
3058 --- linux-2.6.33/fs/ext2/ialloc.c       2009-06-11 17:13:03.000000000 +0200
3059 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/ialloc.c       2010-02-25 12:02:16.000000000 +0100
3060 @@ -17,6 +17,7 @@
3061  #include <linux/backing-dev.h>
3062  #include <linux/buffer_head.h>
3063  #include <linux/random.h>
3064 +#include <linux/vs_tag.h>
3065  #include "ext2.h"
3066  #include "xattr.h"
3067  #include "acl.h"
3068 @@ -560,6 +561,7 @@ got:
3069         } else
3070                 inode->i_gid = current_fsgid();
3071         inode->i_mode = mode;
3072 +       inode->i_tag = dx_current_fstag(sb);
3073  
3074         inode->i_ino = ino;
3075         inode->i_blocks = 0;
3076 diff -NurpP --minimal linux-2.6.33/fs/ext2/inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/inode.c
3077 --- linux-2.6.33/fs/ext2/inode.c        2010-02-25 11:52:05.000000000 +0100
3078 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/inode.c        2010-02-25 12:02:16.000000000 +0100
3079 @@ -33,6 +33,7 @@
3080  #include <linux/mpage.h>
3081  #include <linux/fiemap.h>
3082  #include <linux/namei.h>
3083 +#include <linux/vs_tag.h>
3084  #include "ext2.h"
3085  #include "acl.h"
3086  #include "xip.h"
3087 @@ -1042,7 +1043,7 @@ void ext2_truncate(struct inode *inode)
3088                 return;
3089         if (ext2_inode_is_fast_symlink(inode))
3090                 return;
3091 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3092 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3093                 return;
3094  
3095         blocksize = inode->i_sb->s_blocksize;
3096 @@ -1180,36 +1181,61 @@ void ext2_set_inode_flags(struct inode *
3097  {
3098         unsigned int flags = EXT2_I(inode)->i_flags;
3099  
3100 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3101 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3102 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3103 +
3104 +
3105 +       if (flags & EXT2_IMMUTABLE_FL)
3106 +               inode->i_flags |= S_IMMUTABLE;
3107 +       if (flags & EXT2_IXUNLINK_FL)
3108 +               inode->i_flags |= S_IXUNLINK;
3109 +
3110         if (flags & EXT2_SYNC_FL)
3111                 inode->i_flags |= S_SYNC;
3112         if (flags & EXT2_APPEND_FL)
3113                 inode->i_flags |= S_APPEND;
3114 -       if (flags & EXT2_IMMUTABLE_FL)
3115 -               inode->i_flags |= S_IMMUTABLE;
3116         if (flags & EXT2_NOATIME_FL)
3117                 inode->i_flags |= S_NOATIME;
3118         if (flags & EXT2_DIRSYNC_FL)
3119                 inode->i_flags |= S_DIRSYNC;
3120 +
3121 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3122 +
3123 +       if (flags & EXT2_BARRIER_FL)
3124 +               inode->i_vflags |= V_BARRIER;
3125 +       if (flags & EXT2_COW_FL)
3126 +               inode->i_vflags |= V_COW;
3127  }
3128  
3129  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
3130  void ext2_get_inode_flags(struct ext2_inode_info *ei)
3131  {
3132         unsigned int flags = ei->vfs_inode.i_flags;
3133 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3134 +
3135 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
3136 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
3137 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
3138 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
3139 +
3140 +       if (flags & S_IMMUTABLE)
3141 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
3142 +       if (flags & S_IXUNLINK)
3143 +               ei->i_flags |= EXT2_IXUNLINK_FL;
3144  
3145 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
3146 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
3147         if (flags & S_SYNC)
3148                 ei->i_flags |= EXT2_SYNC_FL;
3149         if (flags & S_APPEND)
3150                 ei->i_flags |= EXT2_APPEND_FL;
3151 -       if (flags & S_IMMUTABLE)
3152 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
3153         if (flags & S_NOATIME)
3154                 ei->i_flags |= EXT2_NOATIME_FL;
3155         if (flags & S_DIRSYNC)
3156                 ei->i_flags |= EXT2_DIRSYNC_FL;
3157 +
3158 +       if (vflags & V_BARRIER)
3159 +               ei->i_flags |= EXT2_BARRIER_FL;
3160 +       if (vflags & V_COW)
3161 +               ei->i_flags |= EXT2_COW_FL;
3162  }
3163  
3164  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
3165 @@ -1219,6 +1245,8 @@ struct inode *ext2_iget (struct super_bl
3166         struct ext2_inode *raw_inode;
3167         struct inode *inode;
3168         long ret = -EIO;
3169 +       uid_t uid;
3170 +       gid_t gid;
3171         int n;
3172  
3173         inode = iget_locked(sb, ino);
3174 @@ -1237,12 +1265,17 @@ struct inode *ext2_iget (struct super_bl
3175         }
3176  
3177         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3178 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3179 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3180 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3181 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3182         if (!(test_opt (inode->i_sb, NO_UID32))) {
3183 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3184 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3185 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3186 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3187         }
3188 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3189 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3190 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3191 +               le16_to_cpu(raw_inode->i_raw_tag));
3192 +
3193         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3194         inode->i_size = le32_to_cpu(raw_inode->i_size);
3195         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3196 @@ -1340,8 +1373,8 @@ int ext2_write_inode(struct inode *inode
3197         struct ext2_inode_info *ei = EXT2_I(inode);
3198         struct super_block *sb = inode->i_sb;
3199         ino_t ino = inode->i_ino;
3200 -       uid_t uid = inode->i_uid;
3201 -       gid_t gid = inode->i_gid;
3202 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3203 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3204         struct buffer_head * bh;
3205         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
3206         int n;
3207 @@ -1377,6 +1410,9 @@ int ext2_write_inode(struct inode *inode
3208                 raw_inode->i_uid_high = 0;
3209                 raw_inode->i_gid_high = 0;
3210         }
3211 +#ifdef CONFIG_TAGGING_INTERN
3212 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3213 +#endif
3214         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3215         raw_inode->i_size = cpu_to_le32(inode->i_size);
3216         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3217 @@ -1458,7 +1494,8 @@ int ext2_setattr(struct dentry *dentry, 
3218         if (error)
3219                 return error;
3220         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3221 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3222 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3223 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3224                 error = vfs_dq_transfer(inode, iattr) ? -EDQUOT : 0;
3225                 if (error)
3226                         return error;
3227 diff -NurpP --minimal linux-2.6.33/fs/ext2/ioctl.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/ioctl.c
3228 --- linux-2.6.33/fs/ext2/ioctl.c        2009-09-10 15:26:21.000000000 +0200
3229 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/ioctl.c        2010-02-25 12:02:16.000000000 +0100
3230 @@ -17,6 +17,16 @@
3231  #include <asm/uaccess.h>
3232  
3233  
3234 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
3235 +{
3236 +       inode->i_flags = flags;
3237 +       inode->i_vflags = vflags;
3238 +       ext2_get_inode_flags(EXT2_I(inode));
3239 +       inode->i_ctime = CURRENT_TIME_SEC;
3240 +       mark_inode_dirty(inode);
3241 +       return 0;
3242 +}
3243 +
3244  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3245  {
3246         struct inode *inode = filp->f_dentry->d_inode;
3247 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
3248  
3249                 flags = ext2_mask_flags(inode->i_mode, flags);
3250  
3251 +               if (IS_BARRIER(inode)) {
3252 +                       vxwprintk_task(1, "messing with the barrier.");
3253 +                       return -EACCES;
3254 +               }
3255 +
3256                 mutex_lock(&inode->i_mutex);
3257                 /* Is it quota file? Do not allow user to mess with it */
3258                 if (IS_NOQUOTA(inode)) {
3259 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
3260                  *
3261                  * This test looks nicer. Thanks to Pauline Middelink
3262                  */
3263 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
3264 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
3265 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
3266 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
3267                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3268                                 mutex_unlock(&inode->i_mutex);
3269                                 ret = -EPERM;
3270 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
3271                         }
3272                 }
3273  
3274 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
3275 +               flags &= EXT2_FL_USER_MODIFIABLE;
3276                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
3277                 ei->i_flags = flags;
3278                 mutex_unlock(&inode->i_mutex);
3279 diff -NurpP --minimal linux-2.6.33/fs/ext2/namei.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/namei.c
3280 --- linux-2.6.33/fs/ext2/namei.c        2009-12-03 20:02:51.000000000 +0100
3281 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/namei.c        2010-02-25 12:02:16.000000000 +0100
3282 @@ -31,6 +31,7 @@
3283   */
3284  
3285  #include <linux/pagemap.h>
3286 +#include <linux/vs_tag.h>
3287  #include "ext2.h"
3288  #include "xattr.h"
3289  #include "acl.h"
3290 @@ -74,6 +75,7 @@ static struct dentry *ext2_lookup(struct
3291                                 return ERR_PTR(-EIO);
3292                         } else {
3293                                 return ERR_CAST(inode);
3294 +               dx_propagate_tag(nd, inode);
3295                         }
3296                 }
3297         }
3298 @@ -401,6 +403,7 @@ const struct inode_operations ext2_dir_i
3299  #endif
3300         .setattr        = ext2_setattr,
3301         .check_acl      = ext2_check_acl,
3302 +       .sync_flags     = ext2_sync_flags,
3303  };
3304  
3305  const struct inode_operations ext2_special_inode_operations = {
3306 diff -NurpP --minimal linux-2.6.33/fs/ext2/super.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/super.c
3307 --- linux-2.6.33/fs/ext2/super.c        2010-02-25 11:52:05.000000000 +0100
3308 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext2/super.c        2010-02-25 12:02:16.000000000 +0100
3309 @@ -382,7 +382,8 @@ enum {
3310         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3311         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3312         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3313 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3314 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3315 +       Opt_tag, Opt_notag, Opt_tagid
3316  };
3317  
3318  static const match_table_t tokens = {
3319 @@ -410,6 +411,9 @@ static const match_table_t tokens = {
3320         {Opt_acl, "acl"},
3321         {Opt_noacl, "noacl"},
3322         {Opt_xip, "xip"},
3323 +       {Opt_tag, "tag"},
3324 +       {Opt_notag, "notag"},
3325 +       {Opt_tagid, "tagid=%u"},
3326         {Opt_grpquota, "grpquota"},
3327         {Opt_ignore, "noquota"},
3328         {Opt_quota, "quota"},
3329 @@ -480,6 +484,20 @@ static int parse_options(char *options, 
3330                 case Opt_nouid32:
3331                         set_opt (sbi->s_mount_opt, NO_UID32);
3332                         break;
3333 +#ifndef CONFIG_TAGGING_NONE
3334 +               case Opt_tag:
3335 +                       set_opt (sbi->s_mount_opt, TAGGED);
3336 +                       break;
3337 +               case Opt_notag:
3338 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3339 +                       break;
3340 +#endif
3341 +#ifdef CONFIG_PROPAGATE
3342 +               case Opt_tagid:
3343 +                       /* use args[0] */
3344 +                       set_opt (sbi->s_mount_opt, TAGGED);
3345 +                       break;
3346 +#endif
3347                 case Opt_nocheck:
3348                         clear_opt (sbi->s_mount_opt, CHECK);
3349                         break;
3350 @@ -836,6 +854,8 @@ static int ext2_fill_super(struct super_
3351         if (!parse_options((char *) data, sb))
3352                 goto failed_mount;
3353  
3354 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3355 +               sb->s_flags |= MS_TAGGED;
3356         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3357                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3358                  MS_POSIXACL : 0);
3359 @@ -1229,6 +1249,14 @@ static int ext2_remount (struct super_bl
3360                 goto restore_opts;
3361         }
3362  
3363 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3364 +               !(sb->s_flags & MS_TAGGED)) {
3365 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3366 +                      sb->s_id);
3367 +               err = -EINVAL;
3368 +               goto restore_opts;
3369 +       }
3370 +
3371         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3372                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3373  
3374 diff -NurpP --minimal linux-2.6.33/fs/ext3/file.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/file.c
3375 --- linux-2.6.33/fs/ext3/file.c 2009-12-03 20:02:51.000000000 +0100
3376 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/file.c 2010-02-25 12:02:16.000000000 +0100
3377 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
3378  #endif
3379         .check_acl      = ext3_check_acl,
3380         .fiemap         = ext3_fiemap,
3381 +       .sync_flags     = ext3_sync_flags,
3382  };
3383  
3384 diff -NurpP --minimal linux-2.6.33/fs/ext3/ialloc.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/ialloc.c
3385 --- linux-2.6.33/fs/ext3/ialloc.c       2009-09-10 15:26:21.000000000 +0200
3386 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/ialloc.c       2010-02-25 12:02:16.000000000 +0100
3387 @@ -23,6 +23,7 @@
3388  #include <linux/buffer_head.h>
3389  #include <linux/random.h>
3390  #include <linux/bitops.h>
3391 +#include <linux/vs_tag.h>
3392  
3393  #include <asm/byteorder.h>
3394  
3395 @@ -548,6 +549,7 @@ got:
3396         } else
3397                 inode->i_gid = current_fsgid();
3398         inode->i_mode = mode;
3399 +       inode->i_tag = dx_current_fstag(sb);
3400  
3401         inode->i_ino = ino;
3402         /* This is the optimal IO size (for stat), not the fs block size */
3403 diff -NurpP --minimal linux-2.6.33/fs/ext3/inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/inode.c
3404 --- linux-2.6.33/fs/ext3/inode.c        2010-02-25 11:52:05.000000000 +0100
3405 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/inode.c        2010-02-25 12:02:16.000000000 +0100
3406 @@ -38,6 +38,7 @@
3407  #include <linux/bio.h>
3408  #include <linux/fiemap.h>
3409  #include <linux/namei.h>
3410 +#include <linux/vs_tag.h>
3411  #include "xattr.h"
3412  #include "acl.h"
3413  
3414 @@ -2343,7 +2344,7 @@ static void ext3_free_branches(handle_t 
3415  
3416  int ext3_can_truncate(struct inode *inode)
3417  {
3418 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3419 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3420                 return 0;
3421         if (S_ISREG(inode->i_mode))
3422                 return 1;
3423 @@ -2728,36 +2729,60 @@ void ext3_set_inode_flags(struct inode *
3424  {
3425         unsigned int flags = EXT3_I(inode)->i_flags;
3426  
3427 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3428 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3429 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3430 +
3431 +       if (flags & EXT3_IMMUTABLE_FL)
3432 +               inode->i_flags |= S_IMMUTABLE;
3433 +       if (flags & EXT3_IXUNLINK_FL)
3434 +               inode->i_flags |= S_IXUNLINK;
3435 +
3436         if (flags & EXT3_SYNC_FL)
3437                 inode->i_flags |= S_SYNC;
3438         if (flags & EXT3_APPEND_FL)
3439                 inode->i_flags |= S_APPEND;
3440 -       if (flags & EXT3_IMMUTABLE_FL)
3441 -               inode->i_flags |= S_IMMUTABLE;
3442         if (flags & EXT3_NOATIME_FL)
3443                 inode->i_flags |= S_NOATIME;
3444         if (flags & EXT3_DIRSYNC_FL)
3445                 inode->i_flags |= S_DIRSYNC;
3446 +
3447 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3448 +
3449 +       if (flags & EXT3_BARRIER_FL)
3450 +               inode->i_vflags |= V_BARRIER;
3451 +       if (flags & EXT3_COW_FL)
3452 +               inode->i_vflags |= V_COW;
3453  }
3454  
3455  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3456  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3457  {
3458         unsigned int flags = ei->vfs_inode.i_flags;
3459 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3460 +
3461 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3462 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3463 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3464 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3465 +
3466 +       if (flags & S_IMMUTABLE)
3467 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3468 +       if (flags & S_IXUNLINK)
3469 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3470  
3471 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3472 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3473         if (flags & S_SYNC)
3474                 ei->i_flags |= EXT3_SYNC_FL;
3475         if (flags & S_APPEND)
3476                 ei->i_flags |= EXT3_APPEND_FL;
3477 -       if (flags & S_IMMUTABLE)
3478 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3479         if (flags & S_NOATIME)
3480                 ei->i_flags |= EXT3_NOATIME_FL;
3481         if (flags & S_DIRSYNC)
3482                 ei->i_flags |= EXT3_DIRSYNC_FL;
3483 +
3484 +       if (vflags & V_BARRIER)
3485 +               ei->i_flags |= EXT3_BARRIER_FL;
3486 +       if (vflags & V_COW)
3487 +               ei->i_flags |= EXT3_COW_FL;
3488  }
3489  
3490  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3491 @@ -2771,6 +2796,8 @@ struct inode *ext3_iget(struct super_blo
3492         transaction_t *transaction;
3493         long ret;
3494         int block;
3495 +       uid_t uid;
3496 +       gid_t gid;
3497  
3498         inode = iget_locked(sb, ino);
3499         if (!inode)
3500 @@ -2787,12 +2814,17 @@ struct inode *ext3_iget(struct super_blo
3501         bh = iloc.bh;
3502         raw_inode = ext3_raw_inode(&iloc);
3503         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3504 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3505 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3506 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3507 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3508         if(!(test_opt (inode->i_sb, NO_UID32))) {
3509 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3510 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3511 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3512 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3513         }
3514 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3515 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3516 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3517 +               le16_to_cpu(raw_inode->i_raw_tag));
3518 +
3519         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3520         inode->i_size = le32_to_cpu(raw_inode->i_size);
3521         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3522 @@ -2947,6 +2979,8 @@ static int ext3_do_update_inode(handle_t
3523         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3524         struct ext3_inode_info *ei = EXT3_I(inode);
3525         struct buffer_head *bh = iloc->bh;
3526 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3527 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3528         int err = 0, rc, block;
3529  
3530  again:
3531 @@ -2961,29 +2995,32 @@ again:
3532         ext3_get_inode_flags(ei);
3533         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3534         if(!(test_opt(inode->i_sb, NO_UID32))) {
3535 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3536 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3537 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3538 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3539  /*
3540   * Fix up interoperability with old kernels. Otherwise, old inodes get
3541   * re-used with the upper 16 bits of the uid/gid intact
3542   */
3543                 if(!ei->i_dtime) {
3544                         raw_inode->i_uid_high =
3545 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3546 +                               cpu_to_le16(high_16_bits(uid));
3547                         raw_inode->i_gid_high =
3548 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3549 +                               cpu_to_le16(high_16_bits(gid));
3550                 } else {
3551                         raw_inode->i_uid_high = 0;
3552                         raw_inode->i_gid_high = 0;
3553                 }
3554         } else {
3555                 raw_inode->i_uid_low =
3556 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3557 +                       cpu_to_le16(fs_high2lowuid(uid));
3558                 raw_inode->i_gid_low =
3559 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3560 +                       cpu_to_le16(fs_high2lowgid(gid));
3561                 raw_inode->i_uid_high = 0;
3562                 raw_inode->i_gid_high = 0;
3563         }
3564 +#ifdef CONFIG_TAGGING_INTERN
3565 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3566 +#endif
3567         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3568         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3569         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3570 @@ -3141,7 +3178,8 @@ int ext3_setattr(struct dentry *dentry, 
3571                 return error;
3572  
3573         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3574 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3575 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3576 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3577                 handle_t *handle;
3578  
3579                 /* (user+group)*(old+new) structure, inode write (sb,
3580 @@ -3163,6 +3201,8 @@ int ext3_setattr(struct dentry *dentry, 
3581                         inode->i_uid = attr->ia_uid;
3582                 if (attr->ia_valid & ATTR_GID)
3583                         inode->i_gid = attr->ia_gid;
3584 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3585 +                       inode->i_tag = attr->ia_tag;
3586                 error = ext3_mark_inode_dirty(handle, inode);
3587                 ext3_journal_stop(handle);
3588         }
3589 diff -NurpP --minimal linux-2.6.33/fs/ext3/ioctl.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/ioctl.c
3590 --- linux-2.6.33/fs/ext3/ioctl.c        2009-06-11 17:13:03.000000000 +0200
3591 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/ioctl.c        2010-02-25 12:02:16.000000000 +0100
3592 @@ -8,6 +8,7 @@
3593   */
3594  
3595  #include <linux/fs.h>
3596 +#include <linux/mount.h>
3597  #include <linux/jbd.h>
3598  #include <linux/capability.h>
3599  #include <linux/ext3_fs.h>
3600 @@ -17,6 +18,34 @@
3601  #include <linux/compat.h>
3602  #include <asm/uaccess.h>
3603  
3604 +
3605 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3606 +{
3607 +       handle_t *handle = NULL;
3608 +       struct ext3_iloc iloc;
3609 +       int err;
3610 +
3611 +       handle = ext3_journal_start(inode, 1);
3612 +       if (IS_ERR(handle))
3613 +               return PTR_ERR(handle);
3614 +
3615 +       if (IS_SYNC(inode))
3616 +               handle->h_sync = 1;
3617 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3618 +       if (err)
3619 +               goto flags_err;
3620 +
3621 +       inode->i_flags = flags;
3622 +       inode->i_vflags = vflags;
3623 +       ext3_get_inode_flags(EXT3_I(inode));
3624 +       inode->i_ctime = CURRENT_TIME_SEC;
3625 +
3626 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3627 +flags_err:
3628 +       ext3_journal_stop(handle);
3629 +       return err;
3630 +}
3631 +
3632  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3633  {
3634         struct inode *inode = filp->f_dentry->d_inode;
3635 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3636  
3637                 flags = ext3_mask_flags(inode->i_mode, flags);
3638  
3639 +               if (IS_BARRIER(inode)) {
3640 +                       vxwprintk_task(1, "messing with the barrier.");
3641 +                       return -EACCES;
3642 +               }
3643 +
3644                 mutex_lock(&inode->i_mutex);
3645  
3646                 /* Is it quota file? Do not allow user to mess with it */
3647 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3648                  *
3649                  * This test looks nicer. Thanks to Pauline Middelink
3650                  */
3651 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3652 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3653 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3654 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3655                         if (!capable(CAP_LINUX_IMMUTABLE))
3656                                 goto flags_out;
3657                 }
3658 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3659                 if (err)
3660                         goto flags_err;
3661  
3662 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3663 +               flags &= EXT3_FL_USER_MODIFIABLE;
3664                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3665                 ei->i_flags = flags;
3666  
3667 diff -NurpP --minimal linux-2.6.33/fs/ext3/namei.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/namei.c
3668 --- linux-2.6.33/fs/ext3/namei.c        2010-02-25 11:52:05.000000000 +0100
3669 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/namei.c        2010-02-25 12:02:16.000000000 +0100
3670 @@ -36,6 +36,7 @@
3671  #include <linux/quotaops.h>
3672  #include <linux/buffer_head.h>
3673  #include <linux/bio.h>
3674 +#include <linux/vs_tag.h>
3675  
3676  #include "namei.h"
3677  #include "xattr.h"
3678 @@ -912,6 +913,7 @@ restart:
3679                                 if (bh)
3680                                         ll_rw_block(READ_META, 1, &bh);
3681                         }
3682 +               dx_propagate_tag(nd, inode);
3683                 }
3684                 if ((bh = bh_use[ra_ptr++]) == NULL)
3685                         goto next;
3686 @@ -2448,6 +2450,7 @@ const struct inode_operations ext3_dir_i
3687         .removexattr    = generic_removexattr,
3688  #endif
3689         .check_acl      = ext3_check_acl,
3690 +       .sync_flags     = ext3_sync_flags,
3691  };
3692  
3693  const struct inode_operations ext3_special_inode_operations = {
3694 diff -NurpP --minimal linux-2.6.33/fs/ext3/super.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/super.c
3695 --- linux-2.6.33/fs/ext3/super.c        2010-02-25 11:52:05.000000000 +0100
3696 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext3/super.c        2010-02-25 13:29:21.000000000 +0100
3697 @@ -817,7 +817,7 @@ enum {
3698         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3699         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3700         Opt_noquota, Opt_ignore, Opt_barrier, Opt_err, Opt_resize,
3701 -       Opt_usrquota, Opt_grpquota
3702 +       Opt_usrquota, Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3703  };
3704  
3705  static const match_table_t tokens = {
3706 @@ -872,6 +872,9 @@ static const match_table_t tokens = {
3707         {Opt_usrquota, "usrquota"},
3708         {Opt_barrier, "barrier=%u"},
3709         {Opt_resize, "resize"},
3710 +       {Opt_tag, "tag"},
3711 +       {Opt_notag, "notag"},
3712 +       {Opt_tagid, "tagid=%u"},
3713         {Opt_err, NULL},
3714  };
3715  
3716 @@ -964,6 +967,20 @@ static int parse_options (char *options,
3717                 case Opt_nouid32:
3718                         set_opt (sbi->s_mount_opt, NO_UID32);
3719                         break;
3720 +#ifndef CONFIG_TAGGING_NONE
3721 +               case Opt_tag:
3722 +                       set_opt (sbi->s_mount_opt, TAGGED);
3723 +                       break;
3724 +               case Opt_notag:
3725 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3726 +                       break;
3727 +#endif
3728 +#ifdef CONFIG_PROPAGATE
3729 +               case Opt_tagid:
3730 +                       /* use args[0] */
3731 +                       set_opt (sbi->s_mount_opt, TAGGED);
3732 +                       break;
3733 +#endif
3734                 case Opt_nocheck:
3735                         clear_opt (sbi->s_mount_opt, CHECK);
3736                         break;
3737 @@ -1693,6 +1710,9 @@ static int ext3_fill_super (struct super
3738                             NULL, 0))
3739                 goto failed_mount;
3740  
3741 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3742 +               sb->s_flags |= MS_TAGGED;
3743 +
3744         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3745                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3746  
3747 @@ -2564,6 +2584,14 @@ static int ext3_remount (struct super_bl
3748         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3749                 ext3_abort(sb, __func__, "Abort forced by user");
3750  
3751 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3752 +               !(sb->s_flags & MS_TAGGED)) {
3753 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3754 +                       sb->s_id);
3755 +               err = -EINVAL;
3756 +               goto restore_opts;
3757 +       }
3758 +
3759         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3760                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3761  
3762 diff -NurpP --minimal linux-2.6.33/fs/ext4/ext4.h linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/ext4.h
3763 --- linux-2.6.33/fs/ext4/ext4.h 2010-02-25 11:52:05.000000000 +0100
3764 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/ext4.h 2010-02-25 12:02:16.000000000 +0100
3765 @@ -284,8 +284,12 @@ struct flex_groups {
3766  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
3767  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
3768  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3769 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3770  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3771  
3772 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3773 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3774 +
3775  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3776  #define EXT4_FL_USER_MODIFIABLE                0x000B80FF /* User modifiable flags */
3777  
3778 @@ -472,7 +476,8 @@ struct ext4_inode {
3779                         __le16  l_i_file_acl_high;
3780                         __le16  l_i_uid_high;   /* these 2 fields */
3781                         __le16  l_i_gid_high;   /* were reserved2[0] */
3782 -                       __u32   l_i_reserved2;
3783 +                       __le16  l_i_tag;        /* Context Tag */
3784 +                       __u16   l_i_reserved2;
3785                 } linux2;
3786                 struct {
3787                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3788 @@ -586,6 +591,7 @@ do {                                                                               \
3789  #define i_gid_low      i_gid
3790  #define i_uid_high     osd2.linux2.l_i_uid_high
3791  #define i_gid_high     osd2.linux2.l_i_gid_high
3792 +#define i_raw_tag      osd2.linux2.l_i_tag
3793  #define i_reserved2    osd2.linux2.l_i_reserved2
3794  
3795  #elif defined(__GNU__)
3796 @@ -760,6 +766,7 @@ struct ext4_inode_info {
3797  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3798  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3799  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3800 +#define EXT4_MOUNT_TAGGED              0x400000 /* Enable Context Tags */
3801  #define EXT4_MOUNT_JOURNAL_CHECKSUM    0x800000 /* Journal checksums */
3802  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
3803  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3804 @@ -1750,6 +1757,7 @@ extern int ext4_get_blocks(handle_t *han
3805                            struct buffer_head *bh, int flags);
3806  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3807                         __u64 start, __u64 len);
3808 +extern int ext4_sync_flags(struct inode *, int, int);
3809  /* move_extent.c */
3810  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3811                              __u64 start_orig, __u64 start_donor,
3812 diff -NurpP --minimal linux-2.6.33/fs/ext4/file.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/file.c
3813 --- linux-2.6.33/fs/ext4/file.c 2009-12-03 20:02:51.000000000 +0100
3814 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/file.c 2010-02-25 12:02:16.000000000 +0100
3815 @@ -161,5 +161,6 @@ const struct inode_operations ext4_file_
3816         .check_acl      = ext4_check_acl,
3817         .fallocate      = ext4_fallocate,
3818         .fiemap         = ext4_fiemap,
3819 +       .sync_flags     = ext4_sync_flags,
3820  };
3821  
3822 diff -NurpP --minimal linux-2.6.33/fs/ext4/ialloc.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/ialloc.c
3823 --- linux-2.6.33/fs/ext4/ialloc.c       2009-12-03 20:02:51.000000000 +0100
3824 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/ialloc.c       2010-02-25 12:02:16.000000000 +0100
3825 @@ -22,6 +22,7 @@
3826  #include <linux/random.h>
3827  #include <linux/bitops.h>
3828  #include <linux/blkdev.h>
3829 +#include <linux/vs_tag.h>
3830  #include <asm/byteorder.h>
3831  
3832  #include "ext4.h"
3833 @@ -995,6 +996,7 @@ got:
3834         } else
3835                 inode->i_gid = current_fsgid();
3836         inode->i_mode = mode;
3837 +       inode->i_tag = dx_current_fstag(sb);
3838  
3839         inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb);
3840         /* This is the optimal IO size (for stat), not the fs block size */
3841 diff -NurpP --minimal linux-2.6.33/fs/ext4/inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/inode.c
3842 --- linux-2.6.33/fs/ext4/inode.c        2010-02-25 11:52:05.000000000 +0100
3843 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/inode.c        2010-02-25 12:02:16.000000000 +0100
3844 @@ -38,6 +38,7 @@
3845  #include <linux/uio.h>
3846  #include <linux/bio.h>
3847  #include <linux/workqueue.h>
3848 +#include <linux/vs_tag.h>
3849  
3850  #include "ext4_jbd2.h"
3851  #include "xattr.h"
3852 @@ -4376,7 +4377,7 @@ static void ext4_free_branches(handle_t 
3853  
3854  int ext4_can_truncate(struct inode *inode)
3855  {
3856 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3857 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3858                 return 0;
3859         if (S_ISREG(inode->i_mode))
3860                 return 1;
3861 @@ -4727,36 +4728,60 @@ void ext4_set_inode_flags(struct inode *
3862  {
3863         unsigned int flags = EXT4_I(inode)->i_flags;
3864  
3865 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3866 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3867 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3868 +
3869 +       if (flags & EXT4_IMMUTABLE_FL)
3870 +               inode->i_flags |= S_IMMUTABLE;
3871 +       if (flags & EXT4_IXUNLINK_FL)
3872 +               inode->i_flags |= S_IXUNLINK;
3873 +
3874         if (flags & EXT4_SYNC_FL)
3875                 inode->i_flags |= S_SYNC;
3876         if (flags & EXT4_APPEND_FL)
3877                 inode->i_flags |= S_APPEND;
3878 -       if (flags & EXT4_IMMUTABLE_FL)
3879 -               inode->i_flags |= S_IMMUTABLE;
3880         if (flags & EXT4_NOATIME_FL)
3881                 inode->i_flags |= S_NOATIME;
3882         if (flags & EXT4_DIRSYNC_FL)
3883                 inode->i_flags |= S_DIRSYNC;
3884 +
3885 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3886 +
3887 +       if (flags & EXT4_BARRIER_FL)
3888 +               inode->i_vflags |= V_BARRIER;
3889 +       if (flags & EXT4_COW_FL)
3890 +               inode->i_vflags |= V_COW;
3891  }
3892  
3893  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3894  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3895  {
3896         unsigned int flags = ei->vfs_inode.i_flags;
3897 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3898 +
3899 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3900 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3901 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3902 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3903 +
3904 +       if (flags & S_IMMUTABLE)
3905 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3906 +       if (flags & S_IXUNLINK)
3907 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3908  
3909 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3910 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3911         if (flags & S_SYNC)
3912                 ei->i_flags |= EXT4_SYNC_FL;
3913         if (flags & S_APPEND)
3914                 ei->i_flags |= EXT4_APPEND_FL;
3915 -       if (flags & S_IMMUTABLE)
3916 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3917         if (flags & S_NOATIME)
3918                 ei->i_flags |= EXT4_NOATIME_FL;
3919         if (flags & S_DIRSYNC)
3920                 ei->i_flags |= EXT4_DIRSYNC_FL;
3921 +
3922 +       if (vflags & V_BARRIER)
3923 +               ei->i_flags |= EXT4_BARRIER_FL;
3924 +       if (vflags & V_COW)
3925 +               ei->i_flags |= EXT4_COW_FL;
3926  }
3927  
3928  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3929 @@ -4791,6 +4816,8 @@ struct inode *ext4_iget(struct super_blo
3930         journal_t *journal = EXT4_SB(sb)->s_journal;
3931         long ret;
3932         int block;
3933 +       uid_t uid;
3934 +       gid_t gid;
3935  
3936         inode = iget_locked(sb, ino);
3937         if (!inode)
3938 @@ -4806,12 +4833,16 @@ struct inode *ext4_iget(struct super_blo
3939                 goto bad_inode;
3940         raw_inode = ext4_raw_inode(&iloc);
3941         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3942 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3943 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3944 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3945 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3946         if (!(test_opt(inode->i_sb, NO_UID32))) {
3947 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3948 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3949 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3950 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3951         }
3952 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3953 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3954 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3955 +               le16_to_cpu(raw_inode->i_raw_tag));
3956         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3957  
3958         ei->i_state = 0;
3959 @@ -5033,6 +5064,8 @@ static int ext4_do_update_inode(handle_t
3960         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3961         struct ext4_inode_info *ei = EXT4_I(inode);
3962         struct buffer_head *bh = iloc->bh;
3963 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3964 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3965         int err = 0, rc, block;
3966  
3967         /* For fields not not tracking in the in-memory inode,
3968 @@ -5043,29 +5076,32 @@ static int ext4_do_update_inode(handle_t
3969         ext4_get_inode_flags(ei);
3970         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3971         if (!(test_opt(inode->i_sb, NO_UID32))) {
3972 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3973 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3974 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3975 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3976  /*
3977   * Fix up interoperability with old kernels. Otherwise, old inodes get
3978   * re-used with the upper 16 bits of the uid/gid intact
3979   */
3980                 if (!ei->i_dtime) {
3981                         raw_inode->i_uid_high =
3982 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3983 +                               cpu_to_le16(high_16_bits(uid));
3984                         raw_inode->i_gid_high =
3985 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3986 +                               cpu_to_le16(high_16_bits(gid));
3987                 } else {
3988                         raw_inode->i_uid_high = 0;
3989                         raw_inode->i_gid_high = 0;
3990                 }
3991         } else {
3992                 raw_inode->i_uid_low =
3993 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3994 +                       cpu_to_le16(fs_high2lowuid(uid));
3995                 raw_inode->i_gid_low =
3996 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3997 +                       cpu_to_le16(fs_high2lowgid(gid));
3998                 raw_inode->i_uid_high = 0;
3999                 raw_inode->i_gid_high = 0;
4000         }
4001 +#ifdef CONFIG_TAGGING_INTERN
4002 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4003 +#endif
4004         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4005  
4006         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
4007 @@ -5250,7 +5286,8 @@ int ext4_setattr(struct dentry *dentry, 
4008                 return error;
4009  
4010         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4011 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4012 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4013 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4014                 handle_t *handle;
4015  
4016                 /* (user+group)*(old+new) structure, inode write (sb,
4017 @@ -5272,6 +5309,8 @@ int ext4_setattr(struct dentry *dentry, 
4018                         inode->i_uid = attr->ia_uid;
4019                 if (attr->ia_valid & ATTR_GID)
4020                         inode->i_gid = attr->ia_gid;
4021 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4022 +                       inode->i_tag = attr->ia_tag;
4023                 error = ext4_mark_inode_dirty(handle, inode);
4024                 ext4_journal_stop(handle);
4025         }
4026 diff -NurpP --minimal linux-2.6.33/fs/ext4/ioctl.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/ioctl.c
4027 --- linux-2.6.33/fs/ext4/ioctl.c        2010-02-25 11:52:05.000000000 +0100
4028 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/ioctl.c        2010-02-25 12:02:16.000000000 +0100
4029 @@ -14,10 +14,39 @@
4030  #include <linux/compat.h>
4031  #include <linux/mount.h>
4032  #include <linux/file.h>
4033 +#include <linux/vs_tag.h>
4034  #include <asm/uaccess.h>
4035  #include "ext4_jbd2.h"
4036  #include "ext4.h"
4037  
4038 +
4039 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
4040 +{
4041 +       handle_t *handle = NULL;
4042 +       struct ext4_iloc iloc;
4043 +       int err;
4044 +
4045 +       handle = ext4_journal_start(inode, 1);
4046 +       if (IS_ERR(handle))
4047 +               return PTR_ERR(handle);
4048 +
4049 +       if (IS_SYNC(inode))
4050 +               ext4_handle_sync(handle);
4051 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
4052 +       if (err)
4053 +               goto flags_err;
4054 +
4055 +       inode->i_flags = flags;
4056 +       inode->i_vflags = vflags;
4057 +       ext4_get_inode_flags(EXT4_I(inode));
4058 +       inode->i_ctime = ext4_current_time(inode);
4059 +
4060 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
4061 +flags_err:
4062 +       ext4_journal_stop(handle);
4063 +       return err;
4064 +}
4065 +
4066  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4067  {
4068         struct inode *inode = filp->f_dentry->d_inode;
4069 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
4070  
4071                 flags = ext4_mask_flags(inode->i_mode, flags);
4072  
4073 +               if (IS_BARRIER(inode)) {
4074 +                       vxwprintk_task(1, "messing with the barrier.");
4075 +                       return -EACCES;
4076 +               }
4077 +
4078                 err = -EPERM;
4079                 mutex_lock(&inode->i_mutex);
4080                 /* Is it quota file? Do not allow user to mess with it */
4081 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
4082                  *
4083                  * This test looks nicer. Thanks to Pauline Middelink
4084                  */
4085 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
4086 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
4087 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
4088 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
4089                         if (!capable(CAP_LINUX_IMMUTABLE))
4090                                 goto flags_out;
4091                 }
4092 diff -NurpP --minimal linux-2.6.33/fs/ext4/namei.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/namei.c
4093 --- linux-2.6.33/fs/ext4/namei.c        2010-02-25 11:52:05.000000000 +0100
4094 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/namei.c        2010-02-25 12:02:16.000000000 +0100
4095 @@ -34,6 +34,7 @@
4096  #include <linux/quotaops.h>
4097  #include <linux/buffer_head.h>
4098  #include <linux/bio.h>
4099 +#include <linux/vs_tag.h>
4100  #include "ext4.h"
4101  #include "ext4_jbd2.h"
4102  
4103 @@ -941,6 +942,7 @@ restart:
4104                                 if (bh)
4105                                         ll_rw_block(READ_META, 1, &bh);
4106                         }
4107 +               dx_propagate_tag(nd, inode);
4108                 }
4109                 if ((bh = bh_use[ra_ptr++]) == NULL)
4110                         goto next;
4111 @@ -2533,6 +2535,7 @@ const struct inode_operations ext4_dir_i
4112  #endif
4113         .check_acl      = ext4_check_acl,
4114         .fiemap         = ext4_fiemap,
4115 +       .sync_flags     = ext4_sync_flags,
4116  };
4117  
4118  const struct inode_operations ext4_special_inode_operations = {
4119 diff -NurpP --minimal linux-2.6.33/fs/ext4/super.c linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/super.c
4120 --- linux-2.6.33/fs/ext4/super.c        2010-02-25 11:52:05.000000000 +0100
4121 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ext4/super.c        2010-02-25 12:02:16.000000000 +0100
4122 @@ -1110,6 +1110,7 @@ enum {
4123         Opt_block_validity, Opt_noblock_validity,
4124         Opt_inode_readahead_blks, Opt_journal_ioprio,
4125         Opt_discard, Opt_nodiscard,
4126 +       Opt_tag, Opt_notag, Opt_tagid
4127  };
4128  
4129  static const match_table_t tokens = {
4130 @@ -1178,6 +1179,9 @@ static const match_table_t tokens = {
4131         {Opt_noauto_da_alloc, "noauto_da_alloc"},
4132         {Opt_discard, "discard"},
4133         {Opt_nodiscard, "nodiscard"},
4134 +       {Opt_tag, "tag"},
4135 +       {Opt_notag, "notag"},
4136 +       {Opt_tagid, "tagid=%u"},
4137         {Opt_err, NULL},
4138  };
4139  
4140 @@ -1275,6 +1279,20 @@ static int parse_options(char *options, 
4141                 case Opt_nouid32:
4142                         set_opt(sbi->s_mount_opt, NO_UID32);
4143                         break;
4144 +#ifndef CONFIG_TAGGING_NONE
4145 +               case Opt_tag:
4146 +                       set_opt (sbi->s_mount_opt, TAGGED);
4147 +                       break;
4148 +               case Opt_notag:
4149 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4150 +                       break;
4151 +#endif
4152 +#ifdef CONFIG_PROPAGATE
4153 +               case Opt_tagid:
4154 +                       /* use args[0] */
4155 +                       set_opt (sbi->s_mount_opt, TAGGED);
4156 +                       break;
4157 +#endif
4158                 case Opt_debug:
4159                         set_opt(sbi->s_mount_opt, DEBUG);
4160                         break;
4161 @@ -2476,6 +2494,9 @@ static int ext4_fill_super(struct super_
4162                            &journal_ioprio, NULL, 0))
4163                 goto failed_mount;
4164  
4165 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
4166 +               sb->s_flags |= MS_TAGGED;
4167 +
4168         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4169                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4170  
4171 @@ -3513,6 +3534,14 @@ static int ext4_remount(struct super_blo
4172         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
4173                 ext4_abort(sb, __func__, "Abort forced by user");
4174  
4175 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
4176 +               !(sb->s_flags & MS_TAGGED)) {
4177 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
4178 +                       sb->s_id);
4179 +               err = -EINVAL;
4180 +               goto restore_opts;
4181 +       }
4182 +
4183         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4184                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4185  
4186 diff -NurpP --minimal linux-2.6.33/fs/fcntl.c linux-2.6.33-vs2.3.0.36.30.1/fs/fcntl.c
4187 --- linux-2.6.33/fs/fcntl.c     2010-02-25 11:52:05.000000000 +0100
4188 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/fcntl.c     2010-02-25 12:02:16.000000000 +0100
4189 @@ -19,6 +19,7 @@
4190  #include <linux/signal.h>
4191  #include <linux/rcupdate.h>
4192  #include <linux/pid_namespace.h>
4193 +#include <linux/vs_limit.h>
4194  
4195  #include <asm/poll.h>
4196  #include <asm/siginfo.h>
4197 @@ -102,6 +103,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
4198  
4199         if (tofree)
4200                 filp_close(tofree, files);
4201 +       else
4202 +               vx_openfd_inc(newfd);   /* fd was unused */
4203  
4204         return newfd;
4205  
4206 @@ -426,6 +429,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
4207         filp = fget(fd);
4208         if (!filp)
4209                 goto out;
4210 +       if (!vx_files_avail(1))
4211 +               goto out;
4212  
4213         err = security_file_fcntl(filp, cmd, arg);
4214         if (err) {
4215 diff -NurpP --minimal linux-2.6.33/fs/file.c linux-2.6.33-vs2.3.0.36.30.1/fs/file.c
4216 --- linux-2.6.33/fs/file.c      2009-12-03 20:02:51.000000000 +0100
4217 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/file.c      2010-02-25 12:02:16.000000000 +0100
4218 @@ -20,6 +20,7 @@
4219  #include <linux/spinlock.h>
4220  #include <linux/rcupdate.h>
4221  #include <linux/workqueue.h>
4222 +#include <linux/vs_limit.h>
4223  
4224  struct fdtable_defer {
4225         spinlock_t lock;
4226 @@ -368,6 +369,8 @@ struct files_struct *dup_fd(struct files
4227                 struct file *f = *old_fds++;
4228                 if (f) {
4229                         get_file(f);
4230 +                       /* TODO: sum it first for check and performance */
4231 +                       vx_openfd_inc(open_files - i);
4232                 } else {
4233                         /*
4234                          * The fd may be claimed in the fd bitmap but not yet
4235 @@ -476,6 +479,7 @@ repeat:
4236         else
4237                 FD_CLR(fd, fdt->close_on_exec);
4238         error = fd;
4239 +       vx_openfd_inc(fd);
4240  #if 1
4241         /* Sanity check */
4242         if (rcu_dereference(fdt->fd[fd]) != NULL) {
4243 diff -NurpP --minimal linux-2.6.33/fs/file_table.c linux-2.6.33-vs2.3.0.36.30.1/fs/file_table.c
4244 --- linux-2.6.33/fs/file_table.c        2010-02-25 11:52:05.000000000 +0100
4245 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/file_table.c        2010-02-25 13:28:39.000000000 +0100
4246 @@ -22,6 +22,8 @@
4247  #include <linux/sysctl.h>
4248  #include <linux/percpu_counter.h>
4249  #include <linux/ima.h>
4250 +#include <linux/vs_limit.h>
4251 +#include <linux/vs_context.h>
4252  
4253  #include <asm/atomic.h>
4254  
4255 @@ -133,6 +135,8 @@ struct file *get_empty_filp(void)
4256         spin_lock_init(&f->f_lock);
4257         eventpoll_init_file(f);
4258         /* f->f_version: 0 */
4259 +       f->f_xid = vx_current_xid();
4260 +       vx_files_inc(f);
4261         return f;
4262  
4263  over:
4264 @@ -258,6 +262,8 @@ void __fput(struct file *file)
4265                 cdev_put(inode->i_cdev);
4266         fops_put(file->f_op);
4267         put_pid(file->f_owner.pid);
4268 +       vx_files_dec(file);
4269 +       file->f_xid = 0;
4270         file_kill(file);
4271         if (file->f_mode & FMODE_WRITE)
4272                 drop_file_write_access(file);
4273 @@ -325,6 +331,8 @@ void put_filp(struct file *file)
4274  {
4275         if (atomic_long_dec_and_test(&file->f_count)) {
4276                 security_file_free(file);
4277 +               vx_files_dec(file);
4278 +               file->f_xid = 0;
4279                 file_kill(file);
4280                 file_free(file);
4281         }
4282 diff -NurpP --minimal linux-2.6.33/fs/fs_struct.c linux-2.6.33-vs2.3.0.36.30.1/fs/fs_struct.c
4283 --- linux-2.6.33/fs/fs_struct.c 2009-06-11 17:13:04.000000000 +0200
4284 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/fs_struct.c 2010-02-25 12:02:16.000000000 +0100
4285 @@ -4,6 +4,7 @@
4286  #include <linux/path.h>
4287  #include <linux/slab.h>
4288  #include <linux/fs_struct.h>
4289 +#include <linux/vserver/global.h>
4290  
4291  /*
4292   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
4293 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
4294  {
4295         path_put(&fs->root);
4296         path_put(&fs->pwd);
4297 +       atomic_dec(&vs_global_fs);
4298         kmem_cache_free(fs_cachep, fs);
4299  }
4300  
4301 @@ -112,6 +114,7 @@ struct fs_struct *copy_fs_struct(struct 
4302                 fs->pwd = old->pwd;
4303                 path_get(&old->pwd);
4304                 read_unlock(&old->lock);
4305 +               atomic_inc(&vs_global_fs);
4306         }
4307         return fs;
4308  }
4309 diff -NurpP --minimal linux-2.6.33/fs/gfs2/file.c linux-2.6.33-vs2.3.0.36.30.1/fs/gfs2/file.c
4310 --- linux-2.6.33/fs/gfs2/file.c 2010-02-25 11:52:05.000000000 +0100
4311 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/gfs2/file.c 2010-02-25 12:02:16.000000000 +0100
4312 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
4313         [7] = GFS2_DIF_NOATIME,
4314         [12] = GFS2_DIF_EXHASH,
4315         [14] = GFS2_DIF_INHERIT_JDATA,
4316 +       [27] = GFS2_DIF_IXUNLINK,
4317 +       [26] = GFS2_DIF_BARRIER,
4318 +       [29] = GFS2_DIF_COW,
4319  };
4320  
4321  static const u32 gfs2_to_fsflags[32] = {
4322 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
4323         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4324         [gfs2fl_ExHash] = FS_INDEX_FL,
4325         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4326 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4327 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4328 +       [gfs2fl_Cow] = FS_COW_FL,
4329  };
4330  
4331  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4332 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
4333  {
4334         struct gfs2_inode *ip = GFS2_I(inode);
4335         unsigned int flags = inode->i_flags;
4336 +       unsigned int vflags = inode->i_vflags;
4337 +
4338 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4339 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4340  
4341 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4342         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4343                 flags |= S_IMMUTABLE;
4344 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4345 +               flags |= S_IXUNLINK;
4346 +
4347         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4348                 flags |= S_APPEND;
4349         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4350 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
4351         if (ip->i_diskflags & GFS2_DIF_SYNC)
4352                 flags |= S_SYNC;
4353         inode->i_flags = flags;
4354 +
4355 +       vflags &= ~(V_BARRIER | V_COW);
4356 +
4357 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4358 +               vflags |= V_BARRIER;
4359 +       if (ip->i_diskflags & GFS2_DIF_COW)
4360 +               vflags |= V_COW;
4361 +       inode->i_vflags = vflags;
4362 +}
4363 +
4364 +void gfs2_get_inode_flags(struct inode *inode)
4365 +{
4366 +       struct gfs2_inode *ip = GFS2_I(inode);
4367 +       unsigned int flags = inode->i_flags;
4368 +       unsigned int vflags = inode->i_vflags;
4369 +
4370 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4371 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4372 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4373 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4374 +
4375 +       if (flags & S_IMMUTABLE)
4376 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4377 +       if (flags & S_IXUNLINK)
4378 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4379 +
4380 +       if (flags & S_APPEND)
4381 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4382 +       if (flags & S_NOATIME)
4383 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4384 +       if (flags & S_SYNC)
4385 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4386 +
4387 +       if (vflags & V_BARRIER)
4388 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4389 +       if (vflags & V_COW)
4390 +               ip->i_diskflags |= GFS2_DIF_COW;
4391  }
4392  
4393  /* Flags that can be set by user space */
4394 @@ -286,6 +335,37 @@ static int gfs2_set_flags(struct file *f
4395         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4396  }
4397  
4398 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4399 +{
4400 +       struct gfs2_inode *ip = GFS2_I(inode);
4401 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4402 +       struct buffer_head *bh;
4403 +       struct gfs2_holder gh;
4404 +       int error;
4405 +
4406 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4407 +       if (error)
4408 +               return error;
4409 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4410 +       if (error)
4411 +               goto out;
4412 +       error = gfs2_meta_inode_buffer(ip, &bh);
4413 +       if (error)
4414 +               goto out_trans_end;
4415 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4416 +       inode->i_flags = flags;
4417 +       inode->i_vflags = vflags;
4418 +       gfs2_get_inode_flags(inode);
4419 +       gfs2_dinode_out(ip, bh->b_data);
4420 +       brelse(bh);
4421 +       gfs2_set_aops(inode);
4422 +out_trans_end:
4423 +       gfs2_trans_end(sdp);
4424 +out:
4425 +       gfs2_glock_dq_uninit(&gh);
4426 +       return error;
4427 +}
4428 +
4429  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4430  {
4431         switch(cmd) {
4432 diff -NurpP --minimal linux-2.6.33/fs/gfs2/inode.h linux-2.6.33-vs2.3.0.36.30.1/fs/gfs2/inode.h
4433 --- linux-2.6.33/fs/gfs2/inode.h        2009-09-10 15:26:22.000000000 +0200
4434 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/gfs2/inode.h        2010-02-25 12:02:16.000000000 +0100
4435 @@ -109,6 +109,7 @@ extern const struct file_operations gfs2
4436  extern const struct file_operations gfs2_dir_fops_nolock;
4437  
4438  extern void gfs2_set_inode_flags(struct inode *inode);
4439 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4440   
4441  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4442  extern const struct file_operations gfs2_file_fops;
4443 diff -NurpP --minimal linux-2.6.33/fs/gfs2/ops_inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/gfs2/ops_inode.c
4444 --- linux-2.6.33/fs/gfs2/ops_inode.c    2010-02-25 11:52:05.000000000 +0100
4445 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/gfs2/ops_inode.c    2010-02-25 12:02:16.000000000 +0100
4446 @@ -1403,6 +1403,7 @@ const struct inode_operations gfs2_file_
4447         .listxattr = gfs2_listxattr,
4448         .removexattr = gfs2_removexattr,
4449         .fiemap = gfs2_fiemap,
4450 +       .sync_flags = gfs2_sync_flags,
4451  };
4452  
4453  const struct inode_operations gfs2_dir_iops = {
4454 @@ -1423,6 +1424,7 @@ const struct inode_operations gfs2_dir_i
4455         .listxattr = gfs2_listxattr,
4456         .removexattr = gfs2_removexattr,
4457         .fiemap = gfs2_fiemap,
4458 +       .sync_flags = gfs2_sync_flags,
4459  };
4460  
4461  const struct inode_operations gfs2_symlink_iops = {
4462 diff -NurpP --minimal linux-2.6.33/fs/hfsplus/ioctl.c linux-2.6.33-vs2.3.0.36.30.1/fs/hfsplus/ioctl.c
4463 --- linux-2.6.33/fs/hfsplus/ioctl.c     2008-12-25 00:26:37.000000000 +0100
4464 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/hfsplus/ioctl.c     2010-02-25 12:02:16.000000000 +0100
4465 @@ -17,6 +17,7 @@
4466  #include <linux/mount.h>
4467  #include <linux/sched.h>
4468  #include <linux/xattr.h>
4469 +#include <linux/mount.h>
4470  #include <asm/uaccess.h>
4471  #include "hfsplus_fs.h"
4472  
4473 diff -NurpP --minimal linux-2.6.33/fs/inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/inode.c
4474 --- linux-2.6.33/fs/inode.c     2010-02-25 11:52:05.000000000 +0100
4475 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/inode.c     2010-02-25 12:02:16.000000000 +0100
4476 @@ -132,6 +132,9 @@ int inode_init_always(struct super_block
4477         struct address_space *const mapping = &inode->i_data;
4478  
4479         inode->i_sb = sb;
4480 +
4481 +       /* essential because of inode slab reuse */
4482 +       inode->i_tag = 0;
4483         inode->i_blkbits = sb->s_blocksize_bits;
4484         inode->i_flags = 0;
4485         atomic_set(&inode->i_count, 1);
4486 @@ -152,6 +155,7 @@ int inode_init_always(struct super_block
4487         inode->i_bdev = NULL;
4488         inode->i_cdev = NULL;
4489         inode->i_rdev = 0;
4490 +       inode->i_mdev = 0;
4491         inode->dirtied_when = 0;
4492  
4493         if (security_inode_alloc(inode))
4494 @@ -297,6 +301,8 @@ void __iget(struct inode *inode)
4495         inodes_stat.nr_unused--;
4496  }
4497  
4498 +EXPORT_SYMBOL_GPL(__iget);
4499 +
4500  /**
4501   * clear_inode - clear an inode
4502   * @inode: inode to clear
4503 @@ -1601,9 +1607,11 @@ void init_special_inode(struct inode *in
4504         if (S_ISCHR(mode)) {
4505                 inode->i_fop = &def_chr_fops;
4506                 inode->i_rdev = rdev;
4507 +               inode->i_mdev = rdev;
4508         } else if (S_ISBLK(mode)) {
4509                 inode->i_fop = &def_blk_fops;
4510                 inode->i_rdev = rdev;
4511 +               inode->i_mdev = rdev;
4512         } else if (S_ISFIFO(mode))
4513                 inode->i_fop = &def_fifo_fops;
4514         else if (S_ISSOCK(mode))
4515 diff -NurpP --minimal linux-2.6.33/fs/ioctl.c linux-2.6.33-vs2.3.0.36.30.1/fs/ioctl.c
4516 --- linux-2.6.33/fs/ioctl.c     2009-12-03 20:02:52.000000000 +0100
4517 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ioctl.c     2010-02-25 12:02:16.000000000 +0100
4518 @@ -16,6 +16,9 @@
4519  #include <linux/writeback.h>
4520  #include <linux/buffer_head.h>
4521  #include <linux/falloc.h>
4522 +#include <linux/proc_fs.h>
4523 +#include <linux/vserver/inode.h>
4524 +#include <linux/vs_tag.h>
4525  
4526  #include <asm/ioctls.h>
4527  
4528 diff -NurpP --minimal linux-2.6.33/fs/ioprio.c linux-2.6.33-vs2.3.0.36.30.1/fs/ioprio.c
4529 --- linux-2.6.33/fs/ioprio.c    2009-03-24 14:22:26.000000000 +0100
4530 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ioprio.c    2010-02-25 12:02:16.000000000 +0100
4531 @@ -26,6 +26,7 @@
4532  #include <linux/syscalls.h>
4533  #include <linux/security.h>
4534  #include <linux/pid_namespace.h>
4535 +#include <linux/vs_base.h>
4536  
4537  int set_task_ioprio(struct task_struct *task, int ioprio)
4538  {
4539 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4540                         else
4541                                 pgrp = find_vpid(who);
4542                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4543 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4544 +                                       continue;
4545                                 ret = set_task_ioprio(p, ioprio);
4546                                 if (ret)
4547                                         break;
4548 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4549                         else
4550                                 pgrp = find_vpid(who);
4551                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4552 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4553 +                                       continue;
4554                                 tmpio = get_task_ioprio(p);
4555                                 if (tmpio < 0)
4556                                         continue;
4557 diff -NurpP --minimal linux-2.6.33/fs/jfs/acl.c linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/acl.c
4558 --- linux-2.6.33/fs/jfs/acl.c   2009-12-03 20:02:52.000000000 +0100
4559 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/acl.c   2010-02-25 12:02:16.000000000 +0100
4560 @@ -216,7 +216,8 @@ int jfs_setattr(struct dentry *dentry, s
4561                 return rc;
4562  
4563         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4564 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4565 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4566 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4567                 if (vfs_dq_transfer(inode, iattr))
4568                         return -EDQUOT;
4569         }
4570 diff -NurpP --minimal linux-2.6.33/fs/jfs/file.c linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/file.c
4571 --- linux-2.6.33/fs/jfs/file.c  2009-12-03 20:02:52.000000000 +0100
4572 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/file.c  2010-02-25 12:02:16.000000000 +0100
4573 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4574         .setattr        = jfs_setattr,
4575         .check_acl      = jfs_check_acl,
4576  #endif
4577 +       .sync_flags     = jfs_sync_flags,
4578  };
4579  
4580  const struct file_operations jfs_file_operations = {
4581 diff -NurpP --minimal linux-2.6.33/fs/jfs/ioctl.c linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/ioctl.c
4582 --- linux-2.6.33/fs/jfs/ioctl.c 2008-12-25 00:26:37.000000000 +0100
4583 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/ioctl.c 2010-02-25 12:02:16.000000000 +0100
4584 @@ -11,6 +11,7 @@
4585  #include <linux/mount.h>
4586  #include <linux/time.h>
4587  #include <linux/sched.h>
4588 +#include <linux/mount.h>
4589  #include <asm/current.h>
4590  #include <asm/uaccess.h>
4591  
4592 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4593  }
4594  
4595  
4596 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4597 +{
4598 +       inode->i_flags = flags;
4599 +       inode->i_vflags = vflags;
4600 +       jfs_get_inode_flags(JFS_IP(inode));
4601 +       inode->i_ctime = CURRENT_TIME_SEC;
4602 +       mark_inode_dirty(inode);
4603 +       return 0;
4604 +}
4605 +
4606  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4607  {
4608         struct inode *inode = filp->f_dentry->d_inode;
4609 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4610                 if (!S_ISDIR(inode->i_mode))
4611                         flags &= ~JFS_DIRSYNC_FL;
4612  
4613 +               if (IS_BARRIER(inode)) {
4614 +                       vxwprintk_task(1, "messing with the barrier.");
4615 +                       return -EACCES;
4616 +               }
4617 +
4618                 /* Is it quota file? Do not allow user to mess with it */
4619                 if (IS_NOQUOTA(inode)) {
4620                         err = -EPERM;
4621 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4622                  * the relevant capability.
4623                  */
4624                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4625 -                       ((flags ^ oldflags) &
4626 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4627 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4628 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4629                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4630                                 mutex_unlock(&inode->i_mutex);
4631                                 err = -EPERM;
4632 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4633                         }
4634                 }
4635  
4636 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4637 +               flags &= JFS_FL_USER_MODIFIABLE;
4638                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4639                 jfs_inode->mode2 = flags;
4640  
4641 diff -NurpP --minimal linux-2.6.33/fs/jfs/jfs_dinode.h linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/jfs_dinode.h
4642 --- linux-2.6.33/fs/jfs/jfs_dinode.h    2008-12-25 00:26:37.000000000 +0100
4643 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/jfs_dinode.h    2010-02-25 12:02:16.000000000 +0100
4644 @@ -161,9 +161,13 @@ struct dinode {
4645  
4646  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4647  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4648 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4649  
4650 -#define JFS_FL_USER_VISIBLE    0x03F80000
4651 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4652 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4653 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4654 +
4655 +#define JFS_FL_USER_VISIBLE    0x07F80000
4656 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4657  #define JFS_FL_INHERIT         0x03C80000
4658  
4659  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4660 diff -NurpP --minimal linux-2.6.33/fs/jfs/jfs_filsys.h linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/jfs_filsys.h
4661 --- linux-2.6.33/fs/jfs/jfs_filsys.h    2008-12-25 00:26:37.000000000 +0100
4662 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/jfs_filsys.h    2010-02-25 12:02:16.000000000 +0100
4663 @@ -263,6 +263,7 @@
4664  #define JFS_NAME_MAX   255
4665  #define JFS_PATH_MAX   BPSIZE
4666  
4667 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4668  
4669  /*
4670   *     file system state (superblock state)
4671 diff -NurpP --minimal linux-2.6.33/fs/jfs/jfs_imap.c linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/jfs_imap.c
4672 --- linux-2.6.33/fs/jfs/jfs_imap.c      2009-09-10 15:26:22.000000000 +0200
4673 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/jfs_imap.c      2010-02-25 12:02:16.000000000 +0100
4674 @@ -45,6 +45,7 @@
4675  #include <linux/buffer_head.h>
4676  #include <linux/pagemap.h>
4677  #include <linux/quotaops.h>
4678 +#include <linux/vs_tag.h>
4679  
4680  #include "jfs_incore.h"
4681  #include "jfs_inode.h"
4682 @@ -3059,6 +3060,8 @@ static int copy_from_dinode(struct dinod
4683  {
4684         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4685         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4686 +       uid_t uid;
4687 +       gid_t gid;
4688  
4689         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4690         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4691 @@ -3079,14 +3082,18 @@ static int copy_from_dinode(struct dinod
4692         }
4693         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4694  
4695 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4696 +       uid = le32_to_cpu(dip->di_uid);
4697 +       gid = le32_to_cpu(dip->di_gid);
4698 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4699 +
4700 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4701         if (sbi->uid == -1)
4702                 ip->i_uid = jfs_ip->saved_uid;
4703         else {
4704                 ip->i_uid = sbi->uid;
4705         }
4706  
4707 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4708 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4709         if (sbi->gid == -1)
4710                 ip->i_gid = jfs_ip->saved_gid;
4711         else {
4712 @@ -3151,14 +3158,12 @@ static void copy_to_dinode(struct dinode
4713         dip->di_size = cpu_to_le64(ip->i_size);
4714         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4715         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4716 -       if (sbi->uid == -1)
4717 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4718 -       else
4719 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4720 -       if (sbi->gid == -1)
4721 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4722 -       else
4723 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4724 +
4725 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4726 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4727 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4728 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4729 +
4730         jfs_get_inode_flags(jfs_ip);
4731         /*
4732          * mode2 is only needed for storing the higher order bits.
4733 diff -NurpP --minimal linux-2.6.33/fs/jfs/jfs_inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/jfs_inode.c
4734 --- linux-2.6.33/fs/jfs/jfs_inode.c     2009-06-11 17:13:05.000000000 +0200
4735 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/jfs_inode.c     2010-02-25 12:02:16.000000000 +0100
4736 @@ -18,6 +18,7 @@
4737  
4738  #include <linux/fs.h>
4739  #include <linux/quotaops.h>
4740 +#include <linux/vs_tag.h>
4741  #include "jfs_incore.h"
4742  #include "jfs_inode.h"
4743  #include "jfs_filsys.h"
4744 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4745  {
4746         unsigned int flags = JFS_IP(inode)->mode2;
4747  
4748 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4749 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4750 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4751 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4752  
4753         if (flags & JFS_IMMUTABLE_FL)
4754                 inode->i_flags |= S_IMMUTABLE;
4755 +       if (flags & JFS_IXUNLINK_FL)
4756 +               inode->i_flags |= S_IXUNLINK;
4757 +
4758 +       if (flags & JFS_SYNC_FL)
4759 +               inode->i_flags |= S_SYNC;
4760         if (flags & JFS_APPEND_FL)
4761                 inode->i_flags |= S_APPEND;
4762         if (flags & JFS_NOATIME_FL)
4763                 inode->i_flags |= S_NOATIME;
4764         if (flags & JFS_DIRSYNC_FL)
4765                 inode->i_flags |= S_DIRSYNC;
4766 -       if (flags & JFS_SYNC_FL)
4767 -               inode->i_flags |= S_SYNC;
4768 +
4769 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4770 +
4771 +       if (flags & JFS_BARRIER_FL)
4772 +               inode->i_vflags |= V_BARRIER;
4773 +       if (flags & JFS_COW_FL)
4774 +               inode->i_vflags |= V_COW;
4775  }
4776  
4777  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4778  {
4779         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4780 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4781 +
4782 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4783 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4784 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4785 +                          JFS_BARRIER_FL | JFS_COW_FL);
4786  
4787 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4788 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4789         if (flags & S_IMMUTABLE)
4790                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4791 +       if (flags & S_IXUNLINK)
4792 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4793 +
4794         if (flags & S_APPEND)
4795                 jfs_ip->mode2 |= JFS_APPEND_FL;
4796         if (flags & S_NOATIME)
4797 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4798                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4799         if (flags & S_SYNC)
4800                 jfs_ip->mode2 |= JFS_SYNC_FL;
4801 +
4802 +       if (vflags & V_BARRIER)
4803 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4804 +       if (vflags & V_COW)
4805 +               jfs_ip->mode2 |= JFS_COW_FL;
4806  }
4807  
4808  /*
4809 @@ -105,6 +128,7 @@ struct inode *ialloc(struct inode *paren
4810                         mode |= S_ISGID;
4811         } else
4812                 inode->i_gid = current_fsgid();
4813 +       inode->i_tag = dx_current_fstag(sb);
4814  
4815         /*
4816          * New inodes need to save sane values on disk when
4817 diff -NurpP --minimal linux-2.6.33/fs/jfs/jfs_inode.h linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/jfs_inode.h
4818 --- linux-2.6.33/fs/jfs/jfs_inode.h     2009-06-11 17:13:05.000000000 +0200
4819 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/jfs_inode.h     2010-02-25 12:02:16.000000000 +0100
4820 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4821  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4822         int fh_len, int fh_type);
4823  extern void jfs_set_inode_flags(struct inode *);
4824 +extern int jfs_sync_flags(struct inode *, int, int);
4825  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4826  
4827  extern const struct address_space_operations jfs_aops;
4828 diff -NurpP --minimal linux-2.6.33/fs/jfs/namei.c linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/namei.c
4829 --- linux-2.6.33/fs/jfs/namei.c 2009-12-03 20:02:52.000000000 +0100
4830 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/namei.c 2010-02-25 12:02:16.000000000 +0100
4831 @@ -21,6 +21,7 @@
4832  #include <linux/ctype.h>
4833  #include <linux/quotaops.h>
4834  #include <linux/exportfs.h>
4835 +#include <linux/vs_tag.h>
4836  #include "jfs_incore.h"
4837  #include "jfs_superblock.h"
4838  #include "jfs_inode.h"
4839 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4840                 return ERR_CAST(ip);
4841         }
4842  
4843 +       dx_propagate_tag(nd, ip);
4844         dentry = d_splice_alias(ip, dentry);
4845  
4846         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4847 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4848         .setattr        = jfs_setattr,
4849         .check_acl      = jfs_check_acl,
4850  #endif
4851 +       .sync_flags     = jfs_sync_flags,
4852  };
4853  
4854  const struct file_operations jfs_dir_operations = {
4855 diff -NurpP --minimal linux-2.6.33/fs/jfs/super.c linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/super.c
4856 --- linux-2.6.33/fs/jfs/super.c 2010-02-25 11:52:05.000000000 +0100
4857 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/jfs/super.c 2010-02-25 12:02:16.000000000 +0100
4858 @@ -192,7 +192,8 @@ static void jfs_put_super(struct super_b
4859  enum {
4860         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4861         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4862 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4863 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4864 +       Opt_tag, Opt_notag, Opt_tagid
4865  };
4866  
4867  static const match_table_t tokens = {
4868 @@ -202,6 +203,10 @@ static const match_table_t tokens = {
4869         {Opt_resize, "resize=%u"},
4870         {Opt_resize_nosize, "resize"},
4871         {Opt_errors, "errors=%s"},
4872 +       {Opt_tag, "tag"},
4873 +       {Opt_notag, "notag"},
4874 +       {Opt_tagid, "tagid=%u"},
4875 +       {Opt_tag, "tagxid"},
4876         {Opt_ignore, "noquota"},
4877         {Opt_ignore, "quota"},
4878         {Opt_usrquota, "usrquota"},
4879 @@ -336,6 +341,20 @@ static int parse_options(char *options, 
4880                         }
4881                         break;
4882                 }
4883 +#ifndef CONFIG_TAGGING_NONE
4884 +               case Opt_tag:
4885 +                       *flag |= JFS_TAGGED;
4886 +                       break;
4887 +               case Opt_notag:
4888 +                       *flag &= JFS_TAGGED;
4889 +                       break;
4890 +#endif
4891 +#ifdef CONFIG_PROPAGATE
4892 +               case Opt_tagid:
4893 +                       /* use args[0] */
4894 +                       *flag |= JFS_TAGGED;
4895 +                       break;
4896 +#endif
4897                 default:
4898                         printk("jfs: Unrecognized mount option \"%s\" "
4899                                         " or missing value\n", p);
4900 @@ -366,6 +385,12 @@ static int jfs_remount(struct super_bloc
4901         if (!parse_options(data, sb, &newLVSize, &flag)) {
4902                 return -EINVAL;
4903         }
4904 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4905 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4906 +                       sb->s_id);
4907 +               return -EINVAL;
4908 +       }
4909 +
4910         lock_kernel();
4911         if (newLVSize) {
4912                 if (sb->s_flags & MS_RDONLY) {
4913 @@ -449,6 +474,9 @@ static int jfs_fill_super(struct super_b
4914  #ifdef CONFIG_JFS_POSIX_ACL
4915         sb->s_flags |= MS_POSIXACL;
4916  #endif
4917 +       /* map mount option tagxid */
4918 +       if (sbi->flag & JFS_TAGGED)
4919 +               sb->s_flags |= MS_TAGGED;
4920  
4921         if (newLVSize) {
4922                 printk(KERN_ERR "resize option for remount only\n");
4923 diff -NurpP --minimal linux-2.6.33/fs/libfs.c linux-2.6.33-vs2.3.0.36.30.1/fs/libfs.c
4924 --- linux-2.6.33/fs/libfs.c     2010-02-25 11:52:05.000000000 +0100
4925 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/libfs.c     2010-02-25 12:02:16.000000000 +0100
4926 @@ -127,7 +127,8 @@ static inline unsigned char dt_type(stru
4927   * both impossible due to the lock on directory.
4928   */
4929  
4930 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4931 +static inline int do_dcache_readdir_filter(struct file *filp,
4932 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4933  {
4934         struct dentry *dentry = filp->f_path.dentry;
4935         struct dentry *cursor = filp->private_data;
4936 @@ -160,6 +161,8 @@ int dcache_readdir(struct file * filp, v
4937                                 next = list_entry(p, struct dentry, d_u.d_child);
4938                                 if (d_unhashed(next) || !next->d_inode)
4939                                         continue;
4940 +                               if (filter && !filter(next))
4941 +                                       continue;
4942  
4943                                 spin_unlock(&dcache_lock);
4944                                 if (filldir(dirent, next->d_name.name, 
4945 @@ -178,6 +181,18 @@ int dcache_readdir(struct file * filp, v
4946         return 0;
4947  }
4948  
4949 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4950 +{
4951 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4952 +}
4953 +
4954 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4955 +       int (*filter)(struct dentry *))
4956 +{
4957 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4958 +}
4959 +
4960 +
4961  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4962  {
4963         return -EISDIR;
4964 @@ -841,6 +856,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4965  EXPORT_SYMBOL(dcache_dir_lseek);
4966  EXPORT_SYMBOL(dcache_dir_open);
4967  EXPORT_SYMBOL(dcache_readdir);
4968 +EXPORT_SYMBOL(dcache_readdir_filter);
4969  EXPORT_SYMBOL(generic_read_dir);
4970  EXPORT_SYMBOL(get_sb_pseudo);
4971  EXPORT_SYMBOL(simple_write_begin);
4972 diff -NurpP --minimal linux-2.6.33/fs/locks.c linux-2.6.33-vs2.3.0.36.30.1/fs/locks.c
4973 --- linux-2.6.33/fs/locks.c     2009-12-03 20:02:52.000000000 +0100
4974 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/locks.c     2010-02-25 12:02:16.000000000 +0100
4975 @@ -127,6 +127,8 @@
4976  #include <linux/time.h>
4977  #include <linux/rcupdate.h>
4978  #include <linux/pid_namespace.h>
4979 +#include <linux/vs_base.h>
4980 +#include <linux/vs_limit.h>
4981  
4982  #include <asm/uaccess.h>
4983  
4984 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4985  /* Allocate an empty lock structure. */
4986  static struct file_lock *locks_alloc_lock(void)
4987  {
4988 +       if (!vx_locks_avail(1))
4989 +               return NULL;
4990         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4991  }
4992  
4993 @@ -174,6 +178,7 @@ static void locks_free_lock(struct file_
4994         BUG_ON(!list_empty(&fl->fl_block));
4995         BUG_ON(!list_empty(&fl->fl_link));
4996  
4997 +       vx_locks_dec(fl);
4998         locks_release_private(fl);
4999         kmem_cache_free(filelock_cache, fl);
5000  }
5001 @@ -194,6 +199,7 @@ void locks_init_lock(struct file_lock *f
5002         fl->fl_start = fl->fl_end = 0;
5003         fl->fl_ops = NULL;
5004         fl->fl_lmops = NULL;
5005 +       fl->fl_xid = -1;
5006  }
5007  
5008  EXPORT_SYMBOL(locks_init_lock);
5009 @@ -248,6 +254,7 @@ void locks_copy_lock(struct file_lock *n
5010         new->fl_file = fl->fl_file;
5011         new->fl_ops = fl->fl_ops;
5012         new->fl_lmops = fl->fl_lmops;
5013 +       new->fl_xid = fl->fl_xid;
5014  
5015         locks_copy_private(new, fl);
5016  }
5017 @@ -286,6 +293,11 @@ static int flock_make_lock(struct file *
5018         fl->fl_flags = FL_FLOCK;
5019         fl->fl_type = type;
5020         fl->fl_end = OFFSET_MAX;
5021 +
5022 +       vxd_assert(filp->f_xid == vx_current_xid(),
5023 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5024 +       fl->fl_xid = filp->f_xid;
5025 +       vx_locks_inc(fl);
5026         
5027         *lock = fl;
5028         return 0;
5029 @@ -451,6 +463,7 @@ static int lease_init(struct file *filp,
5030  
5031         fl->fl_owner = current->files;
5032         fl->fl_pid = current->tgid;
5033 +       fl->fl_xid = vx_current_xid();
5034  
5035         fl->fl_file = filp;
5036         fl->fl_flags = FL_LEASE;
5037 @@ -470,6 +483,11 @@ static struct file_lock *lease_alloc(str
5038         if (fl == NULL)
5039                 return ERR_PTR(error);
5040  
5041 +       fl->fl_xid = vx_current_xid();
5042 +       if (filp)
5043 +               vxd_assert(filp->f_xid == fl->fl_xid,
5044 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
5045 +       vx_locks_inc(fl);
5046         error = lease_init(filp, type, fl);
5047         if (error) {
5048                 locks_free_lock(fl);
5049 @@ -770,6 +788,7 @@ static int flock_lock_file(struct file *
5050         if (found)
5051                 cond_resched();
5052  
5053 +       new_fl->fl_xid = -1;
5054  find_conflict:
5055         for_each_lock(inode, before) {
5056                 struct file_lock *fl = *before;
5057 @@ -790,6 +809,7 @@ find_conflict:
5058                 goto out;
5059         locks_copy_lock(new_fl, request);
5060         locks_insert_lock(before, new_fl);
5061 +       vx_locks_inc(new_fl);
5062         new_fl = NULL;
5063         error = 0;
5064  
5065 @@ -800,7 +820,8 @@ out:
5066         return error;
5067  }
5068  
5069 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
5070 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
5071 +       struct file_lock *conflock, xid_t xid)
5072  {
5073         struct file_lock *fl;
5074         struct file_lock *new_fl = NULL;
5075 @@ -810,6 +831,8 @@ static int __posix_lock_file(struct inod
5076         struct file_lock **before;
5077         int error, added = 0;
5078  
5079 +       vxd_assert(xid == vx_current_xid(),
5080 +               "xid(%d) == current(%d)", xid, vx_current_xid());
5081         /*
5082          * We may need two file_lock structures for this operation,
5083          * so we get them in advance to avoid races.
5084 @@ -820,7 +843,11 @@ static int __posix_lock_file(struct inod
5085             (request->fl_type != F_UNLCK ||
5086              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
5087                 new_fl = locks_alloc_lock();
5088 +               new_fl->fl_xid = xid;
5089 +               vx_locks_inc(new_fl);
5090                 new_fl2 = locks_alloc_lock();
5091 +               new_fl2->fl_xid = xid;
5092 +               vx_locks_inc(new_fl2);
5093         }
5094  
5095         lock_kernel();
5096 @@ -1019,7 +1046,8 @@ static int __posix_lock_file(struct inod
5097  int posix_lock_file(struct file *filp, struct file_lock *fl,
5098                         struct file_lock *conflock)
5099  {
5100 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
5101 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
5102 +               fl, conflock, filp->f_xid);
5103  }
5104  EXPORT_SYMBOL(posix_lock_file);
5105  
5106 @@ -1109,7 +1137,7 @@ int locks_mandatory_area(int read_write,
5107         fl.fl_end = offset + count - 1;
5108  
5109         for (;;) {
5110 -               error = __posix_lock_file(inode, &fl, NULL);
5111 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
5112                 if (error != FILE_LOCK_DEFERRED)
5113                         break;
5114                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
5115 @@ -1424,6 +1452,7 @@ int generic_setlease(struct file *filp, 
5116  
5117         locks_copy_lock(new_fl, lease);
5118         locks_insert_lock(before, new_fl);
5119 +       vx_locks_inc(new_fl);
5120  
5121         *flp = new_fl;
5122         return 0;
5123 @@ -1779,6 +1808,11 @@ int fcntl_setlk(unsigned int fd, struct 
5124         if (file_lock == NULL)
5125                 return -ENOLCK;
5126  
5127 +       vxd_assert(filp->f_xid == vx_current_xid(),
5128 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5129 +       file_lock->fl_xid = filp->f_xid;
5130 +       vx_locks_inc(file_lock);
5131 +
5132         /*
5133          * This might block, so we do it before checking the inode.
5134          */
5135 @@ -1897,6 +1931,11 @@ int fcntl_setlk64(unsigned int fd, struc
5136         if (file_lock == NULL)
5137                 return -ENOLCK;
5138  
5139 +       vxd_assert(filp->f_xid == vx_current_xid(),
5140 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5141 +       file_lock->fl_xid = filp->f_xid;
5142 +       vx_locks_inc(file_lock);
5143 +
5144         /*
5145          * This might block, so we do it before checking the inode.
5146          */
5147 @@ -2162,8 +2201,11 @@ static int locks_show(struct seq_file *f
5148  
5149         lock_get_status(f, fl, (long)f->private, "");
5150  
5151 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
5152 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
5153 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
5154 +                       continue;
5155                 lock_get_status(f, bfl, (long)f->private, " ->");
5156 +       }
5157  
5158         f->private++;
5159         return 0;
5160 diff -NurpP --minimal linux-2.6.33/fs/namei.c linux-2.6.33-vs2.3.0.36.30.1/fs/namei.c
5161 --- linux-2.6.33/fs/namei.c     2010-02-25 11:52:05.000000000 +0100
5162 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/namei.c     2010-02-25 15:31:15.000000000 +0100
5163 @@ -33,6 +33,14 @@
5164  #include <linux/fcntl.h>
5165  #include <linux/device_cgroup.h>
5166  #include <linux/fs_struct.h>
5167 +#include <linux/proc_fs.h>
5168 +#include <linux/vserver/inode.h>
5169 +#include <linux/vs_base.h>
5170 +#include <linux/vs_tag.h>
5171 +#include <linux/vs_cowbl.h>
5172 +#include <linux/vs_device.h>
5173 +#include <linux/vs_context.h>
5174 +#include <linux/pid_namespace.h>
5175  #include <asm/uaccess.h>
5176  
5177  #include "internal.h"
5178 @@ -167,6 +175,77 @@ void putname(const char *name)
5179  EXPORT_SYMBOL(putname);
5180  #endif
5181  
5182 +static inline int dx_barrier(const struct inode *inode)
5183 +{
5184 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
5185 +               vxwprintk_task(1, "did hit the barrier.");
5186 +               return 1;
5187 +       }
5188 +       return 0;
5189 +}
5190 +
5191 +static int __dx_permission(const struct inode *inode, int mask)
5192 +{
5193 +       if (dx_barrier(inode))
5194 +               return -EACCES;
5195 +
5196 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
5197 +               /* devpts is xid tagged */
5198 +               if (S_ISDIR(inode->i_mode) ||
5199 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
5200 +                       return 0;
5201 +       }
5202 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
5203 +               struct proc_dir_entry *de = PDE(inode);
5204 +
5205 +               if (de && !vx_hide_check(0, de->vx_flags))
5206 +                       goto out;
5207 +
5208 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
5209 +                       struct pid *pid;
5210 +                       struct task_struct *tsk;
5211 +
5212 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
5213 +                           vx_flags(VXF_STATE_SETUP, 0))
5214 +                               return 0;
5215 +
5216 +                       pid = PROC_I(inode)->pid;
5217 +                       if (!pid)
5218 +                               goto out;
5219 +
5220 +                       tsk = pid_task(pid, PIDTYPE_PID);
5221 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
5222 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
5223 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
5224 +                               return 0;
5225 +               }
5226 +               else {
5227 +                       /* FIXME: Should we block some entries here? */
5228 +                       return 0;
5229 +               }
5230 +       }
5231 +       else {
5232 +               if (dx_notagcheck(inode->i_sb) ||
5233 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
5234 +                            DX_IDENT))
5235 +                       return 0;
5236 +       }
5237 +
5238 +out:
5239 +       return -EACCES;
5240 +}
5241 +
5242 +int dx_permission(const struct inode *inode, int mask)
5243 +{
5244 +       int ret = __dx_permission(inode, mask);
5245 +       if (unlikely(ret)) {
5246 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
5247 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
5248 +                       inode->i_ino);
5249 +       }
5250 +       return ret;
5251 +}
5252 +
5253  /*
5254   * This does basic POSIX ACL permission checking
5255   */
5256 @@ -267,10 +346,14 @@ int inode_permission(struct inode *inode
5257                 /*
5258                  * Nobody gets write access to an immutable file.
5259                  */
5260 -               if (IS_IMMUTABLE(inode))
5261 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5262                         return -EACCES;
5263         }
5264  
5265 +       retval = dx_permission(inode, mask);
5266 +       if (retval)
5267 +               return retval;
5268 +
5269         if (inode->i_op->permission)
5270                 retval = inode->i_op->permission(inode, mask);
5271         else
5272 @@ -465,6 +548,9 @@ static int exec_permission(struct inode 
5273  {
5274         int ret;
5275  
5276 +       if (dx_barrier(inode))
5277 +               return -EACCES;
5278 +
5279         if (inode->i_op->permission) {
5280                 ret = inode->i_op->permission(inode, MAY_EXEC);
5281                 if (!ret)
5282 @@ -694,7 +780,8 @@ static __always_inline void follow_dotdo
5283  
5284                 if (nd->path.dentry == nd->root.dentry &&
5285                     nd->path.mnt == nd->root.mnt) {
5286 -                       break;
5287 +                       /* for sane '/' avoid follow_mount() */
5288 +                       return;
5289                 }
5290                 spin_lock(&dcache_lock);
5291                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5292 @@ -730,7 +817,7 @@ static int do_lookup(struct nameidata *n
5293  {
5294         struct vfsmount *mnt = nd->path.mnt;
5295         struct dentry *dentry, *parent;
5296 -       struct inode *dir;
5297 +       struct inode *dir, *inode;
5298         /*
5299          * See if the low-level filesystem might want
5300          * to use its own hash..
5301 @@ -746,12 +833,26 @@ static int do_lookup(struct nameidata *n
5302                 goto need_lookup;
5303         if (dentry->d_op && dentry->d_op->d_revalidate)
5304                 goto need_revalidate;
5305 +
5306 +       inode = dentry->d_inode;
5307 +       if (!inode)
5308 +               goto done;
5309 +
5310 +       if (__dx_permission(inode, MAY_ACCESS))
5311 +               goto hidden;
5312  done:
5313         path->mnt = mnt;
5314         path->dentry = dentry;
5315         __follow_mount(path);
5316         return 0;
5317  
5318 +hidden:
5319 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s/%.*s«.",
5320 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5321 +               vxd_path(&nd->path), name->len, name->name);
5322 +       dput(dentry);
5323 +       return -ENOENT;
5324 +
5325  need_lookup:
5326         parent = nd->path.dentry;
5327         dir = parent->d_inode;
5328 @@ -1355,7 +1456,7 @@ static int may_delete(struct inode *dir,
5329         if (IS_APPEND(dir))
5330                 return -EPERM;
5331         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5332 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5333 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5334                 return -EPERM;
5335         if (isdir) {
5336                 if (!S_ISDIR(victim->d_inode->i_mode))
5337 @@ -1495,6 +1596,14 @@ int may_open(struct path *path, int acc_
5338                 break;
5339         }
5340  
5341 +#ifdef CONFIG_VSERVER_COWBL
5342 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5343 +               if (IS_COW_LINK(inode))
5344 +                       return -EMLINK;
5345 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5346 +               mark_inode_dirty(inode);
5347 +       }
5348 +#endif
5349         error = inode_permission(inode, acc_mode);
5350         if (error)
5351                 return error;
5352 @@ -1621,6 +1730,11 @@ struct file *do_filp_open(int dfd, const
5353         int flag = open_to_namei_flags(open_flag);
5354         int force_reval = 0;
5355  
5356 +#ifdef CONFIG_VSERVER_COWBL
5357 +       int rflag = flag;
5358 +       int rmode = mode;
5359 +restart:
5360 +#endif
5361         /*
5362          * O_SYNC is implemented as __O_SYNC|O_DSYNC.  As many places only
5363          * check for O_DSYNC if the need any syncing at all we enforce it's
5364 @@ -1799,6 +1913,25 @@ ok:
5365                         goto exit;
5366         }
5367         error = may_open(&nd.path, acc_mode, flag);
5368 +#ifdef CONFIG_VSERVER_COWBL
5369 +       if (error == -EMLINK) {
5370 +               struct dentry *dentry;
5371 +               dentry = cow_break_link(pathname);
5372 +               if (IS_ERR(dentry)) {
5373 +                       error = PTR_ERR(dentry);
5374 +                       goto exit_cow;
5375 +               }
5376 +               dput(dentry);
5377 +               if (will_truncate)
5378 +                       mnt_drop_write(nd.path.mnt);
5379 +               release_open_intent(&nd);
5380 +               path_put(&nd.path);
5381 +               flag = rflag;
5382 +               mode = rmode;
5383 +               goto restart;
5384 +       }
5385 +exit_cow:
5386 +#endif
5387         if (error) {
5388                 if (will_truncate)
5389                         mnt_drop_write(nd.path.mnt);
5390 @@ -1982,9 +2115,17 @@ int vfs_mknod(struct inode *dir, struct 
5391         if (error)
5392                 return error;
5393  
5394 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5395 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5396 +               goto okay;
5397 +
5398 +       if (!capable(CAP_MKNOD))
5399                 return -EPERM;
5400  
5401 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5402 +               return -EPERM;
5403 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5404 +               return -EPERM;
5405 +okay:
5406         if (!dir->i_op->mknod)
5407                 return -EPERM;
5408  
5409 @@ -2451,7 +2592,7 @@ int vfs_link(struct dentry *old_dentry, 
5410         /*
5411          * A link to an append-only or immutable file cannot be created.
5412          */
5413 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5414 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5415                 return -EPERM;
5416         if (!dir->i_op->link)
5417                 return -EPERM;
5418 @@ -2824,6 +2965,219 @@ int vfs_follow_link(struct nameidata *nd
5419         return __vfs_follow_link(nd, link);
5420  }
5421  
5422 +
5423 +#ifdef CONFIG_VSERVER_COWBL
5424 +
5425 +#include <linux/file.h>
5426 +
5427 +static inline
5428 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5429 +{
5430 +       loff_t ppos = 0;
5431 +
5432 +       return do_splice_direct(in, &ppos, out, len, 0);
5433 +}
5434 +
5435 +struct dentry *cow_break_link(const char *pathname)
5436 +{
5437 +       int ret, mode, pathlen, redo = 0;
5438 +       struct nameidata old_nd, dir_nd;
5439 +       struct path old_path, new_path;
5440 +       struct dentry *dir, *res = NULL;
5441 +       struct file *old_file;
5442 +       struct file *new_file;
5443 +       char *to, *path, pad='\251';
5444 +       loff_t size;
5445 +
5446 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5447 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5448 +       ret = -ENOMEM;
5449 +       if (!path)
5450 +               goto out;
5451 +
5452 +       /* old_nd will have refs to dentry and mnt */
5453 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5454 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5455 +       if (ret < 0)
5456 +               goto out_free_path;
5457 +
5458 +       old_path = old_nd.path;
5459 +       mode = old_path.dentry->d_inode->i_mode;
5460 +
5461 +       to = d_path(&old_path, path, PATH_MAX-2);
5462 +       pathlen = strlen(to);
5463 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5464 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5465 +               old_path.dentry->d_name.len);
5466 +
5467 +       to[pathlen + 1] = 0;
5468 +retry:
5469 +       to[pathlen] = pad--;
5470 +       ret = -EMLINK;
5471 +       if (pad <= '\240')
5472 +               goto out_rel_old;
5473 +
5474 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5475 +       /* dir_nd will have refs to dentry and mnt */
5476 +       ret = path_lookup(to,
5477 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5478 +       vxdprintk(VXD_CBIT(misc, 2),
5479 +               "path_lookup(new): %d", ret);
5480 +       if (ret < 0)
5481 +               goto retry;
5482 +
5483 +       /* this puppy downs the inode mutex */
5484 +       new_path.dentry = lookup_create(&dir_nd, 0);
5485 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5486 +               vxdprintk(VXD_CBIT(misc, 2),
5487 +                       "lookup_create(new): %p", new_path.dentry);
5488 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5489 +               path_put(&dir_nd.path);
5490 +               goto retry;
5491 +       }
5492 +       vxdprintk(VXD_CBIT(misc, 2),
5493 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5494 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5495 +               new_path.dentry->d_name.len);
5496 +       dir = dir_nd.path.dentry;
5497 +
5498 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5499 +       vxdprintk(VXD_CBIT(misc, 2),
5500 +               "vfs_create(new): %d", ret);
5501 +       if (ret == -EEXIST) {
5502 +               mutex_unlock(&dir->d_inode->i_mutex);
5503 +               dput(new_path.dentry);
5504 +               path_put(&dir_nd.path);
5505 +               goto retry;
5506 +       }
5507 +       else if (ret < 0)
5508 +               goto out_unlock_new;
5509 +
5510 +       /* drop out early, ret passes ENOENT */
5511 +       ret = -ENOENT;
5512 +       if ((redo = d_unhashed(old_path.dentry)))
5513 +               goto out_unlock_new;
5514 +
5515 +       new_path.mnt = dir_nd.path.mnt;
5516 +       dget(old_path.dentry);
5517 +       mntget(old_path.mnt);
5518 +       /* this one cleans up the dentry/mnt in case of failure */
5519 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5520 +               O_RDONLY, current_cred());
5521 +       vxdprintk(VXD_CBIT(misc, 2),
5522 +               "dentry_open(old): %p", old_file);
5523 +       if (!old_file || IS_ERR(old_file)) {
5524 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5525 +               goto out_unlock_new;
5526 +       }
5527 +
5528 +       dget(new_path.dentry);
5529 +       mntget(new_path.mnt);
5530 +       /* this one cleans up the dentry/mnt in case of failure */
5531 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5532 +               O_WRONLY, current_cred());
5533 +       vxdprintk(VXD_CBIT(misc, 2),
5534 +               "dentry_open(new): %p", new_file);
5535 +
5536 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5537 +       if (!new_file || IS_ERR(new_file))
5538 +               goto out_fput_old;
5539 +
5540 +       size = i_size_read(old_file->f_dentry->d_inode);
5541 +       ret = do_cow_splice(old_file, new_file, size);
5542 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5543 +       if (ret < 0) {
5544 +               goto out_fput_both;
5545 +       } else if (ret < size) {
5546 +               ret = -ENOSPC;
5547 +               goto out_fput_both;
5548 +       } else {
5549 +               struct inode *old_inode = old_path.dentry->d_inode;
5550 +               struct inode *new_inode = new_path.dentry->d_inode;
5551 +               struct iattr attr = {
5552 +                       .ia_uid = old_inode->i_uid,
5553 +                       .ia_gid = old_inode->i_gid,
5554 +                       .ia_valid = ATTR_UID | ATTR_GID
5555 +                       };
5556 +
5557 +               ret = inode_setattr(new_inode, &attr);
5558 +               if (ret)
5559 +                       goto out_fput_both;
5560 +       }
5561 +
5562 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5563 +
5564 +       /* drop out late */
5565 +       ret = -ENOENT;
5566 +       if ((redo = d_unhashed(old_path.dentry)))
5567 +               goto out_unlock;
5568 +
5569 +       vxdprintk(VXD_CBIT(misc, 2),
5570 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5571 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5572 +               new_path.dentry->d_name.len,
5573 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5574 +               old_path.dentry->d_name.len);
5575 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5576 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5577 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5578 +       res = new_path.dentry;
5579 +
5580 +out_unlock:
5581 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5582 +
5583 +out_fput_both:
5584 +       vxdprintk(VXD_CBIT(misc, 3),
5585 +               "fput(new_file=%p[#%ld])", new_file,
5586 +               atomic_long_read(&new_file->f_count));
5587 +       fput(new_file);
5588 +
5589 +out_fput_old:
5590 +       vxdprintk(VXD_CBIT(misc, 3),
5591 +               "fput(old_file=%p[#%ld])", old_file,
5592 +               atomic_long_read(&old_file->f_count));
5593 +       fput(old_file);
5594 +
5595 +out_unlock_new:
5596 +       mutex_unlock(&dir->d_inode->i_mutex);
5597 +       if (!ret)
5598 +               goto out_redo;
5599 +
5600 +       /* error path cleanup */
5601 +       vfs_unlink(dir->d_inode, new_path.dentry);
5602 +       dput(new_path.dentry);
5603 +
5604 +out_redo:
5605 +       if (!redo)
5606 +               goto out_rel_both;
5607 +       /* lookup dentry once again */
5608 +       path_put(&old_nd.path);
5609 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5610 +       if (ret)
5611 +               goto out_rel_both;
5612 +
5613 +       new_path.dentry = old_nd.path.dentry;
5614 +       vxdprintk(VXD_CBIT(misc, 2),
5615 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5616 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5617 +               new_path.dentry->d_name.len);
5618 +       dget(new_path.dentry);
5619 +       res = new_path.dentry;
5620 +
5621 +out_rel_both:
5622 +       path_put(&dir_nd.path);
5623 +out_rel_old:
5624 +       path_put(&old_nd.path);
5625 +out_free_path:
5626 +       kfree(path);
5627 +out:
5628 +       if (ret)
5629 +               res = ERR_PTR(ret);
5630 +       return res;
5631 +}
5632 +
5633 +#endif
5634 +
5635  /* get the link contents into pagecache */
5636  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5637  {
5638 diff -NurpP --minimal linux-2.6.33/fs/namespace.c linux-2.6.33-vs2.3.0.36.30.1/fs/namespace.c
5639 --- linux-2.6.33/fs/namespace.c 2010-02-25 11:52:05.000000000 +0100
5640 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/namespace.c 2010-02-25 12:02:16.000000000 +0100
5641 @@ -29,6 +29,11 @@
5642  #include <linux/log2.h>
5643  #include <linux/idr.h>
5644  #include <linux/fs_struct.h>
5645 +#include <linux/vs_base.h>
5646 +#include <linux/vs_context.h>
5647 +#include <linux/vs_tag.h>
5648 +#include <linux/vserver/space.h>
5649 +#include <linux/vserver/global.h>
5650  #include <asm/uaccess.h>
5651  #include <asm/unistd.h>
5652  #include "pnode.h"
5653 @@ -567,6 +572,7 @@ static struct vfsmount *clone_mnt(struct
5654                 mnt->mnt_root = dget(root);
5655                 mnt->mnt_mountpoint = mnt->mnt_root;
5656                 mnt->mnt_parent = mnt;
5657 +               mnt->mnt_tag = old->mnt_tag;
5658  
5659                 if (flag & CL_SLAVE) {
5660                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5661 @@ -661,6 +667,31 @@ static inline void mangle(struct seq_fil
5662         seq_escape(m, s, " \t\n\\");
5663  }
5664  
5665 +static int mnt_is_reachable(struct vfsmount *mnt)
5666 +{
5667 +       struct path root;
5668 +       struct dentry *point;
5669 +       int ret;
5670 +
5671 +       if (mnt == mnt->mnt_ns->root)
5672 +               return 1;
5673 +
5674 +       spin_lock(&vfsmount_lock);
5675 +       root = current->fs->root;
5676 +       point = root.dentry;
5677 +
5678 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5679 +               point = mnt->mnt_mountpoint;
5680 +               mnt = mnt->mnt_parent;
5681 +       }
5682 +
5683 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5684 +
5685 +       spin_unlock(&vfsmount_lock);
5686 +
5687 +       return ret;
5688 +}
5689 +
5690  /*
5691   * Simple .show_options callback for filesystems which don't want to
5692   * implement more complex mount option showing.
5693 @@ -748,6 +779,8 @@ static int show_sb_opts(struct seq_file 
5694                 { MS_SYNCHRONOUS, ",sync" },
5695                 { MS_DIRSYNC, ",dirsync" },
5696                 { MS_MANDLOCK, ",mand" },
5697 +               { MS_TAGGED, ",tag" },
5698 +               { MS_NOTAGCHECK, ",notagcheck" },
5699                 { 0, NULL }
5700         };
5701         const struct proc_fs_info *fs_infop;
5702 @@ -795,10 +828,20 @@ static int show_vfsmnt(struct seq_file *
5703         int err = 0;
5704         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5705  
5706 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5707 -       seq_putc(m, ' ');
5708 -       seq_path(m, &mnt_path, " \t\n\\");
5709 -       seq_putc(m, ' ');
5710 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5711 +               return SEQ_SKIP;
5712 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5713 +               return SEQ_SKIP;
5714 +
5715 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5716 +               mnt == current->fs->root.mnt) {
5717 +               seq_puts(m, "/dev/root / ");
5718 +       } else {
5719 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5720 +               seq_putc(m, ' ');
5721 +               seq_path(m, &mnt_path, " \t\n\\");
5722 +               seq_putc(m, ' ');
5723 +       }
5724         show_type(m, mnt->mnt_sb);
5725         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5726         err = show_sb_opts(m, mnt->mnt_sb);
5727 @@ -828,6 +871,11 @@ static int show_mountinfo(struct seq_fil
5728         struct path root = p->root;
5729         int err = 0;
5730  
5731 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5732 +               return SEQ_SKIP;
5733 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5734 +               return SEQ_SKIP;
5735 +
5736         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5737                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5738         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5739 @@ -886,17 +934,27 @@ static int show_vfsstat(struct seq_file 
5740         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5741         int err = 0;
5742  
5743 -       /* device */
5744 -       if (mnt->mnt_devname) {
5745 -               seq_puts(m, "device ");
5746 -               mangle(m, mnt->mnt_devname);
5747 -       } else
5748 -               seq_puts(m, "no device");
5749 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5750 +               return SEQ_SKIP;
5751 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5752 +               return SEQ_SKIP;
5753  
5754 -       /* mount point */
5755 -       seq_puts(m, " mounted on ");
5756 -       seq_path(m, &mnt_path, " \t\n\\");
5757 -       seq_putc(m, ' ');
5758 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5759 +               mnt == current->fs->root.mnt) {
5760 +               seq_puts(m, "device /dev/root mounted on / ");
5761 +       } else {
5762 +               /* device */
5763 +               if (mnt->mnt_devname) {
5764 +                       seq_puts(m, "device ");
5765 +                       mangle(m, mnt->mnt_devname);
5766 +               } else
5767 +                       seq_puts(m, "no device");
5768 +
5769 +               /* mount point */
5770 +               seq_puts(m, " mounted on ");
5771 +               seq_path(m, &mnt_path, " \t\n\\");
5772 +               seq_putc(m, ' ');
5773 +       }
5774  
5775         /* file system type */
5776         seq_puts(m, "with fstype ");
5777 @@ -1132,7 +1190,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5778                 goto dput_and_out;
5779  
5780         retval = -EPERM;
5781 -       if (!capable(CAP_SYS_ADMIN))
5782 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5783                 goto dput_and_out;
5784  
5785         retval = do_umount(path.mnt, flags);
5786 @@ -1158,7 +1216,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5787  
5788  static int mount_is_safe(struct path *path)
5789  {
5790 -       if (capable(CAP_SYS_ADMIN))
5791 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5792                 return 0;
5793         return -EPERM;
5794  #ifdef notyet
5795 @@ -1422,7 +1480,7 @@ static int do_change_type(struct path *p
5796         int type = flag & ~MS_REC;
5797         int err = 0;
5798  
5799 -       if (!capable(CAP_SYS_ADMIN))
5800 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5801                 return -EPERM;
5802  
5803         if (path->dentry != path->mnt->mnt_root)
5804 @@ -1449,11 +1507,13 @@ static int do_change_type(struct path *p
5805   * do loopback mount.
5806   */
5807  static int do_loopback(struct path *path, char *old_name,
5808 -                               int recurse)
5809 +       tag_t tag, unsigned long flags, int mnt_flags)
5810  {
5811         struct path old_path;
5812         struct vfsmount *mnt = NULL;
5813         int err = mount_is_safe(path);
5814 +       int recurse = flags & MS_REC;
5815 +
5816         if (err)
5817                 return err;
5818         if (!old_name || !*old_name)
5819 @@ -1487,6 +1547,7 @@ static int do_loopback(struct path *path
5820                 spin_unlock(&vfsmount_lock);
5821                 release_mounts(&umount_list);
5822         }
5823 +       mnt->mnt_flags = mnt_flags;
5824  
5825  out:
5826         up_write(&namespace_sem);
5827 @@ -1517,12 +1578,12 @@ static int change_mount_flags(struct vfs
5828   * on it - tough luck.
5829   */
5830  static int do_remount(struct path *path, int flags, int mnt_flags,
5831 -                     void *data)
5832 +       void *data, xid_t xid)
5833  {
5834         int err;
5835         struct super_block *sb = path->mnt->mnt_sb;
5836  
5837 -       if (!capable(CAP_SYS_ADMIN))
5838 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5839                 return -EPERM;
5840  
5841         if (!check_mnt(path->mnt))
5842 @@ -1568,7 +1629,7 @@ static int do_move_mount(struct path *pa
5843         struct path old_path, parent_path;
5844         struct vfsmount *p;
5845         int err = 0;
5846 -       if (!capable(CAP_SYS_ADMIN))
5847 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5848                 return -EPERM;
5849         if (!old_name || !*old_name)
5850                 return -EINVAL;
5851 @@ -1650,7 +1711,7 @@ static int do_new_mount(struct path *pat
5852                 return -EINVAL;
5853  
5854         /* we need capabilities... */
5855 -       if (!capable(CAP_SYS_ADMIN))
5856 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5857                 return -EPERM;
5858  
5859         lock_kernel();
5860 @@ -1916,6 +1977,7 @@ long do_mount(char *dev_name, char *dir_
5861         struct path path;
5862         int retval = 0;
5863         int mnt_flags = 0;
5864 +       tag_t tag = 0;
5865  
5866         /* Discard magic */
5867         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5868 @@ -1943,6 +2005,12 @@ long do_mount(char *dev_name, char *dir_
5869         if (!(flags & MS_NOATIME))
5870                 mnt_flags |= MNT_RELATIME;
5871  
5872 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5873 +               /* FIXME: bind and re-mounts get the tag flag? */
5874 +               if (flags & (MS_BIND|MS_REMOUNT))
5875 +                       flags |= MS_TAGID;
5876 +       }
5877 +
5878         /* Separate the per-mountpoint flags */
5879         if (flags & MS_NOSUID)
5880                 mnt_flags |= MNT_NOSUID;
5881 @@ -1959,15 +2027,17 @@ long do_mount(char *dev_name, char *dir_
5882         if (flags & MS_RDONLY)
5883                 mnt_flags |= MNT_READONLY;
5884  
5885 +       if (!capable(CAP_SYS_ADMIN))
5886 +               mnt_flags |= MNT_NODEV;
5887         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5888                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5889                    MS_STRICTATIME);
5890  
5891         if (flags & MS_REMOUNT)
5892                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5893 -                                   data_page);
5894 +                                   data_page, tag);
5895         else if (flags & MS_BIND)
5896 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5897 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5898         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5899                 retval = do_change_type(&path, flags);
5900         else if (flags & MS_MOVE)
5901 @@ -2046,6 +2116,7 @@ static struct mnt_namespace *dup_mnt_ns(
5902                 q = next_mnt(q, new_ns->root);
5903         }
5904         up_write(&namespace_sem);
5905 +       atomic_inc(&vs_global_mnt_ns);
5906  
5907         if (rootmnt)
5908                 mntput(rootmnt);
5909 @@ -2190,9 +2261,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5910         down_write(&namespace_sem);
5911         mutex_lock(&old.dentry->d_inode->i_mutex);
5912         error = -EINVAL;
5913 -       if (IS_MNT_SHARED(old.mnt) ||
5914 +       if ((IS_MNT_SHARED(old.mnt) ||
5915                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5916 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5917 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5918 +               !vx_flags(VXF_STATE_SETUP, 0))
5919                 goto out2;
5920         if (!check_mnt(root.mnt))
5921                 goto out2;
5922 @@ -2328,6 +2400,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5923         spin_unlock(&vfsmount_lock);
5924         up_write(&namespace_sem);
5925         release_mounts(&umount_list);
5926 +       atomic_dec(&vs_global_mnt_ns);
5927         kfree(ns);
5928  }
5929  EXPORT_SYMBOL(put_mnt_ns);
5930 diff -NurpP --minimal linux-2.6.33/fs/nfs/client.c linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/client.c
5931 --- linux-2.6.33/fs/nfs/client.c        2010-02-25 11:52:05.000000000 +0100
5932 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/client.c        2010-02-25 12:02:16.000000000 +0100
5933 @@ -738,6 +738,9 @@ static int nfs_init_server_rpcclient(str
5934         if (server->flags & NFS_MOUNT_SOFT)
5935                 server->client->cl_softrtry = 1;
5936  
5937 +       server->client->cl_tag = 0;
5938 +       if (server->flags & NFS_MOUNT_TAGGED)
5939 +               server->client->cl_tag = 1;
5940         return 0;
5941  }
5942  
5943 @@ -909,6 +912,10 @@ static void nfs_server_set_fsinfo(struct
5944                 server->acdirmin = server->acdirmax = 0;
5945         }
5946  
5947 +       /* FIXME: needs fsinfo
5948 +       if (server->flags & NFS_MOUNT_TAGGED)
5949 +               sb->s_flags |= MS_TAGGED;       */
5950 +
5951         server->maxfilesize = fsinfo->maxfilesize;
5952  
5953         /* We're airborne Set socket buffersize */
5954 diff -NurpP --minimal linux-2.6.33/fs/nfs/dir.c linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/dir.c
5955 --- linux-2.6.33/fs/nfs/dir.c   2010-02-25 11:52:05.000000000 +0100
5956 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/dir.c   2010-02-25 12:02:16.000000000 +0100
5957 @@ -33,6 +33,7 @@
5958  #include <linux/namei.h>
5959  #include <linux/mount.h>
5960  #include <linux/sched.h>
5961 +#include <linux/vs_tag.h>
5962  
5963  #include "nfs4_fs.h"
5964  #include "delegation.h"
5965 @@ -949,6 +950,7 @@ static struct dentry *nfs_lookup(struct 
5966         if (IS_ERR(res))
5967                 goto out_unblock_sillyrename;
5968  
5969 +       dx_propagate_tag(nd, inode);
5970  no_entry:
5971         res = d_materialise_unique(dentry, inode);
5972         if (res != NULL) {
5973 diff -NurpP --minimal linux-2.6.33/fs/nfs/inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/inode.c
5974 --- linux-2.6.33/fs/nfs/inode.c 2010-02-25 11:52:05.000000000 +0100
5975 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/inode.c 2010-02-25 12:02:16.000000000 +0100
5976 @@ -36,6 +36,7 @@
5977  #include <linux/vfs.h>
5978  #include <linux/inet.h>
5979  #include <linux/nfs_xdr.h>
5980 +#include <linux/vs_tag.h>
5981  
5982  #include <asm/system.h>
5983  #include <asm/uaccess.h>
5984 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5985         if (inode->i_state & I_NEW) {
5986                 struct nfs_inode *nfsi = NFS_I(inode);
5987                 unsigned long now = jiffies;
5988 +               uid_t uid;
5989 +               gid_t gid;
5990  
5991                 /* We set i_ino for the few things that still rely on it,
5992                  * such as stat(2) */
5993 @@ -327,8 +330,8 @@ nfs_fhget(struct super_block *sb, struct
5994                 nfsi->change_attr = 0;
5995                 inode->i_size = 0;
5996                 inode->i_nlink = 0;
5997 -               inode->i_uid = -2;
5998 -               inode->i_gid = -2;
5999 +               uid = -2;
6000 +               gid = -2;
6001                 inode->i_blocks = 0;
6002                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
6003  
6004 @@ -365,13 +368,13 @@ nfs_fhget(struct super_block *sb, struct
6005                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
6006                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
6007                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
6008 -                       inode->i_uid = fattr->uid;
6009 +                       uid = fattr->uid;
6010                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
6011                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
6012                                 | NFS_INO_INVALID_ACCESS
6013                                 | NFS_INO_INVALID_ACL;
6014                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
6015 -                       inode->i_gid = fattr->gid;
6016 +                       gid = fattr->gid;
6017                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
6018                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
6019                                 | NFS_INO_INVALID_ACCESS
6020 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
6021                          */
6022                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
6023                 }
6024 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6025 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6026 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6027 +                               /* maybe fattr->xid someday */
6028 +
6029                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
6030                 nfsi->attrtimeo_timestamp = now;
6031                 nfsi->access_cache = RB_ROOT;
6032 @@ -496,6 +504,8 @@ void nfs_setattr_update_inode(struct ino
6033                         inode->i_uid = attr->ia_uid;
6034                 if ((attr->ia_valid & ATTR_GID) != 0)
6035                         inode->i_gid = attr->ia_gid;
6036 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
6037 +                       inode->i_tag = attr->ia_tag;
6038                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
6039                 spin_unlock(&inode->i_lock);
6040         }
6041 @@ -906,6 +916,9 @@ static int nfs_check_inode_attributes(st
6042         struct nfs_inode *nfsi = NFS_I(inode);
6043         loff_t cur_size, new_isize;
6044         unsigned long invalid = 0;
6045 +       uid_t uid;
6046 +       gid_t gid;
6047 +       tag_t tag;
6048  
6049  
6050         /* Has the inode gone and changed behind our back? */
6051 @@ -929,13 +942,18 @@ static int nfs_check_inode_attributes(st
6052                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
6053         }
6054  
6055 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
6056 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
6057 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
6058 +
6059         /* Have any file permissions changed? */
6060         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
6061                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
6062 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
6063 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
6064                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
6065 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
6066 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
6067                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
6068 +               /* maybe check for tag too? */
6069  
6070         /* Has the link count changed? */
6071         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
6072 @@ -1150,6 +1168,9 @@ static int nfs_update_inode(struct inode
6073         unsigned long invalid = 0;
6074         unsigned long now = jiffies;
6075         unsigned long save_cache_validity;
6076 +       uid_t uid;
6077 +       gid_t gid;
6078 +       tag_t tag;
6079  
6080         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
6081                         __func__, inode->i_sb->s_id, inode->i_ino,
6082 @@ -1252,6 +1273,9 @@ static int nfs_update_inode(struct inode
6083                                 | NFS_INO_REVAL_PAGECACHE
6084                                 | NFS_INO_REVAL_FORCED);
6085  
6086 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
6087 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
6088 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
6089  
6090         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
6091                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
6092 @@ -1273,9 +1297,9 @@ static int nfs_update_inode(struct inode
6093                                 | NFS_INO_REVAL_FORCED);
6094  
6095         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
6096 -               if (inode->i_uid != fattr->uid) {
6097 +               if (uid != fattr->uid) {
6098                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
6099 -                       inode->i_uid = fattr->uid;
6100 +                       uid = fattr->uid;
6101                 }
6102         } else if (server->caps & NFS_CAP_OWNER)
6103                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
6104 @@ -1284,9 +1308,9 @@ static int nfs_update_inode(struct inode
6105                                 | NFS_INO_REVAL_FORCED);
6106  
6107         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
6108 -               if (inode->i_gid != fattr->gid) {
6109 +               if (gid != fattr->gid) {
6110                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
6111 -                       inode->i_gid = fattr->gid;
6112 +                       gid = fattr->gid;
6113                 }
6114         } else if (server->caps & NFS_CAP_OWNER_GROUP)
6115                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
6116 @@ -1294,6 +1318,10 @@ static int nfs_update_inode(struct inode
6117                                 | NFS_INO_INVALID_ACL
6118                                 | NFS_INO_REVAL_FORCED);
6119  
6120 +       inode->i_uid = uid;
6121 +       inode->i_gid = gid;
6122 +       inode->i_tag = tag;
6123 +
6124         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
6125                 if (inode->i_nlink != fattr->nlink) {
6126                         invalid |= NFS_INO_INVALID_ATTR;
6127 diff -NurpP --minimal linux-2.6.33/fs/nfs/nfs3xdr.c linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/nfs3xdr.c
6128 --- linux-2.6.33/fs/nfs/nfs3xdr.c       2009-12-03 20:02:52.000000000 +0100
6129 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/nfs3xdr.c       2010-02-25 12:02:16.000000000 +0100
6130 @@ -21,6 +21,7 @@
6131  #include <linux/nfs3.h>
6132  #include <linux/nfs_fs.h>
6133  #include <linux/nfsacl.h>
6134 +#include <linux/vs_tag.h>
6135  #include "internal.h"
6136  
6137  #define NFSDBG_FACILITY                NFSDBG_XDR
6138 @@ -176,7 +177,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
6139  }
6140  
6141  static inline __be32 *
6142 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
6143 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
6144  {
6145         if (attr->ia_valid & ATTR_MODE) {
6146                 *p++ = xdr_one;
6147 @@ -184,15 +185,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
6148         } else {
6149                 *p++ = xdr_zero;
6150         }
6151 -       if (attr->ia_valid & ATTR_UID) {
6152 +       if (attr->ia_valid & ATTR_UID ||
6153 +               (tag && (attr->ia_valid & ATTR_TAG))) {
6154                 *p++ = xdr_one;
6155 -               *p++ = htonl(attr->ia_uid);
6156 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
6157         } else {
6158                 *p++ = xdr_zero;
6159         }
6160 -       if (attr->ia_valid & ATTR_GID) {
6161 +       if (attr->ia_valid & ATTR_GID ||
6162 +               (tag && (attr->ia_valid & ATTR_TAG))) {
6163                 *p++ = xdr_one;
6164 -               *p++ = htonl(attr->ia_gid);
6165 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
6166         } else {
6167                 *p++ = xdr_zero;
6168         }
6169 @@ -279,7 +282,8 @@ static int
6170  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
6171  {
6172         p = xdr_encode_fhandle(p, args->fh);
6173 -       p = xdr_encode_sattr(p, args->sattr);
6174 +       p = xdr_encode_sattr(p, args->sattr,
6175 +               req->rq_task->tk_client->cl_tag);
6176         *p++ = htonl(args->guard);
6177         if (args->guard)
6178                 p = xdr_encode_time3(p, &args->guardtime);
6179 @@ -384,7 +388,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
6180                 *p++ = args->verifier[0];
6181                 *p++ = args->verifier[1];
6182         } else
6183 -               p = xdr_encode_sattr(p, args->sattr);
6184 +               p = xdr_encode_sattr(p, args->sattr,
6185 +                       req->rq_task->tk_client->cl_tag);
6186  
6187         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6188         return 0;
6189 @@ -398,7 +403,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
6190  {
6191         p = xdr_encode_fhandle(p, args->fh);
6192         p = xdr_encode_array(p, args->name, args->len);
6193 -       p = xdr_encode_sattr(p, args->sattr);
6194 +       p = xdr_encode_sattr(p, args->sattr,
6195 +               req->rq_task->tk_client->cl_tag);
6196         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6197         return 0;
6198  }
6199 @@ -411,7 +417,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
6200  {
6201         p = xdr_encode_fhandle(p, args->fromfh);
6202         p = xdr_encode_array(p, args->fromname, args->fromlen);
6203 -       p = xdr_encode_sattr(p, args->sattr);
6204 +       p = xdr_encode_sattr(p, args->sattr,
6205 +               req->rq_task->tk_client->cl_tag);
6206         *p++ = htonl(args->pathlen);
6207         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6208  
6209 @@ -429,7 +436,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
6210         p = xdr_encode_fhandle(p, args->fh);
6211         p = xdr_encode_array(p, args->name, args->len);
6212         *p++ = htonl(args->type);
6213 -       p = xdr_encode_sattr(p, args->sattr);
6214 +       p = xdr_encode_sattr(p, args->sattr,
6215 +               req->rq_task->tk_client->cl_tag);
6216         if (args->type == NF3CHR || args->type == NF3BLK) {
6217                 *p++ = htonl(MAJOR(args->rdev));
6218                 *p++ = htonl(MINOR(args->rdev));
6219 diff -NurpP --minimal linux-2.6.33/fs/nfs/nfsroot.c linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/nfsroot.c
6220 --- linux-2.6.33/fs/nfs/nfsroot.c       2009-09-10 15:26:23.000000000 +0200
6221 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/nfsroot.c       2010-02-25 12:02:16.000000000 +0100
6222 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
6223  enum {
6224         /* Options that take integer arguments */
6225         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
6226 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
6227 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
6228         /* Options that take no arguments */
6229         Opt_soft, Opt_hard, Opt_intr,
6230         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
6231         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
6232 -       Opt_acl, Opt_noacl,
6233 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
6234         /* Error token */
6235         Opt_err
6236  };
6237 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
6238         {Opt_tcp, "tcp"},
6239         {Opt_acl, "acl"},
6240         {Opt_noacl, "noacl"},
6241 +       {Opt_tag, "tag"},
6242 +       {Opt_notag, "notag"},
6243 +       {Opt_tagid, "tagid=%u"},
6244         {Opt_err, NULL}
6245         
6246  };
6247 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
6248                         case Opt_noacl:
6249                                 nfs_data.flags |= NFS_MOUNT_NOACL;
6250                                 break;
6251 +#ifndef CONFIG_TAGGING_NONE
6252 +                       case Opt_tag:
6253 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6254 +                               break;
6255 +                       case Opt_notag:
6256 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
6257 +                               break;
6258 +#endif
6259 +#ifdef CONFIG_PROPAGATE
6260 +                       case Opt_tagid:
6261 +                               /* use args[0] */
6262 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6263 +                               break;
6264 +#endif
6265                         default:
6266                                 printk(KERN_WARNING "Root-NFS: unknown "
6267                                         "option: %s\n", p);
6268 diff -NurpP --minimal linux-2.6.33/fs/nfs/super.c linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/super.c
6269 --- linux-2.6.33/fs/nfs/super.c 2010-02-25 11:52:05.000000000 +0100
6270 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/nfs/super.c 2010-02-25 12:02:16.000000000 +0100
6271 @@ -53,6 +53,7 @@
6272  #include <linux/nfs_xdr.h>
6273  #include <linux/magic.h>
6274  #include <linux/parser.h>
6275 +#include <linux/vs_tag.h>
6276  
6277  #include <asm/system.h>
6278  #include <asm/uaccess.h>
6279 @@ -585,6 +586,7 @@ static void nfs_show_mount_options(struc
6280                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6281                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
6282                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
6283 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6284                 { 0, NULL, NULL }
6285         };
6286         const struct proc_nfs_info *nfs_infop;
6287 diff -NurpP --minimal linux-2.6.33/fs/nfsd/auth.c linux-2.6.33-vs2.3.0.36.30.1/fs/nfsd/auth.c
6288 --- linux-2.6.33/fs/nfsd/auth.c 2010-02-25 11:52:05.000000000 +0100
6289 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/nfsd/auth.c 2010-02-25 13:17:41.000000000 +0100
6290 @@ -1,6 +1,7 @@
6291  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
6292  
6293  #include <linux/sched.h>
6294 +#include <linux/vs_tag.h>
6295  #include "nfsd.h"
6296  #include "auth.h"
6297  
6298 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6299  
6300         new->fsuid = rqstp->rq_cred.cr_uid;
6301         new->fsgid = rqstp->rq_cred.cr_gid;
6302 +       /* FIXME: this desperately needs a tag :)
6303 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6304 +                       */
6305  
6306         rqgi = rqstp->rq_cred.cr_group_info;
6307  
6308 diff -NurpP --minimal linux-2.6.33/fs/nfsd/nfs3xdr.c linux-2.6.33-vs2.3.0.36.30.1/fs/nfsd/nfs3xdr.c
6309 --- linux-2.6.33/fs/nfsd/nfs3xdr.c      2010-02-25 11:52:05.000000000 +0100
6310 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/nfsd/nfs3xdr.c      2010-02-25 13:18:45.000000000 +0100
6311 @@ -7,6 +7,7 @@
6312   */
6313  
6314  #include <linux/namei.h>
6315 +#include <linux/vs_tag.h>
6316  #include "xdr3.h"
6317  #include "auth.h"
6318  
6319 @@ -95,6 +96,8 @@ static __be32 *
6320  decode_sattr3(__be32 *p, struct iattr *iap)
6321  {
6322         u32     tmp;
6323 +       uid_t   uid = 0;
6324 +       gid_t   gid = 0;
6325  
6326         iap->ia_valid = 0;
6327  
6328 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6329         }
6330         if (*p++) {
6331                 iap->ia_valid |= ATTR_UID;
6332 -               iap->ia_uid = ntohl(*p++);
6333 +               uid = ntohl(*p++);
6334         }
6335         if (*p++) {
6336                 iap->ia_valid |= ATTR_GID;
6337 -               iap->ia_gid = ntohl(*p++);
6338 +               gid = ntohl(*p++);
6339         }
6340 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6341 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6342 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6343         if (*p++) {
6344                 u64     newsize;
6345  
6346 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6347         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6348         *p++ = htonl((u32) stat->mode);
6349         *p++ = htonl((u32) stat->nlink);
6350 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6351 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6352 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6353 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6354 +               stat->uid, stat->tag)));
6355 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6356 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6357 +               stat->gid, stat->tag)));
6358         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6359                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6360         } else {
6361 diff -NurpP --minimal linux-2.6.33/fs/nfsd/nfs4xdr.c linux-2.6.33-vs2.3.0.36.30.1/fs/nfsd/nfs4xdr.c
6362 --- linux-2.6.33/fs/nfsd/nfs4xdr.c      2010-02-25 11:52:05.000000000 +0100
6363 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/nfsd/nfs4xdr.c      2010-02-25 12:02:16.000000000 +0100
6364 @@ -46,6 +46,7 @@
6365  #include <linux/nfsd_idmap.h>
6366  #include <linux/nfs4_acl.h>
6367  #include <linux/sunrpc/svcauth_gss.h>
6368 +#include <linux/vs_tag.h>
6369  
6370  #include "xdr4.h"
6371  #include "vfs.h"
6372 @@ -2042,14 +2043,18 @@ out_acl:
6373                 WRITE32(stat.nlink);
6374         }
6375         if (bmval1 & FATTR4_WORD1_OWNER) {
6376 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6377 +               status = nfsd4_encode_user(rqstp,
6378 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6379 +                       stat.uid, stat.tag), &p, &buflen);
6380                 if (status == nfserr_resource)
6381                         goto out_resource;
6382                 if (status)
6383                         goto out;
6384         }
6385         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6386 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6387 +               status = nfsd4_encode_group(rqstp,
6388 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6389 +                       stat.gid, stat.tag), &p, &buflen);
6390                 if (status == nfserr_resource)
6391                         goto out_resource;
6392                 if (status)
6393 diff -NurpP --minimal linux-2.6.33/fs/nfsd/nfsxdr.c linux-2.6.33-vs2.3.0.36.30.1/fs/nfsd/nfsxdr.c
6394 --- linux-2.6.33/fs/nfsd/nfsxdr.c       2010-02-25 11:52:05.000000000 +0100
6395 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/nfsd/nfsxdr.c       2010-02-25 13:18:10.000000000 +0100
6396 @@ -6,6 +6,7 @@
6397  
6398  #include "xdr.h"
6399  #include "auth.h"
6400 +#include <linux/vs_tag.h>
6401  
6402  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6403  
6404 @@ -88,6 +89,8 @@ static __be32 *
6405  decode_sattr(__be32 *p, struct iattr *iap)
6406  {
6407         u32     tmp, tmp1;
6408 +       uid_t   uid = 0;
6409 +       gid_t   gid = 0;
6410  
6411         iap->ia_valid = 0;
6412  
6413 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6414         }
6415         if ((tmp = ntohl(*p++)) != (u32)-1) {
6416                 iap->ia_valid |= ATTR_UID;
6417 -               iap->ia_uid = tmp;
6418 +               uid = tmp;
6419         }
6420         if ((tmp = ntohl(*p++)) != (u32)-1) {
6421                 iap->ia_valid |= ATTR_GID;
6422 -               iap->ia_gid = tmp;
6423 +               gid = tmp;
6424         }
6425 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6426 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6427 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6428         if ((tmp = ntohl(*p++)) != (u32)-1) {
6429                 iap->ia_valid |= ATTR_SIZE;
6430                 iap->ia_size = tmp;
6431 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6432         *p++ = htonl(nfs_ftypes[type >> 12]);
6433         *p++ = htonl((u32) stat->mode);
6434         *p++ = htonl((u32) stat->nlink);
6435 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6436 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6437 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6438 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6439 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6440 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6441  
6442         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6443                 *p++ = htonl(NFS_MAXPATHLEN);
6444 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/dlm/dlmfs.c linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/dlm/dlmfs.c
6445 --- linux-2.6.33/fs/ocfs2/dlm/dlmfs.c   2009-12-03 20:02:53.000000000 +0100
6446 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/dlm/dlmfs.c   2010-02-25 12:02:16.000000000 +0100
6447 @@ -43,6 +43,7 @@
6448  #include <linux/init.h>
6449  #include <linux/string.h>
6450  #include <linux/backing-dev.h>
6451 +#include <linux/vs_tag.h>
6452  
6453  #include <asm/uaccess.h>
6454  
6455 @@ -342,6 +343,7 @@ static struct inode *dlmfs_get_root_inod
6456                 inode->i_mode = mode;
6457                 inode->i_uid = current_fsuid();
6458                 inode->i_gid = current_fsgid();
6459 +               inode->i_tag = dx_current_fstag(sb);
6460                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6461                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6462                 inc_nlink(inode);
6463 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6464         inode->i_mode = mode;
6465         inode->i_uid = current_fsuid();
6466         inode->i_gid = current_fsgid();
6467 +       inode->i_tag = dx_current_fstag(sb);
6468         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6469         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6470  
6471 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/dlmglue.c linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/dlmglue.c
6472 --- linux-2.6.33/fs/ocfs2/dlmglue.c     2010-02-25 11:52:06.000000000 +0100
6473 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/dlmglue.c     2010-02-25 12:02:16.000000000 +0100
6474 @@ -2023,6 +2023,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6475         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6476         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6477         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6478 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6479         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6480         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6481         lvb->lvb_iatime_packed  =
6482 @@ -2077,6 +2078,7 @@ static void ocfs2_refresh_inode_from_lvb
6483  
6484         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6485         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6486 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6487         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6488         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6489         ocfs2_unpack_timespec(&inode->i_atime,
6490 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/dlmglue.h linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/dlmglue.h
6491 --- linux-2.6.33/fs/ocfs2/dlmglue.h     2009-12-03 20:02:53.000000000 +0100
6492 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/dlmglue.h     2010-02-25 12:02:16.000000000 +0100
6493 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6494         __be16       lvb_inlink;
6495         __be32       lvb_iattr;
6496         __be32       lvb_igeneration;
6497 -       __be32       lvb_reserved2;
6498 +       __be16       lvb_itag;
6499 +       __be16       lvb_reserved2;
6500  };
6501  
6502  #define OCFS2_QINFO_LVB_VERSION 1
6503 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/file.c linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/file.c
6504 --- linux-2.6.33/fs/ocfs2/file.c        2010-02-25 11:52:06.000000000 +0100
6505 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/file.c        2010-02-25 12:02:16.000000000 +0100
6506 @@ -960,13 +960,15 @@ int ocfs2_setattr(struct dentry *dentry,
6507                 mlog(0, "uid change: %d\n", attr->ia_uid);
6508         if (attr->ia_valid & ATTR_GID)
6509                 mlog(0, "gid change: %d\n", attr->ia_gid);
6510 +       if (attr->ia_valid & ATTR_TAG)
6511 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6512         if (attr->ia_valid & ATTR_SIZE)
6513                 mlog(0, "size change...\n");
6514         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6515                 mlog(0, "time change...\n");
6516  
6517  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6518 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6519 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6520         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6521                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6522                 return 0;
6523 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/inode.c
6524 --- linux-2.6.33/fs/ocfs2/inode.c       2010-02-25 11:52:06.000000000 +0100
6525 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/inode.c       2010-02-25 12:02:16.000000000 +0100
6526 @@ -29,6 +29,7 @@
6527  #include <linux/highmem.h>
6528  #include <linux/pagemap.h>
6529  #include <linux/quotaops.h>
6530 +#include <linux/vs_tag.h>
6531  
6532  #include <asm/byteorder.h>
6533  
6534 @@ -79,11 +80,13 @@ void ocfs2_set_inode_flags(struct inode 
6535  {
6536         unsigned int flags = OCFS2_I(inode)->ip_attr;
6537  
6538 -       inode->i_flags &= ~(S_IMMUTABLE |
6539 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6540                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6541  
6542         if (flags & OCFS2_IMMUTABLE_FL)
6543                 inode->i_flags |= S_IMMUTABLE;
6544 +       if (flags & OCFS2_IXUNLINK_FL)
6545 +               inode->i_flags |= S_IXUNLINK;
6546  
6547         if (flags & OCFS2_SYNC_FL)
6548                 inode->i_flags |= S_SYNC;
6549 @@ -93,25 +96,44 @@ void ocfs2_set_inode_flags(struct inode 
6550                 inode->i_flags |= S_NOATIME;
6551         if (flags & OCFS2_DIRSYNC_FL)
6552                 inode->i_flags |= S_DIRSYNC;
6553 +
6554 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6555 +
6556 +       if (flags & OCFS2_BARRIER_FL)
6557 +               inode->i_vflags |= V_BARRIER;
6558 +       if (flags & OCFS2_COW_FL)
6559 +               inode->i_vflags |= V_COW;
6560  }
6561  
6562  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6563  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6564  {
6565         unsigned int flags = oi->vfs_inode.i_flags;
6566 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6567 +
6568 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6569 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6570 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6571 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6572 +
6573 +       if (flags & S_IMMUTABLE)
6574 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6575 +       if (flags & S_IXUNLINK)
6576 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6577  
6578 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6579 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6580         if (flags & S_SYNC)
6581                 oi->ip_attr |= OCFS2_SYNC_FL;
6582         if (flags & S_APPEND)
6583                 oi->ip_attr |= OCFS2_APPEND_FL;
6584 -       if (flags & S_IMMUTABLE)
6585 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6586         if (flags & S_NOATIME)
6587                 oi->ip_attr |= OCFS2_NOATIME_FL;
6588         if (flags & S_DIRSYNC)
6589                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6590 +
6591 +       if (vflags & V_BARRIER)
6592 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6593 +       if (vflags & V_COW)
6594 +               oi->ip_attr |= OCFS2_COW_FL;
6595  }
6596  
6597  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6598 @@ -246,6 +268,8 @@ void ocfs2_populate_inode(struct inode *
6599         struct super_block *sb;
6600         struct ocfs2_super *osb;
6601         int use_plocks = 1;
6602 +       uid_t uid;
6603 +       gid_t gid;
6604  
6605         mlog_entry("(0x%p, size:%llu)\n", inode,
6606                    (unsigned long long)le64_to_cpu(fe->i_size));
6607 @@ -277,8 +301,12 @@ void ocfs2_populate_inode(struct inode *
6608         inode->i_generation = le32_to_cpu(fe->i_generation);
6609         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6610         inode->i_mode = le16_to_cpu(fe->i_mode);
6611 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6612 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6613 +       uid = le32_to_cpu(fe->i_uid);
6614 +       gid = le32_to_cpu(fe->i_gid);
6615 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6616 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6617 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6618 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6619  
6620         /* Fast symlinks will have i_size but no allocated clusters. */
6621         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6622 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/inode.h linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/inode.h
6623 --- linux-2.6.33/fs/ocfs2/inode.h       2009-12-03 20:02:53.000000000 +0100
6624 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/inode.h       2010-02-25 12:02:16.000000000 +0100
6625 @@ -150,6 +150,7 @@ struct buffer_head *ocfs2_bread(struct i
6626  
6627  void ocfs2_set_inode_flags(struct inode *inode);
6628  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6629 +int ocfs2_sync_flags(struct inode *inode, int, int);
6630  
6631  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6632  {
6633 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/ioctl.c linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/ioctl.c
6634 --- linux-2.6.33/fs/ocfs2/ioctl.c       2010-02-25 11:52:06.000000000 +0100
6635 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/ioctl.c       2010-02-25 12:02:16.000000000 +0100
6636 @@ -43,7 +43,41 @@ static int ocfs2_get_inode_attr(struct i
6637         return status;
6638  }
6639  
6640 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6641 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6642 +{
6643 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6644 +       struct buffer_head *bh = NULL;
6645 +       handle_t *handle = NULL;
6646 +       int status;
6647 +
6648 +       status = ocfs2_inode_lock(inode, &bh, 1);
6649 +       if (status < 0) {
6650 +               mlog_errno(status);
6651 +               return status;
6652 +       }
6653 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6654 +       if (IS_ERR(handle)) {
6655 +               status = PTR_ERR(handle);
6656 +               mlog_errno(status);
6657 +               goto bail_unlock;
6658 +       }
6659 +
6660 +       inode->i_flags = flags;
6661 +       inode->i_vflags = vflags;
6662 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6663 +
6664 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6665 +       if (status < 0)
6666 +               mlog_errno(status);
6667 +
6668 +       ocfs2_commit_trans(osb, handle);
6669 +bail_unlock:
6670 +       ocfs2_inode_unlock(inode, 1);
6671 +       brelse(bh);
6672 +       return status;
6673 +}
6674 +
6675 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6676                                 unsigned mask)
6677  {
6678         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6679 @@ -68,6 +102,11 @@ static int ocfs2_set_inode_attr(struct i
6680         if (!S_ISDIR(inode->i_mode))
6681                 flags &= ~OCFS2_DIRSYNC_FL;
6682  
6683 +       if (IS_BARRIER(inode)) {
6684 +               vxwprintk_task(1, "messing with the barrier.");
6685 +               goto bail_unlock;
6686 +       }
6687 +
6688         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6689         if (IS_ERR(handle)) {
6690                 status = PTR_ERR(handle);
6691 @@ -109,6 +148,7 @@ bail:
6692         return status;
6693  }
6694  
6695 +
6696  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6697  {
6698         struct inode *inode = filp->f_path.dentry->d_inode;
6699 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/namei.c linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/namei.c
6700 --- linux-2.6.33/fs/ocfs2/namei.c       2010-02-25 11:52:06.000000000 +0100
6701 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/namei.c       2010-02-25 12:02:16.000000000 +0100
6702 @@ -41,6 +41,7 @@
6703  #include <linux/slab.h>
6704  #include <linux/highmem.h>
6705  #include <linux/quotaops.h>
6706 +#include <linux/vs_tag.h>
6707  
6708  #define MLOG_MASK_PREFIX ML_NAMEI
6709  #include <cluster/masklog.h>
6710 @@ -481,6 +482,7 @@ static int ocfs2_mknod_locked(struct ocf
6711         u64 fe_blkno = 0;
6712         u16 suballoc_bit;
6713         u16 feat;
6714 +       tag_t tag;
6715  
6716         *new_fe_bh = NULL;
6717  
6718 @@ -524,8 +526,11 @@ static int ocfs2_mknod_locked(struct ocf
6719         fe->i_blkno = cpu_to_le64(fe_blkno);
6720         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6721         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6722 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6723 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6724 +
6725 +       tag = dx_current_fstag(osb->sb);
6726 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6727 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6728 +       inode->i_tag = tag;
6729         fe->i_mode = cpu_to_le16(inode->i_mode);
6730         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6731                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6732 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/ocfs2_fs.h linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/ocfs2_fs.h
6733 --- linux-2.6.33/fs/ocfs2/ocfs2_fs.h    2010-02-25 11:52:06.000000000 +0100
6734 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/ocfs2_fs.h    2010-02-25 12:02:16.000000000 +0100
6735 @@ -231,18 +231,23 @@
6736  #define OCFS2_HAS_REFCOUNT_FL   (0x0010)
6737  
6738  /* Inode attributes, keep in sync with EXT2 */
6739 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6740 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6741 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6742 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6743 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6744 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6745 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6746 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6747 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6748 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6749 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6750 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6751 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6752 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6753 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6754 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6755 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6756  
6757 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6758 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6759 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6760 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6761 +
6762 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6763 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6764 +
6765 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6766 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6767  
6768  /*
6769   * Extent record flags (e_node.leaf.flags)
6770 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/ocfs2.h linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/ocfs2.h
6771 --- linux-2.6.33/fs/ocfs2/ocfs2.h       2010-02-25 11:52:06.000000000 +0100
6772 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/ocfs2.h       2010-02-25 13:22:33.000000000 +0100
6773 @@ -254,6 +254,7 @@ enum ocfs2_mount_options
6774                                                    control lists */
6775         OCFS2_MOUNT_USRQUOTA = 1 << 10, /* We support user quotas */
6776         OCFS2_MOUNT_GRPQUOTA = 1 << 11, /* We support group quotas */
6777 +       OCFS2_MOUNT_TAGGED = 1 << 12, /* use tagging */
6778  };
6779  
6780  #define OCFS2_OSB_SOFT_RO                      0x0001
6781 diff -NurpP --minimal linux-2.6.33/fs/ocfs2/super.c linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/super.c
6782 --- linux-2.6.33/fs/ocfs2/super.c       2010-02-25 11:52:06.000000000 +0100
6783 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/ocfs2/super.c       2010-02-25 13:23:24.000000000 +0100
6784 @@ -175,6 +175,7 @@ enum {
6785         Opt_noacl,
6786         Opt_usrquota,
6787         Opt_grpquota,
6788 +       Opt_tag, Opt_notag, Opt_tagid,
6789         Opt_err,
6790  };
6791  
6792 @@ -201,6 +202,9 @@ static const match_table_t tokens = {
6793         {Opt_noacl, "noacl"},
6794         {Opt_usrquota, "usrquota"},
6795         {Opt_grpquota, "grpquota"},
6796 +       {Opt_tag, "tag"},
6797 +       {Opt_notag, "notag"},
6798 +       {Opt_tagid, "tagid=%u"},
6799         {Opt_err, NULL}
6800  };
6801  
6802 @@ -608,6 +612,13 @@ static int ocfs2_remount(struct super_bl
6803                 goto out;
6804         }
6805  
6806 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6807 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6808 +               ret = -EINVAL;
6809 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6810 +               goto out;
6811 +       }
6812 +
6813         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6814             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6815                 ret = -EINVAL;
6816 @@ -1138,6 +1149,9 @@ static int ocfs2_fill_super(struct super
6817  
6818         ocfs2_complete_mount_recovery(osb);
6819  
6820 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6821 +               sb->s_flags |= MS_TAGGED;
6822 +
6823         if (ocfs2_mount_local(osb))
6824                 snprintf(nodestr, sizeof(nodestr), "local");
6825         else
6826 @@ -1429,6 +1443,20 @@ static int ocfs2_parse_options(struct su
6827                         mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
6828                         mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
6829                         break;
6830 +#ifndef CONFIG_TAGGING_NONE
6831 +               case Opt_tag:
6832 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6833 +                       break;
6834 +               case Opt_notag:
6835 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6836 +                       break;
6837 +#endif
6838 +#ifdef CONFIG_PROPAGATE
6839 +               case Opt_tagid:
6840 +                       /* use args[0] */
6841 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6842 +                       break;
6843 +#endif
6844                 default:
6845                         mlog(ML_ERROR,
6846                              "Unrecognized mount option \"%s\" "
6847 diff -NurpP --minimal linux-2.6.33/fs/open.c linux-2.6.33-vs2.3.0.36.30.1/fs/open.c
6848 --- linux-2.6.33/fs/open.c      2010-02-25 11:52:06.000000000 +0100
6849 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/open.c      2010-02-25 13:17:13.000000000 +0100
6850 @@ -31,6 +31,10 @@
6851  #include <linux/falloc.h>
6852  #include <linux/fs_struct.h>
6853  #include <linux/ima.h>
6854 +#include <linux/vs_base.h>
6855 +#include <linux/vs_limit.h>
6856 +#include <linux/vs_tag.h>
6857 +#include <linux/vs_cowbl.h>
6858  
6859  #include "internal.h"
6860  
6861 @@ -39,16 +43,20 @@ int vfs_statfs(struct dentry *dentry, st
6862         int retval = -ENODEV;
6863  
6864         if (dentry) {
6865 +               struct super_block *sb = dentry->d_sb;
6866 +
6867                 retval = -ENOSYS;
6868 -               if (dentry->d_sb->s_op->statfs) {
6869 +               if (sb->s_op->statfs) {
6870                         memset(buf, 0, sizeof(*buf));
6871                         retval = security_sb_statfs(dentry);
6872                         if (retval)
6873                                 return retval;
6874 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6875 +                       retval = sb->s_op->statfs(dentry, buf);
6876                         if (retval == 0 && buf->f_frsize == 0)
6877                                 buf->f_frsize = buf->f_bsize;
6878                 }
6879 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6880 +                       vx_vsi_statfs(sb, buf);
6881         }
6882         return retval;
6883  }
6884 @@ -650,6 +658,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6885         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6886         if (error)
6887                 goto out;
6888 +
6889 +       error = cow_check_and_break(&path);
6890 +       if (error)
6891 +               goto dput_and_out;
6892         inode = path.dentry->d_inode;
6893  
6894         error = mnt_want_write(path.mnt);
6895 @@ -687,11 +699,11 @@ static int chown_common(struct path *pat
6896         newattrs.ia_valid =  ATTR_CTIME;
6897         if (user != (uid_t) -1) {
6898                 newattrs.ia_valid |= ATTR_UID;
6899 -               newattrs.ia_uid = user;
6900 +               newattrs.ia_uid = dx_map_uid(user);
6901         }
6902         if (group != (gid_t) -1) {
6903                 newattrs.ia_valid |= ATTR_GID;
6904 -               newattrs.ia_gid = group;
6905 +               newattrs.ia_gid = dx_map_gid(group);
6906         }
6907         if (!S_ISDIR(inode->i_mode))
6908                 newattrs.ia_valid |=
6909 @@ -716,6 +728,10 @@ SYSCALL_DEFINE3(chown, const char __user
6910         error = mnt_want_write(path.mnt);
6911         if (error)
6912                 goto out_release;
6913 +#ifdef CONFIG_VSERVER_COWBL
6914 +       error = cow_check_and_break(&path);
6915 +       if (!error)
6916 +#endif
6917         error = chown_common(&path, user, group);
6918         mnt_drop_write(path.mnt);
6919  out_release:
6920 @@ -741,6 +757,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6921         error = mnt_want_write(path.mnt);
6922         if (error)
6923                 goto out_release;
6924 +#ifdef CONFIG_VSERVER_COWBL
6925 +       error = cow_check_and_break(&path);
6926 +       if (!error)
6927 +#endif
6928         error = chown_common(&path, user, group);
6929         mnt_drop_write(path.mnt);
6930  out_release:
6931 @@ -760,6 +780,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6932         error = mnt_want_write(path.mnt);
6933         if (error)
6934                 goto out_release;
6935 +#ifdef CONFIG_VSERVER_COWBL
6936 +       error = cow_check_and_break(&path);
6937 +       if (!error)
6938 +#endif
6939         error = chown_common(&path, user, group);
6940         mnt_drop_write(path.mnt);
6941  out_release:
6942 @@ -1006,6 +1030,7 @@ static void __put_unused_fd(struct files
6943         __FD_CLR(fd, fdt->open_fds);
6944         if (fd < files->next_fd)
6945                 files->next_fd = fd;
6946 +       vx_openfd_dec(fd);
6947  }
6948  
6949  void put_unused_fd(unsigned int fd)
6950 diff -NurpP --minimal linux-2.6.33/fs/proc/array.c linux-2.6.33-vs2.3.0.36.30.1/fs/proc/array.c
6951 --- linux-2.6.33/fs/proc/array.c        2010-02-25 11:52:06.000000000 +0100
6952 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/proc/array.c        2010-02-25 12:02:16.000000000 +0100
6953 @@ -83,6 +83,8 @@
6954  #include <linux/ptrace.h>
6955  #include <linux/tracehook.h>
6956  #include <linux/swapops.h>
6957 +#include <linux/vs_context.h>
6958 +#include <linux/vs_network.h>
6959  
6960  #include <asm/pgtable.h>
6961  #include <asm/processor.h>
6962 @@ -172,6 +174,9 @@ static inline void task_state(struct seq
6963         rcu_read_lock();
6964         ppid = pid_alive(p) ?
6965                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6966 +       if (unlikely(vx_current_initpid(p->pid)))
6967 +               ppid = 0;
6968 +
6969         tpid = 0;
6970         if (pid_alive(p)) {
6971                 struct task_struct *tracer = tracehook_tracer_task(p);
6972 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6973  }
6974  
6975  static void render_cap_t(struct seq_file *m, const char *header,
6976 -                       kernel_cap_t *a)
6977 +                       struct vx_info *vxi, kernel_cap_t *a)
6978  {
6979         unsigned __capi;
6980  
6981 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6982         cap_bset        = cred->cap_bset;
6983         rcu_read_unlock();
6984  
6985 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6986 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6987 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6988 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6989 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6990 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6991 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6992 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6993 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6994  }
6995  
6996  static inline void task_context_switch_counts(struct seq_file *m,
6997 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6998         seq_printf(m, "\n");
6999  }
7000  
7001 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7002 +                       struct pid *pid, struct task_struct *task)
7003 +{
7004 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
7005 +                       "Count:\t%u\n"
7006 +                       "uts:\t%p(%c)\n"
7007 +                       "ipc:\t%p(%c)\n"
7008 +                       "mnt:\t%p(%c)\n"
7009 +                       "pid:\t%p(%c)\n"
7010 +                       "net:\t%p(%c)\n",
7011 +                       task->nsproxy,
7012 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
7013 +                       atomic_read(&task->nsproxy->count),
7014 +                       task->nsproxy->uts_ns,
7015 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
7016 +                       task->nsproxy->ipc_ns,
7017 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
7018 +                       task->nsproxy->mnt_ns,
7019 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
7020 +                       task->nsproxy->pid_ns,
7021 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
7022 +                       task->nsproxy->net_ns,
7023 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
7024 +       return 0;
7025 +}
7026 +
7027 +void task_vs_id(struct seq_file *m, struct task_struct *task)
7028 +{
7029 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
7030 +               return;
7031 +
7032 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
7033 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
7034 +}
7035 +
7036 +
7037  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
7038                         struct pid *pid, struct task_struct *task)
7039  {
7040 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
7041         task_cap(m, task);
7042         task_cpus_allowed(m, task);
7043         cpuset_task_status_allowed(m, task);
7044 +       task_vs_id(m, task);
7045  #if defined(CONFIG_S390)
7046         task_show_regs(m, task);
7047  #endif
7048 @@ -465,6 +508,17 @@ static int do_task_stat(struct seq_file 
7049         /* convert nsec -> ticks */
7050         start_time = nsec_to_clock_t(start_time);
7051  
7052 +       /* fixup start time for virt uptime */
7053 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
7054 +               unsigned long long bias =
7055 +                       current->vx_info->cvirt.bias_clock;
7056 +
7057 +               if (start_time > bias)
7058 +                       start_time -= bias;
7059 +               else
7060 +                       start_time = 0;
7061 +       }
7062 +
7063         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
7064  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
7065  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
7066 diff -NurpP --minimal linux-2.6.33/fs/proc/base.c linux-2.6.33-vs2.3.0.36.30.1/fs/proc/base.c
7067 --- linux-2.6.33/fs/proc/base.c 2010-02-25 11:52:06.000000000 +0100
7068 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/proc/base.c 2010-02-25 12:02:16.000000000 +0100
7069 @@ -81,6 +81,8 @@
7070  #include <linux/elf.h>
7071  #include <linux/pid_namespace.h>
7072  #include <linux/fs_struct.h>
7073 +#include <linux/vs_context.h>
7074 +#include <linux/vs_network.h>
7075  #include "internal.h"
7076  
7077  /* NOTE:
7078 @@ -1047,12 +1049,17 @@ static ssize_t oom_adjust_write(struct f
7079                 return -ESRCH;
7080         }
7081  
7082 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
7083 +       if (oom_adjust < task->signal->oom_adj &&
7084 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
7085                 unlock_task_sighand(task, &flags);
7086                 put_task_struct(task);
7087                 return -EACCES;
7088         }
7089  
7090 +       /* prevent guest processes from circumventing the oom killer */
7091 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
7092 +               oom_adjust = OOM_ADJUST_MIN;
7093 +
7094         task->signal->oom_adj = oom_adjust;
7095  
7096         unlock_task_sighand(task, &flags);
7097 @@ -1092,7 +1099,7 @@ static ssize_t proc_loginuid_write(struc
7098         ssize_t length;
7099         uid_t loginuid;
7100  
7101 -       if (!capable(CAP_AUDIT_CONTROL))
7102 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
7103                 return -EPERM;
7104  
7105         if (current != pid_task(proc_pid(inode), PIDTYPE_PID))
7106 @@ -1523,6 +1530,8 @@ static struct inode *proc_pid_make_inode
7107                 inode->i_gid = cred->egid;
7108                 rcu_read_unlock();
7109         }
7110 +       /* procfs is xid tagged */
7111 +       inode->i_tag = (tag_t)vx_task_xid(task);
7112         security_task_to_inode(task, inode);
7113  
7114  out:
7115 @@ -2073,6 +2082,13 @@ static struct dentry *proc_pident_lookup
7116         if (!task)
7117                 goto out_no_task;
7118  
7119 +       /* TODO: maybe we can come up with a generic approach? */
7120 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
7121 +               (dentry->d_name.len == 5) &&
7122 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
7123 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
7124 +               goto out;
7125 +
7126         /*
7127          * Yes, it does not scale. And it should not. Don't add
7128          * new entries into /proc/<tgid>/ without very good reasons.
7129 @@ -2478,7 +2494,7 @@ out_iput:
7130  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
7131  {
7132         struct dentry *error;
7133 -       struct task_struct *task = get_proc_task(dir);
7134 +       struct task_struct *task = get_proc_task_real(dir);
7135         const struct pid_entry *p, *last;
7136  
7137         error = ERR_PTR(-ENOENT);
7138 @@ -2568,6 +2584,9 @@ static int proc_pid_personality(struct s
7139  static const struct file_operations proc_task_operations;
7140  static const struct inode_operations proc_task_inode_operations;
7141  
7142 +extern int proc_pid_vx_info(struct task_struct *, char *);
7143 +extern int proc_pid_nx_info(struct task_struct *, char *);
7144 +
7145  static const struct pid_entry tgid_base_stuff[] = {
7146         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
7147         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
7148 @@ -2627,6 +2646,8 @@ static const struct pid_entry tgid_base_
7149  #ifdef CONFIG_CGROUPS
7150         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
7151  #endif
7152 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
7153 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
7154         INF("oom_score",  S_IRUGO, proc_oom_score),
7155         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
7156  #ifdef CONFIG_AUDITSYSCALL
7157 @@ -2642,6 +2663,7 @@ static const struct pid_entry tgid_base_
7158  #ifdef CONFIG_TASK_IO_ACCOUNTING
7159         INF("io",       S_IRUGO, proc_tgid_io_accounting),
7160  #endif
7161 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
7162  };
7163  
7164  static int proc_tgid_base_readdir(struct file * filp,
7165 @@ -2833,7 +2855,7 @@ retry:
7166         iter.task = NULL;
7167         pid = find_ge_pid(iter.tgid, ns);
7168         if (pid) {
7169 -               iter.tgid = pid_nr_ns(pid, ns);
7170 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
7171                 iter.task = pid_task(pid, PIDTYPE_PID);
7172                 /* What we to know is if the pid we have find is the
7173                  * pid of a thread_group_leader.  Testing for task
7174 @@ -2863,7 +2885,7 @@ static int proc_pid_fill_cache(struct fi
7175         struct tgid_iter iter)
7176  {
7177         char name[PROC_NUMBUF];
7178 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
7179 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
7180         return proc_fill_cache(filp, dirent, filldir, name, len,
7181                                 proc_pid_instantiate, iter.task, NULL);
7182  }
7183 @@ -2872,7 +2894,7 @@ static int proc_pid_fill_cache(struct fi
7184  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
7185  {
7186         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
7187 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
7188 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
7189         struct tgid_iter iter;
7190         struct pid_namespace *ns;
7191  
7192 @@ -2892,6 +2914,8 @@ int proc_pid_readdir(struct file * filp,
7193              iter.task;
7194              iter.tgid += 1, iter = next_tgid(ns, iter)) {
7195                 filp->f_pos = iter.tgid + TGID_OFFSET;
7196 +               if (!vx_proc_task_visible(iter.task))
7197 +                       continue;
7198                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
7199                         put_task_struct(iter.task);
7200                         goto out;
7201 @@ -3039,6 +3063,8 @@ static struct dentry *proc_task_lookup(s
7202         tid = name_to_int(dentry);
7203         if (tid == ~0U)
7204                 goto out;
7205 +       if (vx_current_initpid(tid))
7206 +               goto out;
7207  
7208         ns = dentry->d_sb->s_fs_info;
7209         rcu_read_lock();
7210 diff -NurpP --minimal linux-2.6.33/fs/proc/generic.c linux-2.6.33-vs2.3.0.36.30.1/fs/proc/generic.c
7211 --- linux-2.6.33/fs/proc/generic.c      2010-02-25 11:52:06.000000000 +0100
7212 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/proc/generic.c      2010-02-25 13:20:40.000000000 +0100
7213 @@ -20,6 +20,7 @@
7214  #include <linux/bitops.h>
7215  #include <linux/spinlock.h>
7216  #include <linux/completion.h>
7217 +#include <linux/vserver/inode.h>
7218  #include <asm/uaccess.h>
7219  
7220  #include "internal.h"
7221 @@ -425,6 +426,8 @@ struct dentry *proc_lookup_de(struct pro
7222         for (de = de->subdir; de ; de = de->next) {
7223                 if (de->namelen != dentry->d_name.len)
7224                         continue;
7225 +                       if (!vx_hide_check(0, de->vx_flags))
7226 +                               continue;
7227                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
7228                         unsigned int ino;
7229  
7230 @@ -433,6 +436,8 @@ struct dentry *proc_lookup_de(struct pro
7231                         spin_unlock(&proc_subdir_lock);
7232                         error = -EINVAL;
7233                         inode = proc_get_inode(dir->i_sb, ino, de);
7234 +                               /* generic proc entries belong to the host */
7235 +                               inode->i_tag = 0;
7236                         goto out_unlock;
7237                 }
7238         }
7239 @@ -510,6 +515,8 @@ int proc_readdir_de(struct proc_dir_entr
7240  
7241                                 /* filldir passes info to user space */
7242                                 pde_get(de);
7243 +                               if (!vx_hide_check(0, de->vx_flags))
7244 +                                       goto skip;
7245                                 spin_unlock(&proc_subdir_lock);
7246                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
7247                                             de->low_ino, de->mode >> 12) < 0) {
7248 @@ -517,6 +524,7 @@ int proc_readdir_de(struct proc_dir_entr
7249                                         goto out;
7250                                 }
7251                                 spin_lock(&proc_subdir_lock);
7252 +                       skip:
7253                                 filp->f_pos++;
7254                                 next = de->next;
7255                                 pde_put(de);
7256 @@ -631,6 +639,7 @@ static struct proc_dir_entry *__proc_cre
7257         ent->nlink = nlink;
7258         atomic_set(&ent->count, 1);
7259         ent->pde_users = 0;
7260 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7261         spin_lock_init(&ent->pde_unload_lock);
7262         ent->pde_unload_completion = NULL;
7263         INIT_LIST_HEAD(&ent->pde_openers);
7264 @@ -654,7 +663,8 @@ struct proc_dir_entry *proc_symlink(cons
7265                                 kfree(ent->data);
7266                                 kfree(ent);
7267                                 ent = NULL;
7268 -                       }
7269 +                       } else
7270 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7271                 } else {
7272                         kfree(ent);
7273                         ent = NULL;
7274 diff -NurpP --minimal linux-2.6.33/fs/proc/inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/proc/inode.c
7275 --- linux-2.6.33/fs/proc/inode.c        2010-02-25 11:52:06.000000000 +0100
7276 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/proc/inode.c        2010-02-25 12:02:16.000000000 +0100
7277 @@ -436,6 +436,8 @@ struct inode *proc_get_inode(struct supe
7278                         inode->i_uid = de->uid;
7279                         inode->i_gid = de->gid;
7280                 }
7281 +               if (de->vx_flags)
7282 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7283                 if (de->size)
7284                         inode->i_size = de->size;
7285                 if (de->nlink)
7286 diff -NurpP --minimal linux-2.6.33/fs/proc/internal.h linux-2.6.33-vs2.3.0.36.30.1/fs/proc/internal.h
7287 --- linux-2.6.33/fs/proc/internal.h     2010-02-25 11:52:06.000000000 +0100
7288 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/proc/internal.h     2010-02-25 12:02:16.000000000 +0100
7289 @@ -10,6 +10,7 @@
7290   */
7291  
7292  #include <linux/proc_fs.h>
7293 +#include <linux/vs_pid.h>
7294  
7295  extern struct proc_dir_entry proc_root;
7296  #ifdef CONFIG_PROC_SYSCTL
7297 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7298                                 struct pid *pid, struct task_struct *task);
7299  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7300                                 struct pid *pid, struct task_struct *task);
7301 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7302 +                               struct pid *pid, struct task_struct *task);
7303 +
7304  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7305  
7306  extern const struct file_operations proc_maps_operations;
7307 @@ -68,11 +72,16 @@ static inline struct pid *proc_pid(struc
7308         return PROC_I(inode)->pid;
7309  }
7310  
7311 -static inline struct task_struct *get_proc_task(struct inode *inode)
7312 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7313  {
7314         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7315  }
7316  
7317 +static inline struct task_struct *get_proc_task(struct inode *inode)
7318 +{
7319 +       return vx_get_proc_task(inode, proc_pid(inode));
7320 +}
7321 +
7322  static inline int proc_fd(struct inode *inode)
7323  {
7324         return PROC_I(inode)->fd;
7325 diff -NurpP --minimal linux-2.6.33/fs/proc/loadavg.c linux-2.6.33-vs2.3.0.36.30.1/fs/proc/loadavg.c
7326 --- linux-2.6.33/fs/proc/loadavg.c      2009-09-10 15:26:23.000000000 +0200
7327 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/proc/loadavg.c      2010-02-25 12:02:16.000000000 +0100
7328 @@ -12,15 +12,27 @@
7329  
7330  static int loadavg_proc_show(struct seq_file *m, void *v)
7331  {
7332 +       unsigned long running;
7333 +       unsigned int threads;
7334         unsigned long avnrun[3];
7335  
7336         get_avenrun(avnrun, FIXED_1/200, 0);
7337  
7338 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7339 +               struct vx_info *vxi = current_vx_info();
7340 +
7341 +               running = atomic_read(&vxi->cvirt.nr_running);
7342 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7343 +       } else {
7344 +               running = nr_running();
7345 +               threads = nr_threads;
7346 +       }
7347 +
7348         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7349                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7350                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7351                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7352 -               nr_running(), nr_threads,
7353 +               running, threads,
7354                 task_active_pid_ns(current)->last_pid);
7355         return 0;
7356  }
7357 diff -NurpP --minimal linux-2.6.33/fs/proc/meminfo.c linux-2.6.33-vs2.3.0.36.30.1/fs/proc/meminfo.c
7358 --- linux-2.6.33/fs/proc/meminfo.c      2009-12-03 20:02:53.000000000 +0100
7359 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/proc/meminfo.c      2010-02-25 12:02:16.000000000 +0100
7360 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7361         allowed = ((totalram_pages - hugetlb_total_pages())
7362                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7363  
7364 -       cached = global_page_state(NR_FILE_PAGES) -
7365 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7366 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7367                         total_swapcache_pages - i.bufferram;
7368         if (cached < 0)
7369                 cached = 0;
7370 diff -NurpP --minimal linux-2.6.33/fs/proc/root.c linux-2.6.33-vs2.3.0.36.30.1/fs/proc/root.c
7371 --- linux-2.6.33/fs/proc/root.c 2009-06-11 17:13:07.000000000 +0200
7372 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/proc/root.c 2010-02-25 12:02:16.000000000 +0100
7373 @@ -18,9 +18,14 @@
7374  #include <linux/bitops.h>
7375  #include <linux/mount.h>
7376  #include <linux/pid_namespace.h>
7377 +#include <linux/vserver/inode.h>
7378  
7379  #include "internal.h"
7380  
7381 +struct proc_dir_entry *proc_virtual;
7382 +
7383 +extern void proc_vx_init(void);
7384 +
7385  static int proc_test_super(struct super_block *sb, void *data)
7386  {
7387         return sb->s_fs_info == data;
7388 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
7389  #endif
7390         proc_mkdir("bus", NULL);
7391         proc_sys_init();
7392 +       proc_vx_init();
7393  }
7394  
7395  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7396 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7397         .proc_iops      = &proc_root_inode_operations, 
7398         .proc_fops      = &proc_root_operations,
7399         .parent         = &proc_root,
7400 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7401  };
7402  
7403  int pid_ns_prepare_proc(struct pid_namespace *ns)
7404 diff -NurpP --minimal linux-2.6.33/fs/proc/uptime.c linux-2.6.33-vs2.3.0.36.30.1/fs/proc/uptime.c
7405 --- linux-2.6.33/fs/proc/uptime.c       2009-12-03 20:02:53.000000000 +0100
7406 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/proc/uptime.c       2010-02-25 12:02:16.000000000 +0100
7407 @@ -4,22 +4,22 @@
7408  #include <linux/sched.h>
7409  #include <linux/seq_file.h>
7410  #include <linux/time.h>
7411 -#include <linux/kernel_stat.h>
7412 +#include <linux/vserver/cvirt.h>
7413  #include <asm/cputime.h>
7414  
7415  static int uptime_proc_show(struct seq_file *m, void *v)
7416  {
7417         struct timespec uptime;
7418         struct timespec idle;
7419 -       int i;
7420 -       cputime_t idletime = cputime_zero;
7421 -
7422 -       for_each_possible_cpu(i)
7423 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7424 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7425  
7426         do_posix_clock_monotonic_gettime(&uptime);
7427         monotonic_to_bootbased(&uptime);
7428         cputime_to_timespec(idletime, &idle);
7429 +
7430 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7431 +               vx_vsi_uptime(&uptime, &idle);
7432 +
7433         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7434                         (unsigned long) uptime.tv_sec,
7435                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7436 diff -NurpP --minimal linux-2.6.33/fs/quota/quota.c linux-2.6.33-vs2.3.0.36.30.1/fs/quota/quota.c
7437 --- linux-2.6.33/fs/quota/quota.c       2010-02-25 11:52:06.000000000 +0100
7438 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/quota/quota.c       2010-02-25 13:25:13.000000000 +0100
7439 @@ -18,6 +18,7 @@
7440  #include <linux/capability.h>
7441  #include <linux/quotaops.h>
7442  #include <linux/types.h>
7443 +#include <linux/vs_context.h>
7444  #include <net/netlink.h>
7445  #include <net/genetlink.h>
7446  
7447 @@ -85,11 +86,11 @@ static int generic_quotactl_valid(struct
7448         if (cmd == Q_GETQUOTA) {
7449                 if (((type == USRQUOTA && current_euid() != id) ||
7450                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7451 -                   !capable(CAP_SYS_ADMIN))
7452 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7453                         return -EPERM;
7454         }
7455         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7456 -               if (!capable(CAP_SYS_ADMIN))
7457 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7458                         return -EPERM;
7459  
7460         return 0;
7461 @@ -137,10 +138,10 @@ static int xqm_quotactl_valid(struct sup
7462         if (cmd == Q_XGETQUOTA) {
7463                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7464                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7465 -                    !capable(CAP_SYS_ADMIN))
7466 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7467                         return -EPERM;
7468         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7469 -               if (!capable(CAP_SYS_ADMIN))
7470 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7471                         return -EPERM;
7472         }
7473  
7474 @@ -353,6 +354,46 @@ static int do_quotactl(struct super_bloc
7475         return 0;
7476  }
7477  
7478 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7479 +
7480 +#include <linux/vroot.h>
7481 +#include <linux/major.h>
7482 +#include <linux/module.h>
7483 +#include <linux/kallsyms.h>
7484 +#include <linux/vserver/debug.h>
7485 +
7486 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7487 +
7488 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7489 +
7490 +int register_vroot_grb(vroot_grb_func *func) {
7491 +       int ret = -EBUSY;
7492 +
7493 +       spin_lock(&vroot_grb_lock);
7494 +       if (!vroot_get_real_bdev) {
7495 +               vroot_get_real_bdev = func;
7496 +               ret = 0;
7497 +       }
7498 +       spin_unlock(&vroot_grb_lock);
7499 +       return ret;
7500 +}
7501 +EXPORT_SYMBOL(register_vroot_grb);
7502 +
7503 +int unregister_vroot_grb(vroot_grb_func *func) {
7504 +       int ret = -EINVAL;
7505 +
7506 +       spin_lock(&vroot_grb_lock);
7507 +       if (vroot_get_real_bdev) {
7508 +               vroot_get_real_bdev = NULL;
7509 +               ret = 0;
7510 +       }
7511 +       spin_unlock(&vroot_grb_lock);
7512 +       return ret;
7513 +}
7514 +EXPORT_SYMBOL(unregister_vroot_grb);
7515 +
7516 +#endif
7517 +
7518  /*
7519   * look up a superblock on which quota ops will be performed
7520   * - use the name of a block device to find the superblock thereon
7521 @@ -370,6 +411,22 @@ static struct super_block *quotactl_bloc
7522         putname(tmp);
7523         if (IS_ERR(bdev))
7524                 return ERR_CAST(bdev);
7525 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7526 +       if (bdev && bdev->bd_inode &&
7527 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7528 +               struct block_device *bdnew = (void *)-EINVAL;
7529 +
7530 +               if (vroot_get_real_bdev)
7531 +                       bdnew = vroot_get_real_bdev(bdev);
7532 +               else
7533 +                       vxdprintk(VXD_CBIT(misc, 0),
7534 +                                       "vroot_get_real_bdev not set");
7535 +               bdput(bdev);
7536 +               if (IS_ERR(bdnew))
7537 +                       return ERR_PTR(PTR_ERR(bdnew));
7538 +               bdev = bdnew;
7539 +       }
7540 +#endif
7541         sb = get_super(bdev);
7542         bdput(bdev);
7543         if (!sb)
7544 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/file.c linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/file.c
7545 --- linux-2.6.33/fs/reiserfs/file.c     2010-02-25 11:52:06.000000000 +0100
7546 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/file.c     2010-02-25 12:02:16.000000000 +0100
7547 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7548         .listxattr = reiserfs_listxattr,
7549         .removexattr = reiserfs_removexattr,
7550         .permission = reiserfs_permission,
7551 +       .sync_flags = reiserfs_sync_flags,
7552  };
7553 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/inode.c
7554 --- linux-2.6.33/fs/reiserfs/inode.c    2010-02-25 11:52:06.000000000 +0100
7555 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/inode.c    2010-02-25 12:02:16.000000000 +0100
7556 @@ -18,6 +18,7 @@
7557  #include <linux/writeback.h>
7558  #include <linux/quotaops.h>
7559  #include <linux/swap.h>
7560 +#include <linux/vs_tag.h>
7561  
7562  int reiserfs_commit_write(struct file *f, struct page *page,
7563                           unsigned from, unsigned to);
7564 @@ -1121,6 +1122,8 @@ static void init_inode(struct inode *ino
7565         struct buffer_head *bh;
7566         struct item_head *ih;
7567         __u32 rdev;
7568 +       uid_t uid;
7569 +       gid_t gid;
7570         //int version = ITEM_VERSION_1;
7571  
7572         bh = PATH_PLAST_BUFFER(path);
7573 @@ -1142,12 +1145,13 @@ static void init_inode(struct inode *ino
7574                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7575                 unsigned long blocks;
7576  
7577 +               uid = sd_v1_uid(sd);
7578 +               gid = sd_v1_gid(sd);
7579 +
7580                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7581                 set_inode_sd_version(inode, STAT_DATA_V1);
7582                 inode->i_mode = sd_v1_mode(sd);
7583                 inode->i_nlink = sd_v1_nlink(sd);
7584 -               inode->i_uid = sd_v1_uid(sd);
7585 -               inode->i_gid = sd_v1_gid(sd);
7586                 inode->i_size = sd_v1_size(sd);
7587                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7588                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7589 @@ -1189,11 +1193,12 @@ static void init_inode(struct inode *ino
7590                 // (directories and symlinks)
7591                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7592  
7593 +               uid    = sd_v2_uid(sd);
7594 +               gid    = sd_v2_gid(sd);
7595 +
7596                 inode->i_mode = sd_v2_mode(sd);
7597                 inode->i_nlink = sd_v2_nlink(sd);
7598 -               inode->i_uid = sd_v2_uid(sd);
7599                 inode->i_size = sd_v2_size(sd);
7600 -               inode->i_gid = sd_v2_gid(sd);
7601                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7602                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7603                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7604 @@ -1223,6 +1228,10 @@ static void init_inode(struct inode *ino
7605                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7606         }
7607  
7608 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7609 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7610 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7611 +
7612         pathrelse(path);
7613         if (S_ISREG(inode->i_mode)) {
7614                 inode->i_op = &reiserfs_file_inode_operations;
7615 @@ -1245,13 +1254,15 @@ static void init_inode(struct inode *ino
7616  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7617  {
7618         struct stat_data *sd_v2 = (struct stat_data *)sd;
7619 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7620 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7621         __u16 flags;
7622  
7623 +       set_sd_v2_uid(sd_v2, uid);
7624 +       set_sd_v2_gid(sd_v2, gid);
7625         set_sd_v2_mode(sd_v2, inode->i_mode);
7626         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7627 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7628         set_sd_v2_size(sd_v2, size);
7629 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7630         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7631         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7632         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7633 @@ -2852,14 +2863,19 @@ int reiserfs_commit_write(struct file *f
7634  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7635  {
7636         if (reiserfs_attrs(inode->i_sb)) {
7637 -               if (sd_attrs & REISERFS_SYNC_FL)
7638 -                       inode->i_flags |= S_SYNC;
7639 -               else
7640 -                       inode->i_flags &= ~S_SYNC;
7641                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7642                         inode->i_flags |= S_IMMUTABLE;
7643                 else
7644                         inode->i_flags &= ~S_IMMUTABLE;
7645 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7646 +                       inode->i_flags |= S_IXUNLINK;
7647 +               else
7648 +                       inode->i_flags &= ~S_IXUNLINK;
7649 +
7650 +               if (sd_attrs & REISERFS_SYNC_FL)
7651 +                       inode->i_flags |= S_SYNC;
7652 +               else
7653 +                       inode->i_flags &= ~S_SYNC;
7654                 if (sd_attrs & REISERFS_APPEND_FL)
7655                         inode->i_flags |= S_APPEND;
7656                 else
7657 @@ -2872,6 +2888,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7658                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7659                 else
7660                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7661 +
7662 +               if (sd_attrs & REISERFS_BARRIER_FL)
7663 +                       inode->i_vflags |= V_BARRIER;
7664 +               else
7665 +                       inode->i_vflags &= ~V_BARRIER;
7666 +               if (sd_attrs & REISERFS_COW_FL)
7667 +                       inode->i_vflags |= V_COW;
7668 +               else
7669 +                       inode->i_vflags &= ~V_COW;
7670         }
7671  }
7672  
7673 @@ -2882,6 +2907,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7674                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7675                 else
7676                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7677 +               if (inode->i_flags & S_IXUNLINK)
7678 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7679 +               else
7680 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7681 +
7682                 if (inode->i_flags & S_SYNC)
7683                         *sd_attrs |= REISERFS_SYNC_FL;
7684                 else
7685 @@ -2894,6 +2924,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7686                         *sd_attrs |= REISERFS_NOTAIL_FL;
7687                 else
7688                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7689 +
7690 +               if (inode->i_vflags & V_BARRIER)
7691 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7692 +               else
7693 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7694 +               if (inode->i_vflags & V_COW)
7695 +                       *sd_attrs |= REISERFS_COW_FL;
7696 +               else
7697 +                       *sd_attrs &= ~REISERFS_COW_FL;
7698         }
7699  }
7700  
7701 @@ -3115,9 +3154,11 @@ int reiserfs_setattr(struct dentry *dent
7702         }
7703  
7704         error = inode_change_ok(inode, attr);
7705 +
7706         if (!error) {
7707                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7708 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7709 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7710 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7711                         error = reiserfs_chown_xattrs(inode, attr);
7712  
7713                         if (!error) {
7714 @@ -3147,6 +3188,9 @@ int reiserfs_setattr(struct dentry *dent
7715                                         inode->i_uid = attr->ia_uid;
7716                                 if (attr->ia_valid & ATTR_GID)
7717                                         inode->i_gid = attr->ia_gid;
7718 +                               if ((attr->ia_valid & ATTR_TAG) &&
7719 +                                       IS_TAGGED(inode))
7720 +                                       inode->i_tag = attr->ia_tag;
7721                                 mark_inode_dirty(inode);
7722                                 error =
7723                                     journal_end(&th, inode->i_sb, jbegin_count);
7724 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/ioctl.c linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/ioctl.c
7725 --- linux-2.6.33/fs/reiserfs/ioctl.c    2010-02-25 11:52:06.000000000 +0100
7726 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/ioctl.c    2010-02-25 13:21:56.000000000 +0100
7727 @@ -7,11 +7,27 @@
7728  #include <linux/mount.h>
7729  #include <linux/reiserfs_fs.h>
7730  #include <linux/time.h>
7731 +#include <linux/mount.h>
7732  #include <asm/uaccess.h>
7733  #include <linux/pagemap.h>
7734  #include <linux/smp_lock.h>
7735  #include <linux/compat.h>
7736  
7737 +
7738 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7739 +{
7740 +       __u16 sd_attrs = 0;
7741 +
7742 +       inode->i_flags = flags;
7743 +       inode->i_vflags = vflags;
7744 +
7745 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7746 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7747 +       inode->i_ctime = CURRENT_TIME_SEC;
7748 +       mark_inode_dirty(inode);
7749 +       return 0;
7750 +}
7751 +
7752  /*
7753   * reiserfs_ioctl - handler for ioctl for inode
7754   * supported commands:
7755 @@ -23,7 +39,7 @@
7756  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7757  {
7758         struct inode *inode = filp->f_path.dentry->d_inode;
7759 -       unsigned int flags;
7760 +       unsigned int flags, oldflags;
7761         int err = 0;
7762  
7763         reiserfs_write_lock(inode->i_sb);
7764 @@ -48,6 +64,7 @@ long reiserfs_ioctl(struct file *filp, u
7765  
7766                 flags = REISERFS_I(inode)->i_attrs;
7767                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7768 +               flags &= REISERFS_FL_USER_VISIBLE;
7769                 err = put_user(flags, (int __user *)arg);
7770                 break;
7771         case REISERFS_IOC_SETFLAGS:{
7772 @@ -68,6 +85,10 @@ long reiserfs_ioctl(struct file *filp, u
7773                                 err = -EFAULT;
7774                                 goto setflags_out;
7775                         }
7776 +                       if (IS_BARRIER(inode)) {
7777 +                               vxwprintk_task(1, "messing with the barrier.");
7778 +                               return -EACCES;
7779 +                       }
7780                         /*
7781                          * Is it quota file? Do not allow user to mess with it
7782                          */
7783 @@ -92,6 +113,10 @@ long reiserfs_ioctl(struct file *filp, u
7784                                         goto setflags_out;
7785                                 }
7786                         }
7787 +
7788 +                       oldflags = REISERFS_I(inode)->i_attrs;
7789 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7790 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7791                         sd_attrs_to_i_attrs(flags, inode);
7792                         REISERFS_I(inode)->i_attrs = flags;
7793                         inode->i_ctime = CURRENT_TIME_SEC;
7794 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/namei.c linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/namei.c
7795 --- linux-2.6.33/fs/reiserfs/namei.c    2010-02-25 11:52:06.000000000 +0100
7796 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/namei.c    2010-02-25 12:02:16.000000000 +0100
7797 @@ -17,6 +17,7 @@
7798  #include <linux/reiserfs_acl.h>
7799  #include <linux/reiserfs_xattr.h>
7800  #include <linux/quotaops.h>
7801 +#include <linux/vs_tag.h>
7802  
7803  #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; }
7804  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7805 @@ -361,6 +362,7 @@ static struct dentry *reiserfs_lookup(st
7806         if (retval == IO_ERROR) {
7807                 return ERR_PTR(-EIO);
7808         }
7809 +               dx_propagate_tag(nd, inode);
7810  
7811         return d_splice_alias(inode, dentry);
7812  }
7813 @@ -577,6 +579,7 @@ static int new_inode_init(struct inode *
7814         } else {
7815                 inode->i_gid = current_fsgid();
7816         }
7817 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7818         vfs_dq_init(inode);
7819         return 0;
7820  }
7821 @@ -1524,6 +1527,7 @@ const struct inode_operations reiserfs_d
7822         .listxattr = reiserfs_listxattr,
7823         .removexattr = reiserfs_removexattr,
7824         .permission = reiserfs_permission,
7825 +       .sync_flags = reiserfs_sync_flags,
7826  };
7827  
7828  /*
7829 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/super.c linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/super.c
7830 --- linux-2.6.33/fs/reiserfs/super.c    2010-02-25 11:52:06.000000000 +0100
7831 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/super.c    2010-02-25 12:02:16.000000000 +0100
7832 @@ -887,6 +887,14 @@ static int reiserfs_parse_options(struct
7833                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7834                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7835  #endif
7836 +#ifndef CONFIG_TAGGING_NONE
7837 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7838 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7839 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7840 +#endif
7841 +#ifdef CONFIG_PROPAGATE
7842 +               {"tag",.arg_required = 'T',.values = NULL},
7843 +#endif
7844  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7845                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7846                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7847 @@ -1196,6 +1204,14 @@ static int reiserfs_remount(struct super
7848         handle_quota_files(s, qf_names, &qfmt);
7849  #endif
7850  
7851 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7852 +               !(s->s_flags & MS_TAGGED)) {
7853 +               reiserfs_warning(s, "super-vs01",
7854 +                       "reiserfs: tagging not permitted on remount.");
7855 +               err = -EINVAL;
7856 +               goto out_err;
7857 +       }
7858 +
7859         handle_attrs(s);
7860  
7861         /* Add options that are safe here */
7862 @@ -1674,6 +1690,10 @@ static int reiserfs_fill_super(struct su
7863                 goto error;
7864         }
7865  
7866 +       /* map mount option tagxid */
7867 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7868 +               s->s_flags |= MS_TAGGED;
7869 +
7870         rs = SB_DISK_SUPER_BLOCK(s);
7871         /* Let's do basic sanity check to verify that underlying device is not
7872            smaller than the filesystem. If the check fails then abort and scream,
7873 diff -NurpP --minimal linux-2.6.33/fs/reiserfs/xattr.c linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/xattr.c
7874 --- linux-2.6.33/fs/reiserfs/xattr.c    2010-02-25 11:52:06.000000000 +0100
7875 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/reiserfs/xattr.c    2010-02-25 12:02:16.000000000 +0100
7876 @@ -39,6 +39,7 @@
7877  #include <linux/namei.h>
7878  #include <linux/errno.h>
7879  #include <linux/fs.h>
7880 +#include <linux/mount.h>
7881  #include <linux/file.h>
7882  #include <linux/pagemap.h>
7883  #include <linux/xattr.h>
7884 diff -NurpP --minimal linux-2.6.33/fs/stat.c linux-2.6.33-vs2.3.0.36.30.1/fs/stat.c
7885 --- linux-2.6.33/fs/stat.c      2010-02-25 11:52:06.000000000 +0100
7886 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/stat.c      2010-02-25 12:02:16.000000000 +0100
7887 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7888         stat->nlink = inode->i_nlink;
7889         stat->uid = inode->i_uid;
7890         stat->gid = inode->i_gid;
7891 +       stat->tag = inode->i_tag;
7892         stat->rdev = inode->i_rdev;
7893         stat->atime = inode->i_atime;
7894         stat->mtime = inode->i_mtime;
7895 diff -NurpP --minimal linux-2.6.33/fs/super.c linux-2.6.33-vs2.3.0.36.30.1/fs/super.c
7896 --- linux-2.6.33/fs/super.c     2010-02-25 11:52:06.000000000 +0100
7897 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/super.c     2010-02-25 12:02:16.000000000 +0100
7898 @@ -37,6 +37,9 @@
7899  #include <linux/kobject.h>
7900  #include <linux/mutex.h>
7901  #include <linux/file.h>
7902 +#include <linux/devpts_fs.h>
7903 +#include <linux/proc_fs.h>
7904 +#include <linux/vs_context.h>
7905  #include <asm/uaccess.h>
7906  #include "internal.h"
7907  
7908 @@ -914,12 +917,18 @@ struct vfsmount *
7909  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7910  {
7911         struct vfsmount *mnt;
7912 +       struct super_block *sb;
7913         char *secdata = NULL;
7914         int error;
7915  
7916         if (!type)
7917                 return ERR_PTR(-ENODEV);
7918  
7919 +       error = -EPERM;
7920 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7921 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7922 +               goto out;
7923 +
7924         error = -ENOMEM;
7925         mnt = alloc_vfsmnt(name);
7926         if (!mnt)
7927 @@ -938,9 +947,17 @@ vfs_kern_mount(struct file_system_type *
7928         error = type->get_sb(type, flags, name, data, mnt);
7929         if (error < 0)
7930                 goto out_free_secdata;
7931 -       BUG_ON(!mnt->mnt_sb);
7932  
7933 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7934 +       sb = mnt->mnt_sb;
7935 +       BUG_ON(!sb);
7936 +
7937 +       error = -EPERM;
7938 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7939 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7940 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7941 +               goto out_sb;
7942 +
7943 +       error = security_sb_kern_mount(sb, flags, secdata);
7944         if (error)
7945                 goto out_sb;
7946  
7947 diff -NurpP --minimal linux-2.6.33/fs/sysfs/mount.c linux-2.6.33-vs2.3.0.36.30.1/fs/sysfs/mount.c
7948 --- linux-2.6.33/fs/sysfs/mount.c       2009-06-11 17:13:08.000000000 +0200
7949 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/sysfs/mount.c       2010-02-25 12:02:16.000000000 +0100
7950 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7951  
7952         sb->s_blocksize = PAGE_CACHE_SIZE;
7953         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7954 -       sb->s_magic = SYSFS_MAGIC;
7955 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7956         sb->s_op = &sysfs_ops;
7957         sb->s_time_gran = 1;
7958         sysfs_sb = sb;
7959 diff -NurpP --minimal linux-2.6.33/fs/utimes.c linux-2.6.33-vs2.3.0.36.30.1/fs/utimes.c
7960 --- linux-2.6.33/fs/utimes.c    2009-03-24 14:22:37.000000000 +0100
7961 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/utimes.c    2010-02-25 12:02:16.000000000 +0100
7962 @@ -8,6 +8,8 @@
7963  #include <linux/stat.h>
7964  #include <linux/utime.h>
7965  #include <linux/syscalls.h>
7966 +#include <linux/mount.h>
7967 +#include <linux/vs_cowbl.h>
7968  #include <asm/uaccess.h>
7969  #include <asm/unistd.h>
7970  
7971 diff -NurpP --minimal linux-2.6.33/fs/xattr.c linux-2.6.33-vs2.3.0.36.30.1/fs/xattr.c
7972 --- linux-2.6.33/fs/xattr.c     2010-02-25 11:52:06.000000000 +0100
7973 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xattr.c     2010-02-25 12:02:16.000000000 +0100
7974 @@ -18,6 +18,7 @@
7975  #include <linux/module.h>
7976  #include <linux/fsnotify.h>
7977  #include <linux/audit.h>
7978 +#include <linux/mount.h>
7979  #include <asm/uaccess.h>
7980  
7981  
7982 diff -NurpP --minimal linux-2.6.33/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/linux-2.6/xfs_ioctl.c
7983 --- linux-2.6.33/fs/xfs/linux-2.6/xfs_ioctl.c   2010-02-25 11:52:06.000000000 +0100
7984 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/linux-2.6/xfs_ioctl.c   2010-02-25 12:02:16.000000000 +0100
7985 @@ -34,7 +34,6 @@
7986  #include "xfs_dir2_sf.h"
7987  #include "xfs_dinode.h"
7988  #include "xfs_inode.h"
7989 -#include "xfs_ioctl.h"
7990  #include "xfs_btree.h"
7991  #include "xfs_ialloc.h"
7992  #include "xfs_rtalloc.h"
7993 @@ -743,6 +742,10 @@ xfs_merge_ioc_xflags(
7994                 xflags |= XFS_XFLAG_IMMUTABLE;
7995         else
7996                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7997 +       if (flags & FS_IXUNLINK_FL)
7998 +               xflags |= XFS_XFLAG_IXUNLINK;
7999 +       else
8000 +               xflags &= ~XFS_XFLAG_IXUNLINK;
8001         if (flags & FS_APPEND_FL)
8002                 xflags |= XFS_XFLAG_APPEND;
8003         else
8004 @@ -771,6 +774,8 @@ xfs_di2lxflags(
8005  
8006         if (di_flags & XFS_DIFLAG_IMMUTABLE)
8007                 flags |= FS_IMMUTABLE_FL;
8008 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
8009 +               flags |= FS_IXUNLINK_FL;
8010         if (di_flags & XFS_DIFLAG_APPEND)
8011                 flags |= FS_APPEND_FL;
8012         if (di_flags & XFS_DIFLAG_SYNC)
8013 @@ -829,6 +834,8 @@ xfs_set_diflags(
8014         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
8015         if (xflags & XFS_XFLAG_IMMUTABLE)
8016                 di_flags |= XFS_DIFLAG_IMMUTABLE;
8017 +       if (xflags & XFS_XFLAG_IXUNLINK)
8018 +               di_flags |= XFS_DIFLAG_IXUNLINK;
8019         if (xflags & XFS_XFLAG_APPEND)
8020                 di_flags |= XFS_DIFLAG_APPEND;
8021         if (xflags & XFS_XFLAG_SYNC)
8022 @@ -871,6 +878,10 @@ xfs_diflags_to_linux(
8023                 inode->i_flags |= S_IMMUTABLE;
8024         else
8025                 inode->i_flags &= ~S_IMMUTABLE;
8026 +       if (xflags & XFS_XFLAG_IXUNLINK)
8027 +               inode->i_flags |= S_IXUNLINK;
8028 +       else
8029 +               inode->i_flags &= ~S_IXUNLINK;
8030         if (xflags & XFS_XFLAG_APPEND)
8031                 inode->i_flags |= S_APPEND;
8032         else
8033 @@ -1347,10 +1358,18 @@ xfs_file_ioctl(
8034         case XFS_IOC_FSGETXATTRA:
8035                 return xfs_ioc_fsgetxattr(ip, 1, arg);
8036         case XFS_IOC_FSSETXATTR:
8037 +               if (IS_BARRIER(inode)) {
8038 +                       vxwprintk_task(1, "messing with the barrier.");
8039 +                       return -XFS_ERROR(EACCES);
8040 +               }
8041                 return xfs_ioc_fssetxattr(ip, filp, arg);
8042         case XFS_IOC_GETXFLAGS:
8043                 return xfs_ioc_getxflags(ip, arg);
8044         case XFS_IOC_SETXFLAGS:
8045 +               if (IS_BARRIER(inode)) {
8046 +                       vxwprintk_task(1, "messing with the barrier.");
8047 +                       return -XFS_ERROR(EACCES);
8048 +               }
8049                 return xfs_ioc_setxflags(ip, filp, arg);
8050  
8051         case XFS_IOC_FSSETDM: {
8052 diff -NurpP --minimal linux-2.6.33/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/linux-2.6/xfs_ioctl.h
8053 --- linux-2.6.33/fs/xfs/linux-2.6/xfs_ioctl.h   2009-03-24 14:22:37.000000000 +0100
8054 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/linux-2.6/xfs_ioctl.h   2010-02-25 12:02:16.000000000 +0100
8055 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
8056         void __user             *uhandle,
8057         u32                     hlen);
8058  
8059 +extern int
8060 +xfs_sync_flags(
8061 +       struct inode            *inode,
8062 +       int                     flags,
8063 +       int                     vflags);
8064 +
8065  extern long
8066  xfs_file_ioctl(
8067         struct file             *filp,
8068 diff -NurpP --minimal linux-2.6.33/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/linux-2.6/xfs_iops.c
8069 --- linux-2.6.33/fs/xfs/linux-2.6/xfs_iops.c    2010-02-25 11:52:06.000000000 +0100
8070 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/linux-2.6/xfs_iops.c    2010-02-25 12:02:16.000000000 +0100
8071 @@ -36,6 +36,7 @@
8072  #include "xfs_attr_sf.h"
8073  #include "xfs_dinode.h"
8074  #include "xfs_inode.h"
8075 +#include "xfs_ioctl.h"
8076  #include "xfs_bmap.h"
8077  #include "xfs_btree.h"
8078  #include "xfs_ialloc.h"
8079 @@ -56,6 +57,7 @@
8080  #include <linux/security.h>
8081  #include <linux/falloc.h>
8082  #include <linux/fiemap.h>
8083 +#include <linux/vs_tag.h>
8084  
8085  /*
8086   * Bring the timestamps in the XFS inode uptodate.
8087 @@ -496,6 +498,7 @@ xfs_vn_getattr(
8088         stat->nlink = ip->i_d.di_nlink;
8089         stat->uid = ip->i_d.di_uid;
8090         stat->gid = ip->i_d.di_gid;
8091 +       stat->tag = ip->i_d.di_tag;
8092         stat->ino = ip->i_ino;
8093         stat->atime = inode->i_atime;
8094         stat->mtime = inode->i_mtime;
8095 @@ -687,6 +690,7 @@ static const struct inode_operations xfs
8096         .listxattr              = xfs_vn_listxattr,
8097         .fallocate              = xfs_vn_fallocate,
8098         .fiemap                 = xfs_vn_fiemap,
8099 +       .sync_flags             = xfs_sync_flags,
8100  };
8101  
8102  static const struct inode_operations xfs_dir_inode_operations = {
8103 @@ -712,6 +716,7 @@ static const struct inode_operations xfs
8104         .getxattr               = generic_getxattr,
8105         .removexattr            = generic_removexattr,
8106         .listxattr              = xfs_vn_listxattr,
8107 +       .sync_flags             = xfs_sync_flags,
8108  };
8109  
8110  static const struct inode_operations xfs_dir_ci_inode_operations = {
8111 @@ -761,6 +766,10 @@ xfs_diflags_to_iflags(
8112                 inode->i_flags |= S_IMMUTABLE;
8113         else
8114                 inode->i_flags &= ~S_IMMUTABLE;
8115 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
8116 +               inode->i_flags |= S_IXUNLINK;
8117 +       else
8118 +               inode->i_flags &= ~S_IXUNLINK;
8119         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
8120                 inode->i_flags |= S_APPEND;
8121         else
8122 @@ -773,6 +782,15 @@ xfs_diflags_to_iflags(
8123                 inode->i_flags |= S_NOATIME;
8124         else
8125                 inode->i_flags &= ~S_NOATIME;
8126 +
8127 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
8128 +               inode->i_vflags |= V_BARRIER;
8129 +       else
8130 +               inode->i_vflags &= ~V_BARRIER;
8131 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
8132 +               inode->i_vflags |= V_COW;
8133 +       else
8134 +               inode->i_vflags &= ~V_COW;
8135  }
8136  
8137  /*
8138 @@ -801,6 +819,7 @@ xfs_setup_inode(
8139         inode->i_nlink  = ip->i_d.di_nlink;
8140         inode->i_uid    = ip->i_d.di_uid;
8141         inode->i_gid    = ip->i_d.di_gid;
8142 +       inode->i_tag    = ip->i_d.di_tag;
8143  
8144         switch (inode->i_mode & S_IFMT) {
8145         case S_IFBLK:
8146 diff -NurpP --minimal linux-2.6.33/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/linux-2.6/xfs_linux.h
8147 --- linux-2.6.33/fs/xfs/linux-2.6/xfs_linux.h   2010-02-25 11:52:06.000000000 +0100
8148 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/linux-2.6/xfs_linux.h   2010-02-25 12:02:16.000000000 +0100
8149 @@ -118,6 +118,7 @@
8150  
8151  #define current_cpu()          (raw_smp_processor_id())
8152  #define current_pid()          (current->pid)
8153 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
8154  #define current_test_flags(f)  (current->flags & (f))
8155  #define current_set_flags_nested(sp, f)                \
8156                 (*(sp) = current->flags, current->flags |= (f))
8157 diff -NurpP --minimal linux-2.6.33/fs/xfs/linux-2.6/xfs_super.c linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/linux-2.6/xfs_super.c
8158 --- linux-2.6.33/fs/xfs/linux-2.6/xfs_super.c   2010-02-25 11:52:06.000000000 +0100
8159 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/linux-2.6/xfs_super.c   2010-02-25 12:02:16.000000000 +0100
8160 @@ -118,6 +118,9 @@ mempool_t *xfs_ioend_pool;
8161  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
8162  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
8163  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
8164 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8165 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8166 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8167  
8168  /*
8169   * Table driven mount option parser.
8170 @@ -126,10 +129,14 @@ mempool_t *xfs_ioend_pool;
8171   * in the future, too.
8172   */
8173  enum {
8174 +       Opt_tag, Opt_notag,
8175         Opt_barrier, Opt_nobarrier, Opt_err
8176  };
8177  
8178  static const match_table_t tokens = {
8179 +       {Opt_tag, "tagxid"},
8180 +       {Opt_tag, "tag"},
8181 +       {Opt_notag, "notag"},
8182         {Opt_barrier, "barrier"},
8183         {Opt_nobarrier, "nobarrier"},
8184         {Opt_err, NULL}
8185 @@ -383,6 +390,19 @@ xfs_parseargs(
8186                 } else if (!strcmp(this_char, "irixsgid")) {
8187                         cmn_err(CE_WARN,
8188         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8189 +#ifndef CONFIG_TAGGING_NONE
8190 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8191 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8192 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8193 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
8194 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8195 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8196 +#endif
8197 +#ifdef CONFIG_PROPAGATE
8198 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8199 +                       /* use value */
8200 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8201 +#endif
8202                 } else {
8203                         cmn_err(CE_WARN,
8204                                 "XFS: unknown mount option [%s].", this_char);
8205 @@ -1290,6 +1310,16 @@ xfs_fs_remount(
8206                 case Opt_nobarrier:
8207                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8208                         break;
8209 +               case Opt_tag:
8210 +                       if (!(sb->s_flags & MS_TAGGED)) {
8211 +                               printk(KERN_INFO
8212 +                                       "XFS: %s: tagging not permitted on remount.\n",
8213 +                                       sb->s_id);
8214 +                               return -EINVAL;
8215 +                       }
8216 +                       break;
8217 +               case Opt_notag:
8218 +                       break;
8219                 default:
8220                         /*
8221                          * Logically we would return an error here to prevent
8222 @@ -1497,6 +1527,9 @@ xfs_fs_fill_super(
8223  
8224         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
8225  
8226 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8227 +               sb->s_flags |= MS_TAGGED;
8228 +
8229         sb->s_magic = XFS_SB_MAGIC;
8230         sb->s_blocksize = mp->m_sb.sb_blocksize;
8231         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
8232 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_dinode.h linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_dinode.h
8233 --- linux-2.6.33/fs/xfs/xfs_dinode.h    2009-06-11 17:13:09.000000000 +0200
8234 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_dinode.h    2010-02-25 12:02:16.000000000 +0100
8235 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
8236         __be32          di_gid;         /* owner's group id */
8237         __be32          di_nlink;       /* number of links to file */
8238         __be16          di_projid;      /* owner's project id */
8239 -       __u8            di_pad[8];      /* unused, zeroed space */
8240 +       __be16          di_tag;         /* context tagging */
8241 +       __be16          di_vflags;      /* vserver specific flags */
8242 +       __u8            di_pad[4];      /* unused, zeroed space */
8243         __be16          di_flushiter;   /* incremented on flush */
8244         xfs_timestamp_t di_atime;       /* time last accessed */
8245         xfs_timestamp_t di_mtime;       /* time last modified */
8246 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
8247  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8248  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8249  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8250 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8251 +
8252  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8253  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8254  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8255 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
8256  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8257  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8258  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8259 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8260  
8261  #ifdef CONFIG_XFS_RT
8262  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8263 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
8264          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8265          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8266          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8267 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8268 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8269 +        XFS_DIFLAG_IXUNLINK)
8270 +
8271 +#define XFS_DIVFLAG_BARRIER    0x01
8272 +#define XFS_DIVFLAG_COW                0x02
8273  
8274  #endif /* __XFS_DINODE_H__ */
8275 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_fs.h linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_fs.h
8276 --- linux-2.6.33/fs/xfs/xfs_fs.h        2009-12-03 20:02:53.000000000 +0100
8277 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_fs.h        2010-02-25 12:02:16.000000000 +0100
8278 @@ -67,6 +67,9 @@ struct fsxattr {
8279  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8280  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8281  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8282 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8283 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8284 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8285  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8286  
8287  /*
8288 @@ -292,7 +295,8 @@ typedef struct xfs_bstat {
8289         __s32           bs_extents;     /* number of extents            */
8290         __u32           bs_gen;         /* generation count             */
8291         __u16           bs_projid;      /* project id                   */
8292 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8293 +       __u16           bs_tag;         /* context tagging              */
8294 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8295         __u32           bs_dmevmask;    /* DMIG event mask              */
8296         __u16           bs_dmstate;     /* DMIG state info              */
8297         __u16           bs_aextents;    /* attribute number of extents  */
8298 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_ialloc.c linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_ialloc.c
8299 --- linux-2.6.33/fs/xfs/xfs_ialloc.c    2010-02-25 11:52:06.000000000 +0100
8300 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_ialloc.c    2010-02-25 12:02:16.000000000 +0100
8301 @@ -41,7 +41,6 @@
8302  #include "xfs_error.h"
8303  #include "xfs_bmap.h"
8304  
8305 -
8306  /*
8307   * Allocation group level functions.
8308   */
8309 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_inode.c linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_inode.c
8310 --- linux-2.6.33/fs/xfs/xfs_inode.c     2010-02-25 11:52:06.000000000 +0100
8311 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_inode.c     2010-02-25 12:02:16.000000000 +0100
8312 @@ -249,6 +249,7 @@ xfs_inotobp(
8313         return 0;
8314  }
8315  
8316 +#include <linux/vs_tag.h>
8317  
8318  /*
8319   * This routine is called to map an inode to the buffer containing
8320 @@ -654,15 +655,25 @@ xfs_iformat_btree(
8321  STATIC void
8322  xfs_dinode_from_disk(
8323         xfs_icdinode_t          *to,
8324 -       xfs_dinode_t            *from)
8325 +       xfs_dinode_t            *from,
8326 +       int tagged)
8327  {
8328 +       uint32_t uid, gid, tag;
8329 +
8330         to->di_magic = be16_to_cpu(from->di_magic);
8331         to->di_mode = be16_to_cpu(from->di_mode);
8332         to->di_version = from ->di_version;
8333         to->di_format = from->di_format;
8334         to->di_onlink = be16_to_cpu(from->di_onlink);
8335 -       to->di_uid = be32_to_cpu(from->di_uid);
8336 -       to->di_gid = be32_to_cpu(from->di_gid);
8337 +
8338 +       uid = be32_to_cpu(from->di_uid);
8339 +       gid = be32_to_cpu(from->di_gid);
8340 +       tag = be16_to_cpu(from->di_tag);
8341 +
8342 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8343 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8344 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8345 +
8346         to->di_nlink = be32_to_cpu(from->di_nlink);
8347         to->di_projid = be16_to_cpu(from->di_projid);
8348         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8349 @@ -683,21 +694,26 @@ xfs_dinode_from_disk(
8350         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8351         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8352         to->di_flags    = be16_to_cpu(from->di_flags);
8353 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8354         to->di_gen      = be32_to_cpu(from->di_gen);
8355  }
8356  
8357  void
8358  xfs_dinode_to_disk(
8359         xfs_dinode_t            *to,
8360 -       xfs_icdinode_t          *from)
8361 +       xfs_icdinode_t          *from,
8362 +       int tagged)
8363  {
8364         to->di_magic = cpu_to_be16(from->di_magic);
8365         to->di_mode = cpu_to_be16(from->di_mode);
8366         to->di_version = from ->di_version;
8367         to->di_format = from->di_format;
8368         to->di_onlink = cpu_to_be16(from->di_onlink);
8369 -       to->di_uid = cpu_to_be32(from->di_uid);
8370 -       to->di_gid = cpu_to_be32(from->di_gid);
8371 +
8372 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8373 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8374 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8375 +
8376         to->di_nlink = cpu_to_be32(from->di_nlink);
8377         to->di_projid = cpu_to_be16(from->di_projid);
8378         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8379 @@ -718,12 +734,14 @@ xfs_dinode_to_disk(
8380         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8381         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8382         to->di_flags = cpu_to_be16(from->di_flags);
8383 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8384         to->di_gen = cpu_to_be32(from->di_gen);
8385  }
8386  
8387  STATIC uint
8388  _xfs_dic2xflags(
8389 -       __uint16_t              di_flags)
8390 +       __uint16_t              di_flags,
8391 +       __uint16_t              di_vflags)
8392  {
8393         uint                    flags = 0;
8394  
8395 @@ -734,6 +752,8 @@ _xfs_dic2xflags(
8396                         flags |= XFS_XFLAG_PREALLOC;
8397                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8398                         flags |= XFS_XFLAG_IMMUTABLE;
8399 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8400 +                       flags |= XFS_XFLAG_IXUNLINK;
8401                 if (di_flags & XFS_DIFLAG_APPEND)
8402                         flags |= XFS_XFLAG_APPEND;
8403                 if (di_flags & XFS_DIFLAG_SYNC)
8404 @@ -758,6 +778,10 @@ _xfs_dic2xflags(
8405                         flags |= XFS_XFLAG_FILESTREAM;
8406         }
8407  
8408 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8409 +               flags |= FS_BARRIER_FL;
8410 +       if (di_vflags & XFS_DIVFLAG_COW)
8411 +               flags |= FS_COW_FL;
8412         return flags;
8413  }
8414  
8415 @@ -767,7 +791,7 @@ xfs_ip2xflags(
8416  {
8417         xfs_icdinode_t          *dic = &ip->i_d;
8418  
8419 -       return _xfs_dic2xflags(dic->di_flags) |
8420 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8421                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8422  }
8423  
8424 @@ -775,7 +799,8 @@ uint
8425  xfs_dic2xflags(
8426         xfs_dinode_t            *dip)
8427  {
8428 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8429 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8430 +                               be16_to_cpu(dip->di_vflags)) |
8431                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8432  }
8433  
8434 @@ -811,7 +836,6 @@ xfs_iread(
8435         if (error)
8436                 return error;
8437         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8438 -
8439         /*
8440          * If we got something that isn't an inode it means someone
8441          * (nfs or dmi) has a stale handle.
8442 @@ -836,7 +860,8 @@ xfs_iread(
8443          * Otherwise, just get the truly permanent information.
8444          */
8445         if (dip->di_mode) {
8446 -               xfs_dinode_from_disk(&ip->i_d, dip);
8447 +               xfs_dinode_from_disk(&ip->i_d, dip,
8448 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8449                 error = xfs_iformat(ip, dip);
8450                 if (error)  {
8451  #ifdef DEBUG
8452 @@ -1036,6 +1061,7 @@ xfs_ialloc(
8453         ASSERT(ip->i_d.di_nlink == nlink);
8454         ip->i_d.di_uid = current_fsuid();
8455         ip->i_d.di_gid = current_fsgid();
8456 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8457         ip->i_d.di_projid = prid;
8458         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8459  
8460 @@ -1096,6 +1122,7 @@ xfs_ialloc(
8461         ip->i_d.di_dmevmask = 0;
8462         ip->i_d.di_dmstate = 0;
8463         ip->i_d.di_flags = 0;
8464 +       ip->i_d.di_vflags = 0;
8465         flags = XFS_ILOG_CORE;
8466         switch (mode & S_IFMT) {
8467         case S_IFIFO:
8468 @@ -2136,6 +2163,7 @@ xfs_ifree(
8469         }
8470         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8471         ip->i_d.di_flags = 0;
8472 +       ip->i_d.di_vflags = 0;
8473         ip->i_d.di_dmevmask = 0;
8474         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8475         ip->i_df.if_ext_max =
8476 @@ -3116,7 +3144,8 @@ xfs_iflush_int(
8477          * because if the inode is dirty at all the core must
8478          * be.
8479          */
8480 -       xfs_dinode_to_disk(dip, &ip->i_d);
8481 +       xfs_dinode_to_disk(dip, &ip->i_d,
8482 +               mp->m_flags & XFS_MOUNT_TAGGED);
8483  
8484         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8485         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8486 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_inode.h linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_inode.h
8487 --- linux-2.6.33/fs/xfs/xfs_inode.h     2010-02-25 11:52:06.000000000 +0100
8488 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_inode.h     2010-02-25 12:02:16.000000000 +0100
8489 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8490         __uint32_t      di_gid;         /* owner's group id */
8491         __uint32_t      di_nlink;       /* number of links to file */
8492         __uint16_t      di_projid;      /* owner's project id */
8493 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8494 +       __uint16_t      di_tag;         /* context tagging */
8495 +       __uint16_t      di_vflags;      /* vserver specific flags */
8496 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8497         __uint16_t      di_flushiter;   /* incremented on flush */
8498         xfs_ictimestamp_t di_atime;     /* time last accessed */
8499         xfs_ictimestamp_t di_mtime;     /* time last modified */
8500 @@ -521,7 +523,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8501  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8502                           struct xfs_inode *, xfs_daddr_t, uint);
8503  void           xfs_dinode_to_disk(struct xfs_dinode *,
8504 -                                  struct xfs_icdinode *);
8505 +                                  struct xfs_icdinode *, int);
8506  void           xfs_idestroy_fork(struct xfs_inode *, int);
8507  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8508  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8509 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_itable.c linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_itable.c
8510 --- linux-2.6.33/fs/xfs/xfs_itable.c    2009-12-03 20:02:54.000000000 +0100
8511 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_itable.c    2010-02-25 12:02:16.000000000 +0100
8512 @@ -84,6 +84,7 @@ xfs_bulkstat_one_iget(
8513         buf->bs_mode = dic->di_mode;
8514         buf->bs_uid = dic->di_uid;
8515         buf->bs_gid = dic->di_gid;
8516 +       buf->bs_tag = dic->di_tag;
8517         buf->bs_size = dic->di_size;
8518  
8519         /*
8520 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_log_recover.c linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_log_recover.c
8521 --- linux-2.6.33/fs/xfs/xfs_log_recover.c       2010-02-25 11:52:06.000000000 +0100
8522 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_log_recover.c       2010-02-25 12:02:16.000000000 +0100
8523 @@ -2462,7 +2462,8 @@ xlog_recover_do_inode_trans(
8524         }
8525  
8526         /* The core is in in-core format */
8527 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8528 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8529 +               mp->m_flags & XFS_MOUNT_TAGGED);
8530  
8531         /* the rest is in on-disk format */
8532         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8533 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_mount.h linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_mount.h
8534 --- linux-2.6.33/fs/xfs/xfs_mount.h     2010-02-25 11:52:06.000000000 +0100
8535 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_mount.h     2010-02-25 12:02:16.000000000 +0100
8536 @@ -298,6 +298,7 @@ typedef struct xfs_mount {
8537                                                    allocator */
8538  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8539  
8540 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8541  
8542  /*
8543   * Default minimum read and write sizes.
8544 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_vnodeops.c linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_vnodeops.c
8545 --- linux-2.6.33/fs/xfs/xfs_vnodeops.c  2010-02-25 11:52:06.000000000 +0100
8546 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_vnodeops.c  2010-02-25 13:24:14.000000000 +0100
8547 @@ -55,6 +55,80 @@
8548  #include "xfs_vnodeops.h"
8549  #include "xfs_trace.h"
8550  
8551 +
8552 +STATIC void
8553 +xfs_get_inode_flags(
8554 +       xfs_inode_t     *ip)
8555 +{
8556 +       struct inode    *inode = VFS_I(ip);
8557 +       unsigned int    flags = inode->i_flags;
8558 +       unsigned int    vflags = inode->i_vflags;
8559 +
8560 +       if (flags & S_IMMUTABLE)
8561 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8562 +       else
8563 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8564 +       if (flags & S_IXUNLINK)
8565 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8566 +       else
8567 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8568 +
8569 +       if (vflags & V_BARRIER)
8570 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8571 +       else
8572 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8573 +       if (vflags & V_COW)
8574 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8575 +       else
8576 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8577 +}
8578 +
8579 +int
8580 +xfs_sync_flags(
8581 +       struct inode            *inode,
8582 +       int                     flags,
8583 +       int                     vflags)
8584 +{
8585 +       struct xfs_inode        *ip = XFS_I(inode);
8586 +       struct xfs_mount        *mp = ip->i_mount;
8587 +       struct xfs_trans        *tp;
8588 +       unsigned int            lock_flags = 0;
8589 +       int                     code;
8590 +
8591 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8592 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8593 +       if (code)
8594 +               goto error_out;
8595 +
8596 +       lock_flags = XFS_ILOCK_EXCL;
8597 +       xfs_ilock(ip, lock_flags);
8598 +
8599 +       xfs_trans_ijoin(tp, ip, lock_flags);
8600 +       xfs_trans_ihold(tp, ip);
8601 +
8602 +       inode->i_flags = flags;
8603 +       inode->i_vflags = vflags;
8604 +       xfs_get_inode_flags(ip);
8605 +
8606 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8607 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8608 +
8609 +       XFS_STATS_INC(xs_ig_attrchg);
8610 +
8611 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8612 +               xfs_trans_set_sync(tp);
8613 +       code = xfs_trans_commit(tp, 0);
8614 +       xfs_iunlock(ip, lock_flags);
8615 +       return code;
8616 +
8617 +error_out:
8618 +       xfs_trans_cancel(tp, 0);
8619 +       if (lock_flags)
8620 +               xfs_iunlock(ip, lock_flags);
8621 +       return code;
8622 +}
8623 +
8624 +
8625  int
8626  xfs_setattr(
8627         struct xfs_inode        *ip,
8628 @@ -70,6 +144,7 @@ xfs_setattr(
8629         uint                    commit_flags=0;
8630         uid_t                   uid=0, iuid=0;
8631         gid_t                   gid=0, igid=0;
8632 +       tag_t                   tag=0, itag=0;
8633         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8634         int                     need_iolock = 1;
8635  
8636 @@ -162,7 +237,7 @@ xfs_setattr(
8637         /*
8638          * Change file ownership.  Must be the owner or privileged.
8639          */
8640 -       if (mask & (ATTR_UID|ATTR_GID)) {
8641 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8642                 /*
8643                  * These IDs could have changed since we last looked at them.
8644                  * But, we're assured that if the ownership did change
8645 @@ -171,8 +246,10 @@ xfs_setattr(
8646                  */
8647                 iuid = ip->i_d.di_uid;
8648                 igid = ip->i_d.di_gid;
8649 +               itag = ip->i_d.di_tag;
8650                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8651                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8652 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8653  
8654                 /*
8655                  * Do a quota reservation only if uid/gid is actually
8656 @@ -180,7 +257,8 @@ xfs_setattr(
8657                  */
8658                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8659                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8660 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8661 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8662 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8663                         ASSERT(tp);
8664                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8665                                                 capable(CAP_FOWNER) ?
8666 @@ -341,7 +419,7 @@ xfs_setattr(
8667         /*
8668          * Change file ownership.  Must be the owner or privileged.
8669          */
8670 -       if (mask & (ATTR_UID|ATTR_GID)) {
8671 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8672                 /*
8673                  * CAP_FSETID overrides the following restrictions:
8674                  *
8675 @@ -357,6 +435,10 @@ xfs_setattr(
8676                  * Change the ownerships and register quota modifications
8677                  * in the transaction.
8678                  */
8679 +               if (itag != tag) {
8680 +                       ip->i_d.di_tag = tag;
8681 +                       inode->i_tag = tag;
8682 +               }
8683                 if (iuid != uid) {
8684                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8685                                 ASSERT(mask & ATTR_UID);
8686 diff -NurpP --minimal linux-2.6.33/fs/xfs/xfs_vnodeops.h linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_vnodeops.h
8687 --- linux-2.6.33/fs/xfs/xfs_vnodeops.h  2010-02-25 11:52:06.000000000 +0100
8688 +++ linux-2.6.33-vs2.3.0.36.30.1/fs/xfs/xfs_vnodeops.h  2010-02-25 12:02:16.000000000 +0100
8689 @@ -14,6 +14,7 @@ struct xfs_inode;
8690  struct xfs_iomap;
8691  
8692  
8693 +int xfs_sync_xflags(struct xfs_inode *ip);
8694  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8695  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8696  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8697 diff -NurpP --minimal linux-2.6.33/include/asm-generic/tlb.h linux-2.6.33-vs2.3.0.36.30.1/include/asm-generic/tlb.h
8698 --- linux-2.6.33/include/asm-generic/tlb.h      2009-09-10 15:26:24.000000000 +0200
8699 +++ linux-2.6.33-vs2.3.0.36.30.1/include/asm-generic/tlb.h      2010-02-25 12:02:16.000000000 +0100
8700 @@ -14,6 +14,7 @@
8701  #define _ASM_GENERIC__TLB_H
8702  
8703  #include <linux/swap.h>
8704 +#include <linux/vs_memory.h>
8705  #include <asm/pgalloc.h>
8706  #include <asm/tlbflush.h>
8707  
8708 diff -NurpP --minimal linux-2.6.33/include/linux/capability.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/capability.h
8709 --- linux-2.6.33/include/linux/capability.h     2010-02-25 11:52:07.000000000 +0100
8710 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/capability.h     2010-02-25 12:02:16.000000000 +0100
8711 @@ -283,6 +283,7 @@ struct cpu_vfs_cap_data {
8712     arbitrary SCSI commands */
8713  /* Allow setting encryption key on loopback filesystem */
8714  /* Allow setting zone reclaim policy */
8715 +/* Allow the selection of a security context */
8716  
8717  #define CAP_SYS_ADMIN        21
8718  
8719 @@ -355,7 +356,13 @@ struct cpu_vfs_cap_data {
8720  
8721  #define CAP_MAC_ADMIN        33
8722  
8723 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8724 +/* Allow context manipulations */
8725 +/* Allow changing context info on files */
8726 +
8727 +#define CAP_CONTEXT         34
8728 +
8729 +
8730 +#define CAP_LAST_CAP         CAP_CONTEXT
8731  
8732  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8733  
8734 diff -NurpP --minimal linux-2.6.33/include/linux/devpts_fs.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/devpts_fs.h
8735 --- linux-2.6.33/include/linux/devpts_fs.h      2008-12-25 00:26:37.000000000 +0100
8736 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/devpts_fs.h      2010-02-25 12:02:16.000000000 +0100
8737 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8738  
8739  #endif
8740  
8741 -
8742  #endif /* _LINUX_DEVPTS_FS_H */
8743 diff -NurpP --minimal linux-2.6.33/include/linux/ext2_fs.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/ext2_fs.h
8744 --- linux-2.6.33/include/linux/ext2_fs.h        2010-02-25 11:52:07.000000000 +0100
8745 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/ext2_fs.h        2010-02-25 12:02:16.000000000 +0100
8746 @@ -189,8 +189,12 @@ struct ext2_group_desc
8747  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8748  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8749  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8750 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8751  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8752  
8753 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8754 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8755 +
8756  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8757  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8758  
8759 @@ -274,7 +278,8 @@ struct ext2_inode {
8760                         __u16   i_pad1;
8761                         __le16  l_i_uid_high;   /* these 2 fields    */
8762                         __le16  l_i_gid_high;   /* were reserved2[0] */
8763 -                       __u32   l_i_reserved2;
8764 +                       __le16  l_i_tag;        /* Context Tag */
8765 +                       __u16   l_i_reserved2;
8766                 } linux2;
8767                 struct {
8768                         __u8    h_i_frag;       /* Fragment number */
8769 @@ -303,6 +308,7 @@ struct ext2_inode {
8770  #define i_gid_low      i_gid
8771  #define i_uid_high     osd2.linux2.l_i_uid_high
8772  #define i_gid_high     osd2.linux2.l_i_gid_high
8773 +#define i_raw_tag      osd2.linux2.l_i_tag
8774  #define i_reserved2    osd2.linux2.l_i_reserved2
8775  #endif
8776  
8777 @@ -347,6 +353,7 @@ struct ext2_inode {
8778  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8779  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8780  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8781 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8782  
8783  
8784  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8785 diff -NurpP --minimal linux-2.6.33/include/linux/ext3_fs.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/ext3_fs.h
8786 --- linux-2.6.33/include/linux/ext3_fs.h        2010-02-25 11:52:07.000000000 +0100
8787 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/ext3_fs.h        2010-02-25 12:02:16.000000000 +0100
8788 @@ -173,10 +173,14 @@ struct ext3_group_desc
8789  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8790  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8791  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8792 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8793  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8794  
8795 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8796 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8797 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8798 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8799 +
8800 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8801 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8802  
8803  /* Flags that should be inherited by new inodes from their parent. */
8804  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8805 @@ -320,7 +324,8 @@ struct ext3_inode {
8806                         __u16   i_pad1;
8807                         __le16  l_i_uid_high;   /* these 2 fields    */
8808                         __le16  l_i_gid_high;   /* were reserved2[0] */
8809 -                       __u32   l_i_reserved2;
8810 +                       __le16  l_i_tag;        /* Context Tag */
8811 +                       __u16   l_i_reserved2;
8812                 } linux2;
8813                 struct {
8814                         __u8    h_i_frag;       /* Fragment number */
8815 @@ -351,6 +356,7 @@ struct ext3_inode {
8816  #define i_gid_low      i_gid
8817  #define i_uid_high     osd2.linux2.l_i_uid_high
8818  #define i_gid_high     osd2.linux2.l_i_gid_high
8819 +#define i_raw_tag      osd2.linux2.l_i_tag
8820  #define i_reserved2    osd2.linux2.l_i_reserved2
8821  
8822  #elif defined(__GNU__)
8823 @@ -414,6 +420,7 @@ struct ext3_inode {
8824  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8825  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8826                                                   * error in ordered mode */
8827 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8828  
8829  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8830  #ifndef _LINUX_EXT2_FS_H
8831 @@ -892,6 +899,7 @@ extern void ext3_get_inode_flags(struct 
8832  extern void ext3_set_aops(struct inode *inode);
8833  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8834                        u64 start, u64 len);
8835 +extern int ext3_sync_flags(struct inode *, int, int);
8836  
8837  /* ioctl.c */
8838  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8839 diff -NurpP --minimal linux-2.6.33/include/linux/fs.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/fs.h
8840 --- linux-2.6.33/include/linux/fs.h     2010-02-25 11:52:07.000000000 +0100
8841 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/fs.h     2010-02-25 13:36:54.000000000 +0100
8842 @@ -206,6 +206,9 @@ struct inodes_stat_t {
8843  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8844  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8845  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8846 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8847 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8848 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8849  #define MS_ACTIVE      (1<<30)
8850  #define MS_NOUSER      (1<<31)
8851  
8852 @@ -232,6 +235,14 @@ struct inodes_stat_t {
8853  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8854  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8855  #define S_PRIVATE      512     /* Inode is fs-internal */
8856 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8857 +
8858 +/* Linux-VServer related Inode flags */
8859 +
8860 +#define V_VALID                1
8861 +#define V_XATTR                2
8862 +#define V_BARRIER      4       /* Barrier for chroot() */
8863 +#define V_COW          8       /* Copy on Write */
8864  
8865  /*
8866   * Note that nosuid etc flags are inode-specific: setting some file-system
8867 @@ -254,12 +265,15 @@ struct inodes_stat_t {
8868  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8869                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8870  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8871 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8872 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8873 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8874 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8875 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8876  
8877  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8878  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8879  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8880 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8881 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8882  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8883  
8884  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8885 @@ -267,6 +281,16 @@ struct inodes_stat_t {
8886  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8887  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8888  
8889 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8890 +
8891 +#ifdef CONFIG_VSERVER_COWBL
8892 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8893 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8894 +#else
8895 +#  define IS_COW(inode)                (0)
8896 +#  define IS_COW_LINK(inode)   (0)
8897 +#endif
8898 +
8899  /* the read-only stuff doesn't really belong here, but any other place is
8900     probably as bad and I don't want to create yet another include file. */
8901  
8902 @@ -349,11 +373,14 @@ struct inodes_stat_t {
8903  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8904  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8905  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8906 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8907  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8908  
8909 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8910 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8911 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8912 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8913  
8914 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8915 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8916  
8917  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8918  #define SYNC_FILE_RANGE_WRITE          2
8919 @@ -435,6 +462,7 @@ typedef void (dio_iodone_t)(struct kiocb
8920  #define ATTR_KILL_PRIV (1 << 14)
8921  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8922  #define ATTR_TIMES_SET (1 << 16)
8923 +#define ATTR_TAG       (1 << 17)
8924  
8925  /*
8926   * This is the Inode Attributes structure, used for notify_change().  It
8927 @@ -450,6 +478,7 @@ struct iattr {
8928         umode_t         ia_mode;
8929         uid_t           ia_uid;
8930         gid_t           ia_gid;
8931 +       tag_t           ia_tag;
8932         loff_t          ia_size;
8933         struct timespec ia_atime;
8934         struct timespec ia_mtime;
8935 @@ -463,6 +492,9 @@ struct iattr {
8936         struct file     *ia_file;
8937  };
8938  
8939 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8940 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8941 +
8942  /*
8943   * Includes for diskquotas.
8944   */
8945 @@ -728,7 +760,9 @@ struct inode {
8946         unsigned int            i_nlink;
8947         uid_t                   i_uid;
8948         gid_t                   i_gid;
8949 +       tag_t                   i_tag;
8950         dev_t                   i_rdev;
8951 +       dev_t                   i_mdev;
8952         unsigned int            i_blkbits;
8953         u64                     i_version;
8954         loff_t                  i_size;
8955 @@ -775,7 +809,8 @@ struct inode {
8956         unsigned long           i_state;
8957         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8958  
8959 -       unsigned int            i_flags;
8960 +       unsigned short          i_flags;
8961 +       unsigned short          i_vflags;
8962  
8963         atomic_t                i_writecount;
8964  #ifdef CONFIG_SECURITY
8965 @@ -863,12 +898,12 @@ static inline void i_size_write(struct i
8966  
8967  static inline unsigned iminor(const struct inode *inode)
8968  {
8969 -       return MINOR(inode->i_rdev);
8970 +       return MINOR(inode->i_mdev);
8971  }
8972  
8973  static inline unsigned imajor(const struct inode *inode)
8974  {
8975 -       return MAJOR(inode->i_rdev);
8976 +       return MAJOR(inode->i_mdev);
8977  }
8978  
8979  extern struct block_device *I_BDEV(struct inode *inode);
8980 @@ -927,6 +962,7 @@ struct file {
8981         loff_t                  f_pos;
8982         struct fown_struct      f_owner;
8983         const struct cred       *f_cred;
8984 +       xid_t                   f_xid;
8985         struct file_ra_state    f_ra;
8986  
8987         u64                     f_version;
8988 @@ -1068,6 +1104,7 @@ struct file_lock {
8989         struct file *fl_file;
8990         loff_t fl_start;
8991         loff_t fl_end;
8992 +       xid_t fl_xid;
8993  
8994         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8995         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8996 @@ -1529,6 +1566,7 @@ struct inode_operations {
8997         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8998         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8999         int (*removexattr) (struct dentry *, const char *);
9000 +       int (*sync_flags) (struct inode *, int, int);
9001         void (*truncate_range)(struct inode *, loff_t, loff_t);
9002         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
9003                           loff_t len);
9004 @@ -1549,6 +1587,7 @@ extern ssize_t vfs_readv(struct file *, 
9005                 unsigned long, loff_t *);
9006  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
9007                 unsigned long, loff_t *);
9008 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
9009  
9010  struct super_operations {
9011         struct inode *(*alloc_inode)(struct super_block *sb);
9012 @@ -2331,6 +2370,7 @@ extern int dcache_dir_open(struct inode 
9013  extern int dcache_dir_close(struct inode *, struct file *);
9014  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
9015  extern int dcache_readdir(struct file *, void *, filldir_t);
9016 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
9017  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
9018  extern int simple_statfs(struct dentry *, struct kstatfs *);
9019  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
9020 diff -NurpP --minimal linux-2.6.33/include/linux/gfs2_ondisk.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/gfs2_ondisk.h
9021 --- linux-2.6.33/include/linux/gfs2_ondisk.h    2010-02-25 11:52:07.000000000 +0100
9022 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/gfs2_ondisk.h    2010-02-25 12:02:16.000000000 +0100
9023 @@ -239,6 +239,9 @@ enum {
9024         gfs2fl_NoAtime          = 7,
9025         gfs2fl_Sync             = 8,
9026         gfs2fl_System           = 9,
9027 +       gfs2fl_IXUnlink         = 16,
9028 +       gfs2fl_Barrier          = 17,
9029 +       gfs2fl_Cow              = 18,
9030         gfs2fl_TruncInProg      = 29,
9031         gfs2fl_InheritDirectio  = 30,
9032         gfs2fl_InheritJdata     = 31,
9033 @@ -255,6 +258,9 @@ enum {
9034  #define GFS2_DIF_NOATIME               0x00000080
9035  #define GFS2_DIF_SYNC                  0x00000100
9036  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
9037 +#define GFS2_DIF_IXUNLINK              0x00010000
9038 +#define GFS2_DIF_BARRIER               0x00020000
9039 +#define GFS2_DIF_COW                   0x00040000
9040  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
9041  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
9042  #define GFS2_DIF_INHERIT_JDATA         0x80000000
9043 diff -NurpP --minimal linux-2.6.33/include/linux/if_tun.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/if_tun.h
9044 --- linux-2.6.33/include/linux/if_tun.h 2009-12-03 20:02:55.000000000 +0100
9045 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/if_tun.h 2010-02-25 12:02:16.000000000 +0100
9046 @@ -48,6 +48,7 @@
9047  #define TUNGETIFF      _IOR('T', 210, unsigned int)
9048  #define TUNGETSNDBUF   _IOR('T', 211, int)
9049  #define TUNSETSNDBUF   _IOW('T', 212, int)
9050 +#define TUNSETNID     _IOW('T', 215, int)
9051  
9052  /* TUNSETIFF ifr flags */
9053  #define IFF_TUN                0x0001
9054 diff -NurpP --minimal linux-2.6.33/include/linux/init_task.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/init_task.h
9055 --- linux-2.6.33/include/linux/init_task.h      2010-02-25 11:52:07.000000000 +0100
9056 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/init_task.h      2010-02-25 12:02:16.000000000 +0100
9057 @@ -180,6 +180,10 @@ extern struct cred init_cred;
9058         INIT_FTRACE_GRAPH                                               \
9059         INIT_TRACE_RECURSION                                            \
9060         INIT_TASK_RCU_PREEMPT(tsk)                                      \
9061 +       .xid            = 0,                                            \
9062 +       .vx_info        = NULL,                                         \
9063 +       .nid            = 0,                                            \
9064 +       .nx_info        = NULL,                                         \
9065  }
9066  
9067  
9068 diff -NurpP --minimal linux-2.6.33/include/linux/ipc.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/ipc.h
9069 --- linux-2.6.33/include/linux/ipc.h    2009-12-03 20:02:55.000000000 +0100
9070 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/ipc.h    2010-02-25 12:02:16.000000000 +0100
9071 @@ -91,6 +91,7 @@ struct kern_ipc_perm
9072         key_t           key;
9073         uid_t           uid;
9074         gid_t           gid;
9075 +       xid_t           xid;
9076         uid_t           cuid;
9077         gid_t           cgid;
9078         mode_t          mode; 
9079 diff -NurpP --minimal linux-2.6.33/include/linux/Kbuild linux-2.6.33-vs2.3.0.36.30.1/include/linux/Kbuild
9080 --- linux-2.6.33/include/linux/Kbuild   2010-02-25 11:52:07.000000000 +0100
9081 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/Kbuild   2010-02-25 12:02:16.000000000 +0100
9082 @@ -383,5 +383,8 @@ unifdef-y += xattr.h
9083  unifdef-y += xfrm.h
9084  
9085  objhdr-y += version.h
9086 +
9087 +header-y += vserver/
9088  header-y += wimax.h
9089  header-y += wimax/
9090 +
9091 diff -NurpP --minimal linux-2.6.33/include/linux/loop.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/loop.h
9092 --- linux-2.6.33/include/linux/loop.h   2009-09-10 15:26:25.000000000 +0200
9093 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/loop.h   2010-02-25 12:02:16.000000000 +0100
9094 @@ -45,6 +45,7 @@ struct loop_device {
9095         struct loop_func_table *lo_encryption;
9096         __u32           lo_init[2];
9097         uid_t           lo_key_owner;   /* Who set the key */
9098 +       xid_t           lo_xid;
9099         int             (*ioctl)(struct loop_device *, int cmd, 
9100                                  unsigned long arg); 
9101  
9102 diff -NurpP --minimal linux-2.6.33/include/linux/magic.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/magic.h
9103 --- linux-2.6.33/include/linux/magic.h  2009-12-03 20:02:55.000000000 +0100
9104 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/magic.h  2010-02-25 12:02:16.000000000 +0100
9105 @@ -3,7 +3,7 @@
9106  
9107  #define ADFS_SUPER_MAGIC       0xadf5
9108  #define AFFS_SUPER_MAGIC       0xadff
9109 -#define AFS_SUPER_MAGIC                0x5346414F
9110 +#define AFS_SUPER_MAGIC                0x5346414F
9111  #define AUTOFS_SUPER_MAGIC     0x0187
9112  #define CODA_SUPER_MAGIC       0x73757245
9113  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
9114 @@ -38,6 +38,7 @@
9115  #define NFS_SUPER_MAGIC                0x6969
9116  #define OPENPROM_SUPER_MAGIC   0x9fa1
9117  #define PROC_SUPER_MAGIC       0x9fa0
9118 +#define DEVPTS_SUPER_MAGIC     0x1cd1
9119  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
9120  
9121  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
9122 diff -NurpP --minimal linux-2.6.33/include/linux/major.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/major.h
9123 --- linux-2.6.33/include/linux/major.h  2009-09-10 15:26:25.000000000 +0200
9124 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/major.h  2010-02-25 12:02:16.000000000 +0100
9125 @@ -15,6 +15,7 @@
9126  #define HD_MAJOR               IDE0_MAJOR
9127  #define PTY_SLAVE_MAJOR                3
9128  #define TTY_MAJOR              4
9129 +#define VROOT_MAJOR            4
9130  #define TTYAUX_MAJOR           5
9131  #define LP_MAJOR               6
9132  #define VCS_MAJOR              7
9133 diff -NurpP --minimal linux-2.6.33/include/linux/memcontrol.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/memcontrol.h
9134 --- linux-2.6.33/include/linux/memcontrol.h     2010-02-25 11:52:07.000000000 +0100
9135 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/memcontrol.h     2010-02-25 12:02:16.000000000 +0100
9136 @@ -76,6 +76,13 @@ int task_in_mem_cgroup(struct task_struc
9137  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
9138  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
9139  
9140 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
9141 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
9142 +
9143 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
9144 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
9145 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
9146 +
9147  static inline
9148  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
9149  {
9150 diff -NurpP --minimal linux-2.6.33/include/linux/mm_types.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/mm_types.h
9151 --- linux-2.6.33/include/linux/mm_types.h       2010-02-25 11:52:07.000000000 +0100
9152 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/mm_types.h       2010-02-25 12:02:16.000000000 +0100
9153 @@ -250,6 +250,7 @@ struct mm_struct {
9154  
9155         /* Architecture-specific MM context */
9156         mm_context_t context;
9157 +       struct vx_info *mm_vx_info;
9158  
9159         /* Swap token stuff */
9160         /*
9161 diff -NurpP --minimal linux-2.6.33/include/linux/mount.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/mount.h
9162 --- linux-2.6.33/include/linux/mount.h  2009-09-10 15:26:25.000000000 +0200
9163 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/mount.h  2010-02-25 12:02:16.000000000 +0100
9164 @@ -36,6 +36,9 @@ struct mnt_namespace;
9165  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
9166  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
9167  
9168 +#define MNT_TAGID      0x10000
9169 +#define MNT_NOTAG      0x20000
9170 +
9171  struct vfsmount {
9172         struct list_head mnt_hash;
9173         struct vfsmount *mnt_parent;    /* fs we are mounted on */
9174 @@ -70,6 +73,7 @@ struct vfsmount {
9175  #else
9176         int mnt_writers;
9177  #endif
9178 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9179  };
9180  
9181  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
9182 diff -NurpP --minimal linux-2.6.33/include/linux/net.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/net.h
9183 --- linux-2.6.33/include/linux/net.h    2010-02-25 11:52:07.000000000 +0100
9184 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/net.h    2010-02-25 12:02:16.000000000 +0100
9185 @@ -70,6 +70,7 @@ struct net;
9186  #define SOCK_NOSPACE           2
9187  #define SOCK_PASSCRED          3
9188  #define SOCK_PASSSEC           4
9189 +#define SOCK_USER_SOCKET       5
9190  
9191  #ifndef ARCH_HAS_SOCKET_TYPES
9192  /**
9193 diff -NurpP --minimal linux-2.6.33/include/linux/nfs_mount.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/nfs_mount.h
9194 --- linux-2.6.33/include/linux/nfs_mount.h      2009-03-24 14:22:43.000000000 +0100
9195 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/nfs_mount.h      2010-02-25 12:02:16.000000000 +0100
9196 @@ -63,7 +63,8 @@ struct nfs_mount_data {
9197  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9198  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9199  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9200 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9201 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9202 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9203  
9204  /* The following are for internal use only */
9205  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9206 diff -NurpP --minimal linux-2.6.33/include/linux/nsproxy.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/nsproxy.h
9207 --- linux-2.6.33/include/linux/nsproxy.h        2009-06-11 17:13:17.000000000 +0200
9208 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/nsproxy.h        2010-02-25 12:02:16.000000000 +0100
9209 @@ -3,6 +3,7 @@
9210  
9211  #include <linux/spinlock.h>
9212  #include <linux/sched.h>
9213 +#include <linux/vserver/debug.h>
9214  
9215  struct mnt_namespace;
9216  struct uts_namespace;
9217 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9218  }
9219  
9220  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9221 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9222  void exit_task_namespaces(struct task_struct *tsk);
9223  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9224  void free_nsproxy(struct nsproxy *ns);
9225  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9226         struct fs_struct *);
9227  
9228 -static inline void put_nsproxy(struct nsproxy *ns)
9229 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9230 +
9231 +static inline void __get_nsproxy(struct nsproxy *ns,
9232 +       const char *_file, int _line)
9233  {
9234 -       if (atomic_dec_and_test(&ns->count)) {
9235 -               free_nsproxy(ns);
9236 -       }
9237 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9238 +               ns, atomic_read(&ns->count), _file, _line);
9239 +       atomic_inc(&ns->count);
9240  }
9241  
9242 -static inline void get_nsproxy(struct nsproxy *ns)
9243 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9244 +
9245 +static inline void __put_nsproxy(struct nsproxy *ns,
9246 +       const char *_file, int _line)
9247  {
9248 -       atomic_inc(&ns->count);
9249 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9250 +               ns, atomic_read(&ns->count), _file, _line);
9251 +       if (atomic_dec_and_test(&ns->count)) {
9252 +               free_nsproxy(ns);
9253 +       }
9254  }
9255  
9256  #ifdef CONFIG_CGROUP_NS
9257 diff -NurpP --minimal linux-2.6.33/include/linux/pid.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/pid.h
9258 --- linux-2.6.33/include/linux/pid.h    2009-03-24 14:22:43.000000000 +0100
9259 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/pid.h    2010-02-25 12:02:16.000000000 +0100
9260 @@ -8,7 +8,8 @@ enum pid_type
9261         PIDTYPE_PID,
9262         PIDTYPE_PGID,
9263         PIDTYPE_SID,
9264 -       PIDTYPE_MAX
9265 +       PIDTYPE_MAX,
9266 +       PIDTYPE_REALPID
9267  };
9268  
9269  /*
9270 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9271  }
9272  
9273  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9274 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9275  pid_t pid_vnr(struct pid *pid);
9276  
9277  #define do_each_pid_task(pid, type, task)                              \
9278 diff -NurpP --minimal linux-2.6.33/include/linux/proc_fs.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/proc_fs.h
9279 --- linux-2.6.33/include/linux/proc_fs.h        2009-12-03 20:02:56.000000000 +0100
9280 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/proc_fs.h        2010-02-25 12:02:16.000000000 +0100
9281 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9282         nlink_t nlink;
9283         uid_t uid;
9284         gid_t gid;
9285 +       int vx_flags;
9286         loff_t size;
9287         const struct inode_operations *proc_iops;
9288         /*
9289 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9290  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9291  #endif
9292  
9293 +struct vx_info;
9294 +struct nx_info;
9295 +
9296  union proc_op {
9297         int (*proc_get_link)(struct inode *, struct path *);
9298         int (*proc_read)(struct task_struct *task, char *page);
9299         int (*proc_show)(struct seq_file *m,
9300                 struct pid_namespace *ns, struct pid *pid,
9301                 struct task_struct *task);
9302 +       int (*proc_vs_read)(char *page);
9303 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9304 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9305  };
9306  
9307  struct ctl_table_header;
9308 @@ -263,6 +270,7 @@ struct ctl_table;
9309  
9310  struct proc_inode {
9311         struct pid *pid;
9312 +       int vx_flags;
9313         int fd;
9314         union proc_op op;
9315         struct proc_dir_entry *pde;
9316 diff -NurpP --minimal linux-2.6.33/include/linux/quotaops.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/quotaops.h
9317 --- linux-2.6.33/include/linux/quotaops.h       2009-12-03 20:02:56.000000000 +0100
9318 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/quotaops.h       2010-02-25 12:02:16.000000000 +0100
9319 @@ -8,6 +8,7 @@
9320  #define _LINUX_QUOTAOPS_
9321  
9322  #include <linux/fs.h>
9323 +#include <linux/vs_dlimit.h>
9324  
9325  static inline struct quota_info *sb_dqopt(struct super_block *sb)
9326  {
9327 @@ -154,10 +155,14 @@ static inline void vfs_dq_init(struct in
9328   * a transaction (deadlocks possible otherwise) */
9329  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9330  {
9331 +       if (dl_alloc_space(inode, nr))
9332 +               return 1;
9333         if (sb_any_quota_active(inode->i_sb)) {
9334                 /* Used space is updated in alloc_space() */
9335 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
9336 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) {
9337 +                       dl_free_space(inode, nr);
9338                         return 1;
9339 +               }
9340         }
9341         else
9342                 inode_add_bytes(inode, nr);
9343 @@ -174,10 +179,14 @@ static inline int vfs_dq_prealloc_space(
9344  
9345  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9346  {
9347 +       if (dl_alloc_space(inode, nr))
9348 +               return 1;
9349         if (sb_any_quota_active(inode->i_sb)) {
9350                 /* Used space is updated in alloc_space() */
9351 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
9352 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) {
9353 +                       dl_free_space(inode, nr);
9354                         return 1;
9355 +               }
9356         }
9357         else
9358                 inode_add_bytes(inode, nr);
9359 @@ -194,20 +203,28 @@ static inline int vfs_dq_alloc_space(str
9360  
9361  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9362  {
9363 +       if (dl_reserve_space(inode, nr))
9364 +               return 1;
9365         if (sb_any_quota_active(inode->i_sb)) {
9366                 /* Used space is updated in alloc_space() */
9367 -               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
9368 +               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA) {
9369 +                       dl_release_space(inode, nr);
9370                         return 1;
9371 +               }
9372         }
9373         return 0;
9374  }
9375  
9376  static inline int vfs_dq_alloc_inode(struct inode *inode)
9377  {
9378 +       if (dl_alloc_inode(inode))
9379 +               return 1;
9380         if (sb_any_quota_active(inode->i_sb)) {
9381                 vfs_dq_init(inode);
9382 -               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
9383 +               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
9384 +                       dl_free_inode(inode);
9385                         return 1;
9386 +               }
9387         }
9388         return 0;
9389  }
9390 @@ -217,9 +234,13 @@ static inline int vfs_dq_alloc_inode(str
9391   */
9392  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9393  {
9394 +       if (dl_claim_space(inode, nr))
9395 +               return 1;
9396         if (sb_any_quota_active(inode->i_sb)) {
9397 -               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
9398 +               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA) {
9399 +                       dl_release_space(inode, nr);
9400                         return 1;
9401 +               }
9402         } else
9403                 inode_add_bytes(inode, nr);
9404  
9405 @@ -235,6 +256,7 @@ void vfs_dq_release_reservation_space(st
9406  {
9407         if (sb_any_quota_active(inode->i_sb))
9408                 inode->i_sb->dq_op->release_rsv(inode, nr);
9409 +       dl_release_space(inode, nr);
9410  }
9411  
9412  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9413 @@ -243,6 +265,7 @@ static inline void vfs_dq_free_space_nod
9414                 inode->i_sb->dq_op->free_space(inode, nr);
9415         else
9416                 inode_sub_bytes(inode, nr);
9417 +       dl_free_space(inode, nr);
9418  }
9419  
9420  static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
9421 @@ -255,6 +278,7 @@ static inline void vfs_dq_free_inode(str
9422  {
9423         if (sb_any_quota_active(inode->i_sb))
9424                 inode->i_sb->dq_op->free_inode(inode, 1);
9425 +       dl_free_inode(inode);
9426  }
9427  
9428  /* Cannot be called inside a transaction */
9429 @@ -358,6 +382,8 @@ static inline int vfs_dq_transfer(struct
9430  
9431  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9432  {
9433 +       if (dl_alloc_space(inode, nr))
9434 +               return 1;
9435         inode_add_bytes(inode, nr);
9436         return 0;
9437  }
9438 @@ -371,6 +397,8 @@ static inline int vfs_dq_prealloc_space(
9439  
9440  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9441  {
9442 +       if (dl_alloc_space(inode, nr))
9443 +               return 1;
9444         inode_add_bytes(inode, nr);
9445         return 0;
9446  }
9447 @@ -384,22 +412,28 @@ static inline int vfs_dq_alloc_space(str
9448  
9449  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9450  {
9451 +       if (dl_reserve_space(inode, nr))
9452 +               return 1;
9453         return 0;
9454  }
9455  
9456  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9457  {
9458 +       if (dl_claim_space(inode, nr))
9459 +               return 1;
9460         return vfs_dq_alloc_space(inode, nr);
9461  }
9462  
9463  static inline
9464  int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
9465  {
9466 +       dl_release_space(inode, nr);
9467         return 0;
9468  }
9469  
9470  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9471  {
9472 +       dl_free_space(inode, nr);
9473         inode_sub_bytes(inode, nr);
9474  }
9475  
9476 diff -NurpP --minimal linux-2.6.33/include/linux/reboot.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/reboot.h
9477 --- linux-2.6.33/include/linux/reboot.h 2008-12-25 00:26:37.000000000 +0100
9478 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/reboot.h 2010-02-25 12:02:16.000000000 +0100
9479 @@ -33,6 +33,7 @@
9480  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9481  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9482  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9483 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9484  
9485  
9486  #ifdef __KERNEL__
9487 diff -NurpP --minimal linux-2.6.33/include/linux/reiserfs_fs.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/reiserfs_fs.h
9488 --- linux-2.6.33/include/linux/reiserfs_fs.h    2010-02-25 11:52:07.000000000 +0100
9489 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/reiserfs_fs.h    2010-02-25 12:02:16.000000000 +0100
9490 @@ -977,6 +977,11 @@ struct stat_data_v1 {
9491  #define REISERFS_COMPR_FL     FS_COMPR_FL
9492  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9493  
9494 +/* unfortunately reiserfs sdattr is only 16 bit */
9495 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9496 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9497 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9498 +
9499  /* persistent flags that file inherits from the parent directory */
9500  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9501                                 REISERFS_SYNC_FL |      \
9502 @@ -986,6 +991,9 @@ struct stat_data_v1 {
9503                                 REISERFS_COMPR_FL |     \
9504                                 REISERFS_NOTAIL_FL )
9505  
9506 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9507 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9508 +
9509  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9510     address blocks) */
9511  struct stat_data {
9512 @@ -2071,6 +2079,7 @@ static inline void reiserfs_update_sd(st
9513  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9514  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9515  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9516 +int reiserfs_sync_flags(struct inode *inode, int, int);
9517  
9518  /* namei.c */
9519  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9520 diff -NurpP --minimal linux-2.6.33/include/linux/reiserfs_fs_sb.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/reiserfs_fs_sb.h
9521 --- linux-2.6.33/include/linux/reiserfs_fs_sb.h 2010-02-25 11:52:07.000000000 +0100
9522 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/reiserfs_fs_sb.h 2010-02-25 12:02:16.000000000 +0100
9523 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9524         REISERFS_EXPOSE_PRIVROOT,
9525         REISERFS_BARRIER_NONE,
9526         REISERFS_BARRIER_FLUSH,
9527 +       REISERFS_TAGGED,
9528  
9529         /* Actions on error */
9530         REISERFS_ERROR_PANIC,
9531 diff -NurpP --minimal linux-2.6.33/include/linux/sched.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/sched.h
9532 --- linux-2.6.33/include/linux/sched.h  2010-02-25 11:52:07.000000000 +0100
9533 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/sched.h  2010-02-25 16:23:29.000000000 +0100
9534 @@ -401,25 +401,28 @@ static inline void arch_pick_mmap_layout
9535   * The mm counters are not protected by its page_table_lock,
9536   * so must be incremented atomically.
9537   */
9538 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9539 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9540 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9541 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9542 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9543 +#define __set_mm_counter(mm, member, value) \
9544 +       atomic_long_set(&(mm)->_##member, value)
9545 +#define get_mm_counter(mm, member) \
9546 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9547  
9548  #else  /* !USE_SPLIT_PTLOCKS */
9549  /*
9550   * The mm counters are protected by its page_table_lock,
9551   * so can be incremented directly.
9552   */
9553 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9554 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9555  #define get_mm_counter(mm, member) ((mm)->_##member)
9556 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9557 -#define inc_mm_counter(mm, member) (mm)->_##member++
9558 -#define dec_mm_counter(mm, member) (mm)->_##member--
9559  
9560  #endif /* !USE_SPLIT_PTLOCKS */
9561  
9562 +#define set_mm_counter(mm, member, value) \
9563 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9564 +#define add_mm_counter(mm, member, value) \
9565 +       vx_ ## member ## pages_add((mm), (value))
9566 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9567 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9568 +
9569  #define get_mm_rss(mm)                                 \
9570         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9571  #define update_hiwater_rss(mm) do {                    \
9572 @@ -1200,6 +1203,12 @@ struct sched_entity {
9573         u64                     nr_wakeups_affine_attempts;
9574         u64                     nr_wakeups_passive;
9575         u64                     nr_wakeups_idle;
9576 +#ifdef CONFIG_CFS_HARD_LIMITS
9577 +       u64                     throttle_start;
9578 +       u64                     throttle_max;
9579 +       u64                     throttle_count;
9580 +       u64                     throttle_sum;
9581 +#endif
9582  #endif
9583  
9584  #ifdef CONFIG_FAIR_GROUP_SCHED
9585 @@ -1412,6 +1421,14 @@ struct task_struct {
9586  #endif
9587         seccomp_t seccomp;
9588  
9589 +/* vserver context data */
9590 +       struct vx_info *vx_info;
9591 +       struct nx_info *nx_info;
9592 +
9593 +       xid_t xid;
9594 +       nid_t nid;
9595 +       tag_t tag;
9596 +
9597  /* Thread group tracking */
9598         u32 parent_exec_id;
9599         u32 self_exec_id;
9600 @@ -1645,6 +1662,11 @@ struct pid_namespace;
9601  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9602                         struct pid_namespace *ns);
9603  
9604 +#include <linux/vserver/base.h>
9605 +#include <linux/vserver/context.h>
9606 +#include <linux/vserver/debug.h>
9607 +#include <linux/vserver/pid.h>
9608 +
9609  static inline pid_t task_pid_nr(struct task_struct *tsk)
9610  {
9611         return tsk->pid;
9612 @@ -1658,7 +1680,8 @@ static inline pid_t task_pid_nr_ns(struc
9613  
9614  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9615  {
9616 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9617 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9618 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9619  }
9620  
9621  
9622 @@ -1671,7 +1694,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9623  
9624  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9625  {
9626 -       return pid_vnr(task_tgid(tsk));
9627 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9628  }
9629  
9630  
9631 diff -NurpP --minimal linux-2.6.33/include/linux/shmem_fs.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/shmem_fs.h
9632 --- linux-2.6.33/include/linux/shmem_fs.h       2010-02-25 11:52:08.000000000 +0100
9633 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/shmem_fs.h       2010-02-25 12:02:16.000000000 +0100
9634 @@ -8,6 +8,9 @@
9635  
9636  #define SHMEM_NR_DIRECT 16
9637  
9638 +#define TMPFS_SUPER_MAGIC      0x01021994
9639 +
9640 +
9641  struct shmem_inode_info {
9642         spinlock_t              lock;
9643         unsigned long           flags;
9644 diff -NurpP --minimal linux-2.6.33/include/linux/stat.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/stat.h
9645 --- linux-2.6.33/include/linux/stat.h   2008-12-25 00:26:37.000000000 +0100
9646 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/stat.h   2010-02-25 12:02:16.000000000 +0100
9647 @@ -66,6 +66,7 @@ struct kstat {
9648         unsigned int    nlink;
9649         uid_t           uid;
9650         gid_t           gid;
9651 +       tag_t           tag;
9652         dev_t           rdev;
9653         loff_t          size;
9654         struct timespec  atime;
9655 diff -NurpP --minimal linux-2.6.33/include/linux/sunrpc/auth.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/sunrpc/auth.h
9656 --- linux-2.6.33/include/linux/sunrpc/auth.h    2009-12-03 20:02:56.000000000 +0100
9657 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/sunrpc/auth.h    2010-02-25 12:02:16.000000000 +0100
9658 @@ -25,6 +25,7 @@
9659  struct auth_cred {
9660         uid_t   uid;
9661         gid_t   gid;
9662 +       tag_t   tag;
9663         struct group_info *group_info;
9664         unsigned char machine_cred : 1;
9665  };
9666 diff -NurpP --minimal linux-2.6.33/include/linux/sunrpc/clnt.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/sunrpc/clnt.h
9667 --- linux-2.6.33/include/linux/sunrpc/clnt.h    2009-12-03 20:02:56.000000000 +0100
9668 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/sunrpc/clnt.h    2010-02-25 12:02:16.000000000 +0100
9669 @@ -49,7 +49,8 @@ struct rpc_clnt {
9670         unsigned int            cl_softrtry : 1,/* soft timeouts */
9671                                 cl_discrtry : 1,/* disconnect before retry */
9672                                 cl_autobind : 1,/* use getport() */
9673 -                               cl_chatty   : 1;/* be verbose */
9674 +                               cl_chatty   : 1,/* be verbose */
9675 +                               cl_tag      : 1;/* context tagging */
9676  
9677         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9678         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9679 diff -NurpP --minimal linux-2.6.33/include/linux/syscalls.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/syscalls.h
9680 --- linux-2.6.33/include/linux/syscalls.h       2010-02-25 11:52:08.000000000 +0100
9681 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/syscalls.h       2010-02-25 12:02:16.000000000 +0100
9682 @@ -496,6 +496,8 @@ asmlinkage long sys_symlink(const char _
9683  asmlinkage long sys_unlink(const char __user *pathname);
9684  asmlinkage long sys_rename(const char __user *oldname,
9685                                 const char __user *newname);
9686 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9687 +                               umode_t mode);
9688  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9689  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9690  
9691 diff -NurpP --minimal linux-2.6.33/include/linux/sysctl.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/sysctl.h
9692 --- linux-2.6.33/include/linux/sysctl.h 2010-02-25 11:52:08.000000000 +0100
9693 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/sysctl.h 2010-02-25 12:02:16.000000000 +0100
9694 @@ -60,6 +60,7 @@ enum
9695         CTL_ABI=9,              /* Binary emulation */
9696         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9697         CTL_ARLAN=254,          /* arlan wireless driver */
9698 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9699         CTL_S390DBF=5677,       /* s390 debug */
9700         CTL_SUNRPC=7249,        /* sunrpc debug */
9701         CTL_PM=9899,            /* frv power management */
9702 @@ -94,6 +95,7 @@ enum
9703  
9704         KERN_PANIC=15,          /* int: panic timeout */
9705         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9706 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9707  
9708         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9709         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9710 diff -NurpP --minimal linux-2.6.33/include/linux/sysfs.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/sysfs.h
9711 --- linux-2.6.33/include/linux/sysfs.h  2010-02-25 11:52:08.000000000 +0100
9712 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/sysfs.h  2010-02-25 12:02:16.000000000 +0100
9713 @@ -17,6 +17,8 @@
9714  #include <linux/list.h>
9715  #include <asm/atomic.h>
9716  
9717 +#define SYSFS_SUPER_MAGIC      0x62656572
9718 +
9719  struct kobject;
9720  struct module;
9721  
9722 diff -NurpP --minimal linux-2.6.33/include/linux/time.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/time.h
9723 --- linux-2.6.33/include/linux/time.h   2010-02-25 11:52:08.000000000 +0100
9724 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/time.h   2010-02-25 12:02:16.000000000 +0100
9725 @@ -238,6 +238,9 @@ static __always_inline void timespec_add
9726         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9727         a->tv_nsec = ns;
9728  }
9729 +
9730 +#include <linux/vs_time.h>
9731 +
9732  #endif /* __KERNEL__ */
9733  
9734  #define NFDBITS                        __NFDBITS
9735 diff -NurpP --minimal linux-2.6.33/include/linux/types.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/types.h
9736 --- linux-2.6.33/include/linux/types.h  2009-09-10 15:26:26.000000000 +0200
9737 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/types.h  2010-02-25 12:02:16.000000000 +0100
9738 @@ -37,6 +37,9 @@ typedef __kernel_uid32_t      uid_t;
9739  typedef __kernel_gid32_t       gid_t;
9740  typedef __kernel_uid16_t        uid16_t;
9741  typedef __kernel_gid16_t        gid16_t;
9742 +typedef unsigned int           xid_t;
9743 +typedef unsigned int           nid_t;
9744 +typedef unsigned int           tag_t;
9745  
9746  typedef unsigned long          uintptr_t;
9747  
9748 diff -NurpP --minimal linux-2.6.33/include/linux/vroot.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vroot.h
9749 --- linux-2.6.33/include/linux/vroot.h  1970-01-01 01:00:00.000000000 +0100
9750 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vroot.h  2010-02-25 12:02:16.000000000 +0100
9751 @@ -0,0 +1,51 @@
9752 +
9753 +/*
9754 + * include/linux/vroot.h
9755 + *
9756 + * written by Herbert Pötzl, 9/11/2002
9757 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9758 + *
9759 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9760 + * Redistribution of this file is permitted under the
9761 + * GNU General Public License.
9762 + */
9763 +
9764 +#ifndef _LINUX_VROOT_H
9765 +#define _LINUX_VROOT_H
9766 +
9767 +
9768 +#ifdef __KERNEL__
9769 +
9770 +/* Possible states of device */
9771 +enum {
9772 +       Vr_unbound,
9773 +       Vr_bound,
9774 +};
9775 +
9776 +struct vroot_device {
9777 +       int             vr_number;
9778 +       int             vr_refcnt;
9779 +
9780 +       struct semaphore        vr_ctl_mutex;
9781 +       struct block_device    *vr_device;
9782 +       int                     vr_state;
9783 +};
9784 +
9785 +
9786 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9787 +
9788 +extern int register_vroot_grb(vroot_grb_func *);
9789 +extern int unregister_vroot_grb(vroot_grb_func *);
9790 +
9791 +#endif /* __KERNEL__ */
9792 +
9793 +#define MAX_VROOT_DEFAULT      8
9794 +
9795 +/*
9796 + * IOCTL commands --- we will commandeer 0x56 ('V')
9797 + */
9798 +
9799 +#define VROOT_SET_DEV          0x5600
9800 +#define VROOT_CLR_DEV          0x5601
9801 +
9802 +#endif /* _LINUX_VROOT_H */
9803 diff -NurpP --minimal linux-2.6.33/include/linux/vs_base.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_base.h
9804 --- linux-2.6.33/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
9805 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_base.h        2010-02-25 12:02:16.000000000 +0100
9806 @@ -0,0 +1,10 @@
9807 +#ifndef _VS_BASE_H
9808 +#define _VS_BASE_H
9809 +
9810 +#include "vserver/base.h"
9811 +#include "vserver/check.h"
9812 +#include "vserver/debug.h"
9813 +
9814 +#else
9815 +#warning duplicate inclusion
9816 +#endif
9817 diff -NurpP --minimal linux-2.6.33/include/linux/vs_context.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_context.h
9818 --- linux-2.6.33/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
9819 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_context.h     2010-02-25 12:02:16.000000000 +0100
9820 @@ -0,0 +1,242 @@
9821 +#ifndef _VS_CONTEXT_H
9822 +#define _VS_CONTEXT_H
9823 +
9824 +#include "vserver/base.h"
9825 +#include "vserver/check.h"
9826 +#include "vserver/context.h"
9827 +#include "vserver/history.h"
9828 +#include "vserver/debug.h"
9829 +
9830 +#include <linux/sched.h>
9831 +
9832 +
9833 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9834 +
9835 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9836 +       const char *_file, int _line, void *_here)
9837 +{
9838 +       if (!vxi)
9839 +               return NULL;
9840 +
9841 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9842 +               vxi, vxi ? vxi->vx_id : 0,
9843 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9844 +               _file, _line);
9845 +       __vxh_get_vx_info(vxi, _here);
9846 +
9847 +       atomic_inc(&vxi->vx_usecnt);
9848 +       return vxi;
9849 +}
9850 +
9851 +
9852 +extern void free_vx_info(struct vx_info *);
9853 +
9854 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9855 +
9856 +static inline void __put_vx_info(struct vx_info *vxi,
9857 +       const char *_file, int _line, void *_here)
9858 +{
9859 +       if (!vxi)
9860 +               return;
9861 +
9862 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9863 +               vxi, vxi ? vxi->vx_id : 0,
9864 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9865 +               _file, _line);
9866 +       __vxh_put_vx_info(vxi, _here);
9867 +
9868 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9869 +               free_vx_info(vxi);
9870 +}
9871 +
9872 +
9873 +#define init_vx_info(p, i) \
9874 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9875 +
9876 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9877 +       const char *_file, int _line, void *_here)
9878 +{
9879 +       if (vxi) {
9880 +               vxlprintk(VXD_CBIT(xid, 3),
9881 +                       "init_vx_info(%p[#%d.%d])",
9882 +                       vxi, vxi ? vxi->vx_id : 0,
9883 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9884 +                       _file, _line);
9885 +               __vxh_init_vx_info(vxi, vxp, _here);
9886 +
9887 +               atomic_inc(&vxi->vx_usecnt);
9888 +       }
9889 +       *vxp = vxi;
9890 +}
9891 +
9892 +
9893 +#define set_vx_info(p, i) \
9894 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9895 +
9896 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9897 +       const char *_file, int _line, void *_here)
9898 +{
9899 +       struct vx_info *vxo;
9900 +
9901 +       if (!vxi)
9902 +               return;
9903 +
9904 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9905 +               vxi, vxi ? vxi->vx_id : 0,
9906 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9907 +               _file, _line);
9908 +       __vxh_set_vx_info(vxi, vxp, _here);
9909 +
9910 +       atomic_inc(&vxi->vx_usecnt);
9911 +       vxo = xchg(vxp, vxi);
9912 +       BUG_ON(vxo);
9913 +}
9914 +
9915 +
9916 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9917 +
9918 +static inline void __clr_vx_info(struct vx_info **vxp,
9919 +       const char *_file, int _line, void *_here)
9920 +{
9921 +       struct vx_info *vxo;
9922 +
9923 +       vxo = xchg(vxp, NULL);
9924 +       if (!vxo)
9925 +               return;
9926 +
9927 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9928 +               vxo, vxo ? vxo->vx_id : 0,
9929 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9930 +               _file, _line);
9931 +       __vxh_clr_vx_info(vxo, vxp, _here);
9932 +
9933 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9934 +               free_vx_info(vxo);
9935 +}
9936 +
9937 +
9938 +#define claim_vx_info(v, p) \
9939 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9940 +
9941 +static inline void __claim_vx_info(struct vx_info *vxi,
9942 +       struct task_struct *task,
9943 +       const char *_file, int _line, void *_here)
9944 +{
9945 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9946 +               vxi, vxi ? vxi->vx_id : 0,
9947 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9948 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9949 +               task, _file, _line);
9950 +       __vxh_claim_vx_info(vxi, task, _here);
9951 +
9952 +       atomic_inc(&vxi->vx_tasks);
9953 +}
9954 +
9955 +
9956 +extern void unhash_vx_info(struct vx_info *);
9957 +
9958 +#define release_vx_info(v, p) \
9959 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9960 +
9961 +static inline void __release_vx_info(struct vx_info *vxi,
9962 +       struct task_struct *task,
9963 +       const char *_file, int _line, void *_here)
9964 +{
9965 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9966 +               vxi, vxi ? vxi->vx_id : 0,
9967 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9968 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9969 +               task, _file, _line);
9970 +       __vxh_release_vx_info(vxi, task, _here);
9971 +
9972 +       might_sleep();
9973 +
9974 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9975 +               unhash_vx_info(vxi);
9976 +}
9977 +
9978 +
9979 +#define task_get_vx_info(p) \
9980 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9981 +
9982 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9983 +       const char *_file, int _line, void *_here)
9984 +{
9985 +       struct vx_info *vxi;
9986 +
9987 +       task_lock(p);
9988 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9989 +               p, _file, _line);
9990 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9991 +       task_unlock(p);
9992 +       return vxi;
9993 +}
9994 +
9995 +
9996 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9997 +{
9998 +       if (waitqueue_active(&vxi->vx_wait))
9999 +               wake_up_interruptible(&vxi->vx_wait);
10000 +}
10001 +
10002 +
10003 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
10004 +
10005 +static inline void __enter_vx_info(struct vx_info *vxi,
10006 +       struct vx_info_save *vxis, const char *_file, int _line)
10007 +{
10008 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
10009 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
10010 +               current->xid, current->vx_info, _file, _line);
10011 +       vxis->vxi = xchg(&current->vx_info, vxi);
10012 +       vxis->xid = current->xid;
10013 +       current->xid = vxi ? vxi->vx_id : 0;
10014 +}
10015 +
10016 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
10017 +
10018 +static inline void __leave_vx_info(struct vx_info_save *vxis,
10019 +       const char *_file, int _line)
10020 +{
10021 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
10022 +               vxis, vxis->xid, vxis->vxi, current,
10023 +               current->xid, current->vx_info, _file, _line);
10024 +       (void)xchg(&current->vx_info, vxis->vxi);
10025 +       current->xid = vxis->xid;
10026 +}
10027 +
10028 +
10029 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
10030 +{
10031 +       vxis->vxi = xchg(&current->vx_info, NULL);
10032 +       vxis->xid = xchg(&current->xid, (xid_t)0);
10033 +}
10034 +
10035 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
10036 +{
10037 +       (void)xchg(&current->xid, vxis->xid);
10038 +       (void)xchg(&current->vx_info, vxis->vxi);
10039 +}
10040 +
10041 +#define task_is_init(p) \
10042 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
10043 +
10044 +static inline int __task_is_init(struct task_struct *p,
10045 +       const char *_file, int _line, void *_here)
10046 +{
10047 +       int is_init = is_global_init(p);
10048 +
10049 +       task_lock(p);
10050 +       if (p->vx_info)
10051 +               is_init = p->vx_info->vx_initpid == p->pid;
10052 +       task_unlock(p);
10053 +       return is_init;
10054 +}
10055 +
10056 +extern void exit_vx_info(struct task_struct *, int);
10057 +extern void exit_vx_info_early(struct task_struct *, int);
10058 +
10059 +
10060 +#else
10061 +#warning duplicate inclusion
10062 +#endif
10063 diff -NurpP --minimal linux-2.6.33/include/linux/vs_cowbl.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_cowbl.h
10064 --- linux-2.6.33/include/linux/vs_cowbl.h       1970-01-01 01:00:00.000000000 +0100
10065 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_cowbl.h       2010-02-25 12:02:16.000000000 +0100
10066 @@ -0,0 +1,47 @@
10067 +#ifndef _VS_COWBL_H
10068 +#define _VS_COWBL_H
10069 +
10070 +#include <linux/fs.h>
10071 +#include <linux/dcache.h>
10072 +#include <linux/namei.h>
10073 +
10074 +extern struct dentry *cow_break_link(const char *pathname);
10075 +
10076 +static inline int cow_check_and_break(struct path *path)
10077 +{
10078 +       struct inode *inode = path->dentry->d_inode;
10079 +       int error = 0;
10080 +
10081 +       /* do we need this check? */
10082 +       if (IS_RDONLY(inode))
10083 +               return -EROFS;
10084 +
10085 +       if (IS_COW(inode)) {
10086 +               if (IS_COW_LINK(inode)) {
10087 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
10088 +                       char *pp, *buf;
10089 +
10090 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
10091 +                       if (!buf) {
10092 +                               return -ENOMEM;
10093 +                       }
10094 +                       pp = d_path(path, buf, PATH_MAX);
10095 +                       new_dentry = cow_break_link(pp);
10096 +                       kfree(buf);
10097 +                       if (!IS_ERR(new_dentry)) {
10098 +                               path->dentry = new_dentry;
10099 +                               dput(old_dentry);
10100 +                       } else
10101 +                               error = PTR_ERR(new_dentry);
10102 +               } else {
10103 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
10104 +                       inode->i_ctime = CURRENT_TIME;
10105 +                       mark_inode_dirty(inode);
10106 +               }
10107 +       }
10108 +       return error;
10109 +}
10110 +
10111 +#else
10112 +#warning duplicate inclusion
10113 +#endif
10114 diff -NurpP --minimal linux-2.6.33/include/linux/vs_cvirt.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_cvirt.h
10115 --- linux-2.6.33/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
10116 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_cvirt.h       2010-02-25 12:02:16.000000000 +0100
10117 @@ -0,0 +1,50 @@
10118 +#ifndef _VS_CVIRT_H
10119 +#define _VS_CVIRT_H
10120 +
10121 +#include "vserver/cvirt.h"
10122 +#include "vserver/context.h"
10123 +#include "vserver/base.h"
10124 +#include "vserver/check.h"
10125 +#include "vserver/debug.h"
10126 +
10127 +
10128 +static inline void vx_activate_task(struct task_struct *p)
10129 +{
10130 +       struct vx_info *vxi;
10131 +
10132 +       if ((vxi = p->vx_info)) {
10133 +               vx_update_load(vxi);
10134 +               atomic_inc(&vxi->cvirt.nr_running);
10135 +       }
10136 +}
10137 +
10138 +static inline void vx_deactivate_task(struct task_struct *p)
10139 +{
10140 +       struct vx_info *vxi;
10141 +
10142 +       if ((vxi = p->vx_info)) {
10143 +               vx_update_load(vxi);
10144 +               atomic_dec(&vxi->cvirt.nr_running);
10145 +       }
10146 +}
10147 +
10148 +static inline void vx_uninterruptible_inc(struct task_struct *p)
10149 +{
10150 +       struct vx_info *vxi;
10151 +
10152 +       if ((vxi = p->vx_info))
10153 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
10154 +}
10155 +
10156 +static inline void vx_uninterruptible_dec(struct task_struct *p)
10157 +{
10158 +       struct vx_info *vxi;
10159 +
10160 +       if ((vxi = p->vx_info))
10161 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
10162 +}
10163 +
10164 +
10165 +#else
10166 +#warning duplicate inclusion
10167 +#endif
10168 diff -NurpP --minimal linux-2.6.33/include/linux/vs_device.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_device.h
10169 --- linux-2.6.33/include/linux/vs_device.h      1970-01-01 01:00:00.000000000 +0100
10170 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_device.h      2010-02-25 12:02:16.000000000 +0100
10171 @@ -0,0 +1,45 @@
10172 +#ifndef _VS_DEVICE_H
10173 +#define _VS_DEVICE_H
10174 +
10175 +#include "vserver/base.h"
10176 +#include "vserver/device.h"
10177 +#include "vserver/debug.h"
10178 +
10179 +
10180 +#ifdef CONFIG_VSERVER_DEVICE
10181 +
10182 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
10183 +
10184 +#define vs_device_perm(v, d, m, p) \
10185 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
10186 +
10187 +#else
10188 +
10189 +static inline
10190 +int vs_map_device(struct vx_info *vxi,
10191 +       dev_t device, dev_t *target, umode_t mode)
10192 +{
10193 +       if (target)
10194 +               *target = device;
10195 +       return ~0;
10196 +}
10197 +
10198 +#define vs_device_perm(v, d, m, p) ((p) == (p))
10199 +
10200 +#endif
10201 +
10202 +
10203 +#define vs_map_chrdev(d, t, p) \
10204 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
10205 +#define vs_map_blkdev(d, t, p) \
10206 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
10207 +
10208 +#define vs_chrdev_perm(d, p) \
10209 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
10210 +#define vs_blkdev_perm(d, p) \
10211 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
10212 +
10213 +
10214 +#else
10215 +#warning duplicate inclusion
10216 +#endif
10217 diff -NurpP --minimal linux-2.6.33/include/linux/vs_dlimit.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_dlimit.h
10218 --- linux-2.6.33/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
10219 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_dlimit.h      2010-02-25 12:02:16.000000000 +0100
10220 @@ -0,0 +1,216 @@
10221 +#ifndef _VS_DLIMIT_H
10222 +#define _VS_DLIMIT_H
10223 +
10224 +#include <linux/fs.h>
10225 +
10226 +#include "vserver/dlimit.h"
10227 +#include "vserver/base.h"
10228 +#include "vserver/debug.h"
10229 +
10230 +
10231 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
10232 +
10233 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
10234 +       const char *_file, int _line)
10235 +{
10236 +       if (!dli)
10237 +               return NULL;
10238 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
10239 +               dli, dli ? dli->dl_tag : 0,
10240 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10241 +               _file, _line);
10242 +       atomic_inc(&dli->dl_usecnt);
10243 +       return dli;
10244 +}
10245 +
10246 +
10247 +#define free_dl_info(i) \
10248 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
10249 +
10250 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
10251 +
10252 +static inline void __put_dl_info(struct dl_info *dli,
10253 +       const char *_file, int _line)
10254 +{
10255 +       if (!dli)
10256 +               return;
10257 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
10258 +               dli, dli ? dli->dl_tag : 0,
10259 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10260 +               _file, _line);
10261 +       if (atomic_dec_and_test(&dli->dl_usecnt))
10262 +               free_dl_info(dli);
10263 +}
10264 +
10265 +
10266 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10267 +
10268 +static inline int __dl_alloc_space(struct super_block *sb,
10269 +       tag_t tag, dlsize_t nr, const char *file, int line)
10270 +{
10271 +       struct dl_info *dli = NULL;
10272 +       int ret = 0;
10273 +
10274 +       if (nr == 0)
10275 +               goto out;
10276 +       dli = locate_dl_info(sb, tag);
10277 +       if (!dli)
10278 +               goto out;
10279 +
10280 +       spin_lock(&dli->dl_lock);
10281 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10282 +       if (!ret)
10283 +               dli->dl_space_used += nr;
10284 +       spin_unlock(&dli->dl_lock);
10285 +       put_dl_info(dli);
10286 +out:
10287 +       vxlprintk(VXD_CBIT(dlim, 1),
10288 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10289 +               sb, tag, __dlimit_char(dli), (long long)nr,
10290 +               ret, file, line);
10291 +       return ret;
10292 +}
10293 +
10294 +static inline void __dl_free_space(struct super_block *sb,
10295 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10296 +{
10297 +       struct dl_info *dli = NULL;
10298 +
10299 +       if (nr == 0)
10300 +               goto out;
10301 +       dli = locate_dl_info(sb, tag);
10302 +       if (!dli)
10303 +               goto out;
10304 +
10305 +       spin_lock(&dli->dl_lock);
10306 +       if (dli->dl_space_used > nr)
10307 +               dli->dl_space_used -= nr;
10308 +       else
10309 +               dli->dl_space_used = 0;
10310 +       spin_unlock(&dli->dl_lock);
10311 +       put_dl_info(dli);
10312 +out:
10313 +       vxlprintk(VXD_CBIT(dlim, 1),
10314 +               "FREE  (%p,#%d)%c %lld bytes",
10315 +               sb, tag, __dlimit_char(dli), (long long)nr,
10316 +               _file, _line);
10317 +}
10318 +
10319 +static inline int __dl_alloc_inode(struct super_block *sb,
10320 +       tag_t tag, const char *_file, int _line)
10321 +{
10322 +       struct dl_info *dli;
10323 +       int ret = 0;
10324 +
10325 +       dli = locate_dl_info(sb, tag);
10326 +       if (!dli)
10327 +               goto out;
10328 +
10329 +       spin_lock(&dli->dl_lock);
10330 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
10331 +       if (!ret)
10332 +               dli->dl_inodes_used++;
10333 +       spin_unlock(&dli->dl_lock);
10334 +       put_dl_info(dli);
10335 +out:
10336 +       vxlprintk(VXD_CBIT(dlim, 0),
10337 +               "ALLOC (%p,#%d)%c inode (%d)",
10338 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10339 +       return ret;
10340 +}
10341 +
10342 +static inline void __dl_free_inode(struct super_block *sb,
10343 +       tag_t tag, const char *_file, int _line)
10344 +{
10345 +       struct dl_info *dli;
10346 +
10347 +       dli = locate_dl_info(sb, tag);
10348 +       if (!dli)
10349 +               goto out;
10350 +
10351 +       spin_lock(&dli->dl_lock);
10352 +       if (dli->dl_inodes_used > 1)
10353 +               dli->dl_inodes_used--;
10354 +       else
10355 +               dli->dl_inodes_used = 0;
10356 +       spin_unlock(&dli->dl_lock);
10357 +       put_dl_info(dli);
10358 +out:
10359 +       vxlprintk(VXD_CBIT(dlim, 0),
10360 +               "FREE  (%p,#%d)%c inode",
10361 +               sb, tag, __dlimit_char(dli), _file, _line);
10362 +}
10363 +
10364 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10365 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10366 +       const char *_file, int _line)
10367 +{
10368 +       struct dl_info *dli;
10369 +       uint64_t broot, bfree;
10370 +
10371 +       dli = locate_dl_info(sb, tag);
10372 +       if (!dli)
10373 +               return;
10374 +
10375 +       spin_lock(&dli->dl_lock);
10376 +       broot = (dli->dl_space_total -
10377 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10378 +               >> sb->s_blocksize_bits;
10379 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10380 +                       >> sb->s_blocksize_bits;
10381 +       spin_unlock(&dli->dl_lock);
10382 +
10383 +       vxlprintk(VXD_CBIT(dlim, 2),
10384 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10385 +               (long long)bfree, (long long)broot,
10386 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10387 +               _file, _line);
10388 +       if (free_blocks) {
10389 +               if (*free_blocks > bfree)
10390 +                       *free_blocks = bfree;
10391 +       }
10392 +       if (root_blocks) {
10393 +               if (*root_blocks > broot)
10394 +                       *root_blocks = broot;
10395 +       }
10396 +       put_dl_info(dli);
10397 +}
10398 +
10399 +#define dl_prealloc_space(in, bytes) \
10400 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10401 +               __FILE__, __LINE__ )
10402 +
10403 +#define dl_alloc_space(in, bytes) \
10404 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10405 +               __FILE__, __LINE__ )
10406 +
10407 +#define dl_reserve_space(in, bytes) \
10408 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10409 +               __FILE__, __LINE__ )
10410 +
10411 +#define dl_claim_space(in, bytes) (0)
10412 +
10413 +#define dl_release_space(in, bytes) \
10414 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10415 +               __FILE__, __LINE__ )
10416 +
10417 +#define dl_free_space(in, bytes) \
10418 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10419 +               __FILE__, __LINE__ )
10420 +
10421 +
10422 +
10423 +#define dl_alloc_inode(in) \
10424 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10425 +
10426 +#define dl_free_inode(in) \
10427 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10428 +
10429 +
10430 +#define dl_adjust_block(sb, tag, fb, rb) \
10431 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10432 +
10433 +
10434 +#else
10435 +#warning duplicate inclusion
10436 +#endif
10437 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/base.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/base.h
10438 --- linux-2.6.33/include/linux/vserver/base.h   1970-01-01 01:00:00.000000000 +0100
10439 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/base.h   2010-02-25 12:02:16.000000000 +0100
10440 @@ -0,0 +1,170 @@
10441 +#ifndef _VX_BASE_H
10442 +#define _VX_BASE_H
10443 +
10444 +
10445 +/* context state changes */
10446 +
10447 +enum {
10448 +       VSC_STARTUP = 1,
10449 +       VSC_SHUTDOWN,
10450 +
10451 +       VSC_NETUP,
10452 +       VSC_NETDOWN,
10453 +};
10454 +
10455 +
10456 +
10457 +#define vx_task_xid(t) ((t)->xid)
10458 +
10459 +#define vx_current_xid() vx_task_xid(current)
10460 +
10461 +#define current_vx_info() (current->vx_info)
10462 +
10463 +
10464 +#define nx_task_nid(t) ((t)->nid)
10465 +
10466 +#define nx_current_nid() nx_task_nid(current)
10467 +
10468 +#define current_nx_info() (current->nx_info)
10469 +
10470 +
10471 +/* generic flag merging */
10472 +
10473 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10474 +
10475 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10476 +
10477 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10478 +
10479 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10480 +
10481 +
10482 +/* context flags */
10483 +
10484 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10485 +
10486 +#define vx_current_flags()     __vx_flags(current_vx_info())
10487 +
10488 +#define vx_info_flags(v, m, f) \
10489 +       vs_check_flags(__vx_flags(v), m, f)
10490 +
10491 +#define task_vx_flags(t, m, f) \
10492 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10493 +
10494 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10495 +
10496 +
10497 +/* context caps */
10498 +
10499 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10500 +
10501 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10502 +
10503 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10504 +
10505 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10506 +
10507 +
10508 +
10509 +/* network flags */
10510 +
10511 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10512 +
10513 +#define nx_current_flags()     __nx_flags(current_nx_info())
10514 +
10515 +#define nx_info_flags(n, m, f) \
10516 +       vs_check_flags(__nx_flags(n), m, f)
10517 +
10518 +#define task_nx_flags(t, m, f) \
10519 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10520 +
10521 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10522 +
10523 +
10524 +/* network caps */
10525 +
10526 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10527 +
10528 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10529 +
10530 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10531 +
10532 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10533 +
10534 +
10535 +/* context mask capabilities */
10536 +
10537 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10538 +
10539 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10540 +
10541 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10542 +
10543 +
10544 +/* context bcap mask */
10545 +
10546 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10547 +
10548 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10549 +
10550 +
10551 +/* mask given bcaps */
10552 +
10553 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10554 +
10555 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10556 +
10557 +
10558 +/* masked cap_bset */
10559 +
10560 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10561 +
10562 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10563 +
10564 +#if 0
10565 +#define vx_info_mbcap(v, b) \
10566 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10567 +       vx_info_bcaps(v, b) : (b))
10568 +
10569 +#define task_vx_mbcap(t, b) \
10570 +       vx_info_mbcap((t)->vx_info, (t)->b)
10571 +
10572 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10573 +#endif
10574 +
10575 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10576 +
10577 +#define vx_capable(b, c) (capable(b) || \
10578 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10579 +
10580 +#define nx_capable(b, c) (capable(b) || \
10581 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10582 +
10583 +#define vx_task_initpid(t, n) \
10584 +       ((t)->vx_info && \
10585 +       ((t)->vx_info->vx_initpid == (n)))
10586 +
10587 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10588 +
10589 +
10590 +/* context unshare mask */
10591 +
10592 +#define __vx_umask(v)          ((v)->vx_umask)
10593 +
10594 +#define vx_current_umask()     __vx_umask(current_vx_info())
10595 +
10596 +#define vx_can_unshare(b, f) (capable(b) || \
10597 +       (cap_raised(current_cap(), b) && \
10598 +       !((f) & ~vx_current_umask())))
10599 +
10600 +
10601 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10602 +
10603 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10604 +
10605 +
10606 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10607 +
10608 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10609 +
10610 +#endif
10611 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cacct_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cacct_cmd.h
10612 --- linux-2.6.33/include/linux/vserver/cacct_cmd.h      1970-01-01 01:00:00.000000000 +0100
10613 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cacct_cmd.h      2010-02-25 12:02:16.000000000 +0100
10614 @@ -0,0 +1,23 @@
10615 +#ifndef _VX_CACCT_CMD_H
10616 +#define _VX_CACCT_CMD_H
10617 +
10618 +
10619 +/* virtual host info name commands */
10620 +
10621 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10622 +
10623 +struct vcmd_sock_stat_v0 {
10624 +       uint32_t field;
10625 +       uint32_t count[3];
10626 +       uint64_t total[3];
10627 +};
10628 +
10629 +
10630 +#ifdef __KERNEL__
10631 +
10632 +#include <linux/compiler.h>
10633 +
10634 +extern int vc_sock_stat(struct vx_info *, void __user *);
10635 +
10636 +#endif /* __KERNEL__ */
10637 +#endif /* _VX_CACCT_CMD_H */
10638 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cacct_def.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cacct_def.h
10639 --- linux-2.6.33/include/linux/vserver/cacct_def.h      1970-01-01 01:00:00.000000000 +0100
10640 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cacct_def.h      2010-02-25 12:02:16.000000000 +0100
10641 @@ -0,0 +1,43 @@
10642 +#ifndef _VX_CACCT_DEF_H
10643 +#define _VX_CACCT_DEF_H
10644 +
10645 +#include <asm/atomic.h>
10646 +#include <linux/vserver/cacct.h>
10647 +
10648 +
10649 +struct _vx_sock_acc {
10650 +       atomic_long_t count;
10651 +       atomic_long_t total;
10652 +};
10653 +
10654 +/* context sub struct */
10655 +
10656 +struct _vx_cacct {
10657 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10658 +       atomic_t slab[8];
10659 +       atomic_t page[6][8];
10660 +};
10661 +
10662 +#ifdef CONFIG_VSERVER_DEBUG
10663 +
10664 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10665 +{
10666 +       int i, j;
10667 +
10668 +       printk("\t_vx_cacct:");
10669 +       for (i = 0; i < 6; i++) {
10670 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10671 +
10672 +               printk("\t [%d] =", i);
10673 +               for (j = 0; j < 3; j++) {
10674 +                       printk(" [%d] = %8lu, %8lu", j,
10675 +                               atomic_long_read(&ptr[j].count),
10676 +                               atomic_long_read(&ptr[j].total));
10677 +               }
10678 +               printk("\n");
10679 +       }
10680 +}
10681 +
10682 +#endif
10683 +
10684 +#endif /* _VX_CACCT_DEF_H */
10685 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cacct.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cacct.h
10686 --- linux-2.6.33/include/linux/vserver/cacct.h  1970-01-01 01:00:00.000000000 +0100
10687 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cacct.h  2010-02-25 12:02:16.000000000 +0100
10688 @@ -0,0 +1,15 @@
10689 +#ifndef _VX_CACCT_H
10690 +#define _VX_CACCT_H
10691 +
10692 +
10693 +enum sock_acc_field {
10694 +       VXA_SOCK_UNSPEC = 0,
10695 +       VXA_SOCK_UNIX,
10696 +       VXA_SOCK_INET,
10697 +       VXA_SOCK_INET6,
10698 +       VXA_SOCK_PACKET,
10699 +       VXA_SOCK_OTHER,
10700 +       VXA_SOCK_SIZE   /* array size */
10701 +};
10702 +
10703 +#endif /* _VX_CACCT_H */
10704 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cacct_int.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cacct_int.h
10705 --- linux-2.6.33/include/linux/vserver/cacct_int.h      1970-01-01 01:00:00.000000000 +0100
10706 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cacct_int.h      2010-02-25 12:02:16.000000000 +0100
10707 @@ -0,0 +1,21 @@
10708 +#ifndef _VX_CACCT_INT_H
10709 +#define _VX_CACCT_INT_H
10710 +
10711 +
10712 +#ifdef __KERNEL__
10713 +
10714 +static inline
10715 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10716 +{
10717 +       return atomic_long_read(&cacct->sock[type][pos].count);
10718 +}
10719 +
10720 +
10721 +static inline
10722 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10723 +{
10724 +       return atomic_long_read(&cacct->sock[type][pos].total);
10725 +}
10726 +
10727 +#endif /* __KERNEL__ */
10728 +#endif /* _VX_CACCT_INT_H */
10729 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/check.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/check.h
10730 --- linux-2.6.33/include/linux/vserver/check.h  1970-01-01 01:00:00.000000000 +0100
10731 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/check.h  2010-02-25 12:02:16.000000000 +0100
10732 @@ -0,0 +1,89 @@
10733 +#ifndef _VS_CHECK_H
10734 +#define _VS_CHECK_H
10735 +
10736 +
10737 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10738 +
10739 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10740 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10741 +#else
10742 +#define MIN_D_CONTEXT  65536
10743 +#endif
10744 +
10745 +/* check conditions */
10746 +
10747 +#define VS_ADMIN       0x0001
10748 +#define VS_WATCH       0x0002
10749 +#define VS_HIDE                0x0004
10750 +#define VS_HOSTID      0x0008
10751 +
10752 +#define VS_IDENT       0x0010
10753 +#define VS_EQUIV       0x0020
10754 +#define VS_PARENT      0x0040
10755 +#define VS_CHILD       0x0080
10756 +
10757 +#define VS_ARG_MASK    0x00F0
10758 +
10759 +#define VS_DYNAMIC     0x0100
10760 +#define VS_STATIC      0x0200
10761 +
10762 +#define VS_ATR_MASK    0x0F00
10763 +
10764 +#ifdef CONFIG_VSERVER_PRIVACY
10765 +#define VS_ADMIN_P     (0)
10766 +#define VS_WATCH_P     (0)
10767 +#else
10768 +#define VS_ADMIN_P     VS_ADMIN
10769 +#define VS_WATCH_P     VS_WATCH
10770 +#endif
10771 +
10772 +#define VS_HARDIRQ     0x1000
10773 +#define VS_SOFTIRQ     0x2000
10774 +#define VS_IRQ         0x4000
10775 +
10776 +#define VS_IRQ_MASK    0xF000
10777 +
10778 +#include <linux/hardirq.h>
10779 +
10780 +/*
10781 + * check current context for ADMIN/WATCH and
10782 + * optionally against supplied argument
10783 + */
10784 +static inline int __vs_check(int cid, int id, unsigned int mode)
10785 +{
10786 +       if (mode & VS_ARG_MASK) {
10787 +               if ((mode & VS_IDENT) && (id == cid))
10788 +                       return 1;
10789 +       }
10790 +       if (mode & VS_ATR_MASK) {
10791 +               if ((mode & VS_DYNAMIC) &&
10792 +                       (id >= MIN_D_CONTEXT) &&
10793 +                       (id <= MAX_S_CONTEXT))
10794 +                       return 1;
10795 +               if ((mode & VS_STATIC) &&
10796 +                       (id > 1) && (id < MIN_D_CONTEXT))
10797 +                       return 1;
10798 +       }
10799 +       if (mode & VS_IRQ_MASK) {
10800 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10801 +                       return 1;
10802 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10803 +                       return 1;
10804 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10805 +                       return 1;
10806 +       }
10807 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10808 +               ((mode & VS_WATCH) && (cid == 1)) ||
10809 +               ((mode & VS_HOSTID) && (id == 0)));
10810 +}
10811 +
10812 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10813 +
10814 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10815 +
10816 +
10817 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10818 +
10819 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10820 +
10821 +#endif
10822 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/context_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/context_cmd.h
10823 --- linux-2.6.33/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
10824 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/context_cmd.h    2010-02-25 12:02:16.000000000 +0100
10825 @@ -0,0 +1,145 @@
10826 +#ifndef _VX_CONTEXT_CMD_H
10827 +#define _VX_CONTEXT_CMD_H
10828 +
10829 +
10830 +/* vinfo commands */
10831 +
10832 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10833 +
10834 +#ifdef __KERNEL__
10835 +extern int vc_task_xid(uint32_t);
10836 +
10837 +#endif /* __KERNEL__ */
10838 +
10839 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10840 +
10841 +struct vcmd_vx_info_v0 {
10842 +       uint32_t xid;
10843 +       uint32_t initpid;
10844 +       /* more to come */
10845 +};
10846 +
10847 +#ifdef __KERNEL__
10848 +extern int vc_vx_info(struct vx_info *, void __user *);
10849 +
10850 +#endif /* __KERNEL__ */
10851 +
10852 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10853 +
10854 +struct vcmd_ctx_stat_v0 {
10855 +       uint32_t usecnt;
10856 +       uint32_t tasks;
10857 +       /* more to come */
10858 +};
10859 +
10860 +#ifdef __KERNEL__
10861 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10862 +
10863 +#endif /* __KERNEL__ */
10864 +
10865 +/* context commands */
10866 +
10867 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10868 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10869 +
10870 +struct vcmd_ctx_create {
10871 +       uint64_t flagword;
10872 +};
10873 +
10874 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10875 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10876 +
10877 +struct vcmd_ctx_migrate {
10878 +       uint64_t flagword;
10879 +};
10880 +
10881 +#ifdef __KERNEL__
10882 +extern int vc_ctx_create(uint32_t, void __user *);
10883 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10884 +
10885 +#endif /* __KERNEL__ */
10886 +
10887 +
10888 +/* flag commands */
10889 +
10890 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10891 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10892 +
10893 +struct vcmd_ctx_flags_v0 {
10894 +       uint64_t flagword;
10895 +       uint64_t mask;
10896 +};
10897 +
10898 +#ifdef __KERNEL__
10899 +extern int vc_get_cflags(struct vx_info *, void __user *);
10900 +extern int vc_set_cflags(struct vx_info *, void __user *);
10901 +
10902 +#endif /* __KERNEL__ */
10903 +
10904 +
10905 +/* context caps commands */
10906 +
10907 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10908 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10909 +
10910 +struct vcmd_ctx_caps_v1 {
10911 +       uint64_t ccaps;
10912 +       uint64_t cmask;
10913 +};
10914 +
10915 +#ifdef __KERNEL__
10916 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10917 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10918 +
10919 +#endif /* __KERNEL__ */
10920 +
10921 +
10922 +/* bcaps commands */
10923 +
10924 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10925 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10926 +
10927 +struct vcmd_bcaps {
10928 +       uint64_t bcaps;
10929 +       uint64_t bmask;
10930 +};
10931 +
10932 +#ifdef __KERNEL__
10933 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10934 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10935 +
10936 +#endif /* __KERNEL__ */
10937 +
10938 +
10939 +/* umask commands */
10940 +
10941 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10942 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10943 +
10944 +struct vcmd_umask {
10945 +       uint64_t umask;
10946 +       uint64_t mask;
10947 +};
10948 +
10949 +#ifdef __KERNEL__
10950 +extern int vc_get_umask(struct vx_info *, void __user *);
10951 +extern int vc_set_umask(struct vx_info *, void __user *);
10952 +
10953 +#endif /* __KERNEL__ */
10954 +
10955 +
10956 +/* OOM badness */
10957 +
10958 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10959 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10960 +
10961 +struct vcmd_badness_v0 {
10962 +       int64_t bias;
10963 +};
10964 +
10965 +#ifdef __KERNEL__
10966 +extern int vc_get_badness(struct vx_info *, void __user *);
10967 +extern int vc_set_badness(struct vx_info *, void __user *);
10968 +
10969 +#endif /* __KERNEL__ */
10970 +#endif /* _VX_CONTEXT_CMD_H */
10971 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/context.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/context.h
10972 --- linux-2.6.33/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
10973 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/context.h        2010-02-25 12:02:16.000000000 +0100
10974 @@ -0,0 +1,183 @@
10975 +#ifndef _VX_CONTEXT_H
10976 +#define _VX_CONTEXT_H
10977 +
10978 +#include <linux/types.h>
10979 +#include <linux/capability.h>
10980 +
10981 +
10982 +/* context flags */
10983 +
10984 +#define VXF_INFO_SCHED         0x00000002
10985 +#define VXF_INFO_NPROC         0x00000004
10986 +#define VXF_INFO_PRIVATE       0x00000008
10987 +
10988 +#define VXF_INFO_INIT          0x00000010
10989 +#define VXF_INFO_HIDE          0x00000020
10990 +#define VXF_INFO_ULIMIT                0x00000040
10991 +#define VXF_INFO_NSPACE                0x00000080
10992 +
10993 +#define VXF_SCHED_HARD         0x00000100
10994 +#define VXF_SCHED_PRIO         0x00000200
10995 +#define VXF_SCHED_PAUSE                0x00000400
10996 +
10997 +#define VXF_VIRT_MEM           0x00010000
10998 +#define VXF_VIRT_UPTIME                0x00020000
10999 +#define VXF_VIRT_CPU           0x00040000
11000 +#define VXF_VIRT_LOAD          0x00080000
11001 +#define VXF_VIRT_TIME          0x00100000
11002 +
11003 +#define VXF_HIDE_MOUNT         0x01000000
11004 +/* was VXF_HIDE_NETIF          0x02000000 */
11005 +#define VXF_HIDE_VINFO         0x04000000
11006 +
11007 +#define VXF_STATE_SETUP                (1ULL << 32)
11008 +#define VXF_STATE_INIT         (1ULL << 33)
11009 +#define VXF_STATE_ADMIN                (1ULL << 34)
11010 +
11011 +#define VXF_SC_HELPER          (1ULL << 36)
11012 +#define VXF_REBOOT_KILL                (1ULL << 37)
11013 +#define VXF_PERSISTENT         (1ULL << 38)
11014 +
11015 +#define VXF_FORK_RSS           (1ULL << 48)
11016 +#define VXF_PROLIFIC           (1ULL << 49)
11017 +
11018 +#define VXF_IGNEG_NICE         (1ULL << 52)
11019 +
11020 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11021 +
11022 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11023 +
11024 +
11025 +/* context migration */
11026 +
11027 +#define VXM_SET_INIT           0x00000001
11028 +#define VXM_SET_REAPER         0x00000002
11029 +
11030 +/* context caps */
11031 +
11032 +#define VXC_CAP_MASK           0x00000000
11033 +
11034 +#define VXC_SET_UTSNAME                0x00000001
11035 +#define VXC_SET_RLIMIT         0x00000002
11036 +#define VXC_FS_SECURITY                0x00000004
11037 +#define VXC_TIOCSTI            0x00000010
11038 +
11039 +/* was VXC_RAW_ICMP            0x00000100 */
11040 +#define VXC_SYSLOG             0x00001000
11041 +#define VXC_OOM_ADJUST         0x00002000
11042 +#define VXC_AUDIT_CONTROL      0x00004000
11043 +
11044 +#define VXC_SECURE_MOUNT       0x00010000
11045 +#define VXC_SECURE_REMOUNT     0x00020000
11046 +#define VXC_BINARY_MOUNT       0x00040000
11047 +
11048 +#define VXC_QUOTA_CTL          0x00100000
11049 +#define VXC_ADMIN_MAPPER       0x00200000
11050 +#define VXC_ADMIN_CLOOP                0x00400000
11051 +
11052 +#define VXC_KTHREAD            0x01000000
11053 +#define VXC_NAMESPACE          0x02000000
11054 +
11055 +
11056 +#ifdef __KERNEL__
11057 +
11058 +#include <linux/list.h>
11059 +#include <linux/spinlock.h>
11060 +#include <linux/rcupdate.h>
11061 +
11062 +#include "limit_def.h"
11063 +#include "sched_def.h"
11064 +#include "cvirt_def.h"
11065 +#include "cacct_def.h"
11066 +#include "device_def.h"
11067 +
11068 +#define VX_SPACES      2
11069 +
11070 +struct _vx_info_pc {
11071 +       struct _vx_sched_pc sched_pc;
11072 +       struct _vx_cvirt_pc cvirt_pc;
11073 +};
11074 +
11075 +struct vx_info {
11076 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11077 +       xid_t vx_id;                            /* context id */
11078 +       atomic_t vx_usecnt;                     /* usage count */
11079 +       atomic_t vx_tasks;                      /* tasks count */
11080 +       struct vx_info *vx_parent;              /* parent context */
11081 +       int vx_state;                           /* context state */
11082 +
11083 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
11084 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
11085 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
11086 +
11087 +       uint64_t vx_flags;                      /* context flags */
11088 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11089 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11090 +       unsigned long vx_umask;                 /* unshare mask (guest) */
11091 +
11092 +       struct task_struct *vx_reaper;          /* guest reaper process */
11093 +       pid_t vx_initpid;                       /* PID of guest init */
11094 +       int64_t vx_badness_bias;                /* OOM points bias */
11095 +
11096 +       struct _vx_limit limit;                 /* vserver limits */
11097 +       struct _vx_sched sched;                 /* vserver scheduler */
11098 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11099 +       struct _vx_cacct cacct;                 /* context accounting */
11100 +
11101 +       struct _vx_device dmap;                 /* default device map targets */
11102 +
11103 +#ifndef CONFIG_SMP
11104 +       struct _vx_info_pc info_pc;             /* per cpu data */
11105 +#else
11106 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11107 +#endif
11108 +
11109 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11110 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11111 +       int exit_code;                          /* last process exit code */
11112 +
11113 +       char vx_name[65];                       /* vserver name */
11114 +};
11115 +
11116 +#ifndef CONFIG_SMP
11117 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11118 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11119 +#else
11120 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11121 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11122 +#endif
11123 +
11124 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11125 +
11126 +
11127 +struct vx_info_save {
11128 +       struct vx_info *vxi;
11129 +       xid_t xid;
11130 +};
11131 +
11132 +
11133 +/* status flags */
11134 +
11135 +#define VXS_HASHED     0x0001
11136 +#define VXS_PAUSED     0x0010
11137 +#define VXS_SHUTDOWN   0x0100
11138 +#define VXS_HELPER     0x1000
11139 +#define VXS_RELEASED   0x8000
11140 +
11141 +
11142 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11143 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11144 +
11145 +extern struct vx_info *lookup_vx_info(int);
11146 +extern struct vx_info *lookup_or_create_vx_info(int);
11147 +
11148 +extern int get_xid_list(int, unsigned int *, int);
11149 +extern int xid_is_hashed(xid_t);
11150 +
11151 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11152 +
11153 +extern long vs_state_change(struct vx_info *, unsigned int);
11154 +
11155 +
11156 +#endif /* __KERNEL__ */
11157 +#endif /* _VX_CONTEXT_H */
11158 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cvirt_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cvirt_cmd.h
11159 --- linux-2.6.33/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
11160 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cvirt_cmd.h      2010-02-25 12:02:16.000000000 +0100
11161 @@ -0,0 +1,53 @@
11162 +#ifndef _VX_CVIRT_CMD_H
11163 +#define _VX_CVIRT_CMD_H
11164 +
11165 +
11166 +/* virtual host info name commands */
11167 +
11168 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11169 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11170 +
11171 +struct vcmd_vhi_name_v0 {
11172 +       uint32_t field;
11173 +       char name[65];
11174 +};
11175 +
11176 +
11177 +enum vhi_name_field {
11178 +       VHIN_CONTEXT = 0,
11179 +       VHIN_SYSNAME,
11180 +       VHIN_NODENAME,
11181 +       VHIN_RELEASE,
11182 +       VHIN_VERSION,
11183 +       VHIN_MACHINE,
11184 +       VHIN_DOMAINNAME,
11185 +};
11186 +
11187 +
11188 +#ifdef __KERNEL__
11189 +
11190 +#include <linux/compiler.h>
11191 +
11192 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11193 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11194 +
11195 +#endif /* __KERNEL__ */
11196 +
11197 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11198 +
11199 +struct vcmd_virt_stat_v0 {
11200 +       uint64_t offset;
11201 +       uint64_t uptime;
11202 +       uint32_t nr_threads;
11203 +       uint32_t nr_running;
11204 +       uint32_t nr_uninterruptible;
11205 +       uint32_t nr_onhold;
11206 +       uint32_t nr_forks;
11207 +       uint32_t load[3];
11208 +};
11209 +
11210 +#ifdef __KERNEL__
11211 +extern int vc_virt_stat(struct vx_info *, void __user *);
11212 +
11213 +#endif /* __KERNEL__ */
11214 +#endif /* _VX_CVIRT_CMD_H */
11215 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cvirt_def.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cvirt_def.h
11216 --- linux-2.6.33/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
11217 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cvirt_def.h      2010-02-25 12:02:16.000000000 +0100
11218 @@ -0,0 +1,80 @@
11219 +#ifndef _VX_CVIRT_DEF_H
11220 +#define _VX_CVIRT_DEF_H
11221 +
11222 +#include <linux/jiffies.h>
11223 +#include <linux/spinlock.h>
11224 +#include <linux/wait.h>
11225 +#include <linux/time.h>
11226 +#include <asm/atomic.h>
11227 +
11228 +
11229 +struct _vx_usage_stat {
11230 +       uint64_t user;
11231 +       uint64_t nice;
11232 +       uint64_t system;
11233 +       uint64_t softirq;
11234 +       uint64_t irq;
11235 +       uint64_t idle;
11236 +       uint64_t iowait;
11237 +};
11238 +
11239 +struct _vx_syslog {
11240 +       wait_queue_head_t log_wait;
11241 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11242 +
11243 +       unsigned long log_start;        /* next char to be read by syslog() */
11244 +       unsigned long con_start;        /* next char to be sent to consoles */
11245 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11246 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11247 +
11248 +       char log_buf[1024];
11249 +};
11250 +
11251 +
11252 +/* context sub struct */
11253 +
11254 +struct _vx_cvirt {
11255 +       atomic_t nr_threads;            /* number of current threads */
11256 +       atomic_t nr_running;            /* number of running threads */
11257 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11258 +
11259 +       atomic_t nr_onhold;             /* processes on hold */
11260 +       uint32_t onhold_last;           /* jiffies when put on hold */
11261 +
11262 +       struct timeval bias_tv;         /* time offset to the host */
11263 +       struct timespec bias_idle;
11264 +       struct timespec bias_uptime;    /* context creation point */
11265 +       uint64_t bias_clock;            /* offset in clock_t */
11266 +
11267 +       spinlock_t load_lock;           /* lock for the load averages */
11268 +       atomic_t load_updates;          /* nr of load updates done so far */
11269 +       uint32_t load_last;             /* last time load was calculated */
11270 +       uint32_t load[3];               /* load averages 1,5,15 */
11271 +
11272 +       atomic_t total_forks;           /* number of forks so far */
11273 +
11274 +       struct _vx_syslog syslog;
11275 +};
11276 +
11277 +struct _vx_cvirt_pc {
11278 +       struct _vx_usage_stat cpustat;
11279 +};
11280 +
11281 +
11282 +#ifdef CONFIG_VSERVER_DEBUG
11283 +
11284 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11285 +{
11286 +       printk("\t_vx_cvirt:\n");
11287 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11288 +               atomic_read(&cvirt->nr_threads),
11289 +               atomic_read(&cvirt->nr_running),
11290 +               atomic_read(&cvirt->nr_uninterruptible),
11291 +               atomic_read(&cvirt->nr_onhold));
11292 +       /* add rest here */
11293 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11294 +}
11295 +
11296 +#endif
11297 +
11298 +#endif /* _VX_CVIRT_DEF_H */
11299 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/cvirt.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cvirt.h
11300 --- linux-2.6.33/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
11301 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/cvirt.h  2010-02-25 12:02:16.000000000 +0100
11302 @@ -0,0 +1,20 @@
11303 +#ifndef _VX_CVIRT_H
11304 +#define _VX_CVIRT_H
11305 +
11306 +
11307 +#ifdef __KERNEL__
11308 +
11309 +struct timespec;
11310 +
11311 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11312 +
11313 +
11314 +struct vx_info;
11315 +
11316 +void vx_update_load(struct vx_info *);
11317 +
11318 +
11319 +int vx_do_syslog(int, char __user *, int);
11320 +
11321 +#endif /* __KERNEL__ */
11322 +#endif /* _VX_CVIRT_H */
11323 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/debug_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/debug_cmd.h
11324 --- linux-2.6.33/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
11325 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/debug_cmd.h      2010-02-25 12:02:16.000000000 +0100
11326 @@ -0,0 +1,58 @@
11327 +#ifndef _VX_DEBUG_CMD_H
11328 +#define _VX_DEBUG_CMD_H
11329 +
11330 +
11331 +/* debug commands */
11332 +
11333 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11334 +
11335 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11336 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11337 +
11338 +struct  vcmd_read_history_v0 {
11339 +       uint32_t index;
11340 +       uint32_t count;
11341 +       char __user *data;
11342 +};
11343 +
11344 +struct  vcmd_read_monitor_v0 {
11345 +       uint32_t index;
11346 +       uint32_t count;
11347 +       char __user *data;
11348 +};
11349 +
11350 +
11351 +#ifdef __KERNEL__
11352 +
11353 +#ifdef CONFIG_COMPAT
11354 +
11355 +#include <asm/compat.h>
11356 +
11357 +struct vcmd_read_history_v0_x32 {
11358 +       uint32_t index;
11359 +       uint32_t count;
11360 +       compat_uptr_t data_ptr;
11361 +};
11362 +
11363 +struct vcmd_read_monitor_v0_x32 {
11364 +       uint32_t index;
11365 +       uint32_t count;
11366 +       compat_uptr_t data_ptr;
11367 +};
11368 +
11369 +#endif  /* CONFIG_COMPAT */
11370 +
11371 +extern int vc_dump_history(uint32_t);
11372 +
11373 +extern int vc_read_history(uint32_t, void __user *);
11374 +extern int vc_read_monitor(uint32_t, void __user *);
11375 +
11376 +#ifdef CONFIG_COMPAT
11377 +
11378 +extern int vc_read_history_x32(uint32_t, void __user *);
11379 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11380 +
11381 +#endif  /* CONFIG_COMPAT */
11382 +
11383 +#endif /* __KERNEL__ */
11384 +#endif /* _VX_DEBUG_CMD_H */
11385 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/debug.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/debug.h
11386 --- linux-2.6.33/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
11387 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/debug.h  2010-02-25 12:02:16.000000000 +0100
11388 @@ -0,0 +1,127 @@
11389 +#ifndef _VX_DEBUG_H
11390 +#define _VX_DEBUG_H
11391 +
11392 +
11393 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11394 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11395 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11396 +
11397 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11398 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11399 +#define VXF_DEV                "%p[%lu,%d:%d]"
11400 +
11401 +
11402 +#define vxd_path(p)                                            \
11403 +       ({ static char _buffer[PATH_MAX];                       \
11404 +          d_path(p, _buffer, sizeof(_buffer)); })
11405 +
11406 +#define vxd_cond_path(n)                                       \
11407 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11408 +
11409 +
11410 +#ifdef CONFIG_VSERVER_DEBUG
11411 +
11412 +extern unsigned int vx_debug_switch;
11413 +extern unsigned int vx_debug_xid;
11414 +extern unsigned int vx_debug_nid;
11415 +extern unsigned int vx_debug_tag;
11416 +extern unsigned int vx_debug_net;
11417 +extern unsigned int vx_debug_limit;
11418 +extern unsigned int vx_debug_cres;
11419 +extern unsigned int vx_debug_dlim;
11420 +extern unsigned int vx_debug_quota;
11421 +extern unsigned int vx_debug_cvirt;
11422 +extern unsigned int vx_debug_space;
11423 +extern unsigned int vx_debug_misc;
11424 +
11425 +
11426 +#define VX_LOGLEVEL    "vxD: "
11427 +#define VX_PROC_FMT    "%p: "
11428 +#define VX_PROCESS     current
11429 +
11430 +#define vxdprintk(c, f, x...)                                  \
11431 +       do {                                                    \
11432 +               if (c)                                          \
11433 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11434 +                               VX_PROCESS , ##x);              \
11435 +       } while (0)
11436 +
11437 +#define vxlprintk(c, f, x...)                                  \
11438 +       do {                                                    \
11439 +               if (c)                                          \
11440 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11441 +       } while (0)
11442 +
11443 +#define vxfprintk(c, f, x...)                                  \
11444 +       do {                                                    \
11445 +               if (c)                                          \
11446 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11447 +       } while (0)
11448 +
11449 +
11450 +struct vx_info;
11451 +
11452 +void dump_vx_info(struct vx_info *, int);
11453 +void dump_vx_info_inactive(int);
11454 +
11455 +#else  /* CONFIG_VSERVER_DEBUG */
11456 +
11457 +#define vx_debug_switch 0
11458 +#define vx_debug_xid   0
11459 +#define vx_debug_nid   0
11460 +#define vx_debug_tag   0
11461 +#define vx_debug_net   0
11462 +#define vx_debug_limit 0
11463 +#define vx_debug_cres  0
11464 +#define vx_debug_dlim  0
11465 +#define vx_debug_cvirt 0
11466 +
11467 +#define vxdprintk(x...) do { } while (0)
11468 +#define vxlprintk(x...) do { } while (0)
11469 +#define vxfprintk(x...) do { } while (0)
11470 +
11471 +#endif /* CONFIG_VSERVER_DEBUG */
11472 +
11473 +
11474 +#ifdef CONFIG_VSERVER_WARN
11475 +
11476 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11477 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11478 +#define VX_WARN_XID    "[xid #%u] "
11479 +#define VX_WARN_NID    "[nid #%u] "
11480 +#define VX_WARN_TAG    "[tag #%u] "
11481 +
11482 +#define vxwprintk(c, f, x...)                                  \
11483 +       do {                                                    \
11484 +               if (c)                                          \
11485 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11486 +       } while (0)
11487 +
11488 +#else  /* CONFIG_VSERVER_WARN */
11489 +
11490 +#define vxwprintk(x...) do { } while (0)
11491 +
11492 +#endif /* CONFIG_VSERVER_WARN */
11493 +
11494 +#define vxwprintk_task(c, f, x...)                             \
11495 +       vxwprintk(c, VX_WARN_TASK f,                            \
11496 +               current->comm, current->pid,                    \
11497 +               current->xid, current->nid, current->tag, ##x)
11498 +#define vxwprintk_xid(c, f, x...)                              \
11499 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11500 +#define vxwprintk_nid(c, f, x...)                              \
11501 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11502 +#define vxwprintk_tag(c, f, x...)                              \
11503 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11504 +
11505 +#ifdef CONFIG_VSERVER_DEBUG
11506 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11507 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11508 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11509 +#else
11510 +#define vxd_assert_lock(l)     do { } while (0)
11511 +#define vxd_assert(c, f, x...) do { } while (0)
11512 +#endif
11513 +
11514 +
11515 +#endif /* _VX_DEBUG_H */
11516 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/device_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/device_cmd.h
11517 --- linux-2.6.33/include/linux/vserver/device_cmd.h     1970-01-01 01:00:00.000000000 +0100
11518 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/device_cmd.h     2010-02-25 12:02:16.000000000 +0100
11519 @@ -0,0 +1,44 @@
11520 +#ifndef _VX_DEVICE_CMD_H
11521 +#define _VX_DEVICE_CMD_H
11522 +
11523 +
11524 +/*  device vserver commands */
11525 +
11526 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11527 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11528 +
11529 +struct vcmd_set_mapping_v0 {
11530 +       const char __user *device;
11531 +       const char __user *target;
11532 +       uint32_t flags;
11533 +};
11534 +
11535 +
11536 +#ifdef __KERNEL__
11537 +
11538 +#ifdef CONFIG_COMPAT
11539 +
11540 +#include <asm/compat.h>
11541 +
11542 +struct vcmd_set_mapping_v0_x32 {
11543 +       compat_uptr_t device_ptr;
11544 +       compat_uptr_t target_ptr;
11545 +       uint32_t flags;
11546 +};
11547 +
11548 +#endif /* CONFIG_COMPAT */
11549 +
11550 +#include <linux/compiler.h>
11551 +
11552 +extern int vc_set_mapping(struct vx_info *, void __user *);
11553 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11554 +
11555 +#ifdef CONFIG_COMPAT
11556 +
11557 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11558 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11559 +
11560 +#endif /* CONFIG_COMPAT */
11561 +
11562 +#endif /* __KERNEL__ */
11563 +#endif /* _VX_DEVICE_CMD_H */
11564 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/device_def.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/device_def.h
11565 --- linux-2.6.33/include/linux/vserver/device_def.h     1970-01-01 01:00:00.000000000 +0100
11566 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/device_def.h     2010-02-25 12:02:16.000000000 +0100
11567 @@ -0,0 +1,17 @@
11568 +#ifndef _VX_DEVICE_DEF_H
11569 +#define _VX_DEVICE_DEF_H
11570 +
11571 +#include <linux/types.h>
11572 +
11573 +struct vx_dmap_target {
11574 +       dev_t target;
11575 +       uint32_t flags;
11576 +};
11577 +
11578 +struct _vx_device {
11579 +#ifdef CONFIG_VSERVER_DEVICE
11580 +       struct vx_dmap_target targets[2];
11581 +#endif
11582 +};
11583 +
11584 +#endif /* _VX_DEVICE_DEF_H */
11585 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/device.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/device.h
11586 --- linux-2.6.33/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
11587 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/device.h 2010-02-25 12:02:16.000000000 +0100
11588 @@ -0,0 +1,15 @@
11589 +#ifndef _VX_DEVICE_H
11590 +#define _VX_DEVICE_H
11591 +
11592 +
11593 +#define DATTR_CREATE   0x00000001
11594 +#define DATTR_OPEN     0x00000002
11595 +
11596 +#define DATTR_REMAP    0x00000010
11597 +
11598 +#define DATTR_MASK     0x00000013
11599 +
11600 +
11601 +#else  /* _VX_DEVICE_H */
11602 +#warning duplicate inclusion
11603 +#endif /* _VX_DEVICE_H */
11604 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/dlimit_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/dlimit_cmd.h
11605 --- linux-2.6.33/include/linux/vserver/dlimit_cmd.h     1970-01-01 01:00:00.000000000 +0100
11606 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/dlimit_cmd.h     2010-02-25 12:02:16.000000000 +0100
11607 @@ -0,0 +1,109 @@
11608 +#ifndef _VX_DLIMIT_CMD_H
11609 +#define _VX_DLIMIT_CMD_H
11610 +
11611 +
11612 +/*  dlimit vserver commands */
11613 +
11614 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11615 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11616 +
11617 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11618 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11619 +
11620 +struct vcmd_ctx_dlimit_base_v0 {
11621 +       const char __user *name;
11622 +       uint32_t flags;
11623 +};
11624 +
11625 +struct vcmd_ctx_dlimit_v0 {
11626 +       const char __user *name;
11627 +       uint32_t space_used;                    /* used space in kbytes */
11628 +       uint32_t space_total;                   /* maximum space in kbytes */
11629 +       uint32_t inodes_used;                   /* used inodes */
11630 +       uint32_t inodes_total;                  /* maximum inodes */
11631 +       uint32_t reserved;                      /* reserved for root in % */
11632 +       uint32_t flags;
11633 +};
11634 +
11635 +#define CDLIM_UNSET            ((uint32_t)0UL)
11636 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11637 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11638 +
11639 +#define DLIME_UNIT     0
11640 +#define DLIME_KILO     1
11641 +#define DLIME_MEGA     2
11642 +#define DLIME_GIGA     3
11643 +
11644 +#define DLIMF_SHIFT    0x10
11645 +
11646 +#define DLIMS_USED     0
11647 +#define DLIMS_TOTAL    2
11648 +
11649 +static inline
11650 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11651 +{
11652 +       int exp = (flags & DLIMF_SHIFT) ?
11653 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11654 +       return ((uint64_t)val) << (10 * exp);
11655 +}
11656 +
11657 +static inline
11658 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11659 +{
11660 +       int exp = 0;
11661 +
11662 +       if (*flags & DLIMF_SHIFT) {
11663 +               while (val > (1LL << 32) && (exp < 3)) {
11664 +                       val >>= 10;
11665 +                       exp++;
11666 +               }
11667 +               *flags &= ~(DLIME_GIGA << shift);
11668 +               *flags |= exp << shift;
11669 +       } else
11670 +               val >>= 10;
11671 +       return val;
11672 +}
11673 +
11674 +#ifdef __KERNEL__
11675 +
11676 +#ifdef CONFIG_COMPAT
11677 +
11678 +#include <asm/compat.h>
11679 +
11680 +struct vcmd_ctx_dlimit_base_v0_x32 {
11681 +       compat_uptr_t name_ptr;
11682 +       uint32_t flags;
11683 +};
11684 +
11685 +struct vcmd_ctx_dlimit_v0_x32 {
11686 +       compat_uptr_t name_ptr;
11687 +       uint32_t space_used;                    /* used space in kbytes */
11688 +       uint32_t space_total;                   /* maximum space in kbytes */
11689 +       uint32_t inodes_used;                   /* used inodes */
11690 +       uint32_t inodes_total;                  /* maximum inodes */
11691 +       uint32_t reserved;                      /* reserved for root in % */
11692 +       uint32_t flags;
11693 +};
11694 +
11695 +#endif /* CONFIG_COMPAT */
11696 +
11697 +#include <linux/compiler.h>
11698 +
11699 +extern int vc_add_dlimit(uint32_t, void __user *);
11700 +extern int vc_rem_dlimit(uint32_t, void __user *);
11701 +
11702 +extern int vc_set_dlimit(uint32_t, void __user *);
11703 +extern int vc_get_dlimit(uint32_t, void __user *);
11704 +
11705 +#ifdef CONFIG_COMPAT
11706 +
11707 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11708 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11709 +
11710 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11711 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11712 +
11713 +#endif /* CONFIG_COMPAT */
11714 +
11715 +#endif /* __KERNEL__ */
11716 +#endif /* _VX_DLIMIT_CMD_H */
11717 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/dlimit.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/dlimit.h
11718 --- linux-2.6.33/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
11719 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/dlimit.h 2010-02-25 12:02:16.000000000 +0100
11720 @@ -0,0 +1,54 @@
11721 +#ifndef _VX_DLIMIT_H
11722 +#define _VX_DLIMIT_H
11723 +
11724 +#include "switch.h"
11725 +
11726 +
11727 +#ifdef __KERNEL__
11728 +
11729 +/*      keep in sync with CDLIM_INFINITY       */
11730 +
11731 +#define DLIM_INFINITY          (~0ULL)
11732 +
11733 +#include <linux/spinlock.h>
11734 +#include <linux/rcupdate.h>
11735 +
11736 +struct super_block;
11737 +
11738 +struct dl_info {
11739 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11740 +       struct rcu_head dl_rcu;                 /* the rcu head */
11741 +       tag_t dl_tag;                           /* context tag */
11742 +       atomic_t dl_usecnt;                     /* usage count */
11743 +       atomic_t dl_refcnt;                     /* reference count */
11744 +
11745 +       struct super_block *dl_sb;              /* associated superblock */
11746 +
11747 +       spinlock_t dl_lock;                     /* protect the values */
11748 +
11749 +       unsigned long long dl_space_used;       /* used space in bytes */
11750 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11751 +       unsigned long dl_inodes_used;           /* used inodes */
11752 +       unsigned long dl_inodes_total;          /* maximum inodes */
11753 +
11754 +       unsigned int dl_nrlmult;                /* non root limit mult */
11755 +};
11756 +
11757 +struct rcu_head;
11758 +
11759 +extern void rcu_free_dl_info(struct rcu_head *);
11760 +extern void unhash_dl_info(struct dl_info *);
11761 +
11762 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11763 +
11764 +
11765 +struct kstatfs;
11766 +
11767 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11768 +
11769 +typedef uint64_t dlsize_t;
11770 +
11771 +#endif /* __KERNEL__ */
11772 +#else  /* _VX_DLIMIT_H */
11773 +#warning duplicate inclusion
11774 +#endif /* _VX_DLIMIT_H */
11775 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/global.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/global.h
11776 --- linux-2.6.33/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
11777 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/global.h 2010-02-25 12:02:16.000000000 +0100
11778 @@ -0,0 +1,19 @@
11779 +#ifndef _VX_GLOBAL_H
11780 +#define _VX_GLOBAL_H
11781 +
11782 +
11783 +extern atomic_t vx_global_ctotal;
11784 +extern atomic_t vx_global_cactive;
11785 +
11786 +extern atomic_t nx_global_ctotal;
11787 +extern atomic_t nx_global_cactive;
11788 +
11789 +extern atomic_t vs_global_nsproxy;
11790 +extern atomic_t vs_global_fs;
11791 +extern atomic_t vs_global_mnt_ns;
11792 +extern atomic_t vs_global_uts_ns;
11793 +extern atomic_t vs_global_user_ns;
11794 +extern atomic_t vs_global_pid_ns;
11795 +
11796 +
11797 +#endif /* _VX_GLOBAL_H */
11798 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/history.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/history.h
11799 --- linux-2.6.33/include/linux/vserver/history.h        1970-01-01 01:00:00.000000000 +0100
11800 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/history.h        2010-02-25 12:02:16.000000000 +0100
11801 @@ -0,0 +1,197 @@
11802 +#ifndef _VX_HISTORY_H
11803 +#define _VX_HISTORY_H
11804 +
11805 +
11806 +enum {
11807 +       VXH_UNUSED = 0,
11808 +       VXH_THROW_OOPS = 1,
11809 +
11810 +       VXH_GET_VX_INFO,
11811 +       VXH_PUT_VX_INFO,
11812 +       VXH_INIT_VX_INFO,
11813 +       VXH_SET_VX_INFO,
11814 +       VXH_CLR_VX_INFO,
11815 +       VXH_CLAIM_VX_INFO,
11816 +       VXH_RELEASE_VX_INFO,
11817 +       VXH_ALLOC_VX_INFO,
11818 +       VXH_DEALLOC_VX_INFO,
11819 +       VXH_HASH_VX_INFO,
11820 +       VXH_UNHASH_VX_INFO,
11821 +       VXH_LOC_VX_INFO,
11822 +       VXH_LOOKUP_VX_INFO,
11823 +       VXH_CREATE_VX_INFO,
11824 +};
11825 +
11826 +struct _vxhe_vxi {
11827 +       struct vx_info *ptr;
11828 +       unsigned xid;
11829 +       unsigned usecnt;
11830 +       unsigned tasks;
11831 +};
11832 +
11833 +struct _vxhe_set_clr {
11834 +       void *data;
11835 +};
11836 +
11837 +struct _vxhe_loc_lookup {
11838 +       unsigned arg;
11839 +};
11840 +
11841 +struct _vx_hist_entry {
11842 +       void *loc;
11843 +       unsigned short seq;
11844 +       unsigned short type;
11845 +       struct _vxhe_vxi vxi;
11846 +       union {
11847 +               struct _vxhe_set_clr sc;
11848 +               struct _vxhe_loc_lookup ll;
11849 +       };
11850 +};
11851 +
11852 +#ifdef CONFIG_VSERVER_HISTORY
11853 +
11854 +extern unsigned volatile int vxh_active;
11855 +
11856 +struct _vx_hist_entry *vxh_advance(void *loc);
11857 +
11858 +
11859 +static inline
11860 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11861 +{
11862 +       entry->vxi.ptr = vxi;
11863 +       if (vxi) {
11864 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11865 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11866 +               entry->vxi.xid = vxi->vx_id;
11867 +       }
11868 +}
11869 +
11870 +
11871 +#define        __HERE__ current_text_addr()
11872 +
11873 +#define __VXH_BODY(__type, __data, __here)     \
11874 +       struct _vx_hist_entry *entry;           \
11875 +                                               \
11876 +       preempt_disable();                      \
11877 +       entry = vxh_advance(__here);            \
11878 +       __data;                                 \
11879 +       entry->type = __type;                   \
11880 +       preempt_enable();
11881 +
11882 +
11883 +       /* pass vxi only */
11884 +
11885 +#define __VXH_SMPL                             \
11886 +       __vxh_copy_vxi(entry, vxi)
11887 +
11888 +static inline
11889 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11890 +{
11891 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11892 +}
11893 +
11894 +       /* pass vxi and data (void *) */
11895 +
11896 +#define __VXH_DATA                             \
11897 +       __vxh_copy_vxi(entry, vxi);             \
11898 +       entry->sc.data = data
11899 +
11900 +static inline
11901 +void   __vxh_data(struct vx_info *vxi, void *data,
11902 +                       int __type, void *__here)
11903 +{
11904 +       __VXH_BODY(__type, __VXH_DATA, __here)
11905 +}
11906 +
11907 +       /* pass vxi and arg (long) */
11908 +
11909 +#define __VXH_LONG                             \
11910 +       __vxh_copy_vxi(entry, vxi);             \
11911 +       entry->ll.arg = arg
11912 +
11913 +static inline
11914 +void   __vxh_long(struct vx_info *vxi, long arg,
11915 +                       int __type, void *__here)
11916 +{
11917 +       __VXH_BODY(__type, __VXH_LONG, __here)
11918 +}
11919 +
11920 +
11921 +static inline
11922 +void   __vxh_throw_oops(void *__here)
11923 +{
11924 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11925 +       /* prevent further acquisition */
11926 +       vxh_active = 0;
11927 +}
11928 +
11929 +
11930 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11931 +
11932 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11933 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11934 +
11935 +#define __vxh_init_vx_info(v, d, h) \
11936 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11937 +#define __vxh_set_vx_info(v, d, h) \
11938 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11939 +#define __vxh_clr_vx_info(v, d, h) \
11940 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11941 +
11942 +#define __vxh_claim_vx_info(v, d, h) \
11943 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11944 +#define __vxh_release_vx_info(v, d, h) \
11945 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11946 +
11947 +#define vxh_alloc_vx_info(v) \
11948 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11949 +#define vxh_dealloc_vx_info(v) \
11950 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11951 +
11952 +#define vxh_hash_vx_info(v) \
11953 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11954 +#define vxh_unhash_vx_info(v) \
11955 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11956 +
11957 +#define vxh_loc_vx_info(v, l) \
11958 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11959 +#define vxh_lookup_vx_info(v, l) \
11960 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11961 +#define vxh_create_vx_info(v, l) \
11962 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11963 +
11964 +extern void vxh_dump_history(void);
11965 +
11966 +
11967 +#else  /* CONFIG_VSERVER_HISTORY */
11968 +
11969 +#define        __HERE__        0
11970 +
11971 +#define vxh_throw_oops()               do { } while (0)
11972 +
11973 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11974 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11975 +
11976 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11977 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11978 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11979 +
11980 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11981 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11982 +
11983 +#define vxh_alloc_vx_info(v)           do { } while (0)
11984 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11985 +
11986 +#define vxh_hash_vx_info(v)            do { } while (0)
11987 +#define vxh_unhash_vx_info(v)          do { } while (0)
11988 +
11989 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11990 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11991 +#define vxh_create_vx_info(v, l)       do { } while (0)
11992 +
11993 +#define vxh_dump_history()             do { } while (0)
11994 +
11995 +
11996 +#endif /* CONFIG_VSERVER_HISTORY */
11997 +
11998 +#endif /* _VX_HISTORY_H */
11999 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/inode_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/inode_cmd.h
12000 --- linux-2.6.33/include/linux/vserver/inode_cmd.h      1970-01-01 01:00:00.000000000 +0100
12001 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/inode_cmd.h      2010-02-25 12:02:16.000000000 +0100
12002 @@ -0,0 +1,59 @@
12003 +#ifndef _VX_INODE_CMD_H
12004 +#define _VX_INODE_CMD_H
12005 +
12006 +
12007 +/*  inode vserver commands */
12008 +
12009 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12010 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12011 +
12012 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12013 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12014 +
12015 +struct vcmd_ctx_iattr_v1 {
12016 +       const char __user *name;
12017 +       uint32_t tag;
12018 +       uint32_t flags;
12019 +       uint32_t mask;
12020 +};
12021 +
12022 +struct vcmd_ctx_fiattr_v0 {
12023 +       uint32_t tag;
12024 +       uint32_t flags;
12025 +       uint32_t mask;
12026 +};
12027 +
12028 +
12029 +#ifdef __KERNEL__
12030 +
12031 +
12032 +#ifdef CONFIG_COMPAT
12033 +
12034 +#include <asm/compat.h>
12035 +
12036 +struct vcmd_ctx_iattr_v1_x32 {
12037 +       compat_uptr_t name_ptr;
12038 +       uint32_t tag;
12039 +       uint32_t flags;
12040 +       uint32_t mask;
12041 +};
12042 +
12043 +#endif /* CONFIG_COMPAT */
12044 +
12045 +#include <linux/compiler.h>
12046 +
12047 +extern int vc_get_iattr(void __user *);
12048 +extern int vc_set_iattr(void __user *);
12049 +
12050 +extern int vc_fget_iattr(uint32_t, void __user *);
12051 +extern int vc_fset_iattr(uint32_t, void __user *);
12052 +
12053 +#ifdef CONFIG_COMPAT
12054 +
12055 +extern int vc_get_iattr_x32(void __user *);
12056 +extern int vc_set_iattr_x32(void __user *);
12057 +
12058 +#endif /* CONFIG_COMPAT */
12059 +
12060 +#endif /* __KERNEL__ */
12061 +#endif /* _VX_INODE_CMD_H */
12062 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/inode.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/inode.h
12063 --- linux-2.6.33/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
12064 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/inode.h  2010-02-25 12:02:16.000000000 +0100
12065 @@ -0,0 +1,39 @@
12066 +#ifndef _VX_INODE_H
12067 +#define _VX_INODE_H
12068 +
12069 +
12070 +#define IATTR_TAG      0x01000000
12071 +
12072 +#define IATTR_ADMIN    0x00000001
12073 +#define IATTR_WATCH    0x00000002
12074 +#define IATTR_HIDE     0x00000004
12075 +#define IATTR_FLAGS    0x00000007
12076 +
12077 +#define IATTR_BARRIER  0x00010000
12078 +#define IATTR_IXUNLINK 0x00020000
12079 +#define IATTR_IMMUTABLE 0x00040000
12080 +#define IATTR_COW      0x00080000
12081 +
12082 +#ifdef __KERNEL__
12083 +
12084 +
12085 +#ifdef CONFIG_VSERVER_PROC_SECURE
12086 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12087 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12088 +#else
12089 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12090 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12091 +#endif
12092 +
12093 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12094 +
12095 +#endif /* __KERNEL__ */
12096 +
12097 +/* inode ioctls */
12098 +
12099 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12100 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12101 +
12102 +#else  /* _VX_INODE_H */
12103 +#warning duplicate inclusion
12104 +#endif /* _VX_INODE_H */
12105 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/Kbuild linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/Kbuild
12106 --- linux-2.6.33/include/linux/vserver/Kbuild   1970-01-01 01:00:00.000000000 +0100
12107 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/Kbuild   2010-02-25 12:02:16.000000000 +0100
12108 @@ -0,0 +1,8 @@
12109 +
12110 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
12111 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12112 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12113 +       debug_cmd.h device_cmd.h
12114 +
12115 +unifdef-y += switch.h network.h monitor.h inode.h device.h
12116 +
12117 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/limit_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/limit_cmd.h
12118 --- linux-2.6.33/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
12119 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/limit_cmd.h      2010-02-25 12:02:16.000000000 +0100
12120 @@ -0,0 +1,71 @@
12121 +#ifndef _VX_LIMIT_CMD_H
12122 +#define _VX_LIMIT_CMD_H
12123 +
12124 +
12125 +/*  rlimit vserver commands */
12126 +
12127 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12128 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12129 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12130 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12131 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12132 +
12133 +struct vcmd_ctx_rlimit_v0 {
12134 +       uint32_t id;
12135 +       uint64_t minimum;
12136 +       uint64_t softlimit;
12137 +       uint64_t maximum;
12138 +};
12139 +
12140 +struct vcmd_ctx_rlimit_mask_v0 {
12141 +       uint32_t minimum;
12142 +       uint32_t softlimit;
12143 +       uint32_t maximum;
12144 +};
12145 +
12146 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12147 +
12148 +struct vcmd_rlimit_stat_v0 {
12149 +       uint32_t id;
12150 +       uint32_t hits;
12151 +       uint64_t value;
12152 +       uint64_t minimum;
12153 +       uint64_t maximum;
12154 +};
12155 +
12156 +#define CRLIM_UNSET            (0ULL)
12157 +#define CRLIM_INFINITY         (~0ULL)
12158 +#define CRLIM_KEEP             (~1ULL)
12159 +
12160 +#ifdef __KERNEL__
12161 +
12162 +#ifdef CONFIG_IA32_EMULATION
12163 +
12164 +struct vcmd_ctx_rlimit_v0_x32 {
12165 +       uint32_t id;
12166 +       uint64_t minimum;
12167 +       uint64_t softlimit;
12168 +       uint64_t maximum;
12169 +} __attribute__ ((packed));
12170 +
12171 +#endif /* CONFIG_IA32_EMULATION */
12172 +
12173 +#include <linux/compiler.h>
12174 +
12175 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12176 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12177 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12178 +extern int vc_reset_hits(struct vx_info *, void __user *);
12179 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12180 +
12181 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12182 +
12183 +#ifdef CONFIG_IA32_EMULATION
12184 +
12185 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12186 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12187 +
12188 +#endif /* CONFIG_IA32_EMULATION */
12189 +
12190 +#endif /* __KERNEL__ */
12191 +#endif /* _VX_LIMIT_CMD_H */
12192 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/limit_def.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/limit_def.h
12193 --- linux-2.6.33/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
12194 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/limit_def.h      2010-02-25 12:02:16.000000000 +0100
12195 @@ -0,0 +1,47 @@
12196 +#ifndef _VX_LIMIT_DEF_H
12197 +#define _VX_LIMIT_DEF_H
12198 +
12199 +#include <asm/atomic.h>
12200 +#include <asm/resource.h>
12201 +
12202 +#include "limit.h"
12203 +
12204 +
12205 +struct _vx_res_limit {
12206 +       rlim_t soft;            /* Context soft limit */
12207 +       rlim_t hard;            /* Context hard limit */
12208 +
12209 +       rlim_atomic_t rcur;     /* Current value */
12210 +       rlim_t rmin;            /* Context minimum */
12211 +       rlim_t rmax;            /* Context maximum */
12212 +
12213 +       atomic_t lhit;          /* Limit hits */
12214 +};
12215 +
12216 +/* context sub struct */
12217 +
12218 +struct _vx_limit {
12219 +       struct _vx_res_limit res[NUM_LIMITS];
12220 +};
12221 +
12222 +#ifdef CONFIG_VSERVER_DEBUG
12223 +
12224 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12225 +{
12226 +       int i;
12227 +
12228 +       printk("\t_vx_limit:");
12229 +       for (i = 0; i < NUM_LIMITS; i++) {
12230 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12231 +                       i, (unsigned long)__rlim_get(limit, i),
12232 +                       (unsigned long)__rlim_rmin(limit, i),
12233 +                       (unsigned long)__rlim_rmax(limit, i),
12234 +                       (long)__rlim_soft(limit, i),
12235 +                       (long)__rlim_hard(limit, i),
12236 +                       atomic_read(&__rlim_lhit(limit, i)));
12237 +       }
12238 +}
12239 +
12240 +#endif
12241 +
12242 +#endif /* _VX_LIMIT_DEF_H */
12243 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/limit.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/limit.h
12244 --- linux-2.6.33/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
12245 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/limit.h  2010-02-25 12:02:16.000000000 +0100
12246 @@ -0,0 +1,71 @@
12247 +#ifndef _VX_LIMIT_H
12248 +#define _VX_LIMIT_H
12249 +
12250 +#define VLIMIT_NSOCK   16
12251 +#define VLIMIT_OPENFD  17
12252 +#define VLIMIT_ANON    18
12253 +#define VLIMIT_SHMEM   19
12254 +#define VLIMIT_SEMARY  20
12255 +#define VLIMIT_NSEMS   21
12256 +#define VLIMIT_DENTRY  22
12257 +#define VLIMIT_MAPPED  23
12258 +
12259 +
12260 +#ifdef __KERNEL__
12261 +
12262 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12263 +
12264 +/*     keep in sync with CRLIM_INFINITY */
12265 +
12266 +#define        VLIM_INFINITY   (~0ULL)
12267 +
12268 +#include <asm/atomic.h>
12269 +#include <asm/resource.h>
12270 +
12271 +#ifndef RLIM_INFINITY
12272 +#warning RLIM_INFINITY is undefined
12273 +#endif
12274 +
12275 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12276 +
12277 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12278 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12279 +
12280 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12281 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12282 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12283 +
12284 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12285 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12286 +
12287 +typedef atomic_long_t rlim_atomic_t;
12288 +typedef unsigned long rlim_t;
12289 +
12290 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12291 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12292 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12293 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12294 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12295 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12296 +
12297 +
12298 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12299 +#define        VX_VLIM(r) ((long long)(long)(r))
12300 +#define        VX_RLIM(v) ((rlim_t)(v))
12301 +#else
12302 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12303 +               ? VLIM_INFINITY : (long long)(r))
12304 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12305 +               ? RLIM_INFINITY : (rlim_t)(v))
12306 +#endif
12307 +
12308 +struct sysinfo;
12309 +
12310 +void vx_vsi_meminfo(struct sysinfo *);
12311 +void vx_vsi_swapinfo(struct sysinfo *);
12312 +long vx_vsi_cached(struct sysinfo *);
12313 +
12314 +#define NUM_LIMITS     24
12315 +
12316 +#endif /* __KERNEL__ */
12317 +#endif /* _VX_LIMIT_H */
12318 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/limit_int.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/limit_int.h
12319 --- linux-2.6.33/include/linux/vserver/limit_int.h      1970-01-01 01:00:00.000000000 +0100
12320 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/limit_int.h      2010-02-25 12:02:16.000000000 +0100
12321 @@ -0,0 +1,198 @@
12322 +#ifndef _VX_LIMIT_INT_H
12323 +#define _VX_LIMIT_INT_H
12324 +
12325 +#include "context.h"
12326 +
12327 +#ifdef __KERNEL__
12328 +
12329 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12330 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12331 +
12332 +extern const char *vlimit_name[NUM_LIMITS];
12333 +
12334 +static inline void __vx_acc_cres(struct vx_info *vxi,
12335 +       int res, int dir, void *_data, char *_file, int _line)
12336 +{
12337 +       if (VXD_RCRES_COND(res))
12338 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12339 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12340 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12341 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12342 +       if (!vxi)
12343 +               return;
12344 +
12345 +       if (dir > 0)
12346 +               __rlim_inc(&vxi->limit, res);
12347 +       else
12348 +               __rlim_dec(&vxi->limit, res);
12349 +}
12350 +
12351 +static inline void __vx_add_cres(struct vx_info *vxi,
12352 +       int res, int amount, void *_data, char *_file, int _line)
12353 +{
12354 +       if (VXD_RCRES_COND(res))
12355 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12356 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12357 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12358 +                       amount, _data, _file, _line);
12359 +       if (amount == 0)
12360 +               return;
12361 +       if (!vxi)
12362 +               return;
12363 +       __rlim_add(&vxi->limit, res, amount);
12364 +}
12365 +
12366 +static inline
12367 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12368 +{
12369 +       int cond = (value > __rlim_rmax(limit, res));
12370 +
12371 +       if (cond)
12372 +               __rlim_rmax(limit, res) = value;
12373 +       return cond;
12374 +}
12375 +
12376 +static inline
12377 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12378 +{
12379 +       int cond = (value < __rlim_rmin(limit, res));
12380 +
12381 +       if (cond)
12382 +               __rlim_rmin(limit, res) = value;
12383 +       return cond;
12384 +}
12385 +
12386 +static inline
12387 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12388 +{
12389 +       if (!__vx_cres_adjust_max(limit, res, value))
12390 +               __vx_cres_adjust_min(limit, res, value);
12391 +}
12392 +
12393 +
12394 +/*     return values:
12395 +        +1 ... no limit hit
12396 +        -1 ... over soft limit
12397 +         0 ... over hard limit         */
12398 +
12399 +static inline int __vx_cres_avail(struct vx_info *vxi,
12400 +       int res, int num, char *_file, int _line)
12401 +{
12402 +       struct _vx_limit *limit;
12403 +       rlim_t value;
12404 +
12405 +       if (VXD_RLIMIT_COND(res))
12406 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12407 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12408 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12409 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12410 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12411 +                       num, _file, _line);
12412 +       if (!vxi)
12413 +               return 1;
12414 +
12415 +       limit = &vxi->limit;
12416 +       value = __rlim_get(limit, res);
12417 +
12418 +       if (!__vx_cres_adjust_max(limit, res, value))
12419 +               __vx_cres_adjust_min(limit, res, value);
12420 +
12421 +       if (num == 0)
12422 +               return 1;
12423 +
12424 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12425 +               return -1;
12426 +       if (value + num <= __rlim_soft(limit, res))
12427 +               return -1;
12428 +
12429 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12430 +               return 1;
12431 +       if (value + num <= __rlim_hard(limit, res))
12432 +               return 1;
12433 +
12434 +       __rlim_hit(limit, res);
12435 +       return 0;
12436 +}
12437 +
12438 +
12439 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12440 +
12441 +static inline
12442 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12443 +{
12444 +       rlim_t value, sum = 0;
12445 +       int res;
12446 +
12447 +       while ((res = *array++)) {
12448 +               value = __rlim_get(limit, res);
12449 +               __vx_cres_fixup(limit, res, value);
12450 +               sum += value;
12451 +       }
12452 +       return sum;
12453 +}
12454 +
12455 +static inline
12456 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12457 +{
12458 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12459 +       int res = *array;
12460 +
12461 +       if (value == __rlim_get(limit, res))
12462 +               return value;
12463 +
12464 +       __rlim_set(limit, res, value);
12465 +       /* now adjust min/max */
12466 +       if (!__vx_cres_adjust_max(limit, res, value))
12467 +               __vx_cres_adjust_min(limit, res, value);
12468 +
12469 +       return value;
12470 +}
12471 +
12472 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12473 +       const int *array, int num, char *_file, int _line)
12474 +{
12475 +       struct _vx_limit *limit;
12476 +       rlim_t value = 0;
12477 +       int res;
12478 +
12479 +       if (num == 0)
12480 +               return 1;
12481 +       if (!vxi)
12482 +               return 1;
12483 +
12484 +       limit = &vxi->limit;
12485 +       res = *array;
12486 +       value = __vx_cres_array_sum(limit, array + 1);
12487 +
12488 +       __rlim_set(limit, res, value);
12489 +       __vx_cres_fixup(limit, res, value);
12490 +
12491 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12492 +}
12493 +
12494 +
12495 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12496 +{
12497 +       rlim_t value;
12498 +       int res;
12499 +
12500 +       /* complex resources first */
12501 +       if ((id < 0) || (id == RLIMIT_RSS))
12502 +               __vx_cres_array_fixup(limit, VLA_RSS);
12503 +
12504 +       for (res = 0; res < NUM_LIMITS; res++) {
12505 +               if ((id > 0) && (res != id))
12506 +                       continue;
12507 +
12508 +               value = __rlim_get(limit, res);
12509 +               __vx_cres_fixup(limit, res, value);
12510 +
12511 +               /* not supposed to happen, maybe warn? */
12512 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12513 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12514 +       }
12515 +}
12516 +
12517 +
12518 +#endif /* __KERNEL__ */
12519 +#endif /* _VX_LIMIT_INT_H */
12520 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/monitor.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/monitor.h
12521 --- linux-2.6.33/include/linux/vserver/monitor.h        1970-01-01 01:00:00.000000000 +0100
12522 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/monitor.h        2010-02-25 12:02:16.000000000 +0100
12523 @@ -0,0 +1,96 @@
12524 +#ifndef _VX_MONITOR_H
12525 +#define _VX_MONITOR_H
12526 +
12527 +#include <linux/types.h>
12528 +
12529 +enum {
12530 +       VXM_UNUSED = 0,
12531 +
12532 +       VXM_SYNC = 0x10,
12533 +
12534 +       VXM_UPDATE = 0x20,
12535 +       VXM_UPDATE_1,
12536 +       VXM_UPDATE_2,
12537 +
12538 +       VXM_RQINFO_1 = 0x24,
12539 +       VXM_RQINFO_2,
12540 +
12541 +       VXM_ACTIVATE = 0x40,
12542 +       VXM_DEACTIVATE,
12543 +       VXM_IDLE,
12544 +
12545 +       VXM_HOLD = 0x44,
12546 +       VXM_UNHOLD,
12547 +
12548 +       VXM_MIGRATE = 0x48,
12549 +       VXM_RESCHED,
12550 +
12551 +       /* all other bits are flags */
12552 +       VXM_SCHED = 0x80,
12553 +};
12554 +
12555 +struct _vxm_update_1 {
12556 +       uint32_t tokens_max;
12557 +       uint32_t fill_rate;
12558 +       uint32_t interval;
12559 +};
12560 +
12561 +struct _vxm_update_2 {
12562 +       uint32_t tokens_min;
12563 +       uint32_t fill_rate;
12564 +       uint32_t interval;
12565 +};
12566 +
12567 +struct _vxm_rqinfo_1 {
12568 +       uint16_t running;
12569 +       uint16_t onhold;
12570 +       uint16_t iowait;
12571 +       uint16_t uintr;
12572 +       uint32_t idle_tokens;
12573 +};
12574 +
12575 +struct _vxm_rqinfo_2 {
12576 +       uint32_t norm_time;
12577 +       uint32_t idle_time;
12578 +       uint32_t idle_skip;
12579 +};
12580 +
12581 +struct _vxm_sched {
12582 +       uint32_t tokens;
12583 +       uint32_t norm_time;
12584 +       uint32_t idle_time;
12585 +};
12586 +
12587 +struct _vxm_task {
12588 +       uint16_t pid;
12589 +       uint16_t state;
12590 +};
12591 +
12592 +struct _vxm_event {
12593 +       uint32_t jif;
12594 +       union {
12595 +               uint32_t seq;
12596 +               uint32_t sec;
12597 +       };
12598 +       union {
12599 +               uint32_t tokens;
12600 +               uint32_t nsec;
12601 +               struct _vxm_task tsk;
12602 +       };
12603 +};
12604 +
12605 +struct _vx_mon_entry {
12606 +       uint16_t type;
12607 +       uint16_t xid;
12608 +       union {
12609 +               struct _vxm_event ev;
12610 +               struct _vxm_sched sd;
12611 +               struct _vxm_update_1 u1;
12612 +               struct _vxm_update_2 u2;
12613 +               struct _vxm_rqinfo_1 q1;
12614 +               struct _vxm_rqinfo_2 q2;
12615 +       };
12616 +};
12617 +
12618 +
12619 +#endif /* _VX_MONITOR_H */
12620 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/network_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/network_cmd.h
12621 --- linux-2.6.33/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
12622 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/network_cmd.h    2010-02-25 12:02:16.000000000 +0100
12623 @@ -0,0 +1,150 @@
12624 +#ifndef _VX_NETWORK_CMD_H
12625 +#define _VX_NETWORK_CMD_H
12626 +
12627 +
12628 +/* vinfo commands */
12629 +
12630 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12631 +
12632 +#ifdef __KERNEL__
12633 +extern int vc_task_nid(uint32_t);
12634 +
12635 +#endif /* __KERNEL__ */
12636 +
12637 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12638 +
12639 +struct vcmd_nx_info_v0 {
12640 +       uint32_t nid;
12641 +       /* more to come */
12642 +};
12643 +
12644 +#ifdef __KERNEL__
12645 +extern int vc_nx_info(struct nx_info *, void __user *);
12646 +
12647 +#endif /* __KERNEL__ */
12648 +
12649 +#include <linux/in.h>
12650 +#include <linux/in6.h>
12651 +
12652 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12653 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12654 +
12655 +struct  vcmd_net_create {
12656 +       uint64_t flagword;
12657 +};
12658 +
12659 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12660 +
12661 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12662 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12663 +
12664 +struct vcmd_net_addr_v0 {
12665 +       uint16_t type;
12666 +       uint16_t count;
12667 +       struct in_addr ip[4];
12668 +       struct in_addr mask[4];
12669 +};
12670 +
12671 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12672 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12673 +
12674 +struct vcmd_net_addr_ipv4_v1 {
12675 +       uint16_t type;
12676 +       uint16_t flags;
12677 +       struct in_addr ip;
12678 +       struct in_addr mask;
12679 +};
12680 +
12681 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12682 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12683 +
12684 +struct vcmd_net_addr_ipv6_v1 {
12685 +       uint16_t type;
12686 +       uint16_t flags;
12687 +       uint32_t prefix;
12688 +       struct in6_addr ip;
12689 +       struct in6_addr mask;
12690 +};
12691 +
12692 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12693 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12694 +
12695 +struct vcmd_match_ipv4_v0 {
12696 +       uint16_t type;
12697 +       uint16_t flags;
12698 +       uint16_t parent;
12699 +       uint16_t prefix;
12700 +       struct in_addr ip;
12701 +       struct in_addr ip2;
12702 +       struct in_addr mask;
12703 +};
12704 +
12705 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12706 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12707 +
12708 +struct vcmd_match_ipv6_v0 {
12709 +       uint16_t type;
12710 +       uint16_t flags;
12711 +       uint16_t parent;
12712 +       uint16_t prefix;
12713 +       struct in6_addr ip;
12714 +       struct in6_addr ip2;
12715 +       struct in6_addr mask;
12716 +};
12717 +
12718 +
12719 +#ifdef __KERNEL__
12720 +extern int vc_net_create(uint32_t, void __user *);
12721 +extern int vc_net_migrate(struct nx_info *, void __user *);
12722 +
12723 +extern int vc_net_add(struct nx_info *, void __user *);
12724 +extern int vc_net_remove(struct nx_info *, void __user *);
12725 +
12726 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12727 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12728 +
12729 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12730 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12731 +
12732 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12733 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12734 +
12735 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12736 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12737 +
12738 +#endif /* __KERNEL__ */
12739 +
12740 +
12741 +/* flag commands */
12742 +
12743 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12744 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12745 +
12746 +struct vcmd_net_flags_v0 {
12747 +       uint64_t flagword;
12748 +       uint64_t mask;
12749 +};
12750 +
12751 +#ifdef __KERNEL__
12752 +extern int vc_get_nflags(struct nx_info *, void __user *);
12753 +extern int vc_set_nflags(struct nx_info *, void __user *);
12754 +
12755 +#endif /* __KERNEL__ */
12756 +
12757 +
12758 +/* network caps commands */
12759 +
12760 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12761 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12762 +
12763 +struct vcmd_net_caps_v0 {
12764 +       uint64_t ncaps;
12765 +       uint64_t cmask;
12766 +};
12767 +
12768 +#ifdef __KERNEL__
12769 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12770 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12771 +
12772 +#endif /* __KERNEL__ */
12773 +#endif /* _VX_CONTEXT_CMD_H */
12774 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/network.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/network.h
12775 --- linux-2.6.33/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
12776 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/network.h        2010-02-25 12:02:16.000000000 +0100
12777 @@ -0,0 +1,146 @@
12778 +#ifndef _VX_NETWORK_H
12779 +#define _VX_NETWORK_H
12780 +
12781 +#include <linux/types.h>
12782 +
12783 +
12784 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12785 +
12786 +
12787 +/* network flags */
12788 +
12789 +#define NXF_INFO_PRIVATE       0x00000008
12790 +
12791 +#define NXF_SINGLE_IP          0x00000100
12792 +#define NXF_LBACK_REMAP                0x00000200
12793 +#define NXF_LBACK_ALLOW                0x00000400
12794 +
12795 +#define NXF_HIDE_NETIF         0x02000000
12796 +#define NXF_HIDE_LBACK         0x04000000
12797 +
12798 +#define NXF_STATE_SETUP                (1ULL << 32)
12799 +#define NXF_STATE_ADMIN                (1ULL << 34)
12800 +
12801 +#define NXF_SC_HELPER          (1ULL << 36)
12802 +#define NXF_PERSISTENT         (1ULL << 38)
12803 +
12804 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12805 +
12806 +
12807 +#define        NXF_INIT_SET            (__nxf_init_set())
12808 +
12809 +static inline uint64_t __nxf_init_set(void) {
12810 +       return    NXF_STATE_ADMIN
12811 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12812 +               | NXF_LBACK_REMAP
12813 +               | NXF_HIDE_LBACK
12814 +#endif
12815 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12816 +               | NXF_SINGLE_IP
12817 +#endif
12818 +               | NXF_HIDE_NETIF;
12819 +}
12820 +
12821 +
12822 +/* network caps */
12823 +
12824 +#define NXC_TUN_CREATE         0x00000001
12825 +
12826 +#define NXC_RAW_ICMP           0x00000100
12827 +
12828 +
12829 +/* address types */
12830 +
12831 +#define NXA_TYPE_IPV4          0x0001
12832 +#define NXA_TYPE_IPV6          0x0002
12833 +
12834 +#define NXA_TYPE_NONE          0x0000
12835 +#define NXA_TYPE_ANY           0x00FF
12836 +
12837 +#define NXA_TYPE_ADDR          0x0010
12838 +#define NXA_TYPE_MASK          0x0020
12839 +#define NXA_TYPE_RANGE         0x0040
12840 +
12841 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12842 +
12843 +#define NXA_MOD_BCAST          0x0100
12844 +#define NXA_MOD_LBACK          0x0200
12845 +
12846 +#define NXA_LOOPBACK           0x1000
12847 +
12848 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12849 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12850 +
12851 +#ifdef __KERNEL__
12852 +
12853 +#include <linux/list.h>
12854 +#include <linux/spinlock.h>
12855 +#include <linux/rcupdate.h>
12856 +#include <linux/in.h>
12857 +#include <linux/in6.h>
12858 +#include <asm/atomic.h>
12859 +
12860 +struct nx_addr_v4 {
12861 +       struct nx_addr_v4 *next;
12862 +       struct in_addr ip[2];
12863 +       struct in_addr mask;
12864 +       uint16_t type;
12865 +       uint16_t flags;
12866 +};
12867 +
12868 +struct nx_addr_v6 {
12869 +       struct nx_addr_v6 *next;
12870 +       struct in6_addr ip;
12871 +       struct in6_addr mask;
12872 +       uint32_t prefix;
12873 +       uint16_t type;
12874 +       uint16_t flags;
12875 +};
12876 +
12877 +struct nx_info {
12878 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12879 +       nid_t nx_id;                    /* vnet id */
12880 +       atomic_t nx_usecnt;             /* usage count */
12881 +       atomic_t nx_tasks;              /* tasks count */
12882 +       int nx_state;                   /* context state */
12883 +
12884 +       uint64_t nx_flags;              /* network flag word */
12885 +       uint64_t nx_ncaps;              /* network capabilities */
12886 +
12887 +       struct in_addr v4_lback;        /* Loopback address */
12888 +       struct in_addr v4_bcast;        /* Broadcast address */
12889 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12890 +#ifdef CONFIG_IPV6
12891 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12892 +#endif
12893 +       char nx_name[65];               /* network context name */
12894 +};
12895 +
12896 +
12897 +/* status flags */
12898 +
12899 +#define NXS_HASHED      0x0001
12900 +#define NXS_SHUTDOWN    0x0100
12901 +#define NXS_RELEASED    0x8000
12902 +
12903 +extern struct nx_info *lookup_nx_info(int);
12904 +
12905 +extern int get_nid_list(int, unsigned int *, int);
12906 +extern int nid_is_hashed(nid_t);
12907 +
12908 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12909 +
12910 +extern long vs_net_change(struct nx_info *, unsigned int);
12911 +
12912 +struct sock;
12913 +
12914 +
12915 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12916 +#ifdef  CONFIG_IPV6
12917 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12918 +#else
12919 +#define NX_IPV6(n)     (0)
12920 +#endif
12921 +
12922 +#endif /* __KERNEL__ */
12923 +#endif /* _VX_NETWORK_H */
12924 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/percpu.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/percpu.h
12925 --- linux-2.6.33/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
12926 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/percpu.h 2010-02-25 12:02:16.000000000 +0100
12927 @@ -0,0 +1,14 @@
12928 +#ifndef _VX_PERCPU_H
12929 +#define _VX_PERCPU_H
12930 +
12931 +#include "cvirt_def.h"
12932 +#include "sched_def.h"
12933 +
12934 +struct _vx_percpu {
12935 +       struct _vx_cvirt_pc cvirt;
12936 +       struct _vx_sched_pc sched;
12937 +};
12938 +
12939 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12940 +
12941 +#endif /* _VX_PERCPU_H */
12942 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/pid.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/pid.h
12943 --- linux-2.6.33/include/linux/vserver/pid.h    1970-01-01 01:00:00.000000000 +0100
12944 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/pid.h    2010-02-25 12:02:16.000000000 +0100
12945 @@ -0,0 +1,51 @@
12946 +#ifndef _VSERVER_PID_H
12947 +#define _VSERVER_PID_H
12948 +
12949 +/* pid faking stuff */
12950 +
12951 +#define vx_info_map_pid(v, p) \
12952 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12953 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12954 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12955 +#define vx_map_tgid(p) vx_map_pid(p)
12956 +
12957 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12958 +       const char *func, const char *file, int line)
12959 +{
12960 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12961 +               vxfprintk(VXD_CBIT(cvirt, 2),
12962 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12963 +                       vxi, (long long)vxi->vx_flags, pid,
12964 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12965 +                       func, file, line);
12966 +               if (pid == 0)
12967 +                       return 0;
12968 +               if (pid == vxi->vx_initpid)
12969 +                       return 1;
12970 +       }
12971 +       return pid;
12972 +}
12973 +
12974 +#define vx_info_rmap_pid(v, p) \
12975 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12976 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12977 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12978 +
12979 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12980 +       const char *func, const char *file, int line)
12981 +{
12982 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12983 +               vxfprintk(VXD_CBIT(cvirt, 2),
12984 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12985 +                       vxi, (long long)vxi->vx_flags, pid,
12986 +                       (pid == 1) ? vxi->vx_initpid : pid,
12987 +                       func, file, line);
12988 +               if ((pid == 1) && vxi->vx_initpid)
12989 +                       return vxi->vx_initpid;
12990 +               if (pid == vxi->vx_initpid)
12991 +                       return ~0U;
12992 +       }
12993 +       return pid;
12994 +}
12995 +
12996 +#endif
12997 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/sched_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/sched_cmd.h
12998 --- linux-2.6.33/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
12999 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/sched_cmd.h      2010-02-25 12:02:16.000000000 +0100
13000 @@ -0,0 +1,108 @@
13001 +#ifndef _VX_SCHED_CMD_H
13002 +#define _VX_SCHED_CMD_H
13003 +
13004 +
13005 +/*  sched vserver commands */
13006 +
13007 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
13008 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
13009 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
13010 +
13011 +struct vcmd_set_sched_v2 {
13012 +       int32_t fill_rate;
13013 +       int32_t interval;
13014 +       int32_t tokens;
13015 +       int32_t tokens_min;
13016 +       int32_t tokens_max;
13017 +       uint64_t cpu_mask;
13018 +};
13019 +
13020 +struct vcmd_set_sched_v3 {
13021 +       uint32_t set_mask;
13022 +       int32_t fill_rate;
13023 +       int32_t interval;
13024 +       int32_t tokens;
13025 +       int32_t tokens_min;
13026 +       int32_t tokens_max;
13027 +       int32_t priority_bias;
13028 +};
13029 +
13030 +struct vcmd_set_sched_v4 {
13031 +       uint32_t set_mask;
13032 +       int32_t fill_rate;
13033 +       int32_t interval;
13034 +       int32_t tokens;
13035 +       int32_t tokens_min;
13036 +       int32_t tokens_max;
13037 +       int32_t prio_bias;
13038 +       int32_t cpu_id;
13039 +       int32_t bucket_id;
13040 +};
13041 +
13042 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
13043 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
13044 +
13045 +struct vcmd_sched_v5 {
13046 +       uint32_t mask;
13047 +       int32_t cpu_id;
13048 +       int32_t bucket_id;
13049 +       int32_t fill_rate[2];
13050 +       int32_t interval[2];
13051 +       int32_t tokens;
13052 +       int32_t tokens_min;
13053 +       int32_t tokens_max;
13054 +       int32_t prio_bias;
13055 +};
13056 +
13057 +#define VXSM_FILL_RATE         0x0001
13058 +#define VXSM_INTERVAL          0x0002
13059 +#define VXSM_FILL_RATE2                0x0004
13060 +#define VXSM_INTERVAL2         0x0008
13061 +#define VXSM_TOKENS            0x0010
13062 +#define VXSM_TOKENS_MIN                0x0020
13063 +#define VXSM_TOKENS_MAX                0x0040
13064 +#define VXSM_PRIO_BIAS         0x0100
13065 +
13066 +#define VXSM_IDLE_TIME         0x0200
13067 +#define VXSM_FORCE             0x0400
13068 +
13069 +#define        VXSM_V3_MASK            0x0173
13070 +#define        VXSM_SET_MASK           0x01FF
13071 +
13072 +#define VXSM_CPU_ID            0x1000
13073 +#define VXSM_BUCKET_ID         0x2000
13074 +
13075 +#define VXSM_MSEC              0x4000
13076 +
13077 +#define SCHED_KEEP             (-2)    /* only for v2 */
13078 +
13079 +#ifdef __KERNEL__
13080 +
13081 +#include <linux/compiler.h>
13082 +
13083 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
13084 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
13085 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
13086 +extern int vc_set_sched(struct vx_info *, void __user *);
13087 +extern int vc_get_sched(struct vx_info *, void __user *);
13088 +
13089 +#endif /* __KERNEL__ */
13090 +
13091 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
13092 +
13093 +struct vcmd_sched_info {
13094 +       int32_t cpu_id;
13095 +       int32_t bucket_id;
13096 +       uint64_t user_msec;
13097 +       uint64_t sys_msec;
13098 +       uint64_t hold_msec;
13099 +       uint32_t token_usec;
13100 +       int32_t vavavoom;
13101 +};
13102 +
13103 +#ifdef __KERNEL__
13104 +
13105 +extern int vc_sched_info(struct vx_info *, void __user *);
13106 +
13107 +#endif /* __KERNEL__ */
13108 +#endif /* _VX_SCHED_CMD_H */
13109 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/sched_def.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/sched_def.h
13110 --- linux-2.6.33/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
13111 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/sched_def.h      2010-02-25 12:02:16.000000000 +0100
13112 @@ -0,0 +1,68 @@
13113 +#ifndef _VX_SCHED_DEF_H
13114 +#define _VX_SCHED_DEF_H
13115 +
13116 +#include <linux/spinlock.h>
13117 +#include <linux/jiffies.h>
13118 +#include <linux/cpumask.h>
13119 +#include <asm/atomic.h>
13120 +#include <asm/param.h>
13121 +
13122 +
13123 +/* context sub struct */
13124 +
13125 +struct _vx_sched {
13126 +       spinlock_t tokens_lock;         /* lock for token bucket */
13127 +
13128 +       int tokens;                     /* number of CPU tokens */
13129 +       int fill_rate[2];               /* Fill rate: add X tokens... */
13130 +       int interval[2];                /* Divisor:   per Y jiffies   */
13131 +       int tokens_min;                 /* Limit:     minimum for unhold */
13132 +       int tokens_max;                 /* Limit:     no more than N tokens */
13133 +
13134 +       int prio_bias;                  /* bias offset for priority */
13135 +
13136 +       unsigned update_mask;           /* which features should be updated */
13137 +       cpumask_t update;               /* CPUs which should update */
13138 +};
13139 +
13140 +struct _vx_sched_pc {
13141 +       int tokens;                     /* number of CPU tokens */
13142 +       int flags;                      /* bucket flags */
13143 +
13144 +       int fill_rate[2];               /* Fill rate: add X tokens... */
13145 +       int interval[2];                /* Divisor:   per Y jiffies   */
13146 +       int tokens_min;                 /* Limit:     minimum for unhold */
13147 +       int tokens_max;                 /* Limit:     no more than N tokens */
13148 +
13149 +       int prio_bias;                  /* bias offset for priority */
13150 +       int vavavoom;                   /* last calculated vavavoom */
13151 +
13152 +       unsigned long norm_time;        /* last time accounted */
13153 +       unsigned long idle_time;        /* non linear time for fair sched */
13154 +       unsigned long token_time;       /* token time for accounting */
13155 +       unsigned long onhold;           /* jiffies when put on hold */
13156 +
13157 +       uint64_t user_ticks;            /* token tick events */
13158 +       uint64_t sys_ticks;             /* token tick events */
13159 +       uint64_t hold_ticks;            /* token ticks paused */
13160 +};
13161 +
13162 +
13163 +#define VXSF_ONHOLD    0x0001
13164 +#define VXSF_IDLE_TIME 0x0100
13165 +
13166 +#ifdef CONFIG_VSERVER_DEBUG
13167 +
13168 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13169 +{
13170 +       printk("\t_vx_sched:\n");
13171 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
13172 +               sched->fill_rate[0], sched->interval[0],
13173 +               sched->fill_rate[1], sched->interval[1],
13174 +               sched->tokens_min, sched->tokens_max);
13175 +       printk("\t priority = %4d\n", sched->prio_bias);
13176 +}
13177 +
13178 +#endif
13179 +
13180 +#endif /* _VX_SCHED_DEF_H */
13181 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/sched.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/sched.h
13182 --- linux-2.6.33/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
13183 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/sched.h  2010-02-25 12:02:16.000000000 +0100
13184 @@ -0,0 +1,26 @@
13185 +#ifndef _VX_SCHED_H
13186 +#define _VX_SCHED_H
13187 +
13188 +
13189 +#ifdef __KERNEL__
13190 +
13191 +struct timespec;
13192 +
13193 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13194 +
13195 +
13196 +struct vx_info;
13197 +
13198 +void vx_update_load(struct vx_info *);
13199 +
13200 +
13201 +int vx_tokens_recalc(struct _vx_sched_pc *,
13202 +       unsigned long *, unsigned long *, int [2]);
13203 +
13204 +void vx_update_sched_param(struct _vx_sched *sched,
13205 +       struct _vx_sched_pc *sched_pc);
13206 +
13207 +#endif /* __KERNEL__ */
13208 +#else  /* _VX_SCHED_H */
13209 +#warning duplicate inclusion
13210 +#endif /* _VX_SCHED_H */
13211 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/signal_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/signal_cmd.h
13212 --- linux-2.6.33/include/linux/vserver/signal_cmd.h     1970-01-01 01:00:00.000000000 +0100
13213 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/signal_cmd.h     2010-02-25 12:02:16.000000000 +0100
13214 @@ -0,0 +1,43 @@
13215 +#ifndef _VX_SIGNAL_CMD_H
13216 +#define _VX_SIGNAL_CMD_H
13217 +
13218 +
13219 +/*  signalling vserver commands */
13220 +
13221 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13222 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13223 +
13224 +struct vcmd_ctx_kill_v0 {
13225 +       int32_t pid;
13226 +       int32_t sig;
13227 +};
13228 +
13229 +struct vcmd_wait_exit_v0 {
13230 +       int32_t reboot_cmd;
13231 +       int32_t exit_code;
13232 +};
13233 +
13234 +#ifdef __KERNEL__
13235 +
13236 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13237 +extern int vc_wait_exit(struct vx_info *, void __user *);
13238 +
13239 +#endif /* __KERNEL__ */
13240 +
13241 +/*  process alteration commands */
13242 +
13243 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13244 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13245 +
13246 +struct vcmd_pflags_v0 {
13247 +       uint32_t flagword;
13248 +       uint32_t mask;
13249 +};
13250 +
13251 +#ifdef __KERNEL__
13252 +
13253 +extern int vc_get_pflags(uint32_t pid, void __user *);
13254 +extern int vc_set_pflags(uint32_t pid, void __user *);
13255 +
13256 +#endif /* __KERNEL__ */
13257 +#endif /* _VX_SIGNAL_CMD_H */
13258 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/signal.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/signal.h
13259 --- linux-2.6.33/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
13260 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/signal.h 2010-02-25 12:02:16.000000000 +0100
13261 @@ -0,0 +1,14 @@
13262 +#ifndef _VX_SIGNAL_H
13263 +#define _VX_SIGNAL_H
13264 +
13265 +
13266 +#ifdef __KERNEL__
13267 +
13268 +struct vx_info;
13269 +
13270 +int vx_info_kill(struct vx_info *, int, int);
13271 +
13272 +#endif /* __KERNEL__ */
13273 +#else  /* _VX_SIGNAL_H */
13274 +#warning duplicate inclusion
13275 +#endif /* _VX_SIGNAL_H */
13276 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/space_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/space_cmd.h
13277 --- linux-2.6.33/include/linux/vserver/space_cmd.h      1970-01-01 01:00:00.000000000 +0100
13278 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/space_cmd.h      2010-02-25 12:02:16.000000000 +0100
13279 @@ -0,0 +1,38 @@
13280 +#ifndef _VX_SPACE_CMD_H
13281 +#define _VX_SPACE_CMD_H
13282 +
13283 +
13284 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13285 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13286 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13287 +
13288 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13289 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13290 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13291 +
13292 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13293 +
13294 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13295 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13296 +
13297 +
13298 +struct vcmd_space_mask_v1 {
13299 +       uint64_t mask;
13300 +};
13301 +
13302 +struct vcmd_space_mask_v2 {
13303 +       uint64_t mask;
13304 +       uint32_t index;
13305 +};
13306 +
13307 +
13308 +#ifdef __KERNEL__
13309 +
13310 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13311 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13312 +extern int vc_enter_space(struct vx_info *, void __user *);
13313 +extern int vc_set_space(struct vx_info *, void __user *);
13314 +extern int vc_get_space_mask(void __user *, int);
13315 +
13316 +#endif /* __KERNEL__ */
13317 +#endif /* _VX_SPACE_CMD_H */
13318 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/space.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/space.h
13319 --- linux-2.6.33/include/linux/vserver/space.h  1970-01-01 01:00:00.000000000 +0100
13320 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/space.h  2010-02-25 12:02:16.000000000 +0100
13321 @@ -0,0 +1,12 @@
13322 +#ifndef _VX_SPACE_H
13323 +#define _VX_SPACE_H
13324 +
13325 +#include <linux/types.h>
13326 +
13327 +struct vx_info;
13328 +
13329 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13330 +
13331 +#else  /* _VX_SPACE_H */
13332 +#warning duplicate inclusion
13333 +#endif /* _VX_SPACE_H */
13334 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/switch.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/switch.h
13335 --- linux-2.6.33/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
13336 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/switch.h 2010-02-25 12:02:16.000000000 +0100
13337 @@ -0,0 +1,98 @@
13338 +#ifndef _VX_SWITCH_H
13339 +#define _VX_SWITCH_H
13340 +
13341 +#include <linux/types.h>
13342 +
13343 +
13344 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13345 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13346 +#define VC_VERSION(c)          ((c) & 0xFFF)
13347 +
13348 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13349 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13350 +
13351 +/*
13352 +
13353 +  Syscall Matrix V2.8
13354 +
13355 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13356 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13357 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13358 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13359 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13360 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13361 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13362 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13363 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13364 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13365 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13366 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13367 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13368 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13369 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13370 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13371 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13372 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13373 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13374 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13375 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13376 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13377 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13378 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13379 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13380 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13381 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13382 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13383 +
13384 +*/
13385 +
13386 +#define VC_CAT_VERSION         0
13387 +
13388 +#define VC_CAT_VSETUP          1
13389 +#define VC_CAT_VHOST           2
13390 +
13391 +#define VC_CAT_DEVICE          6
13392 +
13393 +#define VC_CAT_VPROC           9
13394 +#define VC_CAT_PROCALT         10
13395 +#define VC_CAT_PROCMIG         11
13396 +#define VC_CAT_PROCTRL         12
13397 +
13398 +#define VC_CAT_SCHED           14
13399 +#define VC_CAT_MEMCTRL         20
13400 +
13401 +#define VC_CAT_VNET            25
13402 +#define VC_CAT_NETALT          26
13403 +#define VC_CAT_NETMIG          27
13404 +#define VC_CAT_NETCTRL         28
13405 +
13406 +#define VC_CAT_TAGMIG          35
13407 +#define VC_CAT_DLIMIT          36
13408 +#define VC_CAT_INODE           38
13409 +
13410 +#define VC_CAT_VSTAT           40
13411 +#define VC_CAT_VINFO           46
13412 +#define VC_CAT_EVENT           48
13413 +
13414 +#define VC_CAT_FLAGS           52
13415 +#define VC_CAT_VSPACE          54
13416 +#define VC_CAT_DEBUG           56
13417 +#define VC_CAT_RLIMIT          60
13418 +
13419 +#define VC_CAT_SYSTEST         61
13420 +#define VC_CAT_COMPAT          63
13421 +
13422 +/*  query version */
13423 +
13424 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13425 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13426 +
13427 +
13428 +#ifdef __KERNEL__
13429 +
13430 +#include <linux/errno.h>
13431 +
13432 +#endif /* __KERNEL__ */
13433 +
13434 +#endif /* _VX_SWITCH_H */
13435 +
13436 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/tag_cmd.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/tag_cmd.h
13437 --- linux-2.6.33/include/linux/vserver/tag_cmd.h        1970-01-01 01:00:00.000000000 +0100
13438 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/tag_cmd.h        2010-02-25 12:02:16.000000000 +0100
13439 @@ -0,0 +1,22 @@
13440 +#ifndef _VX_TAG_CMD_H
13441 +#define _VX_TAG_CMD_H
13442 +
13443 +
13444 +/* vinfo commands */
13445 +
13446 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13447 +
13448 +#ifdef __KERNEL__
13449 +extern int vc_task_tag(uint32_t);
13450 +
13451 +#endif /* __KERNEL__ */
13452 +
13453 +/* context commands */
13454 +
13455 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13456 +
13457 +#ifdef __KERNEL__
13458 +extern int vc_tag_migrate(uint32_t);
13459 +
13460 +#endif /* __KERNEL__ */
13461 +#endif /* _VX_TAG_CMD_H */
13462 diff -NurpP --minimal linux-2.6.33/include/linux/vserver/tag.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/tag.h
13463 --- linux-2.6.33/include/linux/vserver/tag.h    1970-01-01 01:00:00.000000000 +0100
13464 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/tag.h    2010-02-25 12:02:16.000000000 +0100
13465 @@ -0,0 +1,143 @@
13466 +#ifndef _DX_TAG_H
13467 +#define _DX_TAG_H
13468 +
13469 +#include <linux/types.h>
13470 +
13471 +
13472 +#define DX_TAG(in)     (IS_TAGGED(in))
13473 +
13474 +
13475 +#ifdef CONFIG_TAG_NFSD
13476 +#define DX_TAG_NFSD    1
13477 +#else
13478 +#define DX_TAG_NFSD    0
13479 +#endif
13480 +
13481 +
13482 +#ifdef CONFIG_TAGGING_NONE
13483 +
13484 +#define MAX_UID                0xFFFFFFFF
13485 +#define MAX_GID                0xFFFFFFFF
13486 +
13487 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13488 +
13489 +#define TAGINO_UID(cond, uid, tag)     (uid)
13490 +#define TAGINO_GID(cond, gid, tag)     (gid)
13491 +
13492 +#endif
13493 +
13494 +
13495 +#ifdef CONFIG_TAGGING_GID16
13496 +
13497 +#define MAX_UID                0xFFFFFFFF
13498 +#define MAX_GID                0x0000FFFF
13499 +
13500 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13501 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13502 +
13503 +#define TAGINO_UID(cond, uid, tag)     (uid)
13504 +#define TAGINO_GID(cond, gid, tag)     \
13505 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13506 +
13507 +#endif
13508 +
13509 +
13510 +#ifdef CONFIG_TAGGING_ID24
13511 +
13512 +#define MAX_UID                0x00FFFFFF
13513 +#define MAX_GID                0x00FFFFFF
13514 +
13515 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13516 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13517 +
13518 +#define TAGINO_UID(cond, uid, tag)     \
13519 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13520 +#define TAGINO_GID(cond, gid, tag)     \
13521 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13522 +
13523 +#endif
13524 +
13525 +
13526 +#ifdef CONFIG_TAGGING_UID16
13527 +
13528 +#define MAX_UID                0x0000FFFF
13529 +#define MAX_GID                0xFFFFFFFF
13530 +
13531 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13532 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13533 +
13534 +#define TAGINO_UID(cond, uid, tag)     \
13535 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13536 +#define TAGINO_GID(cond, gid, tag)     (gid)
13537 +
13538 +#endif
13539 +
13540 +
13541 +#ifdef CONFIG_TAGGING_INTERN
13542 +
13543 +#define MAX_UID                0xFFFFFFFF
13544 +#define MAX_GID                0xFFFFFFFF
13545 +
13546 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13547 +       ((cond) ? (tag) : 0)
13548 +
13549 +#define TAGINO_UID(cond, uid, tag)     (uid)
13550 +#define TAGINO_GID(cond, gid, tag)     (gid)
13551 +
13552 +#endif
13553 +
13554 +
13555 +#ifndef CONFIG_TAGGING_NONE
13556 +#define dx_current_fstag(sb)   \
13557 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13558 +#else
13559 +#define dx_current_fstag(sb)   (0)
13560 +#endif
13561 +
13562 +#ifndef CONFIG_TAGGING_INTERN
13563 +#define TAGINO_TAG(cond, tag)  (0)
13564 +#else
13565 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13566 +#endif
13567 +
13568 +#define INOTAG_UID(cond, uid, gid)     \
13569 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13570 +#define INOTAG_GID(cond, uid, gid)     \
13571 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13572 +
13573 +
13574 +static inline uid_t dx_map_uid(uid_t uid)
13575 +{
13576 +       if ((uid > MAX_UID) && (uid != -1))
13577 +               uid = -2;
13578 +       return (uid & MAX_UID);
13579 +}
13580 +
13581 +static inline gid_t dx_map_gid(gid_t gid)
13582 +{
13583 +       if ((gid > MAX_GID) && (gid != -1))
13584 +               gid = -2;
13585 +       return (gid & MAX_GID);
13586 +}
13587 +
13588 +struct peer_tag {
13589 +       int32_t xid;
13590 +       int32_t nid;
13591 +};
13592 +
13593 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13594 +
13595 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13596 +                unsigned long *flags);
13597 +
13598 +#ifdef CONFIG_PROPAGATE
13599 +
13600 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13601 +
13602 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13603 +
13604 +#else
13605 +#define dx_propagate_tag(n, i) do { } while (0)
13606 +#endif
13607 +
13608 +#endif /* _DX_TAG_H */
13609 diff -NurpP --minimal linux-2.6.33/include/linux/vs_inet6.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_inet6.h
13610 --- linux-2.6.33/include/linux/vs_inet6.h       1970-01-01 01:00:00.000000000 +0100
13611 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_inet6.h       2010-02-25 14:47:08.000000000 +0100
13612 @@ -0,0 +1,246 @@
13613 +#ifndef _VS_INET6_H
13614 +#define _VS_INET6_H
13615 +
13616 +#include "vserver/base.h"
13617 +#include "vserver/network.h"
13618 +#include "vserver/debug.h"
13619 +
13620 +#include <net/ipv6.h>
13621 +
13622 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13623 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13624 +
13625 +
13626 +#ifdef CONFIG_IPV6
13627 +
13628 +static inline
13629 +int v6_addr_match(struct nx_addr_v6 *nxa,
13630 +       const struct in6_addr *addr, uint16_t mask)
13631 +{
13632 +       int ret = 0;
13633 +
13634 +       switch (nxa->type & mask) {
13635 +       case NXA_TYPE_MASK:
13636 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13637 +               break;
13638 +       case NXA_TYPE_ADDR:
13639 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13640 +               break;
13641 +       case NXA_TYPE_ANY:
13642 +               ret = 1;
13643 +               break;
13644 +       }
13645 +       vxdprintk(VXD_CBIT(net, 0),
13646 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13647 +               nxa, NXAV6(nxa), addr, mask, ret);
13648 +       return ret;
13649 +}
13650 +
13651 +static inline
13652 +int v6_addr_in_nx_info(struct nx_info *nxi,
13653 +       const struct in6_addr *addr, uint16_t mask)
13654 +{
13655 +       struct nx_addr_v6 *nxa;
13656 +       int ret = 1;
13657 +
13658 +       if (!nxi)
13659 +               goto out;
13660 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13661 +               if (v6_addr_match(nxa, addr, mask))
13662 +                       goto out;
13663 +       ret = 0;
13664 +out:
13665 +       vxdprintk(VXD_CBIT(net, 0),
13666 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13667 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13668 +       return ret;
13669 +}
13670 +
13671 +static inline
13672 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13673 +{
13674 +       /* FIXME: needs full range checks */
13675 +       return v6_addr_match(nxa, &addr->ip, mask);
13676 +}
13677 +
13678 +static inline
13679 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13680 +{
13681 +       struct nx_addr_v6 *ptr;
13682 +
13683 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13684 +               if (v6_nx_addr_match(ptr, nxa, mask))
13685 +                       return 1;
13686 +       return 0;
13687 +}
13688 +
13689 +
13690 +/*
13691 + *     Check if a given address matches for a socket
13692 + *
13693 + *     nxi:            the socket's nx_info if any
13694 + *     addr:           to be verified address
13695 + */
13696 +static inline
13697 +int v6_sock_addr_match (
13698 +       struct nx_info *nxi,
13699 +       struct inet_sock *inet,
13700 +       struct in6_addr *addr)
13701 +{
13702 +       struct sock *sk = &inet->sk;
13703 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13704 +
13705 +       if (!ipv6_addr_any(addr) &&
13706 +               ipv6_addr_equal(saddr, addr))
13707 +               return 1;
13708 +       if (ipv6_addr_any(saddr))
13709 +               return v6_addr_in_nx_info(nxi, addr, -1);
13710 +       return 0;
13711 +}
13712 +
13713 +/*
13714 + *     check if address is covered by socket
13715 + *
13716 + *     sk:     the socket to check against
13717 + *     addr:   the address in question (must be != 0)
13718 + */
13719 +
13720 +static inline
13721 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13722 +{
13723 +       struct nx_info *nxi = sk->sk_nx_info;
13724 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13725 +
13726 +       vxdprintk(VXD_CBIT(net, 5),
13727 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13728 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13729 +               (sk->sk_socket?sk->sk_socket->flags:0));
13730 +
13731 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13732 +               return v6_addr_match(nxa, saddr, -1);
13733 +       } else if (nxi) {               /* match against nx_info */
13734 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13735 +       } else {                        /* unrestricted any socket */
13736 +               return 1;
13737 +       }
13738 +}
13739 +
13740 +
13741 +/* inet related checks and helpers */
13742 +
13743 +
13744 +struct in_ifaddr;
13745 +struct net_device;
13746 +struct sock;
13747 +
13748 +
13749 +#include <linux/netdevice.h>
13750 +#include <linux/inetdevice.h>
13751 +#include <net/inet_timewait_sock.h>
13752 +
13753 +
13754 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13755 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13756 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13757 +
13758 +
13759 +
13760 +static inline
13761 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13762 +{
13763 +       if (!nxi)
13764 +               return 1;
13765 +       if (!ifa)
13766 +               return 0;
13767 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13768 +}
13769 +
13770 +static inline
13771 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13772 +{
13773 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13774 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13775 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13776 +
13777 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13778 +               return 1;
13779 +       if (v6_ifa_in_nx_info(ifa, nxi))
13780 +               return 1;
13781 +       return 0;
13782 +}
13783 +
13784 +
13785 +struct nx_v6_sock_addr {
13786 +       struct in6_addr saddr;  /* Address used for validation */
13787 +       struct in6_addr baddr;  /* Address used for socket bind */
13788 +};
13789 +
13790 +static inline
13791 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13792 +       struct nx_v6_sock_addr *nsa)
13793 +{
13794 +       // struct sock *sk = &inet->sk;
13795 +       // struct nx_info *nxi = sk->sk_nx_info;
13796 +       struct in6_addr saddr = addr->sin6_addr;
13797 +       struct in6_addr baddr = saddr;
13798 +
13799 +       nsa->saddr = saddr;
13800 +       nsa->baddr = baddr;
13801 +       return 0;
13802 +}
13803 +
13804 +static inline
13805 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13806 +{
13807 +       // struct sock *sk = &inet->sk;
13808 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13809 +
13810 +       // *saddr = nsa->baddr;
13811 +       // inet->inet_saddr = nsa->baddr;
13812 +}
13813 +
13814 +static inline
13815 +int nx_info_has_v6(struct nx_info *nxi)
13816 +{
13817 +       if (!nxi)
13818 +               return 1;
13819 +       if (NX_IPV6(nxi))
13820 +               return 1;
13821 +       return 0;
13822 +}
13823 +
13824 +#else /* CONFIG_IPV6 */
13825 +
13826 +static inline
13827 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13828 +{
13829 +       return 1;
13830 +}
13831 +
13832 +
13833 +static inline
13834 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13835 +{
13836 +       return 1;
13837 +}
13838 +
13839 +static inline
13840 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13841 +{
13842 +       return 1;
13843 +}
13844 +
13845 +static inline
13846 +int nx_info_has_v6(struct nx_info *nxi)
13847 +{
13848 +       return 0;
13849 +}
13850 +
13851 +#endif /* CONFIG_IPV6 */
13852 +
13853 +#define current_nx_info_has_v6() \
13854 +       nx_info_has_v6(current_nx_info())
13855 +
13856 +#else
13857 +#warning duplicate inclusion
13858 +#endif
13859 diff -NurpP --minimal linux-2.6.33/include/linux/vs_inet.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_inet.h
13860 --- linux-2.6.33/include/linux/vs_inet.h        1970-01-01 01:00:00.000000000 +0100
13861 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_inet.h        2010-02-25 14:45:44.000000000 +0100
13862 @@ -0,0 +1,342 @@
13863 +#ifndef _VS_INET_H
13864 +#define _VS_INET_H
13865 +
13866 +#include "vserver/base.h"
13867 +#include "vserver/network.h"
13868 +#include "vserver/debug.h"
13869 +
13870 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13871 +
13872 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13873 +                       NIPQUAD((a)->mask), (a)->type
13874 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13875 +
13876 +
13877 +static inline
13878 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13879 +{
13880 +       __be32 ip = nxa->ip[0].s_addr;
13881 +       __be32 mask = nxa->mask.s_addr;
13882 +       __be32 bcast = ip | ~mask;
13883 +       int ret = 0;
13884 +
13885 +       switch (nxa->type & tmask) {
13886 +       case NXA_TYPE_MASK:
13887 +               ret = (ip == (addr & mask));
13888 +               break;
13889 +       case NXA_TYPE_ADDR:
13890 +               ret = 3;
13891 +               if (addr == ip)
13892 +                       break;
13893 +               /* fall through to broadcast */
13894 +       case NXA_MOD_BCAST:
13895 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13896 +               break;
13897 +       case NXA_TYPE_RANGE:
13898 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13899 +                       (nxa->ip[1].s_addr > addr));
13900 +               break;
13901 +       case NXA_TYPE_ANY:
13902 +               ret = 2;
13903 +               break;
13904 +       }
13905 +
13906 +       vxdprintk(VXD_CBIT(net, 0),
13907 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13908 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13909 +       return ret;
13910 +}
13911 +
13912 +static inline
13913 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13914 +{
13915 +       struct nx_addr_v4 *nxa;
13916 +       int ret = 1;
13917 +
13918 +       if (!nxi)
13919 +               goto out;
13920 +
13921 +       ret = 2;
13922 +       /* allow 127.0.0.1 when remapping lback */
13923 +       if ((tmask & NXA_LOOPBACK) &&
13924 +               (addr == IPI_LOOPBACK) &&
13925 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13926 +               goto out;
13927 +       ret = 3;
13928 +       /* check for lback address */
13929 +       if ((tmask & NXA_MOD_LBACK) &&
13930 +               (nxi->v4_lback.s_addr == addr))
13931 +               goto out;
13932 +       ret = 4;
13933 +       /* check for broadcast address */
13934 +       if ((tmask & NXA_MOD_BCAST) &&
13935 +               (nxi->v4_bcast.s_addr == addr))
13936 +               goto out;
13937 +       ret = 5;
13938 +       /* check for v4 addresses */
13939 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13940 +               if (v4_addr_match(nxa, addr, tmask))
13941 +                       goto out;
13942 +       ret = 0;
13943 +out:
13944 +       vxdprintk(VXD_CBIT(net, 0),
13945 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13946 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13947 +       return ret;
13948 +}
13949 +
13950 +static inline
13951 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13952 +{
13953 +       /* FIXME: needs full range checks */
13954 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13955 +}
13956 +
13957 +static inline
13958 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13959 +{
13960 +       struct nx_addr_v4 *ptr;
13961 +
13962 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13963 +               if (v4_nx_addr_match(ptr, nxa, mask))
13964 +                       return 1;
13965 +       return 0;
13966 +}
13967 +
13968 +#include <net/inet_sock.h>
13969 +
13970 +/*
13971 + *     Check if a given address matches for a socket
13972 + *
13973 + *     nxi:            the socket's nx_info if any
13974 + *     addr:           to be verified address
13975 + */
13976 +static inline
13977 +int v4_sock_addr_match (
13978 +       struct nx_info *nxi,
13979 +       struct inet_sock *inet,
13980 +       __be32 addr)
13981 +{
13982 +       __be32 saddr = inet->inet_rcv_saddr;
13983 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13984 +
13985 +       if (addr && (saddr == addr || bcast == addr))
13986 +               return 1;
13987 +       if (!saddr)
13988 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13989 +       return 0;
13990 +}
13991 +
13992 +
13993 +/* inet related checks and helpers */
13994 +
13995 +
13996 +struct in_ifaddr;
13997 +struct net_device;
13998 +struct sock;
13999 +
14000 +#ifdef CONFIG_INET
14001 +
14002 +#include <linux/netdevice.h>
14003 +#include <linux/inetdevice.h>
14004 +#include <net/inet_sock.h>
14005 +#include <net/inet_timewait_sock.h>
14006 +
14007 +
14008 +int dev_in_nx_info(struct net_device *, struct nx_info *);
14009 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
14010 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
14011 +
14012 +
14013 +/*
14014 + *     check if address is covered by socket
14015 + *
14016 + *     sk:     the socket to check against
14017 + *     addr:   the address in question (must be != 0)
14018 + */
14019 +
14020 +static inline
14021 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
14022 +{
14023 +       struct nx_info *nxi = sk->sk_nx_info;
14024 +       __be32 saddr = inet_rcv_saddr(sk);
14025 +
14026 +       vxdprintk(VXD_CBIT(net, 5),
14027 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
14028 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
14029 +               (sk->sk_socket?sk->sk_socket->flags:0));
14030 +
14031 +       if (saddr) {            /* direct address match */
14032 +               return v4_addr_match(nxa, saddr, -1);
14033 +       } else if (nxi) {       /* match against nx_info */
14034 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
14035 +       } else {                /* unrestricted any socket */
14036 +               return 1;
14037 +       }
14038 +}
14039 +
14040 +
14041 +
14042 +static inline
14043 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
14044 +{
14045 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
14046 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
14047 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
14048 +
14049 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
14050 +               return 1;
14051 +       if (dev_in_nx_info(dev, nxi))
14052 +               return 1;
14053 +       return 0;
14054 +}
14055 +
14056 +
14057 +static inline
14058 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
14059 +{
14060 +       if (!nxi)
14061 +               return 1;
14062 +       if (!ifa)
14063 +               return 0;
14064 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
14065 +}
14066 +
14067 +static inline
14068 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
14069 +{
14070 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
14071 +               nxi, nxi ? nxi->nx_id : 0, ifa,
14072 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
14073 +
14074 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
14075 +               return 1;
14076 +       if (v4_ifa_in_nx_info(ifa, nxi))
14077 +               return 1;
14078 +       return 0;
14079 +}
14080 +
14081 +
14082 +struct nx_v4_sock_addr {
14083 +       __be32 saddr;   /* Address used for validation */
14084 +       __be32 baddr;   /* Address used for socket bind */
14085 +};
14086 +
14087 +static inline
14088 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
14089 +       struct nx_v4_sock_addr *nsa)
14090 +{
14091 +       struct sock *sk = &inet->sk;
14092 +       struct nx_info *nxi = sk->sk_nx_info;
14093 +       __be32 saddr = addr->sin_addr.s_addr;
14094 +       __be32 baddr = saddr;
14095 +
14096 +       vxdprintk(VXD_CBIT(net, 3),
14097 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
14098 +               sk, sk->sk_nx_info, sk->sk_socket,
14099 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
14100 +               NIPQUAD(saddr));
14101 +
14102 +       if (nxi) {
14103 +               if (saddr == INADDR_ANY) {
14104 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
14105 +                               baddr = nxi->v4.ip[0].s_addr;
14106 +               } else if (saddr == IPI_LOOPBACK) {
14107 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
14108 +                               baddr = nxi->v4_lback.s_addr;
14109 +               } else {        /* normal address bind */
14110 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
14111 +                               return -EADDRNOTAVAIL;
14112 +               }
14113 +       }
14114 +
14115 +       vxdprintk(VXD_CBIT(net, 3),
14116 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
14117 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
14118 +
14119 +       nsa->saddr = saddr;
14120 +       nsa->baddr = baddr;
14121 +       return 0;
14122 +}
14123 +
14124 +static inline
14125 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
14126 +{
14127 +       inet->inet_saddr = nsa->baddr;
14128 +       inet->inet_rcv_saddr = nsa->baddr;
14129 +}
14130 +
14131 +
14132 +/*
14133 + *      helper to simplify inet_lookup_listener
14134 + *
14135 + *      nxi:   the socket's nx_info if any
14136 + *      addr:  to be verified address
14137 + *      saddr: socket address
14138 + */
14139 +static inline int v4_inet_addr_match (
14140 +       struct nx_info *nxi,
14141 +       __be32 addr,
14142 +       __be32 saddr)
14143 +{
14144 +       if (addr && (saddr == addr))
14145 +               return 1;
14146 +       if (!saddr)
14147 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
14148 +       return 0;
14149 +}
14150 +
14151 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
14152 +{
14153 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
14154 +               (addr == nxi->v4_lback.s_addr))
14155 +               return IPI_LOOPBACK;
14156 +       return addr;
14157 +}
14158 +
14159 +static inline
14160 +int nx_info_has_v4(struct nx_info *nxi)
14161 +{
14162 +       if (!nxi)
14163 +               return 1;
14164 +       if (NX_IPV4(nxi))
14165 +               return 1;
14166 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
14167 +               return 1;
14168 +       return 0;
14169 +}
14170 +
14171 +#else /* CONFIG_INET */
14172 +
14173 +static inline
14174 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
14175 +{
14176 +       return 1;
14177 +}
14178 +
14179 +static inline
14180 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
14181 +{
14182 +       return 1;
14183 +}
14184 +
14185 +static inline
14186 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
14187 +{
14188 +       return 1;
14189 +}
14190 +
14191 +static inline
14192 +int nx_info_has_v4(struct nx_info *nxi)
14193 +{
14194 +       return 0;
14195 +}
14196 +
14197 +#endif /* CONFIG_INET */
14198 +
14199 +#define current_nx_info_has_v4() \
14200 +       nx_info_has_v4(current_nx_info())
14201 +
14202 +#else
14203 +// #warning duplicate inclusion
14204 +#endif
14205 diff -NurpP --minimal linux-2.6.33/include/linux/vs_limit.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_limit.h
14206 --- linux-2.6.33/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
14207 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_limit.h       2010-02-25 12:02:16.000000000 +0100
14208 @@ -0,0 +1,140 @@
14209 +#ifndef _VS_LIMIT_H
14210 +#define _VS_LIMIT_H
14211 +
14212 +#include "vserver/limit.h"
14213 +#include "vserver/base.h"
14214 +#include "vserver/context.h"
14215 +#include "vserver/debug.h"
14216 +#include "vserver/context.h"
14217 +#include "vserver/limit_int.h"
14218 +
14219 +
14220 +#define vx_acc_cres(v, d, p, r) \
14221 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
14222 +
14223 +#define vx_acc_cres_cond(x, d, p, r) \
14224 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
14225 +       r, d, p, __FILE__, __LINE__)
14226 +
14227 +
14228 +#define vx_add_cres(v, a, p, r) \
14229 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
14230 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
14231 +
14232 +#define vx_add_cres_cond(x, a, p, r) \
14233 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
14234 +       r, a, p, __FILE__, __LINE__)
14235 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
14236 +
14237 +
14238 +/* process and file limits */
14239 +
14240 +#define vx_nproc_inc(p) \
14241 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
14242 +
14243 +#define vx_nproc_dec(p) \
14244 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
14245 +
14246 +#define vx_files_inc(f) \
14247 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
14248 +
14249 +#define vx_files_dec(f) \
14250 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
14251 +
14252 +#define vx_locks_inc(l) \
14253 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
14254 +
14255 +#define vx_locks_dec(l) \
14256 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
14257 +
14258 +#define vx_openfd_inc(f) \
14259 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
14260 +
14261 +#define vx_openfd_dec(f) \
14262 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
14263 +
14264 +
14265 +#define vx_cres_avail(v, n, r) \
14266 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
14267 +
14268 +
14269 +#define vx_nproc_avail(n) \
14270 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
14271 +
14272 +#define vx_files_avail(n) \
14273 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
14274 +
14275 +#define vx_locks_avail(n) \
14276 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
14277 +
14278 +#define vx_openfd_avail(n) \
14279 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
14280 +
14281 +
14282 +/* dentry limits */
14283 +
14284 +#define vx_dentry_inc(d) do {                                          \
14285 +       if (atomic_read(&d->d_count) == 1)                              \
14286 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
14287 +       } while (0)
14288 +
14289 +#define vx_dentry_dec(d) do {                                          \
14290 +       if (atomic_read(&d->d_count) == 0)                              \
14291 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
14292 +       } while (0)
14293 +
14294 +#define vx_dentry_avail(n) \
14295 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
14296 +
14297 +
14298 +/* socket limits */
14299 +
14300 +#define vx_sock_inc(s) \
14301 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
14302 +
14303 +#define vx_sock_dec(s) \
14304 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
14305 +
14306 +#define vx_sock_avail(n) \
14307 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
14308 +
14309 +
14310 +/* ipc resource limits */
14311 +
14312 +#define vx_ipcmsg_add(v, u, a) \
14313 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
14314 +
14315 +#define vx_ipcmsg_sub(v, u, a) \
14316 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
14317 +
14318 +#define vx_ipcmsg_avail(v, a) \
14319 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
14320 +
14321 +
14322 +#define vx_ipcshm_add(v, k, a) \
14323 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14324 +
14325 +#define vx_ipcshm_sub(v, k, a) \
14326 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14327 +
14328 +#define vx_ipcshm_avail(v, a) \
14329 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14330 +
14331 +
14332 +#define vx_semary_inc(a) \
14333 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
14334 +
14335 +#define vx_semary_dec(a) \
14336 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
14337 +
14338 +
14339 +#define vx_nsems_add(a,n) \
14340 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14341 +
14342 +#define vx_nsems_sub(a,n) \
14343 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14344 +
14345 +
14346 +#else
14347 +#warning duplicate inclusion
14348 +#endif
14349 diff -NurpP --minimal linux-2.6.33/include/linux/vs_memory.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_memory.h
14350 --- linux-2.6.33/include/linux/vs_memory.h      1970-01-01 01:00:00.000000000 +0100
14351 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_memory.h      2010-02-25 12:02:16.000000000 +0100
14352 @@ -0,0 +1,159 @@
14353 +#ifndef _VS_MEMORY_H
14354 +#define _VS_MEMORY_H
14355 +
14356 +#include "vserver/limit.h"
14357 +#include "vserver/base.h"
14358 +#include "vserver/context.h"
14359 +#include "vserver/debug.h"
14360 +#include "vserver/context.h"
14361 +#include "vserver/limit_int.h"
14362 +
14363 +
14364 +#define __acc_add_long(a, v)   (*(v) += (a))
14365 +#define __acc_inc_long(v)      (++*(v))
14366 +#define __acc_dec_long(v)      (--*(v))
14367 +
14368 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14369 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14370 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14371 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14372 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14373 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14374 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14375 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14376 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14377 +
14378 +
14379 +#define vx_acc_page(m, d, v, r) do {                                   \
14380 +       if ((d) > 0)                                                    \
14381 +               __acc_inc_long(&(m)->v);                                \
14382 +       else                                                            \
14383 +               __acc_dec_long(&(m)->v);                                \
14384 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14385 +} while (0)
14386 +
14387 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14388 +       if ((d) > 0)                                                    \
14389 +               __acc_inc_atomic(&(m)->v);                              \
14390 +       else                                                            \
14391 +               __acc_dec_atomic(&(m)->v);                              \
14392 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14393 +} while (0)
14394 +
14395 +
14396 +#define vx_acc_pages(m, p, v, r) do {                                  \
14397 +       unsigned long __p = (p);                                        \
14398 +       __acc_add_long(__p, &(m)->v);                                   \
14399 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14400 +} while (0)
14401 +
14402 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14403 +       unsigned long __p = (p);                                        \
14404 +       __acc_add_atomic(__p, &(m)->v);                                 \
14405 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14406 +} while (0)
14407 +
14408 +
14409 +
14410 +#define vx_acc_vmpage(m, d) \
14411 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14412 +#define vx_acc_vmlpage(m, d) \
14413 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14414 +#define vx_acc_file_rsspage(m, d) \
14415 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14416 +#define vx_acc_anon_rsspage(m, d) \
14417 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14418 +
14419 +#define vx_acc_vmpages(m, p) \
14420 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14421 +#define vx_acc_vmlpages(m, p) \
14422 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14423 +#define vx_acc_file_rsspages(m, p) \
14424 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14425 +#define vx_acc_anon_rsspages(m, p) \
14426 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14427 +
14428 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14429 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14430 +
14431 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14432 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14433 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14434 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14435 +
14436 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14437 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14438 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14439 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14440 +
14441 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14442 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14443 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14444 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14445 +
14446 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14447 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14448 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14449 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14450 +
14451 +
14452 +#define vx_pages_avail(m, p, r) \
14453 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14454 +
14455 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14456 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14457 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14458 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14459 +
14460 +#define vx_rss_avail(m, p) \
14461 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14462 +
14463 +
14464 +enum {
14465 +       VXPT_UNKNOWN = 0,
14466 +       VXPT_ANON,
14467 +       VXPT_NONE,
14468 +       VXPT_FILE,
14469 +       VXPT_SWAP,
14470 +       VXPT_WRITE
14471 +};
14472 +
14473 +#if 0
14474 +#define        vx_page_fault(mm, vma, type, ret)
14475 +#else
14476 +
14477 +static inline
14478 +void __vx_page_fault(struct mm_struct *mm,
14479 +       struct vm_area_struct *vma, int type, int ret)
14480 +{
14481 +       struct vx_info *vxi = mm->mm_vx_info;
14482 +       int what;
14483 +/*
14484 +       static char *page_type[6] =
14485 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14486 +       static char *page_what[4] =
14487 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14488 +*/
14489 +
14490 +       if (!vxi)
14491 +               return;
14492 +
14493 +       what = (ret & 0x3);
14494 +
14495 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14496 +               type, what, ret, page_type[type], page_what[what]);
14497 +*/
14498 +       if (ret & VM_FAULT_WRITE)
14499 +               what |= 0x4;
14500 +       atomic_inc(&vxi->cacct.page[type][what]);
14501 +}
14502 +
14503 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14504 +#endif
14505 +
14506 +
14507 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14508 +
14509 +#else
14510 +#warning duplicate inclusion
14511 +#endif
14512 diff -NurpP --minimal linux-2.6.33/include/linux/vs_network.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_network.h
14513 --- linux-2.6.33/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
14514 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_network.h     2010-02-25 12:02:16.000000000 +0100
14515 @@ -0,0 +1,169 @@
14516 +#ifndef _NX_VS_NETWORK_H
14517 +#define _NX_VS_NETWORK_H
14518 +
14519 +#include "vserver/context.h"
14520 +#include "vserver/network.h"
14521 +#include "vserver/base.h"
14522 +#include "vserver/check.h"
14523 +#include "vserver/debug.h"
14524 +
14525 +#include <linux/sched.h>
14526 +
14527 +
14528 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14529 +
14530 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14531 +       const char *_file, int _line)
14532 +{
14533 +       if (!nxi)
14534 +               return NULL;
14535 +
14536 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14537 +               nxi, nxi ? nxi->nx_id : 0,
14538 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14539 +               _file, _line);
14540 +
14541 +       atomic_inc(&nxi->nx_usecnt);
14542 +       return nxi;
14543 +}
14544 +
14545 +
14546 +extern void free_nx_info(struct nx_info *);
14547 +
14548 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14549 +
14550 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14551 +{
14552 +       if (!nxi)
14553 +               return;
14554 +
14555 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14556 +               nxi, nxi ? nxi->nx_id : 0,
14557 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14558 +               _file, _line);
14559 +
14560 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14561 +               free_nx_info(nxi);
14562 +}
14563 +
14564 +
14565 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14566 +
14567 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14568 +               const char *_file, int _line)
14569 +{
14570 +       if (nxi) {
14571 +               vxlprintk(VXD_CBIT(nid, 3),
14572 +                       "init_nx_info(%p[#%d.%d])",
14573 +                       nxi, nxi ? nxi->nx_id : 0,
14574 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14575 +                       _file, _line);
14576 +
14577 +               atomic_inc(&nxi->nx_usecnt);
14578 +       }
14579 +       *nxp = nxi;
14580 +}
14581 +
14582 +
14583 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14584 +
14585 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14586 +       const char *_file, int _line)
14587 +{
14588 +       struct nx_info *nxo;
14589 +
14590 +       if (!nxi)
14591 +               return;
14592 +
14593 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14594 +               nxi, nxi ? nxi->nx_id : 0,
14595 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14596 +               _file, _line);
14597 +
14598 +       atomic_inc(&nxi->nx_usecnt);
14599 +       nxo = xchg(nxp, nxi);
14600 +       BUG_ON(nxo);
14601 +}
14602 +
14603 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14604 +
14605 +static inline void __clr_nx_info(struct nx_info **nxp,
14606 +       const char *_file, int _line)
14607 +{
14608 +       struct nx_info *nxo;
14609 +
14610 +       nxo = xchg(nxp, NULL);
14611 +       if (!nxo)
14612 +               return;
14613 +
14614 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14615 +               nxo, nxo ? nxo->nx_id : 0,
14616 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14617 +               _file, _line);
14618 +
14619 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14620 +               free_nx_info(nxo);
14621 +}
14622 +
14623 +
14624 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14625 +
14626 +static inline void __claim_nx_info(struct nx_info *nxi,
14627 +       struct task_struct *task, const char *_file, int _line)
14628 +{
14629 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14630 +               nxi, nxi ? nxi->nx_id : 0,
14631 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14632 +               nxi?atomic_read(&nxi->nx_tasks):0,
14633 +               task, _file, _line);
14634 +
14635 +       atomic_inc(&nxi->nx_tasks);
14636 +}
14637 +
14638 +
14639 +extern void unhash_nx_info(struct nx_info *);
14640 +
14641 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14642 +
14643 +static inline void __release_nx_info(struct nx_info *nxi,
14644 +       struct task_struct *task, const char *_file, int _line)
14645 +{
14646 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14647 +               nxi, nxi ? nxi->nx_id : 0,
14648 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14649 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14650 +               task, _file, _line);
14651 +
14652 +       might_sleep();
14653 +
14654 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14655 +               unhash_nx_info(nxi);
14656 +}
14657 +
14658 +
14659 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14660 +
14661 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14662 +       const char *_file, int _line)
14663 +{
14664 +       struct nx_info *nxi;
14665 +
14666 +       task_lock(p);
14667 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14668 +               p, _file, _line);
14669 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14670 +       task_unlock(p);
14671 +       return nxi;
14672 +}
14673 +
14674 +
14675 +static inline void exit_nx_info(struct task_struct *p)
14676 +{
14677 +       if (p->nx_info)
14678 +               release_nx_info(p->nx_info, p);
14679 +}
14680 +
14681 +
14682 +#else
14683 +#warning duplicate inclusion
14684 +#endif
14685 diff -NurpP --minimal linux-2.6.33/include/linux/vs_pid.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_pid.h
14686 --- linux-2.6.33/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
14687 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_pid.h 2010-02-25 12:02:16.000000000 +0100
14688 @@ -0,0 +1,95 @@
14689 +#ifndef _VS_PID_H
14690 +#define _VS_PID_H
14691 +
14692 +#include "vserver/base.h"
14693 +#include "vserver/check.h"
14694 +#include "vserver/context.h"
14695 +#include "vserver/debug.h"
14696 +#include "vserver/pid.h"
14697 +#include <linux/pid_namespace.h>
14698 +
14699 +
14700 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14701 +
14702 +static inline
14703 +int vx_proc_task_visible(struct task_struct *task)
14704 +{
14705 +       if ((task->pid == 1) &&
14706 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14707 +               /* show a blend through init */
14708 +               goto visible;
14709 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14710 +               goto visible;
14711 +       return 0;
14712 +visible:
14713 +       return 1;
14714 +}
14715 +
14716 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14717 +
14718 +#if 0
14719 +
14720 +static inline
14721 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14722 +{
14723 +       struct task_struct *task = find_task_by_real_pid(pid);
14724 +
14725 +       if (task && !vx_proc_task_visible(task)) {
14726 +               vxdprintk(VXD_CBIT(misc, 6),
14727 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14728 +                       task, task->xid, task->pid,
14729 +                       current, current->xid, current->pid);
14730 +               task = NULL;
14731 +       }
14732 +       return task;
14733 +}
14734 +
14735 +#endif
14736 +
14737 +static inline
14738 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14739 +{
14740 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14741 +
14742 +       if (task && !vx_proc_task_visible(task)) {
14743 +               vxdprintk(VXD_CBIT(misc, 6),
14744 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14745 +                       task, task->xid, task->pid,
14746 +                       current, current->xid, current->pid);
14747 +               put_task_struct(task);
14748 +               task = NULL;
14749 +       }
14750 +       return task;
14751 +}
14752 +
14753 +#if 0
14754 +
14755 +static inline
14756 +struct task_struct *vx_child_reaper(struct task_struct *p)
14757 +{
14758 +       struct vx_info *vxi = p->vx_info;
14759 +       struct task_struct *reaper = child_reaper(p);
14760 +
14761 +       if (!vxi)
14762 +               goto out;
14763 +
14764 +       BUG_ON(!p->vx_info->vx_reaper);
14765 +
14766 +       /* child reaper for the guest reaper */
14767 +       if (vxi->vx_reaper == p)
14768 +               goto out;
14769 +
14770 +       reaper = vxi->vx_reaper;
14771 +out:
14772 +       vxdprintk(VXD_CBIT(xid, 7),
14773 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14774 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14775 +       return reaper;
14776 +}
14777 +
14778 +#endif
14779 +
14780 +
14781 +#else
14782 +#warning duplicate inclusion
14783 +#endif
14784 diff -NurpP --minimal linux-2.6.33/include/linux/vs_sched.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_sched.h
14785 --- linux-2.6.33/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
14786 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_sched.h       2010-02-25 12:02:16.000000000 +0100
14787 @@ -0,0 +1,110 @@
14788 +#ifndef _VS_SCHED_H
14789 +#define _VS_SCHED_H
14790 +
14791 +#include "vserver/base.h"
14792 +#include "vserver/context.h"
14793 +#include "vserver/sched.h"
14794 +
14795 +
14796 +#define VAVAVOOM_RATIO          50
14797 +
14798 +#define MAX_PRIO_BIAS           20
14799 +#define MIN_PRIO_BIAS          -20
14800 +
14801 +
14802 +#ifdef CONFIG_VSERVER_HARDCPU
14803 +
14804 +/*
14805 + * effective_prio - return the priority that is based on the static
14806 + * priority but is modified by bonuses/penalties.
14807 + *
14808 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14809 + * into a -4 ... 0 ... +4 bonus/penalty range.
14810 + *
14811 + * Additionally, we scale another amount based on the number of
14812 + * CPU tokens currently held by the context, if the process is
14813 + * part of a context (and the appropriate SCHED flag is set).
14814 + * This ranges from -5 ... 0 ... +15, quadratically.
14815 + *
14816 + * So, the total bonus is -9 .. 0 .. +19
14817 + * We use ~50% of the full 0...39 priority range so that:
14818 + *
14819 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14820 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14821 + *    unless that context is far exceeding its CPU allocation.
14822 + *
14823 + * Both properties are important to certain workloads.
14824 + */
14825 +static inline
14826 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14827 +{
14828 +       int vavavoom, max;
14829 +
14830 +       /* lots of tokens = lots of vavavoom
14831 +        *      no tokens = no vavavoom      */
14832 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14833 +               max = sched_pc->tokens_max;
14834 +               vavavoom = max - vavavoom;
14835 +               max = max * max;
14836 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14837 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14838 +               return vavavoom;
14839 +       }
14840 +       return 0;
14841 +}
14842 +
14843 +
14844 +static inline
14845 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14846 +{
14847 +       struct vx_info *vxi = p->vx_info;
14848 +       struct _vx_sched_pc *sched_pc;
14849 +
14850 +       if (!vxi)
14851 +               return prio;
14852 +
14853 +       sched_pc = &vx_cpu(vxi, sched_pc);
14854 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14855 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14856 +
14857 +               sched_pc->vavavoom = vavavoom;
14858 +               prio += vavavoom;
14859 +       }
14860 +       prio += sched_pc->prio_bias;
14861 +       return prio;
14862 +}
14863 +
14864 +#else /* !CONFIG_VSERVER_HARDCPU */
14865 +
14866 +static inline
14867 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14868 +{
14869 +       struct vx_info *vxi = p->vx_info;
14870 +
14871 +       if (vxi)
14872 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14873 +       return prio;
14874 +}
14875 +
14876 +#endif /* CONFIG_VSERVER_HARDCPU */
14877 +
14878 +
14879 +static inline void vx_account_user(struct vx_info *vxi,
14880 +       cputime_t cputime, int nice)
14881 +{
14882 +       if (!vxi)
14883 +               return;
14884 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14885 +}
14886 +
14887 +static inline void vx_account_system(struct vx_info *vxi,
14888 +       cputime_t cputime, int idle)
14889 +{
14890 +       if (!vxi)
14891 +               return;
14892 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14893 +}
14894 +
14895 +#else
14896 +#warning duplicate inclusion
14897 +#endif
14898 diff -NurpP --minimal linux-2.6.33/include/linux/vs_socket.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_socket.h
14899 --- linux-2.6.33/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
14900 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_socket.h      2010-02-25 12:02:16.000000000 +0100
14901 @@ -0,0 +1,67 @@
14902 +#ifndef _VS_SOCKET_H
14903 +#define _VS_SOCKET_H
14904 +
14905 +#include "vserver/debug.h"
14906 +#include "vserver/base.h"
14907 +#include "vserver/cacct.h"
14908 +#include "vserver/context.h"
14909 +#include "vserver/tag.h"
14910 +
14911 +
14912 +/* socket accounting */
14913 +
14914 +#include <linux/socket.h>
14915 +
14916 +static inline int vx_sock_type(int family)
14917 +{
14918 +       switch (family) {
14919 +       case PF_UNSPEC:
14920 +               return VXA_SOCK_UNSPEC;
14921 +       case PF_UNIX:
14922 +               return VXA_SOCK_UNIX;
14923 +       case PF_INET:
14924 +               return VXA_SOCK_INET;
14925 +       case PF_INET6:
14926 +               return VXA_SOCK_INET6;
14927 +       case PF_PACKET:
14928 +               return VXA_SOCK_PACKET;
14929 +       default:
14930 +               return VXA_SOCK_OTHER;
14931 +       }
14932 +}
14933 +
14934 +#define vx_acc_sock(v, f, p, s) \
14935 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14936 +
14937 +static inline void __vx_acc_sock(struct vx_info *vxi,
14938 +       int family, int pos, int size, char *file, int line)
14939 +{
14940 +       if (vxi) {
14941 +               int type = vx_sock_type(family);
14942 +
14943 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14944 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14945 +       }
14946 +}
14947 +
14948 +#define vx_sock_recv(sk, s) \
14949 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14950 +#define vx_sock_send(sk, s) \
14951 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14952 +#define vx_sock_fail(sk, s) \
14953 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14954 +
14955 +
14956 +#define sock_vx_init(s) do {           \
14957 +       (s)->sk_xid = 0;                \
14958 +       (s)->sk_vx_info = NULL;         \
14959 +       } while (0)
14960 +
14961 +#define sock_nx_init(s) do {           \
14962 +       (s)->sk_nid = 0;                \
14963 +       (s)->sk_nx_info = NULL;         \
14964 +       } while (0)
14965 +
14966 +#else
14967 +#warning duplicate inclusion
14968 +#endif
14969 diff -NurpP --minimal linux-2.6.33/include/linux/vs_tag.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_tag.h
14970 --- linux-2.6.33/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
14971 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_tag.h 2010-02-25 12:02:16.000000000 +0100
14972 @@ -0,0 +1,47 @@
14973 +#ifndef _VS_TAG_H
14974 +#define _VS_TAG_H
14975 +
14976 +#include <linux/vserver/tag.h>
14977 +
14978 +/* check conditions */
14979 +
14980 +#define DX_ADMIN       0x0001
14981 +#define DX_WATCH       0x0002
14982 +#define DX_HOSTID      0x0008
14983 +
14984 +#define DX_IDENT       0x0010
14985 +
14986 +#define DX_ARG_MASK    0x0010
14987 +
14988 +
14989 +#define dx_task_tag(t) ((t)->tag)
14990 +
14991 +#define dx_current_tag() dx_task_tag(current)
14992 +
14993 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14994 +
14995 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14996 +
14997 +
14998 +/*
14999 + * check current context for ADMIN/WATCH and
15000 + * optionally against supplied argument
15001 + */
15002 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
15003 +{
15004 +       if (mode & DX_ARG_MASK) {
15005 +               if ((mode & DX_IDENT) && (id == cid))
15006 +                       return 1;
15007 +       }
15008 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
15009 +               ((mode & DX_WATCH) && (cid == 1)) ||
15010 +               ((mode & DX_HOSTID) && (id == 0)));
15011 +}
15012 +
15013 +struct inode;
15014 +int dx_permission(const struct inode *inode, int mask);
15015 +
15016 +
15017 +#else
15018 +#warning duplicate inclusion
15019 +#endif
15020 diff -NurpP --minimal linux-2.6.33/include/linux/vs_time.h linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_time.h
15021 --- linux-2.6.33/include/linux/vs_time.h        1970-01-01 01:00:00.000000000 +0100
15022 +++ linux-2.6.33-vs2.3.0.36.30.1/include/linux/vs_time.h        2010-02-25 12:02:16.000000000 +0100
15023 @@ -0,0 +1,19 @@
15024 +#ifndef _VS_TIME_H
15025 +#define _VS_TIME_H
15026 +
15027 +
15028 +/* time faking stuff */
15029 +
15030 +#ifdef CONFIG_VSERVER_VTIME
15031 +
15032 +extern void vx_gettimeofday(struct timeval *tv);
15033 +extern int vx_settimeofday(struct timespec *ts);
15034 +
15035 +#else
15036 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
15037 +#define        vx_settimeofday(t)      do_settimeofday(t)
15038 +#endif
15039 +
15040 +#else
15041 +#warning duplicate inclusion
15042 +#endif
15043 diff -NurpP --minimal linux-2.6.33/include/net/addrconf.h linux-2.6.33-vs2.3.0.36.30.1/include/net/addrconf.h
15044 --- linux-2.6.33/include/net/addrconf.h 2009-12-03 20:02:57.000000000 +0100
15045 +++ linux-2.6.33-vs2.3.0.36.30.1/include/net/addrconf.h 2010-02-25 12:02:16.000000000 +0100
15046 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
15047                                                struct net_device *dev,
15048                                                const struct in6_addr *daddr,
15049                                                unsigned int srcprefs,
15050 -                                              struct in6_addr *saddr);
15051 +                                              struct in6_addr *saddr,
15052 +                                              struct nx_info *nxi);
15053  extern int                     ipv6_get_lladdr(struct net_device *dev,
15054                                                 struct in6_addr *addr,
15055                                                 unsigned char banned_flags);
15056 diff -NurpP --minimal linux-2.6.33/include/net/af_unix.h linux-2.6.33-vs2.3.0.36.30.1/include/net/af_unix.h
15057 --- linux-2.6.33/include/net/af_unix.h  2008-12-25 00:26:37.000000000 +0100
15058 +++ linux-2.6.33-vs2.3.0.36.30.1/include/net/af_unix.h  2010-02-25 12:02:16.000000000 +0100
15059 @@ -4,6 +4,7 @@
15060  #include <linux/socket.h>
15061  #include <linux/un.h>
15062  #include <linux/mutex.h>
15063 +#include <linux/vs_base.h>
15064  #include <net/sock.h>
15065  
15066  extern void unix_inflight(struct file *fp);
15067 diff -NurpP --minimal linux-2.6.33/include/net/inet_timewait_sock.h linux-2.6.33-vs2.3.0.36.30.1/include/net/inet_timewait_sock.h
15068 --- linux-2.6.33/include/net/inet_timewait_sock.h       2010-02-25 11:52:08.000000000 +0100
15069 +++ linux-2.6.33-vs2.3.0.36.30.1/include/net/inet_timewait_sock.h       2010-02-25 12:02:16.000000000 +0100
15070 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
15071  #define tw_hash                        __tw_common.skc_hash
15072  #define tw_prot                        __tw_common.skc_prot
15073  #define tw_net                 __tw_common.skc_net
15074 +#define tw_xid                 __tw_common.skc_xid
15075 +#define tw_vx_info             __tw_common.skc_vx_info
15076 +#define tw_nid                 __tw_common.skc_nid
15077 +#define tw_nx_info             __tw_common.skc_nx_info
15078         int                     tw_timeout;
15079         volatile unsigned char  tw_substate;
15080         /* 3 bits hole, try to pack */
15081 diff -NurpP --minimal linux-2.6.33/include/net/route.h linux-2.6.33-vs2.3.0.36.30.1/include/net/route.h
15082 --- linux-2.6.33/include/net/route.h    2010-02-25 11:52:08.000000000 +0100
15083 +++ linux-2.6.33-vs2.3.0.36.30.1/include/net/route.h    2010-02-25 12:02:16.000000000 +0100
15084 @@ -132,6 +132,9 @@ static inline void ip_rt_put(struct rtab
15085                 dst_release(&rt->u.dst);
15086  }
15087  
15088 +#include <linux/vs_base.h>
15089 +#include <linux/vs_inet.h>
15090 +
15091  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
15092  
15093  extern const __u8 ip_tos2prio[16];
15094 @@ -141,6 +144,9 @@ static inline char rt_tos2priority(u8 to
15095         return ip_tos2prio[IPTOS_TOS(tos)>>1];
15096  }
15097  
15098 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
15099 +       struct rtable **, struct flowi *);
15100 +
15101  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
15102                                    __be32 src, u32 tos, int oif, u8 protocol,
15103                                    __be16 sport, __be16 dport, struct sock *sk,
15104 @@ -158,11 +164,24 @@ static inline int ip_route_connect(struc
15105  
15106         int err;
15107         struct net *net = sock_net(sk);
15108 +       struct nx_info *nx_info = current_nx_info();
15109  
15110         if (inet_sk(sk)->transparent)
15111                 fl.flags |= FLOWI_FLAG_ANYSRC;
15112  
15113 -       if (!dst || !src) {
15114 +       if (sk)
15115 +               nx_info = sk->sk_nx_info;
15116 +
15117 +       vxdprintk(VXD_CBIT(net, 4),
15118 +               "ip_route_connect(%p) %p,%p;%lx",
15119 +               sk, nx_info, sk->sk_socket,
15120 +               (sk->sk_socket?sk->sk_socket->flags:0));
15121 +
15122 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
15123 +       if (err)
15124 +               return err;
15125 +
15126 +       if (!fl.fl4_dst || !fl.fl4_src) {
15127                 err = __ip_route_output_key(net, rp, &fl);
15128                 if (err)
15129                         return err;
15130 diff -NurpP --minimal linux-2.6.33/include/net/sock.h linux-2.6.33-vs2.3.0.36.30.1/include/net/sock.h
15131 --- linux-2.6.33/include/net/sock.h     2010-02-25 11:52:08.000000000 +0100
15132 +++ linux-2.6.33-vs2.3.0.36.30.1/include/net/sock.h     2010-02-25 12:02:16.000000000 +0100
15133 @@ -149,6 +149,10 @@ struct sock_common {
15134  #ifdef CONFIG_NET_NS
15135         struct net              *skc_net;
15136  #endif
15137 +       xid_t                   skc_xid;
15138 +       struct vx_info          *skc_vx_info;
15139 +       nid_t                   skc_nid;
15140 +       struct nx_info          *skc_nx_info;
15141  };
15142  
15143  /**
15144 @@ -236,6 +240,10 @@ struct sock {
15145  #define sk_bind_node           __sk_common.skc_bind_node
15146  #define sk_prot                        __sk_common.skc_prot
15147  #define sk_net                 __sk_common.skc_net
15148 +#define sk_xid                 __sk_common.skc_xid
15149 +#define sk_vx_info             __sk_common.skc_vx_info
15150 +#define sk_nid                 __sk_common.skc_nid
15151 +#define sk_nx_info             __sk_common.skc_nx_info
15152         kmemcheck_bitfield_begin(flags);
15153         unsigned int            sk_shutdown  : 2,
15154                                 sk_no_check  : 2,
15155 diff -NurpP --minimal linux-2.6.33/init/Kconfig linux-2.6.33-vs2.3.0.36.30.1/init/Kconfig
15156 --- linux-2.6.33/init/Kconfig   2010-02-25 11:52:09.000000000 +0100
15157 +++ linux-2.6.33-vs2.3.0.36.30.1/init/Kconfig   2010-02-25 16:27:44.000000000 +0100
15158 @@ -496,8 +496,22 @@ config CGROUP_SCHED
15159  
15160  endchoice
15161  
15162 +config CFS_HARD_LIMITS
15163 +       bool "Hard Limits for CFS Group Scheduler"
15164 +       depends on EXPERIMENTAL
15165 +       depends on FAIR_GROUP_SCHED && CGROUP_SCHED
15166 +       default y
15167 +       help
15168 +         This option enables hard limiting of CPU time obtained by
15169 +         a fair task group. Use this if you want to throttle a group of tasks
15170 +         based on its CPU usage. For more details refer to
15171 +         Documentation/scheduler/sched-cfs-hard-limits.txt
15172 +
15173 +         Say N if unsure.
15174 +
15175  menuconfig CGROUPS
15176         boolean "Control Group support"
15177 +       default y
15178         help
15179           This option adds support for grouping sets of processes together, for
15180           use with process control subsystems such as Cpusets, CFS, memory
15181 @@ -525,6 +539,7 @@ config CGROUP_DEBUG
15182  config CGROUP_NS
15183         bool "Namespace cgroup subsystem"
15184         depends on CGROUPS
15185 +       default n
15186         help
15187           Provides a simple namespace cgroup subsystem to
15188           provide hierarchical naming of sets of namespaces,
15189 diff -NurpP --minimal linux-2.6.33/init/main.c linux-2.6.33-vs2.3.0.36.30.1/init/main.c
15190 --- linux-2.6.33/init/main.c    2010-02-25 11:52:09.000000000 +0100
15191 +++ linux-2.6.33-vs2.3.0.36.30.1/init/main.c    2010-02-25 12:02:16.000000000 +0100
15192 @@ -70,6 +70,7 @@
15193  #include <linux/sfi.h>
15194  #include <linux/shmem_fs.h>
15195  #include <trace/boot.h>
15196 +#include <linux/vserver/percpu.h>
15197  
15198  #include <asm/io.h>
15199  #include <asm/bugs.h>
15200 diff -NurpP --minimal linux-2.6.33/ipc/mqueue.c linux-2.6.33-vs2.3.0.36.30.1/ipc/mqueue.c
15201 --- linux-2.6.33/ipc/mqueue.c   2010-02-25 11:52:09.000000000 +0100
15202 +++ linux-2.6.33-vs2.3.0.36.30.1/ipc/mqueue.c   2010-02-25 12:21:21.000000000 +0100
15203 @@ -32,6 +32,8 @@
15204  #include <linux/nsproxy.h>
15205  #include <linux/pid.h>
15206  #include <linux/ipc_namespace.h>
15207 +#include <linux/vs_context.h>
15208 +#include <linux/vs_limit.h>
15209  
15210  #include <net/sock.h>
15211  #include "util.h"
15212 @@ -65,6 +67,7 @@ struct mqueue_inode_info {
15213         struct sigevent notify;
15214         struct pid* notify_owner;
15215         struct user_struct *user;       /* user who created, for accounting */
15216 +       struct vx_info *vxi;
15217         struct sock *notify_sock;
15218         struct sk_buff *notify_cookie;
15219  
15220 @@ -124,6 +127,7 @@ static struct inode *mqueue_get_inode(st
15221                 if (S_ISREG(mode)) {
15222                         struct mqueue_inode_info *info;
15223                         struct task_struct *p = current;
15224 +                       struct vx_info *vxi = p->vx_info;
15225                         unsigned long mq_bytes, mq_msg_tblsz;
15226  
15227                         inode->i_fop = &mqueue_file_operations;
15228 @@ -138,6 +142,7 @@ static struct inode *mqueue_get_inode(st
15229                         info->notify_owner = NULL;
15230                         info->qsize = 0;
15231                         info->user = NULL;      /* set when all is ok */
15232 +                       info->vxi = NULL;
15233                         memset(&info->attr, 0, sizeof(info->attr));
15234                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
15235                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
15236 @@ -152,22 +157,26 @@ static struct inode *mqueue_get_inode(st
15237                         spin_lock(&mq_lock);
15238                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
15239                             u->mq_bytes + mq_bytes >
15240 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
15241 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
15242 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
15243                                 spin_unlock(&mq_lock);
15244                                 goto out_inode;
15245                         }
15246                         u->mq_bytes += mq_bytes;
15247 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
15248                         spin_unlock(&mq_lock);
15249  
15250                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
15251                         if (!info->messages) {
15252                                 spin_lock(&mq_lock);
15253                                 u->mq_bytes -= mq_bytes;
15254 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
15255                                 spin_unlock(&mq_lock);
15256                                 goto out_inode;
15257                         }
15258                         /* all is ok */
15259                         info->user = get_uid(u);
15260 +                       info->vxi = get_vx_info(vxi);
15261                 } else if (S_ISDIR(mode)) {
15262                         inc_nlink(inode);
15263                         /* Some things misbehave if size == 0 on a directory */
15264 @@ -268,8 +277,11 @@ static void mqueue_delete_inode(struct i
15265                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
15266         user = info->user;
15267         if (user) {
15268 +               struct vx_info *vxi = info->vxi;
15269 +
15270                 spin_lock(&mq_lock);
15271                 user->mq_bytes -= mq_bytes;
15272 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
15273                 /*
15274                  * get_ns_from_inode() ensures that the
15275                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
15276 @@ -279,6 +291,7 @@ static void mqueue_delete_inode(struct i
15277                 if (ipc_ns)
15278                         ipc_ns->mq_queues_count--;
15279                 spin_unlock(&mq_lock);
15280 +               put_vx_info(vxi);
15281                 free_uid(user);
15282         }
15283         if (ipc_ns)
15284 diff -NurpP --minimal linux-2.6.33/ipc/msg.c linux-2.6.33-vs2.3.0.36.30.1/ipc/msg.c
15285 --- linux-2.6.33/ipc/msg.c      2010-02-25 11:52:09.000000000 +0100
15286 +++ linux-2.6.33-vs2.3.0.36.30.1/ipc/msg.c      2010-02-25 12:02:16.000000000 +0100
15287 @@ -38,6 +38,7 @@
15288  #include <linux/rwsem.h>
15289  #include <linux/nsproxy.h>
15290  #include <linux/ipc_namespace.h>
15291 +#include <linux/vs_base.h>
15292  
15293  #include <asm/current.h>
15294  #include <asm/uaccess.h>
15295 @@ -191,6 +192,7 @@ static int newque(struct ipc_namespace *
15296  
15297         msq->q_perm.mode = msgflg & S_IRWXUGO;
15298         msq->q_perm.key = key;
15299 +       msq->q_perm.xid = vx_current_xid();
15300  
15301         msq->q_perm.security = NULL;
15302         retval = security_msg_queue_alloc(msq);
15303 diff -NurpP --minimal linux-2.6.33/ipc/namespace.c linux-2.6.33-vs2.3.0.36.30.1/ipc/namespace.c
15304 --- linux-2.6.33/ipc/namespace.c        2009-09-10 15:26:27.000000000 +0200
15305 +++ linux-2.6.33-vs2.3.0.36.30.1/ipc/namespace.c        2010-02-25 12:02:16.000000000 +0100
15306 @@ -11,6 +11,8 @@
15307  #include <linux/slab.h>
15308  #include <linux/fs.h>
15309  #include <linux/mount.h>
15310 +#include <linux/vs_base.h>
15311 +#include <linux/vserver/global.h>
15312  
15313  #include "util.h"
15314  
15315 diff -NurpP --minimal linux-2.6.33/ipc/sem.c linux-2.6.33-vs2.3.0.36.30.1/ipc/sem.c
15316 --- linux-2.6.33/ipc/sem.c      2010-02-25 11:52:09.000000000 +0100
15317 +++ linux-2.6.33-vs2.3.0.36.30.1/ipc/sem.c      2010-02-25 12:02:16.000000000 +0100
15318 @@ -83,6 +83,8 @@
15319  #include <linux/rwsem.h>
15320  #include <linux/nsproxy.h>
15321  #include <linux/ipc_namespace.h>
15322 +#include <linux/vs_base.h>
15323 +#include <linux/vs_limit.h>
15324  
15325  #include <asm/uaccess.h>
15326  #include "util.h"
15327 @@ -257,6 +259,7 @@ static int newary(struct ipc_namespace *
15328  
15329         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15330         sma->sem_perm.key = key;
15331 +       sma->sem_perm.xid = vx_current_xid();
15332  
15333         sma->sem_perm.security = NULL;
15334         retval = security_sem_alloc(sma);
15335 @@ -272,6 +275,9 @@ static int newary(struct ipc_namespace *
15336                 return id;
15337         }
15338         ns->used_sems += nsems;
15339 +       /* FIXME: obsoleted? */
15340 +       vx_semary_inc(sma);
15341 +       vx_nsems_add(sma, nsems);
15342  
15343         sma->sem_base = (struct sem *) &sma[1];
15344  
15345 @@ -595,6 +601,9 @@ static void freeary(struct ipc_namespace
15346         sem_unlock(sma);
15347  
15348         ns->used_sems -= sma->sem_nsems;
15349 +       /* FIXME: obsoleted? */
15350 +       vx_nsems_sub(sma, sma->sem_nsems);
15351 +       vx_semary_dec(sma);
15352         security_sem_free(sma);
15353         ipc_rcu_putref(sma);
15354  }
15355 diff -NurpP --minimal linux-2.6.33/ipc/shm.c linux-2.6.33-vs2.3.0.36.30.1/ipc/shm.c
15356 --- linux-2.6.33/ipc/shm.c      2010-02-25 11:52:09.000000000 +0100
15357 +++ linux-2.6.33-vs2.3.0.36.30.1/ipc/shm.c      2010-02-25 12:23:04.000000000 +0100
15358 @@ -39,6 +39,8 @@
15359  #include <linux/nsproxy.h>
15360  #include <linux/mount.h>
15361  #include <linux/ipc_namespace.h>
15362 +#include <linux/vs_context.h>
15363 +#include <linux/vs_limit.h>
15364  
15365  #include <asm/uaccess.h>
15366  
15367 @@ -169,7 +171,12 @@ static void shm_open(struct vm_area_stru
15368   */
15369  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15370  {
15371 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15372 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15373 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15374 +
15375 +       vx_ipcshm_sub(vxi, shp, numpages);
15376 +       ns->shm_tot -= numpages;
15377 +
15378         shm_rmid(ns, shp);
15379         shm_unlock(shp);
15380         if (!is_file_hugepages(shp->shm_file))
15381 @@ -179,6 +186,7 @@ static void shm_destroy(struct ipc_names
15382                                                 shp->mlock_user);
15383         fput (shp->shm_file);
15384         security_shm_free(shp);
15385 +       put_vx_info(vxi);
15386         ipc_rcu_putref(shp);
15387  }
15388  
15389 @@ -352,11 +360,15 @@ static int newseg(struct ipc_namespace *
15390         if (ns->shm_tot + numpages > ns->shm_ctlall)
15391                 return -ENOSPC;
15392  
15393 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
15394 +               return -ENOSPC;
15395 +
15396         shp = ipc_rcu_alloc(sizeof(*shp));
15397         if (!shp)
15398                 return -ENOMEM;
15399  
15400         shp->shm_perm.key = key;
15401 +       shp->shm_perm.xid = vx_current_xid();
15402         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15403         shp->mlock_user = NULL;
15404  
15405 @@ -410,6 +422,7 @@ static int newseg(struct ipc_namespace *
15406         ns->shm_tot += numpages;
15407         error = shp->shm_perm.id;
15408         shm_unlock(shp);
15409 +       vx_ipcshm_add(current_vx_info(), key, numpages);
15410         return error;
15411  
15412  no_id:
15413 diff -NurpP --minimal linux-2.6.33/kernel/capability.c linux-2.6.33-vs2.3.0.36.30.1/kernel/capability.c
15414 --- linux-2.6.33/kernel/capability.c    2010-02-25 11:52:09.000000000 +0100
15415 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/capability.c    2010-02-25 12:02:16.000000000 +0100
15416 @@ -14,6 +14,7 @@
15417  #include <linux/security.h>
15418  #include <linux/syscalls.h>
15419  #include <linux/pid_namespace.h>
15420 +#include <linux/vs_context.h>
15421  #include <asm/uaccess.h>
15422  #include "cred-internals.h"
15423  
15424 @@ -120,6 +121,7 @@ static int cap_validate_magic(cap_user_h
15425         return 0;
15426  }
15427  
15428 +
15429  /*
15430   * The only thing that can change the capabilities of the current
15431   * process is the current process. As such, we can't be in this code
15432 @@ -290,6 +292,8 @@ error:
15433         return ret;
15434  }
15435  
15436 +#include <linux/vserver/base.h>
15437 +
15438  /**
15439   * capable - Determine if the current task has a superior capability in effect
15440   * @cap: The capability to be tested for
15441 @@ -302,6 +306,9 @@ error:
15442   */
15443  int capable(int cap)
15444  {
15445 +       /* here for now so we don't require task locking */
15446 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15447 +               return 0;
15448         if (unlikely(!cap_valid(cap))) {
15449                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15450                 BUG();
15451 diff -NurpP --minimal linux-2.6.33/kernel/compat.c linux-2.6.33-vs2.3.0.36.30.1/kernel/compat.c
15452 --- linux-2.6.33/kernel/compat.c        2009-09-10 15:26:27.000000000 +0200
15453 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/compat.c        2010-02-25 12:02:16.000000000 +0100
15454 @@ -902,7 +902,7 @@ asmlinkage long compat_sys_time(compat_t
15455         compat_time_t i;
15456         struct timeval tv;
15457  
15458 -       do_gettimeofday(&tv);
15459 +       vx_gettimeofday(&tv);
15460         i = tv.tv_sec;
15461  
15462         if (tloc) {
15463 @@ -927,7 +927,7 @@ asmlinkage long compat_sys_stime(compat_
15464         if (err)
15465                 return err;
15466  
15467 -       do_settimeofday(&tv);
15468 +       vx_settimeofday(&tv);
15469         return 0;
15470  }
15471  
15472 diff -NurpP --minimal linux-2.6.33/kernel/exit.c linux-2.6.33-vs2.3.0.36.30.1/kernel/exit.c
15473 --- linux-2.6.33/kernel/exit.c  2010-02-25 11:52:09.000000000 +0100
15474 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/exit.c  2010-02-25 12:02:16.000000000 +0100
15475 @@ -48,6 +48,10 @@
15476  #include <linux/fs_struct.h>
15477  #include <linux/init_task.h>
15478  #include <linux/perf_event.h>
15479 +#include <linux/vs_limit.h>
15480 +#include <linux/vs_context.h>
15481 +#include <linux/vs_network.h>
15482 +#include <linux/vs_pid.h>
15483  #include <trace/events/sched.h>
15484  #include <linux/hw_breakpoint.h>
15485  
15486 @@ -489,9 +493,11 @@ static void close_files(struct files_str
15487                                         filp_close(file, files);
15488                                         cond_resched();
15489                                 }
15490 +                               vx_openfd_dec(i);
15491                         }
15492                         i++;
15493                         set >>= 1;
15494 +                       cond_resched();
15495                 }
15496         }
15497  }
15498 @@ -1019,11 +1025,16 @@ NORET_TYPE void do_exit(long code)
15499  
15500         validate_creds_for_do_exit(tsk);
15501  
15502 +       /* needs to stay after exit_notify() */
15503 +       exit_vx_info(tsk, code);
15504 +       exit_nx_info(tsk);
15505 +
15506         preempt_disable();
15507         exit_rcu();
15508         /* causes final put_task_struct in finish_task_switch(). */
15509         tsk->state = TASK_DEAD;
15510         schedule();
15511 +       printk("bad task: %p [%lx]\n", current, current->state);
15512         BUG();
15513         /* Avoid "noreturn function does return".  */
15514         for (;;)
15515 diff -NurpP --minimal linux-2.6.33/kernel/fork.c linux-2.6.33-vs2.3.0.36.30.1/kernel/fork.c
15516 --- linux-2.6.33/kernel/fork.c  2010-02-25 11:52:09.000000000 +0100
15517 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/fork.c  2010-02-25 12:23:31.000000000 +0100
15518 @@ -65,6 +65,10 @@
15519  #include <linux/perf_event.h>
15520  #include <linux/posix-timers.h>
15521  #include <linux/user-return-notifier.h>
15522 +#include <linux/vs_context.h>
15523 +#include <linux/vs_network.h>
15524 +#include <linux/vs_limit.h>
15525 +#include <linux/vs_memory.h>
15526  
15527  #include <asm/pgtable.h>
15528  #include <asm/pgalloc.h>
15529 @@ -152,6 +156,8 @@ void free_task(struct task_struct *tsk)
15530         account_kernel_stack(tsk->stack, -1);
15531         free_thread_info(tsk->stack);
15532         rt_mutex_debug_task_free(tsk);
15533 +       clr_vx_info(&tsk->vx_info);
15534 +       clr_nx_info(&tsk->nx_info);
15535         ftrace_graph_exit_task(tsk);
15536         free_task_struct(tsk);
15537  }
15538 @@ -298,6 +304,8 @@ static int dup_mmap(struct mm_struct *mm
15539         mm->free_area_cache = oldmm->mmap_base;
15540         mm->cached_hole_size = ~0UL;
15541         mm->map_count = 0;
15542 +       __set_mm_counter(mm, file_rss, 0);
15543 +       __set_mm_counter(mm, anon_rss, 0);
15544         cpumask_clear(mm_cpumask(mm));
15545         mm->mm_rb = RB_ROOT;
15546         rb_link = &mm->mm_rb.rb_node;
15547 @@ -312,7 +320,7 @@ static int dup_mmap(struct mm_struct *mm
15548  
15549                 if (mpnt->vm_flags & VM_DONTCOPY) {
15550                         long pages = vma_pages(mpnt);
15551 -                       mm->total_vm -= pages;
15552 +                       vx_vmpages_sub(mm, pages);
15553                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15554                                                                 -pages);
15555                         continue;
15556 @@ -454,8 +462,8 @@ static struct mm_struct * mm_init(struct
15557                 (current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
15558         mm->core_state = NULL;
15559         mm->nr_ptes = 0;
15560 -       set_mm_counter(mm, file_rss, 0);
15561 -       set_mm_counter(mm, anon_rss, 0);
15562 +       __set_mm_counter(mm, file_rss, 0);
15563 +       __set_mm_counter(mm, anon_rss, 0);
15564         spin_lock_init(&mm->page_table_lock);
15565         mm->free_area_cache = TASK_UNMAPPED_BASE;
15566         mm->cached_hole_size = ~0UL;
15567 @@ -465,6 +473,7 @@ static struct mm_struct * mm_init(struct
15568         if (likely(!mm_alloc_pgd(mm))) {
15569                 mm->def_flags = 0;
15570                 mmu_notifier_mm_init(mm);
15571 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15572                 return mm;
15573         }
15574  
15575 @@ -498,6 +507,7 @@ void __mmdrop(struct mm_struct *mm)
15576         mm_free_pgd(mm);
15577         destroy_context(mm);
15578         mmu_notifier_mm_destroy(mm);
15579 +       clr_vx_info(&mm->mm_vx_info);
15580         free_mm(mm);
15581  }
15582  EXPORT_SYMBOL_GPL(__mmdrop);
15583 @@ -633,6 +643,7 @@ struct mm_struct *dup_mm(struct task_str
15584                 goto fail_nomem;
15585  
15586         memcpy(mm, oldmm, sizeof(*mm));
15587 +       mm->mm_vx_info = NULL;
15588  
15589         /* Initializing for Swap token stuff */
15590         mm->token_priority = 0;
15591 @@ -671,6 +682,7 @@ fail_nocontext:
15592          * If init_new_context() failed, we cannot use mmput() to free the mm
15593          * because it calls destroy_context()
15594          */
15595 +       clr_vx_info(&mm->mm_vx_info);
15596         mm_free_pgd(mm);
15597         free_mm(mm);
15598         return NULL;
15599 @@ -985,6 +997,8 @@ static struct task_struct *copy_process(
15600         int retval;
15601         struct task_struct *p;
15602         int cgroup_callbacks_done = 0;
15603 +       struct vx_info *vxi;
15604 +       struct nx_info *nxi;
15605  
15606         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15607                 return ERR_PTR(-EINVAL);
15608 @@ -1031,12 +1045,28 @@ static struct task_struct *copy_process(
15609         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15610         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15611  #endif
15612 +       init_vx_info(&p->vx_info, current_vx_info());
15613 +       init_nx_info(&p->nx_info, current_nx_info());
15614 +
15615 +       /* check vserver memory */
15616 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15617 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15618 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15619 +               else
15620 +                       goto bad_fork_free;
15621 +       }
15622 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15623 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15624 +                       goto bad_fork_cleanup_vm;
15625 +       }
15626         retval = -EAGAIN;
15627 +       if (!vx_nproc_avail(1))
15628 +               goto bad_fork_cleanup_vm;
15629         if (atomic_read(&p->real_cred->user->processes) >=
15630                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15631                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15632                     p->real_cred->user != INIT_USER)
15633 -                       goto bad_fork_free;
15634 +                       goto bad_fork_cleanup_vm;
15635         }
15636  
15637         retval = copy_creds(p, clone_flags);
15638 @@ -1297,6 +1327,18 @@ static struct task_struct *copy_process(
15639  
15640         total_forks++;
15641         spin_unlock(&current->sighand->siglock);
15642 +
15643 +       /* p is copy of current */
15644 +       vxi = p->vx_info;
15645 +       if (vxi) {
15646 +               claim_vx_info(vxi, p);
15647 +               atomic_inc(&vxi->cvirt.nr_threads);
15648 +               atomic_inc(&vxi->cvirt.total_forks);
15649 +               vx_nproc_inc(p);
15650 +       }
15651 +       nxi = p->nx_info;
15652 +       if (nxi)
15653 +               claim_nx_info(nxi, p);
15654         write_unlock_irq(&tasklist_lock);
15655         proc_fork_connector(p);
15656         cgroup_post_fork(p);
15657 @@ -1339,6 +1381,9 @@ bad_fork_cleanup_cgroup:
15658  bad_fork_cleanup_count:
15659         atomic_dec(&p->cred->user->processes);
15660         exit_creds(p);
15661 +bad_fork_cleanup_vm:
15662 +       if (p->mm && !(clone_flags & CLONE_VM))
15663 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15664  bad_fork_free:
15665         free_task(p);
15666  fork_out:
15667 diff -NurpP --minimal linux-2.6.33/kernel/kthread.c linux-2.6.33-vs2.3.0.36.30.1/kernel/kthread.c
15668 --- linux-2.6.33/kernel/kthread.c       2010-02-25 11:52:09.000000000 +0100
15669 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/kthread.c       2010-02-25 12:02:16.000000000 +0100
15670 @@ -14,6 +14,7 @@
15671  #include <linux/file.h>
15672  #include <linux/module.h>
15673  #include <linux/mutex.h>
15674 +#include <linux/vs_pid.h>
15675  #include <trace/events/sched.h>
15676  
15677  static DEFINE_SPINLOCK(kthread_create_lock);
15678 diff -NurpP --minimal linux-2.6.33/kernel/Makefile linux-2.6.33-vs2.3.0.36.30.1/kernel/Makefile
15679 --- linux-2.6.33/kernel/Makefile        2010-02-25 11:52:09.000000000 +0100
15680 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/Makefile        2010-02-25 12:02:16.000000000 +0100
15681 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
15682  CFLAGS_REMOVE_perf_event.o = -pg
15683  endif
15684  
15685 +obj-y += vserver/
15686  obj-$(CONFIG_FREEZER) += freezer.o
15687  obj-$(CONFIG_PROFILING) += profile.o
15688  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15689 diff -NurpP --minimal linux-2.6.33/kernel/nsproxy.c linux-2.6.33-vs2.3.0.36.30.1/kernel/nsproxy.c
15690 --- linux-2.6.33/kernel/nsproxy.c       2009-09-10 15:26:28.000000000 +0200
15691 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/nsproxy.c       2010-02-25 12:02:16.000000000 +0100
15692 @@ -19,6 +19,8 @@
15693  #include <linux/mnt_namespace.h>
15694  #include <linux/utsname.h>
15695  #include <linux/pid_namespace.h>
15696 +#include <linux/vserver/global.h>
15697 +#include <linux/vserver/debug.h>
15698  #include <net/net_namespace.h>
15699  #include <linux/ipc_namespace.h>
15700  
15701 @@ -31,8 +33,11 @@ static inline struct nsproxy *create_nsp
15702         struct nsproxy *nsproxy;
15703  
15704         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15705 -       if (nsproxy)
15706 +       if (nsproxy) {
15707                 atomic_set(&nsproxy->count, 1);
15708 +               atomic_inc(&vs_global_nsproxy);
15709 +       }
15710 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15711         return nsproxy;
15712  }
15713  
15714 @@ -41,41 +46,52 @@ static inline struct nsproxy *create_nsp
15715   * Return the newly created nsproxy.  Do not attach this to the task,
15716   * leave it to the caller to do proper locking and attach it to task.
15717   */
15718 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15719 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15720 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15721 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15722  {
15723         struct nsproxy *new_nsp;
15724         int err;
15725  
15726 +       vxdprintk(VXD_CBIT(space, 4),
15727 +               "unshare_namespaces(0x%08lx,%p,%p)",
15728 +               flags, orig, new_fs);
15729 +
15730         new_nsp = create_nsproxy();
15731         if (!new_nsp)
15732                 return ERR_PTR(-ENOMEM);
15733  
15734 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15735 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15736         if (IS_ERR(new_nsp->mnt_ns)) {
15737                 err = PTR_ERR(new_nsp->mnt_ns);
15738                 goto out_ns;
15739         }
15740  
15741 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15742 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15743         if (IS_ERR(new_nsp->uts_ns)) {
15744                 err = PTR_ERR(new_nsp->uts_ns);
15745                 goto out_uts;
15746         }
15747  
15748 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15749 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15750         if (IS_ERR(new_nsp->ipc_ns)) {
15751                 err = PTR_ERR(new_nsp->ipc_ns);
15752                 goto out_ipc;
15753         }
15754  
15755 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15756 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15757         if (IS_ERR(new_nsp->pid_ns)) {
15758                 err = PTR_ERR(new_nsp->pid_ns);
15759                 goto out_pid;
15760         }
15761  
15762 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15763 +       /* disabled now?
15764 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15765 +       if (IS_ERR(new_nsp->user_ns)) {
15766 +               err = PTR_ERR(new_nsp->user_ns);
15767 +               goto out_user;
15768 +       } */
15769 +
15770 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15771         if (IS_ERR(new_nsp->net_ns)) {
15772                 err = PTR_ERR(new_nsp->net_ns);
15773                 goto out_net;
15774 @@ -100,6 +116,38 @@ out_ns:
15775         return ERR_PTR(err);
15776  }
15777  
15778 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15779 +                       struct fs_struct *new_fs)
15780 +{
15781 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15782 +}
15783 +
15784 +/*
15785 + * copies the nsproxy, setting refcount to 1, and grabbing a
15786 + * reference to all contained namespaces.
15787 + */
15788 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15789 +{
15790 +       struct nsproxy *ns = create_nsproxy();
15791 +
15792 +       if (ns) {
15793 +               memcpy(ns, orig, sizeof(struct nsproxy));
15794 +               atomic_set(&ns->count, 1);
15795 +
15796 +               if (ns->mnt_ns)
15797 +                       get_mnt_ns(ns->mnt_ns);
15798 +               if (ns->uts_ns)
15799 +                       get_uts_ns(ns->uts_ns);
15800 +               if (ns->ipc_ns)
15801 +                       get_ipc_ns(ns->ipc_ns);
15802 +               if (ns->pid_ns)
15803 +                       get_pid_ns(ns->pid_ns);
15804 +               if (ns->net_ns)
15805 +                       get_net(ns->net_ns);
15806 +       }
15807 +       return ns;
15808 +}
15809 +
15810  /*
15811   * called from clone.  This now handles copy for nsproxy and all
15812   * namespaces therein.
15813 @@ -107,9 +155,12 @@ out_ns:
15814  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15815  {
15816         struct nsproxy *old_ns = tsk->nsproxy;
15817 -       struct nsproxy *new_ns;
15818 +       struct nsproxy *new_ns = NULL;
15819         int err = 0;
15820  
15821 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15822 +               flags, tsk, old_ns);
15823 +
15824         if (!old_ns)
15825                 return 0;
15826  
15827 @@ -119,7 +170,7 @@ int copy_namespaces(unsigned long flags,
15828                                 CLONE_NEWPID | CLONE_NEWNET)))
15829                 return 0;
15830  
15831 -       if (!capable(CAP_SYS_ADMIN)) {
15832 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15833                 err = -EPERM;
15834                 goto out;
15835         }
15836 @@ -146,6 +197,9 @@ int copy_namespaces(unsigned long flags,
15837  
15838  out:
15839         put_nsproxy(old_ns);
15840 +       vxdprintk(VXD_CBIT(space, 3),
15841 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15842 +               flags, tsk, old_ns, err, new_ns);
15843         return err;
15844  }
15845  
15846 @@ -159,7 +213,9 @@ void free_nsproxy(struct nsproxy *ns)
15847                 put_ipc_ns(ns->ipc_ns);
15848         if (ns->pid_ns)
15849                 put_pid_ns(ns->pid_ns);
15850 -       put_net(ns->net_ns);
15851 +       if (ns->net_ns)
15852 +               put_net(ns->net_ns);
15853 +       atomic_dec(&vs_global_nsproxy);
15854         kmem_cache_free(nsproxy_cachep, ns);
15855  }
15856  
15857 @@ -172,11 +228,15 @@ int unshare_nsproxy_namespaces(unsigned 
15858  {
15859         int err = 0;
15860  
15861 +       vxdprintk(VXD_CBIT(space, 4),
15862 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15863 +               unshare_flags, current->nsproxy);
15864 +
15865         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15866                                CLONE_NEWNET)))
15867                 return 0;
15868  
15869 -       if (!capable(CAP_SYS_ADMIN))
15870 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15871                 return -EPERM;
15872  
15873         *new_nsp = create_new_namespaces(unshare_flags, current,
15874 diff -NurpP --minimal linux-2.6.33/kernel/pid.c linux-2.6.33-vs2.3.0.36.30.1/kernel/pid.c
15875 --- linux-2.6.33/kernel/pid.c   2010-02-25 11:52:09.000000000 +0100
15876 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/pid.c   2010-02-25 12:02:16.000000000 +0100
15877 @@ -36,6 +36,7 @@
15878  #include <linux/pid_namespace.h>
15879  #include <linux/init_task.h>
15880  #include <linux/syscalls.h>
15881 +#include <linux/vs_pid.h>
15882  
15883  #define pid_hashfn(nr, ns)     \
15884         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15885 @@ -305,7 +306,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15886  
15887  struct pid *find_vpid(int nr)
15888  {
15889 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15890 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15891  }
15892  EXPORT_SYMBOL_GPL(find_vpid);
15893  
15894 @@ -365,6 +366,9 @@ void transfer_pid(struct task_struct *ol
15895  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15896  {
15897         struct task_struct *result = NULL;
15898 +
15899 +       if (type == PIDTYPE_REALPID)
15900 +               type = PIDTYPE_PID;
15901         if (pid) {
15902                 struct hlist_node *first;
15903                 first = rcu_dereference(pid->tasks[type].first);
15904 @@ -380,7 +384,7 @@ EXPORT_SYMBOL(pid_task);
15905   */
15906  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15907  {
15908 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15909 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15910  }
15911  
15912  struct task_struct *find_task_by_vpid(pid_t vnr)
15913 @@ -422,7 +426,7 @@ struct pid *find_get_pid(pid_t nr)
15914  }
15915  EXPORT_SYMBOL_GPL(find_get_pid);
15916  
15917 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15918 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15919  {
15920         struct upid *upid;
15921         pid_t nr = 0;
15922 @@ -435,6 +439,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15923         return nr;
15924  }
15925  
15926 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15927 +{
15928 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15929 +}
15930 +
15931  pid_t pid_vnr(struct pid *pid)
15932  {
15933         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15934 diff -NurpP --minimal linux-2.6.33/kernel/pid_namespace.c linux-2.6.33-vs2.3.0.36.30.1/kernel/pid_namespace.c
15935 --- linux-2.6.33/kernel/pid_namespace.c 2009-12-03 20:02:58.000000000 +0100
15936 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/pid_namespace.c 2010-02-25 12:02:16.000000000 +0100
15937 @@ -13,6 +13,7 @@
15938  #include <linux/syscalls.h>
15939  #include <linux/err.h>
15940  #include <linux/acct.h>
15941 +#include <linux/vserver/global.h>
15942  
15943  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15944  
15945 @@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_
15946                 goto out_free_map;
15947  
15948         kref_init(&ns->kref);
15949 +       atomic_inc(&vs_global_pid_ns);
15950         ns->level = level;
15951         ns->parent = get_pid_ns(parent_pid_ns);
15952  
15953 @@ -111,6 +113,7 @@ static void destroy_pid_namespace(struct
15954  
15955         for (i = 0; i < PIDMAP_ENTRIES; i++)
15956                 kfree(ns->pidmap[i].page);
15957 +       atomic_dec(&vs_global_pid_ns);
15958         kmem_cache_free(pid_ns_cachep, ns);
15959  }
15960  
15961 diff -NurpP --minimal linux-2.6.33/kernel/posix-timers.c linux-2.6.33-vs2.3.0.36.30.1/kernel/posix-timers.c
15962 --- linux-2.6.33/kernel/posix-timers.c  2009-12-03 20:02:58.000000000 +0100
15963 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/posix-timers.c  2010-02-25 12:02:16.000000000 +0100
15964 @@ -46,6 +46,7 @@
15965  #include <linux/wait.h>
15966  #include <linux/workqueue.h>
15967  #include <linux/module.h>
15968 +#include <linux/vs_context.h>
15969  
15970  /*
15971   * Management arrays for POSIX timers.  Timers are kept in slab memory
15972 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15973  {
15974         struct task_struct *task;
15975         int shared, ret = -1;
15976 +
15977         /*
15978          * FIXME: if ->sigq is queued we can race with
15979          * dequeue_signal()->do_schedule_next_timer().
15980 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15981         rcu_read_lock();
15982         task = pid_task(timr->it_pid, PIDTYPE_PID);
15983         if (task) {
15984 +               struct vx_info_save vxis;
15985 +               struct vx_info *vxi;
15986 +
15987 +               vxi = get_vx_info(task->vx_info);
15988 +               enter_vx_info(vxi, &vxis);
15989                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15990                 ret = send_sigqueue(timr->sigq, task, shared);
15991 +               leave_vx_info(&vxis);
15992 +               put_vx_info(vxi);
15993         }
15994         rcu_read_unlock();
15995 +
15996         /* If we failed to send the signal the timer stops. */
15997         return ret > 0;
15998  }
15999 diff -NurpP --minimal linux-2.6.33/kernel/printk.c linux-2.6.33-vs2.3.0.36.30.1/kernel/printk.c
16000 --- linux-2.6.33/kernel/printk.c        2010-02-25 11:52:09.000000000 +0100
16001 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/printk.c        2010-02-25 13:11:15.000000000 +0100
16002 @@ -35,6 +35,7 @@
16003  #include <linux/kexec.h>
16004  #include <linux/ratelimit.h>
16005  #include <linux/kmsg_dump.h>
16006 +#include <linux/vs_cvirt.h>
16007  
16008  #include <asm/uaccess.h>
16009  
16010 @@ -278,18 +279,13 @@ int do_syslog(int type, char __user *buf
16011         unsigned i, j, limit, count;
16012         int do_clear = 0;
16013         char c;
16014 -       int error = 0;
16015 +       int error;
16016  
16017         error = security_syslog(type);
16018         if (error)
16019                 return error;
16020  
16021 -       switch (type) {
16022 -       case 0:         /* Close log */
16023 -               break;
16024 -       case 1:         /* Open log */
16025 -               break;
16026 -       case 2:         /* Read from log */
16027 +       if ((type >= 2) && (type <= 4)) {
16028                 error = -EINVAL;
16029                 if (!buf || len < 0)
16030                         goto out;
16031 @@ -300,6 +296,16 @@ int do_syslog(int type, char __user *buf
16032                         error = -EFAULT;
16033                         goto out;
16034                 }
16035 +       }
16036 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16037 +               return vx_do_syslog(type, buf, len);
16038 +
16039 +       switch (type) {
16040 +       case 0:         /* Close log */
16041 +               break;
16042 +       case 1:         /* Open log */
16043 +               break;
16044 +       case 2:         /* Read from log */
16045                 error = wait_event_interruptible(log_wait,
16046                                                         (log_start - log_end));
16047                 if (error)
16048 @@ -324,16 +330,6 @@ int do_syslog(int type, char __user *buf
16049                 do_clear = 1;
16050                 /* FALL THRU */
16051         case 3:         /* Read last kernel messages */
16052 -               error = -EINVAL;
16053 -               if (!buf || len < 0)
16054 -                       goto out;
16055 -               error = 0;
16056 -               if (!len)
16057 -                       goto out;
16058 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
16059 -                       error = -EFAULT;
16060 -                       goto out;
16061 -               }
16062                 count = len;
16063                 if (count > log_buf_len)
16064                         count = log_buf_len;
16065 diff -NurpP --minimal linux-2.6.33/kernel/ptrace.c linux-2.6.33-vs2.3.0.36.30.1/kernel/ptrace.c
16066 --- linux-2.6.33/kernel/ptrace.c        2009-12-03 20:02:58.000000000 +0100
16067 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/ptrace.c        2010-02-25 12:02:16.000000000 +0100
16068 @@ -22,6 +22,7 @@
16069  #include <linux/pid_namespace.h>
16070  #include <linux/syscalls.h>
16071  #include <linux/uaccess.h>
16072 +#include <linux/vs_context.h>
16073  
16074  
16075  /*
16076 @@ -151,6 +152,11 @@ int __ptrace_may_access(struct task_stru
16077                 dumpable = get_dumpable(task->mm);
16078         if (!dumpable && !capable(CAP_SYS_PTRACE))
16079                 return -EPERM;
16080 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
16081 +               return -EPERM;
16082 +       if (!vx_check(task->xid, VS_IDENT) &&
16083 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
16084 +               return -EACCES;
16085  
16086         return security_ptrace_access_check(task, mode);
16087  }
16088 @@ -621,6 +627,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
16089                 goto out;
16090         }
16091  
16092 +       ret = -EPERM;
16093 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
16094 +               goto out_put_task_struct;
16095 +
16096         if (request == PTRACE_ATTACH) {
16097                 ret = ptrace_attach(child);
16098                 /*
16099 diff -NurpP --minimal linux-2.6.33/kernel/sched.c linux-2.6.33-vs2.3.0.36.30.1/kernel/sched.c
16100 --- linux-2.6.33/kernel/sched.c 2010-02-25 11:52:09.000000000 +0100
16101 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/sched.c 2010-02-25 16:24:45.000000000 +0100
16102 @@ -71,6 +71,8 @@
16103  #include <linux/debugfs.h>
16104  #include <linux/ctype.h>
16105  #include <linux/ftrace.h>
16106 +#include <linux/vs_sched.h>
16107 +#include <linux/vs_cvirt.h>
16108  
16109  #include <asm/tlb.h>
16110  #include <asm/irq_regs.h>
16111 @@ -139,50 +141,59 @@ struct rt_prio_array {
16112         struct list_head queue[MAX_RT_PRIO];
16113  };
16114  
16115 -struct rt_bandwidth {
16116 +struct sched_bandwidth {
16117         /* nests inside the rq lock: */
16118 -       raw_spinlock_t          rt_runtime_lock;
16119 -       ktime_t                 rt_period;
16120 -       u64                     rt_runtime;
16121 -       struct hrtimer          rt_period_timer;
16122 +       raw_spinlock_t          runtime_lock;
16123 +       ktime_t                 period;
16124 +       u64                     runtime;
16125 +       struct hrtimer          period_timer;
16126  };
16127  
16128 -static struct rt_bandwidth def_rt_bandwidth;
16129 +static struct sched_bandwidth def_rt_bandwidth;
16130  
16131 -static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun);
16132 +static int do_sched_rt_period_timer(struct sched_bandwidth *sched_b, int overrun);
16133 +static int do_sched_cfs_period_timer(struct sched_bandwidth *sched_b, int overrun);
16134  
16135 -static enum hrtimer_restart sched_rt_period_timer(struct hrtimer *timer)
16136 +static enum hrtimer_restart sched_period_timer(struct hrtimer *timer, int rt)
16137  {
16138 -       struct rt_bandwidth *rt_b =
16139 -               container_of(timer, struct rt_bandwidth, rt_period_timer);
16140 +       struct sched_bandwidth *sched_b =
16141 +               container_of(timer, struct sched_bandwidth, period_timer);
16142         ktime_t now;
16143         int overrun;
16144         int idle = 0;
16145  
16146         for (;;) {
16147                 now = hrtimer_cb_get_time(timer);
16148 -               overrun = hrtimer_forward(timer, now, rt_b->rt_period);
16149 +               overrun = hrtimer_forward(timer, now, sched_b->period);
16150  
16151                 if (!overrun)
16152                         break;
16153  
16154 -               idle = do_sched_rt_period_timer(rt_b, overrun);
16155 +               if (rt)
16156 +                       idle = do_sched_rt_period_timer(sched_b, overrun);
16157 +               else
16158 +                       idle = do_sched_cfs_period_timer(sched_b, overrun);
16159         }
16160  
16161         return idle ? HRTIMER_NORESTART : HRTIMER_RESTART;
16162  }
16163  
16164 -static
16165 -void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime)
16166 +static enum hrtimer_restart sched_rt_period_timer(struct hrtimer *timer)
16167  {
16168 -       rt_b->rt_period = ns_to_ktime(period);
16169 -       rt_b->rt_runtime = runtime;
16170 +       return sched_period_timer(timer, 1);
16171 +}
16172  
16173 -       raw_spin_lock_init(&rt_b->rt_runtime_lock);
16174 +static void init_sched_bandwidth(struct sched_bandwidth *sched_b, u64 period,
16175 +       u64 runtime, enum hrtimer_restart (*period_timer)(struct hrtimer *))
16176 +{
16177 +       sched_b->period = ns_to_ktime(period);
16178 +       sched_b->runtime = runtime;
16179  
16180 -       hrtimer_init(&rt_b->rt_period_timer,
16181 +       raw_spin_lock_init(&sched_b->runtime_lock);
16182 +
16183 +       hrtimer_init(&sched_b->period_timer,
16184                         CLOCK_MONOTONIC, HRTIMER_MODE_REL);
16185 -       rt_b->rt_period_timer.function = sched_rt_period_timer;
16186 +       sched_b->period_timer.function = *period_timer;
16187  }
16188  
16189  static inline int rt_bandwidth_enabled(void)
16190 @@ -190,40 +201,43 @@ static inline int rt_bandwidth_enabled(v
16191         return sysctl_sched_rt_runtime >= 0;
16192  }
16193  
16194 -static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
16195 +static void start_sched_bandwidth(struct sched_bandwidth *sched_b, int rt)
16196  {
16197         ktime_t now;
16198  
16199 -       if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
16200 +       if (rt && !rt_bandwidth_enabled())
16201                 return;
16202  
16203 -       if (hrtimer_active(&rt_b->rt_period_timer))
16204 +       if (sched_b->runtime == RUNTIME_INF)
16205                 return;
16206  
16207 -       raw_spin_lock(&rt_b->rt_runtime_lock);
16208 +       if (hrtimer_active(&sched_b->period_timer))
16209 +               return;
16210 +
16211 +       raw_spin_lock(&sched_b->runtime_lock);
16212         for (;;) {
16213                 unsigned long delta;
16214                 ktime_t soft, hard;
16215  
16216 -               if (hrtimer_active(&rt_b->rt_period_timer))
16217 +               if (hrtimer_active(&sched_b->period_timer))
16218                         break;
16219  
16220 -               now = hrtimer_cb_get_time(&rt_b->rt_period_timer);
16221 -               hrtimer_forward(&rt_b->rt_period_timer, now, rt_b->rt_period);
16222 +               now = hrtimer_cb_get_time(&sched_b->period_timer);
16223 +               hrtimer_forward(&sched_b->period_timer, now, sched_b->period);
16224  
16225 -               soft = hrtimer_get_softexpires(&rt_b->rt_period_timer);
16226 -               hard = hrtimer_get_expires(&rt_b->rt_period_timer);
16227 +               soft = hrtimer_get_softexpires(&sched_b->period_timer);
16228 +               hard = hrtimer_get_expires(&sched_b->period_timer);
16229                 delta = ktime_to_ns(ktime_sub(hard, soft));
16230 -               __hrtimer_start_range_ns(&rt_b->rt_period_timer, soft, delta,
16231 +               __hrtimer_start_range_ns(&sched_b->period_timer, soft, delta,
16232                                 HRTIMER_MODE_ABS_PINNED, 0);
16233         }
16234 -       raw_spin_unlock(&rt_b->rt_runtime_lock);
16235 +       raw_spin_unlock(&sched_b->runtime_lock);
16236  }
16237  
16238 -#ifdef CONFIG_RT_GROUP_SCHED
16239 -static void destroy_rt_bandwidth(struct rt_bandwidth *rt_b)
16240 +#if defined CONFIG_RT_GROUP_SCHED || defined CONFIG_FAIR_GROUP_SCHED
16241 +static void destroy_sched_bandwidth(struct sched_bandwidth *sched_b)
16242  {
16243 -       hrtimer_cancel(&rt_b->rt_period_timer);
16244 +       hrtimer_cancel(&sched_b->period_timer);
16245  }
16246  #endif
16247  
16248 @@ -257,13 +271,14 @@ struct task_group {
16249         /* runqueue "owned" by this group on each cpu */
16250         struct cfs_rq **cfs_rq;
16251         unsigned long shares;
16252 +       struct sched_bandwidth cfs_bandwidth;
16253  #endif
16254  
16255  #ifdef CONFIG_RT_GROUP_SCHED
16256         struct sched_rt_entity **rt_se;
16257         struct rt_rq **rt_rq;
16258  
16259 -       struct rt_bandwidth rt_bandwidth;
16260 +       struct sched_bandwidth rt_bandwidth;
16261  #endif
16262  
16263         struct rcu_head rcu;
16264 @@ -385,6 +400,14 @@ static inline struct task_group *task_gr
16265  
16266  #endif /* CONFIG_GROUP_SCHED */
16267  
16268 +struct rq_bandwidth {
16269 +       int throttled;
16270 +       u64 time;
16271 +       u64 runtime;
16272 +       /* Nests inside the rq lock: */
16273 +       raw_spinlock_t runtime_lock;
16274 +};
16275 +
16276  /* CFS-related fields in a runqueue */
16277  struct cfs_rq {
16278         struct load_weight load;
16279 @@ -446,6 +469,7 @@ struct cfs_rq {
16280         unsigned long rq_weight;
16281  #endif
16282  #endif
16283 +       struct rq_bandwidth rq_bandwidth;
16284  };
16285  
16286  /* Real-Time classes' related field in a runqueue: */
16287 @@ -466,11 +490,7 @@ struct rt_rq {
16288         int overloaded;
16289         struct plist_head pushable_tasks;
16290  #endif
16291 -       int rt_throttled;
16292 -       u64 rt_time;
16293 -       u64 rt_runtime;
16294 -       /* Nests inside the rq lock: */
16295 -       raw_spinlock_t rt_runtime_lock;
16296 +       struct rq_bandwidth rq_bandwidth;
16297  
16298  #ifdef CONFIG_RT_GROUP_SCHED
16299         unsigned long rt_nr_boosted;
16300 @@ -1608,6 +1628,7 @@ static void update_group_shares_cpu(stru
16301         }
16302  }
16303  
16304 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq);
16305  /*
16306   * Re-compute the task group their per cpu shares over the given domain.
16307   * This needs to be done in a bottom-up fashion because the rq weight of a
16308 @@ -1636,8 +1657,10 @@ static int tg_shares_up(struct task_grou
16309                  * If there are currently no tasks on the cpu pretend there
16310                  * is one of average load so that when a new task gets to
16311                  * run here it will not get delayed by group starvation.
16312 +                * Also if the group is throttled on this cpu, pretend that
16313 +                * it has no tasks.
16314                  */
16315 -               if (!weight)
16316 +               if (!weight || cfs_rq_throttled(tg->cfs_rq[i]))
16317                         weight = NICE_0_LOAD;
16318  
16319                 sum_weight += weight;
16320 @@ -1834,6 +1857,297 @@ static inline void __set_task_cpu(struct
16321  #endif
16322  }
16323  
16324 +
16325 +#if defined(CONFIG_RT_GROUP_SCHED) || defined(CONFIG_FAIR_GROUP_SCHED)
16326 +
16327 +#ifdef CONFIG_SMP
16328 +static inline const struct cpumask *sched_bw_period_mask(void)
16329 +{
16330 +       return cpu_rq(smp_processor_id())->rd->span;
16331 +}
16332 +#else /* !CONFIG_SMP */
16333 +static inline const struct cpumask *sched_bw_period_mask(void)
16334 +{
16335 +       return cpu_online_mask;
16336 +}
16337 +#endif /* CONFIG_SMP */
16338 +
16339 +#else
16340 +static inline const struct cpumask *sched_bw_period_mask(void)
16341 +{
16342 +       return cpu_online_mask;
16343 +}
16344 +
16345 +#endif
16346 +
16347 +static void init_rq_bandwidth(struct rq_bandwidth *rq_b, u64 runtime)
16348 +{
16349 +       rq_b->time = 0;
16350 +       rq_b->throttled = 0;
16351 +       rq_b->runtime = runtime;
16352 +       raw_spin_lock_init(&rq_b->runtime_lock);
16353 +}
16354 +
16355 +#ifdef CONFIG_RT_GROUP_SCHED
16356 +
16357 +static inline
16358 +struct rt_rq *sched_rt_period_rt_rq(struct sched_bandwidth *rt_b, int cpu)
16359 +{
16360 +       return container_of(rt_b, struct task_group, rt_bandwidth)->rt_rq[cpu];
16361 +}
16362 +
16363 +#else
16364 +
16365 +static inline
16366 +struct rt_rq *sched_rt_period_rt_rq(struct sched_bandwidth *rt_b, int cpu)
16367 +{
16368 +       return &cpu_rq(cpu)->rt;
16369 +}
16370 +
16371 +#endif
16372 +
16373 +#ifdef CONFIG_FAIR_GROUP_SCHED
16374 +static inline
16375 +struct cfs_rq *sched_cfs_period_cfs_rq(struct sched_bandwidth *cfs_b, int cpu)
16376 +{
16377 +       return container_of(cfs_b, struct task_group,
16378 +                       cfs_bandwidth)->cfs_rq[cpu];
16379 +}
16380 +
16381 +#else
16382 +
16383 +static inline
16384 +struct cfs_rq *sched_cfs_period_cfs_rq(struct sched_bandwidth *cfs_b, int cpu)
16385 +{
16386 +       return &cpu_rq(cpu)->cfs;
16387 +}
16388 +
16389 +#endif
16390 +
16391 +#ifdef CONFIG_SMP
16392 +
16393 +void __disable_runtime(struct rq *rq, struct sched_bandwidth *sched_b,
16394 +               struct rq_bandwidth *rq_b, int rt)
16395 +{
16396 +       struct root_domain *rd = rq->rd;
16397 +       s64 want;
16398 +       int i;
16399 +
16400 +       raw_spin_lock(&sched_b->runtime_lock);
16401 +       raw_spin_lock(&rq_b->runtime_lock);
16402 +
16403 +       /*
16404 +        * Either we're all inf and nobody needs to borrow, or we're
16405 +        * already disabled and thus have nothing to do, or we have
16406 +        * exactly the right amount of runtime to take out.
16407 +        */
16408 +       if (rq_b->runtime == RUNTIME_INF || rq_b->runtime == sched_b->runtime)
16409 +               goto balanced;
16410 +
16411 +       raw_spin_unlock(&rq_b->runtime_lock);
16412 +
16413 +       /*
16414 +        * Calculate the difference between what we started out with
16415 +        * and what we current have, that's the amount of runtime
16416 +        * we lend and now have to reclaim.
16417 +        */
16418 +       want = sched_b->runtime - rq_b->runtime;
16419 +
16420 +       /*
16421 +        * Greedy reclaim, take back as much as we can.
16422 +        */
16423 +       for_each_cpu(i, rd->span) {
16424 +               struct rq_bandwidth *iter;
16425 +               s64 diff;
16426 +
16427 +               if (rt)
16428 +                       iter = &(sched_rt_period_rt_rq(sched_b, i)->rq_bandwidth);
16429 +               else
16430 +                       iter = &(sched_cfs_period_cfs_rq(sched_b, i)->rq_bandwidth);
16431 +               /*
16432 +                * Can't reclaim from ourselves or disabled runqueues.
16433 +                */
16434 +               if (iter == rq_b || iter->runtime == RUNTIME_INF)
16435 +                       continue;
16436 +
16437 +               raw_spin_lock(&iter->runtime_lock);
16438 +               if (want > 0) {
16439 +                       diff = min_t(s64, iter->runtime, want);
16440 +                       iter->runtime -= diff;
16441 +                       want -= diff;
16442 +               } else {
16443 +                       iter->runtime -= want;
16444 +                       want -= want;
16445 +               }
16446 +               raw_spin_unlock(&iter->runtime_lock);
16447 +
16448 +               if (!want)
16449 +                       break;
16450 +       }
16451 +
16452 +       raw_spin_lock(&rq_b->runtime_lock);
16453 +       /*
16454 +        * We cannot be left wanting - that would mean some runtime
16455 +        * leaked out of the system.
16456 +        */
16457 +       BUG_ON(want);
16458 +
16459 +balanced:
16460 +       /*
16461 +        * Disable all the borrow logic by pretending we have inf
16462 +        * runtime - in which case borrowing doesn't make sense.
16463 +        */
16464 +       rq_b->runtime = RUNTIME_INF;
16465 +       raw_spin_unlock(&rq_b->runtime_lock);
16466 +       raw_spin_unlock(&sched_b->runtime_lock);
16467 +}
16468 +
16469 +void disable_runtime_rt(struct rq *rq);
16470 +void disable_runtime_cfs(struct rq *rq);
16471 +static void disable_runtime(struct rq *rq)
16472 +{
16473 +       unsigned long flags;
16474 +
16475 +       raw_spin_lock_irqsave(&rq->lock, flags);
16476 +       disable_runtime_rt(rq);
16477 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16478 +       disable_runtime_cfs(rq);
16479 +#endif
16480 +       raw_spin_unlock_irqrestore(&rq->lock, flags);
16481 +}
16482 +
16483 +void __enable_runtime(struct sched_bandwidth *sched_b,
16484 +               struct rq_bandwidth *rq_b)
16485 +{
16486 +       raw_spin_lock(&sched_b->runtime_lock);
16487 +       raw_spin_lock(&rq_b->runtime_lock);
16488 +       rq_b->runtime = sched_b->runtime;
16489 +       rq_b->time = 0;
16490 +       rq_b->throttled = 0;
16491 +       raw_spin_unlock(&rq_b->runtime_lock);
16492 +       raw_spin_unlock(&sched_b->runtime_lock);
16493 +}
16494 +
16495 +void enable_runtime_rt(struct rq *rq);
16496 +void enable_runtime_cfs(struct rq *rq);
16497 +static void enable_runtime(struct rq *rq)
16498 +{
16499 +       unsigned long flags;
16500 +
16501 +       raw_spin_lock_irqsave(&rq->lock, flags);
16502 +       enable_runtime_rt(rq);
16503 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16504 +       enable_runtime_cfs(rq);
16505 +#endif
16506 +       raw_spin_unlock_irqrestore(&rq->lock, flags);
16507 +}
16508 +
16509 +/*
16510 + * We ran out of runtime, see if we can borrow some from our neighbours.
16511 + */
16512 +static void do_balance_runtime(struct rq_bandwidth *rq_b,
16513 +               struct sched_bandwidth *sched_b, int rt)
16514 +{
16515 +       struct root_domain *rd = cpu_rq(smp_processor_id())->rd;
16516 +       int i, weight;
16517 +       u64 period;
16518 +
16519 +       weight = cpumask_weight(rd->span);
16520 +
16521 +       raw_spin_lock(&sched_b->runtime_lock);
16522 +       period = ktime_to_ns(sched_b->period);
16523 +       for_each_cpu(i, rd->span) {
16524 +               struct rq_bandwidth *iter;
16525 +               s64 diff;
16526 +
16527 +               if (rt)
16528 +                       iter = &(sched_rt_period_rt_rq(sched_b, i)->rq_bandwidth);
16529 +               else
16530 +                       iter = &(sched_cfs_period_cfs_rq(sched_b, i)->rq_bandwidth);
16531 +
16532 +               if (iter == rq_b)
16533 +                       continue;
16534 +
16535 +               raw_spin_lock(&iter->runtime_lock);
16536 +               /*
16537 +                * Either all rqs have inf runtime and there's nothing to steal
16538 +                * or __disable_runtime() below sets a specific rq to inf to
16539 +                * indicate its been disabled and disalow stealing.
16540 +                */
16541 +               if (iter->runtime == RUNTIME_INF)
16542 +                       goto next;
16543 +
16544 +               /*
16545 +                * From runqueues with spare time, take 1/n part of their
16546 +                * spare time, but no more than our period.
16547 +                */
16548 +               diff = iter->runtime - iter->time;
16549 +               if (diff > 0) {
16550 +                       diff = div_u64((u64)diff, weight);
16551 +                       if (rq_b->runtime + diff > period)
16552 +                               diff = period - rq_b->runtime;
16553 +                       iter->runtime -= diff;
16554 +                       rq_b->runtime += diff;
16555 +                       if (rq_b->runtime == period) {
16556 +                               raw_spin_unlock(&iter->runtime_lock);
16557 +                               break;
16558 +                       }
16559 +               }
16560 +next:
16561 +               raw_spin_unlock(&iter->runtime_lock);
16562 +       }
16563 +       raw_spin_unlock(&sched_b->runtime_lock);
16564 +}
16565 +
16566 +static void balance_runtime(struct rq_bandwidth *rq_b,
16567 +               struct sched_bandwidth *sched_b, int rt)
16568 +{
16569 +       if (rq_b->time > rq_b->runtime) {
16570 +               raw_spin_unlock(&rq_b->runtime_lock);
16571 +               do_balance_runtime(rq_b, sched_b, rt);
16572 +               raw_spin_lock(&rq_b->runtime_lock);
16573 +       }
16574 +}
16575 +#else /* !CONFIG_SMP */
16576 +static inline void balance_runtime(struct rq_bandwidth *rq_b,
16577 +               struct sched_bandwidth *sched_b, int rt)
16578 +{
16579 +       return;
16580 +}
16581 +#endif /* CONFIG_SMP */
16582 +
16583 +/*
16584 + * Runtime allowed for a cfs group before it is hard limited.
16585 + * default: Infinite which means no hard limiting.
16586 + */
16587 +u64 sched_cfs_runtime = RUNTIME_INF;
16588 +
16589 +/*
16590 + * period over which we hard limit the cfs group's bandwidth.
16591 + * default: 0.5s
16592 + */
16593 +u64 sched_cfs_period = 500000;
16594 +
16595 +static inline u64 global_cfs_period(void)
16596 +{
16597 +       return sched_cfs_period * NSEC_PER_USEC;
16598 +}
16599 +
16600 +static inline u64 global_cfs_runtime(void)
16601 +{
16602 +       return RUNTIME_INF;
16603 +}
16604 +
16605 +#ifdef CONFIG_FAIR_GROUP_SCHED
16606 +/*
16607 + * Refresh the runtimes of the throttled groups.
16608 + */
16609 +static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer)
16610 +{
16611 +       return sched_period_timer(timer, 0);
16612 +}
16613 +#endif
16614 +
16615  #include "sched_stats.h"
16616  #include "sched_idletask.c"
16617  #include "sched_fair.c"
16618 @@ -3009,9 +3323,17 @@ EXPORT_SYMBOL(avenrun);
16619   */
16620  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
16621  {
16622 -       loads[0] = (avenrun[0] + offset) << shift;
16623 -       loads[1] = (avenrun[1] + offset) << shift;
16624 -       loads[2] = (avenrun[2] + offset) << shift;
16625 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
16626 +               struct vx_info *vxi = current_vx_info();
16627 +
16628 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
16629 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
16630 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
16631 +       } else {
16632 +               loads[0] = (avenrun[0] + offset) << shift;
16633 +               loads[1] = (avenrun[1] + offset) << shift;
16634 +               loads[2] = (avenrun[2] + offset) << shift;
16635 +       }
16636  }
16637  
16638  static unsigned long
16639 @@ -5046,16 +5368,19 @@ void account_user_time(struct task_struc
16640                        cputime_t cputime_scaled)
16641  {
16642         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16643 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16644         cputime64_t tmp;
16645 +       int nice = (TASK_NICE(p) > 0);
16646  
16647         /* Add user time to process. */
16648         p->utime = cputime_add(p->utime, cputime);
16649         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
16650 +       vx_account_user(vxi, cputime, nice);
16651         account_group_user_time(p, cputime);
16652  
16653         /* Add user time to cpustat. */
16654         tmp = cputime_to_cputime64(cputime);
16655 -       if (TASK_NICE(p) > 0)
16656 +       if (nice)
16657                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16658         else
16659                 cpustat->user = cputime64_add(cpustat->user, tmp);
16660 @@ -5106,6 +5431,7 @@ void account_system_time(struct task_str
16661                          cputime_t cputime, cputime_t cputime_scaled)
16662  {
16663         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16664 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16665         cputime64_t tmp;
16666  
16667         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
16668 @@ -5116,6 +5442,7 @@ void account_system_time(struct task_str
16669         /* Add system time to process. */
16670         p->stime = cputime_add(p->stime, cputime);
16671         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
16672 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
16673         account_group_system_time(p, cputime);
16674  
16675         /* Add system time to cpustat. */
16676 @@ -6180,7 +6507,7 @@ SYSCALL_DEFINE1(nice, int, increment)
16677                 nice = 19;
16678  
16679         if (increment < 0 && !can_nice(current, nice))
16680 -               return -EPERM;
16681 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16682  
16683         retval = security_task_setnice(current, nice);
16684         if (retval)
16685 @@ -6358,7 +6685,7 @@ recheck:
16686                  * assigned.
16687                  */
16688                 if (rt_bandwidth_enabled() && rt_policy(policy) &&
16689 -                               task_group(p)->rt_bandwidth.rt_runtime == 0)
16690 +                               task_group(p)->rt_bandwidth.runtime == 0)
16691                         return -EPERM;
16692  #endif
16693  
16694 @@ -9401,11 +9728,7 @@ static void init_rt_rq(struct rt_rq *rt_
16695         rt_rq->overloaded = 0;
16696         plist_head_init_raw(&rt_rq->pushable_tasks, &rq->lock);
16697  #endif
16698 -
16699 -       rt_rq->rt_time = 0;
16700 -       rt_rq->rt_throttled = 0;
16701 -       rt_rq->rt_runtime = 0;
16702 -       raw_spin_lock_init(&rt_rq->rt_runtime_lock);
16703 +       init_rq_bandwidth(&rt_rq->rq_bandwidth, 0);
16704  
16705  #ifdef CONFIG_RT_GROUP_SCHED
16706         rt_rq->rt_nr_boosted = 0;
16707 @@ -9421,6 +9744,7 @@ static void init_tg_cfs_entry(struct tas
16708         struct rq *rq = cpu_rq(cpu);
16709         tg->cfs_rq[cpu] = cfs_rq;
16710         init_cfs_rq(cfs_rq, rq);
16711 +       init_rq_bandwidth(&cfs_rq->rq_bandwidth, tg->cfs_bandwidth.runtime);
16712         cfs_rq->tg = tg;
16713         if (add)
16714                 list_add(&cfs_rq->leaf_cfs_rq_list, &rq->leaf_cfs_rq_list);
16715 @@ -9453,7 +9777,7 @@ static void init_tg_rt_entry(struct task
16716         init_rt_rq(rt_rq, rq);
16717         rt_rq->tg = tg;
16718         rt_rq->rt_se = rt_se;
16719 -       rt_rq->rt_runtime = tg->rt_bandwidth.rt_runtime;
16720 +       rt_rq->rq_bandwidth.runtime = tg->rt_bandwidth.runtime;
16721         if (add)
16722                 list_add(&rt_rq->leaf_rt_rq_list, &rq->leaf_rt_rq_list);
16723  
16724 @@ -9534,18 +9858,24 @@ void __init sched_init(void)
16725         init_defrootdomain();
16726  #endif
16727  
16728 -       init_rt_bandwidth(&def_rt_bandwidth,
16729 -                       global_rt_period(), global_rt_runtime());
16730 +       init_sched_bandwidth(&def_rt_bandwidth, global_rt_period(),
16731 +                       global_rt_runtime(), &sched_rt_period_timer);
16732  
16733  #ifdef CONFIG_RT_GROUP_SCHED
16734 -       init_rt_bandwidth(&init_task_group.rt_bandwidth,
16735 -                       global_rt_period(), global_rt_runtime());
16736 +       init_sched_bandwidth(&init_task_group.rt_bandwidth, global_rt_period(),
16737 +                       global_rt_runtime(), &sched_rt_period_timer);
16738  #ifdef CONFIG_USER_SCHED
16739 -       init_rt_bandwidth(&root_task_group.rt_bandwidth,
16740 -                       global_rt_period(), RUNTIME_INF);
16741 +       init_sched_bandwidth(&root_task_group.rt_bandwidth, global_rt_period(),
16742 +                       RUNTIME_INF, &sched_rt_period_timer);
16743  #endif /* CONFIG_USER_SCHED */
16744  #endif /* CONFIG_RT_GROUP_SCHED */
16745  
16746 +#ifdef CONFIG_FAIR_GROUP_SCHED
16747 +       init_sched_bandwidth(&init_task_group.cfs_bandwidth,
16748 +               global_cfs_period(), global_cfs_runtime(),
16749 +               &sched_cfs_period_timer);
16750 +#endif
16751 +
16752  #ifdef CONFIG_GROUP_SCHED
16753         list_add(&init_task_group.list, &task_groups);
16754         INIT_LIST_HEAD(&init_task_group.children);
16755 @@ -9572,6 +9902,8 @@ void __init sched_init(void)
16756                 init_cfs_rq(&rq->cfs, rq);
16757                 init_rt_rq(&rq->rt, rq);
16758  #ifdef CONFIG_FAIR_GROUP_SCHED
16759 +               init_rq_bandwidth(&rq->cfs.rq_bandwidth,
16760 +                               init_task_group.cfs_bandwidth.runtime);
16761                 init_task_group.shares = init_task_group_load;
16762                 INIT_LIST_HEAD(&rq->leaf_cfs_rq_list);
16763  #ifdef CONFIG_CGROUP_SCHED
16764 @@ -9617,7 +9949,7 @@ void __init sched_init(void)
16765  #endif
16766  #endif /* CONFIG_FAIR_GROUP_SCHED */
16767  
16768 -               rq->rt.rt_runtime = def_rt_bandwidth.rt_runtime;
16769 +               rq->rt.rq_bandwidth.runtime = def_rt_bandwidth.runtime;
16770  #ifdef CONFIG_RT_GROUP_SCHED
16771                 INIT_LIST_HEAD(&rq->leaf_rt_rq_list);
16772  #ifdef CONFIG_CGROUP_SCHED
16773 @@ -9851,6 +10183,7 @@ static void free_fair_sched_group(struct
16774  {
16775         int i;
16776  
16777 +       destroy_sched_bandwidth(&tg->cfs_bandwidth);
16778         for_each_possible_cpu(i) {
16779                 if (tg->cfs_rq)
16780                         kfree(tg->cfs_rq[i]);
16781 @@ -9877,6 +10210,8 @@ int alloc_fair_sched_group(struct task_g
16782         if (!tg->se)
16783                 goto err;
16784  
16785 +       init_sched_bandwidth(&tg->cfs_bandwidth, global_cfs_period(),
16786 +               global_cfs_runtime(), &sched_cfs_period_timer);
16787         tg->shares = NICE_0_LOAD;
16788  
16789         for_each_possible_cpu(i) {
16790 @@ -9938,7 +10273,7 @@ static void free_rt_sched_group(struct t
16791  {
16792         int i;
16793  
16794 -       destroy_rt_bandwidth(&tg->rt_bandwidth);
16795 +       destroy_sched_bandwidth(&tg->rt_bandwidth);
16796  
16797         for_each_possible_cpu(i) {
16798                 if (tg->rt_rq)
16799 @@ -9966,8 +10301,9 @@ int alloc_rt_sched_group(struct task_gro
16800         if (!tg->rt_se)
16801                 goto err;
16802  
16803 -       init_rt_bandwidth(&tg->rt_bandwidth,
16804 -                       ktime_to_ns(def_rt_bandwidth.rt_period), 0);
16805 +       init_sched_bandwidth(&tg->rt_bandwidth,
16806 +                       ktime_to_ns(def_rt_bandwidth.period), 0,
16807 +                       &sched_rt_period_timer);
16808  
16809         for_each_possible_cpu(i) {
16810                 rq = cpu_rq(i);
16811 @@ -10266,8 +10602,8 @@ static int tg_schedulable(struct task_gr
16812         unsigned long total, sum = 0;
16813         u64 period, runtime;
16814  
16815 -       period = ktime_to_ns(tg->rt_bandwidth.rt_period);
16816 -       runtime = tg->rt_bandwidth.rt_runtime;
16817 +       period = ktime_to_ns(tg->rt_bandwidth.period);
16818 +       runtime = tg->rt_bandwidth.runtime;
16819  
16820         if (tg == d->tg) {
16821                 period = d->rt_period;
16822 @@ -10305,8 +10641,8 @@ static int tg_schedulable(struct task_gr
16823          * The sum of our children's runtime should not exceed our own.
16824          */
16825         list_for_each_entry_rcu(child, &tg->children, siblings) {
16826 -               period = ktime_to_ns(child->rt_bandwidth.rt_period);
16827 -               runtime = child->rt_bandwidth.rt_runtime;
16828 +               period = ktime_to_ns(child->rt_bandwidth.period);
16829 +               runtime = child->rt_bandwidth.runtime;
16830  
16831                 if (child == d->tg) {
16832                         period = d->rt_period;
16833 @@ -10344,18 +10680,18 @@ static int tg_set_bandwidth(struct task_
16834         if (err)
16835                 goto unlock;
16836  
16837 -       raw_spin_lock_irq(&tg->rt_bandwidth.rt_runtime_lock);
16838 -       tg->rt_bandwidth.rt_period = ns_to_ktime(rt_period);
16839 -       tg->rt_bandwidth.rt_runtime = rt_runtime;
16840 +       raw_spin_lock_irq(&tg->rt_bandwidth.runtime_lock);
16841 +       tg->rt_bandwidth.period = ns_to_ktime(rt_period);
16842 +       tg->rt_bandwidth.runtime = rt_runtime;
16843  
16844         for_each_possible_cpu(i) {
16845                 struct rt_rq *rt_rq = tg->rt_rq[i];
16846  
16847 -               raw_spin_lock(&rt_rq->rt_runtime_lock);
16848 -               rt_rq->rt_runtime = rt_runtime;
16849 -               raw_spin_unlock(&rt_rq->rt_runtime_lock);
16850 +               raw_spin_lock(&rt_rq->rq_bandwidth.runtime_lock);
16851 +               rt_rq->rq_bandwidth.runtime = rt_runtime;
16852 +               raw_spin_unlock(&rt_rq->rq_bandwidth.runtime_lock);
16853         }
16854 -       raw_spin_unlock_irq(&tg->rt_bandwidth.rt_runtime_lock);
16855 +       raw_spin_unlock_irq(&tg->rt_bandwidth.runtime_lock);
16856   unlock:
16857         read_unlock(&tasklist_lock);
16858         mutex_unlock(&rt_constraints_mutex);
16859 @@ -10367,7 +10703,7 @@ int sched_group_set_rt_runtime(struct ta
16860  {
16861         u64 rt_runtime, rt_period;
16862  
16863 -       rt_period = ktime_to_ns(tg->rt_bandwidth.rt_period);
16864 +       rt_period = ktime_to_ns(tg->rt_bandwidth.period);
16865         rt_runtime = (u64)rt_runtime_us * NSEC_PER_USEC;
16866         if (rt_runtime_us < 0)
16867                 rt_runtime = RUNTIME_INF;
16868 @@ -10379,10 +10715,10 @@ long sched_group_rt_runtime(struct task_
16869  {
16870         u64 rt_runtime_us;
16871  
16872 -       if (tg->rt_bandwidth.rt_runtime == RUNTIME_INF)
16873 +       if (tg->rt_bandwidth.runtime == RUNTIME_INF)
16874                 return -1;
16875  
16876 -       rt_runtime_us = tg->rt_bandwidth.rt_runtime;
16877 +       rt_runtime_us = tg->rt_bandwidth.runtime;
16878         do_div(rt_runtime_us, NSEC_PER_USEC);
16879         return rt_runtime_us;
16880  }
16881 @@ -10392,7 +10728,7 @@ int sched_group_set_rt_period(struct tas
16882         u64 rt_runtime, rt_period;
16883  
16884         rt_period = (u64)rt_period_us * NSEC_PER_USEC;
16885 -       rt_runtime = tg->rt_bandwidth.rt_runtime;
16886 +       rt_runtime = tg->rt_bandwidth.runtime;
16887  
16888         if (rt_period == 0)
16889                 return -EINVAL;
16890 @@ -10404,7 +10740,7 @@ long sched_group_rt_period(struct task_g
16891  {
16892         u64 rt_period_us;
16893  
16894 -       rt_period_us = ktime_to_ns(tg->rt_bandwidth.rt_period);
16895 +       rt_period_us = ktime_to_ns(tg->rt_bandwidth.period);
16896         do_div(rt_period_us, NSEC_PER_USEC);
16897         return rt_period_us;
16898  }
16899 @@ -10438,7 +10774,7 @@ static int sched_rt_global_constraints(v
16900  int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk)
16901  {
16902         /* Don't accept realtime tasks when there is no way for them to run */
16903 -       if (rt_task(tsk) && tg->rt_bandwidth.rt_runtime == 0)
16904 +       if (rt_task(tsk) && tg->rt_bandwidth.runtime == 0)
16905                 return 0;
16906  
16907         return 1;
16908 @@ -10460,15 +10796,15 @@ static int sched_rt_global_constraints(v
16909         if (sysctl_sched_rt_runtime == 0)
16910                 return -EBUSY;
16911  
16912 -       raw_spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags);
16913 +       raw_spin_lock_irqsave(&def_rt_bandwidth.runtime_lock, flags);
16914         for_each_possible_cpu(i) {
16915                 struct rt_rq *rt_rq = &cpu_rq(i)->rt;
16916  
16917 -               raw_spin_lock(&rt_rq->rt_runtime_lock);
16918 -               rt_rq->rt_runtime = global_rt_runtime();
16919 -               raw_spin_unlock(&rt_rq->rt_runtime_lock);
16920 +               raw_spin_lock(&rt_rq->rq_bandwidth.runtime_lock);
16921 +               rt_rq->rq_bandwidth.runtime = global_rt_runtime();
16922 +               raw_spin_unlock(&rt_rq->rq_bandwidth.runtime_lock);
16923         }
16924 -       raw_spin_unlock_irqrestore(&def_rt_bandwidth.rt_runtime_lock, flags);
16925 +       raw_spin_unlock_irqrestore(&def_rt_bandwidth.runtime_lock, flags);
16926  
16927         return 0;
16928  }
16929 @@ -10494,8 +10830,8 @@ int sched_rt_handler(struct ctl_table *t
16930                         sysctl_sched_rt_period = old_period;
16931                         sysctl_sched_rt_runtime = old_runtime;
16932                 } else {
16933 -                       def_rt_bandwidth.rt_runtime = global_rt_runtime();
16934 -                       def_rt_bandwidth.rt_period =
16935 +                       def_rt_bandwidth.runtime = global_rt_runtime();
16936 +                       def_rt_bandwidth.period =
16937                                 ns_to_ktime(global_rt_period());
16938                 }
16939         }
16940 @@ -10604,6 +10940,102 @@ static u64 cpu_shares_read_u64(struct cg
16941  
16942         return (u64) tg->shares;
16943  }
16944 +
16945 +#ifdef CONFIG_CFS_HARD_LIMITS
16946 +
16947 +static int tg_set_cfs_bandwidth(struct task_group *tg,
16948 +               u64 cfs_period, u64 cfs_runtime)
16949 +{
16950 +       int i;
16951 +
16952 +       if (tg == &init_task_group)
16953 +               return -EINVAL;
16954 +
16955 +       raw_spin_lock_irq(&tg->cfs_bandwidth.runtime_lock);
16956 +       tg->cfs_bandwidth.period = ns_to_ktime(cfs_period);
16957 +       tg->cfs_bandwidth.runtime = cfs_runtime;
16958 +
16959 +       for_each_possible_cpu(i) {
16960 +               struct cfs_rq *cfs_rq = tg->cfs_rq[i];
16961 +
16962 +               raw_spin_lock(&cfs_rq->rq_bandwidth.runtime_lock);
16963 +               cfs_rq->rq_bandwidth.runtime = cfs_runtime;
16964 +               raw_spin_unlock(&cfs_rq->rq_bandwidth.runtime_lock);
16965 +       }
16966 +
16967 +       raw_spin_unlock_irq(&tg->cfs_bandwidth.runtime_lock);
16968 +       return 0;
16969 +}
16970 +
16971 +int tg_set_cfs_runtime(struct task_group *tg, long cfs_runtime_us)
16972 +{
16973 +       u64 cfs_runtime, cfs_period;
16974 +
16975 +       cfs_period = ktime_to_ns(tg->cfs_bandwidth.period);
16976 +       cfs_runtime = (u64)cfs_runtime_us * NSEC_PER_USEC;
16977 +       if (cfs_runtime_us < 0)
16978 +               cfs_runtime = RUNTIME_INF;
16979 +
16980 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16981 +}
16982 +
16983 +long tg_get_cfs_runtime(struct task_group *tg)
16984 +{
16985 +       u64 cfs_runtime_us;
16986 +
16987 +       if (tg->cfs_bandwidth.runtime == RUNTIME_INF)
16988 +               return -1;
16989 +
16990 +       cfs_runtime_us = tg->cfs_bandwidth.runtime;
16991 +       do_div(cfs_runtime_us, NSEC_PER_USEC);
16992 +       return cfs_runtime_us;
16993 +}
16994 +
16995 +int tg_set_cfs_period(struct task_group *tg, long cfs_period_us)
16996 +{
16997 +       u64 cfs_runtime, cfs_period;
16998 +
16999 +       cfs_period = (u64)cfs_period_us * NSEC_PER_USEC;
17000 +       cfs_runtime = tg->cfs_bandwidth.runtime;
17001 +
17002 +       if (cfs_period == 0)
17003 +               return -EINVAL;
17004 +
17005 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
17006 +}
17007 +
17008 +long tg_get_cfs_period(struct task_group *tg)
17009 +{
17010 +       u64 cfs_period_us;
17011 +
17012 +       cfs_period_us = ktime_to_ns(tg->cfs_bandwidth.period);
17013 +       do_div(cfs_period_us, NSEC_PER_USEC);
17014 +       return cfs_period_us;
17015 +}
17016 +
17017 +static s64 cpu_cfs_runtime_read_s64(struct cgroup *cgrp, struct cftype *cft)
17018 +{
17019 +       return tg_get_cfs_runtime(cgroup_tg(cgrp));
17020 +}
17021 +
17022 +static int cpu_cfs_runtime_write_s64(struct cgroup *cgrp, struct cftype *cftype,
17023 +                               s64 cfs_runtime_us)
17024 +{
17025 +       return tg_set_cfs_runtime(cgroup_tg(cgrp), cfs_runtime_us);
17026 +}
17027 +
17028 +static u64 cpu_cfs_period_read_u64(struct cgroup *cgrp, struct cftype *cft)
17029 +{
17030 +       return tg_get_cfs_period(cgroup_tg(cgrp));
17031 +}
17032 +
17033 +static int cpu_cfs_period_write_u64(struct cgroup *cgrp, struct cftype *cftype,
17034 +                               u64 cfs_period_us)
17035 +{
17036 +       return tg_set_cfs_period(cgroup_tg(cgrp), cfs_period_us);
17037 +}
17038 +
17039 +#endif /* CONFIG_CFS_HARD_LIMITS */
17040  #endif /* CONFIG_FAIR_GROUP_SCHED */
17041  
17042  #ifdef CONFIG_RT_GROUP_SCHED
17043 @@ -10637,6 +11069,18 @@ static struct cftype cpu_files[] = {
17044                 .read_u64 = cpu_shares_read_u64,
17045                 .write_u64 = cpu_shares_write_u64,
17046         },
17047 +#ifdef CONFIG_CFS_HARD_LIMITS
17048 +       {
17049 +               .name = "cfs_runtime_us",
17050 +               .read_s64 = cpu_cfs_runtime_read_s64,
17051 +               .write_s64 = cpu_cfs_runtime_write_s64,
17052 +       },
17053 +       {
17054 +               .name = "cfs_period_us",
17055 +               .read_u64 = cpu_cfs_period_read_u64,
17056 +               .write_u64 = cpu_cfs_period_write_u64,
17057 +       },
17058 +#endif /* CONFIG_CFS_HARD_LIMITS */
17059  #endif
17060  #ifdef CONFIG_RT_GROUP_SCHED
17061         {
17062 diff -NurpP --minimal linux-2.6.33/kernel/sched_debug.c linux-2.6.33-vs2.3.0.36.30.1/kernel/sched_debug.c
17063 --- linux-2.6.33/kernel/sched_debug.c   2010-02-25 11:52:09.000000000 +0100
17064 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/sched_debug.c   2010-02-25 18:09:39.000000000 +0100
17065 @@ -80,6 +80,11 @@ static void print_cfs_group_stats(struct
17066         PN(se->wait_max);
17067         PN(se->wait_sum);
17068         P(se->wait_count);
17069 +#ifdef CONFIG_CFS_HARD_LIMITS
17070 +       PN(se->throttle_max);
17071 +       PN(se->throttle_sum);
17072 +       P(se->throttle_count);
17073 +#endif
17074  #endif
17075         P(se->load.weight);
17076  #undef PN
17077 @@ -214,6 +219,16 @@ void print_cfs_rq(struct seq_file *m, in
17078  #ifdef CONFIG_SMP
17079         SEQ_printf(m, "  .%-30s: %lu\n", "shares", cfs_rq->shares);
17080  #endif
17081 +#ifdef CONFIG_CFS_HARD_LIMITS
17082 +       raw_spin_lock_irqsave(&rq->lock, flags);
17083 +       SEQ_printf(m, "  .%-30s: %d\n", "rq_bandwidth.throttled",
17084 +                       cfs_rq->rq_bandwidth.throttled);
17085 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "rq_bandwidth.time",
17086 +                       SPLIT_NS(cfs_rq->rq_bandwidth.time));
17087 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "rq_bandwidth.runtime",
17088 +                       SPLIT_NS(cfs_rq->rq_bandwidth.runtime));
17089 +       raw_spin_unlock_irqrestore(&rq->lock, flags);
17090 +#endif /* CONFIG_CFS_HARD_LIMITS */
17091         print_cfs_group_stats(m, cpu, cfs_rq->tg);
17092  #endif
17093  }
17094 @@ -238,9 +253,9 @@ void print_rt_rq(struct seq_file *m, int
17095         SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x))
17096  
17097         P(rt_nr_running);
17098 -       P(rt_throttled);
17099 -       PN(rt_time);
17100 -       PN(rt_runtime);
17101 +       P(rq_bandwidth.throttled);
17102 +       PN(rq_bandwidth.time);
17103 +       PN(rq_bandwidth.runtime);
17104  
17105  #undef PN
17106  #undef P
17107 @@ -320,7 +335,7 @@ static int sched_debug_show(struct seq_f
17108         u64 now = ktime_to_ns(ktime_get());
17109         int cpu;
17110  
17111 -       SEQ_printf(m, "Sched Debug Version: v0.09, %s %.*s\n",
17112 +       SEQ_printf(m, "Sched Debug Version: v0.10, %s %.*s\n",
17113                 init_utsname()->release,
17114                 (int)strcspn(init_utsname()->version, " "),
17115                 init_utsname()->version);
17116 diff -NurpP --minimal linux-2.6.33/kernel/sched_fair.c linux-2.6.33-vs2.3.0.36.30.1/kernel/sched_fair.c
17117 --- linux-2.6.33/kernel/sched_fair.c    2010-02-25 11:52:09.000000000 +0100
17118 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/sched_fair.c    2010-02-25 16:24:45.000000000 +0100
17119 @@ -205,7 +205,205 @@ find_matching_se(struct sched_entity **s
17120         }
17121  }
17122  
17123 -#else  /* !CONFIG_FAIR_GROUP_SCHED */
17124 +static inline struct sched_bandwidth *sched_cfs_bandwidth(struct cfs_rq *cfs_rq)
17125 +{
17126 +       return &cfs_rq->tg->cfs_bandwidth;
17127 +}
17128 +
17129 +static inline void start_cfs_bandwidth(struct cfs_rq *cfs_rq)
17130 +{
17131 +       if (cfs_rq->tg)
17132 +               start_sched_bandwidth(sched_cfs_bandwidth(cfs_rq), 0);
17133 +       return;
17134 +}
17135 +
17136 +#ifdef CONFIG_CFS_HARD_LIMITS
17137 +
17138 +static inline void update_stats_throttle_start(struct cfs_rq *cfs_rq,
17139 +                       struct sched_entity *se)
17140 +{
17141 +       schedstat_set(se->throttle_start, rq_of(cfs_rq)->clock);
17142 +}
17143 +
17144 +static inline void update_stats_throttle_end(struct cfs_rq *cfs_rq,
17145 +                       struct sched_entity *se)
17146 +{
17147 +       schedstat_set(se->throttle_max, max(se->throttle_max,
17148 +                       rq_of(cfs_rq)->clock - se->throttle_start));
17149 +       schedstat_set(se->throttle_count, se->throttle_count + 1);
17150 +       schedstat_set(se->throttle_sum, se->throttle_sum +
17151 +                       rq_of(cfs_rq)->clock - se->throttle_start);
17152 +       schedstat_set(se->throttle_start, 0);
17153 +}
17154 +
17155 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
17156 +{
17157 +       return cfs_rq->rq_bandwidth.throttled;
17158 +}
17159 +
17160 +#ifdef CONFIG_SMP
17161 +/*
17162 + * Ensure this RQ takes back all the runtime it lend to its neighbours.
17163 + */
17164 +void disable_runtime_cfs(struct rq *rq)
17165 +{
17166 +       struct cfs_rq *cfs_rq;
17167 +
17168 +       if (unlikely(!scheduler_running))
17169 +               return;
17170 +
17171 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
17172 +               struct sched_bandwidth *sched_b = sched_cfs_bandwidth(cfs_rq);
17173 +               __disable_runtime(rq, sched_b, &cfs_rq->rq_bandwidth, 0);
17174 +       }
17175 +}
17176 +
17177 +void enable_runtime_cfs(struct rq *rq)
17178 +{
17179 +       struct cfs_rq *cfs_rq;
17180 +
17181 +       if (unlikely(!scheduler_running))
17182 +               return;
17183 +
17184 +       /*
17185 +        * Reset each runqueue's bandwidth settings
17186 +        */
17187 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
17188 +               struct sched_bandwidth *sched_b = sched_cfs_bandwidth(cfs_rq);
17189 +               __enable_runtime(sched_b, &cfs_rq->rq_bandwidth);
17190 +       }
17191 +}
17192 +
17193 +#endif /* CONFIG_SMP */
17194 +
17195 +/*
17196 + * Check if group entity exceeded its runtime. If so, mark the cfs_rq as
17197 + * throttled mark the current task for reschedling.
17198 + */
17199 +static void sched_cfs_runtime_exceeded(struct sched_entity *se,
17200 +       struct task_struct *tsk_curr, unsigned long delta_exec)
17201 +{
17202 +       struct cfs_rq *cfs_rq;
17203 +
17204 +       cfs_rq = group_cfs_rq(se);
17205 +
17206 +       if (cfs_rq->rq_bandwidth.runtime == RUNTIME_INF)
17207 +               return;
17208 +
17209 +       cfs_rq->rq_bandwidth.time += delta_exec;
17210 +
17211 +       if (cfs_rq_throttled(cfs_rq))
17212 +               return;
17213 +
17214 +       if (cfs_rq->rq_bandwidth.time > cfs_rq->rq_bandwidth.runtime)
17215 +               balance_runtime(&cfs_rq->rq_bandwidth,
17216 +                                       sched_cfs_bandwidth(cfs_rq), 0);
17217 +
17218 +       if (cfs_rq->rq_bandwidth.time > cfs_rq->rq_bandwidth.runtime) {
17219 +               cfs_rq->rq_bandwidth.throttled = 1;
17220 +               update_stats_throttle_start(cfs_rq, se);
17221 +               resched_task(tsk_curr);
17222 +       }
17223 +}
17224 +
17225 +static inline void update_curr_group(struct sched_entity *curr,
17226 +               unsigned long delta_exec, struct task_struct *tsk_curr)
17227 +{
17228 +       sched_cfs_runtime_exceeded(curr, tsk_curr, delta_exec);
17229 +}
17230 +
17231 +static void enqueue_entity(struct cfs_rq *cfs_rq,
17232 +               struct sched_entity *se, int wakeup);
17233 +
17234 +static void enqueue_throttled_entity(struct rq *rq, struct sched_entity *se)
17235 +{
17236 +       for_each_sched_entity(se) {
17237 +               struct cfs_rq *gcfs_rq = group_cfs_rq(se);
17238 +
17239 +               if (se->on_rq || cfs_rq_throttled(gcfs_rq) ||
17240 +                               !gcfs_rq->nr_running)
17241 +                       break;
17242 +               enqueue_entity(cfs_rq_of(se), se, 0);
17243 +       }
17244 +}
17245 +
17246 +/*
17247 + * Refresh runtimes of all cfs_rqs in this group, i,e.,
17248 + * refresh runtimes of the representative cfs_rq of this
17249 + * tg on all cpus. Enqueue any throttled entity back.
17250 + */
17251 +static int do_sched_cfs_period_timer(struct sched_bandwidth *cfs_b, int overrun)
17252 +{
17253 +       int i, idle = 1;
17254 +       const struct cpumask *span;
17255 +
17256 +       if (cfs_b->runtime == RUNTIME_INF)
17257 +               return 1;
17258 +
17259 +       span = sched_bw_period_mask();
17260 +       for_each_cpu(i, span) {
17261 +               int enqueue = 0;
17262 +               struct rq *rq = cpu_rq(i);
17263 +               struct cfs_rq *cfs_rq = sched_cfs_period_cfs_rq(cfs_b, i);
17264 +               struct sched_entity *se = cfs_rq->tg->se[i];
17265 +
17266 +               raw_spin_lock(&rq->lock);
17267 +               if (cfs_rq->rq_bandwidth.time) {
17268 +                       u64 runtime;
17269 +
17270 +                       raw_spin_lock(&cfs_rq->rq_bandwidth.runtime_lock);
17271 +                       if (cfs_rq_throttled(cfs_rq))
17272 +                               balance_runtime(&cfs_rq->rq_bandwidth,
17273 +                                       sched_cfs_bandwidth(cfs_rq), 0);
17274 +                       runtime = cfs_rq->rq_bandwidth.runtime;
17275 +                       cfs_rq->rq_bandwidth.time -= min(cfs_rq->rq_bandwidth.time, overrun*runtime);
17276 +                       if (cfs_rq_throttled(cfs_rq) &&
17277 +                                       cfs_rq->rq_bandwidth.time < runtime) {
17278 +                               cfs_rq->rq_bandwidth.throttled = 0;
17279 +                               update_rq_clock(rq);
17280 +                               update_stats_throttle_end(cfs_rq, se);
17281 +                               enqueue = 1;
17282 +                       }
17283 +                       if (cfs_rq->rq_bandwidth.time || cfs_rq->nr_running)
17284 +                               idle = 0;
17285 +                       raw_spin_unlock(&cfs_rq->rq_bandwidth.runtime_lock);
17286 +               } else if (cfs_rq->nr_running)
17287 +                       idle = 0;
17288 +
17289 +               if (enqueue)
17290 +                       enqueue_throttled_entity(rq, se);
17291 +               raw_spin_unlock(&rq->lock);
17292 +       }
17293 +       return idle;
17294 +}
17295 +
17296 +#else
17297 +
17298 +static inline void update_curr_group(struct sched_entity *curr,
17299 +               unsigned long delta_exec, struct task_struct *tsk_curr)
17300 +{
17301 +       return;
17302 +}
17303 +
17304 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
17305 +{
17306 +       return 0;
17307 +}
17308 +
17309 +static int do_sched_cfs_period_timer(struct sched_bandwidth *cfs_b, int overrun)
17310 +{
17311 +       return 0;
17312 +}
17313 +
17314 +#endif /* CONFIG_CFS_HARD_LIMITS */
17315 +
17316 +#else  /* CONFIG_FAIR_GROUP_SCHED */
17317 +
17318 +static inline void update_curr_group(struct sched_entity *curr,
17319 +               unsigned long delta_exec, struct task_struct *tsk_curr)
17320 +{
17321 +       return;
17322 +}
17323  
17324  static inline struct task_struct *task_of(struct sched_entity *se)
17325  {
17326 @@ -265,8 +463,22 @@ find_matching_se(struct sched_entity **s
17327  {
17328  }
17329  
17330 -#endif /* CONFIG_FAIR_GROUP_SCHED */
17331 +static inline void start_cfs_bandwidth(struct cfs_rq *cfs_rq)
17332 +{
17333 +       return;
17334 +}
17335 +
17336 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
17337 +{
17338 +       return 0;
17339 +}
17340 +
17341 +static int do_sched_cfs_period_timer(struct sched_bandwidth *cfs_b, int overrun)
17342 +{
17343 +       return 0;
17344 +}
17345  
17346 +#endif /* CONFIG_FAIR_GROUP_SCHED */
17347  
17348  /**************************************************************
17349   * Scheduling class tree data structure manipulation methods:
17350 @@ -360,6 +572,7 @@ static void __enqueue_entity(struct cfs_
17351  
17352         rb_link_node(&se->run_node, parent, link);
17353         rb_insert_color(&se->run_node, &cfs_rq->tasks_timeline);
17354 +       start_cfs_bandwidth(cfs_rq);
17355  }
17356  
17357  static void __dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
17358 @@ -515,14 +728,25 @@ __update_curr(struct cfs_rq *cfs_rq, str
17359         update_min_vruntime(cfs_rq);
17360  }
17361  
17362 -static void update_curr(struct cfs_rq *cfs_rq)
17363 +static void update_curr_task(struct sched_entity *curr,
17364 +               unsigned long delta_exec)
17365 +{
17366 +       struct task_struct *curtask = task_of(curr);
17367 +
17368 +       trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
17369 +       cpuacct_charge(curtask, delta_exec);
17370 +       account_group_exec_runtime(curtask, delta_exec);
17371 +}
17372 +
17373 +static int update_curr_common(struct cfs_rq *cfs_rq, unsigned long *delta)
17374  {
17375         struct sched_entity *curr = cfs_rq->curr;
17376 -       u64 now = rq_of(cfs_rq)->clock;
17377 +       struct rq *rq = rq_of(cfs_rq);
17378 +       u64 now = rq->clock;
17379         unsigned long delta_exec;
17380  
17381         if (unlikely(!curr))
17382 -               return;
17383 +               return 1;
17384  
17385         /*
17386          * Get the amount of time the current task was running
17387 @@ -531,17 +755,31 @@ static void update_curr(struct cfs_rq *c
17388          */
17389         delta_exec = (unsigned long)(now - curr->exec_start);
17390         if (!delta_exec)
17391 -               return;
17392 +               return 1;
17393  
17394         __update_curr(cfs_rq, curr, delta_exec);
17395         curr->exec_start = now;
17396 +       *delta = delta_exec;
17397 +       return 0;
17398 +}
17399  
17400 -       if (entity_is_task(curr)) {
17401 -               struct task_struct *curtask = task_of(curr);
17402 +static void update_curr(struct cfs_rq *cfs_rq)
17403 +{
17404 +       struct sched_entity *curr = cfs_rq->curr;
17405 +       struct rq *rq = rq_of(cfs_rq);
17406 +       unsigned long delta_exec;
17407 +       struct rq_bandwidth *rq_b;
17408  
17409 -               trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
17410 -               cpuacct_charge(curtask, delta_exec);
17411 -               account_group_exec_runtime(curtask, delta_exec);
17412 +       if (update_curr_common(cfs_rq, &delta_exec))
17413 +               return ;
17414 +
17415 +       if (entity_is_task(curr))
17416 +               update_curr_task(curr, delta_exec);
17417 +       else {
17418 +               rq_b = &group_cfs_rq(curr)->rq_bandwidth;
17419 +               raw_spin_lock(&rq_b->runtime_lock);
17420 +               update_curr_group(curr, delta_exec, rq->curr);
17421 +               raw_spin_unlock(&rq_b->runtime_lock);
17422         }
17423  }
17424  
17425 @@ -769,6 +1007,22 @@ place_entity(struct cfs_rq *cfs_rq, stru
17426  #define ENQUEUE_WAKEUP 1
17427  #define ENQUEUE_MIGRATE 2
17428  
17429 +static void enqueue_entity_common(struct cfs_rq *cfs_rq,
17430 +               struct sched_entity *se, int flags)
17431 +{
17432 +       account_entity_enqueue(cfs_rq, se);
17433 +
17434 +       if (flags & ENQUEUE_WAKEUP) {
17435 +               place_entity(cfs_rq, se, 0);
17436 +               enqueue_sleeper(cfs_rq, se);
17437 +       }
17438 +
17439 +       update_stats_enqueue(cfs_rq, se);
17440 +       check_spread(cfs_rq, se);
17441 +       if (se != cfs_rq->curr)
17442 +               __enqueue_entity(cfs_rq, se);
17443 +}
17444 +
17445  static void
17446  enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
17447  {
17448 @@ -783,17 +1037,10 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
17449          * Update run-time statistics of the 'current'.
17450          */
17451         update_curr(cfs_rq);
17452 -       account_entity_enqueue(cfs_rq, se);
17453 -
17454 -       if (flags & ENQUEUE_WAKEUP) {
17455 -               place_entity(cfs_rq, se, 0);
17456 -               enqueue_sleeper(cfs_rq, se);
17457 -       }
17458 +       enqueue_entity_common(cfs_rq, se, flags);
17459  
17460 -       update_stats_enqueue(cfs_rq, se);
17461 -       check_spread(cfs_rq, se);
17462 -       if (se != cfs_rq->curr)
17463 -               __enqueue_entity(cfs_rq, se);
17464 +       if (entity_is_task(se))
17465 +               vx_activate_task(task_of(se));
17466  }
17467  
17468  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
17469 @@ -837,6 +1084,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
17470  
17471         if (se != cfs_rq->curr)
17472                 __dequeue_entity(cfs_rq, se);
17473 +       if (entity_is_task(se))
17474 +               vx_deactivate_task(task_of(se));
17475         account_entity_dequeue(cfs_rq, se);
17476         update_min_vruntime(cfs_rq);
17477  
17478 @@ -941,6 +1190,28 @@ static struct sched_entity *pick_next_en
17479         return se;
17480  }
17481  
17482 +/*
17483 + * Called from put_prev_entity()
17484 + * If a group entity (@se) is found to be throttled, it will not be put back
17485 + * on @cfs_rq, which is equivalent to dequeing it.
17486 + */
17487 +static int dequeue_throttled_entity(struct cfs_rq *cfs_rq,
17488 +               struct sched_entity *se)
17489 +{
17490 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
17491 +
17492 +       if (entity_is_task(se))
17493 +               return 0;
17494 +
17495 +       if (!cfs_rq_throttled(gcfs_rq) && gcfs_rq->nr_running)
17496 +               return 0;
17497 +
17498 +       __clear_buddies(cfs_rq, se);
17499 +       account_entity_dequeue(cfs_rq, se);
17500 +       cfs_rq->curr = NULL;
17501 +       return 1;
17502 +}
17503 +
17504  static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
17505  {
17506         /*
17507 @@ -952,6 +1223,8 @@ static void put_prev_entity(struct cfs_r
17508  
17509         check_spread(cfs_rq, prev);
17510         if (prev->on_rq) {
17511 +               if (dequeue_throttled_entity(cfs_rq, prev))
17512 +                       return;
17513                 update_stats_wait_start(cfs_rq, prev);
17514                 /* Put 'current' back into the tree. */
17515                 __enqueue_entity(cfs_rq, prev);
17516 @@ -1048,10 +1321,26 @@ static inline void hrtick_update(struct 
17517  }
17518  #endif
17519  
17520 +static int enqueue_group_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
17521 +                int flags)
17522 +{
17523 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
17524 +       int ret = 0;
17525 +
17526 +       if (cfs_rq_throttled(gcfs_rq)) {
17527 +               ret = 1;
17528 +               goto out;
17529 +       }
17530 +       enqueue_entity(cfs_rq, se, flags);
17531 +out:
17532 +       return ret;
17533 +}
17534 +
17535  /*
17536   * The enqueue_task method is called before nr_running is
17537   * increased. Here we update the fair scheduling stats and
17538   * then put the task into the rbtree:
17539 + * Don't enqueue a throttled entity further into the hierarchy.
17540   */
17541  static void enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup)
17542  {
17543 @@ -1067,11 +1356,15 @@ static void enqueue_task_fair(struct rq 
17544         for_each_sched_entity(se) {
17545                 if (se->on_rq)
17546                         break;
17547 +
17548                 cfs_rq = cfs_rq_of(se);
17549 -               enqueue_entity(cfs_rq, se, flags);
17550 +               if (entity_is_task(se))
17551 +                       enqueue_entity(cfs_rq, se, flags);
17552 +               else
17553 +                       if (enqueue_group_entity(cfs_rq, se, flags))
17554 +                               break;
17555                 flags = ENQUEUE_WAKEUP;
17556         }
17557 -
17558         hrtick_update(rq);
17559  }
17560  
17561 @@ -1091,6 +1384,13 @@ static void dequeue_task_fair(struct rq 
17562                 /* Don't dequeue parent if it has other entities besides us */
17563                 if (cfs_rq->load.weight)
17564                         break;
17565 +
17566 +               /*
17567 +                * If this cfs_rq is throttled, then it is already
17568 +                * dequeued.
17569 +                */
17570 +               if (cfs_rq_throttled(cfs_rq))
17571 +                       break;
17572                 sleep = 1;
17573         }
17574  
17575 @@ -1889,9 +2189,10 @@ load_balance_fair(struct rq *this_rq, in
17576                 u64 rem_load, moved_load;
17577  
17578                 /*
17579 -                * empty group
17580 +                * empty group or throttled group
17581                  */
17582 -               if (!busiest_cfs_rq->task_weight)
17583 +               if (!busiest_cfs_rq->task_weight ||
17584 +                               cfs_rq_throttled(busiest_cfs_rq))
17585                         continue;
17586  
17587                 rem_load = (u64)rem_load_move * busiest_weight;
17588 @@ -1940,6 +2241,12 @@ move_one_task_fair(struct rq *this_rq, i
17589  
17590         for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
17591                 /*
17592 +                * Don't move task from a throttled cfs_rq
17593 +                */
17594 +               if (cfs_rq_throttled(busy_cfs_rq))
17595 +                       continue;
17596 +
17597 +               /*
17598                  * pass busy_cfs_rq argument into
17599                  * load_balance_[start|next]_fair iterators
17600                  */
17601 diff -NurpP --minimal linux-2.6.33/kernel/sched_rt.c linux-2.6.33-vs2.3.0.36.30.1/kernel/sched_rt.c
17602 --- linux-2.6.33/kernel/sched_rt.c      2010-02-25 11:52:09.000000000 +0100
17603 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/sched_rt.c      2010-02-25 16:19:21.000000000 +0100
17604 @@ -175,12 +175,12 @@ static inline u64 sched_rt_runtime(struc
17605         if (!rt_rq->tg)
17606                 return RUNTIME_INF;
17607  
17608 -       return rt_rq->rt_runtime;
17609 +       return rt_rq->rq_bandwidth.runtime;
17610  }
17611  
17612  static inline u64 sched_rt_period(struct rt_rq *rt_rq)
17613  {
17614 -       return ktime_to_ns(rt_rq->tg->rt_bandwidth.rt_period);
17615 +       return ktime_to_ns(rt_rq->tg->rt_bandwidth.period);
17616  }
17617  
17618  #define for_each_leaf_rt_rq(rt_rq, rq) \
17619 @@ -220,7 +220,7 @@ static void sched_rt_rq_dequeue(struct r
17620  
17621  static inline int rt_rq_throttled(struct rt_rq *rt_rq)
17622  {
17623 -       return rt_rq->rt_throttled && !rt_rq->rt_nr_boosted;
17624 +       return rt_rq->rq_bandwidth.throttled && !rt_rq->rt_nr_boosted;
17625  }
17626  
17627  static int rt_se_boosted(struct sched_rt_entity *rt_se)
17628 @@ -235,25 +235,7 @@ static int rt_se_boosted(struct sched_rt
17629         return p->prio != p->normal_prio;
17630  }
17631  
17632 -#ifdef CONFIG_SMP
17633 -static inline const struct cpumask *sched_rt_period_mask(void)
17634 -{
17635 -       return cpu_rq(smp_processor_id())->rd->span;
17636 -}
17637 -#else
17638 -static inline const struct cpumask *sched_rt_period_mask(void)
17639 -{
17640 -       return cpu_online_mask;
17641 -}
17642 -#endif
17643 -
17644 -static inline
17645 -struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
17646 -{
17647 -       return container_of(rt_b, struct task_group, rt_bandwidth)->rt_rq[cpu];
17648 -}
17649 -
17650 -static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
17651 +static inline struct sched_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
17652  {
17653         return &rt_rq->tg->rt_bandwidth;
17654  }
17655 @@ -262,12 +244,12 @@ static inline struct rt_bandwidth *sched
17656  
17657  static inline u64 sched_rt_runtime(struct rt_rq *rt_rq)
17658  {
17659 -       return rt_rq->rt_runtime;
17660 +       return rt_rq->rq_bandwidth.runtime;
17661  }
17662  
17663  static inline u64 sched_rt_period(struct rt_rq *rt_rq)
17664  {
17665 -       return ktime_to_ns(def_rt_bandwidth.rt_period);
17666 +       return ktime_to_ns(def_rt_bandwidth.period);
17667  }
17668  
17669  #define for_each_leaf_rt_rq(rt_rq, rq) \
17670 @@ -293,21 +275,10 @@ static inline void sched_rt_rq_dequeue(s
17671  
17672  static inline int rt_rq_throttled(struct rt_rq *rt_rq)
17673  {
17674 -       return rt_rq->rt_throttled;
17675 -}
17676 -
17677 -static inline const struct cpumask *sched_rt_period_mask(void)
17678 -{
17679 -       return cpu_online_mask;
17680 -}
17681 -
17682 -static inline
17683 -struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
17684 -{
17685 -       return &cpu_rq(cpu)->rt;
17686 +       return rt_rq->rq_bandwidth.throttled;
17687  }
17688  
17689 -static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
17690 +static inline struct sched_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
17691  {
17692         return &def_rt_bandwidth;
17693  }
17694 @@ -315,151 +286,24 @@ static inline struct rt_bandwidth *sched
17695  #endif /* CONFIG_RT_GROUP_SCHED */
17696  
17697  #ifdef CONFIG_SMP
17698 -/*
17699 - * We ran out of runtime, see if we can borrow some from our neighbours.
17700 - */
17701 -static int do_balance_runtime(struct rt_rq *rt_rq)
17702 -{
17703 -       struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
17704 -       struct root_domain *rd = cpu_rq(smp_processor_id())->rd;
17705 -       int i, weight, more = 0;
17706 -       u64 rt_period;
17707 -
17708 -       weight = cpumask_weight(rd->span);
17709 -
17710 -       raw_spin_lock(&rt_b->rt_runtime_lock);
17711 -       rt_period = ktime_to_ns(rt_b->rt_period);
17712 -       for_each_cpu(i, rd->span) {
17713 -               struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
17714 -               s64 diff;
17715 -
17716 -               if (iter == rt_rq)
17717 -                       continue;
17718 -
17719 -               raw_spin_lock(&iter->rt_runtime_lock);
17720 -               /*
17721 -                * Either all rqs have inf runtime and there's nothing to steal
17722 -                * or __disable_runtime() below sets a specific rq to inf to
17723 -                * indicate its been disabled and disalow stealing.
17724 -                */
17725 -               if (iter->rt_runtime == RUNTIME_INF)
17726 -                       goto next;
17727 -
17728 -               /*
17729 -                * From runqueues with spare time, take 1/n part of their
17730 -                * spare time, but no more than our period.
17731 -                */
17732 -               diff = iter->rt_runtime - iter->rt_time;
17733 -               if (diff > 0) {
17734 -                       diff = div_u64((u64)diff, weight);
17735 -                       if (rt_rq->rt_runtime + diff > rt_period)
17736 -                               diff = rt_period - rt_rq->rt_runtime;
17737 -                       iter->rt_runtime -= diff;
17738 -                       rt_rq->rt_runtime += diff;
17739 -                       more = 1;
17740 -                       if (rt_rq->rt_runtime == rt_period) {
17741 -                               raw_spin_unlock(&iter->rt_runtime_lock);
17742 -                               break;
17743 -                       }
17744 -               }
17745 -next:
17746 -               raw_spin_unlock(&iter->rt_runtime_lock);
17747 -       }
17748 -       raw_spin_unlock(&rt_b->rt_runtime_lock);
17749 -
17750 -       return more;
17751 -}
17752  
17753  /*
17754   * Ensure this RQ takes back all the runtime it lend to its neighbours.
17755   */
17756 -static void __disable_runtime(struct rq *rq)
17757 +void disable_runtime_rt(struct rq *rq)
17758  {
17759 -       struct root_domain *rd = rq->rd;
17760         struct rt_rq *rt_rq;
17761  
17762         if (unlikely(!scheduler_running))
17763                 return;
17764  
17765         for_each_leaf_rt_rq(rt_rq, rq) {
17766 -               struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
17767 -               s64 want;
17768 -               int i;
17769 -
17770 -               raw_spin_lock(&rt_b->rt_runtime_lock);
17771 -               raw_spin_lock(&rt_rq->rt_runtime_lock);
17772 -               /*
17773 -                * Either we're all inf and nobody needs to borrow, or we're
17774 -                * already disabled and thus have nothing to do, or we have
17775 -                * exactly the right amount of runtime to take out.
17776 -                */
17777 -               if (rt_rq->rt_runtime == RUNTIME_INF ||
17778 -                               rt_rq->rt_runtime == rt_b->rt_runtime)
17779 -                       goto balanced;
17780 -               raw_spin_unlock(&rt_rq->rt_runtime_lock);
17781 -
17782 -               /*
17783 -                * Calculate the difference between what we started out with
17784 -                * and what we current have, that's the amount of runtime
17785 -                * we lend and now have to reclaim.
17786 -                */
17787 -               want = rt_b->rt_runtime - rt_rq->rt_runtime;
17788 -
17789 -               /*
17790 -                * Greedy reclaim, take back as much as we can.
17791 -                */
17792 -               for_each_cpu(i, rd->span) {
17793 -                       struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
17794 -                       s64 diff;
17795 -
17796 -                       /*
17797 -                        * Can't reclaim from ourselves or disabled runqueues.
17798 -                        */
17799 -                       if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF)
17800 -                               continue;
17801 -
17802 -                       raw_spin_lock(&iter->rt_runtime_lock);
17803 -                       if (want > 0) {
17804 -                               diff = min_t(s64, iter->rt_runtime, want);
17805 -                               iter->rt_runtime -= diff;
17806 -                               want -= diff;
17807 -                       } else {
17808 -                               iter->rt_runtime -= want;
17809 -                               want -= want;
17810 -                       }
17811 -                       raw_spin_unlock(&iter->rt_runtime_lock);
17812 -
17813 -                       if (!want)
17814 -                               break;
17815 -               }
17816 -
17817 -               raw_spin_lock(&rt_rq->rt_runtime_lock);
17818 -               /*
17819 -                * We cannot be left wanting - that would mean some runtime
17820 -                * leaked out of the system.
17821 -                */
17822 -               BUG_ON(want);
17823 -balanced:
17824 -               /*
17825 -                * Disable all the borrow logic by pretending we have inf
17826 -                * runtime - in which case borrowing doesn't make sense.
17827 -                */
17828 -               rt_rq->rt_runtime = RUNTIME_INF;
17829 -               raw_spin_unlock(&rt_rq->rt_runtime_lock);
17830 -               raw_spin_unlock(&rt_b->rt_runtime_lock);
17831 +               struct sched_bandwidth *sched_b = sched_rt_bandwidth(rt_rq);
17832 +               __disable_runtime(rq, sched_b, &rt_rq->rq_bandwidth, 1);
17833         }
17834  }
17835  
17836 -static void disable_runtime(struct rq *rq)
17837 -{
17838 -       unsigned long flags;
17839 -
17840 -       raw_spin_lock_irqsave(&rq->lock, flags);
17841 -       __disable_runtime(rq);
17842 -       raw_spin_unlock_irqrestore(&rq->lock, flags);
17843 -}
17844 -
17845 -static void __enable_runtime(struct rq *rq)
17846 +void enable_runtime_rt(struct rq *rq)
17847  {
17848         struct rt_rq *rt_rq;
17849  
17850 @@ -470,76 +314,44 @@ static void __enable_runtime(struct rq *
17851          * Reset each runqueue's bandwidth settings
17852          */
17853         for_each_leaf_rt_rq(rt_rq, rq) {
17854 -               struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
17855 -
17856 -               raw_spin_lock(&rt_b->rt_runtime_lock);
17857 -               raw_spin_lock(&rt_rq->rt_runtime_lock);
17858 -               rt_rq->rt_runtime = rt_b->rt_runtime;
17859 -               rt_rq->rt_time = 0;
17860 -               rt_rq->rt_throttled = 0;
17861 -               raw_spin_unlock(&rt_rq->rt_runtime_lock);
17862 -               raw_spin_unlock(&rt_b->rt_runtime_lock);
17863 +               struct sched_bandwidth *sched_b = sched_rt_bandwidth(rt_rq);
17864 +               __enable_runtime(sched_b, &rt_rq->rq_bandwidth);
17865         }
17866  }
17867  
17868 -static void enable_runtime(struct rq *rq)
17869 -{
17870 -       unsigned long flags;
17871 -
17872 -       raw_spin_lock_irqsave(&rq->lock, flags);
17873 -       __enable_runtime(rq);
17874 -       raw_spin_unlock_irqrestore(&rq->lock, flags);
17875 -}
17876 -
17877 -static int balance_runtime(struct rt_rq *rt_rq)
17878 -{
17879 -       int more = 0;
17880 -
17881 -       if (rt_rq->rt_time > rt_rq->rt_runtime) {
17882 -               raw_spin_unlock(&rt_rq->rt_runtime_lock);
17883 -               more = do_balance_runtime(rt_rq);
17884 -               raw_spin_lock(&rt_rq->rt_runtime_lock);
17885 -       }
17886 -
17887 -       return more;
17888 -}
17889 -#else /* !CONFIG_SMP */
17890 -static inline int balance_runtime(struct rt_rq *rt_rq)
17891 -{
17892 -       return 0;
17893 -}
17894 -#endif /* CONFIG_SMP */
17895 +#endif
17896  
17897 -static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun)
17898 +static int do_sched_rt_period_timer(struct sched_bandwidth *rt_b, int overrun)
17899  {
17900         int i, idle = 1;
17901         const struct cpumask *span;
17902  
17903 -       if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
17904 +       if (!rt_bandwidth_enabled() || rt_b->runtime == RUNTIME_INF)
17905                 return 1;
17906  
17907 -       span = sched_rt_period_mask();
17908 +       span = sched_bw_period_mask();
17909         for_each_cpu(i, span) {
17910                 int enqueue = 0;
17911                 struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
17912                 struct rq *rq = rq_of_rt_rq(rt_rq);
17913  
17914                 raw_spin_lock(&rq->lock);
17915 -               if (rt_rq->rt_time) {
17916 +               if (rt_rq->rq_bandwidth.time) {
17917                         u64 runtime;
17918  
17919 -                       raw_spin_lock(&rt_rq->rt_runtime_lock);
17920 -                       if (rt_rq->rt_throttled)
17921 -                               balance_runtime(rt_rq);
17922 -                       runtime = rt_rq->rt_runtime;
17923 -                       rt_rq->rt_time -= min(rt_rq->rt_time, overrun*runtime);
17924 -                       if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) {
17925 -                               rt_rq->rt_throttled = 0;
17926 +                       raw_spin_lock(&rt_rq->rq_bandwidth.runtime_lock);
17927 +                       if (rt_rq->rq_bandwidth.throttled)
17928 +                               balance_runtime(&rt_rq->rq_bandwidth,
17929 +                                       sched_rt_bandwidth(rt_rq), 1);
17930 +                       runtime = rt_rq->rq_bandwidth.runtime;
17931 +                       rt_rq->rq_bandwidth.time -= min(rt_rq->rq_bandwidth.time, overrun*runtime);
17932 +                       if (rt_rq->rq_bandwidth.throttled && rt_rq->rq_bandwidth.time < runtime) {
17933 +                               rt_rq->rq_bandwidth.throttled = 0;
17934                                 enqueue = 1;
17935                         }
17936 -                       if (rt_rq->rt_time || rt_rq->rt_nr_running)
17937 +                       if (rt_rq->rq_bandwidth.time || rt_rq->rt_nr_running)
17938                                 idle = 0;
17939 -                       raw_spin_unlock(&rt_rq->rt_runtime_lock);
17940 +                       raw_spin_unlock(&rt_rq->rq_bandwidth.runtime_lock);
17941                 } else if (rt_rq->rt_nr_running)
17942                         idle = 0;
17943  
17944 @@ -567,19 +379,19 @@ static int sched_rt_runtime_exceeded(str
17945  {
17946         u64 runtime = sched_rt_runtime(rt_rq);
17947  
17948 -       if (rt_rq->rt_throttled)
17949 +       if (rt_rq->rq_bandwidth.throttled)
17950                 return rt_rq_throttled(rt_rq);
17951  
17952         if (sched_rt_runtime(rt_rq) >= sched_rt_period(rt_rq))
17953                 return 0;
17954  
17955 -       balance_runtime(rt_rq);
17956 +       balance_runtime(&rt_rq->rq_bandwidth, sched_rt_bandwidth(rt_rq), 1);
17957         runtime = sched_rt_runtime(rt_rq);
17958         if (runtime == RUNTIME_INF)
17959                 return 0;
17960  
17961 -       if (rt_rq->rt_time > runtime) {
17962 -               rt_rq->rt_throttled = 1;
17963 +       if (rt_rq->rq_bandwidth.time > runtime) {
17964 +               rt_rq->rq_bandwidth.throttled = 1;
17965                 if (rt_rq_throttled(rt_rq)) {
17966                         sched_rt_rq_dequeue(rt_rq);
17967                         return 1;
17968 @@ -624,11 +436,11 @@ static void update_curr_rt(struct rq *rq
17969                 rt_rq = rt_rq_of_se(rt_se);
17970  
17971                 if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
17972 -                       raw_spin_lock(&rt_rq->rt_runtime_lock);
17973 -                       rt_rq->rt_time += delta_exec;
17974 +                       raw_spin_lock(&rt_rq->rq_bandwidth.runtime_lock);
17975 +                       rt_rq->rq_bandwidth.time += delta_exec;
17976                         if (sched_rt_runtime_exceeded(rt_rq))
17977                                 resched_task(curr);
17978 -                       raw_spin_unlock(&rt_rq->rt_runtime_lock);
17979 +                       raw_spin_unlock(&rt_rq->rq_bandwidth.runtime_lock);
17980                 }
17981         }
17982  }
17983 @@ -753,7 +565,7 @@ inc_rt_group(struct sched_rt_entity *rt_
17984                 rt_rq->rt_nr_boosted++;
17985  
17986         if (rt_rq->tg)
17987 -               start_rt_bandwidth(&rt_rq->tg->rt_bandwidth);
17988 +               start_sched_bandwidth(&rt_rq->tg->rt_bandwidth, 1);
17989  }
17990  
17991  static void
17992 @@ -770,7 +582,7 @@ dec_rt_group(struct sched_rt_entity *rt_
17993  static void
17994  inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
17995  {
17996 -       start_rt_bandwidth(&def_rt_bandwidth);
17997 +       start_sched_bandwidth(&def_rt_bandwidth, 1);
17998  }
17999  
18000  static inline
18001 @@ -1551,7 +1363,7 @@ static void rq_online_rt(struct rq *rq)
18002         if (rq->rt.overloaded)
18003                 rt_set_overload(rq);
18004  
18005 -       __enable_runtime(rq);
18006 +       enable_runtime_rt(rq);
18007  
18008         cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
18009  }
18010 @@ -1562,7 +1374,7 @@ static void rq_offline_rt(struct rq *rq)
18011         if (rq->rt.overloaded)
18012                 rt_clear_overload(rq);
18013  
18014 -       __disable_runtime(rq);
18015 +       disable_runtime_rt(rq);
18016  
18017         cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
18018  }
18019 diff -NurpP --minimal linux-2.6.33/kernel/signal.c linux-2.6.33-vs2.3.0.36.30.1/kernel/signal.c
18020 --- linux-2.6.33/kernel/signal.c        2010-02-25 11:52:09.000000000 +0100
18021 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/signal.c        2010-02-25 13:10:38.000000000 +0100
18022 @@ -28,6 +28,8 @@
18023  #include <linux/freezer.h>
18024  #include <linux/pid_namespace.h>
18025  #include <linux/nsproxy.h>
18026 +#include <linux/vs_context.h>
18027 +#include <linux/vs_pid.h>
18028  #define CREATE_TRACE_POINTS
18029  #include <trace/events/signal.h>
18030  
18031 @@ -629,9 +631,18 @@ static int check_kill_permission(int sig
18032         struct pid *sid;
18033         int error;
18034  
18035 +       vxdprintk(VXD_CBIT(misc, 7),
18036 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
18037 +               sig, info, t, vx_task_xid(t), t->pid);
18038 +
18039         if (!valid_signal(sig))
18040                 return -EINVAL;
18041  
18042 +/*     FIXME: needed? if so, why?
18043 +       if ((info != SEND_SIG_NOINFO) &&
18044 +               (is_si_special(info) || !si_fromuser(info)))
18045 +               goto skip;      */
18046 +
18047         if (!si_fromuser(info))
18048                 return 0;
18049  
18050 @@ -659,6 +670,20 @@ static int check_kill_permission(int sig
18051                 }
18052         }
18053  
18054 +       error = -EPERM;
18055 +       if (t->pid == 1 && current->xid)
18056 +               return error;
18057 +
18058 +       error = -ESRCH;
18059 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
18060 +                 loops, maybe ENOENT or EACCES? */
18061 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
18062 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
18063 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
18064 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
18065 +               return error;
18066 +       }
18067 +skip:
18068         return security_task_kill(t, info, sig, 0);
18069  }
18070  
18071 @@ -1147,7 +1172,7 @@ int kill_pid_info(int sig, struct siginf
18072         rcu_read_lock();
18073  retry:
18074         p = pid_task(pid, PIDTYPE_PID);
18075 -       if (p) {
18076 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
18077                 error = group_send_sig_info(sig, info, p);
18078                 if (unlikely(error == -ESRCH))
18079                         /*
18080 @@ -1187,7 +1212,7 @@ int kill_pid_info_as_uid(int sig, struct
18081  
18082         rcu_read_lock();
18083         p = pid_task(pid, PIDTYPE_PID);
18084 -       if (!p) {
18085 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
18086                 ret = -ESRCH;
18087                 goto out_unlock;
18088         }
18089 @@ -1242,8 +1267,10 @@ static int kill_something_info(int sig, 
18090                 struct task_struct * p;
18091  
18092                 for_each_process(p) {
18093 -                       if (task_pid_vnr(p) > 1 &&
18094 -                                       !same_thread_group(p, current)) {
18095 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
18096 +                               task_pid_vnr(p) > 1 &&
18097 +                               !same_thread_group(p, current) &&
18098 +                               !vx_current_initpid(p->pid)) {
18099                                 int err = group_send_sig_info(sig, info, p);
18100                                 ++count;
18101                                 if (err != -EPERM)
18102 @@ -1910,6 +1937,11 @@ relock:
18103                                 !sig_kernel_only(signr))
18104                         continue;
18105  
18106 +               /* virtual init is protected against user signals */
18107 +               if ((info->si_code == SI_USER) &&
18108 +                       vx_current_initpid(current->pid))
18109 +                       continue;
18110 +
18111                 if (sig_kernel_stop(signr)) {
18112                         /*
18113                          * The default action is to stop all threads in
18114 diff -NurpP --minimal linux-2.6.33/kernel/softirq.c linux-2.6.33-vs2.3.0.36.30.1/kernel/softirq.c
18115 --- linux-2.6.33/kernel/softirq.c       2010-02-25 11:52:09.000000000 +0100
18116 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/softirq.c       2010-02-25 12:02:16.000000000 +0100
18117 @@ -24,6 +24,7 @@
18118  #include <linux/ftrace.h>
18119  #include <linux/smp.h>
18120  #include <linux/tick.h>
18121 +#include <linux/vs_context.h>
18122  
18123  #define CREATE_TRACE_POINTS
18124  #include <trace/events/irq.h>
18125 diff -NurpP --minimal linux-2.6.33/kernel/sys.c linux-2.6.33-vs2.3.0.36.30.1/kernel/sys.c
18126 --- linux-2.6.33/kernel/sys.c   2010-02-25 11:52:09.000000000 +0100
18127 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/sys.c   2010-02-25 13:13:03.000000000 +0100
18128 @@ -40,6 +40,7 @@
18129  #include <linux/syscalls.h>
18130  #include <linux/kprobes.h>
18131  #include <linux/user_namespace.h>
18132 +#include <linux/vs_pid.h>
18133  
18134  #include <asm/uaccess.h>
18135  #include <asm/io.h>
18136 @@ -129,7 +130,10 @@ static int set_one_prio(struct task_stru
18137                 goto out;
18138         }
18139         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
18140 -               error = -EACCES;
18141 +               if (vx_flags(VXF_IGNEG_NICE, 0))
18142 +                       error = 0;
18143 +               else
18144 +                       error = -EACCES;
18145                 goto out;
18146         }
18147         no_nice = security_task_setnice(p, niceval);
18148 @@ -179,6 +183,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
18149                         else
18150                                 pgrp = task_pgrp(current);
18151                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
18152 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
18153 +                                       continue;
18154                                 error = set_one_prio(p, niceval, error);
18155                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
18156                         break;
18157 @@ -242,6 +248,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
18158                         else
18159                                 pgrp = task_pgrp(current);
18160                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
18161 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
18162 +                                       continue;
18163                                 niceval = 20 - task_nice(p);
18164                                 if (niceval > retval)
18165                                         retval = niceval;
18166 @@ -355,6 +363,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
18167  
18168  static DEFINE_MUTEX(reboot_mutex);
18169  
18170 +long vs_reboot(unsigned int, void __user *);
18171 +
18172  /*
18173   * Reboot system call: for obvious reasons only root may call it,
18174   * and even root needs to set up some magic numbers in the registers
18175 @@ -387,6 +397,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
18176         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
18177                 cmd = LINUX_REBOOT_CMD_HALT;
18178  
18179 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
18180 +               return vs_reboot(cmd, arg);
18181 +
18182         mutex_lock(&reboot_mutex);
18183         switch (cmd) {
18184         case LINUX_REBOOT_CMD_RESTART:
18185 @@ -1136,7 +1149,7 @@ SYSCALL_DEFINE2(sethostname, char __user
18186         int errno;
18187         char tmp[__NEW_UTS_LEN];
18188  
18189 -       if (!capable(CAP_SYS_ADMIN))
18190 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
18191                 return -EPERM;
18192         if (len < 0 || len > __NEW_UTS_LEN)
18193                 return -EINVAL;
18194 @@ -1185,7 +1198,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
18195         int errno;
18196         char tmp[__NEW_UTS_LEN];
18197  
18198 -       if (!capable(CAP_SYS_ADMIN))
18199 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
18200                 return -EPERM;
18201         if (len < 0 || len > __NEW_UTS_LEN)
18202                 return -EINVAL;
18203 @@ -1254,7 +1267,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
18204                 return -EINVAL;
18205         old_rlim = current->signal->rlim + resource;
18206         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
18207 -           !capable(CAP_SYS_RESOURCE))
18208 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
18209                 return -EPERM;
18210         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
18211                 return -EPERM;
18212 diff -NurpP --minimal linux-2.6.33/kernel/sysctl_binary.c linux-2.6.33-vs2.3.0.36.30.1/kernel/sysctl_binary.c
18213 --- linux-2.6.33/kernel/sysctl_binary.c 2010-02-25 11:52:09.000000000 +0100
18214 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/sysctl_binary.c 2010-02-25 12:40:06.000000000 +0100
18215 @@ -71,6 +71,7 @@ static const struct bin_table bin_kern_t
18216  
18217         { CTL_INT,      KERN_PANIC,                     "panic" },
18218         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
18219 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
18220  
18221         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
18222         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
18223 diff -NurpP --minimal linux-2.6.33/kernel/sysctl.c linux-2.6.33-vs2.3.0.36.30.1/kernel/sysctl.c
18224 --- linux-2.6.33/kernel/sysctl.c        2010-02-25 11:52:09.000000000 +0100
18225 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/sysctl.c        2010-02-25 14:43:48.000000000 +0100
18226 @@ -123,6 +123,7 @@ static int ngroups_max = NGROUPS_MAX;
18227  extern char modprobe_path[];
18228  extern int modules_disabled;
18229  #endif
18230 +extern char vshelper_path[];
18231  #ifdef CONFIG_CHR_DEV_SG
18232  extern int sg_big_buff;
18233  #endif
18234 @@ -553,6 +554,13 @@ static struct ctl_table kern_table[] = {
18235                 .proc_handler   = proc_dostring,
18236         },
18237  #endif
18238 +       {
18239 +               .procname       = "vshelper",
18240 +               .data           = &vshelper_path,
18241 +               .maxlen         = 256,
18242 +               .mode           = 0644,
18243 +               .proc_handler   = &proc_dostring,
18244 +       },
18245  #ifdef CONFIG_CHR_DEV_SG
18246         {
18247                 .procname       = "sg-big-buff",
18248 diff -NurpP --minimal linux-2.6.33/kernel/time.c linux-2.6.33-vs2.3.0.36.30.1/kernel/time.c
18249 --- linux-2.6.33/kernel/time.c  2010-02-25 11:52:09.000000000 +0100
18250 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/time.c  2010-02-25 12:02:16.000000000 +0100
18251 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
18252  SYSCALL_DEFINE1(time, time_t __user *, tloc)
18253  {
18254         time_t i = get_seconds();
18255 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
18256  
18257         if (tloc) {
18258                 if (put_user(i,tloc))
18259 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
18260         if (err)
18261                 return err;
18262  
18263 -       do_settimeofday(&tv);
18264 +       vx_settimeofday(&tv);
18265         return 0;
18266  }
18267  
18268 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
18269  {
18270         if (likely(tv != NULL)) {
18271                 struct timeval ktv;
18272 -               do_gettimeofday(&ktv);
18273 +               vx_gettimeofday(&ktv);
18274                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
18275                         return -EFAULT;
18276         }
18277 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
18278                 /* SMP safe, again the code in arch/foo/time.c should
18279                  * globally block out interrupts when it runs.
18280                  */
18281 -               return do_settimeofday(tv);
18282 +               return vx_settimeofday(tv);
18283         }
18284         return 0;
18285  }
18286 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
18287  {
18288         struct timeval x;
18289  
18290 -       do_gettimeofday(&x);
18291 +       vx_gettimeofday(&x);
18292         tv->tv_sec = x.tv_sec;
18293         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
18294  }
18295 diff -NurpP --minimal linux-2.6.33/kernel/timer.c linux-2.6.33-vs2.3.0.36.30.1/kernel/timer.c
18296 --- linux-2.6.33/kernel/timer.c 2010-02-25 11:52:09.000000000 +0100
18297 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/timer.c 2010-02-25 12:02:16.000000000 +0100
18298 @@ -39,6 +39,10 @@
18299  #include <linux/kallsyms.h>
18300  #include <linux/perf_event.h>
18301  #include <linux/sched.h>
18302 +#include <linux/vs_base.h>
18303 +#include <linux/vs_cvirt.h>
18304 +#include <linux/vs_pid.h>
18305 +#include <linux/vserver/sched.h>
18306  
18307  #include <asm/uaccess.h>
18308  #include <asm/unistd.h>
18309 @@ -1252,12 +1256,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
18310  
18311  #endif
18312  
18313 -#ifndef __alpha__
18314 -
18315 -/*
18316 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
18317 - * should be moved into arch/i386 instead?
18318 - */
18319  
18320  /**
18321   * sys_getpid - return the thread group id of the current process
18322 @@ -1286,10 +1284,23 @@ SYSCALL_DEFINE0(getppid)
18323         rcu_read_lock();
18324         pid = task_tgid_vnr(current->real_parent);
18325         rcu_read_unlock();
18326 +       return vx_map_pid(pid);
18327 +}
18328  
18329 -       return pid;
18330 +#ifdef __alpha__
18331 +
18332 +/*
18333 + * The Alpha uses getxpid, getxuid, and getxgid instead.
18334 + */
18335 +
18336 +asmlinkage long do_getxpid(long *ppid)
18337 +{
18338 +       *ppid = sys_getppid();
18339 +       return sys_getpid();
18340  }
18341  
18342 +#else /* _alpha_ */
18343 +
18344  SYSCALL_DEFINE0(getuid)
18345  {
18346         /* Only we change this so SMP safe */
18347 diff -NurpP --minimal linux-2.6.33/kernel/user.c linux-2.6.33-vs2.3.0.36.30.1/kernel/user.c
18348 --- linux-2.6.33/kernel/user.c  2009-12-03 20:02:58.000000000 +0100
18349 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/user.c  2010-02-25 12:02:16.000000000 +0100
18350 @@ -251,10 +251,10 @@ static struct kobj_type uids_ktype = {
18351   *
18352   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
18353   */
18354 -static int uids_user_create(struct user_struct *up)
18355 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
18356  {
18357         struct kobject *kobj = &up->kobj;
18358 -       int error;
18359 +       int error = 0;
18360  
18361         memset(kobj, 0, sizeof(struct kobject));
18362         if (up->user_ns != &init_user_ns)
18363 @@ -282,7 +282,7 @@ int __init uids_sysfs_init(void)
18364         if (!uids_kset)
18365                 return -ENOMEM;
18366  
18367 -       return uids_user_create(&root_user);
18368 +       return uids_user_create(NULL, &root_user);
18369  }
18370  
18371  /* delayed work function to remove sysfs directory for a user and free up
18372 @@ -353,7 +353,8 @@ static struct user_struct *uid_hash_find
18373  }
18374  
18375  int uids_sysfs_init(void) { return 0; }
18376 -static inline int uids_user_create(struct user_struct *up) { return 0; }
18377 +static inline int uids_user_create(struct user_namespace *ns,
18378 +       struct user_struct *up) { return 0; }
18379  static inline void uids_mutex_lock(void) { }
18380  static inline void uids_mutex_unlock(void) { }
18381  
18382 @@ -450,7 +451,7 @@ struct user_struct *alloc_uid(struct use
18383  
18384                 new->user_ns = get_user_ns(ns);
18385  
18386 -               if (uids_user_create(new))
18387 +               if (uids_user_create(ns, new))
18388                         goto out_destoy_sched;
18389  
18390                 /*
18391 diff -NurpP --minimal linux-2.6.33/kernel/user_namespace.c linux-2.6.33-vs2.3.0.36.30.1/kernel/user_namespace.c
18392 --- linux-2.6.33/kernel/user_namespace.c        2009-03-24 14:22:45.000000000 +0100
18393 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/user_namespace.c        2010-02-25 12:02:16.000000000 +0100
18394 @@ -10,6 +10,7 @@
18395  #include <linux/slab.h>
18396  #include <linux/user_namespace.h>
18397  #include <linux/cred.h>
18398 +#include <linux/vserver/global.h>
18399  
18400  /*
18401   * Create a new user namespace, deriving the creator from the user in the
18402 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
18403                 return -ENOMEM;
18404  
18405         kref_init(&ns->kref);
18406 +       atomic_inc(&vs_global_user_ns);
18407  
18408         for (n = 0; n < UIDHASH_SZ; ++n)
18409                 INIT_HLIST_HEAD(ns->uidhash_table + n);
18410 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
18411         struct user_namespace *ns =
18412                 container_of(kref, struct user_namespace, kref);
18413  
18414 +       /* FIXME: maybe move into destroyer? */
18415 +       atomic_dec(&vs_global_user_ns);
18416         INIT_WORK(&ns->destroyer, free_user_ns_work);
18417         schedule_work(&ns->destroyer);
18418  }
18419 diff -NurpP --minimal linux-2.6.33/kernel/utsname.c linux-2.6.33-vs2.3.0.36.30.1/kernel/utsname.c
18420 --- linux-2.6.33/kernel/utsname.c       2009-09-10 15:26:28.000000000 +0200
18421 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/utsname.c       2010-02-25 12:02:16.000000000 +0100
18422 @@ -14,14 +14,17 @@
18423  #include <linux/utsname.h>
18424  #include <linux/err.h>
18425  #include <linux/slab.h>
18426 +#include <linux/vserver/global.h>
18427  
18428  static struct uts_namespace *create_uts_ns(void)
18429  {
18430         struct uts_namespace *uts_ns;
18431  
18432         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
18433 -       if (uts_ns)
18434 +       if (uts_ns) {
18435                 kref_init(&uts_ns->kref);
18436 +               atomic_inc(&vs_global_uts_ns);
18437 +       }
18438         return uts_ns;
18439  }
18440  
18441 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
18442         struct uts_namespace *ns;
18443  
18444         ns = container_of(kref, struct uts_namespace, kref);
18445 +       atomic_dec(&vs_global_uts_ns);
18446         kfree(ns);
18447  }
18448 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cacct.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cacct.c
18449 --- linux-2.6.33/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
18450 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cacct.c 2010-02-25 12:02:16.000000000 +0100
18451 @@ -0,0 +1,42 @@
18452 +/*
18453 + *  linux/kernel/vserver/cacct.c
18454 + *
18455 + *  Virtual Server: Context Accounting
18456 + *
18457 + *  Copyright (C) 2006-2007 Herbert Pötzl
18458 + *
18459 + *  V0.01  added accounting stats
18460 + *
18461 + */
18462 +
18463 +#include <linux/types.h>
18464 +#include <linux/vs_context.h>
18465 +#include <linux/vserver/cacct_cmd.h>
18466 +#include <linux/vserver/cacct_int.h>
18467 +
18468 +#include <asm/errno.h>
18469 +#include <asm/uaccess.h>
18470 +
18471 +
18472 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
18473 +{
18474 +       struct vcmd_sock_stat_v0 vc_data;
18475 +       int j, field;
18476 +
18477 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18478 +               return -EFAULT;
18479 +
18480 +       field = vc_data.field;
18481 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
18482 +               return -EINVAL;
18483 +
18484 +       for (j = 0; j < 3; j++) {
18485 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
18486 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
18487 +       }
18488 +
18489 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18490 +               return -EFAULT;
18491 +       return 0;
18492 +}
18493 +
18494 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cacct_init.h linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cacct_init.h
18495 --- linux-2.6.33/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
18496 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cacct_init.h    2010-02-25 12:02:16.000000000 +0100
18497 @@ -0,0 +1,25 @@
18498 +
18499 +
18500 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
18501 +{
18502 +       int i, j;
18503 +
18504 +
18505 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
18506 +               for (j = 0; j < 3; j++) {
18507 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
18508 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
18509 +               }
18510 +       }
18511 +       for (i = 0; i < 8; i++)
18512 +               atomic_set(&cacct->slab[i], 0);
18513 +       for (i = 0; i < 5; i++)
18514 +               for (j = 0; j < 4; j++)
18515 +                       atomic_set(&cacct->page[i][j], 0);
18516 +}
18517 +
18518 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
18519 +{
18520 +       return;
18521 +}
18522 +
18523 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cacct_proc.h linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cacct_proc.h
18524 --- linux-2.6.33/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
18525 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cacct_proc.h    2010-02-25 12:02:16.000000000 +0100
18526 @@ -0,0 +1,53 @@
18527 +#ifndef _VX_CACCT_PROC_H
18528 +#define _VX_CACCT_PROC_H
18529 +
18530 +#include <linux/vserver/cacct_int.h>
18531 +
18532 +
18533 +#define VX_SOCKA_TOP   \
18534 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
18535 +
18536 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
18537 +{
18538 +       int i, j, length = 0;
18539 +       static char *type[VXA_SOCK_SIZE] = {
18540 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
18541 +       };
18542 +
18543 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
18544 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
18545 +               length += sprintf(buffer + length, "%s:", type[i]);
18546 +               for (j = 0; j < 3; j++) {
18547 +                       length += sprintf(buffer + length,
18548 +                               "\t%10lu/%-10lu",
18549 +                               vx_sock_count(cacct, i, j),
18550 +                               vx_sock_total(cacct, i, j));
18551 +               }
18552 +               buffer[length++] = '\n';
18553 +       }
18554 +
18555 +       length += sprintf(buffer + length, "\n");
18556 +       length += sprintf(buffer + length,
18557 +               "slab:\t %8u %8u %8u %8u\n",
18558 +               atomic_read(&cacct->slab[1]),
18559 +               atomic_read(&cacct->slab[4]),
18560 +               atomic_read(&cacct->slab[0]),
18561 +               atomic_read(&cacct->slab[2]));
18562 +
18563 +       length += sprintf(buffer + length, "\n");
18564 +       for (i = 0; i < 5; i++) {
18565 +               length += sprintf(buffer + length,
18566 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
18567 +                       atomic_read(&cacct->page[i][0]),
18568 +                       atomic_read(&cacct->page[i][1]),
18569 +                       atomic_read(&cacct->page[i][2]),
18570 +                       atomic_read(&cacct->page[i][3]),
18571 +                       atomic_read(&cacct->page[i][4]),
18572 +                       atomic_read(&cacct->page[i][5]),
18573 +                       atomic_read(&cacct->page[i][6]),
18574 +                       atomic_read(&cacct->page[i][7]));
18575 +       }
18576 +       return length;
18577 +}
18578 +
18579 +#endif /* _VX_CACCT_PROC_H */
18580 diff -NurpP --minimal linux-2.6.33/kernel/vserver/context.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/context.c
18581 --- linux-2.6.33/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
18582 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/context.c       2010-02-25 12:02:16.000000000 +0100
18583 @@ -0,0 +1,1057 @@
18584 +/*
18585 + *  linux/kernel/vserver/context.c
18586 + *
18587 + *  Virtual Server: Context Support
18588 + *
18589 + *  Copyright (C) 2003-2007  Herbert Pötzl
18590 + *
18591 + *  V0.01  context helper
18592 + *  V0.02  vx_ctx_kill syscall command
18593 + *  V0.03  replaced context_info calls
18594 + *  V0.04  redesign of struct (de)alloc
18595 + *  V0.05  rlimit basic implementation
18596 + *  V0.06  task_xid and info commands
18597 + *  V0.07  context flags and caps
18598 + *  V0.08  switch to RCU based hash
18599 + *  V0.09  revert to non RCU for now
18600 + *  V0.10  and back to working RCU hash
18601 + *  V0.11  and back to locking again
18602 + *  V0.12  referenced context store
18603 + *  V0.13  separate per cpu data
18604 + *  V0.14  changed vcmds to vxi arg
18605 + *  V0.15  added context stat
18606 + *  V0.16  have __create claim() the vxi
18607 + *  V0.17  removed older and legacy stuff
18608 + *
18609 + */
18610 +
18611 +#include <linux/slab.h>
18612 +#include <linux/types.h>
18613 +#include <linux/security.h>
18614 +#include <linux/pid_namespace.h>
18615 +
18616 +#include <linux/vserver/context.h>
18617 +#include <linux/vserver/network.h>
18618 +#include <linux/vserver/debug.h>
18619 +#include <linux/vserver/limit.h>
18620 +#include <linux/vserver/limit_int.h>
18621 +#include <linux/vserver/space.h>
18622 +#include <linux/init_task.h>
18623 +#include <linux/fs_struct.h>
18624 +
18625 +#include <linux/vs_context.h>
18626 +#include <linux/vs_limit.h>
18627 +#include <linux/vs_pid.h>
18628 +#include <linux/vserver/context_cmd.h>
18629 +
18630 +#include "cvirt_init.h"
18631 +#include "cacct_init.h"
18632 +#include "limit_init.h"
18633 +#include "sched_init.h"
18634 +
18635 +
18636 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
18637 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
18638 +
18639 +
18640 +/*     now inactive context structures */
18641 +
18642 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
18643 +
18644 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
18645 +
18646 +
18647 +/*     __alloc_vx_info()
18648 +
18649 +       * allocate an initialized vx_info struct
18650 +       * doesn't make it visible (hash)                        */
18651 +
18652 +static struct vx_info *__alloc_vx_info(xid_t xid)
18653 +{
18654 +       struct vx_info *new = NULL;
18655 +       int cpu, index;
18656 +
18657 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
18658 +
18659 +       /* would this benefit from a slab cache? */
18660 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
18661 +       if (!new)
18662 +               return 0;
18663 +
18664 +       memset(new, 0, sizeof(struct vx_info));
18665 +#ifdef CONFIG_SMP
18666 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
18667 +       if (!new->ptr_pc)
18668 +               goto error;
18669 +#endif
18670 +       new->vx_id = xid;
18671 +       INIT_HLIST_NODE(&new->vx_hlist);
18672 +       atomic_set(&new->vx_usecnt, 0);
18673 +       atomic_set(&new->vx_tasks, 0);
18674 +       new->vx_parent = NULL;
18675 +       new->vx_state = 0;
18676 +       init_waitqueue_head(&new->vx_wait);
18677 +
18678 +       /* prepare reaper */
18679 +       get_task_struct(init_pid_ns.child_reaper);
18680 +       new->vx_reaper = init_pid_ns.child_reaper;
18681 +       new->vx_badness_bias = 0;
18682 +
18683 +       /* rest of init goes here */
18684 +       vx_info_init_limit(&new->limit);
18685 +       vx_info_init_sched(&new->sched);
18686 +       vx_info_init_cvirt(&new->cvirt);
18687 +       vx_info_init_cacct(&new->cacct);
18688 +
18689 +       /* per cpu data structures */
18690 +       for_each_possible_cpu(cpu) {
18691 +               vx_info_init_sched_pc(
18692 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
18693 +               vx_info_init_cvirt_pc(
18694 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
18695 +       }
18696 +
18697 +       new->vx_flags = VXF_INIT_SET;
18698 +       cap_set_init_eff(new->vx_bcaps);
18699 +       new->vx_ccaps = 0;
18700 +       new->vx_umask = 0;
18701 +
18702 +       new->reboot_cmd = 0;
18703 +       new->exit_code = 0;
18704 +
18705 +       // preconfig fs entries
18706 +       for (index = 0; index < VX_SPACES; index++) {
18707 +               write_lock(&init_fs.lock);
18708 +               init_fs.users++;
18709 +               write_unlock(&init_fs.lock);
18710 +               new->vx_fs[index] = &init_fs;
18711 +       }
18712 +
18713 +       vxdprintk(VXD_CBIT(xid, 0),
18714 +               "alloc_vx_info(%d) = %p", xid, new);
18715 +       vxh_alloc_vx_info(new);
18716 +       atomic_inc(&vx_global_ctotal);
18717 +       return new;
18718 +#ifdef CONFIG_SMP
18719 +error:
18720 +       kfree(new);
18721 +       return 0;
18722 +#endif
18723 +}
18724 +
18725 +/*     __dealloc_vx_info()
18726 +
18727 +       * final disposal of vx_info                             */
18728 +
18729 +static void __dealloc_vx_info(struct vx_info *vxi)
18730 +{
18731 +       struct vx_info_save vxis;
18732 +       int cpu;
18733 +
18734 +       vxdprintk(VXD_CBIT(xid, 0),
18735 +               "dealloc_vx_info(%p)", vxi);
18736 +       vxh_dealloc_vx_info(vxi);
18737 +
18738 +#ifdef CONFIG_VSERVER_WARN
18739 +       enter_vx_info(vxi, &vxis);
18740 +       vx_info_exit_limit(&vxi->limit);
18741 +       vx_info_exit_sched(&vxi->sched);
18742 +       vx_info_exit_cvirt(&vxi->cvirt);
18743 +       vx_info_exit_cacct(&vxi->cacct);
18744 +
18745 +       for_each_possible_cpu(cpu) {
18746 +               vx_info_exit_sched_pc(
18747 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
18748 +               vx_info_exit_cvirt_pc(
18749 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
18750 +       }
18751 +       leave_vx_info(&vxis);
18752 +#endif
18753 +
18754 +       vxi->vx_id = -1;
18755 +       vxi->vx_state |= VXS_RELEASED;
18756 +
18757 +#ifdef CONFIG_SMP
18758 +       free_percpu(vxi->ptr_pc);
18759 +#endif
18760 +       kfree(vxi);
18761 +       atomic_dec(&vx_global_ctotal);
18762 +}
18763 +
18764 +static void __shutdown_vx_info(struct vx_info *vxi)
18765 +{
18766 +       struct nsproxy *nsproxy;
18767 +       struct fs_struct *fs;
18768 +       int index, kill;
18769 +
18770 +       might_sleep();
18771 +
18772 +       vxi->vx_state |= VXS_SHUTDOWN;
18773 +       vs_state_change(vxi, VSC_SHUTDOWN);
18774 +
18775 +       for (index = 0; index < VX_SPACES; index++) {
18776 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
18777 +               if (nsproxy)
18778 +                       put_nsproxy(nsproxy);
18779 +
18780 +               fs = xchg(&vxi->vx_fs[index], NULL);
18781 +               write_lock(&fs->lock);
18782 +               kill = !--fs->users;
18783 +               write_unlock(&fs->lock);
18784 +               if (kill)
18785 +                       free_fs_struct(fs);
18786 +       }
18787 +}
18788 +
18789 +/* exported stuff */
18790 +
18791 +void free_vx_info(struct vx_info *vxi)
18792 +{
18793 +       unsigned long flags;
18794 +       unsigned index;
18795 +
18796 +       /* check for reference counts first */
18797 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
18798 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18799 +
18800 +       /* context must not be hashed */
18801 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18802 +
18803 +       /* context shutdown is mandatory */
18804 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
18805 +
18806 +       /* nsproxy and fs check */
18807 +       for (index = 0; index < VX_SPACES; index++) {
18808 +               BUG_ON(vxi->vx_nsproxy[index]);
18809 +               BUG_ON(vxi->vx_fs[index]);
18810 +       }
18811 +
18812 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18813 +       hlist_del(&vxi->vx_hlist);
18814 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18815 +
18816 +       __dealloc_vx_info(vxi);
18817 +}
18818 +
18819 +
18820 +/*     hash table for vx_info hash */
18821 +
18822 +#define VX_HASH_SIZE   13
18823 +
18824 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
18825 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
18826 +
18827 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
18828 +
18829 +
18830 +static inline unsigned int __hashval(xid_t xid)
18831 +{
18832 +       return (xid % VX_HASH_SIZE);
18833 +}
18834 +
18835 +
18836 +
18837 +/*     __hash_vx_info()
18838 +
18839 +       * add the vxi to the global hash table
18840 +       * requires the hash_lock to be held                     */
18841 +
18842 +static inline void __hash_vx_info(struct vx_info *vxi)
18843 +{
18844 +       struct hlist_head *head;
18845 +
18846 +       vxd_assert_lock(&vx_info_hash_lock);
18847 +       vxdprintk(VXD_CBIT(xid, 4),
18848 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
18849 +       vxh_hash_vx_info(vxi);
18850 +
18851 +       /* context must not be hashed */
18852 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18853 +
18854 +       vxi->vx_state |= VXS_HASHED;
18855 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
18856 +       hlist_add_head(&vxi->vx_hlist, head);
18857 +       atomic_inc(&vx_global_cactive);
18858 +}
18859 +
18860 +/*     __unhash_vx_info()
18861 +
18862 +       * remove the vxi from the global hash table
18863 +       * requires the hash_lock to be held                     */
18864 +
18865 +static inline void __unhash_vx_info(struct vx_info *vxi)
18866 +{
18867 +       unsigned long flags;
18868 +
18869 +       vxd_assert_lock(&vx_info_hash_lock);
18870 +       vxdprintk(VXD_CBIT(xid, 4),
18871 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
18872 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
18873 +       vxh_unhash_vx_info(vxi);
18874 +
18875 +       /* context must be hashed */
18876 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
18877 +       /* but without tasks */
18878 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18879 +
18880 +       vxi->vx_state &= ~VXS_HASHED;
18881 +       hlist_del_init(&vxi->vx_hlist);
18882 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18883 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
18884 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18885 +       atomic_dec(&vx_global_cactive);
18886 +}
18887 +
18888 +
18889 +/*     __lookup_vx_info()
18890 +
18891 +       * requires the hash_lock to be held
18892 +       * doesn't increment the vx_refcnt                       */
18893 +
18894 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
18895 +{
18896 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
18897 +       struct hlist_node *pos;
18898 +       struct vx_info *vxi;
18899 +
18900 +       vxd_assert_lock(&vx_info_hash_lock);
18901 +       hlist_for_each(pos, head) {
18902 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18903 +
18904 +               if (vxi->vx_id == xid)
18905 +                       goto found;
18906 +       }
18907 +       vxi = NULL;
18908 +found:
18909 +       vxdprintk(VXD_CBIT(xid, 0),
18910 +               "__lookup_vx_info(#%u): %p[#%u]",
18911 +               xid, vxi, vxi ? vxi->vx_id : 0);
18912 +       vxh_lookup_vx_info(vxi, xid);
18913 +       return vxi;
18914 +}
18915 +
18916 +
18917 +/*     __create_vx_info()
18918 +
18919 +       * create the requested context
18920 +       * get(), claim() and hash it                            */
18921 +
18922 +static struct vx_info *__create_vx_info(int id)
18923 +{
18924 +       struct vx_info *new, *vxi = NULL;
18925 +
18926 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
18927 +
18928 +       if (!(new = __alloc_vx_info(id)))
18929 +               return ERR_PTR(-ENOMEM);
18930 +
18931 +       /* required to make dynamic xids unique */
18932 +       spin_lock(&vx_info_hash_lock);
18933 +
18934 +       /* static context requested */
18935 +       if ((vxi = __lookup_vx_info(id))) {
18936 +               vxdprintk(VXD_CBIT(xid, 0),
18937 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
18938 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18939 +                       vxi = ERR_PTR(-EBUSY);
18940 +               else
18941 +                       vxi = ERR_PTR(-EEXIST);
18942 +               goto out_unlock;
18943 +       }
18944 +       /* new context */
18945 +       vxdprintk(VXD_CBIT(xid, 0),
18946 +               "create_vx_info(%d) = %p (new)", id, new);
18947 +       claim_vx_info(new, NULL);
18948 +       __hash_vx_info(get_vx_info(new));
18949 +       vxi = new, new = NULL;
18950 +
18951 +out_unlock:
18952 +       spin_unlock(&vx_info_hash_lock);
18953 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
18954 +       if (new)
18955 +               __dealloc_vx_info(new);
18956 +       return vxi;
18957 +}
18958 +
18959 +
18960 +/*     exported stuff                                          */
18961 +
18962 +
18963 +void unhash_vx_info(struct vx_info *vxi)
18964 +{
18965 +       __shutdown_vx_info(vxi);
18966 +       spin_lock(&vx_info_hash_lock);
18967 +       __unhash_vx_info(vxi);
18968 +       spin_unlock(&vx_info_hash_lock);
18969 +       __wakeup_vx_info(vxi);
18970 +}
18971 +
18972 +
18973 +/*     lookup_vx_info()
18974 +
18975 +       * search for a vx_info and get() it
18976 +       * negative id means current                             */
18977 +
18978 +struct vx_info *lookup_vx_info(int id)
18979 +{
18980 +       struct vx_info *vxi = NULL;
18981 +
18982 +       if (id < 0) {
18983 +               vxi = get_vx_info(current_vx_info());
18984 +       } else if (id > 1) {
18985 +               spin_lock(&vx_info_hash_lock);
18986 +               vxi = get_vx_info(__lookup_vx_info(id));
18987 +               spin_unlock(&vx_info_hash_lock);
18988 +       }
18989 +       return vxi;
18990 +}
18991 +
18992 +/*     xid_is_hashed()
18993 +
18994 +       * verify that xid is still hashed                       */
18995 +
18996 +int xid_is_hashed(xid_t xid)
18997 +{
18998 +       int hashed;
18999 +
19000 +       spin_lock(&vx_info_hash_lock);
19001 +       hashed = (__lookup_vx_info(xid) != NULL);
19002 +       spin_unlock(&vx_info_hash_lock);
19003 +       return hashed;
19004 +}
19005 +
19006 +#ifdef CONFIG_PROC_FS
19007 +
19008 +/*     get_xid_list()
19009 +
19010 +       * get a subset of hashed xids for proc
19011 +       * assumes size is at least one                          */
19012 +
19013 +int get_xid_list(int index, unsigned int *xids, int size)
19014 +{
19015 +       int hindex, nr_xids = 0;
19016 +
19017 +       /* only show current and children */
19018 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
19019 +               if (index > 0)
19020 +                       return 0;
19021 +               xids[nr_xids] = vx_current_xid();
19022 +               return 1;
19023 +       }
19024 +
19025 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
19026 +               struct hlist_head *head = &vx_info_hash[hindex];
19027 +               struct hlist_node *pos;
19028 +
19029 +               spin_lock(&vx_info_hash_lock);
19030 +               hlist_for_each(pos, head) {
19031 +                       struct vx_info *vxi;
19032 +
19033 +                       if (--index > 0)
19034 +                               continue;
19035 +
19036 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
19037 +                       xids[nr_xids] = vxi->vx_id;
19038 +                       if (++nr_xids >= size) {
19039 +                               spin_unlock(&vx_info_hash_lock);
19040 +                               goto out;
19041 +                       }
19042 +               }
19043 +               /* keep the lock time short */
19044 +               spin_unlock(&vx_info_hash_lock);
19045 +       }
19046 +out:
19047 +       return nr_xids;
19048 +}
19049 +#endif
19050 +
19051 +#ifdef CONFIG_VSERVER_DEBUG
19052 +
19053 +void   dump_vx_info_inactive(int level)
19054 +{
19055 +       struct hlist_node *entry, *next;
19056 +
19057 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
19058 +               struct vx_info *vxi =
19059 +                       list_entry(entry, struct vx_info, vx_hlist);
19060 +
19061 +               dump_vx_info(vxi, level);
19062 +       }
19063 +}
19064 +
19065 +#endif
19066 +
19067 +#if 0
19068 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
19069 +{
19070 +       struct user_struct *new_user, *old_user;
19071 +
19072 +       if (!p || !vxi)
19073 +               BUG();
19074 +
19075 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
19076 +               return -EACCES;
19077 +
19078 +       new_user = alloc_uid(vxi->vx_id, p->uid);
19079 +       if (!new_user)
19080 +               return -ENOMEM;
19081 +
19082 +       old_user = p->user;
19083 +       if (new_user != old_user) {
19084 +               atomic_inc(&new_user->processes);
19085 +               atomic_dec(&old_user->processes);
19086 +               p->user = new_user;
19087 +       }
19088 +       free_uid(old_user);
19089 +       return 0;
19090 +}
19091 +#endif
19092 +
19093 +#if 0
19094 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
19095 +{
19096 +       // p->cap_effective &= vxi->vx_cap_bset;
19097 +       p->cap_effective =
19098 +               cap_intersect(p->cap_effective, vxi->cap_bset);
19099 +       // p->cap_inheritable &= vxi->vx_cap_bset;
19100 +       p->cap_inheritable =
19101 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
19102 +       // p->cap_permitted &= vxi->vx_cap_bset;
19103 +       p->cap_permitted =
19104 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
19105 +}
19106 +#endif
19107 +
19108 +
19109 +#include <linux/file.h>
19110 +#include <linux/fdtable.h>
19111 +
19112 +static int vx_openfd_task(struct task_struct *tsk)
19113 +{
19114 +       struct files_struct *files = tsk->files;
19115 +       struct fdtable *fdt;
19116 +       const unsigned long *bptr;
19117 +       int count, total;
19118 +
19119 +       /* no rcu_read_lock() because of spin_lock() */
19120 +       spin_lock(&files->file_lock);
19121 +       fdt = files_fdtable(files);
19122 +       bptr = fdt->open_fds->fds_bits;
19123 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
19124 +       for (total = 0; count > 0; count--) {
19125 +               if (*bptr)
19126 +                       total += hweight_long(*bptr);
19127 +               bptr++;
19128 +       }
19129 +       spin_unlock(&files->file_lock);
19130 +       return total;
19131 +}
19132 +
19133 +
19134 +/*     for *space compatibility */
19135 +
19136 +asmlinkage long sys_unshare(unsigned long);
19137 +
19138 +/*
19139 + *     migrate task to new context
19140 + *     gets vxi, puts old_vxi on change
19141 + *     optionally unshares namespaces (hack)
19142 + */
19143 +
19144 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
19145 +{
19146 +       struct vx_info *old_vxi;
19147 +       int ret = 0;
19148 +
19149 +       if (!p || !vxi)
19150 +               BUG();
19151 +
19152 +       vxdprintk(VXD_CBIT(xid, 5),
19153 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
19154 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
19155 +
19156 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
19157 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
19158 +               return -EACCES;
19159 +
19160 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
19161 +               return -EFAULT;
19162 +
19163 +       old_vxi = task_get_vx_info(p);
19164 +       if (old_vxi == vxi)
19165 +               goto out;
19166 +
19167 +//     if (!(ret = vx_migrate_user(p, vxi))) {
19168 +       {
19169 +               int openfd;
19170 +
19171 +               task_lock(p);
19172 +               openfd = vx_openfd_task(p);
19173 +
19174 +               if (old_vxi) {
19175 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
19176 +                       atomic_dec(&old_vxi->cvirt.nr_running);
19177 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
19178 +                       /* FIXME: what about the struct files here? */
19179 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
19180 +                       /* account for the executable */
19181 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
19182 +               }
19183 +               atomic_inc(&vxi->cvirt.nr_threads);
19184 +               atomic_inc(&vxi->cvirt.nr_running);
19185 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
19186 +               /* FIXME: what about the struct files here? */
19187 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
19188 +               /* account for the executable */
19189 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
19190 +
19191 +               if (old_vxi) {
19192 +                       release_vx_info(old_vxi, p);
19193 +                       clr_vx_info(&p->vx_info);
19194 +               }
19195 +               claim_vx_info(vxi, p);
19196 +               set_vx_info(&p->vx_info, vxi);
19197 +               p->xid = vxi->vx_id;
19198 +
19199 +               vxdprintk(VXD_CBIT(xid, 5),
19200 +                       "moved task %p into vxi:%p[#%d]",
19201 +                       p, vxi, vxi->vx_id);
19202 +
19203 +               // vx_mask_cap_bset(vxi, p);
19204 +               task_unlock(p);
19205 +
19206 +               /* hack for *spaces to provide compatibility */
19207 +               if (unshare) {
19208 +                       struct nsproxy *old_nsp, *new_nsp;
19209 +
19210 +                       ret = unshare_nsproxy_namespaces(
19211 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
19212 +                               &new_nsp, NULL);
19213 +                       if (ret)
19214 +                               goto out;
19215 +
19216 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
19217 +                       vx_set_space(vxi,
19218 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
19219 +                       put_nsproxy(old_nsp);
19220 +               }
19221 +       }
19222 +out:
19223 +       put_vx_info(old_vxi);
19224 +       return ret;
19225 +}
19226 +
19227 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
19228 +{
19229 +       struct task_struct *old_reaper;
19230 +
19231 +       if (!vxi)
19232 +               return -EINVAL;
19233 +
19234 +       vxdprintk(VXD_CBIT(xid, 6),
19235 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
19236 +               vxi, vxi->vx_id, p, p->xid, p->pid);
19237 +
19238 +       old_reaper = vxi->vx_reaper;
19239 +       if (old_reaper == p)
19240 +               return 0;
19241 +
19242 +       /* set new child reaper */
19243 +       get_task_struct(p);
19244 +       vxi->vx_reaper = p;
19245 +       put_task_struct(old_reaper);
19246 +       return 0;
19247 +}
19248 +
19249 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
19250 +{
19251 +       if (!vxi)
19252 +               return -EINVAL;
19253 +
19254 +       vxdprintk(VXD_CBIT(xid, 6),
19255 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
19256 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
19257 +
19258 +       vxi->vx_flags &= ~VXF_STATE_INIT;
19259 +       // vxi->vx_initpid = p->tgid;
19260 +       vxi->vx_initpid = p->pid;
19261 +       return 0;
19262 +}
19263 +
19264 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
19265 +{
19266 +       vxdprintk(VXD_CBIT(xid, 6),
19267 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
19268 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
19269 +
19270 +       vxi->exit_code = code;
19271 +       vxi->vx_initpid = 0;
19272 +}
19273 +
19274 +
19275 +void vx_set_persistent(struct vx_info *vxi)
19276 +{
19277 +       vxdprintk(VXD_CBIT(xid, 6),
19278 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
19279 +
19280 +       get_vx_info(vxi);
19281 +       claim_vx_info(vxi, NULL);
19282 +}
19283 +
19284 +void vx_clear_persistent(struct vx_info *vxi)
19285 +{
19286 +       vxdprintk(VXD_CBIT(xid, 6),
19287 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
19288 +
19289 +       release_vx_info(vxi, NULL);
19290 +       put_vx_info(vxi);
19291 +}
19292 +
19293 +void vx_update_persistent(struct vx_info *vxi)
19294 +{
19295 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
19296 +               vx_set_persistent(vxi);
19297 +       else
19298 +               vx_clear_persistent(vxi);
19299 +}
19300 +
19301 +
19302 +/*     task must be current or locked          */
19303 +
19304 +void   exit_vx_info(struct task_struct *p, int code)
19305 +{
19306 +       struct vx_info *vxi = p->vx_info;
19307 +
19308 +       if (vxi) {
19309 +               atomic_dec(&vxi->cvirt.nr_threads);
19310 +               vx_nproc_dec(p);
19311 +
19312 +               vxi->exit_code = code;
19313 +               release_vx_info(vxi, p);
19314 +       }
19315 +}
19316 +
19317 +void   exit_vx_info_early(struct task_struct *p, int code)
19318 +{
19319 +       struct vx_info *vxi = p->vx_info;
19320 +
19321 +       if (vxi) {
19322 +               if (vxi->vx_initpid == p->pid)
19323 +                       vx_exit_init(vxi, p, code);
19324 +               if (vxi->vx_reaper == p)
19325 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
19326 +       }
19327 +}
19328 +
19329 +
19330 +/* vserver syscall commands below here */
19331 +
19332 +/* taks xid and vx_info functions */
19333 +
19334 +#include <asm/uaccess.h>
19335 +
19336 +
19337 +int vc_task_xid(uint32_t id)
19338 +{
19339 +       xid_t xid;
19340 +
19341 +       if (id) {
19342 +               struct task_struct *tsk;
19343 +
19344 +               read_lock(&tasklist_lock);
19345 +               tsk = find_task_by_real_pid(id);
19346 +               xid = (tsk) ? tsk->xid : -ESRCH;
19347 +               read_unlock(&tasklist_lock);
19348 +       } else
19349 +               xid = vx_current_xid();
19350 +       return xid;
19351 +}
19352 +
19353 +
19354 +int vc_vx_info(struct vx_info *vxi, void __user *data)
19355 +{
19356 +       struct vcmd_vx_info_v0 vc_data;
19357 +
19358 +       vc_data.xid = vxi->vx_id;
19359 +       vc_data.initpid = vxi->vx_initpid;
19360 +
19361 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19362 +               return -EFAULT;
19363 +       return 0;
19364 +}
19365 +
19366 +
19367 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
19368 +{
19369 +       struct vcmd_ctx_stat_v0 vc_data;
19370 +
19371 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
19372 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
19373 +
19374 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19375 +               return -EFAULT;
19376 +       return 0;
19377 +}
19378 +
19379 +
19380 +/* context functions */
19381 +
19382 +int vc_ctx_create(uint32_t xid, void __user *data)
19383 +{
19384 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
19385 +       struct vx_info *new_vxi;
19386 +       int ret;
19387 +
19388 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19389 +               return -EFAULT;
19390 +
19391 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
19392 +               return -EINVAL;
19393 +
19394 +       new_vxi = __create_vx_info(xid);
19395 +       if (IS_ERR(new_vxi))
19396 +               return PTR_ERR(new_vxi);
19397 +
19398 +       /* initial flags */
19399 +       new_vxi->vx_flags = vc_data.flagword;
19400 +
19401 +       ret = -ENOEXEC;
19402 +       if (vs_state_change(new_vxi, VSC_STARTUP))
19403 +               goto out;
19404 +
19405 +       ret = vx_migrate_task(current, new_vxi, (!data));
19406 +       if (ret)
19407 +               goto out;
19408 +
19409 +       /* return context id on success */
19410 +       ret = new_vxi->vx_id;
19411 +
19412 +       /* get a reference for persistent contexts */
19413 +       if ((vc_data.flagword & VXF_PERSISTENT))
19414 +               vx_set_persistent(new_vxi);
19415 +out:
19416 +       release_vx_info(new_vxi, NULL);
19417 +       put_vx_info(new_vxi);
19418 +       return ret;
19419 +}
19420 +
19421 +
19422 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
19423 +{
19424 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
19425 +       int ret;
19426 +
19427 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19428 +               return -EFAULT;
19429 +
19430 +       ret = vx_migrate_task(current, vxi, 0);
19431 +       if (ret)
19432 +               return ret;
19433 +       if (vc_data.flagword & VXM_SET_INIT)
19434 +               ret = vx_set_init(vxi, current);
19435 +       if (ret)
19436 +               return ret;
19437 +       if (vc_data.flagword & VXM_SET_REAPER)
19438 +               ret = vx_set_reaper(vxi, current);
19439 +       return ret;
19440 +}
19441 +
19442 +
19443 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
19444 +{
19445 +       struct vcmd_ctx_flags_v0 vc_data;
19446 +
19447 +       vc_data.flagword = vxi->vx_flags;
19448 +
19449 +       /* special STATE flag handling */
19450 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
19451 +
19452 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19453 +               return -EFAULT;
19454 +       return 0;
19455 +}
19456 +
19457 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
19458 +{
19459 +       struct vcmd_ctx_flags_v0 vc_data;
19460 +       uint64_t mask, trigger;
19461 +
19462 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19463 +               return -EFAULT;
19464 +
19465 +       /* special STATE flag handling */
19466 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
19467 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
19468 +
19469 +       if (vxi == current_vx_info()) {
19470 +               /* if (trigger & VXF_STATE_SETUP)
19471 +                       vx_mask_cap_bset(vxi, current); */
19472 +               if (trigger & VXF_STATE_INIT) {
19473 +                       int ret;
19474 +
19475 +                       ret = vx_set_init(vxi, current);
19476 +                       if (ret)
19477 +                               return ret;
19478 +                       ret = vx_set_reaper(vxi, current);
19479 +                       if (ret)
19480 +                               return ret;
19481 +               }
19482 +       }
19483 +
19484 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
19485 +               vc_data.flagword, mask);
19486 +       if (trigger & VXF_PERSISTENT)
19487 +               vx_update_persistent(vxi);
19488 +
19489 +       return 0;
19490 +}
19491 +
19492 +
19493 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
19494 +{
19495 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
19496 +
19497 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
19498 +       return v;
19499 +}
19500 +
19501 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
19502 +{
19503 +       kernel_cap_t c = __cap_empty_set;
19504 +
19505 +       c.cap[0] = v & 0xFFFFFFFF;
19506 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
19507 +
19508 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
19509 +       return c;
19510 +}
19511 +
19512 +
19513 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
19514 +{
19515 +       if (bcaps)
19516 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
19517 +       if (ccaps)
19518 +               *ccaps = vxi->vx_ccaps;
19519 +
19520 +       return 0;
19521 +}
19522 +
19523 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
19524 +{
19525 +       struct vcmd_ctx_caps_v1 vc_data;
19526 +       int ret;
19527 +
19528 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
19529 +       if (ret)
19530 +               return ret;
19531 +       vc_data.cmask = ~0ULL;
19532 +
19533 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19534 +               return -EFAULT;
19535 +       return 0;
19536 +}
19537 +
19538 +static int do_set_caps(struct vx_info *vxi,
19539 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
19540 +{
19541 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
19542 +
19543 +#if 0
19544 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
19545 +               bcaps, bmask, ccaps, cmask);
19546 +#endif
19547 +       vxi->vx_bcaps = cap_t_from_caps(
19548 +               vs_mask_flags(bcold, bcaps, bmask));
19549 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
19550 +
19551 +       return 0;
19552 +}
19553 +
19554 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
19555 +{
19556 +       struct vcmd_ctx_caps_v1 vc_data;
19557 +
19558 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19559 +               return -EFAULT;
19560 +
19561 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
19562 +}
19563 +
19564 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
19565 +{
19566 +       struct vcmd_bcaps vc_data;
19567 +       int ret;
19568 +
19569 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
19570 +       if (ret)
19571 +               return ret;
19572 +       vc_data.bmask = ~0ULL;
19573 +
19574 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19575 +               return -EFAULT;
19576 +       return 0;
19577 +}
19578 +
19579 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
19580 +{
19581 +       struct vcmd_bcaps vc_data;
19582 +
19583 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19584 +               return -EFAULT;
19585 +
19586 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
19587 +}
19588 +
19589 +
19590 +int vc_get_umask(struct vx_info *vxi, void __user *data)
19591 +{
19592 +       struct vcmd_umask vc_data;
19593 +
19594 +       vc_data.umask = vxi->vx_umask;
19595 +       vc_data.mask = ~0ULL;
19596 +
19597 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19598 +               return -EFAULT;
19599 +       return 0;
19600 +}
19601 +
19602 +int vc_set_umask(struct vx_info *vxi, void __user *data)
19603 +{
19604 +       struct vcmd_umask vc_data;
19605 +
19606 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19607 +               return -EFAULT;
19608 +
19609 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
19610 +               vc_data.umask, vc_data.mask);
19611 +       return 0;
19612 +}
19613 +
19614 +
19615 +int vc_get_badness(struct vx_info *vxi, void __user *data)
19616 +{
19617 +       struct vcmd_badness_v0 vc_data;
19618 +
19619 +       vc_data.bias = vxi->vx_badness_bias;
19620 +
19621 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19622 +               return -EFAULT;
19623 +       return 0;
19624 +}
19625 +
19626 +int vc_set_badness(struct vx_info *vxi, void __user *data)
19627 +{
19628 +       struct vcmd_badness_v0 vc_data;
19629 +
19630 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19631 +               return -EFAULT;
19632 +
19633 +       vxi->vx_badness_bias = vc_data.bias;
19634 +       return 0;
19635 +}
19636 +
19637 +#include <linux/module.h>
19638 +
19639 +EXPORT_SYMBOL_GPL(free_vx_info);
19640 +
19641 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cvirt.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cvirt.c
19642 --- linux-2.6.33/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
19643 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cvirt.c 2010-02-25 12:02:16.000000000 +0100
19644 @@ -0,0 +1,304 @@
19645 +/*
19646 + *  linux/kernel/vserver/cvirt.c
19647 + *
19648 + *  Virtual Server: Context Virtualization
19649 + *
19650 + *  Copyright (C) 2004-2007  Herbert Pötzl
19651 + *
19652 + *  V0.01  broken out from limit.c
19653 + *  V0.02  added utsname stuff
19654 + *  V0.03  changed vcmds to vxi arg
19655 + *
19656 + */
19657 +
19658 +#include <linux/types.h>
19659 +#include <linux/utsname.h>
19660 +#include <linux/vs_cvirt.h>
19661 +#include <linux/vserver/switch.h>
19662 +#include <linux/vserver/cvirt_cmd.h>
19663 +
19664 +#include <asm/uaccess.h>
19665 +
19666 +
19667 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
19668 +{
19669 +       struct vx_info *vxi = current_vx_info();
19670 +
19671 +       set_normalized_timespec(uptime,
19672 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
19673 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
19674 +       if (!idle)
19675 +               return;
19676 +       set_normalized_timespec(idle,
19677 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
19678 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
19679 +       return;
19680 +}
19681 +
19682 +uint64_t vx_idle_jiffies(void)
19683 +{
19684 +       return init_task.utime + init_task.stime;
19685 +}
19686 +
19687 +
19688 +
19689 +static inline uint32_t __update_loadavg(uint32_t load,
19690 +       int wsize, int delta, int n)
19691 +{
19692 +       unsigned long long calc, prev;
19693 +
19694 +       /* just set it to n */
19695 +       if (unlikely(delta >= wsize))
19696 +               return (n << FSHIFT);
19697 +
19698 +       calc = delta * n;
19699 +       calc <<= FSHIFT;
19700 +       prev = (wsize - delta);
19701 +       prev *= load;
19702 +       calc += prev;
19703 +       do_div(calc, wsize);
19704 +       return calc;
19705 +}
19706 +
19707 +
19708 +void vx_update_load(struct vx_info *vxi)
19709 +{
19710 +       uint32_t now, last, delta;
19711 +       unsigned int nr_running, nr_uninterruptible;
19712 +       unsigned int total;
19713 +       unsigned long flags;
19714 +
19715 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
19716 +
19717 +       now = jiffies;
19718 +       last = vxi->cvirt.load_last;
19719 +       delta = now - last;
19720 +
19721 +       if (delta < 5*HZ)
19722 +               goto out;
19723 +
19724 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
19725 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
19726 +       total = nr_running + nr_uninterruptible;
19727 +
19728 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
19729 +               60*HZ, delta, total);
19730 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
19731 +               5*60*HZ, delta, total);
19732 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
19733 +               15*60*HZ, delta, total);
19734 +
19735 +       vxi->cvirt.load_last = now;
19736 +out:
19737 +       atomic_inc(&vxi->cvirt.load_updates);
19738 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
19739 +}
19740 +
19741 +
19742 +/*
19743 + * Commands to do_syslog:
19744 + *
19745 + *      0 -- Close the log.  Currently a NOP.
19746 + *      1 -- Open the log. Currently a NOP.
19747 + *      2 -- Read from the log.
19748 + *      3 -- Read all messages remaining in the ring buffer.
19749 + *      4 -- Read and clear all messages remaining in the ring buffer
19750 + *      5 -- Clear ring buffer.
19751 + *      6 -- Disable printk's to console
19752 + *      7 -- Enable printk's to console
19753 + *      8 -- Set level of messages printed to console
19754 + *      9 -- Return number of unread characters in the log buffer
19755 + *     10 -- Return size of the log buffer
19756 + */
19757 +int vx_do_syslog(int type, char __user *buf, int len)
19758 +{
19759 +       int error = 0;
19760 +       int do_clear = 0;
19761 +       struct vx_info *vxi = current_vx_info();
19762 +       struct _vx_syslog *log;
19763 +
19764 +       if (!vxi)
19765 +               return -EINVAL;
19766 +       log = &vxi->cvirt.syslog;
19767 +
19768 +       switch (type) {
19769 +       case 0:         /* Close log */
19770 +       case 1:         /* Open log */
19771 +               break;
19772 +       case 2:         /* Read from log */
19773 +               error = wait_event_interruptible(log->log_wait,
19774 +                       (log->log_start - log->log_end));
19775 +               if (error)
19776 +                       break;
19777 +               spin_lock_irq(&log->logbuf_lock);
19778 +               spin_unlock_irq(&log->logbuf_lock);
19779 +               break;
19780 +       case 4:         /* Read/clear last kernel messages */
19781 +               do_clear = 1;
19782 +               /* fall through */
19783 +       case 3:         /* Read last kernel messages */
19784 +               return 0;
19785 +
19786 +       case 5:         /* Clear ring buffer */
19787 +               return 0;
19788 +
19789 +       case 6:         /* Disable logging to console */
19790 +       case 7:         /* Enable logging to console */
19791 +       case 8:         /* Set level of messages printed to console */
19792 +               break;
19793 +
19794 +       case 9:         /* Number of chars in the log buffer */
19795 +               return 0;
19796 +       case 10:        /* Size of the log buffer */
19797 +               return 0;
19798 +       default:
19799 +               error = -EINVAL;
19800 +               break;
19801 +       }
19802 +       return error;
19803 +}
19804 +
19805 +
19806 +/* virtual host info names */
19807 +
19808 +static char *vx_vhi_name(struct vx_info *vxi, int id)
19809 +{
19810 +       struct nsproxy *nsproxy;
19811 +       struct uts_namespace *uts;
19812 +
19813 +       if (id == VHIN_CONTEXT)
19814 +               return vxi->vx_name;
19815 +
19816 +       nsproxy = vxi->vx_nsproxy[0];
19817 +       if (!nsproxy)
19818 +               return NULL;
19819 +
19820 +       uts = nsproxy->uts_ns;
19821 +       if (!uts)
19822 +               return NULL;
19823 +
19824 +       switch (id) {
19825 +       case VHIN_SYSNAME:
19826 +               return uts->name.sysname;
19827 +       case VHIN_NODENAME:
19828 +               return uts->name.nodename;
19829 +       case VHIN_RELEASE:
19830 +               return uts->name.release;
19831 +       case VHIN_VERSION:
19832 +               return uts->name.version;
19833 +       case VHIN_MACHINE:
19834 +               return uts->name.machine;
19835 +       case VHIN_DOMAINNAME:
19836 +               return uts->name.domainname;
19837 +       default:
19838 +               return NULL;
19839 +       }
19840 +       return NULL;
19841 +}
19842 +
19843 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
19844 +{
19845 +       struct vcmd_vhi_name_v0 vc_data;
19846 +       char *name;
19847 +
19848 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19849 +               return -EFAULT;
19850 +
19851 +       name = vx_vhi_name(vxi, vc_data.field);
19852 +       if (!name)
19853 +               return -EINVAL;
19854 +
19855 +       memcpy(name, vc_data.name, 65);
19856 +       return 0;
19857 +}
19858 +
19859 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
19860 +{
19861 +       struct vcmd_vhi_name_v0 vc_data;
19862 +       char *name;
19863 +
19864 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19865 +               return -EFAULT;
19866 +
19867 +       name = vx_vhi_name(vxi, vc_data.field);
19868 +       if (!name)
19869 +               return -EINVAL;
19870 +
19871 +       memcpy(vc_data.name, name, 65);
19872 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19873 +               return -EFAULT;
19874 +       return 0;
19875 +}
19876 +
19877 +
19878 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
19879 +{
19880 +       struct vcmd_virt_stat_v0 vc_data;
19881 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
19882 +       struct timespec uptime;
19883 +
19884 +       do_posix_clock_monotonic_gettime(&uptime);
19885 +       set_normalized_timespec(&uptime,
19886 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
19887 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
19888 +
19889 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
19890 +       vc_data.uptime = timespec_to_ns(&uptime);
19891 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
19892 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
19893 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
19894 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
19895 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
19896 +       vc_data.load[0] = cvirt->load[0];
19897 +       vc_data.load[1] = cvirt->load[1];
19898 +       vc_data.load[2] = cvirt->load[2];
19899 +
19900 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19901 +               return -EFAULT;
19902 +       return 0;
19903 +}
19904 +
19905 +
19906 +#ifdef CONFIG_VSERVER_VTIME
19907 +
19908 +/* virtualized time base */
19909 +
19910 +void vx_gettimeofday(struct timeval *tv)
19911 +{
19912 +       struct vx_info *vxi;
19913 +
19914 +       do_gettimeofday(tv);
19915 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19916 +               return;
19917 +
19918 +       vxi = current_vx_info();
19919 +       tv->tv_sec += vxi->cvirt.bias_tv.tv_sec;
19920 +       tv->tv_usec += vxi->cvirt.bias_tv.tv_usec;
19921 +
19922 +       if (tv->tv_usec >= USEC_PER_SEC) {
19923 +               tv->tv_sec++;
19924 +               tv->tv_usec -= USEC_PER_SEC;
19925 +       } else if (tv->tv_usec < 0) {
19926 +               tv->tv_sec--;
19927 +               tv->tv_usec += USEC_PER_SEC;
19928 +       }
19929 +}
19930 +
19931 +int vx_settimeofday(struct timespec *ts)
19932 +{
19933 +       struct timeval tv;
19934 +       struct vx_info *vxi;
19935 +
19936 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19937 +               return do_settimeofday(ts);
19938 +
19939 +       do_gettimeofday(&tv);
19940 +       vxi = current_vx_info();
19941 +       vxi->cvirt.bias_tv.tv_sec = ts->tv_sec - tv.tv_sec;
19942 +       vxi->cvirt.bias_tv.tv_usec =
19943 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
19944 +       return 0;
19945 +}
19946 +
19947 +#endif
19948 +
19949 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cvirt_init.h linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cvirt_init.h
19950 --- linux-2.6.33/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
19951 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cvirt_init.h    2010-02-25 12:02:16.000000000 +0100
19952 @@ -0,0 +1,69 @@
19953 +
19954 +
19955 +extern uint64_t vx_idle_jiffies(void);
19956 +
19957 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
19958 +{
19959 +       uint64_t idle_jiffies = vx_idle_jiffies();
19960 +       uint64_t nsuptime;
19961 +
19962 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
19963 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
19964 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
19965 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
19966 +       cvirt->bias_tv.tv_sec = 0;
19967 +       cvirt->bias_tv.tv_usec = 0;
19968 +
19969 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
19970 +       atomic_set(&cvirt->nr_threads, 0);
19971 +       atomic_set(&cvirt->nr_running, 0);
19972 +       atomic_set(&cvirt->nr_uninterruptible, 0);
19973 +       atomic_set(&cvirt->nr_onhold, 0);
19974 +
19975 +       spin_lock_init(&cvirt->load_lock);
19976 +       cvirt->load_last = jiffies;
19977 +       atomic_set(&cvirt->load_updates, 0);
19978 +       cvirt->load[0] = 0;
19979 +       cvirt->load[1] = 0;
19980 +       cvirt->load[2] = 0;
19981 +       atomic_set(&cvirt->total_forks, 0);
19982 +
19983 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
19984 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19985 +       cvirt->syslog.log_start = 0;
19986 +       cvirt->syslog.log_end = 0;
19987 +       cvirt->syslog.con_start = 0;
19988 +       cvirt->syslog.logged_chars = 0;
19989 +}
19990 +
19991 +static inline
19992 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19993 +{
19994 +       // cvirt_pc->cpustat = { 0 };
19995 +}
19996 +
19997 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19998 +{
19999 +       int value;
20000 +
20001 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
20002 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
20003 +               cvirt, value);
20004 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
20005 +               "!!! cvirt: %p[nr_running] = %d on exit.",
20006 +               cvirt, value);
20007 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
20008 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
20009 +               cvirt, value);
20010 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
20011 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
20012 +               cvirt, value);
20013 +       return;
20014 +}
20015 +
20016 +static inline
20017 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
20018 +{
20019 +       return;
20020 +}
20021 +
20022 diff -NurpP --minimal linux-2.6.33/kernel/vserver/cvirt_proc.h linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cvirt_proc.h
20023 --- linux-2.6.33/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
20024 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/cvirt_proc.h    2010-02-25 12:02:16.000000000 +0100
20025 @@ -0,0 +1,135 @@
20026 +#ifndef _VX_CVIRT_PROC_H
20027 +#define _VX_CVIRT_PROC_H
20028 +
20029 +#include <linux/nsproxy.h>
20030 +#include <linux/mnt_namespace.h>
20031 +#include <linux/ipc_namespace.h>
20032 +#include <linux/utsname.h>
20033 +#include <linux/ipc.h>
20034 +
20035 +
20036 +static inline
20037 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
20038 +{
20039 +       struct mnt_namespace *ns;
20040 +       struct uts_namespace *uts;
20041 +       struct ipc_namespace *ipc;
20042 +       struct path path;
20043 +       char *pstr, *root;
20044 +       int length = 0;
20045 +
20046 +       if (!nsproxy)
20047 +               goto out;
20048 +
20049 +       length += sprintf(buffer + length,
20050 +               "NSProxy:\t%p [%p,%p,%p]\n",
20051 +               nsproxy, nsproxy->mnt_ns,
20052 +               nsproxy->uts_ns, nsproxy->ipc_ns);
20053 +
20054 +       ns = nsproxy->mnt_ns;
20055 +       if (!ns)
20056 +               goto skip_ns;
20057 +
20058 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
20059 +       if (!pstr)
20060 +               goto skip_ns;
20061 +
20062 +       path.mnt = ns->root;
20063 +       path.dentry = ns->root->mnt_root;
20064 +       root = d_path(&path, pstr, PATH_MAX - 2);
20065 +       length += sprintf(buffer + length,
20066 +               "Namespace:\t%p [#%u]\n"
20067 +               "RootPath:\t%s\n",
20068 +               ns, atomic_read(&ns->count),
20069 +               root);
20070 +       kfree(pstr);
20071 +skip_ns:
20072 +
20073 +       uts = nsproxy->uts_ns;
20074 +       if (!uts)
20075 +               goto skip_uts;
20076 +
20077 +       length += sprintf(buffer + length,
20078 +               "SysName:\t%.*s\n"
20079 +               "NodeName:\t%.*s\n"
20080 +               "Release:\t%.*s\n"
20081 +               "Version:\t%.*s\n"
20082 +               "Machine:\t%.*s\n"
20083 +               "DomainName:\t%.*s\n",
20084 +               __NEW_UTS_LEN, uts->name.sysname,
20085 +               __NEW_UTS_LEN, uts->name.nodename,
20086 +               __NEW_UTS_LEN, uts->name.release,
20087 +               __NEW_UTS_LEN, uts->name.version,
20088 +               __NEW_UTS_LEN, uts->name.machine,
20089 +               __NEW_UTS_LEN, uts->name.domainname);
20090 +skip_uts:
20091 +
20092 +       ipc = nsproxy->ipc_ns;
20093 +       if (!ipc)
20094 +               goto skip_ipc;
20095 +
20096 +       length += sprintf(buffer + length,
20097 +               "SEMS:\t\t%d %d %d %d  %d\n"
20098 +               "MSG:\t\t%d %d %d\n"
20099 +               "SHM:\t\t%lu %lu  %d %d\n",
20100 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
20101 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
20102 +               ipc->used_sems,
20103 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
20104 +               (unsigned long)ipc->shm_ctlmax,
20105 +               (unsigned long)ipc->shm_ctlall,
20106 +               ipc->shm_ctlmni, ipc->shm_tot);
20107 +skip_ipc:
20108 +out:
20109 +       return length;
20110 +}
20111 +
20112 +
20113 +#include <linux/sched.h>
20114 +
20115 +#define LOAD_INT(x) ((x) >> FSHIFT)
20116 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
20117 +
20118 +static inline
20119 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
20120 +{
20121 +       int length = 0;
20122 +       int a, b, c;
20123 +
20124 +       length += sprintf(buffer + length,
20125 +               "BiasUptime:\t%lu.%02lu\n",
20126 +               (unsigned long)cvirt->bias_uptime.tv_sec,
20127 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
20128 +
20129 +       a = cvirt->load[0] + (FIXED_1 / 200);
20130 +       b = cvirt->load[1] + (FIXED_1 / 200);
20131 +       c = cvirt->load[2] + (FIXED_1 / 200);
20132 +       length += sprintf(buffer + length,
20133 +               "nr_threads:\t%d\n"
20134 +               "nr_running:\t%d\n"
20135 +               "nr_unintr:\t%d\n"
20136 +               "nr_onhold:\t%d\n"
20137 +               "load_updates:\t%d\n"
20138 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
20139 +               "total_forks:\t%d\n",
20140 +               atomic_read(&cvirt->nr_threads),
20141 +               atomic_read(&cvirt->nr_running),
20142 +               atomic_read(&cvirt->nr_uninterruptible),
20143 +               atomic_read(&cvirt->nr_onhold),
20144 +               atomic_read(&cvirt->load_updates),
20145 +               LOAD_INT(a), LOAD_FRAC(a),
20146 +               LOAD_INT(b), LOAD_FRAC(b),
20147 +               LOAD_INT(c), LOAD_FRAC(c),
20148 +               atomic_read(&cvirt->total_forks));
20149 +       return length;
20150 +}
20151 +
20152 +static inline
20153 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
20154 +       char *buffer, int cpu)
20155 +{
20156 +       int length = 0;
20157 +       return length;
20158 +}
20159 +
20160 +#endif /* _VX_CVIRT_PROC_H */
20161 diff -NurpP --minimal linux-2.6.33/kernel/vserver/debug.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/debug.c
20162 --- linux-2.6.33/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
20163 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/debug.c 2010-02-25 12:02:16.000000000 +0100
20164 @@ -0,0 +1,32 @@
20165 +/*
20166 + *  kernel/vserver/debug.c
20167 + *
20168 + *  Copyright (C) 2005-2007 Herbert Pötzl
20169 + *
20170 + *  V0.01  vx_info dump support
20171 + *
20172 + */
20173 +
20174 +#include <linux/module.h>
20175 +
20176 +#include <linux/vserver/context.h>
20177 +
20178 +
20179 +void   dump_vx_info(struct vx_info *vxi, int level)
20180 +{
20181 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
20182 +               atomic_read(&vxi->vx_usecnt),
20183 +               atomic_read(&vxi->vx_tasks),
20184 +               vxi->vx_state);
20185 +       if (level > 0) {
20186 +               __dump_vx_limit(&vxi->limit);
20187 +               __dump_vx_sched(&vxi->sched);
20188 +               __dump_vx_cvirt(&vxi->cvirt);
20189 +               __dump_vx_cacct(&vxi->cacct);
20190 +       }
20191 +       printk("---\n");
20192 +}
20193 +
20194 +
20195 +EXPORT_SYMBOL_GPL(dump_vx_info);
20196 +
20197 diff -NurpP --minimal linux-2.6.33/kernel/vserver/device.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/device.c
20198 --- linux-2.6.33/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
20199 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/device.c        2010-02-25 12:02:16.000000000 +0100
20200 @@ -0,0 +1,443 @@
20201 +/*
20202 + *  linux/kernel/vserver/device.c
20203 + *
20204 + *  Linux-VServer: Device Support
20205 + *
20206 + *  Copyright (C) 2006  Herbert Pötzl
20207 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
20208 + *
20209 + *  V0.01  device mapping basics
20210 + *  V0.02  added defaults
20211 + *
20212 + */
20213 +
20214 +#include <linux/slab.h>
20215 +#include <linux/rcupdate.h>
20216 +#include <linux/fs.h>
20217 +#include <linux/namei.h>
20218 +#include <linux/hash.h>
20219 +
20220 +#include <asm/errno.h>
20221 +#include <asm/uaccess.h>
20222 +#include <linux/vserver/base.h>
20223 +#include <linux/vserver/debug.h>
20224 +#include <linux/vserver/context.h>
20225 +#include <linux/vserver/device.h>
20226 +#include <linux/vserver/device_cmd.h>
20227 +
20228 +
20229 +#define DMAP_HASH_BITS 4
20230 +
20231 +
20232 +struct vs_mapping {
20233 +       union {
20234 +               struct hlist_node hlist;
20235 +               struct list_head list;
20236 +       } u;
20237 +#define dm_hlist       u.hlist
20238 +#define dm_list                u.list
20239 +       xid_t xid;
20240 +       dev_t device;
20241 +       struct vx_dmap_target target;
20242 +};
20243 +
20244 +
20245 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
20246 +
20247 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
20248 +
20249 +static struct vx_dmap_target dmap_defaults[2] = {
20250 +       { .flags = DATTR_OPEN },
20251 +       { .flags = DATTR_OPEN },
20252 +};
20253 +
20254 +
20255 +struct kmem_cache *dmap_cachep __read_mostly;
20256 +
20257 +int __init dmap_cache_init(void)
20258 +{
20259 +       dmap_cachep = kmem_cache_create("dmap_cache",
20260 +               sizeof(struct vs_mapping), 0,
20261 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20262 +       return 0;
20263 +}
20264 +
20265 +__initcall(dmap_cache_init);
20266 +
20267 +
20268 +static inline unsigned int __hashval(dev_t dev, int bits)
20269 +{
20270 +       return hash_long((unsigned long)dev, bits);
20271 +}
20272 +
20273 +
20274 +/*     __hash_mapping()
20275 + *     add the mapping to the hash table
20276 + */
20277 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
20278 +{
20279 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
20280 +       struct hlist_head *head, *hash = dmap_main_hash;
20281 +       int device = vdm->device;
20282 +
20283 +       spin_lock(hash_lock);
20284 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
20285 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
20286 +
20287 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
20288 +       hlist_add_head(&vdm->dm_hlist, head);
20289 +       spin_unlock(hash_lock);
20290 +}
20291 +
20292 +
20293 +static inline int __mode_to_default(umode_t mode)
20294 +{
20295 +       switch (mode) {
20296 +       case S_IFBLK:
20297 +               return 0;
20298 +       case S_IFCHR:
20299 +               return 1;
20300 +       default:
20301 +               BUG();
20302 +       }
20303 +}
20304 +
20305 +
20306 +/*     __set_default()
20307 + *     set a default
20308 + */
20309 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
20310 +       struct vx_dmap_target *vdmt)
20311 +{
20312 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
20313 +       spin_lock(hash_lock);
20314 +
20315 +       if (vxi)
20316 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
20317 +       else
20318 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
20319 +
20320 +
20321 +       spin_unlock(hash_lock);
20322 +
20323 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
20324 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
20325 +}
20326 +
20327 +
20328 +/*     __remove_default()
20329 + *     remove a default
20330 + */
20331 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
20332 +{
20333 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
20334 +       spin_lock(hash_lock);
20335 +
20336 +       if (vxi)
20337 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
20338 +       else    /* remove == reset */
20339 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
20340 +
20341 +       spin_unlock(hash_lock);
20342 +       return 0;
20343 +}
20344 +
20345 +
20346 +/*     __find_mapping()
20347 + *     find a mapping in the hash table
20348 + *
20349 + *     caller must hold hash_lock
20350 + */
20351 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
20352 +       struct vs_mapping **local, struct vs_mapping **global)
20353 +{
20354 +       struct hlist_head *hash = dmap_main_hash;
20355 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
20356 +       struct hlist_node *pos;
20357 +       struct vs_mapping *vdm;
20358 +
20359 +       *local = NULL;
20360 +       if (global)
20361 +               *global = NULL;
20362 +
20363 +       hlist_for_each(pos, head) {
20364 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
20365 +
20366 +               if ((vdm->device == device) &&
20367 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
20368 +                       if (vdm->xid == xid) {
20369 +                               *local = vdm;
20370 +                               return 1;
20371 +                       } else if (global && vdm->xid == 0)
20372 +                               *global = vdm;
20373 +               }
20374 +       }
20375 +
20376 +       if (global && *global)
20377 +               return 0;
20378 +       else
20379 +               return -ENOENT;
20380 +}
20381 +
20382 +
20383 +/*     __lookup_mapping()
20384 + *     find a mapping and store the result in target and flags
20385 + */
20386 +static inline int __lookup_mapping(struct vx_info *vxi,
20387 +       dev_t device, dev_t *target, int *flags, umode_t mode)
20388 +{
20389 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
20390 +       struct vs_mapping *vdm, *global;
20391 +       struct vx_dmap_target *vdmt;
20392 +       int ret = 0;
20393 +       xid_t xid = vxi->vx_id;
20394 +       int index;
20395 +
20396 +       spin_lock(hash_lock);
20397 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
20398 +               ret = 1;
20399 +               vdmt = &vdm->target;
20400 +               goto found;
20401 +       }
20402 +
20403 +       index = __mode_to_default(mode);
20404 +       if (vxi && vxi->dmap.targets[index].flags) {
20405 +               ret = 2;
20406 +               vdmt = &vxi->dmap.targets[index];
20407 +       } else if (global) {
20408 +               ret = 3;
20409 +               vdmt = &global->target;
20410 +               goto found;
20411 +       } else {
20412 +               ret = 4;
20413 +               vdmt = &dmap_defaults[index];
20414 +       }
20415 +
20416 +found:
20417 +       if (target && (vdmt->flags & DATTR_REMAP))
20418 +               *target = vdmt->target;
20419 +       else if (target)
20420 +               *target = device;
20421 +       if (flags)
20422 +               *flags = vdmt->flags;
20423 +
20424 +       spin_unlock(hash_lock);
20425 +
20426 +       return ret;
20427 +}
20428 +
20429 +
20430 +/*     __remove_mapping()
20431 + *     remove a mapping from the hash table
20432 + */
20433 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
20434 +       umode_t mode)
20435 +{
20436 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
20437 +       struct vs_mapping *vdm = NULL;
20438 +       int ret = 0;
20439 +
20440 +       spin_lock(hash_lock);
20441 +
20442 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
20443 +               NULL);
20444 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
20445 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
20446 +       if (ret < 0)
20447 +               goto out;
20448 +       hlist_del(&vdm->dm_hlist);
20449 +
20450 +out:
20451 +       spin_unlock(hash_lock);
20452 +       if (vdm)
20453 +               kmem_cache_free(dmap_cachep, vdm);
20454 +       return ret;
20455 +}
20456 +
20457 +
20458 +
20459 +int vs_map_device(struct vx_info *vxi,
20460 +       dev_t device, dev_t *target, umode_t mode)
20461 +{
20462 +       int ret, flags = DATTR_MASK;
20463 +
20464 +       if (!vxi) {
20465 +               if (target)
20466 +                       *target = device;
20467 +               goto out;
20468 +       }
20469 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
20470 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
20471 +               device, target ? *target : 0, flags, mode, ret);
20472 +out:
20473 +       return (flags & DATTR_MASK);
20474 +}
20475 +
20476 +
20477 +
20478 +static int do_set_mapping(struct vx_info *vxi,
20479 +       dev_t device, dev_t target, int flags, umode_t mode)
20480 +{
20481 +       if (device) {
20482 +               struct vs_mapping *new;
20483 +
20484 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
20485 +               if (!new)
20486 +                       return -ENOMEM;
20487 +
20488 +               INIT_HLIST_NODE(&new->dm_hlist);
20489 +               new->device = device;
20490 +               new->target.target = target;
20491 +               new->target.flags = flags | mode;
20492 +               new->xid = (vxi ? vxi->vx_id : 0);
20493 +
20494 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
20495 +               __hash_mapping(vxi, new);
20496 +       } else {
20497 +               struct vx_dmap_target new = {
20498 +                       .target = target,
20499 +                       .flags = flags | mode,
20500 +               };
20501 +               __set_default(vxi, mode, &new);
20502 +       }
20503 +       return 0;
20504 +}
20505 +
20506 +
20507 +static int do_unset_mapping(struct vx_info *vxi,
20508 +       dev_t device, dev_t target, int flags, umode_t mode)
20509 +{
20510 +       int ret = -EINVAL;
20511 +
20512 +       if (device) {
20513 +               ret = __remove_mapping(vxi, device, mode);
20514 +               if (ret < 0)
20515 +                       goto out;
20516 +       } else {
20517 +               ret = __remove_default(vxi, mode);
20518 +               if (ret < 0)
20519 +                       goto out;
20520 +       }
20521 +
20522 +out:
20523 +       return ret;
20524 +}
20525 +
20526 +
20527 +static inline int __user_device(const char __user *name, dev_t *dev,
20528 +       umode_t *mode)
20529 +{
20530 +       struct nameidata nd;
20531 +       int ret;
20532 +
20533 +       if (!name) {
20534 +               *dev = 0;
20535 +               return 0;
20536 +       }
20537 +       ret = user_lpath(name, &nd.path);
20538 +       if (ret)
20539 +               return ret;
20540 +       if (nd.path.dentry->d_inode) {
20541 +               *dev = nd.path.dentry->d_inode->i_rdev;
20542 +               *mode = nd.path.dentry->d_inode->i_mode;
20543 +       }
20544 +       path_put(&nd.path);
20545 +       return 0;
20546 +}
20547 +
20548 +static inline int __mapping_mode(dev_t device, dev_t target,
20549 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
20550 +{
20551 +       if (device)
20552 +               *mode = device_mode & S_IFMT;
20553 +       else if (target)
20554 +               *mode = target_mode & S_IFMT;
20555 +       else
20556 +               return -EINVAL;
20557 +
20558 +       /* if both given, device and target mode have to match */
20559 +       if (device && target &&
20560 +               ((device_mode ^ target_mode) & S_IFMT))
20561 +               return -EINVAL;
20562 +       return 0;
20563 +}
20564 +
20565 +
20566 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
20567 +       const char __user *target_path, int flags, int set)
20568 +{
20569 +       dev_t device = ~0, target = ~0;
20570 +       umode_t device_mode = 0, target_mode = 0, mode;
20571 +       int ret;
20572 +
20573 +       ret = __user_device(device_path, &device, &device_mode);
20574 +       if (ret)
20575 +               return ret;
20576 +       ret = __user_device(target_path, &target, &target_mode);
20577 +       if (ret)
20578 +               return ret;
20579 +
20580 +       ret = __mapping_mode(device, target,
20581 +               device_mode, target_mode, &mode);
20582 +       if (ret)
20583 +               return ret;
20584 +
20585 +       if (set)
20586 +               return do_set_mapping(vxi, device, target,
20587 +                       flags, mode);
20588 +       else
20589 +               return do_unset_mapping(vxi, device, target,
20590 +                       flags, mode);
20591 +}
20592 +
20593 +
20594 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
20595 +{
20596 +       struct vcmd_set_mapping_v0 vc_data;
20597 +
20598 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20599 +               return -EFAULT;
20600 +
20601 +       return do_mapping(vxi, vc_data.device, vc_data.target,
20602 +               vc_data.flags, 1);
20603 +}
20604 +
20605 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
20606 +{
20607 +       struct vcmd_set_mapping_v0 vc_data;
20608 +
20609 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20610 +               return -EFAULT;
20611 +
20612 +       return do_mapping(vxi, vc_data.device, vc_data.target,
20613 +               vc_data.flags, 0);
20614 +}
20615 +
20616 +
20617 +#ifdef CONFIG_COMPAT
20618 +
20619 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
20620 +{
20621 +       struct vcmd_set_mapping_v0_x32 vc_data;
20622 +
20623 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20624 +               return -EFAULT;
20625 +
20626 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
20627 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
20628 +}
20629 +
20630 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
20631 +{
20632 +       struct vcmd_set_mapping_v0_x32 vc_data;
20633 +
20634 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20635 +               return -EFAULT;
20636 +
20637 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
20638 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
20639 +}
20640 +
20641 +#endif /* CONFIG_COMPAT */
20642 +
20643 +
20644 diff -NurpP --minimal linux-2.6.33/kernel/vserver/dlimit.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/dlimit.c
20645 --- linux-2.6.33/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
20646 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/dlimit.c        2010-02-25 12:02:16.000000000 +0100
20647 @@ -0,0 +1,529 @@
20648 +/*
20649 + *  linux/kernel/vserver/dlimit.c
20650 + *
20651 + *  Virtual Server: Context Disk Limits
20652 + *
20653 + *  Copyright (C) 2004-2009  Herbert Pötzl
20654 + *
20655 + *  V0.01  initial version
20656 + *  V0.02  compat32 splitup
20657 + *  V0.03  extended interface
20658 + *
20659 + */
20660 +
20661 +#include <linux/statfs.h>
20662 +#include <linux/sched.h>
20663 +#include <linux/namei.h>
20664 +#include <linux/vs_tag.h>
20665 +#include <linux/vs_dlimit.h>
20666 +#include <linux/vserver/dlimit_cmd.h>
20667 +
20668 +#include <asm/uaccess.h>
20669 +
20670 +/*     __alloc_dl_info()
20671 +
20672 +       * allocate an initialized dl_info struct
20673 +       * doesn't make it visible (hash)                        */
20674 +
20675 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
20676 +{
20677 +       struct dl_info *new = NULL;
20678 +
20679 +       vxdprintk(VXD_CBIT(dlim, 5),
20680 +               "alloc_dl_info(%p,%d)*", sb, tag);
20681 +
20682 +       /* would this benefit from a slab cache? */
20683 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
20684 +       if (!new)
20685 +               return 0;
20686 +
20687 +       memset(new, 0, sizeof(struct dl_info));
20688 +       new->dl_tag = tag;
20689 +       new->dl_sb = sb;
20690 +       INIT_RCU_HEAD(&new->dl_rcu);
20691 +       INIT_HLIST_NODE(&new->dl_hlist);
20692 +       spin_lock_init(&new->dl_lock);
20693 +       atomic_set(&new->dl_refcnt, 0);
20694 +       atomic_set(&new->dl_usecnt, 0);
20695 +
20696 +       /* rest of init goes here */
20697 +
20698 +       vxdprintk(VXD_CBIT(dlim, 4),
20699 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
20700 +       return new;
20701 +}
20702 +
20703 +/*     __dealloc_dl_info()
20704 +
20705 +       * final disposal of dl_info                             */
20706 +
20707 +static void __dealloc_dl_info(struct dl_info *dli)
20708 +{
20709 +       vxdprintk(VXD_CBIT(dlim, 4),
20710 +               "dealloc_dl_info(%p)", dli);
20711 +
20712 +       dli->dl_hlist.next = LIST_POISON1;
20713 +       dli->dl_tag = -1;
20714 +       dli->dl_sb = 0;
20715 +
20716 +       BUG_ON(atomic_read(&dli->dl_usecnt));
20717 +       BUG_ON(atomic_read(&dli->dl_refcnt));
20718 +
20719 +       kfree(dli);
20720 +}
20721 +
20722 +
20723 +/*     hash table for dl_info hash */
20724 +
20725 +#define DL_HASH_SIZE   13
20726 +
20727 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
20728 +
20729 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
20730 +
20731 +
20732 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
20733 +{
20734 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
20735 +}
20736 +
20737 +
20738 +
20739 +/*     __hash_dl_info()
20740 +
20741 +       * add the dli to the global hash table
20742 +       * requires the hash_lock to be held                     */
20743 +
20744 +static inline void __hash_dl_info(struct dl_info *dli)
20745 +{
20746 +       struct hlist_head *head;
20747 +
20748 +       vxdprintk(VXD_CBIT(dlim, 6),
20749 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
20750 +       get_dl_info(dli);
20751 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
20752 +       hlist_add_head_rcu(&dli->dl_hlist, head);
20753 +}
20754 +
20755 +/*     __unhash_dl_info()
20756 +
20757 +       * remove the dli from the global hash table
20758 +       * requires the hash_lock to be held                     */
20759 +
20760 +static inline void __unhash_dl_info(struct dl_info *dli)
20761 +{
20762 +       vxdprintk(VXD_CBIT(dlim, 6),
20763 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
20764 +       hlist_del_rcu(&dli->dl_hlist);
20765 +       put_dl_info(dli);
20766 +}
20767 +
20768 +
20769 +/*     __lookup_dl_info()
20770 +
20771 +       * requires the rcu_read_lock()
20772 +       * doesn't increment the dl_refcnt                       */
20773 +
20774 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
20775 +{
20776 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
20777 +       struct hlist_node *pos;
20778 +       struct dl_info *dli;
20779 +
20780 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
20781 +
20782 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
20783 +                       return dli;
20784 +               }
20785 +       }
20786 +       return NULL;
20787 +}
20788 +
20789 +
20790 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
20791 +{
20792 +       struct dl_info *dli;
20793 +
20794 +       rcu_read_lock();
20795 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
20796 +       vxdprintk(VXD_CBIT(dlim, 7),
20797 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
20798 +       rcu_read_unlock();
20799 +       return dli;
20800 +}
20801 +
20802 +void rcu_free_dl_info(struct rcu_head *head)
20803 +{
20804 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
20805 +       int usecnt, refcnt;
20806 +
20807 +       BUG_ON(!dli || !head);
20808 +
20809 +       usecnt = atomic_read(&dli->dl_usecnt);
20810 +       BUG_ON(usecnt < 0);
20811 +
20812 +       refcnt = atomic_read(&dli->dl_refcnt);
20813 +       BUG_ON(refcnt < 0);
20814 +
20815 +       vxdprintk(VXD_CBIT(dlim, 3),
20816 +               "rcu_free_dl_info(%p)", dli);
20817 +       if (!usecnt)
20818 +               __dealloc_dl_info(dli);
20819 +       else
20820 +               printk("!!! rcu didn't free\n");
20821 +}
20822 +
20823 +
20824 +
20825 +
20826 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
20827 +       uint32_t flags, int add)
20828 +{
20829 +       struct path path;
20830 +       int ret;
20831 +
20832 +       ret = user_lpath(name, &path);
20833 +       if (!ret) {
20834 +               struct super_block *sb;
20835 +               struct dl_info *dli;
20836 +
20837 +               ret = -EINVAL;
20838 +               if (!path.dentry->d_inode)
20839 +                       goto out_release;
20840 +               if (!(sb = path.dentry->d_inode->i_sb))
20841 +                       goto out_release;
20842 +
20843 +               if (add) {
20844 +                       dli = __alloc_dl_info(sb, id);
20845 +                       spin_lock(&dl_info_hash_lock);
20846 +
20847 +                       ret = -EEXIST;
20848 +                       if (__lookup_dl_info(sb, id))
20849 +                               goto out_unlock;
20850 +                       __hash_dl_info(dli);
20851 +                       dli = NULL;
20852 +               } else {
20853 +                       spin_lock(&dl_info_hash_lock);
20854 +                       dli = __lookup_dl_info(sb, id);
20855 +
20856 +                       ret = -ESRCH;
20857 +                       if (!dli)
20858 +                               goto out_unlock;
20859 +                       __unhash_dl_info(dli);
20860 +               }
20861 +               ret = 0;
20862 +       out_unlock:
20863 +               spin_unlock(&dl_info_hash_lock);
20864 +               if (add && dli)
20865 +                       __dealloc_dl_info(dli);
20866 +       out_release:
20867 +               path_put(&path);
20868 +       }
20869 +       return ret;
20870 +}
20871 +
20872 +int vc_add_dlimit(uint32_t id, void __user *data)
20873 +{
20874 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20875 +
20876 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20877 +               return -EFAULT;
20878 +
20879 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
20880 +}
20881 +
20882 +int vc_rem_dlimit(uint32_t id, void __user *data)
20883 +{
20884 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20885 +
20886 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20887 +               return -EFAULT;
20888 +
20889 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
20890 +}
20891 +
20892 +#ifdef CONFIG_COMPAT
20893 +
20894 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
20895 +{
20896 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20897 +
20898 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20899 +               return -EFAULT;
20900 +
20901 +       return do_addrem_dlimit(id,
20902 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
20903 +}
20904 +
20905 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
20906 +{
20907 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20908 +
20909 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20910 +               return -EFAULT;
20911 +
20912 +       return do_addrem_dlimit(id,
20913 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
20914 +}
20915 +
20916 +#endif /* CONFIG_COMPAT */
20917 +
20918 +
20919 +static inline
20920 +int do_set_dlimit(uint32_t id, const char __user *name,
20921 +       uint32_t space_used, uint32_t space_total,
20922 +       uint32_t inodes_used, uint32_t inodes_total,
20923 +       uint32_t reserved, uint32_t flags)
20924 +{
20925 +       struct path path;
20926 +       int ret;
20927 +
20928 +       ret = user_lpath(name, &path);
20929 +       if (!ret) {
20930 +               struct super_block *sb;
20931 +               struct dl_info *dli;
20932 +
20933 +               ret = -EINVAL;
20934 +               if (!path.dentry->d_inode)
20935 +                       goto out_release;
20936 +               if (!(sb = path.dentry->d_inode->i_sb))
20937 +                       goto out_release;
20938 +
20939 +               /* sanity checks */
20940 +               if ((reserved != CDLIM_KEEP &&
20941 +                       reserved > 100) ||
20942 +                       (inodes_used != CDLIM_KEEP &&
20943 +                       inodes_used > inodes_total) ||
20944 +                       (space_used != CDLIM_KEEP &&
20945 +                       space_used > space_total))
20946 +                       goto out_release;
20947 +
20948 +               ret = -ESRCH;
20949 +               dli = locate_dl_info(sb, id);
20950 +               if (!dli)
20951 +                       goto out_release;
20952 +
20953 +               spin_lock(&dli->dl_lock);
20954 +
20955 +               if (inodes_used != CDLIM_KEEP)
20956 +                       dli->dl_inodes_used = inodes_used;
20957 +               if (inodes_total != CDLIM_KEEP)
20958 +                       dli->dl_inodes_total = inodes_total;
20959 +               if (space_used != CDLIM_KEEP)
20960 +                       dli->dl_space_used = dlimit_space_32to64(
20961 +                               space_used, flags, DLIMS_USED);
20962 +
20963 +               if (space_total == CDLIM_INFINITY)
20964 +                       dli->dl_space_total = DLIM_INFINITY;
20965 +               else if (space_total != CDLIM_KEEP)
20966 +                       dli->dl_space_total = dlimit_space_32to64(
20967 +                               space_total, flags, DLIMS_TOTAL);
20968 +
20969 +               if (reserved != CDLIM_KEEP)
20970 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
20971 +
20972 +               spin_unlock(&dli->dl_lock);
20973 +
20974 +               put_dl_info(dli);
20975 +               ret = 0;
20976 +
20977 +       out_release:
20978 +               path_put(&path);
20979 +       }
20980 +       return ret;
20981 +}
20982 +
20983 +int vc_set_dlimit(uint32_t id, void __user *data)
20984 +{
20985 +       struct vcmd_ctx_dlimit_v0 vc_data;
20986 +
20987 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20988 +               return -EFAULT;
20989 +
20990 +       return do_set_dlimit(id, vc_data.name,
20991 +               vc_data.space_used, vc_data.space_total,
20992 +               vc_data.inodes_used, vc_data.inodes_total,
20993 +               vc_data.reserved, vc_data.flags);
20994 +}
20995 +
20996 +#ifdef CONFIG_COMPAT
20997 +
20998 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20999 +{
21000 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
21001 +
21002 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21003 +               return -EFAULT;
21004 +
21005 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
21006 +               vc_data.space_used, vc_data.space_total,
21007 +               vc_data.inodes_used, vc_data.inodes_total,
21008 +               vc_data.reserved, vc_data.flags);
21009 +}
21010 +
21011 +#endif /* CONFIG_COMPAT */
21012 +
21013 +
21014 +static inline
21015 +int do_get_dlimit(uint32_t id, const char __user *name,
21016 +       uint32_t *space_used, uint32_t *space_total,
21017 +       uint32_t *inodes_used, uint32_t *inodes_total,
21018 +       uint32_t *reserved, uint32_t *flags)
21019 +{
21020 +       struct path path;
21021 +       int ret;
21022 +
21023 +       ret = user_lpath(name, &path);
21024 +       if (!ret) {
21025 +               struct super_block *sb;
21026 +               struct dl_info *dli;
21027 +
21028 +               ret = -EINVAL;
21029 +               if (!path.dentry->d_inode)
21030 +                       goto out_release;
21031 +               if (!(sb = path.dentry->d_inode->i_sb))
21032 +                       goto out_release;
21033 +
21034 +               ret = -ESRCH;
21035 +               dli = locate_dl_info(sb, id);
21036 +               if (!dli)
21037 +                       goto out_release;
21038 +
21039 +               spin_lock(&dli->dl_lock);
21040 +               *inodes_used = dli->dl_inodes_used;
21041 +               *inodes_total = dli->dl_inodes_total;
21042 +
21043 +               *space_used = dlimit_space_64to32(
21044 +                       dli->dl_space_used, flags, DLIMS_USED);
21045 +
21046 +               if (dli->dl_space_total == DLIM_INFINITY)
21047 +                       *space_total = CDLIM_INFINITY;
21048 +               else
21049 +                       *space_total = dlimit_space_64to32(
21050 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
21051 +
21052 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
21053 +               spin_unlock(&dli->dl_lock);
21054 +
21055 +               put_dl_info(dli);
21056 +               ret = -EFAULT;
21057 +
21058 +               ret = 0;
21059 +       out_release:
21060 +               path_put(&path);
21061 +       }
21062 +       return ret;
21063 +}
21064 +
21065 +
21066 +int vc_get_dlimit(uint32_t id, void __user *data)
21067 +{
21068 +       struct vcmd_ctx_dlimit_v0 vc_data;
21069 +       int ret;
21070 +
21071 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21072 +               return -EFAULT;
21073 +
21074 +       ret = do_get_dlimit(id, vc_data.name,
21075 +               &vc_data.space_used, &vc_data.space_total,
21076 +               &vc_data.inodes_used, &vc_data.inodes_total,
21077 +               &vc_data.reserved, &vc_data.flags);
21078 +       if (ret)
21079 +               return ret;
21080 +
21081 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21082 +               return -EFAULT;
21083 +       return 0;
21084 +}
21085 +
21086 +#ifdef CONFIG_COMPAT
21087 +
21088 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
21089 +{
21090 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
21091 +       int ret;
21092 +
21093 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21094 +               return -EFAULT;
21095 +
21096 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
21097 +               &vc_data.space_used, &vc_data.space_total,
21098 +               &vc_data.inodes_used, &vc_data.inodes_total,
21099 +               &vc_data.reserved, &vc_data.flags);
21100 +       if (ret)
21101 +               return ret;
21102 +
21103 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21104 +               return -EFAULT;
21105 +       return 0;
21106 +}
21107 +
21108 +#endif /* CONFIG_COMPAT */
21109 +
21110 +
21111 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
21112 +{
21113 +       struct dl_info *dli;
21114 +       __u64 blimit, bfree, bavail;
21115 +       __u32 ifree;
21116 +
21117 +       dli = locate_dl_info(sb, dx_current_tag());
21118 +       if (!dli)
21119 +               return;
21120 +
21121 +       spin_lock(&dli->dl_lock);
21122 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
21123 +               goto no_ilim;
21124 +
21125 +       /* reduce max inodes available to limit */
21126 +       if (buf->f_files > dli->dl_inodes_total)
21127 +               buf->f_files = dli->dl_inodes_total;
21128 +
21129 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
21130 +       /* reduce free inodes to min */
21131 +       if (ifree < buf->f_ffree)
21132 +               buf->f_ffree = ifree;
21133 +
21134 +no_ilim:
21135 +       if (dli->dl_space_total == DLIM_INFINITY)
21136 +               goto no_blim;
21137 +
21138 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
21139 +
21140 +       if (dli->dl_space_total < dli->dl_space_used)
21141 +               bfree = 0;
21142 +       else
21143 +               bfree = (dli->dl_space_total - dli->dl_space_used)
21144 +                       >> sb->s_blocksize_bits;
21145 +
21146 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
21147 +       if (bavail < dli->dl_space_used)
21148 +               bavail = 0;
21149 +       else
21150 +               bavail = (bavail - dli->dl_space_used)
21151 +                       >> sb->s_blocksize_bits;
21152 +
21153 +       /* reduce max space available to limit */
21154 +       if (buf->f_blocks > blimit)
21155 +               buf->f_blocks = blimit;
21156 +
21157 +       /* reduce free space to min */
21158 +       if (bfree < buf->f_bfree)
21159 +               buf->f_bfree = bfree;
21160 +
21161 +       /* reduce avail space to min */
21162 +       if (bavail < buf->f_bavail)
21163 +               buf->f_bavail = bavail;
21164 +
21165 +no_blim:
21166 +       spin_unlock(&dli->dl_lock);
21167 +       put_dl_info(dli);
21168 +
21169 +       return;
21170 +}
21171 +
21172 +#include <linux/module.h>
21173 +
21174 +EXPORT_SYMBOL_GPL(locate_dl_info);
21175 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
21176 +
21177 diff -NurpP --minimal linux-2.6.33/kernel/vserver/helper.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/helper.c
21178 --- linux-2.6.33/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
21179 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/helper.c        2010-02-25 12:02:16.000000000 +0100
21180 @@ -0,0 +1,223 @@
21181 +/*
21182 + *  linux/kernel/vserver/helper.c
21183 + *
21184 + *  Virtual Context Support
21185 + *
21186 + *  Copyright (C) 2004-2007  Herbert Pötzl
21187 + *
21188 + *  V0.01  basic helper
21189 + *
21190 + */
21191 +
21192 +#include <linux/kmod.h>
21193 +#include <linux/reboot.h>
21194 +#include <linux/vs_context.h>
21195 +#include <linux/vs_network.h>
21196 +#include <linux/vserver/signal.h>
21197 +
21198 +
21199 +char vshelper_path[255] = "/sbin/vshelper";
21200 +
21201 +
21202 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
21203 +{
21204 +       int ret;
21205 +
21206 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
21207 +               printk( KERN_WARNING
21208 +                       "%s: (%s %s) returned %s with %d\n",
21209 +                       name, argv[1], argv[2],
21210 +                       sync ? "sync" : "async", ret);
21211 +       }
21212 +       vxdprintk(VXD_CBIT(switch, 4),
21213 +               "%s: (%s %s) returned %s with %d",
21214 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
21215 +       return ret;
21216 +}
21217 +
21218 +/*
21219 + *      vshelper path is set via /proc/sys
21220 + *      invoked by vserver sys_reboot(), with
21221 + *      the following arguments
21222 + *
21223 + *      argv [0] = vshelper_path;
21224 + *      argv [1] = action: "restart", "halt", "poweroff", ...
21225 + *      argv [2] = context identifier
21226 + *
21227 + *      envp [*] = type-specific parameters
21228 + */
21229 +
21230 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
21231 +{
21232 +       char id_buf[8], cmd_buf[16];
21233 +       char uid_buf[16], pid_buf[16];
21234 +       int ret;
21235 +
21236 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
21237 +       char *envp[] = {"HOME=/", "TERM=linux",
21238 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
21239 +                       uid_buf, pid_buf, cmd_buf, 0};
21240 +
21241 +       if (vx_info_state(vxi, VXS_HELPER))
21242 +               return -EAGAIN;
21243 +       vxi->vx_state |= VXS_HELPER;
21244 +
21245 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
21246 +
21247 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
21248 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
21249 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
21250 +
21251 +       switch (cmd) {
21252 +       case LINUX_REBOOT_CMD_RESTART:
21253 +               argv[1] = "restart";
21254 +               break;
21255 +
21256 +       case LINUX_REBOOT_CMD_HALT:
21257 +               argv[1] = "halt";
21258 +               break;
21259 +
21260 +       case LINUX_REBOOT_CMD_POWER_OFF:
21261 +               argv[1] = "poweroff";
21262 +               break;
21263 +
21264 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
21265 +               argv[1] = "swsusp";
21266 +               break;
21267 +
21268 +       case LINUX_REBOOT_CMD_OOM:
21269 +               argv[1] = "oom";
21270 +               break;
21271 +
21272 +       default:
21273 +               vxi->vx_state &= ~VXS_HELPER;
21274 +               return 0;
21275 +       }
21276 +
21277 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
21278 +       vxi->vx_state &= ~VXS_HELPER;
21279 +       __wakeup_vx_info(vxi);
21280 +       return (ret) ? -EPERM : 0;
21281 +}
21282 +
21283 +
21284 +long vs_reboot(unsigned int cmd, void __user *arg)
21285 +{
21286 +       struct vx_info *vxi = current_vx_info();
21287 +       long ret = 0;
21288 +
21289 +       vxdprintk(VXD_CBIT(misc, 5),
21290 +               "vs_reboot(%p[#%d],%u)",
21291 +               vxi, vxi ? vxi->vx_id : 0, cmd);
21292 +
21293 +       ret = vs_reboot_helper(vxi, cmd, arg);
21294 +       if (ret)
21295 +               return ret;
21296 +
21297 +       vxi->reboot_cmd = cmd;
21298 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
21299 +               switch (cmd) {
21300 +               case LINUX_REBOOT_CMD_RESTART:
21301 +               case LINUX_REBOOT_CMD_HALT:
21302 +               case LINUX_REBOOT_CMD_POWER_OFF:
21303 +                       vx_info_kill(vxi, 0, SIGKILL);
21304 +                       vx_info_kill(vxi, 1, SIGKILL);
21305 +               default:
21306 +                       break;
21307 +               }
21308 +       }
21309 +       return 0;
21310 +}
21311 +
21312 +long vs_oom_action(unsigned int cmd)
21313 +{
21314 +       struct vx_info *vxi = current_vx_info();
21315 +       long ret = 0;
21316 +
21317 +       vxdprintk(VXD_CBIT(misc, 5),
21318 +               "vs_oom_action(%p[#%d],%u)",
21319 +               vxi, vxi ? vxi->vx_id : 0, cmd);
21320 +
21321 +       ret = vs_reboot_helper(vxi, cmd, NULL);
21322 +       if (ret)
21323 +               return ret;
21324 +
21325 +       vxi->reboot_cmd = cmd;
21326 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
21327 +               vx_info_kill(vxi, 0, SIGKILL);
21328 +               vx_info_kill(vxi, 1, SIGKILL);
21329 +       }
21330 +       return 0;
21331 +}
21332 +
21333 +/*
21334 + *      argv [0] = vshelper_path;
21335 + *      argv [1] = action: "startup", "shutdown"
21336 + *      argv [2] = context identifier
21337 + *
21338 + *      envp [*] = type-specific parameters
21339 + */
21340 +
21341 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
21342 +{
21343 +       char id_buf[8], cmd_buf[16];
21344 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
21345 +       char *envp[] = {"HOME=/", "TERM=linux",
21346 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
21347 +
21348 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
21349 +               return 0;
21350 +
21351 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
21352 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
21353 +
21354 +       switch (cmd) {
21355 +       case VSC_STARTUP:
21356 +               argv[1] = "startup";
21357 +               break;
21358 +       case VSC_SHUTDOWN:
21359 +               argv[1] = "shutdown";
21360 +               break;
21361 +       default:
21362 +               return 0;
21363 +       }
21364 +
21365 +       return do_vshelper(vshelper_path, argv, envp, 1);
21366 +}
21367 +
21368 +
21369 +/*
21370 + *      argv [0] = vshelper_path;
21371 + *      argv [1] = action: "netup", "netdown"
21372 + *      argv [2] = context identifier
21373 + *
21374 + *      envp [*] = type-specific parameters
21375 + */
21376 +
21377 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
21378 +{
21379 +       char id_buf[8], cmd_buf[16];
21380 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
21381 +       char *envp[] = {"HOME=/", "TERM=linux",
21382 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
21383 +
21384 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
21385 +               return 0;
21386 +
21387 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
21388 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
21389 +
21390 +       switch (cmd) {
21391 +       case VSC_NETUP:
21392 +               argv[1] = "netup";
21393 +               break;
21394 +       case VSC_NETDOWN:
21395 +               argv[1] = "netdown";
21396 +               break;
21397 +       default:
21398 +               return 0;
21399 +       }
21400 +
21401 +       return do_vshelper(vshelper_path, argv, envp, 1);
21402 +}
21403 +
21404 diff -NurpP --minimal linux-2.6.33/kernel/vserver/history.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/history.c
21405 --- linux-2.6.33/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
21406 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/history.c       2010-02-25 12:02:16.000000000 +0100
21407 @@ -0,0 +1,258 @@
21408 +/*
21409 + *  kernel/vserver/history.c
21410 + *
21411 + *  Virtual Context History Backtrace
21412 + *
21413 + *  Copyright (C) 2004-2007  Herbert Pötzl
21414 + *
21415 + *  V0.01  basic structure
21416 + *  V0.02  hash/unhash and trace
21417 + *  V0.03  preemption fixes
21418 + *
21419 + */
21420 +
21421 +#include <linux/module.h>
21422 +#include <asm/uaccess.h>
21423 +
21424 +#include <linux/vserver/context.h>
21425 +#include <linux/vserver/debug.h>
21426 +#include <linux/vserver/debug_cmd.h>
21427 +#include <linux/vserver/history.h>
21428 +
21429 +
21430 +#ifdef CONFIG_VSERVER_HISTORY
21431 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
21432 +#else
21433 +#define VXH_SIZE       64
21434 +#endif
21435 +
21436 +struct _vx_history {
21437 +       unsigned int counter;
21438 +
21439 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
21440 +};
21441 +
21442 +
21443 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
21444 +
21445 +unsigned volatile int vxh_active = 1;
21446 +
21447 +static atomic_t sequence = ATOMIC_INIT(0);
21448 +
21449 +
21450 +/*     vxh_advance()
21451 +
21452 +       * requires disabled preemption                          */
21453 +
21454 +struct _vx_hist_entry *vxh_advance(void *loc)
21455 +{
21456 +       unsigned int cpu = smp_processor_id();
21457 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
21458 +       struct _vx_hist_entry *entry;
21459 +       unsigned int index;
21460 +
21461 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
21462 +       entry = &hist->entry[index];
21463 +
21464 +       entry->seq = atomic_inc_return(&sequence);
21465 +       entry->loc = loc;
21466 +       return entry;
21467 +}
21468 +
21469 +EXPORT_SYMBOL_GPL(vxh_advance);
21470 +
21471 +
21472 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
21473 +
21474 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
21475 +
21476 +
21477 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
21478 +
21479 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
21480 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
21481 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
21482 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
21483 +
21484 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
21485 +{
21486 +       switch (e->type) {
21487 +       case VXH_THROW_OOPS:
21488 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
21489 +               break;
21490 +
21491 +       case VXH_GET_VX_INFO:
21492 +       case VXH_PUT_VX_INFO:
21493 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
21494 +                       VXH_LOC_ARGS(e),
21495 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
21496 +                       VXH_VXI_ARGS(e));
21497 +               break;
21498 +
21499 +       case VXH_INIT_VX_INFO:
21500 +       case VXH_SET_VX_INFO:
21501 +       case VXH_CLR_VX_INFO:
21502 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
21503 +                       VXH_LOC_ARGS(e),
21504 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
21505 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
21506 +                       VXH_VXI_ARGS(e), e->sc.data);
21507 +               break;
21508 +
21509 +       case VXH_CLAIM_VX_INFO:
21510 +       case VXH_RELEASE_VX_INFO:
21511 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
21512 +                       VXH_LOC_ARGS(e),
21513 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
21514 +                       VXH_VXI_ARGS(e), e->sc.data);
21515 +               break;
21516 +
21517 +       case VXH_ALLOC_VX_INFO:
21518 +       case VXH_DEALLOC_VX_INFO:
21519 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
21520 +                       VXH_LOC_ARGS(e),
21521 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
21522 +                       VXH_VXI_ARGS(e));
21523 +               break;
21524 +
21525 +       case VXH_HASH_VX_INFO:
21526 +       case VXH_UNHASH_VX_INFO:
21527 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
21528 +                       VXH_LOC_ARGS(e),
21529 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
21530 +                       VXH_VXI_ARGS(e));
21531 +               break;
21532 +
21533 +       case VXH_LOC_VX_INFO:
21534 +       case VXH_LOOKUP_VX_INFO:
21535 +       case VXH_CREATE_VX_INFO:
21536 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
21537 +                       VXH_LOC_ARGS(e),
21538 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
21539 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
21540 +                       e->ll.arg, VXH_VXI_ARGS(e));
21541 +               break;
21542 +       }
21543 +}
21544 +
21545 +static void __vxh_dump_history(void)
21546 +{
21547 +       unsigned int i, cpu;
21548 +
21549 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
21550 +               atomic_read(&sequence), NR_CPUS);
21551 +
21552 +       for (i = 0; i < VXH_SIZE; i++) {
21553 +               for_each_online_cpu(cpu) {
21554 +                       struct _vx_history *hist =
21555 +                               &per_cpu(vx_history_buffer, cpu);
21556 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
21557 +                       struct _vx_hist_entry *entry = &hist->entry[index];
21558 +
21559 +                       vxh_dump_entry(entry, cpu);
21560 +               }
21561 +       }
21562 +}
21563 +
21564 +void   vxh_dump_history(void)
21565 +{
21566 +       vxh_active = 0;
21567 +#ifdef CONFIG_SMP
21568 +       local_irq_enable();
21569 +       smp_send_stop();
21570 +       local_irq_disable();
21571 +#endif
21572 +       __vxh_dump_history();
21573 +}
21574 +
21575 +
21576 +/* vserver syscall commands below here */
21577 +
21578 +
21579 +int vc_dump_history(uint32_t id)
21580 +{
21581 +       vxh_active = 0;
21582 +       __vxh_dump_history();
21583 +       vxh_active = 1;
21584 +
21585 +       return 0;
21586 +}
21587 +
21588 +
21589 +int do_read_history(struct __user _vx_hist_entry *data,
21590 +       int cpu, uint32_t *index, uint32_t *count)
21591 +{
21592 +       int pos, ret = 0;
21593 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
21594 +       int end = hist->counter;
21595 +       int start = end - VXH_SIZE + 2;
21596 +       int idx = *index;
21597 +
21598 +       /* special case: get current pos */
21599 +       if (!*count) {
21600 +               *index = end;
21601 +               return 0;
21602 +       }
21603 +
21604 +       /* have we lost some data? */
21605 +       if (idx < start)
21606 +               idx = start;
21607 +
21608 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21609 +               struct _vx_hist_entry *entry =
21610 +                       &hist->entry[idx % VXH_SIZE];
21611 +
21612 +               /* send entry to userspace */
21613 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21614 +               if (ret)
21615 +                       break;
21616 +       }
21617 +       /* save new index and count */
21618 +       *index = idx;
21619 +       *count = pos;
21620 +       return ret ? ret : (*index < end);
21621 +}
21622 +
21623 +int vc_read_history(uint32_t id, void __user *data)
21624 +{
21625 +       struct vcmd_read_history_v0 vc_data;
21626 +       int ret;
21627 +
21628 +       if (id >= NR_CPUS)
21629 +               return -EINVAL;
21630 +
21631 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21632 +               return -EFAULT;
21633 +
21634 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
21635 +               id, &vc_data.index, &vc_data.count);
21636 +
21637 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21638 +               return -EFAULT;
21639 +       return ret;
21640 +}
21641 +
21642 +#ifdef CONFIG_COMPAT
21643 +
21644 +int vc_read_history_x32(uint32_t id, void __user *data)
21645 +{
21646 +       struct vcmd_read_history_v0_x32 vc_data;
21647 +       int ret;
21648 +
21649 +       if (id >= NR_CPUS)
21650 +               return -EINVAL;
21651 +
21652 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21653 +               return -EFAULT;
21654 +
21655 +       ret = do_read_history((struct __user _vx_hist_entry *)
21656 +               compat_ptr(vc_data.data_ptr),
21657 +               id, &vc_data.index, &vc_data.count);
21658 +
21659 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21660 +               return -EFAULT;
21661 +       return ret;
21662 +}
21663 +
21664 +#endif /* CONFIG_COMPAT */
21665 +
21666 diff -NurpP --minimal linux-2.6.33/kernel/vserver/inet.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/inet.c
21667 --- linux-2.6.33/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
21668 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/inet.c  2010-02-25 12:02:16.000000000 +0100
21669 @@ -0,0 +1,225 @@
21670 +
21671 +#include <linux/in.h>
21672 +#include <linux/inetdevice.h>
21673 +#include <linux/vs_inet.h>
21674 +#include <linux/vs_inet6.h>
21675 +#include <linux/vserver/debug.h>
21676 +#include <net/route.h>
21677 +#include <net/addrconf.h>
21678 +
21679 +
21680 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
21681 +{
21682 +       int ret = 0;
21683 +
21684 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
21685 +               ret = 1;
21686 +       else {
21687 +               struct nx_addr_v4 *ptr;
21688 +
21689 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
21690 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
21691 +                               ret = 1;
21692 +                               break;
21693 +                       }
21694 +               }
21695 +       }
21696 +
21697 +       vxdprintk(VXD_CBIT(net, 2),
21698 +               "nx_v4_addr_conflict(%p,%p): %d",
21699 +               nxi1, nxi2, ret);
21700 +
21701 +       return ret;
21702 +}
21703 +
21704 +
21705 +#ifdef CONFIG_IPV6
21706 +
21707 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
21708 +{
21709 +       int ret = 0;
21710 +
21711 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
21712 +               ret = 1;
21713 +       else {
21714 +               struct nx_addr_v6 *ptr;
21715 +
21716 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
21717 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
21718 +                               ret = 1;
21719 +                               break;
21720 +                       }
21721 +               }
21722 +       }
21723 +
21724 +       vxdprintk(VXD_CBIT(net, 2),
21725 +               "nx_v6_addr_conflict(%p,%p): %d",
21726 +               nxi1, nxi2, ret);
21727 +
21728 +       return ret;
21729 +}
21730 +
21731 +#endif
21732 +
21733 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21734 +{
21735 +       struct in_device *in_dev;
21736 +       struct in_ifaddr **ifap;
21737 +       struct in_ifaddr *ifa;
21738 +       int ret = 0;
21739 +
21740 +       if (!dev)
21741 +               goto out;
21742 +       in_dev = in_dev_get(dev);
21743 +       if (!in_dev)
21744 +               goto out;
21745 +
21746 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
21747 +               ifap = &ifa->ifa_next) {
21748 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
21749 +                       ret = 1;
21750 +                       break;
21751 +               }
21752 +       }
21753 +       in_dev_put(in_dev);
21754 +out:
21755 +       return ret;
21756 +}
21757 +
21758 +
21759 +#ifdef CONFIG_IPV6
21760 +
21761 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21762 +{
21763 +       struct inet6_dev *in_dev;
21764 +       struct inet6_ifaddr **ifap;
21765 +       struct inet6_ifaddr *ifa;
21766 +       int ret = 0;
21767 +
21768 +       if (!dev)
21769 +               goto out;
21770 +       in_dev = in6_dev_get(dev);
21771 +       if (!in_dev)
21772 +               goto out;
21773 +
21774 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
21775 +               ifap = &ifa->if_next) {
21776 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
21777 +                       ret = 1;
21778 +                       break;
21779 +               }
21780 +       }
21781 +       in6_dev_put(in_dev);
21782 +out:
21783 +       return ret;
21784 +}
21785 +
21786 +#endif
21787 +
21788 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21789 +{
21790 +       int ret = 1;
21791 +
21792 +       if (!nxi)
21793 +               goto out;
21794 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
21795 +               goto out;
21796 +#ifdef CONFIG_IPV6
21797 +       ret = 2;
21798 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
21799 +               goto out;
21800 +#endif
21801 +       ret = 0;
21802 +out:
21803 +       vxdprintk(VXD_CBIT(net, 3),
21804 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
21805 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
21806 +       return ret;
21807 +}
21808 +
21809 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
21810 +       struct rtable **rp, struct flowi *fl)
21811 +{
21812 +       if (!nxi)
21813 +               return 0;
21814 +
21815 +       /* FIXME: handle lback only case */
21816 +       if (!NX_IPV4(nxi))
21817 +               return -EPERM;
21818 +
21819 +       vxdprintk(VXD_CBIT(net, 4),
21820 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
21821 +               nxi, nxi ? nxi->nx_id : 0,
21822 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
21823 +
21824 +       /* single IP is unconditional */
21825 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
21826 +               (fl->fl4_src == INADDR_ANY))
21827 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
21828 +
21829 +       if (fl->fl4_src == INADDR_ANY) {
21830 +               struct nx_addr_v4 *ptr;
21831 +               __be32 found = 0;
21832 +               int err;
21833 +
21834 +               err = __ip_route_output_key(net, rp, fl);
21835 +               if (!err) {
21836 +                       found = (*rp)->rt_src;
21837 +                       ip_rt_put(*rp);
21838 +                       vxdprintk(VXD_CBIT(net, 4),
21839 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21840 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
21841 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
21842 +                               goto found;
21843 +               }
21844 +
21845 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
21846 +                       __be32 primary = ptr->ip[0].s_addr;
21847 +                       __be32 mask = ptr->mask.s_addr;
21848 +                       __be32 neta = primary & mask;
21849 +
21850 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
21851 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
21852 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
21853 +                               NIPQUAD(mask), NIPQUAD(neta));
21854 +                       if ((found & mask) != neta)
21855 +                               continue;
21856 +
21857 +                       fl->fl4_src = primary;
21858 +                       err = __ip_route_output_key(net, rp, fl);
21859 +                       vxdprintk(VXD_CBIT(net, 4),
21860 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21861 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
21862 +                       if (!err) {
21863 +                               found = (*rp)->rt_src;
21864 +                               ip_rt_put(*rp);
21865 +                               if (found == primary)
21866 +                                       goto found;
21867 +                       }
21868 +               }
21869 +               /* still no source ip? */
21870 +               found = ipv4_is_loopback(fl->fl4_dst)
21871 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
21872 +       found:
21873 +               /* assign src ip to flow */
21874 +               fl->fl4_src = found;
21875 +
21876 +       } else {
21877 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
21878 +                       return -EPERM;
21879 +       }
21880 +
21881 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
21882 +               if (ipv4_is_loopback(fl->fl4_dst))
21883 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
21884 +               if (ipv4_is_loopback(fl->fl4_src))
21885 +                       fl->fl4_src = nxi->v4_lback.s_addr;
21886 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
21887 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
21888 +               return -EPERM;
21889 +
21890 +       return 0;
21891 +}
21892 +
21893 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
21894 +
21895 diff -NurpP --minimal linux-2.6.33/kernel/vserver/init.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/init.c
21896 --- linux-2.6.33/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
21897 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/init.c  2010-02-25 12:02:16.000000000 +0100
21898 @@ -0,0 +1,45 @@
21899 +/*
21900 + *  linux/kernel/init.c
21901 + *
21902 + *  Virtual Server Init
21903 + *
21904 + *  Copyright (C) 2004-2007  Herbert Pötzl
21905 + *
21906 + *  V0.01  basic structure
21907 + *
21908 + */
21909 +
21910 +#include <linux/init.h>
21911 +
21912 +int    vserver_register_sysctl(void);
21913 +void   vserver_unregister_sysctl(void);
21914 +
21915 +
21916 +static int __init init_vserver(void)
21917 +{
21918 +       int ret = 0;
21919 +
21920 +#ifdef CONFIG_VSERVER_DEBUG
21921 +       vserver_register_sysctl();
21922 +#endif
21923 +       return ret;
21924 +}
21925 +
21926 +
21927 +static void __exit exit_vserver(void)
21928 +{
21929 +
21930 +#ifdef CONFIG_VSERVER_DEBUG
21931 +       vserver_unregister_sysctl();
21932 +#endif
21933 +       return;
21934 +}
21935 +
21936 +/* FIXME: GFP_ZONETYPES gone
21937 +long vx_slab[GFP_ZONETYPES]; */
21938 +long vx_area;
21939 +
21940 +
21941 +module_init(init_vserver);
21942 +module_exit(exit_vserver);
21943 +
21944 diff -NurpP --minimal linux-2.6.33/kernel/vserver/inode.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/inode.c
21945 --- linux-2.6.33/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
21946 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/inode.c 2010-02-25 12:02:16.000000000 +0100
21947 @@ -0,0 +1,433 @@
21948 +/*
21949 + *  linux/kernel/vserver/inode.c
21950 + *
21951 + *  Virtual Server: File System Support
21952 + *
21953 + *  Copyright (C) 2004-2007  Herbert Pötzl
21954 + *
21955 + *  V0.01  separated from vcontext V0.05
21956 + *  V0.02  moved to tag (instead of xid)
21957 + *
21958 + */
21959 +
21960 +#include <linux/tty.h>
21961 +#include <linux/proc_fs.h>
21962 +#include <linux/devpts_fs.h>
21963 +#include <linux/fs.h>
21964 +#include <linux/file.h>
21965 +#include <linux/mount.h>
21966 +#include <linux/parser.h>
21967 +#include <linux/namei.h>
21968 +#include <linux/vserver/inode.h>
21969 +#include <linux/vserver/inode_cmd.h>
21970 +#include <linux/vs_base.h>
21971 +#include <linux/vs_tag.h>
21972 +
21973 +#include <asm/uaccess.h>
21974 +
21975 +
21976 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21977 +{
21978 +       struct proc_dir_entry *entry;
21979 +
21980 +       if (!in || !in->i_sb)
21981 +               return -ESRCH;
21982 +
21983 +       *flags = IATTR_TAG
21984 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
21985 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
21986 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
21987 +               | (IS_COW(in) ? IATTR_COW : 0);
21988 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
21989 +
21990 +       if (S_ISDIR(in->i_mode))
21991 +               *mask |= IATTR_BARRIER;
21992 +
21993 +       if (IS_TAGGED(in)) {
21994 +               *tag = in->i_tag;
21995 +               *mask |= IATTR_TAG;
21996 +       }
21997 +
21998 +       switch (in->i_sb->s_magic) {
21999 +       case PROC_SUPER_MAGIC:
22000 +               entry = PROC_I(in)->pde;
22001 +
22002 +               /* check for specific inodes? */
22003 +               if (entry)
22004 +                       *mask |= IATTR_FLAGS;
22005 +               if (entry)
22006 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
22007 +               else
22008 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
22009 +               break;
22010 +
22011 +       case DEVPTS_SUPER_MAGIC:
22012 +               *tag = in->i_tag;
22013 +               *mask |= IATTR_TAG;
22014 +               break;
22015 +
22016 +       default:
22017 +               break;
22018 +       }
22019 +       return 0;
22020 +}
22021 +
22022 +int vc_get_iattr(void __user *data)
22023 +{
22024 +       struct path path;
22025 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
22026 +       int ret;
22027 +
22028 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22029 +               return -EFAULT;
22030 +
22031 +       ret = user_lpath(vc_data.name, &path);
22032 +       if (!ret) {
22033 +               ret = __vc_get_iattr(path.dentry->d_inode,
22034 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
22035 +               path_put(&path);
22036 +       }
22037 +       if (ret)
22038 +               return ret;
22039 +
22040 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22041 +               ret = -EFAULT;
22042 +       return ret;
22043 +}
22044 +
22045 +#ifdef CONFIG_COMPAT
22046 +
22047 +int vc_get_iattr_x32(void __user *data)
22048 +{
22049 +       struct path path;
22050 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
22051 +       int ret;
22052 +
22053 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22054 +               return -EFAULT;
22055 +
22056 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
22057 +       if (!ret) {
22058 +               ret = __vc_get_iattr(path.dentry->d_inode,
22059 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
22060 +               path_put(&path);
22061 +       }
22062 +       if (ret)
22063 +               return ret;
22064 +
22065 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22066 +               ret = -EFAULT;
22067 +       return ret;
22068 +}
22069 +
22070 +#endif /* CONFIG_COMPAT */
22071 +
22072 +
22073 +int vc_fget_iattr(uint32_t fd, void __user *data)
22074 +{
22075 +       struct file *filp;
22076 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
22077 +       int ret;
22078 +
22079 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22080 +               return -EFAULT;
22081 +
22082 +       filp = fget(fd);
22083 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
22084 +               return -EBADF;
22085 +
22086 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
22087 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
22088 +
22089 +       fput(filp);
22090 +
22091 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22092 +               ret = -EFAULT;
22093 +       return ret;
22094 +}
22095 +
22096 +
22097 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
22098 +{
22099 +       struct inode *in = de->d_inode;
22100 +       int error = 0, is_proc = 0, has_tag = 0;
22101 +       struct iattr attr = { 0 };
22102 +
22103 +       if (!in || !in->i_sb)
22104 +               return -ESRCH;
22105 +
22106 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
22107 +       if ((*mask & IATTR_FLAGS) && !is_proc)
22108 +               return -EINVAL;
22109 +
22110 +       has_tag = IS_TAGGED(in) ||
22111 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
22112 +       if ((*mask & IATTR_TAG) && !has_tag)
22113 +               return -EINVAL;
22114 +
22115 +       mutex_lock(&in->i_mutex);
22116 +       if (*mask & IATTR_TAG) {
22117 +               attr.ia_tag = *tag;
22118 +               attr.ia_valid |= ATTR_TAG;
22119 +       }
22120 +
22121 +       if (*mask & IATTR_FLAGS) {
22122 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
22123 +               unsigned int iflags = PROC_I(in)->vx_flags;
22124 +
22125 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
22126 +                       | (*flags & IATTR_FLAGS);
22127 +               PROC_I(in)->vx_flags = iflags;
22128 +               if (entry)
22129 +                       entry->vx_flags = iflags;
22130 +       }
22131 +
22132 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
22133 +               IATTR_BARRIER | IATTR_COW)) {
22134 +               int iflags = in->i_flags;
22135 +               int vflags = in->i_vflags;
22136 +
22137 +               if (*mask & IATTR_IMMUTABLE) {
22138 +                       if (*flags & IATTR_IMMUTABLE)
22139 +                               iflags |= S_IMMUTABLE;
22140 +                       else
22141 +                               iflags &= ~S_IMMUTABLE;
22142 +               }
22143 +               if (*mask & IATTR_IXUNLINK) {
22144 +                       if (*flags & IATTR_IXUNLINK)
22145 +                               iflags |= S_IXUNLINK;
22146 +                       else
22147 +                               iflags &= ~S_IXUNLINK;
22148 +               }
22149 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
22150 +                       if (*flags & IATTR_BARRIER)
22151 +                               vflags |= V_BARRIER;
22152 +                       else
22153 +                               vflags &= ~V_BARRIER;
22154 +               }
22155 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
22156 +                       if (*flags & IATTR_COW)
22157 +                               vflags |= V_COW;
22158 +                       else
22159 +                               vflags &= ~V_COW;
22160 +               }
22161 +               if (in->i_op && in->i_op->sync_flags) {
22162 +                       error = in->i_op->sync_flags(in, iflags, vflags);
22163 +                       if (error)
22164 +                               goto out;
22165 +               }
22166 +       }
22167 +
22168 +       if (attr.ia_valid) {
22169 +               if (in->i_op && in->i_op->setattr)
22170 +                       error = in->i_op->setattr(de, &attr);
22171 +               else {
22172 +                       error = inode_change_ok(in, &attr);
22173 +                       if (!error)
22174 +                               error = inode_setattr(in, &attr);
22175 +               }
22176 +       }
22177 +
22178 +out:
22179 +       mutex_unlock(&in->i_mutex);
22180 +       return error;
22181 +}
22182 +
22183 +int vc_set_iattr(void __user *data)
22184 +{
22185 +       struct path path;
22186 +       struct vcmd_ctx_iattr_v1 vc_data;
22187 +       int ret;
22188 +
22189 +       if (!capable(CAP_LINUX_IMMUTABLE))
22190 +               return -EPERM;
22191 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22192 +               return -EFAULT;
22193 +
22194 +       ret = user_lpath(vc_data.name, &path);
22195 +       if (!ret) {
22196 +               ret = __vc_set_iattr(path.dentry,
22197 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
22198 +               path_put(&path);
22199 +       }
22200 +
22201 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22202 +               ret = -EFAULT;
22203 +       return ret;
22204 +}
22205 +
22206 +#ifdef CONFIG_COMPAT
22207 +
22208 +int vc_set_iattr_x32(void __user *data)
22209 +{
22210 +       struct path path;
22211 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
22212 +       int ret;
22213 +
22214 +       if (!capable(CAP_LINUX_IMMUTABLE))
22215 +               return -EPERM;
22216 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22217 +               return -EFAULT;
22218 +
22219 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
22220 +       if (!ret) {
22221 +               ret = __vc_set_iattr(path.dentry,
22222 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
22223 +               path_put(&path);
22224 +       }
22225 +
22226 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22227 +               ret = -EFAULT;
22228 +       return ret;
22229 +}
22230 +
22231 +#endif /* CONFIG_COMPAT */
22232 +
22233 +int vc_fset_iattr(uint32_t fd, void __user *data)
22234 +{
22235 +       struct file *filp;
22236 +       struct vcmd_ctx_fiattr_v0 vc_data;
22237 +       int ret;
22238 +
22239 +       if (!capable(CAP_LINUX_IMMUTABLE))
22240 +               return -EPERM;
22241 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22242 +               return -EFAULT;
22243 +
22244 +       filp = fget(fd);
22245 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
22246 +               return -EBADF;
22247 +
22248 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
22249 +               &vc_data.flags, &vc_data.mask);
22250 +
22251 +       fput(filp);
22252 +
22253 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22254 +               return -EFAULT;
22255 +       return ret;
22256 +}
22257 +
22258 +
22259 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
22260 +
22261 +static match_table_t tokens = {
22262 +       {Opt_notagcheck, "notagcheck"},
22263 +#ifdef CONFIG_PROPAGATE
22264 +       {Opt_notag, "notag"},
22265 +       {Opt_tag, "tag"},
22266 +       {Opt_tagid, "tagid=%u"},
22267 +#endif
22268 +       {Opt_err, NULL}
22269 +};
22270 +
22271 +
22272 +static void __dx_parse_remove(char *string, char *opt)
22273 +{
22274 +       char *p = strstr(string, opt);
22275 +       char *q = p;
22276 +
22277 +       if (p) {
22278 +               while (*q != '\0' && *q != ',')
22279 +                       q++;
22280 +               while (*q)
22281 +                       *p++ = *q++;
22282 +               while (*p)
22283 +                       *p++ = '\0';
22284 +       }
22285 +}
22286 +
22287 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
22288 +                unsigned long *flags)
22289 +{
22290 +       int set = 0;
22291 +       substring_t args[MAX_OPT_ARGS];
22292 +       int token, option = 0;
22293 +       char *s, *p, *opts;
22294 +
22295 +       if (!string)
22296 +               return 0;
22297 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
22298 +       if (!s)
22299 +               return 0;
22300 +
22301 +       opts = s;
22302 +       while ((p = strsep(&opts, ",")) != NULL) {
22303 +               token = match_token(p, tokens, args);
22304 +
22305 +               vxdprintk(VXD_CBIT(tag, 7),
22306 +                       "dx_parse_tag(»%s«): %d:#%d",
22307 +                       p, token, option);
22308 +
22309 +               switch (token) {
22310 +#ifdef CONFIG_PROPAGATE
22311 +               case Opt_tag:
22312 +                       if (tag)
22313 +                               *tag = 0;
22314 +                       if (remove)
22315 +                               __dx_parse_remove(s, "tag");
22316 +                       *mnt_flags |= MNT_TAGID;
22317 +                       set |= MNT_TAGID;
22318 +                       break;
22319 +               case Opt_notag:
22320 +                       if (remove)
22321 +                               __dx_parse_remove(s, "notag");
22322 +                       *mnt_flags |= MNT_NOTAG;
22323 +                       set |= MNT_NOTAG;
22324 +                       break;
22325 +               case Opt_tagid:
22326 +                       if (tag && !match_int(args, &option))
22327 +                               *tag = option;
22328 +                       if (remove)
22329 +                               __dx_parse_remove(s, "tagid");
22330 +                       *mnt_flags |= MNT_TAGID;
22331 +                       set |= MNT_TAGID;
22332 +                       break;
22333 +#endif
22334 +               case Opt_notagcheck:
22335 +                       if (remove)
22336 +                               __dx_parse_remove(s, "notagcheck");
22337 +                       *flags |= MS_NOTAGCHECK;
22338 +                       set |= MS_NOTAGCHECK;
22339 +                       break;
22340 +               }
22341 +       }
22342 +       if (set)
22343 +               strcpy(string, s);
22344 +       kfree(s);
22345 +       return set;
22346 +}
22347 +
22348 +#ifdef CONFIG_PROPAGATE
22349 +
22350 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
22351 +{
22352 +       tag_t new_tag = 0;
22353 +       struct vfsmount *mnt;
22354 +       int propagate;
22355 +
22356 +       if (!nd)
22357 +               return;
22358 +       mnt = nd->path.mnt;
22359 +       if (!mnt)
22360 +               return;
22361 +
22362 +       propagate = (mnt->mnt_flags & MNT_TAGID);
22363 +       if (propagate)
22364 +               new_tag = mnt->mnt_tag;
22365 +
22366 +       vxdprintk(VXD_CBIT(tag, 7),
22367 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
22368 +               inode, inode->i_ino, inode->i_tag,
22369 +               new_tag, (propagate) ? 1 : 0);
22370 +
22371 +       if (propagate)
22372 +               inode->i_tag = new_tag;
22373 +}
22374 +
22375 +#include <linux/module.h>
22376 +
22377 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
22378 +
22379 +#endif /* CONFIG_PROPAGATE */
22380 +
22381 diff -NurpP --minimal linux-2.6.33/kernel/vserver/Kconfig linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/Kconfig
22382 --- linux-2.6.33/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
22383 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/Kconfig 2010-02-25 12:02:16.000000000 +0100
22384 @@ -0,0 +1,251 @@
22385 +#
22386 +# Linux VServer configuration
22387 +#
22388 +
22389 +menu "Linux VServer"
22390 +
22391 +config VSERVER_AUTO_LBACK
22392 +       bool    "Automatically Assign Loopback IP"
22393 +       default y
22394 +       help
22395 +         Automatically assign a guest specific loopback
22396 +         IP and add it to the kernel network stack on
22397 +         startup.
22398 +
22399 +config VSERVER_AUTO_SINGLE
22400 +       bool    "Automatic Single IP Special Casing"
22401 +       depends on EXPERIMENTAL
22402 +       default y
22403 +       help
22404 +         This allows network contexts with a single IP to
22405 +         automatically remap 0.0.0.0 bindings to that IP,
22406 +         avoiding further network checks and improving
22407 +         performance.
22408 +
22409 +         (note: such guests do not allow to change the ip
22410 +          on the fly and do not show loopback addresses)
22411 +
22412 +config VSERVER_COWBL
22413 +       bool    "Enable COW Immutable Link Breaking"
22414 +       default y
22415 +       help
22416 +         This enables the COW (Copy-On-Write) link break code.
22417 +         It allows you to treat unified files like normal files
22418 +         when writing to them (which will implicitely break the
22419 +         link and create a copy of the unified file)
22420 +
22421 +config VSERVER_VTIME
22422 +       bool    "Enable Virtualized Guest Time"
22423 +       depends on EXPERIMENTAL
22424 +       default n
22425 +       help
22426 +         This enables per guest time offsets to allow for
22427 +         adjusting the system clock individually per guest.
22428 +         this adds some overhead to the time functions and
22429 +         therefore should not be enabled without good reason.
22430 +
22431 +config VSERVER_DEVICE
22432 +       bool    "Enable Guest Device Mapping"
22433 +       depends on EXPERIMENTAL
22434 +       default n
22435 +       help
22436 +         This enables generic device remapping.
22437 +
22438 +config VSERVER_PROC_SECURE
22439 +       bool    "Enable Proc Security"
22440 +       depends on PROC_FS
22441 +       default y
22442 +       help
22443 +         This configures ProcFS security to initially hide
22444 +         non-process entries for all contexts except the main and
22445 +         spectator context (i.e. for all guests), which is a secure
22446 +         default.
22447 +
22448 +         (note: on 1.2x the entries were visible by default)
22449 +
22450 +config VSERVER_HARDCPU
22451 +       bool    "Enable Hard CPU Limits"
22452 +       default y
22453 +       help
22454 +         Activate the Hard CPU Limits
22455 +
22456 +         This will compile in code that allows the Token Bucket
22457 +         Scheduler to put processes on hold when a context's
22458 +         tokens are depleted (provided that its per-context
22459 +         sched_hard flag is set).
22460 +
22461 +         Processes belonging to that context will not be able
22462 +         to consume CPU resources again until a per-context
22463 +         configured minimum of tokens has been reached.
22464 +
22465 +config VSERVER_IDLETIME
22466 +       bool    "Avoid idle CPUs by skipping Time"
22467 +       depends on VSERVER_HARDCPU
22468 +       default y
22469 +       help
22470 +         This option allows the scheduler to artificially
22471 +         advance time (per cpu) when otherwise the idle
22472 +         task would be scheduled, thus keeping the cpu
22473 +         busy and sharing the available resources among
22474 +         certain contexts.
22475 +
22476 +config VSERVER_IDLELIMIT
22477 +       bool    "Limit the IDLE task"
22478 +       depends on VSERVER_HARDCPU
22479 +       default n
22480 +       help
22481 +         Limit the idle slices, so the the next context
22482 +         will be scheduled as soon as possible.
22483 +
22484 +         This might improve interactivity and latency, but
22485 +         will also marginally increase scheduling overhead.
22486 +
22487 +choice
22488 +       prompt  "Persistent Inode Tagging"
22489 +       default TAGGING_ID24
22490 +       help
22491 +         This adds persistent context information to filesystems
22492 +         mounted with the tagxid option. Tagging is a requirement
22493 +         for per-context disk limits and per-context quota.
22494 +
22495 +
22496 +config TAGGING_NONE
22497 +       bool    "Disabled"
22498 +       help
22499 +         do not store per-context information in inodes.
22500 +
22501 +config TAGGING_UID16
22502 +       bool    "UID16/GID32"
22503 +       help
22504 +         reduces UID to 16 bit, but leaves GID at 32 bit.
22505 +
22506 +config TAGGING_GID16
22507 +       bool    "UID32/GID16"
22508 +       help
22509 +         reduces GID to 16 bit, but leaves UID at 32 bit.
22510 +
22511 +config TAGGING_ID24
22512 +       bool    "UID24/GID24"
22513 +       help
22514 +         uses the upper 8bit from UID and GID for XID tagging
22515 +         which leaves 24bit for UID/GID each, which should be
22516 +         more than sufficient for normal use.
22517 +
22518 +config TAGGING_INTERN
22519 +       bool    "UID32/GID32"
22520 +       help
22521 +         this uses otherwise reserved inode fields in the on
22522 +         disk representation, which limits the use to a few
22523 +         filesystems (currently ext2 and ext3)
22524 +
22525 +endchoice
22526 +
22527 +config TAG_NFSD
22528 +       bool    "Tag NFSD User Auth and Files"
22529 +       default n
22530 +       help
22531 +         Enable this if you do want the in-kernel NFS
22532 +         Server to use the tagging specified above.
22533 +         (will require patched clients too)
22534 +
22535 +config VSERVER_PRIVACY
22536 +       bool    "Honor Privacy Aspects of Guests"
22537 +       default n
22538 +       help
22539 +         When enabled, most context checks will disallow
22540 +         access to structures assigned to a specific context,
22541 +         like ptys or loop devices.
22542 +
22543 +config VSERVER_CONTEXTS
22544 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
22545 +       range 1 65533
22546 +       default "768"   if 64BIT
22547 +       default "256"
22548 +       help
22549 +         This setting will optimize certain data structures
22550 +         and memory allocations according to the expected
22551 +         maximum.
22552 +
22553 +         note: this is not a strict upper limit.
22554 +
22555 +config VSERVER_WARN
22556 +       bool    "VServer Warnings"
22557 +       default y
22558 +       help
22559 +         This enables various runtime warnings, which will
22560 +         notify about potential manipulation attempts or
22561 +         resource shortage. It is generally considered to
22562 +         be a good idea to have that enabled.
22563 +
22564 +config VSERVER_DEBUG
22565 +       bool    "VServer Debugging Code"
22566 +       default n
22567 +       help
22568 +         Set this to yes if you want to be able to activate
22569 +         debugging output at runtime. It adds a very small
22570 +         overhead to all vserver related functions and
22571 +         increases the kernel size by about 20k.
22572 +
22573 +config VSERVER_HISTORY
22574 +       bool    "VServer History Tracing"
22575 +       depends on VSERVER_DEBUG
22576 +       default n
22577 +       help
22578 +         Set this to yes if you want to record the history of
22579 +         linux-vserver activities, so they can be replayed in
22580 +         the event of a kernel panic or oops.
22581 +
22582 +config VSERVER_HISTORY_SIZE
22583 +       int     "Per-CPU History Size (32-65536)"
22584 +       depends on VSERVER_HISTORY
22585 +       range 32 65536
22586 +       default 64
22587 +       help
22588 +         This allows you to specify the number of entries in
22589 +         the per-CPU history buffer.
22590 +
22591 +config VSERVER_MONITOR
22592 +       bool    "VServer Scheduling Monitor"
22593 +       depends on VSERVER_DISABLED
22594 +       default n
22595 +       help
22596 +         Set this to yes if you want to record the scheduling
22597 +         decisions, so that they can be relayed to userspace
22598 +         for detailed analysis.
22599 +
22600 +config VSERVER_MONITOR_SIZE
22601 +       int     "Per-CPU Monitor Queue Size (32-65536)"
22602 +       depends on VSERVER_MONITOR
22603 +       range 32 65536
22604 +       default 1024
22605 +       help
22606 +         This allows you to specify the number of entries in
22607 +         the per-CPU scheduling monitor buffer.
22608 +
22609 +config VSERVER_MONITOR_SYNC
22610 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
22611 +       depends on VSERVER_MONITOR
22612 +       range 0 65536
22613 +       default 256
22614 +       help
22615 +         This allows you to specify the interval in ticks
22616 +         when a time sync entry is inserted.
22617 +
22618 +endmenu
22619 +
22620 +
22621 +config VSERVER
22622 +       bool
22623 +       default y
22624 +       select NAMESPACES
22625 +       select UTS_NS
22626 +       select IPC_NS
22627 +       select USER_NS
22628 +       select SYSVIPC
22629 +
22630 +config VSERVER_SECURITY
22631 +       bool
22632 +       depends on SECURITY
22633 +       default y
22634 +       select SECURITY_CAPABILITIES
22635 +
22636 diff -NurpP --minimal linux-2.6.33/kernel/vserver/limit.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/limit.c
22637 --- linux-2.6.33/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
22638 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/limit.c 2010-03-02 21:45:20.000000000 +0100
22639 @@ -0,0 +1,387 @@
22640 +/*
22641 + *  linux/kernel/vserver/limit.c
22642 + *
22643 + *  Virtual Server: Context Limits
22644 + *
22645 + *  Copyright (C) 2004-2010  Herbert Pötzl
22646 + *
22647 + *  V0.01  broken out from vcontext V0.05
22648 + *  V0.02  changed vcmds to vxi arg
22649 + *  V0.03  added memory cgroup support
22650 + *
22651 + */
22652 +
22653 +#include <linux/sched.h>
22654 +#include <linux/module.h>
22655 +#include <linux/memcontrol.h>
22656 +#include <linux/res_counter.h>
22657 +#include <linux/vs_limit.h>
22658 +#include <linux/vserver/limit.h>
22659 +#include <linux/vserver/limit_cmd.h>
22660 +
22661 +#include <asm/uaccess.h>
22662 +
22663 +
22664 +const char *vlimit_name[NUM_LIMITS] = {
22665 +       [RLIMIT_CPU]            = "CPU",
22666 +       [RLIMIT_RSS]            = "RSS",
22667 +       [RLIMIT_NPROC]          = "NPROC",
22668 +       [RLIMIT_NOFILE]         = "NOFILE",
22669 +       [RLIMIT_MEMLOCK]        = "VML",
22670 +       [RLIMIT_AS]             = "VM",
22671 +       [RLIMIT_LOCKS]          = "LOCKS",
22672 +       [RLIMIT_SIGPENDING]     = "SIGP",
22673 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
22674 +
22675 +       [VLIMIT_NSOCK]          = "NSOCK",
22676 +       [VLIMIT_OPENFD]         = "OPENFD",
22677 +       [VLIMIT_ANON]           = "ANON",
22678 +       [VLIMIT_SHMEM]          = "SHMEM",
22679 +       [VLIMIT_DENTRY]         = "DENTRY",
22680 +};
22681 +
22682 +EXPORT_SYMBOL_GPL(vlimit_name);
22683 +
22684 +#define MASK_ENTRY(x)  (1 << (x))
22685 +
22686 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
22687 +               /* minimum */
22688 +       0
22689 +       ,       /* softlimit */
22690 +       MASK_ENTRY( RLIMIT_RSS          ) |
22691 +       MASK_ENTRY( VLIMIT_ANON         ) |
22692 +       0
22693 +       ,       /* maximum */
22694 +       MASK_ENTRY( RLIMIT_RSS          ) |
22695 +       MASK_ENTRY( RLIMIT_NPROC        ) |
22696 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
22697 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
22698 +       MASK_ENTRY( RLIMIT_AS           ) |
22699 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
22700 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
22701 +
22702 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
22703 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
22704 +       MASK_ENTRY( VLIMIT_ANON         ) |
22705 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
22706 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
22707 +       0
22708 +};
22709 +               /* accounting only */
22710 +uint32_t account_mask =
22711 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
22712 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
22713 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
22714 +       0;
22715 +
22716 +
22717 +static int is_valid_vlimit(int id)
22718 +{
22719 +       uint32_t mask = vlimit_mask.minimum |
22720 +               vlimit_mask.softlimit | vlimit_mask.maximum;
22721 +       return mask & (1 << id);
22722 +}
22723 +
22724 +static int is_accounted_vlimit(int id)
22725 +{
22726 +       if (is_valid_vlimit(id))
22727 +               return 1;
22728 +       return account_mask & (1 << id);
22729 +}
22730 +
22731 +
22732 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
22733 +{
22734 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
22735 +       return VX_VLIM(limit);
22736 +}
22737 +
22738 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
22739 +{
22740 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
22741 +       return VX_VLIM(limit);
22742 +}
22743 +
22744 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
22745 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
22746 +{
22747 +       if (!is_valid_vlimit(id))
22748 +               return -EINVAL;
22749 +
22750 +       if (minimum)
22751 +               *minimum = CRLIM_UNSET;
22752 +       if (softlimit)
22753 +               *softlimit = vc_get_soft(vxi, id);
22754 +       if (maximum)
22755 +               *maximum = vc_get_hard(vxi, id);
22756 +       return 0;
22757 +}
22758 +
22759 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
22760 +{
22761 +       struct vcmd_ctx_rlimit_v0 vc_data;
22762 +       int ret;
22763 +
22764 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22765 +               return -EFAULT;
22766 +
22767 +       ret = do_get_rlimit(vxi, vc_data.id,
22768 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
22769 +       if (ret)
22770 +               return ret;
22771 +
22772 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22773 +               return -EFAULT;
22774 +       return 0;
22775 +}
22776 +
22777 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
22778 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
22779 +{
22780 +       if (!is_valid_vlimit(id))
22781 +               return -EINVAL;
22782 +
22783 +       if (maximum != CRLIM_KEEP)
22784 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
22785 +       if (softlimit != CRLIM_KEEP)
22786 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
22787 +
22788 +       /* clamp soft limit */
22789 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
22790 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
22791 +
22792 +       return 0;
22793 +}
22794 +
22795 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
22796 +{
22797 +       struct vcmd_ctx_rlimit_v0 vc_data;
22798 +
22799 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22800 +               return -EFAULT;
22801 +
22802 +       return do_set_rlimit(vxi, vc_data.id,
22803 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
22804 +}
22805 +
22806 +#ifdef CONFIG_IA32_EMULATION
22807 +
22808 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
22809 +{
22810 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
22811 +
22812 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22813 +               return -EFAULT;
22814 +
22815 +       return do_set_rlimit(vxi, vc_data.id,
22816 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
22817 +}
22818 +
22819 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
22820 +{
22821 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
22822 +       int ret;
22823 +
22824 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22825 +               return -EFAULT;
22826 +
22827 +       ret = do_get_rlimit(vxi, vc_data.id,
22828 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
22829 +       if (ret)
22830 +               return ret;
22831 +
22832 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22833 +               return -EFAULT;
22834 +       return 0;
22835 +}
22836 +
22837 +#endif /* CONFIG_IA32_EMULATION */
22838 +
22839 +
22840 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
22841 +{
22842 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
22843 +               return -EFAULT;
22844 +       return 0;
22845 +}
22846 +
22847 +
22848 +static inline void vx_reset_hits(struct _vx_limit *limit)
22849 +{
22850 +       int lim;
22851 +
22852 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22853 +               atomic_set(&__rlim_lhit(limit, lim), 0);
22854 +       }
22855 +}
22856 +
22857 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
22858 +{
22859 +       vx_reset_hits(&vxi->limit);
22860 +       return 0;
22861 +}
22862 +
22863 +static inline void vx_reset_minmax(struct _vx_limit *limit)
22864 +{
22865 +       rlim_t value;
22866 +       int lim;
22867 +
22868 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22869 +               value = __rlim_get(limit, lim);
22870 +               __rlim_rmax(limit, lim) = value;
22871 +               __rlim_rmin(limit, lim) = value;
22872 +       }
22873 +}
22874 +
22875 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
22876 +{
22877 +       vx_reset_minmax(&vxi->limit);
22878 +       return 0;
22879 +}
22880 +
22881 +
22882 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
22883 +{
22884 +       struct vcmd_rlimit_stat_v0 vc_data;
22885 +       struct _vx_limit *limit = &vxi->limit;
22886 +       int id;
22887 +
22888 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22889 +               return -EFAULT;
22890 +
22891 +       id = vc_data.id;
22892 +       if (!is_accounted_vlimit(id))
22893 +               return -EINVAL;
22894 +
22895 +       vx_limit_fixup(limit, id);
22896 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
22897 +       vc_data.value = __rlim_get(limit, id);
22898 +       vc_data.minimum = __rlim_rmin(limit, id);
22899 +       vc_data.maximum = __rlim_rmax(limit, id);
22900 +
22901 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22902 +               return -EFAULT;
22903 +       return 0;
22904 +}
22905 +
22906 +
22907 +void vx_vsi_meminfo(struct sysinfo *val)
22908 +{
22909 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22910 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22911 +       u64 res_limit, res_usage;
22912 +
22913 +       if (!mcg)
22914 +               return;
22915 +
22916 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
22917 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
22918 +
22919 +       if (res_limit != RESOURCE_MAX)
22920 +               val->totalram = (res_limit >> PAGE_SHIFT);
22921 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
22922 +       val->bufferram = 0;
22923 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR */
22924 +       struct vx_info *vxi = current_vx_info();
22925 +       unsigned long totalram, freeram;
22926 +       rlim_t v;
22927 +
22928 +       /* we blindly accept the max */
22929 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22930 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
22931 +
22932 +       /* total minus used equals free */
22933 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22934 +       freeram = (v < totalram) ? totalram - v : 0;
22935 +
22936 +       val->totalram = totalram;
22937 +       val->freeram = freeram;
22938 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
22939 +       val->totalhigh = 0;
22940 +       val->freehigh = 0;
22941 +       return;
22942 +}
22943 +
22944 +void vx_vsi_swapinfo(struct sysinfo *val)
22945 +{
22946 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
22947 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22948 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
22949 +       s64 swap_limit, swap_usage;
22950 +
22951 +       if (!mcg)
22952 +               return;
22953 +
22954 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
22955 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
22956 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
22957 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
22958 +
22959 +       if (res_limit == RESOURCE_MAX)
22960 +               return;
22961 +
22962 +       swap_limit = memsw_limit - res_limit;
22963 +       if (memsw_limit != RESOURCE_MAX)
22964 +               val->totalswap = swap_limit >> PAGE_SHIFT;
22965 +
22966 +       swap_usage = memsw_usage - res_usage;
22967 +       val->freeswap = (swap_usage < swap_limit) ?
22968 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
22969 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
22970 +       struct vx_info *vxi = current_vx_info();
22971 +       unsigned long totalswap, freeswap;
22972 +       rlim_t v, w;
22973 +
22974 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22975 +       if (v == RLIM_INFINITY) {
22976 +               val->freeswap = val->totalswap;
22977 +               return;
22978 +       }
22979 +
22980 +       /* we blindly accept the max */
22981 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
22982 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
22983 +
22984 +       /* currently 'used' swap */
22985 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22986 +       w -= (w > v) ? v : w;
22987 +
22988 +       /* total minus used equals free */
22989 +       freeswap = (w < totalswap) ? totalswap - w : 0;
22990 +
22991 +       val->totalswap = totalswap;
22992 +       val->freeswap = freeswap;
22993 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
22994 +       return;
22995 +}
22996 +
22997 +long vx_vsi_cached(struct sysinfo *val)
22998 +{
22999 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23000 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
23001 +
23002 +       return mem_cgroup_stat_read_cache(mcg);
23003 +#else
23004 +       return 0;
23005 +#endif
23006 +}
23007 +
23008 +
23009 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
23010 +{
23011 +       struct vx_info *vxi = mm->mm_vx_info;
23012 +       unsigned long points;
23013 +       rlim_t v, w;
23014 +
23015 +       if (!vxi)
23016 +               return 0;
23017 +
23018 +       points = vxi->vx_badness_bias;
23019 +
23020 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23021 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23022 +       points += (v > w) ? (v - w) : 0;
23023 +
23024 +       return points;
23025 +}
23026 +
23027 diff -NurpP --minimal linux-2.6.33/kernel/vserver/limit_init.h linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/limit_init.h
23028 --- linux-2.6.33/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
23029 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/limit_init.h    2010-02-25 12:02:16.000000000 +0100
23030 @@ -0,0 +1,31 @@
23031 +
23032 +
23033 +static inline void vx_info_init_limit(struct _vx_limit *limit)
23034 +{
23035 +       int lim;
23036 +
23037 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23038 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
23039 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
23040 +               __rlim_set(limit, lim, 0);
23041 +               atomic_set(&__rlim_lhit(limit, lim), 0);
23042 +               __rlim_rmin(limit, lim) = 0;
23043 +               __rlim_rmax(limit, lim) = 0;
23044 +       }
23045 +}
23046 +
23047 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
23048 +{
23049 +       rlim_t value;
23050 +       int lim;
23051 +
23052 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23053 +               if ((1 << lim) & VLIM_NOCHECK)
23054 +                       continue;
23055 +               value = __rlim_get(limit, lim);
23056 +               vxwprintk_xid(value,
23057 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
23058 +                       limit, vlimit_name[lim], lim, (long)value);
23059 +       }
23060 +}
23061 +
23062 diff -NurpP --minimal linux-2.6.33/kernel/vserver/limit_proc.h linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/limit_proc.h
23063 --- linux-2.6.33/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
23064 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/limit_proc.h    2010-02-25 12:02:16.000000000 +0100
23065 @@ -0,0 +1,57 @@
23066 +#ifndef _VX_LIMIT_PROC_H
23067 +#define _VX_LIMIT_PROC_H
23068 +
23069 +#include <linux/vserver/limit_int.h>
23070 +
23071 +
23072 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
23073 +#define VX_LIMIT_TOP   \
23074 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
23075 +
23076 +#define VX_LIMIT_ARG(r)                                \
23077 +       (unsigned long)__rlim_get(limit, r),    \
23078 +       (unsigned long)__rlim_rmin(limit, r),   \
23079 +       (unsigned long)__rlim_rmax(limit, r),   \
23080 +       VX_VLIM(__rlim_soft(limit, r)),         \
23081 +       VX_VLIM(__rlim_hard(limit, r)),         \
23082 +       atomic_read(&__rlim_lhit(limit, r))
23083 +
23084 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
23085 +{
23086 +       vx_limit_fixup(limit, -1);
23087 +       return sprintf(buffer, VX_LIMIT_TOP
23088 +               "PROC"  VX_LIMIT_FMT
23089 +               "VM"    VX_LIMIT_FMT
23090 +               "VML"   VX_LIMIT_FMT
23091 +               "RSS"   VX_LIMIT_FMT
23092 +               "ANON"  VX_LIMIT_FMT
23093 +               "RMAP"  VX_LIMIT_FMT
23094 +               "FILES" VX_LIMIT_FMT
23095 +               "OFD"   VX_LIMIT_FMT
23096 +               "LOCKS" VX_LIMIT_FMT
23097 +               "SOCK"  VX_LIMIT_FMT
23098 +               "MSGQ"  VX_LIMIT_FMT
23099 +               "SHM"   VX_LIMIT_FMT
23100 +               "SEMA"  VX_LIMIT_FMT
23101 +               "SEMS"  VX_LIMIT_FMT
23102 +               "DENT"  VX_LIMIT_FMT,
23103 +               VX_LIMIT_ARG(RLIMIT_NPROC),
23104 +               VX_LIMIT_ARG(RLIMIT_AS),
23105 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
23106 +               VX_LIMIT_ARG(RLIMIT_RSS),
23107 +               VX_LIMIT_ARG(VLIMIT_ANON),
23108 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
23109 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
23110 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
23111 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
23112 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
23113 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
23114 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
23115 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
23116 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
23117 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
23118 +}
23119 +
23120 +#endif /* _VX_LIMIT_PROC_H */
23121 +
23122 +
23123 diff -NurpP --minimal linux-2.6.33/kernel/vserver/Makefile linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/Makefile
23124 --- linux-2.6.33/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
23125 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/Makefile        2010-02-25 12:02:16.000000000 +0100
23126 @@ -0,0 +1,18 @@
23127 +#
23128 +# Makefile for the Linux vserver routines.
23129 +#
23130 +
23131 +
23132 +obj-y          += vserver.o
23133 +
23134 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
23135 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
23136 +                  dlimit.o tag.o
23137 +
23138 +vserver-$(CONFIG_INET) += inet.o
23139 +vserver-$(CONFIG_PROC_FS) += proc.o
23140 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
23141 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
23142 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
23143 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
23144 +
23145 diff -NurpP --minimal linux-2.6.33/kernel/vserver/monitor.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/monitor.c
23146 --- linux-2.6.33/kernel/vserver/monitor.c       1970-01-01 01:00:00.000000000 +0100
23147 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/monitor.c       2010-02-25 12:02:16.000000000 +0100
23148 @@ -0,0 +1,138 @@
23149 +/*
23150 + *  kernel/vserver/monitor.c
23151 + *
23152 + *  Virtual Context Scheduler Monitor
23153 + *
23154 + *  Copyright (C) 2006-2007 Herbert Pötzl
23155 + *
23156 + *  V0.01  basic design
23157 + *
23158 + */
23159 +
23160 +#include <linux/module.h>
23161 +#include <linux/jiffies.h>
23162 +#include <asm/uaccess.h>
23163 +#include <asm/atomic.h>
23164 +
23165 +#include <linux/vserver/monitor.h>
23166 +#include <linux/vserver/debug_cmd.h>
23167 +
23168 +
23169 +#ifdef CONFIG_VSERVER_MONITOR
23170 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
23171 +#else
23172 +#define VXM_SIZE       64
23173 +#endif
23174 +
23175 +struct _vx_monitor {
23176 +       unsigned int counter;
23177 +
23178 +       struct _vx_mon_entry entry[VXM_SIZE+1];
23179 +};
23180 +
23181 +
23182 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
23183 +
23184 +unsigned volatile int vxm_active = 1;
23185 +
23186 +static atomic_t sequence = ATOMIC_INIT(0);
23187 +
23188 +
23189 +/*     vxm_advance()
23190 +
23191 +       * requires disabled preemption                          */
23192 +
23193 +struct _vx_mon_entry *vxm_advance(int cpu)
23194 +{
23195 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
23196 +       struct _vx_mon_entry *entry;
23197 +       unsigned int index;
23198 +
23199 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
23200 +       entry = &mon->entry[index];
23201 +
23202 +       entry->ev.seq = atomic_inc_return(&sequence);
23203 +       entry->ev.jif = jiffies;
23204 +       return entry;
23205 +}
23206 +
23207 +EXPORT_SYMBOL_GPL(vxm_advance);
23208 +
23209 +
23210 +int do_read_monitor(struct __user _vx_mon_entry *data,
23211 +       int cpu, uint32_t *index, uint32_t *count)
23212 +{
23213 +       int pos, ret = 0;
23214 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
23215 +       int end = mon->counter;
23216 +       int start = end - VXM_SIZE + 2;
23217 +       int idx = *index;
23218 +
23219 +       /* special case: get current pos */
23220 +       if (!*count) {
23221 +               *index = end;
23222 +               return 0;
23223 +       }
23224 +
23225 +       /* have we lost some data? */
23226 +       if (idx < start)
23227 +               idx = start;
23228 +
23229 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
23230 +               struct _vx_mon_entry *entry =
23231 +                       &mon->entry[idx % VXM_SIZE];
23232 +
23233 +               /* send entry to userspace */
23234 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
23235 +               if (ret)
23236 +                       break;
23237 +       }
23238 +       /* save new index and count */
23239 +       *index = idx;
23240 +       *count = pos;
23241 +       return ret ? ret : (*index < end);
23242 +}
23243 +
23244 +int vc_read_monitor(uint32_t id, void __user *data)
23245 +{
23246 +       struct vcmd_read_monitor_v0 vc_data;
23247 +       int ret;
23248 +
23249 +       if (id >= NR_CPUS)
23250 +               return -EINVAL;
23251 +
23252 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23253 +               return -EFAULT;
23254 +
23255 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
23256 +               id, &vc_data.index, &vc_data.count);
23257 +
23258 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23259 +               return -EFAULT;
23260 +       return ret;
23261 +}
23262 +
23263 +#ifdef CONFIG_COMPAT
23264 +
23265 +int vc_read_monitor_x32(uint32_t id, void __user *data)
23266 +{
23267 +       struct vcmd_read_monitor_v0_x32 vc_data;
23268 +       int ret;
23269 +
23270 +       if (id >= NR_CPUS)
23271 +               return -EINVAL;
23272 +
23273 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23274 +               return -EFAULT;
23275 +
23276 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
23277 +               compat_ptr(vc_data.data_ptr),
23278 +               id, &vc_data.index, &vc_data.count);
23279 +
23280 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23281 +               return -EFAULT;
23282 +       return ret;
23283 +}
23284 +
23285 +#endif /* CONFIG_COMPAT */
23286 +
23287 diff -NurpP --minimal linux-2.6.33/kernel/vserver/network.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/network.c
23288 --- linux-2.6.33/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
23289 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/network.c       2010-02-25 12:02:16.000000000 +0100
23290 @@ -0,0 +1,864 @@
23291 +/*
23292 + *  linux/kernel/vserver/network.c
23293 + *
23294 + *  Virtual Server: Network Support
23295 + *
23296 + *  Copyright (C) 2003-2007  Herbert Pötzl
23297 + *
23298 + *  V0.01  broken out from vcontext V0.05
23299 + *  V0.02  cleaned up implementation
23300 + *  V0.03  added equiv nx commands
23301 + *  V0.04  switch to RCU based hash
23302 + *  V0.05  and back to locking again
23303 + *  V0.06  changed vcmds to nxi arg
23304 + *  V0.07  have __create claim() the nxi
23305 + *
23306 + */
23307 +
23308 +#include <linux/err.h>
23309 +#include <linux/slab.h>
23310 +#include <linux/rcupdate.h>
23311 +
23312 +#include <linux/vs_network.h>
23313 +#include <linux/vs_pid.h>
23314 +#include <linux/vserver/network_cmd.h>
23315 +
23316 +
23317 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
23318 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
23319 +
23320 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
23321 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
23322 +
23323 +
23324 +static int __init init_network(void)
23325 +{
23326 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
23327 +               sizeof(struct nx_addr_v4), 0,
23328 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
23329 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
23330 +               sizeof(struct nx_addr_v6), 0,
23331 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
23332 +       return 0;
23333 +}
23334 +
23335 +
23336 +/*     __alloc_nx_addr_v4()                                    */
23337 +
23338 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
23339 +{
23340 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
23341 +               nx_addr_v4_cachep, GFP_KERNEL);
23342 +
23343 +       if (!IS_ERR(nxa))
23344 +               memset(nxa, 0, sizeof(*nxa));
23345 +       return nxa;
23346 +}
23347 +
23348 +/*     __dealloc_nx_addr_v4()                                  */
23349 +
23350 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
23351 +{
23352 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
23353 +}
23354 +
23355 +/*     __dealloc_nx_addr_v4_all()                              */
23356 +
23357 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
23358 +{
23359 +       while (nxa) {
23360 +               struct nx_addr_v4 *next = nxa->next;
23361 +
23362 +               __dealloc_nx_addr_v4(nxa);
23363 +               nxa = next;
23364 +       }
23365 +}
23366 +
23367 +
23368 +#ifdef CONFIG_IPV6
23369 +
23370 +/*     __alloc_nx_addr_v6()                                    */
23371 +
23372 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
23373 +{
23374 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
23375 +               nx_addr_v6_cachep, GFP_KERNEL);
23376 +
23377 +       if (!IS_ERR(nxa))
23378 +               memset(nxa, 0, sizeof(*nxa));
23379 +       return nxa;
23380 +}
23381 +
23382 +/*     __dealloc_nx_addr_v6()                                  */
23383 +
23384 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
23385 +{
23386 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
23387 +}
23388 +
23389 +/*     __dealloc_nx_addr_v6_all()                              */
23390 +
23391 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
23392 +{
23393 +       while (nxa) {
23394 +               struct nx_addr_v6 *next = nxa->next;
23395 +
23396 +               __dealloc_nx_addr_v6(nxa);
23397 +               nxa = next;
23398 +       }
23399 +}
23400 +
23401 +#endif /* CONFIG_IPV6 */
23402 +
23403 +/*     __alloc_nx_info()
23404 +
23405 +       * allocate an initialized nx_info struct
23406 +       * doesn't make it visible (hash)                        */
23407 +
23408 +static struct nx_info *__alloc_nx_info(nid_t nid)
23409 +{
23410 +       struct nx_info *new = NULL;
23411 +
23412 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
23413 +
23414 +       /* would this benefit from a slab cache? */
23415 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
23416 +       if (!new)
23417 +               return 0;
23418 +
23419 +       memset(new, 0, sizeof(struct nx_info));
23420 +       new->nx_id = nid;
23421 +       INIT_HLIST_NODE(&new->nx_hlist);
23422 +       atomic_set(&new->nx_usecnt, 0);
23423 +       atomic_set(&new->nx_tasks, 0);
23424 +       new->nx_state = 0;
23425 +
23426 +       new->nx_flags = NXF_INIT_SET;
23427 +
23428 +       /* rest of init goes here */
23429 +
23430 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
23431 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
23432 +
23433 +       vxdprintk(VXD_CBIT(nid, 0),
23434 +               "alloc_nx_info(%d) = %p", nid, new);
23435 +       atomic_inc(&nx_global_ctotal);
23436 +       return new;
23437 +}
23438 +
23439 +/*     __dealloc_nx_info()
23440 +
23441 +       * final disposal of nx_info                             */
23442 +
23443 +static void __dealloc_nx_info(struct nx_info *nxi)
23444 +{
23445 +       vxdprintk(VXD_CBIT(nid, 0),
23446 +               "dealloc_nx_info(%p)", nxi);
23447 +
23448 +       nxi->nx_hlist.next = LIST_POISON1;
23449 +       nxi->nx_id = -1;
23450 +
23451 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
23452 +       BUG_ON(atomic_read(&nxi->nx_tasks));
23453 +
23454 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
23455 +
23456 +       nxi->nx_state |= NXS_RELEASED;
23457 +       kfree(nxi);
23458 +       atomic_dec(&nx_global_ctotal);
23459 +}
23460 +
23461 +static void __shutdown_nx_info(struct nx_info *nxi)
23462 +{
23463 +       nxi->nx_state |= NXS_SHUTDOWN;
23464 +       vs_net_change(nxi, VSC_NETDOWN);
23465 +}
23466 +
23467 +/*     exported stuff                                          */
23468 +
23469 +void free_nx_info(struct nx_info *nxi)
23470 +{
23471 +       /* context shutdown is mandatory */
23472 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
23473 +
23474 +       /* context must not be hashed */
23475 +       BUG_ON(nxi->nx_state & NXS_HASHED);
23476 +
23477 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
23478 +       BUG_ON(atomic_read(&nxi->nx_tasks));
23479 +
23480 +       __dealloc_nx_info(nxi);
23481 +}
23482 +
23483 +
23484 +void __nx_set_lback(struct nx_info *nxi)
23485 +{
23486 +       int nid = nxi->nx_id;
23487 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
23488 +
23489 +       nxi->v4_lback.s_addr = lback;
23490 +}
23491 +
23492 +extern int __nx_inet_add_lback(__be32 addr);
23493 +extern int __nx_inet_del_lback(__be32 addr);
23494 +
23495 +
23496 +/*     hash table for nx_info hash */
23497 +
23498 +#define NX_HASH_SIZE   13
23499 +
23500 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
23501 +
23502 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
23503 +
23504 +
23505 +static inline unsigned int __hashval(nid_t nid)
23506 +{
23507 +       return (nid % NX_HASH_SIZE);
23508 +}
23509 +
23510 +
23511 +
23512 +/*     __hash_nx_info()
23513 +
23514 +       * add the nxi to the global hash table
23515 +       * requires the hash_lock to be held                     */
23516 +
23517 +static inline void __hash_nx_info(struct nx_info *nxi)
23518 +{
23519 +       struct hlist_head *head;
23520 +
23521 +       vxd_assert_lock(&nx_info_hash_lock);
23522 +       vxdprintk(VXD_CBIT(nid, 4),
23523 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
23524 +
23525 +       /* context must not be hashed */
23526 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
23527 +
23528 +       nxi->nx_state |= NXS_HASHED;
23529 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
23530 +       hlist_add_head(&nxi->nx_hlist, head);
23531 +       atomic_inc(&nx_global_cactive);
23532 +}
23533 +
23534 +/*     __unhash_nx_info()
23535 +
23536 +       * remove the nxi from the global hash table
23537 +       * requires the hash_lock to be held                     */
23538 +
23539 +static inline void __unhash_nx_info(struct nx_info *nxi)
23540 +{
23541 +       vxd_assert_lock(&nx_info_hash_lock);
23542 +       vxdprintk(VXD_CBIT(nid, 4),
23543 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
23544 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
23545 +
23546 +       /* context must be hashed */
23547 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
23548 +       /* but without tasks */
23549 +       BUG_ON(atomic_read(&nxi->nx_tasks));
23550 +
23551 +       nxi->nx_state &= ~NXS_HASHED;
23552 +       hlist_del(&nxi->nx_hlist);
23553 +       atomic_dec(&nx_global_cactive);
23554 +}
23555 +
23556 +
23557 +/*     __lookup_nx_info()
23558 +
23559 +       * requires the hash_lock to be held
23560 +       * doesn't increment the nx_refcnt                       */
23561 +
23562 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
23563 +{
23564 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
23565 +       struct hlist_node *pos;
23566 +       struct nx_info *nxi;
23567 +
23568 +       vxd_assert_lock(&nx_info_hash_lock);
23569 +       hlist_for_each(pos, head) {
23570 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
23571 +
23572 +               if (nxi->nx_id == nid)
23573 +                       goto found;
23574 +       }
23575 +       nxi = NULL;
23576 +found:
23577 +       vxdprintk(VXD_CBIT(nid, 0),
23578 +               "__lookup_nx_info(#%u): %p[#%u]",
23579 +               nid, nxi, nxi ? nxi->nx_id : 0);
23580 +       return nxi;
23581 +}
23582 +
23583 +
23584 +/*     __create_nx_info()
23585 +
23586 +       * create the requested context
23587 +       * get(), claim() and hash it                            */
23588 +
23589 +static struct nx_info *__create_nx_info(int id)
23590 +{
23591 +       struct nx_info *new, *nxi = NULL;
23592 +
23593 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
23594 +
23595 +       if (!(new = __alloc_nx_info(id)))
23596 +               return ERR_PTR(-ENOMEM);
23597 +
23598 +       /* required to make dynamic xids unique */
23599 +       spin_lock(&nx_info_hash_lock);
23600 +
23601 +       /* static context requested */
23602 +       if ((nxi = __lookup_nx_info(id))) {
23603 +               vxdprintk(VXD_CBIT(nid, 0),
23604 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
23605 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
23606 +                       nxi = ERR_PTR(-EBUSY);
23607 +               else
23608 +                       nxi = ERR_PTR(-EEXIST);
23609 +               goto out_unlock;
23610 +       }
23611 +       /* new context */
23612 +       vxdprintk(VXD_CBIT(nid, 0),
23613 +               "create_nx_info(%d) = %p (new)", id, new);
23614 +       claim_nx_info(new, NULL);
23615 +       __nx_set_lback(new);
23616 +       __hash_nx_info(get_nx_info(new));
23617 +       nxi = new, new = NULL;
23618 +
23619 +out_unlock:
23620 +       spin_unlock(&nx_info_hash_lock);
23621 +       if (new)
23622 +               __dealloc_nx_info(new);
23623 +       return nxi;
23624 +}
23625 +
23626 +
23627 +
23628 +/*     exported stuff                                          */
23629 +
23630 +
23631 +void unhash_nx_info(struct nx_info *nxi)
23632 +{
23633 +       __shutdown_nx_info(nxi);
23634 +       spin_lock(&nx_info_hash_lock);
23635 +       __unhash_nx_info(nxi);
23636 +       spin_unlock(&nx_info_hash_lock);
23637 +}
23638 +
23639 +/*     lookup_nx_info()
23640 +
23641 +       * search for a nx_info and get() it
23642 +       * negative id means current                             */
23643 +
23644 +struct nx_info *lookup_nx_info(int id)
23645 +{
23646 +       struct nx_info *nxi = NULL;
23647 +
23648 +       if (id < 0) {
23649 +               nxi = get_nx_info(current_nx_info());
23650 +       } else if (id > 1) {
23651 +               spin_lock(&nx_info_hash_lock);
23652 +               nxi = get_nx_info(__lookup_nx_info(id));
23653 +               spin_unlock(&nx_info_hash_lock);
23654 +       }
23655 +       return nxi;
23656 +}
23657 +
23658 +/*     nid_is_hashed()
23659 +
23660 +       * verify that nid is still hashed                       */
23661 +
23662 +int nid_is_hashed(nid_t nid)
23663 +{
23664 +       int hashed;
23665 +
23666 +       spin_lock(&nx_info_hash_lock);
23667 +       hashed = (__lookup_nx_info(nid) != NULL);
23668 +       spin_unlock(&nx_info_hash_lock);
23669 +       return hashed;
23670 +}
23671 +
23672 +
23673 +#ifdef CONFIG_PROC_FS
23674 +
23675 +/*     get_nid_list()
23676 +
23677 +       * get a subset of hashed nids for proc
23678 +       * assumes size is at least one                          */
23679 +
23680 +int get_nid_list(int index, unsigned int *nids, int size)
23681 +{
23682 +       int hindex, nr_nids = 0;
23683 +
23684 +       /* only show current and children */
23685 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
23686 +               if (index > 0)
23687 +                       return 0;
23688 +               nids[nr_nids] = nx_current_nid();
23689 +               return 1;
23690 +       }
23691 +
23692 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
23693 +               struct hlist_head *head = &nx_info_hash[hindex];
23694 +               struct hlist_node *pos;
23695 +
23696 +               spin_lock(&nx_info_hash_lock);
23697 +               hlist_for_each(pos, head) {
23698 +                       struct nx_info *nxi;
23699 +
23700 +                       if (--index > 0)
23701 +                               continue;
23702 +
23703 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
23704 +                       nids[nr_nids] = nxi->nx_id;
23705 +                       if (++nr_nids >= size) {
23706 +                               spin_unlock(&nx_info_hash_lock);
23707 +                               goto out;
23708 +                       }
23709 +               }
23710 +               /* keep the lock time short */
23711 +               spin_unlock(&nx_info_hash_lock);
23712 +       }
23713 +out:
23714 +       return nr_nids;
23715 +}
23716 +#endif
23717 +
23718 +
23719 +/*
23720 + *     migrate task to new network
23721 + *     gets nxi, puts old_nxi on change
23722 + */
23723 +
23724 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
23725 +{
23726 +       struct nx_info *old_nxi;
23727 +       int ret = 0;
23728 +
23729 +       if (!p || !nxi)
23730 +               BUG();
23731 +
23732 +       vxdprintk(VXD_CBIT(nid, 5),
23733 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
23734 +               p, nxi, nxi->nx_id,
23735 +               atomic_read(&nxi->nx_usecnt),
23736 +               atomic_read(&nxi->nx_tasks));
23737 +
23738 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
23739 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
23740 +               return -EACCES;
23741 +
23742 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
23743 +               return -EFAULT;
23744 +
23745 +       /* maybe disallow this completely? */
23746 +       old_nxi = task_get_nx_info(p);
23747 +       if (old_nxi == nxi)
23748 +               goto out;
23749 +
23750 +       task_lock(p);
23751 +       if (old_nxi)
23752 +               clr_nx_info(&p->nx_info);
23753 +       claim_nx_info(nxi, p);
23754 +       set_nx_info(&p->nx_info, nxi);
23755 +       p->nid = nxi->nx_id;
23756 +       task_unlock(p);
23757 +
23758 +       vxdprintk(VXD_CBIT(nid, 5),
23759 +               "moved task %p into nxi:%p[#%d]",
23760 +               p, nxi, nxi->nx_id);
23761 +
23762 +       if (old_nxi)
23763 +               release_nx_info(old_nxi, p);
23764 +       ret = 0;
23765 +out:
23766 +       put_nx_info(old_nxi);
23767 +       return ret;
23768 +}
23769 +
23770 +
23771 +void nx_set_persistent(struct nx_info *nxi)
23772 +{
23773 +       vxdprintk(VXD_CBIT(nid, 6),
23774 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
23775 +
23776 +       get_nx_info(nxi);
23777 +       claim_nx_info(nxi, NULL);
23778 +}
23779 +
23780 +void nx_clear_persistent(struct nx_info *nxi)
23781 +{
23782 +       vxdprintk(VXD_CBIT(nid, 6),
23783 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
23784 +
23785 +       release_nx_info(nxi, NULL);
23786 +       put_nx_info(nxi);
23787 +}
23788 +
23789 +void nx_update_persistent(struct nx_info *nxi)
23790 +{
23791 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
23792 +               nx_set_persistent(nxi);
23793 +       else
23794 +               nx_clear_persistent(nxi);
23795 +}
23796 +
23797 +/* vserver syscall commands below here */
23798 +
23799 +/* taks nid and nx_info functions */
23800 +
23801 +#include <asm/uaccess.h>
23802 +
23803 +
23804 +int vc_task_nid(uint32_t id)
23805 +{
23806 +       nid_t nid;
23807 +
23808 +       if (id) {
23809 +               struct task_struct *tsk;
23810 +
23811 +               read_lock(&tasklist_lock);
23812 +               tsk = find_task_by_real_pid(id);
23813 +               nid = (tsk) ? tsk->nid : -ESRCH;
23814 +               read_unlock(&tasklist_lock);
23815 +       } else
23816 +               nid = nx_current_nid();
23817 +       return nid;
23818 +}
23819 +
23820 +
23821 +int vc_nx_info(struct nx_info *nxi, void __user *data)
23822 +{
23823 +       struct vcmd_nx_info_v0 vc_data;
23824 +
23825 +       vc_data.nid = nxi->nx_id;
23826 +
23827 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23828 +               return -EFAULT;
23829 +       return 0;
23830 +}
23831 +
23832 +
23833 +/* network functions */
23834 +
23835 +int vc_net_create(uint32_t nid, void __user *data)
23836 +{
23837 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
23838 +       struct nx_info *new_nxi;
23839 +       int ret;
23840 +
23841 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23842 +               return -EFAULT;
23843 +
23844 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
23845 +               return -EINVAL;
23846 +
23847 +       new_nxi = __create_nx_info(nid);
23848 +       if (IS_ERR(new_nxi))
23849 +               return PTR_ERR(new_nxi);
23850 +
23851 +       /* initial flags */
23852 +       new_nxi->nx_flags = vc_data.flagword;
23853 +
23854 +       ret = -ENOEXEC;
23855 +       if (vs_net_change(new_nxi, VSC_NETUP))
23856 +               goto out;
23857 +
23858 +       ret = nx_migrate_task(current, new_nxi);
23859 +       if (ret)
23860 +               goto out;
23861 +
23862 +       /* return context id on success */
23863 +       ret = new_nxi->nx_id;
23864 +
23865 +       /* get a reference for persistent contexts */
23866 +       if ((vc_data.flagword & NXF_PERSISTENT))
23867 +               nx_set_persistent(new_nxi);
23868 +out:
23869 +       release_nx_info(new_nxi, NULL);
23870 +       put_nx_info(new_nxi);
23871 +       return ret;
23872 +}
23873 +
23874 +
23875 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
23876 +{
23877 +       return nx_migrate_task(current, nxi);
23878 +}
23879 +
23880 +
23881 +
23882 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
23883 +       uint16_t type, uint16_t flags)
23884 +{
23885 +       struct nx_addr_v4 *nxa = &nxi->v4;
23886 +
23887 +       if (NX_IPV4(nxi)) {
23888 +               /* locate last entry */
23889 +               for (; nxa->next; nxa = nxa->next);
23890 +               nxa->next = __alloc_nx_addr_v4();
23891 +               nxa = nxa->next;
23892 +
23893 +               if (IS_ERR(nxa))
23894 +                       return PTR_ERR(nxa);
23895 +       }
23896 +
23897 +       if (nxi->v4.next)
23898 +               /* remove single ip for ip list */
23899 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
23900 +
23901 +       nxa->ip[0].s_addr = ip;
23902 +       nxa->ip[1].s_addr = ip2;
23903 +       nxa->mask.s_addr = mask;
23904 +       nxa->type = type;
23905 +       nxa->flags = flags;
23906 +       return 0;
23907 +}
23908 +
23909 +
23910 +int vc_net_add(struct nx_info *nxi, void __user *data)
23911 +{
23912 +       struct vcmd_net_addr_v0 vc_data;
23913 +       int index, ret = 0;
23914 +
23915 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23916 +               return -EFAULT;
23917 +
23918 +       switch (vc_data.type) {
23919 +       case NXA_TYPE_IPV4:
23920 +               if ((vc_data.count < 1) || (vc_data.count > 4))
23921 +                       return -EINVAL;
23922 +
23923 +               index = 0;
23924 +               while (index < vc_data.count) {
23925 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
23926 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
23927 +                       if (ret)
23928 +                               return ret;
23929 +                       index++;
23930 +               }
23931 +               ret = index;
23932 +               break;
23933 +
23934 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
23935 +               nxi->v4_bcast = vc_data.ip[0];
23936 +               ret = 1;
23937 +               break;
23938 +
23939 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
23940 +               nxi->v4_lback = vc_data.ip[0];
23941 +               ret = 1;
23942 +               break;
23943 +
23944 +       default:
23945 +               ret = -EINVAL;
23946 +               break;
23947 +       }
23948 +       return ret;
23949 +}
23950 +
23951 +int vc_net_remove(struct nx_info *nxi, void __user *data)
23952 +{
23953 +       struct vcmd_net_addr_v0 vc_data;
23954 +
23955 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23956 +               return -EFAULT;
23957 +
23958 +       switch (vc_data.type) {
23959 +       case NXA_TYPE_ANY:
23960 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
23961 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
23962 +               break;
23963 +
23964 +       default:
23965 +               return -EINVAL;
23966 +       }
23967 +       return 0;
23968 +}
23969 +
23970 +
23971 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
23972 +{
23973 +       struct vcmd_net_addr_ipv4_v1 vc_data;
23974 +
23975 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23976 +               return -EFAULT;
23977 +
23978 +       switch (vc_data.type) {
23979 +       case NXA_TYPE_ADDR:
23980 +       case NXA_TYPE_RANGE:
23981 +       case NXA_TYPE_MASK:
23982 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
23983 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
23984 +
23985 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
23986 +               nxi->v4_bcast = vc_data.ip;
23987 +               break;
23988 +
23989 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
23990 +               nxi->v4_lback = vc_data.ip;
23991 +               break;
23992 +
23993 +       default:
23994 +               return -EINVAL;
23995 +       }
23996 +       return 0;
23997 +}
23998 +
23999 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
24000 +{
24001 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24002 +
24003 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24004 +               return -EFAULT;
24005 +
24006 +       switch (vc_data.type) {
24007 +/*     case NXA_TYPE_ADDR:
24008 +               break;          */
24009 +
24010 +       case NXA_TYPE_ANY:
24011 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24012 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24013 +               break;
24014 +
24015 +       default:
24016 +               return -EINVAL;
24017 +       }
24018 +       return 0;
24019 +}
24020 +
24021 +
24022 +#ifdef CONFIG_IPV6
24023 +
24024 +int do_add_v6_addr(struct nx_info *nxi,
24025 +       struct in6_addr *ip, struct in6_addr *mask,
24026 +       uint32_t prefix, uint16_t type, uint16_t flags)
24027 +{
24028 +       struct nx_addr_v6 *nxa = &nxi->v6;
24029 +
24030 +       if (NX_IPV6(nxi)) {
24031 +               /* locate last entry */
24032 +               for (; nxa->next; nxa = nxa->next);
24033 +               nxa->next = __alloc_nx_addr_v6();
24034 +               nxa = nxa->next;
24035 +
24036 +               if (IS_ERR(nxa))
24037 +                       return PTR_ERR(nxa);
24038 +       }
24039 +
24040 +       nxa->ip = *ip;
24041 +       nxa->mask = *mask;
24042 +       nxa->prefix = prefix;
24043 +       nxa->type = type;
24044 +       nxa->flags = flags;
24045 +       return 0;
24046 +}
24047 +
24048 +
24049 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
24050 +{
24051 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24052 +
24053 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24054 +               return -EFAULT;
24055 +
24056 +       switch (vc_data.type) {
24057 +       case NXA_TYPE_ADDR:
24058 +       case NXA_TYPE_MASK:
24059 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
24060 +                       vc_data.prefix, vc_data.type, vc_data.flags);
24061 +       default:
24062 +               return -EINVAL;
24063 +       }
24064 +       return 0;
24065 +}
24066 +
24067 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
24068 +{
24069 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24070 +
24071 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24072 +               return -EFAULT;
24073 +
24074 +       switch (vc_data.type) {
24075 +       case NXA_TYPE_ANY:
24076 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
24077 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
24078 +               break;
24079 +
24080 +       default:
24081 +               return -EINVAL;
24082 +       }
24083 +       return 0;
24084 +}
24085 +
24086 +#endif /* CONFIG_IPV6 */
24087 +
24088 +
24089 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
24090 +{
24091 +       struct vcmd_net_flags_v0 vc_data;
24092 +
24093 +       vc_data.flagword = nxi->nx_flags;
24094 +
24095 +       /* special STATE flag handling */
24096 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
24097 +
24098 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24099 +               return -EFAULT;
24100 +       return 0;
24101 +}
24102 +
24103 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
24104 +{
24105 +       struct vcmd_net_flags_v0 vc_data;
24106 +       uint64_t mask, trigger;
24107 +
24108 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24109 +               return -EFAULT;
24110 +
24111 +       /* special STATE flag handling */
24112 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
24113 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
24114 +
24115 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
24116 +               vc_data.flagword, mask);
24117 +       if (trigger & NXF_PERSISTENT)
24118 +               nx_update_persistent(nxi);
24119 +
24120 +       return 0;
24121 +}
24122 +
24123 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
24124 +{
24125 +       struct vcmd_net_caps_v0 vc_data;
24126 +
24127 +       vc_data.ncaps = nxi->nx_ncaps;
24128 +       vc_data.cmask = ~0ULL;
24129 +
24130 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24131 +               return -EFAULT;
24132 +       return 0;
24133 +}
24134 +
24135 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
24136 +{
24137 +       struct vcmd_net_caps_v0 vc_data;
24138 +
24139 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24140 +               return -EFAULT;
24141 +
24142 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
24143 +               vc_data.ncaps, vc_data.cmask);
24144 +       return 0;
24145 +}
24146 +
24147 +
24148 +#include <linux/module.h>
24149 +
24150 +module_init(init_network);
24151 +
24152 +EXPORT_SYMBOL_GPL(free_nx_info);
24153 +EXPORT_SYMBOL_GPL(unhash_nx_info);
24154 +
24155 diff -NurpP --minimal linux-2.6.33/kernel/vserver/proc.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/proc.c
24156 --- linux-2.6.33/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
24157 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/proc.c  2010-02-25 12:02:16.000000000 +0100
24158 @@ -0,0 +1,1098 @@
24159 +/*
24160 + *  linux/kernel/vserver/proc.c
24161 + *
24162 + *  Virtual Context Support
24163 + *
24164 + *  Copyright (C) 2003-2007  Herbert Pötzl
24165 + *
24166 + *  V0.01  basic structure
24167 + *  V0.02  adaptation vs1.3.0
24168 + *  V0.03  proc permissions
24169 + *  V0.04  locking/generic
24170 + *  V0.05  next generation procfs
24171 + *  V0.06  inode validation
24172 + *  V0.07  generic rewrite vid
24173 + *  V0.08  remove inode type
24174 + *
24175 + */
24176 +
24177 +#include <linux/proc_fs.h>
24178 +#include <linux/fs_struct.h>
24179 +#include <linux/mount.h>
24180 +#include <asm/unistd.h>
24181 +
24182 +#include <linux/vs_context.h>
24183 +#include <linux/vs_network.h>
24184 +#include <linux/vs_cvirt.h>
24185 +
24186 +#include <linux/in.h>
24187 +#include <linux/inetdevice.h>
24188 +#include <linux/vs_inet.h>
24189 +#include <linux/vs_inet6.h>
24190 +
24191 +#include <linux/vserver/global.h>
24192 +
24193 +#include "cvirt_proc.h"
24194 +#include "cacct_proc.h"
24195 +#include "limit_proc.h"
24196 +#include "sched_proc.h"
24197 +#include "vci_config.h"
24198 +
24199 +
24200 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
24201 +{
24202 +       unsigned __capi;
24203 +
24204 +       CAP_FOR_EACH_U32(__capi) {
24205 +               buffer += sprintf(buffer, "%08x",
24206 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
24207 +       }
24208 +       return buffer;
24209 +}
24210 +
24211 +
24212 +static struct proc_dir_entry *proc_virtual;
24213 +
24214 +static struct proc_dir_entry *proc_virtnet;
24215 +
24216 +
24217 +/* first the actual feeds */
24218 +
24219 +
24220 +static int proc_vci(char *buffer)
24221 +{
24222 +       return sprintf(buffer,
24223 +               "VCIVersion:\t%04x:%04x\n"
24224 +               "VCISyscall:\t%d\n"
24225 +               "VCIKernel:\t%08x\n",
24226 +               VCI_VERSION >> 16,
24227 +               VCI_VERSION & 0xFFFF,
24228 +               __NR_vserver,
24229 +               vci_kernel_config());
24230 +}
24231 +
24232 +static int proc_virtual_info(char *buffer)
24233 +{
24234 +       return proc_vci(buffer);
24235 +}
24236 +
24237 +static int proc_virtual_status(char *buffer)
24238 +{
24239 +       return sprintf(buffer,
24240 +               "#CTotal:\t%d\n"
24241 +               "#CActive:\t%d\n"
24242 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
24243 +               "#InitTask:\t%d\t%d %d\n",
24244 +               atomic_read(&vx_global_ctotal),
24245 +               atomic_read(&vx_global_cactive),
24246 +               atomic_read(&vs_global_nsproxy),
24247 +               atomic_read(&vs_global_fs),
24248 +               atomic_read(&vs_global_mnt_ns),
24249 +               atomic_read(&vs_global_uts_ns),
24250 +               atomic_read(&nr_ipc_ns),
24251 +               atomic_read(&vs_global_user_ns),
24252 +               atomic_read(&vs_global_pid_ns),
24253 +               atomic_read(&init_task.usage),
24254 +               atomic_read(&init_task.nsproxy->count),
24255 +               init_task.fs->users);
24256 +}
24257 +
24258 +
24259 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
24260 +{
24261 +       int length;
24262 +
24263 +       length = sprintf(buffer,
24264 +               "ID:\t%d\n"
24265 +               "Info:\t%p\n"
24266 +               "Init:\t%d\n"
24267 +               "OOM:\t%lld\n",
24268 +               vxi->vx_id,
24269 +               vxi,
24270 +               vxi->vx_initpid,
24271 +               vxi->vx_badness_bias);
24272 +       return length;
24273 +}
24274 +
24275 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
24276 +{
24277 +       char *orig = buffer;
24278 +
24279 +       buffer += sprintf(buffer,
24280 +               "UseCnt:\t%d\n"
24281 +               "Tasks:\t%d\n"
24282 +               "Flags:\t%016llx\n",
24283 +               atomic_read(&vxi->vx_usecnt),
24284 +               atomic_read(&vxi->vx_tasks),
24285 +               (unsigned long long)vxi->vx_flags);
24286 +
24287 +       buffer += sprintf(buffer, "BCaps:\t");
24288 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
24289 +       buffer += sprintf(buffer, "\n");
24290 +
24291 +       buffer += sprintf(buffer,
24292 +               "CCaps:\t%016llx\n"
24293 +               "Spaces:\t%08lx %08lx\n",
24294 +               (unsigned long long)vxi->vx_ccaps,
24295 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
24296 +       return buffer - orig;
24297 +}
24298 +
24299 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
24300 +{
24301 +       return vx_info_proc_limit(&vxi->limit, buffer);
24302 +}
24303 +
24304 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
24305 +{
24306 +       int cpu, length;
24307 +
24308 +       length = vx_info_proc_sched(&vxi->sched, buffer);
24309 +       for_each_online_cpu(cpu) {
24310 +               length += vx_info_proc_sched_pc(
24311 +                       &vx_per_cpu(vxi, sched_pc, cpu),
24312 +                       buffer + length, cpu);
24313 +       }
24314 +       return length;
24315 +}
24316 +
24317 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
24318 +{
24319 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
24320 +}
24321 +
24322 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
24323 +{
24324 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
24325 +}
24326 +
24327 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
24328 +{
24329 +       int cpu, length;
24330 +
24331 +       vx_update_load(vxi);
24332 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
24333 +       for_each_online_cpu(cpu) {
24334 +               length += vx_info_proc_cvirt_pc(
24335 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
24336 +                       buffer + length, cpu);
24337 +       }
24338 +       return length;
24339 +}
24340 +
24341 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
24342 +{
24343 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
24344 +}
24345 +
24346 +
24347 +static int proc_virtnet_info(char *buffer)
24348 +{
24349 +       return proc_vci(buffer);
24350 +}
24351 +
24352 +static int proc_virtnet_status(char *buffer)
24353 +{
24354 +       return sprintf(buffer,
24355 +               "#CTotal:\t%d\n"
24356 +               "#CActive:\t%d\n",
24357 +               atomic_read(&nx_global_ctotal),
24358 +               atomic_read(&nx_global_cactive));
24359 +}
24360 +
24361 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
24362 +{
24363 +       struct nx_addr_v4 *v4a;
24364 +#ifdef CONFIG_IPV6
24365 +       struct nx_addr_v6 *v6a;
24366 +#endif
24367 +       int length, i;
24368 +
24369 +       length = sprintf(buffer,
24370 +               "ID:\t%d\n"
24371 +               "Info:\t%p\n"
24372 +               "Bcast:\t" NIPQUAD_FMT "\n"
24373 +               "Lback:\t" NIPQUAD_FMT "\n",
24374 +               nxi->nx_id,
24375 +               nxi,
24376 +               NIPQUAD(nxi->v4_bcast.s_addr),
24377 +               NIPQUAD(nxi->v4_lback.s_addr));
24378 +
24379 +       if (!NX_IPV4(nxi))
24380 +               goto skip_v4;
24381 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24382 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
24383 +                       i, NXAV4(v4a));
24384 +skip_v4:
24385 +#ifdef CONFIG_IPV6
24386 +       if (!NX_IPV6(nxi))
24387 +               goto skip_v6;
24388 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24389 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
24390 +                       i, NXAV6(v6a));
24391 +skip_v6:
24392 +#endif
24393 +       return length;
24394 +}
24395 +
24396 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
24397 +{
24398 +       int length;
24399 +
24400 +       length = sprintf(buffer,
24401 +               "UseCnt:\t%d\n"
24402 +               "Tasks:\t%d\n"
24403 +               "Flags:\t%016llx\n"
24404 +               "NCaps:\t%016llx\n",
24405 +               atomic_read(&nxi->nx_usecnt),
24406 +               atomic_read(&nxi->nx_tasks),
24407 +               (unsigned long long)nxi->nx_flags,
24408 +               (unsigned long long)nxi->nx_ncaps);
24409 +       return length;
24410 +}
24411 +
24412 +
24413 +
24414 +/* here the inode helpers */
24415 +
24416 +struct vs_entry {
24417 +       int len;
24418 +       char *name;
24419 +       mode_t mode;
24420 +       struct inode_operations *iop;
24421 +       struct file_operations *fop;
24422 +       union proc_op op;
24423 +};
24424 +
24425 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
24426 +{
24427 +       struct inode *inode = new_inode(sb);
24428 +
24429 +       if (!inode)
24430 +               goto out;
24431 +
24432 +       inode->i_mode = p->mode;
24433 +       if (p->iop)
24434 +               inode->i_op = p->iop;
24435 +       if (p->fop)
24436 +               inode->i_fop = p->fop;
24437 +
24438 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
24439 +       inode->i_flags |= S_IMMUTABLE;
24440 +
24441 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
24442 +
24443 +       inode->i_uid = 0;
24444 +       inode->i_gid = 0;
24445 +       inode->i_tag = 0;
24446 +out:
24447 +       return inode;
24448 +}
24449 +
24450 +static struct dentry *vs_proc_instantiate(struct inode *dir,
24451 +       struct dentry *dentry, int id, void *ptr)
24452 +{
24453 +       struct vs_entry *p = ptr;
24454 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
24455 +       struct dentry *error = ERR_PTR(-EINVAL);
24456 +
24457 +       if (!inode)
24458 +               goto out;
24459 +
24460 +       PROC_I(inode)->op = p->op;
24461 +       PROC_I(inode)->fd = id;
24462 +       d_add(dentry, inode);
24463 +       error = NULL;
24464 +out:
24465 +       return error;
24466 +}
24467 +
24468 +/* Lookups */
24469 +
24470 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
24471 +
24472 +/*
24473 + * Fill a directory entry.
24474 + *
24475 + * If possible create the dcache entry and derive our inode number and
24476 + * file type from dcache entry.
24477 + *
24478 + * Since all of the proc inode numbers are dynamically generated, the inode
24479 + * numbers do not exist until the inode is cache.  This means creating the
24480 + * the dcache entry in readdir is necessary to keep the inode numbers
24481 + * reported by readdir in sync with the inode numbers reported
24482 + * by stat.
24483 + */
24484 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
24485 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
24486 +{
24487 +       struct dentry *child, *dir = filp->f_dentry;
24488 +       struct inode *inode;
24489 +       struct qstr qname;
24490 +       ino_t ino = 0;
24491 +       unsigned type = DT_UNKNOWN;
24492 +
24493 +       qname.name = name;
24494 +       qname.len  = len;
24495 +       qname.hash = full_name_hash(name, len);
24496 +
24497 +       child = d_lookup(dir, &qname);
24498 +       if (!child) {
24499 +               struct dentry *new;
24500 +               new = d_alloc(dir, &qname);
24501 +               if (new) {
24502 +                       child = instantiate(dir->d_inode, new, id, ptr);
24503 +                       if (child)
24504 +                               dput(new);
24505 +                       else
24506 +                               child = new;
24507 +               }
24508 +       }
24509 +       if (!child || IS_ERR(child) || !child->d_inode)
24510 +               goto end_instantiate;
24511 +       inode = child->d_inode;
24512 +       if (inode) {
24513 +               ino = inode->i_ino;
24514 +               type = inode->i_mode >> 12;
24515 +       }
24516 +       dput(child);
24517 +end_instantiate:
24518 +       if (!ino)
24519 +               ino = find_inode_number(dir, &qname);
24520 +       if (!ino)
24521 +               ino = 1;
24522 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
24523 +}
24524 +
24525 +
24526 +
24527 +/* get and revalidate vx_info/xid */
24528 +
24529 +static inline
24530 +struct vx_info *get_proc_vx_info(struct inode *inode)
24531 +{
24532 +       return lookup_vx_info(PROC_I(inode)->fd);
24533 +}
24534 +
24535 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
24536 +{
24537 +       struct inode *inode = dentry->d_inode;
24538 +       xid_t xid = PROC_I(inode)->fd;
24539 +
24540 +       if (!xid || xid_is_hashed(xid))
24541 +               return 1;
24542 +       d_drop(dentry);
24543 +       return 0;
24544 +}
24545 +
24546 +
24547 +/* get and revalidate nx_info/nid */
24548 +
24549 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
24550 +{
24551 +       struct inode *inode = dentry->d_inode;
24552 +       nid_t nid = PROC_I(inode)->fd;
24553 +
24554 +       if (!nid || nid_is_hashed(nid))
24555 +               return 1;
24556 +       d_drop(dentry);
24557 +       return 0;
24558 +}
24559 +
24560 +
24561 +
24562 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
24563 +
24564 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
24565 +                         size_t count, loff_t *ppos)
24566 +{
24567 +       struct inode *inode = file->f_dentry->d_inode;
24568 +       unsigned long page;
24569 +       ssize_t length = 0;
24570 +
24571 +       if (count > PROC_BLOCK_SIZE)
24572 +               count = PROC_BLOCK_SIZE;
24573 +
24574 +       /* fade that out as soon as stable */
24575 +       WARN_ON(PROC_I(inode)->fd);
24576 +
24577 +       if (!(page = __get_free_page(GFP_KERNEL)))
24578 +               return -ENOMEM;
24579 +
24580 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
24581 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
24582 +
24583 +       if (length >= 0)
24584 +               length = simple_read_from_buffer(buf, count, ppos,
24585 +                       (char *)page, length);
24586 +
24587 +       free_page(page);
24588 +       return length;
24589 +}
24590 +
24591 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
24592 +                         size_t count, loff_t *ppos)
24593 +{
24594 +       struct inode *inode = file->f_dentry->d_inode;
24595 +       struct vx_info *vxi = NULL;
24596 +       xid_t xid = PROC_I(inode)->fd;
24597 +       unsigned long page;
24598 +       ssize_t length = 0;
24599 +
24600 +       if (count > PROC_BLOCK_SIZE)
24601 +               count = PROC_BLOCK_SIZE;
24602 +
24603 +       /* fade that out as soon as stable */
24604 +       WARN_ON(!xid);
24605 +       vxi = lookup_vx_info(xid);
24606 +       if (!vxi)
24607 +               goto out;
24608 +
24609 +       length = -ENOMEM;
24610 +       if (!(page = __get_free_page(GFP_KERNEL)))
24611 +               goto out_put;
24612 +
24613 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
24614 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
24615 +
24616 +       if (length >= 0)
24617 +               length = simple_read_from_buffer(buf, count, ppos,
24618 +                       (char *)page, length);
24619 +
24620 +       free_page(page);
24621 +out_put:
24622 +       put_vx_info(vxi);
24623 +out:
24624 +       return length;
24625 +}
24626 +
24627 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
24628 +                         size_t count, loff_t *ppos)
24629 +{
24630 +       struct inode *inode = file->f_dentry->d_inode;
24631 +       struct nx_info *nxi = NULL;
24632 +       nid_t nid = PROC_I(inode)->fd;
24633 +       unsigned long page;
24634 +       ssize_t length = 0;
24635 +
24636 +       if (count > PROC_BLOCK_SIZE)
24637 +               count = PROC_BLOCK_SIZE;
24638 +
24639 +       /* fade that out as soon as stable */
24640 +       WARN_ON(!nid);
24641 +       nxi = lookup_nx_info(nid);
24642 +       if (!nxi)
24643 +               goto out;
24644 +
24645 +       length = -ENOMEM;
24646 +       if (!(page = __get_free_page(GFP_KERNEL)))
24647 +               goto out_put;
24648 +
24649 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
24650 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
24651 +
24652 +       if (length >= 0)
24653 +               length = simple_read_from_buffer(buf, count, ppos,
24654 +                       (char *)page, length);
24655 +
24656 +       free_page(page);
24657 +out_put:
24658 +       put_nx_info(nxi);
24659 +out:
24660 +       return length;
24661 +}
24662 +
24663 +
24664 +
24665 +/* here comes the lower level */
24666 +
24667 +
24668 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
24669 +       .len  = sizeof(NAME) - 1,       \
24670 +       .name = (NAME),                 \
24671 +       .mode = MODE,                   \
24672 +       .iop  = IOP,                    \
24673 +       .fop  = FOP,                    \
24674 +       .op   = OP,                     \
24675 +}
24676 +
24677 +
24678 +#define DIR(NAME, MODE, OTYPE)                         \
24679 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
24680 +               &proc_ ## OTYPE ## _inode_operations,   \
24681 +               &proc_ ## OTYPE ## _file_operations, { } )
24682 +
24683 +#define INF(NAME, MODE, OTYPE)                         \
24684 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
24685 +               &proc_vs_info_file_operations,          \
24686 +               { .proc_vs_read = &proc_##OTYPE } )
24687 +
24688 +#define VINF(NAME, MODE, OTYPE)                                \
24689 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
24690 +               &proc_vx_info_file_operations,          \
24691 +               { .proc_vxi_read = &proc_##OTYPE } )
24692 +
24693 +#define NINF(NAME, MODE, OTYPE)                                \
24694 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
24695 +               &proc_nx_info_file_operations,          \
24696 +               { .proc_nxi_read = &proc_##OTYPE } )
24697 +
24698 +
24699 +static struct file_operations proc_vs_info_file_operations = {
24700 +       .read =         proc_vs_info_read,
24701 +};
24702 +
24703 +static struct file_operations proc_vx_info_file_operations = {
24704 +       .read =         proc_vx_info_read,
24705 +};
24706 +
24707 +static struct dentry_operations proc_xid_dentry_operations = {
24708 +       .d_revalidate = proc_xid_revalidate,
24709 +};
24710 +
24711 +static struct vs_entry vx_base_stuff[] = {
24712 +       VINF("info",    S_IRUGO, vxi_info),
24713 +       VINF("status",  S_IRUGO, vxi_status),
24714 +       VINF("limit",   S_IRUGO, vxi_limit),
24715 +       VINF("sched",   S_IRUGO, vxi_sched),
24716 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
24717 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
24718 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
24719 +       VINF("cacct",   S_IRUGO, vxi_cacct),
24720 +       {}
24721 +};
24722 +
24723 +
24724 +
24725 +
24726 +static struct dentry *proc_xid_instantiate(struct inode *dir,
24727 +       struct dentry *dentry, int id, void *ptr)
24728 +{
24729 +       dentry->d_op = &proc_xid_dentry_operations;
24730 +       return vs_proc_instantiate(dir, dentry, id, ptr);
24731 +}
24732 +
24733 +static struct dentry *proc_xid_lookup(struct inode *dir,
24734 +       struct dentry *dentry, struct nameidata *nd)
24735 +{
24736 +       struct vs_entry *p = vx_base_stuff;
24737 +       struct dentry *error = ERR_PTR(-ENOENT);
24738 +
24739 +       for (; p->name; p++) {
24740 +               if (p->len != dentry->d_name.len)
24741 +                       continue;
24742 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24743 +                       break;
24744 +       }
24745 +       if (!p->name)
24746 +               goto out;
24747 +
24748 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
24749 +out:
24750 +       return error;
24751 +}
24752 +
24753 +static int proc_xid_readdir(struct file *filp,
24754 +       void *dirent, filldir_t filldir)
24755 +{
24756 +       struct dentry *dentry = filp->f_dentry;
24757 +       struct inode *inode = dentry->d_inode;
24758 +       struct vs_entry *p = vx_base_stuff;
24759 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
24760 +       int pos, index;
24761 +       u64 ino;
24762 +
24763 +       pos = filp->f_pos;
24764 +       switch (pos) {
24765 +       case 0:
24766 +               ino = inode->i_ino;
24767 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24768 +                       goto out;
24769 +               pos++;
24770 +               /* fall through */
24771 +       case 1:
24772 +               ino = parent_ino(dentry);
24773 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24774 +                       goto out;
24775 +               pos++;
24776 +               /* fall through */
24777 +       default:
24778 +               index = pos - 2;
24779 +               if (index >= size)
24780 +                       goto out;
24781 +               for (p += index; p->name; p++) {
24782 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24783 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
24784 +                               goto out;
24785 +                       pos++;
24786 +               }
24787 +       }
24788 +out:
24789 +       filp->f_pos = pos;
24790 +       return 1;
24791 +}
24792 +
24793 +
24794 +
24795 +static struct file_operations proc_nx_info_file_operations = {
24796 +       .read =         proc_nx_info_read,
24797 +};
24798 +
24799 +static struct dentry_operations proc_nid_dentry_operations = {
24800 +       .d_revalidate = proc_nid_revalidate,
24801 +};
24802 +
24803 +static struct vs_entry nx_base_stuff[] = {
24804 +       NINF("info",    S_IRUGO, nxi_info),
24805 +       NINF("status",  S_IRUGO, nxi_status),
24806 +       {}
24807 +};
24808 +
24809 +
24810 +static struct dentry *proc_nid_instantiate(struct inode *dir,
24811 +       struct dentry *dentry, int id, void *ptr)
24812 +{
24813 +       dentry->d_op = &proc_nid_dentry_operations;
24814 +       return vs_proc_instantiate(dir, dentry, id, ptr);
24815 +}
24816 +
24817 +static struct dentry *proc_nid_lookup(struct inode *dir,
24818 +       struct dentry *dentry, struct nameidata *nd)
24819 +{
24820 +       struct vs_entry *p = nx_base_stuff;
24821 +       struct dentry *error = ERR_PTR(-ENOENT);
24822 +
24823 +       for (; p->name; p++) {
24824 +               if (p->len != dentry->d_name.len)
24825 +                       continue;
24826 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24827 +                       break;
24828 +       }
24829 +       if (!p->name)
24830 +               goto out;
24831 +
24832 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
24833 +out:
24834 +       return error;
24835 +}
24836 +
24837 +static int proc_nid_readdir(struct file *filp,
24838 +       void *dirent, filldir_t filldir)
24839 +{
24840 +       struct dentry *dentry = filp->f_dentry;
24841 +       struct inode *inode = dentry->d_inode;
24842 +       struct vs_entry *p = nx_base_stuff;
24843 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
24844 +       int pos, index;
24845 +       u64 ino;
24846 +
24847 +       pos = filp->f_pos;
24848 +       switch (pos) {
24849 +       case 0:
24850 +               ino = inode->i_ino;
24851 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24852 +                       goto out;
24853 +               pos++;
24854 +               /* fall through */
24855 +       case 1:
24856 +               ino = parent_ino(dentry);
24857 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24858 +                       goto out;
24859 +               pos++;
24860 +               /* fall through */
24861 +       default:
24862 +               index = pos - 2;
24863 +               if (index >= size)
24864 +                       goto out;
24865 +               for (p += index; p->name; p++) {
24866 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24867 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
24868 +                               goto out;
24869 +                       pos++;
24870 +               }
24871 +       }
24872 +out:
24873 +       filp->f_pos = pos;
24874 +       return 1;
24875 +}
24876 +
24877 +
24878 +#define MAX_MULBY10    ((~0U - 9) / 10)
24879 +
24880 +static inline int atovid(const char *str, int len)
24881 +{
24882 +       int vid, c;
24883 +
24884 +       vid = 0;
24885 +       while (len-- > 0) {
24886 +               c = *str - '0';
24887 +               str++;
24888 +               if (c > 9)
24889 +                       return -1;
24890 +               if (vid >= MAX_MULBY10)
24891 +                       return -1;
24892 +               vid *= 10;
24893 +               vid += c;
24894 +               if (!vid)
24895 +                       return -1;
24896 +       }
24897 +       return vid;
24898 +}
24899 +
24900 +/* now the upper level (virtual) */
24901 +
24902 +
24903 +static struct file_operations proc_xid_file_operations = {
24904 +       .read =         generic_read_dir,
24905 +       .readdir =      proc_xid_readdir,
24906 +};
24907 +
24908 +static struct inode_operations proc_xid_inode_operations = {
24909 +       .lookup =       proc_xid_lookup,
24910 +};
24911 +
24912 +static struct vs_entry vx_virtual_stuff[] = {
24913 +       INF("info",     S_IRUGO, virtual_info),
24914 +       INF("status",   S_IRUGO, virtual_status),
24915 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
24916 +};
24917 +
24918 +
24919 +static struct dentry *proc_virtual_lookup(struct inode *dir,
24920 +       struct dentry *dentry, struct nameidata *nd)
24921 +{
24922 +       struct vs_entry *p = vx_virtual_stuff;
24923 +       struct dentry *error = ERR_PTR(-ENOENT);
24924 +       int id = 0;
24925 +
24926 +       for (; p->name; p++) {
24927 +               if (p->len != dentry->d_name.len)
24928 +                       continue;
24929 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24930 +                       break;
24931 +       }
24932 +       if (p->name)
24933 +               goto instantiate;
24934 +
24935 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
24936 +       if ((id < 0) || !xid_is_hashed(id))
24937 +               goto out;
24938 +
24939 +instantiate:
24940 +       error = proc_xid_instantiate(dir, dentry, id, p);
24941 +out:
24942 +       return error;
24943 +}
24944 +
24945 +static struct file_operations proc_nid_file_operations = {
24946 +       .read =         generic_read_dir,
24947 +       .readdir =      proc_nid_readdir,
24948 +};
24949 +
24950 +static struct inode_operations proc_nid_inode_operations = {
24951 +       .lookup =       proc_nid_lookup,
24952 +};
24953 +
24954 +static struct vs_entry nx_virtnet_stuff[] = {
24955 +       INF("info",     S_IRUGO, virtnet_info),
24956 +       INF("status",   S_IRUGO, virtnet_status),
24957 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
24958 +};
24959 +
24960 +
24961 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
24962 +       struct dentry *dentry, struct nameidata *nd)
24963 +{
24964 +       struct vs_entry *p = nx_virtnet_stuff;
24965 +       struct dentry *error = ERR_PTR(-ENOENT);
24966 +       int id = 0;
24967 +
24968 +       for (; p->name; p++) {
24969 +               if (p->len != dentry->d_name.len)
24970 +                       continue;
24971 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24972 +                       break;
24973 +       }
24974 +       if (p->name)
24975 +               goto instantiate;
24976 +
24977 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
24978 +       if ((id < 0) || !nid_is_hashed(id))
24979 +               goto out;
24980 +
24981 +instantiate:
24982 +       error = proc_nid_instantiate(dir, dentry, id, p);
24983 +out:
24984 +       return error;
24985 +}
24986 +
24987 +
24988 +#define PROC_MAXVIDS 32
24989 +
24990 +int proc_virtual_readdir(struct file *filp,
24991 +       void *dirent, filldir_t filldir)
24992 +{
24993 +       struct dentry *dentry = filp->f_dentry;
24994 +       struct inode *inode = dentry->d_inode;
24995 +       struct vs_entry *p = vx_virtual_stuff;
24996 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
24997 +       int pos, index;
24998 +       unsigned int xid_array[PROC_MAXVIDS];
24999 +       char buf[PROC_NUMBUF];
25000 +       unsigned int nr_xids, i;
25001 +       u64 ino;
25002 +
25003 +       pos = filp->f_pos;
25004 +       switch (pos) {
25005 +       case 0:
25006 +               ino = inode->i_ino;
25007 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25008 +                       goto out;
25009 +               pos++;
25010 +               /* fall through */
25011 +       case 1:
25012 +               ino = parent_ino(dentry);
25013 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25014 +                       goto out;
25015 +               pos++;
25016 +               /* fall through */
25017 +       default:
25018 +               index = pos - 2;
25019 +               if (index >= size)
25020 +                       goto entries;
25021 +               for (p += index; p->name; p++) {
25022 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25023 +                               vs_proc_instantiate, 0, p))
25024 +                               goto out;
25025 +                       pos++;
25026 +               }
25027 +       entries:
25028 +               index = pos - size;
25029 +               p = &vx_virtual_stuff[size - 1];
25030 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
25031 +               for (i = 0; i < nr_xids; i++) {
25032 +                       int n, xid = xid_array[i];
25033 +                       unsigned int j = PROC_NUMBUF;
25034 +
25035 +                       n = xid;
25036 +                       do
25037 +                               buf[--j] = '0' + (n % 10);
25038 +                       while (n /= 10);
25039 +
25040 +                       if (proc_fill_cache(filp, dirent, filldir,
25041 +                               buf + j, PROC_NUMBUF - j,
25042 +                               vs_proc_instantiate, xid, p))
25043 +                               goto out;
25044 +                       pos++;
25045 +               }
25046 +       }
25047 +out:
25048 +       filp->f_pos = pos;
25049 +       return 0;
25050 +}
25051 +
25052 +static int proc_virtual_getattr(struct vfsmount *mnt,
25053 +       struct dentry *dentry, struct kstat *stat)
25054 +{
25055 +       struct inode *inode = dentry->d_inode;
25056 +
25057 +       generic_fillattr(inode, stat);
25058 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
25059 +       return 0;
25060 +}
25061 +
25062 +static struct file_operations proc_virtual_dir_operations = {
25063 +       .read =         generic_read_dir,
25064 +       .readdir =      proc_virtual_readdir,
25065 +};
25066 +
25067 +static struct inode_operations proc_virtual_dir_inode_operations = {
25068 +       .getattr =      proc_virtual_getattr,
25069 +       .lookup =       proc_virtual_lookup,
25070 +};
25071 +
25072 +
25073 +
25074 +
25075 +
25076 +int proc_virtnet_readdir(struct file *filp,
25077 +       void *dirent, filldir_t filldir)
25078 +{
25079 +       struct dentry *dentry = filp->f_dentry;
25080 +       struct inode *inode = dentry->d_inode;
25081 +       struct vs_entry *p = nx_virtnet_stuff;
25082 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
25083 +       int pos, index;
25084 +       unsigned int nid_array[PROC_MAXVIDS];
25085 +       char buf[PROC_NUMBUF];
25086 +       unsigned int nr_nids, i;
25087 +       u64 ino;
25088 +
25089 +       pos = filp->f_pos;
25090 +       switch (pos) {
25091 +       case 0:
25092 +               ino = inode->i_ino;
25093 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25094 +                       goto out;
25095 +               pos++;
25096 +               /* fall through */
25097 +       case 1:
25098 +               ino = parent_ino(dentry);
25099 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25100 +                       goto out;
25101 +               pos++;
25102 +               /* fall through */
25103 +       default:
25104 +               index = pos - 2;
25105 +               if (index >= size)
25106 +                       goto entries;
25107 +               for (p += index; p->name; p++) {
25108 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25109 +                               vs_proc_instantiate, 0, p))
25110 +                               goto out;
25111 +                       pos++;
25112 +               }
25113 +       entries:
25114 +               index = pos - size;
25115 +               p = &nx_virtnet_stuff[size - 1];
25116 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
25117 +               for (i = 0; i < nr_nids; i++) {
25118 +                       int n, nid = nid_array[i];
25119 +                       unsigned int j = PROC_NUMBUF;
25120 +
25121 +                       n = nid;
25122 +                       do
25123 +                               buf[--j] = '0' + (n % 10);
25124 +                       while (n /= 10);
25125 +
25126 +                       if (proc_fill_cache(filp, dirent, filldir,
25127 +                               buf + j, PROC_NUMBUF - j,
25128 +                               vs_proc_instantiate, nid, p))
25129 +                               goto out;
25130 +                       pos++;
25131 +               }
25132 +       }
25133 +out:
25134 +       filp->f_pos = pos;
25135 +       return 0;
25136 +}
25137 +
25138 +static int proc_virtnet_getattr(struct vfsmount *mnt,
25139 +       struct dentry *dentry, struct kstat *stat)
25140 +{
25141 +       struct inode *inode = dentry->d_inode;
25142 +
25143 +       generic_fillattr(inode, stat);
25144 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
25145 +       return 0;
25146 +}
25147 +
25148 +static struct file_operations proc_virtnet_dir_operations = {
25149 +       .read =         generic_read_dir,
25150 +       .readdir =      proc_virtnet_readdir,
25151 +};
25152 +
25153 +static struct inode_operations proc_virtnet_dir_inode_operations = {
25154 +       .getattr =      proc_virtnet_getattr,
25155 +       .lookup =       proc_virtnet_lookup,
25156 +};
25157 +
25158 +
25159 +
25160 +void proc_vx_init(void)
25161 +{
25162 +       struct proc_dir_entry *ent;
25163 +
25164 +       ent = proc_mkdir("virtual", 0);
25165 +       if (ent) {
25166 +               ent->proc_fops = &proc_virtual_dir_operations;
25167 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
25168 +       }
25169 +       proc_virtual = ent;
25170 +
25171 +       ent = proc_mkdir("virtnet", 0);
25172 +       if (ent) {
25173 +               ent->proc_fops = &proc_virtnet_dir_operations;
25174 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
25175 +       }
25176 +       proc_virtnet = ent;
25177 +}
25178 +
25179 +
25180 +
25181 +
25182 +/* per pid info */
25183 +
25184 +
25185 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
25186 +{
25187 +       struct vx_info *vxi;
25188 +       char *orig = buffer;
25189 +
25190 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
25191 +
25192 +       vxi = task_get_vx_info(p);
25193 +       if (!vxi)
25194 +               goto out;
25195 +
25196 +       buffer += sprintf(buffer, "BCaps:\t");
25197 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
25198 +       buffer += sprintf(buffer, "\n");
25199 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
25200 +               (unsigned long long)vxi->vx_ccaps);
25201 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
25202 +               (unsigned long long)vxi->vx_flags);
25203 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
25204 +
25205 +       put_vx_info(vxi);
25206 +out:
25207 +       return buffer - orig;
25208 +}
25209 +
25210 +
25211 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
25212 +{
25213 +       struct nx_info *nxi;
25214 +       struct nx_addr_v4 *v4a;
25215 +#ifdef CONFIG_IPV6
25216 +       struct nx_addr_v6 *v6a;
25217 +#endif
25218 +       char *orig = buffer;
25219 +       int i;
25220 +
25221 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
25222 +
25223 +       nxi = task_get_nx_info(p);
25224 +       if (!nxi)
25225 +               goto out;
25226 +
25227 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
25228 +               (unsigned long long)nxi->nx_ncaps);
25229 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
25230 +               (unsigned long long)nxi->nx_flags);
25231 +
25232 +       buffer += sprintf(buffer,
25233 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
25234 +               NIPQUAD(nxi->v4_bcast.s_addr));
25235 +       buffer += sprintf (buffer,
25236 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
25237 +               NIPQUAD(nxi->v4_lback.s_addr));
25238 +       if (!NX_IPV4(nxi))
25239 +               goto skip_v4;
25240 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
25241 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
25242 +                       i, NXAV4(v4a));
25243 +skip_v4:
25244 +#ifdef CONFIG_IPV6
25245 +       if (!NX_IPV6(nxi))
25246 +               goto skip_v6;
25247 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
25248 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
25249 +                       i, NXAV6(v6a));
25250 +skip_v6:
25251 +#endif
25252 +       put_nx_info(nxi);
25253 +out:
25254 +       return buffer - orig;
25255 +}
25256 +
25257 diff -NurpP --minimal linux-2.6.33/kernel/vserver/sched.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/sched.c
25258 --- linux-2.6.33/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
25259 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/sched.c 2010-02-25 12:02:16.000000000 +0100
25260 @@ -0,0 +1,414 @@
25261 +/*
25262 + *  linux/kernel/vserver/sched.c
25263 + *
25264 + *  Virtual Server: Scheduler Support
25265 + *
25266 + *  Copyright (C) 2004-2007  Herbert Pötzl
25267 + *
25268 + *  V0.01  adapted Sam Vilains version to 2.6.3
25269 + *  V0.02  removed legacy interface
25270 + *  V0.03  changed vcmds to vxi arg
25271 + *  V0.04  removed older and legacy interfaces
25272 + *
25273 + */
25274 +
25275 +#include <linux/vs_context.h>
25276 +#include <linux/vs_sched.h>
25277 +#include <linux/vserver/sched_cmd.h>
25278 +
25279 +#include <asm/uaccess.h>
25280 +
25281 +
25282 +#define vxd_check_range(val, min, max) do {            \
25283 +       vxlprintk((val < min) || (val > max),           \
25284 +               "check_range(%ld,%ld,%ld)",             \
25285 +               (long)val, (long)min, (long)max,        \
25286 +               __FILE__, __LINE__);                    \
25287 +       } while (0)
25288 +
25289 +
25290 +void vx_update_sched_param(struct _vx_sched *sched,
25291 +       struct _vx_sched_pc *sched_pc)
25292 +{
25293 +       unsigned int set_mask = sched->update_mask;
25294 +
25295 +       if (set_mask & VXSM_FILL_RATE)
25296 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
25297 +       if (set_mask & VXSM_INTERVAL)
25298 +               sched_pc->interval[0] = sched->interval[0];
25299 +       if (set_mask & VXSM_FILL_RATE2)
25300 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
25301 +       if (set_mask & VXSM_INTERVAL2)
25302 +               sched_pc->interval[1] = sched->interval[1];
25303 +       if (set_mask & VXSM_TOKENS)
25304 +               sched_pc->tokens = sched->tokens;
25305 +       if (set_mask & VXSM_TOKENS_MIN)
25306 +               sched_pc->tokens_min = sched->tokens_min;
25307 +       if (set_mask & VXSM_TOKENS_MAX)
25308 +               sched_pc->tokens_max = sched->tokens_max;
25309 +       if (set_mask & VXSM_PRIO_BIAS)
25310 +               sched_pc->prio_bias = sched->prio_bias;
25311 +
25312 +       if (set_mask & VXSM_IDLE_TIME)
25313 +               sched_pc->flags |= VXSF_IDLE_TIME;
25314 +       else
25315 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
25316 +
25317 +       /* reset time */
25318 +       sched_pc->norm_time = jiffies;
25319 +}
25320 +
25321 +
25322 +/*
25323 + * recalculate the context's scheduling tokens
25324 + *
25325 + * ret > 0 : number of tokens available
25326 + * ret < 0 : on hold, check delta_min[]
25327 + *          -1 only jiffies
25328 + *          -2 also idle time
25329 + *
25330 + */
25331 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
25332 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
25333 +{
25334 +       long delta;
25335 +       long tokens = 0;
25336 +       int flags = sched_pc->flags;
25337 +
25338 +       /* how much time did pass? */
25339 +       delta = *norm_time - sched_pc->norm_time;
25340 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
25341 +       vxd_check_range(delta, 0, INT_MAX);
25342 +
25343 +       if (delta >= sched_pc->interval[0]) {
25344 +               long tokens, integral;
25345 +
25346 +               /* calc integral token part */
25347 +               tokens = delta / sched_pc->interval[0];
25348 +               integral = tokens * sched_pc->interval[0];
25349 +               tokens *= sched_pc->fill_rate[0];
25350 +#ifdef CONFIG_VSERVER_HARDCPU
25351 +               delta_min[0] = delta - integral;
25352 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
25353 +#endif
25354 +               /* advance time */
25355 +               sched_pc->norm_time += delta;
25356 +
25357 +               /* add tokens */
25358 +               sched_pc->tokens += tokens;
25359 +               sched_pc->token_time += tokens;
25360 +       } else
25361 +               delta_min[0] = delta;
25362 +
25363 +#ifdef CONFIG_VSERVER_IDLETIME
25364 +       if (!(flags & VXSF_IDLE_TIME))
25365 +               goto skip_idle;
25366 +
25367 +       /* how much was the idle skip? */
25368 +       delta = *idle_time - sched_pc->idle_time;
25369 +       vxd_check_range(delta, 0, INT_MAX);
25370 +
25371 +       if (delta >= sched_pc->interval[1]) {
25372 +               long tokens, integral;
25373 +
25374 +               /* calc fair share token part */
25375 +               tokens = delta / sched_pc->interval[1];
25376 +               integral = tokens * sched_pc->interval[1];
25377 +               tokens *= sched_pc->fill_rate[1];
25378 +               delta_min[1] = delta - integral;
25379 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
25380 +
25381 +               /* advance idle time */
25382 +               sched_pc->idle_time += integral;
25383 +
25384 +               /* add tokens */
25385 +               sched_pc->tokens += tokens;
25386 +               sched_pc->token_time += tokens;
25387 +       } else
25388 +               delta_min[1] = delta;
25389 +skip_idle:
25390 +#endif
25391 +
25392 +       /* clip at maximum */
25393 +       if (sched_pc->tokens > sched_pc->tokens_max)
25394 +               sched_pc->tokens = sched_pc->tokens_max;
25395 +       tokens = sched_pc->tokens;
25396 +
25397 +       if ((flags & VXSF_ONHOLD)) {
25398 +               /* can we unhold? */
25399 +               if (tokens >= sched_pc->tokens_min) {
25400 +                       flags &= ~VXSF_ONHOLD;
25401 +                       sched_pc->hold_ticks +=
25402 +                               *norm_time - sched_pc->onhold;
25403 +               } else
25404 +                       goto on_hold;
25405 +       } else {
25406 +               /* put on hold? */
25407 +               if (tokens <= 0) {
25408 +                       flags |= VXSF_ONHOLD;
25409 +                       sched_pc->onhold = *norm_time;
25410 +                       goto on_hold;
25411 +               }
25412 +       }
25413 +       sched_pc->flags = flags;
25414 +       return tokens;
25415 +
25416 +on_hold:
25417 +       tokens = sched_pc->tokens_min - tokens;
25418 +       sched_pc->flags = flags;
25419 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
25420 +
25421 +#ifdef CONFIG_VSERVER_HARDCPU
25422 +       /* next interval? */
25423 +       if (!sched_pc->fill_rate[0])
25424 +               delta_min[0] = HZ;
25425 +       else if (tokens > sched_pc->fill_rate[0])
25426 +               delta_min[0] += sched_pc->interval[0] *
25427 +                       tokens / sched_pc->fill_rate[0];
25428 +       else
25429 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
25430 +       vxd_check_range(delta_min[0], 0, INT_MAX);
25431 +
25432 +#ifdef CONFIG_VSERVER_IDLETIME
25433 +       if (!(flags & VXSF_IDLE_TIME))
25434 +               return -1;
25435 +
25436 +       /* next interval? */
25437 +       if (!sched_pc->fill_rate[1])
25438 +               delta_min[1] = HZ;
25439 +       else if (tokens > sched_pc->fill_rate[1])
25440 +               delta_min[1] += sched_pc->interval[1] *
25441 +                       tokens / sched_pc->fill_rate[1];
25442 +       else
25443 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
25444 +       vxd_check_range(delta_min[1], 0, INT_MAX);
25445 +
25446 +       return -2;
25447 +#else
25448 +       return -1;
25449 +#endif /* CONFIG_VSERVER_IDLETIME */
25450 +#else
25451 +       return 0;
25452 +#endif /* CONFIG_VSERVER_HARDCPU */
25453 +}
25454 +
25455 +static inline unsigned long msec_to_ticks(unsigned long msec)
25456 +{
25457 +       return msecs_to_jiffies(msec);
25458 +}
25459 +
25460 +static inline unsigned long ticks_to_msec(unsigned long ticks)
25461 +{
25462 +       return jiffies_to_msecs(ticks);
25463 +}
25464 +
25465 +static inline unsigned long ticks_to_usec(unsigned long ticks)
25466 +{
25467 +       return jiffies_to_usecs(ticks);
25468 +}
25469 +
25470 +
25471 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
25472 +{
25473 +       unsigned int set_mask = data->mask;
25474 +       unsigned int update_mask;
25475 +       int i, cpu;
25476 +
25477 +       /* Sanity check data values */
25478 +       if (data->tokens_max <= 0)
25479 +               data->tokens_max = HZ;
25480 +       if (data->tokens_min < 0)
25481 +               data->tokens_min = HZ / 3;
25482 +       if (data->tokens_min >= data->tokens_max)
25483 +               data->tokens_min = data->tokens_max;
25484 +
25485 +       if (data->prio_bias > MAX_PRIO_BIAS)
25486 +               data->prio_bias = MAX_PRIO_BIAS;
25487 +       if (data->prio_bias < MIN_PRIO_BIAS)
25488 +               data->prio_bias = MIN_PRIO_BIAS;
25489 +
25490 +       spin_lock(&vxi->sched.tokens_lock);
25491 +
25492 +       /* sync up on delayed updates */
25493 +       for_each_cpu_mask(cpu, vxi->sched.update)
25494 +               vx_update_sched_param(&vxi->sched,
25495 +                       &vx_per_cpu(vxi, sched_pc, cpu));
25496 +
25497 +       if (set_mask & VXSM_FILL_RATE)
25498 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
25499 +       if (set_mask & VXSM_FILL_RATE2)
25500 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
25501 +       if (set_mask & VXSM_INTERVAL)
25502 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
25503 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
25504 +       if (set_mask & VXSM_INTERVAL2)
25505 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
25506 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
25507 +       if (set_mask & VXSM_TOKENS)
25508 +               vxi->sched.tokens = data->tokens;
25509 +       if (set_mask & VXSM_TOKENS_MIN)
25510 +               vxi->sched.tokens_min = data->tokens_min;
25511 +       if (set_mask & VXSM_TOKENS_MAX)
25512 +               vxi->sched.tokens_max = data->tokens_max;
25513 +       if (set_mask & VXSM_PRIO_BIAS)
25514 +               vxi->sched.prio_bias = data->prio_bias;
25515 +
25516 +       /* Sanity check rate/interval */
25517 +       for (i = 0; i < 2; i++) {
25518 +               if (data->fill_rate[i] < 0)
25519 +                       data->fill_rate[i] = 0;
25520 +               if (data->interval[i] <= 0)
25521 +                       data->interval[i] = HZ;
25522 +       }
25523 +
25524 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
25525 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
25526 +       vxi->sched.update_mask = update_mask;
25527 +
25528 +#ifdef CONFIG_SMP
25529 +       rmb();
25530 +       if (set_mask & VXSM_CPU_ID) {
25531 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
25532 +               cpus_and(vxi->sched.update, cpu_online_map,
25533 +                       vxi->sched.update);
25534 +       } else
25535 +               vxi->sched.update = cpu_online_map;
25536 +
25537 +       /* forced reload? */
25538 +       if (set_mask & VXSM_FORCE) {
25539 +               for_each_cpu_mask(cpu, vxi->sched.update)
25540 +                       vx_update_sched_param(&vxi->sched,
25541 +                               &vx_per_cpu(vxi, sched_pc, cpu));
25542 +               vxi->sched.update = CPU_MASK_NONE;
25543 +       }
25544 +#else
25545 +       /* on UP we update immediately */
25546 +       vx_update_sched_param(&vxi->sched,
25547 +               &vx_per_cpu(vxi, sched_pc, 0));
25548 +#endif
25549 +
25550 +       spin_unlock(&vxi->sched.tokens_lock);
25551 +       return 0;
25552 +}
25553 +
25554 +
25555 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
25556 +#define COPY_PRI(C) C(prio_bias)
25557 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
25558 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
25559 +                   C(fill_rate[1]); C(interval[1]);
25560 +
25561 +#define COPY_VALUE(name) vc_data.name = data->name
25562 +
25563 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
25564 +{
25565 +       struct vcmd_sched_v5 vc_data;
25566 +
25567 +       vc_data.mask = data->set_mask;
25568 +       COPY_IDS(COPY_VALUE);
25569 +       COPY_PRI(COPY_VALUE);
25570 +       COPY_TOK(COPY_VALUE);
25571 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
25572 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
25573 +       return do_set_sched(vxi, &vc_data);
25574 +}
25575 +
25576 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
25577 +{
25578 +       struct vcmd_set_sched_v4 vc_data;
25579 +
25580 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
25581 +               return -EFAULT;
25582 +
25583 +       return do_set_sched_v4(vxi, &vc_data);
25584 +}
25585 +
25586 +       /* latest interface is v5 */
25587 +
25588 +int vc_set_sched(struct vx_info *vxi, void __user *data)
25589 +{
25590 +       struct vcmd_sched_v5 vc_data;
25591 +
25592 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
25593 +               return -EFAULT;
25594 +
25595 +       return do_set_sched(vxi, &vc_data);
25596 +}
25597 +
25598 +
25599 +#define COPY_PRI(C) C(prio_bias)
25600 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
25601 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
25602 +                   C(fill_rate[1]); C(interval[1]);
25603 +
25604 +#define COPY_VALUE(name) vc_data.name = data->name
25605 +
25606 +
25607 +int vc_get_sched(struct vx_info *vxi, void __user *data)
25608 +{
25609 +       struct vcmd_sched_v5 vc_data;
25610 +
25611 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
25612 +               return -EFAULT;
25613 +
25614 +       if (vc_data.mask & VXSM_CPU_ID) {
25615 +               int cpu = vc_data.cpu_id;
25616 +               struct _vx_sched_pc *data;
25617 +
25618 +               if (!cpu_possible(cpu))
25619 +                       return -EINVAL;
25620 +
25621 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
25622 +               COPY_TOK(COPY_VALUE);
25623 +               COPY_PRI(COPY_VALUE);
25624 +               COPY_FRI(COPY_VALUE);
25625 +
25626 +               if (data->flags & VXSF_IDLE_TIME)
25627 +                       vc_data.mask |= VXSM_IDLE_TIME;
25628 +       } else {
25629 +               struct _vx_sched *data = &vxi->sched;
25630 +
25631 +               COPY_TOK(COPY_VALUE);
25632 +               COPY_PRI(COPY_VALUE);
25633 +               COPY_FRI(COPY_VALUE);
25634 +       }
25635 +
25636 +       if (vc_data.mask & VXSM_MSEC) {
25637 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
25638 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
25639 +       }
25640 +
25641 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
25642 +               return -EFAULT;
25643 +       return 0;
25644 +}
25645 +
25646 +
25647 +int vc_sched_info(struct vx_info *vxi, void __user *data)
25648 +{
25649 +       struct vcmd_sched_info vc_data;
25650 +       int cpu;
25651 +
25652 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
25653 +               return -EFAULT;
25654 +
25655 +       cpu = vc_data.cpu_id;
25656 +       if (!cpu_possible(cpu))
25657 +               return -EINVAL;
25658 +
25659 +       if (vxi) {
25660 +               struct _vx_sched_pc *sched_pc =
25661 +                       &vx_per_cpu(vxi, sched_pc, cpu);
25662 +
25663 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
25664 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
25665 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
25666 +               vc_data.vavavoom = sched_pc->vavavoom;
25667 +       }
25668 +       vc_data.token_usec = ticks_to_usec(1);
25669 +
25670 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
25671 +               return -EFAULT;
25672 +       return 0;
25673 +}
25674 +
25675 diff -NurpP --minimal linux-2.6.33/kernel/vserver/sched_init.h linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/sched_init.h
25676 --- linux-2.6.33/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
25677 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/sched_init.h    2010-02-25 12:02:16.000000000 +0100
25678 @@ -0,0 +1,50 @@
25679 +
25680 +static inline void vx_info_init_sched(struct _vx_sched *sched)
25681 +{
25682 +       static struct lock_class_key tokens_lock_key;
25683 +
25684 +       /* scheduling; hard code starting values as constants */
25685 +       sched->fill_rate[0]     = 1;
25686 +       sched->interval[0]      = 4;
25687 +       sched->fill_rate[1]     = 1;
25688 +       sched->interval[1]      = 8;
25689 +       sched->tokens           = HZ >> 2;
25690 +       sched->tokens_min       = HZ >> 4;
25691 +       sched->tokens_max       = HZ >> 1;
25692 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
25693 +       sched->prio_bias        = 0;
25694 +
25695 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
25696 +}
25697 +
25698 +static inline
25699 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
25700 +{
25701 +       sched_pc->fill_rate[0]  = 1;
25702 +       sched_pc->interval[0]   = 4;
25703 +       sched_pc->fill_rate[1]  = 1;
25704 +       sched_pc->interval[1]   = 8;
25705 +       sched_pc->tokens        = HZ >> 2;
25706 +       sched_pc->tokens_min    = HZ >> 4;
25707 +       sched_pc->tokens_max    = HZ >> 1;
25708 +       sched_pc->prio_bias     = 0;
25709 +       sched_pc->vavavoom      = 0;
25710 +       sched_pc->token_time    = 0;
25711 +       sched_pc->idle_time     = 0;
25712 +       sched_pc->norm_time     = jiffies;
25713 +
25714 +       sched_pc->user_ticks = 0;
25715 +       sched_pc->sys_ticks = 0;
25716 +       sched_pc->hold_ticks = 0;
25717 +}
25718 +
25719 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
25720 +{
25721 +       return;
25722 +}
25723 +
25724 +static inline
25725 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
25726 +{
25727 +       return;
25728 +}
25729 diff -NurpP --minimal linux-2.6.33/kernel/vserver/sched_proc.h linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/sched_proc.h
25730 --- linux-2.6.33/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
25731 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/sched_proc.h    2010-02-25 12:02:16.000000000 +0100
25732 @@ -0,0 +1,57 @@
25733 +#ifndef _VX_SCHED_PROC_H
25734 +#define _VX_SCHED_PROC_H
25735 +
25736 +
25737 +static inline
25738 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
25739 +{
25740 +       int length = 0;
25741 +
25742 +       length += sprintf(buffer,
25743 +               "FillRate:\t%8d,%d\n"
25744 +               "Interval:\t%8d,%d\n"
25745 +               "TokensMin:\t%8d\n"
25746 +               "TokensMax:\t%8d\n"
25747 +               "PrioBias:\t%8d\n",
25748 +               sched->fill_rate[0],
25749 +               sched->fill_rate[1],
25750 +               sched->interval[0],
25751 +               sched->interval[1],
25752 +               sched->tokens_min,
25753 +               sched->tokens_max,
25754 +               sched->prio_bias);
25755 +       return length;
25756 +}
25757 +
25758 +static inline
25759 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
25760 +       char *buffer, int cpu)
25761 +{
25762 +       int length = 0;
25763 +
25764 +       length += sprintf(buffer + length,
25765 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
25766 +               (unsigned long long)sched_pc->user_ticks,
25767 +               (unsigned long long)sched_pc->sys_ticks,
25768 +               (unsigned long long)sched_pc->hold_ticks,
25769 +               sched_pc->token_time,
25770 +               sched_pc->idle_time);
25771 +       length += sprintf(buffer + length,
25772 +               " %c%c %d %d %d %d/%d %d/%d",
25773 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
25774 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
25775 +               sched_pc->tokens,
25776 +               sched_pc->tokens_min,
25777 +               sched_pc->tokens_max,
25778 +               sched_pc->fill_rate[0],
25779 +               sched_pc->interval[0],
25780 +               sched_pc->fill_rate[1],
25781 +               sched_pc->interval[1]);
25782 +       length += sprintf(buffer + length,
25783 +               " %d %d\n",
25784 +               sched_pc->prio_bias,
25785 +               sched_pc->vavavoom);
25786 +       return length;
25787 +}
25788 +
25789 +#endif /* _VX_SCHED_PROC_H */
25790 diff -NurpP --minimal linux-2.6.33/kernel/vserver/signal.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/signal.c
25791 --- linux-2.6.33/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
25792 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/signal.c        2010-02-25 12:02:16.000000000 +0100
25793 @@ -0,0 +1,132 @@
25794 +/*
25795 + *  linux/kernel/vserver/signal.c
25796 + *
25797 + *  Virtual Server: Signal Support
25798 + *
25799 + *  Copyright (C) 2003-2007  Herbert Pötzl
25800 + *
25801 + *  V0.01  broken out from vcontext V0.05
25802 + *  V0.02  changed vcmds to vxi arg
25803 + *  V0.03  adjusted siginfo for kill
25804 + *
25805 + */
25806 +
25807 +#include <asm/uaccess.h>
25808 +
25809 +#include <linux/vs_context.h>
25810 +#include <linux/vs_pid.h>
25811 +#include <linux/vserver/signal_cmd.h>
25812 +
25813 +
25814 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
25815 +{
25816 +       int retval, count = 0;
25817 +       struct task_struct *p;
25818 +       struct siginfo *sip = SEND_SIG_PRIV;
25819 +
25820 +       retval = -ESRCH;
25821 +       vxdprintk(VXD_CBIT(misc, 4),
25822 +               "vx_info_kill(%p[#%d],%d,%d)*",
25823 +               vxi, vxi->vx_id, pid, sig);
25824 +       read_lock(&tasklist_lock);
25825 +       switch (pid) {
25826 +       case  0:
25827 +       case -1:
25828 +               for_each_process(p) {
25829 +                       int err = 0;
25830 +
25831 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
25832 +                               (pid && vxi->vx_initpid == p->pid))
25833 +                               continue;
25834 +
25835 +                       err = group_send_sig_info(sig, sip, p);
25836 +                       ++count;
25837 +                       if (err != -EPERM)
25838 +                               retval = err;
25839 +               }
25840 +               break;
25841 +
25842 +       case 1:
25843 +               if (vxi->vx_initpid) {
25844 +                       pid = vxi->vx_initpid;
25845 +                       /* for now, only SIGINT to private init ... */
25846 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
25847 +                               /* ... as long as there are tasks left */
25848 +                               (atomic_read(&vxi->vx_tasks) > 1))
25849 +                               sig = SIGINT;
25850 +               }
25851 +               /* fallthrough */
25852 +       default:
25853 +               p = find_task_by_real_pid(pid);
25854 +               if (p) {
25855 +                       if (vx_task_xid(p) == vxi->vx_id)
25856 +                               retval = group_send_sig_info(sig, sip, p);
25857 +               }
25858 +               break;
25859 +       }
25860 +       read_unlock(&tasklist_lock);
25861 +       vxdprintk(VXD_CBIT(misc, 4),
25862 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
25863 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
25864 +       return retval;
25865 +}
25866 +
25867 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
25868 +{
25869 +       struct vcmd_ctx_kill_v0 vc_data;
25870 +
25871 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
25872 +               return -EFAULT;
25873 +
25874 +       /* special check to allow guest shutdown */
25875 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
25876 +               /* forbid killall pid=0 when init is present */
25877 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
25878 +               (vc_data.pid > 1)))
25879 +               return -EACCES;
25880 +
25881 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
25882 +}
25883 +
25884 +
25885 +static int __wait_exit(struct vx_info *vxi)
25886 +{
25887 +       DECLARE_WAITQUEUE(wait, current);
25888 +       int ret = 0;
25889 +
25890 +       add_wait_queue(&vxi->vx_wait, &wait);
25891 +       set_current_state(TASK_INTERRUPTIBLE);
25892 +
25893 +wait:
25894 +       if (vx_info_state(vxi,
25895 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
25896 +               goto out;
25897 +       if (signal_pending(current)) {
25898 +               ret = -ERESTARTSYS;
25899 +               goto out;
25900 +       }
25901 +       schedule();
25902 +       goto wait;
25903 +
25904 +out:
25905 +       set_current_state(TASK_RUNNING);
25906 +       remove_wait_queue(&vxi->vx_wait, &wait);
25907 +       return ret;
25908 +}
25909 +
25910 +
25911 +
25912 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
25913 +{
25914 +       struct vcmd_wait_exit_v0 vc_data;
25915 +       int ret;
25916 +
25917 +       ret = __wait_exit(vxi);
25918 +       vc_data.reboot_cmd = vxi->reboot_cmd;
25919 +       vc_data.exit_code = vxi->exit_code;
25920 +
25921 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
25922 +               ret = -EFAULT;
25923 +       return ret;
25924 +}
25925 +
25926 diff -NurpP --minimal linux-2.6.33/kernel/vserver/space.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/space.c
25927 --- linux-2.6.33/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
25928 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/space.c 2010-02-25 12:02:16.000000000 +0100
25929 @@ -0,0 +1,375 @@
25930 +/*
25931 + *  linux/kernel/vserver/space.c
25932 + *
25933 + *  Virtual Server: Context Space Support
25934 + *
25935 + *  Copyright (C) 2003-2007  Herbert Pötzl
25936 + *
25937 + *  V0.01  broken out from context.c 0.07
25938 + *  V0.02  added task locking for namespace
25939 + *  V0.03  broken out vx_enter_namespace
25940 + *  V0.04  added *space support and commands
25941 + *
25942 + */
25943 +
25944 +#include <linux/utsname.h>
25945 +#include <linux/nsproxy.h>
25946 +#include <linux/err.h>
25947 +#include <linux/fs_struct.h>
25948 +#include <asm/uaccess.h>
25949 +
25950 +#include <linux/vs_context.h>
25951 +#include <linux/vserver/space.h>
25952 +#include <linux/vserver/space_cmd.h>
25953 +
25954 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
25955 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
25956 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
25957 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
25958 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
25959 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
25960 +
25961 +
25962 +/* namespace functions */
25963 +
25964 +#include <linux/mnt_namespace.h>
25965 +#include <linux/user_namespace.h>
25966 +#include <linux/pid_namespace.h>
25967 +#include <linux/ipc_namespace.h>
25968 +#include <net/net_namespace.h>
25969 +
25970 +
25971 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
25972 +       .mask = CLONE_FS |
25973 +               CLONE_NEWNS |
25974 +               CLONE_NEWUTS |
25975 +               CLONE_NEWIPC |
25976 +               CLONE_NEWUSER |
25977 +               0
25978 +};
25979 +
25980 +static const struct vcmd_space_mask_v1 space_mask = {
25981 +       .mask = CLONE_FS |
25982 +               CLONE_NEWNS |
25983 +               CLONE_NEWUTS |
25984 +               CLONE_NEWIPC |
25985 +               CLONE_NEWUSER |
25986 +#ifdef CONFIG_PID_NS
25987 +               CLONE_NEWPID |
25988 +#endif
25989 +#ifdef CONFIG_NET_NS
25990 +               CLONE_NEWNET |
25991 +#endif
25992 +               0
25993 +};
25994 +
25995 +static const struct vcmd_space_mask_v1 default_space_mask = {
25996 +       .mask = CLONE_FS |
25997 +               CLONE_NEWNS |
25998 +               CLONE_NEWUTS |
25999 +               CLONE_NEWIPC |
26000 +               CLONE_NEWUSER |
26001 +#ifdef CONFIG_PID_NS
26002 +//             CLONE_NEWPID |
26003 +#endif
26004 +               0
26005 +};
26006 +
26007 +/*
26008 + *     build a new nsproxy mix
26009 + *      assumes that both proxies are 'const'
26010 + *     does not touch nsproxy refcounts
26011 + *     will hold a reference on the result.
26012 + */
26013 +
26014 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
26015 +       struct nsproxy *new_nsproxy, unsigned long mask)
26016 +{
26017 +       struct mnt_namespace *old_ns;
26018 +       struct uts_namespace *old_uts;
26019 +       struct ipc_namespace *old_ipc;
26020 +#ifdef CONFIG_PID_NS
26021 +       struct pid_namespace *old_pid;
26022 +#endif
26023 +#ifdef CONFIG_NET_NS
26024 +       struct net *old_net;
26025 +#endif
26026 +       struct nsproxy *nsproxy;
26027 +
26028 +       nsproxy = copy_nsproxy(old_nsproxy);
26029 +       if (!nsproxy)
26030 +               goto out;
26031 +
26032 +       if (mask & CLONE_NEWNS) {
26033 +               old_ns = nsproxy->mnt_ns;
26034 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
26035 +               if (nsproxy->mnt_ns)
26036 +                       get_mnt_ns(nsproxy->mnt_ns);
26037 +       } else
26038 +               old_ns = NULL;
26039 +
26040 +       if (mask & CLONE_NEWUTS) {
26041 +               old_uts = nsproxy->uts_ns;
26042 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
26043 +               if (nsproxy->uts_ns)
26044 +                       get_uts_ns(nsproxy->uts_ns);
26045 +       } else
26046 +               old_uts = NULL;
26047 +
26048 +       if (mask & CLONE_NEWIPC) {
26049 +               old_ipc = nsproxy->ipc_ns;
26050 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
26051 +               if (nsproxy->ipc_ns)
26052 +                       get_ipc_ns(nsproxy->ipc_ns);
26053 +       } else
26054 +               old_ipc = NULL;
26055 +
26056 +#ifdef CONFIG_PID_NS
26057 +       if (mask & CLONE_NEWPID) {
26058 +               old_pid = nsproxy->pid_ns;
26059 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
26060 +               if (nsproxy->pid_ns)
26061 +                       get_pid_ns(nsproxy->pid_ns);
26062 +       } else
26063 +               old_pid = NULL;
26064 +#endif
26065 +#ifdef CONFIG_NET_NS
26066 +       if (mask & CLONE_NEWNET) {
26067 +               old_net = nsproxy->net_ns;
26068 +               nsproxy->net_ns = new_nsproxy->net_ns;
26069 +               if (nsproxy->net_ns)
26070 +                       get_net(nsproxy->net_ns);
26071 +       } else
26072 +               old_net = NULL;
26073 +#endif
26074 +       if (old_ns)
26075 +               put_mnt_ns(old_ns);
26076 +       if (old_uts)
26077 +               put_uts_ns(old_uts);
26078 +       if (old_ipc)
26079 +               put_ipc_ns(old_ipc);
26080 +#ifdef CONFIG_PID_NS
26081 +       if (old_pid)
26082 +               put_pid_ns(old_pid);
26083 +#endif
26084 +#ifdef CONFIG_NET_NS
26085 +       if (old_net)
26086 +               put_net(old_net);
26087 +#endif
26088 +out:
26089 +       return nsproxy;
26090 +}
26091 +
26092 +
26093 +/*
26094 + *     merge two nsproxy structs into a new one.
26095 + *     will hold a reference on the result.
26096 + */
26097 +
26098 +static inline
26099 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
26100 +       struct nsproxy *proxy, unsigned long mask)
26101 +{
26102 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
26103 +
26104 +       if (!proxy)
26105 +               return NULL;
26106 +
26107 +       if (mask) {
26108 +               /* vs_mix_nsproxy returns with reference */
26109 +               return vs_mix_nsproxy(old ? old : &null_proxy,
26110 +                       proxy, mask);
26111 +       }
26112 +       get_nsproxy(proxy);
26113 +       return proxy;
26114 +}
26115 +
26116 +
26117 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
26118 +{
26119 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
26120 +       struct fs_struct *fs_cur, *fs = NULL;
26121 +       int ret, kill = 0;
26122 +
26123 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
26124 +               vxi, vxi->vx_id, mask, index);
26125 +
26126 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
26127 +               return -EACCES;
26128 +
26129 +       if (!mask)
26130 +               mask = vxi->vx_nsmask[index];
26131 +
26132 +       if ((mask & vxi->vx_nsmask[index]) != mask)
26133 +               return -EINVAL;
26134 +
26135 +       if (mask & CLONE_FS) {
26136 +               fs = copy_fs_struct(vxi->vx_fs[index]);
26137 +               if (!fs)
26138 +                       return -ENOMEM;
26139 +       }
26140 +       proxy = vxi->vx_nsproxy[index];
26141 +
26142 +       vxdprintk(VXD_CBIT(space, 9),
26143 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
26144 +               vxi, vxi->vx_id, mask, index, proxy, fs);
26145 +
26146 +       task_lock(current);
26147 +       fs_cur = current->fs;
26148 +
26149 +       if (mask & CLONE_FS) {
26150 +               write_lock(&fs_cur->lock);
26151 +               current->fs = fs;
26152 +               kill = !--fs_cur->users;
26153 +               write_unlock(&fs_cur->lock);
26154 +       }
26155 +
26156 +       proxy_cur = current->nsproxy;
26157 +       get_nsproxy(proxy_cur);
26158 +       task_unlock(current);
26159 +
26160 +       if (kill)
26161 +               free_fs_struct(fs_cur);
26162 +
26163 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
26164 +       if (IS_ERR(proxy_new)) {
26165 +               ret = PTR_ERR(proxy_new);
26166 +               goto out_put;
26167 +       }
26168 +
26169 +       proxy_new = xchg(&current->nsproxy, proxy_new);
26170 +       ret = 0;
26171 +
26172 +       if (proxy_new)
26173 +               put_nsproxy(proxy_new);
26174 +out_put:
26175 +       if (proxy_cur)
26176 +               put_nsproxy(proxy_cur);
26177 +       return ret;
26178 +}
26179 +
26180 +
26181 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
26182 +{
26183 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
26184 +       struct fs_struct *fs_vxi, *fs;
26185 +       int ret, kill = 0;
26186 +
26187 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
26188 +               vxi, vxi->vx_id, mask, index);
26189 +#if 0
26190 +       if (!mask)
26191 +               mask = default_space_mask.mask;
26192 +#endif
26193 +       if ((mask & space_mask.mask) != mask)
26194 +               return -EINVAL;
26195 +
26196 +       proxy_vxi = vxi->vx_nsproxy[index];
26197 +       fs_vxi = vxi->vx_fs[index];
26198 +
26199 +       if (mask & CLONE_FS) {
26200 +               fs = copy_fs_struct(current->fs);
26201 +               if (!fs)
26202 +                       return -ENOMEM;
26203 +       }
26204 +
26205 +       task_lock(current);
26206 +
26207 +       if (mask & CLONE_FS) {
26208 +               write_lock(&fs_vxi->lock);
26209 +               vxi->vx_fs[index] = fs;
26210 +               kill = !--fs_vxi->users;
26211 +               write_unlock(&fs_vxi->lock);
26212 +       }
26213 +
26214 +       proxy_cur = current->nsproxy;
26215 +       get_nsproxy(proxy_cur);
26216 +       task_unlock(current);
26217 +
26218 +       if (kill)
26219 +               free_fs_struct(fs_vxi);
26220 +
26221 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
26222 +       if (IS_ERR(proxy_new)) {
26223 +               ret = PTR_ERR(proxy_new);
26224 +               goto out_put;
26225 +       }
26226 +
26227 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
26228 +       vxi->vx_nsmask[index] |= mask;
26229 +       ret = 0;
26230 +
26231 +       if (proxy_new)
26232 +               put_nsproxy(proxy_new);
26233 +out_put:
26234 +       if (proxy_cur)
26235 +               put_nsproxy(proxy_cur);
26236 +       return ret;
26237 +}
26238 +
26239 +
26240 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
26241 +{
26242 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
26243 +
26244 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
26245 +               return -EFAULT;
26246 +
26247 +       return vx_enter_space(vxi, vc_data.mask, 0);
26248 +}
26249 +
26250 +int vc_enter_space(struct vx_info *vxi, void __user *data)
26251 +{
26252 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
26253 +
26254 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
26255 +               return -EFAULT;
26256 +
26257 +       if (vc_data.index >= VX_SPACES)
26258 +               return -EINVAL;
26259 +
26260 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
26261 +}
26262 +
26263 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
26264 +{
26265 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
26266 +
26267 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
26268 +               return -EFAULT;
26269 +
26270 +       return vx_set_space(vxi, vc_data.mask, 0);
26271 +}
26272 +
26273 +int vc_set_space(struct vx_info *vxi, void __user *data)
26274 +{
26275 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
26276 +
26277 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
26278 +               return -EFAULT;
26279 +
26280 +       if (vc_data.index >= VX_SPACES)
26281 +               return -EINVAL;
26282 +
26283 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
26284 +}
26285 +
26286 +int vc_get_space_mask(void __user *data, int type)
26287 +{
26288 +       const struct vcmd_space_mask_v1 *mask;
26289 +
26290 +       if (type == 0)
26291 +               mask = &space_mask_v0;
26292 +       else if (type == 1)
26293 +               mask = &space_mask;
26294 +       else
26295 +               mask = &default_space_mask;
26296 +
26297 +       vxdprintk(VXD_CBIT(space, 10),
26298 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
26299 +
26300 +       if (copy_to_user(data, mask, sizeof(*mask)))
26301 +               return -EFAULT;
26302 +       return 0;
26303 +}
26304 +
26305 diff -NurpP --minimal linux-2.6.33/kernel/vserver/switch.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/switch.c
26306 --- linux-2.6.33/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
26307 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/switch.c        2010-02-25 12:02:16.000000000 +0100
26308 @@ -0,0 +1,546 @@
26309 +/*
26310 + *  linux/kernel/vserver/switch.c
26311 + *
26312 + *  Virtual Server: Syscall Switch
26313 + *
26314 + *  Copyright (C) 2003-2007  Herbert Pötzl
26315 + *
26316 + *  V0.01  syscall switch
26317 + *  V0.02  added signal to context
26318 + *  V0.03  added rlimit functions
26319 + *  V0.04  added iattr, task/xid functions
26320 + *  V0.05  added debug/history stuff
26321 + *  V0.06  added compat32 layer
26322 + *  V0.07  vcmd args and perms
26323 + *  V0.08  added status commands
26324 + *  V0.09  added tag commands
26325 + *  V0.10  added oom bias
26326 + *  V0.11  added device commands
26327 + *
26328 + */
26329 +
26330 +#include <linux/vs_context.h>
26331 +#include <linux/vs_network.h>
26332 +#include <linux/vserver/switch.h>
26333 +
26334 +#include "vci_config.h"
26335 +
26336 +
26337 +static inline
26338 +int vc_get_version(uint32_t id)
26339 +{
26340 +       return VCI_VERSION;
26341 +}
26342 +
26343 +static inline
26344 +int vc_get_vci(uint32_t id)
26345 +{
26346 +       return vci_kernel_config();
26347 +}
26348 +
26349 +#include <linux/vserver/context_cmd.h>
26350 +#include <linux/vserver/cvirt_cmd.h>
26351 +#include <linux/vserver/cacct_cmd.h>
26352 +#include <linux/vserver/limit_cmd.h>
26353 +#include <linux/vserver/network_cmd.h>
26354 +#include <linux/vserver/sched_cmd.h>
26355 +#include <linux/vserver/debug_cmd.h>
26356 +#include <linux/vserver/inode_cmd.h>
26357 +#include <linux/vserver/dlimit_cmd.h>
26358 +#include <linux/vserver/signal_cmd.h>
26359 +#include <linux/vserver/space_cmd.h>
26360 +#include <linux/vserver/tag_cmd.h>
26361 +#include <linux/vserver/device_cmd.h>
26362 +
26363 +#include <linux/vserver/inode.h>
26364 +#include <linux/vserver/dlimit.h>
26365 +
26366 +
26367 +#ifdef CONFIG_COMPAT
26368 +#define __COMPAT(name, id, data, compat)       \
26369 +       (compat) ? name ## _x32(id, data) : name(id, data)
26370 +#define __COMPAT_NO_ID(name, data, compat)     \
26371 +       (compat) ? name ## _x32(data) : name(data)
26372 +#else
26373 +#define __COMPAT(name, id, data, compat)       \
26374 +       name(id, data)
26375 +#define __COMPAT_NO_ID(name, data, compat)     \
26376 +       name(data)
26377 +#endif
26378 +
26379 +
26380 +static inline
26381 +long do_vcmd(uint32_t cmd, uint32_t id,
26382 +       struct vx_info *vxi, struct nx_info *nxi,
26383 +       void __user *data, int compat)
26384 +{
26385 +       switch (cmd) {
26386 +
26387 +       case VCMD_get_version:
26388 +               return vc_get_version(id);
26389 +       case VCMD_get_vci:
26390 +               return vc_get_vci(id);
26391 +
26392 +       case VCMD_task_xid:
26393 +               return vc_task_xid(id);
26394 +       case VCMD_vx_info:
26395 +               return vc_vx_info(vxi, data);
26396 +
26397 +       case VCMD_task_nid:
26398 +               return vc_task_nid(id);
26399 +       case VCMD_nx_info:
26400 +               return vc_nx_info(nxi, data);
26401 +
26402 +       case VCMD_task_tag:
26403 +               return vc_task_tag(id);
26404 +
26405 +       case VCMD_set_space_v1:
26406 +               return vc_set_space_v1(vxi, data);
26407 +       /* this is version 2 */
26408 +       case VCMD_set_space:
26409 +               return vc_set_space(vxi, data);
26410 +
26411 +       case VCMD_get_space_mask_v0:
26412 +               return vc_get_space_mask(data, 0);
26413 +       /* this is version 1 */
26414 +       case VCMD_get_space_mask:
26415 +               return vc_get_space_mask(data, 1);
26416 +
26417 +       case VCMD_get_space_default:
26418 +               return vc_get_space_mask(data, -1);
26419 +
26420 +#ifdef CONFIG_IA32_EMULATION
26421 +       case VCMD_get_rlimit:
26422 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
26423 +       case VCMD_set_rlimit:
26424 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
26425 +#else
26426 +       case VCMD_get_rlimit:
26427 +               return vc_get_rlimit(vxi, data);
26428 +       case VCMD_set_rlimit:
26429 +               return vc_set_rlimit(vxi, data);
26430 +#endif
26431 +       case VCMD_get_rlimit_mask:
26432 +               return vc_get_rlimit_mask(id, data);
26433 +       case VCMD_reset_hits:
26434 +               return vc_reset_hits(vxi, data);
26435 +       case VCMD_reset_minmax:
26436 +               return vc_reset_minmax(vxi, data);
26437 +
26438 +       case VCMD_get_vhi_name:
26439 +               return vc_get_vhi_name(vxi, data);
26440 +       case VCMD_set_vhi_name:
26441 +               return vc_set_vhi_name(vxi, data);
26442 +
26443 +       case VCMD_ctx_stat:
26444 +               return vc_ctx_stat(vxi, data);
26445 +       case VCMD_virt_stat:
26446 +               return vc_virt_stat(vxi, data);
26447 +       case VCMD_sock_stat:
26448 +               return vc_sock_stat(vxi, data);
26449 +       case VCMD_rlimit_stat:
26450 +               return vc_rlimit_stat(vxi, data);
26451 +
26452 +       case VCMD_set_cflags:
26453 +               return vc_set_cflags(vxi, data);
26454 +       case VCMD_get_cflags:
26455 +               return vc_get_cflags(vxi, data);
26456 +
26457 +       /* this is version 1 */
26458 +       case VCMD_set_ccaps:
26459 +               return vc_set_ccaps(vxi, data);
26460 +       /* this is version 1 */
26461 +       case VCMD_get_ccaps:
26462 +               return vc_get_ccaps(vxi, data);
26463 +       case VCMD_set_bcaps:
26464 +               return vc_set_bcaps(vxi, data);
26465 +       case VCMD_get_bcaps:
26466 +               return vc_get_bcaps(vxi, data);
26467 +
26468 +       case VCMD_set_badness:
26469 +               return vc_set_badness(vxi, data);
26470 +       case VCMD_get_badness:
26471 +               return vc_get_badness(vxi, data);
26472 +
26473 +       case VCMD_set_nflags:
26474 +               return vc_set_nflags(nxi, data);
26475 +       case VCMD_get_nflags:
26476 +               return vc_get_nflags(nxi, data);
26477 +
26478 +       case VCMD_set_ncaps:
26479 +               return vc_set_ncaps(nxi, data);
26480 +       case VCMD_get_ncaps:
26481 +               return vc_get_ncaps(nxi, data);
26482 +
26483 +       case VCMD_set_sched_v4:
26484 +               return vc_set_sched_v4(vxi, data);
26485 +       /* this is version 5 */
26486 +       case VCMD_set_sched:
26487 +               return vc_set_sched(vxi, data);
26488 +       case VCMD_get_sched:
26489 +               return vc_get_sched(vxi, data);
26490 +       case VCMD_sched_info:
26491 +               return vc_sched_info(vxi, data);
26492 +
26493 +       case VCMD_add_dlimit:
26494 +               return __COMPAT(vc_add_dlimit, id, data, compat);
26495 +       case VCMD_rem_dlimit:
26496 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
26497 +       case VCMD_set_dlimit:
26498 +               return __COMPAT(vc_set_dlimit, id, data, compat);
26499 +       case VCMD_get_dlimit:
26500 +               return __COMPAT(vc_get_dlimit, id, data, compat);
26501 +
26502 +       case VCMD_ctx_kill:
26503 +               return vc_ctx_kill(vxi, data);
26504 +
26505 +       case VCMD_wait_exit:
26506 +               return vc_wait_exit(vxi, data);
26507 +
26508 +       case VCMD_get_iattr:
26509 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
26510 +       case VCMD_set_iattr:
26511 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
26512 +
26513 +       case VCMD_fget_iattr:
26514 +               return vc_fget_iattr(id, data);
26515 +       case VCMD_fset_iattr:
26516 +               return vc_fset_iattr(id, data);
26517 +
26518 +       case VCMD_enter_space_v0:
26519 +               return vc_enter_space_v1(vxi, NULL);
26520 +       case VCMD_enter_space_v1:
26521 +               return vc_enter_space_v1(vxi, data);
26522 +       /* this is version 2 */
26523 +       case VCMD_enter_space:
26524 +               return vc_enter_space(vxi, data);
26525 +
26526 +       case VCMD_ctx_create_v0:
26527 +               return vc_ctx_create(id, NULL);
26528 +       case VCMD_ctx_create:
26529 +               return vc_ctx_create(id, data);
26530 +       case VCMD_ctx_migrate_v0:
26531 +               return vc_ctx_migrate(vxi, NULL);
26532 +       case VCMD_ctx_migrate:
26533 +               return vc_ctx_migrate(vxi, data);
26534 +
26535 +       case VCMD_net_create_v0:
26536 +               return vc_net_create(id, NULL);
26537 +       case VCMD_net_create:
26538 +               return vc_net_create(id, data);
26539 +       case VCMD_net_migrate:
26540 +               return vc_net_migrate(nxi, data);
26541 +
26542 +       case VCMD_tag_migrate:
26543 +               return vc_tag_migrate(id);
26544 +
26545 +       case VCMD_net_add:
26546 +               return vc_net_add(nxi, data);
26547 +       case VCMD_net_remove:
26548 +               return vc_net_remove(nxi, data);
26549 +
26550 +       case VCMD_net_add_ipv4:
26551 +               return vc_net_add_ipv4(nxi, data);
26552 +       case VCMD_net_remove_ipv4:
26553 +               return vc_net_remove_ipv4(nxi, data);
26554 +#ifdef CONFIG_IPV6
26555 +       case VCMD_net_add_ipv6:
26556 +               return vc_net_add_ipv6(nxi, data);
26557 +       case VCMD_net_remove_ipv6:
26558 +               return vc_net_remove_ipv6(nxi, data);
26559 +#endif
26560 +/*     case VCMD_add_match_ipv4:
26561 +               return vc_add_match_ipv4(nxi, data);
26562 +       case VCMD_get_match_ipv4:
26563 +               return vc_get_match_ipv4(nxi, data);
26564 +#ifdef CONFIG_IPV6
26565 +       case VCMD_add_match_ipv6:
26566 +               return vc_add_match_ipv6(nxi, data);
26567 +       case VCMD_get_match_ipv6:
26568 +               return vc_get_match_ipv6(nxi, data);
26569 +#endif */
26570 +
26571 +#ifdef CONFIG_VSERVER_DEVICE
26572 +       case VCMD_set_mapping:
26573 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
26574 +       case VCMD_unset_mapping:
26575 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
26576 +#endif
26577 +#ifdef CONFIG_VSERVER_HISTORY
26578 +       case VCMD_dump_history:
26579 +               return vc_dump_history(id);
26580 +       case VCMD_read_history:
26581 +               return __COMPAT(vc_read_history, id, data, compat);
26582 +#endif
26583 +#ifdef CONFIG_VSERVER_MONITOR
26584 +       case VCMD_read_monitor:
26585 +               return __COMPAT(vc_read_monitor, id, data, compat);
26586 +#endif
26587 +       default:
26588 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
26589 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
26590 +       }
26591 +       return -ENOSYS;
26592 +}
26593 +
26594 +
26595 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
26596 +       case VCMD_ ## vcmd: perm = _perm;               \
26597 +               args = _args; flags = _flags; break
26598 +
26599 +
26600 +#define VCA_NONE       0x00
26601 +#define VCA_VXI                0x01
26602 +#define VCA_NXI                0x02
26603 +
26604 +#define VCF_NONE       0x00
26605 +#define VCF_INFO       0x01
26606 +#define VCF_ADMIN      0x02
26607 +#define VCF_ARES       0x06    /* includes admin */
26608 +#define VCF_SETUP      0x08
26609 +
26610 +#define VCF_ZIDOK      0x10    /* zero id okay */
26611 +
26612 +
26613 +static inline
26614 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
26615 +{
26616 +       long ret;
26617 +       int permit = -1, state = 0;
26618 +       int perm = -1, args = 0, flags = 0;
26619 +       struct vx_info *vxi = NULL;
26620 +       struct nx_info *nxi = NULL;
26621 +
26622 +       switch (cmd) {
26623 +       /* unpriviledged commands */
26624 +       __VCMD(get_version,      0, VCA_NONE,   0);
26625 +       __VCMD(get_vci,          0, VCA_NONE,   0);
26626 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
26627 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
26628 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
26629 +       __VCMD(get_space_default,0, VCA_NONE,   0);
26630 +
26631 +       /* info commands */
26632 +       __VCMD(task_xid,         2, VCA_NONE,   0);
26633 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
26634 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
26635 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
26636 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
26637 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
26638 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
26639 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
26640 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
26641 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
26642 +
26643 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
26644 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
26645 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
26646 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
26647 +
26648 +       __VCMD(task_nid,         2, VCA_NONE,   0);
26649 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
26650 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
26651 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
26652 +
26653 +       __VCMD(task_tag,         2, VCA_NONE,   0);
26654 +
26655 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
26656 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
26657 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
26658 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
26659 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
26660 +
26661 +       /* lower admin commands */
26662 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
26663 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
26664 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
26665 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
26666 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
26667 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
26668 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
26669 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
26670 +
26671 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
26672 +       __VCMD(net_create,       5, VCA_NONE,   0);
26673 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
26674 +
26675 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
26676 +
26677 +       /* higher admin commands */
26678 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
26679 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
26680 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
26681 +
26682 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
26683 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
26684 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
26685 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
26686 +
26687 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
26688 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
26689 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
26690 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
26691 +
26692 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
26693 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
26694 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
26695 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
26696 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
26697 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
26698 +#ifdef CONFIG_IPV6
26699 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
26700 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
26701 +#endif
26702 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
26703 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
26704 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
26705 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
26706 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
26707 +
26708 +#ifdef CONFIG_VSERVER_DEVICE
26709 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
26710 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
26711 +#endif
26712 +       /* debug level admin commands */
26713 +#ifdef CONFIG_VSERVER_HISTORY
26714 +       __VCMD(dump_history,     9, VCA_NONE,   0);
26715 +       __VCMD(read_history,     9, VCA_NONE,   0);
26716 +#endif
26717 +#ifdef CONFIG_VSERVER_MONITOR
26718 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
26719 +#endif
26720 +
26721 +       default:
26722 +               perm = -1;
26723 +       }
26724 +
26725 +       vxdprintk(VXD_CBIT(switch, 0),
26726 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
26727 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
26728 +               VC_VERSION(cmd), id, data, compat,
26729 +               perm, args, flags);
26730 +
26731 +       ret = -ENOSYS;
26732 +       if (perm < 0)
26733 +               goto out;
26734 +
26735 +       state = 1;
26736 +       if (!capable(CAP_CONTEXT))
26737 +               goto out;
26738 +
26739 +       state = 2;
26740 +       /* moved here from the individual commands */
26741 +       ret = -EPERM;
26742 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
26743 +               goto out;
26744 +
26745 +       state = 3;
26746 +       /* vcmd involves resource management  */
26747 +       ret = -EPERM;
26748 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
26749 +               goto out;
26750 +
26751 +       state = 4;
26752 +       /* various legacy exceptions */
26753 +       switch (cmd) {
26754 +       /* will go away when spectator is a cap */
26755 +       case VCMD_ctx_migrate_v0:
26756 +       case VCMD_ctx_migrate:
26757 +               if (id == 1) {
26758 +                       current->xid = 1;
26759 +                       ret = 1;
26760 +                       goto out;
26761 +               }
26762 +               break;
26763 +
26764 +       /* will go away when spectator is a cap */
26765 +       case VCMD_net_migrate:
26766 +               if (id == 1) {
26767 +                       current->nid = 1;
26768 +                       ret = 1;
26769 +                       goto out;
26770 +               }
26771 +               break;
26772 +       }
26773 +
26774 +       /* vcmds are fine by default */
26775 +       permit = 1;
26776 +
26777 +       /* admin type vcmds require admin ... */
26778 +       if (flags & VCF_ADMIN)
26779 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
26780 +
26781 +       /* ... but setup type vcmds override that */
26782 +       if (!permit && (flags & VCF_SETUP))
26783 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
26784 +
26785 +       state = 5;
26786 +       ret = -EPERM;
26787 +       if (!permit)
26788 +               goto out;
26789 +
26790 +       state = 6;
26791 +       if (!id && (flags & VCF_ZIDOK))
26792 +               goto skip_id;
26793 +
26794 +       ret = -ESRCH;
26795 +       if (args & VCA_VXI) {
26796 +               vxi = lookup_vx_info(id);
26797 +               if (!vxi)
26798 +                       goto out;
26799 +
26800 +               if ((flags & VCF_ADMIN) &&
26801 +                       /* special case kill for shutdown */
26802 +                       (cmd != VCMD_ctx_kill) &&
26803 +                       /* can context be administrated? */
26804 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
26805 +                       ret = -EACCES;
26806 +                       goto out_vxi;
26807 +               }
26808 +       }
26809 +       state = 7;
26810 +       if (args & VCA_NXI) {
26811 +               nxi = lookup_nx_info(id);
26812 +               if (!nxi)
26813 +                       goto out_vxi;
26814 +
26815 +               if ((flags & VCF_ADMIN) &&
26816 +                       /* can context be administrated? */
26817 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
26818 +                       ret = -EACCES;
26819 +                       goto out_nxi;
26820 +               }
26821 +       }
26822 +skip_id:
26823 +       state = 8;
26824 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
26825 +
26826 +out_nxi:
26827 +       if ((args & VCA_NXI) && nxi)
26828 +               put_nx_info(nxi);
26829 +out_vxi:
26830 +       if ((args & VCA_VXI) && vxi)
26831 +               put_vx_info(vxi);
26832 +out:
26833 +       vxdprintk(VXD_CBIT(switch, 1),
26834 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
26835 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
26836 +               VC_VERSION(cmd), ret, ret, state, permit);
26837 +       return ret;
26838 +}
26839 +
26840 +asmlinkage long
26841 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
26842 +{
26843 +       return do_vserver(cmd, id, data, 0);
26844 +}
26845 +
26846 +#ifdef CONFIG_COMPAT
26847 +
26848 +asmlinkage long
26849 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
26850 +{
26851 +       return do_vserver(cmd, id, data, 1);
26852 +}
26853 +
26854 +#endif /* CONFIG_COMPAT */
26855 diff -NurpP --minimal linux-2.6.33/kernel/vserver/sysctl.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/sysctl.c
26856 --- linux-2.6.33/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
26857 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/sysctl.c        2010-02-25 15:14:16.000000000 +0100
26858 @@ -0,0 +1,241 @@
26859 +/*
26860 + *  kernel/vserver/sysctl.c
26861 + *
26862 + *  Virtual Context Support
26863 + *
26864 + *  Copyright (C) 2004-2007  Herbert Pötzl
26865 + *
26866 + *  V0.01  basic structure
26867 + *
26868 + */
26869 +
26870 +#include <linux/module.h>
26871 +#include <linux/ctype.h>
26872 +#include <linux/sysctl.h>
26873 +#include <linux/parser.h>
26874 +#include <asm/uaccess.h>
26875 +
26876 +enum {
26877 +       CTL_DEBUG_ERROR         = 0,
26878 +       CTL_DEBUG_SWITCH        = 1,
26879 +       CTL_DEBUG_XID,
26880 +       CTL_DEBUG_NID,
26881 +       CTL_DEBUG_TAG,
26882 +       CTL_DEBUG_NET,
26883 +       CTL_DEBUG_LIMIT,
26884 +       CTL_DEBUG_CRES,
26885 +       CTL_DEBUG_DLIM,
26886 +       CTL_DEBUG_QUOTA,
26887 +       CTL_DEBUG_CVIRT,
26888 +       CTL_DEBUG_SPACE,
26889 +       CTL_DEBUG_MISC,
26890 +};
26891 +
26892 +
26893 +unsigned int vx_debug_switch   = 0;
26894 +unsigned int vx_debug_xid      = 0;
26895 +unsigned int vx_debug_nid      = 0;
26896 +unsigned int vx_debug_tag      = 0;
26897 +unsigned int vx_debug_net      = 0;
26898 +unsigned int vx_debug_limit    = 0;
26899 +unsigned int vx_debug_cres     = 0;
26900 +unsigned int vx_debug_dlim     = 0;
26901 +unsigned int vx_debug_quota    = 0;
26902 +unsigned int vx_debug_cvirt    = 0;
26903 +unsigned int vx_debug_space    = 0;
26904 +unsigned int vx_debug_misc     = 0;
26905 +
26906 +
26907 +static struct ctl_table_header *vserver_table_header;
26908 +static ctl_table vserver_root_table[];
26909 +
26910 +
26911 +void vserver_register_sysctl(void)
26912 +{
26913 +       if (!vserver_table_header) {
26914 +               vserver_table_header = register_sysctl_table(vserver_root_table);
26915 +       }
26916 +
26917 +}
26918 +
26919 +void vserver_unregister_sysctl(void)
26920 +{
26921 +       if (vserver_table_header) {
26922 +               unregister_sysctl_table(vserver_table_header);
26923 +               vserver_table_header = NULL;
26924 +       }
26925 +}
26926 +
26927 +
26928 +static int proc_dodebug(ctl_table *table, int write,
26929 +       void __user *buffer, size_t *lenp, loff_t *ppos)
26930 +{
26931 +       char            tmpbuf[20], *p, c;
26932 +       unsigned int    value;
26933 +       size_t          left, len;
26934 +
26935 +       if ((*ppos && !write) || !*lenp) {
26936 +               *lenp = 0;
26937 +               return 0;
26938 +       }
26939 +
26940 +       left = *lenp;
26941 +
26942 +       if (write) {
26943 +               if (!access_ok(VERIFY_READ, buffer, left))
26944 +                       return -EFAULT;
26945 +               p = (char *)buffer;
26946 +               while (left && __get_user(c, p) >= 0 && isspace(c))
26947 +                       left--, p++;
26948 +               if (!left)
26949 +                       goto done;
26950 +
26951 +               if (left > sizeof(tmpbuf) - 1)
26952 +                       return -EINVAL;
26953 +               if (copy_from_user(tmpbuf, p, left))
26954 +                       return -EFAULT;
26955 +               tmpbuf[left] = '\0';
26956 +
26957 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
26958 +                       value = 10 * value + (*p - '0');
26959 +               if (*p && !isspace(*p))
26960 +                       return -EINVAL;
26961 +               while (left && isspace(*p))
26962 +                       left--, p++;
26963 +               *(unsigned int *)table->data = value;
26964 +       } else {
26965 +               if (!access_ok(VERIFY_WRITE, buffer, left))
26966 +                       return -EFAULT;
26967 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
26968 +               if (len > left)
26969 +                       len = left;
26970 +               if (__copy_to_user(buffer, tmpbuf, len))
26971 +                       return -EFAULT;
26972 +               if ((left -= len) > 0) {
26973 +                       if (put_user('\n', (char *)buffer + len))
26974 +                               return -EFAULT;
26975 +                       left--;
26976 +               }
26977 +       }
26978 +
26979 +done:
26980 +       *lenp -= left;
26981 +       *ppos += *lenp;
26982 +       return 0;
26983 +}
26984 +
26985 +static int zero;
26986 +
26987 +#define        CTL_ENTRY(ctl, name)                            \
26988 +       {                                               \
26989 +               .procname       = #name,                \
26990 +               .data           = &vx_ ## name,         \
26991 +               .maxlen         = sizeof(int),          \
26992 +               .mode           = 0644,                 \
26993 +               .proc_handler   = &proc_dodebug,        \
26994 +               .extra1         = &zero,                \
26995 +               .extra2         = &zero,                \
26996 +       }
26997 +
26998 +static ctl_table vserver_debug_table[] = {
26999 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
27000 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
27001 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
27002 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
27003 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
27004 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
27005 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
27006 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
27007 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
27008 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
27009 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
27010 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
27011 +       { 0 }
27012 +};
27013 +
27014 +static ctl_table vserver_root_table[] = {
27015 +       {
27016 +               .procname       = "vserver",
27017 +               .mode           = 0555,
27018 +               .child          = vserver_debug_table
27019 +       },
27020 +       { 0 }
27021 +};
27022 +
27023 +
27024 +static match_table_t tokens = {
27025 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
27026 +       { CTL_DEBUG_XID,        "xid=%x"        },
27027 +       { CTL_DEBUG_NID,        "nid=%x"        },
27028 +       { CTL_DEBUG_TAG,        "tag=%x"        },
27029 +       { CTL_DEBUG_NET,        "net=%x"        },
27030 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
27031 +       { CTL_DEBUG_CRES,       "cres=%x"       },
27032 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
27033 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
27034 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
27035 +       { CTL_DEBUG_SPACE,      "space=%x"      },
27036 +       { CTL_DEBUG_MISC,       "misc=%x"       },
27037 +       { CTL_DEBUG_ERROR,      NULL            }
27038 +};
27039 +
27040 +#define        HANDLE_CASE(id, name, val)                              \
27041 +       case CTL_DEBUG_ ## id:                                  \
27042 +               vx_debug_ ## name = val;                        \
27043 +               printk("vs_debug_" #name "=0x%x\n", val);       \
27044 +               break
27045 +
27046 +
27047 +static int __init vs_debug_setup(char *str)
27048 +{
27049 +       char *p;
27050 +       int token;
27051 +
27052 +       printk("vs_debug_setup(%s)\n", str);
27053 +       while ((p = strsep(&str, ",")) != NULL) {
27054 +               substring_t args[MAX_OPT_ARGS];
27055 +               unsigned int value;
27056 +
27057 +               if (!*p)
27058 +                       continue;
27059 +
27060 +               token = match_token(p, tokens, args);
27061 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
27062 +
27063 +               switch (token) {
27064 +               HANDLE_CASE(SWITCH, switch, value);
27065 +               HANDLE_CASE(XID,    xid,    value);
27066 +               HANDLE_CASE(NID,    nid,    value);
27067 +               HANDLE_CASE(TAG,    tag,    value);
27068 +               HANDLE_CASE(NET,    net,    value);
27069 +               HANDLE_CASE(LIMIT,  limit,  value);
27070 +               HANDLE_CASE(CRES,   cres,   value);
27071 +               HANDLE_CASE(DLIM,   dlim,   value);
27072 +               HANDLE_CASE(QUOTA,  quota,  value);
27073 +               HANDLE_CASE(CVIRT,  cvirt,  value);
27074 +               HANDLE_CASE(SPACE,  space,  value);
27075 +               HANDLE_CASE(MISC,   misc,   value);
27076 +               default:
27077 +                       return -EINVAL;
27078 +                       break;
27079 +               }
27080 +       }
27081 +       return 1;
27082 +}
27083 +
27084 +__setup("vsdebug=", vs_debug_setup);
27085 +
27086 +
27087 +
27088 +EXPORT_SYMBOL_GPL(vx_debug_switch);
27089 +EXPORT_SYMBOL_GPL(vx_debug_xid);
27090 +EXPORT_SYMBOL_GPL(vx_debug_nid);
27091 +EXPORT_SYMBOL_GPL(vx_debug_net);
27092 +EXPORT_SYMBOL_GPL(vx_debug_limit);
27093 +EXPORT_SYMBOL_GPL(vx_debug_cres);
27094 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
27095 +EXPORT_SYMBOL_GPL(vx_debug_quota);
27096 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
27097 +EXPORT_SYMBOL_GPL(vx_debug_space);
27098 +EXPORT_SYMBOL_GPL(vx_debug_misc);
27099 +
27100 diff -NurpP --minimal linux-2.6.33/kernel/vserver/tag.c linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/tag.c
27101 --- linux-2.6.33/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
27102 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/tag.c   2010-02-25 12:02:16.000000000 +0100
27103 @@ -0,0 +1,63 @@
27104 +/*
27105 + *  linux/kernel/vserver/tag.c
27106 + *
27107 + *  Virtual Server: Shallow Tag Space
27108 + *
27109 + *  Copyright (C) 2007  Herbert Pötzl
27110 + *
27111 + *  V0.01  basic implementation
27112 + *
27113 + */
27114 +
27115 +#include <linux/sched.h>
27116 +#include <linux/vserver/debug.h>
27117 +#include <linux/vs_pid.h>
27118 +#include <linux/vs_tag.h>
27119 +
27120 +#include <linux/vserver/tag_cmd.h>
27121 +
27122 +
27123 +int dx_migrate_task(struct task_struct *p, tag_t tag)
27124 +{
27125 +       if (!p)
27126 +               BUG();
27127 +
27128 +       vxdprintk(VXD_CBIT(tag, 5),
27129 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
27130 +
27131 +       task_lock(p);
27132 +       p->tag = tag;
27133 +       task_unlock(p);
27134 +
27135 +       vxdprintk(VXD_CBIT(tag, 5),
27136 +               "moved task %p into [#%d]", p, tag);
27137 +       return 0;
27138 +}
27139 +
27140 +/* vserver syscall commands below here */
27141 +
27142 +/* taks xid and vx_info functions */
27143 +
27144 +
27145 +int vc_task_tag(uint32_t id)
27146 +{
27147 +       tag_t tag;
27148 +
27149 +       if (id) {
27150 +               struct task_struct *tsk;
27151 +               read_lock(&tasklist_lock);
27152 +               tsk = find_task_by_real_pid(id);
27153 +               tag = (tsk) ? tsk->tag : -ESRCH;
27154 +               read_unlock(&tasklist_lock);
27155 +       } else
27156 +               tag = dx_current_tag();
27157 +       return tag;
27158 +}
27159 +
27160 +
27161 +int vc_tag_migrate(uint32_t tag)
27162 +{
27163 +       return dx_migrate_task(current, tag & 0xFFFF);
27164 +}
27165 +
27166 +
27167 diff -NurpP --minimal linux-2.6.33/kernel/vserver/vci_config.h linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/vci_config.h
27168 --- linux-2.6.33/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
27169 +++ linux-2.6.33-vs2.3.0.36.30.1/kernel/vserver/vci_config.h    2010-02-25 12:02:16.000000000 +0100
27170 @@ -0,0 +1,81 @@
27171 +
27172 +/*  interface version */
27173 +
27174 +#define VCI_VERSION            0x00020305
27175 +
27176 +
27177 +enum {
27178 +       VCI_KCBIT_NO_DYNAMIC = 0,
27179 +
27180 +       VCI_KCBIT_PROC_SECURE = 4,
27181 +       VCI_KCBIT_HARDCPU = 5,
27182 +       VCI_KCBIT_IDLELIMIT = 6,
27183 +       VCI_KCBIT_IDLETIME = 7,
27184 +
27185 +       VCI_KCBIT_COWBL = 8,
27186 +       VCI_KCBIT_FULLCOWBL = 9,
27187 +       VCI_KCBIT_SPACES = 10,
27188 +       VCI_KCBIT_NETV2 = 11,
27189 +
27190 +       VCI_KCBIT_DEBUG = 16,
27191 +       VCI_KCBIT_HISTORY = 20,
27192 +       VCI_KCBIT_TAGGED = 24,
27193 +       VCI_KCBIT_PPTAG = 28,
27194 +
27195 +       VCI_KCBIT_MORE = 31,
27196 +};
27197 +
27198 +
27199 +static inline uint32_t vci_kernel_config(void)
27200 +{
27201 +       return
27202 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
27203 +
27204 +       /* configured features */
27205 +#ifdef CONFIG_VSERVER_PROC_SECURE
27206 +       (1 << VCI_KCBIT_PROC_SECURE) |
27207 +#endif
27208 +#ifdef CONFIG_VSERVER_HARDCPU
27209 +       (1 << VCI_KCBIT_HARDCPU) |
27210 +#endif
27211 +#ifdef CONFIG_VSERVER_IDLELIMIT
27212 +       (1 << VCI_KCBIT_IDLELIMIT) |
27213 +#endif
27214 +#ifdef CONFIG_VSERVER_IDLETIME
27215 +       (1 << VCI_KCBIT_IDLETIME) |
27216 +#endif
27217 +#ifdef CONFIG_VSERVER_COWBL
27218 +       (1 << VCI_KCBIT_COWBL) |
27219 +       (1 << VCI_KCBIT_FULLCOWBL) |
27220 +#endif
27221 +       (1 << VCI_KCBIT_SPACES) |
27222 +       (1 << VCI_KCBIT_NETV2) |
27223 +
27224 +       /* debug options */
27225 +#ifdef CONFIG_VSERVER_DEBUG
27226 +       (1 << VCI_KCBIT_DEBUG) |
27227 +#endif
27228 +#ifdef CONFIG_VSERVER_HISTORY
27229 +       (1 << VCI_KCBIT_HISTORY) |
27230 +#endif
27231 +
27232 +       /* inode context tagging */
27233 +#if    defined(CONFIG_TAGGING_NONE)
27234 +       (0 << VCI_KCBIT_TAGGED) |
27235 +#elif  defined(CONFIG_TAGGING_UID16)
27236 +       (1 << VCI_KCBIT_TAGGED) |
27237 +#elif  defined(CONFIG_TAGGING_GID16)
27238 +       (2 << VCI_KCBIT_TAGGED) |
27239 +#elif  defined(CONFIG_TAGGING_ID24)
27240 +       (3 << VCI_KCBIT_TAGGED) |
27241 +#elif  defined(CONFIG_TAGGING_INTERN)
27242 +       (4 << VCI_KCBIT_TAGGED) |
27243 +#elif  defined(CONFIG_TAGGING_RUNTIME)
27244 +       (5 << VCI_KCBIT_TAGGED) |
27245 +#else
27246 +       (7 << VCI_KCBIT_TAGGED) |
27247 +#endif
27248 +       (1 << VCI_KCBIT_PPTAG) |
27249 +       0;
27250 +}
27251 +
27252 diff -NurpP --minimal linux-2.6.33/mm/filemap_xip.c linux-2.6.33-vs2.3.0.36.30.1/mm/filemap_xip.c
27253 --- linux-2.6.33/mm/filemap_xip.c       2009-12-03 20:02:58.000000000 +0100
27254 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/filemap_xip.c       2010-02-25 12:02:16.000000000 +0100
27255 @@ -17,6 +17,7 @@
27256  #include <linux/sched.h>
27257  #include <linux/seqlock.h>
27258  #include <linux/mutex.h>
27259 +#include <linux/vs_memory.h>
27260  #include <asm/tlbflush.h>
27261  #include <asm/io.h>
27262  
27263 diff -NurpP --minimal linux-2.6.33/mm/fremap.c linux-2.6.33-vs2.3.0.36.30.1/mm/fremap.c
27264 --- linux-2.6.33/mm/fremap.c    2009-03-24 14:22:45.000000000 +0100
27265 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/fremap.c    2010-02-25 12:02:16.000000000 +0100
27266 @@ -16,6 +16,7 @@
27267  #include <linux/module.h>
27268  #include <linux/syscalls.h>
27269  #include <linux/mmu_notifier.h>
27270 +#include <linux/vs_memory.h>
27271  
27272  #include <asm/mmu_context.h>
27273  #include <asm/cacheflush.h>
27274 diff -NurpP --minimal linux-2.6.33/mm/hugetlb.c linux-2.6.33-vs2.3.0.36.30.1/mm/hugetlb.c
27275 --- linux-2.6.33/mm/hugetlb.c   2010-02-25 11:52:09.000000000 +0100
27276 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/hugetlb.c   2010-02-25 12:16:11.000000000 +0100
27277 @@ -25,6 +25,7 @@
27278  
27279  #include <linux/hugetlb.h>
27280  #include <linux/node.h>
27281 +#include <linux/vs_memory.h>
27282  #include "internal.h"
27283  
27284  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
27285 diff -NurpP --minimal linux-2.6.33/mm/memcontrol.c linux-2.6.33-vs2.3.0.36.30.1/mm/memcontrol.c
27286 --- linux-2.6.33/mm/memcontrol.c        2010-02-25 11:52:09.000000000 +0100
27287 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/memcontrol.c        2010-02-26 10:04:15.000000000 +0100
27288 @@ -555,6 +555,31 @@ struct mem_cgroup *mem_cgroup_from_task(
27289                                 struct mem_cgroup, css);
27290  }
27291  
27292 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
27293 +{
27294 +       return res_counter_read_u64(&mem->res, member);
27295 +}
27296 +
27297 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
27298 +{
27299 +       return res_counter_read_u64(&mem->memsw, member);
27300 +}
27301 +
27302 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
27303 +{
27304 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_CACHE);
27305 +}
27306 +
27307 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
27308 +{
27309 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_RSS);
27310 +}
27311 +
27312 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
27313 +{
27314 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_FILE_MAPPED);
27315 +}
27316 +
27317  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
27318  {
27319         struct mem_cgroup *mem = NULL;
27320 diff -NurpP --minimal linux-2.6.33/mm/memory.c linux-2.6.33-vs2.3.0.36.30.1/mm/memory.c
27321 --- linux-2.6.33/mm/memory.c    2010-02-25 11:52:09.000000000 +0100
27322 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/memory.c    2010-02-25 12:02:16.000000000 +0100
27323 @@ -56,6 +56,7 @@
27324  #include <linux/kallsyms.h>
27325  #include <linux/swapops.h>
27326  #include <linux/elf.h>
27327 +// #include <linux/vs_memory.h>
27328  
27329  #include <asm/io.h>
27330  #include <asm/pgalloc.h>
27331 @@ -651,6 +652,9 @@ static int copy_pte_range(struct mm_stru
27332         int rss[2];
27333         swp_entry_t entry = (swp_entry_t){0};
27334  
27335 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
27336 +               return -ENOMEM;
27337 +
27338  again:
27339         rss[1] = rss[0] = 0;
27340         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
27341 @@ -2670,6 +2674,8 @@ static int do_anonymous_page(struct mm_s
27342         /* Allocate our own private page. */
27343         pte_unmap(page_table);
27344  
27345 +       if (!vx_rss_avail(mm, 1))
27346 +               goto oom;
27347         if (unlikely(anon_vma_prepare(vma)))
27348                 goto oom;
27349         page = alloc_zeroed_user_highpage_movable(vma, address);
27350 @@ -2961,6 +2967,7 @@ static inline int handle_pte_fault(struc
27351  {
27352         pte_t entry;
27353         spinlock_t *ptl;
27354 +       int ret = 0, type = VXPT_UNKNOWN;
27355  
27356         entry = *pte;
27357         if (!pte_present(entry)) {
27358 @@ -2985,9 +2992,12 @@ static inline int handle_pte_fault(struc
27359         if (unlikely(!pte_same(*pte, entry)))
27360                 goto unlock;
27361         if (flags & FAULT_FLAG_WRITE) {
27362 -               if (!pte_write(entry))
27363 -                       return do_wp_page(mm, vma, address,
27364 +               if (!pte_write(entry)) {
27365 +                       ret = do_wp_page(mm, vma, address,
27366                                         pte, pmd, ptl, entry);
27367 +                       type = VXPT_WRITE;
27368 +                       goto out;
27369 +               }
27370                 entry = pte_mkdirty(entry);
27371         }
27372         entry = pte_mkyoung(entry);
27373 @@ -3005,7 +3015,10 @@ static inline int handle_pte_fault(struc
27374         }
27375  unlock:
27376         pte_unmap_unlock(pte, ptl);
27377 -       return 0;
27378 +       ret = 0;
27379 +out:
27380 +       vx_page_fault(mm, vma, type, ret);
27381 +       return ret;
27382  }
27383  
27384  /*
27385 diff -NurpP --minimal linux-2.6.33/mm/mlock.c linux-2.6.33-vs2.3.0.36.30.1/mm/mlock.c
27386 --- linux-2.6.33/mm/mlock.c     2010-02-25 11:52:09.000000000 +0100
27387 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/mlock.c     2010-02-25 12:02:16.000000000 +0100
27388 @@ -18,6 +18,7 @@
27389  #include <linux/rmap.h>
27390  #include <linux/mmzone.h>
27391  #include <linux/hugetlb.h>
27392 +#include <linux/vs_memory.h>
27393  
27394  #include "internal.h"
27395  
27396 @@ -398,7 +399,7 @@ success:
27397         nr_pages = (end - start) >> PAGE_SHIFT;
27398         if (!lock)
27399                 nr_pages = -nr_pages;
27400 -       mm->locked_vm += nr_pages;
27401 +       vx_vmlocked_add(mm, nr_pages);
27402  
27403         /*
27404          * vm_flags is protected by the mmap_sem held in write mode.
27405 @@ -471,7 +472,7 @@ static int do_mlock(unsigned long start,
27406  
27407  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
27408  {
27409 -       unsigned long locked;
27410 +       unsigned long locked, grow;
27411         unsigned long lock_limit;
27412         int error = -ENOMEM;
27413  
27414 @@ -484,8 +485,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
27415         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
27416         start &= PAGE_MASK;
27417  
27418 -       locked = len >> PAGE_SHIFT;
27419 -       locked += current->mm->locked_vm;
27420 +       grow = len >> PAGE_SHIFT;
27421 +       if (!vx_vmlocked_avail(current->mm, grow))
27422 +               goto out;
27423 +       locked = current->mm->locked_vm + grow;
27424  
27425         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
27426         lock_limit >>= PAGE_SHIFT;
27427 @@ -493,6 +496,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
27428         /* check against resource limits */
27429         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
27430                 error = do_mlock(start, len, 1);
27431 +out:
27432         up_write(&current->mm->mmap_sem);
27433         return error;
27434  }
27435 @@ -554,6 +558,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
27436         lock_limit >>= PAGE_SHIFT;
27437  
27438         ret = -ENOMEM;
27439 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
27440 +               goto out;
27441         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
27442             capable(CAP_IPC_LOCK))
27443                 ret = do_mlockall(flags);
27444 @@ -628,8 +634,10 @@ int account_locked_memory(struct mm_stru
27445         if (lim < vm)
27446                 goto out;
27447  
27448 -       mm->total_vm  += pgsz;
27449 -       mm->locked_vm += pgsz;
27450 +       // mm->total_vm  += pgsz;
27451 +       vx_vmpages_add(mm, pgsz);
27452 +       // mm->locked_vm += pgsz;
27453 +       vx_vmlocked_add(mm, pgsz);
27454  
27455         error = 0;
27456   out:
27457 @@ -643,8 +651,10 @@ void refund_locked_memory(struct mm_stru
27458  
27459         down_write(&mm->mmap_sem);
27460  
27461 -       mm->total_vm  -= pgsz;
27462 -       mm->locked_vm -= pgsz;
27463 +       // mm->total_vm  -= pgsz;
27464 +       vx_vmpages_sub(mm, pgsz);
27465 +       // mm->locked_vm -= pgsz;
27466 +       vx_vmlocked_sub(mm, pgsz);
27467  
27468         up_write(&mm->mmap_sem);
27469  }
27470 diff -NurpP --minimal linux-2.6.33/mm/mmap.c linux-2.6.33-vs2.3.0.36.30.1/mm/mmap.c
27471 --- linux-2.6.33/mm/mmap.c      2010-02-25 11:52:09.000000000 +0100
27472 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/mmap.c      2010-02-25 12:02:16.000000000 +0100
27473 @@ -1262,7 +1262,8 @@ munmap_back:
27474  out:
27475         perf_event_mmap(vma);
27476  
27477 -       mm->total_vm += len >> PAGE_SHIFT;
27478 +       // mm->total_vm += len >> PAGE_SHIFT;
27479 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
27480         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
27481         if (vm_flags & VM_LOCKED) {
27482                 /*
27483 @@ -1271,7 +1272,8 @@ out:
27484                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
27485                 if (nr_pages < 0)
27486                         return nr_pages;        /* vma gone! */
27487 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
27488 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
27489 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
27490         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
27491                 make_pages_present(addr, addr + len);
27492         return addr;
27493 @@ -1626,9 +1628,9 @@ static int acct_stack_growth(struct vm_a
27494                 return -ENOMEM;
27495  
27496         /* Ok, everything looks good - let it rip */
27497 -       mm->total_vm += grow;
27498 +       vx_vmpages_add(mm, grow);
27499         if (vma->vm_flags & VM_LOCKED)
27500 -               mm->locked_vm += grow;
27501 +               vx_vmlocked_add(mm, grow);
27502         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
27503         return 0;
27504  }
27505 @@ -1803,7 +1805,8 @@ static void remove_vma_list(struct mm_st
27506         do {
27507                 long nrpages = vma_pages(vma);
27508  
27509 -               mm->total_vm -= nrpages;
27510 +               // mm->total_vm -= nrpages;
27511 +               vx_vmpages_sub(mm, nrpages);
27512                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
27513                 vma = remove_vma(vma);
27514         } while (vma);
27515 @@ -1995,7 +1998,8 @@ int do_munmap(struct mm_struct *mm, unsi
27516                 struct vm_area_struct *tmp = vma;
27517                 while (tmp && tmp->vm_start < end) {
27518                         if (tmp->vm_flags & VM_LOCKED) {
27519 -                               mm->locked_vm -= vma_pages(tmp);
27520 +                               // mm->locked_vm -= vma_pages(tmp);
27521 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
27522                                 munlock_vma_pages_all(tmp);
27523                         }
27524                         tmp = tmp->vm_next;
27525 @@ -2078,6 +2082,8 @@ unsigned long do_brk(unsigned long addr,
27526                 lock_limit >>= PAGE_SHIFT;
27527                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
27528                         return -EAGAIN;
27529 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
27530 +                       return -ENOMEM;
27531         }
27532  
27533         /*
27534 @@ -2104,7 +2110,8 @@ unsigned long do_brk(unsigned long addr,
27535         if (mm->map_count > sysctl_max_map_count)
27536                 return -ENOMEM;
27537  
27538 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
27539 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
27540 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
27541                 return -ENOMEM;
27542  
27543         /* Can we just expand an old private anonymous mapping? */
27544 @@ -2130,10 +2137,13 @@ unsigned long do_brk(unsigned long addr,
27545         vma->vm_page_prot = vm_get_page_prot(flags);
27546         vma_link(mm, vma, prev, rb_link, rb_parent);
27547  out:
27548 -       mm->total_vm += len >> PAGE_SHIFT;
27549 +       // mm->total_vm += len >> PAGE_SHIFT;
27550 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
27551 +
27552         if (flags & VM_LOCKED) {
27553                 if (!mlock_vma_pages_range(vma, addr, addr + len))
27554 -                       mm->locked_vm += (len >> PAGE_SHIFT);
27555 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
27556 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
27557         }
27558         return addr;
27559  }
27560 @@ -2177,6 +2187,11 @@ void exit_mmap(struct mm_struct *mm)
27561         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
27562         tlb_finish_mmu(tlb, 0, end);
27563  
27564 +       set_mm_counter(mm, file_rss, 0);
27565 +       set_mm_counter(mm, anon_rss, 0);
27566 +       vx_vmpages_sub(mm, mm->total_vm);
27567 +       vx_vmlocked_sub(mm, mm->locked_vm);
27568 +
27569         /*
27570          * Walk the list again, actually closing and freeing it,
27571          * with preemption enabled, without holding any MM locks.
27572 @@ -2216,7 +2231,8 @@ int insert_vm_struct(struct mm_struct * 
27573         if (__vma && __vma->vm_start < vma->vm_end)
27574                 return -ENOMEM;
27575         if ((vma->vm_flags & VM_ACCOUNT) &&
27576 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
27577 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
27578 +               !vx_vmpages_avail(mm, vma_pages(vma))))
27579                 return -ENOMEM;
27580         vma_link(mm, vma, prev, rb_link, rb_parent);
27581         return 0;
27582 @@ -2292,6 +2308,8 @@ int may_expand_vm(struct mm_struct *mm, 
27583  
27584         if (cur + npages > lim)
27585                 return 0;
27586 +       if (!vx_vmpages_avail(mm, npages))
27587 +               return 0;
27588         return 1;
27589  }
27590  
27591 @@ -2369,7 +2387,7 @@ int install_special_mapping(struct mm_st
27592                 return -ENOMEM;
27593         }
27594  
27595 -       mm->total_vm += len >> PAGE_SHIFT;
27596 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
27597  
27598         perf_event_mmap(vma);
27599  
27600 diff -NurpP --minimal linux-2.6.33/mm/mremap.c linux-2.6.33-vs2.3.0.36.30.1/mm/mremap.c
27601 --- linux-2.6.33/mm/mremap.c    2010-02-25 11:52:09.000000000 +0100
27602 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/mremap.c    2010-02-25 12:02:16.000000000 +0100
27603 @@ -20,6 +20,7 @@
27604  #include <linux/security.h>
27605  #include <linux/syscalls.h>
27606  #include <linux/mmu_notifier.h>
27607 +#include <linux/vs_memory.h>
27608  
27609  #include <asm/uaccess.h>
27610  #include <asm/cacheflush.h>
27611 @@ -234,7 +235,7 @@ static unsigned long move_vma(struct vm_
27612          * If this were a serious issue, we'd add a flag to do_munmap().
27613          */
27614         hiwater_vm = mm->hiwater_vm;
27615 -       mm->total_vm += new_len >> PAGE_SHIFT;
27616 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
27617         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
27618  
27619         if (do_munmap(mm, old_addr, old_len) < 0) {
27620 @@ -252,7 +253,7 @@ static unsigned long move_vma(struct vm_
27621         }
27622  
27623         if (vm_flags & VM_LOCKED) {
27624 -               mm->locked_vm += new_len >> PAGE_SHIFT;
27625 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
27626                 if (new_len > old_len)
27627                         mlock_vma_pages_range(new_vma, new_addr + old_len,
27628                                                        new_addr + new_len);
27629 @@ -463,10 +464,12 @@ unsigned long do_mremap(unsigned long ad
27630                         vma_adjust(vma, vma->vm_start,
27631                                 addr + new_len, vma->vm_pgoff, NULL);
27632  
27633 -                       mm->total_vm += pages;
27634 +                       // mm->total_vm += pages;
27635 +                       vx_vmpages_add(mm, pages);
27636                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
27637                         if (vma->vm_flags & VM_LOCKED) {
27638 -                               mm->locked_vm += pages;
27639 +                               // mm->locked_vm += pages;
27640 +                               vx_vmlocked_add(mm, pages);
27641                                 mlock_vma_pages_range(vma, addr + old_len,
27642                                                    addr + new_len);
27643                         }
27644 diff -NurpP --minimal linux-2.6.33/mm/nommu.c linux-2.6.33-vs2.3.0.36.30.1/mm/nommu.c
27645 --- linux-2.6.33/mm/nommu.c     2010-02-25 11:52:09.000000000 +0100
27646 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/nommu.c     2010-02-25 12:02:16.000000000 +0100
27647 @@ -1349,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file 
27648         /* okay... we have a mapping; now we have to register it */
27649         result = vma->vm_start;
27650  
27651 -       current->mm->total_vm += len >> PAGE_SHIFT;
27652 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
27653  
27654  share:
27655         add_vma_to_mm(current->mm, vma);
27656 @@ -1637,7 +1637,7 @@ void exit_mmap(struct mm_struct *mm)
27657  
27658         kenter("");
27659  
27660 -       mm->total_vm = 0;
27661 +       vx_vmpages_sub(mm, mm->total_vm);
27662  
27663         while ((vma = mm->mmap)) {
27664                 mm->mmap = vma->vm_next;
27665 diff -NurpP --minimal linux-2.6.33/mm/oom_kill.c linux-2.6.33-vs2.3.0.36.30.1/mm/oom_kill.c
27666 --- linux-2.6.33/mm/oom_kill.c  2010-02-25 11:52:09.000000000 +0100
27667 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/oom_kill.c  2010-02-25 12:20:14.000000000 +0100
27668 @@ -27,6 +27,9 @@
27669  #include <linux/notifier.h>
27670  #include <linux/memcontrol.h>
27671  #include <linux/security.h>
27672 +#include <linux/reboot.h>
27673 +#include <linux/vs_memory.h>
27674 +#include <linux/vs_context.h>
27675  
27676  int sysctl_panic_on_oom;
27677  int sysctl_oom_kill_allocating_task;
27678 @@ -186,9 +189,21 @@ unsigned long badness(struct task_struct
27679                         points >>= -(oom_adj);
27680         }
27681  
27682 +       /*
27683 +        * add points for context badness and
27684 +        * reduce badness for processes belonging to
27685 +        * a different context
27686 +        */
27687 +
27688 +       points += vx_badness(p, mm);
27689 +
27690 +       if ((vx_current_xid() > 1) &&
27691 +               vx_current_xid() != vx_task_xid(p))
27692 +               points /= 16;
27693 +
27694  #ifdef DEBUG
27695 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
27696 -       p->pid, p->comm, points);
27697 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
27698 +               task_pid_nr(p), p->xid, p->comm, points);
27699  #endif
27700         return points;
27701  }
27702 @@ -249,6 +264,7 @@ static struct task_struct *select_bad_pr
27703         struct task_struct *p;
27704         struct task_struct *chosen = NULL;
27705         struct timespec uptime;
27706 +       unsigned xid = vx_current_xid();
27707         *ppoints = 0;
27708  
27709         do_posix_clock_monotonic_gettime(&uptime);
27710 @@ -261,11 +277,14 @@ static struct task_struct *select_bad_pr
27711                  */
27712                 if (!p->mm)
27713                         continue;
27714 -               /* skip the init task */
27715 -               if (is_global_init(p))
27716 +               /* skip the init task, global and per guest */
27717 +               if (task_is_init(p))
27718                         continue;
27719                 if (mem && !task_in_mem_cgroup(p, mem))
27720                         continue;
27721 +               /* skip other guest and host processes if oom in guest */
27722 +               if (xid && vx_task_xid(p) != xid)
27723 +                       continue;
27724  
27725                 /*
27726                  * This task already has access to memory reserves and is
27727 @@ -397,9 +416,9 @@ static void __oom_kill_task(struct task_
27728         }
27729  
27730         if (verbose)
27731 -               printk(KERN_ERR "Killed process %d (%s) "
27732 +               printk(KERN_ERR "Killed process %s(%d:#%u) "
27733                        "vsz:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
27734 -                      task_pid_nr(p), p->comm,
27735 +                      p->comm, task_pid_nr(p), p->xid,
27736                        K(p->mm->total_vm),
27737                        K(get_mm_counter(p->mm, anon_rss)),
27738                        K(get_mm_counter(p->mm, file_rss)));
27739 @@ -452,8 +471,8 @@ static int oom_kill_process(struct task_
27740                 return 0;
27741         }
27742  
27743 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
27744 -                                       message, task_pid_nr(p), p->comm, points);
27745 +       printk(KERN_ERR "%s: kill process %s(%d:#%u) score %li or a child\n",
27746 +               message, p->comm, task_pid_nr(p), p->xid, points);
27747  
27748         /* Try to kill a child first */
27749         list_for_each_entry(c, &p->children, sibling) {
27750 @@ -554,6 +573,8 @@ void clear_zonelist_oom(struct zonelist 
27751         spin_unlock(&zone_scan_lock);
27752  }
27753  
27754 +long vs_oom_action(unsigned int);
27755 +
27756  /*
27757   * Must be called with tasklist_lock held for read.
27758   */
27759 @@ -580,7 +601,11 @@ retry:
27760         if (!p) {
27761                 read_unlock(&tasklist_lock);
27762                 dump_header(NULL, gfp_mask, order, NULL);
27763 -               panic("Out of memory and no killable processes...\n");
27764 +               /* avoid panic for guest OOM */
27765 +               if (current->xid)
27766 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
27767 +               else
27768 +                       panic("Out of memory and no killable processes...\n");
27769         }
27770  
27771         if (oom_kill_process(p, gfp_mask, order, points, NULL,
27772 diff -NurpP --minimal linux-2.6.33/mm/page_alloc.c linux-2.6.33-vs2.3.0.36.30.1/mm/page_alloc.c
27773 --- linux-2.6.33/mm/page_alloc.c        2010-02-25 11:52:09.000000000 +0100
27774 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/page_alloc.c        2010-02-25 12:16:45.000000000 +0100
27775 @@ -49,6 +49,8 @@
27776  #include <linux/debugobjects.h>
27777  #include <linux/kmemleak.h>
27778  #include <linux/memory.h>
27779 +#include <linux/vs_base.h>
27780 +#include <linux/vs_limit.h>
27781  #include <trace/events/kmem.h>
27782  
27783  #include <asm/tlbflush.h>
27784 @@ -2138,6 +2140,9 @@ void si_meminfo(struct sysinfo *val)
27785         val->totalhigh = totalhigh_pages;
27786         val->freehigh = nr_free_highpages();
27787         val->mem_unit = PAGE_SIZE;
27788 +
27789 +       if (vx_flags(VXF_VIRT_MEM, 0))
27790 +               vx_vsi_meminfo(val);
27791  }
27792  
27793  EXPORT_SYMBOL(si_meminfo);
27794 @@ -2158,6 +2163,9 @@ void si_meminfo_node(struct sysinfo *val
27795         val->freehigh = 0;
27796  #endif
27797         val->mem_unit = PAGE_SIZE;
27798 +
27799 +       if (vx_flags(VXF_VIRT_MEM, 0))
27800 +               vx_vsi_meminfo(val);
27801  }
27802  #endif
27803  
27804 diff -NurpP --minimal linux-2.6.33/mm/rmap.c linux-2.6.33-vs2.3.0.36.30.1/mm/rmap.c
27805 --- linux-2.6.33/mm/rmap.c      2010-02-25 11:52:09.000000000 +0100
27806 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/rmap.c      2010-02-25 12:02:16.000000000 +0100
27807 @@ -56,6 +56,7 @@
27808  #include <linux/memcontrol.h>
27809  #include <linux/mmu_notifier.h>
27810  #include <linux/migrate.h>
27811 +#include <linux/vs_memory.h>
27812  
27813  #include <asm/tlbflush.h>
27814  
27815 diff -NurpP --minimal linux-2.6.33/mm/shmem.c linux-2.6.33-vs2.3.0.36.30.1/mm/shmem.c
27816 --- linux-2.6.33/mm/shmem.c     2010-02-25 11:52:09.000000000 +0100
27817 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/shmem.c     2010-02-25 12:02:16.000000000 +0100
27818 @@ -1788,7 +1788,7 @@ static int shmem_statfs(struct dentry *d
27819  {
27820         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
27821  
27822 -       buf->f_type = TMPFS_MAGIC;
27823 +       buf->f_type = TMPFS_SUPER_MAGIC;
27824         buf->f_bsize = PAGE_CACHE_SIZE;
27825         buf->f_namelen = NAME_MAX;
27826         spin_lock(&sbinfo->stat_lock);
27827 @@ -2358,7 +2358,7 @@ int shmem_fill_super(struct super_block 
27828         sb->s_maxbytes = SHMEM_MAX_BYTES;
27829         sb->s_blocksize = PAGE_CACHE_SIZE;
27830         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
27831 -       sb->s_magic = TMPFS_MAGIC;
27832 +       sb->s_magic = TMPFS_SUPER_MAGIC;
27833         sb->s_op = &shmem_ops;
27834         sb->s_time_gran = 1;
27835  #ifdef CONFIG_TMPFS_POSIX_ACL
27836 diff -NurpP --minimal linux-2.6.33/mm/slab.c linux-2.6.33-vs2.3.0.36.30.1/mm/slab.c
27837 --- linux-2.6.33/mm/slab.c      2010-02-25 11:52:09.000000000 +0100
27838 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/slab.c      2010-02-25 12:02:16.000000000 +0100
27839 @@ -431,6 +431,8 @@ static void kmem_list3_init(struct kmem_
27840  #define STATS_INC_FREEMISS(x)  do { } while (0)
27841  #endif
27842  
27843 +#include "slab_vs.h"
27844 +
27845  #if DEBUG
27846  
27847  /*
27848 @@ -3275,6 +3277,7 @@ retry:
27849  
27850         obj = slab_get_obj(cachep, slabp, nodeid);
27851         check_slabp(cachep, slabp);
27852 +       vx_slab_alloc(cachep, flags);
27853         l3->free_objects--;
27854         /* move slabp to correct slabp list: */
27855         list_del(&slabp->list);
27856 @@ -3351,6 +3354,7 @@ __cache_alloc_node(struct kmem_cache *ca
27857         /* ___cache_alloc_node can fall back to other nodes */
27858         ptr = ____cache_alloc_node(cachep, flags, nodeid);
27859    out:
27860 +       vx_slab_alloc(cachep, flags);
27861         local_irq_restore(save_flags);
27862         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
27863         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
27864 @@ -3537,6 +3541,7 @@ static inline void __cache_free(struct k
27865         check_irq_off();
27866         kmemleak_free_recursive(objp, cachep->flags);
27867         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
27868 +       vx_slab_free(cachep);
27869  
27870         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
27871  
27872 diff -NurpP --minimal linux-2.6.33/mm/slab_vs.h linux-2.6.33-vs2.3.0.36.30.1/mm/slab_vs.h
27873 --- linux-2.6.33/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
27874 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/slab_vs.h   2010-02-25 12:02:16.000000000 +0100
27875 @@ -0,0 +1,29 @@
27876 +
27877 +#include <linux/vserver/context.h>
27878 +
27879 +#include <linux/vs_context.h>
27880 +
27881 +static inline
27882 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
27883 +{
27884 +       int what = gfp_zone(cachep->gfpflags);
27885 +       struct vx_info *vxi = current_vx_info();
27886 +
27887 +       if (!vxi)
27888 +               return;
27889 +
27890 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
27891 +}
27892 +
27893 +static inline
27894 +void vx_slab_free(struct kmem_cache *cachep)
27895 +{
27896 +       int what = gfp_zone(cachep->gfpflags);
27897 +       struct vx_info *vxi = current_vx_info();
27898 +
27899 +       if (!vxi)
27900 +               return;
27901 +
27902 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
27903 +}
27904 +
27905 diff -NurpP --minimal linux-2.6.33/mm/swapfile.c linux-2.6.33-vs2.3.0.36.30.1/mm/swapfile.c
27906 --- linux-2.6.33/mm/swapfile.c  2010-02-25 11:52:09.000000000 +0100
27907 +++ linux-2.6.33-vs2.3.0.36.30.1/mm/swapfile.c  2010-02-25 12:02:16.000000000 +0100
27908 @@ -35,6 +35,8 @@
27909  #include <asm/tlbflush.h>
27910  #include <linux/swapops.h>
27911  #include <linux/page_cgroup.h>
27912 +#include <linux/vs_base.h>
27913 +#include <linux/vs_memory.h>
27914  
27915  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
27916                                  unsigned char);
27917 @@ -1693,6 +1695,16 @@ static int swap_show(struct seq_file *sw
27918  
27919         if (si == SEQ_START_TOKEN) {
27920                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
27921 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
27922 +                       struct sysinfo si;
27923 +
27924 +                       vx_vsi_swapinfo(&si);
27925 +                       if (si.totalswap < (1 << 10))
27926 +                               return 0;
27927 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
27928 +                               "hdv0", "partition", si.totalswap >> 10,
27929 +                               (si.totalswap - si.freeswap) >> 10, -1);
27930 +               }
27931                 return 0;
27932         }
27933  
27934 @@ -2071,6 +2083,8 @@ void si_swapinfo(struct sysinfo *val)
27935         val->freeswap = nr_swap_pages + nr_to_be_unused;
27936         val->totalswap = total_swap_pages + nr_to_be_unused;
27937         spin_unlock(&swap_lock);
27938 +       if (vx_flags(VXF_VIRT_MEM, 0))
27939 +               vx_vsi_swapinfo(val);
27940  }
27941  
27942  /*
27943 diff -NurpP --minimal linux-2.6.33/net/core/dev.c linux-2.6.33-vs2.3.0.36.30.1/net/core/dev.c
27944 --- linux-2.6.33/net/core/dev.c 2010-02-25 11:52:10.000000000 +0100
27945 +++ linux-2.6.33-vs2.3.0.36.30.1/net/core/dev.c 2010-02-25 14:02:39.000000000 +0100
27946 @@ -128,6 +128,7 @@
27947  #include <linux/in.h>
27948  #include <linux/jhash.h>
27949  #include <linux/random.h>
27950 +#include <linux/vs_inet.h>
27951  #include <trace/events/napi.h>
27952  
27953  #include "net-sysfs.h"
27954 @@ -593,7 +594,8 @@ struct net_device *__dev_get_by_name(str
27955         struct hlist_head *head = dev_name_hash(net, name);
27956  
27957         hlist_for_each_entry(dev, p, head, name_hlist)
27958 -               if (!strncmp(dev->name, name, IFNAMSIZ))
27959 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
27960 +                   nx_dev_visible(current_nx_info(), dev))
27961                         return dev;
27962  
27963         return NULL;
27964 @@ -619,7 +621,8 @@ struct net_device *dev_get_by_name_rcu(s
27965         struct hlist_head *head = dev_name_hash(net, name);
27966  
27967         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
27968 -               if (!strncmp(dev->name, name, IFNAMSIZ))
27969 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
27970 +                   nx_dev_visible(current_nx_info(), dev))
27971                         return dev;
27972  
27973         return NULL;
27974 @@ -670,7 +673,8 @@ struct net_device *__dev_get_by_index(st
27975         struct hlist_head *head = dev_index_hash(net, ifindex);
27976  
27977         hlist_for_each_entry(dev, p, head, index_hlist)
27978 -               if (dev->ifindex == ifindex)
27979 +               if ((dev->ifindex == ifindex) &&
27980 +                   nx_dev_visible(current_nx_info(), dev))
27981                         return dev;
27982  
27983         return NULL;
27984 @@ -695,7 +699,8 @@ struct net_device *dev_get_by_index_rcu(
27985         struct hlist_head *head = dev_index_hash(net, ifindex);
27986  
27987         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
27988 -               if (dev->ifindex == ifindex)
27989 +               if ((dev->ifindex == ifindex) &&
27990 +                   nx_dev_visible(current_nx_info(), dev))
27991                         return dev;
27992  
27993         return NULL;
27994 @@ -748,10 +753,12 @@ struct net_device *dev_getbyhwaddr(struc
27995  
27996         ASSERT_RTNL();
27997  
27998 -       for_each_netdev(net, dev)
27999 +       for_each_netdev(net, dev) {
28000                 if (dev->type == type &&
28001 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
28002 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
28003 +                   nx_dev_visible(current_nx_info(), dev))
28004                         return dev;
28005 +       }
28006  
28007         return NULL;
28008  }
28009 @@ -762,9 +769,11 @@ struct net_device *__dev_getfirstbyhwtyp
28010         struct net_device *dev;
28011  
28012         ASSERT_RTNL();
28013 -       for_each_netdev(net, dev)
28014 -               if (dev->type == type)
28015 +       for_each_netdev(net, dev) {
28016 +               if ((dev->type == type) &&
28017 +                   nx_dev_visible(current_nx_info(), dev))
28018                         return dev;
28019 +       }
28020  
28021         return NULL;
28022  }
28023 @@ -883,6 +892,8 @@ static int __dev_alloc_name(struct net *
28024                                 continue;
28025                         if (i < 0 || i >= max_netdevices)
28026                                 continue;
28027 +                       if (!nx_dev_visible(current_nx_info(), d))
28028 +                               continue;
28029  
28030                         /*  avoid cases where sscanf is not exact inverse of printf */
28031                         snprintf(buf, IFNAMSIZ, name, i);
28032 @@ -3115,6 +3126,8 @@ static int dev_ifconf(struct net *net, c
28033  
28034         total = 0;
28035         for_each_netdev(net, dev) {
28036 +               if (!nx_dev_visible(current_nx_info(), dev))
28037 +                       continue;
28038                 for (i = 0; i < NPROTO; i++) {
28039                         if (gifconf_list[i]) {
28040                                 int done;
28041 @@ -3185,6 +3198,9 @@ static void dev_seq_printf_stats(struct 
28042  {
28043         const struct net_device_stats *stats = dev_get_stats(dev);
28044  
28045 +       if (!nx_dev_visible(current_nx_info(), dev))
28046 +               return;
28047 +
28048         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
28049                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
28050                    dev->name, stats->rx_bytes, stats->rx_packets,
28051 @@ -5528,7 +5544,6 @@ int dev_change_net_namespace(struct net_
28052         if (dev->dev.parent)
28053                 goto out;
28054  #endif
28055 -
28056         /* Ensure the device has been registrered */
28057         err = -EINVAL;
28058         if (dev->reg_state != NETREG_REGISTERED)
28059 diff -NurpP --minimal linux-2.6.33/net/core/rtnetlink.c linux-2.6.33-vs2.3.0.36.30.1/net/core/rtnetlink.c
28060 --- linux-2.6.33/net/core/rtnetlink.c   2010-02-25 11:52:10.000000000 +0100
28061 +++ linux-2.6.33-vs2.3.0.36.30.1/net/core/rtnetlink.c   2010-02-25 13:59:02.000000000 +0100
28062 @@ -695,6 +695,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
28063                 hlist_for_each_entry(dev, node, head, index_hlist) {
28064                         if (idx < s_idx)
28065                                 goto cont;
28066 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
28067 +                               continue;
28068                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
28069                                              NETLINK_CB(cb->skb).pid,
28070                                              cb->nlh->nlmsg_seq, 0,
28071 @@ -1252,6 +1254,9 @@ void rtmsg_ifinfo(int type, struct net_d
28072         struct sk_buff *skb;
28073         int err = -ENOBUFS;
28074  
28075 +       if (!nx_dev_visible(current_nx_info(), dev))
28076 +               return;
28077 +
28078         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
28079         if (skb == NULL)
28080                 goto errout;
28081 diff -NurpP --minimal linux-2.6.33/net/core/sock.c linux-2.6.33-vs2.3.0.36.30.1/net/core/sock.c
28082 --- linux-2.6.33/net/core/sock.c        2010-02-25 11:52:10.000000000 +0100
28083 +++ linux-2.6.33-vs2.3.0.36.30.1/net/core/sock.c        2010-02-25 12:02:16.000000000 +0100
28084 @@ -125,6 +125,10 @@
28085  #include <linux/ipsec.h>
28086  
28087  #include <linux/filter.h>
28088 +#include <linux/vs_socket.h>
28089 +#include <linux/vs_limit.h>
28090 +#include <linux/vs_context.h>
28091 +#include <linux/vs_network.h>
28092  
28093  #ifdef CONFIG_INET
28094  #include <net/tcp.h>
28095 @@ -1008,6 +1012,8 @@ static struct sock *sk_prot_alloc(struct
28096                         goto out_free_sec;
28097                 sk_tx_queue_clear(sk);
28098         }
28099 +               sock_vx_init(sk);
28100 +               sock_nx_init(sk);
28101  
28102         return sk;
28103  
28104 @@ -1087,6 +1093,11 @@ static void __sk_free(struct sock *sk)
28105                        __func__, atomic_read(&sk->sk_omem_alloc));
28106  
28107         put_net(sock_net(sk));
28108 +       vx_sock_dec(sk);
28109 +       clr_vx_info(&sk->sk_vx_info);
28110 +       sk->sk_xid = -1;
28111 +       clr_nx_info(&sk->sk_nx_info);
28112 +       sk->sk_nid = -1;
28113         sk_prot_free(sk->sk_prot_creator, sk);
28114  }
28115  
28116 @@ -1134,6 +1145,8 @@ struct sock *sk_clone(const struct sock 
28117  
28118                 /* SANITY */
28119                 get_net(sock_net(newsk));
28120 +               sock_vx_init(newsk);
28121 +               sock_nx_init(newsk);
28122                 sk_node_init(&newsk->sk_node);
28123                 sock_lock_init(newsk);
28124                 bh_lock_sock(newsk);
28125 @@ -1188,6 +1201,12 @@ struct sock *sk_clone(const struct sock 
28126                 smp_wmb();
28127                 atomic_set(&newsk->sk_refcnt, 2);
28128  
28129 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
28130 +               newsk->sk_xid = sk->sk_xid;
28131 +               vx_sock_inc(newsk);
28132 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
28133 +               newsk->sk_nid = sk->sk_nid;
28134 +
28135                 /*
28136                  * Increment the counter in the same struct proto as the master
28137                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
28138 @@ -1910,6 +1929,12 @@ void sock_init_data(struct socket *sock,
28139  
28140         sk->sk_stamp = ktime_set(-1L, 0);
28141  
28142 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
28143 +       sk->sk_xid = vx_current_xid();
28144 +       vx_sock_inc(sk);
28145 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
28146 +       sk->sk_nid = nx_current_nid();
28147 +
28148         /*
28149          * Before updating sk_refcnt, we must commit prior changes to memory
28150          * (Documentation/RCU/rculist_nulls.txt for details)
28151 diff -NurpP --minimal linux-2.6.33/net/ipv4/af_inet.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/af_inet.c
28152 --- linux-2.6.33/net/ipv4/af_inet.c     2010-02-25 11:52:10.000000000 +0100
28153 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/af_inet.c     2010-02-25 15:53:12.000000000 +0100
28154 @@ -115,6 +115,7 @@
28155  #ifdef CONFIG_IP_MROUTE
28156  #include <linux/mroute.h>
28157  #endif
28158 +#include <linux/vs_limit.h>
28159  
28160  
28161  /* The inetsw table contains everything that inet_create needs to
28162 @@ -326,9 +327,13 @@ lookup_protocol:
28163         }
28164  
28165         err = -EPERM;
28166 +       if ((protocol == IPPROTO_ICMP) &&
28167 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
28168 +               goto override;
28169 +
28170         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
28171                 goto out_rcu_unlock;
28172 -
28173 +override:
28174         err = -EAFNOSUPPORT;
28175         if (!inet_netns_ok(net, protocol))
28176                 goto out_rcu_unlock;
28177 @@ -448,6 +453,7 @@ int inet_bind(struct socket *sock, struc
28178         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
28179         struct sock *sk = sock->sk;
28180         struct inet_sock *inet = inet_sk(sk);
28181 +       struct nx_v4_sock_addr nsa;
28182         unsigned short snum;
28183         int chk_addr_ret;
28184         int err;
28185 @@ -461,7 +467,11 @@ int inet_bind(struct socket *sock, struc
28186         if (addr_len < sizeof(struct sockaddr_in))
28187                 goto out;
28188  
28189 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
28190 +       err = v4_map_sock_addr(inet, addr, &nsa);
28191 +       if (err)
28192 +               goto out;
28193 +
28194 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
28195  
28196         /* Not specified by any standard per-se, however it breaks too
28197          * many applications when removed.  It is unfortunate since
28198 @@ -473,7 +483,7 @@ int inet_bind(struct socket *sock, struc
28199         err = -EADDRNOTAVAIL;
28200         if (!sysctl_ip_nonlocal_bind &&
28201             !(inet->freebind || inet->transparent) &&
28202 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
28203 +           nsa.saddr != htonl(INADDR_ANY) &&
28204             chk_addr_ret != RTN_LOCAL &&
28205             chk_addr_ret != RTN_MULTICAST &&
28206             chk_addr_ret != RTN_BROADCAST)
28207 @@ -498,7 +508,7 @@ int inet_bind(struct socket *sock, struc
28208         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
28209                 goto out_release_sock;
28210  
28211 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
28212 +       v4_set_sock_addr(inet, &nsa);
28213         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
28214                 inet->inet_saddr = 0;  /* Use device */
28215  
28216 @@ -695,11 +705,13 @@ int inet_getname(struct socket *sock, st
28217                      peer == 1))
28218                         return -ENOTCONN;
28219                 sin->sin_port = inet->inet_dport;
28220 -               sin->sin_addr.s_addr = inet->inet_daddr;
28221 +               sin->sin_addr.s_addr =
28222 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
28223         } else {
28224                 __be32 addr = inet->inet_rcv_saddr;
28225                 if (!addr)
28226                         addr = inet->inet_saddr;
28227 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
28228                 sin->sin_port = inet->inet_sport;
28229                 sin->sin_addr.s_addr = addr;
28230         }
28231 diff -NurpP --minimal linux-2.6.33/net/ipv4/devinet.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/devinet.c
28232 --- linux-2.6.33/net/ipv4/devinet.c     2010-02-25 11:52:10.000000000 +0100
28233 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/devinet.c     2010-02-25 14:19:58.000000000 +0100
28234 @@ -416,6 +416,7 @@ struct in_device *inetdev_by_index(struc
28235  }
28236  EXPORT_SYMBOL(inetdev_by_index);
28237  
28238 +
28239  /* Called only from RTNL semaphored context. No locks. */
28240  
28241  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
28242 @@ -658,6 +659,8 @@ int devinet_ioctl(struct net *net, unsig
28243  
28244         in_dev = __in_dev_get_rtnl(dev);
28245         if (in_dev) {
28246 +               struct nx_info *nxi = current_nx_info();
28247 +
28248                 if (tryaddrmatch) {
28249                         /* Matthias Andree */
28250                         /* compare label and address (4.4BSD style) */
28251 @@ -666,6 +669,8 @@ int devinet_ioctl(struct net *net, unsig
28252                            This is checked above. */
28253                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28254                              ifap = &ifa->ifa_next) {
28255 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28256 +                                       continue;
28257                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
28258                                     sin_orig.sin_addr.s_addr ==
28259                                                         ifa->ifa_address) {
28260 @@ -678,9 +683,12 @@ int devinet_ioctl(struct net *net, unsig
28261                    comparing just the label */
28262                 if (!ifa) {
28263                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28264 -                            ifap = &ifa->ifa_next)
28265 +                            ifap = &ifa->ifa_next) {
28266 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28267 +                                       continue;
28268                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
28269                                         break;
28270 +                       }
28271                 }
28272         }
28273  
28274 @@ -832,6 +840,8 @@ static int inet_gifconf(struct net_devic
28275                 goto out;
28276  
28277         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
28278 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
28279 +                       continue;
28280                 if (!buf) {
28281                         done += sizeof(ifr);
28282                         continue;
28283 @@ -1180,6 +1190,7 @@ static int inet_dump_ifaddr(struct sk_bu
28284         struct net_device *dev;
28285         struct in_device *in_dev;
28286         struct in_ifaddr *ifa;
28287 +       struct sock *sk = skb->sk;
28288         struct hlist_head *head;
28289         struct hlist_node *node;
28290  
28291 @@ -1202,6 +1213,8 @@ static int inet_dump_ifaddr(struct sk_bu
28292  
28293                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
28294                              ifa = ifa->ifa_next, ip_idx++) {
28295 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
28296 +                               continue;
28297                                 if (ip_idx < s_ip_idx)
28298                                         continue;
28299                                 if (inet_fill_ifaddr(skb, ifa,
28300 diff -NurpP --minimal linux-2.6.33/net/ipv4/fib_hash.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/fib_hash.c
28301 --- linux-2.6.33/net/ipv4/fib_hash.c    2010-02-25 11:52:10.000000000 +0100
28302 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/fib_hash.c    2010-02-25 12:02:16.000000000 +0100
28303 @@ -1016,7 +1016,7 @@ static int fib_seq_show(struct seq_file 
28304         prefix  = f->fn_key;
28305         mask    = FZ_MASK(iter->zone);
28306         flags   = fib_flag_trans(fa->fa_type, mask, fi);
28307 -       if (fi)
28308 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
28309                 seq_printf(seq,
28310                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
28311                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
28312 diff -NurpP --minimal linux-2.6.33/net/ipv4/inet_connection_sock.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/inet_connection_sock.c
28313 --- linux-2.6.33/net/ipv4/inet_connection_sock.c        2010-02-25 11:52:10.000000000 +0100
28314 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/inet_connection_sock.c        2010-02-25 12:02:16.000000000 +0100
28315 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
28316  }
28317  EXPORT_SYMBOL(inet_get_local_port_range);
28318  
28319 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
28320 +{
28321 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
28322 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
28323 +
28324 +       if (inet_v6_ipv6only(sk2))
28325 +               return 0;
28326 +
28327 +       if (sk1_rcv_saddr &&
28328 +           sk2_rcv_saddr &&
28329 +           sk1_rcv_saddr == sk2_rcv_saddr)
28330 +               return 1;
28331 +
28332 +       if (sk1_rcv_saddr &&
28333 +           !sk2_rcv_saddr &&
28334 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
28335 +               return 1;
28336 +
28337 +       if (sk2_rcv_saddr &&
28338 +           !sk1_rcv_saddr &&
28339 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
28340 +               return 1;
28341 +
28342 +       if (!sk1_rcv_saddr &&
28343 +           !sk2_rcv_saddr &&
28344 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
28345 +               return 1;
28346 +
28347 +       return 0;
28348 +}
28349 +
28350  int inet_csk_bind_conflict(const struct sock *sk,
28351                            const struct inet_bind_bucket *tb)
28352  {
28353 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
28354         struct sock *sk2;
28355         struct hlist_node *node;
28356         int reuse = sk->sk_reuse;
28357 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
28358                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
28359                         if (!reuse || !sk2->sk_reuse ||
28360                             sk2->sk_state == TCP_LISTEN) {
28361 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
28362 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
28363 -                                   sk2_rcv_saddr == sk_rcv_saddr)
28364 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
28365                                         break;
28366                         }
28367                 }
28368 diff -NurpP --minimal linux-2.6.33/net/ipv4/inet_diag.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/inet_diag.c
28369 --- linux-2.6.33/net/ipv4/inet_diag.c   2010-02-25 11:52:10.000000000 +0100
28370 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/inet_diag.c   2010-02-25 14:16:01.000000000 +0100
28371 @@ -32,6 +32,8 @@
28372  #include <linux/stddef.h>
28373  
28374  #include <linux/inet_diag.h>
28375 +#include <linux/vs_network.h>
28376 +#include <linux/vs_inet.h>
28377  
28378  static const struct inet_diag_handler **inet_diag_table;
28379  
28380 @@ -118,8 +120,10 @@ static int inet_csk_diag_fill(struct soc
28381  
28382         r->id.idiag_sport = inet->inet_sport;
28383         r->id.idiag_dport = inet->inet_dport;
28384 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
28385 -       r->id.idiag_dst[0] = inet->inet_daddr;
28386 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
28387 +               inet->inet_rcv_saddr);
28388 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
28389 +               inet->inet_daddr);
28390  
28391  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
28392         if (r->idiag_family == AF_INET6) {
28393 @@ -204,8 +208,8 @@ static int inet_twsk_diag_fill(struct in
28394         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
28395         r->id.idiag_sport     = tw->tw_sport;
28396         r->id.idiag_dport     = tw->tw_dport;
28397 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
28398 -       r->id.idiag_dst[0]    = tw->tw_daddr;
28399 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
28400 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
28401         r->idiag_state        = tw->tw_substate;
28402         r->idiag_timer        = 3;
28403         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
28404 @@ -262,6 +266,7 @@ static int inet_diag_get_exact(struct sk
28405         err = -EINVAL;
28406  
28407         if (req->idiag_family == AF_INET) {
28408 +               /* TODO: lback */
28409                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
28410                                  req->id.idiag_dport, req->id.idiag_src[0],
28411                                  req->id.idiag_sport, req->id.idiag_if);
28412 @@ -504,6 +509,7 @@ static int inet_csk_diag_dump(struct soc
28413                 } else
28414  #endif
28415                 {
28416 +                       /* TODO: lback */
28417                         entry.saddr = &inet->inet_rcv_saddr;
28418                         entry.daddr = &inet->inet_daddr;
28419                 }
28420 @@ -540,6 +546,7 @@ static int inet_twsk_diag_dump(struct in
28421                 } else
28422  #endif
28423                 {
28424 +                       /* TODO: lback */
28425                         entry.saddr = &tw->tw_rcv_saddr;
28426                         entry.daddr = &tw->tw_daddr;
28427                 }
28428 @@ -586,8 +593,8 @@ static int inet_diag_fill_req(struct sk_
28429  
28430         r->id.idiag_sport = inet->inet_sport;
28431         r->id.idiag_dport = ireq->rmt_port;
28432 -       r->id.idiag_src[0] = ireq->loc_addr;
28433 -       r->id.idiag_dst[0] = ireq->rmt_addr;
28434 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
28435 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
28436         r->idiag_expires = jiffies_to_msecs(tmo);
28437         r->idiag_rqueue = 0;
28438         r->idiag_wqueue = 0;
28439 @@ -657,6 +664,7 @@ static int inet_diag_dump_reqs(struct sk
28440                                 continue;
28441  
28442                         if (bc) {
28443 +                               /* TODO: lback */
28444                                 entry.saddr =
28445  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
28446                                         (entry.family == AF_INET6) ?
28447 @@ -727,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
28448                         sk_nulls_for_each(sk, node, &ilb->head) {
28449                                 struct inet_sock *inet = inet_sk(sk);
28450  
28451 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28452 +                                       continue;
28453                                 if (num < s_num) {
28454                                         num++;
28455                                         continue;
28456 @@ -793,6 +803,8 @@ skip_listen_ht:
28457                 sk_nulls_for_each(sk, node, &head->chain) {
28458                         struct inet_sock *inet = inet_sk(sk);
28459  
28460 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28461 +                               continue;
28462                         if (num < s_num)
28463                                 goto next_normal;
28464                         if (!(r->idiag_states & (1 << sk->sk_state)))
28465 @@ -817,6 +829,8 @@ next_normal:
28466                         inet_twsk_for_each(tw, node,
28467                                     &head->twchain) {
28468  
28469 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
28470 +                                       continue;
28471                                 if (num < s_num)
28472                                         goto next_dying;
28473                                 if (r->id.idiag_sport != tw->tw_sport &&
28474 diff -NurpP --minimal linux-2.6.33/net/ipv4/inet_hashtables.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/inet_hashtables.c
28475 --- linux-2.6.33/net/ipv4/inet_hashtables.c     2010-02-25 11:52:10.000000000 +0100
28476 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/inet_hashtables.c     2010-02-25 12:02:16.000000000 +0100
28477 @@ -21,6 +21,7 @@
28478  
28479  #include <net/inet_connection_sock.h>
28480  #include <net/inet_hashtables.h>
28481 +#include <net/route.h>
28482  #include <net/ip.h>
28483  
28484  /*
28485 @@ -134,6 +135,11 @@ static inline int compute_score(struct s
28486                         if (rcv_saddr != daddr)
28487                                 return -1;
28488                         score += 2;
28489 +               } else {
28490 +                       /* block non nx_info ips */
28491 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
28492 +                               daddr, NXA_MASK_BIND))
28493 +                               return -1;
28494                 }
28495                 if (sk->sk_bound_dev_if) {
28496                         if (sk->sk_bound_dev_if != dif)
28497 @@ -151,7 +157,6 @@ static inline int compute_score(struct s
28498   * wildcarded during the search since they can never be otherwise.
28499   */
28500  
28501 -
28502  struct sock *__inet_lookup_listener(struct net *net,
28503                                     struct inet_hashinfo *hashinfo,
28504                                     const __be32 daddr, const unsigned short hnum,
28505 @@ -174,6 +179,7 @@ begin:
28506                         hiscore = score;
28507                 }
28508         }
28509 +
28510         /*
28511          * if the nulls value we got at the end of this lookup is
28512          * not the expected one, we must restart lookup.
28513 diff -NurpP --minimal linux-2.6.33/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/netfilter/nf_nat_helper.c
28514 --- linux-2.6.33/net/ipv4/netfilter/nf_nat_helper.c     2010-02-25 11:52:10.000000000 +0100
28515 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/netfilter/nf_nat_helper.c     2010-02-25 12:02:16.000000000 +0100
28516 @@ -19,6 +19,7 @@
28517  #include <net/route.h>
28518  
28519  #include <linux/netfilter_ipv4.h>
28520 +#include <net/route.h>
28521  #include <net/netfilter/nf_conntrack.h>
28522  #include <net/netfilter/nf_conntrack_helper.h>
28523  #include <net/netfilter/nf_conntrack_ecache.h>
28524 diff -NurpP --minimal linux-2.6.33/net/ipv4/netfilter.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/netfilter.c
28525 --- linux-2.6.33/net/ipv4/netfilter.c   2010-02-25 11:52:10.000000000 +0100
28526 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/netfilter.c   2010-02-25 12:02:16.000000000 +0100
28527 @@ -4,7 +4,7 @@
28528  #include <linux/netfilter_ipv4.h>
28529  #include <linux/ip.h>
28530  #include <linux/skbuff.h>
28531 -#include <net/route.h>
28532 +// #include <net/route.h>
28533  #include <net/xfrm.h>
28534  #include <net/ip.h>
28535  #include <net/netfilter/nf_queue.h>
28536 diff -NurpP --minimal linux-2.6.33/net/ipv4/raw.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/raw.c
28537 --- linux-2.6.33/net/ipv4/raw.c 2010-02-25 11:52:10.000000000 +0100
28538 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/raw.c 2010-02-25 14:07:52.000000000 +0100
28539 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
28540  
28541                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
28542                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
28543 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
28544 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
28545                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
28546                         goto found; /* gotcha */
28547         }
28548 @@ -382,6 +382,12 @@ static int raw_send_hdrinc(struct sock *
28549                 icmp_out_count(net, ((struct icmphdr *)
28550                         skb_transport_header(skb))->type);
28551  
28552 +       err = -EPERM;
28553 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
28554 +               sk->sk_nx_info &&
28555 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
28556 +               goto error_free;
28557 +
28558         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
28559                       dst_output);
28560         if (err > 0)
28561 @@ -562,6 +568,13 @@ static int raw_sendmsg(struct kiocb *ioc
28562                 }
28563  
28564                 security_sk_classify_flow(sk, &fl);
28565 +               if (sk->sk_nx_info) {
28566 +                       err = ip_v4_find_src(sock_net(sk),
28567 +                               sk->sk_nx_info, &rt, &fl);
28568 +
28569 +                       if (err)
28570 +                               goto done;
28571 +               }
28572                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
28573         }
28574         if (err)
28575 @@ -634,17 +647,19 @@ static int raw_bind(struct sock *sk, str
28576  {
28577         struct inet_sock *inet = inet_sk(sk);
28578         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
28579 +       struct nx_v4_sock_addr nsa = { 0 };
28580         int ret = -EINVAL;
28581         int chk_addr_ret;
28582  
28583         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
28584                 goto out;
28585 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
28586 +       v4_map_sock_addr(inet, addr, &nsa);
28587 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
28588         ret = -EADDRNOTAVAIL;
28589 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
28590 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
28591             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
28592                 goto out;
28593 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
28594 +       v4_set_sock_addr(inet, &nsa);
28595         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
28596                 inet->inet_saddr = 0;  /* Use device */
28597         sk_dst_reset(sk);
28598 @@ -696,7 +711,8 @@ static int raw_recvmsg(struct kiocb *ioc
28599         /* Copy the address. */
28600         if (sin) {
28601                 sin->sin_family = AF_INET;
28602 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
28603 +               sin->sin_addr.s_addr =
28604 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
28605                 sin->sin_port = 0;
28606                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
28607         }
28608 @@ -874,7 +890,8 @@ static struct sock *raw_get_first(struct
28609                 struct hlist_node *node;
28610  
28611                 sk_for_each(sk, node, &state->h->ht[state->bucket])
28612 -                       if (sock_net(sk) == seq_file_net(seq))
28613 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
28614 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28615                                 goto found;
28616         }
28617         sk = NULL;
28618 @@ -890,7 +907,8 @@ static struct sock *raw_get_next(struct 
28619                 sk = sk_next(sk);
28620  try_again:
28621                 ;
28622 -       } while (sk && sock_net(sk) != seq_file_net(seq));
28623 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
28624 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
28625  
28626         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
28627                 sk = sk_head(&state->h->ht[state->bucket]);
28628 @@ -949,7 +967,10 @@ static void raw_sock_seq_show(struct seq
28629  
28630         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
28631                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
28632 -               i, src, srcp, dest, destp, sp->sk_state,
28633 +               i,
28634 +               nx_map_sock_lback(current_nx_info(), src), srcp,
28635 +               nx_map_sock_lback(current_nx_info(), dest), destp,
28636 +               sp->sk_state,
28637                 sk_wmem_alloc_get(sp),
28638                 sk_rmem_alloc_get(sp),
28639                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
28640 diff -NurpP --minimal linux-2.6.33/net/ipv4/tcp.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/tcp.c
28641 --- linux-2.6.33/net/ipv4/tcp.c 2010-02-25 11:52:10.000000000 +0100
28642 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/tcp.c 2010-02-25 14:03:32.000000000 +0100
28643 @@ -265,6 +265,7 @@
28644  #include <linux/err.h>
28645  #include <linux/crypto.h>
28646  #include <linux/time.h>
28647 +#include <linux/in.h>
28648  
28649  #include <net/icmp.h>
28650  #include <net/tcp.h>
28651 diff -NurpP --minimal linux-2.6.33/net/ipv4/tcp_ipv4.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/tcp_ipv4.c
28652 --- linux-2.6.33/net/ipv4/tcp_ipv4.c    2010-02-25 11:52:10.000000000 +0100
28653 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/tcp_ipv4.c    2010-02-25 14:08:55.000000000 +0100
28654 @@ -1988,6 +1988,12 @@ static void *listening_get_next(struct s
28655                 req = req->dl_next;
28656                 while (1) {
28657                         while (req) {
28658 +                               vxdprintk(VXD_CBIT(net, 6),
28659 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
28660 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
28661 +                               if (req->sk &&
28662 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
28663 +                                       continue;
28664                                 if (req->rsk_ops->family == st->family) {
28665                                         cur = req;
28666                                         goto out;
28667 @@ -2012,6 +2018,10 @@ get_req:
28668         }
28669  get_sk:
28670         sk_nulls_for_each_from(sk, node) {
28671 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
28672 +                       sk, sk->sk_nid, nx_current_nid());
28673 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28674 +                       continue;
28675                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
28676                         cur = sk;
28677                         goto out;
28678 @@ -2075,6 +2085,11 @@ static void *established_get_first(struc
28679  
28680                 spin_lock_bh(lock);
28681                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
28682 +                       vxdprintk(VXD_CBIT(net, 6),
28683 +                               "sk,egf: %p [#%d] (from %d)",
28684 +                               sk, sk->sk_nid, nx_current_nid());
28685 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28686 +                               continue;
28687                         if (sk->sk_family != st->family ||
28688                             !net_eq(sock_net(sk), net)) {
28689                                 continue;
28690 @@ -2085,6 +2100,11 @@ static void *established_get_first(struc
28691                 st->state = TCP_SEQ_STATE_TIME_WAIT;
28692                 inet_twsk_for_each(tw, node,
28693                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
28694 +                       vxdprintk(VXD_CBIT(net, 6),
28695 +                               "tw: %p [#%d] (from %d)",
28696 +                               tw, tw->tw_nid, nx_current_nid());
28697 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
28698 +                               continue;
28699                         if (tw->tw_family != st->family ||
28700                             !net_eq(twsk_net(tw), net)) {
28701                                 continue;
28702 @@ -2113,7 +2133,9 @@ static void *established_get_next(struct
28703                 tw = cur;
28704                 tw = tw_next(tw);
28705  get_tw:
28706 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
28707 +               while (tw && (tw->tw_family != st->family ||
28708 +                       !net_eq(twsk_net(tw), net) ||
28709 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
28710                         tw = tw_next(tw);
28711                 }
28712                 if (tw) {
28713 @@ -2136,6 +2158,11 @@ get_tw:
28714                 sk = sk_nulls_next(sk);
28715  
28716         sk_nulls_for_each_from(sk, node) {
28717 +               vxdprintk(VXD_CBIT(net, 6),
28718 +                       "sk,egn: %p [#%d] (from %d)",
28719 +                       sk, sk->sk_nid, nx_current_nid());
28720 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28721 +                       continue;
28722                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
28723                         goto found;
28724         }
28725 @@ -2287,9 +2314,9 @@ static void get_openreq4(struct sock *sk
28726         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
28727                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
28728                 i,
28729 -               ireq->loc_addr,
28730 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
28731                 ntohs(inet_sk(sk)->inet_sport),
28732 -               ireq->rmt_addr,
28733 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
28734                 ntohs(ireq->rmt_port),
28735                 TCP_SYN_RECV,
28736                 0, 0, /* could print option size, but that is af dependent. */
28737 @@ -2341,7 +2368,10 @@ static void get_tcp4_sock(struct sock *s
28738  
28739         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
28740                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
28741 -               i, src, srcp, dest, destp, sk->sk_state,
28742 +               i,
28743 +               nx_map_sock_lback(current_nx_info(), src), srcp,
28744 +               nx_map_sock_lback(current_nx_info(), dest), destp,
28745 +               sk->sk_state,
28746                 tp->write_seq - tp->snd_una,
28747                 rx_queue,
28748                 timer_active,
28749 @@ -2376,7 +2406,10 @@ static void get_timewait4_sock(struct in
28750  
28751         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
28752                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
28753 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
28754 +               i,
28755 +               nx_map_sock_lback(current_nx_info(), src), srcp,
28756 +               nx_map_sock_lback(current_nx_info(), dest), destp,
28757 +               tw->tw_substate, 0, 0,
28758                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
28759                 atomic_read(&tw->tw_refcnt), tw, len);
28760  }
28761 diff -NurpP --minimal linux-2.6.33/net/ipv4/tcp_minisocks.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/tcp_minisocks.c
28762 --- linux-2.6.33/net/ipv4/tcp_minisocks.c       2010-02-25 11:52:10.000000000 +0100
28763 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/tcp_minisocks.c       2010-02-25 14:03:06.000000000 +0100
28764 @@ -22,6 +22,9 @@
28765  #include <linux/module.h>
28766  #include <linux/sysctl.h>
28767  #include <linux/workqueue.h>
28768 +#include <linux/vs_limit.h>
28769 +#include <linux/vs_socket.h>
28770 +#include <linux/vs_context.h>
28771  #include <net/tcp.h>
28772  #include <net/inet_common.h>
28773  #include <net/xfrm.h>
28774 @@ -289,6 +292,11 @@ void tcp_time_wait(struct sock *sk, int 
28775                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
28776                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
28777  
28778 +               tw->tw_xid              = sk->sk_xid;
28779 +               tw->tw_vx_info          = NULL;
28780 +               tw->tw_nid              = sk->sk_nid;
28781 +               tw->tw_nx_info          = NULL;
28782 +
28783  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
28784                 if (tw->tw_family == PF_INET6) {
28785                         struct ipv6_pinfo *np = inet6_sk(sk);
28786 diff -NurpP --minimal linux-2.6.33/net/ipv4/udp.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/udp.c
28787 --- linux-2.6.33/net/ipv4/udp.c 2010-02-25 11:52:10.000000000 +0100
28788 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv4/udp.c 2010-02-25 14:18:12.000000000 +0100
28789 @@ -294,14 +294,7 @@ fail:
28790  }
28791  EXPORT_SYMBOL(udp_lib_get_port);
28792  
28793 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
28794 -{
28795 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
28796 -
28797 -       return  (!ipv6_only_sock(sk2)  &&
28798 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
28799 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
28800 -}
28801 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
28802  
28803  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
28804                                        unsigned int port)
28805 @@ -336,6 +329,11 @@ static inline int compute_score(struct s
28806                         if (inet->inet_rcv_saddr != daddr)
28807                                 return -1;
28808                         score += 2;
28809 +               } else {
28810 +                       /* block non nx_info ips */
28811 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
28812 +                               daddr, NXA_MASK_BIND))
28813 +                               return -1;
28814                 }
28815                 if (inet->inet_daddr) {
28816                         if (inet->inet_daddr != saddr)
28817 @@ -439,6 +437,7 @@ exact_match:
28818         return result;
28819  }
28820  
28821 +
28822  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
28823   * harder than this. -DaveM
28824   */
28825 @@ -484,6 +483,11 @@ begin:
28826         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
28827                 score = compute_score(sk, net, saddr, hnum, sport,
28828                                       daddr, dport, dif);
28829 +               /* FIXME: disabled?
28830 +               if (score == 9) {
28831 +                       result = sk;
28832 +                       break;
28833 +               } else */
28834                 if (score > badness) {
28835                         result = sk;
28836                         badness = score;
28837 @@ -497,6 +501,7 @@ begin:
28838         if (get_nulls_value(node) != slot)
28839                 goto begin;
28840  
28841 +
28842         if (result) {
28843                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
28844                         result = NULL;
28845 @@ -506,6 +511,7 @@ begin:
28846                         goto begin;
28847                 }
28848         }
28849 +
28850         rcu_read_unlock();
28851         return result;
28852  }
28853 @@ -548,8 +554,7 @@ static inline struct sock *udp_v4_mcast_
28854                     udp_sk(s)->udp_port_hash != hnum ||
28855                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
28856                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
28857 -                   (inet->inet_rcv_saddr &&
28858 -                    inet->inet_rcv_saddr != loc_addr) ||
28859 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
28860                     ipv6_only_sock(s) ||
28861                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
28862                         continue;
28863 @@ -898,8 +903,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
28864                                                { .sport = inet->inet_sport,
28865                                                  .dport = dport } } };
28866                 struct net *net = sock_net(sk);
28867 +               struct nx_info *nxi = sk->sk_nx_info;
28868  
28869                 security_sk_classify_flow(sk, &fl);
28870 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
28871 +               if (err)
28872 +                       goto out;
28873 +
28874                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
28875                 if (err) {
28876                         if (err == -ENETUNREACH)
28877 @@ -1180,7 +1190,8 @@ try_again:
28878         if (sin) {
28879                 sin->sin_family = AF_INET;
28880                 sin->sin_port = udp_hdr(skb)->source;
28881 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
28882 +               sin->sin_addr.s_addr = nx_map_sock_lback(
28883 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
28884                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
28885         }
28886         if (inet->cmsg_flags)
28887 @@ -1865,6 +1876,8 @@ static struct sock *udp_get_first(struct
28888                 sk_nulls_for_each(sk, node, &hslot->head) {
28889                         if (!net_eq(sock_net(sk), net))
28890                                 continue;
28891 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28892 +                               continue;
28893                         if (sk->sk_family == state->family)
28894                                 goto found;
28895                 }
28896 @@ -1882,7 +1895,9 @@ static struct sock *udp_get_next(struct 
28897  
28898         do {
28899                 sk = sk_nulls_next(sk);
28900 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
28901 +       } while (sk && (!net_eq(sock_net(sk), net) ||
28902 +               sk->sk_family != state->family ||
28903 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
28904  
28905         if (!sk) {
28906                 if (state->bucket <= state->udp_table->mask)
28907 @@ -1989,7 +2004,10 @@ static void udp4_format_sock(struct sock
28908  
28909         seq_printf(f, "%5d: %08X:%04X %08X:%04X"
28910                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
28911 -               bucket, src, srcp, dest, destp, sp->sk_state,
28912 +               bucket,
28913 +               nx_map_sock_lback(current_nx_info(), src), srcp,
28914 +               nx_map_sock_lback(current_nx_info(), dest), destp,
28915 +               sp->sk_state,
28916                 sk_wmem_alloc_get(sp),
28917                 sk_rmem_alloc_get(sp),
28918                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
28919 diff -NurpP --minimal linux-2.6.33/net/ipv6/addrconf.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/addrconf.c
28920 --- linux-2.6.33/net/ipv6/addrconf.c    2010-02-25 11:52:10.000000000 +0100
28921 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/addrconf.c    2010-02-25 13:40:38.000000000 +0100
28922 @@ -86,6 +86,8 @@
28923  
28924  #include <linux/proc_fs.h>
28925  #include <linux/seq_file.h>
28926 +#include <linux/vs_network.h>
28927 +#include <linux/vs_inet6.h>
28928  
28929  /* Set to 3 to get tracing... */
28930  #define ACONF_DEBUG 2
28931 @@ -1120,7 +1122,7 @@ out:
28932  
28933  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
28934                        const struct in6_addr *daddr, unsigned int prefs,
28935 -                      struct in6_addr *saddr)
28936 +                      struct in6_addr *saddr, struct nx_info *nxi)
28937  {
28938         struct ipv6_saddr_score scores[2],
28939                                 *score = &scores[0], *hiscore = &scores[1];
28940 @@ -1192,6 +1194,8 @@ int ipv6_dev_get_saddr(struct net *net, 
28941                                                dev->name);
28942                                 continue;
28943                         }
28944 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
28945 +                               continue;
28946  
28947                         score->rule = -1;
28948                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
28949 @@ -2999,7 +3003,10 @@ static void if6_seq_stop(struct seq_file
28950  static int if6_seq_show(struct seq_file *seq, void *v)
28951  {
28952         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
28953 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
28954 +
28955 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
28956 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
28957 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
28958                    &ifp->addr,
28959                    ifp->idev->dev->ifindex,
28960                    ifp->prefix_len,
28961 @@ -3494,6 +3501,11 @@ static int in6_dump_addrs(struct inet6_d
28962         struct ifacaddr6 *ifaca;
28963         int err = 1;
28964         int ip_idx = *p_ip_idx;
28965 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
28966 +
28967 +       /* disable ipv6 on non v6 guests */
28968 +       if (nxi && !nx_info_has_v6(nxi))
28969 +               return skb->len;
28970  
28971         read_lock_bh(&idev->lock);
28972         switch (type) {
28973 @@ -3503,6 +3515,8 @@ static int in6_dump_addrs(struct inet6_d
28974                      ifa = ifa->if_next, ip_idx++) {
28975                         if (ip_idx < s_ip_idx)
28976                                 continue;
28977 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
28978 +                                       continue;
28979                         err = inet6_fill_ifaddr(skb, ifa,
28980                                                 NETLINK_CB(cb->skb).pid,
28981                                                 cb->nlh->nlmsg_seq,
28982 @@ -3518,6 +3532,8 @@ static int in6_dump_addrs(struct inet6_d
28983                      ifmca = ifmca->next, ip_idx++) {
28984                         if (ip_idx < s_ip_idx)
28985                                 continue;
28986 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
28987 +                                       continue;
28988                         err = inet6_fill_ifmcaddr(skb, ifmca,
28989                                                   NETLINK_CB(cb->skb).pid,
28990                                                   cb->nlh->nlmsg_seq,
28991 @@ -3533,6 +3549,8 @@ static int in6_dump_addrs(struct inet6_d
28992                      ifaca = ifaca->aca_next, ip_idx++) {
28993                         if (ip_idx < s_ip_idx)
28994                                 continue;
28995 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
28996 +                                       continue;
28997                         err = inet6_fill_ifacaddr(skb, ifaca,
28998                                                   NETLINK_CB(cb->skb).pid,
28999                                                   cb->nlh->nlmsg_seq,
29000 @@ -3861,6 +3879,11 @@ static int inet6_dump_ifinfo(struct sk_b
29001         struct inet6_dev *idev;
29002         struct hlist_head *head;
29003         struct hlist_node *node;
29004 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29005 +
29006 +       /* FIXME: maybe disable ipv6 on non v6 guests?
29007 +       if (skb->sk && skb->sk->sk_vx_info)
29008 +               return skb->len; */
29009  
29010         s_h = cb->args[0];
29011         s_idx = cb->args[1];
29012 @@ -3872,6 +3895,8 @@ static int inet6_dump_ifinfo(struct sk_b
29013                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
29014                         if (idx < s_idx)
29015                                 goto cont;
29016 +                       if (!v6_dev_in_nx_info(dev, nxi))
29017 +                               goto cont;
29018                         idev = __in6_dev_get(dev);
29019                         if (!idev)
29020                                 goto cont;
29021 diff -NurpP --minimal linux-2.6.33/net/ipv6/af_inet6.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/af_inet6.c
29022 --- linux-2.6.33/net/ipv6/af_inet6.c    2010-02-25 11:52:10.000000000 +0100
29023 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/af_inet6.c    2010-02-25 15:54:53.000000000 +0100
29024 @@ -41,6 +41,8 @@
29025  #include <linux/netdevice.h>
29026  #include <linux/icmpv6.h>
29027  #include <linux/netfilter_ipv6.h>
29028 +#include <linux/vs_inet.h>
29029 +#include <linux/vs_inet6.h>
29030  
29031  #include <net/ip.h>
29032  #include <net/ipv6.h>
29033 @@ -159,9 +161,12 @@ lookup_protocol:
29034         }
29035  
29036         err = -EPERM;
29037 +       if ((protocol == IPPROTO_ICMPV6) &&
29038 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
29039 +               goto override;
29040         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
29041                 goto out_rcu_unlock;
29042 -
29043 +override:
29044         sock->ops = answer->ops;
29045         answer_prot = answer->prot;
29046         answer_no_check = answer->no_check;
29047 @@ -260,6 +265,7 @@ int inet6_bind(struct socket *sock, stru
29048         struct inet_sock *inet = inet_sk(sk);
29049         struct ipv6_pinfo *np = inet6_sk(sk);
29050         struct net *net = sock_net(sk);
29051 +       struct nx_v6_sock_addr nsa;
29052         __be32 v4addr = 0;
29053         unsigned short snum;
29054         int addr_type = 0;
29055 @@ -271,6 +277,11 @@ int inet6_bind(struct socket *sock, stru
29056  
29057         if (addr_len < SIN6_LEN_RFC2133)
29058                 return -EINVAL;
29059 +
29060 +       err = v6_map_sock_addr(inet, addr, &nsa);
29061 +       if (err)
29062 +               return err;
29063 +
29064         addr_type = ipv6_addr_type(&addr->sin6_addr);
29065         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
29066                 return -EINVAL;
29067 @@ -302,6 +313,7 @@ int inet6_bind(struct socket *sock, stru
29068                 /* Reproduce AF_INET checks to make the bindings consitant */
29069                 v4addr = addr->sin6_addr.s6_addr32[3];
29070                 chk_addr_ret = inet_addr_type(net, v4addr);
29071 +
29072                 if (!sysctl_ip_nonlocal_bind &&
29073                     !(inet->freebind || inet->transparent) &&
29074                     v4addr != htonl(INADDR_ANY) &&
29075 @@ -311,6 +323,10 @@ int inet6_bind(struct socket *sock, stru
29076                         err = -EADDRNOTAVAIL;
29077                         goto out;
29078                 }
29079 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
29080 +                       err = -EADDRNOTAVAIL;
29081 +                       goto out;
29082 +               }
29083         } else {
29084                 if (addr_type != IPV6_ADDR_ANY) {
29085                         struct net_device *dev = NULL;
29086 @@ -337,6 +353,11 @@ int inet6_bind(struct socket *sock, stru
29087                                 }
29088                         }
29089  
29090 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
29091 +                               err = -EADDRNOTAVAIL;
29092 +                               goto out;
29093 +                       }
29094 +
29095                         /* ipv4 addr of the socket is invalid.  Only the
29096                          * unspecified and mapped address have a v4 equivalent.
29097                          */
29098 @@ -352,6 +373,9 @@ int inet6_bind(struct socket *sock, stru
29099                 }
29100         }
29101  
29102 +       /* what's that for? */
29103 +       v6_set_sock_addr(inet, &nsa);
29104 +
29105         inet->inet_rcv_saddr = v4addr;
29106         inet->inet_saddr = v4addr;
29107  
29108 @@ -450,9 +474,11 @@ int inet6_getname(struct socket *sock, s
29109                         return -ENOTCONN;
29110                 sin->sin6_port = inet->inet_dport;
29111                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
29112 +               /* FIXME: remap lback? */
29113                 if (np->sndflow)
29114                         sin->sin6_flowinfo = np->flow_label;
29115         } else {
29116 +               /* FIXME: remap lback? */
29117                 if (ipv6_addr_any(&np->rcv_saddr))
29118                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
29119                 else
29120 diff -NurpP --minimal linux-2.6.33/net/ipv6/fib6_rules.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/fib6_rules.c
29121 --- linux-2.6.33/net/ipv6/fib6_rules.c  2010-02-25 11:52:10.000000000 +0100
29122 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/fib6_rules.c  2010-02-25 12:02:16.000000000 +0100
29123 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
29124                         if (ipv6_dev_get_saddr(net,
29125                                                ip6_dst_idev(&rt->u.dst)->dev,
29126                                                &flp->fl6_dst, srcprefs,
29127 -                                              &saddr))
29128 +                                              &saddr, NULL))
29129                                 goto again;
29130                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
29131                                                r->src.plen))
29132 diff -NurpP --minimal linux-2.6.33/net/ipv6/inet6_hashtables.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/inet6_hashtables.c
29133 --- linux-2.6.33/net/ipv6/inet6_hashtables.c    2010-02-25 11:52:10.000000000 +0100
29134 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/inet6_hashtables.c    2010-02-25 12:02:16.000000000 +0100
29135 @@ -16,6 +16,7 @@
29136  
29137  #include <linux/module.h>
29138  #include <linux/random.h>
29139 +#include <linux/vs_inet6.h>
29140  
29141  #include <net/inet_connection_sock.h>
29142  #include <net/inet_hashtables.h>
29143 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
29144         unsigned int slot = hash & hashinfo->ehash_mask;
29145         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
29146  
29147 -
29148         rcu_read_lock();
29149  begin:
29150         sk_nulls_for_each_rcu(sk, node, &head->chain) {
29151 @@ -94,7 +94,7 @@ begin:
29152                                 sock_put(sk);
29153                                 goto begin;
29154                         }
29155 -               goto out;
29156 +                       goto out;
29157                 }
29158         }
29159         if (get_nulls_value(node) != slot)
29160 @@ -140,6 +140,9 @@ static int inline compute_score(struct s
29161                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29162                                 return -1;
29163                         score++;
29164 +               } else {
29165 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29166 +                               return -1;
29167                 }
29168                 if (sk->sk_bound_dev_if) {
29169                         if (sk->sk_bound_dev_if != dif)
29170 diff -NurpP --minimal linux-2.6.33/net/ipv6/ip6_output.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/ip6_output.c
29171 --- linux-2.6.33/net/ipv6/ip6_output.c  2010-02-25 11:52:10.000000000 +0100
29172 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/ip6_output.c  2010-02-25 12:02:16.000000000 +0100
29173 @@ -933,7 +933,7 @@ static int ip6_dst_lookup_tail(struct so
29174                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
29175                                          &fl->fl6_dst,
29176                                          sk ? inet6_sk(sk)->srcprefs : 0,
29177 -                                        &fl->fl6_src);
29178 +                                        &fl->fl6_src, sk->sk_nx_info);
29179                 if (err)
29180                         goto out_err_release;
29181         }
29182 diff -NurpP --minimal linux-2.6.33/net/ipv6/Kconfig linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/Kconfig
29183 --- linux-2.6.33/net/ipv6/Kconfig       2010-02-25 11:52:10.000000000 +0100
29184 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/Kconfig       2010-02-25 12:02:16.000000000 +0100
29185 @@ -4,8 +4,8 @@
29186  
29187  #   IPv6 as module will cause a CRASH if you try to unload it
29188  menuconfig IPV6
29189 -       tristate "The IPv6 protocol"
29190 -       default m
29191 +       bool "The IPv6 protocol"
29192 +       default n
29193         ---help---
29194           This is complemental support for the IP version 6.
29195           You will still be able to do traditional IPv4 networking as well.
29196 diff -NurpP --minimal linux-2.6.33/net/ipv6/ndisc.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/ndisc.c
29197 --- linux-2.6.33/net/ipv6/ndisc.c       2010-02-25 11:52:10.000000000 +0100
29198 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/ndisc.c       2010-02-25 12:02:16.000000000 +0100
29199 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
29200         } else {
29201                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
29202                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
29203 -                                      &tmpaddr))
29204 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
29205                         return;
29206                 src_addr = &tmpaddr;
29207         }
29208 diff -NurpP --minimal linux-2.6.33/net/ipv6/raw.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/raw.c
29209 --- linux-2.6.33/net/ipv6/raw.c 2010-02-25 11:52:11.000000000 +0100
29210 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/raw.c 2010-02-25 12:02:16.000000000 +0100
29211 @@ -29,6 +29,7 @@
29212  #include <linux/icmpv6.h>
29213  #include <linux/netfilter.h>
29214  #include <linux/netfilter_ipv6.h>
29215 +#include <linux/vs_inet6.h>
29216  #include <linux/skbuff.h>
29217  #include <asm/uaccess.h>
29218  #include <asm/ioctls.h>
29219 @@ -282,6 +283,13 @@ static int rawv6_bind(struct sock *sk, s
29220                                 goto out_unlock;
29221                 }
29222  
29223 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
29224 +                       err = -EADDRNOTAVAIL;
29225 +                       if (dev)
29226 +                               dev_put(dev);
29227 +                       goto out;
29228 +               }
29229 +
29230                 /* ipv4 addr of the socket is invalid.  Only the
29231                  * unspecified and mapped address have a v4 equivalent.
29232                  */
29233 diff -NurpP --minimal linux-2.6.33/net/ipv6/route.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/route.c
29234 --- linux-2.6.33/net/ipv6/route.c       2010-02-25 11:52:11.000000000 +0100
29235 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/route.c       2010-02-25 12:02:16.000000000 +0100
29236 @@ -2258,7 +2258,8 @@ static int rt6_fill_node(struct net *net
29237                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
29238                 struct in6_addr saddr_buf;
29239                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
29240 -                                      dst, 0, &saddr_buf) == 0)
29241 +                       dst, 0, &saddr_buf,
29242 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
29243                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
29244         }
29245  
29246 diff -NurpP --minimal linux-2.6.33/net/ipv6/tcp_ipv6.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/tcp_ipv6.c
29247 --- linux-2.6.33/net/ipv6/tcp_ipv6.c    2010-02-25 11:52:11.000000000 +0100
29248 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/tcp_ipv6.c    2010-02-25 12:02:16.000000000 +0100
29249 @@ -68,6 +68,7 @@
29250  
29251  #include <linux/crypto.h>
29252  #include <linux/scatterlist.h>
29253 +#include <linux/vs_inet6.h>
29254  
29255  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
29256  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
29257 @@ -156,8 +157,15 @@ static int tcp_v6_connect(struct sock *s
29258          *      connect() to INADDR_ANY means loopback (BSD'ism).
29259          */
29260  
29261 -       if(ipv6_addr_any(&usin->sin6_addr))
29262 -               usin->sin6_addr.s6_addr[15] = 0x1;
29263 +       if(ipv6_addr_any(&usin->sin6_addr)) {
29264 +               struct nx_info *nxi =  sk->sk_nx_info;
29265 +
29266 +               if (nxi && nx_info_has_v6(nxi))
29267 +                       /* FIXME: remap lback? */
29268 +                       usin->sin6_addr = nxi->v6.ip;
29269 +               else
29270 +                       usin->sin6_addr.s6_addr[15] = 0x1;
29271 +       }
29272  
29273         addr_type = ipv6_addr_type(&usin->sin6_addr);
29274  
29275 diff -NurpP --minimal linux-2.6.33/net/ipv6/udp.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/udp.c
29276 --- linux-2.6.33/net/ipv6/udp.c 2010-02-25 11:52:11.000000000 +0100
29277 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/udp.c 2010-02-25 15:58:22.000000000 +0100
29278 @@ -47,13 +47,14 @@
29279  
29280  #include <linux/proc_fs.h>
29281  #include <linux/seq_file.h>
29282 +#include <linux/vs_inet6.h>
29283  #include "udp_impl.h"
29284  
29285  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
29286  {
29287         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
29288         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
29289 -       __be32 sk1_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
29290 +       __be32 sk_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
29291         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
29292         int sk_ipv6only = ipv6_only_sock(sk);
29293         int sk2_ipv6only = inet_v6_ipv6only(sk2);
29294 @@ -61,24 +62,49 @@ int ipv6_rcv_saddr_equal(const struct so
29295         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
29296  
29297         /* if both are mapped, treat as IPv4 */
29298 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
29299 -               return (!sk2_ipv6only &&
29300 -                       (!sk1_rcv_saddr || !sk2_rcv_saddr ||
29301 -                         sk1_rcv_saddr == sk2_rcv_saddr));
29302 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
29303 +               if (!sk2_ipv6only &&
29304 +                       (!sk_rcv_saddr || !sk2_rcv_saddr ||
29305 +                         sk_rcv_saddr == sk2_rcv_saddr))
29306 +                       goto vs_v4;
29307 +               else
29308 +                       return 0;
29309 +       }
29310  
29311         if (addr_type2 == IPV6_ADDR_ANY &&
29312             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
29313 -               return 1;
29314 +               goto vs;
29315  
29316         if (addr_type == IPV6_ADDR_ANY &&
29317             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
29318 -               return 1;
29319 +               goto vs;
29320  
29321         if (sk2_rcv_saddr6 &&
29322             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
29323 -               return 1;
29324 +               goto vs;
29325  
29326         return 0;
29327 +
29328 +vs_v4:
29329 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
29330 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
29331 +       if (!sk2_rcv_saddr)
29332 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
29333 +       if (!sk_rcv_saddr)
29334 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
29335 +       return 1;
29336 +vs:
29337 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
29338 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
29339 +       else if (addr_type2 == IPV6_ADDR_ANY)
29340 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
29341 +       else if (addr_type == IPV6_ADDR_ANY) {
29342 +               if (addr_type2 == IPV6_ADDR_MAPPED)
29343 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
29344 +               else
29345 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
29346 +       }
29347 +       return 1;
29348  }
29349  
29350  static unsigned int udp6_portaddr_hash(struct net *net,
29351 @@ -133,6 +159,10 @@ static inline int compute_score(struct s
29352                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29353                                 return -1;
29354                         score++;
29355 +               } else {
29356 +                       /* block non nx_info ips */
29357 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29358 +                               return -1;
29359                 }
29360                 if (!ipv6_addr_any(&np->daddr)) {
29361                         if (!ipv6_addr_equal(&np->daddr, saddr))
29362 diff -NurpP --minimal linux-2.6.33/net/ipv6/xfrm6_policy.c linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/xfrm6_policy.c
29363 --- linux-2.6.33/net/ipv6/xfrm6_policy.c        2010-02-25 11:52:11.000000000 +0100
29364 +++ linux-2.6.33-vs2.3.0.36.30.1/net/ipv6/xfrm6_policy.c        2010-02-25 12:02:16.000000000 +0100
29365 @@ -62,7 +62,7 @@ static int xfrm6_get_saddr(struct net *n
29366         dev = ip6_dst_idev(dst)->dev;
29367         ipv6_dev_get_saddr(dev_net(dev), dev,
29368                            (struct in6_addr *)&daddr->a6, 0,
29369 -                          (struct in6_addr *)&saddr->a6);
29370 +                          (struct in6_addr *)&saddr->a6, NULL);
29371         dst_release(dst);
29372         return 0;
29373  }
29374 diff -NurpP --minimal linux-2.6.33/net/netlink/af_netlink.c linux-2.6.33-vs2.3.0.36.30.1/net/netlink/af_netlink.c
29375 --- linux-2.6.33/net/netlink/af_netlink.c       2010-02-25 11:52:11.000000000 +0100
29376 +++ linux-2.6.33-vs2.3.0.36.30.1/net/netlink/af_netlink.c       2010-02-25 12:02:16.000000000 +0100
29377 @@ -55,6 +55,9 @@
29378  #include <linux/types.h>
29379  #include <linux/audit.h>
29380  #include <linux/mutex.h>
29381 +#include <linux/vs_context.h>
29382 +#include <linux/vs_network.h>
29383 +#include <linux/vs_limit.h>
29384  
29385  #include <net/net_namespace.h>
29386  #include <net/sock.h>
29387 @@ -1905,6 +1908,8 @@ static struct sock *netlink_seq_socket_i
29388                         sk_for_each(s, node, &hash->table[j]) {
29389                                 if (sock_net(s) != seq_file_net(seq))
29390                                         continue;
29391 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
29392 +                                       continue;
29393                                 if (off == pos) {
29394                                         iter->link = i;
29395                                         iter->hash_idx = j;
29396 @@ -1939,7 +1944,8 @@ static void *netlink_seq_next(struct seq
29397         s = v;
29398         do {
29399                 s = sk_next(s);
29400 -       } while (s && sock_net(s) != seq_file_net(seq));
29401 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
29402 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
29403         if (s)
29404                 return s;
29405  
29406 @@ -1951,7 +1957,8 @@ static void *netlink_seq_next(struct seq
29407  
29408                 for (; j <= hash->mask; j++) {
29409                         s = sk_head(&hash->table[j]);
29410 -                       while (s && sock_net(s) != seq_file_net(seq))
29411 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
29412 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
29413                                 s = sk_next(s);
29414                         if (s) {
29415                                 iter->link = i;
29416 diff -NurpP --minimal linux-2.6.33/net/sctp/ipv6.c linux-2.6.33-vs2.3.0.36.30.1/net/sctp/ipv6.c
29417 --- linux-2.6.33/net/sctp/ipv6.c        2010-02-25 11:52:12.000000000 +0100
29418 +++ linux-2.6.33-vs2.3.0.36.30.1/net/sctp/ipv6.c        2010-02-25 12:02:16.000000000 +0100
29419 @@ -316,7 +316,8 @@ static void sctp_v6_get_saddr(struct sct
29420                                    dst ? ip6_dst_idev(dst)->dev : NULL,
29421                                    &daddr->v6.sin6_addr,
29422                                    inet6_sk(&sk->inet.sk)->srcprefs,
29423 -                                  &saddr->v6.sin6_addr);
29424 +                                  &saddr->v6.sin6_addr,
29425 +                                  asoc->base.sk->sk_nx_info);
29426                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
29427                                   &saddr->v6.sin6_addr);
29428                 return;
29429 diff -NurpP --minimal linux-2.6.33/net/socket.c linux-2.6.33-vs2.3.0.36.30.1/net/socket.c
29430 --- linux-2.6.33/net/socket.c   2010-02-25 11:52:12.000000000 +0100
29431 +++ linux-2.6.33-vs2.3.0.36.30.1/net/socket.c   2010-02-25 13:51:25.000000000 +0100
29432 @@ -96,6 +96,10 @@
29433  
29434  #include <net/sock.h>
29435  #include <linux/netfilter.h>
29436 +#include <linux/vs_base.h>
29437 +#include <linux/vs_socket.h>
29438 +#include <linux/vs_inet.h>
29439 +#include <linux/vs_inet6.h>
29440  
29441  #include <linux/if_tun.h>
29442  #include <linux/ipv6_route.h>
29443 @@ -539,7 +543,7 @@ static inline int __sock_sendmsg(struct 
29444                                  struct msghdr *msg, size_t size)
29445  {
29446         struct sock_iocb *si = kiocb_to_siocb(iocb);
29447 -       int err;
29448 +       int err, len;
29449  
29450         si->sock = sock;
29451         si->scm = NULL;
29452 @@ -550,7 +554,22 @@ static inline int __sock_sendmsg(struct 
29453         if (err)
29454                 return err;
29455  
29456 -       return sock->ops->sendmsg(iocb, sock, msg, size);
29457 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
29458 +       if (sock->sk) {
29459 +               if (len == size)
29460 +                       vx_sock_send(sock->sk, size);
29461 +               else
29462 +                       vx_sock_fail(sock->sk, size);
29463 +       }
29464 +       vxdprintk(VXD_CBIT(net, 7),
29465 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29466 +               sock, sock->sk,
29467 +               (sock->sk)?sock->sk->sk_nx_info:0,
29468 +               (sock->sk)?sock->sk->sk_vx_info:0,
29469 +               (sock->sk)?sock->sk->sk_xid:0,
29470 +               (sock->sk)?sock->sk->sk_nid:0,
29471 +               (unsigned int)size, len);
29472 +       return len;
29473  }
29474  
29475  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
29476 @@ -667,6 +686,7 @@ static inline int __sock_recvmsg_nosec(s
29477                                        struct msghdr *msg, size_t size, int flags)
29478  {
29479         struct sock_iocb *si = kiocb_to_siocb(iocb);
29480 +       int len;
29481  
29482         si->sock = sock;
29483         si->scm = NULL;
29484 @@ -674,7 +694,18 @@ static inline int __sock_recvmsg_nosec(s
29485         si->size = size;
29486         si->flags = flags;
29487  
29488 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
29489 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
29490 +       if ((len >= 0) && sock->sk)
29491 +               vx_sock_recv(sock->sk, len);
29492 +       vxdprintk(VXD_CBIT(net, 7),
29493 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29494 +               sock, sock->sk,
29495 +               (sock->sk)?sock->sk->sk_nx_info:0,
29496 +               (sock->sk)?sock->sk->sk_vx_info:0,
29497 +               (sock->sk)?sock->sk->sk_xid:0,
29498 +               (sock->sk)?sock->sk->sk_nid:0,
29499 +               (unsigned int)size, len);
29500 +       return len;
29501  }
29502  
29503  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
29504 @@ -1182,6 +1213,13 @@ static int __sock_create(struct net *net
29505         if (type < 0 || type >= SOCK_MAX)
29506                 return -EINVAL;
29507  
29508 +       if (!nx_check(0, VS_ADMIN)) {
29509 +               if (family == PF_INET && !current_nx_info_has_v4())
29510 +                       return -EAFNOSUPPORT;
29511 +               if (family == PF_INET6 && !current_nx_info_has_v6())
29512 +                       return -EAFNOSUPPORT;
29513 +       }
29514 +
29515         /* Compatibility.
29516  
29517            This uglymoron is moved from INET layer to here to avoid
29518 @@ -1314,6 +1352,7 @@ SYSCALL_DEFINE3(socket, int, family, int
29519         if (retval < 0)
29520                 goto out;
29521  
29522 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
29523         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
29524         if (retval < 0)
29525                 goto out_release;
29526 @@ -1355,10 +1394,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
29527         err = sock_create(family, type, protocol, &sock1);
29528         if (err < 0)
29529                 goto out;
29530 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
29531  
29532         err = sock_create(family, type, protocol, &sock2);
29533         if (err < 0)
29534                 goto out_release_1;
29535 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
29536  
29537         err = sock1->ops->socketpair(sock1, sock2);
29538         if (err < 0)
29539 diff -NurpP --minimal linux-2.6.33/net/sunrpc/auth.c linux-2.6.33-vs2.3.0.36.30.1/net/sunrpc/auth.c
29540 --- linux-2.6.33/net/sunrpc/auth.c      2010-02-25 11:52:12.000000000 +0100
29541 +++ linux-2.6.33-vs2.3.0.36.30.1/net/sunrpc/auth.c      2010-02-25 12:02:16.000000000 +0100
29542 @@ -14,6 +14,7 @@
29543  #include <linux/hash.h>
29544  #include <linux/sunrpc/clnt.h>
29545  #include <linux/spinlock.h>
29546 +#include <linux/vs_tag.h>
29547  
29548  #ifdef RPC_DEBUG
29549  # define RPCDBG_FACILITY       RPCDBG_AUTH
29550 @@ -363,6 +364,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
29551         memset(&acred, 0, sizeof(acred));
29552         acred.uid = cred->fsuid;
29553         acred.gid = cred->fsgid;
29554 +       acred.tag = dx_current_tag();
29555         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
29556  
29557         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
29558 @@ -403,6 +405,7 @@ rpcauth_bind_root_cred(struct rpc_task *
29559         struct auth_cred acred = {
29560                 .uid = 0,
29561                 .gid = 0,
29562 +               .tag = dx_current_tag(),
29563         };
29564         struct rpc_cred *ret;
29565  
29566 diff -NurpP --minimal linux-2.6.33/net/sunrpc/auth_unix.c linux-2.6.33-vs2.3.0.36.30.1/net/sunrpc/auth_unix.c
29567 --- linux-2.6.33/net/sunrpc/auth_unix.c 2008-12-25 00:26:37.000000000 +0100
29568 +++ linux-2.6.33-vs2.3.0.36.30.1/net/sunrpc/auth_unix.c 2010-02-25 12:02:16.000000000 +0100
29569 @@ -11,12 +11,14 @@
29570  #include <linux/module.h>
29571  #include <linux/sunrpc/clnt.h>
29572  #include <linux/sunrpc/auth.h>
29573 +#include <linux/vs_tag.h>
29574  
29575  #define NFS_NGROUPS    16
29576  
29577  struct unx_cred {
29578         struct rpc_cred         uc_base;
29579         gid_t                   uc_gid;
29580 +       tag_t                   uc_tag;
29581         gid_t                   uc_gids[NFS_NGROUPS];
29582  };
29583  #define uc_uid                 uc_base.cr_uid
29584 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
29585                 groups = NFS_NGROUPS;
29586  
29587         cred->uc_gid = acred->gid;
29588 +       cred->uc_tag = acred->tag;
29589         for (i = 0; i < groups; i++)
29590                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
29591         if (i < NFS_NGROUPS)
29592 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
29593         unsigned int i;
29594  
29595  
29596 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
29597 +       if (cred->uc_uid != acred->uid ||
29598 +               cred->uc_gid != acred->gid ||
29599 +               cred->uc_tag != acred->tag)
29600                 return 0;
29601  
29602         if (acred->group_info != NULL)
29603 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
29604         struct rpc_clnt *clnt = task->tk_client;
29605         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
29606         __be32          *base, *hold;
29607 -       int             i;
29608 +       int             i, tag;
29609  
29610         *p++ = htonl(RPC_AUTH_UNIX);
29611         base = p++;
29612 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
29613          * Copy the UTS nodename captured when the client was created.
29614          */
29615         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
29616 +       tag = task->tk_client->cl_tag;
29617  
29618 -       *p++ = htonl((u32) cred->uc_uid);
29619 -       *p++ = htonl((u32) cred->uc_gid);
29620 +       *p++ = htonl((u32) TAGINO_UID(tag,
29621 +               cred->uc_uid, cred->uc_tag));
29622 +       *p++ = htonl((u32) TAGINO_GID(tag,
29623 +               cred->uc_gid, cred->uc_tag));
29624         hold = p++;
29625         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
29626                 *p++ = htonl((u32) cred->uc_gids[i]);
29627 diff -NurpP --minimal linux-2.6.33/net/sunrpc/clnt.c linux-2.6.33-vs2.3.0.36.30.1/net/sunrpc/clnt.c
29628 --- linux-2.6.33/net/sunrpc/clnt.c      2010-02-25 11:52:12.000000000 +0100
29629 +++ linux-2.6.33-vs2.3.0.36.30.1/net/sunrpc/clnt.c      2010-02-25 12:02:16.000000000 +0100
29630 @@ -33,6 +33,7 @@
29631  #include <linux/utsname.h>
29632  #include <linux/workqueue.h>
29633  #include <linux/in6.h>
29634 +#include <linux/vs_cvirt.h>
29635  
29636  #include <linux/sunrpc/clnt.h>
29637  #include <linux/sunrpc/rpc_pipe_fs.h>
29638 @@ -358,6 +359,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
29639         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
29640                 clnt->cl_chatty = 1;
29641  
29642 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
29643 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
29644 +               clnt->cl_tag = 1; */
29645         return clnt;
29646  }
29647  EXPORT_SYMBOL_GPL(rpc_create);
29648 diff -NurpP --minimal linux-2.6.33/net/unix/af_unix.c linux-2.6.33-vs2.3.0.36.30.1/net/unix/af_unix.c
29649 --- linux-2.6.33/net/unix/af_unix.c     2010-02-25 11:52:12.000000000 +0100
29650 +++ linux-2.6.33-vs2.3.0.36.30.1/net/unix/af_unix.c     2010-02-25 12:02:16.000000000 +0100
29651 @@ -114,6 +114,8 @@
29652  #include <linux/mount.h>
29653  #include <net/checksum.h>
29654  #include <linux/security.h>
29655 +#include <linux/vs_context.h>
29656 +#include <linux/vs_limit.h>
29657  
29658  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
29659  static DEFINE_SPINLOCK(unix_table_lock);
29660 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
29661                 if (!net_eq(sock_net(s), net))
29662                         continue;
29663  
29664 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
29665 +                       continue;
29666                 if (u->addr->len == len &&
29667                     !memcmp(u->addr->name, sunname, len))
29668                         goto found;
29669 @@ -2115,6 +2119,8 @@ static struct sock *unix_seq_idx(struct 
29670         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
29671                 if (sock_net(s) != seq_file_net(seq))
29672                         continue;
29673 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
29674 +                       continue;
29675                 if (off == pos)
29676                         return s;
29677                 ++off;
29678 @@ -2139,7 +2145,8 @@ static void *unix_seq_next(struct seq_fi
29679                 sk = first_unix_socket(&iter->i);
29680         else
29681                 sk = next_unix_socket(&iter->i, sk);
29682 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
29683 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
29684 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
29685                 sk = next_unix_socket(&iter->i, sk);
29686         return sk;
29687  }
29688 diff -NurpP --minimal linux-2.6.33/net/x25/af_x25.c linux-2.6.33-vs2.3.0.36.30.1/net/x25/af_x25.c
29689 --- linux-2.6.33/net/x25/af_x25.c       2010-02-25 11:52:12.000000000 +0100
29690 +++ linux-2.6.33-vs2.3.0.36.30.1/net/x25/af_x25.c       2010-02-25 12:02:16.000000000 +0100
29691 @@ -526,7 +526,10 @@ static int x25_create(struct net *net, s
29692  
29693         x25 = x25_sk(sk);
29694  
29695 -       sock_init_data(sock, sk);
29696 +       sk->sk_socket = sock;
29697 +       sk->sk_type = sock->type;
29698 +       sk->sk_sleep = &sock->wait;
29699 +       sock->sk = sk;
29700  
29701         x25_init_timers(sk);
29702  
29703 diff -NurpP --minimal linux-2.6.33/scripts/checksyscalls.sh linux-2.6.33-vs2.3.0.36.30.1/scripts/checksyscalls.sh
29704 --- linux-2.6.33/scripts/checksyscalls.sh       2009-09-10 15:26:31.000000000 +0200
29705 +++ linux-2.6.33-vs2.3.0.36.30.1/scripts/checksyscalls.sh       2010-02-25 12:02:16.000000000 +0100
29706 @@ -194,7 +194,6 @@ cat << EOF
29707  #define __IGNORE_afs_syscall
29708  #define __IGNORE_getpmsg
29709  #define __IGNORE_putpmsg
29710 -#define __IGNORE_vserver
29711  EOF
29712  }
29713  
29714 diff -NurpP --minimal linux-2.6.33/security/commoncap.c linux-2.6.33-vs2.3.0.36.30.1/security/commoncap.c
29715 --- linux-2.6.33/security/commoncap.c   2010-02-25 11:52:12.000000000 +0100
29716 +++ linux-2.6.33-vs2.3.0.36.30.1/security/commoncap.c   2010-02-25 12:02:16.000000000 +0100
29717 @@ -27,6 +27,7 @@
29718  #include <linux/sched.h>
29719  #include <linux/prctl.h>
29720  #include <linux/securebits.h>
29721 +#include <linux/vs_context.h>
29722  
29723  /*
29724   * If a non-root user executes a setuid-root binary in
29725 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
29726  
29727  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
29728  {
29729 -       NETLINK_CB(skb).eff_cap = current_cap();
29730 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
29731         return 0;
29732  }
29733  
29734 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
29735                 return -EPERM;
29736         return 0;
29737  }
29738 +
29739  EXPORT_SYMBOL(cap_netlink_recv);
29740  
29741  /**
29742 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
29743  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
29744                 int audit)
29745  {
29746 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
29747 +       struct vx_info *vxi = tsk->vx_info;
29748 +
29749 +#if 0
29750 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
29751 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
29752 +               cap_raised(tsk->cap_effective, cap),
29753 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
29754 +#endif
29755 +
29756 +       /* special case SETUP */
29757 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
29758 +               /* FIXME: maybe use cred instead? */
29759 +               cap_raised(tsk->cred->cap_effective, cap))
29760 +               return 0;
29761 +
29762 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
29763  }
29764  
29765  /**
29766 @@ -596,7 +613,7 @@ int cap_inode_removexattr(struct dentry 
29767  
29768         if (!strncmp(name, XATTR_SECURITY_PREFIX,
29769                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
29770 -           !capable(CAP_SYS_ADMIN))
29771 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
29772                 return -EPERM;
29773         return 0;
29774  }
29775 @@ -894,7 +911,8 @@ error:
29776   */
29777  int cap_syslog(int type)
29778  {
29779 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
29780 +       if ((type != 3 && type != 10) &&
29781 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
29782                 return -EPERM;
29783         return 0;
29784  }
29785 @@ -946,3 +964,4 @@ int cap_file_mmap(struct file *file, uns
29786         }
29787         return ret;
29788  }
29789 +
29790 diff -NurpP --minimal linux-2.6.33/security/selinux/av_permissions.h linux-2.6.33-vs2.3.0.36.30.1/security/selinux/av_permissions.h
29791 --- linux-2.6.33/security/selinux/av_permissions.h      1970-01-01 01:00:00.000000000 +0100
29792 +++ linux-2.6.33-vs2.3.0.36.30.1/security/selinux/av_permissions.h      2010-02-27 15:49:05.000000000 +0100
29793 @@ -0,0 +1,827 @@
29794 +/* This file is automatically generated.  Do not edit. */
29795 +#ifndef _SELINUX_AV_PERMISSIONS_H_
29796 +#define _SELINUX_AV_PERMISSIONS_H_
29797 +
29798 +#define SECURITY__COMPUTE_AV                      0x00000001UL
29799 +#define SECURITY__COMPUTE_CREATE                  0x00000002UL
29800 +#define SECURITY__COMPUTE_MEMBER                  0x00000004UL
29801 +#define SECURITY__CHECK_CONTEXT                   0x00000008UL
29802 +#define SECURITY__LOAD_POLICY                     0x00000010UL
29803 +#define SECURITY__COMPUTE_RELABEL                 0x00000020UL
29804 +#define SECURITY__COMPUTE_USER                    0x00000040UL
29805 +#define SECURITY__SETENFORCE                      0x00000080UL
29806 +#define SECURITY__SETBOOL                         0x00000100UL
29807 +#define SECURITY__SETSECPARAM                     0x00000200UL
29808 +#define SECURITY__SETCHECKREQPROT                 0x00000400UL
29809 +#define PROCESS__FORK                             0x00000001UL
29810 +#define PROCESS__TRANSITION                       0x00000002UL
29811 +#define PROCESS__SIGCHLD                          0x00000004UL
29812 +#define PROCESS__SIGKILL                          0x00000008UL
29813 +#define PROCESS__SIGSTOP                          0x00000010UL
29814 +#define PROCESS__SIGNULL                          0x00000020UL
29815 +#define PROCESS__SIGNAL                           0x00000040UL
29816 +#define PROCESS__PTRACE                           0x00000080UL
29817 +#define PROCESS__GETSCHED                         0x00000100UL
29818 +#define PROCESS__SETSCHED                         0x00000200UL
29819 +#define PROCESS__GETSESSION                       0x00000400UL
29820 +#define PROCESS__GETPGID                          0x00000800UL
29821 +#define PROCESS__SETPGID                          0x00001000UL
29822 +#define PROCESS__GETCAP                           0x00002000UL
29823 +#define PROCESS__SETCAP                           0x00004000UL
29824 +#define PROCESS__SHARE                            0x00008000UL
29825 +#define PROCESS__GETATTR                          0x00010000UL
29826 +#define PROCESS__SETEXEC                          0x00020000UL
29827 +#define PROCESS__SETFSCREATE                      0x00040000UL
29828 +#define PROCESS__NOATSECURE                       0x00080000UL
29829 +#define PROCESS__SIGINH                           0x00100000UL
29830 +#define PROCESS__SETRLIMIT                        0x00200000UL
29831 +#define PROCESS__RLIMITINH                        0x00400000UL
29832 +#define PROCESS__DYNTRANSITION                    0x00800000UL
29833 +#define PROCESS__SETCURRENT                       0x01000000UL
29834 +#define PROCESS__EXECMEM                          0x02000000UL
29835 +#define PROCESS__EXECSTACK                        0x04000000UL
29836 +#define PROCESS__EXECHEAP                         0x08000000UL
29837 +#define PROCESS__SETKEYCREATE                     0x10000000UL
29838 +#define PROCESS__SETSOCKCREATE                    0x20000000UL
29839 +#define SYSTEM__IPC_INFO                          0x00000001UL
29840 +#define SYSTEM__SYSLOG_READ                       0x00000002UL
29841 +#define SYSTEM__SYSLOG_MOD                        0x00000004UL
29842 +#define SYSTEM__SYSLOG_CONSOLE                    0x00000008UL
29843 +#define SYSTEM__MODULE_REQUEST                    0x00000010UL
29844 +#define CAPABILITY__CHOWN                         0x00000001UL
29845 +#define CAPABILITY__DAC_OVERRIDE                  0x00000002UL
29846 +#define CAPABILITY__DAC_READ_SEARCH               0x00000004UL
29847 +#define CAPABILITY__FOWNER                        0x00000008UL
29848 +#define CAPABILITY__FSETID                        0x00000010UL
29849 +#define CAPABILITY__KILL                          0x00000020UL
29850 +#define CAPABILITY__SETGID                        0x00000040UL
29851 +#define CAPABILITY__SETUID                        0x00000080UL
29852 +#define CAPABILITY__SETPCAP                       0x00000100UL
29853 +#define CAPABILITY__LINUX_IMMUTABLE               0x00000200UL
29854 +#define CAPABILITY__NET_BIND_SERVICE              0x00000400UL
29855 +#define CAPABILITY__NET_BROADCAST                 0x00000800UL
29856 +#define CAPABILITY__NET_ADMIN                     0x00001000UL
29857 +#define CAPABILITY__NET_RAW                       0x00002000UL
29858 +#define CAPABILITY__IPC_LOCK                      0x00004000UL
29859 +#define CAPABILITY__IPC_OWNER                     0x00008000UL
29860 +#define CAPABILITY__SYS_MODULE                    0x00010000UL
29861 +#define CAPABILITY__SYS_RAWIO                     0x00020000UL
29862 +#define CAPABILITY__SYS_CHROOT                    0x00040000UL
29863 +#define CAPABILITY__SYS_PTRACE                    0x00080000UL
29864 +#define CAPABILITY__SYS_PACCT                     0x00100000UL
29865 +#define CAPABILITY__SYS_ADMIN                     0x00200000UL
29866 +#define CAPABILITY__SYS_BOOT                      0x00400000UL
29867 +#define CAPABILITY__SYS_NICE                      0x00800000UL
29868 +#define CAPABILITY__SYS_RESOURCE                  0x01000000UL
29869 +#define CAPABILITY__SYS_TIME                      0x02000000UL
29870 +#define CAPABILITY__SYS_TTY_CONFIG                0x04000000UL
29871 +#define CAPABILITY__MKNOD                         0x08000000UL
29872 +#define CAPABILITY__LEASE                         0x10000000UL
29873 +#define CAPABILITY__AUDIT_WRITE                   0x20000000UL
29874 +#define CAPABILITY__AUDIT_CONTROL                 0x40000000UL
29875 +#define CAPABILITY__SETFCAP                       0x80000000UL
29876 +#define FILESYSTEM__MOUNT                         0x00000001UL
29877 +#define FILESYSTEM__REMOUNT                       0x00000002UL
29878 +#define FILESYSTEM__UNMOUNT                       0x00000004UL
29879 +#define FILESYSTEM__GETATTR                       0x00000008UL
29880 +#define FILESYSTEM__RELABELFROM                   0x00000010UL
29881 +#define FILESYSTEM__RELABELTO                     0x00000020UL
29882 +#define FILESYSTEM__TRANSITION                    0x00000040UL
29883 +#define FILESYSTEM__ASSOCIATE                     0x00000080UL
29884 +#define FILESYSTEM__QUOTAMOD                      0x00000100UL
29885 +#define FILESYSTEM__QUOTAGET                      0x00000200UL
29886 +#define FILE__IOCTL                               0x00000001UL
29887 +#define FILE__READ                                0x00000002UL
29888 +#define FILE__WRITE                               0x00000004UL
29889 +#define FILE__CREATE                              0x00000008UL
29890 +#define FILE__GETATTR                             0x00000010UL
29891 +#define FILE__SETATTR                             0x00000020UL
29892 +#define FILE__LOCK                                0x00000040UL
29893 +#define FILE__RELABELFROM                         0x00000080UL
29894 +#define FILE__RELABELTO                           0x00000100UL
29895 +#define FILE__APPEND                              0x00000200UL
29896 +#define FILE__UNLINK                              0x00000400UL
29897 +#define FILE__LINK                                0x00000800UL
29898 +#define FILE__RENAME                              0x00001000UL
29899 +#define FILE__EXECUTE                             0x00002000UL
29900 +#define FILE__SWAPON                              0x00004000UL
29901 +#define FILE__QUOTAON                             0x00008000UL
29902 +#define FILE__MOUNTON                             0x00010000UL
29903 +#define FILE__EXECUTE_NO_TRANS                    0x00020000UL
29904 +#define FILE__ENTRYPOINT                          0x00040000UL
29905 +#define FILE__EXECMOD                             0x00080000UL
29906 +#define FILE__OPEN                                0x00100000UL
29907 +#define DIR__IOCTL                                0x00000001UL
29908 +#define DIR__READ                                 0x00000002UL
29909 +#define DIR__WRITE                                0x00000004UL
29910 +#define DIR__CREATE                               0x00000008UL
29911 +#define DIR__GETATTR                              0x00000010UL
29912 +#define DIR__SETATTR                              0x00000020UL
29913 +#define DIR__LOCK                                 0x00000040UL
29914 +#define DIR__RELABELFROM                          0x00000080UL
29915 +#define DIR__RELABELTO                            0x00000100UL
29916 +#define DIR__APPEND                               0x00000200UL
29917 +#define DIR__UNLINK                               0x00000400UL
29918 +#define DIR__LINK                                 0x00000800UL
29919 +#define DIR__RENAME                               0x00001000UL
29920 +#define DIR__EXECUTE                              0x00002000UL
29921 +#define DIR__SWAPON                               0x00004000UL
29922 +#define DIR__QUOTAON                              0x00008000UL
29923 +#define DIR__MOUNTON                              0x00010000UL
29924 +#define DIR__ADD_NAME                             0x00020000UL
29925 +#define DIR__REMOVE_NAME                          0x00040000UL
29926 +#define DIR__REPARENT                             0x00080000UL
29927 +#define DIR__SEARCH                               0x00100000UL
29928 +#define DIR__RMDIR                                0x00200000UL
29929 +#define DIR__OPEN                                 0x00400000UL
29930 +#define FD__USE                                   0x00000001UL
29931 +#define LNK_FILE__IOCTL                           0x00000001UL
29932 +#define LNK_FILE__READ                            0x00000002UL
29933 +#define LNK_FILE__WRITE                           0x00000004UL
29934 +#define LNK_FILE__CREATE                          0x00000008UL
29935 +#define LNK_FILE__GETATTR                         0x00000010UL
29936 +#define LNK_FILE__SETATTR                         0x00000020UL
29937 +#define LNK_FILE__LOCK                            0x00000040UL
29938 +#define LNK_FILE__RELABELFROM                     0x00000080UL
29939 +#define LNK_FILE__RELABELTO                       0x00000100UL
29940 +#define LNK_FILE__APPEND                          0x00000200UL
29941 +#define LNK_FILE__UNLINK                          0x00000400UL
29942 +#define LNK_FILE__LINK                            0x00000800UL
29943 +#define LNK_FILE__RENAME                          0x00001000UL
29944 +#define LNK_FILE__EXECUTE                         0x00002000UL
29945 +#define LNK_FILE__SWAPON                          0x00004000UL
29946 +#define LNK_FILE__QUOTAON                         0x00008000UL
29947 +#define LNK_FILE__MOUNTON                         0x00010000UL
29948 +#define CHR_FILE__IOCTL                           0x00000001UL
29949 +#define CHR_FILE__READ                            0x00000002UL
29950 +#define CHR_FILE__WRITE                           0x00000004UL
29951 +#define CHR_FILE__CREATE                          0x00000008UL
29952 +#define CHR_FILE__GETATTR                         0x00000010UL
29953 +#define CHR_FILE__SETATTR                         0x00000020UL
29954 +#define CHR_FILE__LOCK                            0x00000040UL
29955 +#define CHR_FILE__RELABELFROM                     0x00000080UL
29956 +#define CHR_FILE__RELABELTO                       0x00000100UL
29957 +#define CHR_FILE__APPEND                          0x00000200UL
29958 +#define CHR_FILE__UNLINK                          0x00000400UL
29959 +#define CHR_FILE__LINK                            0x00000800UL
29960 +#define CHR_FILE__RENAME                          0x00001000UL
29961 +#define CHR_FILE__EXECUTE                         0x00002000UL
29962 +#define CHR_FILE__SWAPON                          0x00004000UL
29963 +#define CHR_FILE__QUOTAON                         0x00008000UL
29964 +#define CHR_FILE__MOUNTON                         0x00010000UL
29965 +#define CHR_FILE__EXECUTE_NO_TRANS                0x00020000UL
29966 +#define CHR_FILE__ENTRYPOINT                      0x00040000UL
29967 +#define CHR_FILE__EXECMOD                         0x00080000UL
29968 +#define CHR_FILE__OPEN                            0x00100000UL
29969 +#define BLK_FILE__IOCTL                           0x00000001UL
29970 +#define BLK_FILE__READ                            0x00000002UL
29971 +#define BLK_FILE__WRITE                           0x00000004UL
29972 +#define BLK_FILE__CREATE                          0x00000008UL
29973 +#define BLK_FILE__GETATTR                         0x00000010UL
29974 +#define BLK_FILE__SETATTR                         0x00000020UL
29975 +#define BLK_FILE__LOCK                            0x00000040UL
29976 +#define BLK_FILE__RELABELFROM                     0x00000080UL
29977 +#define BLK_FILE__RELABELTO                       0x00000100UL
29978 +#define BLK_FILE__APPEND                          0x00000200UL
29979 +#define BLK_FILE__UNLINK                          0x00000400UL
29980 +#define BLK_FILE__LINK                            0x00000800UL
29981 +#define BLK_FILE__RENAME                          0x00001000UL
29982 +#define BLK_FILE__EXECUTE                         0x00002000UL
29983 +#define BLK_FILE__SWAPON                          0x00004000UL
29984 +#define BLK_FILE__QUOTAON                         0x00008000UL
29985 +#define BLK_FILE__MOUNTON                         0x00010000UL
29986 +#define BLK_FILE__OPEN                            0x00020000UL
29987 +#define SOCK_FILE__IOCTL                          0x00000001UL
29988 +#define SOCK_FILE__READ                           0x00000002UL
29989 +#define SOCK_FILE__WRITE                          0x00000004UL
29990 +#define SOCK_FILE__CREATE                         0x00000008UL
29991 +#define SOCK_FILE__GETATTR                        0x00000010UL
29992 +#define SOCK_FILE__SETATTR                        0x00000020UL
29993 +#define SOCK_FILE__LOCK                           0x00000040UL
29994 +#define SOCK_FILE__RELABELFROM                    0x00000080UL
29995 +#define SOCK_FILE__RELABELTO                      0x00000100UL
29996 +#define SOCK_FILE__APPEND                         0x00000200UL
29997 +#define SOCK_FILE__UNLINK                         0x00000400UL
29998 +#define SOCK_FILE__LINK                           0x00000800UL
29999 +#define SOCK_FILE__RENAME                         0x00001000UL
30000 +#define SOCK_FILE__EXECUTE                        0x00002000UL
30001 +#define SOCK_FILE__SWAPON                         0x00004000UL
30002 +#define SOCK_FILE__QUOTAON                        0x00008000UL
30003 +#define SOCK_FILE__MOUNTON                        0x00010000UL
30004 +#define SOCK_FILE__OPEN                           0x00020000UL
30005 +#define FIFO_FILE__IOCTL                          0x00000001UL
30006 +#define FIFO_FILE__READ                           0x00000002UL
30007 +#define FIFO_FILE__WRITE                          0x00000004UL
30008 +#define FIFO_FILE__CREATE                         0x00000008UL
30009 +#define FIFO_FILE__GETATTR                        0x00000010UL
30010 +#define FIFO_FILE__SETATTR                        0x00000020UL
30011 +#define FIFO_FILE__LOCK                           0x00000040UL
30012 +#define FIFO_FILE__RELABELFROM                    0x00000080UL
30013 +#define FIFO_FILE__RELABELTO                      0x00000100UL
30014 +#define FIFO_FILE__APPEND                         0x00000200UL
30015 +#define FIFO_FILE__UNLINK                         0x00000400UL
30016 +#define FIFO_FILE__LINK                           0x00000800UL
30017 +#define FIFO_FILE__RENAME                         0x00001000UL
30018 +#define FIFO_FILE__EXECUTE                        0x00002000UL
30019 +#define FIFO_FILE__SWAPON                         0x00004000UL
30020 +#define FIFO_FILE__QUOTAON                        0x00008000UL
30021 +#define FIFO_FILE__MOUNTON                        0x00010000UL
30022 +#define FIFO_FILE__OPEN                           0x00020000UL
30023 +#define SOCKET__IOCTL                             0x00000001UL
30024 +#define SOCKET__READ                              0x00000002UL
30025 +#define SOCKET__WRITE                             0x00000004UL
30026 +#define SOCKET__CREATE                            0x00000008UL
30027 +#define SOCKET__GETATTR                           0x00000010UL
30028 +#define SOCKET__SETATTR                           0x00000020UL
30029 +#define SOCKET__LOCK                              0x00000040UL
30030 +#define SOCKET__RELABELFROM                       0x00000080UL
30031 +#define SOCKET__RELABELTO                         0x00000100UL
30032 +#define SOCKET__APPEND                            0x00000200UL
30033 +#define SOCKET__BIND                              0x00000400UL
30034 +#define SOCKET__CONNECT                           0x00000800UL
30035 +#define SOCKET__LISTEN                            0x00001000UL
30036 +#define SOCKET__ACCEPT                            0x00002000UL
30037 +#define SOCKET__GETOPT                            0x00004000UL
30038 +#define SOCKET__SETOPT                            0x00008000UL
30039 +#define SOCKET__SHUTDOWN                          0x00010000UL
30040 +#define SOCKET__RECVFROM                          0x00020000UL
30041 +#define SOCKET__SENDTO                            0x00040000UL
30042 +#define SOCKET__RECV_MSG                          0x00080000UL
30043 +#define SOCKET__SEND_MSG                          0x00100000UL
30044 +#define SOCKET__NAME_BIND                         0x00200000UL
30045 +#define TCP_SOCKET__IOCTL                         0x00000001UL
30046 +#define TCP_SOCKET__READ                          0x00000002UL
30047 +#define TCP_SOCKET__WRITE                         0x00000004UL
30048 +#define TCP_SOCKET__CREATE                        0x00000008UL
30049 +#define TCP_SOCKET__GETATTR                       0x00000010UL
30050 +#define TCP_SOCKET__SETATTR                       0x00000020UL
30051 +#define TCP_SOCKET__LOCK                          0x00000040UL
30052 +#define TCP_SOCKET__RELABELFROM                   0x00000080UL
30053 +#define TCP_SOCKET__RELABELTO                     0x00000100UL
30054 +#define TCP_SOCKET__APPEND                        0x00000200UL
30055 +#define TCP_SOCKET__BIND                          0x00000400UL
30056 +#define TCP_SOCKET__CONNECT                       0x00000800UL
30057 +#define TCP_SOCKET__LISTEN                        0x00001000UL
30058 +#define TCP_SOCKET__ACCEPT                        0x00002000UL
30059 +#define TCP_SOCKET__GETOPT                        0x00004000UL
30060 +#define TCP_SOCKET__SETOPT                        0x00008000UL
30061 +#define TCP_SOCKET__SHUTDOWN                      0x00010000UL
30062 +#define TCP_SOCKET__RECVFROM                      0x00020000UL
30063 +#define TCP_SOCKET__SENDTO                        0x00040000UL
30064 +#define TCP_SOCKET__RECV_MSG                      0x00080000UL
30065 +#define TCP_SOCKET__SEND_MSG                      0x00100000UL
30066 +#define TCP_SOCKET__NAME_BIND                     0x00200000UL
30067 +#define TCP_SOCKET__CONNECTTO                     0x00400000UL
30068 +#define TCP_SOCKET__NEWCONN                       0x00800000UL
30069 +#define TCP_SOCKET__ACCEPTFROM                    0x01000000UL
30070 +#define TCP_SOCKET__NODE_BIND                     0x02000000UL
30071 +#define TCP_SOCKET__NAME_CONNECT                  0x04000000UL
30072 +#define UDP_SOCKET__IOCTL                         0x00000001UL
30073 +#define UDP_SOCKET__READ                          0x00000002UL
30074 +#define UDP_SOCKET__WRITE                         0x00000004UL
30075 +#define UDP_SOCKET__CREATE                        0x00000008UL
30076 +#define UDP_SOCKET__GETATTR                       0x00000010UL
30077 +#define UDP_SOCKET__SETATTR                       0x00000020UL
30078 +#define UDP_SOCKET__LOCK                          0x00000040UL
30079 +#define UDP_SOCKET__RELABELFROM                   0x00000080UL
30080 +#define UDP_SOCKET__RELABELTO                     0x00000100UL
30081 +#define UDP_SOCKET__APPEND                        0x00000200UL
30082 +#define UDP_SOCKET__BIND                          0x00000400UL
30083 +#define UDP_SOCKET__CONNECT                       0x00000800UL
30084 +#define UDP_SOCKET__LISTEN                        0x00001000UL
30085 +#define UDP_SOCKET__ACCEPT                        0x00002000UL
30086 +#define UDP_SOCKET__GETOPT                        0x00004000UL
30087 +#define UDP_SOCKET__SETOPT                        0x00008000UL
30088 +#define UDP_SOCKET__SHUTDOWN                      0x00010000UL
30089 +#define UDP_SOCKET__RECVFROM                      0x00020000UL
30090 +#define UDP_SOCKET__SENDTO                        0x00040000UL
30091 +#define UDP_SOCKET__RECV_MSG                      0x00080000UL
30092 +#define UDP_SOCKET__SEND_MSG                      0x00100000UL
30093 +#define UDP_SOCKET__NAME_BIND                     0x00200000UL
30094 +#define UDP_SOCKET__NODE_BIND                     0x00400000UL
30095 +#define RAWIP_SOCKET__IOCTL                       0x00000001UL
30096 +#define RAWIP_SOCKET__READ                        0x00000002UL
30097 +#define RAWIP_SOCKET__WRITE                       0x00000004UL
30098 +#define RAWIP_SOCKET__CREATE                      0x00000008UL
30099 +#define RAWIP_SOCKET__GETATTR                     0x00000010UL
30100 +#define RAWIP_SOCKET__SETATTR                     0x00000020UL
30101 +#define RAWIP_SOCKET__LOCK                        0x00000040UL
30102 +#define RAWIP_SOCKET__RELABELFROM                 0x00000080UL
30103 +#define RAWIP_SOCKET__RELABELTO                   0x00000100UL
30104 +#define RAWIP_SOCKET__APPEND                      0x00000200UL
30105 +#define RAWIP_SOCKET__BIND                        0x00000400UL
30106 +#define RAWIP_SOCKET__CONNECT                     0x00000800UL
30107 +#define RAWIP_SOCKET__LISTEN                      0x00001000UL
30108 +#define RAWIP_SOCKET__ACCEPT                      0x00002000UL
30109 +#define RAWIP_SOCKET__GETOPT                      0x00004000UL
30110 +#define RAWIP_SOCKET__SETOPT                      0x00008000UL
30111 +#define RAWIP_SOCKET__SHUTDOWN                    0x00010000UL
30112 +#define RAWIP_SOCKET__RECVFROM                    0x00020000UL
30113 +#define RAWIP_SOCKET__SENDTO                      0x00040000UL
30114 +#define RAWIP_SOCKET__RECV_MSG                    0x00080000UL
30115 +#define RAWIP_SOCKET__SEND_MSG                    0x00100000UL
30116 +#define RAWIP_SOCKET__NAME_BIND                   0x00200000UL
30117 +#define RAWIP_SOCKET__NODE_BIND                   0x00400000UL
30118 +#define NODE__TCP_RECV                            0x00000001UL
30119 +#define NODE__TCP_SEND                            0x00000002UL
30120 +#define NODE__UDP_RECV                            0x00000004UL
30121 +#define NODE__UDP_SEND                            0x00000008UL
30122 +#define NODE__RAWIP_RECV                          0x00000010UL
30123 +#define NODE__RAWIP_SEND                          0x00000020UL
30124 +#define NODE__ENFORCE_DEST                        0x00000040UL
30125 +#define NODE__DCCP_RECV                           0x00000080UL
30126 +#define NODE__DCCP_SEND                           0x00000100UL
30127 +#define NODE__RECVFROM                            0x00000200UL
30128 +#define NODE__SENDTO                              0x00000400UL
30129 +#define NETIF__TCP_RECV                           0x00000001UL
30130 +#define NETIF__TCP_SEND                           0x00000002UL
30131 +#define NETIF__UDP_RECV                           0x00000004UL
30132 +#define NETIF__UDP_SEND                           0x00000008UL
30133 +#define NETIF__RAWIP_RECV                         0x00000010UL
30134 +#define NETIF__RAWIP_SEND                         0x00000020UL
30135 +#define NETIF__DCCP_RECV                          0x00000040UL
30136 +#define NETIF__DCCP_SEND                          0x00000080UL
30137 +#define NETIF__INGRESS                            0x00000100UL
30138 +#define NETIF__EGRESS                             0x00000200UL
30139 +#define NETLINK_SOCKET__IOCTL                     0x00000001UL
30140 +#define NETLINK_SOCKET__READ                      0x00000002UL
30141 +#define NETLINK_SOCKET__WRITE                     0x00000004UL
30142 +#define NETLINK_SOCKET__CREATE                    0x00000008UL
30143 +#define NETLINK_SOCKET__GETATTR                   0x00000010UL
30144 +#define NETLINK_SOCKET__SETATTR                   0x00000020UL
30145 +#define NETLINK_SOCKET__LOCK                      0x00000040UL
30146 +#define NETLINK_SOCKET__RELABELFROM               0x00000080UL
30147 +#define NETLINK_SOCKET__RELABELTO                 0x00000100UL
30148 +#define NETLINK_SOCKET__APPEND                    0x00000200UL
30149 +#define NETLINK_SOCKET__BIND                      0x00000400UL
30150 +#define NETLINK_SOCKET__CONNECT                   0x00000800UL
30151 +#define NETLINK_SOCKET__LISTEN                    0x00001000UL
30152 +#define NETLINK_SOCKET__ACCEPT                    0x00002000UL
30153 +#define NETLINK_SOCKET__GETOPT                    0x00004000UL
30154 +#define NETLINK_SOCKET__SETOPT                    0x00008000UL
30155 +#define NETLINK_SOCKET__SHUTDOWN                  0x00010000UL
30156 +#define NETLINK_SOCKET__RECVFROM                  0x00020000UL
30157 +#define NETLINK_SOCKET__SENDTO                    0x00040000UL
30158 +#define NETLINK_SOCKET__RECV_MSG                  0x00080000UL
30159 +#define NETLINK_SOCKET__SEND_MSG                  0x00100000UL
30160 +#define NETLINK_SOCKET__NAME_BIND                 0x00200000UL
30161 +#define PACKET_SOCKET__IOCTL                      0x00000001UL
30162 +#define PACKET_SOCKET__READ                       0x00000002UL
30163 +#define PACKET_SOCKET__WRITE                      0x00000004UL
30164 +#define PACKET_SOCKET__CREATE                     0x00000008UL
30165 +#define PACKET_SOCKET__GETATTR                    0x00000010UL
30166 +#define PACKET_SOCKET__SETATTR                    0x00000020UL
30167 +#define PACKET_SOCKET__LOCK                       0x00000040UL
30168 +#define PACKET_SOCKET__RELABELFROM                0x00000080UL
30169 +#define PACKET_SOCKET__RELABELTO                  0x00000100UL
30170 +#define PACKET_SOCKET__APPEND                     0x00000200UL
30171 +#define PACKET_SOCKET__BIND                       0x00000400UL
30172 +#define PACKET_SOCKET__CONNECT                    0x00000800UL
30173 +#define PACKET_SOCKET__LISTEN                     0x00001000UL
30174 +#define PACKET_SOCKET__ACCEPT                     0x00002000UL
30175 +#define PACKET_SOCKET__GETOPT                     0x00004000UL
30176 +#define PACKET_SOCKET__SETOPT                     0x00008000UL
30177 +#define PACKET_SOCKET__SHUTDOWN                   0x00010000UL
30178 +#define PACKET_SOCKET__RECVFROM                   0x00020000UL
30179 +#define PACKET_SOCKET__SENDTO                     0x00040000UL
30180 +#define PACKET_SOCKET__RECV_MSG                   0x00080000UL
30181 +#define PACKET_SOCKET__SEND_MSG                   0x00100000UL
30182 +#define PACKET_SOCKET__NAME_BIND                  0x00200000UL
30183 +#define KEY_SOCKET__IOCTL                         0x00000001UL
30184 +#define KEY_SOCKET__READ                          0x00000002UL
30185 +#define KEY_SOCKET__WRITE                         0x00000004UL
30186 +#define KEY_SOCKET__CREATE                        0x00000008UL
30187 +#define KEY_SOCKET__GETATTR                       0x00000010UL
30188 +#define KEY_SOCKET__SETATTR                       0x00000020UL
30189 +#define KEY_SOCKET__LOCK                          0x00000040UL
30190 +#define KEY_SOCKET__RELABELFROM                   0x00000080UL
30191 +#define KEY_SOCKET__RELABELTO                     0x00000100UL
30192 +#define KEY_SOCKET__APPEND                        0x00000200UL
30193 +#define KEY_SOCKET__BIND                          0x00000400UL
30194 +#define KEY_SOCKET__CONNECT                       0x00000800UL
30195 +#define KEY_SOCKET__LISTEN                        0x00001000UL
30196 +#define KEY_SOCKET__ACCEPT                        0x00002000UL
30197 +#define KEY_SOCKET__GETOPT                        0x00004000UL
30198 +#define KEY_SOCKET__SETOPT                        0x00008000UL
30199 +#define KEY_SOCKET__SHUTDOWN                      0x00010000UL
30200 +#define KEY_SOCKET__RECVFROM                      0x00020000UL
30201 +#define KEY_SOCKET__SENDTO                        0x00040000UL
30202 +#define KEY_SOCKET__RECV_MSG                      0x00080000UL
30203 +#define KEY_SOCKET__SEND_MSG                      0x00100000UL
30204 +#define KEY_SOCKET__NAME_BIND                     0x00200000UL
30205 +#define UNIX_STREAM_SOCKET__IOCTL                 0x00000001UL
30206 +#define UNIX_STREAM_SOCKET__READ                  0x00000002UL
30207 +#define UNIX_STREAM_SOCKET__WRITE                 0x00000004UL
30208 +#define UNIX_STREAM_SOCKET__CREATE                0x00000008UL
30209 +#define UNIX_STREAM_SOCKET__GETATTR               0x00000010UL
30210 +#define UNIX_STREAM_SOCKET__SETATTR               0x00000020UL
30211 +#define UNIX_STREAM_SOCKET__LOCK                  0x00000040UL
30212 +#define UNIX_STREAM_SOCKET__RELABELFROM           0x00000080UL
30213 +#define UNIX_STREAM_SOCKET__RELABELTO             0x00000100UL
30214 +#define UNIX_STREAM_SOCKET__APPEND                0x00000200UL
30215 +#define UNIX_STREAM_SOCKET__BIND                  0x00000400UL
30216 +#define UNIX_STREAM_SOCKET__CONNECT               0x00000800UL
30217 +#define UNIX_STREAM_SOCKET__LISTEN                0x00001000UL
30218 +#define UNIX_STREAM_SOCKET__ACCEPT                0x00002000UL
30219 +#define UNIX_STREAM_SOCKET__GETOPT                0x00004000UL
30220 +#define UNIX_STREAM_SOCKET__SETOPT                0x00008000UL
30221 +#define UNIX_STREAM_SOCKET__SHUTDOWN              0x00010000UL
30222 +#define UNIX_STREAM_SOCKET__RECVFROM              0x00020000UL
30223 +#define UNIX_STREAM_SOCKET__SENDTO                0x00040000UL
30224 +#define UNIX_STREAM_SOCKET__RECV_MSG              0x00080000UL
30225 +#define UNIX_STREAM_SOCKET__SEND_MSG              0x00100000UL
30226 +#define UNIX_STREAM_SOCKET__NAME_BIND             0x00200000UL
30227 +#define UNIX_STREAM_SOCKET__CONNECTTO             0x00400000UL
30228 +#define UNIX_STREAM_SOCKET__NEWCONN               0x00800000UL
30229 +#define UNIX_STREAM_SOCKET__ACCEPTFROM            0x01000000UL
30230 +#define UNIX_DGRAM_SOCKET__IOCTL                  0x00000001UL
30231 +#define UNIX_DGRAM_SOCKET__READ                   0x00000002UL
30232 +#define UNIX_DGRAM_SOCKET__WRITE                  0x00000004UL
30233 +#define UNIX_DGRAM_SOCKET__CREATE                 0x00000008UL
30234 +#define UNIX_DGRAM_SOCKET__GETATTR                0x00000010UL
30235 +#define UNIX_DGRAM_SOCKET__SETATTR                0x00000020UL
30236 +#define UNIX_DGRAM_SOCKET__LOCK                   0x00000040UL
30237 +#define UNIX_DGRAM_SOCKET__RELABELFROM            0x00000080UL
30238 +#define UNIX_DGRAM_SOCKET__RELABELTO              0x00000100UL
30239 +#define UNIX_DGRAM_SOCKET__APPEND                 0x00000200UL
30240 +#define UNIX_DGRAM_SOCKET__BIND                   0x00000400UL
30241 +#define UNIX_DGRAM_SOCKET__CONNECT                0x00000800UL
30242 +#define UNIX_DGRAM_SOCKET__LISTEN                 0x00001000UL
30243 +#define UNIX_DGRAM_SOCKET__ACCEPT                 0x00002000UL
30244 +#define UNIX_DGRAM_SOCKET__GETOPT                 0x00004000UL
30245 +#define UNIX_DGRAM_SOCKET__SETOPT                 0x00008000UL
30246 +#define UNIX_DGRAM_SOCKET__SHUTDOWN               0x00010000UL
30247 +#define UNIX_DGRAM_SOCKET__RECVFROM               0x00020000UL
30248 +#define UNIX_DGRAM_SOCKET__SENDTO                 0x00040000UL
30249 +#define UNIX_DGRAM_SOCKET__RECV_MSG               0x00080000UL
30250 +#define UNIX_DGRAM_SOCKET__SEND_MSG               0x00100000UL
30251 +#define UNIX_DGRAM_SOCKET__NAME_BIND              0x00200000UL
30252 +#define SEM__CREATE                               0x00000001UL
30253 +#define SEM__DESTROY                              0x00000002UL
30254 +#define SEM__GETATTR                              0x00000004UL
30255 +#define SEM__SETATTR                              0x00000008UL
30256 +#define SEM__READ                                 0x00000010UL
30257 +#define SEM__WRITE                                0x00000020UL
30258 +#define SEM__ASSOCIATE                            0x00000040UL
30259 +#define SEM__UNIX_READ                            0x00000080UL
30260 +#define SEM__UNIX_WRITE                           0x00000100UL
30261 +#define MSG__SEND                                 0x00000001UL
30262 +#define MSG__RECEIVE                              0x00000002UL
30263 +#define MSGQ__CREATE                              0x00000001UL
30264 +#define MSGQ__DESTROY                             0x00000002UL
30265 +#define MSGQ__GETATTR                             0x00000004UL
30266 +#define MSGQ__SETATTR                             0x00000008UL
30267 +#define MSGQ__READ                                0x00000010UL
30268 +#define MSGQ__WRITE                               0x00000020UL
30269 +#define MSGQ__ASSOCIATE                           0x00000040UL
30270 +#define MSGQ__UNIX_READ                           0x00000080UL
30271 +#define MSGQ__UNIX_WRITE                          0x00000100UL
30272 +#define MSGQ__ENQUEUE                             0x00000200UL
30273 +#define SHM__CREATE                               0x00000001UL
30274 +#define SHM__DESTROY                              0x00000002UL
30275 +#define SHM__GETATTR                              0x00000004UL
30276 +#define SHM__SETATTR                              0x00000008UL
30277 +#define SHM__READ                                 0x00000010UL
30278 +#define SHM__WRITE                                0x00000020UL
30279 +#define SHM__ASSOCIATE                            0x00000040UL
30280 +#define SHM__UNIX_READ                            0x00000080UL
30281 +#define SHM__UNIX_WRITE                           0x00000100UL
30282 +#define SHM__LOCK                                 0x00000200UL
30283 +#define IPC__CREATE                               0x00000001UL
30284 +#define IPC__DESTROY                              0x00000002UL
30285 +#define IPC__GETATTR                              0x00000004UL
30286 +#define IPC__SETATTR                              0x00000008UL
30287 +#define IPC__READ                                 0x00000010UL
30288 +#define IPC__WRITE                                0x00000020UL
30289 +#define IPC__ASSOCIATE                            0x00000040UL
30290 +#define IPC__UNIX_READ                            0x00000080UL
30291 +#define IPC__UNIX_WRITE                           0x00000100UL
30292 +#define NETLINK_ROUTE_SOCKET__IOCTL               0x00000001UL
30293 +#define NETLINK_ROUTE_SOCKET__READ                0x00000002UL
30294 +#define NETLINK_ROUTE_SOCKET__WRITE               0x00000004UL
30295 +#define NETLINK_ROUTE_SOCKET__CREATE              0x00000008UL
30296 +#define NETLINK_ROUTE_SOCKET__GETATTR             0x00000010UL
30297 +#define NETLINK_ROUTE_SOCKET__SETATTR             0x00000020UL
30298 +#define NETLINK_ROUTE_SOCKET__LOCK                0x00000040UL
30299 +#define NETLINK_ROUTE_SOCKET__RELABELFROM         0x00000080UL
30300 +#define NETLINK_ROUTE_SOCKET__RELABELTO           0x00000100UL
30301 +#define NETLINK_ROUTE_SOCKET__APPEND              0x00000200UL
30302 +#define NETLINK_ROUTE_SOCKET__BIND                0x00000400UL
30303 +#define NETLINK_ROUTE_SOCKET__CONNECT             0x00000800UL
30304 +#define NETLINK_ROUTE_SOCKET__LISTEN              0x00001000UL
30305 +#define NETLINK_ROUTE_SOCKET__ACCEPT              0x00002000UL
30306 +#define NETLINK_ROUTE_SOCKET__GETOPT              0x00004000UL
30307 +#define NETLINK_ROUTE_SOCKET__SETOPT              0x00008000UL
30308 +#define NETLINK_ROUTE_SOCKET__SHUTDOWN            0x00010000UL
30309 +#define NETLINK_ROUTE_SOCKET__RECVFROM            0x00020000UL
30310 +#define NETLINK_ROUTE_SOCKET__SENDTO              0x00040000UL
30311 +#define NETLINK_ROUTE_SOCKET__RECV_MSG            0x00080000UL
30312 +#define NETLINK_ROUTE_SOCKET__SEND_MSG            0x00100000UL
30313 +#define NETLINK_ROUTE_SOCKET__NAME_BIND           0x00200000UL
30314 +#define NETLINK_ROUTE_SOCKET__NLMSG_READ          0x00400000UL
30315 +#define NETLINK_ROUTE_SOCKET__NLMSG_WRITE         0x00800000UL
30316 +#define NETLINK_FIREWALL_SOCKET__IOCTL            0x00000001UL
30317 +#define NETLINK_FIREWALL_SOCKET__READ             0x00000002UL
30318 +#define NETLINK_FIREWALL_SOCKET__WRITE            0x00000004UL
30319 +#define NETLINK_FIREWALL_SOCKET__CREATE           0x00000008UL
30320 +#define NETLINK_FIREWALL_SOCKET__GETATTR          0x00000010UL
30321 +#define NETLINK_FIREWALL_SOCKET__SETATTR          0x00000020UL
30322 +#define NETLINK_FIREWALL_SOCKET__LOCK             0x00000040UL
30323 +#define NETLINK_FIREWALL_SOCKET__RELABELFROM      0x00000080UL
30324 +#define NETLINK_FIREWALL_SOCKET__RELABELTO        0x00000100UL
30325 +#define NETLINK_FIREWALL_SOCKET__APPEND           0x00000200UL
30326 +#define NETLINK_FIREWALL_SOCKET__BIND             0x00000400UL
30327 +#define NETLINK_FIREWALL_SOCKET__CONNECT          0x00000800UL
30328 +#define NETLINK_FIREWALL_SOCKET__LISTEN           0x00001000UL
30329 +#define NETLINK_FIREWALL_SOCKET__ACCEPT           0x00002000UL
30330 +#define NETLINK_FIREWALL_SOCKET__GETOPT           0x00004000UL
30331 +#define NETLINK_FIREWALL_SOCKET__SETOPT           0x00008000UL
30332 +#define NETLINK_FIREWALL_SOCKET__SHUTDOWN         0x00010000UL
30333 +#define NETLINK_FIREWALL_SOCKET__RECVFROM         0x00020000UL
30334 +#define NETLINK_FIREWALL_SOCKET__SENDTO           0x00040000UL
30335 +#define NETLINK_FIREWALL_SOCKET__RECV_MSG         0x00080000UL
30336 +#define NETLINK_FIREWALL_SOCKET__SEND_MSG         0x00100000UL
30337 +#define NETLINK_FIREWALL_SOCKET__NAME_BIND        0x00200000UL
30338 +#define NETLINK_FIREWALL_SOCKET__NLMSG_READ       0x00400000UL
30339 +#define NETLINK_FIREWALL_SOCKET__NLMSG_WRITE      0x00800000UL
30340 +#define NETLINK_TCPDIAG_SOCKET__IOCTL             0x00000001UL
30341 +#define NETLINK_TCPDIAG_SOCKET__READ              0x00000002UL
30342 +#define NETLINK_TCPDIAG_SOCKET__WRITE             0x00000004UL
30343 +#define NETLINK_TCPDIAG_SOCKET__CREATE            0x00000008UL
30344 +#define NETLINK_TCPDIAG_SOCKET__GETATTR           0x00000010UL
30345 +#define NETLINK_TCPDIAG_SOCKET__SETATTR           0x00000020UL
30346 +#define NETLINK_TCPDIAG_SOCKET__LOCK              0x00000040UL
30347 +#define NETLINK_TCPDIAG_SOCKET__RELABELFROM       0x00000080UL
30348 +#define NETLINK_TCPDIAG_SOCKET__RELABELTO         0x00000100UL
30349 +#define NETLINK_TCPDIAG_SOCKET__APPEND            0x00000200UL
30350 +#define NETLINK_TCPDIAG_SOCKET__BIND              0x00000400UL
30351 +#define NETLINK_TCPDIAG_SOCKET__CONNECT           0x00000800UL
30352 +#define NETLINK_TCPDIAG_SOCKET__LISTEN            0x00001000UL
30353 +#define NETLINK_TCPDIAG_SOCKET__ACCEPT            0x00002000UL
30354 +#define NETLINK_TCPDIAG_SOCKET__GETOPT            0x00004000UL
30355 +#define NETLINK_TCPDIAG_SOCKET__SETOPT            0x00008000UL
30356 +#define NETLINK_TCPDIAG_SOCKET__SHUTDOWN          0x00010000UL
30357 +#define NETLINK_TCPDIAG_SOCKET__RECVFROM          0x00020000UL
30358 +#define NETLINK_TCPDIAG_SOCKET__SENDTO            0x00040000UL
30359 +#define NETLINK_TCPDIAG_SOCKET__RECV_MSG          0x00080000UL
30360 +#define NETLINK_TCPDIAG_SOCKET__SEND_MSG          0x00100000UL
30361 +#define NETLINK_TCPDIAG_SOCKET__NAME_BIND         0x00200000UL
30362 +#define NETLINK_TCPDIAG_SOCKET__NLMSG_READ        0x00400000UL
30363 +#define NETLINK_TCPDIAG_SOCKET__NLMSG_WRITE       0x00800000UL
30364 +#define NETLINK_NFLOG_SOCKET__IOCTL               0x00000001UL
30365 +#define NETLINK_NFLOG_SOCKET__READ                0x00000002UL
30366 +#define NETLINK_NFLOG_SOCKET__WRITE               0x00000004UL
30367 +#define NETLINK_NFLOG_SOCKET__CREATE              0x00000008UL
30368 +#define NETLINK_NFLOG_SOCKET__GETATTR             0x00000010UL
30369 +#define NETLINK_NFLOG_SOCKET__SETATTR             0x00000020UL
30370 +#define NETLINK_NFLOG_SOCKET__LOCK                0x00000040UL
30371 +#define NETLINK_NFLOG_SOCKET__RELABELFROM         0x00000080UL
30372 +#define NETLINK_NFLOG_SOCKET__RELABELTO           0x00000100UL
30373 +#define NETLINK_NFLOG_SOCKET__APPEND              0x00000200UL
30374 +#define NETLINK_NFLOG_SOCKET__BIND                0x00000400UL
30375 +#define NETLINK_NFLOG_SOCKET__CONNECT             0x00000800UL
30376 +#define NETLINK_NFLOG_SOCKET__LISTEN              0x00001000UL
30377 +#define NETLINK_NFLOG_SOCKET__ACCEPT              0x00002000UL
30378 +#define NETLINK_NFLOG_SOCKET__GETOPT              0x00004000UL
30379 +#define NETLINK_NFLOG_SOCKET__SETOPT              0x00008000UL
30380 +#define NETLINK_NFLOG_SOCKET__SHUTDOWN            0x00010000UL
30381 +#define NETLINK_NFLOG_SOCKET__RECVFROM            0x00020000UL
30382 +#define NETLINK_NFLOG_SOCKET__SENDTO              0x00040000UL
30383 +#define NETLINK_NFLOG_SOCKET__RECV_MSG            0x00080000UL
30384 +#define NETLINK_NFLOG_SOCKET__SEND_MSG            0x00100000UL
30385 +#define NETLINK_NFLOG_SOCKET__NAME_BIND           0x00200000UL
30386 +#define NETLINK_XFRM_SOCKET__IOCTL                0x00000001UL
30387 +#define NETLINK_XFRM_SOCKET__READ                 0x00000002UL
30388 +#define NETLINK_XFRM_SOCKET__WRITE                0x00000004UL
30389 +#define NETLINK_XFRM_SOCKET__CREATE               0x00000008UL
30390 +#define NETLINK_XFRM_SOCKET__GETATTR              0x00000010UL
30391 +#define NETLINK_XFRM_SOCKET__SETATTR              0x00000020UL
30392 +#define NETLINK_XFRM_SOCKET__LOCK                 0x00000040UL
30393 +#define NETLINK_XFRM_SOCKET__RELABELFROM          0x00000080UL
30394 +#define NETLINK_XFRM_SOCKET__RELABELTO            0x00000100UL
30395 +#define NETLINK_XFRM_SOCKET__APPEND               0x00000200UL
30396 +#define NETLINK_XFRM_SOCKET__BIND                 0x00000400UL
30397 +#define NETLINK_XFRM_SOCKET__CONNECT              0x00000800UL
30398 +#define NETLINK_XFRM_SOCKET__LISTEN               0x00001000UL
30399 +#define NETLINK_XFRM_SOCKET__ACCEPT               0x00002000UL
30400 +#define NETLINK_XFRM_SOCKET__GETOPT               0x00004000UL
30401 +#define NETLINK_XFRM_SOCKET__SETOPT               0x00008000UL
30402 +#define NETLINK_XFRM_SOCKET__SHUTDOWN             0x00010000UL
30403 +#define NETLINK_XFRM_SOCKET__RECVFROM             0x00020000UL
30404 +#define NETLINK_XFRM_SOCKET__SENDTO               0x00040000UL
30405 +#define NETLINK_XFRM_SOCKET__RECV_MSG             0x00080000UL
30406 +#define NETLINK_XFRM_SOCKET__SEND_MSG             0x00100000UL
30407 +#define NETLINK_XFRM_SOCKET__NAME_BIND            0x00200000UL
30408 +#define NETLINK_XFRM_SOCKET__NLMSG_READ           0x00400000UL
30409 +#define NETLINK_XFRM_SOCKET__NLMSG_WRITE          0x00800000UL
30410 +#define NETLINK_SELINUX_SOCKET__IOCTL             0x00000001UL
30411 +#define NETLINK_SELINUX_SOCKET__READ              0x00000002UL
30412 +#define NETLINK_SELINUX_SOCKET__WRITE             0x00000004UL
30413 +#define NETLINK_SELINUX_SOCKET__CREATE            0x00000008UL
30414 +#define NETLINK_SELINUX_SOCKET__GETATTR           0x00000010UL
30415 +#define NETLINK_SELINUX_SOCKET__SETATTR           0x00000020UL
30416 +#define NETLINK_SELINUX_SOCKET__LOCK              0x00000040UL
30417 +#define NETLINK_SELINUX_SOCKET__RELABELFROM       0x00000080UL
30418 +#define NETLINK_SELINUX_SOCKET__RELABELTO         0x00000100UL
30419 +#define NETLINK_SELINUX_SOCKET__APPEND            0x00000200UL
30420 +#define NETLINK_SELINUX_SOCKET__BIND              0x00000400UL
30421 +#define NETLINK_SELINUX_SOCKET__CONNECT           0x00000800UL
30422 +#define NETLINK_SELINUX_SOCKET__LISTEN            0x00001000UL
30423 +#define NETLINK_SELINUX_SOCKET__ACCEPT            0x00002000UL
30424 +#define NETLINK_SELINUX_SOCKET__GETOPT            0x00004000UL
30425 +#define NETLINK_SELINUX_SOCKET__SETOPT            0x00008000UL
30426 +#define NETLINK_SELINUX_SOCKET__SHUTDOWN          0x00010000UL
30427 +#define NETLINK_SELINUX_SOCKET__RECVFROM          0x00020000UL
30428 +#define NETLINK_SELINUX_SOCKET__SENDTO            0x00040000UL
30429 +#define NETLINK_SELINUX_SOCKET__RECV_MSG          0x00080000UL
30430 +#define NETLINK_SELINUX_SOCKET__SEND_MSG          0x00100000UL
30431 +#define NETLINK_SELINUX_SOCKET__NAME_BIND         0x00200000UL
30432 +#define NETLINK_AUDIT_SOCKET__IOCTL               0x00000001UL
30433 +#define NETLINK_AUDIT_SOCKET__READ                0x00000002UL
30434 +#define NETLINK_AUDIT_SOCKET__WRITE               0x00000004UL
30435 +#define NETLINK_AUDIT_SOCKET__CREATE              0x00000008UL
30436 +#define NETLINK_AUDIT_SOCKET__GETATTR             0x00000010UL
30437 +#define NETLINK_AUDIT_SOCKET__SETATTR             0x00000020UL
30438 +#define NETLINK_AUDIT_SOCKET__LOCK                0x00000040UL
30439 +#define NETLINK_AUDIT_SOCKET__RELABELFROM         0x00000080UL
30440 +#define NETLINK_AUDIT_SOCKET__RELABELTO           0x00000100UL
30441 +#define NETLINK_AUDIT_SOCKET__APPEND              0x00000200UL
30442 +#define NETLINK_AUDIT_SOCKET__BIND                0x00000400UL
30443 +#define NETLINK_AUDIT_SOCKET__CONNECT             0x00000800UL
30444 +#define NETLINK_AUDIT_SOCKET__LISTEN              0x00001000UL
30445 +#define NETLINK_AUDIT_SOCKET__ACCEPT              0x00002000UL
30446 +#define NETLINK_AUDIT_SOCKET__GETOPT              0x00004000UL
30447 +#define NETLINK_AUDIT_SOCKET__SETOPT              0x00008000UL
30448 +#define NETLINK_AUDIT_SOCKET__SHUTDOWN            0x00010000UL
30449 +#define NETLINK_AUDIT_SOCKET__RECVFROM            0x00020000UL
30450 +#define NETLINK_AUDIT_SOCKET__SENDTO              0x00040000UL
30451 +#define NETLINK_AUDIT_SOCKET__RECV_MSG            0x00080000UL
30452 +#define NETLINK_AUDIT_SOCKET__SEND_MSG            0x00100000UL
30453 +#define NETLINK_AUDIT_SOCKET__NAME_BIND           0x00200000UL
30454 +#define NETLINK_AUDIT_SOCKET__NLMSG_READ          0x00400000UL
30455 +#define NETLINK_AUDIT_SOCKET__NLMSG_WRITE         0x00800000UL
30456 +#define NETLINK_AUDIT_SOCKET__NLMSG_RELAY         0x01000000UL
30457 +#define NETLINK_AUDIT_SOCKET__NLMSG_READPRIV      0x02000000UL
30458 +#define NETLINK_AUDIT_SOCKET__NLMSG_TTY_AUDIT     0x04000000UL
30459 +#define NETLINK_IP6FW_SOCKET__IOCTL               0x00000001UL
30460 +#define NETLINK_IP6FW_SOCKET__READ                0x00000002UL
30461 +#define NETLINK_IP6FW_SOCKET__WRITE               0x00000004UL
30462 +#define NETLINK_IP6FW_SOCKET__CREATE              0x00000008UL
30463 +#define NETLINK_IP6FW_SOCKET__GETATTR             0x00000010UL
30464 +#define NETLINK_IP6FW_SOCKET__SETATTR             0x00000020UL
30465 +#define NETLINK_IP6FW_SOCKET__LOCK                0x00000040UL
30466 +#define NETLINK_IP6FW_SOCKET__RELABELFROM         0x00000080UL
30467 +#define NETLINK_IP6FW_SOCKET__RELABELTO           0x00000100UL
30468 +#define NETLINK_IP6FW_SOCKET__APPEND              0x00000200UL
30469 +#define NETLINK_IP6FW_SOCKET__BIND                0x00000400UL
30470 +#define NETLINK_IP6FW_SOCKET__CONNECT             0x00000800UL
30471 +#define NETLINK_IP6FW_SOCKET__LISTEN              0x00001000UL
30472 +#define NETLINK_IP6FW_SOCKET__ACCEPT              0x00002000UL
30473 +#define NETLINK_IP6FW_SOCKET__GETOPT              0x00004000UL
30474 +#define NETLINK_IP6FW_SOCKET__SETOPT              0x00008000UL
30475 +#define NETLINK_IP6FW_SOCKET__SHUTDOWN            0x00010000UL
30476 +#define NETLINK_IP6FW_SOCKET__RECVFROM            0x00020000UL
30477 +#define NETLINK_IP6FW_SOCKET__SENDTO              0x00040000UL
30478 +#define NETLINK_IP6FW_SOCKET__RECV_MSG            0x00080000UL
30479 +#define NETLINK_IP6FW_SOCKET__SEND_MSG            0x00100000UL
30480 +#define NETLINK_IP6FW_SOCKET__NAME_BIND           0x00200000UL
30481 +#define NETLINK_IP6FW_SOCKET__NLMSG_READ          0x00400000UL
30482 +#define NETLINK_IP6FW_SOCKET__NLMSG_WRITE         0x00800000UL
30483 +#define NETLINK_DNRT_SOCKET__IOCTL                0x00000001UL
30484 +#define NETLINK_DNRT_SOCKET__READ                 0x00000002UL
30485 +#define NETLINK_DNRT_SOCKET__WRITE                0x00000004UL
30486 +#define NETLINK_DNRT_SOCKET__CREATE               0x00000008UL
30487 +#define NETLINK_DNRT_SOCKET__GETATTR              0x00000010UL
30488 +#define NETLINK_DNRT_SOCKET__SETATTR              0x00000020UL
30489 +#define NETLINK_DNRT_SOCKET__LOCK                 0x00000040UL
30490 +#define NETLINK_DNRT_SOCKET__RELABELFROM          0x00000080UL
30491 +#define NETLINK_DNRT_SOCKET__RELABELTO            0x00000100UL
30492 +#define NETLINK_DNRT_SOCKET__APPEND               0x00000200UL
30493 +#define NETLINK_DNRT_SOCKET__BIND                 0x00000400UL
30494 +#define NETLINK_DNRT_SOCKET__CONNECT              0x00000800UL
30495 +#define NETLINK_DNRT_SOCKET__LISTEN               0x00001000UL
30496 +#define NETLINK_DNRT_SOCKET__ACCEPT               0x00002000UL
30497 +#define NETLINK_DNRT_SOCKET__GETOPT               0x00004000UL
30498 +#define NETLINK_DNRT_SOCKET__SETOPT               0x00008000UL
30499 +#define NETLINK_DNRT_SOCKET__SHUTDOWN             0x00010000UL
30500 +#define NETLINK_DNRT_SOCKET__RECVFROM             0x00020000UL
30501 +#define NETLINK_DNRT_SOCKET__SENDTO               0x00040000UL
30502 +#define NETLINK_DNRT_SOCKET__RECV_MSG             0x00080000UL
30503 +#define NETLINK_DNRT_SOCKET__SEND_MSG             0x00100000UL
30504 +#define NETLINK_DNRT_SOCKET__NAME_BIND            0x00200000UL
30505 +#define ASSOCIATION__SENDTO                       0x00000001UL
30506 +#define ASSOCIATION__RECVFROM                     0x00000002UL
30507 +#define ASSOCIATION__SETCONTEXT                   0x00000004UL
30508 +#define ASSOCIATION__POLMATCH                     0x00000008UL
30509 +#define NETLINK_KOBJECT_UEVENT_SOCKET__IOCTL      0x00000001UL
30510 +#define NETLINK_KOBJECT_UEVENT_SOCKET__READ       0x00000002UL
30511 +#define NETLINK_KOBJECT_UEVENT_SOCKET__WRITE      0x00000004UL
30512 +#define NETLINK_KOBJECT_UEVENT_SOCKET__CREATE     0x00000008UL
30513 +#define NETLINK_KOBJECT_UEVENT_SOCKET__GETATTR    0x00000010UL
30514 +#define NETLINK_KOBJECT_UEVENT_SOCKET__SETATTR    0x00000020UL
30515 +#define NETLINK_KOBJECT_UEVENT_SOCKET__LOCK       0x00000040UL
30516 +#define NETLINK_KOBJECT_UEVENT_SOCKET__RELABELFROM 0x00000080UL
30517 +#define NETLINK_KOBJECT_UEVENT_SOCKET__RELABELTO  0x00000100UL
30518 +#define NETLINK_KOBJECT_UEVENT_SOCKET__APPEND     0x00000200UL
30519 +#define NETLINK_KOBJECT_UEVENT_SOCKET__BIND       0x00000400UL
30520 +#define NETLINK_KOBJECT_UEVENT_SOCKET__CONNECT    0x00000800UL
30521 +#define NETLINK_KOBJECT_UEVENT_SOCKET__LISTEN     0x00001000UL
30522 +#define NETLINK_KOBJECT_UEVENT_SOCKET__ACCEPT     0x00002000UL
30523 +#define NETLINK_KOBJECT_UEVENT_SOCKET__GETOPT     0x00004000UL
30524 +#define NETLINK_KOBJECT_UEVENT_SOCKET__SETOPT     0x00008000UL
30525 +#define NETLINK_KOBJECT_UEVENT_SOCKET__SHUTDOWN   0x00010000UL
30526 +#define NETLINK_KOBJECT_UEVENT_SOCKET__RECVFROM   0x00020000UL
30527 +#define NETLINK_KOBJECT_UEVENT_SOCKET__SENDTO     0x00040000UL
30528 +#define NETLINK_KOBJECT_UEVENT_SOCKET__RECV_MSG   0x00080000UL
30529 +#define NETLINK_KOBJECT_UEVENT_SOCKET__SEND_MSG   0x00100000UL
30530 +#define NETLINK_KOBJECT_UEVENT_SOCKET__NAME_BIND  0x00200000UL
30531 +#define APPLETALK_SOCKET__IOCTL                   0x00000001UL
30532 +#define APPLETALK_SOCKET__READ                    0x00000002UL
30533 +#define APPLETALK_SOCKET__WRITE                   0x00000004UL
30534 +#define APPLETALK_SOCKET__CREATE                  0x00000008UL
30535 +#define APPLETALK_SOCKET__GETATTR                 0x00000010UL
30536 +#define APPLETALK_SOCKET__SETATTR                 0x00000020UL
30537 +#define APPLETALK_SOCKET__LOCK                    0x00000040UL
30538 +#define APPLETALK_SOCKET__RELABELFROM             0x00000080UL
30539 +#define APPLETALK_SOCKET__RELABELTO               0x00000100UL
30540 +#define APPLETALK_SOCKET__APPEND                  0x00000200UL
30541 +#define APPLETALK_SOCKET__BIND                    0x00000400UL
30542 +#define APPLETALK_SOCKET__CONNECT                 0x00000800UL
30543 +#define APPLETALK_SOCKET__LISTEN                  0x00001000UL
30544 +#define APPLETALK_SOCKET__ACCEPT                  0x00002000UL
30545 +#define APPLETALK_SOCKET__GETOPT                  0x00004000UL
30546 +#define APPLETALK_SOCKET__SETOPT                  0x00008000UL
30547 +#define APPLETALK_SOCKET__SHUTDOWN                0x00010000UL
30548 +#define APPLETALK_SOCKET__RECVFROM                0x00020000UL
30549 +#define APPLETALK_SOCKET__SENDTO                  0x00040000UL
30550 +#define APPLETALK_SOCKET__RECV_MSG                0x00080000UL
30551 +#define APPLETALK_SOCKET__SEND_MSG                0x00100000UL
30552 +#define APPLETALK_SOCKET__NAME_BIND               0x00200000UL
30553 +#define PACKET__SEND                              0x00000001UL
30554 +#define PACKET__RECV                              0x00000002UL
30555 +#define PACKET__RELABELTO                         0x00000004UL
30556 +#define PACKET__FLOW_IN                           0x00000008UL
30557 +#define PACKET__FLOW_OUT                          0x00000010UL
30558 +#define PACKET__FORWARD_IN                        0x00000020UL
30559 +#define PACKET__FORWARD_OUT                       0x00000040UL
30560 +#define KEY__VIEW                                 0x00000001UL
30561 +#define KEY__READ                                 0x00000002UL
30562 +#define KEY__WRITE                                0x00000004UL
30563 +#define KEY__SEARCH                               0x00000008UL
30564 +#define KEY__LINK                                 0x00000010UL
30565 +#define KEY__SETATTR                              0x00000020UL
30566 +#define KEY__CREATE                               0x00000040UL
30567 +#define DCCP_SOCKET__IOCTL                        0x00000001UL
30568 +#define DCCP_SOCKET__READ                         0x00000002UL
30569 +#define DCCP_SOCKET__WRITE                        0x00000004UL
30570 +#define DCCP_SOCKET__CREATE                       0x00000008UL
30571 +#define DCCP_SOCKET__GETATTR                      0x00000010UL
30572 +#define DCCP_SOCKET__SETATTR                      0x00000020UL
30573 +#define DCCP_SOCKET__LOCK                         0x00000040UL
30574 +#define DCCP_SOCKET__RELABELFROM                  0x00000080UL
30575 +#define DCCP_SOCKET__RELABELTO                    0x00000100UL
30576 +#define DCCP_SOCKET__APPEND                       0x00000200UL
30577 +#define DCCP_SOCKET__BIND                         0x00000400UL
30578 +#define DCCP_SOCKET__CONNECT                      0x00000800UL
30579 +#define DCCP_SOCKET__LISTEN                       0x00001000UL
30580 +#define DCCP_SOCKET__ACCEPT                       0x00002000UL
30581 +#define DCCP_SOCKET__GETOPT                       0x00004000UL
30582 +#define DCCP_SOCKET__SETOPT                       0x00008000UL
30583 +#define DCCP_SOCKET__SHUTDOWN                     0x00010000UL
30584 +#define DCCP_SOCKET__RECVFROM                     0x00020000UL
30585 +#define DCCP_SOCKET__SENDTO                       0x00040000UL
30586 +#define DCCP_SOCKET__RECV_MSG                     0x00080000UL
30587 +#define DCCP_SOCKET__SEND_MSG                     0x00100000UL
30588 +#define DCCP_SOCKET__NAME_BIND                    0x00200000UL
30589 +#define DCCP_SOCKET__NODE_BIND                    0x00400000UL
30590 +#define DCCP_SOCKET__NAME_CONNECT                 0x00800000UL
30591 +#define MEMPROTECT__MMAP_ZERO                     0x00000001UL
30592 +#define PEER__RECV                                0x00000001UL
30593 +#define CAPABILITY2__MAC_OVERRIDE                 0x00000001UL
30594 +#define CAPABILITY2__MAC_ADMIN                    0x00000002UL
30595 +#define KERNEL_SERVICE__USE_AS_OVERRIDE           0x00000001UL
30596 +#define KERNEL_SERVICE__CREATE_FILES_AS           0x00000002UL
30597 +#define TUN_SOCKET__IOCTL                         0x00000001UL
30598 +#define TUN_SOCKET__READ                          0x00000002UL
30599 +#define TUN_SOCKET__WRITE                         0x00000004UL
30600 +#define TUN_SOCKET__CREATE                        0x00000008UL
30601 +#define TUN_SOCKET__GETATTR                       0x00000010UL
30602 +#define TUN_SOCKET__SETATTR                       0x00000020UL
30603 +#define TUN_SOCKET__LOCK                          0x00000040UL
30604 +#define TUN_SOCKET__RELABELFROM                   0x00000080UL
30605 +#define TUN_SOCKET__RELABELTO                     0x00000100UL
30606 +#define TUN_SOCKET__APPEND                        0x00000200UL
30607 +#define TUN_SOCKET__BIND                          0x00000400UL
30608 +#define TUN_SOCKET__CONNECT                       0x00000800UL
30609 +#define TUN_SOCKET__LISTEN                        0x00001000UL
30610 +#define TUN_SOCKET__ACCEPT                        0x00002000UL
30611 +#define TUN_SOCKET__GETOPT                        0x00004000UL
30612 +#define TUN_SOCKET__SETOPT                        0x00008000UL
30613 +#define TUN_SOCKET__SHUTDOWN                      0x00010000UL
30614 +#define TUN_SOCKET__RECVFROM                      0x00020000UL
30615 +#define TUN_SOCKET__SENDTO                        0x00040000UL
30616 +#define TUN_SOCKET__RECV_MSG                      0x00080000UL
30617 +#define TUN_SOCKET__SEND_MSG                      0x00100000UL
30618 +#define TUN_SOCKET__NAME_BIND                     0x00200000UL
30619 +
30620 +#endif
30621 diff -NurpP --minimal linux-2.6.33/security/selinux/hooks.c linux-2.6.33-vs2.3.0.36.30.1/security/selinux/hooks.c
30622 --- linux-2.6.33/security/selinux/hooks.c       2010-02-25 11:52:12.000000000 +0100
30623 +++ linux-2.6.33-vs2.3.0.36.30.1/security/selinux/hooks.c       2010-02-25 12:02:16.000000000 +0100
30624 @@ -64,7 +64,6 @@
30625  #include <linux/dccp.h>
30626  #include <linux/quota.h>
30627  #include <linux/un.h>          /* for Unix socket types */
30628 -#include <net/af_unix.h>       /* for Unix socket types */
30629  #include <linux/parser.h>
30630  #include <linux/nfs_mount.h>
30631  #include <net/ipv6.h>
30632 diff -NurpP linux-2.6.33-vs2.3.0.36.30.1/security/commoncap.c linux-2.6.33-vs2.3.0.36.30.2/security/commoncap.c
30633 --- linux-2.6.33-vs2.3.0.36.30.1/security/commoncap.c   2010-02-25 12:02:16.000000000 +0100
30634 +++ linux-2.6.33-vs2.3.0.36.30.2/security/commoncap.c   2010-03-05 15:30:01.000000000 +0100
30635 @@ -587,7 +587,7 @@ int cap_inode_setxattr(struct dentry *de
30636  
30637         if (!strncmp(name, XATTR_SECURITY_PREFIX,
30638                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
30639 -           !capable(CAP_SYS_ADMIN))
30640 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
30641                 return -EPERM;
30642         return 0;
30643  }
30644 diff -NurpP linux-2.6.33-vs2.3.0.36.30.1/fs/xattr.c linux-2.6.33-vs2.3.0.36.30.2/fs/xattr.c
30645 --- linux-2.6.33-vs2.3.0.36.30.1/fs/xattr.c     2010-02-25 12:02:16.000000000 +0100
30646 +++ linux-2.6.33-vs2.3.0.36.30.2/fs/xattr.c     2010-03-05 19:55:41.000000000 +0100
30647 @@ -50,7 +50,7 @@ xattr_permission(struct inode *inode, co
30648          * The trusted.* namespace can only be accessed by a privileged user.
30649          */
30650         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
30651 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
30652 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
30653  
30654         /* In user.* namespace, only regular files and directories can have
30655          * extended attributes. For sticky directories, only the owner and
30656 diff -NurpP linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/context.h linux-2.6.33-vs2.3.0.36.30.2/include/linux/vserver/context.h
30657 --- linux-2.6.33-vs2.3.0.36.30.1/include/linux/vserver/context.h        2010-02-25 12:02:16.000000000 +0100
30658 +++ linux-2.6.33-vs2.3.0.36.30.2/include/linux/vserver/context.h        2010-03-05 19:53:00.000000000 +0100
30659 @@ -60,6 +60,7 @@
30660  #define VXC_SET_UTSNAME                0x00000001
30661  #define VXC_SET_RLIMIT         0x00000002
30662  #define VXC_FS_SECURITY                0x00000004
30663 +#define VXC_FS_TRUSTED         0x00000008
30664  #define VXC_TIOCSTI            0x00000010
30665  
30666  /* was VXC_RAW_ICMP            0x00000100 */
This page took 2.605886 seconds and 4 git commands to generate.