]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- http://vserver.13thfloor.at/Experimental/patch-2.6.32.10-vs2.3.0.36.29.2.diff
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.32.10/arch/alpha/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/Kconfig
2 --- linux-2.6.32.10/arch/alpha/Kconfig  2009-12-03 20:01:49.000000000 +0100
3 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/Kconfig  2009-12-03 20:04:56.000000000 +0100
4 @@ -674,6 +674,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.32.10/arch/alpha/kernel/entry.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/kernel/entry.S
14 --- linux-2.6.32.10/arch/alpha/kernel/entry.S   2009-06-11 17:11:46.000000000 +0200
15 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/kernel/entry.S   2009-12-03 20:04:56.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.32.10/arch/alpha/kernel/osf_sys.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.32.10/arch/alpha/kernel/osf_sys.c 2010-03-18 16:17:26.000000000 +0100
50 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/kernel/osf_sys.c 2010-01-20 04:21:33.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.32.10/arch/alpha/kernel/ptrace.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.32.10/arch/alpha/kernel/ptrace.c  2009-09-10 15:25:14.000000000 +0200
62 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/kernel/ptrace.c  2009-12-03 20:04:56.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.32.10/arch/alpha/kernel/systbls.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/kernel/systbls.S
72 --- linux-2.6.32.10/arch/alpha/kernel/systbls.S 2009-03-24 14:18:08.000000000 +0100
73 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/kernel/systbls.S 2009-12-03 20:04:56.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.32.10/arch/alpha/kernel/traps.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/kernel/traps.c
84 --- linux-2.6.32.10/arch/alpha/kernel/traps.c   2009-06-11 17:11:46.000000000 +0200
85 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/kernel/traps.c   2009-12-03 20:04:56.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.32.10/arch/alpha/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/mm/fault.c
97 --- linux-2.6.32.10/arch/alpha/mm/fault.c       2009-09-10 15:25:14.000000000 +0200
98 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/alpha/mm/fault.c       2009-12-03 20:04:56.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.32.10/arch/arm/include/asm/tlb.h linux-2.6.32.10-vs2.3.0.36.29.2/arch/arm/include/asm/tlb.h
111 --- linux-2.6.32.10/arch/arm/include/asm/tlb.h  2009-09-10 15:25:15.000000000 +0200
112 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/arm/include/asm/tlb.h  2010-02-19 16:17:49.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.32.10/arch/arm/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/arm/Kconfig
122 --- linux-2.6.32.10/arch/arm/Kconfig    2009-12-03 20:01:49.000000000 +0100
123 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/arm/Kconfig    2009-12-03 20:04:56.000000000 +0100
124 @@ -1512,6 +1512,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.32.10/arch/arm/kernel/calls.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/arm/kernel/calls.S
134 --- linux-2.6.32.10/arch/arm/kernel/calls.S     2010-03-18 16:17:26.000000000 +0100
135 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/arm/kernel/calls.S     2010-01-20 04:21:33.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.32.10/arch/arm/kernel/process.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/arm/kernel/process.c
146 --- linux-2.6.32.10/arch/arm/kernel/process.c   2009-12-03 20:01:50.000000000 +0100
147 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/arm/kernel/process.c   2009-12-03 20:04:56.000000000 +0100
148 @@ -269,7 +269,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.32.10/arch/arm/kernel/traps.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/arm/kernel/traps.c
159 --- linux-2.6.32.10/arch/arm/kernel/traps.c     2009-12-03 20:01:50.000000000 +0100
160 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/arm/kernel/traps.c     2009-12-03 20:04:56.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.32.10/arch/avr32/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/avr32/mm/fault.c
173 --- linux-2.6.32.10/arch/avr32/mm/fault.c       2009-09-10 15:25:20.000000000 +0200
174 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/avr32/mm/fault.c       2009-12-03 20:04:56.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.32.10/arch/cris/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/cris/Kconfig
186 --- linux-2.6.32.10/arch/cris/Kconfig   2009-06-11 17:11:56.000000000 +0200
187 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/cris/Kconfig   2009-12-03 20:04:56.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.32.10/arch/cris/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/cris/mm/fault.c
198 --- linux-2.6.32.10/arch/cris/mm/fault.c        2009-12-03 20:01:56.000000000 +0100
199 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/cris/mm/fault.c        2009-12-03 20:04:56.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.32.10/arch/frv/kernel/kernel_thread.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/frv/kernel/kernel_thread.S
211 --- linux-2.6.32.10/arch/frv/kernel/kernel_thread.S     2008-12-25 00:26:37.000000000 +0100
212 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/frv/kernel/kernel_thread.S     2009-12-03 20:04:56.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.32.10/arch/frv/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/frv/mm/fault.c
223 --- linux-2.6.32.10/arch/frv/mm/fault.c 2009-09-10 15:25:22.000000000 +0200
224 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/frv/mm/fault.c 2009-12-03 20:04:56.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.32.10/arch/h8300/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/h8300/Kconfig
236 --- linux-2.6.32.10/arch/h8300/Kconfig  2009-03-24 14:18:24.000000000 +0100
237 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/h8300/Kconfig  2009-12-03 20:04:56.000000000 +0100
238 @@ -226,6 +226,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.32.10/arch/ia64/ia32/ia32_entry.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/ia32/ia32_entry.S
248 --- linux-2.6.32.10/arch/ia64/ia32/ia32_entry.S 2009-06-11 17:11:57.000000000 +0200
249 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/ia32/ia32_entry.S 2009-12-03 20:04:56.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.32.10/arch/ia64/include/asm/tlb.h linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/include/asm/tlb.h
260 --- linux-2.6.32.10/arch/ia64/include/asm/tlb.h 2009-09-10 15:25:22.000000000 +0200
261 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/include/asm/tlb.h 2009-12-31 14:37:34.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.32.10/arch/ia64/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/Kconfig
271 --- linux-2.6.32.10/arch/ia64/Kconfig   2009-12-03 20:01:56.000000000 +0100
272 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/Kconfig   2009-12-03 20:04:56.000000000 +0100
273 @@ -685,6 +685,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.32.10/arch/ia64/kernel/entry.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/kernel/entry.S
283 --- linux-2.6.32.10/arch/ia64/kernel/entry.S    2009-09-10 15:25:22.000000000 +0200
284 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/kernel/entry.S    2009-12-03 20:04:56.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.32.10/arch/ia64/kernel/perfmon.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/kernel/perfmon.c
295 --- linux-2.6.32.10/arch/ia64/kernel/perfmon.c  2009-09-10 15:25:22.000000000 +0200
296 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/kernel/perfmon.c  2009-12-03 20:04:56.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 @@ -2372,7 +2373,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.32.10/arch/ia64/kernel/process.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/kernel/process.c
315 --- linux-2.6.32.10/arch/ia64/kernel/process.c  2009-12-03 20:01:56.000000000 +0100
316 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/kernel/process.c  2009-12-03 20:04:56.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.32.10/arch/ia64/kernel/ptrace.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/kernel/ptrace.c
329 --- linux-2.6.32.10/arch/ia64/kernel/ptrace.c   2009-09-10 15:25:22.000000000 +0200
330 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/kernel/ptrace.c   2009-12-03 20:04:56.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.32.10/arch/ia64/kernel/traps.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/kernel/traps.c
340 --- linux-2.6.32.10/arch/ia64/kernel/traps.c    2008-12-25 00:26:37.000000000 +0100
341 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/kernel/traps.c    2009-12-03 20:04:56.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.32.10/arch/ia64/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/mm/fault.c
367 --- linux-2.6.32.10/arch/ia64/mm/fault.c        2009-09-10 15:25:23.000000000 +0200
368 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/ia64/mm/fault.c        2009-12-03 20:04:56.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.32.10/arch/m32r/kernel/traps.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/m32r/kernel/traps.c
388 --- linux-2.6.32.10/arch/m32r/kernel/traps.c    2009-12-03 20:01:57.000000000 +0100
389 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/m32r/kernel/traps.c    2009-12-03 20:04:56.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.32.10/arch/m32r/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/m32r/mm/fault.c
403 --- linux-2.6.32.10/arch/m32r/mm/fault.c        2009-09-10 15:25:23.000000000 +0200
404 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/m32r/mm/fault.c        2009-12-03 20:04:56.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.32.10/arch/m68k/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68k/Kconfig
416 --- linux-2.6.32.10/arch/m68k/Kconfig   2009-12-03 20:01:57.000000000 +0100
417 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68k/Kconfig   2009-12-03 20:04:56.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.32.10/arch/m68k/kernel/ptrace.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68k/kernel/ptrace.c
428 --- linux-2.6.32.10/arch/m68k/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
429 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68k/kernel/ptrace.c   2009-12-03 20:04:56.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 @@ -269,6 +270,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.32.10/arch/m68k/kernel/traps.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68k/kernel/traps.c
448 --- linux-2.6.32.10/arch/m68k/kernel/traps.c    2009-09-10 15:25:23.000000000 +0200
449 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68k/kernel/traps.c    2009-12-03 20:04:56.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.32.10/arch/m68k/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68k/mm/fault.c
462 --- linux-2.6.32.10/arch/m68k/mm/fault.c        2009-09-10 15:25:23.000000000 +0200
463 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68k/mm/fault.c        2009-12-03 20:04:56.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.32.10/arch/m68knommu/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68knommu/Kconfig
475 --- linux-2.6.32.10/arch/m68knommu/Kconfig      2009-12-03 20:01:57.000000000 +0100
476 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68knommu/Kconfig      2009-12-03 20:04:56.000000000 +0100
477 @@ -727,6 +727,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.32.10/arch/m68knommu/kernel/traps.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68knommu/kernel/traps.c
487 --- linux-2.6.32.10/arch/m68knommu/kernel/traps.c       2009-09-10 15:25:23.000000000 +0200
488 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/m68knommu/kernel/traps.c       2009-12-03 20:04:56.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.32.10/arch/microblaze/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/microblaze/mm/fault.c
502 --- linux-2.6.32.10/arch/microblaze/mm/fault.c  2009-09-10 15:25:24.000000000 +0200
503 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/microblaze/mm/fault.c  2009-12-03 20:04:56.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.32.10/arch/mips/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/Kconfig
515 --- linux-2.6.32.10/arch/mips/Kconfig   2009-12-03 20:01:58.000000000 +0100
516 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/Kconfig   2009-12-03 20:04:56.000000000 +0100
517 @@ -2188,6 +2188,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.32.10/arch/mips/kernel/ptrace.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/ptrace.c
527 --- linux-2.6.32.10/arch/mips/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
528 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/ptrace.c   2009-12-03 20:04:56.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.32.10/arch/mips/kernel/scall32-o32.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/scall32-o32.S
548 --- linux-2.6.32.10/arch/mips/kernel/scall32-o32.S      2009-12-03 20:01:59.000000000 +0100
549 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/scall32-o32.S      2009-12-03 20:04:56.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.32.10/arch/mips/kernel/scall64-64.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/scall64-64.S
560 --- linux-2.6.32.10/arch/mips/kernel/scall64-64.S       2009-12-03 20:01:59.000000000 +0100
561 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/scall64-64.S       2009-12-03 20:04:56.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.32.10/arch/mips/kernel/scall64-n32.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/scall64-n32.S
572 --- linux-2.6.32.10/arch/mips/kernel/scall64-n32.S      2009-12-03 20:01:59.000000000 +0100
573 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/scall64-n32.S      2009-12-03 20:04:56.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.32.10/arch/mips/kernel/scall64-o32.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/scall64-o32.S
584 --- linux-2.6.32.10/arch/mips/kernel/scall64-o32.S      2009-12-03 20:01:59.000000000 +0100
585 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/scall64-o32.S      2009-12-03 20:04:56.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.32.10/arch/mips/kernel/traps.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/traps.c
596 --- linux-2.6.32.10/arch/mips/kernel/traps.c    2009-12-03 20:01:59.000000000 +0100
597 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/mips/kernel/traps.c    2009-12-03 20:04:56.000000000 +0100
598 @@ -335,9 +335,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.32.10/arch/mn10300/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/mn10300/mm/fault.c
613 --- linux-2.6.32.10/arch/mn10300/mm/fault.c     2009-09-10 15:25:39.000000000 +0200
614 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/mn10300/mm/fault.c     2009-12-03 20:04:56.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.32.10/arch/parisc/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/parisc/Kconfig
626 --- linux-2.6.32.10/arch/parisc/Kconfig 2009-12-03 20:02:00.000000000 +0100
627 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/parisc/Kconfig 2009-12-03 20:04:56.000000000 +0100
628 @@ -294,6 +294,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.32.10/arch/parisc/kernel/syscall_table.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/parisc/kernel/syscall_table.S
638 --- linux-2.6.32.10/arch/parisc/kernel/syscall_table.S  2009-12-03 20:02:00.000000000 +0100
639 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/parisc/kernel/syscall_table.S  2009-12-03 20:04:56.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.32.10/arch/parisc/kernel/traps.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/parisc/kernel/traps.c
650 --- linux-2.6.32.10/arch/parisc/kernel/traps.c  2009-09-10 15:25:40.000000000 +0200
651 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/parisc/kernel/traps.c  2009-12-03 20:04:56.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.32.10/arch/parisc/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/parisc/mm/fault.c
676 --- linux-2.6.32.10/arch/parisc/mm/fault.c      2009-09-10 15:25:40.000000000 +0200
677 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/parisc/mm/fault.c      2009-12-03 20:04:56.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.32.10/arch/powerpc/include/asm/unistd.h linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/include/asm/unistd.h
701 --- linux-2.6.32.10/arch/powerpc/include/asm/unistd.h   2009-12-03 20:02:01.000000000 +0100
702 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/include/asm/unistd.h   2009-12-03 20:04:56.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.32.10/arch/powerpc/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/Kconfig
713 --- linux-2.6.32.10/arch/powerpc/Kconfig        2009-12-03 20:02:00.000000000 +0100
714 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/Kconfig        2009-12-03 20:04:56.000000000 +0100
715 @@ -943,6 +943,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.32.10/arch/powerpc/kernel/irq.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/kernel/irq.c
725 --- linux-2.6.32.10/arch/powerpc/kernel/irq.c   2009-12-03 20:02:01.000000000 +0100
726 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/kernel/irq.c   2009-12-03 20:04:56.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.32.10/arch/powerpc/kernel/process.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/kernel/process.c
736 --- linux-2.6.32.10/arch/powerpc/kernel/process.c       2010-03-18 16:17:26.000000000 +0100
737 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/kernel/process.c       2010-02-12 10:59:55.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.32.10/arch/powerpc/kernel/traps.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/kernel/traps.c
751 --- linux-2.6.32.10/arch/powerpc/kernel/traps.c 2009-09-10 15:25:41.000000000 +0200
752 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/kernel/traps.c 2009-12-03 20:04:56.000000000 +0100
753 @@ -931,8 +931,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.32.10/arch/powerpc/kernel/vdso.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/kernel/vdso.c
766 --- linux-2.6.32.10/arch/powerpc/kernel/vdso.c  2009-12-03 20:02:02.000000000 +0100
767 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/kernel/vdso.c  2009-12-03 20:04:56.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.32.10/arch/powerpc/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/mm/fault.c
777 --- linux-2.6.32.10/arch/powerpc/mm/fault.c     2009-12-03 20:02:02.000000000 +0100
778 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/powerpc/mm/fault.c     2009-12-03 20:04:56.000000000 +0100
779 @@ -358,7 +358,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.32.10/arch/s390/include/asm/tlb.h linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/include/asm/tlb.h
790 --- linux-2.6.32.10/arch/s390/include/asm/tlb.h 2009-09-10 15:25:43.000000000 +0200
791 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/include/asm/tlb.h 2009-12-31 14:37:21.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.32.10/arch/s390/include/asm/unistd.h linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/include/asm/unistd.h
802 --- linux-2.6.32.10/arch/s390/include/asm/unistd.h      2009-12-03 20:02:03.000000000 +0100
803 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/include/asm/unistd.h      2009-12-30 00:58:47.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.32.10/arch/s390/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/Kconfig
814 --- linux-2.6.32.10/arch/s390/Kconfig   2009-12-03 20:02:03.000000000 +0100
815 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/Kconfig   2009-12-03 20:04:56.000000000 +0100
816 @@ -616,6 +616,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.32.10/arch/s390/kernel/ptrace.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/kernel/ptrace.c
826 --- linux-2.6.32.10/arch/s390/kernel/ptrace.c   2009-12-03 20:02:03.000000000 +0100
827 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/kernel/ptrace.c   2009-12-03 20:04:56.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.32.10/arch/s390/kernel/syscalls.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/kernel/syscalls.S
837 --- linux-2.6.32.10/arch/s390/kernel/syscalls.S 2009-12-03 20:02:03.000000000 +0100
838 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/kernel/syscalls.S 2009-12-03 20:04:56.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.32.10/arch/s390/lib/uaccess_pt.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/lib/uaccess_pt.c
849 --- linux-2.6.32.10/arch/s390/lib/uaccess_pt.c  2009-09-10 15:25:43.000000000 +0200
850 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/s390/lib/uaccess_pt.c  2009-12-03 20:04:56.000000000 +0100
851 @@ -90,7 +90,8 @@ out_of_memory:
852                 down_read(&mm->mmap_sem);
853                 goto survive;
854         }
855 -       printk("VM: killing process %s\n", current->comm);
856 +       printk("VM: killing process %s(%d:#%u)\n",
857 +               current->comm, task_pid_nr(current), current->xid);
858         return ret;
859  
860  out_sigbus:
861 diff -NurpP --minimal linux-2.6.32.10/arch/sh/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/sh/Kconfig
862 --- linux-2.6.32.10/arch/sh/Kconfig     2009-12-03 20:02:03.000000000 +0100
863 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/sh/Kconfig     2009-12-03 20:04:56.000000000 +0100
864 @@ -853,6 +853,8 @@ source "fs/Kconfig"
865  
866  source "arch/sh/Kconfig.debug"
867  
868 +source "kernel/vserver/Kconfig"
869 +
870  source "security/Kconfig"
871  
872  source "crypto/Kconfig"
873 diff -NurpP --minimal linux-2.6.32.10/arch/sh/kernel/irq.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/sh/kernel/irq.c
874 --- linux-2.6.32.10/arch/sh/kernel/irq.c        2009-12-03 20:02:10.000000000 +0100
875 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/sh/kernel/irq.c        2009-12-03 20:04:56.000000000 +0100
876 @@ -12,6 +12,7 @@
877  #include <linux/kernel_stat.h>
878  #include <linux/seq_file.h>
879  #include <linux/ftrace.h>
880 +// #include <linux/vs_context.h>
881  #include <asm/processor.h>
882  #include <asm/machvec.h>
883  #include <asm/uaccess.h>
884 diff -NurpP --minimal linux-2.6.32.10/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/sh/kernel/vsyscall/vsyscall.c
885 --- linux-2.6.32.10/arch/sh/kernel/vsyscall/vsyscall.c  2009-03-24 14:18:42.000000000 +0100
886 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/sh/kernel/vsyscall/vsyscall.c  2009-12-03 20:04:56.000000000 +0100
887 @@ -19,6 +19,7 @@
888  #include <linux/elf.h>
889  #include <linux/sched.h>
890  #include <linux/err.h>
891 +#include <linux/vs_memory.h>
892  
893  /*
894   * Should the kernel map a VDSO page into processes and pass its
895 diff -NurpP --minimal linux-2.6.32.10/arch/sh/mm/fault_32.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/sh/mm/fault_32.c
896 --- linux-2.6.32.10/arch/sh/mm/fault_32.c       2009-12-03 20:02:14.000000000 +0100
897 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/sh/mm/fault_32.c       2009-12-03 20:04:56.000000000 +0100
898 @@ -292,7 +292,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.32.10/arch/sh/mm/tlbflush_64.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/sh/mm/tlbflush_64.c
909 --- linux-2.6.32.10/arch/sh/mm/tlbflush_64.c    2009-12-03 20:02:14.000000000 +0100
910 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/sh/mm/tlbflush_64.c    2009-12-03 20:04:56.000000000 +0100
911 @@ -306,7 +306,8 @@ out_of_memory:
912                 down_read(&mm->mmap_sem);
913                 goto survive;
914         }
915 -       printk("VM: killing process %s\n", tsk->comm);
916 +       printk("VM: killing process %s(%d:#%u)\n",
917 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
918         if (user_mode(regs))
919                 do_group_exit(SIGKILL);
920         goto no_context;
921 diff -NurpP --minimal linux-2.6.32.10/arch/sparc/include/asm/tlb_64.h linux-2.6.32.10-vs2.3.0.36.29.2/arch/sparc/include/asm/tlb_64.h
922 --- linux-2.6.32.10/arch/sparc/include/asm/tlb_64.h     2009-09-10 15:25:45.000000000 +0200
923 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/sparc/include/asm/tlb_64.h     2009-12-03 20:04:56.000000000 +0100
924 @@ -3,6 +3,7 @@
925  
926  #include <linux/swap.h>
927  #include <linux/pagemap.h>
928 +#include <linux/vs_memory.h>
929  #include <asm/pgalloc.h>
930  #include <asm/tlbflush.h>
931  #include <asm/mmu_context.h>
932 diff -NurpP --minimal linux-2.6.32.10/arch/sparc/include/asm/unistd.h linux-2.6.32.10-vs2.3.0.36.29.2/arch/sparc/include/asm/unistd.h
933 --- linux-2.6.32.10/arch/sparc/include/asm/unistd.h     2009-12-03 20:02:15.000000000 +0100
934 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/sparc/include/asm/unistd.h     2009-12-03 20:04:56.000000000 +0100
935 @@ -335,7 +335,7 @@
936  #define __NR_timer_getoverrun  264
937  #define __NR_timer_delete      265
938  #define __NR_timer_create      266
939 -/* #define __NR_vserver                267 Reserved for VSERVER */
940 +#define __NR_vserver           267
941  #define __NR_io_setup          268
942  #define __NR_io_destroy                269
943  #define __NR_io_submit         270
944 diff -NurpP --minimal linux-2.6.32.10/arch/sparc/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/sparc/Kconfig
945 --- linux-2.6.32.10/arch/sparc/Kconfig  2009-12-03 20:02:14.000000000 +0100
946 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/sparc/Kconfig  2009-12-03 20:04:56.000000000 +0100
947 @@ -550,6 +550,8 @@ source "fs/Kconfig"
948  
949  source "arch/sparc/Kconfig.debug"
950  
951 +source "kernel/vserver/Kconfig"
952 +
953  source "security/Kconfig"
954  
955  source "crypto/Kconfig"
956 diff -NurpP --minimal linux-2.6.32.10/arch/sparc/kernel/systbls_32.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/sparc/kernel/systbls_32.S
957 --- linux-2.6.32.10/arch/sparc/kernel/systbls_32.S      2010-03-18 16:17:27.000000000 +0100
958 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/sparc/kernel/systbls_32.S      2010-01-20 04:21:33.000000000 +0100
959 @@ -70,7 +70,7 @@ sys_call_table:
960  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
961  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
962  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
963 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
964 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
965  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
966  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
967  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
968 diff -NurpP --minimal linux-2.6.32.10/arch/sparc/kernel/systbls_64.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/sparc/kernel/systbls_64.S
969 --- linux-2.6.32.10/arch/sparc/kernel/systbls_64.S      2010-03-18 16:17:27.000000000 +0100
970 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/sparc/kernel/systbls_64.S      2010-01-20 04:21:33.000000000 +0100
971 @@ -71,7 +71,7 @@ sys_call_table32:
972  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
973         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
974  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
975 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
976 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
977  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
978         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
979  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
980 @@ -146,7 +146,7 @@ sys_call_table:
981  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
982         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
983  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
984 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
985 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
986  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
987         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
988  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
989 diff -NurpP --minimal linux-2.6.32.10/arch/um/include/asm/tlb.h linux-2.6.32.10-vs2.3.0.36.29.2/arch/um/include/asm/tlb.h
990 --- linux-2.6.32.10/arch/um/include/asm/tlb.h   2009-09-10 15:25:46.000000000 +0200
991 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/um/include/asm/tlb.h   2010-03-13 21:49:04.000000000 +0100
992 @@ -3,6 +3,7 @@
993  
994  #include <linux/pagemap.h>
995  #include <linux/swap.h>
996 +#include <linux/vs_memory.h>
997  #include <asm/percpu.h>
998  #include <asm/pgalloc.h>
999  #include <asm/tlbflush.h>
1000 diff -NurpP --minimal linux-2.6.32.10/arch/um/Kconfig.rest linux-2.6.32.10-vs2.3.0.36.29.2/arch/um/Kconfig.rest
1001 --- linux-2.6.32.10/arch/um/Kconfig.rest        2009-06-11 17:12:19.000000000 +0200
1002 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/um/Kconfig.rest        2010-03-13 21:49:04.000000000 +0100
1003 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
1004  
1005  source "fs/Kconfig"
1006  
1007 +source "kernel/vserver/Kconfig"
1008 +
1009  source "security/Kconfig"
1010  
1011  source "crypto/Kconfig"
1012 diff -NurpP --minimal linux-2.6.32.10/arch/x86/ia32/ia32entry.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/x86/ia32/ia32entry.S
1013 --- linux-2.6.32.10/arch/x86/ia32/ia32entry.S   2010-03-18 16:17:27.000000000 +0100
1014 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/x86/ia32/ia32entry.S   2010-01-20 04:21:33.000000000 +0100
1015 @@ -777,7 +777,7 @@ ia32_sys_call_table:
1016         .quad sys_tgkill                /* 270 */
1017         .quad compat_sys_utimes
1018         .quad sys32_fadvise64_64
1019 -       .quad quiet_ni_syscall  /* sys_vserver */
1020 +       .quad sys32_vserver
1021         .quad sys_mbind
1022         .quad compat_sys_get_mempolicy  /* 275 */
1023         .quad sys_set_mempolicy
1024 diff -NurpP --minimal linux-2.6.32.10/arch/x86/include/asm/unistd_64.h linux-2.6.32.10-vs2.3.0.36.29.2/arch/x86/include/asm/unistd_64.h
1025 --- linux-2.6.32.10/arch/x86/include/asm/unistd_64.h    2009-12-03 20:02:16.000000000 +0100
1026 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/x86/include/asm/unistd_64.h    2009-12-03 20:04:56.000000000 +0100
1027 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
1028  #define __NR_utimes                            235
1029  __SYSCALL(__NR_utimes, sys_utimes)
1030  #define __NR_vserver                           236
1031 -__SYSCALL(__NR_vserver, sys_ni_syscall)
1032 +__SYSCALL(__NR_vserver, sys_vserver)
1033  #define __NR_mbind                             237
1034  __SYSCALL(__NR_mbind, sys_mbind)
1035  #define __NR_set_mempolicy                     238
1036 diff -NurpP --minimal linux-2.6.32.10/arch/x86/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/arch/x86/Kconfig
1037 --- linux-2.6.32.10/arch/x86/Kconfig    2010-03-18 16:17:27.000000000 +0100
1038 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/x86/Kconfig    2010-02-12 10:59:55.000000000 +0100
1039 @@ -2079,6 +2079,8 @@ source "fs/Kconfig"
1040  
1041  source "arch/x86/Kconfig.debug"
1042  
1043 +source "kernel/vserver/Kconfig"
1044 +
1045  source "security/Kconfig"
1046  
1047  source "crypto/Kconfig"
1048 diff -NurpP --minimal linux-2.6.32.10/arch/x86/kernel/syscall_table_32.S linux-2.6.32.10-vs2.3.0.36.29.2/arch/x86/kernel/syscall_table_32.S
1049 --- linux-2.6.32.10/arch/x86/kernel/syscall_table_32.S  2010-03-18 16:17:27.000000000 +0100
1050 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/x86/kernel/syscall_table_32.S  2010-01-20 04:21:33.000000000 +0100
1051 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1052         .long sys_tgkill        /* 270 */
1053         .long sys_utimes
1054         .long sys_fadvise64_64
1055 -       .long sys_ni_syscall    /* sys_vserver */
1056 +       .long sys_vserver
1057         .long sys_mbind
1058         .long sys_get_mempolicy
1059         .long sys_set_mempolicy
1060 diff -NurpP --minimal linux-2.6.32.10/arch/xtensa/mm/fault.c linux-2.6.32.10-vs2.3.0.36.29.2/arch/xtensa/mm/fault.c
1061 --- linux-2.6.32.10/arch/xtensa/mm/fault.c      2009-09-10 15:25:48.000000000 +0200
1062 +++ linux-2.6.32.10-vs2.3.0.36.29.2/arch/xtensa/mm/fault.c      2009-12-03 20:04:56.000000000 +0100
1063 @@ -151,7 +151,8 @@ out_of_memory:
1064                 down_read(&mm->mmap_sem);
1065                 goto survive;
1066         }
1067 -       printk("VM: killing process %s\n", current->comm);
1068 +       printk("VM: killing process %s(%d:#%u)\n",
1069 +               current->comm, task_pid_nr(current), current->xid);
1070         if (user_mode(regs))
1071                 do_group_exit(SIGKILL);
1072         bad_page_fault(regs, address, SIGKILL);
1073 diff -NurpP --minimal linux-2.6.32.10/Documentation/scheduler/sched-cfs-hard-limits.txt linux-2.6.32.10-vs2.3.0.36.29.2/Documentation/scheduler/sched-cfs-hard-limits.txt
1074 --- linux-2.6.32.10/Documentation/scheduler/sched-cfs-hard-limits.txt   1970-01-01 01:00:00.000000000 +0100
1075 +++ linux-2.6.32.10-vs2.3.0.36.29.2/Documentation/scheduler/sched-cfs-hard-limits.txt   2009-12-03 20:04:56.000000000 +0100
1076 @@ -0,0 +1,48 @@
1077 +CPU HARD LIMITS FOR CFS GROUPS
1078 +==============================
1079 +
1080 +1. Overview
1081 +2. Interface
1082 +3. Examples
1083 +
1084 +1. Overview
1085 +-----------
1086 +
1087 +CFS is a proportional share scheduler which tries to divide the CPU time
1088 +proportionately between tasks or groups of tasks (task group/cgroup) depending
1089 +on the priority/weight of the task or shares assigned to groups of tasks.
1090 +In CFS, a task/task group can get more than its share of CPU if there are
1091 +enough idle CPU cycles available in the system, due to the work conserving
1092 +nature of the scheduler. However in certain scenarios (like pay-per-use),
1093 +it is desirable not to provide extra time to a group even in the presence
1094 +of idle CPU cycles. This is where hard limiting can be of use.
1095 +
1096 +Hard limits for task groups can be set by specifying how much CPU runtime a
1097 +group can consume within a given period. If the group consumes more CPU time
1098 +than the runtime in a given period, it gets throttled. None of the tasks of
1099 +the throttled group gets to run until the runtime of the group gets refreshed
1100 +at the beginning of the next period.
1101 +
1102 +2. Interface
1103 +------------
1104 +
1105 +Hard limit feature adds 2 cgroup files for CFS group scheduler:
1106 +
1107 +cfs_runtime_us: Hard limit for the group in microseconds.
1108 +
1109 +cfs_period_us: Time period in microseconds within which hard limits is
1110 +enforced.
1111 +
1112 +A group gets created with default values for runtime (infinite runtime which
1113 +means hard limits disabled) and period (0.5s). Each group can set its own
1114 +values for runtime and period independent of other groups in the system.
1115 +
1116 +3. Examples
1117 +-----------
1118 +
1119 +# mount -t cgroup -ocpu none /cgroups/
1120 +# cd /cgroups
1121 +# mkdir 1
1122 +# cd 1/
1123 +# echo 250000 > cfs_runtime_us /* set a 250ms runtime or limit */
1124 +# echo 500000 > cfs_period_us /* set a 500ms period */
1125 diff -NurpP --minimal linux-2.6.32.10/Documentation/vserver/debug.txt linux-2.6.32.10-vs2.3.0.36.29.2/Documentation/vserver/debug.txt
1126 --- linux-2.6.32.10/Documentation/vserver/debug.txt     1970-01-01 01:00:00.000000000 +0100
1127 +++ linux-2.6.32.10-vs2.3.0.36.29.2/Documentation/vserver/debug.txt     2009-12-03 20:04:56.000000000 +0100
1128 @@ -0,0 +1,154 @@
1129 +
1130 +debug_cvirt:
1131 +
1132 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
1133 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
1134 +
1135 +debug_dlim:
1136 +
1137 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
1138 +       "FREE  (%p,#%d)%c inode"
1139 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
1140 +       "FREE  (%p,#%d)%c %lld bytes"
1141 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
1142 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
1143 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
1144 +       "rcu_free_dl_info(%p)"
1145 + 4  10 "alloc_dl_info(%p,%d) = %p"
1146 +       "dealloc_dl_info(%p)"
1147 +       "get_dl_info(%p[#%d.%d])"
1148 +       "put_dl_info(%p[#%d.%d])"
1149 + 5  20 "alloc_dl_info(%p,%d)*"
1150 + 6  40 "__hash_dl_info: %p[#%d]"
1151 +       "__unhash_dl_info: %p[#%d]"
1152 + 7  80 "locate_dl_info(%p,#%d) = %p"
1153 +
1154 +debug_misc:
1155 +
1156 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
1157 +       "new_dqhash: %p [#0x%08x]"
1158 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
1159 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
1160 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
1161 +       "vroot_get_real_bdev not set"
1162 + 1   2 "cow_break_link(»%s«)"
1163 +       "temp copy Â»%s«"
1164 + 2   4 "dentry_open(new): %p"
1165 +       "dentry_open(old): %p"
1166 +       "lookup_create(new): %p"
1167 +       "old path Â»%s«"
1168 +       "path_lookup(old): %d"
1169 +       "vfs_create(new): %d"
1170 +       "vfs_rename: %d"
1171 +       "vfs_sendfile: %d"
1172 + 3   8 "fput(new_file=%p[#%d])"
1173 +       "fput(old_file=%p[#%d])"
1174 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
1175 +       "vx_info_kill(%p[#%d],%d,%d)*"
1176 + 5  20 "vs_reboot(%p[#%d],%d)"
1177 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
1178 +
1179 +debug_net:
1180 +
1181 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
1182 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
1183 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
1184 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
1185 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
1186 + 6  40 "sk,egf: %p [#%d] (from %d)"
1187 +       "sk,egn: %p [#%d] (from %d)"
1188 +       "sk,req: %p [#%d] (from %d)"
1189 +       "sk: %p [#%d] (from %d)"
1190 +       "tw: %p [#%d] (from %d)"
1191 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
1192 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
1193 +
1194 +debug_nid:
1195 +
1196 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
1197 +       "alloc_nx_info(%d) = %p"
1198 +       "create_nx_info(%d) (dynamic rejected)"
1199 +       "create_nx_info(%d) = %p (already there)"
1200 +       "create_nx_info(%d) = %p (new)"
1201 +       "dealloc_nx_info(%p)"
1202 + 1   2 "alloc_nx_info(%d)*"
1203 +       "create_nx_info(%d)*"
1204 + 2   4 "get_nx_info(%p[#%d.%d])"
1205 +       "put_nx_info(%p[#%d.%d])"
1206 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
1207 +       "clr_nx_info(%p[#%d.%d])"
1208 +       "init_nx_info(%p[#%d.%d])"
1209 +       "release_nx_info(%p[#%d.%d.%d]) %p"
1210 +       "set_nx_info(%p[#%d.%d])"
1211 + 4  10 "__hash_nx_info: %p[#%d]"
1212 +       "__nx_dynamic_id: [#%d]"
1213 +       "__unhash_nx_info: %p[#%d.%d.%d]"
1214 + 5  20 "moved task %p into nxi:%p[#%d]"
1215 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
1216 +       "task_get_nx_info(%p)"
1217 + 6  40 "nx_clear_persistent(%p[#%d])"
1218 +
1219 +debug_quota:
1220 +
1221 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
1222 + 1   2 "quota_sync_dqh(%p,%d)"
1223 +       "sync_dquots(%p,%d)"
1224 +       "sync_dquots_dqh(%p,%d)"
1225 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
1226 +
1227 +debug_switch:
1228 +
1229 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
1230 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
1231 + 4  10 "%s: (%s %s) returned %s with %d"
1232 +
1233 +debug_tag:
1234 +
1235 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
1236 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1237 +
1238 +debug_xid:
1239 +
1240 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1241 +       "alloc_vx_info(%d) = %p"
1242 +       "alloc_vx_info(%d)*"
1243 +       "create_vx_info(%d) (dynamic rejected)"
1244 +       "create_vx_info(%d) = %p (already there)"
1245 +       "create_vx_info(%d) = %p (new)"
1246 +       "dealloc_vx_info(%p)"
1247 +       "loc_vx_info(%d) = %p (found)"
1248 +       "loc_vx_info(%d) = %p (new)"
1249 +       "loc_vx_info(%d) = %p (not available)"
1250 + 1   2 "create_vx_info(%d)*"
1251 +       "loc_vx_info(%d)*"
1252 + 2   4 "get_vx_info(%p[#%d.%d])"
1253 +       "put_vx_info(%p[#%d.%d])"
1254 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1255 +       "clr_vx_info(%p[#%d.%d])"
1256 +       "init_vx_info(%p[#%d.%d])"
1257 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1258 +       "set_vx_info(%p[#%d.%d])"
1259 + 4  10 "__hash_vx_info: %p[#%d]"
1260 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1261 +       "__vx_dynamic_id: [#%d]"
1262 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1263 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1264 +       "moved task %p into vxi:%p[#%d]"
1265 +       "task_get_vx_info(%p)"
1266 +       "vx_migrate_task(%p,%p[#%d.%d])"
1267 + 6  40 "vx_clear_persistent(%p[#%d])"
1268 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1269 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1270 +       "vx_set_persistent(%p[#%d])"
1271 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1272 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1273 +
1274 +
1275 +debug_limit:
1276 +
1277 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1278 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1279 +
1280 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1281 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1282 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1283 diff -NurpP --minimal linux-2.6.32.10/drivers/block/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/drivers/block/Kconfig
1284 --- linux-2.6.32.10/drivers/block/Kconfig       2009-09-10 15:25:49.000000000 +0200
1285 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/block/Kconfig       2009-12-03 20:04:56.000000000 +0100
1286 @@ -271,6 +271,13 @@ config BLK_DEV_CRYPTOLOOP
1287           instead, which can be configured to be on-disk compatible with the
1288           cryptoloop device.
1289  
1290 +config BLK_DEV_VROOT
1291 +       tristate "Virtual Root device support"
1292 +       depends on QUOTACTL
1293 +       ---help---
1294 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1295 +         partition within a virtual server without compromising security.
1296 +
1297  config BLK_DEV_NBD
1298         tristate "Network block device support"
1299         depends on NET
1300 diff -NurpP --minimal linux-2.6.32.10/drivers/block/loop.c linux-2.6.32.10-vs2.3.0.36.29.2/drivers/block/loop.c
1301 --- linux-2.6.32.10/drivers/block/loop.c        2009-12-03 20:02:19.000000000 +0100
1302 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/block/loop.c        2009-12-03 20:04:56.000000000 +0100
1303 @@ -74,6 +74,7 @@
1304  #include <linux/gfp.h>
1305  #include <linux/kthread.h>
1306  #include <linux/splice.h>
1307 +#include <linux/vs_context.h>
1308  
1309  #include <asm/uaccess.h>
1310  
1311 @@ -812,6 +813,7 @@ static int loop_set_fd(struct loop_devic
1312         lo->lo_blocksize = lo_blocksize;
1313         lo->lo_device = bdev;
1314         lo->lo_flags = lo_flags;
1315 +       lo->lo_xid = vx_current_xid();
1316         lo->lo_backing_file = file;
1317         lo->transfer = transfer_none;
1318         lo->ioctl = NULL;
1319 @@ -937,6 +939,7 @@ static int loop_clr_fd(struct loop_devic
1320         lo->lo_encrypt_key_size = 0;
1321         lo->lo_flags = 0;
1322         lo->lo_thread = NULL;
1323 +       lo->lo_xid = 0;
1324         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1325         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1326         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1327 @@ -971,7 +974,7 @@ loop_set_status(struct loop_device *lo, 
1328  
1329         if (lo->lo_encrypt_key_size &&
1330             lo->lo_key_owner != uid &&
1331 -           !capable(CAP_SYS_ADMIN))
1332 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1333                 return -EPERM;
1334         if (lo->lo_state != Lo_bound)
1335                 return -ENXIO;
1336 @@ -1055,7 +1058,8 @@ loop_get_status(struct loop_device *lo, 
1337         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1338         info->lo_encrypt_type =
1339                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1340 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1341 +       if (lo->lo_encrypt_key_size &&
1342 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1343                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1344                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1345                        lo->lo_encrypt_key_size);
1346 @@ -1399,6 +1403,9 @@ static int lo_open(struct block_device *
1347  {
1348         struct loop_device *lo = bdev->bd_disk->private_data;
1349  
1350 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1351 +               return -EACCES;
1352 +
1353         mutex_lock(&lo->lo_ctl_mutex);
1354         lo->lo_refcnt++;
1355         mutex_unlock(&lo->lo_ctl_mutex);
1356 diff -NurpP --minimal linux-2.6.32.10/drivers/block/Makefile linux-2.6.32.10-vs2.3.0.36.29.2/drivers/block/Makefile
1357 --- linux-2.6.32.10/drivers/block/Makefile      2009-09-10 15:25:49.000000000 +0200
1358 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/block/Makefile      2009-12-03 20:04:56.000000000 +0100
1359 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1360  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1361  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1362  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1363 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1364  
1365  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1366  
1367 diff -NurpP --minimal linux-2.6.32.10/drivers/block/vroot.c linux-2.6.32.10-vs2.3.0.36.29.2/drivers/block/vroot.c
1368 --- linux-2.6.32.10/drivers/block/vroot.c       1970-01-01 01:00:00.000000000 +0100
1369 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/block/vroot.c       2009-12-03 20:04:56.000000000 +0100
1370 @@ -0,0 +1,281 @@
1371 +/*
1372 + *  linux/drivers/block/vroot.c
1373 + *
1374 + *  written by Herbert Pötzl, 9/11/2002
1375 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1376 + *
1377 + *  based on the loop.c code by Theodore Ts'o.
1378 + *
1379 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1380 + * Redistribution of this file is permitted under the
1381 + * GNU General Public License.
1382 + *
1383 + */
1384 +
1385 +#include <linux/module.h>
1386 +#include <linux/moduleparam.h>
1387 +#include <linux/file.h>
1388 +#include <linux/major.h>
1389 +#include <linux/blkdev.h>
1390 +
1391 +#include <linux/vroot.h>
1392 +#include <linux/vs_context.h>
1393 +
1394 +
1395 +static int max_vroot = 8;
1396 +
1397 +static struct vroot_device *vroot_dev;
1398 +static struct gendisk **disks;
1399 +
1400 +
1401 +static int vroot_set_dev(
1402 +       struct vroot_device *vr,
1403 +       struct block_device *bdev,
1404 +       unsigned int arg)
1405 +{
1406 +       struct block_device *real_bdev;
1407 +       struct file *file;
1408 +       struct inode *inode;
1409 +       int error;
1410 +
1411 +       error = -EBUSY;
1412 +       if (vr->vr_state != Vr_unbound)
1413 +               goto out;
1414 +
1415 +       error = -EBADF;
1416 +       file = fget(arg);
1417 +       if (!file)
1418 +               goto out;
1419 +
1420 +       error = -EINVAL;
1421 +       inode = file->f_dentry->d_inode;
1422 +
1423 +
1424 +       if (S_ISBLK(inode->i_mode)) {
1425 +               real_bdev = inode->i_bdev;
1426 +               vr->vr_device = real_bdev;
1427 +               __iget(real_bdev->bd_inode);
1428 +       } else
1429 +               goto out_fput;
1430 +
1431 +       vxdprintk(VXD_CBIT(misc, 0),
1432 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1433 +               vr->vr_number, VXD_DEV(real_bdev));
1434 +
1435 +       vr->vr_state = Vr_bound;
1436 +       error = 0;
1437 +
1438 + out_fput:
1439 +       fput(file);
1440 + out:
1441 +       return error;
1442 +}
1443 +
1444 +static int vroot_clr_dev(
1445 +       struct vroot_device *vr,
1446 +       struct block_device *bdev)
1447 +{
1448 +       struct block_device *real_bdev;
1449 +
1450 +       if (vr->vr_state != Vr_bound)
1451 +               return -ENXIO;
1452 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1453 +               return -EBUSY;
1454 +
1455 +       real_bdev = vr->vr_device;
1456 +
1457 +       vxdprintk(VXD_CBIT(misc, 0),
1458 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1459 +               vr->vr_number, VXD_DEV(real_bdev));
1460 +
1461 +       bdput(real_bdev);
1462 +       vr->vr_state = Vr_unbound;
1463 +       vr->vr_device = NULL;
1464 +       return 0;
1465 +}
1466 +
1467 +
1468 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1469 +       unsigned int cmd, unsigned long arg)
1470 +{
1471 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1472 +       int err;
1473 +
1474 +       down(&vr->vr_ctl_mutex);
1475 +       switch (cmd) {
1476 +       case VROOT_SET_DEV:
1477 +               err = vroot_set_dev(vr, bdev, arg);
1478 +               break;
1479 +       case VROOT_CLR_DEV:
1480 +               err = vroot_clr_dev(vr, bdev);
1481 +               break;
1482 +       default:
1483 +               err = -EINVAL;
1484 +               break;
1485 +       }
1486 +       up(&vr->vr_ctl_mutex);
1487 +       return err;
1488 +}
1489 +
1490 +static int vr_open(struct block_device *bdev, fmode_t mode)
1491 +{
1492 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1493 +
1494 +       down(&vr->vr_ctl_mutex);
1495 +       vr->vr_refcnt++;
1496 +       up(&vr->vr_ctl_mutex);
1497 +       return 0;
1498 +}
1499 +
1500 +static int vr_release(struct gendisk *disk, fmode_t mode)
1501 +{
1502 +       struct vroot_device *vr = disk->private_data;
1503 +
1504 +       down(&vr->vr_ctl_mutex);
1505 +       --vr->vr_refcnt;
1506 +       up(&vr->vr_ctl_mutex);
1507 +       return 0;
1508 +}
1509 +
1510 +static struct block_device_operations vr_fops = {
1511 +       .owner =        THIS_MODULE,
1512 +       .open =         vr_open,
1513 +       .release =      vr_release,
1514 +       .ioctl =        vr_ioctl,
1515 +};
1516 +
1517 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1518 +{
1519 +       struct inode *inode = bdev->bd_inode;
1520 +       struct vroot_device *vr;
1521 +       struct block_device *real_bdev;
1522 +       int minor = iminor(inode);
1523 +
1524 +       vr = &vroot_dev[minor];
1525 +       real_bdev = vr->vr_device;
1526 +
1527 +       vxdprintk(VXD_CBIT(misc, 0),
1528 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1529 +               vr->vr_number, VXD_DEV(real_bdev));
1530 +
1531 +       if (vr->vr_state != Vr_bound)
1532 +               return ERR_PTR(-ENXIO);
1533 +
1534 +       __iget(real_bdev->bd_inode);
1535 +       return real_bdev;
1536 +}
1537 +
1538 +/*
1539 + * And now the modules code and kernel interface.
1540 + */
1541 +
1542 +module_param(max_vroot, int, 0);
1543 +
1544 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1545 +MODULE_LICENSE("GPL");
1546 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1547 +
1548 +MODULE_AUTHOR ("Herbert Pötzl");
1549 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1550 +
1551 +
1552 +int __init vroot_init(void)
1553 +{
1554 +       int err, i;
1555 +
1556 +       if (max_vroot < 1 || max_vroot > 256) {
1557 +               max_vroot = MAX_VROOT_DEFAULT;
1558 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1559 +                       "(must be between 1 and 256), "
1560 +                       "using default (%d)\n", max_vroot);
1561 +       }
1562 +
1563 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1564 +               return -EIO;
1565 +
1566 +       err = -ENOMEM;
1567 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1568 +       if (!vroot_dev)
1569 +               goto out_mem1;
1570 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1571 +
1572 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1573 +       if (!disks)
1574 +               goto out_mem2;
1575 +
1576 +       for (i = 0; i < max_vroot; i++) {
1577 +               disks[i] = alloc_disk(1);
1578 +               if (!disks[i])
1579 +                       goto out_mem3;
1580 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1581 +               if (!disks[i]->queue)
1582 +                       goto out_mem3;
1583 +       }
1584 +
1585 +       for (i = 0; i < max_vroot; i++) {
1586 +               struct vroot_device *vr = &vroot_dev[i];
1587 +               struct gendisk *disk = disks[i];
1588 +
1589 +               memset(vr, 0, sizeof(*vr));
1590 +               init_MUTEX(&vr->vr_ctl_mutex);
1591 +               vr->vr_number = i;
1592 +               disk->major = VROOT_MAJOR;
1593 +               disk->first_minor = i;
1594 +               disk->fops = &vr_fops;
1595 +               sprintf(disk->disk_name, "vroot%d", i);
1596 +               disk->private_data = vr;
1597 +       }
1598 +
1599 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1600 +       if (err)
1601 +               goto out_mem3;
1602 +
1603 +       for (i = 0; i < max_vroot; i++)
1604 +               add_disk(disks[i]);
1605 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1606 +       return 0;
1607 +
1608 +out_mem3:
1609 +       while (i--)
1610 +               put_disk(disks[i]);
1611 +       kfree(disks);
1612 +out_mem2:
1613 +       kfree(vroot_dev);
1614 +out_mem1:
1615 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1616 +       printk(KERN_ERR "vroot: ran out of memory\n");
1617 +       return err;
1618 +}
1619 +
1620 +void vroot_exit(void)
1621 +{
1622 +       int i;
1623 +
1624 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1625 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1626 +
1627 +       for (i = 0; i < max_vroot; i++) {
1628 +               del_gendisk(disks[i]);
1629 +               put_disk(disks[i]);
1630 +       }
1631 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1632 +
1633 +       kfree(disks);
1634 +       kfree(vroot_dev);
1635 +}
1636 +
1637 +module_init(vroot_init);
1638 +module_exit(vroot_exit);
1639 +
1640 +#ifndef MODULE
1641 +
1642 +static int __init max_vroot_setup(char *str)
1643 +{
1644 +       max_vroot = simple_strtol(str, NULL, 0);
1645 +       return 1;
1646 +}
1647 +
1648 +__setup("max_vroot=", max_vroot_setup);
1649 +
1650 +#endif
1651 +
1652 diff -NurpP --minimal linux-2.6.32.10/drivers/char/sysrq.c linux-2.6.32.10-vs2.3.0.36.29.2/drivers/char/sysrq.c
1653 --- linux-2.6.32.10/drivers/char/sysrq.c        2009-12-03 20:02:20.000000000 +0100
1654 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/char/sysrq.c        2009-12-03 20:04:56.000000000 +0100
1655 @@ -38,6 +38,7 @@
1656  #include <linux/workqueue.h>
1657  #include <linux/hrtimer.h>
1658  #include <linux/oom.h>
1659 +#include <linux/vserver/debug.h>
1660  
1661  #include <asm/ptrace.h>
1662  #include <asm/irq_regs.h>
1663 @@ -391,6 +392,21 @@ static struct sysrq_key_op sysrq_unrt_op
1664         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1665  };
1666  
1667 +
1668 +#ifdef CONFIG_VSERVER_DEBUG
1669 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1670 +{
1671 +       dump_vx_info_inactive((key == 'x')?0:1);
1672 +}
1673 +
1674 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1675 +       .handler        = sysrq_handle_vxinfo,
1676 +       .help_msg       = "conteXt",
1677 +       .action_msg     = "Show Context Info",
1678 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1679 +};
1680 +#endif
1681 +
1682  /* Key Operations table and lock */
1683  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1684  
1685 @@ -445,7 +461,11 @@ static struct sysrq_key_op *sysrq_key_ta
1686         NULL,                           /* v */
1687         &sysrq_showstate_blocked_op,    /* w */
1688         /* x: May be registered on ppc/powerpc for xmon */
1689 +#ifdef CONFIG_VSERVER_DEBUG
1690 +       &sysrq_showvxinfo_op,           /* x */
1691 +#else
1692         NULL,                           /* x */
1693 +#endif
1694         /* y: May be registered on sparc64 for global register dump */
1695         NULL,                           /* y */
1696         &sysrq_ftrace_dump_op,          /* z */
1697 @@ -460,6 +480,8 @@ static int sysrq_key_table_key2index(int
1698                 retval = key - '0';
1699         else if ((key >= 'a') && (key <= 'z'))
1700                 retval = key + 10 - 'a';
1701 +       else if ((key >= 'A') && (key <= 'Z'))
1702 +               retval = key + 10 - 'A';
1703         else
1704                 retval = -1;
1705         return retval;
1706 diff -NurpP --minimal linux-2.6.32.10/drivers/char/tty_io.c linux-2.6.32.10-vs2.3.0.36.29.2/drivers/char/tty_io.c
1707 --- linux-2.6.32.10/drivers/char/tty_io.c       2010-03-18 16:17:28.000000000 +0100
1708 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/char/tty_io.c       2010-02-24 12:32:54.000000000 +0100
1709 @@ -106,6 +106,7 @@
1710  
1711  #include <linux/kmod.h>
1712  #include <linux/nsproxy.h>
1713 +#include <linux/vs_pid.h>
1714  
1715  #undef TTY_DEBUG_HANGUP
1716  
1717 @@ -1968,7 +1969,8 @@ static int tiocsti(struct tty_struct *tt
1718         char ch, mbz = 0;
1719         struct tty_ldisc *ld;
1720  
1721 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1722 +       if (((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) ||
1723 +               !vx_ccaps(VXC_TIOCSTI))
1724                 return -EPERM;
1725         if (get_user(ch, p))
1726                 return -EFAULT;
1727 @@ -2256,6 +2258,7 @@ static int tiocspgrp(struct tty_struct *
1728                 return -ENOTTY;
1729         if (get_user(pgrp_nr, p))
1730                 return -EFAULT;
1731 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1732         if (pgrp_nr < 0)
1733                 return -EINVAL;
1734         rcu_read_lock();
1735 diff -NurpP --minimal linux-2.6.32.10/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.32.10-vs2.3.0.36.29.2/drivers/infiniband/hw/ipath/ipath_user_pages.c
1736 --- linux-2.6.32.10/drivers/infiniband/hw/ipath/ipath_user_pages.c      2009-12-03 20:02:23.000000000 +0100
1737 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/infiniband/hw/ipath/ipath_user_pages.c      2009-12-04 23:31:17.000000000 +0100
1738 @@ -34,6 +34,7 @@
1739  #include <linux/mm.h>
1740  #include <linux/device.h>
1741  #include <linux/sched.h>
1742 +#include <linux/vs_memory.h>
1743  
1744  #include "ipath_kernel.h"
1745  
1746 @@ -62,7 +63,8 @@ static int __get_user_pages(unsigned lon
1747         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1748                 PAGE_SHIFT;
1749  
1750 -       if (num_pages > lock_limit) {
1751 +       if (num_pages > lock_limit ||
1752 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1753                 ret = -ENOMEM;
1754                 goto bail;
1755         }
1756 @@ -79,7 +81,7 @@ static int __get_user_pages(unsigned lon
1757                         goto bail_release;
1758         }
1759  
1760 -       current->mm->locked_vm += num_pages;
1761 +       vx_vmlocked_add(current->mm, num_pages);
1762  
1763         ret = 0;
1764         goto bail;
1765 @@ -178,7 +180,7 @@ void ipath_release_user_pages(struct pag
1766  
1767         __ipath_release_user_pages(p, num_pages, 1);
1768  
1769 -       current->mm->locked_vm -= num_pages;
1770 +       vx_vmlocked_sub(current->mm, num_pages);
1771  
1772         up_write(&current->mm->mmap_sem);
1773  }
1774 @@ -195,7 +197,7 @@ static void user_pages_account(struct wo
1775                 container_of(_work, struct ipath_user_pages_work, work);
1776  
1777         down_write(&work->mm->mmap_sem);
1778 -       work->mm->locked_vm -= work->num_pages;
1779 +       vx_vmlocked_sub(work->mm, work->num_pages);
1780         up_write(&work->mm->mmap_sem);
1781         mmput(work->mm);
1782         kfree(work);
1783 diff -NurpP --minimal linux-2.6.32.10/drivers/md/dm.c linux-2.6.32.10-vs2.3.0.36.29.2/drivers/md/dm.c
1784 --- linux-2.6.32.10/drivers/md/dm.c     2010-03-18 16:17:29.000000000 +0100
1785 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/md/dm.c     2010-03-18 16:53:05.000000000 +0100
1786 @@ -19,6 +19,7 @@
1787  #include <linux/slab.h>
1788  #include <linux/idr.h>
1789  #include <linux/hdreg.h>
1790 +#include <linux/vs_base.h>
1791  
1792  #include <trace/events/block.h>
1793  
1794 @@ -119,6 +120,7 @@ struct mapped_device {
1795         rwlock_t map_lock;
1796         atomic_t holders;
1797         atomic_t open_count;
1798 +       xid_t xid;
1799  
1800         unsigned long flags;
1801  
1802 @@ -323,6 +325,7 @@ static void __exit dm_exit(void)
1803  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1804  {
1805         struct mapped_device *md;
1806 +       int ret = -ENXIO;
1807  
1808         spin_lock(&_minor_lock);
1809  
1810 @@ -331,18 +334,19 @@ static int dm_blk_open(struct block_devi
1811                 goto out;
1812  
1813         if (test_bit(DMF_FREEING, &md->flags) ||
1814 -           test_bit(DMF_DELETING, &md->flags)) {
1815 -               md = NULL;
1816 +           test_bit(DMF_DELETING, &md->flags))
1817 +               goto out;
1818 +
1819 +       ret = -EACCES;
1820 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1821                 goto out;
1822 -       }
1823  
1824         dm_get(md);
1825         atomic_inc(&md->open_count);
1826 -
1827 +       ret = 0;
1828  out:
1829         spin_unlock(&_minor_lock);
1830 -
1831 -       return md ? 0 : -ENXIO;
1832 +       return ret;
1833  }
1834  
1835  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1836 @@ -553,6 +557,14 @@ int dm_set_geometry(struct mapped_device
1837         return 0;
1838  }
1839  
1840 +/*
1841 + * Get the xid associated with a dm device
1842 + */
1843 +xid_t dm_get_xid(struct mapped_device *md)
1844 +{
1845 +       return md->xid;
1846 +}
1847 +
1848  /*-----------------------------------------------------------------
1849   * CRUD START:
1850   *   A more elegant soln is in the works that uses the queue
1851 @@ -1762,6 +1774,7 @@ static struct mapped_device *alloc_dev(i
1852         INIT_LIST_HEAD(&md->uevent_list);
1853         spin_lock_init(&md->uevent_lock);
1854  
1855 +       md->xid = vx_current_xid();
1856         md->queue = blk_init_queue(dm_request_fn, NULL);
1857         if (!md->queue)
1858                 goto bad_queue;
1859 diff -NurpP --minimal linux-2.6.32.10/drivers/md/dm.h linux-2.6.32.10-vs2.3.0.36.29.2/drivers/md/dm.h
1860 --- linux-2.6.32.10/drivers/md/dm.h     2009-09-10 15:25:55.000000000 +0200
1861 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/md/dm.h     2009-12-03 20:04:56.000000000 +0100
1862 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1863  struct dm_table;
1864  struct dm_md_mempools;
1865  
1866 +xid_t dm_get_xid(struct mapped_device *md);
1867 +
1868  /*-----------------------------------------------------------------
1869   * Internal table functions.
1870   *---------------------------------------------------------------*/
1871 diff -NurpP --minimal linux-2.6.32.10/drivers/md/dm-ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/drivers/md/dm-ioctl.c
1872 --- linux-2.6.32.10/drivers/md/dm-ioctl.c       2010-03-18 16:17:29.000000000 +0100
1873 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/md/dm-ioctl.c       2009-12-29 00:36:25.000000000 +0100
1874 @@ -16,6 +16,7 @@
1875  #include <linux/dm-ioctl.h>
1876  #include <linux/hdreg.h>
1877  #include <linux/compat.h>
1878 +#include <linux/vs_context.h>
1879  
1880  #include <asm/uaccess.h>
1881  
1882 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1883         unsigned int h = hash_str(str);
1884  
1885         list_for_each_entry (hc, _name_buckets + h, name_list)
1886 -               if (!strcmp(hc->name, str)) {
1887 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1888 +                       !strcmp(hc->name, str)) {
1889                         dm_get(hc->md);
1890                         return hc;
1891                 }
1892 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1893         unsigned int h = hash_str(str);
1894  
1895         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1896 -               if (!strcmp(hc->uuid, str)) {
1897 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1898 +                       !strcmp(hc->uuid, str)) {
1899                         dm_get(hc->md);
1900                         return hc;
1901                 }
1902 @@ -363,6 +366,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1903  
1904  static int remove_all(struct dm_ioctl *param, size_t param_size)
1905  {
1906 +       if (!vx_check(0, VS_ADMIN))
1907 +               return -EPERM;
1908 +
1909         dm_hash_remove_all(1);
1910         param->data_size = 0;
1911         return 0;
1912 @@ -410,6 +416,8 @@ static int list_devices(struct dm_ioctl 
1913          */
1914         for (i = 0; i < NUM_BUCKETS; i++) {
1915                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1916 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1917 +                               continue;
1918                         needed += sizeof(struct dm_name_list);
1919                         needed += strlen(hc->name) + 1;
1920                         needed += ALIGN_MASK;
1921 @@ -433,6 +441,8 @@ static int list_devices(struct dm_ioctl 
1922          */
1923         for (i = 0; i < NUM_BUCKETS; i++) {
1924                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1925 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1926 +                               continue;
1927                         if (old_nl)
1928                                 old_nl->next = (uint32_t) ((void *) nl -
1929                                                            (void *) old_nl);
1930 @@ -623,10 +633,11 @@ static struct hash_cell *__find_device_h
1931         if (!md)
1932                 goto out;
1933  
1934 -       mdptr = dm_get_mdptr(md);
1935 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1936 +               mdptr = dm_get_mdptr(md);
1937 +
1938         if (!mdptr)
1939                 dm_put(md);
1940 -
1941  out:
1942         return mdptr;
1943  }
1944 @@ -1456,8 +1467,8 @@ static int ctl_ioctl(uint command, struc
1945         ioctl_fn fn = NULL;
1946         size_t param_size;
1947  
1948 -       /* only root can play with this */
1949 -       if (!capable(CAP_SYS_ADMIN))
1950 +       /* only root and certain contexts can play with this */
1951 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1952                 return -EACCES;
1953  
1954         if (_IOC_TYPE(command) != DM_IOCTL)
1955 diff -NurpP --minimal linux-2.6.32.10/drivers/net/tun.c linux-2.6.32.10-vs2.3.0.36.29.2/drivers/net/tun.c
1956 --- linux-2.6.32.10/drivers/net/tun.c   2009-12-03 20:02:32.000000000 +0100
1957 +++ linux-2.6.32.10-vs2.3.0.36.29.2/drivers/net/tun.c   2009-12-03 20:04:56.000000000 +0100
1958 @@ -61,6 +61,7 @@
1959  #include <linux/crc32.h>
1960  #include <linux/nsproxy.h>
1961  #include <linux/virtio_net.h>
1962 +#include <linux/vs_network.h>
1963  #include <net/net_namespace.h>
1964  #include <net/netns/generic.h>
1965  #include <net/rtnetlink.h>
1966 @@ -102,6 +103,7 @@ struct tun_struct {
1967         unsigned int            flags;
1968         uid_t                   owner;
1969         gid_t                   group;
1970 +       nid_t                   nid;
1971  
1972         struct net_device       *dev;
1973         struct fasync_struct    *fasync;
1974 @@ -816,6 +818,7 @@ static void tun_setup(struct net_device 
1975  
1976         tun->owner = -1;
1977         tun->group = -1;
1978 +       tun->nid = current->nid;
1979  
1980         dev->ethtool_ops = &tun_ethtool_ops;
1981         dev->destructor = tun_free_netdev;
1982 @@ -932,7 +935,7 @@ static int tun_set_iff(struct net *net, 
1983  
1984                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1985                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1986 -                   !capable(CAP_NET_ADMIN))
1987 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1988                         return -EPERM;
1989                 err = security_tun_dev_attach(tun->socket.sk);
1990                 if (err < 0)
1991 @@ -946,7 +949,7 @@ static int tun_set_iff(struct net *net, 
1992                 char *name;
1993                 unsigned long flags = 0;
1994  
1995 -               if (!capable(CAP_NET_ADMIN))
1996 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1997                         return -EPERM;
1998                 err = security_tun_dev_create();
1999                 if (err < 0)
2000 @@ -1013,6 +1016,9 @@ static int tun_set_iff(struct net *net, 
2001  
2002                 sk->sk_destruct = tun_sock_destruct;
2003  
2004 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
2005 +                       return -EPERM;
2006 +
2007                 err = tun_attach(tun, file);
2008                 if (err < 0)
2009                         goto failed;
2010 @@ -1202,6 +1208,16 @@ static long tun_chr_ioctl(struct file *f
2011                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
2012                 break;
2013  
2014 +       case TUNSETNID:
2015 +               if (!capable(CAP_CONTEXT))
2016 +                       return -EPERM;
2017 +
2018 +               /* Set nid owner of the device */
2019 +               tun->nid = (nid_t) arg;
2020 +
2021 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
2022 +               break;
2023 +
2024         case TUNSETLINK:
2025                 /* Only allow setting the type when the interface is down */
2026                 if (tun->dev->flags & IFF_UP) {
2027 diff -NurpP --minimal linux-2.6.32.10/fs/attr.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/attr.c
2028 --- linux-2.6.32.10/fs/attr.c   2009-12-03 20:02:51.000000000 +0100
2029 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/attr.c   2009-12-03 20:04:56.000000000 +0100
2030 @@ -14,6 +14,9 @@
2031  #include <linux/fcntl.h>
2032  #include <linux/quotaops.h>
2033  #include <linux/security.h>
2034 +#include <linux/proc_fs.h>
2035 +#include <linux/devpts_fs.h>
2036 +#include <linux/vs_tag.h>
2037  
2038  /* Taken over from the old code... */
2039  
2040 @@ -55,6 +58,10 @@ int inode_change_ok(const struct inode *
2041                 if (!is_owner_or_cap(inode))
2042                         goto error;
2043         }
2044 +
2045 +       if (dx_permission(inode, MAY_WRITE))
2046 +               goto error;
2047 +
2048  fine:
2049         retval = 0;
2050  error:
2051 @@ -120,6 +127,8 @@ int inode_setattr(struct inode * inode, 
2052                 inode->i_uid = attr->ia_uid;
2053         if (ia_valid & ATTR_GID)
2054                 inode->i_gid = attr->ia_gid;
2055 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2056 +               inode->i_tag = attr->ia_tag;
2057         if (ia_valid & ATTR_ATIME)
2058                 inode->i_atime = timespec_trunc(attr->ia_atime,
2059                                                 inode->i_sb->s_time_gran);
2060 @@ -214,7 +223,8 @@ int notify_change(struct dentry * dentry
2061                 error = inode_change_ok(inode, attr);
2062                 if (!error) {
2063                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2064 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2065 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2066 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2067                                 error = vfs_dq_transfer(inode, attr) ?
2068                                         -EDQUOT : 0;
2069                         if (!error)
2070 diff -NurpP --minimal linux-2.6.32.10/fs/binfmt_aout.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/binfmt_aout.c
2071 --- linux-2.6.32.10/fs/binfmt_aout.c    2010-03-18 16:17:36.000000000 +0100
2072 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/binfmt_aout.c    2010-02-12 10:59:55.000000000 +0100
2073 @@ -24,6 +24,7 @@
2074  #include <linux/binfmts.h>
2075  #include <linux/personality.h>
2076  #include <linux/init.h>
2077 +#include <linux/vs_memory.h>
2078  
2079  #include <asm/system.h>
2080  #include <asm/uaccess.h>
2081 diff -NurpP --minimal linux-2.6.32.10/fs/binfmt_elf.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/binfmt_elf.c
2082 --- linux-2.6.32.10/fs/binfmt_elf.c     2010-03-18 16:17:36.000000000 +0100
2083 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/binfmt_elf.c     2010-02-12 10:59:55.000000000 +0100
2084 @@ -31,6 +31,7 @@
2085  #include <linux/random.h>
2086  #include <linux/elf.h>
2087  #include <linux/utsname.h>
2088 +#include <linux/vs_memory.h>
2089  #include <asm/uaccess.h>
2090  #include <asm/param.h>
2091  #include <asm/page.h>
2092 diff -NurpP --minimal linux-2.6.32.10/fs/binfmt_flat.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/binfmt_flat.c
2093 --- linux-2.6.32.10/fs/binfmt_flat.c    2010-03-18 16:17:36.000000000 +0100
2094 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/binfmt_flat.c    2010-02-12 10:59:55.000000000 +0100
2095 @@ -35,6 +35,7 @@
2096  #include <linux/init.h>
2097  #include <linux/flat.h>
2098  #include <linux/syscalls.h>
2099 +#include <linux/vs_memory.h>
2100  
2101  #include <asm/byteorder.h>
2102  #include <asm/system.h>
2103 diff -NurpP --minimal linux-2.6.32.10/fs/binfmt_som.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/binfmt_som.c
2104 --- linux-2.6.32.10/fs/binfmt_som.c     2010-03-18 16:17:36.000000000 +0100
2105 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/binfmt_som.c     2010-02-12 10:59:55.000000000 +0100
2106 @@ -28,6 +28,7 @@
2107  #include <linux/shm.h>
2108  #include <linux/personality.h>
2109  #include <linux/init.h>
2110 +#include <linux/vs_memory.h>
2111  
2112  #include <asm/uaccess.h>
2113  #include <asm/pgtable.h>
2114 diff -NurpP --minimal linux-2.6.32.10/fs/block_dev.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/block_dev.c
2115 --- linux-2.6.32.10/fs/block_dev.c      2010-03-18 16:17:36.000000000 +0100
2116 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/block_dev.c      2010-02-24 12:32:54.000000000 +0100
2117 @@ -26,6 +26,7 @@
2118  #include <linux/namei.h>
2119  #include <linux/log2.h>
2120  #include <linux/kmemleak.h>
2121 +#include <linux/vs_device.h>
2122  #include <asm/uaccess.h>
2123  #include "internal.h"
2124  
2125 @@ -556,6 +557,7 @@ struct block_device *bdget(dev_t dev)
2126                 bdev->bd_invalidated = 0;
2127                 inode->i_mode = S_IFBLK;
2128                 inode->i_rdev = dev;
2129 +               inode->i_mdev = dev;
2130                 inode->i_bdev = bdev;
2131                 inode->i_data.a_ops = &def_blk_aops;
2132                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2133 @@ -602,6 +604,11 @@ EXPORT_SYMBOL(bdput);
2134  static struct block_device *bd_acquire(struct inode *inode)
2135  {
2136         struct block_device *bdev;
2137 +       dev_t mdev;
2138 +
2139 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2140 +               return NULL;
2141 +       inode->i_mdev = mdev;
2142  
2143         spin_lock(&bdev_lock);
2144         bdev = inode->i_bdev;
2145 @@ -612,7 +619,7 @@ static struct block_device *bd_acquire(s
2146         }
2147         spin_unlock(&bdev_lock);
2148  
2149 -       bdev = bdget(inode->i_rdev);
2150 +       bdev = bdget(mdev);
2151         if (bdev) {
2152                 spin_lock(&bdev_lock);
2153                 if (!inode->i_bdev) {
2154 diff -NurpP --minimal linux-2.6.32.10/fs/btrfs/ctree.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/btrfs/ctree.h
2155 --- linux-2.6.32.10/fs/btrfs/ctree.h    2009-12-03 20:02:51.000000000 +0100
2156 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/btrfs/ctree.h    2009-12-03 20:04:56.000000000 +0100
2157 @@ -544,11 +544,14 @@ struct btrfs_inode_item {
2158         /* modification sequence number for NFS */
2159         __le64 sequence;
2160  
2161 +       __le16 tag;
2162         /*
2163          * a little future expansion, for more than this we can
2164          * just grow the inode item and version it
2165          */
2166 -       __le64 reserved[4];
2167 +       __le16 reserved16;
2168 +       __le32 reserved32;
2169 +       __le64 reserved[3];
2170         struct btrfs_timespec atime;
2171         struct btrfs_timespec ctime;
2172         struct btrfs_timespec mtime;
2173 @@ -1155,6 +1158,8 @@ struct btrfs_root {
2174  #define BTRFS_MOUNT_NOSSD              (1 << 9)
2175  #define BTRFS_MOUNT_DISCARD            (1 << 10)
2176  
2177 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2178 +
2179  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2180  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2181  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2182 @@ -1174,6 +1179,10 @@ struct btrfs_root {
2183  #define BTRFS_INODE_NOATIME            (1 << 9)
2184  #define BTRFS_INODE_DIRSYNC            (1 << 10)
2185  
2186 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2187 +#define BTRFS_INODE_BARRIER            (1 << 25)
2188 +#define BTRFS_INODE_COW                        (1 << 26)
2189 +
2190  
2191  /* some macros to generate set/get funcs for the struct fields.  This
2192   * assumes there is a lefoo_to_cpu for every type, so lets make a simple
2193 @@ -1376,6 +1385,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2194  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2195  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2196  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2197 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2198  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2199  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2200  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2201 @@ -2338,6 +2348,7 @@ extern const struct dentry_operations bt
2202  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2203  void btrfs_update_iflags(struct inode *inode);
2204  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2205 +int btrfs_sync_flags(struct inode *inode, int, int);
2206  
2207  /* file.c */
2208  int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync);
2209 diff -NurpP --minimal linux-2.6.32.10/fs/btrfs/disk-io.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/btrfs/disk-io.c
2210 --- linux-2.6.32.10/fs/btrfs/disk-io.c  2009-12-03 20:02:51.000000000 +0100
2211 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/btrfs/disk-io.c  2009-12-03 20:04:56.000000000 +0100
2212 @@ -1723,6 +1723,9 @@ struct btrfs_root *open_ctree(struct sup
2213                 goto fail_iput;
2214         }
2215  
2216 +       if (btrfs_test_opt(tree_root, TAGGED))
2217 +               sb->s_flags |= MS_TAGGED;
2218 +
2219         features = btrfs_super_incompat_flags(disk_super) &
2220                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2221         if (features) {
2222 diff -NurpP --minimal linux-2.6.32.10/fs/btrfs/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/btrfs/inode.c
2223 --- linux-2.6.32.10/fs/btrfs/inode.c    2009-12-03 20:02:51.000000000 +0100
2224 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/btrfs/inode.c    2009-12-03 20:04:56.000000000 +0100
2225 @@ -36,6 +36,8 @@
2226  #include <linux/xattr.h>
2227  #include <linux/posix_acl.h>
2228  #include <linux/falloc.h>
2229 +#include <linux/vs_tag.h>
2230 +
2231  #include "compat.h"
2232  #include "ctree.h"
2233  #include "disk-io.h"
2234 @@ -2242,6 +2244,8 @@ static void btrfs_read_locked_inode(stru
2235         int maybe_acls;
2236         u64 alloc_group_block;
2237         u32 rdev;
2238 +       uid_t uid;
2239 +       gid_t gid;
2240         int ret;
2241  
2242         path = btrfs_alloc_path();
2243 @@ -2258,8 +2262,13 @@ static void btrfs_read_locked_inode(stru
2244  
2245         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2246         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2247 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2248 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2249 +
2250 +       uid = btrfs_inode_uid(leaf, inode_item);
2251 +       gid = btrfs_inode_gid(leaf, inode_item);
2252 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2253 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2254 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2255 +               btrfs_inode_tag(leaf, inode_item));
2256         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2257  
2258         tspec = btrfs_inode_atime(inode_item);
2259 @@ -2341,8 +2350,15 @@ static void fill_inode_item(struct btrfs
2260                             struct btrfs_inode_item *item,
2261                             struct inode *inode)
2262  {
2263 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2264 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2265 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2266 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2267 +
2268 +       btrfs_set_inode_uid(leaf, item, uid);
2269 +       btrfs_set_inode_gid(leaf, item, gid);
2270 +#ifdef CONFIG_TAGGING_INTERN
2271 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2272 +#endif
2273 +
2274         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2275         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2276         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2277 @@ -4065,6 +4081,7 @@ static struct inode *btrfs_new_inode(str
2278         } else
2279                 inode->i_gid = current_fsgid();
2280  
2281 +       inode->i_tag = dx_current_fstag(root->fs_info->sb);
2282         inode->i_mode = mode;
2283         inode->i_ino = objectid;
2284         inode_set_bytes(inode, 0);
2285 @@ -5836,6 +5853,7 @@ static const struct inode_operations btr
2286         .listxattr      = btrfs_listxattr,
2287         .removexattr    = btrfs_removexattr,
2288         .permission     = btrfs_permission,
2289 +       .sync_flags     = btrfs_sync_flags,
2290  };
2291  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2292         .lookup         = btrfs_lookup,
2293 @@ -5911,6 +5929,7 @@ static const struct inode_operations btr
2294         .permission     = btrfs_permission,
2295         .fallocate      = btrfs_fallocate,
2296         .fiemap         = btrfs_fiemap,
2297 +       .sync_flags     = btrfs_sync_flags,
2298  };
2299  static const struct inode_operations btrfs_special_inode_operations = {
2300         .getattr        = btrfs_getattr,
2301 diff -NurpP --minimal linux-2.6.32.10/fs/btrfs/ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/btrfs/ioctl.c
2302 --- linux-2.6.32.10/fs/btrfs/ioctl.c    2009-12-03 20:02:51.000000000 +0100
2303 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/btrfs/ioctl.c    2009-12-03 20:04:56.000000000 +0100
2304 @@ -67,10 +67,13 @@ static unsigned int btrfs_flags_to_ioctl
2305  {
2306         unsigned int iflags = 0;
2307  
2308 -       if (flags & BTRFS_INODE_SYNC)
2309 -               iflags |= FS_SYNC_FL;
2310         if (flags & BTRFS_INODE_IMMUTABLE)
2311                 iflags |= FS_IMMUTABLE_FL;
2312 +       if (flags & BTRFS_INODE_IXUNLINK)
2313 +               iflags |= FS_IXUNLINK_FL;
2314 +
2315 +       if (flags & BTRFS_INODE_SYNC)
2316 +               iflags |= FS_SYNC_FL;
2317         if (flags & BTRFS_INODE_APPEND)
2318                 iflags |= FS_APPEND_FL;
2319         if (flags & BTRFS_INODE_NODUMP)
2320 @@ -80,28 +83,78 @@ static unsigned int btrfs_flags_to_ioctl
2321         if (flags & BTRFS_INODE_DIRSYNC)
2322                 iflags |= FS_DIRSYNC_FL;
2323  
2324 +       if (flags & BTRFS_INODE_BARRIER)
2325 +               iflags |= FS_BARRIER_FL;
2326 +       if (flags & BTRFS_INODE_COW)
2327 +               iflags |= FS_COW_FL;
2328         return iflags;
2329  }
2330  
2331  /*
2332 - * Update inode->i_flags based on the btrfs internal flags.
2333 + * Update inode->i_(v)flags based on the btrfs internal flags.
2334   */
2335  void btrfs_update_iflags(struct inode *inode)
2336  {
2337         struct btrfs_inode *ip = BTRFS_I(inode);
2338  
2339 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2340 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2341 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2342  
2343 -       if (ip->flags & BTRFS_INODE_SYNC)
2344 -               inode->i_flags |= S_SYNC;
2345         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2346                 inode->i_flags |= S_IMMUTABLE;
2347 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2348 +               inode->i_flags |= S_IXUNLINK;
2349 +
2350 +       if (ip->flags & BTRFS_INODE_SYNC)
2351 +               inode->i_flags |= S_SYNC;
2352         if (ip->flags & BTRFS_INODE_APPEND)
2353                 inode->i_flags |= S_APPEND;
2354         if (ip->flags & BTRFS_INODE_NOATIME)
2355                 inode->i_flags |= S_NOATIME;
2356         if (ip->flags & BTRFS_INODE_DIRSYNC)
2357                 inode->i_flags |= S_DIRSYNC;
2358 +
2359 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2360 +
2361 +       if (ip->flags & BTRFS_INODE_BARRIER)
2362 +               inode->i_vflags |= V_BARRIER;
2363 +       if (ip->flags & BTRFS_INODE_COW)
2364 +               inode->i_vflags |= V_COW;
2365 +}
2366 +
2367 +/*
2368 + * Update btrfs internal flags from inode->i_(v)flags.
2369 + */
2370 +void btrfs_update_flags(struct inode *inode)
2371 +{
2372 +       struct btrfs_inode *ip = BTRFS_I(inode);
2373 +
2374 +       unsigned int flags = inode->i_flags;
2375 +       unsigned int vflags = inode->i_vflags;
2376 +
2377 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2378 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2379 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2380 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2381 +
2382 +       if (flags & S_IMMUTABLE)
2383 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2384 +       if (flags & S_IXUNLINK)
2385 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2386 +
2387 +       if (flags & S_SYNC)
2388 +               ip->flags |= BTRFS_INODE_SYNC;
2389 +       if (flags & S_APPEND)
2390 +               ip->flags |= BTRFS_INODE_APPEND;
2391 +       if (flags & S_NOATIME)
2392 +               ip->flags |= BTRFS_INODE_NOATIME;
2393 +       if (flags & S_DIRSYNC)
2394 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2395 +
2396 +       if (vflags & V_BARRIER)
2397 +               ip->flags |= BTRFS_INODE_BARRIER;
2398 +       if (vflags & V_COW)
2399 +               ip->flags |= BTRFS_INODE_COW;
2400  }
2401  
2402  /*
2403 @@ -119,7 +172,7 @@ void btrfs_inherit_iflags(struct inode *
2404         flags = BTRFS_I(dir)->flags;
2405  
2406         if (S_ISREG(inode->i_mode))
2407 -               flags &= ~BTRFS_INODE_DIRSYNC;
2408 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2409         else if (!S_ISDIR(inode->i_mode))
2410                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2411  
2412 @@ -127,6 +180,30 @@ void btrfs_inherit_iflags(struct inode *
2413         btrfs_update_iflags(inode);
2414  }
2415  
2416 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2417 +{
2418 +       struct btrfs_inode *ip = BTRFS_I(inode);
2419 +       struct btrfs_root *root = ip->root;
2420 +       struct btrfs_trans_handle *trans;
2421 +       int ret;
2422 +
2423 +       trans = btrfs_join_transaction(root, 1);
2424 +       BUG_ON(!trans);
2425 +
2426 +       inode->i_flags = flags;
2427 +       inode->i_vflags = vflags;
2428 +       btrfs_update_flags(inode);
2429 +
2430 +       ret = btrfs_update_inode(trans, root, inode);
2431 +       BUG_ON(ret);
2432 +
2433 +       btrfs_update_iflags(inode);
2434 +       inode->i_ctime = CURRENT_TIME;
2435 +       btrfs_end_transaction(trans, root);
2436 +
2437 +       return 0;
2438 +}
2439 +
2440  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2441  {
2442         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2443 @@ -149,6 +226,7 @@ static int btrfs_ioctl_setflags(struct f
2444         if (copy_from_user(&flags, arg, sizeof(flags)))
2445                 return -EFAULT;
2446  
2447 +       /* maybe add FS_IXUNLINK_FL ? */
2448         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2449                       FS_NOATIME_FL | FS_NODUMP_FL | \
2450                       FS_SYNC_FL | FS_DIRSYNC_FL))
2451 @@ -161,7 +239,8 @@ static int btrfs_ioctl_setflags(struct f
2452  
2453         flags = btrfs_mask_flags(inode->i_mode, flags);
2454         oldflags = btrfs_flags_to_ioctl(ip->flags);
2455 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2456 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2457 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2458                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2459                         ret = -EPERM;
2460                         goto out_unlock;
2461 @@ -172,14 +251,19 @@ static int btrfs_ioctl_setflags(struct f
2462         if (ret)
2463                 goto out_unlock;
2464  
2465 -       if (flags & FS_SYNC_FL)
2466 -               ip->flags |= BTRFS_INODE_SYNC;
2467 -       else
2468 -               ip->flags &= ~BTRFS_INODE_SYNC;
2469         if (flags & FS_IMMUTABLE_FL)
2470                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2471         else
2472                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2473 +       if (flags & FS_IXUNLINK_FL)
2474 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2475 +       else
2476 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2477 +
2478 +       if (flags & FS_SYNC_FL)
2479 +               ip->flags |= BTRFS_INODE_SYNC;
2480 +       else
2481 +               ip->flags &= ~BTRFS_INODE_SYNC;
2482         if (flags & FS_APPEND_FL)
2483                 ip->flags |= BTRFS_INODE_APPEND;
2484         else
2485 diff -NurpP --minimal linux-2.6.32.10/fs/btrfs/super.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/btrfs/super.c
2486 --- linux-2.6.32.10/fs/btrfs/super.c    2009-12-03 20:02:51.000000000 +0100
2487 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/btrfs/super.c    2009-12-03 20:04:56.000000000 +0100
2488 @@ -67,7 +67,7 @@ enum {
2489         Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier,
2490         Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl,
2491         Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
2492 -       Opt_discard, Opt_err,
2493 +       Opt_tag, Opt_notag, Opt_tagid, Opt_discard, Opt_err,
2494  };
2495  
2496  static match_table_t tokens = {
2497 @@ -90,6 +90,9 @@ static match_table_t tokens = {
2498         {Opt_flushoncommit, "flushoncommit"},
2499         {Opt_ratio, "metadata_ratio=%d"},
2500         {Opt_discard, "discard"},
2501 +       {Opt_tag, "tag"},
2502 +       {Opt_notag, "notag"},
2503 +       {Opt_tagid, "tagid=%u"},
2504         {Opt_err, NULL},
2505  };
2506  
2507 @@ -262,6 +265,22 @@ int btrfs_parse_options(struct btrfs_roo
2508                 case Opt_discard:
2509                         btrfs_set_opt(info->mount_opt, DISCARD);
2510                         break;
2511 +#ifndef CONFIG_TAGGING_NONE
2512 +               case Opt_tag:
2513 +                       printk(KERN_INFO "btrfs: use tagging\n");
2514 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2515 +                       break;
2516 +               case Opt_notag:
2517 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2518 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2519 +                       break;
2520 +#endif
2521 +#ifdef CONFIG_PROPAGATE
2522 +               case Opt_tagid:
2523 +                       /* use args[0] */
2524 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2525 +                       break;
2526 +#endif
2527                 default:
2528                         break;
2529                 }
2530 @@ -575,6 +594,12 @@ static int btrfs_remount(struct super_bl
2531         if (ret)
2532                 return -EINVAL;
2533  
2534 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2535 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2536 +                       sb->s_id);
2537 +               return -EINVAL;
2538 +       }
2539 +
2540         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2541                 return 0;
2542  
2543 diff -NurpP --minimal linux-2.6.32.10/fs/char_dev.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/char_dev.c
2544 --- linux-2.6.32.10/fs/char_dev.c       2009-12-03 20:02:51.000000000 +0100
2545 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/char_dev.c       2009-12-03 20:04:56.000000000 +0100
2546 @@ -20,6 +20,8 @@
2547  #include <linux/cdev.h>
2548  #include <linux/mutex.h>
2549  #include <linux/backing-dev.h>
2550 +#include <linux/vs_context.h>
2551 +#include <linux/vs_device.h>
2552  
2553  #include "internal.h"
2554  
2555 @@ -368,14 +370,21 @@ static int chrdev_open(struct inode *ino
2556         struct cdev *p;
2557         struct cdev *new = NULL;
2558         int ret = 0;
2559 +       dev_t mdev;
2560 +
2561 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2562 +               return -EPERM;
2563 +       inode->i_mdev = mdev;
2564  
2565         spin_lock(&cdev_lock);
2566         p = inode->i_cdev;
2567         if (!p) {
2568                 struct kobject *kobj;
2569                 int idx;
2570 +
2571                 spin_unlock(&cdev_lock);
2572 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2573 +
2574 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2575                 if (!kobj)
2576                         return -ENXIO;
2577                 new = container_of(kobj, struct cdev, kobj);
2578 diff -NurpP --minimal linux-2.6.32.10/fs/dcache.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/dcache.c
2579 --- linux-2.6.32.10/fs/dcache.c 2009-12-03 20:02:51.000000000 +0100
2580 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/dcache.c 2009-12-03 20:04:56.000000000 +0100
2581 @@ -33,6 +33,7 @@
2582  #include <linux/bootmem.h>
2583  #include <linux/fs_struct.h>
2584  #include <linux/hardirq.h>
2585 +#include <linux/vs_limit.h>
2586  #include "internal.h"
2587  
2588  int sysctl_vfs_cache_pressure __read_mostly = 100;
2589 @@ -230,6 +231,8 @@ repeat:
2590                 return;
2591         }
2592  
2593 +       vx_dentry_dec(dentry);
2594 +
2595         /*
2596          * AV: ->d_delete() is _NOT_ allowed to block now.
2597          */
2598 @@ -321,6 +324,7 @@ static inline struct dentry * __dget_loc
2599  {
2600         atomic_inc(&dentry->d_count);
2601         dentry_lru_del_init(dentry);
2602 +       vx_dentry_inc(dentry);
2603         return dentry;
2604  }
2605  
2606 @@ -919,6 +923,9 @@ struct dentry *d_alloc(struct dentry * p
2607         struct dentry *dentry;
2608         char *dname;
2609  
2610 +       if (!vx_dentry_avail(1))
2611 +               return NULL;
2612 +
2613         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2614         if (!dentry)
2615                 return NULL;
2616 @@ -964,6 +971,7 @@ struct dentry *d_alloc(struct dentry * p
2617         if (parent)
2618                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2619         dentry_stat.nr_dentry++;
2620 +       vx_dentry_inc(dentry);
2621         spin_unlock(&dcache_lock);
2622  
2623         return dentry;
2624 @@ -1407,6 +1415,7 @@ struct dentry * __d_lookup(struct dentry
2625                 }
2626  
2627                 atomic_inc(&dentry->d_count);
2628 +               vx_dentry_inc(dentry);
2629                 found = dentry;
2630                 spin_unlock(&dentry->d_lock);
2631                 break;
2632 diff -NurpP --minimal linux-2.6.32.10/fs/devpts/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/devpts/inode.c
2633 --- linux-2.6.32.10/fs/devpts/inode.c   2010-03-18 16:17:36.000000000 +0100
2634 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/devpts/inode.c   2009-12-29 00:36:26.000000000 +0100
2635 @@ -24,6 +24,7 @@
2636  #include <linux/parser.h>
2637  #include <linux/fsnotify.h>
2638  #include <linux/seq_file.h>
2639 +#include <linux/vs_base.h>
2640  
2641  #define DEVPTS_DEFAULT_MODE 0600
2642  /*
2643 @@ -35,6 +36,20 @@
2644  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2645  #define PTMX_MINOR     2
2646  
2647 +static int devpts_permission(struct inode *inode, int mask)
2648 +{
2649 +       int ret = -EACCES;
2650 +
2651 +       /* devpts is xid tagged */
2652 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2653 +               ret = generic_permission(inode, mask, NULL);
2654 +       return ret;
2655 +}
2656 +
2657 +static struct inode_operations devpts_file_inode_operations = {
2658 +       .permission     = devpts_permission,
2659 +};
2660 +
2661  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2662  static DEFINE_MUTEX(allocated_ptys_lock);
2663  
2664 @@ -262,6 +277,25 @@ static int devpts_show_options(struct se
2665         return 0;
2666  }
2667  
2668 +static int devpts_filter(struct dentry *de)
2669 +{
2670 +       /* devpts is xid tagged */
2671 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2672 +}
2673 +
2674 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2675 +{
2676 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2677 +}
2678 +
2679 +static struct file_operations devpts_dir_operations = {
2680 +       .open           = dcache_dir_open,
2681 +       .release        = dcache_dir_close,
2682 +       .llseek         = dcache_dir_lseek,
2683 +       .read           = generic_read_dir,
2684 +       .readdir        = devpts_readdir,
2685 +};
2686 +
2687  static const struct super_operations devpts_sops = {
2688         .statfs         = simple_statfs,
2689         .remount_fs     = devpts_remount,
2690 @@ -301,12 +335,15 @@ devpts_fill_super(struct super_block *s,
2691         inode = new_inode(s);
2692         if (!inode)
2693                 goto free_fsi;
2694 +
2695         inode->i_ino = 1;
2696         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2697         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2698         inode->i_op = &simple_dir_inode_operations;
2699 -       inode->i_fop = &simple_dir_operations;
2700 +       inode->i_fop = &devpts_dir_operations;
2701         inode->i_nlink = 2;
2702 +       /* devpts is xid tagged */
2703 +       inode->i_tag = (tag_t)vx_current_xid();
2704  
2705         s->s_root = d_alloc_root(inode);
2706         if (s->s_root)
2707 @@ -497,6 +534,9 @@ int devpts_pty_new(struct inode *ptmx_in
2708         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2709         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2710         init_special_inode(inode, S_IFCHR|opts->mode, device);
2711 +       /* devpts is xid tagged */
2712 +       inode->i_tag = (tag_t)vx_current_xid();
2713 +       inode->i_op = &devpts_file_inode_operations;
2714         inode->i_private = tty;
2715         tty->driver_data = inode;
2716  
2717 diff -NurpP --minimal linux-2.6.32.10/fs/exec.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/exec.c
2718 --- linux-2.6.32.10/fs/exec.c   2010-03-18 16:17:36.000000000 +0100
2719 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/exec.c   2010-03-18 16:53:06.000000000 +0100
2720 @@ -251,7 +251,9 @@ static int __bprm_mm_init(struct linux_b
2721         if (err)
2722                 goto err;
2723  
2724 -       mm->stack_vm = mm->total_vm = 1;
2725 +       mm->total_vm = 0;
2726 +       vx_vmpages_inc(mm);
2727 +       mm->stack_vm = 1;
2728         up_write(&mm->mmap_sem);
2729         bprm->p = vma->vm_end - sizeof(void *);
2730         return 0;
2731 @@ -1496,7 +1498,7 @@ static int format_corename(char *corenam
2732                         /* UNIX time of coredump */
2733                         case 't': {
2734                                 struct timeval tv;
2735 -                               do_gettimeofday(&tv);
2736 +                               vx_gettimeofday(&tv);
2737                                 rc = snprintf(out_ptr, out_end - out_ptr,
2738                                               "%lu", tv.tv_sec);
2739                                 if (rc > out_end - out_ptr)
2740 diff -NurpP --minimal linux-2.6.32.10/fs/ext2/balloc.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/balloc.c
2741 --- linux-2.6.32.10/fs/ext2/balloc.c    2009-06-11 17:13:03.000000000 +0200
2742 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/balloc.c    2009-12-03 20:04:56.000000000 +0100
2743 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2744                         start = 0;
2745                 end = EXT2_BLOCKS_PER_GROUP(sb);
2746         }
2747 -
2748         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2749  
2750  repeat:
2751 diff -NurpP --minimal linux-2.6.32.10/fs/ext2/ext2.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/ext2.h
2752 --- linux-2.6.32.10/fs/ext2/ext2.h      2009-09-10 15:26:21.000000000 +0200
2753 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/ext2.h      2009-12-03 20:04:56.000000000 +0100
2754 @@ -131,6 +131,7 @@ extern int ext2_fiemap(struct inode *ino
2755  int __ext2_write_begin(struct file *file, struct address_space *mapping,
2756                 loff_t pos, unsigned len, unsigned flags,
2757                 struct page **pagep, void **fsdata);
2758 +extern int ext2_sync_flags(struct inode *, int, int);
2759  
2760  /* ioctl.c */
2761  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2762 diff -NurpP --minimal linux-2.6.32.10/fs/ext2/file.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/file.c
2763 --- linux-2.6.32.10/fs/ext2/file.c      2009-12-03 20:02:51.000000000 +0100
2764 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/file.c      2009-12-03 20:04:56.000000000 +0100
2765 @@ -87,4 +87,5 @@ const struct inode_operations ext2_file_
2766         .setattr        = ext2_setattr,
2767         .check_acl      = ext2_check_acl,
2768         .fiemap         = ext2_fiemap,
2769 +       .sync_flags     = ext2_sync_flags,
2770  };
2771 diff -NurpP --minimal linux-2.6.32.10/fs/ext2/ialloc.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/ialloc.c
2772 --- linux-2.6.32.10/fs/ext2/ialloc.c    2009-06-11 17:13:03.000000000 +0200
2773 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/ialloc.c    2009-12-03 20:04:56.000000000 +0100
2774 @@ -17,6 +17,7 @@
2775  #include <linux/backing-dev.h>
2776  #include <linux/buffer_head.h>
2777  #include <linux/random.h>
2778 +#include <linux/vs_tag.h>
2779  #include "ext2.h"
2780  #include "xattr.h"
2781  #include "acl.h"
2782 @@ -560,6 +561,7 @@ got:
2783         } else
2784                 inode->i_gid = current_fsgid();
2785         inode->i_mode = mode;
2786 +       inode->i_tag = dx_current_fstag(sb);
2787  
2788         inode->i_ino = ino;
2789         inode->i_blocks = 0;
2790 diff -NurpP --minimal linux-2.6.32.10/fs/ext2/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/inode.c
2791 --- linux-2.6.32.10/fs/ext2/inode.c     2009-12-03 20:02:51.000000000 +0100
2792 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/inode.c     2009-12-03 20:04:56.000000000 +0100
2793 @@ -33,6 +33,7 @@
2794  #include <linux/mpage.h>
2795  #include <linux/fiemap.h>
2796  #include <linux/namei.h>
2797 +#include <linux/vs_tag.h>
2798  #include "ext2.h"
2799  #include "acl.h"
2800  #include "xip.h"
2801 @@ -1040,7 +1041,7 @@ void ext2_truncate(struct inode *inode)
2802                 return;
2803         if (ext2_inode_is_fast_symlink(inode))
2804                 return;
2805 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2806 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2807                 return;
2808  
2809         blocksize = inode->i_sb->s_blocksize;
2810 @@ -1178,36 +1179,61 @@ void ext2_set_inode_flags(struct inode *
2811  {
2812         unsigned int flags = EXT2_I(inode)->i_flags;
2813  
2814 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2815 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2816 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2817 +
2818 +
2819 +       if (flags & EXT2_IMMUTABLE_FL)
2820 +               inode->i_flags |= S_IMMUTABLE;
2821 +       if (flags & EXT2_IXUNLINK_FL)
2822 +               inode->i_flags |= S_IXUNLINK;
2823 +
2824         if (flags & EXT2_SYNC_FL)
2825                 inode->i_flags |= S_SYNC;
2826         if (flags & EXT2_APPEND_FL)
2827                 inode->i_flags |= S_APPEND;
2828 -       if (flags & EXT2_IMMUTABLE_FL)
2829 -               inode->i_flags |= S_IMMUTABLE;
2830         if (flags & EXT2_NOATIME_FL)
2831                 inode->i_flags |= S_NOATIME;
2832         if (flags & EXT2_DIRSYNC_FL)
2833                 inode->i_flags |= S_DIRSYNC;
2834 +
2835 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2836 +
2837 +       if (flags & EXT2_BARRIER_FL)
2838 +               inode->i_vflags |= V_BARRIER;
2839 +       if (flags & EXT2_COW_FL)
2840 +               inode->i_vflags |= V_COW;
2841  }
2842  
2843  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2844  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2845  {
2846         unsigned int flags = ei->vfs_inode.i_flags;
2847 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2848 +
2849 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2850 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2851 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2852 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2853 +
2854 +       if (flags & S_IMMUTABLE)
2855 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2856 +       if (flags & S_IXUNLINK)
2857 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2858  
2859 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2860 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2861         if (flags & S_SYNC)
2862                 ei->i_flags |= EXT2_SYNC_FL;
2863         if (flags & S_APPEND)
2864                 ei->i_flags |= EXT2_APPEND_FL;
2865 -       if (flags & S_IMMUTABLE)
2866 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2867         if (flags & S_NOATIME)
2868                 ei->i_flags |= EXT2_NOATIME_FL;
2869         if (flags & S_DIRSYNC)
2870                 ei->i_flags |= EXT2_DIRSYNC_FL;
2871 +
2872 +       if (vflags & V_BARRIER)
2873 +               ei->i_flags |= EXT2_BARRIER_FL;
2874 +       if (vflags & V_COW)
2875 +               ei->i_flags |= EXT2_COW_FL;
2876  }
2877  
2878  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2879 @@ -1217,6 +1243,8 @@ struct inode *ext2_iget (struct super_bl
2880         struct ext2_inode *raw_inode;
2881         struct inode *inode;
2882         long ret = -EIO;
2883 +       uid_t uid;
2884 +       gid_t gid;
2885         int n;
2886  
2887         inode = iget_locked(sb, ino);
2888 @@ -1235,12 +1263,17 @@ struct inode *ext2_iget (struct super_bl
2889         }
2890  
2891         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2892 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2893 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2894 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2895 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2896         if (!(test_opt (inode->i_sb, NO_UID32))) {
2897 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2898 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2899 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2900 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2901         }
2902 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2903 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2904 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2905 +               le16_to_cpu(raw_inode->i_raw_tag));
2906 +
2907         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2908         inode->i_size = le32_to_cpu(raw_inode->i_size);
2909         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2910 @@ -1338,8 +1371,8 @@ int ext2_write_inode(struct inode *inode
2911         struct ext2_inode_info *ei = EXT2_I(inode);
2912         struct super_block *sb = inode->i_sb;
2913         ino_t ino = inode->i_ino;
2914 -       uid_t uid = inode->i_uid;
2915 -       gid_t gid = inode->i_gid;
2916 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2917 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2918         struct buffer_head * bh;
2919         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2920         int n;
2921 @@ -1375,6 +1408,9 @@ int ext2_write_inode(struct inode *inode
2922                 raw_inode->i_uid_high = 0;
2923                 raw_inode->i_gid_high = 0;
2924         }
2925 +#ifdef CONFIG_TAGGING_INTERN
2926 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2927 +#endif
2928         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2929         raw_inode->i_size = cpu_to_le32(inode->i_size);
2930         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2931 @@ -1456,7 +1492,8 @@ int ext2_setattr(struct dentry *dentry, 
2932         if (error)
2933                 return error;
2934         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2935 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2936 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2937 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2938                 error = vfs_dq_transfer(inode, iattr) ? -EDQUOT : 0;
2939                 if (error)
2940                         return error;
2941 diff -NurpP --minimal linux-2.6.32.10/fs/ext2/ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/ioctl.c
2942 --- linux-2.6.32.10/fs/ext2/ioctl.c     2009-09-10 15:26:21.000000000 +0200
2943 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/ioctl.c     2009-12-03 20:04:56.000000000 +0100
2944 @@ -17,6 +17,16 @@
2945  #include <asm/uaccess.h>
2946  
2947  
2948 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2949 +{
2950 +       inode->i_flags = flags;
2951 +       inode->i_vflags = vflags;
2952 +       ext2_get_inode_flags(EXT2_I(inode));
2953 +       inode->i_ctime = CURRENT_TIME_SEC;
2954 +       mark_inode_dirty(inode);
2955 +       return 0;
2956 +}
2957 +
2958  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2959  {
2960         struct inode *inode = filp->f_dentry->d_inode;
2961 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2962  
2963                 flags = ext2_mask_flags(inode->i_mode, flags);
2964  
2965 +               if (IS_BARRIER(inode)) {
2966 +                       vxwprintk_task(1, "messing with the barrier.");
2967 +                       return -EACCES;
2968 +               }
2969 +
2970                 mutex_lock(&inode->i_mutex);
2971                 /* Is it quota file? Do not allow user to mess with it */
2972                 if (IS_NOQUOTA(inode)) {
2973 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2974                  *
2975                  * This test looks nicer. Thanks to Pauline Middelink
2976                  */
2977 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2978 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2979 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2980 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2981                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2982                                 mutex_unlock(&inode->i_mutex);
2983                                 ret = -EPERM;
2984 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2985                         }
2986                 }
2987  
2988 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2989 +               flags &= EXT2_FL_USER_MODIFIABLE;
2990                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2991                 ei->i_flags = flags;
2992                 mutex_unlock(&inode->i_mutex);
2993 diff -NurpP --minimal linux-2.6.32.10/fs/ext2/namei.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/namei.c
2994 --- linux-2.6.32.10/fs/ext2/namei.c     2009-12-03 20:02:51.000000000 +0100
2995 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/namei.c     2009-12-03 20:04:56.000000000 +0100
2996 @@ -31,6 +31,7 @@
2997   */
2998  
2999  #include <linux/pagemap.h>
3000 +#include <linux/vs_tag.h>
3001  #include "ext2.h"
3002  #include "xattr.h"
3003  #include "acl.h"
3004 @@ -74,6 +75,7 @@ static struct dentry *ext2_lookup(struct
3005                                 return ERR_PTR(-EIO);
3006                         } else {
3007                                 return ERR_CAST(inode);
3008 +               dx_propagate_tag(nd, inode);
3009                         }
3010                 }
3011         }
3012 @@ -401,6 +403,7 @@ const struct inode_operations ext2_dir_i
3013  #endif
3014         .setattr        = ext2_setattr,
3015         .check_acl      = ext2_check_acl,
3016 +       .sync_flags     = ext2_sync_flags,
3017  };
3018  
3019  const struct inode_operations ext2_special_inode_operations = {
3020 diff -NurpP --minimal linux-2.6.32.10/fs/ext2/super.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/super.c
3021 --- linux-2.6.32.10/fs/ext2/super.c     2009-09-10 15:26:21.000000000 +0200
3022 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext2/super.c     2009-12-03 20:04:56.000000000 +0100
3023 @@ -382,7 +382,8 @@ enum {
3024         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3025         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3026         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3027 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3028 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3029 +       Opt_tag, Opt_notag, Opt_tagid
3030  };
3031  
3032  static const match_table_t tokens = {
3033 @@ -410,6 +411,9 @@ static const match_table_t tokens = {
3034         {Opt_acl, "acl"},
3035         {Opt_noacl, "noacl"},
3036         {Opt_xip, "xip"},
3037 +       {Opt_tag, "tag"},
3038 +       {Opt_notag, "notag"},
3039 +       {Opt_tagid, "tagid=%u"},
3040         {Opt_grpquota, "grpquota"},
3041         {Opt_ignore, "noquota"},
3042         {Opt_quota, "quota"},
3043 @@ -480,6 +484,20 @@ static int parse_options (char * options
3044                 case Opt_nouid32:
3045                         set_opt (sbi->s_mount_opt, NO_UID32);
3046                         break;
3047 +#ifndef CONFIG_TAGGING_NONE
3048 +               case Opt_tag:
3049 +                       set_opt (sbi->s_mount_opt, TAGGED);
3050 +                       break;
3051 +               case Opt_notag:
3052 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3053 +                       break;
3054 +#endif
3055 +#ifdef CONFIG_PROPAGATE
3056 +               case Opt_tagid:
3057 +                       /* use args[0] */
3058 +                       set_opt (sbi->s_mount_opt, TAGGED);
3059 +                       break;
3060 +#endif
3061                 case Opt_nocheck:
3062                         clear_opt (sbi->s_mount_opt, CHECK);
3063                         break;
3064 @@ -829,6 +847,8 @@ static int ext2_fill_super(struct super_
3065         if (!parse_options ((char *) data, sbi))
3066                 goto failed_mount;
3067  
3068 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3069 +               sb->s_flags |= MS_TAGGED;
3070         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3071                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3072                  MS_POSIXACL : 0);
3073 @@ -1175,6 +1195,14 @@ static int ext2_remount (struct super_bl
3074                 goto restore_opts;
3075         }
3076  
3077 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3078 +               !(sb->s_flags & MS_TAGGED)) {
3079 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3080 +                      sb->s_id);
3081 +               err = -EINVAL;
3082 +               goto restore_opts;
3083 +       }
3084 +
3085         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3086                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3087  
3088 diff -NurpP --minimal linux-2.6.32.10/fs/ext3/file.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/file.c
3089 --- linux-2.6.32.10/fs/ext3/file.c      2009-12-03 20:02:51.000000000 +0100
3090 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/file.c      2009-12-03 20:04:56.000000000 +0100
3091 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
3092  #endif
3093         .check_acl      = ext3_check_acl,
3094         .fiemap         = ext3_fiemap,
3095 +       .sync_flags     = ext3_sync_flags,
3096  };
3097  
3098 diff -NurpP --minimal linux-2.6.32.10/fs/ext3/ialloc.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/ialloc.c
3099 --- linux-2.6.32.10/fs/ext3/ialloc.c    2009-09-10 15:26:21.000000000 +0200
3100 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/ialloc.c    2009-12-03 20:04:56.000000000 +0100
3101 @@ -23,6 +23,7 @@
3102  #include <linux/buffer_head.h>
3103  #include <linux/random.h>
3104  #include <linux/bitops.h>
3105 +#include <linux/vs_tag.h>
3106  
3107  #include <asm/byteorder.h>
3108  
3109 @@ -548,6 +549,7 @@ got:
3110         } else
3111                 inode->i_gid = current_fsgid();
3112         inode->i_mode = mode;
3113 +       inode->i_tag = dx_current_fstag(sb);
3114  
3115         inode->i_ino = ino;
3116         /* This is the optimal IO size (for stat), not the fs block size */
3117 diff -NurpP --minimal linux-2.6.32.10/fs/ext3/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/inode.c
3118 --- linux-2.6.32.10/fs/ext3/inode.c     2010-03-18 16:17:36.000000000 +0100
3119 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/inode.c     2009-12-29 00:36:26.000000000 +0100
3120 @@ -38,6 +38,7 @@
3121  #include <linux/bio.h>
3122  #include <linux/fiemap.h>
3123  #include <linux/namei.h>
3124 +#include <linux/vs_tag.h>
3125  #include "xattr.h"
3126  #include "acl.h"
3127  
3128 @@ -2343,7 +2344,7 @@ static void ext3_free_branches(handle_t 
3129  
3130  int ext3_can_truncate(struct inode *inode)
3131  {
3132 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3133 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3134                 return 0;
3135         if (S_ISREG(inode->i_mode))
3136                 return 1;
3137 @@ -2728,36 +2729,60 @@ void ext3_set_inode_flags(struct inode *
3138  {
3139         unsigned int flags = EXT3_I(inode)->i_flags;
3140  
3141 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3142 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3143 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3144 +
3145 +       if (flags & EXT3_IMMUTABLE_FL)
3146 +               inode->i_flags |= S_IMMUTABLE;
3147 +       if (flags & EXT3_IXUNLINK_FL)
3148 +               inode->i_flags |= S_IXUNLINK;
3149 +
3150         if (flags & EXT3_SYNC_FL)
3151                 inode->i_flags |= S_SYNC;
3152         if (flags & EXT3_APPEND_FL)
3153                 inode->i_flags |= S_APPEND;
3154 -       if (flags & EXT3_IMMUTABLE_FL)
3155 -               inode->i_flags |= S_IMMUTABLE;
3156         if (flags & EXT3_NOATIME_FL)
3157                 inode->i_flags |= S_NOATIME;
3158         if (flags & EXT3_DIRSYNC_FL)
3159                 inode->i_flags |= S_DIRSYNC;
3160 +
3161 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3162 +
3163 +       if (flags & EXT3_BARRIER_FL)
3164 +               inode->i_vflags |= V_BARRIER;
3165 +       if (flags & EXT3_COW_FL)
3166 +               inode->i_vflags |= V_COW;
3167  }
3168  
3169  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3170  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3171  {
3172         unsigned int flags = ei->vfs_inode.i_flags;
3173 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3174 +
3175 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3176 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3177 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3178 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3179 +
3180 +       if (flags & S_IMMUTABLE)
3181 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3182 +       if (flags & S_IXUNLINK)
3183 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3184  
3185 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3186 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3187         if (flags & S_SYNC)
3188                 ei->i_flags |= EXT3_SYNC_FL;
3189         if (flags & S_APPEND)
3190                 ei->i_flags |= EXT3_APPEND_FL;
3191 -       if (flags & S_IMMUTABLE)
3192 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3193         if (flags & S_NOATIME)
3194                 ei->i_flags |= EXT3_NOATIME_FL;
3195         if (flags & S_DIRSYNC)
3196                 ei->i_flags |= EXT3_DIRSYNC_FL;
3197 +
3198 +       if (vflags & V_BARRIER)
3199 +               ei->i_flags |= EXT3_BARRIER_FL;
3200 +       if (vflags & V_COW)
3201 +               ei->i_flags |= EXT3_COW_FL;
3202  }
3203  
3204  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3205 @@ -2771,6 +2796,8 @@ struct inode *ext3_iget(struct super_blo
3206         transaction_t *transaction;
3207         long ret;
3208         int block;
3209 +       uid_t uid;
3210 +       gid_t gid;
3211  
3212         inode = iget_locked(sb, ino);
3213         if (!inode)
3214 @@ -2787,12 +2814,17 @@ struct inode *ext3_iget(struct super_blo
3215         bh = iloc.bh;
3216         raw_inode = ext3_raw_inode(&iloc);
3217         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3218 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3219 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3220 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3221 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3222         if(!(test_opt (inode->i_sb, NO_UID32))) {
3223 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3224 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3225 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3226 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3227         }
3228 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3229 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3230 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3231 +               le16_to_cpu(raw_inode->i_raw_tag));
3232 +
3233         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3234         inode->i_size = le32_to_cpu(raw_inode->i_size);
3235         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3236 @@ -2947,6 +2979,8 @@ static int ext3_do_update_inode(handle_t
3237         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3238         struct ext3_inode_info *ei = EXT3_I(inode);
3239         struct buffer_head *bh = iloc->bh;
3240 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3241 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3242         int err = 0, rc, block;
3243  
3244  again:
3245 @@ -2961,29 +2995,32 @@ again:
3246         ext3_get_inode_flags(ei);
3247         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3248         if(!(test_opt(inode->i_sb, NO_UID32))) {
3249 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3250 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3251 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3252 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3253  /*
3254   * Fix up interoperability with old kernels. Otherwise, old inodes get
3255   * re-used with the upper 16 bits of the uid/gid intact
3256   */
3257                 if(!ei->i_dtime) {
3258                         raw_inode->i_uid_high =
3259 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3260 +                               cpu_to_le16(high_16_bits(uid));
3261                         raw_inode->i_gid_high =
3262 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3263 +                               cpu_to_le16(high_16_bits(gid));
3264                 } else {
3265                         raw_inode->i_uid_high = 0;
3266                         raw_inode->i_gid_high = 0;
3267                 }
3268         } else {
3269                 raw_inode->i_uid_low =
3270 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3271 +                       cpu_to_le16(fs_high2lowuid(uid));
3272                 raw_inode->i_gid_low =
3273 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3274 +                       cpu_to_le16(fs_high2lowgid(gid));
3275                 raw_inode->i_uid_high = 0;
3276                 raw_inode->i_gid_high = 0;
3277         }
3278 +#ifdef CONFIG_TAGGING_INTERN
3279 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3280 +#endif
3281         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3282         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3283         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3284 @@ -3141,7 +3178,8 @@ int ext3_setattr(struct dentry *dentry, 
3285                 return error;
3286  
3287         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3288 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3289 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3290 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3291                 handle_t *handle;
3292  
3293                 /* (user+group)*(old+new) structure, inode write (sb,
3294 @@ -3163,6 +3201,8 @@ int ext3_setattr(struct dentry *dentry, 
3295                         inode->i_uid = attr->ia_uid;
3296                 if (attr->ia_valid & ATTR_GID)
3297                         inode->i_gid = attr->ia_gid;
3298 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3299 +                       inode->i_tag = attr->ia_tag;
3300                 error = ext3_mark_inode_dirty(handle, inode);
3301                 ext3_journal_stop(handle);
3302         }
3303 diff -NurpP --minimal linux-2.6.32.10/fs/ext3/ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/ioctl.c
3304 --- linux-2.6.32.10/fs/ext3/ioctl.c     2009-06-11 17:13:03.000000000 +0200
3305 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/ioctl.c     2009-12-03 20:04:56.000000000 +0100
3306 @@ -8,6 +8,7 @@
3307   */
3308  
3309  #include <linux/fs.h>
3310 +#include <linux/mount.h>
3311  #include <linux/jbd.h>
3312  #include <linux/capability.h>
3313  #include <linux/ext3_fs.h>
3314 @@ -17,6 +18,34 @@
3315  #include <linux/compat.h>
3316  #include <asm/uaccess.h>
3317  
3318 +
3319 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3320 +{
3321 +       handle_t *handle = NULL;
3322 +       struct ext3_iloc iloc;
3323 +       int err;
3324 +
3325 +       handle = ext3_journal_start(inode, 1);
3326 +       if (IS_ERR(handle))
3327 +               return PTR_ERR(handle);
3328 +
3329 +       if (IS_SYNC(inode))
3330 +               handle->h_sync = 1;
3331 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3332 +       if (err)
3333 +               goto flags_err;
3334 +
3335 +       inode->i_flags = flags;
3336 +       inode->i_vflags = vflags;
3337 +       ext3_get_inode_flags(EXT3_I(inode));
3338 +       inode->i_ctime = CURRENT_TIME_SEC;
3339 +
3340 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3341 +flags_err:
3342 +       ext3_journal_stop(handle);
3343 +       return err;
3344 +}
3345 +
3346  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3347  {
3348         struct inode *inode = filp->f_dentry->d_inode;
3349 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3350  
3351                 flags = ext3_mask_flags(inode->i_mode, flags);
3352  
3353 +               if (IS_BARRIER(inode)) {
3354 +                       vxwprintk_task(1, "messing with the barrier.");
3355 +                       return -EACCES;
3356 +               }
3357 +
3358                 mutex_lock(&inode->i_mutex);
3359  
3360                 /* Is it quota file? Do not allow user to mess with it */
3361 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3362                  *
3363                  * This test looks nicer. Thanks to Pauline Middelink
3364                  */
3365 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3366 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3367 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3368 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3369                         if (!capable(CAP_LINUX_IMMUTABLE))
3370                                 goto flags_out;
3371                 }
3372 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3373                 if (err)
3374                         goto flags_err;
3375  
3376 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3377 +               flags &= EXT3_FL_USER_MODIFIABLE;
3378                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3379                 ei->i_flags = flags;
3380  
3381 diff -NurpP --minimal linux-2.6.32.10/fs/ext3/namei.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/namei.c
3382 --- linux-2.6.32.10/fs/ext3/namei.c     2009-12-03 20:02:51.000000000 +0100
3383 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/namei.c     2009-12-03 20:04:56.000000000 +0100
3384 @@ -36,6 +36,7 @@
3385  #include <linux/quotaops.h>
3386  #include <linux/buffer_head.h>
3387  #include <linux/bio.h>
3388 +#include <linux/vs_tag.h>
3389  
3390  #include "namei.h"
3391  #include "xattr.h"
3392 @@ -912,6 +913,7 @@ restart:
3393                                 if (bh)
3394                                         ll_rw_block(READ_META, 1, &bh);
3395                         }
3396 +               dx_propagate_tag(nd, inode);
3397                 }
3398                 if ((bh = bh_use[ra_ptr++]) == NULL)
3399                         goto next;
3400 @@ -2446,6 +2448,7 @@ const struct inode_operations ext3_dir_i
3401         .removexattr    = generic_removexattr,
3402  #endif
3403         .check_acl      = ext3_check_acl,
3404 +       .sync_flags     = ext3_sync_flags,
3405  };
3406  
3407  const struct inode_operations ext3_special_inode_operations = {
3408 diff -NurpP --minimal linux-2.6.32.10/fs/ext3/super.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/super.c
3409 --- linux-2.6.32.10/fs/ext3/super.c     2009-12-03 20:02:51.000000000 +0100
3410 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext3/super.c     2009-12-03 20:04:56.000000000 +0100
3411 @@ -789,7 +789,7 @@ enum {
3412         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3413         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3414         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3415 -       Opt_grpquota
3416 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3417  };
3418  
3419  static const match_table_t tokens = {
3420 @@ -842,6 +842,9 @@ static const match_table_t tokens = {
3421         {Opt_usrquota, "usrquota"},
3422         {Opt_barrier, "barrier=%u"},
3423         {Opt_resize, "resize"},
3424 +       {Opt_tag, "tag"},
3425 +       {Opt_notag, "notag"},
3426 +       {Opt_tagid, "tagid=%u"},
3427         {Opt_err, NULL},
3428  };
3429  
3430 @@ -934,6 +937,20 @@ static int parse_options (char *options,
3431                 case Opt_nouid32:
3432                         set_opt (sbi->s_mount_opt, NO_UID32);
3433                         break;
3434 +#ifndef CONFIG_TAGGING_NONE
3435 +               case Opt_tag:
3436 +                       set_opt (sbi->s_mount_opt, TAGGED);
3437 +                       break;
3438 +               case Opt_notag:
3439 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3440 +                       break;
3441 +#endif
3442 +#ifdef CONFIG_PROPAGATE
3443 +               case Opt_tagid:
3444 +                       /* use args[0] */
3445 +                       set_opt (sbi->s_mount_opt, TAGGED);
3446 +                       break;
3447 +#endif
3448                 case Opt_nocheck:
3449                         clear_opt (sbi->s_mount_opt, CHECK);
3450                         break;
3451 @@ -1658,6 +1675,9 @@ static int ext3_fill_super (struct super
3452                             NULL, 0))
3453                 goto failed_mount;
3454  
3455 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3456 +               sb->s_flags |= MS_TAGGED;
3457 +
3458         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3459                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3460  
3461 @@ -2527,6 +2547,14 @@ static int ext3_remount (struct super_bl
3462         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3463                 ext3_abort(sb, __func__, "Abort forced by user");
3464  
3465 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3466 +               !(sb->s_flags & MS_TAGGED)) {
3467 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3468 +                       sb->s_id);
3469 +               err = -EINVAL;
3470 +               goto restore_opts;
3471 +       }
3472 +
3473         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3474                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3475  
3476 diff -NurpP --minimal linux-2.6.32.10/fs/ext4/ext4.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/ext4.h
3477 --- linux-2.6.32.10/fs/ext4/ext4.h      2010-03-18 16:17:36.000000000 +0100
3478 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/ext4.h      2010-01-13 14:33:47.000000000 +0100
3479 @@ -284,8 +284,12 @@ struct flex_groups {
3480  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
3481  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
3482  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3483 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3484  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3485  
3486 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3487 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3488 +
3489  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3490  #define EXT4_FL_USER_MODIFIABLE                0x000B80FF /* User modifiable flags */
3491  
3492 @@ -469,7 +473,8 @@ struct ext4_inode {
3493                         __le16  l_i_file_acl_high;
3494                         __le16  l_i_uid_high;   /* these 2 fields */
3495                         __le16  l_i_gid_high;   /* were reserved2[0] */
3496 -                       __u32   l_i_reserved2;
3497 +                       __le16  l_i_tag;        /* Context Tag */
3498 +                       __u16   l_i_reserved2;
3499                 } linux2;
3500                 struct {
3501                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3502 @@ -583,6 +588,7 @@ do {                                                                               \
3503  #define i_gid_low      i_gid
3504  #define i_uid_high     osd2.linux2.l_i_uid_high
3505  #define i_gid_high     osd2.linux2.l_i_gid_high
3506 +#define i_raw_tag      osd2.linux2.l_i_tag
3507  #define i_reserved2    osd2.linux2.l_i_reserved2
3508  
3509  #elif defined(__GNU__)
3510 @@ -755,6 +761,7 @@ struct ext4_inode_info {
3511  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3512  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3513  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3514 +#define EXT4_MOUNT_TAGGED              0x400000 /* Enable Context Tags */
3515  #define EXT4_MOUNT_JOURNAL_CHECKSUM    0x800000 /* Journal checksums */
3516  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
3517  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3518 @@ -1746,6 +1753,7 @@ extern int ext4_get_blocks(handle_t *han
3519                            struct buffer_head *bh, int flags);
3520  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3521                         __u64 start, __u64 len);
3522 +extern int ext4_sync_flags(struct inode *, int, int);
3523  /* move_extent.c */
3524  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3525                              __u64 start_orig, __u64 start_donor,
3526 diff -NurpP --minimal linux-2.6.32.10/fs/ext4/file.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/file.c
3527 --- linux-2.6.32.10/fs/ext4/file.c      2009-12-03 20:02:51.000000000 +0100
3528 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/file.c      2009-12-03 20:04:56.000000000 +0100
3529 @@ -161,5 +161,6 @@ const struct inode_operations ext4_file_
3530         .check_acl      = ext4_check_acl,
3531         .fallocate      = ext4_fallocate,
3532         .fiemap         = ext4_fiemap,
3533 +       .sync_flags     = ext4_sync_flags,
3534  };
3535  
3536 diff -NurpP --minimal linux-2.6.32.10/fs/ext4/ialloc.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/ialloc.c
3537 --- linux-2.6.32.10/fs/ext4/ialloc.c    2009-12-03 20:02:51.000000000 +0100
3538 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/ialloc.c    2009-12-03 20:04:56.000000000 +0100
3539 @@ -22,6 +22,7 @@
3540  #include <linux/random.h>
3541  #include <linux/bitops.h>
3542  #include <linux/blkdev.h>
3543 +#include <linux/vs_tag.h>
3544  #include <asm/byteorder.h>
3545  
3546  #include "ext4.h"
3547 @@ -995,6 +996,7 @@ got:
3548         } else
3549                 inode->i_gid = current_fsgid();
3550         inode->i_mode = mode;
3551 +       inode->i_tag = dx_current_fstag(sb);
3552  
3553         inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb);
3554         /* This is the optimal IO size (for stat), not the fs block size */
3555 diff -NurpP --minimal linux-2.6.32.10/fs/ext4/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/inode.c
3556 --- linux-2.6.32.10/fs/ext4/inode.c     2010-03-18 16:17:36.000000000 +0100
3557 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/inode.c     2010-01-13 14:33:47.000000000 +0100
3558 @@ -38,6 +38,7 @@
3559  #include <linux/uio.h>
3560  #include <linux/bio.h>
3561  #include <linux/workqueue.h>
3562 +#include <linux/vs_tag.h>
3563  
3564  #include "ext4_jbd2.h"
3565  #include "xattr.h"
3566 @@ -4378,7 +4379,7 @@ static void ext4_free_branches(handle_t 
3567  
3568  int ext4_can_truncate(struct inode *inode)
3569  {
3570 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3571 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3572                 return 0;
3573         if (S_ISREG(inode->i_mode))
3574                 return 1;
3575 @@ -4729,36 +4730,60 @@ void ext4_set_inode_flags(struct inode *
3576  {
3577         unsigned int flags = EXT4_I(inode)->i_flags;
3578  
3579 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3580 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3581 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3582 +
3583 +       if (flags & EXT4_IMMUTABLE_FL)
3584 +               inode->i_flags |= S_IMMUTABLE;
3585 +       if (flags & EXT4_IXUNLINK_FL)
3586 +               inode->i_flags |= S_IXUNLINK;
3587 +
3588         if (flags & EXT4_SYNC_FL)
3589                 inode->i_flags |= S_SYNC;
3590         if (flags & EXT4_APPEND_FL)
3591                 inode->i_flags |= S_APPEND;
3592 -       if (flags & EXT4_IMMUTABLE_FL)
3593 -               inode->i_flags |= S_IMMUTABLE;
3594         if (flags & EXT4_NOATIME_FL)
3595                 inode->i_flags |= S_NOATIME;
3596         if (flags & EXT4_DIRSYNC_FL)
3597                 inode->i_flags |= S_DIRSYNC;
3598 +
3599 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3600 +
3601 +       if (flags & EXT4_BARRIER_FL)
3602 +               inode->i_vflags |= V_BARRIER;
3603 +       if (flags & EXT4_COW_FL)
3604 +               inode->i_vflags |= V_COW;
3605  }
3606  
3607  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3608  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3609  {
3610         unsigned int flags = ei->vfs_inode.i_flags;
3611 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3612 +
3613 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3614 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3615 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3616 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3617 +
3618 +       if (flags & S_IMMUTABLE)
3619 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3620 +       if (flags & S_IXUNLINK)
3621 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3622  
3623 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3624 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3625         if (flags & S_SYNC)
3626                 ei->i_flags |= EXT4_SYNC_FL;
3627         if (flags & S_APPEND)
3628                 ei->i_flags |= EXT4_APPEND_FL;
3629 -       if (flags & S_IMMUTABLE)
3630 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3631         if (flags & S_NOATIME)
3632                 ei->i_flags |= EXT4_NOATIME_FL;
3633         if (flags & S_DIRSYNC)
3634                 ei->i_flags |= EXT4_DIRSYNC_FL;
3635 +
3636 +       if (vflags & V_BARRIER)
3637 +               ei->i_flags |= EXT4_BARRIER_FL;
3638 +       if (vflags & V_COW)
3639 +               ei->i_flags |= EXT4_COW_FL;
3640  }
3641  
3642  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3643 @@ -4793,6 +4818,8 @@ struct inode *ext4_iget(struct super_blo
3644         journal_t *journal = EXT4_SB(sb)->s_journal;
3645         long ret;
3646         int block;
3647 +       uid_t uid;
3648 +       gid_t gid;
3649  
3650         inode = iget_locked(sb, ino);
3651         if (!inode)
3652 @@ -4808,12 +4835,16 @@ struct inode *ext4_iget(struct super_blo
3653                 goto bad_inode;
3654         raw_inode = ext4_raw_inode(&iloc);
3655         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3656 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3657 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3658 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3659 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3660         if (!(test_opt(inode->i_sb, NO_UID32))) {
3661 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3662 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3663 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3664 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3665         }
3666 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3667 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3668 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3669 +               le16_to_cpu(raw_inode->i_raw_tag));
3670         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3671  
3672         ei->i_state = 0;
3673 @@ -5035,6 +5066,8 @@ static int ext4_do_update_inode(handle_t
3674         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3675         struct ext4_inode_info *ei = EXT4_I(inode);
3676         struct buffer_head *bh = iloc->bh;
3677 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3678 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3679         int err = 0, rc, block;
3680  
3681         /* For fields not not tracking in the in-memory inode,
3682 @@ -5045,29 +5078,32 @@ static int ext4_do_update_inode(handle_t
3683         ext4_get_inode_flags(ei);
3684         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3685         if (!(test_opt(inode->i_sb, NO_UID32))) {
3686 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3687 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3688 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3689 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3690  /*
3691   * Fix up interoperability with old kernels. Otherwise, old inodes get
3692   * re-used with the upper 16 bits of the uid/gid intact
3693   */
3694                 if (!ei->i_dtime) {
3695                         raw_inode->i_uid_high =
3696 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3697 +                               cpu_to_le16(high_16_bits(uid));
3698                         raw_inode->i_gid_high =
3699 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3700 +                               cpu_to_le16(high_16_bits(gid));
3701                 } else {
3702                         raw_inode->i_uid_high = 0;
3703                         raw_inode->i_gid_high = 0;
3704                 }
3705         } else {
3706                 raw_inode->i_uid_low =
3707 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3708 +                       cpu_to_le16(fs_high2lowuid(uid));
3709                 raw_inode->i_gid_low =
3710 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3711 +                       cpu_to_le16(fs_high2lowgid(gid));
3712                 raw_inode->i_uid_high = 0;
3713                 raw_inode->i_gid_high = 0;
3714         }
3715 +#ifdef CONFIG_TAGGING_INTERN
3716 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3717 +#endif
3718         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3719  
3720         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3721 @@ -5252,7 +5288,8 @@ int ext4_setattr(struct dentry *dentry, 
3722                 return error;
3723  
3724         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3725 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3726 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3727 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3728                 handle_t *handle;
3729  
3730                 /* (user+group)*(old+new) structure, inode write (sb,
3731 @@ -5274,6 +5311,8 @@ int ext4_setattr(struct dentry *dentry, 
3732                         inode->i_uid = attr->ia_uid;
3733                 if (attr->ia_valid & ATTR_GID)
3734                         inode->i_gid = attr->ia_gid;
3735 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3736 +                       inode->i_tag = attr->ia_tag;
3737                 error = ext4_mark_inode_dirty(handle, inode);
3738                 ext4_journal_stop(handle);
3739         }
3740 diff -NurpP --minimal linux-2.6.32.10/fs/ext4/ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/ioctl.c
3741 --- linux-2.6.32.10/fs/ext4/ioctl.c     2010-03-18 16:17:36.000000000 +0100
3742 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/ioctl.c     2009-12-14 22:20:55.000000000 +0100
3743 @@ -14,10 +14,39 @@
3744  #include <linux/compat.h>
3745  #include <linux/mount.h>
3746  #include <linux/file.h>
3747 +#include <linux/vs_tag.h>
3748  #include <asm/uaccess.h>
3749  #include "ext4_jbd2.h"
3750  #include "ext4.h"
3751  
3752 +
3753 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3754 +{
3755 +       handle_t *handle = NULL;
3756 +       struct ext4_iloc iloc;
3757 +       int err;
3758 +
3759 +       handle = ext4_journal_start(inode, 1);
3760 +       if (IS_ERR(handle))
3761 +               return PTR_ERR(handle);
3762 +
3763 +       if (IS_SYNC(inode))
3764 +               ext4_handle_sync(handle);
3765 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3766 +       if (err)
3767 +               goto flags_err;
3768 +
3769 +       inode->i_flags = flags;
3770 +       inode->i_vflags = vflags;
3771 +       ext4_get_inode_flags(EXT4_I(inode));
3772 +       inode->i_ctime = ext4_current_time(inode);
3773 +
3774 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3775 +flags_err:
3776 +       ext4_journal_stop(handle);
3777 +       return err;
3778 +}
3779 +
3780  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3781  {
3782         struct inode *inode = filp->f_dentry->d_inode;
3783 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3784  
3785                 flags = ext4_mask_flags(inode->i_mode, flags);
3786  
3787 +               if (IS_BARRIER(inode)) {
3788 +                       vxwprintk_task(1, "messing with the barrier.");
3789 +                       return -EACCES;
3790 +               }
3791 +
3792                 err = -EPERM;
3793                 mutex_lock(&inode->i_mutex);
3794                 /* Is it quota file? Do not allow user to mess with it */
3795 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3796                  *
3797                  * This test looks nicer. Thanks to Pauline Middelink
3798                  */
3799 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3800 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3801 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3802 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3803                         if (!capable(CAP_LINUX_IMMUTABLE))
3804                                 goto flags_out;
3805                 }
3806 diff -NurpP --minimal linux-2.6.32.10/fs/ext4/namei.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/namei.c
3807 --- linux-2.6.32.10/fs/ext4/namei.c     2010-03-18 16:17:36.000000000 +0100
3808 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/namei.c     2009-12-14 22:20:55.000000000 +0100
3809 @@ -34,6 +34,7 @@
3810  #include <linux/quotaops.h>
3811  #include <linux/buffer_head.h>
3812  #include <linux/bio.h>
3813 +#include <linux/vs_tag.h>
3814  #include "ext4.h"
3815  #include "ext4_jbd2.h"
3816  
3817 @@ -941,6 +942,7 @@ restart:
3818                                 if (bh)
3819                                         ll_rw_block(READ_META, 1, &bh);
3820                         }
3821 +               dx_propagate_tag(nd, inode);
3822                 }
3823                 if ((bh = bh_use[ra_ptr++]) == NULL)
3824                         goto next;
3825 @@ -2533,6 +2535,7 @@ const struct inode_operations ext4_dir_i
3826  #endif
3827         .check_acl      = ext4_check_acl,
3828         .fiemap         = ext4_fiemap,
3829 +       .sync_flags     = ext4_sync_flags,
3830  };
3831  
3832  const struct inode_operations ext4_special_inode_operations = {
3833 diff -NurpP --minimal linux-2.6.32.10/fs/ext4/super.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/super.c
3834 --- linux-2.6.32.10/fs/ext4/super.c     2010-03-18 16:17:36.000000000 +0100
3835 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ext4/super.c     2010-01-13 14:33:47.000000000 +0100
3836 @@ -1096,6 +1096,7 @@ enum {
3837         Opt_block_validity, Opt_noblock_validity,
3838         Opt_inode_readahead_blks, Opt_journal_ioprio,
3839         Opt_discard, Opt_nodiscard,
3840 +       Opt_tag, Opt_notag, Opt_tagid
3841  };
3842  
3843  static const match_table_t tokens = {
3844 @@ -1163,6 +1164,9 @@ static const match_table_t tokens = {
3845         {Opt_noauto_da_alloc, "noauto_da_alloc"},
3846         {Opt_discard, "discard"},
3847         {Opt_nodiscard, "nodiscard"},
3848 +       {Opt_tag, "tag"},
3849 +       {Opt_notag, "notag"},
3850 +       {Opt_tagid, "tagid=%u"},
3851         {Opt_err, NULL},
3852  };
3853  
3854 @@ -1260,6 +1264,20 @@ static int parse_options(char *options, 
3855                 case Opt_nouid32:
3856                         set_opt(sbi->s_mount_opt, NO_UID32);
3857                         break;
3858 +#ifndef CONFIG_TAGGING_NONE
3859 +               case Opt_tag:
3860 +                       set_opt (sbi->s_mount_opt, TAGGED);
3861 +                       break;
3862 +               case Opt_notag:
3863 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3864 +                       break;
3865 +#endif
3866 +#ifdef CONFIG_PROPAGATE
3867 +               case Opt_tagid:
3868 +                       /* use args[0] */
3869 +                       set_opt (sbi->s_mount_opt, TAGGED);
3870 +                       break;
3871 +#endif
3872                 case Opt_debug:
3873                         set_opt(sbi->s_mount_opt, DEBUG);
3874                         break;
3875 @@ -2460,6 +2478,9 @@ static int ext4_fill_super(struct super_
3876                            &journal_ioprio, NULL, 0))
3877                 goto failed_mount;
3878  
3879 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3880 +               sb->s_flags |= MS_TAGGED;
3881 +
3882         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3883                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3884  
3885 @@ -3517,6 +3538,14 @@ static int ext4_remount(struct super_blo
3886         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3887                 ext4_abort(sb, __func__, "Abort forced by user");
3888  
3889 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3890 +               !(sb->s_flags & MS_TAGGED)) {
3891 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3892 +                       sb->s_id);
3893 +               err = -EINVAL;
3894 +               goto restore_opts;
3895 +       }
3896 +
3897         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3898                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3899  
3900 diff -NurpP --minimal linux-2.6.32.10/fs/fcntl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/fcntl.c
3901 --- linux-2.6.32.10/fs/fcntl.c  2010-03-18 16:17:36.000000000 +0100
3902 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/fcntl.c  2010-02-24 12:32:54.000000000 +0100
3903 @@ -19,6 +19,7 @@
3904  #include <linux/signal.h>
3905  #include <linux/rcupdate.h>
3906  #include <linux/pid_namespace.h>
3907 +#include <linux/vs_limit.h>
3908  
3909  #include <asm/poll.h>
3910  #include <asm/siginfo.h>
3911 @@ -102,6 +103,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3912  
3913         if (tofree)
3914                 filp_close(tofree, files);
3915 +       else
3916 +               vx_openfd_inc(newfd);   /* fd was unused */
3917  
3918         return newfd;
3919  
3920 @@ -426,6 +429,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3921         filp = fget(fd);
3922         if (!filp)
3923                 goto out;
3924 +       if (!vx_files_avail(1))
3925 +               goto out;
3926  
3927         err = security_file_fcntl(filp, cmd, arg);
3928         if (err) {
3929 diff -NurpP --minimal linux-2.6.32.10/fs/file.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/file.c
3930 --- linux-2.6.32.10/fs/file.c   2009-12-03 20:02:51.000000000 +0100
3931 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/file.c   2009-12-03 20:04:56.000000000 +0100
3932 @@ -20,6 +20,7 @@
3933  #include <linux/spinlock.h>
3934  #include <linux/rcupdate.h>
3935  #include <linux/workqueue.h>
3936 +#include <linux/vs_limit.h>
3937  
3938  struct fdtable_defer {
3939         spinlock_t lock;
3940 @@ -368,6 +369,8 @@ struct files_struct *dup_fd(struct files
3941                 struct file *f = *old_fds++;
3942                 if (f) {
3943                         get_file(f);
3944 +                       /* TODO: sum it first for check and performance */
3945 +                       vx_openfd_inc(open_files - i);
3946                 } else {
3947                         /*
3948                          * The fd may be claimed in the fd bitmap but not yet
3949 @@ -476,6 +479,7 @@ repeat:
3950         else
3951                 FD_CLR(fd, fdt->close_on_exec);
3952         error = fd;
3953 +       vx_openfd_inc(fd);
3954  #if 1
3955         /* Sanity check */
3956         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3957 diff -NurpP --minimal linux-2.6.32.10/fs/file_table.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/file_table.c
3958 --- linux-2.6.32.10/fs/file_table.c     2010-03-18 16:17:36.000000000 +0100
3959 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/file_table.c     2010-03-18 16:53:06.000000000 +0100
3960 @@ -22,6 +22,8 @@
3961  #include <linux/fsnotify.h>
3962  #include <linux/sysctl.h>
3963  #include <linux/percpu_counter.h>
3964 +#include <linux/vs_limit.h>
3965 +#include <linux/vs_context.h>
3966  
3967  #include <asm/atomic.h>
3968  
3969 @@ -131,6 +133,8 @@ struct file *get_empty_filp(void)
3970         spin_lock_init(&f->f_lock);
3971         eventpoll_init_file(f);
3972         /* f->f_version: 0 */
3973 +       f->f_xid = vx_current_xid();
3974 +       vx_files_inc(f);
3975         return f;
3976  
3977  over:
3978 @@ -285,6 +289,8 @@ void __fput(struct file *file)
3979                 cdev_put(inode->i_cdev);
3980         fops_put(file->f_op);
3981         put_pid(file->f_owner.pid);
3982 +       vx_files_dec(file);
3983 +       file->f_xid = 0;
3984         file_kill(file);
3985         if (file->f_mode & FMODE_WRITE)
3986                 drop_file_write_access(file);
3987 @@ -352,6 +358,8 @@ void put_filp(struct file *file)
3988  {
3989         if (atomic_long_dec_and_test(&file->f_count)) {
3990                 security_file_free(file);
3991 +               vx_files_dec(file);
3992 +               file->f_xid = 0;
3993                 file_kill(file);
3994                 file_free(file);
3995         }
3996 diff -NurpP --minimal linux-2.6.32.10/fs/fs_struct.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/fs_struct.c
3997 --- linux-2.6.32.10/fs/fs_struct.c      2009-06-11 17:13:04.000000000 +0200
3998 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/fs_struct.c      2009-12-03 20:04:56.000000000 +0100
3999 @@ -4,6 +4,7 @@
4000  #include <linux/path.h>
4001  #include <linux/slab.h>
4002  #include <linux/fs_struct.h>
4003 +#include <linux/vserver/global.h>
4004  
4005  /*
4006   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
4007 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
4008  {
4009         path_put(&fs->root);
4010         path_put(&fs->pwd);
4011 +       atomic_dec(&vs_global_fs);
4012         kmem_cache_free(fs_cachep, fs);
4013  }
4014  
4015 @@ -112,6 +114,7 @@ struct fs_struct *copy_fs_struct(struct 
4016                 fs->pwd = old->pwd;
4017                 path_get(&old->pwd);
4018                 read_unlock(&old->lock);
4019 +               atomic_inc(&vs_global_fs);
4020         }
4021         return fs;
4022  }
4023 diff -NurpP --minimal linux-2.6.32.10/fs/gfs2/file.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/gfs2/file.c
4024 --- linux-2.6.32.10/fs/gfs2/file.c      2009-12-03 20:02:52.000000000 +0100
4025 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/gfs2/file.c      2009-12-03 20:04:56.000000000 +0100
4026 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
4027         [7] = GFS2_DIF_NOATIME,
4028         [12] = GFS2_DIF_EXHASH,
4029         [14] = GFS2_DIF_INHERIT_JDATA,
4030 +       [27] = GFS2_DIF_IXUNLINK,
4031 +       [26] = GFS2_DIF_BARRIER,
4032 +       [29] = GFS2_DIF_COW,
4033  };
4034  
4035  static const u32 gfs2_to_fsflags[32] = {
4036 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
4037         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4038         [gfs2fl_ExHash] = FS_INDEX_FL,
4039         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4040 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4041 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4042 +       [gfs2fl_Cow] = FS_COW_FL,
4043  };
4044  
4045  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4046 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
4047  {
4048         struct gfs2_inode *ip = GFS2_I(inode);
4049         unsigned int flags = inode->i_flags;
4050 +       unsigned int vflags = inode->i_vflags;
4051 +
4052 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4053 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4054  
4055 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4056         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4057                 flags |= S_IMMUTABLE;
4058 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4059 +               flags |= S_IXUNLINK;
4060 +
4061         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4062                 flags |= S_APPEND;
4063         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4064 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
4065         if (ip->i_diskflags & GFS2_DIF_SYNC)
4066                 flags |= S_SYNC;
4067         inode->i_flags = flags;
4068 +
4069 +       vflags &= ~(V_BARRIER | V_COW);
4070 +
4071 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4072 +               vflags |= V_BARRIER;
4073 +       if (ip->i_diskflags & GFS2_DIF_COW)
4074 +               vflags |= V_COW;
4075 +       inode->i_vflags = vflags;
4076 +}
4077 +
4078 +void gfs2_get_inode_flags(struct inode *inode)
4079 +{
4080 +       struct gfs2_inode *ip = GFS2_I(inode);
4081 +       unsigned int flags = inode->i_flags;
4082 +       unsigned int vflags = inode->i_vflags;
4083 +
4084 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4085 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4086 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4087 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4088 +
4089 +       if (flags & S_IMMUTABLE)
4090 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4091 +       if (flags & S_IXUNLINK)
4092 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4093 +
4094 +       if (flags & S_APPEND)
4095 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4096 +       if (flags & S_NOATIME)
4097 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4098 +       if (flags & S_SYNC)
4099 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4100 +
4101 +       if (vflags & V_BARRIER)
4102 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4103 +       if (vflags & V_COW)
4104 +               ip->i_diskflags |= GFS2_DIF_COW;
4105  }
4106  
4107  /* Flags that can be set by user space */
4108 @@ -286,6 +335,37 @@ static int gfs2_set_flags(struct file *f
4109         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4110  }
4111  
4112 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4113 +{
4114 +       struct gfs2_inode *ip = GFS2_I(inode);
4115 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4116 +       struct buffer_head *bh;
4117 +       struct gfs2_holder gh;
4118 +       int error;
4119 +
4120 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4121 +       if (error)
4122 +               return error;
4123 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4124 +       if (error)
4125 +               goto out;
4126 +       error = gfs2_meta_inode_buffer(ip, &bh);
4127 +       if (error)
4128 +               goto out_trans_end;
4129 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4130 +       inode->i_flags = flags;
4131 +       inode->i_vflags = vflags;
4132 +       gfs2_get_inode_flags(inode);
4133 +       gfs2_dinode_out(ip, bh->b_data);
4134 +       brelse(bh);
4135 +       gfs2_set_aops(inode);
4136 +out_trans_end:
4137 +       gfs2_trans_end(sdp);
4138 +out:
4139 +       gfs2_glock_dq_uninit(&gh);
4140 +       return error;
4141 +}
4142 +
4143  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4144  {
4145         switch(cmd) {
4146 diff -NurpP --minimal linux-2.6.32.10/fs/gfs2/inode.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/gfs2/inode.h
4147 --- linux-2.6.32.10/fs/gfs2/inode.h     2009-09-10 15:26:22.000000000 +0200
4148 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/gfs2/inode.h     2009-12-03 20:04:56.000000000 +0100
4149 @@ -109,6 +109,7 @@ extern const struct file_operations gfs2
4150  extern const struct file_operations gfs2_dir_fops_nolock;
4151  
4152  extern void gfs2_set_inode_flags(struct inode *inode);
4153 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4154   
4155  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4156  extern const struct file_operations gfs2_file_fops;
4157 diff -NurpP --minimal linux-2.6.32.10/fs/gfs2/ops_inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/gfs2/ops_inode.c
4158 --- linux-2.6.32.10/fs/gfs2/ops_inode.c 2009-12-03 20:02:52.000000000 +0100
4159 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/gfs2/ops_inode.c 2009-12-03 20:04:56.000000000 +0100
4160 @@ -1400,6 +1400,7 @@ const struct inode_operations gfs2_file_
4161         .listxattr = gfs2_listxattr,
4162         .removexattr = gfs2_removexattr,
4163         .fiemap = gfs2_fiemap,
4164 +       .sync_flags = gfs2_sync_flags,
4165  };
4166  
4167  const struct inode_operations gfs2_dir_iops = {
4168 @@ -1420,6 +1421,7 @@ const struct inode_operations gfs2_dir_i
4169         .listxattr = gfs2_listxattr,
4170         .removexattr = gfs2_removexattr,
4171         .fiemap = gfs2_fiemap,
4172 +       .sync_flags = gfs2_sync_flags,
4173  };
4174  
4175  const struct inode_operations gfs2_symlink_iops = {
4176 diff -NurpP --minimal linux-2.6.32.10/fs/hfsplus/ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/hfsplus/ioctl.c
4177 --- linux-2.6.32.10/fs/hfsplus/ioctl.c  2008-12-25 00:26:37.000000000 +0100
4178 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/hfsplus/ioctl.c  2009-12-03 20:04:56.000000000 +0100
4179 @@ -17,6 +17,7 @@
4180  #include <linux/mount.h>
4181  #include <linux/sched.h>
4182  #include <linux/xattr.h>
4183 +#include <linux/mount.h>
4184  #include <asm/uaccess.h>
4185  #include "hfsplus_fs.h"
4186  
4187 diff -NurpP --minimal linux-2.6.32.10/fs/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/inode.c
4188 --- linux-2.6.32.10/fs/inode.c  2009-12-03 20:02:52.000000000 +0100
4189 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/inode.c  2009-12-03 20:04:56.000000000 +0100
4190 @@ -133,6 +133,9 @@ int inode_init_always(struct super_block
4191         struct address_space *const mapping = &inode->i_data;
4192  
4193         inode->i_sb = sb;
4194 +
4195 +       /* essential because of inode slab reuse */
4196 +       inode->i_tag = 0;
4197         inode->i_blkbits = sb->s_blocksize_bits;
4198         inode->i_flags = 0;
4199         atomic_set(&inode->i_count, 1);
4200 @@ -153,6 +156,7 @@ int inode_init_always(struct super_block
4201         inode->i_bdev = NULL;
4202         inode->i_cdev = NULL;
4203         inode->i_rdev = 0;
4204 +       inode->i_mdev = 0;
4205         inode->dirtied_when = 0;
4206  
4207         if (security_inode_alloc(inode))
4208 @@ -307,6 +311,8 @@ void __iget(struct inode *inode)
4209         inodes_stat.nr_unused--;
4210  }
4211  
4212 +EXPORT_SYMBOL_GPL(__iget);
4213 +
4214  /**
4215   * clear_inode - clear an inode
4216   * @inode: inode to clear
4217 @@ -1611,9 +1617,11 @@ void init_special_inode(struct inode *in
4218         if (S_ISCHR(mode)) {
4219                 inode->i_fop = &def_chr_fops;
4220                 inode->i_rdev = rdev;
4221 +               inode->i_mdev = rdev;
4222         } else if (S_ISBLK(mode)) {
4223                 inode->i_fop = &def_blk_fops;
4224                 inode->i_rdev = rdev;
4225 +               inode->i_mdev = rdev;
4226         } else if (S_ISFIFO(mode))
4227                 inode->i_fop = &def_fifo_fops;
4228         else if (S_ISSOCK(mode))
4229 diff -NurpP --minimal linux-2.6.32.10/fs/ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ioctl.c
4230 --- linux-2.6.32.10/fs/ioctl.c  2009-12-03 20:02:52.000000000 +0100
4231 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ioctl.c  2009-12-03 20:04:56.000000000 +0100
4232 @@ -16,6 +16,9 @@
4233  #include <linux/writeback.h>
4234  #include <linux/buffer_head.h>
4235  #include <linux/falloc.h>
4236 +#include <linux/proc_fs.h>
4237 +#include <linux/vserver/inode.h>
4238 +#include <linux/vs_tag.h>
4239  
4240  #include <asm/ioctls.h>
4241  
4242 diff -NurpP --minimal linux-2.6.32.10/fs/ioprio.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ioprio.c
4243 --- linux-2.6.32.10/fs/ioprio.c 2009-03-24 14:22:26.000000000 +0100
4244 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ioprio.c 2009-12-03 20:04:56.000000000 +0100
4245 @@ -26,6 +26,7 @@
4246  #include <linux/syscalls.h>
4247  #include <linux/security.h>
4248  #include <linux/pid_namespace.h>
4249 +#include <linux/vs_base.h>
4250  
4251  int set_task_ioprio(struct task_struct *task, int ioprio)
4252  {
4253 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4254                         else
4255                                 pgrp = find_vpid(who);
4256                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4257 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4258 +                                       continue;
4259                                 ret = set_task_ioprio(p, ioprio);
4260                                 if (ret)
4261                                         break;
4262 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4263                         else
4264                                 pgrp = find_vpid(who);
4265                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4266 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4267 +                                       continue;
4268                                 tmpio = get_task_ioprio(p);
4269                                 if (tmpio < 0)
4270                                         continue;
4271 diff -NurpP --minimal linux-2.6.32.10/fs/jfs/acl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/acl.c
4272 --- linux-2.6.32.10/fs/jfs/acl.c        2009-12-03 20:02:52.000000000 +0100
4273 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/acl.c        2009-12-03 20:04:56.000000000 +0100
4274 @@ -216,7 +216,8 @@ int jfs_setattr(struct dentry *dentry, s
4275                 return rc;
4276  
4277         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4278 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4279 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4280 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4281                 if (vfs_dq_transfer(inode, iattr))
4282                         return -EDQUOT;
4283         }
4284 diff -NurpP --minimal linux-2.6.32.10/fs/jfs/file.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/file.c
4285 --- linux-2.6.32.10/fs/jfs/file.c       2009-12-03 20:02:52.000000000 +0100
4286 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/file.c       2009-12-03 20:04:56.000000000 +0100
4287 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4288         .setattr        = jfs_setattr,
4289         .check_acl      = jfs_check_acl,
4290  #endif
4291 +       .sync_flags     = jfs_sync_flags,
4292  };
4293  
4294  const struct file_operations jfs_file_operations = {
4295 diff -NurpP --minimal linux-2.6.32.10/fs/jfs/ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/ioctl.c
4296 --- linux-2.6.32.10/fs/jfs/ioctl.c      2008-12-25 00:26:37.000000000 +0100
4297 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/ioctl.c      2009-12-03 20:04:56.000000000 +0100
4298 @@ -11,6 +11,7 @@
4299  #include <linux/mount.h>
4300  #include <linux/time.h>
4301  #include <linux/sched.h>
4302 +#include <linux/mount.h>
4303  #include <asm/current.h>
4304  #include <asm/uaccess.h>
4305  
4306 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4307  }
4308  
4309  
4310 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4311 +{
4312 +       inode->i_flags = flags;
4313 +       inode->i_vflags = vflags;
4314 +       jfs_get_inode_flags(JFS_IP(inode));
4315 +       inode->i_ctime = CURRENT_TIME_SEC;
4316 +       mark_inode_dirty(inode);
4317 +       return 0;
4318 +}
4319 +
4320  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4321  {
4322         struct inode *inode = filp->f_dentry->d_inode;
4323 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4324                 if (!S_ISDIR(inode->i_mode))
4325                         flags &= ~JFS_DIRSYNC_FL;
4326  
4327 +               if (IS_BARRIER(inode)) {
4328 +                       vxwprintk_task(1, "messing with the barrier.");
4329 +                       return -EACCES;
4330 +               }
4331 +
4332                 /* Is it quota file? Do not allow user to mess with it */
4333                 if (IS_NOQUOTA(inode)) {
4334                         err = -EPERM;
4335 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4336                  * the relevant capability.
4337                  */
4338                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4339 -                       ((flags ^ oldflags) &
4340 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4341 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4342 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4343                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4344                                 mutex_unlock(&inode->i_mutex);
4345                                 err = -EPERM;
4346 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4347                         }
4348                 }
4349  
4350 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4351 +               flags &= JFS_FL_USER_MODIFIABLE;
4352                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4353                 jfs_inode->mode2 = flags;
4354  
4355 diff -NurpP --minimal linux-2.6.32.10/fs/jfs/jfs_dinode.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/jfs_dinode.h
4356 --- linux-2.6.32.10/fs/jfs/jfs_dinode.h 2008-12-25 00:26:37.000000000 +0100
4357 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/jfs_dinode.h 2009-12-03 20:04:56.000000000 +0100
4358 @@ -161,9 +161,13 @@ struct dinode {
4359  
4360  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4361  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4362 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4363  
4364 -#define JFS_FL_USER_VISIBLE    0x03F80000
4365 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4366 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4367 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4368 +
4369 +#define JFS_FL_USER_VISIBLE    0x07F80000
4370 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4371  #define JFS_FL_INHERIT         0x03C80000
4372  
4373  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4374 diff -NurpP --minimal linux-2.6.32.10/fs/jfs/jfs_filsys.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/jfs_filsys.h
4375 --- linux-2.6.32.10/fs/jfs/jfs_filsys.h 2008-12-25 00:26:37.000000000 +0100
4376 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/jfs_filsys.h 2009-12-03 20:04:56.000000000 +0100
4377 @@ -263,6 +263,7 @@
4378  #define JFS_NAME_MAX   255
4379  #define JFS_PATH_MAX   BPSIZE
4380  
4381 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4382  
4383  /*
4384   *     file system state (superblock state)
4385 diff -NurpP --minimal linux-2.6.32.10/fs/jfs/jfs_imap.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/jfs_imap.c
4386 --- linux-2.6.32.10/fs/jfs/jfs_imap.c   2009-09-10 15:26:22.000000000 +0200
4387 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/jfs_imap.c   2009-12-03 20:04:56.000000000 +0100
4388 @@ -45,6 +45,7 @@
4389  #include <linux/buffer_head.h>
4390  #include <linux/pagemap.h>
4391  #include <linux/quotaops.h>
4392 +#include <linux/vs_tag.h>
4393  
4394  #include "jfs_incore.h"
4395  #include "jfs_inode.h"
4396 @@ -3059,6 +3060,8 @@ static int copy_from_dinode(struct dinod
4397  {
4398         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4399         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4400 +       uid_t uid;
4401 +       gid_t gid;
4402  
4403         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4404         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4405 @@ -3079,14 +3082,18 @@ static int copy_from_dinode(struct dinod
4406         }
4407         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4408  
4409 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4410 +       uid = le32_to_cpu(dip->di_uid);
4411 +       gid = le32_to_cpu(dip->di_gid);
4412 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4413 +
4414 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4415         if (sbi->uid == -1)
4416                 ip->i_uid = jfs_ip->saved_uid;
4417         else {
4418                 ip->i_uid = sbi->uid;
4419         }
4420  
4421 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4422 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4423         if (sbi->gid == -1)
4424                 ip->i_gid = jfs_ip->saved_gid;
4425         else {
4426 @@ -3151,14 +3158,12 @@ static void copy_to_dinode(struct dinode
4427         dip->di_size = cpu_to_le64(ip->i_size);
4428         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4429         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4430 -       if (sbi->uid == -1)
4431 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4432 -       else
4433 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4434 -       if (sbi->gid == -1)
4435 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4436 -       else
4437 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4438 +
4439 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4440 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4441 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4442 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4443 +
4444         jfs_get_inode_flags(jfs_ip);
4445         /*
4446          * mode2 is only needed for storing the higher order bits.
4447 diff -NurpP --minimal linux-2.6.32.10/fs/jfs/jfs_inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/jfs_inode.c
4448 --- linux-2.6.32.10/fs/jfs/jfs_inode.c  2009-06-11 17:13:05.000000000 +0200
4449 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/jfs_inode.c  2009-12-03 20:04:56.000000000 +0100
4450 @@ -18,6 +18,7 @@
4451  
4452  #include <linux/fs.h>
4453  #include <linux/quotaops.h>
4454 +#include <linux/vs_tag.h>
4455  #include "jfs_incore.h"
4456  #include "jfs_inode.h"
4457  #include "jfs_filsys.h"
4458 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4459  {
4460         unsigned int flags = JFS_IP(inode)->mode2;
4461  
4462 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4463 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4464 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4465 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4466  
4467         if (flags & JFS_IMMUTABLE_FL)
4468                 inode->i_flags |= S_IMMUTABLE;
4469 +       if (flags & JFS_IXUNLINK_FL)
4470 +               inode->i_flags |= S_IXUNLINK;
4471 +
4472 +       if (flags & JFS_SYNC_FL)
4473 +               inode->i_flags |= S_SYNC;
4474         if (flags & JFS_APPEND_FL)
4475                 inode->i_flags |= S_APPEND;
4476         if (flags & JFS_NOATIME_FL)
4477                 inode->i_flags |= S_NOATIME;
4478         if (flags & JFS_DIRSYNC_FL)
4479                 inode->i_flags |= S_DIRSYNC;
4480 -       if (flags & JFS_SYNC_FL)
4481 -               inode->i_flags |= S_SYNC;
4482 +
4483 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4484 +
4485 +       if (flags & JFS_BARRIER_FL)
4486 +               inode->i_vflags |= V_BARRIER;
4487 +       if (flags & JFS_COW_FL)
4488 +               inode->i_vflags |= V_COW;
4489  }
4490  
4491  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4492  {
4493         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4494 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4495 +
4496 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4497 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4498 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4499 +                          JFS_BARRIER_FL | JFS_COW_FL);
4500  
4501 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4502 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4503         if (flags & S_IMMUTABLE)
4504                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4505 +       if (flags & S_IXUNLINK)
4506 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4507 +
4508         if (flags & S_APPEND)
4509                 jfs_ip->mode2 |= JFS_APPEND_FL;
4510         if (flags & S_NOATIME)
4511 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4512                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4513         if (flags & S_SYNC)
4514                 jfs_ip->mode2 |= JFS_SYNC_FL;
4515 +
4516 +       if (vflags & V_BARRIER)
4517 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4518 +       if (vflags & V_COW)
4519 +               jfs_ip->mode2 |= JFS_COW_FL;
4520  }
4521  
4522  /*
4523 @@ -105,6 +128,7 @@ struct inode *ialloc(struct inode *paren
4524                         mode |= S_ISGID;
4525         } else
4526                 inode->i_gid = current_fsgid();
4527 +       inode->i_tag = dx_current_fstag(sb);
4528  
4529         /*
4530          * New inodes need to save sane values on disk when
4531 diff -NurpP --minimal linux-2.6.32.10/fs/jfs/jfs_inode.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/jfs_inode.h
4532 --- linux-2.6.32.10/fs/jfs/jfs_inode.h  2009-06-11 17:13:05.000000000 +0200
4533 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/jfs_inode.h  2009-12-03 20:04:56.000000000 +0100
4534 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4535  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4536         int fh_len, int fh_type);
4537  extern void jfs_set_inode_flags(struct inode *);
4538 +extern int jfs_sync_flags(struct inode *, int, int);
4539  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4540  
4541  extern const struct address_space_operations jfs_aops;
4542 diff -NurpP --minimal linux-2.6.32.10/fs/jfs/namei.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/namei.c
4543 --- linux-2.6.32.10/fs/jfs/namei.c      2009-12-03 20:02:52.000000000 +0100
4544 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/namei.c      2009-12-03 20:04:56.000000000 +0100
4545 @@ -21,6 +21,7 @@
4546  #include <linux/ctype.h>
4547  #include <linux/quotaops.h>
4548  #include <linux/exportfs.h>
4549 +#include <linux/vs_tag.h>
4550  #include "jfs_incore.h"
4551  #include "jfs_superblock.h"
4552  #include "jfs_inode.h"
4553 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4554                 return ERR_CAST(ip);
4555         }
4556  
4557 +       dx_propagate_tag(nd, ip);
4558         dentry = d_splice_alias(ip, dentry);
4559  
4560         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4561 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4562         .setattr        = jfs_setattr,
4563         .check_acl      = jfs_check_acl,
4564  #endif
4565 +       .sync_flags     = jfs_sync_flags,
4566  };
4567  
4568  const struct file_operations jfs_dir_operations = {
4569 diff -NurpP --minimal linux-2.6.32.10/fs/jfs/super.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/super.c
4570 --- linux-2.6.32.10/fs/jfs/super.c      2009-12-03 20:02:52.000000000 +0100
4571 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/jfs/super.c      2009-12-03 20:04:56.000000000 +0100
4572 @@ -192,7 +192,8 @@ static void jfs_put_super(struct super_b
4573  enum {
4574         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4575         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4576 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4577 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4578 +       Opt_tag, Opt_notag, Opt_tagid
4579  };
4580  
4581  static const match_table_t tokens = {
4582 @@ -202,6 +203,10 @@ static const match_table_t tokens = {
4583         {Opt_resize, "resize=%u"},
4584         {Opt_resize_nosize, "resize"},
4585         {Opt_errors, "errors=%s"},
4586 +       {Opt_tag, "tag"},
4587 +       {Opt_notag, "notag"},
4588 +       {Opt_tagid, "tagid=%u"},
4589 +       {Opt_tag, "tagxid"},
4590         {Opt_ignore, "noquota"},
4591         {Opt_ignore, "quota"},
4592         {Opt_usrquota, "usrquota"},
4593 @@ -336,6 +341,20 @@ static int parse_options(char *options, 
4594                         }
4595                         break;
4596                 }
4597 +#ifndef CONFIG_TAGGING_NONE
4598 +               case Opt_tag:
4599 +                       *flag |= JFS_TAGGED;
4600 +                       break;
4601 +               case Opt_notag:
4602 +                       *flag &= JFS_TAGGED;
4603 +                       break;
4604 +#endif
4605 +#ifdef CONFIG_PROPAGATE
4606 +               case Opt_tagid:
4607 +                       /* use args[0] */
4608 +                       *flag |= JFS_TAGGED;
4609 +                       break;
4610 +#endif
4611                 default:
4612                         printk("jfs: Unrecognized mount option \"%s\" "
4613                                         " or missing value\n", p);
4614 @@ -366,6 +385,12 @@ static int jfs_remount(struct super_bloc
4615         if (!parse_options(data, sb, &newLVSize, &flag)) {
4616                 return -EINVAL;
4617         }
4618 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4619 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4620 +                       sb->s_id);
4621 +               return -EINVAL;
4622 +       }
4623 +
4624         lock_kernel();
4625         if (newLVSize) {
4626                 if (sb->s_flags & MS_RDONLY) {
4627 @@ -449,6 +474,9 @@ static int jfs_fill_super(struct super_b
4628  #ifdef CONFIG_JFS_POSIX_ACL
4629         sb->s_flags |= MS_POSIXACL;
4630  #endif
4631 +       /* map mount option tagxid */
4632 +       if (sbi->flag & JFS_TAGGED)
4633 +               sb->s_flags |= MS_TAGGED;
4634  
4635         if (newLVSize) {
4636                 printk(KERN_ERR "resize option for remount only\n");
4637 diff -NurpP --minimal linux-2.6.32.10/fs/libfs.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/libfs.c
4638 --- linux-2.6.32.10/fs/libfs.c  2009-12-03 20:02:52.000000000 +0100
4639 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/libfs.c  2009-12-03 20:04:56.000000000 +0100
4640 @@ -127,7 +127,8 @@ static inline unsigned char dt_type(stru
4641   * both impossible due to the lock on directory.
4642   */
4643  
4644 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4645 +static inline int do_dcache_readdir_filter(struct file *filp,
4646 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4647  {
4648         struct dentry *dentry = filp->f_path.dentry;
4649         struct dentry *cursor = filp->private_data;
4650 @@ -160,6 +161,8 @@ int dcache_readdir(struct file * filp, v
4651                                 next = list_entry(p, struct dentry, d_u.d_child);
4652                                 if (d_unhashed(next) || !next->d_inode)
4653                                         continue;
4654 +                               if (filter && !filter(next))
4655 +                                       continue;
4656  
4657                                 spin_unlock(&dcache_lock);
4658                                 if (filldir(dirent, next->d_name.name, 
4659 @@ -178,6 +181,18 @@ int dcache_readdir(struct file * filp, v
4660         return 0;
4661  }
4662  
4663 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4664 +{
4665 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4666 +}
4667 +
4668 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4669 +       int (*filter)(struct dentry *))
4670 +{
4671 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4672 +}
4673 +
4674 +
4675  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4676  {
4677         return -EISDIR;
4678 @@ -841,6 +856,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4679  EXPORT_SYMBOL(dcache_dir_lseek);
4680  EXPORT_SYMBOL(dcache_dir_open);
4681  EXPORT_SYMBOL(dcache_readdir);
4682 +EXPORT_SYMBOL(dcache_readdir_filter);
4683  EXPORT_SYMBOL(generic_read_dir);
4684  EXPORT_SYMBOL(get_sb_pseudo);
4685  EXPORT_SYMBOL(simple_write_begin);
4686 diff -NurpP --minimal linux-2.6.32.10/fs/locks.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/locks.c
4687 --- linux-2.6.32.10/fs/locks.c  2009-12-03 20:02:52.000000000 +0100
4688 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/locks.c  2009-12-03 20:04:56.000000000 +0100
4689 @@ -127,6 +127,8 @@
4690  #include <linux/time.h>
4691  #include <linux/rcupdate.h>
4692  #include <linux/pid_namespace.h>
4693 +#include <linux/vs_base.h>
4694 +#include <linux/vs_limit.h>
4695  
4696  #include <asm/uaccess.h>
4697  
4698 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4699  /* Allocate an empty lock structure. */
4700  static struct file_lock *locks_alloc_lock(void)
4701  {
4702 +       if (!vx_locks_avail(1))
4703 +               return NULL;
4704         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4705  }
4706  
4707 @@ -174,6 +178,7 @@ static void locks_free_lock(struct file_
4708         BUG_ON(!list_empty(&fl->fl_block));
4709         BUG_ON(!list_empty(&fl->fl_link));
4710  
4711 +       vx_locks_dec(fl);
4712         locks_release_private(fl);
4713         kmem_cache_free(filelock_cache, fl);
4714  }
4715 @@ -194,6 +199,7 @@ void locks_init_lock(struct file_lock *f
4716         fl->fl_start = fl->fl_end = 0;
4717         fl->fl_ops = NULL;
4718         fl->fl_lmops = NULL;
4719 +       fl->fl_xid = -1;
4720  }
4721  
4722  EXPORT_SYMBOL(locks_init_lock);
4723 @@ -248,6 +254,7 @@ void locks_copy_lock(struct file_lock *n
4724         new->fl_file = fl->fl_file;
4725         new->fl_ops = fl->fl_ops;
4726         new->fl_lmops = fl->fl_lmops;
4727 +       new->fl_xid = fl->fl_xid;
4728  
4729         locks_copy_private(new, fl);
4730  }
4731 @@ -286,6 +293,11 @@ static int flock_make_lock(struct file *
4732         fl->fl_flags = FL_FLOCK;
4733         fl->fl_type = type;
4734         fl->fl_end = OFFSET_MAX;
4735 +
4736 +       vxd_assert(filp->f_xid == vx_current_xid(),
4737 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4738 +       fl->fl_xid = filp->f_xid;
4739 +       vx_locks_inc(fl);
4740         
4741         *lock = fl;
4742         return 0;
4743 @@ -451,6 +463,7 @@ static int lease_init(struct file *filp,
4744  
4745         fl->fl_owner = current->files;
4746         fl->fl_pid = current->tgid;
4747 +       fl->fl_xid = vx_current_xid();
4748  
4749         fl->fl_file = filp;
4750         fl->fl_flags = FL_LEASE;
4751 @@ -470,6 +483,11 @@ static struct file_lock *lease_alloc(str
4752         if (fl == NULL)
4753                 return ERR_PTR(error);
4754  
4755 +       fl->fl_xid = vx_current_xid();
4756 +       if (filp)
4757 +               vxd_assert(filp->f_xid == fl->fl_xid,
4758 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4759 +       vx_locks_inc(fl);
4760         error = lease_init(filp, type, fl);
4761         if (error) {
4762                 locks_free_lock(fl);
4763 @@ -770,6 +788,7 @@ static int flock_lock_file(struct file *
4764         if (found)
4765                 cond_resched();
4766  
4767 +       new_fl->fl_xid = -1;
4768  find_conflict:
4769         for_each_lock(inode, before) {
4770                 struct file_lock *fl = *before;
4771 @@ -790,6 +809,7 @@ find_conflict:
4772                 goto out;
4773         locks_copy_lock(new_fl, request);
4774         locks_insert_lock(before, new_fl);
4775 +       vx_locks_inc(new_fl);
4776         new_fl = NULL;
4777         error = 0;
4778  
4779 @@ -800,7 +820,8 @@ out:
4780         return error;
4781  }
4782  
4783 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4784 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4785 +       struct file_lock *conflock, xid_t xid)
4786  {
4787         struct file_lock *fl;
4788         struct file_lock *new_fl = NULL;
4789 @@ -810,6 +831,8 @@ static int __posix_lock_file(struct inod
4790         struct file_lock **before;
4791         int error, added = 0;
4792  
4793 +       vxd_assert(xid == vx_current_xid(),
4794 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4795         /*
4796          * We may need two file_lock structures for this operation,
4797          * so we get them in advance to avoid races.
4798 @@ -820,7 +843,11 @@ static int __posix_lock_file(struct inod
4799             (request->fl_type != F_UNLCK ||
4800              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4801                 new_fl = locks_alloc_lock();
4802 +               new_fl->fl_xid = xid;
4803 +               vx_locks_inc(new_fl);
4804                 new_fl2 = locks_alloc_lock();
4805 +               new_fl2->fl_xid = xid;
4806 +               vx_locks_inc(new_fl2);
4807         }
4808  
4809         lock_kernel();
4810 @@ -1019,7 +1046,8 @@ static int __posix_lock_file(struct inod
4811  int posix_lock_file(struct file *filp, struct file_lock *fl,
4812                         struct file_lock *conflock)
4813  {
4814 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4815 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4816 +               fl, conflock, filp->f_xid);
4817  }
4818  EXPORT_SYMBOL(posix_lock_file);
4819  
4820 @@ -1109,7 +1137,7 @@ int locks_mandatory_area(int read_write,
4821         fl.fl_end = offset + count - 1;
4822  
4823         for (;;) {
4824 -               error = __posix_lock_file(inode, &fl, NULL);
4825 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4826                 if (error != FILE_LOCK_DEFERRED)
4827                         break;
4828                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4829 @@ -1424,6 +1452,7 @@ int generic_setlease(struct file *filp, 
4830  
4831         locks_copy_lock(new_fl, lease);
4832         locks_insert_lock(before, new_fl);
4833 +       vx_locks_inc(new_fl);
4834  
4835         *flp = new_fl;
4836         return 0;
4837 @@ -1779,6 +1808,11 @@ int fcntl_setlk(unsigned int fd, struct 
4838         if (file_lock == NULL)
4839                 return -ENOLCK;
4840  
4841 +       vxd_assert(filp->f_xid == vx_current_xid(),
4842 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4843 +       file_lock->fl_xid = filp->f_xid;
4844 +       vx_locks_inc(file_lock);
4845 +
4846         /*
4847          * This might block, so we do it before checking the inode.
4848          */
4849 @@ -1897,6 +1931,11 @@ int fcntl_setlk64(unsigned int fd, struc
4850         if (file_lock == NULL)
4851                 return -ENOLCK;
4852  
4853 +       vxd_assert(filp->f_xid == vx_current_xid(),
4854 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4855 +       file_lock->fl_xid = filp->f_xid;
4856 +       vx_locks_inc(file_lock);
4857 +
4858         /*
4859          * This might block, so we do it before checking the inode.
4860          */
4861 @@ -2162,8 +2201,11 @@ static int locks_show(struct seq_file *f
4862  
4863         lock_get_status(f, fl, (long)f->private, "");
4864  
4865 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4866 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4867 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4868 +                       continue;
4869                 lock_get_status(f, bfl, (long)f->private, " ->");
4870 +       }
4871  
4872         f->private++;
4873         return 0;
4874 diff -NurpP --minimal linux-2.6.32.10/fs/namei.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/namei.c
4875 --- linux-2.6.32.10/fs/namei.c  2010-03-18 16:17:36.000000000 +0100
4876 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/namei.c  2010-03-18 16:53:06.000000000 +0100
4877 @@ -33,6 +33,14 @@
4878  #include <linux/fcntl.h>
4879  #include <linux/device_cgroup.h>
4880  #include <linux/fs_struct.h>
4881 +#include <linux/proc_fs.h>
4882 +#include <linux/vserver/inode.h>
4883 +#include <linux/vs_base.h>
4884 +#include <linux/vs_tag.h>
4885 +#include <linux/vs_cowbl.h>
4886 +#include <linux/vs_device.h>
4887 +#include <linux/vs_context.h>
4888 +#include <linux/pid_namespace.h>
4889  #include <asm/uaccess.h>
4890  
4891  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
4892 @@ -169,6 +177,77 @@ void putname(const char *name)
4893  EXPORT_SYMBOL(putname);
4894  #endif
4895  
4896 +static inline int dx_barrier(const struct inode *inode)
4897 +{
4898 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4899 +               vxwprintk_task(1, "did hit the barrier.");
4900 +               return 1;
4901 +       }
4902 +       return 0;
4903 +}
4904 +
4905 +static int __dx_permission(const struct inode *inode, int mask)
4906 +{
4907 +       if (dx_barrier(inode))
4908 +               return -EACCES;
4909 +
4910 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4911 +               /* devpts is xid tagged */
4912 +               if (S_ISDIR(inode->i_mode) ||
4913 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4914 +                       return 0;
4915 +       }
4916 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4917 +               struct proc_dir_entry *de = PDE(inode);
4918 +
4919 +               if (de && !vx_hide_check(0, de->vx_flags))
4920 +                       goto out;
4921 +
4922 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4923 +                       struct pid *pid;
4924 +                       struct task_struct *tsk;
4925 +
4926 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4927 +                           vx_flags(VXF_STATE_SETUP, 0))
4928 +                               return 0;
4929 +
4930 +                       pid = PROC_I(inode)->pid;
4931 +                       if (!pid)
4932 +                               goto out;
4933 +
4934 +                       tsk = pid_task(pid, PIDTYPE_PID);
4935 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4936 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4937 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4938 +                               return 0;
4939 +               }
4940 +               else {
4941 +                       /* FIXME: Should we block some entries here? */
4942 +                       return 0;
4943 +               }
4944 +       }
4945 +       else {
4946 +               if (dx_notagcheck(inode->i_sb) ||
4947 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4948 +                            DX_IDENT))
4949 +                       return 0;
4950 +       }
4951 +
4952 +out:
4953 +       return -EACCES;
4954 +}
4955 +
4956 +int dx_permission(const struct inode *inode, int mask)
4957 +{
4958 +       int ret = __dx_permission(inode, mask);
4959 +       if (unlikely(ret)) {
4960 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4961 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4962 +                       inode->i_ino);
4963 +       }
4964 +       return ret;
4965 +}
4966 +
4967  /*
4968   * This does basic POSIX ACL permission checking
4969   */
4970 @@ -269,10 +348,14 @@ int inode_permission(struct inode *inode
4971                 /*
4972                  * Nobody gets write access to an immutable file.
4973                  */
4974 -               if (IS_IMMUTABLE(inode))
4975 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4976                         return -EACCES;
4977         }
4978  
4979 +       retval = dx_permission(inode, mask);
4980 +       if (retval)
4981 +               return retval;
4982 +
4983         if (inode->i_op->permission)
4984                 retval = inode->i_op->permission(inode, mask);
4985         else
4986 @@ -448,6 +531,9 @@ static int exec_permission_lite(struct i
4987  {
4988         int ret;
4989  
4990 +       if (dx_barrier(inode))
4991 +               return -EACCES;
4992 +
4993         if (inode->i_op->permission) {
4994                 ret = inode->i_op->permission(inode, MAY_EXEC);
4995                 if (!ret)
4996 @@ -763,7 +849,8 @@ static __always_inline void follow_dotdo
4997  
4998                 if (nd->path.dentry == nd->root.dentry &&
4999                     nd->path.mnt == nd->root.mnt) {
5000 -                       break;
5001 +                       /* for sane '/' avoid follow_mount() */
5002 +                       return;
5003                 }
5004                 spin_lock(&dcache_lock);
5005                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5006 @@ -799,16 +886,30 @@ static int do_lookup(struct nameidata *n
5007  {
5008         struct vfsmount *mnt = nd->path.mnt;
5009         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
5010 +       struct inode *inode;
5011  
5012         if (!dentry)
5013                 goto need_lookup;
5014         if (dentry->d_op && dentry->d_op->d_revalidate)
5015                 goto need_revalidate;
5016 +       inode = dentry->d_inode;
5017 +       if (!inode)
5018 +               goto done;
5019 +
5020 +       if (__dx_permission(inode, MAY_ACCESS))
5021 +               goto hidden;
5022 +
5023  done:
5024         path->mnt = mnt;
5025         path->dentry = dentry;
5026         __follow_mount(path);
5027         return 0;
5028 +hidden:
5029 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s/%.*s«.",
5030 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5031 +               vxd_path(&nd->path), name->len, name->name);
5032 +       dput(dentry);
5033 +       return -ENOENT;
5034  
5035  need_lookup:
5036         dentry = real_lookup(nd->path.dentry, name, nd);
5037 @@ -1400,7 +1501,7 @@ static int may_delete(struct inode *dir,
5038         if (IS_APPEND(dir))
5039                 return -EPERM;
5040         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5041 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5042 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5043                 return -EPERM;
5044         if (isdir) {
5045                 if (!S_ISDIR(victim->d_inode->i_mode))
5046 @@ -1540,6 +1641,14 @@ int may_open(struct path *path, int acc_
5047                 break;
5048         }
5049  
5050 +#ifdef CONFIG_VSERVER_COWBL
5051 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5052 +               if (IS_COW_LINK(inode))
5053 +                       return -EMLINK;
5054 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5055 +               mark_inode_dirty(inode);
5056 +       }
5057 +#endif
5058         error = inode_permission(inode, acc_mode);
5059         if (error)
5060                 return error;
5061 @@ -1688,7 +1797,11 @@ struct file *do_filp_open(int dfd, const
5062         int count = 0;
5063         int will_write;
5064         int flag = open_to_namei_flags(open_flag);
5065 -
5066 +#ifdef CONFIG_VSERVER_COWBL
5067 +       int rflag = flag;
5068 +       int rmode = mode;
5069 +restart:
5070 +#endif
5071         if (!acc_mode)
5072                 acc_mode = MAY_OPEN | ACC_MODE(flag);
5073  
5074 @@ -1836,6 +1949,25 @@ ok:
5075                         goto exit;
5076         }
5077         error = may_open(&nd.path, acc_mode, flag);
5078 +#ifdef CONFIG_VSERVER_COWBL
5079 +       if (error == -EMLINK) {
5080 +               struct dentry *dentry;
5081 +               dentry = cow_break_link(pathname);
5082 +               if (IS_ERR(dentry)) {
5083 +                       error = PTR_ERR(dentry);
5084 +                       goto exit_cow;
5085 +               }
5086 +               dput(dentry);
5087 +               if (will_write)
5088 +                       mnt_drop_write(nd.path.mnt);
5089 +               release_open_intent(&nd);
5090 +               path_put(&nd.path);
5091 +               flag = rflag;
5092 +               mode = rmode;
5093 +               goto restart;
5094 +       }
5095 +exit_cow:
5096 +#endif
5097         if (error) {
5098                 if (will_write)
5099                         mnt_drop_write(nd.path.mnt);
5100 @@ -1998,9 +2130,17 @@ int vfs_mknod(struct inode *dir, struct 
5101         if (error)
5102                 return error;
5103  
5104 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5105 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5106 +               goto okay;
5107 +
5108 +       if (!capable(CAP_MKNOD))
5109                 return -EPERM;
5110  
5111 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5112 +               return -EPERM;
5113 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5114 +               return -EPERM;
5115 +okay:
5116         if (!dir->i_op->mknod)
5117                 return -EPERM;
5118  
5119 @@ -2467,7 +2607,7 @@ int vfs_link(struct dentry *old_dentry, 
5120         /*
5121          * A link to an append-only or immutable file cannot be created.
5122          */
5123 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5124 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5125                 return -EPERM;
5126         if (!dir->i_op->link)
5127                 return -EPERM;
5128 @@ -2840,6 +2980,219 @@ int vfs_follow_link(struct nameidata *nd
5129         return __vfs_follow_link(nd, link);
5130  }
5131  
5132 +
5133 +#ifdef CONFIG_VSERVER_COWBL
5134 +
5135 +#include <linux/file.h>
5136 +
5137 +static inline
5138 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5139 +{
5140 +       loff_t ppos = 0;
5141 +
5142 +       return do_splice_direct(in, &ppos, out, len, 0);
5143 +}
5144 +
5145 +struct dentry *cow_break_link(const char *pathname)
5146 +{
5147 +       int ret, mode, pathlen, redo = 0;
5148 +       struct nameidata old_nd, dir_nd;
5149 +       struct path old_path, new_path;
5150 +       struct dentry *dir, *res = NULL;
5151 +       struct file *old_file;
5152 +       struct file *new_file;
5153 +       char *to, *path, pad='\251';
5154 +       loff_t size;
5155 +
5156 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5157 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5158 +       ret = -ENOMEM;
5159 +       if (!path)
5160 +               goto out;
5161 +
5162 +       /* old_nd will have refs to dentry and mnt */
5163 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5164 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5165 +       if (ret < 0)
5166 +               goto out_free_path;
5167 +
5168 +       old_path = old_nd.path;
5169 +       mode = old_path.dentry->d_inode->i_mode;
5170 +
5171 +       to = d_path(&old_path, path, PATH_MAX-2);
5172 +       pathlen = strlen(to);
5173 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5174 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5175 +               old_path.dentry->d_name.len);
5176 +
5177 +       to[pathlen + 1] = 0;
5178 +retry:
5179 +       to[pathlen] = pad--;
5180 +       ret = -EMLINK;
5181 +       if (pad <= '\240')
5182 +               goto out_rel_old;
5183 +
5184 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5185 +       /* dir_nd will have refs to dentry and mnt */
5186 +       ret = path_lookup(to,
5187 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5188 +       vxdprintk(VXD_CBIT(misc, 2),
5189 +               "path_lookup(new): %d", ret);
5190 +       if (ret < 0)
5191 +               goto retry;
5192 +
5193 +       /* this puppy downs the inode mutex */
5194 +       new_path.dentry = lookup_create(&dir_nd, 0);
5195 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5196 +               vxdprintk(VXD_CBIT(misc, 2),
5197 +                       "lookup_create(new): %p", new_path.dentry);
5198 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5199 +               path_put(&dir_nd.path);
5200 +               goto retry;
5201 +       }
5202 +       vxdprintk(VXD_CBIT(misc, 2),
5203 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5204 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5205 +               new_path.dentry->d_name.len);
5206 +       dir = dir_nd.path.dentry;
5207 +
5208 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5209 +       vxdprintk(VXD_CBIT(misc, 2),
5210 +               "vfs_create(new): %d", ret);
5211 +       if (ret == -EEXIST) {
5212 +               mutex_unlock(&dir->d_inode->i_mutex);
5213 +               dput(new_path.dentry);
5214 +               path_put(&dir_nd.path);
5215 +               goto retry;
5216 +       }
5217 +       else if (ret < 0)
5218 +               goto out_unlock_new;
5219 +
5220 +       /* drop out early, ret passes ENOENT */
5221 +       ret = -ENOENT;
5222 +       if ((redo = d_unhashed(old_path.dentry)))
5223 +               goto out_unlock_new;
5224 +
5225 +       new_path.mnt = dir_nd.path.mnt;
5226 +       dget(old_path.dentry);
5227 +       mntget(old_path.mnt);
5228 +       /* this one cleans up the dentry/mnt in case of failure */
5229 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5230 +               O_RDONLY, current_cred());
5231 +       vxdprintk(VXD_CBIT(misc, 2),
5232 +               "dentry_open(old): %p", old_file);
5233 +       if (!old_file || IS_ERR(old_file)) {
5234 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5235 +               goto out_unlock_new;
5236 +       }
5237 +
5238 +       dget(new_path.dentry);
5239 +       mntget(new_path.mnt);
5240 +       /* this one cleans up the dentry/mnt in case of failure */
5241 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5242 +               O_WRONLY, current_cred());
5243 +       vxdprintk(VXD_CBIT(misc, 2),
5244 +               "dentry_open(new): %p", new_file);
5245 +
5246 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5247 +       if (!new_file || IS_ERR(new_file))
5248 +               goto out_fput_old;
5249 +
5250 +       size = i_size_read(old_file->f_dentry->d_inode);
5251 +       ret = do_cow_splice(old_file, new_file, size);
5252 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5253 +       if (ret < 0) {
5254 +               goto out_fput_both;
5255 +       } else if (ret < size) {
5256 +               ret = -ENOSPC;
5257 +               goto out_fput_both;
5258 +       } else {
5259 +               struct inode *old_inode = old_path.dentry->d_inode;
5260 +               struct inode *new_inode = new_path.dentry->d_inode;
5261 +               struct iattr attr = {
5262 +                       .ia_uid = old_inode->i_uid,
5263 +                       .ia_gid = old_inode->i_gid,
5264 +                       .ia_valid = ATTR_UID | ATTR_GID
5265 +                       };
5266 +
5267 +               ret = inode_setattr(new_inode, &attr);
5268 +               if (ret)
5269 +                       goto out_fput_both;
5270 +       }
5271 +
5272 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5273 +
5274 +       /* drop out late */
5275 +       ret = -ENOENT;
5276 +       if ((redo = d_unhashed(old_path.dentry)))
5277 +               goto out_unlock;
5278 +
5279 +       vxdprintk(VXD_CBIT(misc, 2),
5280 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5281 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5282 +               new_path.dentry->d_name.len,
5283 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5284 +               old_path.dentry->d_name.len);
5285 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5286 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5287 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5288 +       res = new_path.dentry;
5289 +
5290 +out_unlock:
5291 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5292 +
5293 +out_fput_both:
5294 +       vxdprintk(VXD_CBIT(misc, 3),
5295 +               "fput(new_file=%p[#%ld])", new_file,
5296 +               atomic_long_read(&new_file->f_count));
5297 +       fput(new_file);
5298 +
5299 +out_fput_old:
5300 +       vxdprintk(VXD_CBIT(misc, 3),
5301 +               "fput(old_file=%p[#%ld])", old_file,
5302 +               atomic_long_read(&old_file->f_count));
5303 +       fput(old_file);
5304 +
5305 +out_unlock_new:
5306 +       mutex_unlock(&dir->d_inode->i_mutex);
5307 +       if (!ret)
5308 +               goto out_redo;
5309 +
5310 +       /* error path cleanup */
5311 +       vfs_unlink(dir->d_inode, new_path.dentry);
5312 +       dput(new_path.dentry);
5313 +
5314 +out_redo:
5315 +       if (!redo)
5316 +               goto out_rel_both;
5317 +       /* lookup dentry once again */
5318 +       path_put(&old_nd.path);
5319 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5320 +       if (ret)
5321 +               goto out_rel_both;
5322 +
5323 +       new_path.dentry = old_nd.path.dentry;
5324 +       vxdprintk(VXD_CBIT(misc, 2),
5325 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5326 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5327 +               new_path.dentry->d_name.len);
5328 +       dget(new_path.dentry);
5329 +       res = new_path.dentry;
5330 +
5331 +out_rel_both:
5332 +       path_put(&dir_nd.path);
5333 +out_rel_old:
5334 +       path_put(&old_nd.path);
5335 +out_free_path:
5336 +       kfree(path);
5337 +out:
5338 +       if (ret)
5339 +               res = ERR_PTR(ret);
5340 +       return res;
5341 +}
5342 +
5343 +#endif
5344 +
5345  /* get the link contents into pagecache */
5346  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5347  {
5348 diff -NurpP --minimal linux-2.6.32.10/fs/namespace.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/namespace.c
5349 --- linux-2.6.32.10/fs/namespace.c      2009-12-03 20:02:52.000000000 +0100
5350 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/namespace.c      2009-12-03 20:04:56.000000000 +0100
5351 @@ -29,6 +29,11 @@
5352  #include <linux/log2.h>
5353  #include <linux/idr.h>
5354  #include <linux/fs_struct.h>
5355 +#include <linux/vs_base.h>
5356 +#include <linux/vs_context.h>
5357 +#include <linux/vs_tag.h>
5358 +#include <linux/vserver/space.h>
5359 +#include <linux/vserver/global.h>
5360  #include <asm/uaccess.h>
5361  #include <asm/unistd.h>
5362  #include "pnode.h"
5363 @@ -567,6 +572,7 @@ static struct vfsmount *clone_mnt(struct
5364                 mnt->mnt_root = dget(root);
5365                 mnt->mnt_mountpoint = mnt->mnt_root;
5366                 mnt->mnt_parent = mnt;
5367 +               mnt->mnt_tag = old->mnt_tag;
5368  
5369                 if (flag & CL_SLAVE) {
5370                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5371 @@ -661,6 +667,31 @@ static inline void mangle(struct seq_fil
5372         seq_escape(m, s, " \t\n\\");
5373  }
5374  
5375 +static int mnt_is_reachable(struct vfsmount *mnt)
5376 +{
5377 +       struct path root;
5378 +       struct dentry *point;
5379 +       int ret;
5380 +
5381 +       if (mnt == mnt->mnt_ns->root)
5382 +               return 1;
5383 +
5384 +       spin_lock(&vfsmount_lock);
5385 +       root = current->fs->root;
5386 +       point = root.dentry;
5387 +
5388 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5389 +               point = mnt->mnt_mountpoint;
5390 +               mnt = mnt->mnt_parent;
5391 +       }
5392 +
5393 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5394 +
5395 +       spin_unlock(&vfsmount_lock);
5396 +
5397 +       return ret;
5398 +}
5399 +
5400  /*
5401   * Simple .show_options callback for filesystems which don't want to
5402   * implement more complex mount option showing.
5403 @@ -748,6 +779,8 @@ static int show_sb_opts(struct seq_file 
5404                 { MS_SYNCHRONOUS, ",sync" },
5405                 { MS_DIRSYNC, ",dirsync" },
5406                 { MS_MANDLOCK, ",mand" },
5407 +               { MS_TAGGED, ",tag" },
5408 +               { MS_NOTAGCHECK, ",notagcheck" },
5409                 { 0, NULL }
5410         };
5411         const struct proc_fs_info *fs_infop;
5412 @@ -795,10 +828,20 @@ static int show_vfsmnt(struct seq_file *
5413         int err = 0;
5414         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5415  
5416 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5417 -       seq_putc(m, ' ');
5418 -       seq_path(m, &mnt_path, " \t\n\\");
5419 -       seq_putc(m, ' ');
5420 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5421 +               return SEQ_SKIP;
5422 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5423 +               return SEQ_SKIP;
5424 +
5425 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5426 +               mnt == current->fs->root.mnt) {
5427 +               seq_puts(m, "/dev/root / ");
5428 +       } else {
5429 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5430 +               seq_putc(m, ' ');
5431 +               seq_path(m, &mnt_path, " \t\n\\");
5432 +               seq_putc(m, ' ');
5433 +       }
5434         show_type(m, mnt->mnt_sb);
5435         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5436         err = show_sb_opts(m, mnt->mnt_sb);
5437 @@ -828,6 +871,11 @@ static int show_mountinfo(struct seq_fil
5438         struct path root = p->root;
5439         int err = 0;
5440  
5441 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5442 +               return SEQ_SKIP;
5443 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5444 +               return SEQ_SKIP;
5445 +
5446         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5447                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5448         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5449 @@ -886,17 +934,27 @@ static int show_vfsstat(struct seq_file 
5450         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5451         int err = 0;
5452  
5453 -       /* device */
5454 -       if (mnt->mnt_devname) {
5455 -               seq_puts(m, "device ");
5456 -               mangle(m, mnt->mnt_devname);
5457 -       } else
5458 -               seq_puts(m, "no device");
5459 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5460 +               return SEQ_SKIP;
5461 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5462 +               return SEQ_SKIP;
5463  
5464 -       /* mount point */
5465 -       seq_puts(m, " mounted on ");
5466 -       seq_path(m, &mnt_path, " \t\n\\");
5467 -       seq_putc(m, ' ');
5468 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5469 +               mnt == current->fs->root.mnt) {
5470 +               seq_puts(m, "device /dev/root mounted on / ");
5471 +       } else {
5472 +               /* device */
5473 +               if (mnt->mnt_devname) {
5474 +                       seq_puts(m, "device ");
5475 +                       mangle(m, mnt->mnt_devname);
5476 +               } else
5477 +                       seq_puts(m, "no device");
5478 +
5479 +               /* mount point */
5480 +               seq_puts(m, " mounted on ");
5481 +               seq_path(m, &mnt_path, " \t\n\\");
5482 +               seq_putc(m, ' ');
5483 +       }
5484  
5485         /* file system type */
5486         seq_puts(m, "with fstype ");
5487 @@ -1130,7 +1188,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5488                 goto dput_and_out;
5489  
5490         retval = -EPERM;
5491 -       if (!capable(CAP_SYS_ADMIN))
5492 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5493                 goto dput_and_out;
5494  
5495         retval = do_umount(path.mnt, flags);
5496 @@ -1156,7 +1214,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5497  
5498  static int mount_is_safe(struct path *path)
5499  {
5500 -       if (capable(CAP_SYS_ADMIN))
5501 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5502                 return 0;
5503         return -EPERM;
5504  #ifdef notyet
5505 @@ -1420,7 +1478,7 @@ static int do_change_type(struct path *p
5506         int type = flag & ~MS_REC;
5507         int err = 0;
5508  
5509 -       if (!capable(CAP_SYS_ADMIN))
5510 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5511                 return -EPERM;
5512  
5513         if (path->dentry != path->mnt->mnt_root)
5514 @@ -1447,11 +1505,13 @@ static int do_change_type(struct path *p
5515   * do loopback mount.
5516   */
5517  static int do_loopback(struct path *path, char *old_name,
5518 -                               int recurse)
5519 +       tag_t tag, unsigned long flags, int mnt_flags)
5520  {
5521         struct path old_path;
5522         struct vfsmount *mnt = NULL;
5523         int err = mount_is_safe(path);
5524 +       int recurse = flags & MS_REC;
5525 +
5526         if (err)
5527                 return err;
5528         if (!old_name || !*old_name)
5529 @@ -1485,6 +1545,7 @@ static int do_loopback(struct path *path
5530                 spin_unlock(&vfsmount_lock);
5531                 release_mounts(&umount_list);
5532         }
5533 +       mnt->mnt_flags = mnt_flags;
5534  
5535  out:
5536         up_write(&namespace_sem);
5537 @@ -1515,12 +1576,12 @@ static int change_mount_flags(struct vfs
5538   * on it - tough luck.
5539   */
5540  static int do_remount(struct path *path, int flags, int mnt_flags,
5541 -                     void *data)
5542 +       void *data, xid_t xid)
5543  {
5544         int err;
5545         struct super_block *sb = path->mnt->mnt_sb;
5546  
5547 -       if (!capable(CAP_SYS_ADMIN))
5548 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5549                 return -EPERM;
5550  
5551         if (!check_mnt(path->mnt))
5552 @@ -1562,7 +1623,7 @@ static int do_move_mount(struct path *pa
5553         struct path old_path, parent_path;
5554         struct vfsmount *p;
5555         int err = 0;
5556 -       if (!capable(CAP_SYS_ADMIN))
5557 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5558                 return -EPERM;
5559         if (!old_name || !*old_name)
5560                 return -EINVAL;
5561 @@ -1644,7 +1705,7 @@ static int do_new_mount(struct path *pat
5562                 return -EINVAL;
5563  
5564         /* we need capabilities... */
5565 -       if (!capable(CAP_SYS_ADMIN))
5566 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5567                 return -EPERM;
5568  
5569         lock_kernel();
5570 @@ -1908,6 +1969,7 @@ long do_mount(char *dev_name, char *dir_
5571         struct path path;
5572         int retval = 0;
5573         int mnt_flags = 0;
5574 +       tag_t tag = 0;
5575  
5576         /* Discard magic */
5577         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5578 @@ -1925,6 +1987,12 @@ long do_mount(char *dev_name, char *dir_
5579         if (!(flags & MS_NOATIME))
5580                 mnt_flags |= MNT_RELATIME;
5581  
5582 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5583 +               /* FIXME: bind and re-mounts get the tag flag? */
5584 +               if (flags & (MS_BIND|MS_REMOUNT))
5585 +                       flags |= MS_TAGID;
5586 +       }
5587 +
5588         /* Separate the per-mountpoint flags */
5589         if (flags & MS_NOSUID)
5590                 mnt_flags |= MNT_NOSUID;
5591 @@ -1941,6 +2009,8 @@ long do_mount(char *dev_name, char *dir_
5592         if (flags & MS_RDONLY)
5593                 mnt_flags |= MNT_READONLY;
5594  
5595 +       if (!capable(CAP_SYS_ADMIN))
5596 +               mnt_flags |= MNT_NODEV;
5597         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5598                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5599                    MS_STRICTATIME);
5600 @@ -1957,9 +2027,9 @@ long do_mount(char *dev_name, char *dir_
5601  
5602         if (flags & MS_REMOUNT)
5603                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5604 -                                   data_page);
5605 +                                   data_page, tag);
5606         else if (flags & MS_BIND)
5607 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5608 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5609         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5610                 retval = do_change_type(&path, flags);
5611         else if (flags & MS_MOVE)
5612 @@ -2038,6 +2108,7 @@ static struct mnt_namespace *dup_mnt_ns(
5613                 q = next_mnt(q, new_ns->root);
5614         }
5615         up_write(&namespace_sem);
5616 +       atomic_inc(&vs_global_mnt_ns);
5617  
5618         if (rootmnt)
5619                 mntput(rootmnt);
5620 @@ -2182,9 +2253,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5621         down_write(&namespace_sem);
5622         mutex_lock(&old.dentry->d_inode->i_mutex);
5623         error = -EINVAL;
5624 -       if (IS_MNT_SHARED(old.mnt) ||
5625 +       if ((IS_MNT_SHARED(old.mnt) ||
5626                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5627 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5628 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5629 +               !vx_flags(VXF_STATE_SETUP, 0))
5630                 goto out2;
5631         if (!check_mnt(root.mnt))
5632                 goto out2;
5633 @@ -2320,6 +2392,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5634         spin_unlock(&vfsmount_lock);
5635         up_write(&namespace_sem);
5636         release_mounts(&umount_list);
5637 +       atomic_dec(&vs_global_mnt_ns);
5638         kfree(ns);
5639  }
5640  EXPORT_SYMBOL(put_mnt_ns);
5641 diff -NurpP --minimal linux-2.6.32.10/fs/nfs/client.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/client.c
5642 --- linux-2.6.32.10/fs/nfs/client.c     2009-12-03 20:02:52.000000000 +0100
5643 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/client.c     2009-12-03 20:04:56.000000000 +0100
5644 @@ -738,6 +738,9 @@ static int nfs_init_server_rpcclient(str
5645         if (server->flags & NFS_MOUNT_SOFT)
5646                 server->client->cl_softrtry = 1;
5647  
5648 +       server->client->cl_tag = 0;
5649 +       if (server->flags & NFS_MOUNT_TAGGED)
5650 +               server->client->cl_tag = 1;
5651         return 0;
5652  }
5653  
5654 @@ -909,6 +912,10 @@ static void nfs_server_set_fsinfo(struct
5655                 server->acdirmin = server->acdirmax = 0;
5656         }
5657  
5658 +       /* FIXME: needs fsinfo
5659 +       if (server->flags & NFS_MOUNT_TAGGED)
5660 +               sb->s_flags |= MS_TAGGED;       */
5661 +
5662         server->maxfilesize = fsinfo->maxfilesize;
5663  
5664         /* We're airborne Set socket buffersize */
5665 diff -NurpP --minimal linux-2.6.32.10/fs/nfs/dir.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/dir.c
5666 --- linux-2.6.32.10/fs/nfs/dir.c        2009-12-03 20:02:52.000000000 +0100
5667 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/dir.c        2009-12-03 20:04:56.000000000 +0100
5668 @@ -33,6 +33,7 @@
5669  #include <linux/namei.h>
5670  #include <linux/mount.h>
5671  #include <linux/sched.h>
5672 +#include <linux/vs_tag.h>
5673  
5674  #include "nfs4_fs.h"
5675  #include "delegation.h"
5676 @@ -949,6 +950,7 @@ static struct dentry *nfs_lookup(struct 
5677         if (IS_ERR(res))
5678                 goto out_unblock_sillyrename;
5679  
5680 +       dx_propagate_tag(nd, inode);
5681  no_entry:
5682         res = d_materialise_unique(dentry, inode);
5683         if (res != NULL) {
5684 diff -NurpP --minimal linux-2.6.32.10/fs/nfs/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/inode.c
5685 --- linux-2.6.32.10/fs/nfs/inode.c      2009-12-03 20:02:52.000000000 +0100
5686 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/inode.c      2009-12-03 20:04:56.000000000 +0100
5687 @@ -36,6 +36,7 @@
5688  #include <linux/vfs.h>
5689  #include <linux/inet.h>
5690  #include <linux/nfs_xdr.h>
5691 +#include <linux/vs_tag.h>
5692  
5693  #include <asm/system.h>
5694  #include <asm/uaccess.h>
5695 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5696         if (inode->i_state & I_NEW) {
5697                 struct nfs_inode *nfsi = NFS_I(inode);
5698                 unsigned long now = jiffies;
5699 +               uid_t uid;
5700 +               gid_t gid;
5701  
5702                 /* We set i_ino for the few things that still rely on it,
5703                  * such as stat(2) */
5704 @@ -327,8 +330,8 @@ nfs_fhget(struct super_block *sb, struct
5705                 nfsi->change_attr = 0;
5706                 inode->i_size = 0;
5707                 inode->i_nlink = 0;
5708 -               inode->i_uid = -2;
5709 -               inode->i_gid = -2;
5710 +               uid = -2;
5711 +               gid = -2;
5712                 inode->i_blocks = 0;
5713                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5714  
5715 @@ -365,13 +368,13 @@ nfs_fhget(struct super_block *sb, struct
5716                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5717                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5718                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5719 -                       inode->i_uid = fattr->uid;
5720 +                       uid = fattr->uid;
5721                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5722                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5723                                 | NFS_INO_INVALID_ACCESS
5724                                 | NFS_INO_INVALID_ACL;
5725                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5726 -                       inode->i_gid = fattr->gid;
5727 +                       gid = fattr->gid;
5728                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5729                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5730                                 | NFS_INO_INVALID_ACCESS
5731 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5732                          */
5733                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5734                 }
5735 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5736 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5737 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5738 +                               /* maybe fattr->xid someday */
5739 +
5740                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5741                 nfsi->attrtimeo_timestamp = now;
5742                 nfsi->access_cache = RB_ROOT;
5743 @@ -496,6 +504,8 @@ void nfs_setattr_update_inode(struct ino
5744                         inode->i_uid = attr->ia_uid;
5745                 if ((attr->ia_valid & ATTR_GID) != 0)
5746                         inode->i_gid = attr->ia_gid;
5747 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5748 +                       inode->i_tag = attr->ia_tag;
5749                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5750                 spin_unlock(&inode->i_lock);
5751         }
5752 @@ -906,6 +916,9 @@ static int nfs_check_inode_attributes(st
5753         struct nfs_inode *nfsi = NFS_I(inode);
5754         loff_t cur_size, new_isize;
5755         unsigned long invalid = 0;
5756 +       uid_t uid;
5757 +       gid_t gid;
5758 +       tag_t tag;
5759  
5760  
5761         /* Has the inode gone and changed behind our back? */
5762 @@ -929,13 +942,18 @@ static int nfs_check_inode_attributes(st
5763                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5764         }
5765  
5766 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5767 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5768 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5769 +
5770         /* Have any file permissions changed? */
5771         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5772                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5773 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5774 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5775                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5776 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5777 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5778                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5779 +               /* maybe check for tag too? */
5780  
5781         /* Has the link count changed? */
5782         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5783 @@ -1150,6 +1168,9 @@ static int nfs_update_inode(struct inode
5784         unsigned long invalid = 0;
5785         unsigned long now = jiffies;
5786         unsigned long save_cache_validity;
5787 +       uid_t uid;
5788 +       gid_t gid;
5789 +       tag_t tag;
5790  
5791         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5792                         __func__, inode->i_sb->s_id, inode->i_ino,
5793 @@ -1252,6 +1273,9 @@ static int nfs_update_inode(struct inode
5794                                 | NFS_INO_REVAL_PAGECACHE
5795                                 | NFS_INO_REVAL_FORCED);
5796  
5797 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5798 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5799 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5800  
5801         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5802                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5803 @@ -1271,9 +1295,9 @@ static int nfs_update_inode(struct inode
5804                                 | NFS_INO_REVAL_FORCED);
5805  
5806         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5807 -               if (inode->i_uid != fattr->uid) {
5808 +               if (uid != fattr->uid) {
5809                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5810 -                       inode->i_uid = fattr->uid;
5811 +                       uid = fattr->uid;
5812                 }
5813         } else if (server->caps & NFS_CAP_OWNER)
5814                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5815 @@ -1282,9 +1306,9 @@ static int nfs_update_inode(struct inode
5816                                 | NFS_INO_REVAL_FORCED);
5817  
5818         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5819 -               if (inode->i_gid != fattr->gid) {
5820 +               if (gid != fattr->gid) {
5821                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5822 -                       inode->i_gid = fattr->gid;
5823 +                       gid = fattr->gid;
5824                 }
5825         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5826                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5827 @@ -1292,6 +1316,10 @@ static int nfs_update_inode(struct inode
5828                                 | NFS_INO_INVALID_ACL
5829                                 | NFS_INO_REVAL_FORCED);
5830  
5831 +       inode->i_uid = uid;
5832 +       inode->i_gid = gid;
5833 +       inode->i_tag = tag;
5834 +
5835         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5836                 if (inode->i_nlink != fattr->nlink) {
5837                         invalid |= NFS_INO_INVALID_ATTR;
5838 diff -NurpP --minimal linux-2.6.32.10/fs/nfs/nfs3xdr.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/nfs3xdr.c
5839 --- linux-2.6.32.10/fs/nfs/nfs3xdr.c    2009-12-03 20:02:52.000000000 +0100
5840 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/nfs3xdr.c    2009-12-03 20:04:56.000000000 +0100
5841 @@ -21,6 +21,7 @@
5842  #include <linux/nfs3.h>
5843  #include <linux/nfs_fs.h>
5844  #include <linux/nfsacl.h>
5845 +#include <linux/vs_tag.h>
5846  #include "internal.h"
5847  
5848  #define NFSDBG_FACILITY                NFSDBG_XDR
5849 @@ -176,7 +177,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5850  }
5851  
5852  static inline __be32 *
5853 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5854 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5855  {
5856         if (attr->ia_valid & ATTR_MODE) {
5857                 *p++ = xdr_one;
5858 @@ -184,15 +185,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5859         } else {
5860                 *p++ = xdr_zero;
5861         }
5862 -       if (attr->ia_valid & ATTR_UID) {
5863 +       if (attr->ia_valid & ATTR_UID ||
5864 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5865                 *p++ = xdr_one;
5866 -               *p++ = htonl(attr->ia_uid);
5867 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5868         } else {
5869                 *p++ = xdr_zero;
5870         }
5871 -       if (attr->ia_valid & ATTR_GID) {
5872 +       if (attr->ia_valid & ATTR_GID ||
5873 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5874                 *p++ = xdr_one;
5875 -               *p++ = htonl(attr->ia_gid);
5876 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5877         } else {
5878                 *p++ = xdr_zero;
5879         }
5880 @@ -279,7 +282,8 @@ static int
5881  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5882  {
5883         p = xdr_encode_fhandle(p, args->fh);
5884 -       p = xdr_encode_sattr(p, args->sattr);
5885 +       p = xdr_encode_sattr(p, args->sattr,
5886 +               req->rq_task->tk_client->cl_tag);
5887         *p++ = htonl(args->guard);
5888         if (args->guard)
5889                 p = xdr_encode_time3(p, &args->guardtime);
5890 @@ -384,7 +388,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5891                 *p++ = args->verifier[0];
5892                 *p++ = args->verifier[1];
5893         } else
5894 -               p = xdr_encode_sattr(p, args->sattr);
5895 +               p = xdr_encode_sattr(p, args->sattr,
5896 +                       req->rq_task->tk_client->cl_tag);
5897  
5898         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5899         return 0;
5900 @@ -398,7 +403,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5901  {
5902         p = xdr_encode_fhandle(p, args->fh);
5903         p = xdr_encode_array(p, args->name, args->len);
5904 -       p = xdr_encode_sattr(p, args->sattr);
5905 +       p = xdr_encode_sattr(p, args->sattr,
5906 +               req->rq_task->tk_client->cl_tag);
5907         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5908         return 0;
5909  }
5910 @@ -411,7 +417,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5911  {
5912         p = xdr_encode_fhandle(p, args->fromfh);
5913         p = xdr_encode_array(p, args->fromname, args->fromlen);
5914 -       p = xdr_encode_sattr(p, args->sattr);
5915 +       p = xdr_encode_sattr(p, args->sattr,
5916 +               req->rq_task->tk_client->cl_tag);
5917         *p++ = htonl(args->pathlen);
5918         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5919  
5920 @@ -429,7 +436,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5921         p = xdr_encode_fhandle(p, args->fh);
5922         p = xdr_encode_array(p, args->name, args->len);
5923         *p++ = htonl(args->type);
5924 -       p = xdr_encode_sattr(p, args->sattr);
5925 +       p = xdr_encode_sattr(p, args->sattr,
5926 +               req->rq_task->tk_client->cl_tag);
5927         if (args->type == NF3CHR || args->type == NF3BLK) {
5928                 *p++ = htonl(MAJOR(args->rdev));
5929                 *p++ = htonl(MINOR(args->rdev));
5930 diff -NurpP --minimal linux-2.6.32.10/fs/nfs/nfsroot.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/nfsroot.c
5931 --- linux-2.6.32.10/fs/nfs/nfsroot.c    2009-09-10 15:26:23.000000000 +0200
5932 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/nfsroot.c    2009-12-03 20:04:56.000000000 +0100
5933 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
5934  enum {
5935         /* Options that take integer arguments */
5936         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
5937 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
5938 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
5939         /* Options that take no arguments */
5940         Opt_soft, Opt_hard, Opt_intr,
5941         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
5942         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
5943 -       Opt_acl, Opt_noacl,
5944 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
5945         /* Error token */
5946         Opt_err
5947  };
5948 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
5949         {Opt_tcp, "tcp"},
5950         {Opt_acl, "acl"},
5951         {Opt_noacl, "noacl"},
5952 +       {Opt_tag, "tag"},
5953 +       {Opt_notag, "notag"},
5954 +       {Opt_tagid, "tagid=%u"},
5955         {Opt_err, NULL}
5956         
5957  };
5958 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
5959                         case Opt_noacl:
5960                                 nfs_data.flags |= NFS_MOUNT_NOACL;
5961                                 break;
5962 +#ifndef CONFIG_TAGGING_NONE
5963 +                       case Opt_tag:
5964 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5965 +                               break;
5966 +                       case Opt_notag:
5967 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
5968 +                               break;
5969 +#endif
5970 +#ifdef CONFIG_PROPAGATE
5971 +                       case Opt_tagid:
5972 +                               /* use args[0] */
5973 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5974 +                               break;
5975 +#endif
5976                         default:
5977                                 printk(KERN_WARNING "Root-NFS: unknown "
5978                                         "option: %s\n", p);
5979 diff -NurpP --minimal linux-2.6.32.10/fs/nfs/super.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/super.c
5980 --- linux-2.6.32.10/fs/nfs/super.c      2010-03-18 16:17:36.000000000 +0100
5981 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfs/super.c      2010-02-24 12:32:54.000000000 +0100
5982 @@ -53,6 +53,7 @@
5983  #include <linux/nfs_xdr.h>
5984  #include <linux/magic.h>
5985  #include <linux/parser.h>
5986 +#include <linux/vs_tag.h>
5987  
5988  #include <asm/system.h>
5989  #include <asm/uaccess.h>
5990 @@ -554,6 +555,7 @@ static void nfs_show_mount_options(struc
5991                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5992                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5993                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5994 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5995                 { 0, NULL, NULL }
5996         };
5997         const struct proc_nfs_info *nfs_infop;
5998 diff -NurpP --minimal linux-2.6.32.10/fs/nfsd/auth.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfsd/auth.c
5999 --- linux-2.6.32.10/fs/nfsd/auth.c      2009-12-03 20:02:52.000000000 +0100
6000 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfsd/auth.c      2009-12-03 20:04:56.000000000 +0100
6001 @@ -10,6 +10,7 @@
6002  #include <linux/sunrpc/svcauth.h>
6003  #include <linux/nfsd/nfsd.h>
6004  #include <linux/nfsd/export.h>
6005 +#include <linux/vs_tag.h>
6006  #include "auth.h"
6007  
6008  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
6009 @@ -44,6 +45,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6010  
6011         new->fsuid = rqstp->rq_cred.cr_uid;
6012         new->fsgid = rqstp->rq_cred.cr_gid;
6013 +       /* FIXME: this desperately needs a tag :)
6014 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6015 +                       */
6016  
6017         rqgi = rqstp->rq_cred.cr_group_info;
6018  
6019 diff -NurpP --minimal linux-2.6.32.10/fs/nfsd/nfs3xdr.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfsd/nfs3xdr.c
6020 --- linux-2.6.32.10/fs/nfsd/nfs3xdr.c   2009-12-03 20:02:52.000000000 +0100
6021 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfsd/nfs3xdr.c   2009-12-03 20:04:56.000000000 +0100
6022 @@ -21,6 +21,7 @@
6023  #include <linux/sunrpc/svc.h>
6024  #include <linux/nfsd/nfsd.h>
6025  #include <linux/nfsd/xdr3.h>
6026 +#include <linux/vs_tag.h>
6027  #include "auth.h"
6028  
6029  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6030 @@ -108,6 +109,8 @@ static __be32 *
6031  decode_sattr3(__be32 *p, struct iattr *iap)
6032  {
6033         u32     tmp;
6034 +       uid_t   uid = 0;
6035 +       gid_t   gid = 0;
6036  
6037         iap->ia_valid = 0;
6038  
6039 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6040         }
6041         if (*p++) {
6042                 iap->ia_valid |= ATTR_UID;
6043 -               iap->ia_uid = ntohl(*p++);
6044 +               uid = ntohl(*p++);
6045         }
6046         if (*p++) {
6047                 iap->ia_valid |= ATTR_GID;
6048 -               iap->ia_gid = ntohl(*p++);
6049 +               gid = ntohl(*p++);
6050         }
6051 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6052 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6053 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6054         if (*p++) {
6055                 u64     newsize;
6056  
6057 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6058         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6059         *p++ = htonl((u32) stat->mode);
6060         *p++ = htonl((u32) stat->nlink);
6061 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6062 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6063 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6064 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6065 +               stat->uid, stat->tag)));
6066 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6067 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6068 +               stat->gid, stat->tag)));
6069         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6070                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6071         } else {
6072 diff -NurpP --minimal linux-2.6.32.10/fs/nfsd/nfs4xdr.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfsd/nfs4xdr.c
6073 --- linux-2.6.32.10/fs/nfsd/nfs4xdr.c   2009-12-03 20:02:52.000000000 +0100
6074 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfsd/nfs4xdr.c   2009-12-03 20:04:56.000000000 +0100
6075 @@ -57,6 +57,7 @@
6076  #include <linux/nfs4_acl.h>
6077  #include <linux/sunrpc/gss_api.h>
6078  #include <linux/sunrpc/svcauth_gss.h>
6079 +#include <linux/vs_tag.h>
6080  
6081  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6082  
6083 @@ -2050,14 +2051,18 @@ out_acl:
6084                 WRITE32(stat.nlink);
6085         }
6086         if (bmval1 & FATTR4_WORD1_OWNER) {
6087 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6088 +               status = nfsd4_encode_user(rqstp,
6089 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6090 +                       stat.uid, stat.tag), &p, &buflen);
6091                 if (status == nfserr_resource)
6092                         goto out_resource;
6093                 if (status)
6094                         goto out;
6095         }
6096         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6097 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6098 +               status = nfsd4_encode_group(rqstp,
6099 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6100 +                       stat.gid, stat.tag), &p, &buflen);
6101                 if (status == nfserr_resource)
6102                         goto out_resource;
6103                 if (status)
6104 diff -NurpP --minimal linux-2.6.32.10/fs/nfsd/nfsxdr.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfsd/nfsxdr.c
6105 --- linux-2.6.32.10/fs/nfsd/nfsxdr.c    2008-12-25 00:26:37.000000000 +0100
6106 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/nfsd/nfsxdr.c    2009-12-03 20:04:56.000000000 +0100
6107 @@ -15,6 +15,7 @@
6108  #include <linux/nfsd/nfsd.h>
6109  #include <linux/nfsd/xdr.h>
6110  #include <linux/mm.h>
6111 +#include <linux/vs_tag.h>
6112  #include "auth.h"
6113  
6114  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6115 @@ -98,6 +99,8 @@ static __be32 *
6116  decode_sattr(__be32 *p, struct iattr *iap)
6117  {
6118         u32     tmp, tmp1;
6119 +       uid_t   uid = 0;
6120 +       gid_t   gid = 0;
6121  
6122         iap->ia_valid = 0;
6123  
6124 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6125         }
6126         if ((tmp = ntohl(*p++)) != (u32)-1) {
6127                 iap->ia_valid |= ATTR_UID;
6128 -               iap->ia_uid = tmp;
6129 +               uid = tmp;
6130         }
6131         if ((tmp = ntohl(*p++)) != (u32)-1) {
6132                 iap->ia_valid |= ATTR_GID;
6133 -               iap->ia_gid = tmp;
6134 +               gid = tmp;
6135         }
6136 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6137 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6138 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6139         if ((tmp = ntohl(*p++)) != (u32)-1) {
6140                 iap->ia_valid |= ATTR_SIZE;
6141                 iap->ia_size = tmp;
6142 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6143         *p++ = htonl(nfs_ftypes[type >> 12]);
6144         *p++ = htonl((u32) stat->mode);
6145         *p++ = htonl((u32) stat->nlink);
6146 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6147 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6148 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6149 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6150 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6151 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6152  
6153         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6154                 *p++ = htonl(NFS_MAXPATHLEN);
6155 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/dlm/dlmfs.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/dlm/dlmfs.c
6156 --- linux-2.6.32.10/fs/ocfs2/dlm/dlmfs.c        2009-12-03 20:02:53.000000000 +0100
6157 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/dlm/dlmfs.c        2009-12-03 20:04:56.000000000 +0100
6158 @@ -43,6 +43,7 @@
6159  #include <linux/init.h>
6160  #include <linux/string.h>
6161  #include <linux/backing-dev.h>
6162 +#include <linux/vs_tag.h>
6163  
6164  #include <asm/uaccess.h>
6165  
6166 @@ -342,6 +343,7 @@ static struct inode *dlmfs_get_root_inod
6167                 inode->i_mode = mode;
6168                 inode->i_uid = current_fsuid();
6169                 inode->i_gid = current_fsgid();
6170 +               inode->i_tag = dx_current_fstag(sb);
6171                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6172                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6173                 inc_nlink(inode);
6174 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6175         inode->i_mode = mode;
6176         inode->i_uid = current_fsuid();
6177         inode->i_gid = current_fsgid();
6178 +       inode->i_tag = dx_current_fstag(sb);
6179         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6180         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6181  
6182 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/dlmglue.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/dlmglue.c
6183 --- linux-2.6.32.10/fs/ocfs2/dlmglue.c  2009-12-03 20:02:53.000000000 +0100
6184 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/dlmglue.c  2009-12-03 20:04:56.000000000 +0100
6185 @@ -1991,6 +1991,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6186         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6187         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6188         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6189 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6190         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6191         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6192         lvb->lvb_iatime_packed  =
6193 @@ -2045,6 +2046,7 @@ static void ocfs2_refresh_inode_from_lvb
6194  
6195         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6196         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6197 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6198         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6199         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6200         ocfs2_unpack_timespec(&inode->i_atime,
6201 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/dlmglue.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/dlmglue.h
6202 --- linux-2.6.32.10/fs/ocfs2/dlmglue.h  2009-12-03 20:02:53.000000000 +0100
6203 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/dlmglue.h  2009-12-03 20:04:56.000000000 +0100
6204 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6205         __be16       lvb_inlink;
6206         __be32       lvb_iattr;
6207         __be32       lvb_igeneration;
6208 -       __be32       lvb_reserved2;
6209 +       __be16       lvb_itag;
6210 +       __be16       lvb_reserved2;
6211  };
6212  
6213  #define OCFS2_QINFO_LVB_VERSION 1
6214 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/file.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/file.c
6215 --- linux-2.6.32.10/fs/ocfs2/file.c     2009-12-03 20:02:53.000000000 +0100
6216 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/file.c     2009-12-03 20:04:56.000000000 +0100
6217 @@ -960,13 +960,15 @@ int ocfs2_setattr(struct dentry *dentry,
6218                 mlog(0, "uid change: %d\n", attr->ia_uid);
6219         if (attr->ia_valid & ATTR_GID)
6220                 mlog(0, "gid change: %d\n", attr->ia_gid);
6221 +       if (attr->ia_valid & ATTR_TAG)
6222 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6223         if (attr->ia_valid & ATTR_SIZE)
6224                 mlog(0, "size change...\n");
6225         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6226                 mlog(0, "time change...\n");
6227  
6228  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6229 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6230 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6231         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6232                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6233                 return 0;
6234 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/inode.c
6235 --- linux-2.6.32.10/fs/ocfs2/inode.c    2009-12-03 20:02:53.000000000 +0100
6236 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/inode.c    2009-12-03 20:04:56.000000000 +0100
6237 @@ -29,6 +29,7 @@
6238  #include <linux/highmem.h>
6239  #include <linux/pagemap.h>
6240  #include <linux/quotaops.h>
6241 +#include <linux/vs_tag.h>
6242  
6243  #include <asm/byteorder.h>
6244  
6245 @@ -79,11 +80,13 @@ void ocfs2_set_inode_flags(struct inode 
6246  {
6247         unsigned int flags = OCFS2_I(inode)->ip_attr;
6248  
6249 -       inode->i_flags &= ~(S_IMMUTABLE |
6250 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6251                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6252  
6253         if (flags & OCFS2_IMMUTABLE_FL)
6254                 inode->i_flags |= S_IMMUTABLE;
6255 +       if (flags & OCFS2_IXUNLINK_FL)
6256 +               inode->i_flags |= S_IXUNLINK;
6257  
6258         if (flags & OCFS2_SYNC_FL)
6259                 inode->i_flags |= S_SYNC;
6260 @@ -93,25 +96,44 @@ void ocfs2_set_inode_flags(struct inode 
6261                 inode->i_flags |= S_NOATIME;
6262         if (flags & OCFS2_DIRSYNC_FL)
6263                 inode->i_flags |= S_DIRSYNC;
6264 +
6265 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6266 +
6267 +       if (flags & OCFS2_BARRIER_FL)
6268 +               inode->i_vflags |= V_BARRIER;
6269 +       if (flags & OCFS2_COW_FL)
6270 +               inode->i_vflags |= V_COW;
6271  }
6272  
6273  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6274  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6275  {
6276         unsigned int flags = oi->vfs_inode.i_flags;
6277 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6278 +
6279 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6280 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6281 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6282 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6283 +
6284 +       if (flags & S_IMMUTABLE)
6285 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6286 +       if (flags & S_IXUNLINK)
6287 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6288  
6289 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6290 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6291         if (flags & S_SYNC)
6292                 oi->ip_attr |= OCFS2_SYNC_FL;
6293         if (flags & S_APPEND)
6294                 oi->ip_attr |= OCFS2_APPEND_FL;
6295 -       if (flags & S_IMMUTABLE)
6296 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6297         if (flags & S_NOATIME)
6298                 oi->ip_attr |= OCFS2_NOATIME_FL;
6299         if (flags & S_DIRSYNC)
6300                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6301 +
6302 +       if (vflags & V_BARRIER)
6303 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6304 +       if (vflags & V_COW)
6305 +               oi->ip_attr |= OCFS2_COW_FL;
6306  }
6307  
6308  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6309 @@ -246,6 +268,8 @@ void ocfs2_populate_inode(struct inode *
6310         struct super_block *sb;
6311         struct ocfs2_super *osb;
6312         int use_plocks = 1;
6313 +       uid_t uid;
6314 +       gid_t gid;
6315  
6316         mlog_entry("(0x%p, size:%llu)\n", inode,
6317                    (unsigned long long)le64_to_cpu(fe->i_size));
6318 @@ -277,8 +301,12 @@ void ocfs2_populate_inode(struct inode *
6319         inode->i_generation = le32_to_cpu(fe->i_generation);
6320         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6321         inode->i_mode = le16_to_cpu(fe->i_mode);
6322 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6323 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6324 +       uid = le32_to_cpu(fe->i_uid);
6325 +       gid = le32_to_cpu(fe->i_gid);
6326 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6327 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6328 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6329 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6330  
6331         /* Fast symlinks will have i_size but no allocated clusters. */
6332         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6333 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/inode.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/inode.h
6334 --- linux-2.6.32.10/fs/ocfs2/inode.h    2009-12-03 20:02:53.000000000 +0100
6335 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/inode.h    2009-12-03 20:04:56.000000000 +0100
6336 @@ -150,6 +150,7 @@ struct buffer_head *ocfs2_bread(struct i
6337  
6338  void ocfs2_set_inode_flags(struct inode *inode);
6339  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6340 +int ocfs2_sync_flags(struct inode *inode, int, int);
6341  
6342  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6343  {
6344 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/ioctl.c
6345 --- linux-2.6.32.10/fs/ocfs2/ioctl.c    2009-12-03 20:02:53.000000000 +0100
6346 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/ioctl.c    2009-12-03 20:04:56.000000000 +0100
6347 @@ -42,7 +42,41 @@ static int ocfs2_get_inode_attr(struct i
6348         return status;
6349  }
6350  
6351 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6352 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6353 +{
6354 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6355 +       struct buffer_head *bh = NULL;
6356 +       handle_t *handle = NULL;
6357 +       int status;
6358 +
6359 +       status = ocfs2_inode_lock(inode, &bh, 1);
6360 +       if (status < 0) {
6361 +               mlog_errno(status);
6362 +               return status;
6363 +       }
6364 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6365 +       if (IS_ERR(handle)) {
6366 +               status = PTR_ERR(handle);
6367 +               mlog_errno(status);
6368 +               goto bail_unlock;
6369 +       }
6370 +
6371 +       inode->i_flags = flags;
6372 +       inode->i_vflags = vflags;
6373 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6374 +
6375 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6376 +       if (status < 0)
6377 +               mlog_errno(status);
6378 +
6379 +       ocfs2_commit_trans(osb, handle);
6380 +bail_unlock:
6381 +       ocfs2_inode_unlock(inode, 1);
6382 +       brelse(bh);
6383 +       return status;
6384 +}
6385 +
6386 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6387                                 unsigned mask)
6388  {
6389         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6390 @@ -67,6 +101,11 @@ static int ocfs2_set_inode_attr(struct i
6391         if (!S_ISDIR(inode->i_mode))
6392                 flags &= ~OCFS2_DIRSYNC_FL;
6393  
6394 +       if (IS_BARRIER(inode)) {
6395 +               vxwprintk_task(1, "messing with the barrier.");
6396 +               goto bail_unlock;
6397 +       }
6398 +
6399         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6400         if (IS_ERR(handle)) {
6401                 status = PTR_ERR(handle);
6402 @@ -108,6 +147,7 @@ bail:
6403         return status;
6404  }
6405  
6406 +
6407  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6408  {
6409         struct inode *inode = filp->f_path.dentry->d_inode;
6410 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/namei.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/namei.c
6411 --- linux-2.6.32.10/fs/ocfs2/namei.c    2009-12-03 20:02:53.000000000 +0100
6412 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/namei.c    2009-12-03 20:04:56.000000000 +0100
6413 @@ -41,6 +41,7 @@
6414  #include <linux/slab.h>
6415  #include <linux/highmem.h>
6416  #include <linux/quotaops.h>
6417 +#include <linux/vs_tag.h>
6418  
6419  #define MLOG_MASK_PREFIX ML_NAMEI
6420  #include <cluster/masklog.h>
6421 @@ -481,6 +482,7 @@ static int ocfs2_mknod_locked(struct ocf
6422         u64 fe_blkno = 0;
6423         u16 suballoc_bit;
6424         u16 feat;
6425 +       tag_t tag;
6426  
6427         *new_fe_bh = NULL;
6428  
6429 @@ -524,8 +526,11 @@ static int ocfs2_mknod_locked(struct ocf
6430         fe->i_blkno = cpu_to_le64(fe_blkno);
6431         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6432         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6433 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6434 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6435 +
6436 +       tag = dx_current_fstag(osb->sb);
6437 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6438 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6439 +       inode->i_tag = tag;
6440         fe->i_mode = cpu_to_le16(inode->i_mode);
6441         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6442                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6443 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/ocfs2_fs.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/ocfs2_fs.h
6444 --- linux-2.6.32.10/fs/ocfs2/ocfs2_fs.h 2009-12-03 20:02:53.000000000 +0100
6445 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/ocfs2_fs.h 2009-12-03 20:04:56.000000000 +0100
6446 @@ -231,18 +231,23 @@
6447  #define OCFS2_HAS_REFCOUNT_FL   (0x0010)
6448  
6449  /* Inode attributes, keep in sync with EXT2 */
6450 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6451 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6452 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6453 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6454 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6455 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6456 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6457 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6458 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6459 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6460 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6461 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6462 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6463 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6464 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6465 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6466 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6467  
6468 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6469 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6470 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6471 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6472 +
6473 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6474 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6475 +
6476 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6477 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6478  
6479  /*
6480   * Extent record flags (e_node.leaf.flags)
6481 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/ocfs2.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/ocfs2.h
6482 --- linux-2.6.32.10/fs/ocfs2/ocfs2.h    2009-12-03 20:02:53.000000000 +0100
6483 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/ocfs2.h    2009-12-03 20:04:56.000000000 +0100
6484 @@ -248,6 +248,7 @@ enum ocfs2_mount_options
6485         OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */
6486         OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */
6487         OCFS2_MOUNT_GRPQUOTA = 1 << 10, /* We support group quotas */
6488 +       OCFS2_MOUNT_TAGGED = 1 << 11, /* use tagging */
6489  };
6490  
6491  #define OCFS2_OSB_SOFT_RO                      0x0001
6492 diff -NurpP --minimal linux-2.6.32.10/fs/ocfs2/super.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/super.c
6493 --- linux-2.6.32.10/fs/ocfs2/super.c    2009-12-03 20:02:53.000000000 +0100
6494 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/ocfs2/super.c    2009-12-03 20:04:56.000000000 +0100
6495 @@ -173,6 +173,7 @@ enum {
6496         Opt_noacl,
6497         Opt_usrquota,
6498         Opt_grpquota,
6499 +       Opt_tag, Opt_notag, Opt_tagid,
6500         Opt_err,
6501  };
6502  
6503 @@ -199,6 +200,9 @@ static const match_table_t tokens = {
6504         {Opt_noacl, "noacl"},
6505         {Opt_usrquota, "usrquota"},
6506         {Opt_grpquota, "grpquota"},
6507 +       {Opt_tag, "tag"},
6508 +       {Opt_notag, "notag"},
6509 +       {Opt_tagid, "tagid=%u"},
6510         {Opt_err, NULL}
6511  };
6512  
6513 @@ -605,6 +609,13 @@ static int ocfs2_remount(struct super_bl
6514                 goto out;
6515         }
6516  
6517 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6518 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6519 +               ret = -EINVAL;
6520 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6521 +               goto out;
6522 +       }
6523 +
6524         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6525             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6526                 ret = -EINVAL;
6527 @@ -1148,6 +1159,9 @@ static int ocfs2_fill_super(struct super
6528  
6529         ocfs2_complete_mount_recovery(osb);
6530  
6531 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6532 +               sb->s_flags |= MS_TAGGED;
6533 +
6534         if (ocfs2_mount_local(osb))
6535                 snprintf(nodestr, sizeof(nodestr), "local");
6536         else
6537 @@ -1426,6 +1440,20 @@ static int ocfs2_parse_options(struct su
6538                         printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
6539                         break;
6540  #endif
6541 +#ifndef CONFIG_TAGGING_NONE
6542 +               case Opt_tag:
6543 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6544 +                       break;
6545 +               case Opt_notag:
6546 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6547 +                       break;
6548 +#endif
6549 +#ifdef CONFIG_PROPAGATE
6550 +               case Opt_tagid:
6551 +                       /* use args[0] */
6552 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6553 +                       break;
6554 +#endif
6555                 default:
6556                         mlog(ML_ERROR,
6557                              "Unrecognized mount option \"%s\" "
6558 diff -NurpP --minimal linux-2.6.32.10/fs/open.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/open.c
6559 --- linux-2.6.32.10/fs/open.c   2009-12-03 20:02:53.000000000 +0100
6560 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/open.c   2009-12-03 20:04:56.000000000 +0100
6561 @@ -30,22 +30,30 @@
6562  #include <linux/audit.h>
6563  #include <linux/falloc.h>
6564  #include <linux/fs_struct.h>
6565 +#include <linux/vs_base.h>
6566 +#include <linux/vs_limit.h>
6567 +#include <linux/vs_tag.h>
6568 +#include <linux/vs_cowbl.h>
6569  
6570  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6571  {
6572         int retval = -ENODEV;
6573  
6574         if (dentry) {
6575 +               struct super_block *sb = dentry->d_sb;
6576 +
6577                 retval = -ENOSYS;
6578 -               if (dentry->d_sb->s_op->statfs) {
6579 +               if (sb->s_op->statfs) {
6580                         memset(buf, 0, sizeof(*buf));
6581                         retval = security_sb_statfs(dentry);
6582                         if (retval)
6583                                 return retval;
6584 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6585 +                       retval = sb->s_op->statfs(dentry, buf);
6586                         if (retval == 0 && buf->f_frsize == 0)
6587                                 buf->f_frsize = buf->f_bsize;
6588                 }
6589 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6590 +                       vx_vsi_statfs(sb, buf);
6591         }
6592         return retval;
6593  }
6594 @@ -640,6 +648,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6595         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6596         if (error)
6597                 goto out;
6598 +
6599 +       error = cow_check_and_break(&path);
6600 +       if (error)
6601 +               goto dput_and_out;
6602         inode = path.dentry->d_inode;
6603  
6604         error = mnt_want_write(path.mnt);
6605 @@ -673,11 +685,11 @@ static int chown_common(struct dentry * 
6606         newattrs.ia_valid =  ATTR_CTIME;
6607         if (user != (uid_t) -1) {
6608                 newattrs.ia_valid |= ATTR_UID;
6609 -               newattrs.ia_uid = user;
6610 +               newattrs.ia_uid = dx_map_uid(user);
6611         }
6612         if (group != (gid_t) -1) {
6613                 newattrs.ia_valid |= ATTR_GID;
6614 -               newattrs.ia_gid = group;
6615 +               newattrs.ia_gid = dx_map_gid(group);
6616         }
6617         if (!S_ISDIR(inode->i_mode))
6618                 newattrs.ia_valid |=
6619 @@ -700,7 +712,11 @@ SYSCALL_DEFINE3(chown, const char __user
6620         error = mnt_want_write(path.mnt);
6621         if (error)
6622                 goto out_release;
6623 -       error = chown_common(path.dentry, user, group);
6624 +#ifdef CONFIG_VSERVER_COWBL
6625 +       error = cow_check_and_break(&path);
6626 +       if (!error)
6627 +#endif
6628 +               error = chown_common(path.dentry, user, group);
6629         mnt_drop_write(path.mnt);
6630  out_release:
6631         path_put(&path);
6632 @@ -725,7 +741,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6633         error = mnt_want_write(path.mnt);
6634         if (error)
6635                 goto out_release;
6636 -       error = chown_common(path.dentry, user, group);
6637 +#ifdef CONFIG_VSERVER_COWBL
6638 +       error = cow_check_and_break(&path);
6639 +       if (!error)
6640 +#endif
6641 +               error = chown_common(path.dentry, user, group);
6642         mnt_drop_write(path.mnt);
6643  out_release:
6644         path_put(&path);
6645 @@ -744,7 +764,11 @@ SYSCALL_DEFINE3(lchown, const char __use
6646         error = mnt_want_write(path.mnt);
6647         if (error)
6648                 goto out_release;
6649 -       error = chown_common(path.dentry, user, group);
6650 +#ifdef CONFIG_VSERVER_COWBL
6651 +       error = cow_check_and_break(&path);
6652 +       if (!error)
6653 +#endif
6654 +               error = chown_common(path.dentry, user, group);
6655         mnt_drop_write(path.mnt);
6656  out_release:
6657         path_put(&path);
6658 @@ -990,6 +1014,7 @@ static void __put_unused_fd(struct files
6659         __FD_CLR(fd, fdt->open_fds);
6660         if (fd < files->next_fd)
6661                 files->next_fd = fd;
6662 +       vx_openfd_dec(fd);
6663  }
6664  
6665  void put_unused_fd(unsigned int fd)
6666 diff -NurpP --minimal linux-2.6.32.10/fs/proc/array.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/array.c
6667 --- linux-2.6.32.10/fs/proc/array.c     2009-12-03 20:02:53.000000000 +0100
6668 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/array.c     2009-12-03 20:04:56.000000000 +0100
6669 @@ -83,6 +83,8 @@
6670  #include <linux/ptrace.h>
6671  #include <linux/tracehook.h>
6672  #include <linux/swapops.h>
6673 +#include <linux/vs_context.h>
6674 +#include <linux/vs_network.h>
6675  
6676  #include <asm/pgtable.h>
6677  #include <asm/processor.h>
6678 @@ -139,8 +141,9 @@ static const char *task_state_array[] = 
6679         "D (disk sleep)",       /*  2 */
6680         "T (stopped)",          /*  4 */
6681         "T (tracing stop)",     /*  8 */
6682 -       "Z (zombie)",           /* 16 */
6683 -       "X (dead)"              /* 32 */
6684 +       "H (on hold)",          /* 16 */
6685 +       "Z (zombie)",           /* 32 */
6686 +       "X (dead)",             /* 64 */
6687  };
6688  
6689  static inline const char *get_task_state(struct task_struct *tsk)
6690 @@ -167,6 +170,9 @@ static inline void task_state(struct seq
6691         rcu_read_lock();
6692         ppid = pid_alive(p) ?
6693                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6694 +       if (unlikely(vx_current_initpid(p->pid)))
6695 +               ppid = 0;
6696 +
6697         tpid = 0;
6698         if (pid_alive(p)) {
6699                 struct task_struct *tracer = tracehook_tracer_task(p);
6700 @@ -282,7 +288,7 @@ static inline void task_sig(struct seq_f
6701  }
6702  
6703  static void render_cap_t(struct seq_file *m, const char *header,
6704 -                       kernel_cap_t *a)
6705 +                       struct vx_info *vxi, kernel_cap_t *a)
6706  {
6707         unsigned __capi;
6708  
6709 @@ -307,10 +313,11 @@ static inline void task_cap(struct seq_f
6710         cap_bset        = cred->cap_bset;
6711         rcu_read_unlock();
6712  
6713 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6714 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6715 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6716 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6717 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6718 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6719 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6720 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6721 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6722  }
6723  
6724  static inline void task_context_switch_counts(struct seq_file *m,
6725 @@ -410,6 +417,42 @@ static void task_show_stack_usage(struct
6726  }
6727  #endif         /* CONFIG_MMU */
6728  
6729 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6730 +                       struct pid *pid, struct task_struct *task)
6731 +{
6732 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6733 +                       "Count:\t%u\n"
6734 +                       "uts:\t%p(%c)\n"
6735 +                       "ipc:\t%p(%c)\n"
6736 +                       "mnt:\t%p(%c)\n"
6737 +                       "pid:\t%p(%c)\n"
6738 +                       "net:\t%p(%c)\n",
6739 +                       task->nsproxy,
6740 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6741 +                       atomic_read(&task->nsproxy->count),
6742 +                       task->nsproxy->uts_ns,
6743 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6744 +                       task->nsproxy->ipc_ns,
6745 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6746 +                       task->nsproxy->mnt_ns,
6747 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6748 +                       task->nsproxy->pid_ns,
6749 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6750 +                       task->nsproxy->net_ns,
6751 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6752 +       return 0;
6753 +}
6754 +
6755 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6756 +{
6757 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6758 +               return;
6759 +
6760 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6761 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6762 +}
6763 +
6764 +
6765  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6766                         struct pid *pid, struct task_struct *task)
6767  {
6768 @@ -425,6 +468,7 @@ int proc_pid_status(struct seq_file *m, 
6769         task_sig(m, task);
6770         task_cap(m, task);
6771         cpuset_task_status_allowed(m, task);
6772 +       task_vs_id(m, task);
6773  #if defined(CONFIG_S390)
6774         task_show_regs(m, task);
6775  #endif
6776 @@ -542,6 +586,17 @@ static int do_task_stat(struct seq_file 
6777         /* convert nsec -> ticks */
6778         start_time = nsec_to_clock_t(start_time);
6779  
6780 +       /* fixup start time for virt uptime */
6781 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6782 +               unsigned long long bias =
6783 +                       current->vx_info->cvirt.bias_clock;
6784 +
6785 +               if (start_time > bias)
6786 +                       start_time -= bias;
6787 +               else
6788 +                       start_time = 0;
6789 +       }
6790 +
6791         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6792  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6793  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6794 diff -NurpP --minimal linux-2.6.32.10/fs/proc/base.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/base.c
6795 --- linux-2.6.32.10/fs/proc/base.c      2010-03-18 16:17:37.000000000 +0100
6796 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/base.c      2010-03-18 16:53:06.000000000 +0100
6797 @@ -81,6 +81,8 @@
6798  #include <linux/elf.h>
6799  #include <linux/pid_namespace.h>
6800  #include <linux/fs_struct.h>
6801 +#include <linux/vs_context.h>
6802 +#include <linux/vs_network.h>
6803  #include "internal.h"
6804  
6805  /* NOTE:
6806 @@ -1047,12 +1049,17 @@ static ssize_t oom_adjust_write(struct f
6807                 return -ESRCH;
6808         }
6809  
6810 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6811 +       if (oom_adjust < task->signal->oom_adj &&
6812 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6813                 unlock_task_sighand(task, &flags);
6814                 put_task_struct(task);
6815                 return -EACCES;
6816         }
6817  
6818 +       /* prevent guest processes from circumventing the oom killer */
6819 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6820 +               oom_adjust = OOM_ADJUST_MIN;
6821 +
6822         task->signal->oom_adj = oom_adjust;
6823  
6824         unlock_task_sighand(task, &flags);
6825 @@ -1092,7 +1099,7 @@ static ssize_t proc_loginuid_write(struc
6826         ssize_t length;
6827         uid_t loginuid;
6828  
6829 -       if (!capable(CAP_AUDIT_CONTROL))
6830 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6831                 return -EPERM;
6832  
6833         if (current != pid_task(proc_pid(inode), PIDTYPE_PID))
6834 @@ -1458,6 +1465,8 @@ static struct inode *proc_pid_make_inode
6835                 inode->i_gid = cred->egid;
6836                 rcu_read_unlock();
6837         }
6838 +       /* procfs is xid tagged */
6839 +       inode->i_tag = (tag_t)vx_task_xid(task);
6840         security_task_to_inode(task, inode);
6841  
6842  out:
6843 @@ -2008,6 +2017,13 @@ static struct dentry *proc_pident_lookup
6844         if (!task)
6845                 goto out_no_task;
6846  
6847 +       /* TODO: maybe we can come up with a generic approach? */
6848 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6849 +               (dentry->d_name.len == 5) &&
6850 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6851 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6852 +               goto out;
6853 +
6854         /*
6855          * Yes, it does not scale. And it should not. Don't add
6856          * new entries into /proc/<tgid>/ without very good reasons.
6857 @@ -2413,7 +2429,7 @@ out_iput:
6858  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6859  {
6860         struct dentry *error;
6861 -       struct task_struct *task = get_proc_task(dir);
6862 +       struct task_struct *task = get_proc_task_real(dir);
6863         const struct pid_entry *p, *last;
6864  
6865         error = ERR_PTR(-ENOENT);
6866 @@ -2503,6 +2519,9 @@ static int proc_pid_personality(struct s
6867  static const struct file_operations proc_task_operations;
6868  static const struct inode_operations proc_task_inode_operations;
6869  
6870 +extern int proc_pid_vx_info(struct task_struct *, char *);
6871 +extern int proc_pid_nx_info(struct task_struct *, char *);
6872 +
6873  static const struct pid_entry tgid_base_stuff[] = {
6874         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6875         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6876 @@ -2561,6 +2580,8 @@ static const struct pid_entry tgid_base_
6877  #ifdef CONFIG_CGROUPS
6878         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6879  #endif
6880 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6881 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6882         INF("oom_score",  S_IRUGO, proc_oom_score),
6883         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6884  #ifdef CONFIG_AUDITSYSCALL
6885 @@ -2576,6 +2597,7 @@ static const struct pid_entry tgid_base_
6886  #ifdef CONFIG_TASK_IO_ACCOUNTING
6887         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6888  #endif
6889 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6890  };
6891  
6892  static int proc_tgid_base_readdir(struct file * filp,
6893 @@ -2767,7 +2789,7 @@ retry:
6894         iter.task = NULL;
6895         pid = find_ge_pid(iter.tgid, ns);
6896         if (pid) {
6897 -               iter.tgid = pid_nr_ns(pid, ns);
6898 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6899                 iter.task = pid_task(pid, PIDTYPE_PID);
6900                 /* What we to know is if the pid we have find is the
6901                  * pid of a thread_group_leader.  Testing for task
6902 @@ -2797,7 +2819,7 @@ static int proc_pid_fill_cache(struct fi
6903         struct tgid_iter iter)
6904  {
6905         char name[PROC_NUMBUF];
6906 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6907 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6908         return proc_fill_cache(filp, dirent, filldir, name, len,
6909                                 proc_pid_instantiate, iter.task, NULL);
6910  }
6911 @@ -2806,7 +2828,7 @@ static int proc_pid_fill_cache(struct fi
6912  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6913  {
6914         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6915 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6916 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6917         struct tgid_iter iter;
6918         struct pid_namespace *ns;
6919  
6920 @@ -2826,6 +2848,8 @@ int proc_pid_readdir(struct file * filp,
6921              iter.task;
6922              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6923                 filp->f_pos = iter.tgid + TGID_OFFSET;
6924 +               if (!vx_proc_task_visible(iter.task))
6925 +                       continue;
6926                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6927                         put_task_struct(iter.task);
6928                         goto out;
6929 @@ -2972,6 +2996,8 @@ static struct dentry *proc_task_lookup(s
6930         tid = name_to_int(dentry);
6931         if (tid == ~0U)
6932                 goto out;
6933 +       if (vx_current_initpid(tid))
6934 +               goto out;
6935  
6936         ns = dentry->d_sb->s_fs_info;
6937         rcu_read_lock();
6938 diff -NurpP --minimal linux-2.6.32.10/fs/proc/generic.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/generic.c
6939 --- linux-2.6.32.10/fs/proc/generic.c   2009-06-11 17:13:07.000000000 +0200
6940 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/generic.c   2009-12-03 20:04:56.000000000 +0100
6941 @@ -20,6 +20,7 @@
6942  #include <linux/bitops.h>
6943  #include <linux/spinlock.h>
6944  #include <linux/completion.h>
6945 +#include <linux/vserver/inode.h>
6946  #include <asm/uaccess.h>
6947  
6948  #include "internal.h"
6949 @@ -425,6 +426,8 @@ struct dentry *proc_lookup_de(struct pro
6950         for (de = de->subdir; de ; de = de->next) {
6951                 if (de->namelen != dentry->d_name.len)
6952                         continue;
6953 +                       if (!vx_hide_check(0, de->vx_flags))
6954 +                               continue;
6955                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6956                         unsigned int ino;
6957  
6958 @@ -433,6 +436,8 @@ struct dentry *proc_lookup_de(struct pro
6959                         spin_unlock(&proc_subdir_lock);
6960                         error = -EINVAL;
6961                         inode = proc_get_inode(dir->i_sb, ino, de);
6962 +                               /* generic proc entries belong to the host */
6963 +                               inode->i_tag = 0;
6964                         goto out_unlock;
6965                 }
6966         }
6967 @@ -510,6 +515,8 @@ int proc_readdir_de(struct proc_dir_entr
6968  
6969                                 /* filldir passes info to user space */
6970                                 de_get(de);
6971 +                               if (!vx_hide_check(0, de->vx_flags))
6972 +                                       goto skip;
6973                                 spin_unlock(&proc_subdir_lock);
6974                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6975                                             de->low_ino, de->mode >> 12) < 0) {
6976 @@ -517,6 +524,7 @@ int proc_readdir_de(struct proc_dir_entr
6977                                         goto out;
6978                                 }
6979                                 spin_lock(&proc_subdir_lock);
6980 +                       skip:
6981                                 filp->f_pos++;
6982                                 next = de->next;
6983                                 de_put(de);
6984 @@ -631,6 +639,7 @@ static struct proc_dir_entry *__proc_cre
6985         ent->nlink = nlink;
6986         atomic_set(&ent->count, 1);
6987         ent->pde_users = 0;
6988 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6989         spin_lock_init(&ent->pde_unload_lock);
6990         ent->pde_unload_completion = NULL;
6991         INIT_LIST_HEAD(&ent->pde_openers);
6992 @@ -654,7 +663,8 @@ struct proc_dir_entry *proc_symlink(cons
6993                                 kfree(ent->data);
6994                                 kfree(ent);
6995                                 ent = NULL;
6996 -                       }
6997 +                       } else
6998 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6999                 } else {
7000                         kfree(ent);
7001                         ent = NULL;
7002 diff -NurpP --minimal linux-2.6.32.10/fs/proc/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/inode.c
7003 --- linux-2.6.32.10/fs/proc/inode.c     2009-06-11 17:13:07.000000000 +0200
7004 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/inode.c     2009-12-03 20:04:56.000000000 +0100
7005 @@ -459,6 +459,8 @@ struct inode *proc_get_inode(struct supe
7006                         inode->i_uid = de->uid;
7007                         inode->i_gid = de->gid;
7008                 }
7009 +               if (de->vx_flags)
7010 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7011                 if (de->size)
7012                         inode->i_size = de->size;
7013                 if (de->nlink)
7014 diff -NurpP --minimal linux-2.6.32.10/fs/proc/internal.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/internal.h
7015 --- linux-2.6.32.10/fs/proc/internal.h  2009-09-10 15:26:23.000000000 +0200
7016 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/internal.h  2009-12-03 20:04:56.000000000 +0100
7017 @@ -10,6 +10,7 @@
7018   */
7019  
7020  #include <linux/proc_fs.h>
7021 +#include <linux/vs_pid.h>
7022  
7023  extern struct proc_dir_entry proc_root;
7024  #ifdef CONFIG_PROC_SYSCTL
7025 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7026                                 struct pid *pid, struct task_struct *task);
7027  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7028                                 struct pid *pid, struct task_struct *task);
7029 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7030 +                               struct pid *pid, struct task_struct *task);
7031 +
7032  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7033  
7034  extern const struct file_operations proc_maps_operations;
7035 @@ -70,11 +74,16 @@ static inline struct pid *proc_pid(struc
7036         return PROC_I(inode)->pid;
7037  }
7038  
7039 -static inline struct task_struct *get_proc_task(struct inode *inode)
7040 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7041  {
7042         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7043  }
7044  
7045 +static inline struct task_struct *get_proc_task(struct inode *inode)
7046 +{
7047 +       return vx_get_proc_task(inode, proc_pid(inode));
7048 +}
7049 +
7050  static inline int proc_fd(struct inode *inode)
7051  {
7052         return PROC_I(inode)->fd;
7053 diff -NurpP --minimal linux-2.6.32.10/fs/proc/loadavg.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/loadavg.c
7054 --- linux-2.6.32.10/fs/proc/loadavg.c   2009-09-10 15:26:23.000000000 +0200
7055 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/loadavg.c   2009-12-03 20:04:56.000000000 +0100
7056 @@ -12,15 +12,27 @@
7057  
7058  static int loadavg_proc_show(struct seq_file *m, void *v)
7059  {
7060 +       unsigned long running;
7061 +       unsigned int threads;
7062         unsigned long avnrun[3];
7063  
7064         get_avenrun(avnrun, FIXED_1/200, 0);
7065  
7066 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7067 +               struct vx_info *vxi = current_vx_info();
7068 +
7069 +               running = atomic_read(&vxi->cvirt.nr_running);
7070 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7071 +       } else {
7072 +               running = nr_running();
7073 +               threads = nr_threads;
7074 +       }
7075 +
7076         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7077                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7078                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7079                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7080 -               nr_running(), nr_threads,
7081 +               running, threads,
7082                 task_active_pid_ns(current)->last_pid);
7083         return 0;
7084  }
7085 diff -NurpP --minimal linux-2.6.32.10/fs/proc/meminfo.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/meminfo.c
7086 --- linux-2.6.32.10/fs/proc/meminfo.c   2009-12-03 20:02:53.000000000 +0100
7087 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/meminfo.c   2010-02-05 00:31:48.000000000 +0100
7088 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7089         allowed = ((totalram_pages - hugetlb_total_pages())
7090                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7091  
7092 -       cached = global_page_state(NR_FILE_PAGES) -
7093 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7094 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7095                         total_swapcache_pages - i.bufferram;
7096         if (cached < 0)
7097                 cached = 0;
7098 diff -NurpP --minimal linux-2.6.32.10/fs/proc/root.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/root.c
7099 --- linux-2.6.32.10/fs/proc/root.c      2009-06-11 17:13:07.000000000 +0200
7100 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/root.c      2009-12-03 20:04:56.000000000 +0100
7101 @@ -18,9 +18,14 @@
7102  #include <linux/bitops.h>
7103  #include <linux/mount.h>
7104  #include <linux/pid_namespace.h>
7105 +#include <linux/vserver/inode.h>
7106  
7107  #include "internal.h"
7108  
7109 +struct proc_dir_entry *proc_virtual;
7110 +
7111 +extern void proc_vx_init(void);
7112 +
7113  static int proc_test_super(struct super_block *sb, void *data)
7114  {
7115         return sb->s_fs_info == data;
7116 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
7117  #endif
7118         proc_mkdir("bus", NULL);
7119         proc_sys_init();
7120 +       proc_vx_init();
7121  }
7122  
7123  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7124 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7125         .proc_iops      = &proc_root_inode_operations, 
7126         .proc_fops      = &proc_root_operations,
7127         .parent         = &proc_root,
7128 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7129  };
7130  
7131  int pid_ns_prepare_proc(struct pid_namespace *ns)
7132 diff -NurpP --minimal linux-2.6.32.10/fs/proc/uptime.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/uptime.c
7133 --- linux-2.6.32.10/fs/proc/uptime.c    2009-12-03 20:02:53.000000000 +0100
7134 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/proc/uptime.c    2009-12-03 20:04:56.000000000 +0100
7135 @@ -4,22 +4,22 @@
7136  #include <linux/sched.h>
7137  #include <linux/seq_file.h>
7138  #include <linux/time.h>
7139 -#include <linux/kernel_stat.h>
7140 +#include <linux/vserver/cvirt.h>
7141  #include <asm/cputime.h>
7142  
7143  static int uptime_proc_show(struct seq_file *m, void *v)
7144  {
7145         struct timespec uptime;
7146         struct timespec idle;
7147 -       int i;
7148 -       cputime_t idletime = cputime_zero;
7149 -
7150 -       for_each_possible_cpu(i)
7151 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7152 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7153  
7154         do_posix_clock_monotonic_gettime(&uptime);
7155         monotonic_to_bootbased(&uptime);
7156         cputime_to_timespec(idletime, &idle);
7157 +
7158 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7159 +               vx_vsi_uptime(&uptime, &idle);
7160 +
7161         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7162                         (unsigned long) uptime.tv_sec,
7163                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7164 diff -NurpP --minimal linux-2.6.32.10/fs/quota/quota.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/quota/quota.c
7165 --- linux-2.6.32.10/fs/quota/quota.c    2009-09-10 15:26:24.000000000 +0200
7166 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/quota/quota.c    2009-12-03 20:04:56.000000000 +0100
7167 @@ -18,6 +18,7 @@
7168  #include <linux/capability.h>
7169  #include <linux/quotaops.h>
7170  #include <linux/types.h>
7171 +#include <linux/vs_context.h>
7172  
7173  /* Check validity of generic quotactl commands */
7174  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd,
7175 @@ -83,11 +84,11 @@ static int generic_quotactl_valid(struct
7176         if (cmd == Q_GETQUOTA) {
7177                 if (((type == USRQUOTA && current_euid() != id) ||
7178                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7179 -                   !capable(CAP_SYS_ADMIN))
7180 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7181                         return -EPERM;
7182         }
7183         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7184 -               if (!capable(CAP_SYS_ADMIN))
7185 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7186                         return -EPERM;
7187  
7188         return 0;
7189 @@ -135,10 +136,10 @@ static int xqm_quotactl_valid(struct sup
7190         if (cmd == Q_XGETQUOTA) {
7191                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7192                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7193 -                    !capable(CAP_SYS_ADMIN))
7194 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7195                         return -EPERM;
7196         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7197 -               if (!capable(CAP_SYS_ADMIN))
7198 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7199                         return -EPERM;
7200         }
7201  
7202 @@ -351,6 +352,46 @@ static int do_quotactl(struct super_bloc
7203         return 0;
7204  }
7205  
7206 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7207 +
7208 +#include <linux/vroot.h>
7209 +#include <linux/major.h>
7210 +#include <linux/module.h>
7211 +#include <linux/kallsyms.h>
7212 +#include <linux/vserver/debug.h>
7213 +
7214 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7215 +
7216 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7217 +
7218 +int register_vroot_grb(vroot_grb_func *func) {
7219 +       int ret = -EBUSY;
7220 +
7221 +       spin_lock(&vroot_grb_lock);
7222 +       if (!vroot_get_real_bdev) {
7223 +               vroot_get_real_bdev = func;
7224 +               ret = 0;
7225 +       }
7226 +       spin_unlock(&vroot_grb_lock);
7227 +       return ret;
7228 +}
7229 +EXPORT_SYMBOL(register_vroot_grb);
7230 +
7231 +int unregister_vroot_grb(vroot_grb_func *func) {
7232 +       int ret = -EINVAL;
7233 +
7234 +       spin_lock(&vroot_grb_lock);
7235 +       if (vroot_get_real_bdev) {
7236 +               vroot_get_real_bdev = NULL;
7237 +               ret = 0;
7238 +       }
7239 +       spin_unlock(&vroot_grb_lock);
7240 +       return ret;
7241 +}
7242 +EXPORT_SYMBOL(unregister_vroot_grb);
7243 +
7244 +#endif
7245 +
7246  /*
7247   * look up a superblock on which quota ops will be performed
7248   * - use the name of a block device to find the superblock thereon
7249 @@ -368,6 +409,22 @@ static struct super_block *quotactl_bloc
7250         putname(tmp);
7251         if (IS_ERR(bdev))
7252                 return ERR_CAST(bdev);
7253 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7254 +       if (bdev && bdev->bd_inode &&
7255 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7256 +               struct block_device *bdnew = (void *)-EINVAL;
7257 +
7258 +               if (vroot_get_real_bdev)
7259 +                       bdnew = vroot_get_real_bdev(bdev);
7260 +               else
7261 +                       vxdprintk(VXD_CBIT(misc, 0),
7262 +                                       "vroot_get_real_bdev not set");
7263 +               bdput(bdev);
7264 +               if (IS_ERR(bdnew))
7265 +                       return ERR_PTR(PTR_ERR(bdnew));
7266 +               bdev = bdnew;
7267 +       }
7268 +#endif
7269         sb = get_super(bdev);
7270         bdput(bdev);
7271         if (!sb)
7272 diff -NurpP --minimal linux-2.6.32.10/fs/reiserfs/file.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/file.c
7273 --- linux-2.6.32.10/fs/reiserfs/file.c  2009-06-11 17:13:08.000000000 +0200
7274 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/file.c  2009-12-03 20:04:56.000000000 +0100
7275 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7276         .listxattr = reiserfs_listxattr,
7277         .removexattr = reiserfs_removexattr,
7278         .permission = reiserfs_permission,
7279 +       .sync_flags = reiserfs_sync_flags,
7280  };
7281 diff -NurpP --minimal linux-2.6.32.10/fs/reiserfs/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/inode.c
7282 --- linux-2.6.32.10/fs/reiserfs/inode.c 2010-03-18 16:17:37.000000000 +0100
7283 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/inode.c 2010-01-26 20:35:35.000000000 +0100
7284 @@ -18,6 +18,7 @@
7285  #include <linux/writeback.h>
7286  #include <linux/quotaops.h>
7287  #include <linux/swap.h>
7288 +#include <linux/vs_tag.h>
7289  
7290  int reiserfs_commit_write(struct file *f, struct page *page,
7291                           unsigned from, unsigned to);
7292 @@ -1117,6 +1118,8 @@ static void init_inode(struct inode *ino
7293         struct buffer_head *bh;
7294         struct item_head *ih;
7295         __u32 rdev;
7296 +       uid_t uid;
7297 +       gid_t gid;
7298         //int version = ITEM_VERSION_1;
7299  
7300         bh = PATH_PLAST_BUFFER(path);
7301 @@ -1138,12 +1141,13 @@ static void init_inode(struct inode *ino
7302                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7303                 unsigned long blocks;
7304  
7305 +               uid = sd_v1_uid(sd);
7306 +               gid = sd_v1_gid(sd);
7307 +
7308                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7309                 set_inode_sd_version(inode, STAT_DATA_V1);
7310                 inode->i_mode = sd_v1_mode(sd);
7311                 inode->i_nlink = sd_v1_nlink(sd);
7312 -               inode->i_uid = sd_v1_uid(sd);
7313 -               inode->i_gid = sd_v1_gid(sd);
7314                 inode->i_size = sd_v1_size(sd);
7315                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7316                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7317 @@ -1185,11 +1189,12 @@ static void init_inode(struct inode *ino
7318                 // (directories and symlinks)
7319                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7320  
7321 +               uid    = sd_v2_uid(sd);
7322 +               gid    = sd_v2_gid(sd);
7323 +
7324                 inode->i_mode = sd_v2_mode(sd);
7325                 inode->i_nlink = sd_v2_nlink(sd);
7326 -               inode->i_uid = sd_v2_uid(sd);
7327                 inode->i_size = sd_v2_size(sd);
7328 -               inode->i_gid = sd_v2_gid(sd);
7329                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7330                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7331                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7332 @@ -1219,6 +1224,10 @@ static void init_inode(struct inode *ino
7333                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7334         }
7335  
7336 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7337 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7338 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7339 +
7340         pathrelse(path);
7341         if (S_ISREG(inode->i_mode)) {
7342                 inode->i_op = &reiserfs_file_inode_operations;
7343 @@ -1241,13 +1250,15 @@ static void init_inode(struct inode *ino
7344  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7345  {
7346         struct stat_data *sd_v2 = (struct stat_data *)sd;
7347 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7348 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7349         __u16 flags;
7350  
7351 +       set_sd_v2_uid(sd_v2, uid);
7352 +       set_sd_v2_gid(sd_v2, gid);
7353         set_sd_v2_mode(sd_v2, inode->i_mode);
7354         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7355 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7356         set_sd_v2_size(sd_v2, size);
7357 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7358         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7359         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7360         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7361 @@ -2839,14 +2850,19 @@ int reiserfs_commit_write(struct file *f
7362  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7363  {
7364         if (reiserfs_attrs(inode->i_sb)) {
7365 -               if (sd_attrs & REISERFS_SYNC_FL)
7366 -                       inode->i_flags |= S_SYNC;
7367 -               else
7368 -                       inode->i_flags &= ~S_SYNC;
7369                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7370                         inode->i_flags |= S_IMMUTABLE;
7371                 else
7372                         inode->i_flags &= ~S_IMMUTABLE;
7373 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7374 +                       inode->i_flags |= S_IXUNLINK;
7375 +               else
7376 +                       inode->i_flags &= ~S_IXUNLINK;
7377 +
7378 +               if (sd_attrs & REISERFS_SYNC_FL)
7379 +                       inode->i_flags |= S_SYNC;
7380 +               else
7381 +                       inode->i_flags &= ~S_SYNC;
7382                 if (sd_attrs & REISERFS_APPEND_FL)
7383                         inode->i_flags |= S_APPEND;
7384                 else
7385 @@ -2859,6 +2875,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7386                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7387                 else
7388                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7389 +
7390 +               if (sd_attrs & REISERFS_BARRIER_FL)
7391 +                       inode->i_vflags |= V_BARRIER;
7392 +               else
7393 +                       inode->i_vflags &= ~V_BARRIER;
7394 +               if (sd_attrs & REISERFS_COW_FL)
7395 +                       inode->i_vflags |= V_COW;
7396 +               else
7397 +                       inode->i_vflags &= ~V_COW;
7398         }
7399  }
7400  
7401 @@ -2869,6 +2894,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7402                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7403                 else
7404                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7405 +               if (inode->i_flags & S_IXUNLINK)
7406 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7407 +               else
7408 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7409 +
7410                 if (inode->i_flags & S_SYNC)
7411                         *sd_attrs |= REISERFS_SYNC_FL;
7412                 else
7413 @@ -2881,6 +2911,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7414                         *sd_attrs |= REISERFS_NOTAIL_FL;
7415                 else
7416                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7417 +
7418 +               if (inode->i_vflags & V_BARRIER)
7419 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7420 +               else
7421 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7422 +               if (inode->i_vflags & V_COW)
7423 +                       *sd_attrs |= REISERFS_COW_FL;
7424 +               else
7425 +                       *sd_attrs &= ~REISERFS_COW_FL;
7426         }
7427  }
7428  
7429 @@ -3101,9 +3140,11 @@ int reiserfs_setattr(struct dentry *dent
7430         }
7431  
7432         error = inode_change_ok(inode, attr);
7433 +
7434         if (!error) {
7435                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7436 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7437 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7438 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7439                         error = reiserfs_chown_xattrs(inode, attr);
7440  
7441                         if (!error) {
7442 @@ -3133,6 +3174,9 @@ int reiserfs_setattr(struct dentry *dent
7443                                         inode->i_uid = attr->ia_uid;
7444                                 if (attr->ia_valid & ATTR_GID)
7445                                         inode->i_gid = attr->ia_gid;
7446 +                               if ((attr->ia_valid & ATTR_TAG) &&
7447 +                                       IS_TAGGED(inode))
7448 +                                       inode->i_tag = attr->ia_tag;
7449                                 mark_inode_dirty(inode);
7450                                 error =
7451                                     journal_end(&th, inode->i_sb, jbegin_count);
7452 diff -NurpP --minimal linux-2.6.32.10/fs/reiserfs/ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/ioctl.c
7453 --- linux-2.6.32.10/fs/reiserfs/ioctl.c 2009-06-11 17:13:08.000000000 +0200
7454 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/ioctl.c 2009-12-03 20:04:56.000000000 +0100
7455 @@ -7,11 +7,27 @@
7456  #include <linux/mount.h>
7457  #include <linux/reiserfs_fs.h>
7458  #include <linux/time.h>
7459 +#include <linux/mount.h>
7460  #include <asm/uaccess.h>
7461  #include <linux/pagemap.h>
7462  #include <linux/smp_lock.h>
7463  #include <linux/compat.h>
7464  
7465 +
7466 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7467 +{
7468 +       __u16 sd_attrs = 0;
7469 +
7470 +       inode->i_flags = flags;
7471 +       inode->i_vflags = vflags;
7472 +
7473 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7474 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7475 +       inode->i_ctime = CURRENT_TIME_SEC;
7476 +       mark_inode_dirty(inode);
7477 +       return 0;
7478 +}
7479 +
7480  /*
7481  ** reiserfs_ioctl - handler for ioctl for inode
7482  ** supported commands:
7483 @@ -23,7 +39,7 @@
7484  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7485                    unsigned long arg)
7486  {
7487 -       unsigned int flags;
7488 +       unsigned int flags, oldflags;
7489         int err = 0;
7490  
7491         switch (cmd) {
7492 @@ -43,6 +59,7 @@ int reiserfs_ioctl(struct inode *inode, 
7493  
7494                 flags = REISERFS_I(inode)->i_attrs;
7495                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7496 +               flags &= REISERFS_FL_USER_VISIBLE;
7497                 return put_user(flags, (int __user *)arg);
7498         case REISERFS_IOC_SETFLAGS:{
7499                         if (!reiserfs_attrs(inode->i_sb))
7500 @@ -60,6 +77,10 @@ int reiserfs_ioctl(struct inode *inode, 
7501                                 err = -EFAULT;
7502                                 goto setflags_out;
7503                         }
7504 +                       if (IS_BARRIER(inode)) {
7505 +                               vxwprintk_task(1, "messing with the barrier.");
7506 +                               return -EACCES;
7507 +                       }
7508                         /*
7509                          * Is it quota file? Do not allow user to mess with it
7510                          */
7511 @@ -84,6 +105,10 @@ int reiserfs_ioctl(struct inode *inode, 
7512                                         goto setflags_out;
7513                                 }
7514                         }
7515 +
7516 +                       oldflags = REISERFS_I(inode)->i_attrs;
7517 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7518 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7519                         sd_attrs_to_i_attrs(flags, inode);
7520                         REISERFS_I(inode)->i_attrs = flags;
7521                         inode->i_ctime = CURRENT_TIME_SEC;
7522 diff -NurpP --minimal linux-2.6.32.10/fs/reiserfs/namei.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/namei.c
7523 --- linux-2.6.32.10/fs/reiserfs/namei.c 2009-06-11 17:13:08.000000000 +0200
7524 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/namei.c 2009-12-03 20:04:56.000000000 +0100
7525 @@ -17,6 +17,7 @@
7526  #include <linux/reiserfs_acl.h>
7527  #include <linux/reiserfs_xattr.h>
7528  #include <linux/quotaops.h>
7529 +#include <linux/vs_tag.h>
7530  
7531  #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; }
7532  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7533 @@ -354,6 +355,7 @@ static struct dentry *reiserfs_lookup(st
7534         if (retval == IO_ERROR) {
7535                 return ERR_PTR(-EIO);
7536         }
7537 +               dx_propagate_tag(nd, inode);
7538  
7539         return d_splice_alias(inode, dentry);
7540  }
7541 @@ -570,6 +572,7 @@ static int new_inode_init(struct inode *
7542         } else {
7543                 inode->i_gid = current_fsgid();
7544         }
7545 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7546         vfs_dq_init(inode);
7547         return 0;
7548  }
7549 @@ -1515,6 +1518,7 @@ const struct inode_operations reiserfs_d
7550         .listxattr = reiserfs_listxattr,
7551         .removexattr = reiserfs_removexattr,
7552         .permission = reiserfs_permission,
7553 +       .sync_flags = reiserfs_sync_flags,
7554  };
7555  
7556  /*
7557 diff -NurpP --minimal linux-2.6.32.10/fs/reiserfs/super.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/super.c
7558 --- linux-2.6.32.10/fs/reiserfs/super.c 2009-12-03 20:02:53.000000000 +0100
7559 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/super.c 2009-12-03 20:04:56.000000000 +0100
7560 @@ -884,6 +884,14 @@ static int reiserfs_parse_options(struct
7561                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7562                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7563  #endif
7564 +#ifndef CONFIG_TAGGING_NONE
7565 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7566 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7567 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7568 +#endif
7569 +#ifdef CONFIG_PROPAGATE
7570 +               {"tag",.arg_required = 'T',.values = NULL},
7571 +#endif
7572  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7573                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7574                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7575 @@ -1190,6 +1198,14 @@ static int reiserfs_remount(struct super
7576         handle_quota_files(s, qf_names, &qfmt);
7577  #endif
7578  
7579 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7580 +               !(s->s_flags & MS_TAGGED)) {
7581 +               reiserfs_warning(s, "super-vs01",
7582 +                       "reiserfs: tagging not permitted on remount.");
7583 +               err = -EINVAL;
7584 +               goto out_err;
7585 +       }
7586 +
7587         handle_attrs(s);
7588  
7589         /* Add options that are safe here */
7590 @@ -1652,6 +1668,10 @@ static int reiserfs_fill_super(struct su
7591                 goto error;
7592         }
7593  
7594 +       /* map mount option tagxid */
7595 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7596 +               s->s_flags |= MS_TAGGED;
7597 +
7598         rs = SB_DISK_SUPER_BLOCK(s);
7599         /* Let's do basic sanity check to verify that underlying device is not
7600            smaller than the filesystem. If the check fails then abort and scream,
7601 diff -NurpP --minimal linux-2.6.32.10/fs/reiserfs/xattr.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/xattr.c
7602 --- linux-2.6.32.10/fs/reiserfs/xattr.c 2009-09-10 15:26:24.000000000 +0200
7603 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/reiserfs/xattr.c 2009-12-03 20:04:56.000000000 +0100
7604 @@ -39,6 +39,7 @@
7605  #include <linux/namei.h>
7606  #include <linux/errno.h>
7607  #include <linux/fs.h>
7608 +#include <linux/mount.h>
7609  #include <linux/file.h>
7610  #include <linux/pagemap.h>
7611  #include <linux/xattr.h>
7612 diff -NurpP --minimal linux-2.6.32.10/fs/stat.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/stat.c
7613 --- linux-2.6.32.10/fs/stat.c   2010-03-18 16:17:37.000000000 +0100
7614 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/stat.c   2010-01-13 14:33:47.000000000 +0100
7615 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7616         stat->nlink = inode->i_nlink;
7617         stat->uid = inode->i_uid;
7618         stat->gid = inode->i_gid;
7619 +       stat->tag = inode->i_tag;
7620         stat->rdev = inode->i_rdev;
7621         stat->atime = inode->i_atime;
7622         stat->mtime = inode->i_mtime;
7623 diff -NurpP --minimal linux-2.6.32.10/fs/super.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/super.c
7624 --- linux-2.6.32.10/fs/super.c  2010-03-18 16:17:37.000000000 +0100
7625 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/super.c  2010-02-12 10:59:55.000000000 +0100
7626 @@ -37,6 +37,9 @@
7627  #include <linux/kobject.h>
7628  #include <linux/mutex.h>
7629  #include <linux/file.h>
7630 +#include <linux/devpts_fs.h>
7631 +#include <linux/proc_fs.h>
7632 +#include <linux/vs_context.h>
7633  #include <asm/uaccess.h>
7634  #include "internal.h"
7635  
7636 @@ -914,12 +917,18 @@ struct vfsmount *
7637  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7638  {
7639         struct vfsmount *mnt;
7640 +       struct super_block *sb;
7641         char *secdata = NULL;
7642         int error;
7643  
7644         if (!type)
7645                 return ERR_PTR(-ENODEV);
7646  
7647 +       error = -EPERM;
7648 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7649 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7650 +               goto out;
7651 +
7652         error = -ENOMEM;
7653         mnt = alloc_vfsmnt(name);
7654         if (!mnt)
7655 @@ -938,9 +947,17 @@ vfs_kern_mount(struct file_system_type *
7656         error = type->get_sb(type, flags, name, data, mnt);
7657         if (error < 0)
7658                 goto out_free_secdata;
7659 -       BUG_ON(!mnt->mnt_sb);
7660  
7661 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7662 +       sb = mnt->mnt_sb;
7663 +       BUG_ON(!sb);
7664 +
7665 +       error = -EPERM;
7666 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7667 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7668 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7669 +               goto out_sb;
7670 +
7671 +       error = security_sb_kern_mount(sb, flags, secdata);
7672         if (error)
7673                 goto out_sb;
7674  
7675 diff -NurpP --minimal linux-2.6.32.10/fs/sysfs/mount.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/sysfs/mount.c
7676 --- linux-2.6.32.10/fs/sysfs/mount.c    2009-06-11 17:13:08.000000000 +0200
7677 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/sysfs/mount.c    2009-12-03 20:04:56.000000000 +0100
7678 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7679  
7680         sb->s_blocksize = PAGE_CACHE_SIZE;
7681         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7682 -       sb->s_magic = SYSFS_MAGIC;
7683 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7684         sb->s_op = &sysfs_ops;
7685         sb->s_time_gran = 1;
7686         sysfs_sb = sb;
7687 diff -NurpP --minimal linux-2.6.32.10/fs/utimes.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/utimes.c
7688 --- linux-2.6.32.10/fs/utimes.c 2009-03-24 14:22:37.000000000 +0100
7689 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/utimes.c 2009-12-03 20:04:56.000000000 +0100
7690 @@ -8,6 +8,8 @@
7691  #include <linux/stat.h>
7692  #include <linux/utime.h>
7693  #include <linux/syscalls.h>
7694 +#include <linux/mount.h>
7695 +#include <linux/vs_cowbl.h>
7696  #include <asm/uaccess.h>
7697  #include <asm/unistd.h>
7698  
7699 diff -NurpP --minimal linux-2.6.32.10/fs/xattr.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/xattr.c
7700 --- linux-2.6.32.10/fs/xattr.c  2009-12-03 20:02:53.000000000 +0100
7701 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xattr.c  2010-03-13 21:50:00.000000000 +0100
7702 @@ -18,6 +18,7 @@
7703  #include <linux/module.h>
7704  #include <linux/fsnotify.h>
7705  #include <linux/audit.h>
7706 +#include <linux/mount.h>
7707  #include <asm/uaccess.h>
7708  
7709  
7710 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7711          * The trusted.* namespace can only be accessed by a privileged user.
7712          */
7713         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
7714 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
7715 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
7716  
7717         /* In user.* namespace, only regular files and directories can have
7718          * extended attributes. For sticky directories, only the owner and
7719 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/linux-2.6/xfs_ioctl.c
7720 --- linux-2.6.32.10/fs/xfs/linux-2.6/xfs_ioctl.c        2009-09-10 15:26:24.000000000 +0200
7721 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/linux-2.6/xfs_ioctl.c        2009-12-03 20:04:56.000000000 +0100
7722 @@ -34,7 +34,6 @@
7723  #include "xfs_dir2_sf.h"
7724  #include "xfs_dinode.h"
7725  #include "xfs_inode.h"
7726 -#include "xfs_ioctl.h"
7727  #include "xfs_btree.h"
7728  #include "xfs_ialloc.h"
7729  #include "xfs_rtalloc.h"
7730 @@ -742,6 +741,10 @@ xfs_merge_ioc_xflags(
7731                 xflags |= XFS_XFLAG_IMMUTABLE;
7732         else
7733                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7734 +       if (flags & FS_IXUNLINK_FL)
7735 +               xflags |= XFS_XFLAG_IXUNLINK;
7736 +       else
7737 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7738         if (flags & FS_APPEND_FL)
7739                 xflags |= XFS_XFLAG_APPEND;
7740         else
7741 @@ -770,6 +773,8 @@ xfs_di2lxflags(
7742  
7743         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7744                 flags |= FS_IMMUTABLE_FL;
7745 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7746 +               flags |= FS_IXUNLINK_FL;
7747         if (di_flags & XFS_DIFLAG_APPEND)
7748                 flags |= FS_APPEND_FL;
7749         if (di_flags & XFS_DIFLAG_SYNC)
7750 @@ -828,6 +833,8 @@ xfs_set_diflags(
7751         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7752         if (xflags & XFS_XFLAG_IMMUTABLE)
7753                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7754 +       if (xflags & XFS_XFLAG_IXUNLINK)
7755 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7756         if (xflags & XFS_XFLAG_APPEND)
7757                 di_flags |= XFS_DIFLAG_APPEND;
7758         if (xflags & XFS_XFLAG_SYNC)
7759 @@ -870,6 +877,10 @@ xfs_diflags_to_linux(
7760                 inode->i_flags |= S_IMMUTABLE;
7761         else
7762                 inode->i_flags &= ~S_IMMUTABLE;
7763 +       if (xflags & XFS_XFLAG_IXUNLINK)
7764 +               inode->i_flags |= S_IXUNLINK;
7765 +       else
7766 +               inode->i_flags &= ~S_IXUNLINK;
7767         if (xflags & XFS_XFLAG_APPEND)
7768                 inode->i_flags |= S_APPEND;
7769         else
7770 @@ -1346,10 +1357,18 @@ xfs_file_ioctl(
7771         case XFS_IOC_FSGETXATTRA:
7772                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7773         case XFS_IOC_FSSETXATTR:
7774 +               if (IS_BARRIER(inode)) {
7775 +                       vxwprintk_task(1, "messing with the barrier.");
7776 +                       return -XFS_ERROR(EACCES);
7777 +               }
7778                 return xfs_ioc_fssetxattr(ip, filp, arg);
7779         case XFS_IOC_GETXFLAGS:
7780                 return xfs_ioc_getxflags(ip, arg);
7781         case XFS_IOC_SETXFLAGS:
7782 +               if (IS_BARRIER(inode)) {
7783 +                       vxwprintk_task(1, "messing with the barrier.");
7784 +                       return -XFS_ERROR(EACCES);
7785 +               }
7786                 return xfs_ioc_setxflags(ip, filp, arg);
7787  
7788         case XFS_IOC_FSSETDM: {
7789 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/linux-2.6/xfs_ioctl.h
7790 --- linux-2.6.32.10/fs/xfs/linux-2.6/xfs_ioctl.h        2009-03-24 14:22:37.000000000 +0100
7791 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/linux-2.6/xfs_ioctl.h        2009-12-03 20:04:56.000000000 +0100
7792 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7793         void __user             *uhandle,
7794         u32                     hlen);
7795  
7796 +extern int
7797 +xfs_sync_flags(
7798 +       struct inode            *inode,
7799 +       int                     flags,
7800 +       int                     vflags);
7801 +
7802  extern long
7803  xfs_file_ioctl(
7804         struct file             *filp,
7805 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/linux-2.6/xfs_iops.c
7806 --- linux-2.6.32.10/fs/xfs/linux-2.6/xfs_iops.c 2009-12-03 20:02:53.000000000 +0100
7807 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/linux-2.6/xfs_iops.c 2009-12-03 20:04:56.000000000 +0100
7808 @@ -36,6 +36,7 @@
7809  #include "xfs_attr_sf.h"
7810  #include "xfs_dinode.h"
7811  #include "xfs_inode.h"
7812 +#include "xfs_ioctl.h"
7813  #include "xfs_bmap.h"
7814  #include "xfs_btree.h"
7815  #include "xfs_ialloc.h"
7816 @@ -55,6 +56,7 @@
7817  #include <linux/security.h>
7818  #include <linux/falloc.h>
7819  #include <linux/fiemap.h>
7820 +#include <linux/vs_tag.h>
7821  
7822  /*
7823   * Bring the timestamps in the XFS inode uptodate.
7824 @@ -495,6 +497,7 @@ xfs_vn_getattr(
7825         stat->nlink = ip->i_d.di_nlink;
7826         stat->uid = ip->i_d.di_uid;
7827         stat->gid = ip->i_d.di_gid;
7828 +       stat->tag = ip->i_d.di_tag;
7829         stat->ino = ip->i_ino;
7830         stat->atime = inode->i_atime;
7831         stat->mtime = inode->i_mtime;
7832 @@ -686,6 +689,7 @@ static const struct inode_operations xfs
7833         .listxattr              = xfs_vn_listxattr,
7834         .fallocate              = xfs_vn_fallocate,
7835         .fiemap                 = xfs_vn_fiemap,
7836 +       .sync_flags             = xfs_sync_flags,
7837  };
7838  
7839  static const struct inode_operations xfs_dir_inode_operations = {
7840 @@ -711,6 +715,7 @@ static const struct inode_operations xfs
7841         .getxattr               = generic_getxattr,
7842         .removexattr            = generic_removexattr,
7843         .listxattr              = xfs_vn_listxattr,
7844 +       .sync_flags             = xfs_sync_flags,
7845  };
7846  
7847  static const struct inode_operations xfs_dir_ci_inode_operations = {
7848 @@ -760,6 +765,10 @@ xfs_diflags_to_iflags(
7849                 inode->i_flags |= S_IMMUTABLE;
7850         else
7851                 inode->i_flags &= ~S_IMMUTABLE;
7852 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7853 +               inode->i_flags |= S_IXUNLINK;
7854 +       else
7855 +               inode->i_flags &= ~S_IXUNLINK;
7856         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7857                 inode->i_flags |= S_APPEND;
7858         else
7859 @@ -772,6 +781,15 @@ xfs_diflags_to_iflags(
7860                 inode->i_flags |= S_NOATIME;
7861         else
7862                 inode->i_flags &= ~S_NOATIME;
7863 +
7864 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7865 +               inode->i_vflags |= V_BARRIER;
7866 +       else
7867 +               inode->i_vflags &= ~V_BARRIER;
7868 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7869 +               inode->i_vflags |= V_COW;
7870 +       else
7871 +               inode->i_vflags &= ~V_COW;
7872  }
7873  
7874  /*
7875 @@ -800,6 +818,7 @@ xfs_setup_inode(
7876         inode->i_nlink  = ip->i_d.di_nlink;
7877         inode->i_uid    = ip->i_d.di_uid;
7878         inode->i_gid    = ip->i_d.di_gid;
7879 +       inode->i_tag    = ip->i_d.di_tag;
7880  
7881         switch (inode->i_mode & S_IFMT) {
7882         case S_IFBLK:
7883 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/linux-2.6/xfs_linux.h
7884 --- linux-2.6.32.10/fs/xfs/linux-2.6/xfs_linux.h        2009-09-10 15:26:24.000000000 +0200
7885 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/linux-2.6/xfs_linux.h        2009-12-03 20:04:56.000000000 +0100
7886 @@ -119,6 +119,7 @@
7887  
7888  #define current_cpu()          (raw_smp_processor_id())
7889  #define current_pid()          (current->pid)
7890 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
7891  #define current_test_flags(f)  (current->flags & (f))
7892  #define current_set_flags_nested(sp, f)                \
7893                 (*(sp) = current->flags, current->flags |= (f))
7894 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/linux-2.6/xfs_super.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/linux-2.6/xfs_super.c
7895 --- linux-2.6.32.10/fs/xfs/linux-2.6/xfs_super.c        2009-12-03 20:02:53.000000000 +0100
7896 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/linux-2.6/xfs_super.c        2009-12-03 20:04:56.000000000 +0100
7897 @@ -117,6 +117,9 @@ mempool_t *xfs_ioend_pool;
7898  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
7899  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
7900  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
7901 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7902 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7903 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7904  
7905  /*
7906   * Table driven mount option parser.
7907 @@ -125,10 +128,14 @@ mempool_t *xfs_ioend_pool;
7908   * in the future, too.
7909   */
7910  enum {
7911 +       Opt_tag, Opt_notag,
7912         Opt_barrier, Opt_nobarrier, Opt_err
7913  };
7914  
7915  static const match_table_t tokens = {
7916 +       {Opt_tag, "tagxid"},
7917 +       {Opt_tag, "tag"},
7918 +       {Opt_notag, "notag"},
7919         {Opt_barrier, "barrier"},
7920         {Opt_nobarrier, "nobarrier"},
7921         {Opt_err, NULL}
7922 @@ -382,6 +389,19 @@ xfs_parseargs(
7923                 } else if (!strcmp(this_char, "irixsgid")) {
7924                         cmn_err(CE_WARN,
7925         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7926 +#ifndef CONFIG_TAGGING_NONE
7927 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7928 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7929 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7930 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7931 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7932 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7933 +#endif
7934 +#ifdef CONFIG_PROPAGATE
7935 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7936 +                       /* use value */
7937 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7938 +#endif
7939                 } else {
7940                         cmn_err(CE_WARN,
7941                                 "XFS: unknown mount option [%s].", this_char);
7942 @@ -1270,6 +1290,16 @@ xfs_fs_remount(
7943                 case Opt_nobarrier:
7944                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7945                         break;
7946 +               case Opt_tag:
7947 +                       if (!(sb->s_flags & MS_TAGGED)) {
7948 +                               printk(KERN_INFO
7949 +                                       "XFS: %s: tagging not permitted on remount.\n",
7950 +                                       sb->s_id);
7951 +                               return -EINVAL;
7952 +                       }
7953 +                       break;
7954 +               case Opt_notag:
7955 +                       break;
7956                 default:
7957                         /*
7958                          * Logically we would return an error here to prevent
7959 @@ -1477,6 +1507,9 @@ xfs_fs_fill_super(
7960  
7961         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
7962  
7963 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7964 +               sb->s_flags |= MS_TAGGED;
7965 +
7966         sb->s_magic = XFS_SB_MAGIC;
7967         sb->s_blocksize = mp->m_sb.sb_blocksize;
7968         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
7969 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/xfs_dinode.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_dinode.h
7970 --- linux-2.6.32.10/fs/xfs/xfs_dinode.h 2009-06-11 17:13:09.000000000 +0200
7971 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_dinode.h 2009-12-03 20:04:56.000000000 +0100
7972 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
7973         __be32          di_gid;         /* owner's group id */
7974         __be32          di_nlink;       /* number of links to file */
7975         __be16          di_projid;      /* owner's project id */
7976 -       __u8            di_pad[8];      /* unused, zeroed space */
7977 +       __be16          di_tag;         /* context tagging */
7978 +       __be16          di_vflags;      /* vserver specific flags */
7979 +       __u8            di_pad[4];      /* unused, zeroed space */
7980         __be16          di_flushiter;   /* incremented on flush */
7981         xfs_timestamp_t di_atime;       /* time last accessed */
7982         xfs_timestamp_t di_mtime;       /* time last modified */
7983 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
7984  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7985  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7986  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7987 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7988 +
7989  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7990  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7991  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7992 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
7993  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7994  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7995  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7996 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7997  
7998  #ifdef CONFIG_XFS_RT
7999  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8000 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
8001          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8002          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8003          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8004 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8005 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8006 +        XFS_DIFLAG_IXUNLINK)
8007 +
8008 +#define XFS_DIVFLAG_BARRIER    0x01
8009 +#define XFS_DIVFLAG_COW                0x02
8010  
8011  #endif /* __XFS_DINODE_H__ */
8012 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/xfs_fs.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_fs.h
8013 --- linux-2.6.32.10/fs/xfs/xfs_fs.h     2009-12-03 20:02:53.000000000 +0100
8014 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_fs.h     2009-12-03 20:04:56.000000000 +0100
8015 @@ -67,6 +67,9 @@ struct fsxattr {
8016  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8017  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8018  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8019 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8020 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8021 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8022  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8023  
8024  /*
8025 @@ -292,7 +295,8 @@ typedef struct xfs_bstat {
8026         __s32           bs_extents;     /* number of extents            */
8027         __u32           bs_gen;         /* generation count             */
8028         __u16           bs_projid;      /* project id                   */
8029 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8030 +       __u16           bs_tag;         /* context tagging              */
8031 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8032         __u32           bs_dmevmask;    /* DMIG event mask              */
8033         __u16           bs_dmstate;     /* DMIG state info              */
8034         __u16           bs_aextents;    /* attribute number of extents  */
8035 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/xfs_ialloc.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_ialloc.c
8036 --- linux-2.6.32.10/fs/xfs/xfs_ialloc.c 2009-12-03 20:02:53.000000000 +0100
8037 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_ialloc.c 2009-12-03 20:04:56.000000000 +0100
8038 @@ -41,7 +41,6 @@
8039  #include "xfs_error.h"
8040  #include "xfs_bmap.h"
8041  
8042 -
8043  /*
8044   * Allocation group level functions.
8045   */
8046 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/xfs_inode.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_inode.c
8047 --- linux-2.6.32.10/fs/xfs/xfs_inode.c  2009-12-03 20:02:54.000000000 +0100
8048 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_inode.c  2009-12-03 20:04:56.000000000 +0100
8049 @@ -249,6 +249,7 @@ xfs_inotobp(
8050         return 0;
8051  }
8052  
8053 +#include <linux/vs_tag.h>
8054  
8055  /*
8056   * This routine is called to map an inode to the buffer containing
8057 @@ -654,15 +655,25 @@ xfs_iformat_btree(
8058  STATIC void
8059  xfs_dinode_from_disk(
8060         xfs_icdinode_t          *to,
8061 -       xfs_dinode_t            *from)
8062 +       xfs_dinode_t            *from,
8063 +       int tagged)
8064  {
8065 +       uint32_t uid, gid, tag;
8066 +
8067         to->di_magic = be16_to_cpu(from->di_magic);
8068         to->di_mode = be16_to_cpu(from->di_mode);
8069         to->di_version = from ->di_version;
8070         to->di_format = from->di_format;
8071         to->di_onlink = be16_to_cpu(from->di_onlink);
8072 -       to->di_uid = be32_to_cpu(from->di_uid);
8073 -       to->di_gid = be32_to_cpu(from->di_gid);
8074 +
8075 +       uid = be32_to_cpu(from->di_uid);
8076 +       gid = be32_to_cpu(from->di_gid);
8077 +       tag = be16_to_cpu(from->di_tag);
8078 +
8079 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8080 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8081 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8082 +
8083         to->di_nlink = be32_to_cpu(from->di_nlink);
8084         to->di_projid = be16_to_cpu(from->di_projid);
8085         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8086 @@ -683,21 +694,26 @@ xfs_dinode_from_disk(
8087         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8088         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8089         to->di_flags    = be16_to_cpu(from->di_flags);
8090 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8091         to->di_gen      = be32_to_cpu(from->di_gen);
8092  }
8093  
8094  void
8095  xfs_dinode_to_disk(
8096         xfs_dinode_t            *to,
8097 -       xfs_icdinode_t          *from)
8098 +       xfs_icdinode_t          *from,
8099 +       int tagged)
8100  {
8101         to->di_magic = cpu_to_be16(from->di_magic);
8102         to->di_mode = cpu_to_be16(from->di_mode);
8103         to->di_version = from ->di_version;
8104         to->di_format = from->di_format;
8105         to->di_onlink = cpu_to_be16(from->di_onlink);
8106 -       to->di_uid = cpu_to_be32(from->di_uid);
8107 -       to->di_gid = cpu_to_be32(from->di_gid);
8108 +
8109 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8110 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8111 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8112 +
8113         to->di_nlink = cpu_to_be32(from->di_nlink);
8114         to->di_projid = cpu_to_be16(from->di_projid);
8115         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8116 @@ -718,12 +734,14 @@ xfs_dinode_to_disk(
8117         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8118         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8119         to->di_flags = cpu_to_be16(from->di_flags);
8120 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8121         to->di_gen = cpu_to_be32(from->di_gen);
8122  }
8123  
8124  STATIC uint
8125  _xfs_dic2xflags(
8126 -       __uint16_t              di_flags)
8127 +       __uint16_t              di_flags,
8128 +       __uint16_t              di_vflags)
8129  {
8130         uint                    flags = 0;
8131  
8132 @@ -734,6 +752,8 @@ _xfs_dic2xflags(
8133                         flags |= XFS_XFLAG_PREALLOC;
8134                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8135                         flags |= XFS_XFLAG_IMMUTABLE;
8136 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8137 +                       flags |= XFS_XFLAG_IXUNLINK;
8138                 if (di_flags & XFS_DIFLAG_APPEND)
8139                         flags |= XFS_XFLAG_APPEND;
8140                 if (di_flags & XFS_DIFLAG_SYNC)
8141 @@ -758,6 +778,10 @@ _xfs_dic2xflags(
8142                         flags |= XFS_XFLAG_FILESTREAM;
8143         }
8144  
8145 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8146 +               flags |= FS_BARRIER_FL;
8147 +       if (di_vflags & XFS_DIVFLAG_COW)
8148 +               flags |= FS_COW_FL;
8149         return flags;
8150  }
8151  
8152 @@ -767,7 +791,7 @@ xfs_ip2xflags(
8153  {
8154         xfs_icdinode_t          *dic = &ip->i_d;
8155  
8156 -       return _xfs_dic2xflags(dic->di_flags) |
8157 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8158                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8159  }
8160  
8161 @@ -775,7 +799,8 @@ uint
8162  xfs_dic2xflags(
8163         xfs_dinode_t            *dip)
8164  {
8165 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8166 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8167 +                               be16_to_cpu(dip->di_vflags)) |
8168                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8169  }
8170  
8171 @@ -811,7 +836,6 @@ xfs_iread(
8172         if (error)
8173                 return error;
8174         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8175 -
8176         /*
8177          * If we got something that isn't an inode it means someone
8178          * (nfs or dmi) has a stale handle.
8179 @@ -836,7 +860,8 @@ xfs_iread(
8180          * Otherwise, just get the truly permanent information.
8181          */
8182         if (dip->di_mode) {
8183 -               xfs_dinode_from_disk(&ip->i_d, dip);
8184 +               xfs_dinode_from_disk(&ip->i_d, dip,
8185 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8186                 error = xfs_iformat(ip, dip);
8187                 if (error)  {
8188  #ifdef DEBUG
8189 @@ -1036,6 +1061,7 @@ xfs_ialloc(
8190         ASSERT(ip->i_d.di_nlink == nlink);
8191         ip->i_d.di_uid = current_fsuid();
8192         ip->i_d.di_gid = current_fsgid();
8193 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8194         ip->i_d.di_projid = prid;
8195         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8196  
8197 @@ -1096,6 +1122,7 @@ xfs_ialloc(
8198         ip->i_d.di_dmevmask = 0;
8199         ip->i_d.di_dmstate = 0;
8200         ip->i_d.di_flags = 0;
8201 +       ip->i_d.di_vflags = 0;
8202         flags = XFS_ILOG_CORE;
8203         switch (mode & S_IFMT) {
8204         case S_IFIFO:
8205 @@ -2172,6 +2199,7 @@ xfs_ifree(
8206         }
8207         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8208         ip->i_d.di_flags = 0;
8209 +       ip->i_d.di_vflags = 0;
8210         ip->i_d.di_dmevmask = 0;
8211         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8212         ip->i_df.if_ext_max =
8213 @@ -3139,7 +3167,8 @@ xfs_iflush_int(
8214          * because if the inode is dirty at all the core must
8215          * be.
8216          */
8217 -       xfs_dinode_to_disk(dip, &ip->i_d);
8218 +       xfs_dinode_to_disk(dip, &ip->i_d,
8219 +               mp->m_flags & XFS_MOUNT_TAGGED);
8220  
8221         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8222         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8223 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/xfs_inode.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_inode.h
8224 --- linux-2.6.32.10/fs/xfs/xfs_inode.h  2009-12-03 20:02:54.000000000 +0100
8225 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_inode.h  2009-12-03 20:04:56.000000000 +0100
8226 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8227         __uint32_t      di_gid;         /* owner's group id */
8228         __uint32_t      di_nlink;       /* number of links to file */
8229         __uint16_t      di_projid;      /* owner's project id */
8230 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8231 +       __uint16_t      di_tag;         /* context tagging */
8232 +       __uint16_t      di_vflags;      /* vserver specific flags */
8233 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8234         __uint16_t      di_flushiter;   /* incremented on flush */
8235         xfs_ictimestamp_t di_atime;     /* time last accessed */
8236         xfs_ictimestamp_t di_mtime;     /* time last modified */
8237 @@ -569,7 +571,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8238  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8239                           struct xfs_inode *, xfs_daddr_t, uint);
8240  void           xfs_dinode_to_disk(struct xfs_dinode *,
8241 -                                  struct xfs_icdinode *);
8242 +                                  struct xfs_icdinode *, int);
8243  void           xfs_idestroy_fork(struct xfs_inode *, int);
8244  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8245  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8246 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/xfs_itable.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_itable.c
8247 --- linux-2.6.32.10/fs/xfs/xfs_itable.c 2009-12-03 20:02:54.000000000 +0100
8248 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_itable.c 2009-12-03 20:04:56.000000000 +0100
8249 @@ -84,6 +84,7 @@ xfs_bulkstat_one_iget(
8250         buf->bs_mode = dic->di_mode;
8251         buf->bs_uid = dic->di_uid;
8252         buf->bs_gid = dic->di_gid;
8253 +       buf->bs_tag = dic->di_tag;
8254         buf->bs_size = dic->di_size;
8255  
8256         /*
8257 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/xfs_log_recover.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_log_recover.c
8258 --- linux-2.6.32.10/fs/xfs/xfs_log_recover.c    2009-12-03 20:02:54.000000000 +0100
8259 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_log_recover.c    2009-12-03 20:04:56.000000000 +0100
8260 @@ -2467,7 +2467,8 @@ xlog_recover_do_inode_trans(
8261         }
8262  
8263         /* The core is in in-core format */
8264 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8265 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8266 +               mp->m_flags & XFS_MOUNT_TAGGED);
8267  
8268         /* the rest is in on-disk format */
8269         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8270 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/xfs_mount.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_mount.h
8271 --- linux-2.6.32.10/fs/xfs/xfs_mount.h  2009-12-03 20:02:54.000000000 +0100
8272 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_mount.h  2009-12-03 20:04:56.000000000 +0100
8273 @@ -283,6 +283,7 @@ typedef struct xfs_mount {
8274                                                    allocator */
8275  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8276  
8277 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8278  
8279  /*
8280   * Default minimum read and write sizes.
8281 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/xfs_vnodeops.c linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_vnodeops.c
8282 --- linux-2.6.32.10/fs/xfs/xfs_vnodeops.c       2009-12-03 20:02:54.000000000 +0100
8283 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_vnodeops.c       2009-12-03 20:04:56.000000000 +0100
8284 @@ -54,6 +54,80 @@
8285  #include "xfs_filestream.h"
8286  #include "xfs_vnodeops.h"
8287  
8288 +
8289 +STATIC void
8290 +xfs_get_inode_flags(
8291 +       xfs_inode_t     *ip)
8292 +{
8293 +       struct inode    *inode = VFS_I(ip);
8294 +       unsigned int    flags = inode->i_flags;
8295 +       unsigned int    vflags = inode->i_vflags;
8296 +
8297 +       if (flags & S_IMMUTABLE)
8298 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8299 +       else
8300 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8301 +       if (flags & S_IXUNLINK)
8302 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8303 +       else
8304 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8305 +
8306 +       if (vflags & V_BARRIER)
8307 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8308 +       else
8309 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8310 +       if (vflags & V_COW)
8311 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8312 +       else
8313 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8314 +}
8315 +
8316 +int
8317 +xfs_sync_flags(
8318 +       struct inode            *inode,
8319 +       int                     flags,
8320 +       int                     vflags)
8321 +{
8322 +       struct xfs_inode        *ip = XFS_I(inode);
8323 +       struct xfs_mount        *mp = ip->i_mount;
8324 +       struct xfs_trans        *tp;
8325 +       unsigned int            lock_flags = 0;
8326 +       int                     code;
8327 +
8328 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8329 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8330 +       if (code)
8331 +               goto error_out;
8332 +
8333 +       lock_flags = XFS_ILOCK_EXCL;
8334 +       xfs_ilock(ip, lock_flags);
8335 +
8336 +       xfs_trans_ijoin(tp, ip, lock_flags);
8337 +       xfs_trans_ihold(tp, ip);
8338 +
8339 +       inode->i_flags = flags;
8340 +       inode->i_vflags = vflags;
8341 +       xfs_get_inode_flags(ip);
8342 +
8343 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8344 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8345 +
8346 +       XFS_STATS_INC(xs_ig_attrchg);
8347 +
8348 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8349 +               xfs_trans_set_sync(tp);
8350 +       code = xfs_trans_commit(tp, 0);
8351 +       xfs_iunlock(ip, lock_flags);
8352 +       return code;
8353 +
8354 +error_out:
8355 +       xfs_trans_cancel(tp, 0);
8356 +       if (lock_flags)
8357 +               xfs_iunlock(ip, lock_flags);
8358 +       return code;
8359 +}
8360 +
8361 +
8362  int
8363  xfs_setattr(
8364         struct xfs_inode        *ip,
8365 @@ -69,6 +143,7 @@ xfs_setattr(
8366         uint                    commit_flags=0;
8367         uid_t                   uid=0, iuid=0;
8368         gid_t                   gid=0, igid=0;
8369 +       tag_t                   tag=0, itag=0;
8370         int                     timeflags = 0;
8371         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8372         int                     need_iolock = 1;
8373 @@ -165,7 +240,7 @@ xfs_setattr(
8374         /*
8375          * Change file ownership.  Must be the owner or privileged.
8376          */
8377 -       if (mask & (ATTR_UID|ATTR_GID)) {
8378 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8379                 /*
8380                  * These IDs could have changed since we last looked at them.
8381                  * But, we're assured that if the ownership did change
8382 @@ -174,8 +249,10 @@ xfs_setattr(
8383                  */
8384                 iuid = ip->i_d.di_uid;
8385                 igid = ip->i_d.di_gid;
8386 +               itag = ip->i_d.di_tag;
8387                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8388                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8389 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8390  
8391                 /*
8392                  * Do a quota reservation only if uid/gid is actually
8393 @@ -183,7 +260,8 @@ xfs_setattr(
8394                  */
8395                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8396                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8397 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8398 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8399 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8400                         ASSERT(tp);
8401                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8402                                                 capable(CAP_FOWNER) ?
8403 @@ -336,7 +414,7 @@ xfs_setattr(
8404         /*
8405          * Change file ownership.  Must be the owner or privileged.
8406          */
8407 -       if (mask & (ATTR_UID|ATTR_GID)) {
8408 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8409                 /*
8410                  * CAP_FSETID overrides the following restrictions:
8411                  *
8412 @@ -352,6 +430,10 @@ xfs_setattr(
8413                  * Change the ownerships and register quota modifications
8414                  * in the transaction.
8415                  */
8416 +               if (itag != tag) {
8417 +                       ip->i_d.di_tag = tag;
8418 +                       inode->i_tag = tag;
8419 +               }
8420                 if (iuid != uid) {
8421                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8422                                 ASSERT(mask & ATTR_UID);
8423 diff -NurpP --minimal linux-2.6.32.10/fs/xfs/xfs_vnodeops.h linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_vnodeops.h
8424 --- linux-2.6.32.10/fs/xfs/xfs_vnodeops.h       2009-09-10 15:26:24.000000000 +0200
8425 +++ linux-2.6.32.10-vs2.3.0.36.29.2/fs/xfs/xfs_vnodeops.h       2009-12-03 20:04:56.000000000 +0100
8426 @@ -14,6 +14,7 @@ struct xfs_inode;
8427  struct xfs_iomap;
8428  
8429  
8430 +int xfs_sync_xflags(struct xfs_inode *ip);
8431  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8432  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8433  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8434 diff -NurpP --minimal linux-2.6.32.10/include/asm-generic/tlb.h linux-2.6.32.10-vs2.3.0.36.29.2/include/asm-generic/tlb.h
8435 --- linux-2.6.32.10/include/asm-generic/tlb.h   2009-09-10 15:26:24.000000000 +0200
8436 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/asm-generic/tlb.h   2009-12-03 20:04:56.000000000 +0100
8437 @@ -14,6 +14,7 @@
8438  #define _ASM_GENERIC__TLB_H
8439  
8440  #include <linux/swap.h>
8441 +#include <linux/vs_memory.h>
8442  #include <asm/pgalloc.h>
8443  #include <asm/tlbflush.h>
8444  
8445 diff -NurpP --minimal linux-2.6.32.10/include/linux/capability.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/capability.h
8446 --- linux-2.6.32.10/include/linux/capability.h  2009-12-03 20:02:54.000000000 +0100
8447 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/capability.h  2009-12-03 20:04:56.000000000 +0100
8448 @@ -285,6 +285,7 @@ struct cpu_vfs_cap_data {
8449     arbitrary SCSI commands */
8450  /* Allow setting encryption key on loopback filesystem */
8451  /* Allow setting zone reclaim policy */
8452 +/* Allow the selection of a security context */
8453  
8454  #define CAP_SYS_ADMIN        21
8455  
8456 @@ -357,7 +358,13 @@ struct cpu_vfs_cap_data {
8457  
8458  #define CAP_MAC_ADMIN        33
8459  
8460 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8461 +/* Allow context manipulations */
8462 +/* Allow changing context info on files */
8463 +
8464 +#define CAP_CONTEXT         34
8465 +
8466 +
8467 +#define CAP_LAST_CAP         CAP_CONTEXT
8468  
8469  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8470  
8471 diff -NurpP --minimal linux-2.6.32.10/include/linux/devpts_fs.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/devpts_fs.h
8472 --- linux-2.6.32.10/include/linux/devpts_fs.h   2008-12-25 00:26:37.000000000 +0100
8473 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/devpts_fs.h   2009-12-03 20:04:56.000000000 +0100
8474 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8475  
8476  #endif
8477  
8478 -
8479  #endif /* _LINUX_DEVPTS_FS_H */
8480 diff -NurpP --minimal linux-2.6.32.10/include/linux/ext2_fs.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/ext2_fs.h
8481 --- linux-2.6.32.10/include/linux/ext2_fs.h     2009-03-24 14:22:41.000000000 +0100
8482 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/ext2_fs.h     2009-12-03 20:04:56.000000000 +0100
8483 @@ -189,8 +189,12 @@ struct ext2_group_desc
8484  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8485  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8486  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8487 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8488  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8489  
8490 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8491 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8492 +
8493  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8494  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8495  
8496 @@ -274,7 +278,8 @@ struct ext2_inode {
8497                         __u16   i_pad1;
8498                         __le16  l_i_uid_high;   /* these 2 fields    */
8499                         __le16  l_i_gid_high;   /* were reserved2[0] */
8500 -                       __u32   l_i_reserved2;
8501 +                       __le16  l_i_tag;        /* Context Tag */
8502 +                       __u16   l_i_reserved2;
8503                 } linux2;
8504                 struct {
8505                         __u8    h_i_frag;       /* Fragment number */
8506 @@ -303,6 +308,7 @@ struct ext2_inode {
8507  #define i_gid_low      i_gid
8508  #define i_uid_high     osd2.linux2.l_i_uid_high
8509  #define i_gid_high     osd2.linux2.l_i_gid_high
8510 +#define i_raw_tag      osd2.linux2.l_i_tag
8511  #define i_reserved2    osd2.linux2.l_i_reserved2
8512  #endif
8513  
8514 @@ -347,6 +353,7 @@ struct ext2_inode {
8515  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8516  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8517  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8518 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8519  
8520  
8521  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8522 diff -NurpP --minimal linux-2.6.32.10/include/linux/ext3_fs.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/ext3_fs.h
8523 --- linux-2.6.32.10/include/linux/ext3_fs.h     2009-09-10 15:26:25.000000000 +0200
8524 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/ext3_fs.h     2009-12-03 20:04:56.000000000 +0100
8525 @@ -173,10 +173,14 @@ struct ext3_group_desc
8526  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8527  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8528  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8529 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8530  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8531  
8532 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8533 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8534 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8535 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8536 +
8537 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8538 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8539  
8540  /* Flags that should be inherited by new inodes from their parent. */
8541  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8542 @@ -320,7 +324,8 @@ struct ext3_inode {
8543                         __u16   i_pad1;
8544                         __le16  l_i_uid_high;   /* these 2 fields    */
8545                         __le16  l_i_gid_high;   /* were reserved2[0] */
8546 -                       __u32   l_i_reserved2;
8547 +                       __le16  l_i_tag;        /* Context Tag */
8548 +                       __u16   l_i_reserved2;
8549                 } linux2;
8550                 struct {
8551                         __u8    h_i_frag;       /* Fragment number */
8552 @@ -351,6 +356,7 @@ struct ext3_inode {
8553  #define i_gid_low      i_gid
8554  #define i_uid_high     osd2.linux2.l_i_uid_high
8555  #define i_gid_high     osd2.linux2.l_i_gid_high
8556 +#define i_raw_tag      osd2.linux2.l_i_tag
8557  #define i_reserved2    osd2.linux2.l_i_reserved2
8558  
8559  #elif defined(__GNU__)
8560 @@ -414,6 +420,7 @@ struct ext3_inode {
8561  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8562  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8563                                                   * error in ordered mode */
8564 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8565  
8566  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8567  #ifndef _LINUX_EXT2_FS_H
8568 @@ -892,6 +899,7 @@ extern void ext3_get_inode_flags(struct 
8569  extern void ext3_set_aops(struct inode *inode);
8570  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8571                        u64 start, u64 len);
8572 +extern int ext3_sync_flags(struct inode *, int, int);
8573  
8574  /* ioctl.c */
8575  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8576 diff -NurpP --minimal linux-2.6.32.10/include/linux/fs.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/fs.h
8577 --- linux-2.6.32.10/include/linux/fs.h  2010-03-18 16:17:37.000000000 +0100
8578 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/fs.h  2010-03-18 16:53:06.000000000 +0100
8579 @@ -208,6 +208,9 @@ struct inodes_stat_t {
8580  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8581  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8582  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8583 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8584 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8585 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8586  #define MS_ACTIVE      (1<<30)
8587  #define MS_NOUSER      (1<<31)
8588  
8589 @@ -234,6 +237,14 @@ struct inodes_stat_t {
8590  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8591  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8592  #define S_PRIVATE      512     /* Inode is fs-internal */
8593 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8594 +
8595 +/* Linux-VServer related Inode flags */
8596 +
8597 +#define V_VALID                1
8598 +#define V_XATTR                2
8599 +#define V_BARRIER      4       /* Barrier for chroot() */
8600 +#define V_COW          8       /* Copy on Write */
8601  
8602  /*
8603   * Note that nosuid etc flags are inode-specific: setting some file-system
8604 @@ -256,12 +267,15 @@ struct inodes_stat_t {
8605  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8606                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8607  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8608 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8609 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8610 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8611 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8612 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8613  
8614  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8615  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8616  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8617 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8618 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8619  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8620  
8621  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8622 @@ -269,6 +283,16 @@ struct inodes_stat_t {
8623  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8624  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8625  
8626 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8627 +
8628 +#ifdef CONFIG_VSERVER_COWBL
8629 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8630 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8631 +#else
8632 +#  define IS_COW(inode)                (0)
8633 +#  define IS_COW_LINK(inode)   (0)
8634 +#endif
8635 +
8636  /* the read-only stuff doesn't really belong here, but any other place is
8637     probably as bad and I don't want to create yet another include file. */
8638  
8639 @@ -350,11 +374,14 @@ struct inodes_stat_t {
8640  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8641  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8642  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8643 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8644  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8645  
8646 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8647 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8648 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8649 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8650  
8651 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8652 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8653  
8654  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8655  #define SYNC_FILE_RANGE_WRITE          2
8656 @@ -436,6 +463,7 @@ typedef void (dio_iodone_t)(struct kiocb
8657  #define ATTR_KILL_PRIV (1 << 14)
8658  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8659  #define ATTR_TIMES_SET (1 << 16)
8660 +#define ATTR_TAG       (1 << 17)
8661  
8662  /*
8663   * This is the Inode Attributes structure, used for notify_change().  It
8664 @@ -451,6 +479,7 @@ struct iattr {
8665         umode_t         ia_mode;
8666         uid_t           ia_uid;
8667         gid_t           ia_gid;
8668 +       tag_t           ia_tag;
8669         loff_t          ia_size;
8670         struct timespec ia_atime;
8671         struct timespec ia_mtime;
8672 @@ -464,6 +493,9 @@ struct iattr {
8673         struct file     *ia_file;
8674  };
8675  
8676 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8677 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8678 +
8679  /*
8680   * Includes for diskquotas.
8681   */
8682 @@ -729,7 +761,9 @@ struct inode {
8683         unsigned int            i_nlink;
8684         uid_t                   i_uid;
8685         gid_t                   i_gid;
8686 +       tag_t                   i_tag;
8687         dev_t                   i_rdev;
8688 +       dev_t                   i_mdev;
8689         u64                     i_version;
8690         loff_t                  i_size;
8691  #ifdef __NEED_I_SIZE_ORDERED
8692 @@ -776,7 +810,8 @@ struct inode {
8693         unsigned long           i_state;
8694         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8695  
8696 -       unsigned int            i_flags;
8697 +       unsigned short          i_flags;
8698 +       unsigned short          i_vflags;
8699  
8700         atomic_t                i_writecount;
8701  #ifdef CONFIG_SECURITY
8702 @@ -864,12 +899,12 @@ static inline void i_size_write(struct i
8703  
8704  static inline unsigned iminor(const struct inode *inode)
8705  {
8706 -       return MINOR(inode->i_rdev);
8707 +       return MINOR(inode->i_mdev);
8708  }
8709  
8710  static inline unsigned imajor(const struct inode *inode)
8711  {
8712 -       return MAJOR(inode->i_rdev);
8713 +       return MAJOR(inode->i_mdev);
8714  }
8715  
8716  extern struct block_device *I_BDEV(struct inode *inode);
8717 @@ -928,6 +963,7 @@ struct file {
8718         loff_t                  f_pos;
8719         struct fown_struct      f_owner;
8720         const struct cred       *f_cred;
8721 +       xid_t                   f_xid;
8722         struct file_ra_state    f_ra;
8723  
8724         u64                     f_version;
8725 @@ -1069,6 +1105,7 @@ struct file_lock {
8726         struct file *fl_file;
8727         loff_t fl_start;
8728         loff_t fl_end;
8729 +       xid_t fl_xid;
8730  
8731         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8732         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8733 @@ -1534,6 +1571,7 @@ struct inode_operations {
8734         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8735         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8736         int (*removexattr) (struct dentry *, const char *);
8737 +       int (*sync_flags) (struct inode *, int, int);
8738         void (*truncate_range)(struct inode *, loff_t, loff_t);
8739         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8740                           loff_t len);
8741 @@ -1554,6 +1592,7 @@ extern ssize_t vfs_readv(struct file *, 
8742                 unsigned long, loff_t *);
8743  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8744                 unsigned long, loff_t *);
8745 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8746  
8747  struct super_operations {
8748         struct inode *(*alloc_inode)(struct super_block *sb);
8749 @@ -2351,6 +2390,7 @@ extern int dcache_dir_open(struct inode 
8750  extern int dcache_dir_close(struct inode *, struct file *);
8751  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8752  extern int dcache_readdir(struct file *, void *, filldir_t);
8753 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8754  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8755  extern int simple_statfs(struct dentry *, struct kstatfs *);
8756  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8757 diff -NurpP --minimal linux-2.6.32.10/include/linux/gfs2_ondisk.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/gfs2_ondisk.h
8758 --- linux-2.6.32.10/include/linux/gfs2_ondisk.h 2009-12-03 20:02:55.000000000 +0100
8759 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/gfs2_ondisk.h 2009-12-03 20:04:56.000000000 +0100
8760 @@ -235,6 +235,9 @@ enum {
8761         gfs2fl_NoAtime          = 7,
8762         gfs2fl_Sync             = 8,
8763         gfs2fl_System           = 9,
8764 +       gfs2fl_IXUnlink         = 16,
8765 +       gfs2fl_Barrier          = 17,
8766 +       gfs2fl_Cow              = 18,
8767         gfs2fl_TruncInProg      = 29,
8768         gfs2fl_InheritDirectio  = 30,
8769         gfs2fl_InheritJdata     = 31,
8770 @@ -251,6 +254,9 @@ enum {
8771  #define GFS2_DIF_NOATIME               0x00000080
8772  #define GFS2_DIF_SYNC                  0x00000100
8773  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8774 +#define GFS2_DIF_IXUNLINK              0x00010000
8775 +#define GFS2_DIF_BARRIER               0x00020000
8776 +#define GFS2_DIF_COW                   0x00040000
8777  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8778  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8779  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8780 diff -NurpP --minimal linux-2.6.32.10/include/linux/if_tun.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/if_tun.h
8781 --- linux-2.6.32.10/include/linux/if_tun.h      2009-12-03 20:02:55.000000000 +0100
8782 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/if_tun.h      2009-12-03 20:04:56.000000000 +0100
8783 @@ -48,6 +48,7 @@
8784  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8785  #define TUNGETSNDBUF   _IOR('T', 211, int)
8786  #define TUNSETSNDBUF   _IOW('T', 212, int)
8787 +#define TUNSETNID     _IOW('T', 215, int)
8788  
8789  /* TUNSETIFF ifr flags */
8790  #define IFF_TUN                0x0001
8791 diff -NurpP --minimal linux-2.6.32.10/include/linux/init_task.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/init_task.h
8792 --- linux-2.6.32.10/include/linux/init_task.h   2009-12-03 20:02:55.000000000 +0100
8793 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/init_task.h   2009-12-03 20:04:56.000000000 +0100
8794 @@ -184,6 +184,10 @@ extern struct cred init_cred;
8795         INIT_FTRACE_GRAPH                                               \
8796         INIT_TRACE_RECURSION                                            \
8797         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8798 +       .xid            = 0,                                            \
8799 +       .vx_info        = NULL,                                         \
8800 +       .nid            = 0,                                            \
8801 +       .nx_info        = NULL,                                         \
8802  }
8803  
8804  
8805 diff -NurpP --minimal linux-2.6.32.10/include/linux/ipc.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/ipc.h
8806 --- linux-2.6.32.10/include/linux/ipc.h 2009-12-03 20:02:55.000000000 +0100
8807 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/ipc.h 2009-12-03 20:04:56.000000000 +0100
8808 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8809         key_t           key;
8810         uid_t           uid;
8811         gid_t           gid;
8812 +       xid_t           xid;
8813         uid_t           cuid;
8814         gid_t           cgid;
8815         mode_t          mode; 
8816 diff -NurpP --minimal linux-2.6.32.10/include/linux/Kbuild linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/Kbuild
8817 --- linux-2.6.32.10/include/linux/Kbuild        2009-12-03 20:02:54.000000000 +0100
8818 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/Kbuild        2009-12-03 20:04:56.000000000 +0100
8819 @@ -382,5 +382,8 @@ unifdef-y += xattr.h
8820  unifdef-y += xfrm.h
8821  
8822  objhdr-y += version.h
8823 +
8824 +header-y += vserver/
8825  header-y += wimax.h
8826  header-y += wimax/
8827 +
8828 diff -NurpP --minimal linux-2.6.32.10/include/linux/loop.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/loop.h
8829 --- linux-2.6.32.10/include/linux/loop.h        2009-09-10 15:26:25.000000000 +0200
8830 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/loop.h        2009-12-03 20:04:56.000000000 +0100
8831 @@ -45,6 +45,7 @@ struct loop_device {
8832         struct loop_func_table *lo_encryption;
8833         __u32           lo_init[2];
8834         uid_t           lo_key_owner;   /* Who set the key */
8835 +       xid_t           lo_xid;
8836         int             (*ioctl)(struct loop_device *, int cmd, 
8837                                  unsigned long arg); 
8838  
8839 diff -NurpP --minimal linux-2.6.32.10/include/linux/magic.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/magic.h
8840 --- linux-2.6.32.10/include/linux/magic.h       2009-12-03 20:02:55.000000000 +0100
8841 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/magic.h       2009-12-03 20:04:56.000000000 +0100
8842 @@ -3,7 +3,7 @@
8843  
8844  #define ADFS_SUPER_MAGIC       0xadf5
8845  #define AFFS_SUPER_MAGIC       0xadff
8846 -#define AFS_SUPER_MAGIC                0x5346414F
8847 +#define AFS_SUPER_MAGIC                0x5346414F
8848  #define AUTOFS_SUPER_MAGIC     0x0187
8849  #define CODA_SUPER_MAGIC       0x73757245
8850  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8851 @@ -38,6 +38,7 @@
8852  #define NFS_SUPER_MAGIC                0x6969
8853  #define OPENPROM_SUPER_MAGIC   0x9fa1
8854  #define PROC_SUPER_MAGIC       0x9fa0
8855 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8856  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8857  
8858  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8859 diff -NurpP --minimal linux-2.6.32.10/include/linux/major.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/major.h
8860 --- linux-2.6.32.10/include/linux/major.h       2009-09-10 15:26:25.000000000 +0200
8861 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/major.h       2009-12-03 20:04:56.000000000 +0100
8862 @@ -15,6 +15,7 @@
8863  #define HD_MAJOR               IDE0_MAJOR
8864  #define PTY_SLAVE_MAJOR                3
8865  #define TTY_MAJOR              4
8866 +#define VROOT_MAJOR            4
8867  #define TTYAUX_MAJOR           5
8868  #define LP_MAJOR               6
8869  #define VCS_MAJOR              7
8870 diff -NurpP --minimal linux-2.6.32.10/include/linux/memcontrol.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/memcontrol.h
8871 --- linux-2.6.32.10/include/linux/memcontrol.h  2009-12-03 20:02:55.000000000 +0100
8872 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/memcontrol.h  2010-02-05 00:15:49.000000000 +0100
8873 @@ -70,6 +70,13 @@ int task_in_mem_cgroup(struct task_struc
8874  
8875  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8876  
8877 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8878 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8879 +
8880 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8881 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8882 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8883 +
8884  static inline
8885  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8886  {
8887 diff -NurpP --minimal linux-2.6.32.10/include/linux/mm_types.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/mm_types.h
8888 --- linux-2.6.32.10/include/linux/mm_types.h    2009-12-03 20:02:55.000000000 +0100
8889 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/mm_types.h    2009-12-03 20:04:56.000000000 +0100
8890 @@ -246,6 +246,7 @@ struct mm_struct {
8891  
8892         /* Architecture-specific MM context */
8893         mm_context_t context;
8894 +       struct vx_info *mm_vx_info;
8895  
8896         /* Swap token stuff */
8897         /*
8898 diff -NurpP --minimal linux-2.6.32.10/include/linux/mount.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/mount.h
8899 --- linux-2.6.32.10/include/linux/mount.h       2009-09-10 15:26:25.000000000 +0200
8900 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/mount.h       2009-12-03 20:04:56.000000000 +0100
8901 @@ -36,6 +36,9 @@ struct mnt_namespace;
8902  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
8903  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
8904  
8905 +#define MNT_TAGID      0x10000
8906 +#define MNT_NOTAG      0x20000
8907 +
8908  struct vfsmount {
8909         struct list_head mnt_hash;
8910         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8911 @@ -70,6 +73,7 @@ struct vfsmount {
8912  #else
8913         int mnt_writers;
8914  #endif
8915 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8916  };
8917  
8918  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
8919 diff -NurpP --minimal linux-2.6.32.10/include/linux/net.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/net.h
8920 --- linux-2.6.32.10/include/linux/net.h 2009-12-03 20:02:55.000000000 +0100
8921 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/net.h 2009-12-03 20:04:56.000000000 +0100
8922 @@ -69,6 +69,7 @@ struct net;
8923  #define SOCK_NOSPACE           2
8924  #define SOCK_PASSCRED          3
8925  #define SOCK_PASSSEC           4
8926 +#define SOCK_USER_SOCKET       5
8927  
8928  #ifndef ARCH_HAS_SOCKET_TYPES
8929  /**
8930 diff -NurpP --minimal linux-2.6.32.10/include/linux/nfs_mount.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/nfs_mount.h
8931 --- linux-2.6.32.10/include/linux/nfs_mount.h   2009-03-24 14:22:43.000000000 +0100
8932 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/nfs_mount.h   2009-12-03 20:04:56.000000000 +0100
8933 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8934  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8935  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8936  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8937 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8938 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8939 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8940  
8941  /* The following are for internal use only */
8942  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8943 diff -NurpP --minimal linux-2.6.32.10/include/linux/nsproxy.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/nsproxy.h
8944 --- linux-2.6.32.10/include/linux/nsproxy.h     2009-06-11 17:13:17.000000000 +0200
8945 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/nsproxy.h     2009-12-03 20:04:56.000000000 +0100
8946 @@ -3,6 +3,7 @@
8947  
8948  #include <linux/spinlock.h>
8949  #include <linux/sched.h>
8950 +#include <linux/vserver/debug.h>
8951  
8952  struct mnt_namespace;
8953  struct uts_namespace;
8954 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8955  }
8956  
8957  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8958 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8959  void exit_task_namespaces(struct task_struct *tsk);
8960  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8961  void free_nsproxy(struct nsproxy *ns);
8962  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
8963         struct fs_struct *);
8964  
8965 -static inline void put_nsproxy(struct nsproxy *ns)
8966 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8967 +
8968 +static inline void __get_nsproxy(struct nsproxy *ns,
8969 +       const char *_file, int _line)
8970  {
8971 -       if (atomic_dec_and_test(&ns->count)) {
8972 -               free_nsproxy(ns);
8973 -       }
8974 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8975 +               ns, atomic_read(&ns->count), _file, _line);
8976 +       atomic_inc(&ns->count);
8977  }
8978  
8979 -static inline void get_nsproxy(struct nsproxy *ns)
8980 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8981 +
8982 +static inline void __put_nsproxy(struct nsproxy *ns,
8983 +       const char *_file, int _line)
8984  {
8985 -       atomic_inc(&ns->count);
8986 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8987 +               ns, atomic_read(&ns->count), _file, _line);
8988 +       if (atomic_dec_and_test(&ns->count)) {
8989 +               free_nsproxy(ns);
8990 +       }
8991  }
8992  
8993  #ifdef CONFIG_CGROUP_NS
8994 diff -NurpP --minimal linux-2.6.32.10/include/linux/pid.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/pid.h
8995 --- linux-2.6.32.10/include/linux/pid.h 2009-03-24 14:22:43.000000000 +0100
8996 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/pid.h 2009-12-03 20:04:56.000000000 +0100
8997 @@ -8,7 +8,8 @@ enum pid_type
8998         PIDTYPE_PID,
8999         PIDTYPE_PGID,
9000         PIDTYPE_SID,
9001 -       PIDTYPE_MAX
9002 +       PIDTYPE_MAX,
9003 +       PIDTYPE_REALPID
9004  };
9005  
9006  /*
9007 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9008  }
9009  
9010  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9011 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9012  pid_t pid_vnr(struct pid *pid);
9013  
9014  #define do_each_pid_task(pid, type, task)                              \
9015 diff -NurpP --minimal linux-2.6.32.10/include/linux/proc_fs.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/proc_fs.h
9016 --- linux-2.6.32.10/include/linux/proc_fs.h     2009-12-03 20:02:56.000000000 +0100
9017 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/proc_fs.h     2009-12-03 20:04:56.000000000 +0100
9018 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9019         nlink_t nlink;
9020         uid_t uid;
9021         gid_t gid;
9022 +       int vx_flags;
9023         loff_t size;
9024         const struct inode_operations *proc_iops;
9025         /*
9026 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9027  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9028  #endif
9029  
9030 +struct vx_info;
9031 +struct nx_info;
9032 +
9033  union proc_op {
9034         int (*proc_get_link)(struct inode *, struct path *);
9035         int (*proc_read)(struct task_struct *task, char *page);
9036         int (*proc_show)(struct seq_file *m,
9037                 struct pid_namespace *ns, struct pid *pid,
9038                 struct task_struct *task);
9039 +       int (*proc_vs_read)(char *page);
9040 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9041 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9042  };
9043  
9044  struct ctl_table_header;
9045 @@ -263,6 +270,7 @@ struct ctl_table;
9046  
9047  struct proc_inode {
9048         struct pid *pid;
9049 +       int vx_flags;
9050         int fd;
9051         union proc_op op;
9052         struct proc_dir_entry *pde;
9053 diff -NurpP --minimal linux-2.6.32.10/include/linux/quotaops.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/quotaops.h
9054 --- linux-2.6.32.10/include/linux/quotaops.h    2009-12-03 20:02:56.000000000 +0100
9055 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/quotaops.h    2009-12-03 20:04:56.000000000 +0100
9056 @@ -8,6 +8,7 @@
9057  #define _LINUX_QUOTAOPS_
9058  
9059  #include <linux/fs.h>
9060 +#include <linux/vs_dlimit.h>
9061  
9062  static inline struct quota_info *sb_dqopt(struct super_block *sb)
9063  {
9064 @@ -154,10 +155,14 @@ static inline void vfs_dq_init(struct in
9065   * a transaction (deadlocks possible otherwise) */
9066  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9067  {
9068 +       if (dl_alloc_space(inode, nr))
9069 +               return 1;
9070         if (sb_any_quota_active(inode->i_sb)) {
9071                 /* Used space is updated in alloc_space() */
9072 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
9073 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) {
9074 +                       dl_free_space(inode, nr);
9075                         return 1;
9076 +               }
9077         }
9078         else
9079                 inode_add_bytes(inode, nr);
9080 @@ -174,10 +179,14 @@ static inline int vfs_dq_prealloc_space(
9081  
9082  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9083  {
9084 +       if (dl_alloc_space(inode, nr))
9085 +               return 1;
9086         if (sb_any_quota_active(inode->i_sb)) {
9087                 /* Used space is updated in alloc_space() */
9088 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
9089 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) {
9090 +                       dl_free_space(inode, nr);
9091                         return 1;
9092 +               }
9093         }
9094         else
9095                 inode_add_bytes(inode, nr);
9096 @@ -194,20 +203,28 @@ static inline int vfs_dq_alloc_space(str
9097  
9098  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9099  {
9100 +       if (dl_reserve_space(inode, nr))
9101 +               return 1;
9102         if (sb_any_quota_active(inode->i_sb)) {
9103                 /* Used space is updated in alloc_space() */
9104 -               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
9105 +               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA) {
9106 +                       dl_release_space(inode, nr);
9107                         return 1;
9108 +               }
9109         }
9110         return 0;
9111  }
9112  
9113  static inline int vfs_dq_alloc_inode(struct inode *inode)
9114  {
9115 +       if (dl_alloc_inode(inode))
9116 +               return 1;
9117         if (sb_any_quota_active(inode->i_sb)) {
9118                 vfs_dq_init(inode);
9119 -               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
9120 +               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
9121 +                       dl_free_inode(inode);
9122                         return 1;
9123 +               }
9124         }
9125         return 0;
9126  }
9127 @@ -217,9 +234,13 @@ static inline int vfs_dq_alloc_inode(str
9128   */
9129  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9130  {
9131 +       if (dl_claim_space(inode, nr))
9132 +               return 1;
9133         if (sb_any_quota_active(inode->i_sb)) {
9134 -               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
9135 +               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA) {
9136 +                       dl_release_space(inode, nr);
9137                         return 1;
9138 +               }
9139         } else
9140                 inode_add_bytes(inode, nr);
9141  
9142 @@ -235,6 +256,7 @@ void vfs_dq_release_reservation_space(st
9143  {
9144         if (sb_any_quota_active(inode->i_sb))
9145                 inode->i_sb->dq_op->release_rsv(inode, nr);
9146 +       dl_release_space(inode, nr);
9147  }
9148  
9149  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9150 @@ -243,6 +265,7 @@ static inline void vfs_dq_free_space_nod
9151                 inode->i_sb->dq_op->free_space(inode, nr);
9152         else
9153                 inode_sub_bytes(inode, nr);
9154 +       dl_free_space(inode, nr);
9155  }
9156  
9157  static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
9158 @@ -255,6 +278,7 @@ static inline void vfs_dq_free_inode(str
9159  {
9160         if (sb_any_quota_active(inode->i_sb))
9161                 inode->i_sb->dq_op->free_inode(inode, 1);
9162 +       dl_free_inode(inode);
9163  }
9164  
9165  /* Cannot be called inside a transaction */
9166 @@ -358,6 +382,8 @@ static inline int vfs_dq_transfer(struct
9167  
9168  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9169  {
9170 +       if (dl_alloc_space(inode, nr))
9171 +               return 1;
9172         inode_add_bytes(inode, nr);
9173         return 0;
9174  }
9175 @@ -371,6 +397,8 @@ static inline int vfs_dq_prealloc_space(
9176  
9177  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9178  {
9179 +       if (dl_alloc_space(inode, nr))
9180 +               return 1;
9181         inode_add_bytes(inode, nr);
9182         return 0;
9183  }
9184 @@ -384,22 +412,28 @@ static inline int vfs_dq_alloc_space(str
9185  
9186  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9187  {
9188 +       if (dl_reserve_space(inode, nr))
9189 +               return 1;
9190         return 0;
9191  }
9192  
9193  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9194  {
9195 +       if (dl_claim_space(inode, nr))
9196 +               return 1;
9197         return vfs_dq_alloc_space(inode, nr);
9198  }
9199  
9200  static inline
9201  int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
9202  {
9203 +       dl_release_space(inode, nr);
9204         return 0;
9205  }
9206  
9207  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9208  {
9209 +       dl_free_space(inode, nr);
9210         inode_sub_bytes(inode, nr);
9211  }
9212  
9213 diff -NurpP --minimal linux-2.6.32.10/include/linux/reboot.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/reboot.h
9214 --- linux-2.6.32.10/include/linux/reboot.h      2008-12-25 00:26:37.000000000 +0100
9215 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/reboot.h      2009-12-03 22:06:59.000000000 +0100
9216 @@ -33,6 +33,7 @@
9217  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9218  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9219  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9220 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9221  
9222  
9223  #ifdef __KERNEL__
9224 diff -NurpP --minimal linux-2.6.32.10/include/linux/reiserfs_fs.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/reiserfs_fs.h
9225 --- linux-2.6.32.10/include/linux/reiserfs_fs.h 2009-09-10 15:26:26.000000000 +0200
9226 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/reiserfs_fs.h 2009-12-03 20:04:56.000000000 +0100
9227 @@ -899,6 +899,11 @@ struct stat_data_v1 {
9228  #define REISERFS_COMPR_FL     FS_COMPR_FL
9229  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9230  
9231 +/* unfortunately reiserfs sdattr is only 16 bit */
9232 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9233 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9234 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9235 +
9236  /* persistent flags that file inherits from the parent directory */
9237  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9238                                 REISERFS_SYNC_FL |      \
9239 @@ -908,6 +913,9 @@ struct stat_data_v1 {
9240                                 REISERFS_COMPR_FL |     \
9241                                 REISERFS_NOTAIL_FL )
9242  
9243 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9244 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9245 +
9246  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9247     address blocks) */
9248  struct stat_data {
9249 @@ -1989,6 +1997,7 @@ static inline void reiserfs_update_sd(st
9250  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9251  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9252  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9253 +int reiserfs_sync_flags(struct inode *inode, int, int);
9254  
9255  /* namei.c */
9256  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9257 diff -NurpP --minimal linux-2.6.32.10/include/linux/reiserfs_fs_sb.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/reiserfs_fs_sb.h
9258 --- linux-2.6.32.10/include/linux/reiserfs_fs_sb.h      2009-09-10 15:26:26.000000000 +0200
9259 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/reiserfs_fs_sb.h      2009-12-03 20:04:56.000000000 +0100
9260 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
9261         REISERFS_EXPOSE_PRIVROOT,
9262         REISERFS_BARRIER_NONE,
9263         REISERFS_BARRIER_FLUSH,
9264 +       REISERFS_TAGGED,
9265  
9266         /* Actions on error */
9267         REISERFS_ERROR_PANIC,
9268 diff -NurpP --minimal linux-2.6.32.10/include/linux/sched.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/sched.h
9269 --- linux-2.6.32.10/include/linux/sched.h       2010-03-18 16:17:37.000000000 +0100
9270 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/sched.h       2010-03-18 16:53:06.000000000 +0100
9271 @@ -390,25 +390,28 @@ extern void arch_unmap_area_topdown(stru
9272   * The mm counters are not protected by its page_table_lock,
9273   * so must be incremented atomically.
9274   */
9275 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9276 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9277 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9278 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9279 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9280 +#define __set_mm_counter(mm, member, value) \
9281 +       atomic_long_set(&(mm)->_##member, value)
9282 +#define get_mm_counter(mm, member) \
9283 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9284  
9285  #else  /* !USE_SPLIT_PTLOCKS */
9286  /*
9287   * The mm counters are protected by its page_table_lock,
9288   * so can be incremented directly.
9289   */
9290 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9291 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9292  #define get_mm_counter(mm, member) ((mm)->_##member)
9293 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9294 -#define inc_mm_counter(mm, member) (mm)->_##member++
9295 -#define dec_mm_counter(mm, member) (mm)->_##member--
9296  
9297  #endif /* !USE_SPLIT_PTLOCKS */
9298  
9299 +#define set_mm_counter(mm, member, value) \
9300 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9301 +#define add_mm_counter(mm, member, value) \
9302 +       vx_ ## member ## pages_add((mm), (value))
9303 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9304 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9305 +
9306  #define get_mm_rss(mm)                                 \
9307         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9308  #define update_hiwater_rss(mm) do {                    \
9309 @@ -1186,6 +1189,12 @@ struct sched_entity {
9310         u64                     nr_wakeups_affine_attempts;
9311         u64                     nr_wakeups_passive;
9312         u64                     nr_wakeups_idle;
9313 +#ifdef CONFIG_CFS_HARD_LIMITS
9314 +       u64                     throttle_start;
9315 +       u64                     throttle_max;
9316 +       u64                     throttle_count;
9317 +       u64                     throttle_sum;
9318 +#endif
9319  #endif
9320  
9321  #ifdef CONFIG_FAIR_GROUP_SCHED
9322 @@ -1396,6 +1405,14 @@ struct task_struct {
9323  #endif
9324         seccomp_t seccomp;
9325  
9326 +/* vserver context data */
9327 +       struct vx_info *vx_info;
9328 +       struct nx_info *nx_info;
9329 +
9330 +       xid_t xid;
9331 +       nid_t nid;
9332 +       tag_t tag;
9333 +
9334  /* Thread group tracking */
9335         u32 parent_exec_id;
9336         u32 self_exec_id;
9337 @@ -1621,6 +1638,11 @@ struct pid_namespace;
9338  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9339                         struct pid_namespace *ns);
9340  
9341 +#include <linux/vserver/base.h>
9342 +#include <linux/vserver/context.h>
9343 +#include <linux/vserver/debug.h>
9344 +#include <linux/vserver/pid.h>
9345 +
9346  static inline pid_t task_pid_nr(struct task_struct *tsk)
9347  {
9348         return tsk->pid;
9349 @@ -1634,7 +1656,8 @@ static inline pid_t task_pid_nr_ns(struc
9350  
9351  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9352  {
9353 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9354 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9355 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9356  }
9357  
9358  
9359 @@ -1647,7 +1670,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9360  
9361  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9362  {
9363 -       return pid_vnr(task_tgid(tsk));
9364 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9365  }
9366  
9367  
9368 diff -NurpP --minimal linux-2.6.32.10/include/linux/shmem_fs.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/shmem_fs.h
9369 --- linux-2.6.32.10/include/linux/shmem_fs.h    2009-12-03 20:02:56.000000000 +0100
9370 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/shmem_fs.h    2009-12-03 20:04:56.000000000 +0100
9371 @@ -8,6 +8,9 @@
9372  
9373  #define SHMEM_NR_DIRECT 16
9374  
9375 +#define TMPFS_SUPER_MAGIC      0x01021994
9376 +
9377 +
9378  struct shmem_inode_info {
9379         spinlock_t              lock;
9380         unsigned long           flags;
9381 diff -NurpP --minimal linux-2.6.32.10/include/linux/stat.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/stat.h
9382 --- linux-2.6.32.10/include/linux/stat.h        2008-12-25 00:26:37.000000000 +0100
9383 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/stat.h        2009-12-03 20:04:56.000000000 +0100
9384 @@ -66,6 +66,7 @@ struct kstat {
9385         unsigned int    nlink;
9386         uid_t           uid;
9387         gid_t           gid;
9388 +       tag_t           tag;
9389         dev_t           rdev;
9390         loff_t          size;
9391         struct timespec  atime;
9392 diff -NurpP --minimal linux-2.6.32.10/include/linux/sunrpc/auth.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/sunrpc/auth.h
9393 --- linux-2.6.32.10/include/linux/sunrpc/auth.h 2009-12-03 20:02:56.000000000 +0100
9394 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/sunrpc/auth.h 2009-12-03 20:04:56.000000000 +0100
9395 @@ -25,6 +25,7 @@
9396  struct auth_cred {
9397         uid_t   uid;
9398         gid_t   gid;
9399 +       tag_t   tag;
9400         struct group_info *group_info;
9401         unsigned char machine_cred : 1;
9402  };
9403 diff -NurpP --minimal linux-2.6.32.10/include/linux/sunrpc/clnt.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/sunrpc/clnt.h
9404 --- linux-2.6.32.10/include/linux/sunrpc/clnt.h 2009-12-03 20:02:56.000000000 +0100
9405 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/sunrpc/clnt.h 2009-12-03 20:04:56.000000000 +0100
9406 @@ -49,7 +49,8 @@ struct rpc_clnt {
9407         unsigned int            cl_softrtry : 1,/* soft timeouts */
9408                                 cl_discrtry : 1,/* disconnect before retry */
9409                                 cl_autobind : 1,/* use getport() */
9410 -                               cl_chatty   : 1;/* be verbose */
9411 +                               cl_chatty   : 1,/* be verbose */
9412 +                               cl_tag      : 1;/* context tagging */
9413  
9414         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9415         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9416 diff -NurpP --minimal linux-2.6.32.10/include/linux/syscalls.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/syscalls.h
9417 --- linux-2.6.32.10/include/linux/syscalls.h    2010-03-18 16:17:37.000000000 +0100
9418 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/syscalls.h    2010-01-20 04:21:33.000000000 +0100
9419 @@ -546,6 +546,8 @@ asmlinkage long sys_symlink(const char _
9420  asmlinkage long sys_unlink(const char __user *pathname);
9421  asmlinkage long sys_rename(const char __user *oldname,
9422                                 const char __user *newname);
9423 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9424 +                               umode_t mode);
9425  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9426  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9427  
9428 diff -NurpP --minimal linux-2.6.32.10/include/linux/sysctl.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/sysctl.h
9429 --- linux-2.6.32.10/include/linux/sysctl.h      2010-03-18 16:17:37.000000000 +0100
9430 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/sysctl.h      2010-02-12 10:59:55.000000000 +0100
9431 @@ -69,6 +69,7 @@ enum
9432         CTL_ABI=9,              /* Binary emulation */
9433         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9434         CTL_ARLAN=254,          /* arlan wireless driver */
9435 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9436         CTL_S390DBF=5677,       /* s390 debug */
9437         CTL_SUNRPC=7249,        /* sunrpc debug */
9438         CTL_PM=9899,            /* frv power management */
9439 @@ -103,6 +104,7 @@ enum
9440  
9441         KERN_PANIC=15,          /* int: panic timeout */
9442         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9443 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9444  
9445         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9446         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9447 diff -NurpP --minimal linux-2.6.32.10/include/linux/sysfs.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/sysfs.h
9448 --- linux-2.6.32.10/include/linux/sysfs.h       2008-12-25 00:26:37.000000000 +0100
9449 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/sysfs.h       2009-12-03 20:04:56.000000000 +0100
9450 @@ -17,6 +17,8 @@
9451  #include <linux/list.h>
9452  #include <asm/atomic.h>
9453  
9454 +#define SYSFS_SUPER_MAGIC      0x62656572
9455 +
9456  struct kobject;
9457  struct module;
9458  
9459 diff -NurpP --minimal linux-2.6.32.10/include/linux/time.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/time.h
9460 --- linux-2.6.32.10/include/linux/time.h        2010-03-18 16:17:37.000000000 +0100
9461 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/time.h        2010-02-12 10:59:55.000000000 +0100
9462 @@ -238,6 +238,9 @@ static __always_inline void timespec_add
9463         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9464         a->tv_nsec = ns;
9465  }
9466 +
9467 +#include <linux/vs_time.h>
9468 +
9469  #endif /* __KERNEL__ */
9470  
9471  #define NFDBITS                        __NFDBITS
9472 diff -NurpP --minimal linux-2.6.32.10/include/linux/types.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/types.h
9473 --- linux-2.6.32.10/include/linux/types.h       2009-09-10 15:26:26.000000000 +0200
9474 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/types.h       2009-12-03 20:04:56.000000000 +0100
9475 @@ -37,6 +37,9 @@ typedef __kernel_uid32_t      uid_t;
9476  typedef __kernel_gid32_t       gid_t;
9477  typedef __kernel_uid16_t        uid16_t;
9478  typedef __kernel_gid16_t        gid16_t;
9479 +typedef unsigned int           xid_t;
9480 +typedef unsigned int           nid_t;
9481 +typedef unsigned int           tag_t;
9482  
9483  typedef unsigned long          uintptr_t;
9484  
9485 diff -NurpP --minimal linux-2.6.32.10/include/linux/vroot.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vroot.h
9486 --- linux-2.6.32.10/include/linux/vroot.h       1970-01-01 01:00:00.000000000 +0100
9487 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vroot.h       2009-12-03 20:04:56.000000000 +0100
9488 @@ -0,0 +1,51 @@
9489 +
9490 +/*
9491 + * include/linux/vroot.h
9492 + *
9493 + * written by Herbert Pötzl, 9/11/2002
9494 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9495 + *
9496 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9497 + * Redistribution of this file is permitted under the
9498 + * GNU General Public License.
9499 + */
9500 +
9501 +#ifndef _LINUX_VROOT_H
9502 +#define _LINUX_VROOT_H
9503 +
9504 +
9505 +#ifdef __KERNEL__
9506 +
9507 +/* Possible states of device */
9508 +enum {
9509 +       Vr_unbound,
9510 +       Vr_bound,
9511 +};
9512 +
9513 +struct vroot_device {
9514 +       int             vr_number;
9515 +       int             vr_refcnt;
9516 +
9517 +       struct semaphore        vr_ctl_mutex;
9518 +       struct block_device    *vr_device;
9519 +       int                     vr_state;
9520 +};
9521 +
9522 +
9523 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9524 +
9525 +extern int register_vroot_grb(vroot_grb_func *);
9526 +extern int unregister_vroot_grb(vroot_grb_func *);
9527 +
9528 +#endif /* __KERNEL__ */
9529 +
9530 +#define MAX_VROOT_DEFAULT      8
9531 +
9532 +/*
9533 + * IOCTL commands --- we will commandeer 0x56 ('V')
9534 + */
9535 +
9536 +#define VROOT_SET_DEV          0x5600
9537 +#define VROOT_CLR_DEV          0x5601
9538 +
9539 +#endif /* _LINUX_VROOT_H */
9540 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_base.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_base.h
9541 --- linux-2.6.32.10/include/linux/vs_base.h     1970-01-01 01:00:00.000000000 +0100
9542 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_base.h     2009-12-03 20:04:56.000000000 +0100
9543 @@ -0,0 +1,10 @@
9544 +#ifndef _VS_BASE_H
9545 +#define _VS_BASE_H
9546 +
9547 +#include "vserver/base.h"
9548 +#include "vserver/check.h"
9549 +#include "vserver/debug.h"
9550 +
9551 +#else
9552 +#warning duplicate inclusion
9553 +#endif
9554 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_context.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_context.h
9555 --- linux-2.6.32.10/include/linux/vs_context.h  1970-01-01 01:00:00.000000000 +0100
9556 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_context.h  2009-12-03 20:04:56.000000000 +0100
9557 @@ -0,0 +1,242 @@
9558 +#ifndef _VS_CONTEXT_H
9559 +#define _VS_CONTEXT_H
9560 +
9561 +#include "vserver/base.h"
9562 +#include "vserver/check.h"
9563 +#include "vserver/context.h"
9564 +#include "vserver/history.h"
9565 +#include "vserver/debug.h"
9566 +
9567 +#include <linux/sched.h>
9568 +
9569 +
9570 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9571 +
9572 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9573 +       const char *_file, int _line, void *_here)
9574 +{
9575 +       if (!vxi)
9576 +               return NULL;
9577 +
9578 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9579 +               vxi, vxi ? vxi->vx_id : 0,
9580 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9581 +               _file, _line);
9582 +       __vxh_get_vx_info(vxi, _here);
9583 +
9584 +       atomic_inc(&vxi->vx_usecnt);
9585 +       return vxi;
9586 +}
9587 +
9588 +
9589 +extern void free_vx_info(struct vx_info *);
9590 +
9591 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9592 +
9593 +static inline void __put_vx_info(struct vx_info *vxi,
9594 +       const char *_file, int _line, void *_here)
9595 +{
9596 +       if (!vxi)
9597 +               return;
9598 +
9599 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9600 +               vxi, vxi ? vxi->vx_id : 0,
9601 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9602 +               _file, _line);
9603 +       __vxh_put_vx_info(vxi, _here);
9604 +
9605 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9606 +               free_vx_info(vxi);
9607 +}
9608 +
9609 +
9610 +#define init_vx_info(p, i) \
9611 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9612 +
9613 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9614 +       const char *_file, int _line, void *_here)
9615 +{
9616 +       if (vxi) {
9617 +               vxlprintk(VXD_CBIT(xid, 3),
9618 +                       "init_vx_info(%p[#%d.%d])",
9619 +                       vxi, vxi ? vxi->vx_id : 0,
9620 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9621 +                       _file, _line);
9622 +               __vxh_init_vx_info(vxi, vxp, _here);
9623 +
9624 +               atomic_inc(&vxi->vx_usecnt);
9625 +       }
9626 +       *vxp = vxi;
9627 +}
9628 +
9629 +
9630 +#define set_vx_info(p, i) \
9631 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9632 +
9633 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9634 +       const char *_file, int _line, void *_here)
9635 +{
9636 +       struct vx_info *vxo;
9637 +
9638 +       if (!vxi)
9639 +               return;
9640 +
9641 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9642 +               vxi, vxi ? vxi->vx_id : 0,
9643 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9644 +               _file, _line);
9645 +       __vxh_set_vx_info(vxi, vxp, _here);
9646 +
9647 +       atomic_inc(&vxi->vx_usecnt);
9648 +       vxo = xchg(vxp, vxi);
9649 +       BUG_ON(vxo);
9650 +}
9651 +
9652 +
9653 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9654 +
9655 +static inline void __clr_vx_info(struct vx_info **vxp,
9656 +       const char *_file, int _line, void *_here)
9657 +{
9658 +       struct vx_info *vxo;
9659 +
9660 +       vxo = xchg(vxp, NULL);
9661 +       if (!vxo)
9662 +               return;
9663 +
9664 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9665 +               vxo, vxo ? vxo->vx_id : 0,
9666 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9667 +               _file, _line);
9668 +       __vxh_clr_vx_info(vxo, vxp, _here);
9669 +
9670 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9671 +               free_vx_info(vxo);
9672 +}
9673 +
9674 +
9675 +#define claim_vx_info(v, p) \
9676 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9677 +
9678 +static inline void __claim_vx_info(struct vx_info *vxi,
9679 +       struct task_struct *task,
9680 +       const char *_file, int _line, void *_here)
9681 +{
9682 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9683 +               vxi, vxi ? vxi->vx_id : 0,
9684 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9685 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9686 +               task, _file, _line);
9687 +       __vxh_claim_vx_info(vxi, task, _here);
9688 +
9689 +       atomic_inc(&vxi->vx_tasks);
9690 +}
9691 +
9692 +
9693 +extern void unhash_vx_info(struct vx_info *);
9694 +
9695 +#define release_vx_info(v, p) \
9696 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9697 +
9698 +static inline void __release_vx_info(struct vx_info *vxi,
9699 +       struct task_struct *task,
9700 +       const char *_file, int _line, void *_here)
9701 +{
9702 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9703 +               vxi, vxi ? vxi->vx_id : 0,
9704 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9705 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9706 +               task, _file, _line);
9707 +       __vxh_release_vx_info(vxi, task, _here);
9708 +
9709 +       might_sleep();
9710 +
9711 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9712 +               unhash_vx_info(vxi);
9713 +}
9714 +
9715 +
9716 +#define task_get_vx_info(p) \
9717 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9718 +
9719 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9720 +       const char *_file, int _line, void *_here)
9721 +{
9722 +       struct vx_info *vxi;
9723 +
9724 +       task_lock(p);
9725 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9726 +               p, _file, _line);
9727 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9728 +       task_unlock(p);
9729 +       return vxi;
9730 +}
9731 +
9732 +
9733 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9734 +{
9735 +       if (waitqueue_active(&vxi->vx_wait))
9736 +               wake_up_interruptible(&vxi->vx_wait);
9737 +}
9738 +
9739 +
9740 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9741 +
9742 +static inline void __enter_vx_info(struct vx_info *vxi,
9743 +       struct vx_info_save *vxis, const char *_file, int _line)
9744 +{
9745 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9746 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9747 +               current->xid, current->vx_info, _file, _line);
9748 +       vxis->vxi = xchg(&current->vx_info, vxi);
9749 +       vxis->xid = current->xid;
9750 +       current->xid = vxi ? vxi->vx_id : 0;
9751 +}
9752 +
9753 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9754 +
9755 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9756 +       const char *_file, int _line)
9757 +{
9758 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9759 +               vxis, vxis->xid, vxis->vxi, current,
9760 +               current->xid, current->vx_info, _file, _line);
9761 +       (void)xchg(&current->vx_info, vxis->vxi);
9762 +       current->xid = vxis->xid;
9763 +}
9764 +
9765 +
9766 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9767 +{
9768 +       vxis->vxi = xchg(&current->vx_info, NULL);
9769 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9770 +}
9771 +
9772 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9773 +{
9774 +       (void)xchg(&current->xid, vxis->xid);
9775 +       (void)xchg(&current->vx_info, vxis->vxi);
9776 +}
9777 +
9778 +#define task_is_init(p) \
9779 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9780 +
9781 +static inline int __task_is_init(struct task_struct *p,
9782 +       const char *_file, int _line, void *_here)
9783 +{
9784 +       int is_init = is_global_init(p);
9785 +
9786 +       task_lock(p);
9787 +       if (p->vx_info)
9788 +               is_init = p->vx_info->vx_initpid == p->pid;
9789 +       task_unlock(p);
9790 +       return is_init;
9791 +}
9792 +
9793 +extern void exit_vx_info(struct task_struct *, int);
9794 +extern void exit_vx_info_early(struct task_struct *, int);
9795 +
9796 +
9797 +#else
9798 +#warning duplicate inclusion
9799 +#endif
9800 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_cowbl.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_cowbl.h
9801 --- linux-2.6.32.10/include/linux/vs_cowbl.h    1970-01-01 01:00:00.000000000 +0100
9802 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_cowbl.h    2009-12-03 20:04:56.000000000 +0100
9803 @@ -0,0 +1,47 @@
9804 +#ifndef _VS_COWBL_H
9805 +#define _VS_COWBL_H
9806 +
9807 +#include <linux/fs.h>
9808 +#include <linux/dcache.h>
9809 +#include <linux/namei.h>
9810 +
9811 +extern struct dentry *cow_break_link(const char *pathname);
9812 +
9813 +static inline int cow_check_and_break(struct path *path)
9814 +{
9815 +       struct inode *inode = path->dentry->d_inode;
9816 +       int error = 0;
9817 +
9818 +       /* do we need this check? */
9819 +       if (IS_RDONLY(inode))
9820 +               return -EROFS;
9821 +
9822 +       if (IS_COW(inode)) {
9823 +               if (IS_COW_LINK(inode)) {
9824 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9825 +                       char *pp, *buf;
9826 +
9827 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9828 +                       if (!buf) {
9829 +                               return -ENOMEM;
9830 +                       }
9831 +                       pp = d_path(path, buf, PATH_MAX);
9832 +                       new_dentry = cow_break_link(pp);
9833 +                       kfree(buf);
9834 +                       if (!IS_ERR(new_dentry)) {
9835 +                               path->dentry = new_dentry;
9836 +                               dput(old_dentry);
9837 +                       } else
9838 +                               error = PTR_ERR(new_dentry);
9839 +               } else {
9840 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9841 +                       inode->i_ctime = CURRENT_TIME;
9842 +                       mark_inode_dirty(inode);
9843 +               }
9844 +       }
9845 +       return error;
9846 +}
9847 +
9848 +#else
9849 +#warning duplicate inclusion
9850 +#endif
9851 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_cvirt.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_cvirt.h
9852 --- linux-2.6.32.10/include/linux/vs_cvirt.h    1970-01-01 01:00:00.000000000 +0100
9853 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_cvirt.h    2009-12-03 20:04:56.000000000 +0100
9854 @@ -0,0 +1,50 @@
9855 +#ifndef _VS_CVIRT_H
9856 +#define _VS_CVIRT_H
9857 +
9858 +#include "vserver/cvirt.h"
9859 +#include "vserver/context.h"
9860 +#include "vserver/base.h"
9861 +#include "vserver/check.h"
9862 +#include "vserver/debug.h"
9863 +
9864 +
9865 +static inline void vx_activate_task(struct task_struct *p)
9866 +{
9867 +       struct vx_info *vxi;
9868 +
9869 +       if ((vxi = p->vx_info)) {
9870 +               vx_update_load(vxi);
9871 +               atomic_inc(&vxi->cvirt.nr_running);
9872 +       }
9873 +}
9874 +
9875 +static inline void vx_deactivate_task(struct task_struct *p)
9876 +{
9877 +       struct vx_info *vxi;
9878 +
9879 +       if ((vxi = p->vx_info)) {
9880 +               vx_update_load(vxi);
9881 +               atomic_dec(&vxi->cvirt.nr_running);
9882 +       }
9883 +}
9884 +
9885 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9886 +{
9887 +       struct vx_info *vxi;
9888 +
9889 +       if ((vxi = p->vx_info))
9890 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9891 +}
9892 +
9893 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9894 +{
9895 +       struct vx_info *vxi;
9896 +
9897 +       if ((vxi = p->vx_info))
9898 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9899 +}
9900 +
9901 +
9902 +#else
9903 +#warning duplicate inclusion
9904 +#endif
9905 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_device.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_device.h
9906 --- linux-2.6.32.10/include/linux/vs_device.h   1970-01-01 01:00:00.000000000 +0100
9907 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_device.h   2009-12-03 20:04:56.000000000 +0100
9908 @@ -0,0 +1,45 @@
9909 +#ifndef _VS_DEVICE_H
9910 +#define _VS_DEVICE_H
9911 +
9912 +#include "vserver/base.h"
9913 +#include "vserver/device.h"
9914 +#include "vserver/debug.h"
9915 +
9916 +
9917 +#ifdef CONFIG_VSERVER_DEVICE
9918 +
9919 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9920 +
9921 +#define vs_device_perm(v, d, m, p) \
9922 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9923 +
9924 +#else
9925 +
9926 +static inline
9927 +int vs_map_device(struct vx_info *vxi,
9928 +       dev_t device, dev_t *target, umode_t mode)
9929 +{
9930 +       if (target)
9931 +               *target = device;
9932 +       return ~0;
9933 +}
9934 +
9935 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9936 +
9937 +#endif
9938 +
9939 +
9940 +#define vs_map_chrdev(d, t, p) \
9941 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9942 +#define vs_map_blkdev(d, t, p) \
9943 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9944 +
9945 +#define vs_chrdev_perm(d, p) \
9946 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9947 +#define vs_blkdev_perm(d, p) \
9948 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9949 +
9950 +
9951 +#else
9952 +#warning duplicate inclusion
9953 +#endif
9954 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_dlimit.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_dlimit.h
9955 --- linux-2.6.32.10/include/linux/vs_dlimit.h   1970-01-01 01:00:00.000000000 +0100
9956 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_dlimit.h   2009-12-03 20:04:56.000000000 +0100
9957 @@ -0,0 +1,216 @@
9958 +#ifndef _VS_DLIMIT_H
9959 +#define _VS_DLIMIT_H
9960 +
9961 +#include <linux/fs.h>
9962 +
9963 +#include "vserver/dlimit.h"
9964 +#include "vserver/base.h"
9965 +#include "vserver/debug.h"
9966 +
9967 +
9968 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9969 +
9970 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9971 +       const char *_file, int _line)
9972 +{
9973 +       if (!dli)
9974 +               return NULL;
9975 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9976 +               dli, dli ? dli->dl_tag : 0,
9977 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9978 +               _file, _line);
9979 +       atomic_inc(&dli->dl_usecnt);
9980 +       return dli;
9981 +}
9982 +
9983 +
9984 +#define free_dl_info(i) \
9985 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9986 +
9987 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9988 +
9989 +static inline void __put_dl_info(struct dl_info *dli,
9990 +       const char *_file, int _line)
9991 +{
9992 +       if (!dli)
9993 +               return;
9994 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9995 +               dli, dli ? dli->dl_tag : 0,
9996 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9997 +               _file, _line);
9998 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9999 +               free_dl_info(dli);
10000 +}
10001 +
10002 +
10003 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10004 +
10005 +static inline int __dl_alloc_space(struct super_block *sb,
10006 +       tag_t tag, dlsize_t nr, const char *file, int line)
10007 +{
10008 +       struct dl_info *dli = NULL;
10009 +       int ret = 0;
10010 +
10011 +       if (nr == 0)
10012 +               goto out;
10013 +       dli = locate_dl_info(sb, tag);
10014 +       if (!dli)
10015 +               goto out;
10016 +
10017 +       spin_lock(&dli->dl_lock);
10018 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10019 +       if (!ret)
10020 +               dli->dl_space_used += nr;
10021 +       spin_unlock(&dli->dl_lock);
10022 +       put_dl_info(dli);
10023 +out:
10024 +       vxlprintk(VXD_CBIT(dlim, 1),
10025 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10026 +               sb, tag, __dlimit_char(dli), (long long)nr,
10027 +               ret, file, line);
10028 +       return ret;
10029 +}
10030 +
10031 +static inline void __dl_free_space(struct super_block *sb,
10032 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10033 +{
10034 +       struct dl_info *dli = NULL;
10035 +
10036 +       if (nr == 0)
10037 +               goto out;
10038 +       dli = locate_dl_info(sb, tag);
10039 +       if (!dli)
10040 +               goto out;
10041 +
10042 +       spin_lock(&dli->dl_lock);
10043 +       if (dli->dl_space_used > nr)
10044 +               dli->dl_space_used -= nr;
10045 +       else
10046 +               dli->dl_space_used = 0;
10047 +       spin_unlock(&dli->dl_lock);
10048 +       put_dl_info(dli);
10049 +out:
10050 +       vxlprintk(VXD_CBIT(dlim, 1),
10051 +               "FREE  (%p,#%d)%c %lld bytes",
10052 +               sb, tag, __dlimit_char(dli), (long long)nr,
10053 +               _file, _line);
10054 +}
10055 +
10056 +static inline int __dl_alloc_inode(struct super_block *sb,
10057 +       tag_t tag, const char *_file, int _line)
10058 +{
10059 +       struct dl_info *dli;
10060 +       int ret = 0;
10061 +
10062 +       dli = locate_dl_info(sb, tag);
10063 +       if (!dli)
10064 +               goto out;
10065 +
10066 +       spin_lock(&dli->dl_lock);
10067 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
10068 +       if (!ret)
10069 +               dli->dl_inodes_used++;
10070 +       spin_unlock(&dli->dl_lock);
10071 +       put_dl_info(dli);
10072 +out:
10073 +       vxlprintk(VXD_CBIT(dlim, 0),
10074 +               "ALLOC (%p,#%d)%c inode (%d)",
10075 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10076 +       return ret;
10077 +}
10078 +
10079 +static inline void __dl_free_inode(struct super_block *sb,
10080 +       tag_t tag, const char *_file, int _line)
10081 +{
10082 +       struct dl_info *dli;
10083 +
10084 +       dli = locate_dl_info(sb, tag);
10085 +       if (!dli)
10086 +               goto out;
10087 +
10088 +       spin_lock(&dli->dl_lock);
10089 +       if (dli->dl_inodes_used > 1)
10090 +               dli->dl_inodes_used--;
10091 +       else
10092 +               dli->dl_inodes_used = 0;
10093 +       spin_unlock(&dli->dl_lock);
10094 +       put_dl_info(dli);
10095 +out:
10096 +       vxlprintk(VXD_CBIT(dlim, 0),
10097 +               "FREE  (%p,#%d)%c inode",
10098 +               sb, tag, __dlimit_char(dli), _file, _line);
10099 +}
10100 +
10101 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10102 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10103 +       const char *_file, int _line)
10104 +{
10105 +       struct dl_info *dli;
10106 +       uint64_t broot, bfree;
10107 +
10108 +       dli = locate_dl_info(sb, tag);
10109 +       if (!dli)
10110 +               return;
10111 +
10112 +       spin_lock(&dli->dl_lock);
10113 +       broot = (dli->dl_space_total -
10114 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10115 +               >> sb->s_blocksize_bits;
10116 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10117 +                       >> sb->s_blocksize_bits;
10118 +       spin_unlock(&dli->dl_lock);
10119 +
10120 +       vxlprintk(VXD_CBIT(dlim, 2),
10121 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10122 +               (long long)bfree, (long long)broot,
10123 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10124 +               _file, _line);
10125 +       if (free_blocks) {
10126 +               if (*free_blocks > bfree)
10127 +                       *free_blocks = bfree;
10128 +       }
10129 +       if (root_blocks) {
10130 +               if (*root_blocks > broot)
10131 +                       *root_blocks = broot;
10132 +       }
10133 +       put_dl_info(dli);
10134 +}
10135 +
10136 +#define dl_prealloc_space(in, bytes) \
10137 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10138 +               __FILE__, __LINE__ )
10139 +
10140 +#define dl_alloc_space(in, bytes) \
10141 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10142 +               __FILE__, __LINE__ )
10143 +
10144 +#define dl_reserve_space(in, bytes) \
10145 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10146 +               __FILE__, __LINE__ )
10147 +
10148 +#define dl_claim_space(in, bytes) (0)
10149 +
10150 +#define dl_release_space(in, bytes) \
10151 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10152 +               __FILE__, __LINE__ )
10153 +
10154 +#define dl_free_space(in, bytes) \
10155 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10156 +               __FILE__, __LINE__ )
10157 +
10158 +
10159 +
10160 +#define dl_alloc_inode(in) \
10161 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10162 +
10163 +#define dl_free_inode(in) \
10164 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10165 +
10166 +
10167 +#define dl_adjust_block(sb, tag, fb, rb) \
10168 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10169 +
10170 +
10171 +#else
10172 +#warning duplicate inclusion
10173 +#endif
10174 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/base.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/base.h
10175 --- linux-2.6.32.10/include/linux/vserver/base.h        1970-01-01 01:00:00.000000000 +0100
10176 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/base.h        2009-12-03 20:04:56.000000000 +0100
10177 @@ -0,0 +1,170 @@
10178 +#ifndef _VX_BASE_H
10179 +#define _VX_BASE_H
10180 +
10181 +
10182 +/* context state changes */
10183 +
10184 +enum {
10185 +       VSC_STARTUP = 1,
10186 +       VSC_SHUTDOWN,
10187 +
10188 +       VSC_NETUP,
10189 +       VSC_NETDOWN,
10190 +};
10191 +
10192 +
10193 +
10194 +#define vx_task_xid(t) ((t)->xid)
10195 +
10196 +#define vx_current_xid() vx_task_xid(current)
10197 +
10198 +#define current_vx_info() (current->vx_info)
10199 +
10200 +
10201 +#define nx_task_nid(t) ((t)->nid)
10202 +
10203 +#define nx_current_nid() nx_task_nid(current)
10204 +
10205 +#define current_nx_info() (current->nx_info)
10206 +
10207 +
10208 +/* generic flag merging */
10209 +
10210 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10211 +
10212 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10213 +
10214 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10215 +
10216 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10217 +
10218 +
10219 +/* context flags */
10220 +
10221 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10222 +
10223 +#define vx_current_flags()     __vx_flags(current_vx_info())
10224 +
10225 +#define vx_info_flags(v, m, f) \
10226 +       vs_check_flags(__vx_flags(v), m, f)
10227 +
10228 +#define task_vx_flags(t, m, f) \
10229 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10230 +
10231 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10232 +
10233 +
10234 +/* context caps */
10235 +
10236 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10237 +
10238 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10239 +
10240 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10241 +
10242 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10243 +
10244 +
10245 +
10246 +/* network flags */
10247 +
10248 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10249 +
10250 +#define nx_current_flags()     __nx_flags(current_nx_info())
10251 +
10252 +#define nx_info_flags(n, m, f) \
10253 +       vs_check_flags(__nx_flags(n), m, f)
10254 +
10255 +#define task_nx_flags(t, m, f) \
10256 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10257 +
10258 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10259 +
10260 +
10261 +/* network caps */
10262 +
10263 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10264 +
10265 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10266 +
10267 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10268 +
10269 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10270 +
10271 +
10272 +/* context mask capabilities */
10273 +
10274 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10275 +
10276 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10277 +
10278 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10279 +
10280 +
10281 +/* context bcap mask */
10282 +
10283 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10284 +
10285 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10286 +
10287 +
10288 +/* mask given bcaps */
10289 +
10290 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10291 +
10292 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10293 +
10294 +
10295 +/* masked cap_bset */
10296 +
10297 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10298 +
10299 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10300 +
10301 +#if 0
10302 +#define vx_info_mbcap(v, b) \
10303 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10304 +       vx_info_bcaps(v, b) : (b))
10305 +
10306 +#define task_vx_mbcap(t, b) \
10307 +       vx_info_mbcap((t)->vx_info, (t)->b)
10308 +
10309 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10310 +#endif
10311 +
10312 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10313 +
10314 +#define vx_capable(b, c) (capable(b) || \
10315 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10316 +
10317 +#define nx_capable(b, c) (capable(b) || \
10318 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10319 +
10320 +#define vx_task_initpid(t, n) \
10321 +       ((t)->vx_info && \
10322 +       ((t)->vx_info->vx_initpid == (n)))
10323 +
10324 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10325 +
10326 +
10327 +/* context unshare mask */
10328 +
10329 +#define __vx_umask(v)          ((v)->vx_umask)
10330 +
10331 +#define vx_current_umask()     __vx_umask(current_vx_info())
10332 +
10333 +#define vx_can_unshare(b, f) (capable(b) || \
10334 +       (cap_raised(current_cap(), b) && \
10335 +       !((f) & ~vx_current_umask())))
10336 +
10337 +
10338 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10339 +
10340 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10341 +
10342 +
10343 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10344 +
10345 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10346 +
10347 +#endif
10348 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/cacct_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cacct_cmd.h
10349 --- linux-2.6.32.10/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00.000000000 +0100
10350 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cacct_cmd.h   2009-12-03 20:04:56.000000000 +0100
10351 @@ -0,0 +1,23 @@
10352 +#ifndef _VX_CACCT_CMD_H
10353 +#define _VX_CACCT_CMD_H
10354 +
10355 +
10356 +/* virtual host info name commands */
10357 +
10358 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10359 +
10360 +struct vcmd_sock_stat_v0 {
10361 +       uint32_t field;
10362 +       uint32_t count[3];
10363 +       uint64_t total[3];
10364 +};
10365 +
10366 +
10367 +#ifdef __KERNEL__
10368 +
10369 +#include <linux/compiler.h>
10370 +
10371 +extern int vc_sock_stat(struct vx_info *, void __user *);
10372 +
10373 +#endif /* __KERNEL__ */
10374 +#endif /* _VX_CACCT_CMD_H */
10375 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/cacct_def.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cacct_def.h
10376 --- linux-2.6.32.10/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00.000000000 +0100
10377 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cacct_def.h   2009-12-03 20:04:56.000000000 +0100
10378 @@ -0,0 +1,43 @@
10379 +#ifndef _VX_CACCT_DEF_H
10380 +#define _VX_CACCT_DEF_H
10381 +
10382 +#include <asm/atomic.h>
10383 +#include <linux/vserver/cacct.h>
10384 +
10385 +
10386 +struct _vx_sock_acc {
10387 +       atomic_long_t count;
10388 +       atomic_long_t total;
10389 +};
10390 +
10391 +/* context sub struct */
10392 +
10393 +struct _vx_cacct {
10394 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10395 +       atomic_t slab[8];
10396 +       atomic_t page[6][8];
10397 +};
10398 +
10399 +#ifdef CONFIG_VSERVER_DEBUG
10400 +
10401 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10402 +{
10403 +       int i, j;
10404 +
10405 +       printk("\t_vx_cacct:");
10406 +       for (i = 0; i < 6; i++) {
10407 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10408 +
10409 +               printk("\t [%d] =", i);
10410 +               for (j = 0; j < 3; j++) {
10411 +                       printk(" [%d] = %8lu, %8lu", j,
10412 +                               atomic_long_read(&ptr[j].count),
10413 +                               atomic_long_read(&ptr[j].total));
10414 +               }
10415 +               printk("\n");
10416 +       }
10417 +}
10418 +
10419 +#endif
10420 +
10421 +#endif /* _VX_CACCT_DEF_H */
10422 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/cacct.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cacct.h
10423 --- linux-2.6.32.10/include/linux/vserver/cacct.h       1970-01-01 01:00:00.000000000 +0100
10424 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cacct.h       2009-12-03 20:04:56.000000000 +0100
10425 @@ -0,0 +1,15 @@
10426 +#ifndef _VX_CACCT_H
10427 +#define _VX_CACCT_H
10428 +
10429 +
10430 +enum sock_acc_field {
10431 +       VXA_SOCK_UNSPEC = 0,
10432 +       VXA_SOCK_UNIX,
10433 +       VXA_SOCK_INET,
10434 +       VXA_SOCK_INET6,
10435 +       VXA_SOCK_PACKET,
10436 +       VXA_SOCK_OTHER,
10437 +       VXA_SOCK_SIZE   /* array size */
10438 +};
10439 +
10440 +#endif /* _VX_CACCT_H */
10441 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/cacct_int.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cacct_int.h
10442 --- linux-2.6.32.10/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00.000000000 +0100
10443 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cacct_int.h   2009-12-03 20:04:56.000000000 +0100
10444 @@ -0,0 +1,21 @@
10445 +#ifndef _VX_CACCT_INT_H
10446 +#define _VX_CACCT_INT_H
10447 +
10448 +
10449 +#ifdef __KERNEL__
10450 +
10451 +static inline
10452 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10453 +{
10454 +       return atomic_long_read(&cacct->sock[type][pos].count);
10455 +}
10456 +
10457 +
10458 +static inline
10459 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10460 +{
10461 +       return atomic_long_read(&cacct->sock[type][pos].total);
10462 +}
10463 +
10464 +#endif /* __KERNEL__ */
10465 +#endif /* _VX_CACCT_INT_H */
10466 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/check.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/check.h
10467 --- linux-2.6.32.10/include/linux/vserver/check.h       1970-01-01 01:00:00.000000000 +0100
10468 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/check.h       2009-12-03 20:04:56.000000000 +0100
10469 @@ -0,0 +1,89 @@
10470 +#ifndef _VS_CHECK_H
10471 +#define _VS_CHECK_H
10472 +
10473 +
10474 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10475 +
10476 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10477 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10478 +#else
10479 +#define MIN_D_CONTEXT  65536
10480 +#endif
10481 +
10482 +/* check conditions */
10483 +
10484 +#define VS_ADMIN       0x0001
10485 +#define VS_WATCH       0x0002
10486 +#define VS_HIDE                0x0004
10487 +#define VS_HOSTID      0x0008
10488 +
10489 +#define VS_IDENT       0x0010
10490 +#define VS_EQUIV       0x0020
10491 +#define VS_PARENT      0x0040
10492 +#define VS_CHILD       0x0080
10493 +
10494 +#define VS_ARG_MASK    0x00F0
10495 +
10496 +#define VS_DYNAMIC     0x0100
10497 +#define VS_STATIC      0x0200
10498 +
10499 +#define VS_ATR_MASK    0x0F00
10500 +
10501 +#ifdef CONFIG_VSERVER_PRIVACY
10502 +#define VS_ADMIN_P     (0)
10503 +#define VS_WATCH_P     (0)
10504 +#else
10505 +#define VS_ADMIN_P     VS_ADMIN
10506 +#define VS_WATCH_P     VS_WATCH
10507 +#endif
10508 +
10509 +#define VS_HARDIRQ     0x1000
10510 +#define VS_SOFTIRQ     0x2000
10511 +#define VS_IRQ         0x4000
10512 +
10513 +#define VS_IRQ_MASK    0xF000
10514 +
10515 +#include <linux/hardirq.h>
10516 +
10517 +/*
10518 + * check current context for ADMIN/WATCH and
10519 + * optionally against supplied argument
10520 + */
10521 +static inline int __vs_check(int cid, int id, unsigned int mode)
10522 +{
10523 +       if (mode & VS_ARG_MASK) {
10524 +               if ((mode & VS_IDENT) && (id == cid))
10525 +                       return 1;
10526 +       }
10527 +       if (mode & VS_ATR_MASK) {
10528 +               if ((mode & VS_DYNAMIC) &&
10529 +                       (id >= MIN_D_CONTEXT) &&
10530 +                       (id <= MAX_S_CONTEXT))
10531 +                       return 1;
10532 +               if ((mode & VS_STATIC) &&
10533 +                       (id > 1) && (id < MIN_D_CONTEXT))
10534 +                       return 1;
10535 +       }
10536 +       if (mode & VS_IRQ_MASK) {
10537 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10538 +                       return 1;
10539 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10540 +                       return 1;
10541 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10542 +                       return 1;
10543 +       }
10544 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10545 +               ((mode & VS_WATCH) && (cid == 1)) ||
10546 +               ((mode & VS_HOSTID) && (id == 0)));
10547 +}
10548 +
10549 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10550 +
10551 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10552 +
10553 +
10554 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10555 +
10556 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10557 +
10558 +#endif
10559 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/context_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/context_cmd.h
10560 --- linux-2.6.32.10/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00.000000000 +0100
10561 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/context_cmd.h 2009-12-03 20:04:56.000000000 +0100
10562 @@ -0,0 +1,145 @@
10563 +#ifndef _VX_CONTEXT_CMD_H
10564 +#define _VX_CONTEXT_CMD_H
10565 +
10566 +
10567 +/* vinfo commands */
10568 +
10569 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10570 +
10571 +#ifdef __KERNEL__
10572 +extern int vc_task_xid(uint32_t);
10573 +
10574 +#endif /* __KERNEL__ */
10575 +
10576 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10577 +
10578 +struct vcmd_vx_info_v0 {
10579 +       uint32_t xid;
10580 +       uint32_t initpid;
10581 +       /* more to come */
10582 +};
10583 +
10584 +#ifdef __KERNEL__
10585 +extern int vc_vx_info(struct vx_info *, void __user *);
10586 +
10587 +#endif /* __KERNEL__ */
10588 +
10589 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10590 +
10591 +struct vcmd_ctx_stat_v0 {
10592 +       uint32_t usecnt;
10593 +       uint32_t tasks;
10594 +       /* more to come */
10595 +};
10596 +
10597 +#ifdef __KERNEL__
10598 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10599 +
10600 +#endif /* __KERNEL__ */
10601 +
10602 +/* context commands */
10603 +
10604 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10605 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10606 +
10607 +struct vcmd_ctx_create {
10608 +       uint64_t flagword;
10609 +};
10610 +
10611 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10612 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10613 +
10614 +struct vcmd_ctx_migrate {
10615 +       uint64_t flagword;
10616 +};
10617 +
10618 +#ifdef __KERNEL__
10619 +extern int vc_ctx_create(uint32_t, void __user *);
10620 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10621 +
10622 +#endif /* __KERNEL__ */
10623 +
10624 +
10625 +/* flag commands */
10626 +
10627 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10628 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10629 +
10630 +struct vcmd_ctx_flags_v0 {
10631 +       uint64_t flagword;
10632 +       uint64_t mask;
10633 +};
10634 +
10635 +#ifdef __KERNEL__
10636 +extern int vc_get_cflags(struct vx_info *, void __user *);
10637 +extern int vc_set_cflags(struct vx_info *, void __user *);
10638 +
10639 +#endif /* __KERNEL__ */
10640 +
10641 +
10642 +/* context caps commands */
10643 +
10644 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10645 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10646 +
10647 +struct vcmd_ctx_caps_v1 {
10648 +       uint64_t ccaps;
10649 +       uint64_t cmask;
10650 +};
10651 +
10652 +#ifdef __KERNEL__
10653 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10654 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10655 +
10656 +#endif /* __KERNEL__ */
10657 +
10658 +
10659 +/* bcaps commands */
10660 +
10661 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10662 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10663 +
10664 +struct vcmd_bcaps {
10665 +       uint64_t bcaps;
10666 +       uint64_t bmask;
10667 +};
10668 +
10669 +#ifdef __KERNEL__
10670 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10671 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10672 +
10673 +#endif /* __KERNEL__ */
10674 +
10675 +
10676 +/* umask commands */
10677 +
10678 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10679 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10680 +
10681 +struct vcmd_umask {
10682 +       uint64_t umask;
10683 +       uint64_t mask;
10684 +};
10685 +
10686 +#ifdef __KERNEL__
10687 +extern int vc_get_umask(struct vx_info *, void __user *);
10688 +extern int vc_set_umask(struct vx_info *, void __user *);
10689 +
10690 +#endif /* __KERNEL__ */
10691 +
10692 +
10693 +/* OOM badness */
10694 +
10695 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10696 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10697 +
10698 +struct vcmd_badness_v0 {
10699 +       int64_t bias;
10700 +};
10701 +
10702 +#ifdef __KERNEL__
10703 +extern int vc_get_badness(struct vx_info *, void __user *);
10704 +extern int vc_set_badness(struct vx_info *, void __user *);
10705 +
10706 +#endif /* __KERNEL__ */
10707 +#endif /* _VX_CONTEXT_CMD_H */
10708 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/context.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/context.h
10709 --- linux-2.6.32.10/include/linux/vserver/context.h     1970-01-01 01:00:00.000000000 +0100
10710 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/context.h     2010-03-13 21:50:00.000000000 +0100
10711 @@ -0,0 +1,184 @@
10712 +#ifndef _VX_CONTEXT_H
10713 +#define _VX_CONTEXT_H
10714 +
10715 +#include <linux/types.h>
10716 +#include <linux/capability.h>
10717 +
10718 +
10719 +/* context flags */
10720 +
10721 +#define VXF_INFO_SCHED         0x00000002
10722 +#define VXF_INFO_NPROC         0x00000004
10723 +#define VXF_INFO_PRIVATE       0x00000008
10724 +
10725 +#define VXF_INFO_INIT          0x00000010
10726 +#define VXF_INFO_HIDE          0x00000020
10727 +#define VXF_INFO_ULIMIT                0x00000040
10728 +#define VXF_INFO_NSPACE                0x00000080
10729 +
10730 +#define VXF_SCHED_HARD         0x00000100
10731 +#define VXF_SCHED_PRIO         0x00000200
10732 +#define VXF_SCHED_PAUSE                0x00000400
10733 +
10734 +#define VXF_VIRT_MEM           0x00010000
10735 +#define VXF_VIRT_UPTIME                0x00020000
10736 +#define VXF_VIRT_CPU           0x00040000
10737 +#define VXF_VIRT_LOAD          0x00080000
10738 +#define VXF_VIRT_TIME          0x00100000
10739 +
10740 +#define VXF_HIDE_MOUNT         0x01000000
10741 +/* was VXF_HIDE_NETIF          0x02000000 */
10742 +#define VXF_HIDE_VINFO         0x04000000
10743 +
10744 +#define VXF_STATE_SETUP                (1ULL << 32)
10745 +#define VXF_STATE_INIT         (1ULL << 33)
10746 +#define VXF_STATE_ADMIN                (1ULL << 34)
10747 +
10748 +#define VXF_SC_HELPER          (1ULL << 36)
10749 +#define VXF_REBOOT_KILL                (1ULL << 37)
10750 +#define VXF_PERSISTENT         (1ULL << 38)
10751 +
10752 +#define VXF_FORK_RSS           (1ULL << 48)
10753 +#define VXF_PROLIFIC           (1ULL << 49)
10754 +
10755 +#define VXF_IGNEG_NICE         (1ULL << 52)
10756 +
10757 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10758 +
10759 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10760 +
10761 +
10762 +/* context migration */
10763 +
10764 +#define VXM_SET_INIT           0x00000001
10765 +#define VXM_SET_REAPER         0x00000002
10766 +
10767 +/* context caps */
10768 +
10769 +#define VXC_CAP_MASK           0x00000000
10770 +
10771 +#define VXC_SET_UTSNAME                0x00000001
10772 +#define VXC_SET_RLIMIT         0x00000002
10773 +#define VXC_FS_SECURITY                0x00000004
10774 +#define VXC_FS_TRUSTED         0x00000008
10775 +#define VXC_TIOCSTI            0x00000010
10776 +
10777 +/* was VXC_RAW_ICMP            0x00000100 */
10778 +#define VXC_SYSLOG             0x00001000
10779 +#define VXC_OOM_ADJUST         0x00002000
10780 +#define VXC_AUDIT_CONTROL      0x00004000
10781 +
10782 +#define VXC_SECURE_MOUNT       0x00010000
10783 +#define VXC_SECURE_REMOUNT     0x00020000
10784 +#define VXC_BINARY_MOUNT       0x00040000
10785 +
10786 +#define VXC_QUOTA_CTL          0x00100000
10787 +#define VXC_ADMIN_MAPPER       0x00200000
10788 +#define VXC_ADMIN_CLOOP                0x00400000
10789 +
10790 +#define VXC_KTHREAD            0x01000000
10791 +#define VXC_NAMESPACE          0x02000000
10792 +
10793 +
10794 +#ifdef __KERNEL__
10795 +
10796 +#include <linux/list.h>
10797 +#include <linux/spinlock.h>
10798 +#include <linux/rcupdate.h>
10799 +
10800 +#include "limit_def.h"
10801 +#include "sched_def.h"
10802 +#include "cvirt_def.h"
10803 +#include "cacct_def.h"
10804 +#include "device_def.h"
10805 +
10806 +#define VX_SPACES      2
10807 +
10808 +struct _vx_info_pc {
10809 +       struct _vx_sched_pc sched_pc;
10810 +       struct _vx_cvirt_pc cvirt_pc;
10811 +};
10812 +
10813 +struct vx_info {
10814 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10815 +       xid_t vx_id;                            /* context id */
10816 +       atomic_t vx_usecnt;                     /* usage count */
10817 +       atomic_t vx_tasks;                      /* tasks count */
10818 +       struct vx_info *vx_parent;              /* parent context */
10819 +       int vx_state;                           /* context state */
10820 +
10821 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10822 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10823 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10824 +
10825 +       uint64_t vx_flags;                      /* context flags */
10826 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10827 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10828 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10829 +
10830 +       struct task_struct *vx_reaper;          /* guest reaper process */
10831 +       pid_t vx_initpid;                       /* PID of guest init */
10832 +       int64_t vx_badness_bias;                /* OOM points bias */
10833 +
10834 +       struct _vx_limit limit;                 /* vserver limits */
10835 +       struct _vx_sched sched;                 /* vserver scheduler */
10836 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10837 +       struct _vx_cacct cacct;                 /* context accounting */
10838 +
10839 +       struct _vx_device dmap;                 /* default device map targets */
10840 +
10841 +#ifndef CONFIG_SMP
10842 +       struct _vx_info_pc info_pc;             /* per cpu data */
10843 +#else
10844 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10845 +#endif
10846 +
10847 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10848 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10849 +       int exit_code;                          /* last process exit code */
10850 +
10851 +       char vx_name[65];                       /* vserver name */
10852 +};
10853 +
10854 +#ifndef CONFIG_SMP
10855 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10856 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10857 +#else
10858 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10859 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10860 +#endif
10861 +
10862 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10863 +
10864 +
10865 +struct vx_info_save {
10866 +       struct vx_info *vxi;
10867 +       xid_t xid;
10868 +};
10869 +
10870 +
10871 +/* status flags */
10872 +
10873 +#define VXS_HASHED     0x0001
10874 +#define VXS_PAUSED     0x0010
10875 +#define VXS_SHUTDOWN   0x0100
10876 +#define VXS_HELPER     0x1000
10877 +#define VXS_RELEASED   0x8000
10878 +
10879 +
10880 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10881 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10882 +
10883 +extern struct vx_info *lookup_vx_info(int);
10884 +extern struct vx_info *lookup_or_create_vx_info(int);
10885 +
10886 +extern int get_xid_list(int, unsigned int *, int);
10887 +extern int xid_is_hashed(xid_t);
10888 +
10889 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10890 +
10891 +extern long vs_state_change(struct vx_info *, unsigned int);
10892 +
10893 +
10894 +#endif /* __KERNEL__ */
10895 +#endif /* _VX_CONTEXT_H */
10896 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/cvirt_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cvirt_cmd.h
10897 --- linux-2.6.32.10/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00.000000000 +0100
10898 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cvirt_cmd.h   2009-12-03 20:04:56.000000000 +0100
10899 @@ -0,0 +1,53 @@
10900 +#ifndef _VX_CVIRT_CMD_H
10901 +#define _VX_CVIRT_CMD_H
10902 +
10903 +
10904 +/* virtual host info name commands */
10905 +
10906 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10907 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10908 +
10909 +struct vcmd_vhi_name_v0 {
10910 +       uint32_t field;
10911 +       char name[65];
10912 +};
10913 +
10914 +
10915 +enum vhi_name_field {
10916 +       VHIN_CONTEXT = 0,
10917 +       VHIN_SYSNAME,
10918 +       VHIN_NODENAME,
10919 +       VHIN_RELEASE,
10920 +       VHIN_VERSION,
10921 +       VHIN_MACHINE,
10922 +       VHIN_DOMAINNAME,
10923 +};
10924 +
10925 +
10926 +#ifdef __KERNEL__
10927 +
10928 +#include <linux/compiler.h>
10929 +
10930 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10931 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10932 +
10933 +#endif /* __KERNEL__ */
10934 +
10935 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10936 +
10937 +struct vcmd_virt_stat_v0 {
10938 +       uint64_t offset;
10939 +       uint64_t uptime;
10940 +       uint32_t nr_threads;
10941 +       uint32_t nr_running;
10942 +       uint32_t nr_uninterruptible;
10943 +       uint32_t nr_onhold;
10944 +       uint32_t nr_forks;
10945 +       uint32_t load[3];
10946 +};
10947 +
10948 +#ifdef __KERNEL__
10949 +extern int vc_virt_stat(struct vx_info *, void __user *);
10950 +
10951 +#endif /* __KERNEL__ */
10952 +#endif /* _VX_CVIRT_CMD_H */
10953 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/cvirt_def.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cvirt_def.h
10954 --- linux-2.6.32.10/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00.000000000 +0100
10955 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cvirt_def.h   2009-12-03 20:04:56.000000000 +0100
10956 @@ -0,0 +1,80 @@
10957 +#ifndef _VX_CVIRT_DEF_H
10958 +#define _VX_CVIRT_DEF_H
10959 +
10960 +#include <linux/jiffies.h>
10961 +#include <linux/spinlock.h>
10962 +#include <linux/wait.h>
10963 +#include <linux/time.h>
10964 +#include <asm/atomic.h>
10965 +
10966 +
10967 +struct _vx_usage_stat {
10968 +       uint64_t user;
10969 +       uint64_t nice;
10970 +       uint64_t system;
10971 +       uint64_t softirq;
10972 +       uint64_t irq;
10973 +       uint64_t idle;
10974 +       uint64_t iowait;
10975 +};
10976 +
10977 +struct _vx_syslog {
10978 +       wait_queue_head_t log_wait;
10979 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10980 +
10981 +       unsigned long log_start;        /* next char to be read by syslog() */
10982 +       unsigned long con_start;        /* next char to be sent to consoles */
10983 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10984 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10985 +
10986 +       char log_buf[1024];
10987 +};
10988 +
10989 +
10990 +/* context sub struct */
10991 +
10992 +struct _vx_cvirt {
10993 +       atomic_t nr_threads;            /* number of current threads */
10994 +       atomic_t nr_running;            /* number of running threads */
10995 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10996 +
10997 +       atomic_t nr_onhold;             /* processes on hold */
10998 +       uint32_t onhold_last;           /* jiffies when put on hold */
10999 +
11000 +       struct timeval bias_tv;         /* time offset to the host */
11001 +       struct timespec bias_idle;
11002 +       struct timespec bias_uptime;    /* context creation point */
11003 +       uint64_t bias_clock;            /* offset in clock_t */
11004 +
11005 +       spinlock_t load_lock;           /* lock for the load averages */
11006 +       atomic_t load_updates;          /* nr of load updates done so far */
11007 +       uint32_t load_last;             /* last time load was calculated */
11008 +       uint32_t load[3];               /* load averages 1,5,15 */
11009 +
11010 +       atomic_t total_forks;           /* number of forks so far */
11011 +
11012 +       struct _vx_syslog syslog;
11013 +};
11014 +
11015 +struct _vx_cvirt_pc {
11016 +       struct _vx_usage_stat cpustat;
11017 +};
11018 +
11019 +
11020 +#ifdef CONFIG_VSERVER_DEBUG
11021 +
11022 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11023 +{
11024 +       printk("\t_vx_cvirt:\n");
11025 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11026 +               atomic_read(&cvirt->nr_threads),
11027 +               atomic_read(&cvirt->nr_running),
11028 +               atomic_read(&cvirt->nr_uninterruptible),
11029 +               atomic_read(&cvirt->nr_onhold));
11030 +       /* add rest here */
11031 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11032 +}
11033 +
11034 +#endif
11035 +
11036 +#endif /* _VX_CVIRT_DEF_H */
11037 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/cvirt.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cvirt.h
11038 --- linux-2.6.32.10/include/linux/vserver/cvirt.h       1970-01-01 01:00:00.000000000 +0100
11039 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/cvirt.h       2009-12-03 20:04:56.000000000 +0100
11040 @@ -0,0 +1,20 @@
11041 +#ifndef _VX_CVIRT_H
11042 +#define _VX_CVIRT_H
11043 +
11044 +
11045 +#ifdef __KERNEL__
11046 +
11047 +struct timespec;
11048 +
11049 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11050 +
11051 +
11052 +struct vx_info;
11053 +
11054 +void vx_update_load(struct vx_info *);
11055 +
11056 +
11057 +int vx_do_syslog(int, char __user *, int);
11058 +
11059 +#endif /* __KERNEL__ */
11060 +#endif /* _VX_CVIRT_H */
11061 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/debug_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/debug_cmd.h
11062 --- linux-2.6.32.10/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00.000000000 +0100
11063 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/debug_cmd.h   2009-12-03 20:04:56.000000000 +0100
11064 @@ -0,0 +1,58 @@
11065 +#ifndef _VX_DEBUG_CMD_H
11066 +#define _VX_DEBUG_CMD_H
11067 +
11068 +
11069 +/* debug commands */
11070 +
11071 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11072 +
11073 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11074 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11075 +
11076 +struct  vcmd_read_history_v0 {
11077 +       uint32_t index;
11078 +       uint32_t count;
11079 +       char __user *data;
11080 +};
11081 +
11082 +struct  vcmd_read_monitor_v0 {
11083 +       uint32_t index;
11084 +       uint32_t count;
11085 +       char __user *data;
11086 +};
11087 +
11088 +
11089 +#ifdef __KERNEL__
11090 +
11091 +#ifdef CONFIG_COMPAT
11092 +
11093 +#include <asm/compat.h>
11094 +
11095 +struct vcmd_read_history_v0_x32 {
11096 +       uint32_t index;
11097 +       uint32_t count;
11098 +       compat_uptr_t data_ptr;
11099 +};
11100 +
11101 +struct vcmd_read_monitor_v0_x32 {
11102 +       uint32_t index;
11103 +       uint32_t count;
11104 +       compat_uptr_t data_ptr;
11105 +};
11106 +
11107 +#endif  /* CONFIG_COMPAT */
11108 +
11109 +extern int vc_dump_history(uint32_t);
11110 +
11111 +extern int vc_read_history(uint32_t, void __user *);
11112 +extern int vc_read_monitor(uint32_t, void __user *);
11113 +
11114 +#ifdef CONFIG_COMPAT
11115 +
11116 +extern int vc_read_history_x32(uint32_t, void __user *);
11117 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11118 +
11119 +#endif  /* CONFIG_COMPAT */
11120 +
11121 +#endif /* __KERNEL__ */
11122 +#endif /* _VX_DEBUG_CMD_H */
11123 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/debug.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/debug.h
11124 --- linux-2.6.32.10/include/linux/vserver/debug.h       1970-01-01 01:00:00.000000000 +0100
11125 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/debug.h       2009-12-03 20:04:56.000000000 +0100
11126 @@ -0,0 +1,127 @@
11127 +#ifndef _VX_DEBUG_H
11128 +#define _VX_DEBUG_H
11129 +
11130 +
11131 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11132 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11133 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11134 +
11135 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11136 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11137 +#define VXF_DEV                "%p[%lu,%d:%d]"
11138 +
11139 +
11140 +#define vxd_path(p)                                            \
11141 +       ({ static char _buffer[PATH_MAX];                       \
11142 +          d_path(p, _buffer, sizeof(_buffer)); })
11143 +
11144 +#define vxd_cond_path(n)                                       \
11145 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11146 +
11147 +
11148 +#ifdef CONFIG_VSERVER_DEBUG
11149 +
11150 +extern unsigned int vx_debug_switch;
11151 +extern unsigned int vx_debug_xid;
11152 +extern unsigned int vx_debug_nid;
11153 +extern unsigned int vx_debug_tag;
11154 +extern unsigned int vx_debug_net;
11155 +extern unsigned int vx_debug_limit;
11156 +extern unsigned int vx_debug_cres;
11157 +extern unsigned int vx_debug_dlim;
11158 +extern unsigned int vx_debug_quota;
11159 +extern unsigned int vx_debug_cvirt;
11160 +extern unsigned int vx_debug_space;
11161 +extern unsigned int vx_debug_misc;
11162 +
11163 +
11164 +#define VX_LOGLEVEL    "vxD: "
11165 +#define VX_PROC_FMT    "%p: "
11166 +#define VX_PROCESS     current
11167 +
11168 +#define vxdprintk(c, f, x...)                                  \
11169 +       do {                                                    \
11170 +               if (c)                                          \
11171 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11172 +                               VX_PROCESS , ##x);              \
11173 +       } while (0)
11174 +
11175 +#define vxlprintk(c, f, x...)                                  \
11176 +       do {                                                    \
11177 +               if (c)                                          \
11178 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11179 +       } while (0)
11180 +
11181 +#define vxfprintk(c, f, x...)                                  \
11182 +       do {                                                    \
11183 +               if (c)                                          \
11184 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11185 +       } while (0)
11186 +
11187 +
11188 +struct vx_info;
11189 +
11190 +void dump_vx_info(struct vx_info *, int);
11191 +void dump_vx_info_inactive(int);
11192 +
11193 +#else  /* CONFIG_VSERVER_DEBUG */
11194 +
11195 +#define vx_debug_switch 0
11196 +#define vx_debug_xid   0
11197 +#define vx_debug_nid   0
11198 +#define vx_debug_tag   0
11199 +#define vx_debug_net   0
11200 +#define vx_debug_limit 0
11201 +#define vx_debug_cres  0
11202 +#define vx_debug_dlim  0
11203 +#define vx_debug_cvirt 0
11204 +
11205 +#define vxdprintk(x...) do { } while (0)
11206 +#define vxlprintk(x...) do { } while (0)
11207 +#define vxfprintk(x...) do { } while (0)
11208 +
11209 +#endif /* CONFIG_VSERVER_DEBUG */
11210 +
11211 +
11212 +#ifdef CONFIG_VSERVER_WARN
11213 +
11214 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11215 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11216 +#define VX_WARN_XID    "[xid #%u] "
11217 +#define VX_WARN_NID    "[nid #%u] "
11218 +#define VX_WARN_TAG    "[tag #%u] "
11219 +
11220 +#define vxwprintk(c, f, x...)                                  \
11221 +       do {                                                    \
11222 +               if (c)                                          \
11223 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11224 +       } while (0)
11225 +
11226 +#else  /* CONFIG_VSERVER_WARN */
11227 +
11228 +#define vxwprintk(x...) do { } while (0)
11229 +
11230 +#endif /* CONFIG_VSERVER_WARN */
11231 +
11232 +#define vxwprintk_task(c, f, x...)                             \
11233 +       vxwprintk(c, VX_WARN_TASK f,                            \
11234 +               current->comm, current->pid,                    \
11235 +               current->xid, current->nid, current->tag, ##x)
11236 +#define vxwprintk_xid(c, f, x...)                              \
11237 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11238 +#define vxwprintk_nid(c, f, x...)                              \
11239 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11240 +#define vxwprintk_tag(c, f, x...)                              \
11241 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11242 +
11243 +#ifdef CONFIG_VSERVER_DEBUG
11244 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11245 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11246 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11247 +#else
11248 +#define vxd_assert_lock(l)     do { } while (0)
11249 +#define vxd_assert(c, f, x...) do { } while (0)
11250 +#endif
11251 +
11252 +
11253 +#endif /* _VX_DEBUG_H */
11254 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/device_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/device_cmd.h
11255 --- linux-2.6.32.10/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00.000000000 +0100
11256 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/device_cmd.h  2009-12-03 20:04:56.000000000 +0100
11257 @@ -0,0 +1,44 @@
11258 +#ifndef _VX_DEVICE_CMD_H
11259 +#define _VX_DEVICE_CMD_H
11260 +
11261 +
11262 +/*  device vserver commands */
11263 +
11264 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11265 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11266 +
11267 +struct vcmd_set_mapping_v0 {
11268 +       const char __user *device;
11269 +       const char __user *target;
11270 +       uint32_t flags;
11271 +};
11272 +
11273 +
11274 +#ifdef __KERNEL__
11275 +
11276 +#ifdef CONFIG_COMPAT
11277 +
11278 +#include <asm/compat.h>
11279 +
11280 +struct vcmd_set_mapping_v0_x32 {
11281 +       compat_uptr_t device_ptr;
11282 +       compat_uptr_t target_ptr;
11283 +       uint32_t flags;
11284 +};
11285 +
11286 +#endif /* CONFIG_COMPAT */
11287 +
11288 +#include <linux/compiler.h>
11289 +
11290 +extern int vc_set_mapping(struct vx_info *, void __user *);
11291 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11292 +
11293 +#ifdef CONFIG_COMPAT
11294 +
11295 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11296 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11297 +
11298 +#endif /* CONFIG_COMPAT */
11299 +
11300 +#endif /* __KERNEL__ */
11301 +#endif /* _VX_DEVICE_CMD_H */
11302 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/device_def.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/device_def.h
11303 --- linux-2.6.32.10/include/linux/vserver/device_def.h  1970-01-01 01:00:00.000000000 +0100
11304 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/device_def.h  2009-12-03 20:04:56.000000000 +0100
11305 @@ -0,0 +1,17 @@
11306 +#ifndef _VX_DEVICE_DEF_H
11307 +#define _VX_DEVICE_DEF_H
11308 +
11309 +#include <linux/types.h>
11310 +
11311 +struct vx_dmap_target {
11312 +       dev_t target;
11313 +       uint32_t flags;
11314 +};
11315 +
11316 +struct _vx_device {
11317 +#ifdef CONFIG_VSERVER_DEVICE
11318 +       struct vx_dmap_target targets[2];
11319 +#endif
11320 +};
11321 +
11322 +#endif /* _VX_DEVICE_DEF_H */
11323 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/device.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/device.h
11324 --- linux-2.6.32.10/include/linux/vserver/device.h      1970-01-01 01:00:00.000000000 +0100
11325 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/device.h      2009-12-03 20:04:56.000000000 +0100
11326 @@ -0,0 +1,15 @@
11327 +#ifndef _VX_DEVICE_H
11328 +#define _VX_DEVICE_H
11329 +
11330 +
11331 +#define DATTR_CREATE   0x00000001
11332 +#define DATTR_OPEN     0x00000002
11333 +
11334 +#define DATTR_REMAP    0x00000010
11335 +
11336 +#define DATTR_MASK     0x00000013
11337 +
11338 +
11339 +#else  /* _VX_DEVICE_H */
11340 +#warning duplicate inclusion
11341 +#endif /* _VX_DEVICE_H */
11342 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/dlimit_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/dlimit_cmd.h
11343 --- linux-2.6.32.10/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00.000000000 +0100
11344 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/dlimit_cmd.h  2009-12-10 16:43:43.000000000 +0100
11345 @@ -0,0 +1,109 @@
11346 +#ifndef _VX_DLIMIT_CMD_H
11347 +#define _VX_DLIMIT_CMD_H
11348 +
11349 +
11350 +/*  dlimit vserver commands */
11351 +
11352 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11353 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11354 +
11355 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11356 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11357 +
11358 +struct vcmd_ctx_dlimit_base_v0 {
11359 +       const char __user *name;
11360 +       uint32_t flags;
11361 +};
11362 +
11363 +struct vcmd_ctx_dlimit_v0 {
11364 +       const char __user *name;
11365 +       uint32_t space_used;                    /* used space in kbytes */
11366 +       uint32_t space_total;                   /* maximum space in kbytes */
11367 +       uint32_t inodes_used;                   /* used inodes */
11368 +       uint32_t inodes_total;                  /* maximum inodes */
11369 +       uint32_t reserved;                      /* reserved for root in % */
11370 +       uint32_t flags;
11371 +};
11372 +
11373 +#define CDLIM_UNSET            ((uint32_t)0UL)
11374 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11375 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11376 +
11377 +#define DLIME_UNIT     0
11378 +#define DLIME_KILO     1
11379 +#define DLIME_MEGA     2
11380 +#define DLIME_GIGA     3
11381 +
11382 +#define DLIMF_SHIFT    0x10
11383 +
11384 +#define DLIMS_USED     0
11385 +#define DLIMS_TOTAL    2
11386 +
11387 +static inline
11388 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11389 +{
11390 +       int exp = (flags & DLIMF_SHIFT) ?
11391 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11392 +       return ((uint64_t)val) << (10 * exp);
11393 +}
11394 +
11395 +static inline
11396 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11397 +{
11398 +       int exp = 0;
11399 +
11400 +       if (*flags & DLIMF_SHIFT) {
11401 +               while (val > (1LL << 32) && (exp < 3)) {
11402 +                       val >>= 10;
11403 +                       exp++;
11404 +               }
11405 +               *flags &= ~(DLIME_GIGA << shift);
11406 +               *flags |= exp << shift;
11407 +       } else
11408 +               val >>= 10;
11409 +       return val;
11410 +}
11411 +
11412 +#ifdef __KERNEL__
11413 +
11414 +#ifdef CONFIG_COMPAT
11415 +
11416 +#include <asm/compat.h>
11417 +
11418 +struct vcmd_ctx_dlimit_base_v0_x32 {
11419 +       compat_uptr_t name_ptr;
11420 +       uint32_t flags;
11421 +};
11422 +
11423 +struct vcmd_ctx_dlimit_v0_x32 {
11424 +       compat_uptr_t name_ptr;
11425 +       uint32_t space_used;                    /* used space in kbytes */
11426 +       uint32_t space_total;                   /* maximum space in kbytes */
11427 +       uint32_t inodes_used;                   /* used inodes */
11428 +       uint32_t inodes_total;                  /* maximum inodes */
11429 +       uint32_t reserved;                      /* reserved for root in % */
11430 +       uint32_t flags;
11431 +};
11432 +
11433 +#endif /* CONFIG_COMPAT */
11434 +
11435 +#include <linux/compiler.h>
11436 +
11437 +extern int vc_add_dlimit(uint32_t, void __user *);
11438 +extern int vc_rem_dlimit(uint32_t, void __user *);
11439 +
11440 +extern int vc_set_dlimit(uint32_t, void __user *);
11441 +extern int vc_get_dlimit(uint32_t, void __user *);
11442 +
11443 +#ifdef CONFIG_COMPAT
11444 +
11445 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11446 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11447 +
11448 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11449 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11450 +
11451 +#endif /* CONFIG_COMPAT */
11452 +
11453 +#endif /* __KERNEL__ */
11454 +#endif /* _VX_DLIMIT_CMD_H */
11455 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/dlimit.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/dlimit.h
11456 --- linux-2.6.32.10/include/linux/vserver/dlimit.h      1970-01-01 01:00:00.000000000 +0100
11457 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/dlimit.h      2009-12-03 20:04:56.000000000 +0100
11458 @@ -0,0 +1,54 @@
11459 +#ifndef _VX_DLIMIT_H
11460 +#define _VX_DLIMIT_H
11461 +
11462 +#include "switch.h"
11463 +
11464 +
11465 +#ifdef __KERNEL__
11466 +
11467 +/*      keep in sync with CDLIM_INFINITY       */
11468 +
11469 +#define DLIM_INFINITY          (~0ULL)
11470 +
11471 +#include <linux/spinlock.h>
11472 +#include <linux/rcupdate.h>
11473 +
11474 +struct super_block;
11475 +
11476 +struct dl_info {
11477 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11478 +       struct rcu_head dl_rcu;                 /* the rcu head */
11479 +       tag_t dl_tag;                           /* context tag */
11480 +       atomic_t dl_usecnt;                     /* usage count */
11481 +       atomic_t dl_refcnt;                     /* reference count */
11482 +
11483 +       struct super_block *dl_sb;              /* associated superblock */
11484 +
11485 +       spinlock_t dl_lock;                     /* protect the values */
11486 +
11487 +       unsigned long long dl_space_used;       /* used space in bytes */
11488 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11489 +       unsigned long dl_inodes_used;           /* used inodes */
11490 +       unsigned long dl_inodes_total;          /* maximum inodes */
11491 +
11492 +       unsigned int dl_nrlmult;                /* non root limit mult */
11493 +};
11494 +
11495 +struct rcu_head;
11496 +
11497 +extern void rcu_free_dl_info(struct rcu_head *);
11498 +extern void unhash_dl_info(struct dl_info *);
11499 +
11500 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11501 +
11502 +
11503 +struct kstatfs;
11504 +
11505 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11506 +
11507 +typedef uint64_t dlsize_t;
11508 +
11509 +#endif /* __KERNEL__ */
11510 +#else  /* _VX_DLIMIT_H */
11511 +#warning duplicate inclusion
11512 +#endif /* _VX_DLIMIT_H */
11513 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/global.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/global.h
11514 --- linux-2.6.32.10/include/linux/vserver/global.h      1970-01-01 01:00:00.000000000 +0100
11515 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/global.h      2009-12-03 20:04:56.000000000 +0100
11516 @@ -0,0 +1,19 @@
11517 +#ifndef _VX_GLOBAL_H
11518 +#define _VX_GLOBAL_H
11519 +
11520 +
11521 +extern atomic_t vx_global_ctotal;
11522 +extern atomic_t vx_global_cactive;
11523 +
11524 +extern atomic_t nx_global_ctotal;
11525 +extern atomic_t nx_global_cactive;
11526 +
11527 +extern atomic_t vs_global_nsproxy;
11528 +extern atomic_t vs_global_fs;
11529 +extern atomic_t vs_global_mnt_ns;
11530 +extern atomic_t vs_global_uts_ns;
11531 +extern atomic_t vs_global_user_ns;
11532 +extern atomic_t vs_global_pid_ns;
11533 +
11534 +
11535 +#endif /* _VX_GLOBAL_H */
11536 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/history.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/history.h
11537 --- linux-2.6.32.10/include/linux/vserver/history.h     1970-01-01 01:00:00.000000000 +0100
11538 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/history.h     2009-12-03 20:04:56.000000000 +0100
11539 @@ -0,0 +1,197 @@
11540 +#ifndef _VX_HISTORY_H
11541 +#define _VX_HISTORY_H
11542 +
11543 +
11544 +enum {
11545 +       VXH_UNUSED = 0,
11546 +       VXH_THROW_OOPS = 1,
11547 +
11548 +       VXH_GET_VX_INFO,
11549 +       VXH_PUT_VX_INFO,
11550 +       VXH_INIT_VX_INFO,
11551 +       VXH_SET_VX_INFO,
11552 +       VXH_CLR_VX_INFO,
11553 +       VXH_CLAIM_VX_INFO,
11554 +       VXH_RELEASE_VX_INFO,
11555 +       VXH_ALLOC_VX_INFO,
11556 +       VXH_DEALLOC_VX_INFO,
11557 +       VXH_HASH_VX_INFO,
11558 +       VXH_UNHASH_VX_INFO,
11559 +       VXH_LOC_VX_INFO,
11560 +       VXH_LOOKUP_VX_INFO,
11561 +       VXH_CREATE_VX_INFO,
11562 +};
11563 +
11564 +struct _vxhe_vxi {
11565 +       struct vx_info *ptr;
11566 +       unsigned xid;
11567 +       unsigned usecnt;
11568 +       unsigned tasks;
11569 +};
11570 +
11571 +struct _vxhe_set_clr {
11572 +       void *data;
11573 +};
11574 +
11575 +struct _vxhe_loc_lookup {
11576 +       unsigned arg;
11577 +};
11578 +
11579 +struct _vx_hist_entry {
11580 +       void *loc;
11581 +       unsigned short seq;
11582 +       unsigned short type;
11583 +       struct _vxhe_vxi vxi;
11584 +       union {
11585 +               struct _vxhe_set_clr sc;
11586 +               struct _vxhe_loc_lookup ll;
11587 +       };
11588 +};
11589 +
11590 +#ifdef CONFIG_VSERVER_HISTORY
11591 +
11592 +extern unsigned volatile int vxh_active;
11593 +
11594 +struct _vx_hist_entry *vxh_advance(void *loc);
11595 +
11596 +
11597 +static inline
11598 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11599 +{
11600 +       entry->vxi.ptr = vxi;
11601 +       if (vxi) {
11602 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11603 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11604 +               entry->vxi.xid = vxi->vx_id;
11605 +       }
11606 +}
11607 +
11608 +
11609 +#define        __HERE__ current_text_addr()
11610 +
11611 +#define __VXH_BODY(__type, __data, __here)     \
11612 +       struct _vx_hist_entry *entry;           \
11613 +                                               \
11614 +       preempt_disable();                      \
11615 +       entry = vxh_advance(__here);            \
11616 +       __data;                                 \
11617 +       entry->type = __type;                   \
11618 +       preempt_enable();
11619 +
11620 +
11621 +       /* pass vxi only */
11622 +
11623 +#define __VXH_SMPL                             \
11624 +       __vxh_copy_vxi(entry, vxi)
11625 +
11626 +static inline
11627 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11628 +{
11629 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11630 +}
11631 +
11632 +       /* pass vxi and data (void *) */
11633 +
11634 +#define __VXH_DATA                             \
11635 +       __vxh_copy_vxi(entry, vxi);             \
11636 +       entry->sc.data = data
11637 +
11638 +static inline
11639 +void   __vxh_data(struct vx_info *vxi, void *data,
11640 +                       int __type, void *__here)
11641 +{
11642 +       __VXH_BODY(__type, __VXH_DATA, __here)
11643 +}
11644 +
11645 +       /* pass vxi and arg (long) */
11646 +
11647 +#define __VXH_LONG                             \
11648 +       __vxh_copy_vxi(entry, vxi);             \
11649 +       entry->ll.arg = arg
11650 +
11651 +static inline
11652 +void   __vxh_long(struct vx_info *vxi, long arg,
11653 +                       int __type, void *__here)
11654 +{
11655 +       __VXH_BODY(__type, __VXH_LONG, __here)
11656 +}
11657 +
11658 +
11659 +static inline
11660 +void   __vxh_throw_oops(void *__here)
11661 +{
11662 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11663 +       /* prevent further acquisition */
11664 +       vxh_active = 0;
11665 +}
11666 +
11667 +
11668 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11669 +
11670 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11671 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11672 +
11673 +#define __vxh_init_vx_info(v, d, h) \
11674 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11675 +#define __vxh_set_vx_info(v, d, h) \
11676 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11677 +#define __vxh_clr_vx_info(v, d, h) \
11678 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11679 +
11680 +#define __vxh_claim_vx_info(v, d, h) \
11681 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11682 +#define __vxh_release_vx_info(v, d, h) \
11683 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11684 +
11685 +#define vxh_alloc_vx_info(v) \
11686 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11687 +#define vxh_dealloc_vx_info(v) \
11688 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11689 +
11690 +#define vxh_hash_vx_info(v) \
11691 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11692 +#define vxh_unhash_vx_info(v) \
11693 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11694 +
11695 +#define vxh_loc_vx_info(v, l) \
11696 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11697 +#define vxh_lookup_vx_info(v, l) \
11698 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11699 +#define vxh_create_vx_info(v, l) \
11700 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11701 +
11702 +extern void vxh_dump_history(void);
11703 +
11704 +
11705 +#else  /* CONFIG_VSERVER_HISTORY */
11706 +
11707 +#define        __HERE__        0
11708 +
11709 +#define vxh_throw_oops()               do { } while (0)
11710 +
11711 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11712 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11713 +
11714 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11715 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11716 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11717 +
11718 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11719 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11720 +
11721 +#define vxh_alloc_vx_info(v)           do { } while (0)
11722 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11723 +
11724 +#define vxh_hash_vx_info(v)            do { } while (0)
11725 +#define vxh_unhash_vx_info(v)          do { } while (0)
11726 +
11727 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11728 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11729 +#define vxh_create_vx_info(v, l)       do { } while (0)
11730 +
11731 +#define vxh_dump_history()             do { } while (0)
11732 +
11733 +
11734 +#endif /* CONFIG_VSERVER_HISTORY */
11735 +
11736 +#endif /* _VX_HISTORY_H */
11737 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/inode_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/inode_cmd.h
11738 --- linux-2.6.32.10/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00.000000000 +0100
11739 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/inode_cmd.h   2009-12-03 20:04:56.000000000 +0100
11740 @@ -0,0 +1,59 @@
11741 +#ifndef _VX_INODE_CMD_H
11742 +#define _VX_INODE_CMD_H
11743 +
11744 +
11745 +/*  inode vserver commands */
11746 +
11747 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11748 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11749 +
11750 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11751 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11752 +
11753 +struct vcmd_ctx_iattr_v1 {
11754 +       const char __user *name;
11755 +       uint32_t tag;
11756 +       uint32_t flags;
11757 +       uint32_t mask;
11758 +};
11759 +
11760 +struct vcmd_ctx_fiattr_v0 {
11761 +       uint32_t tag;
11762 +       uint32_t flags;
11763 +       uint32_t mask;
11764 +};
11765 +
11766 +
11767 +#ifdef __KERNEL__
11768 +
11769 +
11770 +#ifdef CONFIG_COMPAT
11771 +
11772 +#include <asm/compat.h>
11773 +
11774 +struct vcmd_ctx_iattr_v1_x32 {
11775 +       compat_uptr_t name_ptr;
11776 +       uint32_t tag;
11777 +       uint32_t flags;
11778 +       uint32_t mask;
11779 +};
11780 +
11781 +#endif /* CONFIG_COMPAT */
11782 +
11783 +#include <linux/compiler.h>
11784 +
11785 +extern int vc_get_iattr(void __user *);
11786 +extern int vc_set_iattr(void __user *);
11787 +
11788 +extern int vc_fget_iattr(uint32_t, void __user *);
11789 +extern int vc_fset_iattr(uint32_t, void __user *);
11790 +
11791 +#ifdef CONFIG_COMPAT
11792 +
11793 +extern int vc_get_iattr_x32(void __user *);
11794 +extern int vc_set_iattr_x32(void __user *);
11795 +
11796 +#endif /* CONFIG_COMPAT */
11797 +
11798 +#endif /* __KERNEL__ */
11799 +#endif /* _VX_INODE_CMD_H */
11800 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/inode.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/inode.h
11801 --- linux-2.6.32.10/include/linux/vserver/inode.h       1970-01-01 01:00:00.000000000 +0100
11802 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/inode.h       2009-12-03 20:04:56.000000000 +0100
11803 @@ -0,0 +1,39 @@
11804 +#ifndef _VX_INODE_H
11805 +#define _VX_INODE_H
11806 +
11807 +
11808 +#define IATTR_TAG      0x01000000
11809 +
11810 +#define IATTR_ADMIN    0x00000001
11811 +#define IATTR_WATCH    0x00000002
11812 +#define IATTR_HIDE     0x00000004
11813 +#define IATTR_FLAGS    0x00000007
11814 +
11815 +#define IATTR_BARRIER  0x00010000
11816 +#define IATTR_IXUNLINK 0x00020000
11817 +#define IATTR_IMMUTABLE 0x00040000
11818 +#define IATTR_COW      0x00080000
11819 +
11820 +#ifdef __KERNEL__
11821 +
11822 +
11823 +#ifdef CONFIG_VSERVER_PROC_SECURE
11824 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11825 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11826 +#else
11827 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11828 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11829 +#endif
11830 +
11831 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11832 +
11833 +#endif /* __KERNEL__ */
11834 +
11835 +/* inode ioctls */
11836 +
11837 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11838 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11839 +
11840 +#else  /* _VX_INODE_H */
11841 +#warning duplicate inclusion
11842 +#endif /* _VX_INODE_H */
11843 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/Kbuild linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/Kbuild
11844 --- linux-2.6.32.10/include/linux/vserver/Kbuild        1970-01-01 01:00:00.000000000 +0100
11845 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/Kbuild        2009-12-03 20:04:56.000000000 +0100
11846 @@ -0,0 +1,8 @@
11847 +
11848 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11849 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11850 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11851 +       debug_cmd.h device_cmd.h
11852 +
11853 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11854 +
11855 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/limit_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/limit_cmd.h
11856 --- linux-2.6.32.10/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00.000000000 +0100
11857 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/limit_cmd.h   2009-12-03 20:04:56.000000000 +0100
11858 @@ -0,0 +1,71 @@
11859 +#ifndef _VX_LIMIT_CMD_H
11860 +#define _VX_LIMIT_CMD_H
11861 +
11862 +
11863 +/*  rlimit vserver commands */
11864 +
11865 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11866 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11867 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11868 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11869 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11870 +
11871 +struct vcmd_ctx_rlimit_v0 {
11872 +       uint32_t id;
11873 +       uint64_t minimum;
11874 +       uint64_t softlimit;
11875 +       uint64_t maximum;
11876 +};
11877 +
11878 +struct vcmd_ctx_rlimit_mask_v0 {
11879 +       uint32_t minimum;
11880 +       uint32_t softlimit;
11881 +       uint32_t maximum;
11882 +};
11883 +
11884 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11885 +
11886 +struct vcmd_rlimit_stat_v0 {
11887 +       uint32_t id;
11888 +       uint32_t hits;
11889 +       uint64_t value;
11890 +       uint64_t minimum;
11891 +       uint64_t maximum;
11892 +};
11893 +
11894 +#define CRLIM_UNSET            (0ULL)
11895 +#define CRLIM_INFINITY         (~0ULL)
11896 +#define CRLIM_KEEP             (~1ULL)
11897 +
11898 +#ifdef __KERNEL__
11899 +
11900 +#ifdef CONFIG_IA32_EMULATION
11901 +
11902 +struct vcmd_ctx_rlimit_v0_x32 {
11903 +       uint32_t id;
11904 +       uint64_t minimum;
11905 +       uint64_t softlimit;
11906 +       uint64_t maximum;
11907 +} __attribute__ ((packed));
11908 +
11909 +#endif /* CONFIG_IA32_EMULATION */
11910 +
11911 +#include <linux/compiler.h>
11912 +
11913 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11914 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11915 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11916 +extern int vc_reset_hits(struct vx_info *, void __user *);
11917 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11918 +
11919 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11920 +
11921 +#ifdef CONFIG_IA32_EMULATION
11922 +
11923 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11924 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11925 +
11926 +#endif /* CONFIG_IA32_EMULATION */
11927 +
11928 +#endif /* __KERNEL__ */
11929 +#endif /* _VX_LIMIT_CMD_H */
11930 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/limit_def.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/limit_def.h
11931 --- linux-2.6.32.10/include/linux/vserver/limit_def.h   1970-01-01 01:00:00.000000000 +0100
11932 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/limit_def.h   2009-12-03 20:04:56.000000000 +0100
11933 @@ -0,0 +1,47 @@
11934 +#ifndef _VX_LIMIT_DEF_H
11935 +#define _VX_LIMIT_DEF_H
11936 +
11937 +#include <asm/atomic.h>
11938 +#include <asm/resource.h>
11939 +
11940 +#include "limit.h"
11941 +
11942 +
11943 +struct _vx_res_limit {
11944 +       rlim_t soft;            /* Context soft limit */
11945 +       rlim_t hard;            /* Context hard limit */
11946 +
11947 +       rlim_atomic_t rcur;     /* Current value */
11948 +       rlim_t rmin;            /* Context minimum */
11949 +       rlim_t rmax;            /* Context maximum */
11950 +
11951 +       atomic_t lhit;          /* Limit hits */
11952 +};
11953 +
11954 +/* context sub struct */
11955 +
11956 +struct _vx_limit {
11957 +       struct _vx_res_limit res[NUM_LIMITS];
11958 +};
11959 +
11960 +#ifdef CONFIG_VSERVER_DEBUG
11961 +
11962 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11963 +{
11964 +       int i;
11965 +
11966 +       printk("\t_vx_limit:");
11967 +       for (i = 0; i < NUM_LIMITS; i++) {
11968 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11969 +                       i, (unsigned long)__rlim_get(limit, i),
11970 +                       (unsigned long)__rlim_rmin(limit, i),
11971 +                       (unsigned long)__rlim_rmax(limit, i),
11972 +                       (long)__rlim_soft(limit, i),
11973 +                       (long)__rlim_hard(limit, i),
11974 +                       atomic_read(&__rlim_lhit(limit, i)));
11975 +       }
11976 +}
11977 +
11978 +#endif
11979 +
11980 +#endif /* _VX_LIMIT_DEF_H */
11981 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/limit.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/limit.h
11982 --- linux-2.6.32.10/include/linux/vserver/limit.h       1970-01-01 01:00:00.000000000 +0100
11983 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/limit.h       2010-02-05 00:34:02.000000000 +0100
11984 @@ -0,0 +1,71 @@
11985 +#ifndef _VX_LIMIT_H
11986 +#define _VX_LIMIT_H
11987 +
11988 +#define VLIMIT_NSOCK   16
11989 +#define VLIMIT_OPENFD  17
11990 +#define VLIMIT_ANON    18
11991 +#define VLIMIT_SHMEM   19
11992 +#define VLIMIT_SEMARY  20
11993 +#define VLIMIT_NSEMS   21
11994 +#define VLIMIT_DENTRY  22
11995 +#define VLIMIT_MAPPED  23
11996 +
11997 +
11998 +#ifdef __KERNEL__
11999 +
12000 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12001 +
12002 +/*     keep in sync with CRLIM_INFINITY */
12003 +
12004 +#define        VLIM_INFINITY   (~0ULL)
12005 +
12006 +#include <asm/atomic.h>
12007 +#include <asm/resource.h>
12008 +
12009 +#ifndef RLIM_INFINITY
12010 +#warning RLIM_INFINITY is undefined
12011 +#endif
12012 +
12013 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12014 +
12015 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12016 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12017 +
12018 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12019 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12020 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12021 +
12022 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12023 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12024 +
12025 +typedef atomic_long_t rlim_atomic_t;
12026 +typedef unsigned long rlim_t;
12027 +
12028 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12029 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12030 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12031 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12032 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12033 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12034 +
12035 +
12036 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12037 +#define        VX_VLIM(r) ((long long)(long)(r))
12038 +#define        VX_RLIM(v) ((rlim_t)(v))
12039 +#else
12040 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12041 +               ? VLIM_INFINITY : (long long)(r))
12042 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12043 +               ? RLIM_INFINITY : (rlim_t)(v))
12044 +#endif
12045 +
12046 +struct sysinfo;
12047 +
12048 +void vx_vsi_meminfo(struct sysinfo *);
12049 +void vx_vsi_swapinfo(struct sysinfo *);
12050 +long vx_vsi_cached(struct sysinfo *);
12051 +
12052 +#define NUM_LIMITS     24
12053 +
12054 +#endif /* __KERNEL__ */
12055 +#endif /* _VX_LIMIT_H */
12056 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/limit_int.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/limit_int.h
12057 --- linux-2.6.32.10/include/linux/vserver/limit_int.h   1970-01-01 01:00:00.000000000 +0100
12058 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/limit_int.h   2009-12-03 20:04:56.000000000 +0100
12059 @@ -0,0 +1,198 @@
12060 +#ifndef _VX_LIMIT_INT_H
12061 +#define _VX_LIMIT_INT_H
12062 +
12063 +#include "context.h"
12064 +
12065 +#ifdef __KERNEL__
12066 +
12067 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12068 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12069 +
12070 +extern const char *vlimit_name[NUM_LIMITS];
12071 +
12072 +static inline void __vx_acc_cres(struct vx_info *vxi,
12073 +       int res, int dir, void *_data, char *_file, int _line)
12074 +{
12075 +       if (VXD_RCRES_COND(res))
12076 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12077 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12078 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12079 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12080 +       if (!vxi)
12081 +               return;
12082 +
12083 +       if (dir > 0)
12084 +               __rlim_inc(&vxi->limit, res);
12085 +       else
12086 +               __rlim_dec(&vxi->limit, res);
12087 +}
12088 +
12089 +static inline void __vx_add_cres(struct vx_info *vxi,
12090 +       int res, int amount, void *_data, char *_file, int _line)
12091 +{
12092 +       if (VXD_RCRES_COND(res))
12093 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12094 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12095 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12096 +                       amount, _data, _file, _line);
12097 +       if (amount == 0)
12098 +               return;
12099 +       if (!vxi)
12100 +               return;
12101 +       __rlim_add(&vxi->limit, res, amount);
12102 +}
12103 +
12104 +static inline
12105 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12106 +{
12107 +       int cond = (value > __rlim_rmax(limit, res));
12108 +
12109 +       if (cond)
12110 +               __rlim_rmax(limit, res) = value;
12111 +       return cond;
12112 +}
12113 +
12114 +static inline
12115 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12116 +{
12117 +       int cond = (value < __rlim_rmin(limit, res));
12118 +
12119 +       if (cond)
12120 +               __rlim_rmin(limit, res) = value;
12121 +       return cond;
12122 +}
12123 +
12124 +static inline
12125 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12126 +{
12127 +       if (!__vx_cres_adjust_max(limit, res, value))
12128 +               __vx_cres_adjust_min(limit, res, value);
12129 +}
12130 +
12131 +
12132 +/*     return values:
12133 +        +1 ... no limit hit
12134 +        -1 ... over soft limit
12135 +         0 ... over hard limit         */
12136 +
12137 +static inline int __vx_cres_avail(struct vx_info *vxi,
12138 +       int res, int num, char *_file, int _line)
12139 +{
12140 +       struct _vx_limit *limit;
12141 +       rlim_t value;
12142 +
12143 +       if (VXD_RLIMIT_COND(res))
12144 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12145 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12146 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12147 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12148 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12149 +                       num, _file, _line);
12150 +       if (!vxi)
12151 +               return 1;
12152 +
12153 +       limit = &vxi->limit;
12154 +       value = __rlim_get(limit, res);
12155 +
12156 +       if (!__vx_cres_adjust_max(limit, res, value))
12157 +               __vx_cres_adjust_min(limit, res, value);
12158 +
12159 +       if (num == 0)
12160 +               return 1;
12161 +
12162 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12163 +               return -1;
12164 +       if (value + num <= __rlim_soft(limit, res))
12165 +               return -1;
12166 +
12167 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12168 +               return 1;
12169 +       if (value + num <= __rlim_hard(limit, res))
12170 +               return 1;
12171 +
12172 +       __rlim_hit(limit, res);
12173 +       return 0;
12174 +}
12175 +
12176 +
12177 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12178 +
12179 +static inline
12180 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12181 +{
12182 +       rlim_t value, sum = 0;
12183 +       int res;
12184 +
12185 +       while ((res = *array++)) {
12186 +               value = __rlim_get(limit, res);
12187 +               __vx_cres_fixup(limit, res, value);
12188 +               sum += value;
12189 +       }
12190 +       return sum;
12191 +}
12192 +
12193 +static inline
12194 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12195 +{
12196 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12197 +       int res = *array;
12198 +
12199 +       if (value == __rlim_get(limit, res))
12200 +               return value;
12201 +
12202 +       __rlim_set(limit, res, value);
12203 +       /* now adjust min/max */
12204 +       if (!__vx_cres_adjust_max(limit, res, value))
12205 +               __vx_cres_adjust_min(limit, res, value);
12206 +
12207 +       return value;
12208 +}
12209 +
12210 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12211 +       const int *array, int num, char *_file, int _line)
12212 +{
12213 +       struct _vx_limit *limit;
12214 +       rlim_t value = 0;
12215 +       int res;
12216 +
12217 +       if (num == 0)
12218 +               return 1;
12219 +       if (!vxi)
12220 +               return 1;
12221 +
12222 +       limit = &vxi->limit;
12223 +       res = *array;
12224 +       value = __vx_cres_array_sum(limit, array + 1);
12225 +
12226 +       __rlim_set(limit, res, value);
12227 +       __vx_cres_fixup(limit, res, value);
12228 +
12229 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12230 +}
12231 +
12232 +
12233 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12234 +{
12235 +       rlim_t value;
12236 +       int res;
12237 +
12238 +       /* complex resources first */
12239 +       if ((id < 0) || (id == RLIMIT_RSS))
12240 +               __vx_cres_array_fixup(limit, VLA_RSS);
12241 +
12242 +       for (res = 0; res < NUM_LIMITS; res++) {
12243 +               if ((id > 0) && (res != id))
12244 +                       continue;
12245 +
12246 +               value = __rlim_get(limit, res);
12247 +               __vx_cres_fixup(limit, res, value);
12248 +
12249 +               /* not supposed to happen, maybe warn? */
12250 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12251 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12252 +       }
12253 +}
12254 +
12255 +
12256 +#endif /* __KERNEL__ */
12257 +#endif /* _VX_LIMIT_INT_H */
12258 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/monitor.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/monitor.h
12259 --- linux-2.6.32.10/include/linux/vserver/monitor.h     1970-01-01 01:00:00.000000000 +0100
12260 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/monitor.h     2009-12-03 20:04:56.000000000 +0100
12261 @@ -0,0 +1,96 @@
12262 +#ifndef _VX_MONITOR_H
12263 +#define _VX_MONITOR_H
12264 +
12265 +#include <linux/types.h>
12266 +
12267 +enum {
12268 +       VXM_UNUSED = 0,
12269 +
12270 +       VXM_SYNC = 0x10,
12271 +
12272 +       VXM_UPDATE = 0x20,
12273 +       VXM_UPDATE_1,
12274 +       VXM_UPDATE_2,
12275 +
12276 +       VXM_RQINFO_1 = 0x24,
12277 +       VXM_RQINFO_2,
12278 +
12279 +       VXM_ACTIVATE = 0x40,
12280 +       VXM_DEACTIVATE,
12281 +       VXM_IDLE,
12282 +
12283 +       VXM_HOLD = 0x44,
12284 +       VXM_UNHOLD,
12285 +
12286 +       VXM_MIGRATE = 0x48,
12287 +       VXM_RESCHED,
12288 +
12289 +       /* all other bits are flags */
12290 +       VXM_SCHED = 0x80,
12291 +};
12292 +
12293 +struct _vxm_update_1 {
12294 +       uint32_t tokens_max;
12295 +       uint32_t fill_rate;
12296 +       uint32_t interval;
12297 +};
12298 +
12299 +struct _vxm_update_2 {
12300 +       uint32_t tokens_min;
12301 +       uint32_t fill_rate;
12302 +       uint32_t interval;
12303 +};
12304 +
12305 +struct _vxm_rqinfo_1 {
12306 +       uint16_t running;
12307 +       uint16_t onhold;
12308 +       uint16_t iowait;
12309 +       uint16_t uintr;
12310 +       uint32_t idle_tokens;
12311 +};
12312 +
12313 +struct _vxm_rqinfo_2 {
12314 +       uint32_t norm_time;
12315 +       uint32_t idle_time;
12316 +       uint32_t idle_skip;
12317 +};
12318 +
12319 +struct _vxm_sched {
12320 +       uint32_t tokens;
12321 +       uint32_t norm_time;
12322 +       uint32_t idle_time;
12323 +};
12324 +
12325 +struct _vxm_task {
12326 +       uint16_t pid;
12327 +       uint16_t state;
12328 +};
12329 +
12330 +struct _vxm_event {
12331 +       uint32_t jif;
12332 +       union {
12333 +               uint32_t seq;
12334 +               uint32_t sec;
12335 +       };
12336 +       union {
12337 +               uint32_t tokens;
12338 +               uint32_t nsec;
12339 +               struct _vxm_task tsk;
12340 +       };
12341 +};
12342 +
12343 +struct _vx_mon_entry {
12344 +       uint16_t type;
12345 +       uint16_t xid;
12346 +       union {
12347 +               struct _vxm_event ev;
12348 +               struct _vxm_sched sd;
12349 +               struct _vxm_update_1 u1;
12350 +               struct _vxm_update_2 u2;
12351 +               struct _vxm_rqinfo_1 q1;
12352 +               struct _vxm_rqinfo_2 q2;
12353 +       };
12354 +};
12355 +
12356 +
12357 +#endif /* _VX_MONITOR_H */
12358 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/network_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/network_cmd.h
12359 --- linux-2.6.32.10/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00.000000000 +0100
12360 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/network_cmd.h 2009-12-03 20:04:56.000000000 +0100
12361 @@ -0,0 +1,150 @@
12362 +#ifndef _VX_NETWORK_CMD_H
12363 +#define _VX_NETWORK_CMD_H
12364 +
12365 +
12366 +/* vinfo commands */
12367 +
12368 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12369 +
12370 +#ifdef __KERNEL__
12371 +extern int vc_task_nid(uint32_t);
12372 +
12373 +#endif /* __KERNEL__ */
12374 +
12375 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12376 +
12377 +struct vcmd_nx_info_v0 {
12378 +       uint32_t nid;
12379 +       /* more to come */
12380 +};
12381 +
12382 +#ifdef __KERNEL__
12383 +extern int vc_nx_info(struct nx_info *, void __user *);
12384 +
12385 +#endif /* __KERNEL__ */
12386 +
12387 +#include <linux/in.h>
12388 +#include <linux/in6.h>
12389 +
12390 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12391 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12392 +
12393 +struct  vcmd_net_create {
12394 +       uint64_t flagword;
12395 +};
12396 +
12397 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12398 +
12399 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12400 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12401 +
12402 +struct vcmd_net_addr_v0 {
12403 +       uint16_t type;
12404 +       uint16_t count;
12405 +       struct in_addr ip[4];
12406 +       struct in_addr mask[4];
12407 +};
12408 +
12409 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12410 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12411 +
12412 +struct vcmd_net_addr_ipv4_v1 {
12413 +       uint16_t type;
12414 +       uint16_t flags;
12415 +       struct in_addr ip;
12416 +       struct in_addr mask;
12417 +};
12418 +
12419 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12420 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12421 +
12422 +struct vcmd_net_addr_ipv6_v1 {
12423 +       uint16_t type;
12424 +       uint16_t flags;
12425 +       uint32_t prefix;
12426 +       struct in6_addr ip;
12427 +       struct in6_addr mask;
12428 +};
12429 +
12430 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12431 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12432 +
12433 +struct vcmd_match_ipv4_v0 {
12434 +       uint16_t type;
12435 +       uint16_t flags;
12436 +       uint16_t parent;
12437 +       uint16_t prefix;
12438 +       struct in_addr ip;
12439 +       struct in_addr ip2;
12440 +       struct in_addr mask;
12441 +};
12442 +
12443 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12444 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12445 +
12446 +struct vcmd_match_ipv6_v0 {
12447 +       uint16_t type;
12448 +       uint16_t flags;
12449 +       uint16_t parent;
12450 +       uint16_t prefix;
12451 +       struct in6_addr ip;
12452 +       struct in6_addr ip2;
12453 +       struct in6_addr mask;
12454 +};
12455 +
12456 +
12457 +#ifdef __KERNEL__
12458 +extern int vc_net_create(uint32_t, void __user *);
12459 +extern int vc_net_migrate(struct nx_info *, void __user *);
12460 +
12461 +extern int vc_net_add(struct nx_info *, void __user *);
12462 +extern int vc_net_remove(struct nx_info *, void __user *);
12463 +
12464 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12465 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12466 +
12467 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12468 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12469 +
12470 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12471 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12472 +
12473 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12474 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12475 +
12476 +#endif /* __KERNEL__ */
12477 +
12478 +
12479 +/* flag commands */
12480 +
12481 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12482 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12483 +
12484 +struct vcmd_net_flags_v0 {
12485 +       uint64_t flagword;
12486 +       uint64_t mask;
12487 +};
12488 +
12489 +#ifdef __KERNEL__
12490 +extern int vc_get_nflags(struct nx_info *, void __user *);
12491 +extern int vc_set_nflags(struct nx_info *, void __user *);
12492 +
12493 +#endif /* __KERNEL__ */
12494 +
12495 +
12496 +/* network caps commands */
12497 +
12498 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12499 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12500 +
12501 +struct vcmd_net_caps_v0 {
12502 +       uint64_t ncaps;
12503 +       uint64_t cmask;
12504 +};
12505 +
12506 +#ifdef __KERNEL__
12507 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12508 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12509 +
12510 +#endif /* __KERNEL__ */
12511 +#endif /* _VX_CONTEXT_CMD_H */
12512 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/network.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/network.h
12513 --- linux-2.6.32.10/include/linux/vserver/network.h     1970-01-01 01:00:00.000000000 +0100
12514 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/network.h     2009-12-03 20:04:56.000000000 +0100
12515 @@ -0,0 +1,146 @@
12516 +#ifndef _VX_NETWORK_H
12517 +#define _VX_NETWORK_H
12518 +
12519 +#include <linux/types.h>
12520 +
12521 +
12522 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12523 +
12524 +
12525 +/* network flags */
12526 +
12527 +#define NXF_INFO_PRIVATE       0x00000008
12528 +
12529 +#define NXF_SINGLE_IP          0x00000100
12530 +#define NXF_LBACK_REMAP                0x00000200
12531 +#define NXF_LBACK_ALLOW                0x00000400
12532 +
12533 +#define NXF_HIDE_NETIF         0x02000000
12534 +#define NXF_HIDE_LBACK         0x04000000
12535 +
12536 +#define NXF_STATE_SETUP                (1ULL << 32)
12537 +#define NXF_STATE_ADMIN                (1ULL << 34)
12538 +
12539 +#define NXF_SC_HELPER          (1ULL << 36)
12540 +#define NXF_PERSISTENT         (1ULL << 38)
12541 +
12542 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12543 +
12544 +
12545 +#define        NXF_INIT_SET            (__nxf_init_set())
12546 +
12547 +static inline uint64_t __nxf_init_set(void) {
12548 +       return    NXF_STATE_ADMIN
12549 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12550 +               | NXF_LBACK_REMAP
12551 +               | NXF_HIDE_LBACK
12552 +#endif
12553 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12554 +               | NXF_SINGLE_IP
12555 +#endif
12556 +               | NXF_HIDE_NETIF;
12557 +}
12558 +
12559 +
12560 +/* network caps */
12561 +
12562 +#define NXC_TUN_CREATE         0x00000001
12563 +
12564 +#define NXC_RAW_ICMP           0x00000100
12565 +
12566 +
12567 +/* address types */
12568 +
12569 +#define NXA_TYPE_IPV4          0x0001
12570 +#define NXA_TYPE_IPV6          0x0002
12571 +
12572 +#define NXA_TYPE_NONE          0x0000
12573 +#define NXA_TYPE_ANY           0x00FF
12574 +
12575 +#define NXA_TYPE_ADDR          0x0010
12576 +#define NXA_TYPE_MASK          0x0020
12577 +#define NXA_TYPE_RANGE         0x0040
12578 +
12579 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12580 +
12581 +#define NXA_MOD_BCAST          0x0100
12582 +#define NXA_MOD_LBACK          0x0200
12583 +
12584 +#define NXA_LOOPBACK           0x1000
12585 +
12586 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12587 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12588 +
12589 +#ifdef __KERNEL__
12590 +
12591 +#include <linux/list.h>
12592 +#include <linux/spinlock.h>
12593 +#include <linux/rcupdate.h>
12594 +#include <linux/in.h>
12595 +#include <linux/in6.h>
12596 +#include <asm/atomic.h>
12597 +
12598 +struct nx_addr_v4 {
12599 +       struct nx_addr_v4 *next;
12600 +       struct in_addr ip[2];
12601 +       struct in_addr mask;
12602 +       uint16_t type;
12603 +       uint16_t flags;
12604 +};
12605 +
12606 +struct nx_addr_v6 {
12607 +       struct nx_addr_v6 *next;
12608 +       struct in6_addr ip;
12609 +       struct in6_addr mask;
12610 +       uint32_t prefix;
12611 +       uint16_t type;
12612 +       uint16_t flags;
12613 +};
12614 +
12615 +struct nx_info {
12616 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12617 +       nid_t nx_id;                    /* vnet id */
12618 +       atomic_t nx_usecnt;             /* usage count */
12619 +       atomic_t nx_tasks;              /* tasks count */
12620 +       int nx_state;                   /* context state */
12621 +
12622 +       uint64_t nx_flags;              /* network flag word */
12623 +       uint64_t nx_ncaps;              /* network capabilities */
12624 +
12625 +       struct in_addr v4_lback;        /* Loopback address */
12626 +       struct in_addr v4_bcast;        /* Broadcast address */
12627 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12628 +#ifdef CONFIG_IPV6
12629 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12630 +#endif
12631 +       char nx_name[65];               /* network context name */
12632 +};
12633 +
12634 +
12635 +/* status flags */
12636 +
12637 +#define NXS_HASHED      0x0001
12638 +#define NXS_SHUTDOWN    0x0100
12639 +#define NXS_RELEASED    0x8000
12640 +
12641 +extern struct nx_info *lookup_nx_info(int);
12642 +
12643 +extern int get_nid_list(int, unsigned int *, int);
12644 +extern int nid_is_hashed(nid_t);
12645 +
12646 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12647 +
12648 +extern long vs_net_change(struct nx_info *, unsigned int);
12649 +
12650 +struct sock;
12651 +
12652 +
12653 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12654 +#ifdef  CONFIG_IPV6
12655 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12656 +#else
12657 +#define NX_IPV6(n)     (0)
12658 +#endif
12659 +
12660 +#endif /* __KERNEL__ */
12661 +#endif /* _VX_NETWORK_H */
12662 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/percpu.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/percpu.h
12663 --- linux-2.6.32.10/include/linux/vserver/percpu.h      1970-01-01 01:00:00.000000000 +0100
12664 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/percpu.h      2009-12-03 20:04:56.000000000 +0100
12665 @@ -0,0 +1,14 @@
12666 +#ifndef _VX_PERCPU_H
12667 +#define _VX_PERCPU_H
12668 +
12669 +#include "cvirt_def.h"
12670 +#include "sched_def.h"
12671 +
12672 +struct _vx_percpu {
12673 +       struct _vx_cvirt_pc cvirt;
12674 +       struct _vx_sched_pc sched;
12675 +};
12676 +
12677 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12678 +
12679 +#endif /* _VX_PERCPU_H */
12680 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/pid.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/pid.h
12681 --- linux-2.6.32.10/include/linux/vserver/pid.h 1970-01-01 01:00:00.000000000 +0100
12682 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/pid.h 2009-12-03 20:04:56.000000000 +0100
12683 @@ -0,0 +1,51 @@
12684 +#ifndef _VSERVER_PID_H
12685 +#define _VSERVER_PID_H
12686 +
12687 +/* pid faking stuff */
12688 +
12689 +#define vx_info_map_pid(v, p) \
12690 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12691 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12692 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12693 +#define vx_map_tgid(p) vx_map_pid(p)
12694 +
12695 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12696 +       const char *func, const char *file, int line)
12697 +{
12698 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12699 +               vxfprintk(VXD_CBIT(cvirt, 2),
12700 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12701 +                       vxi, (long long)vxi->vx_flags, pid,
12702 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12703 +                       func, file, line);
12704 +               if (pid == 0)
12705 +                       return 0;
12706 +               if (pid == vxi->vx_initpid)
12707 +                       return 1;
12708 +       }
12709 +       return pid;
12710 +}
12711 +
12712 +#define vx_info_rmap_pid(v, p) \
12713 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12714 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12715 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12716 +
12717 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12718 +       const char *func, const char *file, int line)
12719 +{
12720 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12721 +               vxfprintk(VXD_CBIT(cvirt, 2),
12722 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12723 +                       vxi, (long long)vxi->vx_flags, pid,
12724 +                       (pid == 1) ? vxi->vx_initpid : pid,
12725 +                       func, file, line);
12726 +               if ((pid == 1) && vxi->vx_initpid)
12727 +                       return vxi->vx_initpid;
12728 +               if (pid == vxi->vx_initpid)
12729 +                       return ~0U;
12730 +       }
12731 +       return pid;
12732 +}
12733 +
12734 +#endif
12735 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/sched_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/sched_cmd.h
12736 --- linux-2.6.32.10/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00.000000000 +0100
12737 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/sched_cmd.h   2009-12-03 20:04:56.000000000 +0100
12738 @@ -0,0 +1,108 @@
12739 +#ifndef _VX_SCHED_CMD_H
12740 +#define _VX_SCHED_CMD_H
12741 +
12742 +
12743 +/*  sched vserver commands */
12744 +
12745 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12746 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12747 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12748 +
12749 +struct vcmd_set_sched_v2 {
12750 +       int32_t fill_rate;
12751 +       int32_t interval;
12752 +       int32_t tokens;
12753 +       int32_t tokens_min;
12754 +       int32_t tokens_max;
12755 +       uint64_t cpu_mask;
12756 +};
12757 +
12758 +struct vcmd_set_sched_v3 {
12759 +       uint32_t set_mask;
12760 +       int32_t fill_rate;
12761 +       int32_t interval;
12762 +       int32_t tokens;
12763 +       int32_t tokens_min;
12764 +       int32_t tokens_max;
12765 +       int32_t priority_bias;
12766 +};
12767 +
12768 +struct vcmd_set_sched_v4 {
12769 +       uint32_t set_mask;
12770 +       int32_t fill_rate;
12771 +       int32_t interval;
12772 +       int32_t tokens;
12773 +       int32_t tokens_min;
12774 +       int32_t tokens_max;
12775 +       int32_t prio_bias;
12776 +       int32_t cpu_id;
12777 +       int32_t bucket_id;
12778 +};
12779 +
12780 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12781 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12782 +
12783 +struct vcmd_sched_v5 {
12784 +       uint32_t mask;
12785 +       int32_t cpu_id;
12786 +       int32_t bucket_id;
12787 +       int32_t fill_rate[2];
12788 +       int32_t interval[2];
12789 +       int32_t tokens;
12790 +       int32_t tokens_min;
12791 +       int32_t tokens_max;
12792 +       int32_t prio_bias;
12793 +};
12794 +
12795 +#define VXSM_FILL_RATE         0x0001
12796 +#define VXSM_INTERVAL          0x0002
12797 +#define VXSM_FILL_RATE2                0x0004
12798 +#define VXSM_INTERVAL2         0x0008
12799 +#define VXSM_TOKENS            0x0010
12800 +#define VXSM_TOKENS_MIN                0x0020
12801 +#define VXSM_TOKENS_MAX                0x0040
12802 +#define VXSM_PRIO_BIAS         0x0100
12803 +
12804 +#define VXSM_IDLE_TIME         0x0200
12805 +#define VXSM_FORCE             0x0400
12806 +
12807 +#define        VXSM_V3_MASK            0x0173
12808 +#define        VXSM_SET_MASK           0x01FF
12809 +
12810 +#define VXSM_CPU_ID            0x1000
12811 +#define VXSM_BUCKET_ID         0x2000
12812 +
12813 +#define VXSM_MSEC              0x4000
12814 +
12815 +#define SCHED_KEEP             (-2)    /* only for v2 */
12816 +
12817 +#ifdef __KERNEL__
12818 +
12819 +#include <linux/compiler.h>
12820 +
12821 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12822 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12823 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12824 +extern int vc_set_sched(struct vx_info *, void __user *);
12825 +extern int vc_get_sched(struct vx_info *, void __user *);
12826 +
12827 +#endif /* __KERNEL__ */
12828 +
12829 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12830 +
12831 +struct vcmd_sched_info {
12832 +       int32_t cpu_id;
12833 +       int32_t bucket_id;
12834 +       uint64_t user_msec;
12835 +       uint64_t sys_msec;
12836 +       uint64_t hold_msec;
12837 +       uint32_t token_usec;
12838 +       int32_t vavavoom;
12839 +};
12840 +
12841 +#ifdef __KERNEL__
12842 +
12843 +extern int vc_sched_info(struct vx_info *, void __user *);
12844 +
12845 +#endif /* __KERNEL__ */
12846 +#endif /* _VX_SCHED_CMD_H */
12847 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/sched_def.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/sched_def.h
12848 --- linux-2.6.32.10/include/linux/vserver/sched_def.h   1970-01-01 01:00:00.000000000 +0100
12849 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/sched_def.h   2009-12-03 20:04:56.000000000 +0100
12850 @@ -0,0 +1,68 @@
12851 +#ifndef _VX_SCHED_DEF_H
12852 +#define _VX_SCHED_DEF_H
12853 +
12854 +#include <linux/spinlock.h>
12855 +#include <linux/jiffies.h>
12856 +#include <linux/cpumask.h>
12857 +#include <asm/atomic.h>
12858 +#include <asm/param.h>
12859 +
12860 +
12861 +/* context sub struct */
12862 +
12863 +struct _vx_sched {
12864 +       spinlock_t tokens_lock;         /* lock for token bucket */
12865 +
12866 +       int tokens;                     /* number of CPU tokens */
12867 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12868 +       int interval[2];                /* Divisor:   per Y jiffies   */
12869 +       int tokens_min;                 /* Limit:     minimum for unhold */
12870 +       int tokens_max;                 /* Limit:     no more than N tokens */
12871 +
12872 +       int prio_bias;                  /* bias offset for priority */
12873 +
12874 +       unsigned update_mask;           /* which features should be updated */
12875 +       cpumask_t update;               /* CPUs which should update */
12876 +};
12877 +
12878 +struct _vx_sched_pc {
12879 +       int tokens;                     /* number of CPU tokens */
12880 +       int flags;                      /* bucket flags */
12881 +
12882 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12883 +       int interval[2];                /* Divisor:   per Y jiffies   */
12884 +       int tokens_min;                 /* Limit:     minimum for unhold */
12885 +       int tokens_max;                 /* Limit:     no more than N tokens */
12886 +
12887 +       int prio_bias;                  /* bias offset for priority */
12888 +       int vavavoom;                   /* last calculated vavavoom */
12889 +
12890 +       unsigned long norm_time;        /* last time accounted */
12891 +       unsigned long idle_time;        /* non linear time for fair sched */
12892 +       unsigned long token_time;       /* token time for accounting */
12893 +       unsigned long onhold;           /* jiffies when put on hold */
12894 +
12895 +       uint64_t user_ticks;            /* token tick events */
12896 +       uint64_t sys_ticks;             /* token tick events */
12897 +       uint64_t hold_ticks;            /* token ticks paused */
12898 +};
12899 +
12900 +
12901 +#define VXSF_ONHOLD    0x0001
12902 +#define VXSF_IDLE_TIME 0x0100
12903 +
12904 +#ifdef CONFIG_VSERVER_DEBUG
12905 +
12906 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12907 +{
12908 +       printk("\t_vx_sched:\n");
12909 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12910 +               sched->fill_rate[0], sched->interval[0],
12911 +               sched->fill_rate[1], sched->interval[1],
12912 +               sched->tokens_min, sched->tokens_max);
12913 +       printk("\t priority = %4d\n", sched->prio_bias);
12914 +}
12915 +
12916 +#endif
12917 +
12918 +#endif /* _VX_SCHED_DEF_H */
12919 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/sched.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/sched.h
12920 --- linux-2.6.32.10/include/linux/vserver/sched.h       1970-01-01 01:00:00.000000000 +0100
12921 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/sched.h       2009-12-03 20:04:56.000000000 +0100
12922 @@ -0,0 +1,26 @@
12923 +#ifndef _VX_SCHED_H
12924 +#define _VX_SCHED_H
12925 +
12926 +
12927 +#ifdef __KERNEL__
12928 +
12929 +struct timespec;
12930 +
12931 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12932 +
12933 +
12934 +struct vx_info;
12935 +
12936 +void vx_update_load(struct vx_info *);
12937 +
12938 +
12939 +int vx_tokens_recalc(struct _vx_sched_pc *,
12940 +       unsigned long *, unsigned long *, int [2]);
12941 +
12942 +void vx_update_sched_param(struct _vx_sched *sched,
12943 +       struct _vx_sched_pc *sched_pc);
12944 +
12945 +#endif /* __KERNEL__ */
12946 +#else  /* _VX_SCHED_H */
12947 +#warning duplicate inclusion
12948 +#endif /* _VX_SCHED_H */
12949 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/signal_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/signal_cmd.h
12950 --- linux-2.6.32.10/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00.000000000 +0100
12951 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/signal_cmd.h  2009-12-03 20:04:56.000000000 +0100
12952 @@ -0,0 +1,43 @@
12953 +#ifndef _VX_SIGNAL_CMD_H
12954 +#define _VX_SIGNAL_CMD_H
12955 +
12956 +
12957 +/*  signalling vserver commands */
12958 +
12959 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12960 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12961 +
12962 +struct vcmd_ctx_kill_v0 {
12963 +       int32_t pid;
12964 +       int32_t sig;
12965 +};
12966 +
12967 +struct vcmd_wait_exit_v0 {
12968 +       int32_t reboot_cmd;
12969 +       int32_t exit_code;
12970 +};
12971 +
12972 +#ifdef __KERNEL__
12973 +
12974 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12975 +extern int vc_wait_exit(struct vx_info *, void __user *);
12976 +
12977 +#endif /* __KERNEL__ */
12978 +
12979 +/*  process alteration commands */
12980 +
12981 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12982 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12983 +
12984 +struct vcmd_pflags_v0 {
12985 +       uint32_t flagword;
12986 +       uint32_t mask;
12987 +};
12988 +
12989 +#ifdef __KERNEL__
12990 +
12991 +extern int vc_get_pflags(uint32_t pid, void __user *);
12992 +extern int vc_set_pflags(uint32_t pid, void __user *);
12993 +
12994 +#endif /* __KERNEL__ */
12995 +#endif /* _VX_SIGNAL_CMD_H */
12996 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/signal.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/signal.h
12997 --- linux-2.6.32.10/include/linux/vserver/signal.h      1970-01-01 01:00:00.000000000 +0100
12998 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/signal.h      2009-12-03 20:04:56.000000000 +0100
12999 @@ -0,0 +1,14 @@
13000 +#ifndef _VX_SIGNAL_H
13001 +#define _VX_SIGNAL_H
13002 +
13003 +
13004 +#ifdef __KERNEL__
13005 +
13006 +struct vx_info;
13007 +
13008 +int vx_info_kill(struct vx_info *, int, int);
13009 +
13010 +#endif /* __KERNEL__ */
13011 +#else  /* _VX_SIGNAL_H */
13012 +#warning duplicate inclusion
13013 +#endif /* _VX_SIGNAL_H */
13014 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/space_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/space_cmd.h
13015 --- linux-2.6.32.10/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00.000000000 +0100
13016 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/space_cmd.h   2009-12-03 20:04:56.000000000 +0100
13017 @@ -0,0 +1,38 @@
13018 +#ifndef _VX_SPACE_CMD_H
13019 +#define _VX_SPACE_CMD_H
13020 +
13021 +
13022 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13023 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13024 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13025 +
13026 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13027 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13028 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13029 +
13030 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13031 +
13032 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13033 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13034 +
13035 +
13036 +struct vcmd_space_mask_v1 {
13037 +       uint64_t mask;
13038 +};
13039 +
13040 +struct vcmd_space_mask_v2 {
13041 +       uint64_t mask;
13042 +       uint32_t index;
13043 +};
13044 +
13045 +
13046 +#ifdef __KERNEL__
13047 +
13048 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13049 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13050 +extern int vc_enter_space(struct vx_info *, void __user *);
13051 +extern int vc_set_space(struct vx_info *, void __user *);
13052 +extern int vc_get_space_mask(void __user *, int);
13053 +
13054 +#endif /* __KERNEL__ */
13055 +#endif /* _VX_SPACE_CMD_H */
13056 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/space.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/space.h
13057 --- linux-2.6.32.10/include/linux/vserver/space.h       1970-01-01 01:00:00.000000000 +0100
13058 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/space.h       2009-12-03 20:04:56.000000000 +0100
13059 @@ -0,0 +1,12 @@
13060 +#ifndef _VX_SPACE_H
13061 +#define _VX_SPACE_H
13062 +
13063 +#include <linux/types.h>
13064 +
13065 +struct vx_info;
13066 +
13067 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13068 +
13069 +#else  /* _VX_SPACE_H */
13070 +#warning duplicate inclusion
13071 +#endif /* _VX_SPACE_H */
13072 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/switch.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/switch.h
13073 --- linux-2.6.32.10/include/linux/vserver/switch.h      1970-01-01 01:00:00.000000000 +0100
13074 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/switch.h      2009-12-03 20:04:56.000000000 +0100
13075 @@ -0,0 +1,98 @@
13076 +#ifndef _VX_SWITCH_H
13077 +#define _VX_SWITCH_H
13078 +
13079 +#include <linux/types.h>
13080 +
13081 +
13082 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13083 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13084 +#define VC_VERSION(c)          ((c) & 0xFFF)
13085 +
13086 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13087 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13088 +
13089 +/*
13090 +
13091 +  Syscall Matrix V2.8
13092 +
13093 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13094 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13095 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13096 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13097 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13098 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13099 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13100 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13101 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13102 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13103 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13104 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13105 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13106 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13107 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13108 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13109 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13110 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13111 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13112 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13113 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13114 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13115 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13116 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13117 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13118 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13119 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13120 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13121 +
13122 +*/
13123 +
13124 +#define VC_CAT_VERSION         0
13125 +
13126 +#define VC_CAT_VSETUP          1
13127 +#define VC_CAT_VHOST           2
13128 +
13129 +#define VC_CAT_DEVICE          6
13130 +
13131 +#define VC_CAT_VPROC           9
13132 +#define VC_CAT_PROCALT         10
13133 +#define VC_CAT_PROCMIG         11
13134 +#define VC_CAT_PROCTRL         12
13135 +
13136 +#define VC_CAT_SCHED           14
13137 +#define VC_CAT_MEMCTRL         20
13138 +
13139 +#define VC_CAT_VNET            25
13140 +#define VC_CAT_NETALT          26
13141 +#define VC_CAT_NETMIG          27
13142 +#define VC_CAT_NETCTRL         28
13143 +
13144 +#define VC_CAT_TAGMIG          35
13145 +#define VC_CAT_DLIMIT          36
13146 +#define VC_CAT_INODE           38
13147 +
13148 +#define VC_CAT_VSTAT           40
13149 +#define VC_CAT_VINFO           46
13150 +#define VC_CAT_EVENT           48
13151 +
13152 +#define VC_CAT_FLAGS           52
13153 +#define VC_CAT_VSPACE          54
13154 +#define VC_CAT_DEBUG           56
13155 +#define VC_CAT_RLIMIT          60
13156 +
13157 +#define VC_CAT_SYSTEST         61
13158 +#define VC_CAT_COMPAT          63
13159 +
13160 +/*  query version */
13161 +
13162 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13163 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13164 +
13165 +
13166 +#ifdef __KERNEL__
13167 +
13168 +#include <linux/errno.h>
13169 +
13170 +#endif /* __KERNEL__ */
13171 +
13172 +#endif /* _VX_SWITCH_H */
13173 +
13174 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/tag_cmd.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/tag_cmd.h
13175 --- linux-2.6.32.10/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00.000000000 +0100
13176 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/tag_cmd.h     2009-12-03 20:04:56.000000000 +0100
13177 @@ -0,0 +1,22 @@
13178 +#ifndef _VX_TAG_CMD_H
13179 +#define _VX_TAG_CMD_H
13180 +
13181 +
13182 +/* vinfo commands */
13183 +
13184 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13185 +
13186 +#ifdef __KERNEL__
13187 +extern int vc_task_tag(uint32_t);
13188 +
13189 +#endif /* __KERNEL__ */
13190 +
13191 +/* context commands */
13192 +
13193 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13194 +
13195 +#ifdef __KERNEL__
13196 +extern int vc_tag_migrate(uint32_t);
13197 +
13198 +#endif /* __KERNEL__ */
13199 +#endif /* _VX_TAG_CMD_H */
13200 diff -NurpP --minimal linux-2.6.32.10/include/linux/vserver/tag.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/tag.h
13201 --- linux-2.6.32.10/include/linux/vserver/tag.h 1970-01-01 01:00:00.000000000 +0100
13202 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vserver/tag.h 2009-12-03 20:04:56.000000000 +0100
13203 @@ -0,0 +1,143 @@
13204 +#ifndef _DX_TAG_H
13205 +#define _DX_TAG_H
13206 +
13207 +#include <linux/types.h>
13208 +
13209 +
13210 +#define DX_TAG(in)     (IS_TAGGED(in))
13211 +
13212 +
13213 +#ifdef CONFIG_TAG_NFSD
13214 +#define DX_TAG_NFSD    1
13215 +#else
13216 +#define DX_TAG_NFSD    0
13217 +#endif
13218 +
13219 +
13220 +#ifdef CONFIG_TAGGING_NONE
13221 +
13222 +#define MAX_UID                0xFFFFFFFF
13223 +#define MAX_GID                0xFFFFFFFF
13224 +
13225 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13226 +
13227 +#define TAGINO_UID(cond, uid, tag)     (uid)
13228 +#define TAGINO_GID(cond, gid, tag)     (gid)
13229 +
13230 +#endif
13231 +
13232 +
13233 +#ifdef CONFIG_TAGGING_GID16
13234 +
13235 +#define MAX_UID                0xFFFFFFFF
13236 +#define MAX_GID                0x0000FFFF
13237 +
13238 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13239 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13240 +
13241 +#define TAGINO_UID(cond, uid, tag)     (uid)
13242 +#define TAGINO_GID(cond, gid, tag)     \
13243 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13244 +
13245 +#endif
13246 +
13247 +
13248 +#ifdef CONFIG_TAGGING_ID24
13249 +
13250 +#define MAX_UID                0x00FFFFFF
13251 +#define MAX_GID                0x00FFFFFF
13252 +
13253 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13254 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13255 +
13256 +#define TAGINO_UID(cond, uid, tag)     \
13257 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13258 +#define TAGINO_GID(cond, gid, tag)     \
13259 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13260 +
13261 +#endif
13262 +
13263 +
13264 +#ifdef CONFIG_TAGGING_UID16
13265 +
13266 +#define MAX_UID                0x0000FFFF
13267 +#define MAX_GID                0xFFFFFFFF
13268 +
13269 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13270 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13271 +
13272 +#define TAGINO_UID(cond, uid, tag)     \
13273 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13274 +#define TAGINO_GID(cond, gid, tag)     (gid)
13275 +
13276 +#endif
13277 +
13278 +
13279 +#ifdef CONFIG_TAGGING_INTERN
13280 +
13281 +#define MAX_UID                0xFFFFFFFF
13282 +#define MAX_GID                0xFFFFFFFF
13283 +
13284 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13285 +       ((cond) ? (tag) : 0)
13286 +
13287 +#define TAGINO_UID(cond, uid, tag)     (uid)
13288 +#define TAGINO_GID(cond, gid, tag)     (gid)
13289 +
13290 +#endif
13291 +
13292 +
13293 +#ifndef CONFIG_TAGGING_NONE
13294 +#define dx_current_fstag(sb)   \
13295 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13296 +#else
13297 +#define dx_current_fstag(sb)   (0)
13298 +#endif
13299 +
13300 +#ifndef CONFIG_TAGGING_INTERN
13301 +#define TAGINO_TAG(cond, tag)  (0)
13302 +#else
13303 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13304 +#endif
13305 +
13306 +#define INOTAG_UID(cond, uid, gid)     \
13307 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13308 +#define INOTAG_GID(cond, uid, gid)     \
13309 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13310 +
13311 +
13312 +static inline uid_t dx_map_uid(uid_t uid)
13313 +{
13314 +       if ((uid > MAX_UID) && (uid != -1))
13315 +               uid = -2;
13316 +       return (uid & MAX_UID);
13317 +}
13318 +
13319 +static inline gid_t dx_map_gid(gid_t gid)
13320 +{
13321 +       if ((gid > MAX_GID) && (gid != -1))
13322 +               gid = -2;
13323 +       return (gid & MAX_GID);
13324 +}
13325 +
13326 +struct peer_tag {
13327 +       int32_t xid;
13328 +       int32_t nid;
13329 +};
13330 +
13331 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13332 +
13333 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13334 +                unsigned long *flags);
13335 +
13336 +#ifdef CONFIG_PROPAGATE
13337 +
13338 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13339 +
13340 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13341 +
13342 +#else
13343 +#define dx_propagate_tag(n, i) do { } while (0)
13344 +#endif
13345 +
13346 +#endif /* _DX_TAG_H */
13347 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_inet6.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_inet6.h
13348 --- linux-2.6.32.10/include/linux/vs_inet6.h    1970-01-01 01:00:00.000000000 +0100
13349 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_inet6.h    2009-12-03 20:04:56.000000000 +0100
13350 @@ -0,0 +1,246 @@
13351 +#ifndef _VS_INET6_H
13352 +#define _VS_INET6_H
13353 +
13354 +#include "vserver/base.h"
13355 +#include "vserver/network.h"
13356 +#include "vserver/debug.h"
13357 +
13358 +#include <net/ipv6.h>
13359 +
13360 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13361 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13362 +
13363 +
13364 +#ifdef CONFIG_IPV6
13365 +
13366 +static inline
13367 +int v6_addr_match(struct nx_addr_v6 *nxa,
13368 +       const struct in6_addr *addr, uint16_t mask)
13369 +{
13370 +       int ret = 0;
13371 +
13372 +       switch (nxa->type & mask) {
13373 +       case NXA_TYPE_MASK:
13374 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13375 +               break;
13376 +       case NXA_TYPE_ADDR:
13377 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13378 +               break;
13379 +       case NXA_TYPE_ANY:
13380 +               ret = 1;
13381 +               break;
13382 +       }
13383 +       vxdprintk(VXD_CBIT(net, 0),
13384 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13385 +               nxa, NXAV6(nxa), addr, mask, ret);
13386 +       return ret;
13387 +}
13388 +
13389 +static inline
13390 +int v6_addr_in_nx_info(struct nx_info *nxi,
13391 +       const struct in6_addr *addr, uint16_t mask)
13392 +{
13393 +       struct nx_addr_v6 *nxa;
13394 +       int ret = 1;
13395 +
13396 +       if (!nxi)
13397 +               goto out;
13398 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13399 +               if (v6_addr_match(nxa, addr, mask))
13400 +                       goto out;
13401 +       ret = 0;
13402 +out:
13403 +       vxdprintk(VXD_CBIT(net, 0),
13404 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13405 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13406 +       return ret;
13407 +}
13408 +
13409 +static inline
13410 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13411 +{
13412 +       /* FIXME: needs full range checks */
13413 +       return v6_addr_match(nxa, &addr->ip, mask);
13414 +}
13415 +
13416 +static inline
13417 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13418 +{
13419 +       struct nx_addr_v6 *ptr;
13420 +
13421 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13422 +               if (v6_nx_addr_match(ptr, nxa, mask))
13423 +                       return 1;
13424 +       return 0;
13425 +}
13426 +
13427 +
13428 +/*
13429 + *     Check if a given address matches for a socket
13430 + *
13431 + *     nxi:            the socket's nx_info if any
13432 + *     addr:           to be verified address
13433 + */
13434 +static inline
13435 +int v6_sock_addr_match (
13436 +       struct nx_info *nxi,
13437 +       struct inet_sock *inet,
13438 +       struct in6_addr *addr)
13439 +{
13440 +       struct sock *sk = &inet->sk;
13441 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13442 +
13443 +       if (!ipv6_addr_any(addr) &&
13444 +               ipv6_addr_equal(saddr, addr))
13445 +               return 1;
13446 +       if (ipv6_addr_any(saddr))
13447 +               return v6_addr_in_nx_info(nxi, addr, -1);
13448 +       return 0;
13449 +}
13450 +
13451 +/*
13452 + *     check if address is covered by socket
13453 + *
13454 + *     sk:     the socket to check against
13455 + *     addr:   the address in question (must be != 0)
13456 + */
13457 +
13458 +static inline
13459 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13460 +{
13461 +       struct nx_info *nxi = sk->sk_nx_info;
13462 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13463 +
13464 +       vxdprintk(VXD_CBIT(net, 5),
13465 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13466 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13467 +               (sk->sk_socket?sk->sk_socket->flags:0));
13468 +
13469 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13470 +               return v6_addr_match(nxa, saddr, -1);
13471 +       } else if (nxi) {               /* match against nx_info */
13472 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13473 +       } else {                        /* unrestricted any socket */
13474 +               return 1;
13475 +       }
13476 +}
13477 +
13478 +
13479 +/* inet related checks and helpers */
13480 +
13481 +
13482 +struct in_ifaddr;
13483 +struct net_device;
13484 +struct sock;
13485 +
13486 +
13487 +#include <linux/netdevice.h>
13488 +#include <linux/inetdevice.h>
13489 +#include <net/inet_timewait_sock.h>
13490 +
13491 +
13492 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13493 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13494 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13495 +
13496 +
13497 +
13498 +static inline
13499 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13500 +{
13501 +       if (!nxi)
13502 +               return 1;
13503 +       if (!ifa)
13504 +               return 0;
13505 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13506 +}
13507 +
13508 +static inline
13509 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13510 +{
13511 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13512 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13513 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13514 +
13515 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13516 +               return 1;
13517 +       if (v6_ifa_in_nx_info(ifa, nxi))
13518 +               return 1;
13519 +       return 0;
13520 +}
13521 +
13522 +
13523 +struct nx_v6_sock_addr {
13524 +       struct in6_addr saddr;  /* Address used for validation */
13525 +       struct in6_addr baddr;  /* Address used for socket bind */
13526 +};
13527 +
13528 +static inline
13529 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13530 +       struct nx_v6_sock_addr *nsa)
13531 +{
13532 +       // struct sock *sk = &inet->sk;
13533 +       // struct nx_info *nxi = sk->sk_nx_info;
13534 +       struct in6_addr saddr = addr->sin6_addr;
13535 +       struct in6_addr baddr = saddr;
13536 +
13537 +       nsa->saddr = saddr;
13538 +       nsa->baddr = baddr;
13539 +       return 0;
13540 +}
13541 +
13542 +static inline
13543 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13544 +{
13545 +       // struct sock *sk = &inet->sk;
13546 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13547 +
13548 +       // *saddr = nsa->baddr;
13549 +       // inet->saddr = nsa->baddr;
13550 +}
13551 +
13552 +static inline
13553 +int nx_info_has_v6(struct nx_info *nxi)
13554 +{
13555 +       if (!nxi)
13556 +               return 1;
13557 +       if (NX_IPV6(nxi))
13558 +               return 1;
13559 +       return 0;
13560 +}
13561 +
13562 +#else /* CONFIG_IPV6 */
13563 +
13564 +static inline
13565 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13566 +{
13567 +       return 1;
13568 +}
13569 +
13570 +
13571 +static inline
13572 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13573 +{
13574 +       return 1;
13575 +}
13576 +
13577 +static inline
13578 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13579 +{
13580 +       return 1;
13581 +}
13582 +
13583 +static inline
13584 +int nx_info_has_v6(struct nx_info *nxi)
13585 +{
13586 +       return 0;
13587 +}
13588 +
13589 +#endif /* CONFIG_IPV6 */
13590 +
13591 +#define current_nx_info_has_v6() \
13592 +       nx_info_has_v6(current_nx_info())
13593 +
13594 +#else
13595 +#warning duplicate inclusion
13596 +#endif
13597 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_inet.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_inet.h
13598 --- linux-2.6.32.10/include/linux/vs_inet.h     1970-01-01 01:00:00.000000000 +0100
13599 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_inet.h     2009-12-03 20:04:56.000000000 +0100
13600 @@ -0,0 +1,342 @@
13601 +#ifndef _VS_INET_H
13602 +#define _VS_INET_H
13603 +
13604 +#include "vserver/base.h"
13605 +#include "vserver/network.h"
13606 +#include "vserver/debug.h"
13607 +
13608 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13609 +
13610 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13611 +                       NIPQUAD((a)->mask), (a)->type
13612 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13613 +
13614 +
13615 +static inline
13616 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13617 +{
13618 +       __be32 ip = nxa->ip[0].s_addr;
13619 +       __be32 mask = nxa->mask.s_addr;
13620 +       __be32 bcast = ip | ~mask;
13621 +       int ret = 0;
13622 +
13623 +       switch (nxa->type & tmask) {
13624 +       case NXA_TYPE_MASK:
13625 +               ret = (ip == (addr & mask));
13626 +               break;
13627 +       case NXA_TYPE_ADDR:
13628 +               ret = 3;
13629 +               if (addr == ip)
13630 +                       break;
13631 +               /* fall through to broadcast */
13632 +       case NXA_MOD_BCAST:
13633 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13634 +               break;
13635 +       case NXA_TYPE_RANGE:
13636 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13637 +                       (nxa->ip[1].s_addr > addr));
13638 +               break;
13639 +       case NXA_TYPE_ANY:
13640 +               ret = 2;
13641 +               break;
13642 +       }
13643 +
13644 +       vxdprintk(VXD_CBIT(net, 0),
13645 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13646 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13647 +       return ret;
13648 +}
13649 +
13650 +static inline
13651 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13652 +{
13653 +       struct nx_addr_v4 *nxa;
13654 +       int ret = 1;
13655 +
13656 +       if (!nxi)
13657 +               goto out;
13658 +
13659 +       ret = 2;
13660 +       /* allow 127.0.0.1 when remapping lback */
13661 +       if ((tmask & NXA_LOOPBACK) &&
13662 +               (addr == IPI_LOOPBACK) &&
13663 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13664 +               goto out;
13665 +       ret = 3;
13666 +       /* check for lback address */
13667 +       if ((tmask & NXA_MOD_LBACK) &&
13668 +               (nxi->v4_lback.s_addr == addr))
13669 +               goto out;
13670 +       ret = 4;
13671 +       /* check for broadcast address */
13672 +       if ((tmask & NXA_MOD_BCAST) &&
13673 +               (nxi->v4_bcast.s_addr == addr))
13674 +               goto out;
13675 +       ret = 5;
13676 +       /* check for v4 addresses */
13677 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13678 +               if (v4_addr_match(nxa, addr, tmask))
13679 +                       goto out;
13680 +       ret = 0;
13681 +out:
13682 +       vxdprintk(VXD_CBIT(net, 0),
13683 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13684 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13685 +       return ret;
13686 +}
13687 +
13688 +static inline
13689 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13690 +{
13691 +       /* FIXME: needs full range checks */
13692 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13693 +}
13694 +
13695 +static inline
13696 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13697 +{
13698 +       struct nx_addr_v4 *ptr;
13699 +
13700 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13701 +               if (v4_nx_addr_match(ptr, nxa, mask))
13702 +                       return 1;
13703 +       return 0;
13704 +}
13705 +
13706 +#include <net/inet_sock.h>
13707 +
13708 +/*
13709 + *     Check if a given address matches for a socket
13710 + *
13711 + *     nxi:            the socket's nx_info if any
13712 + *     addr:           to be verified address
13713 + */
13714 +static inline
13715 +int v4_sock_addr_match (
13716 +       struct nx_info *nxi,
13717 +       struct inet_sock *inet,
13718 +       __be32 addr)
13719 +{
13720 +       __be32 saddr = inet->rcv_saddr;
13721 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13722 +
13723 +       if (addr && (saddr == addr || bcast == addr))
13724 +               return 1;
13725 +       if (!saddr)
13726 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13727 +       return 0;
13728 +}
13729 +
13730 +
13731 +/* inet related checks and helpers */
13732 +
13733 +
13734 +struct in_ifaddr;
13735 +struct net_device;
13736 +struct sock;
13737 +
13738 +#ifdef CONFIG_INET
13739 +
13740 +#include <linux/netdevice.h>
13741 +#include <linux/inetdevice.h>
13742 +#include <net/inet_sock.h>
13743 +#include <net/inet_timewait_sock.h>
13744 +
13745 +
13746 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13747 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13748 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13749 +
13750 +
13751 +/*
13752 + *     check if address is covered by socket
13753 + *
13754 + *     sk:     the socket to check against
13755 + *     addr:   the address in question (must be != 0)
13756 + */
13757 +
13758 +static inline
13759 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13760 +{
13761 +       struct nx_info *nxi = sk->sk_nx_info;
13762 +       __be32 saddr = inet_rcv_saddr(sk);
13763 +
13764 +       vxdprintk(VXD_CBIT(net, 5),
13765 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13766 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13767 +               (sk->sk_socket?sk->sk_socket->flags:0));
13768 +
13769 +       if (saddr) {            /* direct address match */
13770 +               return v4_addr_match(nxa, saddr, -1);
13771 +       } else if (nxi) {       /* match against nx_info */
13772 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13773 +       } else {                /* unrestricted any socket */
13774 +               return 1;
13775 +       }
13776 +}
13777 +
13778 +
13779 +
13780 +static inline
13781 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13782 +{
13783 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13784 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13785 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13786 +
13787 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13788 +               return 1;
13789 +       if (dev_in_nx_info(dev, nxi))
13790 +               return 1;
13791 +       return 0;
13792 +}
13793 +
13794 +
13795 +static inline
13796 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13797 +{
13798 +       if (!nxi)
13799 +               return 1;
13800 +       if (!ifa)
13801 +               return 0;
13802 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13803 +}
13804 +
13805 +static inline
13806 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13807 +{
13808 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13809 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13810 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13811 +
13812 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13813 +               return 1;
13814 +       if (v4_ifa_in_nx_info(ifa, nxi))
13815 +               return 1;
13816 +       return 0;
13817 +}
13818 +
13819 +
13820 +struct nx_v4_sock_addr {
13821 +       __be32 saddr;   /* Address used for validation */
13822 +       __be32 baddr;   /* Address used for socket bind */
13823 +};
13824 +
13825 +static inline
13826 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13827 +       struct nx_v4_sock_addr *nsa)
13828 +{
13829 +       struct sock *sk = &inet->sk;
13830 +       struct nx_info *nxi = sk->sk_nx_info;
13831 +       __be32 saddr = addr->sin_addr.s_addr;
13832 +       __be32 baddr = saddr;
13833 +
13834 +       vxdprintk(VXD_CBIT(net, 3),
13835 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13836 +               sk, sk->sk_nx_info, sk->sk_socket,
13837 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13838 +               NIPQUAD(saddr));
13839 +
13840 +       if (nxi) {
13841 +               if (saddr == INADDR_ANY) {
13842 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13843 +                               baddr = nxi->v4.ip[0].s_addr;
13844 +               } else if (saddr == IPI_LOOPBACK) {
13845 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13846 +                               baddr = nxi->v4_lback.s_addr;
13847 +               } else {        /* normal address bind */
13848 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13849 +                               return -EADDRNOTAVAIL;
13850 +               }
13851 +       }
13852 +
13853 +       vxdprintk(VXD_CBIT(net, 3),
13854 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13855 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13856 +
13857 +       nsa->saddr = saddr;
13858 +       nsa->baddr = baddr;
13859 +       return 0;
13860 +}
13861 +
13862 +static inline
13863 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13864 +{
13865 +       inet->saddr = nsa->baddr;
13866 +       inet->rcv_saddr = nsa->baddr;
13867 +}
13868 +
13869 +
13870 +/*
13871 + *      helper to simplify inet_lookup_listener
13872 + *
13873 + *      nxi:   the socket's nx_info if any
13874 + *      addr:  to be verified address
13875 + *      saddr: socket address
13876 + */
13877 +static inline int v4_inet_addr_match (
13878 +       struct nx_info *nxi,
13879 +       __be32 addr,
13880 +       __be32 saddr)
13881 +{
13882 +       if (addr && (saddr == addr))
13883 +               return 1;
13884 +       if (!saddr)
13885 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13886 +       return 0;
13887 +}
13888 +
13889 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13890 +{
13891 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13892 +               (addr == nxi->v4_lback.s_addr))
13893 +               return IPI_LOOPBACK;
13894 +       return addr;
13895 +}
13896 +
13897 +static inline
13898 +int nx_info_has_v4(struct nx_info *nxi)
13899 +{
13900 +       if (!nxi)
13901 +               return 1;
13902 +       if (NX_IPV4(nxi))
13903 +               return 1;
13904 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13905 +               return 1;
13906 +       return 0;
13907 +}
13908 +
13909 +#else /* CONFIG_INET */
13910 +
13911 +static inline
13912 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13913 +{
13914 +       return 1;
13915 +}
13916 +
13917 +static inline
13918 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13919 +{
13920 +       return 1;
13921 +}
13922 +
13923 +static inline
13924 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13925 +{
13926 +       return 1;
13927 +}
13928 +
13929 +static inline
13930 +int nx_info_has_v4(struct nx_info *nxi)
13931 +{
13932 +       return 0;
13933 +}
13934 +
13935 +#endif /* CONFIG_INET */
13936 +
13937 +#define current_nx_info_has_v4() \
13938 +       nx_info_has_v4(current_nx_info())
13939 +
13940 +#else
13941 +// #warning duplicate inclusion
13942 +#endif
13943 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_limit.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_limit.h
13944 --- linux-2.6.32.10/include/linux/vs_limit.h    1970-01-01 01:00:00.000000000 +0100
13945 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_limit.h    2009-12-03 20:04:56.000000000 +0100
13946 @@ -0,0 +1,140 @@
13947 +#ifndef _VS_LIMIT_H
13948 +#define _VS_LIMIT_H
13949 +
13950 +#include "vserver/limit.h"
13951 +#include "vserver/base.h"
13952 +#include "vserver/context.h"
13953 +#include "vserver/debug.h"
13954 +#include "vserver/context.h"
13955 +#include "vserver/limit_int.h"
13956 +
13957 +
13958 +#define vx_acc_cres(v, d, p, r) \
13959 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13960 +
13961 +#define vx_acc_cres_cond(x, d, p, r) \
13962 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13963 +       r, d, p, __FILE__, __LINE__)
13964 +
13965 +
13966 +#define vx_add_cres(v, a, p, r) \
13967 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13968 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13969 +
13970 +#define vx_add_cres_cond(x, a, p, r) \
13971 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13972 +       r, a, p, __FILE__, __LINE__)
13973 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13974 +
13975 +
13976 +/* process and file limits */
13977 +
13978 +#define vx_nproc_inc(p) \
13979 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13980 +
13981 +#define vx_nproc_dec(p) \
13982 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13983 +
13984 +#define vx_files_inc(f) \
13985 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13986 +
13987 +#define vx_files_dec(f) \
13988 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13989 +
13990 +#define vx_locks_inc(l) \
13991 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13992 +
13993 +#define vx_locks_dec(l) \
13994 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13995 +
13996 +#define vx_openfd_inc(f) \
13997 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13998 +
13999 +#define vx_openfd_dec(f) \
14000 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
14001 +
14002 +
14003 +#define vx_cres_avail(v, n, r) \
14004 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
14005 +
14006 +
14007 +#define vx_nproc_avail(n) \
14008 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
14009 +
14010 +#define vx_files_avail(n) \
14011 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
14012 +
14013 +#define vx_locks_avail(n) \
14014 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
14015 +
14016 +#define vx_openfd_avail(n) \
14017 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
14018 +
14019 +
14020 +/* dentry limits */
14021 +
14022 +#define vx_dentry_inc(d) do {                                          \
14023 +       if (atomic_read(&d->d_count) == 1)                              \
14024 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
14025 +       } while (0)
14026 +
14027 +#define vx_dentry_dec(d) do {                                          \
14028 +       if (atomic_read(&d->d_count) == 0)                              \
14029 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
14030 +       } while (0)
14031 +
14032 +#define vx_dentry_avail(n) \
14033 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
14034 +
14035 +
14036 +/* socket limits */
14037 +
14038 +#define vx_sock_inc(s) \
14039 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
14040 +
14041 +#define vx_sock_dec(s) \
14042 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
14043 +
14044 +#define vx_sock_avail(n) \
14045 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
14046 +
14047 +
14048 +/* ipc resource limits */
14049 +
14050 +#define vx_ipcmsg_add(v, u, a) \
14051 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
14052 +
14053 +#define vx_ipcmsg_sub(v, u, a) \
14054 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
14055 +
14056 +#define vx_ipcmsg_avail(v, a) \
14057 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
14058 +
14059 +
14060 +#define vx_ipcshm_add(v, k, a) \
14061 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14062 +
14063 +#define vx_ipcshm_sub(v, k, a) \
14064 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14065 +
14066 +#define vx_ipcshm_avail(v, a) \
14067 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14068 +
14069 +
14070 +#define vx_semary_inc(a) \
14071 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
14072 +
14073 +#define vx_semary_dec(a) \
14074 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
14075 +
14076 +
14077 +#define vx_nsems_add(a,n) \
14078 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14079 +
14080 +#define vx_nsems_sub(a,n) \
14081 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14082 +
14083 +
14084 +#else
14085 +#warning duplicate inclusion
14086 +#endif
14087 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_memory.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_memory.h
14088 --- linux-2.6.32.10/include/linux/vs_memory.h   1970-01-01 01:00:00.000000000 +0100
14089 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_memory.h   2009-12-03 20:04:56.000000000 +0100
14090 @@ -0,0 +1,159 @@
14091 +#ifndef _VS_MEMORY_H
14092 +#define _VS_MEMORY_H
14093 +
14094 +#include "vserver/limit.h"
14095 +#include "vserver/base.h"
14096 +#include "vserver/context.h"
14097 +#include "vserver/debug.h"
14098 +#include "vserver/context.h"
14099 +#include "vserver/limit_int.h"
14100 +
14101 +
14102 +#define __acc_add_long(a, v)   (*(v) += (a))
14103 +#define __acc_inc_long(v)      (++*(v))
14104 +#define __acc_dec_long(v)      (--*(v))
14105 +
14106 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14107 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14108 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14109 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14110 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14111 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14112 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14113 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14114 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14115 +
14116 +
14117 +#define vx_acc_page(m, d, v, r) do {                                   \
14118 +       if ((d) > 0)                                                    \
14119 +               __acc_inc_long(&(m)->v);                                \
14120 +       else                                                            \
14121 +               __acc_dec_long(&(m)->v);                                \
14122 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14123 +} while (0)
14124 +
14125 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14126 +       if ((d) > 0)                                                    \
14127 +               __acc_inc_atomic(&(m)->v);                              \
14128 +       else                                                            \
14129 +               __acc_dec_atomic(&(m)->v);                              \
14130 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14131 +} while (0)
14132 +
14133 +
14134 +#define vx_acc_pages(m, p, v, r) do {                                  \
14135 +       unsigned long __p = (p);                                        \
14136 +       __acc_add_long(__p, &(m)->v);                                   \
14137 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14138 +} while (0)
14139 +
14140 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14141 +       unsigned long __p = (p);                                        \
14142 +       __acc_add_atomic(__p, &(m)->v);                                 \
14143 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14144 +} while (0)
14145 +
14146 +
14147 +
14148 +#define vx_acc_vmpage(m, d) \
14149 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14150 +#define vx_acc_vmlpage(m, d) \
14151 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14152 +#define vx_acc_file_rsspage(m, d) \
14153 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14154 +#define vx_acc_anon_rsspage(m, d) \
14155 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14156 +
14157 +#define vx_acc_vmpages(m, p) \
14158 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14159 +#define vx_acc_vmlpages(m, p) \
14160 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14161 +#define vx_acc_file_rsspages(m, p) \
14162 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14163 +#define vx_acc_anon_rsspages(m, p) \
14164 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14165 +
14166 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14167 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14168 +
14169 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14170 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14171 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14172 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14173 +
14174 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14175 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14176 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14177 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14178 +
14179 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14180 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14181 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14182 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14183 +
14184 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14185 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14186 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14187 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14188 +
14189 +
14190 +#define vx_pages_avail(m, p, r) \
14191 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14192 +
14193 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14194 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14195 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14196 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14197 +
14198 +#define vx_rss_avail(m, p) \
14199 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14200 +
14201 +
14202 +enum {
14203 +       VXPT_UNKNOWN = 0,
14204 +       VXPT_ANON,
14205 +       VXPT_NONE,
14206 +       VXPT_FILE,
14207 +       VXPT_SWAP,
14208 +       VXPT_WRITE
14209 +};
14210 +
14211 +#if 0
14212 +#define        vx_page_fault(mm, vma, type, ret)
14213 +#else
14214 +
14215 +static inline
14216 +void __vx_page_fault(struct mm_struct *mm,
14217 +       struct vm_area_struct *vma, int type, int ret)
14218 +{
14219 +       struct vx_info *vxi = mm->mm_vx_info;
14220 +       int what;
14221 +/*
14222 +       static char *page_type[6] =
14223 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14224 +       static char *page_what[4] =
14225 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14226 +*/
14227 +
14228 +       if (!vxi)
14229 +               return;
14230 +
14231 +       what = (ret & 0x3);
14232 +
14233 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14234 +               type, what, ret, page_type[type], page_what[what]);
14235 +*/
14236 +       if (ret & VM_FAULT_WRITE)
14237 +               what |= 0x4;
14238 +       atomic_inc(&vxi->cacct.page[type][what]);
14239 +}
14240 +
14241 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14242 +#endif
14243 +
14244 +
14245 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14246 +
14247 +#else
14248 +#warning duplicate inclusion
14249 +#endif
14250 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_network.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_network.h
14251 --- linux-2.6.32.10/include/linux/vs_network.h  1970-01-01 01:00:00.000000000 +0100
14252 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_network.h  2009-12-03 20:04:56.000000000 +0100
14253 @@ -0,0 +1,169 @@
14254 +#ifndef _NX_VS_NETWORK_H
14255 +#define _NX_VS_NETWORK_H
14256 +
14257 +#include "vserver/context.h"
14258 +#include "vserver/network.h"
14259 +#include "vserver/base.h"
14260 +#include "vserver/check.h"
14261 +#include "vserver/debug.h"
14262 +
14263 +#include <linux/sched.h>
14264 +
14265 +
14266 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14267 +
14268 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14269 +       const char *_file, int _line)
14270 +{
14271 +       if (!nxi)
14272 +               return NULL;
14273 +
14274 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14275 +               nxi, nxi ? nxi->nx_id : 0,
14276 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14277 +               _file, _line);
14278 +
14279 +       atomic_inc(&nxi->nx_usecnt);
14280 +       return nxi;
14281 +}
14282 +
14283 +
14284 +extern void free_nx_info(struct nx_info *);
14285 +
14286 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14287 +
14288 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14289 +{
14290 +       if (!nxi)
14291 +               return;
14292 +
14293 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14294 +               nxi, nxi ? nxi->nx_id : 0,
14295 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14296 +               _file, _line);
14297 +
14298 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14299 +               free_nx_info(nxi);
14300 +}
14301 +
14302 +
14303 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14304 +
14305 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14306 +               const char *_file, int _line)
14307 +{
14308 +       if (nxi) {
14309 +               vxlprintk(VXD_CBIT(nid, 3),
14310 +                       "init_nx_info(%p[#%d.%d])",
14311 +                       nxi, nxi ? nxi->nx_id : 0,
14312 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14313 +                       _file, _line);
14314 +
14315 +               atomic_inc(&nxi->nx_usecnt);
14316 +       }
14317 +       *nxp = nxi;
14318 +}
14319 +
14320 +
14321 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14322 +
14323 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14324 +       const char *_file, int _line)
14325 +{
14326 +       struct nx_info *nxo;
14327 +
14328 +       if (!nxi)
14329 +               return;
14330 +
14331 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14332 +               nxi, nxi ? nxi->nx_id : 0,
14333 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14334 +               _file, _line);
14335 +
14336 +       atomic_inc(&nxi->nx_usecnt);
14337 +       nxo = xchg(nxp, nxi);
14338 +       BUG_ON(nxo);
14339 +}
14340 +
14341 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14342 +
14343 +static inline void __clr_nx_info(struct nx_info **nxp,
14344 +       const char *_file, int _line)
14345 +{
14346 +       struct nx_info *nxo;
14347 +
14348 +       nxo = xchg(nxp, NULL);
14349 +       if (!nxo)
14350 +               return;
14351 +
14352 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14353 +               nxo, nxo ? nxo->nx_id : 0,
14354 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14355 +               _file, _line);
14356 +
14357 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14358 +               free_nx_info(nxo);
14359 +}
14360 +
14361 +
14362 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14363 +
14364 +static inline void __claim_nx_info(struct nx_info *nxi,
14365 +       struct task_struct *task, const char *_file, int _line)
14366 +{
14367 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14368 +               nxi, nxi ? nxi->nx_id : 0,
14369 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14370 +               nxi?atomic_read(&nxi->nx_tasks):0,
14371 +               task, _file, _line);
14372 +
14373 +       atomic_inc(&nxi->nx_tasks);
14374 +}
14375 +
14376 +
14377 +extern void unhash_nx_info(struct nx_info *);
14378 +
14379 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14380 +
14381 +static inline void __release_nx_info(struct nx_info *nxi,
14382 +       struct task_struct *task, const char *_file, int _line)
14383 +{
14384 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14385 +               nxi, nxi ? nxi->nx_id : 0,
14386 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14387 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14388 +               task, _file, _line);
14389 +
14390 +       might_sleep();
14391 +
14392 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14393 +               unhash_nx_info(nxi);
14394 +}
14395 +
14396 +
14397 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14398 +
14399 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14400 +       const char *_file, int _line)
14401 +{
14402 +       struct nx_info *nxi;
14403 +
14404 +       task_lock(p);
14405 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14406 +               p, _file, _line);
14407 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14408 +       task_unlock(p);
14409 +       return nxi;
14410 +}
14411 +
14412 +
14413 +static inline void exit_nx_info(struct task_struct *p)
14414 +{
14415 +       if (p->nx_info)
14416 +               release_nx_info(p->nx_info, p);
14417 +}
14418 +
14419 +
14420 +#else
14421 +#warning duplicate inclusion
14422 +#endif
14423 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_pid.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_pid.h
14424 --- linux-2.6.32.10/include/linux/vs_pid.h      1970-01-01 01:00:00.000000000 +0100
14425 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_pid.h      2009-12-03 20:04:56.000000000 +0100
14426 @@ -0,0 +1,95 @@
14427 +#ifndef _VS_PID_H
14428 +#define _VS_PID_H
14429 +
14430 +#include "vserver/base.h"
14431 +#include "vserver/check.h"
14432 +#include "vserver/context.h"
14433 +#include "vserver/debug.h"
14434 +#include "vserver/pid.h"
14435 +#include <linux/pid_namespace.h>
14436 +
14437 +
14438 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14439 +
14440 +static inline
14441 +int vx_proc_task_visible(struct task_struct *task)
14442 +{
14443 +       if ((task->pid == 1) &&
14444 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14445 +               /* show a blend through init */
14446 +               goto visible;
14447 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14448 +               goto visible;
14449 +       return 0;
14450 +visible:
14451 +       return 1;
14452 +}
14453 +
14454 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14455 +
14456 +#if 0
14457 +
14458 +static inline
14459 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14460 +{
14461 +       struct task_struct *task = find_task_by_real_pid(pid);
14462 +
14463 +       if (task && !vx_proc_task_visible(task)) {
14464 +               vxdprintk(VXD_CBIT(misc, 6),
14465 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14466 +                       task, task->xid, task->pid,
14467 +                       current, current->xid, current->pid);
14468 +               task = NULL;
14469 +       }
14470 +       return task;
14471 +}
14472 +
14473 +#endif
14474 +
14475 +static inline
14476 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14477 +{
14478 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14479 +
14480 +       if (task && !vx_proc_task_visible(task)) {
14481 +               vxdprintk(VXD_CBIT(misc, 6),
14482 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14483 +                       task, task->xid, task->pid,
14484 +                       current, current->xid, current->pid);
14485 +               put_task_struct(task);
14486 +               task = NULL;
14487 +       }
14488 +       return task;
14489 +}
14490 +
14491 +#if 0
14492 +
14493 +static inline
14494 +struct task_struct *vx_child_reaper(struct task_struct *p)
14495 +{
14496 +       struct vx_info *vxi = p->vx_info;
14497 +       struct task_struct *reaper = child_reaper(p);
14498 +
14499 +       if (!vxi)
14500 +               goto out;
14501 +
14502 +       BUG_ON(!p->vx_info->vx_reaper);
14503 +
14504 +       /* child reaper for the guest reaper */
14505 +       if (vxi->vx_reaper == p)
14506 +               goto out;
14507 +
14508 +       reaper = vxi->vx_reaper;
14509 +out:
14510 +       vxdprintk(VXD_CBIT(xid, 7),
14511 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14512 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14513 +       return reaper;
14514 +}
14515 +
14516 +#endif
14517 +
14518 +
14519 +#else
14520 +#warning duplicate inclusion
14521 +#endif
14522 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_sched.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_sched.h
14523 --- linux-2.6.32.10/include/linux/vs_sched.h    1970-01-01 01:00:00.000000000 +0100
14524 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_sched.h    2009-12-03 20:04:56.000000000 +0100
14525 @@ -0,0 +1,110 @@
14526 +#ifndef _VS_SCHED_H
14527 +#define _VS_SCHED_H
14528 +
14529 +#include "vserver/base.h"
14530 +#include "vserver/context.h"
14531 +#include "vserver/sched.h"
14532 +
14533 +
14534 +#define VAVAVOOM_RATIO          50
14535 +
14536 +#define MAX_PRIO_BIAS           20
14537 +#define MIN_PRIO_BIAS          -20
14538 +
14539 +
14540 +#ifdef CONFIG_VSERVER_HARDCPU
14541 +
14542 +/*
14543 + * effective_prio - return the priority that is based on the static
14544 + * priority but is modified by bonuses/penalties.
14545 + *
14546 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14547 + * into a -4 ... 0 ... +4 bonus/penalty range.
14548 + *
14549 + * Additionally, we scale another amount based on the number of
14550 + * CPU tokens currently held by the context, if the process is
14551 + * part of a context (and the appropriate SCHED flag is set).
14552 + * This ranges from -5 ... 0 ... +15, quadratically.
14553 + *
14554 + * So, the total bonus is -9 .. 0 .. +19
14555 + * We use ~50% of the full 0...39 priority range so that:
14556 + *
14557 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14558 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14559 + *    unless that context is far exceeding its CPU allocation.
14560 + *
14561 + * Both properties are important to certain workloads.
14562 + */
14563 +static inline
14564 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14565 +{
14566 +       int vavavoom, max;
14567 +
14568 +       /* lots of tokens = lots of vavavoom
14569 +        *      no tokens = no vavavoom      */
14570 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14571 +               max = sched_pc->tokens_max;
14572 +               vavavoom = max - vavavoom;
14573 +               max = max * max;
14574 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14575 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14576 +               return vavavoom;
14577 +       }
14578 +       return 0;
14579 +}
14580 +
14581 +
14582 +static inline
14583 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14584 +{
14585 +       struct vx_info *vxi = p->vx_info;
14586 +       struct _vx_sched_pc *sched_pc;
14587 +
14588 +       if (!vxi)
14589 +               return prio;
14590 +
14591 +       sched_pc = &vx_cpu(vxi, sched_pc);
14592 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14593 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14594 +
14595 +               sched_pc->vavavoom = vavavoom;
14596 +               prio += vavavoom;
14597 +       }
14598 +       prio += sched_pc->prio_bias;
14599 +       return prio;
14600 +}
14601 +
14602 +#else /* !CONFIG_VSERVER_HARDCPU */
14603 +
14604 +static inline
14605 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14606 +{
14607 +       struct vx_info *vxi = p->vx_info;
14608 +
14609 +       if (vxi)
14610 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14611 +       return prio;
14612 +}
14613 +
14614 +#endif /* CONFIG_VSERVER_HARDCPU */
14615 +
14616 +
14617 +static inline void vx_account_user(struct vx_info *vxi,
14618 +       cputime_t cputime, int nice)
14619 +{
14620 +       if (!vxi)
14621 +               return;
14622 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14623 +}
14624 +
14625 +static inline void vx_account_system(struct vx_info *vxi,
14626 +       cputime_t cputime, int idle)
14627 +{
14628 +       if (!vxi)
14629 +               return;
14630 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14631 +}
14632 +
14633 +#else
14634 +#warning duplicate inclusion
14635 +#endif
14636 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_socket.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_socket.h
14637 --- linux-2.6.32.10/include/linux/vs_socket.h   1970-01-01 01:00:00.000000000 +0100
14638 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_socket.h   2009-12-03 20:04:56.000000000 +0100
14639 @@ -0,0 +1,67 @@
14640 +#ifndef _VS_SOCKET_H
14641 +#define _VS_SOCKET_H
14642 +
14643 +#include "vserver/debug.h"
14644 +#include "vserver/base.h"
14645 +#include "vserver/cacct.h"
14646 +#include "vserver/context.h"
14647 +#include "vserver/tag.h"
14648 +
14649 +
14650 +/* socket accounting */
14651 +
14652 +#include <linux/socket.h>
14653 +
14654 +static inline int vx_sock_type(int family)
14655 +{
14656 +       switch (family) {
14657 +       case PF_UNSPEC:
14658 +               return VXA_SOCK_UNSPEC;
14659 +       case PF_UNIX:
14660 +               return VXA_SOCK_UNIX;
14661 +       case PF_INET:
14662 +               return VXA_SOCK_INET;
14663 +       case PF_INET6:
14664 +               return VXA_SOCK_INET6;
14665 +       case PF_PACKET:
14666 +               return VXA_SOCK_PACKET;
14667 +       default:
14668 +               return VXA_SOCK_OTHER;
14669 +       }
14670 +}
14671 +
14672 +#define vx_acc_sock(v, f, p, s) \
14673 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14674 +
14675 +static inline void __vx_acc_sock(struct vx_info *vxi,
14676 +       int family, int pos, int size, char *file, int line)
14677 +{
14678 +       if (vxi) {
14679 +               int type = vx_sock_type(family);
14680 +
14681 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14682 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14683 +       }
14684 +}
14685 +
14686 +#define vx_sock_recv(sk, s) \
14687 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14688 +#define vx_sock_send(sk, s) \
14689 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14690 +#define vx_sock_fail(sk, s) \
14691 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14692 +
14693 +
14694 +#define sock_vx_init(s) do {           \
14695 +       (s)->sk_xid = 0;                \
14696 +       (s)->sk_vx_info = NULL;         \
14697 +       } while (0)
14698 +
14699 +#define sock_nx_init(s) do {           \
14700 +       (s)->sk_nid = 0;                \
14701 +       (s)->sk_nx_info = NULL;         \
14702 +       } while (0)
14703 +
14704 +#else
14705 +#warning duplicate inclusion
14706 +#endif
14707 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_tag.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_tag.h
14708 --- linux-2.6.32.10/include/linux/vs_tag.h      1970-01-01 01:00:00.000000000 +0100
14709 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_tag.h      2009-12-03 20:04:56.000000000 +0100
14710 @@ -0,0 +1,47 @@
14711 +#ifndef _VS_TAG_H
14712 +#define _VS_TAG_H
14713 +
14714 +#include <linux/vserver/tag.h>
14715 +
14716 +/* check conditions */
14717 +
14718 +#define DX_ADMIN       0x0001
14719 +#define DX_WATCH       0x0002
14720 +#define DX_HOSTID      0x0008
14721 +
14722 +#define DX_IDENT       0x0010
14723 +
14724 +#define DX_ARG_MASK    0x0010
14725 +
14726 +
14727 +#define dx_task_tag(t) ((t)->tag)
14728 +
14729 +#define dx_current_tag() dx_task_tag(current)
14730 +
14731 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14732 +
14733 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14734 +
14735 +
14736 +/*
14737 + * check current context for ADMIN/WATCH and
14738 + * optionally against supplied argument
14739 + */
14740 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14741 +{
14742 +       if (mode & DX_ARG_MASK) {
14743 +               if ((mode & DX_IDENT) && (id == cid))
14744 +                       return 1;
14745 +       }
14746 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14747 +               ((mode & DX_WATCH) && (cid == 1)) ||
14748 +               ((mode & DX_HOSTID) && (id == 0)));
14749 +}
14750 +
14751 +struct inode;
14752 +int dx_permission(const struct inode *inode, int mask);
14753 +
14754 +
14755 +#else
14756 +#warning duplicate inclusion
14757 +#endif
14758 diff -NurpP --minimal linux-2.6.32.10/include/linux/vs_time.h linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_time.h
14759 --- linux-2.6.32.10/include/linux/vs_time.h     1970-01-01 01:00:00.000000000 +0100
14760 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/linux/vs_time.h     2009-12-03 20:04:56.000000000 +0100
14761 @@ -0,0 +1,19 @@
14762 +#ifndef _VS_TIME_H
14763 +#define _VS_TIME_H
14764 +
14765 +
14766 +/* time faking stuff */
14767 +
14768 +#ifdef CONFIG_VSERVER_VTIME
14769 +
14770 +extern void vx_gettimeofday(struct timeval *tv);
14771 +extern int vx_settimeofday(struct timespec *ts);
14772 +
14773 +#else
14774 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14775 +#define        vx_settimeofday(t)      do_settimeofday(t)
14776 +#endif
14777 +
14778 +#else
14779 +#warning duplicate inclusion
14780 +#endif
14781 diff -NurpP --minimal linux-2.6.32.10/include/net/addrconf.h linux-2.6.32.10-vs2.3.0.36.29.2/include/net/addrconf.h
14782 --- linux-2.6.32.10/include/net/addrconf.h      2009-12-03 20:02:57.000000000 +0100
14783 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/net/addrconf.h      2009-12-03 20:04:56.000000000 +0100
14784 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14785                                                struct net_device *dev,
14786                                                const struct in6_addr *daddr,
14787                                                unsigned int srcprefs,
14788 -                                              struct in6_addr *saddr);
14789 +                                              struct in6_addr *saddr,
14790 +                                              struct nx_info *nxi);
14791  extern int                     ipv6_get_lladdr(struct net_device *dev,
14792                                                 struct in6_addr *addr,
14793                                                 unsigned char banned_flags);
14794 diff -NurpP --minimal linux-2.6.32.10/include/net/af_unix.h linux-2.6.32.10-vs2.3.0.36.29.2/include/net/af_unix.h
14795 --- linux-2.6.32.10/include/net/af_unix.h       2008-12-25 00:26:37.000000000 +0100
14796 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/net/af_unix.h       2009-12-03 20:04:56.000000000 +0100
14797 @@ -4,6 +4,7 @@
14798  #include <linux/socket.h>
14799  #include <linux/un.h>
14800  #include <linux/mutex.h>
14801 +#include <linux/vs_base.h>
14802  #include <net/sock.h>
14803  
14804  extern void unix_inflight(struct file *fp);
14805 diff -NurpP --minimal linux-2.6.32.10/include/net/inet_timewait_sock.h linux-2.6.32.10-vs2.3.0.36.29.2/include/net/inet_timewait_sock.h
14806 --- linux-2.6.32.10/include/net/inet_timewait_sock.h    2009-12-03 20:02:57.000000000 +0100
14807 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/net/inet_timewait_sock.h    2009-12-03 20:04:56.000000000 +0100
14808 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14809  #define tw_hash                        __tw_common.skc_hash
14810  #define tw_prot                        __tw_common.skc_prot
14811  #define tw_net                 __tw_common.skc_net
14812 +#define tw_xid                 __tw_common.skc_xid
14813 +#define tw_vx_info             __tw_common.skc_vx_info
14814 +#define tw_nid                 __tw_common.skc_nid
14815 +#define tw_nx_info             __tw_common.skc_nx_info
14816         int                     tw_timeout;
14817         volatile unsigned char  tw_substate;
14818         /* 3 bits hole, try to pack */
14819 diff -NurpP --minimal linux-2.6.32.10/include/net/route.h linux-2.6.32.10-vs2.3.0.36.29.2/include/net/route.h
14820 --- linux-2.6.32.10/include/net/route.h 2009-09-10 15:26:27.000000000 +0200
14821 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/net/route.h 2009-12-03 20:04:56.000000000 +0100
14822 @@ -135,6 +135,9 @@ static inline void ip_rt_put(struct rtab
14823                 dst_release(&rt->u.dst);
14824  }
14825  
14826 +#include <linux/vs_base.h>
14827 +#include <linux/vs_inet.h>
14828 +
14829  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14830  
14831  extern const __u8 ip_tos2prio[16];
14832 @@ -144,6 +147,9 @@ static inline char rt_tos2priority(u8 to
14833         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14834  }
14835  
14836 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14837 +       struct rtable **, struct flowi *);
14838 +
14839  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14840                                    __be32 src, u32 tos, int oif, u8 protocol,
14841                                    __be16 sport, __be16 dport, struct sock *sk,
14842 @@ -161,11 +167,24 @@ static inline int ip_route_connect(struc
14843  
14844         int err;
14845         struct net *net = sock_net(sk);
14846 +       struct nx_info *nx_info = current_nx_info();
14847  
14848         if (inet_sk(sk)->transparent)
14849                 fl.flags |= FLOWI_FLAG_ANYSRC;
14850  
14851 -       if (!dst || !src) {
14852 +       if (sk)
14853 +               nx_info = sk->sk_nx_info;
14854 +
14855 +       vxdprintk(VXD_CBIT(net, 4),
14856 +               "ip_route_connect(%p) %p,%p;%lx",
14857 +               sk, nx_info, sk->sk_socket,
14858 +               (sk->sk_socket?sk->sk_socket->flags:0));
14859 +
14860 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14861 +       if (err)
14862 +               return err;
14863 +
14864 +       if (!fl.fl4_dst || !fl.fl4_src) {
14865                 err = __ip_route_output_key(net, rp, &fl);
14866                 if (err)
14867                         return err;
14868 diff -NurpP --minimal linux-2.6.32.10/include/net/sock.h linux-2.6.32.10-vs2.3.0.36.29.2/include/net/sock.h
14869 --- linux-2.6.32.10/include/net/sock.h  2009-12-03 20:02:57.000000000 +0100
14870 +++ linux-2.6.32.10-vs2.3.0.36.29.2/include/net/sock.h  2009-12-03 20:04:56.000000000 +0100
14871 @@ -139,6 +139,10 @@ struct sock_common {
14872  #ifdef CONFIG_NET_NS
14873         struct net              *skc_net;
14874  #endif
14875 +       xid_t                   skc_xid;
14876 +       struct vx_info          *skc_vx_info;
14877 +       nid_t                   skc_nid;
14878 +       struct nx_info          *skc_nx_info;
14879  };
14880  
14881  /**
14882 @@ -225,6 +229,10 @@ struct sock {
14883  #define sk_bind_node           __sk_common.skc_bind_node
14884  #define sk_prot                        __sk_common.skc_prot
14885  #define sk_net                 __sk_common.skc_net
14886 +#define sk_xid                 __sk_common.skc_xid
14887 +#define sk_vx_info             __sk_common.skc_vx_info
14888 +#define sk_nid                 __sk_common.skc_nid
14889 +#define sk_nx_info             __sk_common.skc_nx_info
14890         kmemcheck_bitfield_begin(flags);
14891         unsigned int            sk_shutdown  : 2,
14892                                 sk_no_check  : 2,
14893 diff -NurpP --minimal linux-2.6.32.10/init/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/init/Kconfig
14894 --- linux-2.6.32.10/init/Kconfig        2009-12-03 20:02:57.000000000 +0100
14895 +++ linux-2.6.32.10-vs2.3.0.36.29.2/init/Kconfig        2009-12-03 20:04:56.000000000 +0100
14896 @@ -477,6 +477,19 @@ config CGROUP_SCHED
14897  
14898  endchoice
14899  
14900 +config CFS_HARD_LIMITS
14901 +       bool "Hard Limits for CFS Group Scheduler"
14902 +       depends on EXPERIMENTAL
14903 +       depends on FAIR_GROUP_SCHED && CGROUP_SCHED
14904 +       default n
14905 +       help
14906 +         This option enables hard limiting of CPU time obtained by
14907 +         a fair task group. Use this if you want to throttle a group of tasks
14908 +         based on its CPU usage. For more details refer to
14909 +         Documentation/scheduler/sched-cfs-hard-limits.txt
14910 +
14911 +         Say N if unsure.
14912 +
14913  menuconfig CGROUPS
14914         boolean "Control Group support"
14915         help
14916 diff -NurpP --minimal linux-2.6.32.10/init/main.c linux-2.6.32.10-vs2.3.0.36.29.2/init/main.c
14917 --- linux-2.6.32.10/init/main.c 2009-12-03 20:02:57.000000000 +0100
14918 +++ linux-2.6.32.10-vs2.3.0.36.29.2/init/main.c 2009-12-03 20:04:56.000000000 +0100
14919 @@ -70,6 +70,7 @@
14920  #include <linux/sfi.h>
14921  #include <linux/shmem_fs.h>
14922  #include <trace/boot.h>
14923 +#include <linux/vserver/percpu.h>
14924  
14925  #include <asm/io.h>
14926  #include <asm/bugs.h>
14927 diff -NurpP --minimal linux-2.6.32.10/ipc/mqueue.c linux-2.6.32.10-vs2.3.0.36.29.2/ipc/mqueue.c
14928 --- linux-2.6.32.10/ipc/mqueue.c        2009-12-03 20:02:57.000000000 +0100
14929 +++ linux-2.6.32.10-vs2.3.0.36.29.2/ipc/mqueue.c        2009-12-03 20:04:56.000000000 +0100
14930 @@ -33,6 +33,8 @@
14931  #include <linux/pid.h>
14932  #include <linux/ipc_namespace.h>
14933  #include <linux/ima.h>
14934 +#include <linux/vs_context.h>
14935 +#include <linux/vs_limit.h>
14936  
14937  #include <net/sock.h>
14938  #include "util.h"
14939 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14940         struct sigevent notify;
14941         struct pid* notify_owner;
14942         struct user_struct *user;       /* user who created, for accounting */
14943 +       struct vx_info *vxi;
14944         struct sock *notify_sock;
14945         struct sk_buff *notify_cookie;
14946  
14947 @@ -125,6 +128,7 @@ static struct inode *mqueue_get_inode(st
14948                 if (S_ISREG(mode)) {
14949                         struct mqueue_inode_info *info;
14950                         struct task_struct *p = current;
14951 +                       struct vx_info *vxi = p->vx_info;
14952                         unsigned long mq_bytes, mq_msg_tblsz;
14953  
14954                         inode->i_fop = &mqueue_file_operations;
14955 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14956                         info->notify_owner = NULL;
14957                         info->qsize = 0;
14958                         info->user = NULL;      /* set when all is ok */
14959 +                       info->vxi = NULL;
14960                         memset(&info->attr, 0, sizeof(info->attr));
14961                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14962                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14963 @@ -153,22 +158,26 @@ static struct inode *mqueue_get_inode(st
14964                         spin_lock(&mq_lock);
14965                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14966                             u->mq_bytes + mq_bytes >
14967 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14968 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14969 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14970                                 spin_unlock(&mq_lock);
14971                                 goto out_inode;
14972                         }
14973                         u->mq_bytes += mq_bytes;
14974 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14975                         spin_unlock(&mq_lock);
14976  
14977                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14978                         if (!info->messages) {
14979                                 spin_lock(&mq_lock);
14980                                 u->mq_bytes -= mq_bytes;
14981 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14982                                 spin_unlock(&mq_lock);
14983                                 goto out_inode;
14984                         }
14985                         /* all is ok */
14986                         info->user = get_uid(u);
14987 +                       info->vxi = get_vx_info(vxi);
14988                 } else if (S_ISDIR(mode)) {
14989                         inc_nlink(inode);
14990                         /* Some things misbehave if size == 0 on a directory */
14991 @@ -269,8 +278,11 @@ static void mqueue_delete_inode(struct i
14992                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14993         user = info->user;
14994         if (user) {
14995 +               struct vx_info *vxi = info->vxi;
14996 +
14997                 spin_lock(&mq_lock);
14998                 user->mq_bytes -= mq_bytes;
14999 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
15000                 /*
15001                  * get_ns_from_inode() ensures that the
15002                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
15003 @@ -280,6 +292,7 @@ static void mqueue_delete_inode(struct i
15004                 if (ipc_ns)
15005                         ipc_ns->mq_queues_count--;
15006                 spin_unlock(&mq_lock);
15007 +               put_vx_info(vxi);
15008                 free_uid(user);
15009         }
15010         if (ipc_ns)
15011 diff -NurpP --minimal linux-2.6.32.10/ipc/msg.c linux-2.6.32.10-vs2.3.0.36.29.2/ipc/msg.c
15012 --- linux-2.6.32.10/ipc/msg.c   2010-03-18 16:17:37.000000000 +0100
15013 +++ linux-2.6.32.10-vs2.3.0.36.29.2/ipc/msg.c   2010-02-12 10:59:55.000000000 +0100
15014 @@ -38,6 +38,7 @@
15015  #include <linux/rwsem.h>
15016  #include <linux/nsproxy.h>
15017  #include <linux/ipc_namespace.h>
15018 +#include <linux/vs_base.h>
15019  
15020  #include <asm/current.h>
15021  #include <asm/uaccess.h>
15022 @@ -191,6 +192,7 @@ static int newque(struct ipc_namespace *
15023  
15024         msq->q_perm.mode = msgflg & S_IRWXUGO;
15025         msq->q_perm.key = key;
15026 +       msq->q_perm.xid = vx_current_xid();
15027  
15028         msq->q_perm.security = NULL;
15029         retval = security_msg_queue_alloc(msq);
15030 diff -NurpP --minimal linux-2.6.32.10/ipc/namespace.c linux-2.6.32.10-vs2.3.0.36.29.2/ipc/namespace.c
15031 --- linux-2.6.32.10/ipc/namespace.c     2009-09-10 15:26:27.000000000 +0200
15032 +++ linux-2.6.32.10-vs2.3.0.36.29.2/ipc/namespace.c     2009-12-03 20:04:56.000000000 +0100
15033 @@ -11,6 +11,8 @@
15034  #include <linux/slab.h>
15035  #include <linux/fs.h>
15036  #include <linux/mount.h>
15037 +#include <linux/vs_base.h>
15038 +#include <linux/vserver/global.h>
15039  
15040  #include "util.h"
15041  
15042 diff -NurpP --minimal linux-2.6.32.10/ipc/sem.c linux-2.6.32.10-vs2.3.0.36.29.2/ipc/sem.c
15043 --- linux-2.6.32.10/ipc/sem.c   2010-03-18 16:17:37.000000000 +0100
15044 +++ linux-2.6.32.10-vs2.3.0.36.29.2/ipc/sem.c   2010-02-12 10:59:55.000000000 +0100
15045 @@ -83,6 +83,8 @@
15046  #include <linux/rwsem.h>
15047  #include <linux/nsproxy.h>
15048  #include <linux/ipc_namespace.h>
15049 +#include <linux/vs_base.h>
15050 +#include <linux/vs_limit.h>
15051  
15052  #include <asm/uaccess.h>
15053  #include "util.h"
15054 @@ -256,6 +258,7 @@ static int newary(struct ipc_namespace *
15055  
15056         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15057         sma->sem_perm.key = key;
15058 +       sma->sem_perm.xid = vx_current_xid();
15059  
15060         sma->sem_perm.security = NULL;
15061         retval = security_sem_alloc(sma);
15062 @@ -271,6 +274,9 @@ static int newary(struct ipc_namespace *
15063                 return id;
15064         }
15065         ns->used_sems += nsems;
15066 +       /* FIXME: obsoleted? */
15067 +       vx_semary_inc(sma);
15068 +       vx_nsems_add(sma, nsems);
15069  
15070         sma->sem_base = (struct sem *) &sma[1];
15071         INIT_LIST_HEAD(&sma->sem_pending);
15072 @@ -547,6 +553,9 @@ static void freeary(struct ipc_namespace
15073         sem_unlock(sma);
15074  
15075         ns->used_sems -= sma->sem_nsems;
15076 +       /* FIXME: obsoleted? */
15077 +       vx_nsems_sub(sma, sma->sem_nsems);
15078 +       vx_semary_dec(sma);
15079         security_sem_free(sma);
15080         ipc_rcu_putref(sma);
15081  }
15082 diff -NurpP --minimal linux-2.6.32.10/ipc/shm.c linux-2.6.32.10-vs2.3.0.36.29.2/ipc/shm.c
15083 --- linux-2.6.32.10/ipc/shm.c   2010-03-18 16:17:37.000000000 +0100
15084 +++ linux-2.6.32.10-vs2.3.0.36.29.2/ipc/shm.c   2010-02-12 10:59:55.000000000 +0100
15085 @@ -40,6 +40,8 @@
15086  #include <linux/mount.h>
15087  #include <linux/ipc_namespace.h>
15088  #include <linux/ima.h>
15089 +#include <linux/vs_context.h>
15090 +#include <linux/vs_limit.h>
15091  
15092  #include <asm/uaccess.h>
15093  
15094 @@ -170,7 +172,12 @@ static void shm_open(struct vm_area_stru
15095   */
15096  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15097  {
15098 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15099 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15100 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15101 +
15102 +       vx_ipcshm_sub(vxi, shp, numpages);
15103 +       ns->shm_tot -= numpages;
15104 +
15105         shm_rmid(ns, shp);
15106         shm_unlock(shp);
15107         if (!is_file_hugepages(shp->shm_file))
15108 @@ -180,6 +187,7 @@ static void shm_destroy(struct ipc_names
15109                                                 shp->mlock_user);
15110         fput (shp->shm_file);
15111         security_shm_free(shp);
15112 +       put_vx_info(vxi);
15113         ipc_rcu_putref(shp);
15114  }
15115  
15116 @@ -350,11 +358,15 @@ static int newseg(struct ipc_namespace *
15117         if (ns->shm_tot + numpages > ns->shm_ctlall)
15118                 return -ENOSPC;
15119  
15120 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
15121 +               return -ENOSPC;
15122 +
15123         shp = ipc_rcu_alloc(sizeof(*shp));
15124         if (!shp)
15125                 return -ENOMEM;
15126  
15127         shp->shm_perm.key = key;
15128 +       shp->shm_perm.xid = vx_current_xid();
15129         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15130         shp->mlock_user = NULL;
15131  
15132 @@ -408,6 +420,7 @@ static int newseg(struct ipc_namespace *
15133         ns->shm_tot += numpages;
15134         error = shp->shm_perm.id;
15135         shm_unlock(shp);
15136 +       vx_ipcshm_add(current_vx_info(), key, numpages);
15137         return error;
15138  
15139  no_id:
15140 diff -NurpP --minimal linux-2.6.32.10/kernel/capability.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/capability.c
15141 --- linux-2.6.32.10/kernel/capability.c 2009-03-24 14:22:44.000000000 +0100
15142 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/capability.c 2009-12-03 20:04:56.000000000 +0100
15143 @@ -14,6 +14,7 @@
15144  #include <linux/security.h>
15145  #include <linux/syscalls.h>
15146  #include <linux/pid_namespace.h>
15147 +#include <linux/vs_context.h>
15148  #include <asm/uaccess.h>
15149  #include "cred-internals.h"
15150  
15151 @@ -122,6 +123,7 @@ static int cap_validate_magic(cap_user_h
15152         return 0;
15153  }
15154  
15155 +
15156  /*
15157   * The only thing that can change the capabilities of the current
15158   * process is the current process. As such, we can't be in this code
15159 @@ -289,6 +291,8 @@ error:
15160         return ret;
15161  }
15162  
15163 +#include <linux/vserver/base.h>
15164 +
15165  /**
15166   * capable - Determine if the current task has a superior capability in effect
15167   * @cap: The capability to be tested for
15168 @@ -301,6 +305,9 @@ error:
15169   */
15170  int capable(int cap)
15171  {
15172 +       /* here for now so we don't require task locking */
15173 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15174 +               return 0;
15175         if (unlikely(!cap_valid(cap))) {
15176                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15177                 BUG();
15178 diff -NurpP --minimal linux-2.6.32.10/kernel/compat.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/compat.c
15179 --- linux-2.6.32.10/kernel/compat.c     2009-09-10 15:26:27.000000000 +0200
15180 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/compat.c     2009-12-03 20:04:56.000000000 +0100
15181 @@ -902,7 +902,7 @@ asmlinkage long compat_sys_time(compat_t
15182         compat_time_t i;
15183         struct timeval tv;
15184  
15185 -       do_gettimeofday(&tv);
15186 +       vx_gettimeofday(&tv);
15187         i = tv.tv_sec;
15188  
15189         if (tloc) {
15190 @@ -927,7 +927,7 @@ asmlinkage long compat_sys_stime(compat_
15191         if (err)
15192                 return err;
15193  
15194 -       do_settimeofday(&tv);
15195 +       vx_settimeofday(&tv);
15196         return 0;
15197  }
15198  
15199 diff -NurpP --minimal linux-2.6.32.10/kernel/exit.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/exit.c
15200 --- linux-2.6.32.10/kernel/exit.c       2009-12-03 20:02:57.000000000 +0100
15201 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/exit.c       2009-12-03 20:04:56.000000000 +0100
15202 @@ -48,6 +48,10 @@
15203  #include <linux/fs_struct.h>
15204  #include <linux/init_task.h>
15205  #include <linux/perf_event.h>
15206 +#include <linux/vs_limit.h>
15207 +#include <linux/vs_context.h>
15208 +#include <linux/vs_network.h>
15209 +#include <linux/vs_pid.h>
15210  #include <trace/events/sched.h>
15211  
15212  #include <asm/uaccess.h>
15213 @@ -488,9 +492,11 @@ static void close_files(struct files_str
15214                                         filp_close(file, files);
15215                                         cond_resched();
15216                                 }
15217 +                               vx_openfd_dec(i);
15218                         }
15219                         i++;
15220                         set >>= 1;
15221 +                       cond_resched();
15222                 }
15223         }
15224  }
15225 @@ -1011,11 +1017,16 @@ NORET_TYPE void do_exit(long code)
15226  
15227         validate_creds_for_do_exit(tsk);
15228  
15229 +       /* needs to stay after exit_notify() */
15230 +       exit_vx_info(tsk, code);
15231 +       exit_nx_info(tsk);
15232 +
15233         preempt_disable();
15234         exit_rcu();
15235         /* causes final put_task_struct in finish_task_switch(). */
15236         tsk->state = TASK_DEAD;
15237         schedule();
15238 +       printk("bad task: %p [%lx]\n", current, current->state);
15239         BUG();
15240         /* Avoid "noreturn function does return".  */
15241         for (;;)
15242 diff -NurpP --minimal linux-2.6.32.10/kernel/fork.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/fork.c
15243 --- linux-2.6.32.10/kernel/fork.c       2009-12-03 20:02:57.000000000 +0100
15244 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/fork.c       2009-12-03 20:04:56.000000000 +0100
15245 @@ -64,6 +64,10 @@
15246  #include <linux/magic.h>
15247  #include <linux/perf_event.h>
15248  #include <linux/posix-timers.h>
15249 +#include <linux/vs_context.h>
15250 +#include <linux/vs_network.h>
15251 +#include <linux/vs_limit.h>
15252 +#include <linux/vs_memory.h>
15253  
15254  #include <asm/pgtable.h>
15255  #include <asm/pgalloc.h>
15256 @@ -151,6 +155,8 @@ void free_task(struct task_struct *tsk)
15257         account_kernel_stack(tsk->stack, -1);
15258         free_thread_info(tsk->stack);
15259         rt_mutex_debug_task_free(tsk);
15260 +       clr_vx_info(&tsk->vx_info);
15261 +       clr_nx_info(&tsk->nx_info);
15262         ftrace_graph_exit_task(tsk);
15263         free_task_struct(tsk);
15264  }
15265 @@ -296,6 +302,8 @@ static int dup_mmap(struct mm_struct *mm
15266         mm->free_area_cache = oldmm->mmap_base;
15267         mm->cached_hole_size = ~0UL;
15268         mm->map_count = 0;
15269 +       __set_mm_counter(mm, file_rss, 0);
15270 +       __set_mm_counter(mm, anon_rss, 0);
15271         cpumask_clear(mm_cpumask(mm));
15272         mm->mm_rb = RB_ROOT;
15273         rb_link = &mm->mm_rb.rb_node;
15274 @@ -310,7 +318,7 @@ static int dup_mmap(struct mm_struct *mm
15275  
15276                 if (mpnt->vm_flags & VM_DONTCOPY) {
15277                         long pages = vma_pages(mpnt);
15278 -                       mm->total_vm -= pages;
15279 +                       vx_vmpages_sub(mm, pages);
15280                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15281                                                                 -pages);
15282                         continue;
15283 @@ -452,8 +460,8 @@ static struct mm_struct * mm_init(struct
15284                 (current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
15285         mm->core_state = NULL;
15286         mm->nr_ptes = 0;
15287 -       set_mm_counter(mm, file_rss, 0);
15288 -       set_mm_counter(mm, anon_rss, 0);
15289 +       __set_mm_counter(mm, file_rss, 0);
15290 +       __set_mm_counter(mm, anon_rss, 0);
15291         spin_lock_init(&mm->page_table_lock);
15292         mm->free_area_cache = TASK_UNMAPPED_BASE;
15293         mm->cached_hole_size = ~0UL;
15294 @@ -463,6 +471,7 @@ static struct mm_struct * mm_init(struct
15295         if (likely(!mm_alloc_pgd(mm))) {
15296                 mm->def_flags = 0;
15297                 mmu_notifier_mm_init(mm);
15298 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15299                 return mm;
15300         }
15301  
15302 @@ -496,6 +505,7 @@ void __mmdrop(struct mm_struct *mm)
15303         mm_free_pgd(mm);
15304         destroy_context(mm);
15305         mmu_notifier_mm_destroy(mm);
15306 +       clr_vx_info(&mm->mm_vx_info);
15307         free_mm(mm);
15308  }
15309  EXPORT_SYMBOL_GPL(__mmdrop);
15310 @@ -631,6 +641,7 @@ struct mm_struct *dup_mm(struct task_str
15311                 goto fail_nomem;
15312  
15313         memcpy(mm, oldmm, sizeof(*mm));
15314 +       mm->mm_vx_info = NULL;
15315  
15316         /* Initializing for Swap token stuff */
15317         mm->token_priority = 0;
15318 @@ -669,6 +680,7 @@ fail_nocontext:
15319          * If init_new_context() failed, we cannot use mmput() to free the mm
15320          * because it calls destroy_context()
15321          */
15322 +       clr_vx_info(&mm->mm_vx_info);
15323         mm_free_pgd(mm);
15324         free_mm(mm);
15325         return NULL;
15326 @@ -980,6 +992,8 @@ static struct task_struct *copy_process(
15327         int retval;
15328         struct task_struct *p;
15329         int cgroup_callbacks_done = 0;
15330 +       struct vx_info *vxi;
15331 +       struct nx_info *nxi;
15332  
15333         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15334                 return ERR_PTR(-EINVAL);
15335 @@ -1026,12 +1040,28 @@ static struct task_struct *copy_process(
15336         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15337         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15338  #endif
15339 +       init_vx_info(&p->vx_info, current_vx_info());
15340 +       init_nx_info(&p->nx_info, current_nx_info());
15341 +
15342 +       /* check vserver memory */
15343 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15344 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15345 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15346 +               else
15347 +                       goto bad_fork_free;
15348 +       }
15349 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15350 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15351 +                       goto bad_fork_cleanup_vm;
15352 +       }
15353         retval = -EAGAIN;
15354 +       if (!vx_nproc_avail(1))
15355 +               goto bad_fork_cleanup_vm;
15356         if (atomic_read(&p->real_cred->user->processes) >=
15357                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15358                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15359                     p->real_cred->user != INIT_USER)
15360 -                       goto bad_fork_free;
15361 +                       goto bad_fork_cleanup_vm;
15362         }
15363  
15364         retval = copy_creds(p, clone_flags);
15365 @@ -1300,6 +1330,18 @@ static struct task_struct *copy_process(
15366  
15367         total_forks++;
15368         spin_unlock(&current->sighand->siglock);
15369 +
15370 +       /* p is copy of current */
15371 +       vxi = p->vx_info;
15372 +       if (vxi) {
15373 +               claim_vx_info(vxi, p);
15374 +               atomic_inc(&vxi->cvirt.nr_threads);
15375 +               atomic_inc(&vxi->cvirt.total_forks);
15376 +               vx_nproc_inc(p);
15377 +       }
15378 +       nxi = p->nx_info;
15379 +       if (nxi)
15380 +               claim_nx_info(nxi, p);
15381         write_unlock_irq(&tasklist_lock);
15382         proc_fork_connector(p);
15383         cgroup_post_fork(p);
15384 @@ -1341,6 +1383,9 @@ bad_fork_cleanup_cgroup:
15385  bad_fork_cleanup_count:
15386         atomic_dec(&p->cred->user->processes);
15387         exit_creds(p);
15388 +bad_fork_cleanup_vm:
15389 +       if (p->mm && !(clone_flags & CLONE_VM))
15390 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15391  bad_fork_free:
15392         free_task(p);
15393  fork_out:
15394 diff -NurpP --minimal linux-2.6.32.10/kernel/kthread.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/kthread.c
15395 --- linux-2.6.32.10/kernel/kthread.c    2009-12-03 20:02:58.000000000 +0100
15396 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/kthread.c    2009-12-03 20:04:56.000000000 +0100
15397 @@ -14,6 +14,7 @@
15398  #include <linux/file.h>
15399  #include <linux/module.h>
15400  #include <linux/mutex.h>
15401 +#include <linux/vs_pid.h>
15402  #include <trace/events/sched.h>
15403  
15404  static DEFINE_SPINLOCK(kthread_create_lock);
15405 diff -NurpP --minimal linux-2.6.32.10/kernel/Makefile linux-2.6.32.10-vs2.3.0.36.29.2/kernel/Makefile
15406 --- linux-2.6.32.10/kernel/Makefile     2009-12-03 20:02:57.000000000 +0100
15407 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/Makefile     2009-12-03 20:04:56.000000000 +0100
15408 @@ -23,6 +23,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
15409  CFLAGS_REMOVE_sched_clock.o = -pg
15410  endif
15411  
15412 +obj-y += vserver/
15413  obj-$(CONFIG_FREEZER) += freezer.o
15414  obj-$(CONFIG_PROFILING) += profile.o
15415  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15416 diff -NurpP --minimal linux-2.6.32.10/kernel/nsproxy.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/nsproxy.c
15417 --- linux-2.6.32.10/kernel/nsproxy.c    2009-09-10 15:26:28.000000000 +0200
15418 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/nsproxy.c    2009-12-03 20:04:56.000000000 +0100
15419 @@ -19,6 +19,8 @@
15420  #include <linux/mnt_namespace.h>
15421  #include <linux/utsname.h>
15422  #include <linux/pid_namespace.h>
15423 +#include <linux/vserver/global.h>
15424 +#include <linux/vserver/debug.h>
15425  #include <net/net_namespace.h>
15426  #include <linux/ipc_namespace.h>
15427  
15428 @@ -31,8 +33,11 @@ static inline struct nsproxy *create_nsp
15429         struct nsproxy *nsproxy;
15430  
15431         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15432 -       if (nsproxy)
15433 +       if (nsproxy) {
15434                 atomic_set(&nsproxy->count, 1);
15435 +               atomic_inc(&vs_global_nsproxy);
15436 +       }
15437 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15438         return nsproxy;
15439  }
15440  
15441 @@ -41,41 +46,52 @@ static inline struct nsproxy *create_nsp
15442   * Return the newly created nsproxy.  Do not attach this to the task,
15443   * leave it to the caller to do proper locking and attach it to task.
15444   */
15445 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15446 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15447 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15448 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15449  {
15450         struct nsproxy *new_nsp;
15451         int err;
15452  
15453 +       vxdprintk(VXD_CBIT(space, 4),
15454 +               "unshare_namespaces(0x%08lx,%p,%p)",
15455 +               flags, orig, new_fs);
15456 +
15457         new_nsp = create_nsproxy();
15458         if (!new_nsp)
15459                 return ERR_PTR(-ENOMEM);
15460  
15461 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15462 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15463         if (IS_ERR(new_nsp->mnt_ns)) {
15464                 err = PTR_ERR(new_nsp->mnt_ns);
15465                 goto out_ns;
15466         }
15467  
15468 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15469 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15470         if (IS_ERR(new_nsp->uts_ns)) {
15471                 err = PTR_ERR(new_nsp->uts_ns);
15472                 goto out_uts;
15473         }
15474  
15475 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15476 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15477         if (IS_ERR(new_nsp->ipc_ns)) {
15478                 err = PTR_ERR(new_nsp->ipc_ns);
15479                 goto out_ipc;
15480         }
15481  
15482 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15483 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15484         if (IS_ERR(new_nsp->pid_ns)) {
15485                 err = PTR_ERR(new_nsp->pid_ns);
15486                 goto out_pid;
15487         }
15488  
15489 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15490 +       /* disabled now?
15491 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15492 +       if (IS_ERR(new_nsp->user_ns)) {
15493 +               err = PTR_ERR(new_nsp->user_ns);
15494 +               goto out_user;
15495 +       } */
15496 +
15497 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15498         if (IS_ERR(new_nsp->net_ns)) {
15499                 err = PTR_ERR(new_nsp->net_ns);
15500                 goto out_net;
15501 @@ -100,6 +116,38 @@ out_ns:
15502         return ERR_PTR(err);
15503  }
15504  
15505 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15506 +                       struct fs_struct *new_fs)
15507 +{
15508 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15509 +}
15510 +
15511 +/*
15512 + * copies the nsproxy, setting refcount to 1, and grabbing a
15513 + * reference to all contained namespaces.
15514 + */
15515 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15516 +{
15517 +       struct nsproxy *ns = create_nsproxy();
15518 +
15519 +       if (ns) {
15520 +               memcpy(ns, orig, sizeof(struct nsproxy));
15521 +               atomic_set(&ns->count, 1);
15522 +
15523 +               if (ns->mnt_ns)
15524 +                       get_mnt_ns(ns->mnt_ns);
15525 +               if (ns->uts_ns)
15526 +                       get_uts_ns(ns->uts_ns);
15527 +               if (ns->ipc_ns)
15528 +                       get_ipc_ns(ns->ipc_ns);
15529 +               if (ns->pid_ns)
15530 +                       get_pid_ns(ns->pid_ns);
15531 +               if (ns->net_ns)
15532 +                       get_net(ns->net_ns);
15533 +       }
15534 +       return ns;
15535 +}
15536 +
15537  /*
15538   * called from clone.  This now handles copy for nsproxy and all
15539   * namespaces therein.
15540 @@ -107,9 +155,12 @@ out_ns:
15541  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15542  {
15543         struct nsproxy *old_ns = tsk->nsproxy;
15544 -       struct nsproxy *new_ns;
15545 +       struct nsproxy *new_ns = NULL;
15546         int err = 0;
15547  
15548 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15549 +               flags, tsk, old_ns);
15550 +
15551         if (!old_ns)
15552                 return 0;
15553  
15554 @@ -119,7 +170,7 @@ int copy_namespaces(unsigned long flags,
15555                                 CLONE_NEWPID | CLONE_NEWNET)))
15556                 return 0;
15557  
15558 -       if (!capable(CAP_SYS_ADMIN)) {
15559 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15560                 err = -EPERM;
15561                 goto out;
15562         }
15563 @@ -146,6 +197,9 @@ int copy_namespaces(unsigned long flags,
15564  
15565  out:
15566         put_nsproxy(old_ns);
15567 +       vxdprintk(VXD_CBIT(space, 3),
15568 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15569 +               flags, tsk, old_ns, err, new_ns);
15570         return err;
15571  }
15572  
15573 @@ -159,7 +213,9 @@ void free_nsproxy(struct nsproxy *ns)
15574                 put_ipc_ns(ns->ipc_ns);
15575         if (ns->pid_ns)
15576                 put_pid_ns(ns->pid_ns);
15577 -       put_net(ns->net_ns);
15578 +       if (ns->net_ns)
15579 +               put_net(ns->net_ns);
15580 +       atomic_dec(&vs_global_nsproxy);
15581         kmem_cache_free(nsproxy_cachep, ns);
15582  }
15583  
15584 @@ -172,11 +228,15 @@ int unshare_nsproxy_namespaces(unsigned 
15585  {
15586         int err = 0;
15587  
15588 +       vxdprintk(VXD_CBIT(space, 4),
15589 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15590 +               unshare_flags, current->nsproxy);
15591 +
15592         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15593                                CLONE_NEWNET)))
15594                 return 0;
15595  
15596 -       if (!capable(CAP_SYS_ADMIN))
15597 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15598                 return -EPERM;
15599  
15600         *new_nsp = create_new_namespaces(unshare_flags, current,
15601 diff -NurpP --minimal linux-2.6.32.10/kernel/pid.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/pid.c
15602 --- linux-2.6.32.10/kernel/pid.c        2009-12-03 20:02:58.000000000 +0100
15603 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/pid.c        2009-12-03 20:04:56.000000000 +0100
15604 @@ -36,6 +36,7 @@
15605  #include <linux/pid_namespace.h>
15606  #include <linux/init_task.h>
15607  #include <linux/syscalls.h>
15608 +#include <linux/vs_pid.h>
15609  
15610  #define pid_hashfn(nr, ns)     \
15611         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15612 @@ -305,7 +306,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15613  
15614  struct pid *find_vpid(int nr)
15615  {
15616 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15617 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15618  }
15619  EXPORT_SYMBOL_GPL(find_vpid);
15620  
15621 @@ -365,6 +366,9 @@ void transfer_pid(struct task_struct *ol
15622  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15623  {
15624         struct task_struct *result = NULL;
15625 +
15626 +       if (type == PIDTYPE_REALPID)
15627 +               type = PIDTYPE_PID;
15628         if (pid) {
15629                 struct hlist_node *first;
15630                 first = rcu_dereference(pid->tasks[type].first);
15631 @@ -380,7 +384,7 @@ EXPORT_SYMBOL(pid_task);
15632   */
15633  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15634  {
15635 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15636 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15637  }
15638  
15639  struct task_struct *find_task_by_vpid(pid_t vnr)
15640 @@ -422,7 +426,7 @@ struct pid *find_get_pid(pid_t nr)
15641  }
15642  EXPORT_SYMBOL_GPL(find_get_pid);
15643  
15644 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15645 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15646  {
15647         struct upid *upid;
15648         pid_t nr = 0;
15649 @@ -435,6 +439,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15650         return nr;
15651  }
15652  
15653 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15654 +{
15655 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15656 +}
15657 +
15658  pid_t pid_vnr(struct pid *pid)
15659  {
15660         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15661 diff -NurpP --minimal linux-2.6.32.10/kernel/pid_namespace.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/pid_namespace.c
15662 --- linux-2.6.32.10/kernel/pid_namespace.c      2009-12-03 20:02:58.000000000 +0100
15663 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/pid_namespace.c      2009-12-03 20:04:56.000000000 +0100
15664 @@ -13,6 +13,7 @@
15665  #include <linux/syscalls.h>
15666  #include <linux/err.h>
15667  #include <linux/acct.h>
15668 +#include <linux/vserver/global.h>
15669  
15670  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15671  
15672 @@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_
15673                 goto out_free_map;
15674  
15675         kref_init(&ns->kref);
15676 +       atomic_inc(&vs_global_pid_ns);
15677         ns->level = level;
15678         ns->parent = get_pid_ns(parent_pid_ns);
15679  
15680 @@ -111,6 +113,7 @@ static void destroy_pid_namespace(struct
15681  
15682         for (i = 0; i < PIDMAP_ENTRIES; i++)
15683                 kfree(ns->pidmap[i].page);
15684 +       atomic_dec(&vs_global_pid_ns);
15685         kmem_cache_free(pid_ns_cachep, ns);
15686  }
15687  
15688 diff -NurpP --minimal linux-2.6.32.10/kernel/posix-timers.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/posix-timers.c
15689 --- linux-2.6.32.10/kernel/posix-timers.c       2009-12-03 20:02:58.000000000 +0100
15690 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/posix-timers.c       2009-12-03 20:04:56.000000000 +0100
15691 @@ -46,6 +46,7 @@
15692  #include <linux/wait.h>
15693  #include <linux/workqueue.h>
15694  #include <linux/module.h>
15695 +#include <linux/vs_context.h>
15696  
15697  /*
15698   * Management arrays for POSIX timers.  Timers are kept in slab memory
15699 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15700  {
15701         struct task_struct *task;
15702         int shared, ret = -1;
15703 +
15704         /*
15705          * FIXME: if ->sigq is queued we can race with
15706          * dequeue_signal()->do_schedule_next_timer().
15707 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15708         rcu_read_lock();
15709         task = pid_task(timr->it_pid, PIDTYPE_PID);
15710         if (task) {
15711 +               struct vx_info_save vxis;
15712 +               struct vx_info *vxi;
15713 +
15714 +               vxi = get_vx_info(task->vx_info);
15715 +               enter_vx_info(vxi, &vxis);
15716                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15717                 ret = send_sigqueue(timr->sigq, task, shared);
15718 +               leave_vx_info(&vxis);
15719 +               put_vx_info(vxi);
15720         }
15721         rcu_read_unlock();
15722 +
15723         /* If we failed to send the signal the timer stops. */
15724         return ret > 0;
15725  }
15726 diff -NurpP --minimal linux-2.6.32.10/kernel/printk.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/printk.c
15727 --- linux-2.6.32.10/kernel/printk.c     2009-12-03 20:02:58.000000000 +0100
15728 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/printk.c     2009-12-03 20:04:56.000000000 +0100
15729 @@ -33,6 +33,7 @@
15730  #include <linux/bootmem.h>
15731  #include <linux/syscalls.h>
15732  #include <linux/kexec.h>
15733 +#include <linux/vs_cvirt.h>
15734  
15735  #include <asm/uaccess.h>
15736  
15737 @@ -276,18 +277,13 @@ int do_syslog(int type, char __user *buf
15738         unsigned i, j, limit, count;
15739         int do_clear = 0;
15740         char c;
15741 -       int error = 0;
15742 +       int error;
15743  
15744         error = security_syslog(type);
15745         if (error)
15746                 return error;
15747  
15748 -       switch (type) {
15749 -       case 0:         /* Close log */
15750 -               break;
15751 -       case 1:         /* Open log */
15752 -               break;
15753 -       case 2:         /* Read from log */
15754 +       if ((type >= 2) && (type <= 4)) {
15755                 error = -EINVAL;
15756                 if (!buf || len < 0)
15757                         goto out;
15758 @@ -298,6 +294,16 @@ int do_syslog(int type, char __user *buf
15759                         error = -EFAULT;
15760                         goto out;
15761                 }
15762 +       }
15763 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15764 +               return vx_do_syslog(type, buf, len);
15765 +
15766 +       switch (type) {
15767 +       case 0:         /* Close log */
15768 +               break;
15769 +       case 1:         /* Open log */
15770 +               break;
15771 +       case 2:         /* Read from log */
15772                 error = wait_event_interruptible(log_wait,
15773                                                         (log_start - log_end));
15774                 if (error)
15775 @@ -322,16 +328,6 @@ int do_syslog(int type, char __user *buf
15776                 do_clear = 1;
15777                 /* FALL THRU */
15778         case 3:         /* Read last kernel messages */
15779 -               error = -EINVAL;
15780 -               if (!buf || len < 0)
15781 -                       goto out;
15782 -               error = 0;
15783 -               if (!len)
15784 -                       goto out;
15785 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15786 -                       error = -EFAULT;
15787 -                       goto out;
15788 -               }
15789                 count = len;
15790                 if (count > log_buf_len)
15791                         count = log_buf_len;
15792 diff -NurpP --minimal linux-2.6.32.10/kernel/ptrace.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/ptrace.c
15793 --- linux-2.6.32.10/kernel/ptrace.c     2009-12-03 20:02:58.000000000 +0100
15794 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/ptrace.c     2009-12-03 20:04:56.000000000 +0100
15795 @@ -22,6 +22,7 @@
15796  #include <linux/pid_namespace.h>
15797  #include <linux/syscalls.h>
15798  #include <linux/uaccess.h>
15799 +#include <linux/vs_context.h>
15800  
15801  
15802  /*
15803 @@ -151,6 +152,11 @@ int __ptrace_may_access(struct task_stru
15804                 dumpable = get_dumpable(task->mm);
15805         if (!dumpable && !capable(CAP_SYS_PTRACE))
15806                 return -EPERM;
15807 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15808 +               return -EPERM;
15809 +       if (!vx_check(task->xid, VS_IDENT) &&
15810 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15811 +               return -EACCES;
15812  
15813         return security_ptrace_access_check(task, mode);
15814  }
15815 @@ -621,6 +627,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15816                 goto out;
15817         }
15818  
15819 +       ret = -EPERM;
15820 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15821 +               goto out_put_task_struct;
15822 +
15823         if (request == PTRACE_ATTACH) {
15824                 ret = ptrace_attach(child);
15825                 /*
15826 diff -NurpP --minimal linux-2.6.32.10/kernel/sched.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sched.c
15827 --- linux-2.6.32.10/kernel/sched.c      2010-03-18 16:17:37.000000000 +0100
15828 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sched.c      2010-03-18 16:53:06.000000000 +0100
15829 @@ -71,6 +71,8 @@
15830  #include <linux/debugfs.h>
15831  #include <linux/ctype.h>
15832  #include <linux/ftrace.h>
15833 +#include <linux/vs_sched.h>
15834 +#include <linux/vs_cvirt.h>
15835  
15836  #include <asm/tlb.h>
15837  #include <asm/irq_regs.h>
15838 @@ -237,6 +239,15 @@ static DEFINE_MUTEX(sched_domains_mutex)
15839  
15840  #include <linux/cgroup.h>
15841  
15842 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
15843 +struct cfs_bandwidth {
15844 +       spinlock_t              cfs_runtime_lock;
15845 +       ktime_t                 cfs_period;
15846 +       u64                     cfs_runtime;
15847 +       struct hrtimer          cfs_period_timer;
15848 +};
15849 +#endif
15850 +
15851  struct cfs_rq;
15852  
15853  static LIST_HEAD(task_groups);
15854 @@ -257,6 +268,9 @@ struct task_group {
15855         /* runqueue "owned" by this group on each cpu */
15856         struct cfs_rq **cfs_rq;
15857         unsigned long shares;
15858 +#ifdef CONFIG_CFS_HARD_LIMITS
15859 +       struct cfs_bandwidth cfs_bandwidth;
15860 +#endif
15861  #endif
15862  
15863  #ifdef CONFIG_RT_GROUP_SCHED
15864 @@ -446,6 +460,19 @@ struct cfs_rq {
15865         unsigned long rq_weight;
15866  #endif
15867  #endif
15868 +#ifdef CONFIG_CFS_HARD_LIMITS
15869 +       /* set when the group is throttled  on this cpu */
15870 +       int cfs_throttled;
15871 +
15872 +       /* runtime currently consumed by the group on this rq */
15873 +       u64 cfs_time;
15874 +
15875 +       /* runtime available to the group on this rq */
15876 +       u64 cfs_runtime;
15877 +
15878 +       /* Protects the cfs runtime related fields of this cfs_rq */
15879 +       spinlock_t cfs_runtime_lock;
15880 +#endif
15881  };
15882  
15883  /* Real-Time classes' related field in a runqueue: */
15884 @@ -1610,6 +1637,7 @@ static void update_group_shares_cpu(stru
15885         }
15886  }
15887  
15888 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq);
15889  /*
15890   * Re-compute the task group their per cpu shares over the given domain.
15891   * This needs to be done in a bottom-up fashion because the rq weight of a
15892 @@ -1637,8 +1665,10 @@ static int tg_shares_up(struct task_grou
15893                  * If there are currently no tasks on the cpu pretend there
15894                  * is one of average load so that when a new task gets to
15895                  * run here it will not get delayed by group starvation.
15896 +                * Also if the group is throttled on this cpu, pretend that
15897 +                * it has no tasks.
15898                  */
15899 -               if (!weight)
15900 +               if (!weight || cfs_rq_throttled(tg->cfs_rq[i]))
15901                         weight = NICE_0_LOAD;
15902  
15903                 rq_weight += weight;
15904 @@ -1815,6 +1845,175 @@ static void cfs_rq_set_shares(struct cfs
15905  static void calc_load_account_active(struct rq *this_rq);
15906  static void update_sysctl(void);
15907  
15908 +
15909 +#if defined(CONFIG_RT_GROUP_SCHED) || defined(CONFIG_FAIR_GROUP_SCHED)
15910 +
15911 +#ifdef CONFIG_SMP
15912 +static inline const struct cpumask *sched_bw_period_mask(void)
15913 +{
15914 +       return cpu_rq(smp_processor_id())->rd->span;
15915 +}
15916 +#else /* !CONFIG_SMP */
15917 +static inline const struct cpumask *sched_bw_period_mask(void)
15918 +{
15919 +       return cpu_online_mask;
15920 +}
15921 +#endif /* CONFIG_SMP */
15922 +
15923 +#else
15924 +static inline const struct cpumask *sched_bw_period_mask(void)
15925 +{
15926 +       return cpu_online_mask;
15927 +}
15928 +
15929 +#endif
15930 +
15931 +#ifdef CONFIG_FAIR_GROUP_SCHED
15932 +#ifdef CONFIG_CFS_HARD_LIMITS
15933 +
15934 +/*
15935 + * Runtime allowed for a cfs group before it is hard limited.
15936 + * default: Infinite which means no hard limiting.
15937 + */
15938 +u64 sched_cfs_runtime = RUNTIME_INF;
15939 +
15940 +/*
15941 + * period over which we hard limit the cfs group's bandwidth.
15942 + * default: 0.5s
15943 + */
15944 +u64 sched_cfs_period = 500000;
15945 +
15946 +static inline u64 global_cfs_period(void)
15947 +{
15948 +       return sched_cfs_period * NSEC_PER_USEC;
15949 +}
15950 +
15951 +static inline u64 global_cfs_runtime(void)
15952 +{
15953 +       return RUNTIME_INF;
15954 +}
15955 +
15956 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b);
15957 +
15958 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15959 +{
15960 +       spin_lock(&cfs_rq->cfs_runtime_lock);
15961 +}
15962 +
15963 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15964 +{
15965 +       spin_unlock(&cfs_rq->cfs_runtime_lock);
15966 +}
15967 +
15968 +/*
15969 + * Refresh the runtimes of the throttled groups.
15970 + * But nothing much to do now, will populate this in later patches.
15971 + */
15972 +static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer)
15973 +{
15974 +       struct cfs_bandwidth *cfs_b =
15975 +               container_of(timer, struct cfs_bandwidth, cfs_period_timer);
15976 +
15977 +       do_sched_cfs_period_timer(cfs_b);
15978 +       hrtimer_add_expires_ns(timer, ktime_to_ns(cfs_b->cfs_period));
15979 +       return HRTIMER_RESTART;
15980 +}
15981 +
15982 +/*
15983 + * TODO: Check if this kind of timer setup is sufficient for cfs or
15984 + * should we do what rt is doing.
15985 + */
15986 +static void start_cfs_bandwidth(struct task_group *tg)
15987 +{
15988 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15989 +
15990 +       /*
15991 +        * Timer isn't setup for groups with infinite runtime
15992 +        */
15993 +       if (cfs_b->cfs_runtime == RUNTIME_INF)
15994 +               return;
15995 +
15996 +       if (hrtimer_active(&cfs_b->cfs_period_timer))
15997 +               return;
15998 +
15999 +       hrtimer_start_range_ns(&cfs_b->cfs_period_timer, cfs_b->cfs_period,
16000 +                       0, HRTIMER_MODE_REL);
16001 +}
16002 +
16003 +static void init_cfs_bandwidth(struct task_group *tg)
16004 +{
16005 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
16006 +
16007 +       cfs_b->cfs_period = ns_to_ktime(global_cfs_period());
16008 +       cfs_b->cfs_runtime = global_cfs_runtime();
16009 +
16010 +       spin_lock_init(&cfs_b->cfs_runtime_lock);
16011 +
16012 +       hrtimer_init(&cfs_b->cfs_period_timer,
16013 +                       CLOCK_MONOTONIC, HRTIMER_MODE_REL);
16014 +       cfs_b->cfs_period_timer.function = &sched_cfs_period_timer;
16015 +}
16016 +
16017 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
16018 +{
16019 +       hrtimer_cancel(&tg->cfs_bandwidth.cfs_period_timer);
16020 +}
16021 +
16022 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
16023 +{
16024 +       cfs_rq->cfs_time = 0;
16025 +       cfs_rq->cfs_throttled = 0;
16026 +       cfs_rq->cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
16027 +       spin_lock_init(&cfs_rq->cfs_runtime_lock);
16028 +}
16029 +
16030 +#else /* !CONFIG_CFS_HARD_LIMITS */
16031 +
16032 +static void init_cfs_bandwidth(struct task_group *tg)
16033 +{
16034 +       return;
16035 +}
16036 +
16037 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
16038 +{
16039 +       return;
16040 +}
16041 +
16042 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
16043 +{
16044 +       return;
16045 +}
16046 +
16047 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
16048 +{
16049 +       return;
16050 +}
16051 +
16052 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
16053 +{
16054 +       return;
16055 +}
16056 +
16057 +#endif /* CONFIG_CFS_HARD_LIMITS */
16058 +#else /* !CONFIG_FAIR_GROUP_SCHED */
16059 +
16060 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
16061 +{
16062 +       return;
16063 +}
16064 +
16065 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
16066 +{
16067 +       return;
16068 +}
16069 +
16070 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16071 +{
16072 +       return 0;
16073 +}
16074 +
16075 +#endif /* CONFIG_FAIR_GROUP_SCHED */
16076 +
16077  #include "sched_stats.h"
16078  #include "sched_idletask.c"
16079  #include "sched_fair.c"
16080 @@ -2980,9 +3179,17 @@ EXPORT_SYMBOL(avenrun);
16081   */
16082  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
16083  {
16084 -       loads[0] = (avenrun[0] + offset) << shift;
16085 -       loads[1] = (avenrun[1] + offset) << shift;
16086 -       loads[2] = (avenrun[2] + offset) << shift;
16087 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
16088 +               struct vx_info *vxi = current_vx_info();
16089 +
16090 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
16091 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
16092 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
16093 +       } else {
16094 +               loads[0] = (avenrun[0] + offset) << shift;
16095 +               loads[1] = (avenrun[1] + offset) << shift;
16096 +               loads[2] = (avenrun[2] + offset) << shift;
16097 +       }
16098  }
16099  
16100  static unsigned long
16101 @@ -5035,16 +5242,19 @@ void account_user_time(struct task_struc
16102                        cputime_t cputime_scaled)
16103  {
16104         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16105 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16106         cputime64_t tmp;
16107 +       int nice = (TASK_NICE(p) > 0);
16108  
16109         /* Add user time to process. */
16110         p->utime = cputime_add(p->utime, cputime);
16111         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
16112 +       vx_account_user(vxi, cputime, nice);
16113         account_group_user_time(p, cputime);
16114  
16115         /* Add user time to cpustat. */
16116         tmp = cputime_to_cputime64(cputime);
16117 -       if (TASK_NICE(p) > 0)
16118 +       if (nice)
16119                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16120         else
16121                 cpustat->user = cputime64_add(cpustat->user, tmp);
16122 @@ -5090,6 +5300,7 @@ void account_system_time(struct task_str
16123                          cputime_t cputime, cputime_t cputime_scaled)
16124  {
16125         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16126 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16127         cputime64_t tmp;
16128  
16129         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
16130 @@ -5100,6 +5311,7 @@ void account_system_time(struct task_str
16131         /* Add system time to process. */
16132         p->stime = cputime_add(p->stime, cputime);
16133         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
16134 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
16135         account_group_system_time(p, cputime);
16136  
16137         /* Add system time to cpustat. */
16138 @@ -6136,7 +6348,7 @@ SYSCALL_DEFINE1(nice, int, increment)
16139                 nice = 19;
16140  
16141         if (increment < 0 && !can_nice(current, nice))
16142 -               return -EPERM;
16143 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16144  
16145         retval = security_task_setnice(current, nice);
16146         if (retval)
16147 @@ -9199,6 +9411,32 @@ static int update_sched_domains(struct n
16148  }
16149  #endif
16150  
16151 +#ifdef CONFIG_SMP
16152 +static void disable_runtime(struct rq *rq)
16153 +{
16154 +       unsigned long flags;
16155 +
16156 +       spin_lock_irqsave(&rq->lock, flags);
16157 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16158 +       disable_runtime_cfs(rq);
16159 +#endif
16160 +       disable_runtime_rt(rq);
16161 +       spin_unlock_irqrestore(&rq->lock, flags);
16162 +}
16163 +
16164 +static void enable_runtime(struct rq *rq)
16165 +{
16166 +       unsigned long flags;
16167 +
16168 +       spin_lock_irqsave(&rq->lock, flags);
16169 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16170 +       enable_runtime_cfs(rq);
16171 +#endif
16172 +       enable_runtime_rt(rq);
16173 +       spin_unlock_irqrestore(&rq->lock, flags);
16174 +}
16175 +#endif
16176 +
16177  static int update_runtime(struct notifier_block *nfb,
16178                                 unsigned long action, void *hcpu)
16179  {
16180 @@ -9331,6 +9569,7 @@ static void init_tg_cfs_entry(struct tas
16181         struct rq *rq = cpu_rq(cpu);
16182         tg->cfs_rq[cpu] = cfs_rq;
16183         init_cfs_rq(cfs_rq, rq);
16184 +       init_cfs_hard_limits(cfs_rq, tg);
16185         cfs_rq->tg = tg;
16186         if (add)
16187                 list_add(&cfs_rq->leaf_cfs_rq_list, &rq->leaf_cfs_rq_list);
16188 @@ -9460,6 +9699,10 @@ void __init sched_init(void)
16189  #endif /* CONFIG_USER_SCHED */
16190  #endif /* CONFIG_RT_GROUP_SCHED */
16191  
16192 +#ifdef CONFIG_FAIR_GROUP_SCHED
16193 +       init_cfs_bandwidth(&init_task_group);
16194 +#endif
16195 +
16196  #ifdef CONFIG_GROUP_SCHED
16197         list_add(&init_task_group.list, &task_groups);
16198         INIT_LIST_HEAD(&init_task_group.children);
16199 @@ -9486,6 +9729,7 @@ void __init sched_init(void)
16200                 init_cfs_rq(&rq->cfs, rq);
16201                 init_rt_rq(&rq->rt, rq);
16202  #ifdef CONFIG_FAIR_GROUP_SCHED
16203 +               init_cfs_hard_limits(&rq->cfs, &init_task_group);
16204                 init_task_group.shares = init_task_group_load;
16205                 INIT_LIST_HEAD(&rq->leaf_cfs_rq_list);
16206  #ifdef CONFIG_CGROUP_SCHED
16207 @@ -9765,6 +10009,7 @@ static void free_fair_sched_group(struct
16208  {
16209         int i;
16210  
16211 +       destroy_cfs_bandwidth(tg);
16212         for_each_possible_cpu(i) {
16213                 if (tg->cfs_rq)
16214                         kfree(tg->cfs_rq[i]);
16215 @@ -9791,6 +10036,7 @@ int alloc_fair_sched_group(struct task_g
16216         if (!tg->se)
16217                 goto err;
16218  
16219 +       init_cfs_bandwidth(tg);
16220         tg->shares = NICE_0_LOAD;
16221  
16222         for_each_possible_cpu(i) {
16223 @@ -10514,6 +10760,100 @@ static u64 cpu_shares_read_u64(struct cg
16224  
16225         return (u64) tg->shares;
16226  }
16227 +
16228 +#ifdef CONFIG_CFS_HARD_LIMITS
16229 +
16230 +static int tg_set_cfs_bandwidth(struct task_group *tg,
16231 +               u64 cfs_period, u64 cfs_runtime)
16232 +{
16233 +       int i;
16234 +
16235 +       spin_lock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16236 +       tg->cfs_bandwidth.cfs_period = ns_to_ktime(cfs_period);
16237 +       tg->cfs_bandwidth.cfs_runtime = cfs_runtime;
16238 +
16239 +       for_each_possible_cpu(i) {
16240 +               struct cfs_rq *cfs_rq = tg->cfs_rq[i];
16241 +
16242 +               cfs_rq_runtime_lock(cfs_rq);
16243 +               cfs_rq->cfs_runtime = cfs_runtime;
16244 +               cfs_rq_runtime_unlock(cfs_rq);
16245 +       }
16246 +
16247 +       start_cfs_bandwidth(tg);
16248 +       spin_unlock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16249 +       return 0;
16250 +}
16251 +
16252 +int tg_set_cfs_runtime(struct task_group *tg, long cfs_runtime_us)
16253 +{
16254 +       u64 cfs_runtime, cfs_period;
16255 +
16256 +       cfs_period = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16257 +       cfs_runtime = (u64)cfs_runtime_us * NSEC_PER_USEC;
16258 +       if (cfs_runtime_us < 0)
16259 +               cfs_runtime = RUNTIME_INF;
16260 +
16261 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16262 +}
16263 +
16264 +long tg_get_cfs_runtime(struct task_group *tg)
16265 +{
16266 +       u64 cfs_runtime_us;
16267 +
16268 +       if (tg->cfs_bandwidth.cfs_runtime == RUNTIME_INF)
16269 +               return -1;
16270 +
16271 +       cfs_runtime_us = tg->cfs_bandwidth.cfs_runtime;
16272 +       do_div(cfs_runtime_us, NSEC_PER_USEC);
16273 +       return cfs_runtime_us;
16274 +}
16275 +
16276 +int tg_set_cfs_period(struct task_group *tg, long cfs_period_us)
16277 +{
16278 +       u64 cfs_runtime, cfs_period;
16279 +
16280 +       cfs_period = (u64)cfs_period_us * NSEC_PER_USEC;
16281 +       cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
16282 +
16283 +       if (cfs_period == 0)
16284 +               return -EINVAL;
16285 +
16286 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16287 +}
16288 +
16289 +long tg_get_cfs_period(struct task_group *tg)
16290 +{
16291 +       u64 cfs_period_us;
16292 +
16293 +       cfs_period_us = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16294 +       do_div(cfs_period_us, NSEC_PER_USEC);
16295 +       return cfs_period_us;
16296 +}
16297 +
16298 +static s64 cpu_cfs_runtime_read_s64(struct cgroup *cgrp, struct cftype *cft)
16299 +{
16300 +       return tg_get_cfs_runtime(cgroup_tg(cgrp));
16301 +}
16302 +
16303 +static int cpu_cfs_runtime_write_s64(struct cgroup *cgrp, struct cftype *cftype,
16304 +                               s64 cfs_runtime_us)
16305 +{
16306 +       return tg_set_cfs_runtime(cgroup_tg(cgrp), cfs_runtime_us);
16307 +}
16308 +
16309 +static u64 cpu_cfs_period_read_u64(struct cgroup *cgrp, struct cftype *cft)
16310 +{
16311 +       return tg_get_cfs_period(cgroup_tg(cgrp));
16312 +}
16313 +
16314 +static int cpu_cfs_period_write_u64(struct cgroup *cgrp, struct cftype *cftype,
16315 +                               u64 cfs_period_us)
16316 +{
16317 +       return tg_set_cfs_period(cgroup_tg(cgrp), cfs_period_us);
16318 +}
16319 +
16320 +#endif /* CONFIG_CFS_HARD_LIMITS */
16321  #endif /* CONFIG_FAIR_GROUP_SCHED */
16322  
16323  #ifdef CONFIG_RT_GROUP_SCHED
16324 @@ -10547,6 +10887,18 @@ static struct cftype cpu_files[] = {
16325                 .read_u64 = cpu_shares_read_u64,
16326                 .write_u64 = cpu_shares_write_u64,
16327         },
16328 +#ifdef CONFIG_CFS_HARD_LIMITS
16329 +       {
16330 +               .name = "cfs_runtime_us",
16331 +               .read_s64 = cpu_cfs_runtime_read_s64,
16332 +               .write_s64 = cpu_cfs_runtime_write_s64,
16333 +       },
16334 +       {
16335 +               .name = "cfs_period_us",
16336 +               .read_u64 = cpu_cfs_period_read_u64,
16337 +               .write_u64 = cpu_cfs_period_write_u64,
16338 +       },
16339 +#endif /* CONFIG_CFS_HARD_LIMITS */
16340  #endif
16341  #ifdef CONFIG_RT_GROUP_SCHED
16342         {
16343 diff -NurpP --minimal linux-2.6.32.10/kernel/sched_debug.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sched_debug.c
16344 --- linux-2.6.32.10/kernel/sched_debug.c        2010-03-18 16:17:38.000000000 +0100
16345 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sched_debug.c        2009-12-29 00:36:26.000000000 +0100
16346 @@ -80,6 +80,11 @@ static void print_cfs_group_stats(struct
16347         PN(se->wait_max);
16348         PN(se->wait_sum);
16349         P(se->wait_count);
16350 +#ifdef CONFIG_CFS_HARD_LIMITS
16351 +       PN(se->throttle_max);
16352 +       PN(se->throttle_sum);
16353 +       P(se->throttle_count);
16354 +#endif
16355  #endif
16356         P(se->load.weight);
16357  #undef PN
16358 @@ -214,6 +219,16 @@ void print_cfs_rq(struct seq_file *m, in
16359  #ifdef CONFIG_SMP
16360         SEQ_printf(m, "  .%-30s: %lu\n", "shares", cfs_rq->shares);
16361  #endif
16362 +#ifdef CONFIG_CFS_HARD_LIMITS
16363 +       spin_lock_irqsave(&rq->lock, flags);
16364 +       SEQ_printf(m, "  .%-30s: %d\n", "cfs_throttled",
16365 +                       cfs_rq->cfs_throttled);
16366 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_time",
16367 +                       SPLIT_NS(cfs_rq->cfs_time));
16368 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_runtime",
16369 +                       SPLIT_NS(cfs_rq->cfs_runtime));
16370 +       spin_unlock_irqrestore(&rq->lock, flags);
16371 +#endif /* CONFIG_CFS_HARD_LIMITS */
16372         print_cfs_group_stats(m, cpu, cfs_rq->tg);
16373  #endif
16374  }
16375 @@ -314,7 +329,7 @@ static int sched_debug_show(struct seq_f
16376         u64 now = ktime_to_ns(ktime_get());
16377         int cpu;
16378  
16379 -       SEQ_printf(m, "Sched Debug Version: v0.09, %s %.*s\n",
16380 +       SEQ_printf(m, "Sched Debug Version: v0.10, %s %.*s\n",
16381                 init_utsname()->release,
16382                 (int)strcspn(init_utsname()->version, " "),
16383                 init_utsname()->version);
16384 diff -NurpP --minimal linux-2.6.32.10/kernel/sched_fair.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sched_fair.c
16385 --- linux-2.6.32.10/kernel/sched_fair.c 2010-03-18 16:17:38.000000000 +0100
16386 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sched_fair.c 2010-02-12 10:59:55.000000000 +0100
16387 @@ -192,7 +192,308 @@ find_matching_se(struct sched_entity **s
16388         }
16389  }
16390  
16391 -#else  /* !CONFIG_FAIR_GROUP_SCHED */
16392 +#ifdef CONFIG_CFS_HARD_LIMITS
16393 +
16394 +static inline void update_stats_throttle_start(struct cfs_rq *cfs_rq,
16395 +                       struct sched_entity *se)
16396 +{
16397 +       schedstat_set(se->throttle_start, rq_of(cfs_rq)->clock);
16398 +}
16399 +
16400 +static inline void update_stats_throttle_end(struct cfs_rq *cfs_rq,
16401 +                       struct sched_entity *se)
16402 +{
16403 +       schedstat_set(se->throttle_max, max(se->throttle_max,
16404 +                       rq_of(cfs_rq)->clock - se->throttle_start));
16405 +       schedstat_set(se->throttle_count, se->throttle_count + 1);
16406 +       schedstat_set(se->throttle_sum, se->throttle_sum +
16407 +                       rq_of(cfs_rq)->clock - se->throttle_start);
16408 +       schedstat_set(se->throttle_start, 0);
16409 +}
16410 +
16411 +static inline
16412 +struct cfs_rq *sched_cfs_period_cfs_rq(struct cfs_bandwidth *cfs_b, int cpu)
16413 +{
16414 +       return container_of(cfs_b, struct task_group,
16415 +                       cfs_bandwidth)->cfs_rq[cpu];
16416 +}
16417 +
16418 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16419 +{
16420 +       return cfs_rq->cfs_throttled;
16421 +}
16422 +
16423 +#ifdef CONFIG_SMP
16424 +/*
16425 + * Ensure this RQ takes back all the runtime it lend to its neighbours.
16426 + */
16427 +static void disable_runtime_cfs(struct rq *rq)
16428 +{
16429 +       struct root_domain *rd = rq->rd;
16430 +       struct cfs_rq *cfs_rq;
16431 +
16432 +       if (unlikely(!scheduler_running))
16433 +               return;
16434 +
16435 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16436 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16437 +               s64 want;
16438 +               int i;
16439 +
16440 +               spin_lock(&cfs_b->cfs_runtime_lock);
16441 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16442 +
16443 +               /*
16444 +                * Either we're all are infinity and nobody needs to borrow,
16445 +                * or we're already disabled and this have nothing to do, or
16446 +                * we have exactly the right amount of runtime to take out.
16447 +                */
16448 +                if (cfs_rq->cfs_runtime == RUNTIME_INF ||
16449 +                               cfs_rq->cfs_runtime == cfs_b->cfs_runtime)
16450 +                       goto balanced;
16451 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16452 +
16453 +               /*
16454 +                * Calculate the difference between what we started out with
16455 +                * and what we current have, that's the amount of runtime
16456 +                * we lend and now have to reclaim.
16457 +                */
16458 +                want = cfs_b->cfs_runtime - cfs_rq->cfs_runtime;
16459 +
16460 +               /*
16461 +                * Greedy reclaim, take back as much as possible.
16462 +                */
16463 +               for_each_cpu(i, rd->span) {
16464 +                       struct cfs_rq *iter = sched_cfs_period_cfs_rq(cfs_b, i);
16465 +                       s64 diff;
16466 +
16467 +                       /*
16468 +                        * Can't reclaim from ourselves or disabled runqueues.
16469 +                        */
16470 +                       if (iter == cfs_rq || iter->cfs_runtime == RUNTIME_INF)
16471 +                               continue;
16472 +
16473 +                       spin_lock(&iter->cfs_runtime_lock);
16474 +                       if (want > 0) {
16475 +                               diff = min_t(s64, iter->cfs_runtime, want);
16476 +                               iter->cfs_runtime -= diff;
16477 +                               want -= diff;
16478 +                       } else {
16479 +                               iter->cfs_runtime -= want;
16480 +                               want -= want;
16481 +                       }
16482 +
16483 +                       spin_unlock(&iter->cfs_runtime_lock);
16484 +                       if (!want)
16485 +                               break;
16486 +               }
16487 +
16488 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16489 +               /*
16490 +                * We cannot be left wanting - that would mean some
16491 +                * runtime leaked out of the system.
16492 +                */
16493 +               BUG_ON(want);
16494 +balanced:
16495 +               /*
16496 +                * Disable all the borrow logic by pretending we have infinite
16497 +                * runtime - in which case borrowing doesn't make sense.
16498 +                */
16499 +                cfs_rq->cfs_runtime = RUNTIME_INF;
16500 +                spin_unlock(&cfs_rq->cfs_runtime_lock);
16501 +                spin_unlock(&cfs_b->cfs_runtime_lock);
16502 +       }
16503 +}
16504 +
16505 +static void enable_runtime_cfs(struct rq *rq)
16506 +{
16507 +       struct cfs_rq *cfs_rq;
16508 +
16509 +       if (unlikely(!scheduler_running))
16510 +               return;
16511 +
16512 +       /*
16513 +        * Reset each runqueue's bandwidth settings
16514 +        */
16515 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16516 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16517 +
16518 +               spin_lock(&cfs_b->cfs_runtime_lock);
16519 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16520 +               cfs_rq->cfs_runtime = cfs_b->cfs_runtime;
16521 +               cfs_rq->cfs_time = 0;
16522 +               cfs_rq->cfs_throttled = 0;
16523 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16524 +               spin_unlock(&cfs_b->cfs_runtime_lock);
16525 +       }
16526 +}
16527 +
16528 +/*
16529 + * Ran out of runtime, check if we can borrow some from others
16530 + * instead of getting throttled right away.
16531 + */
16532 +static void do_cfs_balance_runtime(struct cfs_rq *cfs_rq)
16533 +{
16534 +       struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16535 +       const struct cpumask *span = sched_bw_period_mask();
16536 +       int i, weight;
16537 +       u64 cfs_period;
16538 +
16539 +       weight = cpumask_weight(span);
16540 +       spin_lock(&cfs_b->cfs_runtime_lock);
16541 +       cfs_period = ktime_to_ns(cfs_b->cfs_period);
16542 +
16543 +       for_each_cpu(i, span) {
16544 +               struct cfs_rq *borrow_cfs_rq =
16545 +                               sched_cfs_period_cfs_rq(cfs_b, i);
16546 +               s64 diff;
16547 +
16548 +               if (borrow_cfs_rq == cfs_rq)
16549 +                       continue;
16550 +
16551 +               cfs_rq_runtime_lock(borrow_cfs_rq);
16552 +               if (borrow_cfs_rq->cfs_runtime == RUNTIME_INF) {
16553 +                       cfs_rq_runtime_unlock(borrow_cfs_rq);
16554 +                       continue;
16555 +               }
16556 +
16557 +               diff = borrow_cfs_rq->cfs_runtime - borrow_cfs_rq->cfs_time;
16558 +               if (diff > 0) {
16559 +                       diff = div_u64((u64)diff, weight);
16560 +                       if (cfs_rq->cfs_runtime + diff > cfs_period)
16561 +                               diff = cfs_period - cfs_rq->cfs_runtime;
16562 +                       borrow_cfs_rq->cfs_runtime -= diff;
16563 +                       cfs_rq->cfs_runtime += diff;
16564 +                       if (cfs_rq->cfs_runtime == cfs_period) {
16565 +                               cfs_rq_runtime_unlock(borrow_cfs_rq);
16566 +                               break;
16567 +                       }
16568 +               }
16569 +               cfs_rq_runtime_unlock(borrow_cfs_rq);
16570 +       }
16571 +       spin_unlock(&cfs_b->cfs_runtime_lock);
16572 +}
16573 +
16574 +/*
16575 + * Called with rq->runtime_lock held.
16576 + */
16577 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16578 +{
16579 +       cfs_rq_runtime_unlock(cfs_rq);
16580 +       do_cfs_balance_runtime(cfs_rq);
16581 +       cfs_rq_runtime_lock(cfs_rq);
16582 +}
16583 +
16584 +#else /* !CONFIG_SMP */
16585 +
16586 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16587 +{
16588 +       return;
16589 +}
16590 +#endif /* CONFIG_SMP */
16591 +
16592 +/*
16593 + * Check if group entity exceeded its runtime. If so, mark the cfs_rq as
16594 + * throttled mark the current task for reschedling.
16595 + */
16596 +static void sched_cfs_runtime_exceeded(struct sched_entity *se,
16597 +       struct task_struct *tsk_curr, unsigned long delta_exec)
16598 +{
16599 +       struct cfs_rq *cfs_rq;
16600 +
16601 +       cfs_rq = group_cfs_rq(se);
16602 +
16603 +       if (cfs_rq->cfs_runtime == RUNTIME_INF)
16604 +               return;
16605 +
16606 +       cfs_rq->cfs_time += delta_exec;
16607 +
16608 +       if (cfs_rq_throttled(cfs_rq))
16609 +               return;
16610 +
16611 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime)
16612 +               cfs_balance_runtime(cfs_rq);
16613 +
16614 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime) {
16615 +               cfs_rq->cfs_throttled = 1;
16616 +               update_stats_throttle_start(cfs_rq, se);
16617 +               resched_task(tsk_curr);
16618 +       }
16619 +}
16620 +
16621 +static inline void update_curr_group(struct sched_entity *curr,
16622 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16623 +{
16624 +       sched_cfs_runtime_exceeded(curr, tsk_curr, delta_exec);
16625 +}
16626 +
16627 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16628 +               struct sched_entity *se, int wakeup);
16629 +
16630 +static void enqueue_throttled_entity(struct rq *rq, struct sched_entity *se)
16631 +{
16632 +       for_each_sched_entity(se) {
16633 +               struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16634 +
16635 +               if (se->on_rq || cfs_rq_throttled(gcfs_rq) ||
16636 +                               !gcfs_rq->nr_running)
16637 +                       break;
16638 +               enqueue_entity_locked(cfs_rq_of(se), se, 0);
16639 +       }
16640 +}
16641 +
16642 +/*
16643 + * Refresh runtimes of all cfs_rqs in this group, i,e.,
16644 + * refresh runtimes of the representative cfs_rq of this
16645 + * tg on all cpus. Enqueue any throttled entity back.
16646 + */
16647 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b)
16648 +{
16649 +       int i;
16650 +       const struct cpumask *span = sched_bw_period_mask();
16651 +       unsigned long flags;
16652 +
16653 +       for_each_cpu(i, span) {
16654 +               struct rq *rq = cpu_rq(i);
16655 +               struct cfs_rq *cfs_rq = sched_cfs_period_cfs_rq(cfs_b, i);
16656 +               struct sched_entity *se = cfs_rq->tg->se[i];
16657 +
16658 +               spin_lock_irqsave(&rq->lock, flags);
16659 +               cfs_rq_runtime_lock(cfs_rq);
16660 +               cfs_rq->cfs_time = 0;
16661 +               if (cfs_rq_throttled(cfs_rq)) {
16662 +                       update_rq_clock(rq);
16663 +                       update_stats_throttle_end(cfs_rq, se);
16664 +                       cfs_rq->cfs_throttled = 0;
16665 +                       enqueue_throttled_entity(rq, se);
16666 +               }
16667 +               cfs_rq_runtime_unlock(cfs_rq);
16668 +               spin_unlock_irqrestore(&rq->lock, flags);
16669 +       }
16670 +}
16671 +
16672 +#else
16673 +
16674 +static inline void update_curr_group(struct sched_entity *curr,
16675 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16676 +{
16677 +       return;
16678 +}
16679 +
16680 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16681 +{
16682 +       return 0;
16683 +}
16684 +
16685 +#endif /* CONFIG_CFS_HARD_LIMITS */
16686 +
16687 +#else  /* CONFIG_FAIR_GROUP_SCHED */
16688 +
16689 +static inline void update_curr_group(struct sched_entity *curr,
16690 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16691 +{
16692 +       return;
16693 +}
16694  
16695  static inline struct task_struct *task_of(struct sched_entity *se)
16696  {
16697 @@ -254,7 +555,6 @@ find_matching_se(struct sched_entity **s
16698  
16699  #endif /* CONFIG_FAIR_GROUP_SCHED */
16700  
16701 -
16702  /**************************************************************
16703   * Scheduling class tree data structure manipulation methods:
16704   */
16705 @@ -492,14 +792,25 @@ __update_curr(struct cfs_rq *cfs_rq, str
16706         update_min_vruntime(cfs_rq);
16707  }
16708  
16709 -static void update_curr(struct cfs_rq *cfs_rq)
16710 +static void update_curr_task(struct sched_entity *curr,
16711 +               unsigned long delta_exec)
16712 +{
16713 +       struct task_struct *curtask = task_of(curr);
16714 +
16715 +       trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16716 +       cpuacct_charge(curtask, delta_exec);
16717 +       account_group_exec_runtime(curtask, delta_exec);
16718 +}
16719 +
16720 +static int update_curr_common(struct cfs_rq *cfs_rq, unsigned long *delta)
16721  {
16722         struct sched_entity *curr = cfs_rq->curr;
16723 -       u64 now = rq_of(cfs_rq)->clock;
16724 +       struct rq *rq = rq_of(cfs_rq);
16725 +       u64 now = rq->clock;
16726         unsigned long delta_exec;
16727  
16728         if (unlikely(!curr))
16729 -               return;
16730 +               return 1;
16731  
16732         /*
16733          * Get the amount of time the current task was running
16734 @@ -508,17 +819,29 @@ static void update_curr(struct cfs_rq *c
16735          */
16736         delta_exec = (unsigned long)(now - curr->exec_start);
16737         if (!delta_exec)
16738 -               return;
16739 +               return 1;
16740  
16741         __update_curr(cfs_rq, curr, delta_exec);
16742         curr->exec_start = now;
16743 +       *delta = delta_exec;
16744 +       return 0;
16745 +}
16746  
16747 -       if (entity_is_task(curr)) {
16748 -               struct task_struct *curtask = task_of(curr);
16749 +static void update_curr(struct cfs_rq *cfs_rq)
16750 +{
16751 +       struct sched_entity *curr = cfs_rq->curr;
16752 +       struct rq *rq = rq_of(cfs_rq);
16753 +       unsigned long delta_exec;
16754  
16755 -               trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16756 -               cpuacct_charge(curtask, delta_exec);
16757 -               account_group_exec_runtime(curtask, delta_exec);
16758 +       if (update_curr_common(cfs_rq, &delta_exec))
16759 +               return ;
16760 +
16761 +       if (entity_is_task(curr))
16762 +               update_curr_task(curr, delta_exec);
16763 +       else {
16764 +               cfs_rq_runtime_lock(group_cfs_rq(curr));
16765 +               update_curr_group(curr, delta_exec, rq->curr);
16766 +               cfs_rq_runtime_unlock(group_cfs_rq(curr));
16767         }
16768  }
16769  
16770 @@ -743,13 +1066,9 @@ place_entity(struct cfs_rq *cfs_rq, stru
16771         se->vruntime = vruntime;
16772  }
16773  
16774 -static void
16775 -enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int wakeup)
16776 +static void enqueue_entity_common(struct cfs_rq *cfs_rq,
16777 +               struct sched_entity *se, int wakeup)
16778  {
16779 -       /*
16780 -        * Update run-time statistics of the 'current'.
16781 -        */
16782 -       update_curr(cfs_rq);
16783         account_entity_enqueue(cfs_rq, se);
16784  
16785         if (wakeup) {
16786 @@ -761,6 +1080,29 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16787         check_spread(cfs_rq, se);
16788         if (se != cfs_rq->curr)
16789                 __enqueue_entity(cfs_rq, se);
16790 +
16791 +       if (entity_is_task(se))
16792 +               vx_activate_task(task_of(se));
16793 +}
16794 +
16795 +static void enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
16796 +               int wakeup)
16797 +{
16798 +       /*
16799 +        * Update run-time statistics of the 'current'.
16800 +        */
16801 +       update_curr(cfs_rq);
16802 +       enqueue_entity_common(cfs_rq, se, wakeup);
16803 +}
16804 +
16805 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16806 +               struct sched_entity *se, int wakeup)
16807 +{
16808 +       /*
16809 +        * Update run-time statistics of the 'current'.
16810 +        */
16811 +       // update_curr_locked(cfs_rq);
16812 +       enqueue_entity_common(cfs_rq, se, wakeup);
16813  }
16814  
16815  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
16816 @@ -804,6 +1146,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16817  
16818         if (se != cfs_rq->curr)
16819                 __dequeue_entity(cfs_rq, se);
16820 +       if (entity_is_task(se))
16821 +               vx_deactivate_task(task_of(se));
16822         account_entity_dequeue(cfs_rq, se);
16823         update_min_vruntime(cfs_rq);
16824  }
16825 @@ -900,6 +1244,32 @@ static struct sched_entity *pick_next_en
16826         return se;
16827  }
16828  
16829 +/*
16830 + * Called from put_prev_entity()
16831 + * If a group entity (@se) is found to be throttled, it will not be put back
16832 + * on @cfs_rq, which is equivalent to dequeing it.
16833 + */
16834 +static int dequeue_throttled_entity(struct cfs_rq *cfs_rq,
16835 +               struct sched_entity *se)
16836 +{
16837 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16838 +
16839 +       if (entity_is_task(se))
16840 +               return 0;
16841 +
16842 +       cfs_rq_runtime_lock(gcfs_rq);
16843 +       if (!cfs_rq_throttled(gcfs_rq) && gcfs_rq->nr_running) {
16844 +               cfs_rq_runtime_unlock(gcfs_rq);
16845 +               return 0;
16846 +       }
16847 +
16848 +       __clear_buddies(cfs_rq, se);
16849 +       account_entity_dequeue(cfs_rq, se);
16850 +       cfs_rq->curr = NULL;
16851 +       cfs_rq_runtime_unlock(gcfs_rq);
16852 +       return 1;
16853 +}
16854 +
16855  static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
16856  {
16857         /*
16858 @@ -911,6 +1281,8 @@ static void put_prev_entity(struct cfs_r
16859  
16860         check_spread(cfs_rq, prev);
16861         if (prev->on_rq) {
16862 +               if (dequeue_throttled_entity(cfs_rq, prev))
16863 +                       return;
16864                 update_stats_wait_start(cfs_rq, prev);
16865                 /* Put 'current' back into the tree. */
16866                 __enqueue_entity(cfs_rq, prev);
16867 @@ -1007,10 +1379,28 @@ static inline void hrtick_update(struct 
16868  }
16869  #endif
16870  
16871 +static int enqueue_group_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
16872 +                int wakeup)
16873 +{
16874 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16875 +       int ret = 0;
16876 +
16877 +       cfs_rq_runtime_lock(gcfs_rq);
16878 +       if (cfs_rq_throttled(gcfs_rq)) {
16879 +               ret = 1;
16880 +               goto out;
16881 +       }
16882 +       enqueue_entity_locked(cfs_rq, se, wakeup);
16883 +out:
16884 +       cfs_rq_runtime_unlock(gcfs_rq);
16885 +       return ret;
16886 +}
16887 +
16888  /*
16889   * The enqueue_task method is called before nr_running is
16890   * increased. Here we update the fair scheduling stats and
16891   * then put the task into the rbtree:
16892 + * Don't enqueue a throttled entity further into the hierarchy.
16893   */
16894  static void enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup)
16895  {
16896 @@ -1020,11 +1410,15 @@ static void enqueue_task_fair(struct rq 
16897         for_each_sched_entity(se) {
16898                 if (se->on_rq)
16899                         break;
16900 +
16901                 cfs_rq = cfs_rq_of(se);
16902 -               enqueue_entity(cfs_rq, se, wakeup);
16903 +               if (entity_is_task(se))
16904 +                       enqueue_entity(cfs_rq, se, wakeup);
16905 +               else
16906 +                       if (enqueue_group_entity(cfs_rq, se, wakeup))
16907 +                               break;
16908                 wakeup = 1;
16909         }
16910 -
16911         hrtick_update(rq);
16912  }
16913  
16914 @@ -1044,6 +1438,17 @@ static void dequeue_task_fair(struct rq 
16915                 /* Don't dequeue parent if it has other entities besides us */
16916                 if (cfs_rq->load.weight)
16917                         break;
16918 +
16919 +               /*
16920 +                * If this cfs_rq is throttled, then it is already
16921 +                * dequeued.
16922 +                */
16923 +               cfs_rq_runtime_lock(cfs_rq);
16924 +               if (cfs_rq_throttled(cfs_rq)) {
16925 +                       cfs_rq_runtime_unlock(cfs_rq);
16926 +                       break;
16927 +               }
16928 +               cfs_rq_runtime_unlock(cfs_rq);
16929                 sleep = 1;
16930         }
16931  
16932 @@ -1821,9 +2226,10 @@ load_balance_fair(struct rq *this_rq, in
16933                 u64 rem_load, moved_load;
16934  
16935                 /*
16936 -                * empty group
16937 +                * empty group or throttled group
16938                  */
16939 -               if (!busiest_cfs_rq->task_weight)
16940 +               if (!busiest_cfs_rq->task_weight ||
16941 +                               cfs_rq_throttled(busiest_cfs_rq))
16942                         continue;
16943  
16944                 rem_load = (u64)rem_load_move * busiest_weight;
16945 @@ -1872,6 +2278,12 @@ move_one_task_fair(struct rq *this_rq, i
16946  
16947         for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
16948                 /*
16949 +                * Don't move task from a throttled cfs_rq
16950 +                */
16951 +               if (cfs_rq_throttled(busy_cfs_rq))
16952 +                       continue;
16953 +
16954 +               /*
16955                  * pass busy_cfs_rq argument into
16956                  * load_balance_[start|next]_fair iterators
16957                  */
16958 diff -NurpP --minimal linux-2.6.32.10/kernel/sched_rt.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sched_rt.c
16959 --- linux-2.6.32.10/kernel/sched_rt.c   2009-12-03 20:02:58.000000000 +0100
16960 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sched_rt.c   2009-12-03 20:04:56.000000000 +0100
16961 @@ -235,18 +235,6 @@ static int rt_se_boosted(struct sched_rt
16962         return p->prio != p->normal_prio;
16963  }
16964  
16965 -#ifdef CONFIG_SMP
16966 -static inline const struct cpumask *sched_rt_period_mask(void)
16967 -{
16968 -       return cpu_rq(smp_processor_id())->rd->span;
16969 -}
16970 -#else
16971 -static inline const struct cpumask *sched_rt_period_mask(void)
16972 -{
16973 -       return cpu_online_mask;
16974 -}
16975 -#endif
16976 -
16977  static inline
16978  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16979  {
16980 @@ -296,11 +284,6 @@ static inline int rt_rq_throttled(struct
16981         return rt_rq->rt_throttled;
16982  }
16983  
16984 -static inline const struct cpumask *sched_rt_period_mask(void)
16985 -{
16986 -       return cpu_online_mask;
16987 -}
16988 -
16989  static inline
16990  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16991  {
16992 @@ -373,7 +356,7 @@ next:
16993  /*
16994   * Ensure this RQ takes back all the runtime it lend to its neighbours.
16995   */
16996 -static void __disable_runtime(struct rq *rq)
16997 +static void disable_runtime_rt(struct rq *rq)
16998  {
16999         struct root_domain *rd = rq->rd;
17000         struct rt_rq *rt_rq;
17001 @@ -450,16 +433,7 @@ balanced:
17002         }
17003  }
17004  
17005 -static void disable_runtime(struct rq *rq)
17006 -{
17007 -       unsigned long flags;
17008 -
17009 -       spin_lock_irqsave(&rq->lock, flags);
17010 -       __disable_runtime(rq);
17011 -       spin_unlock_irqrestore(&rq->lock, flags);
17012 -}
17013 -
17014 -static void __enable_runtime(struct rq *rq)
17015 +static void enable_runtime_rt(struct rq *rq)
17016  {
17017         struct rt_rq *rt_rq;
17018  
17019 @@ -482,15 +456,6 @@ static void __enable_runtime(struct rq *
17020         }
17021  }
17022  
17023 -static void enable_runtime(struct rq *rq)
17024 -{
17025 -       unsigned long flags;
17026 -
17027 -       spin_lock_irqsave(&rq->lock, flags);
17028 -       __enable_runtime(rq);
17029 -       spin_unlock_irqrestore(&rq->lock, flags);
17030 -}
17031 -
17032  static int balance_runtime(struct rt_rq *rt_rq)
17033  {
17034         int more = 0;
17035 @@ -518,7 +483,7 @@ static int do_sched_rt_period_timer(stru
17036         if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
17037                 return 1;
17038  
17039 -       span = sched_rt_period_mask();
17040 +       span = sched_bw_period_mask();
17041         for_each_cpu(i, span) {
17042                 int enqueue = 0;
17043                 struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
17044 @@ -1564,7 +1529,7 @@ static void rq_online_rt(struct rq *rq)
17045         if (rq->rt.overloaded)
17046                 rt_set_overload(rq);
17047  
17048 -       __enable_runtime(rq);
17049 +       enable_runtime_rt(rq);
17050  
17051         cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
17052  }
17053 @@ -1575,7 +1540,7 @@ static void rq_offline_rt(struct rq *rq)
17054         if (rq->rt.overloaded)
17055                 rt_clear_overload(rq);
17056  
17057 -       __disable_runtime(rq);
17058 +       disable_runtime_rt(rq);
17059  
17060         cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
17061  }
17062 diff -NurpP --minimal linux-2.6.32.10/kernel/signal.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/signal.c
17063 --- linux-2.6.32.10/kernel/signal.c     2010-03-18 16:17:38.000000000 +0100
17064 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/signal.c     2010-03-13 22:09:19.000000000 +0100
17065 @@ -27,6 +27,8 @@
17066  #include <linux/freezer.h>
17067  #include <linux/pid_namespace.h>
17068  #include <linux/nsproxy.h>
17069 +#include <linux/vs_context.h>
17070 +#include <linux/vs_pid.h>
17071  #include <trace/events/sched.h>
17072  
17073  #include <asm/param.h>
17074 @@ -598,6 +600,14 @@ static int check_kill_permission(int sig
17075         if (!valid_signal(sig))
17076                 return -EINVAL;
17077  
17078 +       if ((info != SEND_SIG_NOINFO) &&
17079 +               (is_si_special(info) || !SI_FROMUSER(info)))
17080 +               goto skip;
17081 +
17082 +       vxdprintk(VXD_CBIT(misc, 7),
17083 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
17084 +               sig, info, t, vx_task_xid(t), t->pid);
17085 +
17086         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
17087                 return 0;
17088  
17089 @@ -625,6 +635,20 @@ static int check_kill_permission(int sig
17090                 }
17091         }
17092  
17093 +       error = -EPERM;
17094 +       if (t->pid == 1 && current->xid)
17095 +               return error;
17096 +
17097 +       error = -ESRCH;
17098 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
17099 +                 loops, maybe ENOENT or EACCES? */
17100 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
17101 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
17102 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
17103 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
17104 +               return error;
17105 +       }
17106 +skip:
17107         return security_task_kill(t, info, sig, 0);
17108  }
17109  
17110 @@ -1113,7 +1137,7 @@ int kill_pid_info(int sig, struct siginf
17111         rcu_read_lock();
17112  retry:
17113         p = pid_task(pid, PIDTYPE_PID);
17114 -       if (p) {
17115 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
17116                 error = group_send_sig_info(sig, info, p);
17117                 if (unlikely(error == -ESRCH))
17118                         /*
17119 @@ -1152,7 +1176,7 @@ int kill_pid_info_as_uid(int sig, struct
17120  
17121         read_lock(&tasklist_lock);
17122         p = pid_task(pid, PIDTYPE_PID);
17123 -       if (!p) {
17124 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
17125                 ret = -ESRCH;
17126                 goto out_unlock;
17127         }
17128 @@ -1206,8 +1230,10 @@ static int kill_something_info(int sig, 
17129                 struct task_struct * p;
17130  
17131                 for_each_process(p) {
17132 -                       if (task_pid_vnr(p) > 1 &&
17133 -                                       !same_thread_group(p, current)) {
17134 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
17135 +                               task_pid_vnr(p) > 1 &&
17136 +                               !same_thread_group(p, current) &&
17137 +                               !vx_current_initpid(p->pid)) {
17138                                 int err = group_send_sig_info(sig, info, p);
17139                                 ++count;
17140                                 if (err != -EPERM)
17141 @@ -1872,6 +1898,11 @@ relock:
17142                                 !sig_kernel_only(signr))
17143                         continue;
17144  
17145 +               /* virtual init is protected against user signals */
17146 +               if ((info->si_code == SI_USER) &&
17147 +                       vx_current_initpid(current->pid))
17148 +                       continue;
17149 +
17150                 if (sig_kernel_stop(signr)) {
17151                         /*
17152                          * The default action is to stop all threads in
17153 diff -NurpP --minimal linux-2.6.32.10/kernel/softirq.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/softirq.c
17154 --- linux-2.6.32.10/kernel/softirq.c    2009-12-03 20:02:58.000000000 +0100
17155 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/softirq.c    2009-12-03 20:04:56.000000000 +0100
17156 @@ -24,6 +24,7 @@
17157  #include <linux/ftrace.h>
17158  #include <linux/smp.h>
17159  #include <linux/tick.h>
17160 +#include <linux/vs_context.h>
17161  
17162  #define CREATE_TRACE_POINTS
17163  #include <trace/events/irq.h>
17164 diff -NurpP --minimal linux-2.6.32.10/kernel/sys.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sys.c
17165 --- linux-2.6.32.10/kernel/sys.c        2009-12-03 20:02:58.000000000 +0100
17166 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sys.c        2009-12-03 20:04:56.000000000 +0100
17167 @@ -41,6 +41,7 @@
17168  #include <linux/syscalls.h>
17169  #include <linux/kprobes.h>
17170  #include <linux/user_namespace.h>
17171 +#include <linux/vs_pid.h>
17172  
17173  #include <asm/uaccess.h>
17174  #include <asm/io.h>
17175 @@ -130,7 +131,10 @@ static int set_one_prio(struct task_stru
17176                 goto out;
17177         }
17178         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17179 -               error = -EACCES;
17180 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17181 +                       error = 0;
17182 +               else
17183 +                       error = -EACCES;
17184                 goto out;
17185         }
17186         no_nice = security_task_setnice(p, niceval);
17187 @@ -179,6 +183,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
17188                         else
17189                                 pgrp = task_pgrp(current);
17190                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17191 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17192 +                                       continue;
17193                                 error = set_one_prio(p, niceval, error);
17194                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
17195                         break;
17196 @@ -240,6 +246,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
17197                         else
17198                                 pgrp = task_pgrp(current);
17199                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17200 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17201 +                                       continue;
17202                                 niceval = 20 - task_nice(p);
17203                                 if (niceval > retval)
17204                                         retval = niceval;
17205 @@ -349,6 +357,9 @@ void kernel_power_off(void)
17206         machine_power_off();
17207  }
17208  EXPORT_SYMBOL_GPL(kernel_power_off);
17209 +
17210 +long vs_reboot(unsigned int, void __user *);
17211 +
17212  /*
17213   * Reboot system call: for obvious reasons only root may call it,
17214   * and even root needs to set up some magic numbers in the registers
17215 @@ -381,6 +392,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
17216         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17217                 cmd = LINUX_REBOOT_CMD_HALT;
17218  
17219 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17220 +               return vs_reboot(cmd, arg);
17221 +
17222         lock_kernel();
17223         switch (cmd) {
17224         case LINUX_REBOOT_CMD_RESTART:
17225 @@ -1133,7 +1147,7 @@ SYSCALL_DEFINE2(sethostname, char __user
17226         int errno;
17227         char tmp[__NEW_UTS_LEN];
17228  
17229 -       if (!capable(CAP_SYS_ADMIN))
17230 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17231                 return -EPERM;
17232         if (len < 0 || len > __NEW_UTS_LEN)
17233                 return -EINVAL;
17234 @@ -1182,7 +1196,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
17235         int errno;
17236         char tmp[__NEW_UTS_LEN];
17237  
17238 -       if (!capable(CAP_SYS_ADMIN))
17239 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17240                 return -EPERM;
17241         if (len < 0 || len > __NEW_UTS_LEN)
17242                 return -EINVAL;
17243 @@ -1251,7 +1265,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
17244                 return -EINVAL;
17245         old_rlim = current->signal->rlim + resource;
17246         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
17247 -           !capable(CAP_SYS_RESOURCE))
17248 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17249                 return -EPERM;
17250         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
17251                 return -EPERM;
17252 diff -NurpP --minimal linux-2.6.32.10/kernel/sysctl.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sysctl.c
17253 --- linux-2.6.32.10/kernel/sysctl.c     2010-03-18 16:17:38.000000000 +0100
17254 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sysctl.c     2010-01-20 04:21:33.000000000 +0100
17255 @@ -124,6 +124,7 @@ static int ngroups_max = NGROUPS_MAX;
17256  extern char modprobe_path[];
17257  extern int modules_disabled;
17258  #endif
17259 +extern char vshelper_path[];
17260  #ifdef CONFIG_CHR_DEV_SG
17261  extern int sg_big_buff;
17262  #endif
17263 @@ -593,6 +594,15 @@ static struct ctl_table kern_table[] = {
17264                 .strategy       = &sysctl_string,
17265         },
17266  #endif
17267 +       {
17268 +               .ctl_name       = KERN_VSHELPER,
17269 +               .procname       = "vshelper",
17270 +               .data           = &vshelper_path,
17271 +               .maxlen         = 256,
17272 +               .mode           = 0644,
17273 +               .proc_handler   = &proc_dostring,
17274 +               .strategy       = &sysctl_string,
17275 +       },
17276  #ifdef CONFIG_CHR_DEV_SG
17277         {
17278                 .ctl_name       = KERN_SG_BIG_BUFF,
17279 diff -NurpP --minimal linux-2.6.32.10/kernel/sysctl_check.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sysctl_check.c
17280 --- linux-2.6.32.10/kernel/sysctl_check.c       2010-03-18 16:17:38.000000000 +0100
17281 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/sysctl_check.c       2010-02-12 10:59:55.000000000 +0100
17282 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
17283  
17284         { KERN_PANIC,                   "panic" },
17285         { KERN_REALROOTDEV,             "real-root-dev" },
17286 +       { KERN_VSHELPER,                "vshelper", },
17287  
17288         { KERN_SPARC_REBOOT,            "reboot-cmd" },
17289         { KERN_CTLALTDEL,               "ctrl-alt-del" },
17290 @@ -1218,6 +1219,22 @@ static const struct trans_ctl_table tran
17291         {}
17292  };
17293  
17294 +static struct trans_ctl_table trans_vserver_table[] = {
17295 +       { 1,    "debug_switch" },
17296 +       { 2,    "debug_xid" },
17297 +       { 3,    "debug_nid" },
17298 +       { 4,    "debug_tag" },
17299 +       { 5,    "debug_net" },
17300 +       { 6,    "debug_limit" },
17301 +       { 7,    "debug_cres" },
17302 +       { 8,    "debug_dlim" },
17303 +       { 9,    "debug_quota" },
17304 +       { 10,   "debug_cvirt" },
17305 +       { 11,   "debug_space" },
17306 +       { 12,   "debug_misc" },
17307 +       {}
17308 +};
17309 +
17310  static const struct trans_ctl_table trans_root_table[] = {
17311         { CTL_KERN,     "kernel",       trans_kern_table },
17312         { CTL_VM,       "vm",           trans_vm_table },
17313 @@ -1234,6 +1251,7 @@ static const struct trans_ctl_table tran
17314         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
17315         { CTL_PM,       "pm",           trans_pm_table },
17316         { CTL_FRV,      "frv",          trans_frv_table },
17317 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
17318         {}
17319  };
17320  
17321 diff -NurpP --minimal linux-2.6.32.10/kernel/time.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/time.c
17322 --- linux-2.6.32.10/kernel/time.c       2009-12-03 20:02:58.000000000 +0100
17323 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/time.c       2009-12-03 20:04:56.000000000 +0100
17324 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
17325  SYSCALL_DEFINE1(time, time_t __user *, tloc)
17326  {
17327         time_t i = get_seconds();
17328 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
17329  
17330         if (tloc) {
17331                 if (put_user(i,tloc))
17332 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
17333         if (err)
17334                 return err;
17335  
17336 -       do_settimeofday(&tv);
17337 +       vx_settimeofday(&tv);
17338         return 0;
17339  }
17340  
17341 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
17342  {
17343         if (likely(tv != NULL)) {
17344                 struct timeval ktv;
17345 -               do_gettimeofday(&ktv);
17346 +               vx_gettimeofday(&ktv);
17347                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
17348                         return -EFAULT;
17349         }
17350 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
17351                 /* SMP safe, again the code in arch/foo/time.c should
17352                  * globally block out interrupts when it runs.
17353                  */
17354 -               return do_settimeofday(tv);
17355 +               return vx_settimeofday(tv);
17356         }
17357         return 0;
17358  }
17359 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
17360  {
17361         struct timeval x;
17362  
17363 -       do_gettimeofday(&x);
17364 +       vx_gettimeofday(&x);
17365         tv->tv_sec = x.tv_sec;
17366         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17367  }
17368 diff -NurpP --minimal linux-2.6.32.10/kernel/timer.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/timer.c
17369 --- linux-2.6.32.10/kernel/timer.c      2009-12-03 20:02:58.000000000 +0100
17370 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/timer.c      2009-12-03 20:04:56.000000000 +0100
17371 @@ -39,6 +39,10 @@
17372  #include <linux/kallsyms.h>
17373  #include <linux/perf_event.h>
17374  #include <linux/sched.h>
17375 +#include <linux/vs_base.h>
17376 +#include <linux/vs_cvirt.h>
17377 +#include <linux/vs_pid.h>
17378 +#include <linux/vserver/sched.h>
17379  
17380  #include <asm/uaccess.h>
17381  #include <asm/unistd.h>
17382 @@ -1255,12 +1259,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17383  
17384  #endif
17385  
17386 -#ifndef __alpha__
17387 -
17388 -/*
17389 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17390 - * should be moved into arch/i386 instead?
17391 - */
17392  
17393  /**
17394   * sys_getpid - return the thread group id of the current process
17395 @@ -1289,10 +1287,23 @@ SYSCALL_DEFINE0(getppid)
17396         rcu_read_lock();
17397         pid = task_tgid_vnr(current->real_parent);
17398         rcu_read_unlock();
17399 +       return vx_map_pid(pid);
17400 +}
17401  
17402 -       return pid;
17403 +#ifdef __alpha__
17404 +
17405 +/*
17406 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17407 + */
17408 +
17409 +asmlinkage long do_getxpid(long *ppid)
17410 +{
17411 +       *ppid = sys_getppid();
17412 +       return sys_getpid();
17413  }
17414  
17415 +#else /* _alpha_ */
17416 +
17417  SYSCALL_DEFINE0(getuid)
17418  {
17419         /* Only we change this so SMP safe */
17420 diff -NurpP --minimal linux-2.6.32.10/kernel/user.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/user.c
17421 --- linux-2.6.32.10/kernel/user.c       2009-12-03 20:02:58.000000000 +0100
17422 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/user.c       2009-12-03 20:04:56.000000000 +0100
17423 @@ -251,10 +251,10 @@ static struct kobj_type uids_ktype = {
17424   *
17425   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
17426   */
17427 -static int uids_user_create(struct user_struct *up)
17428 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
17429  {
17430         struct kobject *kobj = &up->kobj;
17431 -       int error;
17432 +       int error = 0;
17433  
17434         memset(kobj, 0, sizeof(struct kobject));
17435         if (up->user_ns != &init_user_ns)
17436 @@ -282,7 +282,7 @@ int __init uids_sysfs_init(void)
17437         if (!uids_kset)
17438                 return -ENOMEM;
17439  
17440 -       return uids_user_create(&root_user);
17441 +       return uids_user_create(NULL, &root_user);
17442  }
17443  
17444  /* delayed work function to remove sysfs directory for a user and free up
17445 @@ -353,7 +353,8 @@ static struct user_struct *uid_hash_find
17446  }
17447  
17448  int uids_sysfs_init(void) { return 0; }
17449 -static inline int uids_user_create(struct user_struct *up) { return 0; }
17450 +static inline int uids_user_create(struct user_namespace *ns,
17451 +       struct user_struct *up) { return 0; }
17452  static inline void uids_mutex_lock(void) { }
17453  static inline void uids_mutex_unlock(void) { }
17454  
17455 @@ -450,7 +451,7 @@ struct user_struct *alloc_uid(struct use
17456  
17457                 new->user_ns = get_user_ns(ns);
17458  
17459 -               if (uids_user_create(new))
17460 +               if (uids_user_create(ns, new))
17461                         goto out_destoy_sched;
17462  
17463                 /*
17464 diff -NurpP --minimal linux-2.6.32.10/kernel/user_namespace.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/user_namespace.c
17465 --- linux-2.6.32.10/kernel/user_namespace.c     2009-03-24 14:22:45.000000000 +0100
17466 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/user_namespace.c     2009-12-03 20:04:56.000000000 +0100
17467 @@ -10,6 +10,7 @@
17468  #include <linux/slab.h>
17469  #include <linux/user_namespace.h>
17470  #include <linux/cred.h>
17471 +#include <linux/vserver/global.h>
17472  
17473  /*
17474   * Create a new user namespace, deriving the creator from the user in the
17475 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
17476                 return -ENOMEM;
17477  
17478         kref_init(&ns->kref);
17479 +       atomic_inc(&vs_global_user_ns);
17480  
17481         for (n = 0; n < UIDHASH_SZ; ++n)
17482                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17483 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
17484         struct user_namespace *ns =
17485                 container_of(kref, struct user_namespace, kref);
17486  
17487 +       /* FIXME: maybe move into destroyer? */
17488 +       atomic_dec(&vs_global_user_ns);
17489         INIT_WORK(&ns->destroyer, free_user_ns_work);
17490         schedule_work(&ns->destroyer);
17491  }
17492 diff -NurpP --minimal linux-2.6.32.10/kernel/utsname.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/utsname.c
17493 --- linux-2.6.32.10/kernel/utsname.c    2009-09-10 15:26:28.000000000 +0200
17494 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/utsname.c    2009-12-03 20:04:56.000000000 +0100
17495 @@ -14,14 +14,17 @@
17496  #include <linux/utsname.h>
17497  #include <linux/err.h>
17498  #include <linux/slab.h>
17499 +#include <linux/vserver/global.h>
17500  
17501  static struct uts_namespace *create_uts_ns(void)
17502  {
17503         struct uts_namespace *uts_ns;
17504  
17505         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
17506 -       if (uts_ns)
17507 +       if (uts_ns) {
17508                 kref_init(&uts_ns->kref);
17509 +               atomic_inc(&vs_global_uts_ns);
17510 +       }
17511         return uts_ns;
17512  }
17513  
17514 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
17515         struct uts_namespace *ns;
17516  
17517         ns = container_of(kref, struct uts_namespace, kref);
17518 +       atomic_dec(&vs_global_uts_ns);
17519         kfree(ns);
17520  }
17521 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/cacct.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cacct.c
17522 --- linux-2.6.32.10/kernel/vserver/cacct.c      1970-01-01 01:00:00.000000000 +0100
17523 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cacct.c      2009-12-03 20:04:56.000000000 +0100
17524 @@ -0,0 +1,42 @@
17525 +/*
17526 + *  linux/kernel/vserver/cacct.c
17527 + *
17528 + *  Virtual Server: Context Accounting
17529 + *
17530 + *  Copyright (C) 2006-2007 Herbert Pötzl
17531 + *
17532 + *  V0.01  added accounting stats
17533 + *
17534 + */
17535 +
17536 +#include <linux/types.h>
17537 +#include <linux/vs_context.h>
17538 +#include <linux/vserver/cacct_cmd.h>
17539 +#include <linux/vserver/cacct_int.h>
17540 +
17541 +#include <asm/errno.h>
17542 +#include <asm/uaccess.h>
17543 +
17544 +
17545 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17546 +{
17547 +       struct vcmd_sock_stat_v0 vc_data;
17548 +       int j, field;
17549 +
17550 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17551 +               return -EFAULT;
17552 +
17553 +       field = vc_data.field;
17554 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17555 +               return -EINVAL;
17556 +
17557 +       for (j = 0; j < 3; j++) {
17558 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17559 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17560 +       }
17561 +
17562 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17563 +               return -EFAULT;
17564 +       return 0;
17565 +}
17566 +
17567 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/cacct_init.h linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cacct_init.h
17568 --- linux-2.6.32.10/kernel/vserver/cacct_init.h 1970-01-01 01:00:00.000000000 +0100
17569 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cacct_init.h 2009-12-03 20:04:56.000000000 +0100
17570 @@ -0,0 +1,25 @@
17571 +
17572 +
17573 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17574 +{
17575 +       int i, j;
17576 +
17577 +
17578 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17579 +               for (j = 0; j < 3; j++) {
17580 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
17581 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
17582 +               }
17583 +       }
17584 +       for (i = 0; i < 8; i++)
17585 +               atomic_set(&cacct->slab[i], 0);
17586 +       for (i = 0; i < 5; i++)
17587 +               for (j = 0; j < 4; j++)
17588 +                       atomic_set(&cacct->page[i][j], 0);
17589 +}
17590 +
17591 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17592 +{
17593 +       return;
17594 +}
17595 +
17596 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/cacct_proc.h linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cacct_proc.h
17597 --- linux-2.6.32.10/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00.000000000 +0100
17598 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cacct_proc.h 2009-12-03 20:04:56.000000000 +0100
17599 @@ -0,0 +1,53 @@
17600 +#ifndef _VX_CACCT_PROC_H
17601 +#define _VX_CACCT_PROC_H
17602 +
17603 +#include <linux/vserver/cacct_int.h>
17604 +
17605 +
17606 +#define VX_SOCKA_TOP   \
17607 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17608 +
17609 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17610 +{
17611 +       int i, j, length = 0;
17612 +       static char *type[VXA_SOCK_SIZE] = {
17613 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17614 +       };
17615 +
17616 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17617 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17618 +               length += sprintf(buffer + length, "%s:", type[i]);
17619 +               for (j = 0; j < 3; j++) {
17620 +                       length += sprintf(buffer + length,
17621 +                               "\t%10lu/%-10lu",
17622 +                               vx_sock_count(cacct, i, j),
17623 +                               vx_sock_total(cacct, i, j));
17624 +               }
17625 +               buffer[length++] = '\n';
17626 +       }
17627 +
17628 +       length += sprintf(buffer + length, "\n");
17629 +       length += sprintf(buffer + length,
17630 +               "slab:\t %8u %8u %8u %8u\n",
17631 +               atomic_read(&cacct->slab[1]),
17632 +               atomic_read(&cacct->slab[4]),
17633 +               atomic_read(&cacct->slab[0]),
17634 +               atomic_read(&cacct->slab[2]));
17635 +
17636 +       length += sprintf(buffer + length, "\n");
17637 +       for (i = 0; i < 5; i++) {
17638 +               length += sprintf(buffer + length,
17639 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17640 +                       atomic_read(&cacct->page[i][0]),
17641 +                       atomic_read(&cacct->page[i][1]),
17642 +                       atomic_read(&cacct->page[i][2]),
17643 +                       atomic_read(&cacct->page[i][3]),
17644 +                       atomic_read(&cacct->page[i][4]),
17645 +                       atomic_read(&cacct->page[i][5]),
17646 +                       atomic_read(&cacct->page[i][6]),
17647 +                       atomic_read(&cacct->page[i][7]));
17648 +       }
17649 +       return length;
17650 +}
17651 +
17652 +#endif /* _VX_CACCT_PROC_H */
17653 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/context.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/context.c
17654 --- linux-2.6.32.10/kernel/vserver/context.c    1970-01-01 01:00:00.000000000 +0100
17655 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/context.c    2010-03-13 21:49:35.000000000 +0100
17656 @@ -0,0 +1,1058 @@
17657 +/*
17658 + *  linux/kernel/vserver/context.c
17659 + *
17660 + *  Virtual Server: Context Support
17661 + *
17662 + *  Copyright (C) 2003-2007  Herbert Pötzl
17663 + *
17664 + *  V0.01  context helper
17665 + *  V0.02  vx_ctx_kill syscall command
17666 + *  V0.03  replaced context_info calls
17667 + *  V0.04  redesign of struct (de)alloc
17668 + *  V0.05  rlimit basic implementation
17669 + *  V0.06  task_xid and info commands
17670 + *  V0.07  context flags and caps
17671 + *  V0.08  switch to RCU based hash
17672 + *  V0.09  revert to non RCU for now
17673 + *  V0.10  and back to working RCU hash
17674 + *  V0.11  and back to locking again
17675 + *  V0.12  referenced context store
17676 + *  V0.13  separate per cpu data
17677 + *  V0.14  changed vcmds to vxi arg
17678 + *  V0.15  added context stat
17679 + *  V0.16  have __create claim() the vxi
17680 + *  V0.17  removed older and legacy stuff
17681 + *
17682 + */
17683 +
17684 +#include <linux/slab.h>
17685 +#include <linux/types.h>
17686 +#include <linux/security.h>
17687 +#include <linux/pid_namespace.h>
17688 +
17689 +#include <linux/vserver/context.h>
17690 +#include <linux/vserver/network.h>
17691 +#include <linux/vserver/debug.h>
17692 +#include <linux/vserver/limit.h>
17693 +#include <linux/vserver/limit_int.h>
17694 +#include <linux/vserver/space.h>
17695 +#include <linux/init_task.h>
17696 +#include <linux/fs_struct.h>
17697 +
17698 +#include <linux/vs_context.h>
17699 +#include <linux/vs_limit.h>
17700 +#include <linux/vs_pid.h>
17701 +#include <linux/vserver/context_cmd.h>
17702 +
17703 +#include "cvirt_init.h"
17704 +#include "cacct_init.h"
17705 +#include "limit_init.h"
17706 +#include "sched_init.h"
17707 +
17708 +
17709 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17710 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17711 +
17712 +
17713 +/*     now inactive context structures */
17714 +
17715 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17716 +
17717 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17718 +
17719 +
17720 +/*     __alloc_vx_info()
17721 +
17722 +       * allocate an initialized vx_info struct
17723 +       * doesn't make it visible (hash)                        */
17724 +
17725 +static struct vx_info *__alloc_vx_info(xid_t xid)
17726 +{
17727 +       struct vx_info *new = NULL;
17728 +       int cpu, index;
17729 +
17730 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17731 +
17732 +       /* would this benefit from a slab cache? */
17733 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17734 +       if (!new)
17735 +               return 0;
17736 +
17737 +       memset(new, 0, sizeof(struct vx_info));
17738 +#ifdef CONFIG_SMP
17739 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17740 +       if (!new->ptr_pc)
17741 +               goto error;
17742 +#endif
17743 +       new->vx_id = xid;
17744 +       INIT_HLIST_NODE(&new->vx_hlist);
17745 +       atomic_set(&new->vx_usecnt, 0);
17746 +       atomic_set(&new->vx_tasks, 0);
17747 +       new->vx_parent = NULL;
17748 +       new->vx_state = 0;
17749 +       init_waitqueue_head(&new->vx_wait);
17750 +
17751 +       /* prepare reaper */
17752 +       get_task_struct(init_pid_ns.child_reaper);
17753 +       new->vx_reaper = init_pid_ns.child_reaper;
17754 +       new->vx_badness_bias = 0;
17755 +
17756 +       /* rest of init goes here */
17757 +       vx_info_init_limit(&new->limit);
17758 +       vx_info_init_sched(&new->sched);
17759 +       vx_info_init_cvirt(&new->cvirt);
17760 +       vx_info_init_cacct(&new->cacct);
17761 +
17762 +       /* per cpu data structures */
17763 +       for_each_possible_cpu(cpu) {
17764 +               vx_info_init_sched_pc(
17765 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17766 +               vx_info_init_cvirt_pc(
17767 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17768 +       }
17769 +
17770 +       new->vx_flags = VXF_INIT_SET;
17771 +       cap_set_init_eff(new->vx_bcaps);
17772 +       new->vx_ccaps = 0;
17773 +       new->vx_umask = 0;
17774 +
17775 +       new->reboot_cmd = 0;
17776 +       new->exit_code = 0;
17777 +
17778 +       // preconfig fs entries
17779 +       for (index = 0; index < VX_SPACES; index++) {
17780 +               write_lock(&init_fs.lock);
17781 +               init_fs.users++;
17782 +               write_unlock(&init_fs.lock);
17783 +               new->vx_fs[index] = &init_fs;
17784 +       }
17785 +
17786 +       vxdprintk(VXD_CBIT(xid, 0),
17787 +               "alloc_vx_info(%d) = %p", xid, new);
17788 +       vxh_alloc_vx_info(new);
17789 +       atomic_inc(&vx_global_ctotal);
17790 +       return new;
17791 +#ifdef CONFIG_SMP
17792 +error:
17793 +       kfree(new);
17794 +       return 0;
17795 +#endif
17796 +}
17797 +
17798 +/*     __dealloc_vx_info()
17799 +
17800 +       * final disposal of vx_info                             */
17801 +
17802 +static void __dealloc_vx_info(struct vx_info *vxi)
17803 +{
17804 +#ifdef CONFIG_VSERVER_WARN
17805 +       struct vx_info_save vxis;
17806 +       int cpu;
17807 +#endif
17808 +       vxdprintk(VXD_CBIT(xid, 0),
17809 +               "dealloc_vx_info(%p)", vxi);
17810 +       vxh_dealloc_vx_info(vxi);
17811 +
17812 +#ifdef CONFIG_VSERVER_WARN
17813 +       enter_vx_info(vxi, &vxis);
17814 +       vx_info_exit_limit(&vxi->limit);
17815 +       vx_info_exit_sched(&vxi->sched);
17816 +       vx_info_exit_cvirt(&vxi->cvirt);
17817 +       vx_info_exit_cacct(&vxi->cacct);
17818 +
17819 +       for_each_possible_cpu(cpu) {
17820 +               vx_info_exit_sched_pc(
17821 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17822 +               vx_info_exit_cvirt_pc(
17823 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17824 +       }
17825 +       leave_vx_info(&vxis);
17826 +#endif
17827 +
17828 +       vxi->vx_id = -1;
17829 +       vxi->vx_state |= VXS_RELEASED;
17830 +
17831 +#ifdef CONFIG_SMP
17832 +       free_percpu(vxi->ptr_pc);
17833 +#endif
17834 +       kfree(vxi);
17835 +       atomic_dec(&vx_global_ctotal);
17836 +}
17837 +
17838 +static void __shutdown_vx_info(struct vx_info *vxi)
17839 +{
17840 +       struct nsproxy *nsproxy;
17841 +       struct fs_struct *fs;
17842 +       int index, kill;
17843 +
17844 +       might_sleep();
17845 +
17846 +       vxi->vx_state |= VXS_SHUTDOWN;
17847 +       vs_state_change(vxi, VSC_SHUTDOWN);
17848 +
17849 +       for (index = 0; index < VX_SPACES; index++) {
17850 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17851 +               if (nsproxy)
17852 +                       put_nsproxy(nsproxy);
17853 +
17854 +               fs = xchg(&vxi->vx_fs[index], NULL);
17855 +               write_lock(&fs->lock);
17856 +               kill = !--fs->users;
17857 +               write_unlock(&fs->lock);
17858 +               if (kill)
17859 +                       free_fs_struct(fs);
17860 +       }
17861 +}
17862 +
17863 +/* exported stuff */
17864 +
17865 +void free_vx_info(struct vx_info *vxi)
17866 +{
17867 +       unsigned long flags;
17868 +       unsigned index;
17869 +
17870 +       /* check for reference counts first */
17871 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17872 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17873 +
17874 +       /* context must not be hashed */
17875 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17876 +
17877 +       /* context shutdown is mandatory */
17878 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17879 +
17880 +       /* nsproxy and fs check */
17881 +       for (index = 0; index < VX_SPACES; index++) {
17882 +               BUG_ON(vxi->vx_nsproxy[index]);
17883 +               BUG_ON(vxi->vx_fs[index]);
17884 +       }
17885 +
17886 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17887 +       hlist_del(&vxi->vx_hlist);
17888 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17889 +
17890 +       __dealloc_vx_info(vxi);
17891 +}
17892 +
17893 +
17894 +/*     hash table for vx_info hash */
17895 +
17896 +#define VX_HASH_SIZE   13
17897 +
17898 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17899 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17900 +
17901 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17902 +
17903 +
17904 +static inline unsigned int __hashval(xid_t xid)
17905 +{
17906 +       return (xid % VX_HASH_SIZE);
17907 +}
17908 +
17909 +
17910 +
17911 +/*     __hash_vx_info()
17912 +
17913 +       * add the vxi to the global hash table
17914 +       * requires the hash_lock to be held                     */
17915 +
17916 +static inline void __hash_vx_info(struct vx_info *vxi)
17917 +{
17918 +       struct hlist_head *head;
17919 +
17920 +       vxd_assert_lock(&vx_info_hash_lock);
17921 +       vxdprintk(VXD_CBIT(xid, 4),
17922 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17923 +       vxh_hash_vx_info(vxi);
17924 +
17925 +       /* context must not be hashed */
17926 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17927 +
17928 +       vxi->vx_state |= VXS_HASHED;
17929 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17930 +       hlist_add_head(&vxi->vx_hlist, head);
17931 +       atomic_inc(&vx_global_cactive);
17932 +}
17933 +
17934 +/*     __unhash_vx_info()
17935 +
17936 +       * remove the vxi from the global hash table
17937 +       * requires the hash_lock to be held                     */
17938 +
17939 +static inline void __unhash_vx_info(struct vx_info *vxi)
17940 +{
17941 +       unsigned long flags;
17942 +
17943 +       vxd_assert_lock(&vx_info_hash_lock);
17944 +       vxdprintk(VXD_CBIT(xid, 4),
17945 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17946 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17947 +       vxh_unhash_vx_info(vxi);
17948 +
17949 +       /* context must be hashed */
17950 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17951 +       /* but without tasks */
17952 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17953 +
17954 +       vxi->vx_state &= ~VXS_HASHED;
17955 +       hlist_del_init(&vxi->vx_hlist);
17956 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17957 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17958 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17959 +       atomic_dec(&vx_global_cactive);
17960 +}
17961 +
17962 +
17963 +/*     __lookup_vx_info()
17964 +
17965 +       * requires the hash_lock to be held
17966 +       * doesn't increment the vx_refcnt                       */
17967 +
17968 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17969 +{
17970 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17971 +       struct hlist_node *pos;
17972 +       struct vx_info *vxi;
17973 +
17974 +       vxd_assert_lock(&vx_info_hash_lock);
17975 +       hlist_for_each(pos, head) {
17976 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17977 +
17978 +               if (vxi->vx_id == xid)
17979 +                       goto found;
17980 +       }
17981 +       vxi = NULL;
17982 +found:
17983 +       vxdprintk(VXD_CBIT(xid, 0),
17984 +               "__lookup_vx_info(#%u): %p[#%u]",
17985 +               xid, vxi, vxi ? vxi->vx_id : 0);
17986 +       vxh_lookup_vx_info(vxi, xid);
17987 +       return vxi;
17988 +}
17989 +
17990 +
17991 +/*     __create_vx_info()
17992 +
17993 +       * create the requested context
17994 +       * get(), claim() and hash it                            */
17995 +
17996 +static struct vx_info *__create_vx_info(int id)
17997 +{
17998 +       struct vx_info *new, *vxi = NULL;
17999 +
18000 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
18001 +
18002 +       if (!(new = __alloc_vx_info(id)))
18003 +               return ERR_PTR(-ENOMEM);
18004 +
18005 +       /* required to make dynamic xids unique */
18006 +       spin_lock(&vx_info_hash_lock);
18007 +
18008 +       /* static context requested */
18009 +       if ((vxi = __lookup_vx_info(id))) {
18010 +               vxdprintk(VXD_CBIT(xid, 0),
18011 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
18012 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18013 +                       vxi = ERR_PTR(-EBUSY);
18014 +               else
18015 +                       vxi = ERR_PTR(-EEXIST);
18016 +               goto out_unlock;
18017 +       }
18018 +       /* new context */
18019 +       vxdprintk(VXD_CBIT(xid, 0),
18020 +               "create_vx_info(%d) = %p (new)", id, new);
18021 +       claim_vx_info(new, NULL);
18022 +       __hash_vx_info(get_vx_info(new));
18023 +       vxi = new, new = NULL;
18024 +
18025 +out_unlock:
18026 +       spin_unlock(&vx_info_hash_lock);
18027 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
18028 +       if (new)
18029 +               __dealloc_vx_info(new);
18030 +       return vxi;
18031 +}
18032 +
18033 +
18034 +/*     exported stuff                                          */
18035 +
18036 +
18037 +void unhash_vx_info(struct vx_info *vxi)
18038 +{
18039 +       __shutdown_vx_info(vxi);
18040 +       spin_lock(&vx_info_hash_lock);
18041 +       __unhash_vx_info(vxi);
18042 +       spin_unlock(&vx_info_hash_lock);
18043 +       __wakeup_vx_info(vxi);
18044 +}
18045 +
18046 +
18047 +/*     lookup_vx_info()
18048 +
18049 +       * search for a vx_info and get() it
18050 +       * negative id means current                             */
18051 +
18052 +struct vx_info *lookup_vx_info(int id)
18053 +{
18054 +       struct vx_info *vxi = NULL;
18055 +
18056 +       if (id < 0) {
18057 +               vxi = get_vx_info(current_vx_info());
18058 +       } else if (id > 1) {
18059 +               spin_lock(&vx_info_hash_lock);
18060 +               vxi = get_vx_info(__lookup_vx_info(id));
18061 +               spin_unlock(&vx_info_hash_lock);
18062 +       }
18063 +       return vxi;
18064 +}
18065 +
18066 +/*     xid_is_hashed()
18067 +
18068 +       * verify that xid is still hashed                       */
18069 +
18070 +int xid_is_hashed(xid_t xid)
18071 +{
18072 +       int hashed;
18073 +
18074 +       spin_lock(&vx_info_hash_lock);
18075 +       hashed = (__lookup_vx_info(xid) != NULL);
18076 +       spin_unlock(&vx_info_hash_lock);
18077 +       return hashed;
18078 +}
18079 +
18080 +#ifdef CONFIG_PROC_FS
18081 +
18082 +/*     get_xid_list()
18083 +
18084 +       * get a subset of hashed xids for proc
18085 +       * assumes size is at least one                          */
18086 +
18087 +int get_xid_list(int index, unsigned int *xids, int size)
18088 +{
18089 +       int hindex, nr_xids = 0;
18090 +
18091 +       /* only show current and children */
18092 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18093 +               if (index > 0)
18094 +                       return 0;
18095 +               xids[nr_xids] = vx_current_xid();
18096 +               return 1;
18097 +       }
18098 +
18099 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18100 +               struct hlist_head *head = &vx_info_hash[hindex];
18101 +               struct hlist_node *pos;
18102 +
18103 +               spin_lock(&vx_info_hash_lock);
18104 +               hlist_for_each(pos, head) {
18105 +                       struct vx_info *vxi;
18106 +
18107 +                       if (--index > 0)
18108 +                               continue;
18109 +
18110 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18111 +                       xids[nr_xids] = vxi->vx_id;
18112 +                       if (++nr_xids >= size) {
18113 +                               spin_unlock(&vx_info_hash_lock);
18114 +                               goto out;
18115 +                       }
18116 +               }
18117 +               /* keep the lock time short */
18118 +               spin_unlock(&vx_info_hash_lock);
18119 +       }
18120 +out:
18121 +       return nr_xids;
18122 +}
18123 +#endif
18124 +
18125 +#ifdef CONFIG_VSERVER_DEBUG
18126 +
18127 +void   dump_vx_info_inactive(int level)
18128 +{
18129 +       struct hlist_node *entry, *next;
18130 +
18131 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18132 +               struct vx_info *vxi =
18133 +                       list_entry(entry, struct vx_info, vx_hlist);
18134 +
18135 +               dump_vx_info(vxi, level);
18136 +       }
18137 +}
18138 +
18139 +#endif
18140 +
18141 +#if 0
18142 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18143 +{
18144 +       struct user_struct *new_user, *old_user;
18145 +
18146 +       if (!p || !vxi)
18147 +               BUG();
18148 +
18149 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18150 +               return -EACCES;
18151 +
18152 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18153 +       if (!new_user)
18154 +               return -ENOMEM;
18155 +
18156 +       old_user = p->user;
18157 +       if (new_user != old_user) {
18158 +               atomic_inc(&new_user->processes);
18159 +               atomic_dec(&old_user->processes);
18160 +               p->user = new_user;
18161 +       }
18162 +       free_uid(old_user);
18163 +       return 0;
18164 +}
18165 +#endif
18166 +
18167 +#if 0
18168 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18169 +{
18170 +       // p->cap_effective &= vxi->vx_cap_bset;
18171 +       p->cap_effective =
18172 +               cap_intersect(p->cap_effective, vxi->cap_bset);
18173 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18174 +       p->cap_inheritable =
18175 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18176 +       // p->cap_permitted &= vxi->vx_cap_bset;
18177 +       p->cap_permitted =
18178 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18179 +}
18180 +#endif
18181 +
18182 +
18183 +#include <linux/file.h>
18184 +#include <linux/fdtable.h>
18185 +
18186 +static int vx_openfd_task(struct task_struct *tsk)
18187 +{
18188 +       struct files_struct *files = tsk->files;
18189 +       struct fdtable *fdt;
18190 +       const unsigned long *bptr;
18191 +       int count, total;
18192 +
18193 +       /* no rcu_read_lock() because of spin_lock() */
18194 +       spin_lock(&files->file_lock);
18195 +       fdt = files_fdtable(files);
18196 +       bptr = fdt->open_fds->fds_bits;
18197 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18198 +       for (total = 0; count > 0; count--) {
18199 +               if (*bptr)
18200 +                       total += hweight_long(*bptr);
18201 +               bptr++;
18202 +       }
18203 +       spin_unlock(&files->file_lock);
18204 +       return total;
18205 +}
18206 +
18207 +
18208 +/*     for *space compatibility */
18209 +
18210 +asmlinkage long sys_unshare(unsigned long);
18211 +
18212 +/*
18213 + *     migrate task to new context
18214 + *     gets vxi, puts old_vxi on change
18215 + *     optionally unshares namespaces (hack)
18216 + */
18217 +
18218 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18219 +{
18220 +       struct vx_info *old_vxi;
18221 +       int ret = 0;
18222 +
18223 +       if (!p || !vxi)
18224 +               BUG();
18225 +
18226 +       vxdprintk(VXD_CBIT(xid, 5),
18227 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18228 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18229 +
18230 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18231 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18232 +               return -EACCES;
18233 +
18234 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18235 +               return -EFAULT;
18236 +
18237 +       old_vxi = task_get_vx_info(p);
18238 +       if (old_vxi == vxi)
18239 +               goto out;
18240 +
18241 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18242 +       {
18243 +               int openfd;
18244 +
18245 +               task_lock(p);
18246 +               openfd = vx_openfd_task(p);
18247 +
18248 +               if (old_vxi) {
18249 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18250 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18251 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18252 +                       /* FIXME: what about the struct files here? */
18253 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18254 +                       /* account for the executable */
18255 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18256 +               }
18257 +               atomic_inc(&vxi->cvirt.nr_threads);
18258 +               atomic_inc(&vxi->cvirt.nr_running);
18259 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18260 +               /* FIXME: what about the struct files here? */
18261 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18262 +               /* account for the executable */
18263 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18264 +
18265 +               if (old_vxi) {
18266 +                       release_vx_info(old_vxi, p);
18267 +                       clr_vx_info(&p->vx_info);
18268 +               }
18269 +               claim_vx_info(vxi, p);
18270 +               set_vx_info(&p->vx_info, vxi);
18271 +               p->xid = vxi->vx_id;
18272 +
18273 +               vxdprintk(VXD_CBIT(xid, 5),
18274 +                       "moved task %p into vxi:%p[#%d]",
18275 +                       p, vxi, vxi->vx_id);
18276 +
18277 +               // vx_mask_cap_bset(vxi, p);
18278 +               task_unlock(p);
18279 +
18280 +               /* hack for *spaces to provide compatibility */
18281 +               if (unshare) {
18282 +                       struct nsproxy *old_nsp, *new_nsp;
18283 +
18284 +                       ret = unshare_nsproxy_namespaces(
18285 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18286 +                               &new_nsp, NULL);
18287 +                       if (ret)
18288 +                               goto out;
18289 +
18290 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18291 +                       vx_set_space(vxi,
18292 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
18293 +                       put_nsproxy(old_nsp);
18294 +               }
18295 +       }
18296 +out:
18297 +       put_vx_info(old_vxi);
18298 +       return ret;
18299 +}
18300 +
18301 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18302 +{
18303 +       struct task_struct *old_reaper;
18304 +
18305 +       if (!vxi)
18306 +               return -EINVAL;
18307 +
18308 +       vxdprintk(VXD_CBIT(xid, 6),
18309 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18310 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18311 +
18312 +       old_reaper = vxi->vx_reaper;
18313 +       if (old_reaper == p)
18314 +               return 0;
18315 +
18316 +       /* set new child reaper */
18317 +       get_task_struct(p);
18318 +       vxi->vx_reaper = p;
18319 +       put_task_struct(old_reaper);
18320 +       return 0;
18321 +}
18322 +
18323 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18324 +{
18325 +       if (!vxi)
18326 +               return -EINVAL;
18327 +
18328 +       vxdprintk(VXD_CBIT(xid, 6),
18329 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18330 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18331 +
18332 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18333 +       // vxi->vx_initpid = p->tgid;
18334 +       vxi->vx_initpid = p->pid;
18335 +       return 0;
18336 +}
18337 +
18338 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18339 +{
18340 +       vxdprintk(VXD_CBIT(xid, 6),
18341 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18342 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18343 +
18344 +       vxi->exit_code = code;
18345 +       vxi->vx_initpid = 0;
18346 +}
18347 +
18348 +
18349 +void vx_set_persistent(struct vx_info *vxi)
18350 +{
18351 +       vxdprintk(VXD_CBIT(xid, 6),
18352 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18353 +
18354 +       get_vx_info(vxi);
18355 +       claim_vx_info(vxi, NULL);
18356 +}
18357 +
18358 +void vx_clear_persistent(struct vx_info *vxi)
18359 +{
18360 +       vxdprintk(VXD_CBIT(xid, 6),
18361 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18362 +
18363 +       release_vx_info(vxi, NULL);
18364 +       put_vx_info(vxi);
18365 +}
18366 +
18367 +void vx_update_persistent(struct vx_info *vxi)
18368 +{
18369 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18370 +               vx_set_persistent(vxi);
18371 +       else
18372 +               vx_clear_persistent(vxi);
18373 +}
18374 +
18375 +
18376 +/*     task must be current or locked          */
18377 +
18378 +void   exit_vx_info(struct task_struct *p, int code)
18379 +{
18380 +       struct vx_info *vxi = p->vx_info;
18381 +
18382 +       if (vxi) {
18383 +               atomic_dec(&vxi->cvirt.nr_threads);
18384 +               vx_nproc_dec(p);
18385 +
18386 +               vxi->exit_code = code;
18387 +               release_vx_info(vxi, p);
18388 +       }
18389 +}
18390 +
18391 +void   exit_vx_info_early(struct task_struct *p, int code)
18392 +{
18393 +       struct vx_info *vxi = p->vx_info;
18394 +
18395 +       if (vxi) {
18396 +               if (vxi->vx_initpid == p->pid)
18397 +                       vx_exit_init(vxi, p, code);
18398 +               if (vxi->vx_reaper == p)
18399 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18400 +       }
18401 +}
18402 +
18403 +
18404 +/* vserver syscall commands below here */
18405 +
18406 +/* taks xid and vx_info functions */
18407 +
18408 +#include <asm/uaccess.h>
18409 +
18410 +
18411 +int vc_task_xid(uint32_t id)
18412 +{
18413 +       xid_t xid;
18414 +
18415 +       if (id) {
18416 +               struct task_struct *tsk;
18417 +
18418 +               read_lock(&tasklist_lock);
18419 +               tsk = find_task_by_real_pid(id);
18420 +               xid = (tsk) ? tsk->xid : -ESRCH;
18421 +               read_unlock(&tasklist_lock);
18422 +       } else
18423 +               xid = vx_current_xid();
18424 +       return xid;
18425 +}
18426 +
18427 +
18428 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18429 +{
18430 +       struct vcmd_vx_info_v0 vc_data;
18431 +
18432 +       vc_data.xid = vxi->vx_id;
18433 +       vc_data.initpid = vxi->vx_initpid;
18434 +
18435 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18436 +               return -EFAULT;
18437 +       return 0;
18438 +}
18439 +
18440 +
18441 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18442 +{
18443 +       struct vcmd_ctx_stat_v0 vc_data;
18444 +
18445 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18446 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18447 +
18448 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18449 +               return -EFAULT;
18450 +       return 0;
18451 +}
18452 +
18453 +
18454 +/* context functions */
18455 +
18456 +int vc_ctx_create(uint32_t xid, void __user *data)
18457 +{
18458 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18459 +       struct vx_info *new_vxi;
18460 +       int ret;
18461 +
18462 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18463 +               return -EFAULT;
18464 +
18465 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18466 +               return -EINVAL;
18467 +
18468 +       new_vxi = __create_vx_info(xid);
18469 +       if (IS_ERR(new_vxi))
18470 +               return PTR_ERR(new_vxi);
18471 +
18472 +       /* initial flags */
18473 +       new_vxi->vx_flags = vc_data.flagword;
18474 +
18475 +       ret = -ENOEXEC;
18476 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18477 +               goto out;
18478 +
18479 +       ret = vx_migrate_task(current, new_vxi, (!data));
18480 +       if (ret)
18481 +               goto out;
18482 +
18483 +       /* return context id on success */
18484 +       ret = new_vxi->vx_id;
18485 +
18486 +       /* get a reference for persistent contexts */
18487 +       if ((vc_data.flagword & VXF_PERSISTENT))
18488 +               vx_set_persistent(new_vxi);
18489 +out:
18490 +       release_vx_info(new_vxi, NULL);
18491 +       put_vx_info(new_vxi);
18492 +       return ret;
18493 +}
18494 +
18495 +
18496 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18497 +{
18498 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18499 +       int ret;
18500 +
18501 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18502 +               return -EFAULT;
18503 +
18504 +       ret = vx_migrate_task(current, vxi, 0);
18505 +       if (ret)
18506 +               return ret;
18507 +       if (vc_data.flagword & VXM_SET_INIT)
18508 +               ret = vx_set_init(vxi, current);
18509 +       if (ret)
18510 +               return ret;
18511 +       if (vc_data.flagword & VXM_SET_REAPER)
18512 +               ret = vx_set_reaper(vxi, current);
18513 +       return ret;
18514 +}
18515 +
18516 +
18517 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18518 +{
18519 +       struct vcmd_ctx_flags_v0 vc_data;
18520 +
18521 +       vc_data.flagword = vxi->vx_flags;
18522 +
18523 +       /* special STATE flag handling */
18524 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18525 +
18526 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18527 +               return -EFAULT;
18528 +       return 0;
18529 +}
18530 +
18531 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18532 +{
18533 +       struct vcmd_ctx_flags_v0 vc_data;
18534 +       uint64_t mask, trigger;
18535 +
18536 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18537 +               return -EFAULT;
18538 +
18539 +       /* special STATE flag handling */
18540 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18541 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18542 +
18543 +       if (vxi == current_vx_info()) {
18544 +               /* if (trigger & VXF_STATE_SETUP)
18545 +                       vx_mask_cap_bset(vxi, current); */
18546 +               if (trigger & VXF_STATE_INIT) {
18547 +                       int ret;
18548 +
18549 +                       ret = vx_set_init(vxi, current);
18550 +                       if (ret)
18551 +                               return ret;
18552 +                       ret = vx_set_reaper(vxi, current);
18553 +                       if (ret)
18554 +                               return ret;
18555 +               }
18556 +       }
18557 +
18558 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18559 +               vc_data.flagword, mask);
18560 +       if (trigger & VXF_PERSISTENT)
18561 +               vx_update_persistent(vxi);
18562 +
18563 +       return 0;
18564 +}
18565 +
18566 +
18567 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18568 +{
18569 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18570 +
18571 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18572 +       return v;
18573 +}
18574 +
18575 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18576 +{
18577 +       kernel_cap_t c = __cap_empty_set;
18578 +
18579 +       c.cap[0] = v & 0xFFFFFFFF;
18580 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18581 +
18582 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18583 +       return c;
18584 +}
18585 +
18586 +
18587 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18588 +{
18589 +       if (bcaps)
18590 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18591 +       if (ccaps)
18592 +               *ccaps = vxi->vx_ccaps;
18593 +
18594 +       return 0;
18595 +}
18596 +
18597 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18598 +{
18599 +       struct vcmd_ctx_caps_v1 vc_data;
18600 +       int ret;
18601 +
18602 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18603 +       if (ret)
18604 +               return ret;
18605 +       vc_data.cmask = ~0ULL;
18606 +
18607 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18608 +               return -EFAULT;
18609 +       return 0;
18610 +}
18611 +
18612 +static int do_set_caps(struct vx_info *vxi,
18613 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18614 +{
18615 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18616 +
18617 +#if 0
18618 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18619 +               bcaps, bmask, ccaps, cmask);
18620 +#endif
18621 +       vxi->vx_bcaps = cap_t_from_caps(
18622 +               vs_mask_flags(bcold, bcaps, bmask));
18623 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18624 +
18625 +       return 0;
18626 +}
18627 +
18628 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18629 +{
18630 +       struct vcmd_ctx_caps_v1 vc_data;
18631 +
18632 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18633 +               return -EFAULT;
18634 +
18635 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18636 +}
18637 +
18638 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18639 +{
18640 +       struct vcmd_bcaps vc_data;
18641 +       int ret;
18642 +
18643 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18644 +       if (ret)
18645 +               return ret;
18646 +       vc_data.bmask = ~0ULL;
18647 +
18648 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18649 +               return -EFAULT;
18650 +       return 0;
18651 +}
18652 +
18653 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18654 +{
18655 +       struct vcmd_bcaps vc_data;
18656 +
18657 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18658 +               return -EFAULT;
18659 +
18660 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18661 +}
18662 +
18663 +
18664 +int vc_get_umask(struct vx_info *vxi, void __user *data)
18665 +{
18666 +       struct vcmd_umask vc_data;
18667 +
18668 +       vc_data.umask = vxi->vx_umask;
18669 +       vc_data.mask = ~0ULL;
18670 +
18671 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18672 +               return -EFAULT;
18673 +       return 0;
18674 +}
18675 +
18676 +int vc_set_umask(struct vx_info *vxi, void __user *data)
18677 +{
18678 +       struct vcmd_umask vc_data;
18679 +
18680 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18681 +               return -EFAULT;
18682 +
18683 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
18684 +               vc_data.umask, vc_data.mask);
18685 +       return 0;
18686 +}
18687 +
18688 +
18689 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18690 +{
18691 +       struct vcmd_badness_v0 vc_data;
18692 +
18693 +       vc_data.bias = vxi->vx_badness_bias;
18694 +
18695 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18696 +               return -EFAULT;
18697 +       return 0;
18698 +}
18699 +
18700 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18701 +{
18702 +       struct vcmd_badness_v0 vc_data;
18703 +
18704 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18705 +               return -EFAULT;
18706 +
18707 +       vxi->vx_badness_bias = vc_data.bias;
18708 +       return 0;
18709 +}
18710 +
18711 +#include <linux/module.h>
18712 +
18713 +EXPORT_SYMBOL_GPL(free_vx_info);
18714 +
18715 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/cvirt.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cvirt.c
18716 --- linux-2.6.32.10/kernel/vserver/cvirt.c      1970-01-01 01:00:00.000000000 +0100
18717 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cvirt.c      2009-12-03 20:04:56.000000000 +0100
18718 @@ -0,0 +1,304 @@
18719 +/*
18720 + *  linux/kernel/vserver/cvirt.c
18721 + *
18722 + *  Virtual Server: Context Virtualization
18723 + *
18724 + *  Copyright (C) 2004-2007  Herbert Pötzl
18725 + *
18726 + *  V0.01  broken out from limit.c
18727 + *  V0.02  added utsname stuff
18728 + *  V0.03  changed vcmds to vxi arg
18729 + *
18730 + */
18731 +
18732 +#include <linux/types.h>
18733 +#include <linux/utsname.h>
18734 +#include <linux/vs_cvirt.h>
18735 +#include <linux/vserver/switch.h>
18736 +#include <linux/vserver/cvirt_cmd.h>
18737 +
18738 +#include <asm/uaccess.h>
18739 +
18740 +
18741 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18742 +{
18743 +       struct vx_info *vxi = current_vx_info();
18744 +
18745 +       set_normalized_timespec(uptime,
18746 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18747 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18748 +       if (!idle)
18749 +               return;
18750 +       set_normalized_timespec(idle,
18751 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18752 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18753 +       return;
18754 +}
18755 +
18756 +uint64_t vx_idle_jiffies(void)
18757 +{
18758 +       return init_task.utime + init_task.stime;
18759 +}
18760 +
18761 +
18762 +
18763 +static inline uint32_t __update_loadavg(uint32_t load,
18764 +       int wsize, int delta, int n)
18765 +{
18766 +       unsigned long long calc, prev;
18767 +
18768 +       /* just set it to n */
18769 +       if (unlikely(delta >= wsize))
18770 +               return (n << FSHIFT);
18771 +
18772 +       calc = delta * n;
18773 +       calc <<= FSHIFT;
18774 +       prev = (wsize - delta);
18775 +       prev *= load;
18776 +       calc += prev;
18777 +       do_div(calc, wsize);
18778 +       return calc;
18779 +}
18780 +
18781 +
18782 +void vx_update_load(struct vx_info *vxi)
18783 +{
18784 +       uint32_t now, last, delta;
18785 +       unsigned int nr_running, nr_uninterruptible;
18786 +       unsigned int total;
18787 +       unsigned long flags;
18788 +
18789 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18790 +
18791 +       now = jiffies;
18792 +       last = vxi->cvirt.load_last;
18793 +       delta = now - last;
18794 +
18795 +       if (delta < 5*HZ)
18796 +               goto out;
18797 +
18798 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18799 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18800 +       total = nr_running + nr_uninterruptible;
18801 +
18802 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18803 +               60*HZ, delta, total);
18804 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18805 +               5*60*HZ, delta, total);
18806 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18807 +               15*60*HZ, delta, total);
18808 +
18809 +       vxi->cvirt.load_last = now;
18810 +out:
18811 +       atomic_inc(&vxi->cvirt.load_updates);
18812 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18813 +}
18814 +
18815 +
18816 +/*
18817 + * Commands to do_syslog:
18818 + *
18819 + *      0 -- Close the log.  Currently a NOP.
18820 + *      1 -- Open the log. Currently a NOP.
18821 + *      2 -- Read from the log.
18822 + *      3 -- Read all messages remaining in the ring buffer.
18823 + *      4 -- Read and clear all messages remaining in the ring buffer
18824 + *      5 -- Clear ring buffer.
18825 + *      6 -- Disable printk's to console
18826 + *      7 -- Enable printk's to console
18827 + *      8 -- Set level of messages printed to console
18828 + *      9 -- Return number of unread characters in the log buffer
18829 + *     10 -- Return size of the log buffer
18830 + */
18831 +int vx_do_syslog(int type, char __user *buf, int len)
18832 +{
18833 +       int error = 0;
18834 +       int do_clear = 0;
18835 +       struct vx_info *vxi = current_vx_info();
18836 +       struct _vx_syslog *log;
18837 +
18838 +       if (!vxi)
18839 +               return -EINVAL;
18840 +       log = &vxi->cvirt.syslog;
18841 +
18842 +       switch (type) {
18843 +       case 0:         /* Close log */
18844 +       case 1:         /* Open log */
18845 +               break;
18846 +       case 2:         /* Read from log */
18847 +               error = wait_event_interruptible(log->log_wait,
18848 +                       (log->log_start - log->log_end));
18849 +               if (error)
18850 +                       break;
18851 +               spin_lock_irq(&log->logbuf_lock);
18852 +               spin_unlock_irq(&log->logbuf_lock);
18853 +               break;
18854 +       case 4:         /* Read/clear last kernel messages */
18855 +               do_clear = 1;
18856 +               /* fall through */
18857 +       case 3:         /* Read last kernel messages */
18858 +               return 0;
18859 +
18860 +       case 5:         /* Clear ring buffer */
18861 +               return 0;
18862 +
18863 +       case 6:         /* Disable logging to console */
18864 +       case 7:         /* Enable logging to console */
18865 +       case 8:         /* Set level of messages printed to console */
18866 +               break;
18867 +
18868 +       case 9:         /* Number of chars in the log buffer */
18869 +               return 0;
18870 +       case 10:        /* Size of the log buffer */
18871 +               return 0;
18872 +       default:
18873 +               error = -EINVAL;
18874 +               break;
18875 +       }
18876 +       return error;
18877 +}
18878 +
18879 +
18880 +/* virtual host info names */
18881 +
18882 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18883 +{
18884 +       struct nsproxy *nsproxy;
18885 +       struct uts_namespace *uts;
18886 +
18887 +       if (id == VHIN_CONTEXT)
18888 +               return vxi->vx_name;
18889 +
18890 +       nsproxy = vxi->vx_nsproxy[0];
18891 +       if (!nsproxy)
18892 +               return NULL;
18893 +
18894 +       uts = nsproxy->uts_ns;
18895 +       if (!uts)
18896 +               return NULL;
18897 +
18898 +       switch (id) {
18899 +       case VHIN_SYSNAME:
18900 +               return uts->name.sysname;
18901 +       case VHIN_NODENAME:
18902 +               return uts->name.nodename;
18903 +       case VHIN_RELEASE:
18904 +               return uts->name.release;
18905 +       case VHIN_VERSION:
18906 +               return uts->name.version;
18907 +       case VHIN_MACHINE:
18908 +               return uts->name.machine;
18909 +       case VHIN_DOMAINNAME:
18910 +               return uts->name.domainname;
18911 +       default:
18912 +               return NULL;
18913 +       }
18914 +       return NULL;
18915 +}
18916 +
18917 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18918 +{
18919 +       struct vcmd_vhi_name_v0 vc_data;
18920 +       char *name;
18921 +
18922 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18923 +               return -EFAULT;
18924 +
18925 +       name = vx_vhi_name(vxi, vc_data.field);
18926 +       if (!name)
18927 +               return -EINVAL;
18928 +
18929 +       memcpy(name, vc_data.name, 65);
18930 +       return 0;
18931 +}
18932 +
18933 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18934 +{
18935 +       struct vcmd_vhi_name_v0 vc_data;
18936 +       char *name;
18937 +
18938 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18939 +               return -EFAULT;
18940 +
18941 +       name = vx_vhi_name(vxi, vc_data.field);
18942 +       if (!name)
18943 +               return -EINVAL;
18944 +
18945 +       memcpy(vc_data.name, name, 65);
18946 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18947 +               return -EFAULT;
18948 +       return 0;
18949 +}
18950 +
18951 +
18952 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18953 +{
18954 +       struct vcmd_virt_stat_v0 vc_data;
18955 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18956 +       struct timespec uptime;
18957 +
18958 +       do_posix_clock_monotonic_gettime(&uptime);
18959 +       set_normalized_timespec(&uptime,
18960 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18961 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18962 +
18963 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18964 +       vc_data.uptime = timespec_to_ns(&uptime);
18965 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18966 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18967 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18968 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18969 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18970 +       vc_data.load[0] = cvirt->load[0];
18971 +       vc_data.load[1] = cvirt->load[1];
18972 +       vc_data.load[2] = cvirt->load[2];
18973 +
18974 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18975 +               return -EFAULT;
18976 +       return 0;
18977 +}
18978 +
18979 +
18980 +#ifdef CONFIG_VSERVER_VTIME
18981 +
18982 +/* virtualized time base */
18983 +
18984 +void vx_gettimeofday(struct timeval *tv)
18985 +{
18986 +       struct vx_info *vxi;
18987 +
18988 +       do_gettimeofday(tv);
18989 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18990 +               return;
18991 +
18992 +       vxi = current_vx_info();
18993 +       tv->tv_sec += vxi->cvirt.bias_tv.tv_sec;
18994 +       tv->tv_usec += vxi->cvirt.bias_tv.tv_usec;
18995 +
18996 +       if (tv->tv_usec >= USEC_PER_SEC) {
18997 +               tv->tv_sec++;
18998 +               tv->tv_usec -= USEC_PER_SEC;
18999 +       } else if (tv->tv_usec < 0) {
19000 +               tv->tv_sec--;
19001 +               tv->tv_usec += USEC_PER_SEC;
19002 +       }
19003 +}
19004 +
19005 +int vx_settimeofday(struct timespec *ts)
19006 +{
19007 +       struct timeval tv;
19008 +       struct vx_info *vxi;
19009 +
19010 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19011 +               return do_settimeofday(ts);
19012 +
19013 +       do_gettimeofday(&tv);
19014 +       vxi = current_vx_info();
19015 +       vxi->cvirt.bias_tv.tv_sec = ts->tv_sec - tv.tv_sec;
19016 +       vxi->cvirt.bias_tv.tv_usec =
19017 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
19018 +       return 0;
19019 +}
19020 +
19021 +#endif
19022 +
19023 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/cvirt_init.h linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cvirt_init.h
19024 --- linux-2.6.32.10/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00.000000000 +0100
19025 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cvirt_init.h 2009-12-03 20:04:56.000000000 +0100
19026 @@ -0,0 +1,69 @@
19027 +
19028 +
19029 +extern uint64_t vx_idle_jiffies(void);
19030 +
19031 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
19032 +{
19033 +       uint64_t idle_jiffies = vx_idle_jiffies();
19034 +       uint64_t nsuptime;
19035 +
19036 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
19037 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
19038 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
19039 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
19040 +       cvirt->bias_tv.tv_sec = 0;
19041 +       cvirt->bias_tv.tv_usec = 0;
19042 +
19043 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
19044 +       atomic_set(&cvirt->nr_threads, 0);
19045 +       atomic_set(&cvirt->nr_running, 0);
19046 +       atomic_set(&cvirt->nr_uninterruptible, 0);
19047 +       atomic_set(&cvirt->nr_onhold, 0);
19048 +
19049 +       spin_lock_init(&cvirt->load_lock);
19050 +       cvirt->load_last = jiffies;
19051 +       atomic_set(&cvirt->load_updates, 0);
19052 +       cvirt->load[0] = 0;
19053 +       cvirt->load[1] = 0;
19054 +       cvirt->load[2] = 0;
19055 +       atomic_set(&cvirt->total_forks, 0);
19056 +
19057 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
19058 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19059 +       cvirt->syslog.log_start = 0;
19060 +       cvirt->syslog.log_end = 0;
19061 +       cvirt->syslog.con_start = 0;
19062 +       cvirt->syslog.logged_chars = 0;
19063 +}
19064 +
19065 +static inline
19066 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19067 +{
19068 +       // cvirt_pc->cpustat = { 0 };
19069 +}
19070 +
19071 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19072 +{
19073 +       int value;
19074 +
19075 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19076 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19077 +               cvirt, value);
19078 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19079 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19080 +               cvirt, value);
19081 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19082 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19083 +               cvirt, value);
19084 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19085 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19086 +               cvirt, value);
19087 +       return;
19088 +}
19089 +
19090 +static inline
19091 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19092 +{
19093 +       return;
19094 +}
19095 +
19096 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/cvirt_proc.h linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cvirt_proc.h
19097 --- linux-2.6.32.10/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00.000000000 +0100
19098 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/cvirt_proc.h 2009-12-03 20:04:56.000000000 +0100
19099 @@ -0,0 +1,135 @@
19100 +#ifndef _VX_CVIRT_PROC_H
19101 +#define _VX_CVIRT_PROC_H
19102 +
19103 +#include <linux/nsproxy.h>
19104 +#include <linux/mnt_namespace.h>
19105 +#include <linux/ipc_namespace.h>
19106 +#include <linux/utsname.h>
19107 +#include <linux/ipc.h>
19108 +
19109 +
19110 +static inline
19111 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19112 +{
19113 +       struct mnt_namespace *ns;
19114 +       struct uts_namespace *uts;
19115 +       struct ipc_namespace *ipc;
19116 +       struct path path;
19117 +       char *pstr, *root;
19118 +       int length = 0;
19119 +
19120 +       if (!nsproxy)
19121 +               goto out;
19122 +
19123 +       length += sprintf(buffer + length,
19124 +               "NSProxy:\t%p [%p,%p,%p]\n",
19125 +               nsproxy, nsproxy->mnt_ns,
19126 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19127 +
19128 +       ns = nsproxy->mnt_ns;
19129 +       if (!ns)
19130 +               goto skip_ns;
19131 +
19132 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
19133 +       if (!pstr)
19134 +               goto skip_ns;
19135 +
19136 +       path.mnt = ns->root;
19137 +       path.dentry = ns->root->mnt_root;
19138 +       root = d_path(&path, pstr, PATH_MAX - 2);
19139 +       length += sprintf(buffer + length,
19140 +               "Namespace:\t%p [#%u]\n"
19141 +               "RootPath:\t%s\n",
19142 +               ns, atomic_read(&ns->count),
19143 +               root);
19144 +       kfree(pstr);
19145 +skip_ns:
19146 +
19147 +       uts = nsproxy->uts_ns;
19148 +       if (!uts)
19149 +               goto skip_uts;
19150 +
19151 +       length += sprintf(buffer + length,
19152 +               "SysName:\t%.*s\n"
19153 +               "NodeName:\t%.*s\n"
19154 +               "Release:\t%.*s\n"
19155 +               "Version:\t%.*s\n"
19156 +               "Machine:\t%.*s\n"
19157 +               "DomainName:\t%.*s\n",
19158 +               __NEW_UTS_LEN, uts->name.sysname,
19159 +               __NEW_UTS_LEN, uts->name.nodename,
19160 +               __NEW_UTS_LEN, uts->name.release,
19161 +               __NEW_UTS_LEN, uts->name.version,
19162 +               __NEW_UTS_LEN, uts->name.machine,
19163 +               __NEW_UTS_LEN, uts->name.domainname);
19164 +skip_uts:
19165 +
19166 +       ipc = nsproxy->ipc_ns;
19167 +       if (!ipc)
19168 +               goto skip_ipc;
19169 +
19170 +       length += sprintf(buffer + length,
19171 +               "SEMS:\t\t%d %d %d %d  %d\n"
19172 +               "MSG:\t\t%d %d %d\n"
19173 +               "SHM:\t\t%lu %lu  %d %d\n",
19174 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19175 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19176 +               ipc->used_sems,
19177 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19178 +               (unsigned long)ipc->shm_ctlmax,
19179 +               (unsigned long)ipc->shm_ctlall,
19180 +               ipc->shm_ctlmni, ipc->shm_tot);
19181 +skip_ipc:
19182 +out:
19183 +       return length;
19184 +}
19185 +
19186 +
19187 +#include <linux/sched.h>
19188 +
19189 +#define LOAD_INT(x) ((x) >> FSHIFT)
19190 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19191 +
19192 +static inline
19193 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19194 +{
19195 +       int length = 0;
19196 +       int a, b, c;
19197 +
19198 +       length += sprintf(buffer + length,
19199 +               "BiasUptime:\t%lu.%02lu\n",
19200 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19201 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19202 +
19203 +       a = cvirt->load[0] + (FIXED_1 / 200);
19204 +       b = cvirt->load[1] + (FIXED_1 / 200);
19205 +       c = cvirt->load[2] + (FIXED_1 / 200);
19206 +       length += sprintf(buffer + length,
19207 +               "nr_threads:\t%d\n"
19208 +               "nr_running:\t%d\n"
19209 +               "nr_unintr:\t%d\n"
19210 +               "nr_onhold:\t%d\n"
19211 +               "load_updates:\t%d\n"
19212 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19213 +               "total_forks:\t%d\n",
19214 +               atomic_read(&cvirt->nr_threads),
19215 +               atomic_read(&cvirt->nr_running),
19216 +               atomic_read(&cvirt->nr_uninterruptible),
19217 +               atomic_read(&cvirt->nr_onhold),
19218 +               atomic_read(&cvirt->load_updates),
19219 +               LOAD_INT(a), LOAD_FRAC(a),
19220 +               LOAD_INT(b), LOAD_FRAC(b),
19221 +               LOAD_INT(c), LOAD_FRAC(c),
19222 +               atomic_read(&cvirt->total_forks));
19223 +       return length;
19224 +}
19225 +
19226 +static inline
19227 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19228 +       char *buffer, int cpu)
19229 +{
19230 +       int length = 0;
19231 +       return length;
19232 +}
19233 +
19234 +#endif /* _VX_CVIRT_PROC_H */
19235 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/debug.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/debug.c
19236 --- linux-2.6.32.10/kernel/vserver/debug.c      1970-01-01 01:00:00.000000000 +0100
19237 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/debug.c      2009-12-03 20:04:56.000000000 +0100
19238 @@ -0,0 +1,32 @@
19239 +/*
19240 + *  kernel/vserver/debug.c
19241 + *
19242 + *  Copyright (C) 2005-2007 Herbert Pötzl
19243 + *
19244 + *  V0.01  vx_info dump support
19245 + *
19246 + */
19247 +
19248 +#include <linux/module.h>
19249 +
19250 +#include <linux/vserver/context.h>
19251 +
19252 +
19253 +void   dump_vx_info(struct vx_info *vxi, int level)
19254 +{
19255 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19256 +               atomic_read(&vxi->vx_usecnt),
19257 +               atomic_read(&vxi->vx_tasks),
19258 +               vxi->vx_state);
19259 +       if (level > 0) {
19260 +               __dump_vx_limit(&vxi->limit);
19261 +               __dump_vx_sched(&vxi->sched);
19262 +               __dump_vx_cvirt(&vxi->cvirt);
19263 +               __dump_vx_cacct(&vxi->cacct);
19264 +       }
19265 +       printk("---\n");
19266 +}
19267 +
19268 +
19269 +EXPORT_SYMBOL_GPL(dump_vx_info);
19270 +
19271 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/device.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/device.c
19272 --- linux-2.6.32.10/kernel/vserver/device.c     1970-01-01 01:00:00.000000000 +0100
19273 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/device.c     2009-12-03 20:04:56.000000000 +0100
19274 @@ -0,0 +1,443 @@
19275 +/*
19276 + *  linux/kernel/vserver/device.c
19277 + *
19278 + *  Linux-VServer: Device Support
19279 + *
19280 + *  Copyright (C) 2006  Herbert Pötzl
19281 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19282 + *
19283 + *  V0.01  device mapping basics
19284 + *  V0.02  added defaults
19285 + *
19286 + */
19287 +
19288 +#include <linux/slab.h>
19289 +#include <linux/rcupdate.h>
19290 +#include <linux/fs.h>
19291 +#include <linux/namei.h>
19292 +#include <linux/hash.h>
19293 +
19294 +#include <asm/errno.h>
19295 +#include <asm/uaccess.h>
19296 +#include <linux/vserver/base.h>
19297 +#include <linux/vserver/debug.h>
19298 +#include <linux/vserver/context.h>
19299 +#include <linux/vserver/device.h>
19300 +#include <linux/vserver/device_cmd.h>
19301 +
19302 +
19303 +#define DMAP_HASH_BITS 4
19304 +
19305 +
19306 +struct vs_mapping {
19307 +       union {
19308 +               struct hlist_node hlist;
19309 +               struct list_head list;
19310 +       } u;
19311 +#define dm_hlist       u.hlist
19312 +#define dm_list                u.list
19313 +       xid_t xid;
19314 +       dev_t device;
19315 +       struct vx_dmap_target target;
19316 +};
19317 +
19318 +
19319 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19320 +
19321 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
19322 +
19323 +static struct vx_dmap_target dmap_defaults[2] = {
19324 +       { .flags = DATTR_OPEN },
19325 +       { .flags = DATTR_OPEN },
19326 +};
19327 +
19328 +
19329 +struct kmem_cache *dmap_cachep __read_mostly;
19330 +
19331 +int __init dmap_cache_init(void)
19332 +{
19333 +       dmap_cachep = kmem_cache_create("dmap_cache",
19334 +               sizeof(struct vs_mapping), 0,
19335 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19336 +       return 0;
19337 +}
19338 +
19339 +__initcall(dmap_cache_init);
19340 +
19341 +
19342 +static inline unsigned int __hashval(dev_t dev, int bits)
19343 +{
19344 +       return hash_long((unsigned long)dev, bits);
19345 +}
19346 +
19347 +
19348 +/*     __hash_mapping()
19349 + *     add the mapping to the hash table
19350 + */
19351 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19352 +{
19353 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19354 +       struct hlist_head *head, *hash = dmap_main_hash;
19355 +       int device = vdm->device;
19356 +
19357 +       spin_lock(hash_lock);
19358 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19359 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19360 +
19361 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19362 +       hlist_add_head(&vdm->dm_hlist, head);
19363 +       spin_unlock(hash_lock);
19364 +}
19365 +
19366 +
19367 +static inline int __mode_to_default(umode_t mode)
19368 +{
19369 +       switch (mode) {
19370 +       case S_IFBLK:
19371 +               return 0;
19372 +       case S_IFCHR:
19373 +               return 1;
19374 +       default:
19375 +               BUG();
19376 +       }
19377 +}
19378 +
19379 +
19380 +/*     __set_default()
19381 + *     set a default
19382 + */
19383 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19384 +       struct vx_dmap_target *vdmt)
19385 +{
19386 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19387 +       spin_lock(hash_lock);
19388 +
19389 +       if (vxi)
19390 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19391 +       else
19392 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19393 +
19394 +
19395 +       spin_unlock(hash_lock);
19396 +
19397 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19398 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19399 +}
19400 +
19401 +
19402 +/*     __remove_default()
19403 + *     remove a default
19404 + */
19405 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19406 +{
19407 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19408 +       spin_lock(hash_lock);
19409 +
19410 +       if (vxi)
19411 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19412 +       else    /* remove == reset */
19413 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19414 +
19415 +       spin_unlock(hash_lock);
19416 +       return 0;
19417 +}
19418 +
19419 +
19420 +/*     __find_mapping()
19421 + *     find a mapping in the hash table
19422 + *
19423 + *     caller must hold hash_lock
19424 + */
19425 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19426 +       struct vs_mapping **local, struct vs_mapping **global)
19427 +{
19428 +       struct hlist_head *hash = dmap_main_hash;
19429 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19430 +       struct hlist_node *pos;
19431 +       struct vs_mapping *vdm;
19432 +
19433 +       *local = NULL;
19434 +       if (global)
19435 +               *global = NULL;
19436 +
19437 +       hlist_for_each(pos, head) {
19438 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19439 +
19440 +               if ((vdm->device == device) &&
19441 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19442 +                       if (vdm->xid == xid) {
19443 +                               *local = vdm;
19444 +                               return 1;
19445 +                       } else if (global && vdm->xid == 0)
19446 +                               *global = vdm;
19447 +               }
19448 +       }
19449 +
19450 +       if (global && *global)
19451 +               return 0;
19452 +       else
19453 +               return -ENOENT;
19454 +}
19455 +
19456 +
19457 +/*     __lookup_mapping()
19458 + *     find a mapping and store the result in target and flags
19459 + */
19460 +static inline int __lookup_mapping(struct vx_info *vxi,
19461 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19462 +{
19463 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19464 +       struct vs_mapping *vdm, *global;
19465 +       struct vx_dmap_target *vdmt;
19466 +       int ret = 0;
19467 +       xid_t xid = vxi->vx_id;
19468 +       int index;
19469 +
19470 +       spin_lock(hash_lock);
19471 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19472 +               ret = 1;
19473 +               vdmt = &vdm->target;
19474 +               goto found;
19475 +       }
19476 +
19477 +       index = __mode_to_default(mode);
19478 +       if (vxi && vxi->dmap.targets[index].flags) {
19479 +               ret = 2;
19480 +               vdmt = &vxi->dmap.targets[index];
19481 +       } else if (global) {
19482 +               ret = 3;
19483 +               vdmt = &global->target;
19484 +               goto found;
19485 +       } else {
19486 +               ret = 4;
19487 +               vdmt = &dmap_defaults[index];
19488 +       }
19489 +
19490 +found:
19491 +       if (target && (vdmt->flags & DATTR_REMAP))
19492 +               *target = vdmt->target;
19493 +       else if (target)
19494 +               *target = device;
19495 +       if (flags)
19496 +               *flags = vdmt->flags;
19497 +
19498 +       spin_unlock(hash_lock);
19499 +
19500 +       return ret;
19501 +}
19502 +
19503 +
19504 +/*     __remove_mapping()
19505 + *     remove a mapping from the hash table
19506 + */
19507 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19508 +       umode_t mode)
19509 +{
19510 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19511 +       struct vs_mapping *vdm = NULL;
19512 +       int ret = 0;
19513 +
19514 +       spin_lock(hash_lock);
19515 +
19516 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19517 +               NULL);
19518 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19519 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19520 +       if (ret < 0)
19521 +               goto out;
19522 +       hlist_del(&vdm->dm_hlist);
19523 +
19524 +out:
19525 +       spin_unlock(hash_lock);
19526 +       if (vdm)
19527 +               kmem_cache_free(dmap_cachep, vdm);
19528 +       return ret;
19529 +}
19530 +
19531 +
19532 +
19533 +int vs_map_device(struct vx_info *vxi,
19534 +       dev_t device, dev_t *target, umode_t mode)
19535 +{
19536 +       int ret, flags = DATTR_MASK;
19537 +
19538 +       if (!vxi) {
19539 +               if (target)
19540 +                       *target = device;
19541 +               goto out;
19542 +       }
19543 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19544 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19545 +               device, target ? *target : 0, flags, mode, ret);
19546 +out:
19547 +       return (flags & DATTR_MASK);
19548 +}
19549 +
19550 +
19551 +
19552 +static int do_set_mapping(struct vx_info *vxi,
19553 +       dev_t device, dev_t target, int flags, umode_t mode)
19554 +{
19555 +       if (device) {
19556 +               struct vs_mapping *new;
19557 +
19558 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19559 +               if (!new)
19560 +                       return -ENOMEM;
19561 +
19562 +               INIT_HLIST_NODE(&new->dm_hlist);
19563 +               new->device = device;
19564 +               new->target.target = target;
19565 +               new->target.flags = flags | mode;
19566 +               new->xid = (vxi ? vxi->vx_id : 0);
19567 +
19568 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19569 +               __hash_mapping(vxi, new);
19570 +       } else {
19571 +               struct vx_dmap_target new = {
19572 +                       .target = target,
19573 +                       .flags = flags | mode,
19574 +               };
19575 +               __set_default(vxi, mode, &new);
19576 +       }
19577 +       return 0;
19578 +}
19579 +
19580 +
19581 +static int do_unset_mapping(struct vx_info *vxi,
19582 +       dev_t device, dev_t target, int flags, umode_t mode)
19583 +{
19584 +       int ret = -EINVAL;
19585 +
19586 +       if (device) {
19587 +               ret = __remove_mapping(vxi, device, mode);
19588 +               if (ret < 0)
19589 +                       goto out;
19590 +       } else {
19591 +               ret = __remove_default(vxi, mode);
19592 +               if (ret < 0)
19593 +                       goto out;
19594 +       }
19595 +
19596 +out:
19597 +       return ret;
19598 +}
19599 +
19600 +
19601 +static inline int __user_device(const char __user *name, dev_t *dev,
19602 +       umode_t *mode)
19603 +{
19604 +       struct nameidata nd;
19605 +       int ret;
19606 +
19607 +       if (!name) {
19608 +               *dev = 0;
19609 +               return 0;
19610 +       }
19611 +       ret = user_lpath(name, &nd.path);
19612 +       if (ret)
19613 +               return ret;
19614 +       if (nd.path.dentry->d_inode) {
19615 +               *dev = nd.path.dentry->d_inode->i_rdev;
19616 +               *mode = nd.path.dentry->d_inode->i_mode;
19617 +       }
19618 +       path_put(&nd.path);
19619 +       return 0;
19620 +}
19621 +
19622 +static inline int __mapping_mode(dev_t device, dev_t target,
19623 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19624 +{
19625 +       if (device)
19626 +               *mode = device_mode & S_IFMT;
19627 +       else if (target)
19628 +               *mode = target_mode & S_IFMT;
19629 +       else
19630 +               return -EINVAL;
19631 +
19632 +       /* if both given, device and target mode have to match */
19633 +       if (device && target &&
19634 +               ((device_mode ^ target_mode) & S_IFMT))
19635 +               return -EINVAL;
19636 +       return 0;
19637 +}
19638 +
19639 +
19640 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19641 +       const char __user *target_path, int flags, int set)
19642 +{
19643 +       dev_t device = ~0, target = ~0;
19644 +       umode_t device_mode = 0, target_mode = 0, mode;
19645 +       int ret;
19646 +
19647 +       ret = __user_device(device_path, &device, &device_mode);
19648 +       if (ret)
19649 +               return ret;
19650 +       ret = __user_device(target_path, &target, &target_mode);
19651 +       if (ret)
19652 +               return ret;
19653 +
19654 +       ret = __mapping_mode(device, target,
19655 +               device_mode, target_mode, &mode);
19656 +       if (ret)
19657 +               return ret;
19658 +
19659 +       if (set)
19660 +               return do_set_mapping(vxi, device, target,
19661 +                       flags, mode);
19662 +       else
19663 +               return do_unset_mapping(vxi, device, target,
19664 +                       flags, mode);
19665 +}
19666 +
19667 +
19668 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19669 +{
19670 +       struct vcmd_set_mapping_v0 vc_data;
19671 +
19672 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19673 +               return -EFAULT;
19674 +
19675 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19676 +               vc_data.flags, 1);
19677 +}
19678 +
19679 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19680 +{
19681 +       struct vcmd_set_mapping_v0 vc_data;
19682 +
19683 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19684 +               return -EFAULT;
19685 +
19686 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19687 +               vc_data.flags, 0);
19688 +}
19689 +
19690 +
19691 +#ifdef CONFIG_COMPAT
19692 +
19693 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19694 +{
19695 +       struct vcmd_set_mapping_v0_x32 vc_data;
19696 +
19697 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19698 +               return -EFAULT;
19699 +
19700 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19701 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19702 +}
19703 +
19704 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19705 +{
19706 +       struct vcmd_set_mapping_v0_x32 vc_data;
19707 +
19708 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19709 +               return -EFAULT;
19710 +
19711 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19712 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19713 +}
19714 +
19715 +#endif /* CONFIG_COMPAT */
19716 +
19717 +
19718 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/dlimit.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/dlimit.c
19719 --- linux-2.6.32.10/kernel/vserver/dlimit.c     1970-01-01 01:00:00.000000000 +0100
19720 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/dlimit.c     2009-12-03 20:04:56.000000000 +0100
19721 @@ -0,0 +1,529 @@
19722 +/*
19723 + *  linux/kernel/vserver/dlimit.c
19724 + *
19725 + *  Virtual Server: Context Disk Limits
19726 + *
19727 + *  Copyright (C) 2004-2009  Herbert Pötzl
19728 + *
19729 + *  V0.01  initial version
19730 + *  V0.02  compat32 splitup
19731 + *  V0.03  extended interface
19732 + *
19733 + */
19734 +
19735 +#include <linux/statfs.h>
19736 +#include <linux/sched.h>
19737 +#include <linux/namei.h>
19738 +#include <linux/vs_tag.h>
19739 +#include <linux/vs_dlimit.h>
19740 +#include <linux/vserver/dlimit_cmd.h>
19741 +
19742 +#include <asm/uaccess.h>
19743 +
19744 +/*     __alloc_dl_info()
19745 +
19746 +       * allocate an initialized dl_info struct
19747 +       * doesn't make it visible (hash)                        */
19748 +
19749 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19750 +{
19751 +       struct dl_info *new = NULL;
19752 +
19753 +       vxdprintk(VXD_CBIT(dlim, 5),
19754 +               "alloc_dl_info(%p,%d)*", sb, tag);
19755 +
19756 +       /* would this benefit from a slab cache? */
19757 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19758 +       if (!new)
19759 +               return 0;
19760 +
19761 +       memset(new, 0, sizeof(struct dl_info));
19762 +       new->dl_tag = tag;
19763 +       new->dl_sb = sb;
19764 +       INIT_RCU_HEAD(&new->dl_rcu);
19765 +       INIT_HLIST_NODE(&new->dl_hlist);
19766 +       spin_lock_init(&new->dl_lock);
19767 +       atomic_set(&new->dl_refcnt, 0);
19768 +       atomic_set(&new->dl_usecnt, 0);
19769 +
19770 +       /* rest of init goes here */
19771 +
19772 +       vxdprintk(VXD_CBIT(dlim, 4),
19773 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19774 +       return new;
19775 +}
19776 +
19777 +/*     __dealloc_dl_info()
19778 +
19779 +       * final disposal of dl_info                             */
19780 +
19781 +static void __dealloc_dl_info(struct dl_info *dli)
19782 +{
19783 +       vxdprintk(VXD_CBIT(dlim, 4),
19784 +               "dealloc_dl_info(%p)", dli);
19785 +
19786 +       dli->dl_hlist.next = LIST_POISON1;
19787 +       dli->dl_tag = -1;
19788 +       dli->dl_sb = 0;
19789 +
19790 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19791 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19792 +
19793 +       kfree(dli);
19794 +}
19795 +
19796 +
19797 +/*     hash table for dl_info hash */
19798 +
19799 +#define DL_HASH_SIZE   13
19800 +
19801 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19802 +
19803 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19804 +
19805 +
19806 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19807 +{
19808 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19809 +}
19810 +
19811 +
19812 +
19813 +/*     __hash_dl_info()
19814 +
19815 +       * add the dli to the global hash table
19816 +       * requires the hash_lock to be held                     */
19817 +
19818 +static inline void __hash_dl_info(struct dl_info *dli)
19819 +{
19820 +       struct hlist_head *head;
19821 +
19822 +       vxdprintk(VXD_CBIT(dlim, 6),
19823 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19824 +       get_dl_info(dli);
19825 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19826 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19827 +}
19828 +
19829 +/*     __unhash_dl_info()
19830 +
19831 +       * remove the dli from the global hash table
19832 +       * requires the hash_lock to be held                     */
19833 +
19834 +static inline void __unhash_dl_info(struct dl_info *dli)
19835 +{
19836 +       vxdprintk(VXD_CBIT(dlim, 6),
19837 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19838 +       hlist_del_rcu(&dli->dl_hlist);
19839 +       put_dl_info(dli);
19840 +}
19841 +
19842 +
19843 +/*     __lookup_dl_info()
19844 +
19845 +       * requires the rcu_read_lock()
19846 +       * doesn't increment the dl_refcnt                       */
19847 +
19848 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19849 +{
19850 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19851 +       struct hlist_node *pos;
19852 +       struct dl_info *dli;
19853 +
19854 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19855 +
19856 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19857 +                       return dli;
19858 +               }
19859 +       }
19860 +       return NULL;
19861 +}
19862 +
19863 +
19864 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19865 +{
19866 +       struct dl_info *dli;
19867 +
19868 +       rcu_read_lock();
19869 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19870 +       vxdprintk(VXD_CBIT(dlim, 7),
19871 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19872 +       rcu_read_unlock();
19873 +       return dli;
19874 +}
19875 +
19876 +void rcu_free_dl_info(struct rcu_head *head)
19877 +{
19878 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19879 +       int usecnt, refcnt;
19880 +
19881 +       BUG_ON(!dli || !head);
19882 +
19883 +       usecnt = atomic_read(&dli->dl_usecnt);
19884 +       BUG_ON(usecnt < 0);
19885 +
19886 +       refcnt = atomic_read(&dli->dl_refcnt);
19887 +       BUG_ON(refcnt < 0);
19888 +
19889 +       vxdprintk(VXD_CBIT(dlim, 3),
19890 +               "rcu_free_dl_info(%p)", dli);
19891 +       if (!usecnt)
19892 +               __dealloc_dl_info(dli);
19893 +       else
19894 +               printk("!!! rcu didn't free\n");
19895 +}
19896 +
19897 +
19898 +
19899 +
19900 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19901 +       uint32_t flags, int add)
19902 +{
19903 +       struct path path;
19904 +       int ret;
19905 +
19906 +       ret = user_lpath(name, &path);
19907 +       if (!ret) {
19908 +               struct super_block *sb;
19909 +               struct dl_info *dli;
19910 +
19911 +               ret = -EINVAL;
19912 +               if (!path.dentry->d_inode)
19913 +                       goto out_release;
19914 +               if (!(sb = path.dentry->d_inode->i_sb))
19915 +                       goto out_release;
19916 +
19917 +               if (add) {
19918 +                       dli = __alloc_dl_info(sb, id);
19919 +                       spin_lock(&dl_info_hash_lock);
19920 +
19921 +                       ret = -EEXIST;
19922 +                       if (__lookup_dl_info(sb, id))
19923 +                               goto out_unlock;
19924 +                       __hash_dl_info(dli);
19925 +                       dli = NULL;
19926 +               } else {
19927 +                       spin_lock(&dl_info_hash_lock);
19928 +                       dli = __lookup_dl_info(sb, id);
19929 +
19930 +                       ret = -ESRCH;
19931 +                       if (!dli)
19932 +                               goto out_unlock;
19933 +                       __unhash_dl_info(dli);
19934 +               }
19935 +               ret = 0;
19936 +       out_unlock:
19937 +               spin_unlock(&dl_info_hash_lock);
19938 +               if (add && dli)
19939 +                       __dealloc_dl_info(dli);
19940 +       out_release:
19941 +               path_put(&path);
19942 +       }
19943 +       return ret;
19944 +}
19945 +
19946 +int vc_add_dlimit(uint32_t id, void __user *data)
19947 +{
19948 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19949 +
19950 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19951 +               return -EFAULT;
19952 +
19953 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19954 +}
19955 +
19956 +int vc_rem_dlimit(uint32_t id, void __user *data)
19957 +{
19958 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19959 +
19960 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19961 +               return -EFAULT;
19962 +
19963 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19964 +}
19965 +
19966 +#ifdef CONFIG_COMPAT
19967 +
19968 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19969 +{
19970 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19971 +
19972 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19973 +               return -EFAULT;
19974 +
19975 +       return do_addrem_dlimit(id,
19976 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19977 +}
19978 +
19979 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19980 +{
19981 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19982 +
19983 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19984 +               return -EFAULT;
19985 +
19986 +       return do_addrem_dlimit(id,
19987 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19988 +}
19989 +
19990 +#endif /* CONFIG_COMPAT */
19991 +
19992 +
19993 +static inline
19994 +int do_set_dlimit(uint32_t id, const char __user *name,
19995 +       uint32_t space_used, uint32_t space_total,
19996 +       uint32_t inodes_used, uint32_t inodes_total,
19997 +       uint32_t reserved, uint32_t flags)
19998 +{
19999 +       struct path path;
20000 +       int ret;
20001 +
20002 +       ret = user_lpath(name, &path);
20003 +       if (!ret) {
20004 +               struct super_block *sb;
20005 +               struct dl_info *dli;
20006 +
20007 +               ret = -EINVAL;
20008 +               if (!path.dentry->d_inode)
20009 +                       goto out_release;
20010 +               if (!(sb = path.dentry->d_inode->i_sb))
20011 +                       goto out_release;
20012 +
20013 +               /* sanity checks */
20014 +               if ((reserved != CDLIM_KEEP &&
20015 +                       reserved > 100) ||
20016 +                       (inodes_used != CDLIM_KEEP &&
20017 +                       inodes_used > inodes_total) ||
20018 +                       (space_used != CDLIM_KEEP &&
20019 +                       space_used > space_total))
20020 +                       goto out_release;
20021 +
20022 +               ret = -ESRCH;
20023 +               dli = locate_dl_info(sb, id);
20024 +               if (!dli)
20025 +                       goto out_release;
20026 +
20027 +               spin_lock(&dli->dl_lock);
20028 +
20029 +               if (inodes_used != CDLIM_KEEP)
20030 +                       dli->dl_inodes_used = inodes_used;
20031 +               if (inodes_total != CDLIM_KEEP)
20032 +                       dli->dl_inodes_total = inodes_total;
20033 +               if (space_used != CDLIM_KEEP)
20034 +                       dli->dl_space_used = dlimit_space_32to64(
20035 +                               space_used, flags, DLIMS_USED);
20036 +
20037 +               if (space_total == CDLIM_INFINITY)
20038 +                       dli->dl_space_total = DLIM_INFINITY;
20039 +               else if (space_total != CDLIM_KEEP)
20040 +                       dli->dl_space_total = dlimit_space_32to64(
20041 +                               space_total, flags, DLIMS_TOTAL);
20042 +
20043 +               if (reserved != CDLIM_KEEP)
20044 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
20045 +
20046 +               spin_unlock(&dli->dl_lock);
20047 +
20048 +               put_dl_info(dli);
20049 +               ret = 0;
20050 +
20051 +       out_release:
20052 +               path_put(&path);
20053 +       }
20054 +       return ret;
20055 +}
20056 +
20057 +int vc_set_dlimit(uint32_t id, void __user *data)
20058 +{
20059 +       struct vcmd_ctx_dlimit_v0 vc_data;
20060 +
20061 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20062 +               return -EFAULT;
20063 +
20064 +       return do_set_dlimit(id, vc_data.name,
20065 +               vc_data.space_used, vc_data.space_total,
20066 +               vc_data.inodes_used, vc_data.inodes_total,
20067 +               vc_data.reserved, vc_data.flags);
20068 +}
20069 +
20070 +#ifdef CONFIG_COMPAT
20071 +
20072 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20073 +{
20074 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20075 +
20076 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20077 +               return -EFAULT;
20078 +
20079 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
20080 +               vc_data.space_used, vc_data.space_total,
20081 +               vc_data.inodes_used, vc_data.inodes_total,
20082 +               vc_data.reserved, vc_data.flags);
20083 +}
20084 +
20085 +#endif /* CONFIG_COMPAT */
20086 +
20087 +
20088 +static inline
20089 +int do_get_dlimit(uint32_t id, const char __user *name,
20090 +       uint32_t *space_used, uint32_t *space_total,
20091 +       uint32_t *inodes_used, uint32_t *inodes_total,
20092 +       uint32_t *reserved, uint32_t *flags)
20093 +{
20094 +       struct path path;
20095 +       int ret;
20096 +
20097 +       ret = user_lpath(name, &path);
20098 +       if (!ret) {
20099 +               struct super_block *sb;
20100 +               struct dl_info *dli;
20101 +
20102 +               ret = -EINVAL;
20103 +               if (!path.dentry->d_inode)
20104 +                       goto out_release;
20105 +               if (!(sb = path.dentry->d_inode->i_sb))
20106 +                       goto out_release;
20107 +
20108 +               ret = -ESRCH;
20109 +               dli = locate_dl_info(sb, id);
20110 +               if (!dli)
20111 +                       goto out_release;
20112 +
20113 +               spin_lock(&dli->dl_lock);
20114 +               *inodes_used = dli->dl_inodes_used;
20115 +               *inodes_total = dli->dl_inodes_total;
20116 +
20117 +               *space_used = dlimit_space_64to32(
20118 +                       dli->dl_space_used, flags, DLIMS_USED);
20119 +
20120 +               if (dli->dl_space_total == DLIM_INFINITY)
20121 +                       *space_total = CDLIM_INFINITY;
20122 +               else
20123 +                       *space_total = dlimit_space_64to32(
20124 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
20125 +
20126 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20127 +               spin_unlock(&dli->dl_lock);
20128 +
20129 +               put_dl_info(dli);
20130 +               ret = -EFAULT;
20131 +
20132 +               ret = 0;
20133 +       out_release:
20134 +               path_put(&path);
20135 +       }
20136 +       return ret;
20137 +}
20138 +
20139 +
20140 +int vc_get_dlimit(uint32_t id, void __user *data)
20141 +{
20142 +       struct vcmd_ctx_dlimit_v0 vc_data;
20143 +       int ret;
20144 +
20145 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20146 +               return -EFAULT;
20147 +
20148 +       ret = do_get_dlimit(id, vc_data.name,
20149 +               &vc_data.space_used, &vc_data.space_total,
20150 +               &vc_data.inodes_used, &vc_data.inodes_total,
20151 +               &vc_data.reserved, &vc_data.flags);
20152 +       if (ret)
20153 +               return ret;
20154 +
20155 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20156 +               return -EFAULT;
20157 +       return 0;
20158 +}
20159 +
20160 +#ifdef CONFIG_COMPAT
20161 +
20162 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20163 +{
20164 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20165 +       int ret;
20166 +
20167 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20168 +               return -EFAULT;
20169 +
20170 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20171 +               &vc_data.space_used, &vc_data.space_total,
20172 +               &vc_data.inodes_used, &vc_data.inodes_total,
20173 +               &vc_data.reserved, &vc_data.flags);
20174 +       if (ret)
20175 +               return ret;
20176 +
20177 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20178 +               return -EFAULT;
20179 +       return 0;
20180 +}
20181 +
20182 +#endif /* CONFIG_COMPAT */
20183 +
20184 +
20185 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20186 +{
20187 +       struct dl_info *dli;
20188 +       __u64 blimit, bfree, bavail;
20189 +       __u32 ifree;
20190 +
20191 +       dli = locate_dl_info(sb, dx_current_tag());
20192 +       if (!dli)
20193 +               return;
20194 +
20195 +       spin_lock(&dli->dl_lock);
20196 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20197 +               goto no_ilim;
20198 +
20199 +       /* reduce max inodes available to limit */
20200 +       if (buf->f_files > dli->dl_inodes_total)
20201 +               buf->f_files = dli->dl_inodes_total;
20202 +
20203 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20204 +       /* reduce free inodes to min */
20205 +       if (ifree < buf->f_ffree)
20206 +               buf->f_ffree = ifree;
20207 +
20208 +no_ilim:
20209 +       if (dli->dl_space_total == DLIM_INFINITY)
20210 +               goto no_blim;
20211 +
20212 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20213 +
20214 +       if (dli->dl_space_total < dli->dl_space_used)
20215 +               bfree = 0;
20216 +       else
20217 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20218 +                       >> sb->s_blocksize_bits;
20219 +
20220 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20221 +       if (bavail < dli->dl_space_used)
20222 +               bavail = 0;
20223 +       else
20224 +               bavail = (bavail - dli->dl_space_used)
20225 +                       >> sb->s_blocksize_bits;
20226 +
20227 +       /* reduce max space available to limit */
20228 +       if (buf->f_blocks > blimit)
20229 +               buf->f_blocks = blimit;
20230 +
20231 +       /* reduce free space to min */
20232 +       if (bfree < buf->f_bfree)
20233 +               buf->f_bfree = bfree;
20234 +
20235 +       /* reduce avail space to min */
20236 +       if (bavail < buf->f_bavail)
20237 +               buf->f_bavail = bavail;
20238 +
20239 +no_blim:
20240 +       spin_unlock(&dli->dl_lock);
20241 +       put_dl_info(dli);
20242 +
20243 +       return;
20244 +}
20245 +
20246 +#include <linux/module.h>
20247 +
20248 +EXPORT_SYMBOL_GPL(locate_dl_info);
20249 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20250 +
20251 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/helper.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/helper.c
20252 --- linux-2.6.32.10/kernel/vserver/helper.c     1970-01-01 01:00:00.000000000 +0100
20253 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/helper.c     2009-12-03 22:20:22.000000000 +0100
20254 @@ -0,0 +1,223 @@
20255 +/*
20256 + *  linux/kernel/vserver/helper.c
20257 + *
20258 + *  Virtual Context Support
20259 + *
20260 + *  Copyright (C) 2004-2007  Herbert Pötzl
20261 + *
20262 + *  V0.01  basic helper
20263 + *
20264 + */
20265 +
20266 +#include <linux/kmod.h>
20267 +#include <linux/reboot.h>
20268 +#include <linux/vs_context.h>
20269 +#include <linux/vs_network.h>
20270 +#include <linux/vserver/signal.h>
20271 +
20272 +
20273 +char vshelper_path[255] = "/sbin/vshelper";
20274 +
20275 +
20276 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20277 +{
20278 +       int ret;
20279 +
20280 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20281 +               printk( KERN_WARNING
20282 +                       "%s: (%s %s) returned %s with %d\n",
20283 +                       name, argv[1], argv[2],
20284 +                       sync ? "sync" : "async", ret);
20285 +       }
20286 +       vxdprintk(VXD_CBIT(switch, 4),
20287 +               "%s: (%s %s) returned %s with %d",
20288 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20289 +       return ret;
20290 +}
20291 +
20292 +/*
20293 + *      vshelper path is set via /proc/sys
20294 + *      invoked by vserver sys_reboot(), with
20295 + *      the following arguments
20296 + *
20297 + *      argv [0] = vshelper_path;
20298 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20299 + *      argv [2] = context identifier
20300 + *
20301 + *      envp [*] = type-specific parameters
20302 + */
20303 +
20304 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20305 +{
20306 +       char id_buf[8], cmd_buf[16];
20307 +       char uid_buf[16], pid_buf[16];
20308 +       int ret;
20309 +
20310 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20311 +       char *envp[] = {"HOME=/", "TERM=linux",
20312 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20313 +                       uid_buf, pid_buf, cmd_buf, 0};
20314 +
20315 +       if (vx_info_state(vxi, VXS_HELPER))
20316 +               return -EAGAIN;
20317 +       vxi->vx_state |= VXS_HELPER;
20318 +
20319 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20320 +
20321 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20322 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
20323 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20324 +
20325 +       switch (cmd) {
20326 +       case LINUX_REBOOT_CMD_RESTART:
20327 +               argv[1] = "restart";
20328 +               break;
20329 +
20330 +       case LINUX_REBOOT_CMD_HALT:
20331 +               argv[1] = "halt";
20332 +               break;
20333 +
20334 +       case LINUX_REBOOT_CMD_POWER_OFF:
20335 +               argv[1] = "poweroff";
20336 +               break;
20337 +
20338 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20339 +               argv[1] = "swsusp";
20340 +               break;
20341 +
20342 +       case LINUX_REBOOT_CMD_OOM:
20343 +               argv[1] = "oom";
20344 +               break;
20345 +
20346 +       default:
20347 +               vxi->vx_state &= ~VXS_HELPER;
20348 +               return 0;
20349 +       }
20350 +
20351 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20352 +       vxi->vx_state &= ~VXS_HELPER;
20353 +       __wakeup_vx_info(vxi);
20354 +       return (ret) ? -EPERM : 0;
20355 +}
20356 +
20357 +
20358 +long vs_reboot(unsigned int cmd, void __user *arg)
20359 +{
20360 +       struct vx_info *vxi = current_vx_info();
20361 +       long ret = 0;
20362 +
20363 +       vxdprintk(VXD_CBIT(misc, 5),
20364 +               "vs_reboot(%p[#%d],%u)",
20365 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20366 +
20367 +       ret = vs_reboot_helper(vxi, cmd, arg);
20368 +       if (ret)
20369 +               return ret;
20370 +
20371 +       vxi->reboot_cmd = cmd;
20372 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20373 +               switch (cmd) {
20374 +               case LINUX_REBOOT_CMD_RESTART:
20375 +               case LINUX_REBOOT_CMD_HALT:
20376 +               case LINUX_REBOOT_CMD_POWER_OFF:
20377 +                       vx_info_kill(vxi, 0, SIGKILL);
20378 +                       vx_info_kill(vxi, 1, SIGKILL);
20379 +               default:
20380 +                       break;
20381 +               }
20382 +       }
20383 +       return 0;
20384 +}
20385 +
20386 +long vs_oom_action(unsigned int cmd)
20387 +{
20388 +       struct vx_info *vxi = current_vx_info();
20389 +       long ret = 0;
20390 +
20391 +       vxdprintk(VXD_CBIT(misc, 5),
20392 +               "vs_oom_action(%p[#%d],%u)",
20393 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20394 +
20395 +       ret = vs_reboot_helper(vxi, cmd, NULL);
20396 +       if (ret)
20397 +               return ret;
20398 +
20399 +       vxi->reboot_cmd = cmd;
20400 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20401 +               vx_info_kill(vxi, 0, SIGKILL);
20402 +               vx_info_kill(vxi, 1, SIGKILL);
20403 +       }
20404 +       return 0;
20405 +}
20406 +
20407 +/*
20408 + *      argv [0] = vshelper_path;
20409 + *      argv [1] = action: "startup", "shutdown"
20410 + *      argv [2] = context identifier
20411 + *
20412 + *      envp [*] = type-specific parameters
20413 + */
20414 +
20415 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20416 +{
20417 +       char id_buf[8], cmd_buf[16];
20418 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20419 +       char *envp[] = {"HOME=/", "TERM=linux",
20420 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20421 +
20422 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20423 +               return 0;
20424 +
20425 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20426 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20427 +
20428 +       switch (cmd) {
20429 +       case VSC_STARTUP:
20430 +               argv[1] = "startup";
20431 +               break;
20432 +       case VSC_SHUTDOWN:
20433 +               argv[1] = "shutdown";
20434 +               break;
20435 +       default:
20436 +               return 0;
20437 +       }
20438 +
20439 +       return do_vshelper(vshelper_path, argv, envp, 1);
20440 +}
20441 +
20442 +
20443 +/*
20444 + *      argv [0] = vshelper_path;
20445 + *      argv [1] = action: "netup", "netdown"
20446 + *      argv [2] = context identifier
20447 + *
20448 + *      envp [*] = type-specific parameters
20449 + */
20450 +
20451 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20452 +{
20453 +       char id_buf[8], cmd_buf[16];
20454 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20455 +       char *envp[] = {"HOME=/", "TERM=linux",
20456 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20457 +
20458 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20459 +               return 0;
20460 +
20461 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20462 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20463 +
20464 +       switch (cmd) {
20465 +       case VSC_NETUP:
20466 +               argv[1] = "netup";
20467 +               break;
20468 +       case VSC_NETDOWN:
20469 +               argv[1] = "netdown";
20470 +               break;
20471 +       default:
20472 +               return 0;
20473 +       }
20474 +
20475 +       return do_vshelper(vshelper_path, argv, envp, 1);
20476 +}
20477 +
20478 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/history.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/history.c
20479 --- linux-2.6.32.10/kernel/vserver/history.c    1970-01-01 01:00:00.000000000 +0100
20480 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/history.c    2009-12-03 20:04:56.000000000 +0100
20481 @@ -0,0 +1,258 @@
20482 +/*
20483 + *  kernel/vserver/history.c
20484 + *
20485 + *  Virtual Context History Backtrace
20486 + *
20487 + *  Copyright (C) 2004-2007  Herbert Pötzl
20488 + *
20489 + *  V0.01  basic structure
20490 + *  V0.02  hash/unhash and trace
20491 + *  V0.03  preemption fixes
20492 + *
20493 + */
20494 +
20495 +#include <linux/module.h>
20496 +#include <asm/uaccess.h>
20497 +
20498 +#include <linux/vserver/context.h>
20499 +#include <linux/vserver/debug.h>
20500 +#include <linux/vserver/debug_cmd.h>
20501 +#include <linux/vserver/history.h>
20502 +
20503 +
20504 +#ifdef CONFIG_VSERVER_HISTORY
20505 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20506 +#else
20507 +#define VXH_SIZE       64
20508 +#endif
20509 +
20510 +struct _vx_history {
20511 +       unsigned int counter;
20512 +
20513 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20514 +};
20515 +
20516 +
20517 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20518 +
20519 +unsigned volatile int vxh_active = 1;
20520 +
20521 +static atomic_t sequence = ATOMIC_INIT(0);
20522 +
20523 +
20524 +/*     vxh_advance()
20525 +
20526 +       * requires disabled preemption                          */
20527 +
20528 +struct _vx_hist_entry *vxh_advance(void *loc)
20529 +{
20530 +       unsigned int cpu = smp_processor_id();
20531 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20532 +       struct _vx_hist_entry *entry;
20533 +       unsigned int index;
20534 +
20535 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20536 +       entry = &hist->entry[index];
20537 +
20538 +       entry->seq = atomic_inc_return(&sequence);
20539 +       entry->loc = loc;
20540 +       return entry;
20541 +}
20542 +
20543 +EXPORT_SYMBOL_GPL(vxh_advance);
20544 +
20545 +
20546 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20547 +
20548 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20549 +
20550 +
20551 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20552 +
20553 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20554 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20555 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20556 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20557 +
20558 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20559 +{
20560 +       switch (e->type) {
20561 +       case VXH_THROW_OOPS:
20562 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20563 +               break;
20564 +
20565 +       case VXH_GET_VX_INFO:
20566 +       case VXH_PUT_VX_INFO:
20567 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20568 +                       VXH_LOC_ARGS(e),
20569 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20570 +                       VXH_VXI_ARGS(e));
20571 +               break;
20572 +
20573 +       case VXH_INIT_VX_INFO:
20574 +       case VXH_SET_VX_INFO:
20575 +       case VXH_CLR_VX_INFO:
20576 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20577 +                       VXH_LOC_ARGS(e),
20578 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20579 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20580 +                       VXH_VXI_ARGS(e), e->sc.data);
20581 +               break;
20582 +
20583 +       case VXH_CLAIM_VX_INFO:
20584 +       case VXH_RELEASE_VX_INFO:
20585 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20586 +                       VXH_LOC_ARGS(e),
20587 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20588 +                       VXH_VXI_ARGS(e), e->sc.data);
20589 +               break;
20590 +
20591 +       case VXH_ALLOC_VX_INFO:
20592 +       case VXH_DEALLOC_VX_INFO:
20593 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20594 +                       VXH_LOC_ARGS(e),
20595 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20596 +                       VXH_VXI_ARGS(e));
20597 +               break;
20598 +
20599 +       case VXH_HASH_VX_INFO:
20600 +       case VXH_UNHASH_VX_INFO:
20601 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20602 +                       VXH_LOC_ARGS(e),
20603 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20604 +                       VXH_VXI_ARGS(e));
20605 +               break;
20606 +
20607 +       case VXH_LOC_VX_INFO:
20608 +       case VXH_LOOKUP_VX_INFO:
20609 +       case VXH_CREATE_VX_INFO:
20610 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20611 +                       VXH_LOC_ARGS(e),
20612 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20613 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20614 +                       e->ll.arg, VXH_VXI_ARGS(e));
20615 +               break;
20616 +       }
20617 +}
20618 +
20619 +static void __vxh_dump_history(void)
20620 +{
20621 +       unsigned int i, cpu;
20622 +
20623 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20624 +               atomic_read(&sequence), NR_CPUS);
20625 +
20626 +       for (i = 0; i < VXH_SIZE; i++) {
20627 +               for_each_online_cpu(cpu) {
20628 +                       struct _vx_history *hist =
20629 +                               &per_cpu(vx_history_buffer, cpu);
20630 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20631 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20632 +
20633 +                       vxh_dump_entry(entry, cpu);
20634 +               }
20635 +       }
20636 +}
20637 +
20638 +void   vxh_dump_history(void)
20639 +{
20640 +       vxh_active = 0;
20641 +#ifdef CONFIG_SMP
20642 +       local_irq_enable();
20643 +       smp_send_stop();
20644 +       local_irq_disable();
20645 +#endif
20646 +       __vxh_dump_history();
20647 +}
20648 +
20649 +
20650 +/* vserver syscall commands below here */
20651 +
20652 +
20653 +int vc_dump_history(uint32_t id)
20654 +{
20655 +       vxh_active = 0;
20656 +       __vxh_dump_history();
20657 +       vxh_active = 1;
20658 +
20659 +       return 0;
20660 +}
20661 +
20662 +
20663 +int do_read_history(struct __user _vx_hist_entry *data,
20664 +       int cpu, uint32_t *index, uint32_t *count)
20665 +{
20666 +       int pos, ret = 0;
20667 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20668 +       int end = hist->counter;
20669 +       int start = end - VXH_SIZE + 2;
20670 +       int idx = *index;
20671 +
20672 +       /* special case: get current pos */
20673 +       if (!*count) {
20674 +               *index = end;
20675 +               return 0;
20676 +       }
20677 +
20678 +       /* have we lost some data? */
20679 +       if (idx < start)
20680 +               idx = start;
20681 +
20682 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20683 +               struct _vx_hist_entry *entry =
20684 +                       &hist->entry[idx % VXH_SIZE];
20685 +
20686 +               /* send entry to userspace */
20687 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20688 +               if (ret)
20689 +                       break;
20690 +       }
20691 +       /* save new index and count */
20692 +       *index = idx;
20693 +       *count = pos;
20694 +       return ret ? ret : (*index < end);
20695 +}
20696 +
20697 +int vc_read_history(uint32_t id, void __user *data)
20698 +{
20699 +       struct vcmd_read_history_v0 vc_data;
20700 +       int ret;
20701 +
20702 +       if (id >= NR_CPUS)
20703 +               return -EINVAL;
20704 +
20705 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20706 +               return -EFAULT;
20707 +
20708 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20709 +               id, &vc_data.index, &vc_data.count);
20710 +
20711 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20712 +               return -EFAULT;
20713 +       return ret;
20714 +}
20715 +
20716 +#ifdef CONFIG_COMPAT
20717 +
20718 +int vc_read_history_x32(uint32_t id, void __user *data)
20719 +{
20720 +       struct vcmd_read_history_v0_x32 vc_data;
20721 +       int ret;
20722 +
20723 +       if (id >= NR_CPUS)
20724 +               return -EINVAL;
20725 +
20726 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20727 +               return -EFAULT;
20728 +
20729 +       ret = do_read_history((struct __user _vx_hist_entry *)
20730 +               compat_ptr(vc_data.data_ptr),
20731 +               id, &vc_data.index, &vc_data.count);
20732 +
20733 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20734 +               return -EFAULT;
20735 +       return ret;
20736 +}
20737 +
20738 +#endif /* CONFIG_COMPAT */
20739 +
20740 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/inet.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/inet.c
20741 --- linux-2.6.32.10/kernel/vserver/inet.c       1970-01-01 01:00:00.000000000 +0100
20742 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/inet.c       2009-12-03 20:04:56.000000000 +0100
20743 @@ -0,0 +1,225 @@
20744 +
20745 +#include <linux/in.h>
20746 +#include <linux/inetdevice.h>
20747 +#include <linux/vs_inet.h>
20748 +#include <linux/vs_inet6.h>
20749 +#include <linux/vserver/debug.h>
20750 +#include <net/route.h>
20751 +#include <net/addrconf.h>
20752 +
20753 +
20754 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20755 +{
20756 +       int ret = 0;
20757 +
20758 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20759 +               ret = 1;
20760 +       else {
20761 +               struct nx_addr_v4 *ptr;
20762 +
20763 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20764 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20765 +                               ret = 1;
20766 +                               break;
20767 +                       }
20768 +               }
20769 +       }
20770 +
20771 +       vxdprintk(VXD_CBIT(net, 2),
20772 +               "nx_v4_addr_conflict(%p,%p): %d",
20773 +               nxi1, nxi2, ret);
20774 +
20775 +       return ret;
20776 +}
20777 +
20778 +
20779 +#ifdef CONFIG_IPV6
20780 +
20781 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20782 +{
20783 +       int ret = 0;
20784 +
20785 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20786 +               ret = 1;
20787 +       else {
20788 +               struct nx_addr_v6 *ptr;
20789 +
20790 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20791 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20792 +                               ret = 1;
20793 +                               break;
20794 +                       }
20795 +               }
20796 +       }
20797 +
20798 +       vxdprintk(VXD_CBIT(net, 2),
20799 +               "nx_v6_addr_conflict(%p,%p): %d",
20800 +               nxi1, nxi2, ret);
20801 +
20802 +       return ret;
20803 +}
20804 +
20805 +#endif
20806 +
20807 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20808 +{
20809 +       struct in_device *in_dev;
20810 +       struct in_ifaddr **ifap;
20811 +       struct in_ifaddr *ifa;
20812 +       int ret = 0;
20813 +
20814 +       if (!dev)
20815 +               goto out;
20816 +       in_dev = in_dev_get(dev);
20817 +       if (!in_dev)
20818 +               goto out;
20819 +
20820 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20821 +               ifap = &ifa->ifa_next) {
20822 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20823 +                       ret = 1;
20824 +                       break;
20825 +               }
20826 +       }
20827 +       in_dev_put(in_dev);
20828 +out:
20829 +       return ret;
20830 +}
20831 +
20832 +
20833 +#ifdef CONFIG_IPV6
20834 +
20835 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20836 +{
20837 +       struct inet6_dev *in_dev;
20838 +       struct inet6_ifaddr **ifap;
20839 +       struct inet6_ifaddr *ifa;
20840 +       int ret = 0;
20841 +
20842 +       if (!dev)
20843 +               goto out;
20844 +       in_dev = in6_dev_get(dev);
20845 +       if (!in_dev)
20846 +               goto out;
20847 +
20848 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20849 +               ifap = &ifa->if_next) {
20850 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20851 +                       ret = 1;
20852 +                       break;
20853 +               }
20854 +       }
20855 +       in6_dev_put(in_dev);
20856 +out:
20857 +       return ret;
20858 +}
20859 +
20860 +#endif
20861 +
20862 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20863 +{
20864 +       int ret = 1;
20865 +
20866 +       if (!nxi)
20867 +               goto out;
20868 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20869 +               goto out;
20870 +#ifdef CONFIG_IPV6
20871 +       ret = 2;
20872 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20873 +               goto out;
20874 +#endif
20875 +       ret = 0;
20876 +out:
20877 +       vxdprintk(VXD_CBIT(net, 3),
20878 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20879 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20880 +       return ret;
20881 +}
20882 +
20883 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20884 +       struct rtable **rp, struct flowi *fl)
20885 +{
20886 +       if (!nxi)
20887 +               return 0;
20888 +
20889 +       /* FIXME: handle lback only case */
20890 +       if (!NX_IPV4(nxi))
20891 +               return -EPERM;
20892 +
20893 +       vxdprintk(VXD_CBIT(net, 4),
20894 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20895 +               nxi, nxi ? nxi->nx_id : 0,
20896 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20897 +
20898 +       /* single IP is unconditional */
20899 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20900 +               (fl->fl4_src == INADDR_ANY))
20901 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20902 +
20903 +       if (fl->fl4_src == INADDR_ANY) {
20904 +               struct nx_addr_v4 *ptr;
20905 +               __be32 found = 0;
20906 +               int err;
20907 +
20908 +               err = __ip_route_output_key(net, rp, fl);
20909 +               if (!err) {
20910 +                       found = (*rp)->rt_src;
20911 +                       ip_rt_put(*rp);
20912 +                       vxdprintk(VXD_CBIT(net, 4),
20913 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20914 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20915 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20916 +                               goto found;
20917 +               }
20918 +
20919 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20920 +                       __be32 primary = ptr->ip[0].s_addr;
20921 +                       __be32 mask = ptr->mask.s_addr;
20922 +                       __be32 neta = primary & mask;
20923 +
20924 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20925 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20926 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20927 +                               NIPQUAD(mask), NIPQUAD(neta));
20928 +                       if ((found & mask) != neta)
20929 +                               continue;
20930 +
20931 +                       fl->fl4_src = primary;
20932 +                       err = __ip_route_output_key(net, rp, fl);
20933 +                       vxdprintk(VXD_CBIT(net, 4),
20934 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20935 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20936 +                       if (!err) {
20937 +                               found = (*rp)->rt_src;
20938 +                               ip_rt_put(*rp);
20939 +                               if (found == primary)
20940 +                                       goto found;
20941 +                       }
20942 +               }
20943 +               /* still no source ip? */
20944 +               found = ipv4_is_loopback(fl->fl4_dst)
20945 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20946 +       found:
20947 +               /* assign src ip to flow */
20948 +               fl->fl4_src = found;
20949 +
20950 +       } else {
20951 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20952 +                       return -EPERM;
20953 +       }
20954 +
20955 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20956 +               if (ipv4_is_loopback(fl->fl4_dst))
20957 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20958 +               if (ipv4_is_loopback(fl->fl4_src))
20959 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20960 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20961 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20962 +               return -EPERM;
20963 +
20964 +       return 0;
20965 +}
20966 +
20967 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20968 +
20969 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/init.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/init.c
20970 --- linux-2.6.32.10/kernel/vserver/init.c       1970-01-01 01:00:00.000000000 +0100
20971 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/init.c       2009-12-03 20:04:56.000000000 +0100
20972 @@ -0,0 +1,45 @@
20973 +/*
20974 + *  linux/kernel/init.c
20975 + *
20976 + *  Virtual Server Init
20977 + *
20978 + *  Copyright (C) 2004-2007  Herbert Pötzl
20979 + *
20980 + *  V0.01  basic structure
20981 + *
20982 + */
20983 +
20984 +#include <linux/init.h>
20985 +
20986 +int    vserver_register_sysctl(void);
20987 +void   vserver_unregister_sysctl(void);
20988 +
20989 +
20990 +static int __init init_vserver(void)
20991 +{
20992 +       int ret = 0;
20993 +
20994 +#ifdef CONFIG_VSERVER_DEBUG
20995 +       vserver_register_sysctl();
20996 +#endif
20997 +       return ret;
20998 +}
20999 +
21000 +
21001 +static void __exit exit_vserver(void)
21002 +{
21003 +
21004 +#ifdef CONFIG_VSERVER_DEBUG
21005 +       vserver_unregister_sysctl();
21006 +#endif
21007 +       return;
21008 +}
21009 +
21010 +/* FIXME: GFP_ZONETYPES gone
21011 +long vx_slab[GFP_ZONETYPES]; */
21012 +long vx_area;
21013 +
21014 +
21015 +module_init(init_vserver);
21016 +module_exit(exit_vserver);
21017 +
21018 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/inode.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/inode.c
21019 --- linux-2.6.32.10/kernel/vserver/inode.c      1970-01-01 01:00:00.000000000 +0100
21020 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/inode.c      2009-12-03 20:04:56.000000000 +0100
21021 @@ -0,0 +1,433 @@
21022 +/*
21023 + *  linux/kernel/vserver/inode.c
21024 + *
21025 + *  Virtual Server: File System Support
21026 + *
21027 + *  Copyright (C) 2004-2007  Herbert Pötzl
21028 + *
21029 + *  V0.01  separated from vcontext V0.05
21030 + *  V0.02  moved to tag (instead of xid)
21031 + *
21032 + */
21033 +
21034 +#include <linux/tty.h>
21035 +#include <linux/proc_fs.h>
21036 +#include <linux/devpts_fs.h>
21037 +#include <linux/fs.h>
21038 +#include <linux/file.h>
21039 +#include <linux/mount.h>
21040 +#include <linux/parser.h>
21041 +#include <linux/namei.h>
21042 +#include <linux/vserver/inode.h>
21043 +#include <linux/vserver/inode_cmd.h>
21044 +#include <linux/vs_base.h>
21045 +#include <linux/vs_tag.h>
21046 +
21047 +#include <asm/uaccess.h>
21048 +
21049 +
21050 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21051 +{
21052 +       struct proc_dir_entry *entry;
21053 +
21054 +       if (!in || !in->i_sb)
21055 +               return -ESRCH;
21056 +
21057 +       *flags = IATTR_TAG
21058 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
21059 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
21060 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
21061 +               | (IS_COW(in) ? IATTR_COW : 0);
21062 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
21063 +
21064 +       if (S_ISDIR(in->i_mode))
21065 +               *mask |= IATTR_BARRIER;
21066 +
21067 +       if (IS_TAGGED(in)) {
21068 +               *tag = in->i_tag;
21069 +               *mask |= IATTR_TAG;
21070 +       }
21071 +
21072 +       switch (in->i_sb->s_magic) {
21073 +       case PROC_SUPER_MAGIC:
21074 +               entry = PROC_I(in)->pde;
21075 +
21076 +               /* check for specific inodes? */
21077 +               if (entry)
21078 +                       *mask |= IATTR_FLAGS;
21079 +               if (entry)
21080 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
21081 +               else
21082 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21083 +               break;
21084 +
21085 +       case DEVPTS_SUPER_MAGIC:
21086 +               *tag = in->i_tag;
21087 +               *mask |= IATTR_TAG;
21088 +               break;
21089 +
21090 +       default:
21091 +               break;
21092 +       }
21093 +       return 0;
21094 +}
21095 +
21096 +int vc_get_iattr(void __user *data)
21097 +{
21098 +       struct path path;
21099 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
21100 +       int ret;
21101 +
21102 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21103 +               return -EFAULT;
21104 +
21105 +       ret = user_lpath(vc_data.name, &path);
21106 +       if (!ret) {
21107 +               ret = __vc_get_iattr(path.dentry->d_inode,
21108 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21109 +               path_put(&path);
21110 +       }
21111 +       if (ret)
21112 +               return ret;
21113 +
21114 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21115 +               ret = -EFAULT;
21116 +       return ret;
21117 +}
21118 +
21119 +#ifdef CONFIG_COMPAT
21120 +
21121 +int vc_get_iattr_x32(void __user *data)
21122 +{
21123 +       struct path path;
21124 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
21125 +       int ret;
21126 +
21127 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21128 +               return -EFAULT;
21129 +
21130 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21131 +       if (!ret) {
21132 +               ret = __vc_get_iattr(path.dentry->d_inode,
21133 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21134 +               path_put(&path);
21135 +       }
21136 +       if (ret)
21137 +               return ret;
21138 +
21139 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21140 +               ret = -EFAULT;
21141 +       return ret;
21142 +}
21143 +
21144 +#endif /* CONFIG_COMPAT */
21145 +
21146 +
21147 +int vc_fget_iattr(uint32_t fd, void __user *data)
21148 +{
21149 +       struct file *filp;
21150 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
21151 +       int ret;
21152 +
21153 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21154 +               return -EFAULT;
21155 +
21156 +       filp = fget(fd);
21157 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21158 +               return -EBADF;
21159 +
21160 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21161 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
21162 +
21163 +       fput(filp);
21164 +
21165 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21166 +               ret = -EFAULT;
21167 +       return ret;
21168 +}
21169 +
21170 +
21171 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21172 +{
21173 +       struct inode *in = de->d_inode;
21174 +       int error = 0, is_proc = 0, has_tag = 0;
21175 +       struct iattr attr = { 0 };
21176 +
21177 +       if (!in || !in->i_sb)
21178 +               return -ESRCH;
21179 +
21180 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21181 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21182 +               return -EINVAL;
21183 +
21184 +       has_tag = IS_TAGGED(in) ||
21185 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21186 +       if ((*mask & IATTR_TAG) && !has_tag)
21187 +               return -EINVAL;
21188 +
21189 +       mutex_lock(&in->i_mutex);
21190 +       if (*mask & IATTR_TAG) {
21191 +               attr.ia_tag = *tag;
21192 +               attr.ia_valid |= ATTR_TAG;
21193 +       }
21194 +
21195 +       if (*mask & IATTR_FLAGS) {
21196 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21197 +               unsigned int iflags = PROC_I(in)->vx_flags;
21198 +
21199 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21200 +                       | (*flags & IATTR_FLAGS);
21201 +               PROC_I(in)->vx_flags = iflags;
21202 +               if (entry)
21203 +                       entry->vx_flags = iflags;
21204 +       }
21205 +
21206 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
21207 +               IATTR_BARRIER | IATTR_COW)) {
21208 +               int iflags = in->i_flags;
21209 +               int vflags = in->i_vflags;
21210 +
21211 +               if (*mask & IATTR_IMMUTABLE) {
21212 +                       if (*flags & IATTR_IMMUTABLE)
21213 +                               iflags |= S_IMMUTABLE;
21214 +                       else
21215 +                               iflags &= ~S_IMMUTABLE;
21216 +               }
21217 +               if (*mask & IATTR_IXUNLINK) {
21218 +                       if (*flags & IATTR_IXUNLINK)
21219 +                               iflags |= S_IXUNLINK;
21220 +                       else
21221 +                               iflags &= ~S_IXUNLINK;
21222 +               }
21223 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21224 +                       if (*flags & IATTR_BARRIER)
21225 +                               vflags |= V_BARRIER;
21226 +                       else
21227 +                               vflags &= ~V_BARRIER;
21228 +               }
21229 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
21230 +                       if (*flags & IATTR_COW)
21231 +                               vflags |= V_COW;
21232 +                       else
21233 +                               vflags &= ~V_COW;
21234 +               }
21235 +               if (in->i_op && in->i_op->sync_flags) {
21236 +                       error = in->i_op->sync_flags(in, iflags, vflags);
21237 +                       if (error)
21238 +                               goto out;
21239 +               }
21240 +       }
21241 +
21242 +       if (attr.ia_valid) {
21243 +               if (in->i_op && in->i_op->setattr)
21244 +                       error = in->i_op->setattr(de, &attr);
21245 +               else {
21246 +                       error = inode_change_ok(in, &attr);
21247 +                       if (!error)
21248 +                               error = inode_setattr(in, &attr);
21249 +               }
21250 +       }
21251 +
21252 +out:
21253 +       mutex_unlock(&in->i_mutex);
21254 +       return error;
21255 +}
21256 +
21257 +int vc_set_iattr(void __user *data)
21258 +{
21259 +       struct path path;
21260 +       struct vcmd_ctx_iattr_v1 vc_data;
21261 +       int ret;
21262 +
21263 +       if (!capable(CAP_LINUX_IMMUTABLE))
21264 +               return -EPERM;
21265 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21266 +               return -EFAULT;
21267 +
21268 +       ret = user_lpath(vc_data.name, &path);
21269 +       if (!ret) {
21270 +               ret = __vc_set_iattr(path.dentry,
21271 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21272 +               path_put(&path);
21273 +       }
21274 +
21275 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21276 +               ret = -EFAULT;
21277 +       return ret;
21278 +}
21279 +
21280 +#ifdef CONFIG_COMPAT
21281 +
21282 +int vc_set_iattr_x32(void __user *data)
21283 +{
21284 +       struct path path;
21285 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21286 +       int ret;
21287 +
21288 +       if (!capable(CAP_LINUX_IMMUTABLE))
21289 +               return -EPERM;
21290 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21291 +               return -EFAULT;
21292 +
21293 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21294 +       if (!ret) {
21295 +               ret = __vc_set_iattr(path.dentry,
21296 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21297 +               path_put(&path);
21298 +       }
21299 +
21300 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21301 +               ret = -EFAULT;
21302 +       return ret;
21303 +}
21304 +
21305 +#endif /* CONFIG_COMPAT */
21306 +
21307 +int vc_fset_iattr(uint32_t fd, void __user *data)
21308 +{
21309 +       struct file *filp;
21310 +       struct vcmd_ctx_fiattr_v0 vc_data;
21311 +       int ret;
21312 +
21313 +       if (!capable(CAP_LINUX_IMMUTABLE))
21314 +               return -EPERM;
21315 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21316 +               return -EFAULT;
21317 +
21318 +       filp = fget(fd);
21319 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21320 +               return -EBADF;
21321 +
21322 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21323 +               &vc_data.flags, &vc_data.mask);
21324 +
21325 +       fput(filp);
21326 +
21327 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21328 +               return -EFAULT;
21329 +       return ret;
21330 +}
21331 +
21332 +
21333 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21334 +
21335 +static match_table_t tokens = {
21336 +       {Opt_notagcheck, "notagcheck"},
21337 +#ifdef CONFIG_PROPAGATE
21338 +       {Opt_notag, "notag"},
21339 +       {Opt_tag, "tag"},
21340 +       {Opt_tagid, "tagid=%u"},
21341 +#endif
21342 +       {Opt_err, NULL}
21343 +};
21344 +
21345 +
21346 +static void __dx_parse_remove(char *string, char *opt)
21347 +{
21348 +       char *p = strstr(string, opt);
21349 +       char *q = p;
21350 +
21351 +       if (p) {
21352 +               while (*q != '\0' && *q != ',')
21353 +                       q++;
21354 +               while (*q)
21355 +                       *p++ = *q++;
21356 +               while (*p)
21357 +                       *p++ = '\0';
21358 +       }
21359 +}
21360 +
21361 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
21362 +                unsigned long *flags)
21363 +{
21364 +       int set = 0;
21365 +       substring_t args[MAX_OPT_ARGS];
21366 +       int token, option = 0;
21367 +       char *s, *p, *opts;
21368 +
21369 +       if (!string)
21370 +               return 0;
21371 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
21372 +       if (!s)
21373 +               return 0;
21374 +
21375 +       opts = s;
21376 +       while ((p = strsep(&opts, ",")) != NULL) {
21377 +               token = match_token(p, tokens, args);
21378 +
21379 +               vxdprintk(VXD_CBIT(tag, 7),
21380 +                       "dx_parse_tag(»%s«): %d:#%d",
21381 +                       p, token, option);
21382 +
21383 +               switch (token) {
21384 +#ifdef CONFIG_PROPAGATE
21385 +               case Opt_tag:
21386 +                       if (tag)
21387 +                               *tag = 0;
21388 +                       if (remove)
21389 +                               __dx_parse_remove(s, "tag");
21390 +                       *mnt_flags |= MNT_TAGID;
21391 +                       set |= MNT_TAGID;
21392 +                       break;
21393 +               case Opt_notag:
21394 +                       if (remove)
21395 +                               __dx_parse_remove(s, "notag");
21396 +                       *mnt_flags |= MNT_NOTAG;
21397 +                       set |= MNT_NOTAG;
21398 +                       break;
21399 +               case Opt_tagid:
21400 +                       if (tag && !match_int(args, &option))
21401 +                               *tag = option;
21402 +                       if (remove)
21403 +                               __dx_parse_remove(s, "tagid");
21404 +                       *mnt_flags |= MNT_TAGID;
21405 +                       set |= MNT_TAGID;
21406 +                       break;
21407 +#endif
21408 +               case Opt_notagcheck:
21409 +                       if (remove)
21410 +                               __dx_parse_remove(s, "notagcheck");
21411 +                       *flags |= MS_NOTAGCHECK;
21412 +                       set |= MS_NOTAGCHECK;
21413 +                       break;
21414 +               }
21415 +       }
21416 +       if (set)
21417 +               strcpy(string, s);
21418 +       kfree(s);
21419 +       return set;
21420 +}
21421 +
21422 +#ifdef CONFIG_PROPAGATE
21423 +
21424 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21425 +{
21426 +       tag_t new_tag = 0;
21427 +       struct vfsmount *mnt;
21428 +       int propagate;
21429 +
21430 +       if (!nd)
21431 +               return;
21432 +       mnt = nd->path.mnt;
21433 +       if (!mnt)
21434 +               return;
21435 +
21436 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21437 +       if (propagate)
21438 +               new_tag = mnt->mnt_tag;
21439 +
21440 +       vxdprintk(VXD_CBIT(tag, 7),
21441 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21442 +               inode, inode->i_ino, inode->i_tag,
21443 +               new_tag, (propagate) ? 1 : 0);
21444 +
21445 +       if (propagate)
21446 +               inode->i_tag = new_tag;
21447 +}
21448 +
21449 +#include <linux/module.h>
21450 +
21451 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21452 +
21453 +#endif /* CONFIG_PROPAGATE */
21454 +
21455 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/Kconfig
21456 --- linux-2.6.32.10/kernel/vserver/Kconfig      1970-01-01 01:00:00.000000000 +0100
21457 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/Kconfig      2010-02-14 01:02:13.000000000 +0100
21458 @@ -0,0 +1,251 @@
21459 +#
21460 +# Linux VServer configuration
21461 +#
21462 +
21463 +menu "Linux VServer"
21464 +
21465 +config VSERVER_AUTO_LBACK
21466 +       bool    "Automatically Assign Loopback IP"
21467 +       default y
21468 +       help
21469 +         Automatically assign a guest specific loopback
21470 +         IP and add it to the kernel network stack on
21471 +         startup.
21472 +
21473 +config VSERVER_AUTO_SINGLE
21474 +       bool    "Automatic Single IP Special Casing"
21475 +       depends on EXPERIMENTAL
21476 +       default y
21477 +       help
21478 +         This allows network contexts with a single IP to
21479 +         automatically remap 0.0.0.0 bindings to that IP,
21480 +         avoiding further network checks and improving
21481 +         performance.
21482 +
21483 +         (note: such guests do not allow to change the ip
21484 +          on the fly and do not show loopback addresses)
21485 +
21486 +config VSERVER_COWBL
21487 +       bool    "Enable COW Immutable Link Breaking"
21488 +       default y
21489 +       help
21490 +         This enables the COW (Copy-On-Write) link break code.
21491 +         It allows you to treat unified files like normal files
21492 +         when writing to them (which will implicitely break the
21493 +         link and create a copy of the unified file)
21494 +
21495 +config VSERVER_VTIME
21496 +       bool    "Enable Virtualized Guest Time"
21497 +       depends on EXPERIMENTAL
21498 +       default n
21499 +       help
21500 +         This enables per guest time offsets to allow for
21501 +         adjusting the system clock individually per guest.
21502 +         this adds some overhead to the time functions and
21503 +         therefore should not be enabled without good reason.
21504 +
21505 +config VSERVER_DEVICE
21506 +       bool    "Enable Guest Device Mapping"
21507 +       depends on EXPERIMENTAL
21508 +       default n
21509 +       help
21510 +         This enables generic device remapping.
21511 +
21512 +config VSERVER_PROC_SECURE
21513 +       bool    "Enable Proc Security"
21514 +       depends on PROC_FS
21515 +       default y
21516 +       help
21517 +         This configures ProcFS security to initially hide
21518 +         non-process entries for all contexts except the main and
21519 +         spectator context (i.e. for all guests), which is a secure
21520 +         default.
21521 +
21522 +         (note: on 1.2x the entries were visible by default)
21523 +
21524 +config VSERVER_HARDCPU
21525 +       bool    "Enable Hard CPU Limits"
21526 +       default y
21527 +       help
21528 +         Activate the Hard CPU Limits
21529 +
21530 +         This will compile in code that allows the Token Bucket
21531 +         Scheduler to put processes on hold when a context's
21532 +         tokens are depleted (provided that its per-context
21533 +         sched_hard flag is set).
21534 +
21535 +         Processes belonging to that context will not be able
21536 +         to consume CPU resources again until a per-context
21537 +         configured minimum of tokens has been reached.
21538 +
21539 +config VSERVER_IDLETIME
21540 +       bool    "Avoid idle CPUs by skipping Time"
21541 +       depends on VSERVER_HARDCPU
21542 +       default y
21543 +       help
21544 +         This option allows the scheduler to artificially
21545 +         advance time (per cpu) when otherwise the idle
21546 +         task would be scheduled, thus keeping the cpu
21547 +         busy and sharing the available resources among
21548 +         certain contexts.
21549 +
21550 +config VSERVER_IDLELIMIT
21551 +       bool    "Limit the IDLE task"
21552 +       depends on VSERVER_HARDCPU
21553 +       default n
21554 +       help
21555 +         Limit the idle slices, so the the next context
21556 +         will be scheduled as soon as possible.
21557 +
21558 +         This might improve interactivity and latency, but
21559 +         will also marginally increase scheduling overhead.
21560 +
21561 +choice
21562 +       prompt  "Persistent Inode Tagging"
21563 +       default TAGGING_ID24
21564 +       help
21565 +         This adds persistent context information to filesystems
21566 +         mounted with the tagxid option. Tagging is a requirement
21567 +         for per-context disk limits and per-context quota.
21568 +
21569 +
21570 +config TAGGING_NONE
21571 +       bool    "Disabled"
21572 +       help
21573 +         do not store per-context information in inodes.
21574 +
21575 +config TAGGING_UID16
21576 +       bool    "UID16/GID32"
21577 +       help
21578 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21579 +
21580 +config TAGGING_GID16
21581 +       bool    "UID32/GID16"
21582 +       help
21583 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21584 +
21585 +config TAGGING_ID24
21586 +       bool    "UID24/GID24"
21587 +       help
21588 +         uses the upper 8bit from UID and GID for XID tagging
21589 +         which leaves 24bit for UID/GID each, which should be
21590 +         more than sufficient for normal use.
21591 +
21592 +config TAGGING_INTERN
21593 +       bool    "UID32/GID32"
21594 +       help
21595 +         this uses otherwise reserved inode fields in the on
21596 +         disk representation, which limits the use to a few
21597 +         filesystems (currently ext2 and ext3)
21598 +
21599 +endchoice
21600 +
21601 +config TAG_NFSD
21602 +       bool    "Tag NFSD User Auth and Files"
21603 +       default n
21604 +       help
21605 +         Enable this if you do want the in-kernel NFS
21606 +         Server to use the tagging specified above.
21607 +         (will require patched clients too)
21608 +
21609 +config VSERVER_PRIVACY
21610 +       bool    "Honor Privacy Aspects of Guests"
21611 +       default n
21612 +       help
21613 +         When enabled, most context checks will disallow
21614 +         access to structures assigned to a specific context,
21615 +         like ptys or loop devices.
21616 +
21617 +config VSERVER_CONTEXTS
21618 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21619 +       range 1 65533
21620 +       default "768"   if 64BIT
21621 +       default "256"
21622 +       help
21623 +         This setting will optimize certain data structures
21624 +         and memory allocations according to the expected
21625 +         maximum.
21626 +
21627 +         note: this is not a strict upper limit.
21628 +
21629 +config VSERVER_WARN
21630 +       bool    "VServer Warnings"
21631 +       default y
21632 +       help
21633 +         This enables various runtime warnings, which will
21634 +         notify about potential manipulation attempts or
21635 +         resource shortage. It is generally considered to
21636 +         be a good idea to have that enabled.
21637 +
21638 +config VSERVER_DEBUG
21639 +       bool    "VServer Debugging Code"
21640 +       default n
21641 +       help
21642 +         Set this to yes if you want to be able to activate
21643 +         debugging output at runtime. It adds a very small
21644 +         overhead to all vserver related functions and
21645 +         increases the kernel size by about 20k.
21646 +
21647 +config VSERVER_HISTORY
21648 +       bool    "VServer History Tracing"
21649 +       depends on VSERVER_DEBUG
21650 +       default n
21651 +       help
21652 +         Set this to yes if you want to record the history of
21653 +         linux-vserver activities, so they can be replayed in
21654 +         the event of a kernel panic or oops.
21655 +
21656 +config VSERVER_HISTORY_SIZE
21657 +       int     "Per-CPU History Size (32-65536)"
21658 +       depends on VSERVER_HISTORY
21659 +       range 32 65536
21660 +       default 64
21661 +       help
21662 +         This allows you to specify the number of entries in
21663 +         the per-CPU history buffer.
21664 +
21665 +config VSERVER_MONITOR
21666 +       bool    "VServer Scheduling Monitor"
21667 +       depends on VSERVER_DISABLED
21668 +       default n
21669 +       help
21670 +         Set this to yes if you want to record the scheduling
21671 +         decisions, so that they can be relayed to userspace
21672 +         for detailed analysis.
21673 +
21674 +config VSERVER_MONITOR_SIZE
21675 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21676 +       depends on VSERVER_MONITOR
21677 +       range 32 65536
21678 +       default 1024
21679 +       help
21680 +         This allows you to specify the number of entries in
21681 +         the per-CPU scheduling monitor buffer.
21682 +
21683 +config VSERVER_MONITOR_SYNC
21684 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21685 +       depends on VSERVER_MONITOR
21686 +       range 0 65536
21687 +       default 256
21688 +       help
21689 +         This allows you to specify the interval in ticks
21690 +         when a time sync entry is inserted.
21691 +
21692 +endmenu
21693 +
21694 +
21695 +config VSERVER
21696 +       bool
21697 +       default y
21698 +       select NAMESPACES
21699 +       select UTS_NS
21700 +       select IPC_NS
21701 +       select USER_NS
21702 +       select SYSVIPC
21703 +
21704 +config VSERVER_SECURITY
21705 +       bool
21706 +       depends on SECURITY
21707 +       default y
21708 +       select SECURITY_CAPABILITIES
21709 +
21710 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/limit.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/limit.c
21711 --- linux-2.6.32.10/kernel/vserver/limit.c      1970-01-01 01:00:00.000000000 +0100
21712 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/limit.c      2010-03-02 21:11:00.000000000 +0100
21713 @@ -0,0 +1,387 @@
21714 +/*
21715 + *  linux/kernel/vserver/limit.c
21716 + *
21717 + *  Virtual Server: Context Limits
21718 + *
21719 + *  Copyright (C) 2004-2010  Herbert Pötzl
21720 + *
21721 + *  V0.01  broken out from vcontext V0.05
21722 + *  V0.02  changed vcmds to vxi arg
21723 + *  V0.03  added memory cgroup support
21724 + *
21725 + */
21726 +
21727 +#include <linux/sched.h>
21728 +#include <linux/module.h>
21729 +#include <linux/memcontrol.h>
21730 +#include <linux/res_counter.h>
21731 +#include <linux/vs_limit.h>
21732 +#include <linux/vserver/limit.h>
21733 +#include <linux/vserver/limit_cmd.h>
21734 +
21735 +#include <asm/uaccess.h>
21736 +
21737 +
21738 +const char *vlimit_name[NUM_LIMITS] = {
21739 +       [RLIMIT_CPU]            = "CPU",
21740 +       [RLIMIT_RSS]            = "RSS",
21741 +       [RLIMIT_NPROC]          = "NPROC",
21742 +       [RLIMIT_NOFILE]         = "NOFILE",
21743 +       [RLIMIT_MEMLOCK]        = "VML",
21744 +       [RLIMIT_AS]             = "VM",
21745 +       [RLIMIT_LOCKS]          = "LOCKS",
21746 +       [RLIMIT_SIGPENDING]     = "SIGP",
21747 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21748 +
21749 +       [VLIMIT_NSOCK]          = "NSOCK",
21750 +       [VLIMIT_OPENFD]         = "OPENFD",
21751 +       [VLIMIT_ANON]           = "ANON",
21752 +       [VLIMIT_SHMEM]          = "SHMEM",
21753 +       [VLIMIT_DENTRY]         = "DENTRY",
21754 +};
21755 +
21756 +EXPORT_SYMBOL_GPL(vlimit_name);
21757 +
21758 +#define MASK_ENTRY(x)  (1 << (x))
21759 +
21760 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21761 +               /* minimum */
21762 +       0
21763 +       ,       /* softlimit */
21764 +       MASK_ENTRY( RLIMIT_RSS          ) |
21765 +       MASK_ENTRY( VLIMIT_ANON         ) |
21766 +       0
21767 +       ,       /* maximum */
21768 +       MASK_ENTRY( RLIMIT_RSS          ) |
21769 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21770 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21771 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21772 +       MASK_ENTRY( RLIMIT_AS           ) |
21773 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21774 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21775 +
21776 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21777 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21778 +       MASK_ENTRY( VLIMIT_ANON         ) |
21779 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21780 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21781 +       0
21782 +};
21783 +               /* accounting only */
21784 +uint32_t account_mask =
21785 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21786 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21787 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21788 +       0;
21789 +
21790 +
21791 +static int is_valid_vlimit(int id)
21792 +{
21793 +       uint32_t mask = vlimit_mask.minimum |
21794 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21795 +       return mask & (1 << id);
21796 +}
21797 +
21798 +static int is_accounted_vlimit(int id)
21799 +{
21800 +       if (is_valid_vlimit(id))
21801 +               return 1;
21802 +       return account_mask & (1 << id);
21803 +}
21804 +
21805 +
21806 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21807 +{
21808 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21809 +       return VX_VLIM(limit);
21810 +}
21811 +
21812 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21813 +{
21814 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21815 +       return VX_VLIM(limit);
21816 +}
21817 +
21818 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21819 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21820 +{
21821 +       if (!is_valid_vlimit(id))
21822 +               return -EINVAL;
21823 +
21824 +       if (minimum)
21825 +               *minimum = CRLIM_UNSET;
21826 +       if (softlimit)
21827 +               *softlimit = vc_get_soft(vxi, id);
21828 +       if (maximum)
21829 +               *maximum = vc_get_hard(vxi, id);
21830 +       return 0;
21831 +}
21832 +
21833 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21834 +{
21835 +       struct vcmd_ctx_rlimit_v0 vc_data;
21836 +       int ret;
21837 +
21838 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21839 +               return -EFAULT;
21840 +
21841 +       ret = do_get_rlimit(vxi, vc_data.id,
21842 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21843 +       if (ret)
21844 +               return ret;
21845 +
21846 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21847 +               return -EFAULT;
21848 +       return 0;
21849 +}
21850 +
21851 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21852 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21853 +{
21854 +       if (!is_valid_vlimit(id))
21855 +               return -EINVAL;
21856 +
21857 +       if (maximum != CRLIM_KEEP)
21858 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21859 +       if (softlimit != CRLIM_KEEP)
21860 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21861 +
21862 +       /* clamp soft limit */
21863 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21864 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21865 +
21866 +       return 0;
21867 +}
21868 +
21869 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21870 +{
21871 +       struct vcmd_ctx_rlimit_v0 vc_data;
21872 +
21873 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21874 +               return -EFAULT;
21875 +
21876 +       return do_set_rlimit(vxi, vc_data.id,
21877 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21878 +}
21879 +
21880 +#ifdef CONFIG_IA32_EMULATION
21881 +
21882 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21883 +{
21884 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21885 +
21886 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21887 +               return -EFAULT;
21888 +
21889 +       return do_set_rlimit(vxi, vc_data.id,
21890 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21891 +}
21892 +
21893 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21894 +{
21895 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21896 +       int ret;
21897 +
21898 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21899 +               return -EFAULT;
21900 +
21901 +       ret = do_get_rlimit(vxi, vc_data.id,
21902 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21903 +       if (ret)
21904 +               return ret;
21905 +
21906 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21907 +               return -EFAULT;
21908 +       return 0;
21909 +}
21910 +
21911 +#endif /* CONFIG_IA32_EMULATION */
21912 +
21913 +
21914 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21915 +{
21916 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21917 +               return -EFAULT;
21918 +       return 0;
21919 +}
21920 +
21921 +
21922 +static inline void vx_reset_hits(struct _vx_limit *limit)
21923 +{
21924 +       int lim;
21925 +
21926 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21927 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21928 +       }
21929 +}
21930 +
21931 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
21932 +{
21933 +       vx_reset_hits(&vxi->limit);
21934 +       return 0;
21935 +}
21936 +
21937 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21938 +{
21939 +       rlim_t value;
21940 +       int lim;
21941 +
21942 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21943 +               value = __rlim_get(limit, lim);
21944 +               __rlim_rmax(limit, lim) = value;
21945 +               __rlim_rmin(limit, lim) = value;
21946 +       }
21947 +}
21948 +
21949 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21950 +{
21951 +       vx_reset_minmax(&vxi->limit);
21952 +       return 0;
21953 +}
21954 +
21955 +
21956 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21957 +{
21958 +       struct vcmd_rlimit_stat_v0 vc_data;
21959 +       struct _vx_limit *limit = &vxi->limit;
21960 +       int id;
21961 +
21962 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21963 +               return -EFAULT;
21964 +
21965 +       id = vc_data.id;
21966 +       if (!is_accounted_vlimit(id))
21967 +               return -EINVAL;
21968 +
21969 +       vx_limit_fixup(limit, id);
21970 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21971 +       vc_data.value = __rlim_get(limit, id);
21972 +       vc_data.minimum = __rlim_rmin(limit, id);
21973 +       vc_data.maximum = __rlim_rmax(limit, id);
21974 +
21975 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21976 +               return -EFAULT;
21977 +       return 0;
21978 +}
21979 +
21980 +
21981 +void vx_vsi_meminfo(struct sysinfo *val)
21982 +{
21983 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
21984 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
21985 +       u64 res_limit, res_usage;
21986 +
21987 +       if (!mcg)
21988 +               return;
21989 +
21990 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
21991 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
21992 +
21993 +       if (res_limit != RESOURCE_MAX)
21994 +               val->totalram = (res_limit >> PAGE_SHIFT);
21995 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
21996 +       val->bufferram = 0;
21997 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR */
21998 +       struct vx_info *vxi = current_vx_info();
21999 +       unsigned long totalram, freeram;
22000 +       rlim_t v;
22001 +
22002 +       /* we blindly accept the max */
22003 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22004 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
22005 +
22006 +       /* total minus used equals free */
22007 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22008 +       freeram = (v < totalram) ? totalram - v : 0;
22009 +
22010 +       val->totalram = totalram;
22011 +       val->freeram = freeram;
22012 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
22013 +       val->totalhigh = 0;
22014 +       val->freehigh = 0;
22015 +       return;
22016 +}
22017 +
22018 +void vx_vsi_swapinfo(struct sysinfo *val)
22019 +{
22020 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
22021 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22022 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
22023 +       s64 swap_limit, swap_usage;
22024 +
22025 +       if (!mcg)
22026 +               return;
22027 +
22028 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
22029 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
22030 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
22031 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
22032 +
22033 +       if (res_limit == RESOURCE_MAX)
22034 +               return;
22035 +
22036 +       swap_limit = memsw_limit - res_limit;
22037 +       if (memsw_limit != RESOURCE_MAX)
22038 +               val->totalswap = swap_limit >> PAGE_SHIFT;
22039 +
22040 +       swap_usage = memsw_usage - res_usage;
22041 +       val->freeswap = (swap_usage < swap_limit) ?
22042 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
22043 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
22044 +       struct vx_info *vxi = current_vx_info();
22045 +       unsigned long totalswap, freeswap;
22046 +       rlim_t v, w;
22047 +
22048 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22049 +       if (v == RLIM_INFINITY) {
22050 +               val->freeswap = val->totalswap;
22051 +               return;
22052 +       }
22053 +
22054 +       /* we blindly accept the max */
22055 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
22056 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
22057 +
22058 +       /* currently 'used' swap */
22059 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22060 +       w -= (w > v) ? v : w;
22061 +
22062 +       /* total minus used equals free */
22063 +       freeswap = (w < totalswap) ? totalswap - w : 0;
22064 +
22065 +       val->totalswap = totalswap;
22066 +       val->freeswap = freeswap;
22067 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
22068 +       return;
22069 +}
22070 +
22071 +long vx_vsi_cached(struct sysinfo *val)
22072 +{
22073 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22074 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22075 +
22076 +       return mem_cgroup_stat_read_cache(mcg);
22077 +#else
22078 +       return 0;
22079 +#endif
22080 +}
22081 +
22082 +
22083 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
22084 +{
22085 +       struct vx_info *vxi = mm->mm_vx_info;
22086 +       unsigned long points;
22087 +       rlim_t v, w;
22088 +
22089 +       if (!vxi)
22090 +               return 0;
22091 +
22092 +       points = vxi->vx_badness_bias;
22093 +
22094 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22095 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22096 +       points += (v > w) ? (v - w) : 0;
22097 +
22098 +       return points;
22099 +}
22100 +
22101 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/limit_init.h linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/limit_init.h
22102 --- linux-2.6.32.10/kernel/vserver/limit_init.h 1970-01-01 01:00:00.000000000 +0100
22103 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/limit_init.h 2009-12-03 20:04:56.000000000 +0100
22104 @@ -0,0 +1,31 @@
22105 +
22106 +
22107 +static inline void vx_info_init_limit(struct _vx_limit *limit)
22108 +{
22109 +       int lim;
22110 +
22111 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22112 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
22113 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
22114 +               __rlim_set(limit, lim, 0);
22115 +               atomic_set(&__rlim_lhit(limit, lim), 0);
22116 +               __rlim_rmin(limit, lim) = 0;
22117 +               __rlim_rmax(limit, lim) = 0;
22118 +       }
22119 +}
22120 +
22121 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
22122 +{
22123 +       rlim_t value;
22124 +       int lim;
22125 +
22126 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22127 +               if ((1 << lim) & VLIM_NOCHECK)
22128 +                       continue;
22129 +               value = __rlim_get(limit, lim);
22130 +               vxwprintk_xid(value,
22131 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
22132 +                       limit, vlimit_name[lim], lim, (long)value);
22133 +       }
22134 +}
22135 +
22136 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/limit_proc.h linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/limit_proc.h
22137 --- linux-2.6.32.10/kernel/vserver/limit_proc.h 1970-01-01 01:00:00.000000000 +0100
22138 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/limit_proc.h 2009-12-03 20:04:56.000000000 +0100
22139 @@ -0,0 +1,57 @@
22140 +#ifndef _VX_LIMIT_PROC_H
22141 +#define _VX_LIMIT_PROC_H
22142 +
22143 +#include <linux/vserver/limit_int.h>
22144 +
22145 +
22146 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
22147 +#define VX_LIMIT_TOP   \
22148 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
22149 +
22150 +#define VX_LIMIT_ARG(r)                                \
22151 +       (unsigned long)__rlim_get(limit, r),    \
22152 +       (unsigned long)__rlim_rmin(limit, r),   \
22153 +       (unsigned long)__rlim_rmax(limit, r),   \
22154 +       VX_VLIM(__rlim_soft(limit, r)),         \
22155 +       VX_VLIM(__rlim_hard(limit, r)),         \
22156 +       atomic_read(&__rlim_lhit(limit, r))
22157 +
22158 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
22159 +{
22160 +       vx_limit_fixup(limit, -1);
22161 +       return sprintf(buffer, VX_LIMIT_TOP
22162 +               "PROC"  VX_LIMIT_FMT
22163 +               "VM"    VX_LIMIT_FMT
22164 +               "VML"   VX_LIMIT_FMT
22165 +               "RSS"   VX_LIMIT_FMT
22166 +               "ANON"  VX_LIMIT_FMT
22167 +               "RMAP"  VX_LIMIT_FMT
22168 +               "FILES" VX_LIMIT_FMT
22169 +               "OFD"   VX_LIMIT_FMT
22170 +               "LOCKS" VX_LIMIT_FMT
22171 +               "SOCK"  VX_LIMIT_FMT
22172 +               "MSGQ"  VX_LIMIT_FMT
22173 +               "SHM"   VX_LIMIT_FMT
22174 +               "SEMA"  VX_LIMIT_FMT
22175 +               "SEMS"  VX_LIMIT_FMT
22176 +               "DENT"  VX_LIMIT_FMT,
22177 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22178 +               VX_LIMIT_ARG(RLIMIT_AS),
22179 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22180 +               VX_LIMIT_ARG(RLIMIT_RSS),
22181 +               VX_LIMIT_ARG(VLIMIT_ANON),
22182 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22183 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22184 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22185 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22186 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22187 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22188 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22189 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22190 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22191 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22192 +}
22193 +
22194 +#endif /* _VX_LIMIT_PROC_H */
22195 +
22196 +
22197 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/Makefile linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/Makefile
22198 --- linux-2.6.32.10/kernel/vserver/Makefile     1970-01-01 01:00:00.000000000 +0100
22199 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/Makefile     2009-12-03 20:04:56.000000000 +0100
22200 @@ -0,0 +1,18 @@
22201 +#
22202 +# Makefile for the Linux vserver routines.
22203 +#
22204 +
22205 +
22206 +obj-y          += vserver.o
22207 +
22208 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
22209 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
22210 +                  dlimit.o tag.o
22211 +
22212 +vserver-$(CONFIG_INET) += inet.o
22213 +vserver-$(CONFIG_PROC_FS) += proc.o
22214 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
22215 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
22216 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
22217 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
22218 +
22219 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/monitor.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/monitor.c
22220 --- linux-2.6.32.10/kernel/vserver/monitor.c    1970-01-01 01:00:00.000000000 +0100
22221 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/monitor.c    2009-12-03 20:04:56.000000000 +0100
22222 @@ -0,0 +1,138 @@
22223 +/*
22224 + *  kernel/vserver/monitor.c
22225 + *
22226 + *  Virtual Context Scheduler Monitor
22227 + *
22228 + *  Copyright (C) 2006-2007 Herbert Pötzl
22229 + *
22230 + *  V0.01  basic design
22231 + *
22232 + */
22233 +
22234 +#include <linux/module.h>
22235 +#include <linux/jiffies.h>
22236 +#include <asm/uaccess.h>
22237 +#include <asm/atomic.h>
22238 +
22239 +#include <linux/vserver/monitor.h>
22240 +#include <linux/vserver/debug_cmd.h>
22241 +
22242 +
22243 +#ifdef CONFIG_VSERVER_MONITOR
22244 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
22245 +#else
22246 +#define VXM_SIZE       64
22247 +#endif
22248 +
22249 +struct _vx_monitor {
22250 +       unsigned int counter;
22251 +
22252 +       struct _vx_mon_entry entry[VXM_SIZE+1];
22253 +};
22254 +
22255 +
22256 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
22257 +
22258 +unsigned volatile int vxm_active = 1;
22259 +
22260 +static atomic_t sequence = ATOMIC_INIT(0);
22261 +
22262 +
22263 +/*     vxm_advance()
22264 +
22265 +       * requires disabled preemption                          */
22266 +
22267 +struct _vx_mon_entry *vxm_advance(int cpu)
22268 +{
22269 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22270 +       struct _vx_mon_entry *entry;
22271 +       unsigned int index;
22272 +
22273 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
22274 +       entry = &mon->entry[index];
22275 +
22276 +       entry->ev.seq = atomic_inc_return(&sequence);
22277 +       entry->ev.jif = jiffies;
22278 +       return entry;
22279 +}
22280 +
22281 +EXPORT_SYMBOL_GPL(vxm_advance);
22282 +
22283 +
22284 +int do_read_monitor(struct __user _vx_mon_entry *data,
22285 +       int cpu, uint32_t *index, uint32_t *count)
22286 +{
22287 +       int pos, ret = 0;
22288 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22289 +       int end = mon->counter;
22290 +       int start = end - VXM_SIZE + 2;
22291 +       int idx = *index;
22292 +
22293 +       /* special case: get current pos */
22294 +       if (!*count) {
22295 +               *index = end;
22296 +               return 0;
22297 +       }
22298 +
22299 +       /* have we lost some data? */
22300 +       if (idx < start)
22301 +               idx = start;
22302 +
22303 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22304 +               struct _vx_mon_entry *entry =
22305 +                       &mon->entry[idx % VXM_SIZE];
22306 +
22307 +               /* send entry to userspace */
22308 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22309 +               if (ret)
22310 +                       break;
22311 +       }
22312 +       /* save new index and count */
22313 +       *index = idx;
22314 +       *count = pos;
22315 +       return ret ? ret : (*index < end);
22316 +}
22317 +
22318 +int vc_read_monitor(uint32_t id, void __user *data)
22319 +{
22320 +       struct vcmd_read_monitor_v0 vc_data;
22321 +       int ret;
22322 +
22323 +       if (id >= NR_CPUS)
22324 +               return -EINVAL;
22325 +
22326 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22327 +               return -EFAULT;
22328 +
22329 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
22330 +               id, &vc_data.index, &vc_data.count);
22331 +
22332 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22333 +               return -EFAULT;
22334 +       return ret;
22335 +}
22336 +
22337 +#ifdef CONFIG_COMPAT
22338 +
22339 +int vc_read_monitor_x32(uint32_t id, void __user *data)
22340 +{
22341 +       struct vcmd_read_monitor_v0_x32 vc_data;
22342 +       int ret;
22343 +
22344 +       if (id >= NR_CPUS)
22345 +               return -EINVAL;
22346 +
22347 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22348 +               return -EFAULT;
22349 +
22350 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
22351 +               compat_ptr(vc_data.data_ptr),
22352 +               id, &vc_data.index, &vc_data.count);
22353 +
22354 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22355 +               return -EFAULT;
22356 +       return ret;
22357 +}
22358 +
22359 +#endif /* CONFIG_COMPAT */
22360 +
22361 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/network.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/network.c
22362 --- linux-2.6.32.10/kernel/vserver/network.c    1970-01-01 01:00:00.000000000 +0100
22363 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/network.c    2009-12-03 20:04:56.000000000 +0100
22364 @@ -0,0 +1,864 @@
22365 +/*
22366 + *  linux/kernel/vserver/network.c
22367 + *
22368 + *  Virtual Server: Network Support
22369 + *
22370 + *  Copyright (C) 2003-2007  Herbert Pötzl
22371 + *
22372 + *  V0.01  broken out from vcontext V0.05
22373 + *  V0.02  cleaned up implementation
22374 + *  V0.03  added equiv nx commands
22375 + *  V0.04  switch to RCU based hash
22376 + *  V0.05  and back to locking again
22377 + *  V0.06  changed vcmds to nxi arg
22378 + *  V0.07  have __create claim() the nxi
22379 + *
22380 + */
22381 +
22382 +#include <linux/err.h>
22383 +#include <linux/slab.h>
22384 +#include <linux/rcupdate.h>
22385 +
22386 +#include <linux/vs_network.h>
22387 +#include <linux/vs_pid.h>
22388 +#include <linux/vserver/network_cmd.h>
22389 +
22390 +
22391 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22392 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22393 +
22394 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22395 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22396 +
22397 +
22398 +static int __init init_network(void)
22399 +{
22400 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22401 +               sizeof(struct nx_addr_v4), 0,
22402 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22403 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22404 +               sizeof(struct nx_addr_v6), 0,
22405 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22406 +       return 0;
22407 +}
22408 +
22409 +
22410 +/*     __alloc_nx_addr_v4()                                    */
22411 +
22412 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22413 +{
22414 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22415 +               nx_addr_v4_cachep, GFP_KERNEL);
22416 +
22417 +       if (!IS_ERR(nxa))
22418 +               memset(nxa, 0, sizeof(*nxa));
22419 +       return nxa;
22420 +}
22421 +
22422 +/*     __dealloc_nx_addr_v4()                                  */
22423 +
22424 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22425 +{
22426 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22427 +}
22428 +
22429 +/*     __dealloc_nx_addr_v4_all()                              */
22430 +
22431 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22432 +{
22433 +       while (nxa) {
22434 +               struct nx_addr_v4 *next = nxa->next;
22435 +
22436 +               __dealloc_nx_addr_v4(nxa);
22437 +               nxa = next;
22438 +       }
22439 +}
22440 +
22441 +
22442 +#ifdef CONFIG_IPV6
22443 +
22444 +/*     __alloc_nx_addr_v6()                                    */
22445 +
22446 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22447 +{
22448 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22449 +               nx_addr_v6_cachep, GFP_KERNEL);
22450 +
22451 +       if (!IS_ERR(nxa))
22452 +               memset(nxa, 0, sizeof(*nxa));
22453 +       return nxa;
22454 +}
22455 +
22456 +/*     __dealloc_nx_addr_v6()                                  */
22457 +
22458 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22459 +{
22460 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22461 +}
22462 +
22463 +/*     __dealloc_nx_addr_v6_all()                              */
22464 +
22465 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22466 +{
22467 +       while (nxa) {
22468 +               struct nx_addr_v6 *next = nxa->next;
22469 +
22470 +               __dealloc_nx_addr_v6(nxa);
22471 +               nxa = next;
22472 +       }
22473 +}
22474 +
22475 +#endif /* CONFIG_IPV6 */
22476 +
22477 +/*     __alloc_nx_info()
22478 +
22479 +       * allocate an initialized nx_info struct
22480 +       * doesn't make it visible (hash)                        */
22481 +
22482 +static struct nx_info *__alloc_nx_info(nid_t nid)
22483 +{
22484 +       struct nx_info *new = NULL;
22485 +
22486 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22487 +
22488 +       /* would this benefit from a slab cache? */
22489 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22490 +       if (!new)
22491 +               return 0;
22492 +
22493 +       memset(new, 0, sizeof(struct nx_info));
22494 +       new->nx_id = nid;
22495 +       INIT_HLIST_NODE(&new->nx_hlist);
22496 +       atomic_set(&new->nx_usecnt, 0);
22497 +       atomic_set(&new->nx_tasks, 0);
22498 +       new->nx_state = 0;
22499 +
22500 +       new->nx_flags = NXF_INIT_SET;
22501 +
22502 +       /* rest of init goes here */
22503 +
22504 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22505 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22506 +
22507 +       vxdprintk(VXD_CBIT(nid, 0),
22508 +               "alloc_nx_info(%d) = %p", nid, new);
22509 +       atomic_inc(&nx_global_ctotal);
22510 +       return new;
22511 +}
22512 +
22513 +/*     __dealloc_nx_info()
22514 +
22515 +       * final disposal of nx_info                             */
22516 +
22517 +static void __dealloc_nx_info(struct nx_info *nxi)
22518 +{
22519 +       vxdprintk(VXD_CBIT(nid, 0),
22520 +               "dealloc_nx_info(%p)", nxi);
22521 +
22522 +       nxi->nx_hlist.next = LIST_POISON1;
22523 +       nxi->nx_id = -1;
22524 +
22525 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22526 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22527 +
22528 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22529 +
22530 +       nxi->nx_state |= NXS_RELEASED;
22531 +       kfree(nxi);
22532 +       atomic_dec(&nx_global_ctotal);
22533 +}
22534 +
22535 +static void __shutdown_nx_info(struct nx_info *nxi)
22536 +{
22537 +       nxi->nx_state |= NXS_SHUTDOWN;
22538 +       vs_net_change(nxi, VSC_NETDOWN);
22539 +}
22540 +
22541 +/*     exported stuff                                          */
22542 +
22543 +void free_nx_info(struct nx_info *nxi)
22544 +{
22545 +       /* context shutdown is mandatory */
22546 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22547 +
22548 +       /* context must not be hashed */
22549 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22550 +
22551 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22552 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22553 +
22554 +       __dealloc_nx_info(nxi);
22555 +}
22556 +
22557 +
22558 +void __nx_set_lback(struct nx_info *nxi)
22559 +{
22560 +       int nid = nxi->nx_id;
22561 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22562 +
22563 +       nxi->v4_lback.s_addr = lback;
22564 +}
22565 +
22566 +extern int __nx_inet_add_lback(__be32 addr);
22567 +extern int __nx_inet_del_lback(__be32 addr);
22568 +
22569 +
22570 +/*     hash table for nx_info hash */
22571 +
22572 +#define NX_HASH_SIZE   13
22573 +
22574 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22575 +
22576 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22577 +
22578 +
22579 +static inline unsigned int __hashval(nid_t nid)
22580 +{
22581 +       return (nid % NX_HASH_SIZE);
22582 +}
22583 +
22584 +
22585 +
22586 +/*     __hash_nx_info()
22587 +
22588 +       * add the nxi to the global hash table
22589 +       * requires the hash_lock to be held                     */
22590 +
22591 +static inline void __hash_nx_info(struct nx_info *nxi)
22592 +{
22593 +       struct hlist_head *head;
22594 +
22595 +       vxd_assert_lock(&nx_info_hash_lock);
22596 +       vxdprintk(VXD_CBIT(nid, 4),
22597 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22598 +
22599 +       /* context must not be hashed */
22600 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22601 +
22602 +       nxi->nx_state |= NXS_HASHED;
22603 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22604 +       hlist_add_head(&nxi->nx_hlist, head);
22605 +       atomic_inc(&nx_global_cactive);
22606 +}
22607 +
22608 +/*     __unhash_nx_info()
22609 +
22610 +       * remove the nxi from the global hash table
22611 +       * requires the hash_lock to be held                     */
22612 +
22613 +static inline void __unhash_nx_info(struct nx_info *nxi)
22614 +{
22615 +       vxd_assert_lock(&nx_info_hash_lock);
22616 +       vxdprintk(VXD_CBIT(nid, 4),
22617 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22618 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22619 +
22620 +       /* context must be hashed */
22621 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22622 +       /* but without tasks */
22623 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22624 +
22625 +       nxi->nx_state &= ~NXS_HASHED;
22626 +       hlist_del(&nxi->nx_hlist);
22627 +       atomic_dec(&nx_global_cactive);
22628 +}
22629 +
22630 +
22631 +/*     __lookup_nx_info()
22632 +
22633 +       * requires the hash_lock to be held
22634 +       * doesn't increment the nx_refcnt                       */
22635 +
22636 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22637 +{
22638 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22639 +       struct hlist_node *pos;
22640 +       struct nx_info *nxi;
22641 +
22642 +       vxd_assert_lock(&nx_info_hash_lock);
22643 +       hlist_for_each(pos, head) {
22644 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22645 +
22646 +               if (nxi->nx_id == nid)
22647 +                       goto found;
22648 +       }
22649 +       nxi = NULL;
22650 +found:
22651 +       vxdprintk(VXD_CBIT(nid, 0),
22652 +               "__lookup_nx_info(#%u): %p[#%u]",
22653 +               nid, nxi, nxi ? nxi->nx_id : 0);
22654 +       return nxi;
22655 +}
22656 +
22657 +
22658 +/*     __create_nx_info()
22659 +
22660 +       * create the requested context
22661 +       * get(), claim() and hash it                            */
22662 +
22663 +static struct nx_info *__create_nx_info(int id)
22664 +{
22665 +       struct nx_info *new, *nxi = NULL;
22666 +
22667 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22668 +
22669 +       if (!(new = __alloc_nx_info(id)))
22670 +               return ERR_PTR(-ENOMEM);
22671 +
22672 +       /* required to make dynamic xids unique */
22673 +       spin_lock(&nx_info_hash_lock);
22674 +
22675 +       /* static context requested */
22676 +       if ((nxi = __lookup_nx_info(id))) {
22677 +               vxdprintk(VXD_CBIT(nid, 0),
22678 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22679 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22680 +                       nxi = ERR_PTR(-EBUSY);
22681 +               else
22682 +                       nxi = ERR_PTR(-EEXIST);
22683 +               goto out_unlock;
22684 +       }
22685 +       /* new context */
22686 +       vxdprintk(VXD_CBIT(nid, 0),
22687 +               "create_nx_info(%d) = %p (new)", id, new);
22688 +       claim_nx_info(new, NULL);
22689 +       __nx_set_lback(new);
22690 +       __hash_nx_info(get_nx_info(new));
22691 +       nxi = new, new = NULL;
22692 +
22693 +out_unlock:
22694 +       spin_unlock(&nx_info_hash_lock);
22695 +       if (new)
22696 +               __dealloc_nx_info(new);
22697 +       return nxi;
22698 +}
22699 +
22700 +
22701 +
22702 +/*     exported stuff                                          */
22703 +
22704 +
22705 +void unhash_nx_info(struct nx_info *nxi)
22706 +{
22707 +       __shutdown_nx_info(nxi);
22708 +       spin_lock(&nx_info_hash_lock);
22709 +       __unhash_nx_info(nxi);
22710 +       spin_unlock(&nx_info_hash_lock);
22711 +}
22712 +
22713 +/*     lookup_nx_info()
22714 +
22715 +       * search for a nx_info and get() it
22716 +       * negative id means current                             */
22717 +
22718 +struct nx_info *lookup_nx_info(int id)
22719 +{
22720 +       struct nx_info *nxi = NULL;
22721 +
22722 +       if (id < 0) {
22723 +               nxi = get_nx_info(current_nx_info());
22724 +       } else if (id > 1) {
22725 +               spin_lock(&nx_info_hash_lock);
22726 +               nxi = get_nx_info(__lookup_nx_info(id));
22727 +               spin_unlock(&nx_info_hash_lock);
22728 +       }
22729 +       return nxi;
22730 +}
22731 +
22732 +/*     nid_is_hashed()
22733 +
22734 +       * verify that nid is still hashed                       */
22735 +
22736 +int nid_is_hashed(nid_t nid)
22737 +{
22738 +       int hashed;
22739 +
22740 +       spin_lock(&nx_info_hash_lock);
22741 +       hashed = (__lookup_nx_info(nid) != NULL);
22742 +       spin_unlock(&nx_info_hash_lock);
22743 +       return hashed;
22744 +}
22745 +
22746 +
22747 +#ifdef CONFIG_PROC_FS
22748 +
22749 +/*     get_nid_list()
22750 +
22751 +       * get a subset of hashed nids for proc
22752 +       * assumes size is at least one                          */
22753 +
22754 +int get_nid_list(int index, unsigned int *nids, int size)
22755 +{
22756 +       int hindex, nr_nids = 0;
22757 +
22758 +       /* only show current and children */
22759 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22760 +               if (index > 0)
22761 +                       return 0;
22762 +               nids[nr_nids] = nx_current_nid();
22763 +               return 1;
22764 +       }
22765 +
22766 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22767 +               struct hlist_head *head = &nx_info_hash[hindex];
22768 +               struct hlist_node *pos;
22769 +
22770 +               spin_lock(&nx_info_hash_lock);
22771 +               hlist_for_each(pos, head) {
22772 +                       struct nx_info *nxi;
22773 +
22774 +                       if (--index > 0)
22775 +                               continue;
22776 +
22777 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22778 +                       nids[nr_nids] = nxi->nx_id;
22779 +                       if (++nr_nids >= size) {
22780 +                               spin_unlock(&nx_info_hash_lock);
22781 +                               goto out;
22782 +                       }
22783 +               }
22784 +               /* keep the lock time short */
22785 +               spin_unlock(&nx_info_hash_lock);
22786 +       }
22787 +out:
22788 +       return nr_nids;
22789 +}
22790 +#endif
22791 +
22792 +
22793 +/*
22794 + *     migrate task to new network
22795 + *     gets nxi, puts old_nxi on change
22796 + */
22797 +
22798 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22799 +{
22800 +       struct nx_info *old_nxi;
22801 +       int ret = 0;
22802 +
22803 +       if (!p || !nxi)
22804 +               BUG();
22805 +
22806 +       vxdprintk(VXD_CBIT(nid, 5),
22807 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22808 +               p, nxi, nxi->nx_id,
22809 +               atomic_read(&nxi->nx_usecnt),
22810 +               atomic_read(&nxi->nx_tasks));
22811 +
22812 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22813 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22814 +               return -EACCES;
22815 +
22816 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22817 +               return -EFAULT;
22818 +
22819 +       /* maybe disallow this completely? */
22820 +       old_nxi = task_get_nx_info(p);
22821 +       if (old_nxi == nxi)
22822 +               goto out;
22823 +
22824 +       task_lock(p);
22825 +       if (old_nxi)
22826 +               clr_nx_info(&p->nx_info);
22827 +       claim_nx_info(nxi, p);
22828 +       set_nx_info(&p->nx_info, nxi);
22829 +       p->nid = nxi->nx_id;
22830 +       task_unlock(p);
22831 +
22832 +       vxdprintk(VXD_CBIT(nid, 5),
22833 +               "moved task %p into nxi:%p[#%d]",
22834 +               p, nxi, nxi->nx_id);
22835 +
22836 +       if (old_nxi)
22837 +               release_nx_info(old_nxi, p);
22838 +       ret = 0;
22839 +out:
22840 +       put_nx_info(old_nxi);
22841 +       return ret;
22842 +}
22843 +
22844 +
22845 +void nx_set_persistent(struct nx_info *nxi)
22846 +{
22847 +       vxdprintk(VXD_CBIT(nid, 6),
22848 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22849 +
22850 +       get_nx_info(nxi);
22851 +       claim_nx_info(nxi, NULL);
22852 +}
22853 +
22854 +void nx_clear_persistent(struct nx_info *nxi)
22855 +{
22856 +       vxdprintk(VXD_CBIT(nid, 6),
22857 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22858 +
22859 +       release_nx_info(nxi, NULL);
22860 +       put_nx_info(nxi);
22861 +}
22862 +
22863 +void nx_update_persistent(struct nx_info *nxi)
22864 +{
22865 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22866 +               nx_set_persistent(nxi);
22867 +       else
22868 +               nx_clear_persistent(nxi);
22869 +}
22870 +
22871 +/* vserver syscall commands below here */
22872 +
22873 +/* taks nid and nx_info functions */
22874 +
22875 +#include <asm/uaccess.h>
22876 +
22877 +
22878 +int vc_task_nid(uint32_t id)
22879 +{
22880 +       nid_t nid;
22881 +
22882 +       if (id) {
22883 +               struct task_struct *tsk;
22884 +
22885 +               read_lock(&tasklist_lock);
22886 +               tsk = find_task_by_real_pid(id);
22887 +               nid = (tsk) ? tsk->nid : -ESRCH;
22888 +               read_unlock(&tasklist_lock);
22889 +       } else
22890 +               nid = nx_current_nid();
22891 +       return nid;
22892 +}
22893 +
22894 +
22895 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22896 +{
22897 +       struct vcmd_nx_info_v0 vc_data;
22898 +
22899 +       vc_data.nid = nxi->nx_id;
22900 +
22901 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22902 +               return -EFAULT;
22903 +       return 0;
22904 +}
22905 +
22906 +
22907 +/* network functions */
22908 +
22909 +int vc_net_create(uint32_t nid, void __user *data)
22910 +{
22911 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22912 +       struct nx_info *new_nxi;
22913 +       int ret;
22914 +
22915 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22916 +               return -EFAULT;
22917 +
22918 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22919 +               return -EINVAL;
22920 +
22921 +       new_nxi = __create_nx_info(nid);
22922 +       if (IS_ERR(new_nxi))
22923 +               return PTR_ERR(new_nxi);
22924 +
22925 +       /* initial flags */
22926 +       new_nxi->nx_flags = vc_data.flagword;
22927 +
22928 +       ret = -ENOEXEC;
22929 +       if (vs_net_change(new_nxi, VSC_NETUP))
22930 +               goto out;
22931 +
22932 +       ret = nx_migrate_task(current, new_nxi);
22933 +       if (ret)
22934 +               goto out;
22935 +
22936 +       /* return context id on success */
22937 +       ret = new_nxi->nx_id;
22938 +
22939 +       /* get a reference for persistent contexts */
22940 +       if ((vc_data.flagword & NXF_PERSISTENT))
22941 +               nx_set_persistent(new_nxi);
22942 +out:
22943 +       release_nx_info(new_nxi, NULL);
22944 +       put_nx_info(new_nxi);
22945 +       return ret;
22946 +}
22947 +
22948 +
22949 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22950 +{
22951 +       return nx_migrate_task(current, nxi);
22952 +}
22953 +
22954 +
22955 +
22956 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22957 +       uint16_t type, uint16_t flags)
22958 +{
22959 +       struct nx_addr_v4 *nxa = &nxi->v4;
22960 +
22961 +       if (NX_IPV4(nxi)) {
22962 +               /* locate last entry */
22963 +               for (; nxa->next; nxa = nxa->next);
22964 +               nxa->next = __alloc_nx_addr_v4();
22965 +               nxa = nxa->next;
22966 +
22967 +               if (IS_ERR(nxa))
22968 +                       return PTR_ERR(nxa);
22969 +       }
22970 +
22971 +       if (nxi->v4.next)
22972 +               /* remove single ip for ip list */
22973 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22974 +
22975 +       nxa->ip[0].s_addr = ip;
22976 +       nxa->ip[1].s_addr = ip2;
22977 +       nxa->mask.s_addr = mask;
22978 +       nxa->type = type;
22979 +       nxa->flags = flags;
22980 +       return 0;
22981 +}
22982 +
22983 +
22984 +int vc_net_add(struct nx_info *nxi, void __user *data)
22985 +{
22986 +       struct vcmd_net_addr_v0 vc_data;
22987 +       int index, ret = 0;
22988 +
22989 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22990 +               return -EFAULT;
22991 +
22992 +       switch (vc_data.type) {
22993 +       case NXA_TYPE_IPV4:
22994 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22995 +                       return -EINVAL;
22996 +
22997 +               index = 0;
22998 +               while (index < vc_data.count) {
22999 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
23000 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
23001 +                       if (ret)
23002 +                               return ret;
23003 +                       index++;
23004 +               }
23005 +               ret = index;
23006 +               break;
23007 +
23008 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
23009 +               nxi->v4_bcast = vc_data.ip[0];
23010 +               ret = 1;
23011 +               break;
23012 +
23013 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
23014 +               nxi->v4_lback = vc_data.ip[0];
23015 +               ret = 1;
23016 +               break;
23017 +
23018 +       default:
23019 +               ret = -EINVAL;
23020 +               break;
23021 +       }
23022 +       return ret;
23023 +}
23024 +
23025 +int vc_net_remove(struct nx_info *nxi, void __user *data)
23026 +{
23027 +       struct vcmd_net_addr_v0 vc_data;
23028 +
23029 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23030 +               return -EFAULT;
23031 +
23032 +       switch (vc_data.type) {
23033 +       case NXA_TYPE_ANY:
23034 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
23035 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
23036 +               break;
23037 +
23038 +       default:
23039 +               return -EINVAL;
23040 +       }
23041 +       return 0;
23042 +}
23043 +
23044 +
23045 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
23046 +{
23047 +       struct vcmd_net_addr_ipv4_v1 vc_data;
23048 +
23049 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23050 +               return -EFAULT;
23051 +
23052 +       switch (vc_data.type) {
23053 +       case NXA_TYPE_ADDR:
23054 +       case NXA_TYPE_RANGE:
23055 +       case NXA_TYPE_MASK:
23056 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
23057 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
23058 +
23059 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
23060 +               nxi->v4_bcast = vc_data.ip;
23061 +               break;
23062 +
23063 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
23064 +               nxi->v4_lback = vc_data.ip;
23065 +               break;
23066 +
23067 +       default:
23068 +               return -EINVAL;
23069 +       }
23070 +       return 0;
23071 +}
23072 +
23073 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
23074 +{
23075 +       struct vcmd_net_addr_ipv4_v1 vc_data;
23076 +
23077 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23078 +               return -EFAULT;
23079 +
23080 +       switch (vc_data.type) {
23081 +/*     case NXA_TYPE_ADDR:
23082 +               break;          */
23083 +
23084 +       case NXA_TYPE_ANY:
23085 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
23086 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
23087 +               break;
23088 +
23089 +       default:
23090 +               return -EINVAL;
23091 +       }
23092 +       return 0;
23093 +}
23094 +
23095 +
23096 +#ifdef CONFIG_IPV6
23097 +
23098 +int do_add_v6_addr(struct nx_info *nxi,
23099 +       struct in6_addr *ip, struct in6_addr *mask,
23100 +       uint32_t prefix, uint16_t type, uint16_t flags)
23101 +{
23102 +       struct nx_addr_v6 *nxa = &nxi->v6;
23103 +
23104 +       if (NX_IPV6(nxi)) {
23105 +               /* locate last entry */
23106 +               for (; nxa->next; nxa = nxa->next);
23107 +               nxa->next = __alloc_nx_addr_v6();
23108 +               nxa = nxa->next;
23109 +
23110 +               if (IS_ERR(nxa))
23111 +                       return PTR_ERR(nxa);
23112 +       }
23113 +
23114 +       nxa->ip = *ip;
23115 +       nxa->mask = *mask;
23116 +       nxa->prefix = prefix;
23117 +       nxa->type = type;
23118 +       nxa->flags = flags;
23119 +       return 0;
23120 +}
23121 +
23122 +
23123 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
23124 +{
23125 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23126 +
23127 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23128 +               return -EFAULT;
23129 +
23130 +       switch (vc_data.type) {
23131 +       case NXA_TYPE_ADDR:
23132 +       case NXA_TYPE_MASK:
23133 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
23134 +                       vc_data.prefix, vc_data.type, vc_data.flags);
23135 +       default:
23136 +               return -EINVAL;
23137 +       }
23138 +       return 0;
23139 +}
23140 +
23141 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
23142 +{
23143 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23144 +
23145 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23146 +               return -EFAULT;
23147 +
23148 +       switch (vc_data.type) {
23149 +       case NXA_TYPE_ANY:
23150 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
23151 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
23152 +               break;
23153 +
23154 +       default:
23155 +               return -EINVAL;
23156 +       }
23157 +       return 0;
23158 +}
23159 +
23160 +#endif /* CONFIG_IPV6 */
23161 +
23162 +
23163 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
23164 +{
23165 +       struct vcmd_net_flags_v0 vc_data;
23166 +
23167 +       vc_data.flagword = nxi->nx_flags;
23168 +
23169 +       /* special STATE flag handling */
23170 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
23171 +
23172 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23173 +               return -EFAULT;
23174 +       return 0;
23175 +}
23176 +
23177 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
23178 +{
23179 +       struct vcmd_net_flags_v0 vc_data;
23180 +       uint64_t mask, trigger;
23181 +
23182 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23183 +               return -EFAULT;
23184 +
23185 +       /* special STATE flag handling */
23186 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
23187 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
23188 +
23189 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
23190 +               vc_data.flagword, mask);
23191 +       if (trigger & NXF_PERSISTENT)
23192 +               nx_update_persistent(nxi);
23193 +
23194 +       return 0;
23195 +}
23196 +
23197 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
23198 +{
23199 +       struct vcmd_net_caps_v0 vc_data;
23200 +
23201 +       vc_data.ncaps = nxi->nx_ncaps;
23202 +       vc_data.cmask = ~0ULL;
23203 +
23204 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23205 +               return -EFAULT;
23206 +       return 0;
23207 +}
23208 +
23209 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
23210 +{
23211 +       struct vcmd_net_caps_v0 vc_data;
23212 +
23213 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23214 +               return -EFAULT;
23215 +
23216 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
23217 +               vc_data.ncaps, vc_data.cmask);
23218 +       return 0;
23219 +}
23220 +
23221 +
23222 +#include <linux/module.h>
23223 +
23224 +module_init(init_network);
23225 +
23226 +EXPORT_SYMBOL_GPL(free_nx_info);
23227 +EXPORT_SYMBOL_GPL(unhash_nx_info);
23228 +
23229 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/proc.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/proc.c
23230 --- linux-2.6.32.10/kernel/vserver/proc.c       1970-01-01 01:00:00.000000000 +0100
23231 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/proc.c       2009-12-03 20:04:56.000000000 +0100
23232 @@ -0,0 +1,1098 @@
23233 +/*
23234 + *  linux/kernel/vserver/proc.c
23235 + *
23236 + *  Virtual Context Support
23237 + *
23238 + *  Copyright (C) 2003-2007  Herbert Pötzl
23239 + *
23240 + *  V0.01  basic structure
23241 + *  V0.02  adaptation vs1.3.0
23242 + *  V0.03  proc permissions
23243 + *  V0.04  locking/generic
23244 + *  V0.05  next generation procfs
23245 + *  V0.06  inode validation
23246 + *  V0.07  generic rewrite vid
23247 + *  V0.08  remove inode type
23248 + *
23249 + */
23250 +
23251 +#include <linux/proc_fs.h>
23252 +#include <linux/fs_struct.h>
23253 +#include <linux/mount.h>
23254 +#include <asm/unistd.h>
23255 +
23256 +#include <linux/vs_context.h>
23257 +#include <linux/vs_network.h>
23258 +#include <linux/vs_cvirt.h>
23259 +
23260 +#include <linux/in.h>
23261 +#include <linux/inetdevice.h>
23262 +#include <linux/vs_inet.h>
23263 +#include <linux/vs_inet6.h>
23264 +
23265 +#include <linux/vserver/global.h>
23266 +
23267 +#include "cvirt_proc.h"
23268 +#include "cacct_proc.h"
23269 +#include "limit_proc.h"
23270 +#include "sched_proc.h"
23271 +#include "vci_config.h"
23272 +
23273 +
23274 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
23275 +{
23276 +       unsigned __capi;
23277 +
23278 +       CAP_FOR_EACH_U32(__capi) {
23279 +               buffer += sprintf(buffer, "%08x",
23280 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
23281 +       }
23282 +       return buffer;
23283 +}
23284 +
23285 +
23286 +static struct proc_dir_entry *proc_virtual;
23287 +
23288 +static struct proc_dir_entry *proc_virtnet;
23289 +
23290 +
23291 +/* first the actual feeds */
23292 +
23293 +
23294 +static int proc_vci(char *buffer)
23295 +{
23296 +       return sprintf(buffer,
23297 +               "VCIVersion:\t%04x:%04x\n"
23298 +               "VCISyscall:\t%d\n"
23299 +               "VCIKernel:\t%08x\n",
23300 +               VCI_VERSION >> 16,
23301 +               VCI_VERSION & 0xFFFF,
23302 +               __NR_vserver,
23303 +               vci_kernel_config());
23304 +}
23305 +
23306 +static int proc_virtual_info(char *buffer)
23307 +{
23308 +       return proc_vci(buffer);
23309 +}
23310 +
23311 +static int proc_virtual_status(char *buffer)
23312 +{
23313 +       return sprintf(buffer,
23314 +               "#CTotal:\t%d\n"
23315 +               "#CActive:\t%d\n"
23316 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
23317 +               "#InitTask:\t%d\t%d %d\n",
23318 +               atomic_read(&vx_global_ctotal),
23319 +               atomic_read(&vx_global_cactive),
23320 +               atomic_read(&vs_global_nsproxy),
23321 +               atomic_read(&vs_global_fs),
23322 +               atomic_read(&vs_global_mnt_ns),
23323 +               atomic_read(&vs_global_uts_ns),
23324 +               atomic_read(&nr_ipc_ns),
23325 +               atomic_read(&vs_global_user_ns),
23326 +               atomic_read(&vs_global_pid_ns),
23327 +               atomic_read(&init_task.usage),
23328 +               atomic_read(&init_task.nsproxy->count),
23329 +               init_task.fs->users);
23330 +}
23331 +
23332 +
23333 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23334 +{
23335 +       int length;
23336 +
23337 +       length = sprintf(buffer,
23338 +               "ID:\t%d\n"
23339 +               "Info:\t%p\n"
23340 +               "Init:\t%d\n"
23341 +               "OOM:\t%lld\n",
23342 +               vxi->vx_id,
23343 +               vxi,
23344 +               vxi->vx_initpid,
23345 +               vxi->vx_badness_bias);
23346 +       return length;
23347 +}
23348 +
23349 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23350 +{
23351 +       char *orig = buffer;
23352 +
23353 +       buffer += sprintf(buffer,
23354 +               "UseCnt:\t%d\n"
23355 +               "Tasks:\t%d\n"
23356 +               "Flags:\t%016llx\n",
23357 +               atomic_read(&vxi->vx_usecnt),
23358 +               atomic_read(&vxi->vx_tasks),
23359 +               (unsigned long long)vxi->vx_flags);
23360 +
23361 +       buffer += sprintf(buffer, "BCaps:\t");
23362 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23363 +       buffer += sprintf(buffer, "\n");
23364 +
23365 +       buffer += sprintf(buffer,
23366 +               "CCaps:\t%016llx\n"
23367 +               "Spaces:\t%08lx %08lx\n",
23368 +               (unsigned long long)vxi->vx_ccaps,
23369 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
23370 +       return buffer - orig;
23371 +}
23372 +
23373 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23374 +{
23375 +       return vx_info_proc_limit(&vxi->limit, buffer);
23376 +}
23377 +
23378 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23379 +{
23380 +       int cpu, length;
23381 +
23382 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23383 +       for_each_online_cpu(cpu) {
23384 +               length += vx_info_proc_sched_pc(
23385 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23386 +                       buffer + length, cpu);
23387 +       }
23388 +       return length;
23389 +}
23390 +
23391 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
23392 +{
23393 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
23394 +}
23395 +
23396 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
23397 +{
23398 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
23399 +}
23400 +
23401 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23402 +{
23403 +       int cpu, length;
23404 +
23405 +       vx_update_load(vxi);
23406 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23407 +       for_each_online_cpu(cpu) {
23408 +               length += vx_info_proc_cvirt_pc(
23409 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23410 +                       buffer + length, cpu);
23411 +       }
23412 +       return length;
23413 +}
23414 +
23415 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23416 +{
23417 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23418 +}
23419 +
23420 +
23421 +static int proc_virtnet_info(char *buffer)
23422 +{
23423 +       return proc_vci(buffer);
23424 +}
23425 +
23426 +static int proc_virtnet_status(char *buffer)
23427 +{
23428 +       return sprintf(buffer,
23429 +               "#CTotal:\t%d\n"
23430 +               "#CActive:\t%d\n",
23431 +               atomic_read(&nx_global_ctotal),
23432 +               atomic_read(&nx_global_cactive));
23433 +}
23434 +
23435 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23436 +{
23437 +       struct nx_addr_v4 *v4a;
23438 +#ifdef CONFIG_IPV6
23439 +       struct nx_addr_v6 *v6a;
23440 +#endif
23441 +       int length, i;
23442 +
23443 +       length = sprintf(buffer,
23444 +               "ID:\t%d\n"
23445 +               "Info:\t%p\n"
23446 +               "Bcast:\t" NIPQUAD_FMT "\n"
23447 +               "Lback:\t" NIPQUAD_FMT "\n",
23448 +               nxi->nx_id,
23449 +               nxi,
23450 +               NIPQUAD(nxi->v4_bcast.s_addr),
23451 +               NIPQUAD(nxi->v4_lback.s_addr));
23452 +
23453 +       if (!NX_IPV4(nxi))
23454 +               goto skip_v4;
23455 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23456 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23457 +                       i, NXAV4(v4a));
23458 +skip_v4:
23459 +#ifdef CONFIG_IPV6
23460 +       if (!NX_IPV6(nxi))
23461 +               goto skip_v6;
23462 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23463 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23464 +                       i, NXAV6(v6a));
23465 +skip_v6:
23466 +#endif
23467 +       return length;
23468 +}
23469 +
23470 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23471 +{
23472 +       int length;
23473 +
23474 +       length = sprintf(buffer,
23475 +               "UseCnt:\t%d\n"
23476 +               "Tasks:\t%d\n"
23477 +               "Flags:\t%016llx\n"
23478 +               "NCaps:\t%016llx\n",
23479 +               atomic_read(&nxi->nx_usecnt),
23480 +               atomic_read(&nxi->nx_tasks),
23481 +               (unsigned long long)nxi->nx_flags,
23482 +               (unsigned long long)nxi->nx_ncaps);
23483 +       return length;
23484 +}
23485 +
23486 +
23487 +
23488 +/* here the inode helpers */
23489 +
23490 +struct vs_entry {
23491 +       int len;
23492 +       char *name;
23493 +       mode_t mode;
23494 +       struct inode_operations *iop;
23495 +       struct file_operations *fop;
23496 +       union proc_op op;
23497 +};
23498 +
23499 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23500 +{
23501 +       struct inode *inode = new_inode(sb);
23502 +
23503 +       if (!inode)
23504 +               goto out;
23505 +
23506 +       inode->i_mode = p->mode;
23507 +       if (p->iop)
23508 +               inode->i_op = p->iop;
23509 +       if (p->fop)
23510 +               inode->i_fop = p->fop;
23511 +
23512 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23513 +       inode->i_flags |= S_IMMUTABLE;
23514 +
23515 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23516 +
23517 +       inode->i_uid = 0;
23518 +       inode->i_gid = 0;
23519 +       inode->i_tag = 0;
23520 +out:
23521 +       return inode;
23522 +}
23523 +
23524 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23525 +       struct dentry *dentry, int id, void *ptr)
23526 +{
23527 +       struct vs_entry *p = ptr;
23528 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23529 +       struct dentry *error = ERR_PTR(-EINVAL);
23530 +
23531 +       if (!inode)
23532 +               goto out;
23533 +
23534 +       PROC_I(inode)->op = p->op;
23535 +       PROC_I(inode)->fd = id;
23536 +       d_add(dentry, inode);
23537 +       error = NULL;
23538 +out:
23539 +       return error;
23540 +}
23541 +
23542 +/* Lookups */
23543 +
23544 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23545 +
23546 +/*
23547 + * Fill a directory entry.
23548 + *
23549 + * If possible create the dcache entry and derive our inode number and
23550 + * file type from dcache entry.
23551 + *
23552 + * Since all of the proc inode numbers are dynamically generated, the inode
23553 + * numbers do not exist until the inode is cache.  This means creating the
23554 + * the dcache entry in readdir is necessary to keep the inode numbers
23555 + * reported by readdir in sync with the inode numbers reported
23556 + * by stat.
23557 + */
23558 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23559 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23560 +{
23561 +       struct dentry *child, *dir = filp->f_dentry;
23562 +       struct inode *inode;
23563 +       struct qstr qname;
23564 +       ino_t ino = 0;
23565 +       unsigned type = DT_UNKNOWN;
23566 +
23567 +       qname.name = name;
23568 +       qname.len  = len;
23569 +       qname.hash = full_name_hash(name, len);
23570 +
23571 +       child = d_lookup(dir, &qname);
23572 +       if (!child) {
23573 +               struct dentry *new;
23574 +               new = d_alloc(dir, &qname);
23575 +               if (new) {
23576 +                       child = instantiate(dir->d_inode, new, id, ptr);
23577 +                       if (child)
23578 +                               dput(new);
23579 +                       else
23580 +                               child = new;
23581 +               }
23582 +       }
23583 +       if (!child || IS_ERR(child) || !child->d_inode)
23584 +               goto end_instantiate;
23585 +       inode = child->d_inode;
23586 +       if (inode) {
23587 +               ino = inode->i_ino;
23588 +               type = inode->i_mode >> 12;
23589 +       }
23590 +       dput(child);
23591 +end_instantiate:
23592 +       if (!ino)
23593 +               ino = find_inode_number(dir, &qname);
23594 +       if (!ino)
23595 +               ino = 1;
23596 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23597 +}
23598 +
23599 +
23600 +
23601 +/* get and revalidate vx_info/xid */
23602 +
23603 +static inline
23604 +struct vx_info *get_proc_vx_info(struct inode *inode)
23605 +{
23606 +       return lookup_vx_info(PROC_I(inode)->fd);
23607 +}
23608 +
23609 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23610 +{
23611 +       struct inode *inode = dentry->d_inode;
23612 +       xid_t xid = PROC_I(inode)->fd;
23613 +
23614 +       if (!xid || xid_is_hashed(xid))
23615 +               return 1;
23616 +       d_drop(dentry);
23617 +       return 0;
23618 +}
23619 +
23620 +
23621 +/* get and revalidate nx_info/nid */
23622 +
23623 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23624 +{
23625 +       struct inode *inode = dentry->d_inode;
23626 +       nid_t nid = PROC_I(inode)->fd;
23627 +
23628 +       if (!nid || nid_is_hashed(nid))
23629 +               return 1;
23630 +       d_drop(dentry);
23631 +       return 0;
23632 +}
23633 +
23634 +
23635 +
23636 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23637 +
23638 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23639 +                         size_t count, loff_t *ppos)
23640 +{
23641 +       struct inode *inode = file->f_dentry->d_inode;
23642 +       unsigned long page;
23643 +       ssize_t length = 0;
23644 +
23645 +       if (count > PROC_BLOCK_SIZE)
23646 +               count = PROC_BLOCK_SIZE;
23647 +
23648 +       /* fade that out as soon as stable */
23649 +       WARN_ON(PROC_I(inode)->fd);
23650 +
23651 +       if (!(page = __get_free_page(GFP_KERNEL)))
23652 +               return -ENOMEM;
23653 +
23654 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23655 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23656 +
23657 +       if (length >= 0)
23658 +               length = simple_read_from_buffer(buf, count, ppos,
23659 +                       (char *)page, length);
23660 +
23661 +       free_page(page);
23662 +       return length;
23663 +}
23664 +
23665 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23666 +                         size_t count, loff_t *ppos)
23667 +{
23668 +       struct inode *inode = file->f_dentry->d_inode;
23669 +       struct vx_info *vxi = NULL;
23670 +       xid_t xid = PROC_I(inode)->fd;
23671 +       unsigned long page;
23672 +       ssize_t length = 0;
23673 +
23674 +       if (count > PROC_BLOCK_SIZE)
23675 +               count = PROC_BLOCK_SIZE;
23676 +
23677 +       /* fade that out as soon as stable */
23678 +       WARN_ON(!xid);
23679 +       vxi = lookup_vx_info(xid);
23680 +       if (!vxi)
23681 +               goto out;
23682 +
23683 +       length = -ENOMEM;
23684 +       if (!(page = __get_free_page(GFP_KERNEL)))
23685 +               goto out_put;
23686 +
23687 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23688 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23689 +
23690 +       if (length >= 0)
23691 +               length = simple_read_from_buffer(buf, count, ppos,
23692 +                       (char *)page, length);
23693 +
23694 +       free_page(page);
23695 +out_put:
23696 +       put_vx_info(vxi);
23697 +out:
23698 +       return length;
23699 +}
23700 +
23701 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23702 +                         size_t count, loff_t *ppos)
23703 +{
23704 +       struct inode *inode = file->f_dentry->d_inode;
23705 +       struct nx_info *nxi = NULL;
23706 +       nid_t nid = PROC_I(inode)->fd;
23707 +       unsigned long page;
23708 +       ssize_t length = 0;
23709 +
23710 +       if (count > PROC_BLOCK_SIZE)
23711 +               count = PROC_BLOCK_SIZE;
23712 +
23713 +       /* fade that out as soon as stable */
23714 +       WARN_ON(!nid);
23715 +       nxi = lookup_nx_info(nid);
23716 +       if (!nxi)
23717 +               goto out;
23718 +
23719 +       length = -ENOMEM;
23720 +       if (!(page = __get_free_page(GFP_KERNEL)))
23721 +               goto out_put;
23722 +
23723 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23724 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23725 +
23726 +       if (length >= 0)
23727 +               length = simple_read_from_buffer(buf, count, ppos,
23728 +                       (char *)page, length);
23729 +
23730 +       free_page(page);
23731 +out_put:
23732 +       put_nx_info(nxi);
23733 +out:
23734 +       return length;
23735 +}
23736 +
23737 +
23738 +
23739 +/* here comes the lower level */
23740 +
23741 +
23742 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23743 +       .len  = sizeof(NAME) - 1,       \
23744 +       .name = (NAME),                 \
23745 +       .mode = MODE,                   \
23746 +       .iop  = IOP,                    \
23747 +       .fop  = FOP,                    \
23748 +       .op   = OP,                     \
23749 +}
23750 +
23751 +
23752 +#define DIR(NAME, MODE, OTYPE)                         \
23753 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23754 +               &proc_ ## OTYPE ## _inode_operations,   \
23755 +               &proc_ ## OTYPE ## _file_operations, { } )
23756 +
23757 +#define INF(NAME, MODE, OTYPE)                         \
23758 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23759 +               &proc_vs_info_file_operations,          \
23760 +               { .proc_vs_read = &proc_##OTYPE } )
23761 +
23762 +#define VINF(NAME, MODE, OTYPE)                                \
23763 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23764 +               &proc_vx_info_file_operations,          \
23765 +               { .proc_vxi_read = &proc_##OTYPE } )
23766 +
23767 +#define NINF(NAME, MODE, OTYPE)                                \
23768 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23769 +               &proc_nx_info_file_operations,          \
23770 +               { .proc_nxi_read = &proc_##OTYPE } )
23771 +
23772 +
23773 +static struct file_operations proc_vs_info_file_operations = {
23774 +       .read =         proc_vs_info_read,
23775 +};
23776 +
23777 +static struct file_operations proc_vx_info_file_operations = {
23778 +       .read =         proc_vx_info_read,
23779 +};
23780 +
23781 +static struct dentry_operations proc_xid_dentry_operations = {
23782 +       .d_revalidate = proc_xid_revalidate,
23783 +};
23784 +
23785 +static struct vs_entry vx_base_stuff[] = {
23786 +       VINF("info",    S_IRUGO, vxi_info),
23787 +       VINF("status",  S_IRUGO, vxi_status),
23788 +       VINF("limit",   S_IRUGO, vxi_limit),
23789 +       VINF("sched",   S_IRUGO, vxi_sched),
23790 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23791 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23792 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23793 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23794 +       {}
23795 +};
23796 +
23797 +
23798 +
23799 +
23800 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23801 +       struct dentry *dentry, int id, void *ptr)
23802 +{
23803 +       dentry->d_op = &proc_xid_dentry_operations;
23804 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23805 +}
23806 +
23807 +static struct dentry *proc_xid_lookup(struct inode *dir,
23808 +       struct dentry *dentry, struct nameidata *nd)
23809 +{
23810 +       struct vs_entry *p = vx_base_stuff;
23811 +       struct dentry *error = ERR_PTR(-ENOENT);
23812 +
23813 +       for (; p->name; p++) {
23814 +               if (p->len != dentry->d_name.len)
23815 +                       continue;
23816 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23817 +                       break;
23818 +       }
23819 +       if (!p->name)
23820 +               goto out;
23821 +
23822 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23823 +out:
23824 +       return error;
23825 +}
23826 +
23827 +static int proc_xid_readdir(struct file *filp,
23828 +       void *dirent, filldir_t filldir)
23829 +{
23830 +       struct dentry *dentry = filp->f_dentry;
23831 +       struct inode *inode = dentry->d_inode;
23832 +       struct vs_entry *p = vx_base_stuff;
23833 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23834 +       int pos, index;
23835 +       u64 ino;
23836 +
23837 +       pos = filp->f_pos;
23838 +       switch (pos) {
23839 +       case 0:
23840 +               ino = inode->i_ino;
23841 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23842 +                       goto out;
23843 +               pos++;
23844 +               /* fall through */
23845 +       case 1:
23846 +               ino = parent_ino(dentry);
23847 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23848 +                       goto out;
23849 +               pos++;
23850 +               /* fall through */
23851 +       default:
23852 +               index = pos - 2;
23853 +               if (index >= size)
23854 +                       goto out;
23855 +               for (p += index; p->name; p++) {
23856 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23857 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23858 +                               goto out;
23859 +                       pos++;
23860 +               }
23861 +       }
23862 +out:
23863 +       filp->f_pos = pos;
23864 +       return 1;
23865 +}
23866 +
23867 +
23868 +
23869 +static struct file_operations proc_nx_info_file_operations = {
23870 +       .read =         proc_nx_info_read,
23871 +};
23872 +
23873 +static struct dentry_operations proc_nid_dentry_operations = {
23874 +       .d_revalidate = proc_nid_revalidate,
23875 +};
23876 +
23877 +static struct vs_entry nx_base_stuff[] = {
23878 +       NINF("info",    S_IRUGO, nxi_info),
23879 +       NINF("status",  S_IRUGO, nxi_status),
23880 +       {}
23881 +};
23882 +
23883 +
23884 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23885 +       struct dentry *dentry, int id, void *ptr)
23886 +{
23887 +       dentry->d_op = &proc_nid_dentry_operations;
23888 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23889 +}
23890 +
23891 +static struct dentry *proc_nid_lookup(struct inode *dir,
23892 +       struct dentry *dentry, struct nameidata *nd)
23893 +{
23894 +       struct vs_entry *p = nx_base_stuff;
23895 +       struct dentry *error = ERR_PTR(-ENOENT);
23896 +
23897 +       for (; p->name; p++) {
23898 +               if (p->len != dentry->d_name.len)
23899 +                       continue;
23900 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23901 +                       break;
23902 +       }
23903 +       if (!p->name)
23904 +               goto out;
23905 +
23906 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23907 +out:
23908 +       return error;
23909 +}
23910 +
23911 +static int proc_nid_readdir(struct file *filp,
23912 +       void *dirent, filldir_t filldir)
23913 +{
23914 +       struct dentry *dentry = filp->f_dentry;
23915 +       struct inode *inode = dentry->d_inode;
23916 +       struct vs_entry *p = nx_base_stuff;
23917 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23918 +       int pos, index;
23919 +       u64 ino;
23920 +
23921 +       pos = filp->f_pos;
23922 +       switch (pos) {
23923 +       case 0:
23924 +               ino = inode->i_ino;
23925 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23926 +                       goto out;
23927 +               pos++;
23928 +               /* fall through */
23929 +       case 1:
23930 +               ino = parent_ino(dentry);
23931 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23932 +                       goto out;
23933 +               pos++;
23934 +               /* fall through */
23935 +       default:
23936 +               index = pos - 2;
23937 +               if (index >= size)
23938 +                       goto out;
23939 +               for (p += index; p->name; p++) {
23940 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23941 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23942 +                               goto out;
23943 +                       pos++;
23944 +               }
23945 +       }
23946 +out:
23947 +       filp->f_pos = pos;
23948 +       return 1;
23949 +}
23950 +
23951 +
23952 +#define MAX_MULBY10    ((~0U - 9) / 10)
23953 +
23954 +static inline int atovid(const char *str, int len)
23955 +{
23956 +       int vid, c;
23957 +
23958 +       vid = 0;
23959 +       while (len-- > 0) {
23960 +               c = *str - '0';
23961 +               str++;
23962 +               if (c > 9)
23963 +                       return -1;
23964 +               if (vid >= MAX_MULBY10)
23965 +                       return -1;
23966 +               vid *= 10;
23967 +               vid += c;
23968 +               if (!vid)
23969 +                       return -1;
23970 +       }
23971 +       return vid;
23972 +}
23973 +
23974 +/* now the upper level (virtual) */
23975 +
23976 +
23977 +static struct file_operations proc_xid_file_operations = {
23978 +       .read =         generic_read_dir,
23979 +       .readdir =      proc_xid_readdir,
23980 +};
23981 +
23982 +static struct inode_operations proc_xid_inode_operations = {
23983 +       .lookup =       proc_xid_lookup,
23984 +};
23985 +
23986 +static struct vs_entry vx_virtual_stuff[] = {
23987 +       INF("info",     S_IRUGO, virtual_info),
23988 +       INF("status",   S_IRUGO, virtual_status),
23989 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23990 +};
23991 +
23992 +
23993 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23994 +       struct dentry *dentry, struct nameidata *nd)
23995 +{
23996 +       struct vs_entry *p = vx_virtual_stuff;
23997 +       struct dentry *error = ERR_PTR(-ENOENT);
23998 +       int id = 0;
23999 +
24000 +       for (; p->name; p++) {
24001 +               if (p->len != dentry->d_name.len)
24002 +                       continue;
24003 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24004 +                       break;
24005 +       }
24006 +       if (p->name)
24007 +               goto instantiate;
24008 +
24009 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
24010 +       if ((id < 0) || !xid_is_hashed(id))
24011 +               goto out;
24012 +
24013 +instantiate:
24014 +       error = proc_xid_instantiate(dir, dentry, id, p);
24015 +out:
24016 +       return error;
24017 +}
24018 +
24019 +static struct file_operations proc_nid_file_operations = {
24020 +       .read =         generic_read_dir,
24021 +       .readdir =      proc_nid_readdir,
24022 +};
24023 +
24024 +static struct inode_operations proc_nid_inode_operations = {
24025 +       .lookup =       proc_nid_lookup,
24026 +};
24027 +
24028 +static struct vs_entry nx_virtnet_stuff[] = {
24029 +       INF("info",     S_IRUGO, virtnet_info),
24030 +       INF("status",   S_IRUGO, virtnet_status),
24031 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
24032 +};
24033 +
24034 +
24035 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
24036 +       struct dentry *dentry, struct nameidata *nd)
24037 +{
24038 +       struct vs_entry *p = nx_virtnet_stuff;
24039 +       struct dentry *error = ERR_PTR(-ENOENT);
24040 +       int id = 0;
24041 +
24042 +       for (; p->name; p++) {
24043 +               if (p->len != dentry->d_name.len)
24044 +                       continue;
24045 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24046 +                       break;
24047 +       }
24048 +       if (p->name)
24049 +               goto instantiate;
24050 +
24051 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
24052 +       if ((id < 0) || !nid_is_hashed(id))
24053 +               goto out;
24054 +
24055 +instantiate:
24056 +       error = proc_nid_instantiate(dir, dentry, id, p);
24057 +out:
24058 +       return error;
24059 +}
24060 +
24061 +
24062 +#define PROC_MAXVIDS 32
24063 +
24064 +int proc_virtual_readdir(struct file *filp,
24065 +       void *dirent, filldir_t filldir)
24066 +{
24067 +       struct dentry *dentry = filp->f_dentry;
24068 +       struct inode *inode = dentry->d_inode;
24069 +       struct vs_entry *p = vx_virtual_stuff;
24070 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
24071 +       int pos, index;
24072 +       unsigned int xid_array[PROC_MAXVIDS];
24073 +       char buf[PROC_NUMBUF];
24074 +       unsigned int nr_xids, i;
24075 +       u64 ino;
24076 +
24077 +       pos = filp->f_pos;
24078 +       switch (pos) {
24079 +       case 0:
24080 +               ino = inode->i_ino;
24081 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24082 +                       goto out;
24083 +               pos++;
24084 +               /* fall through */
24085 +       case 1:
24086 +               ino = parent_ino(dentry);
24087 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24088 +                       goto out;
24089 +               pos++;
24090 +               /* fall through */
24091 +       default:
24092 +               index = pos - 2;
24093 +               if (index >= size)
24094 +                       goto entries;
24095 +               for (p += index; p->name; p++) {
24096 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24097 +                               vs_proc_instantiate, 0, p))
24098 +                               goto out;
24099 +                       pos++;
24100 +               }
24101 +       entries:
24102 +               index = pos - size;
24103 +               p = &vx_virtual_stuff[size - 1];
24104 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
24105 +               for (i = 0; i < nr_xids; i++) {
24106 +                       int n, xid = xid_array[i];
24107 +                       unsigned int j = PROC_NUMBUF;
24108 +
24109 +                       n = xid;
24110 +                       do
24111 +                               buf[--j] = '0' + (n % 10);
24112 +                       while (n /= 10);
24113 +
24114 +                       if (proc_fill_cache(filp, dirent, filldir,
24115 +                               buf + j, PROC_NUMBUF - j,
24116 +                               vs_proc_instantiate, xid, p))
24117 +                               goto out;
24118 +                       pos++;
24119 +               }
24120 +       }
24121 +out:
24122 +       filp->f_pos = pos;
24123 +       return 0;
24124 +}
24125 +
24126 +static int proc_virtual_getattr(struct vfsmount *mnt,
24127 +       struct dentry *dentry, struct kstat *stat)
24128 +{
24129 +       struct inode *inode = dentry->d_inode;
24130 +
24131 +       generic_fillattr(inode, stat);
24132 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
24133 +       return 0;
24134 +}
24135 +
24136 +static struct file_operations proc_virtual_dir_operations = {
24137 +       .read =         generic_read_dir,
24138 +       .readdir =      proc_virtual_readdir,
24139 +};
24140 +
24141 +static struct inode_operations proc_virtual_dir_inode_operations = {
24142 +       .getattr =      proc_virtual_getattr,
24143 +       .lookup =       proc_virtual_lookup,
24144 +};
24145 +
24146 +
24147 +
24148 +
24149 +
24150 +int proc_virtnet_readdir(struct file *filp,
24151 +       void *dirent, filldir_t filldir)
24152 +{
24153 +       struct dentry *dentry = filp->f_dentry;
24154 +       struct inode *inode = dentry->d_inode;
24155 +       struct vs_entry *p = nx_virtnet_stuff;
24156 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
24157 +       int pos, index;
24158 +       unsigned int nid_array[PROC_MAXVIDS];
24159 +       char buf[PROC_NUMBUF];
24160 +       unsigned int nr_nids, i;
24161 +       u64 ino;
24162 +
24163 +       pos = filp->f_pos;
24164 +       switch (pos) {
24165 +       case 0:
24166 +               ino = inode->i_ino;
24167 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24168 +                       goto out;
24169 +               pos++;
24170 +               /* fall through */
24171 +       case 1:
24172 +               ino = parent_ino(dentry);
24173 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24174 +                       goto out;
24175 +               pos++;
24176 +               /* fall through */
24177 +       default:
24178 +               index = pos - 2;
24179 +               if (index >= size)
24180 +                       goto entries;
24181 +               for (p += index; p->name; p++) {
24182 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24183 +                               vs_proc_instantiate, 0, p))
24184 +                               goto out;
24185 +                       pos++;
24186 +               }
24187 +       entries:
24188 +               index = pos - size;
24189 +               p = &nx_virtnet_stuff[size - 1];
24190 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
24191 +               for (i = 0; i < nr_nids; i++) {
24192 +                       int n, nid = nid_array[i];
24193 +                       unsigned int j = PROC_NUMBUF;
24194 +
24195 +                       n = nid;
24196 +                       do
24197 +                               buf[--j] = '0' + (n % 10);
24198 +                       while (n /= 10);
24199 +
24200 +                       if (proc_fill_cache(filp, dirent, filldir,
24201 +                               buf + j, PROC_NUMBUF - j,
24202 +                               vs_proc_instantiate, nid, p))
24203 +                               goto out;
24204 +                       pos++;
24205 +               }
24206 +       }
24207 +out:
24208 +       filp->f_pos = pos;
24209 +       return 0;
24210 +}
24211 +
24212 +static int proc_virtnet_getattr(struct vfsmount *mnt,
24213 +       struct dentry *dentry, struct kstat *stat)
24214 +{
24215 +       struct inode *inode = dentry->d_inode;
24216 +
24217 +       generic_fillattr(inode, stat);
24218 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
24219 +       return 0;
24220 +}
24221 +
24222 +static struct file_operations proc_virtnet_dir_operations = {
24223 +       .read =         generic_read_dir,
24224 +       .readdir =      proc_virtnet_readdir,
24225 +};
24226 +
24227 +static struct inode_operations proc_virtnet_dir_inode_operations = {
24228 +       .getattr =      proc_virtnet_getattr,
24229 +       .lookup =       proc_virtnet_lookup,
24230 +};
24231 +
24232 +
24233 +
24234 +void proc_vx_init(void)
24235 +{
24236 +       struct proc_dir_entry *ent;
24237 +
24238 +       ent = proc_mkdir("virtual", 0);
24239 +       if (ent) {
24240 +               ent->proc_fops = &proc_virtual_dir_operations;
24241 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
24242 +       }
24243 +       proc_virtual = ent;
24244 +
24245 +       ent = proc_mkdir("virtnet", 0);
24246 +       if (ent) {
24247 +               ent->proc_fops = &proc_virtnet_dir_operations;
24248 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
24249 +       }
24250 +       proc_virtnet = ent;
24251 +}
24252 +
24253 +
24254 +
24255 +
24256 +/* per pid info */
24257 +
24258 +
24259 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
24260 +{
24261 +       struct vx_info *vxi;
24262 +       char *orig = buffer;
24263 +
24264 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
24265 +
24266 +       vxi = task_get_vx_info(p);
24267 +       if (!vxi)
24268 +               goto out;
24269 +
24270 +       buffer += sprintf(buffer, "BCaps:\t");
24271 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
24272 +       buffer += sprintf(buffer, "\n");
24273 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
24274 +               (unsigned long long)vxi->vx_ccaps);
24275 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
24276 +               (unsigned long long)vxi->vx_flags);
24277 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
24278 +
24279 +       put_vx_info(vxi);
24280 +out:
24281 +       return buffer - orig;
24282 +}
24283 +
24284 +
24285 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24286 +{
24287 +       struct nx_info *nxi;
24288 +       struct nx_addr_v4 *v4a;
24289 +#ifdef CONFIG_IPV6
24290 +       struct nx_addr_v6 *v6a;
24291 +#endif
24292 +       char *orig = buffer;
24293 +       int i;
24294 +
24295 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24296 +
24297 +       nxi = task_get_nx_info(p);
24298 +       if (!nxi)
24299 +               goto out;
24300 +
24301 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24302 +               (unsigned long long)nxi->nx_ncaps);
24303 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24304 +               (unsigned long long)nxi->nx_flags);
24305 +
24306 +       buffer += sprintf(buffer,
24307 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24308 +               NIPQUAD(nxi->v4_bcast.s_addr));
24309 +       buffer += sprintf (buffer,
24310 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
24311 +               NIPQUAD(nxi->v4_lback.s_addr));
24312 +       if (!NX_IPV4(nxi))
24313 +               goto skip_v4;
24314 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24315 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
24316 +                       i, NXAV4(v4a));
24317 +skip_v4:
24318 +#ifdef CONFIG_IPV6
24319 +       if (!NX_IPV6(nxi))
24320 +               goto skip_v6;
24321 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24322 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24323 +                       i, NXAV6(v6a));
24324 +skip_v6:
24325 +#endif
24326 +       put_nx_info(nxi);
24327 +out:
24328 +       return buffer - orig;
24329 +}
24330 +
24331 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/sched.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/sched.c
24332 --- linux-2.6.32.10/kernel/vserver/sched.c      1970-01-01 01:00:00.000000000 +0100
24333 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/sched.c      2009-12-03 20:04:56.000000000 +0100
24334 @@ -0,0 +1,414 @@
24335 +/*
24336 + *  linux/kernel/vserver/sched.c
24337 + *
24338 + *  Virtual Server: Scheduler Support
24339 + *
24340 + *  Copyright (C) 2004-2007  Herbert Pötzl
24341 + *
24342 + *  V0.01  adapted Sam Vilains version to 2.6.3
24343 + *  V0.02  removed legacy interface
24344 + *  V0.03  changed vcmds to vxi arg
24345 + *  V0.04  removed older and legacy interfaces
24346 + *
24347 + */
24348 +
24349 +#include <linux/vs_context.h>
24350 +#include <linux/vs_sched.h>
24351 +#include <linux/vserver/sched_cmd.h>
24352 +
24353 +#include <asm/uaccess.h>
24354 +
24355 +
24356 +#define vxd_check_range(val, min, max) do {            \
24357 +       vxlprintk((val < min) || (val > max),           \
24358 +               "check_range(%ld,%ld,%ld)",             \
24359 +               (long)val, (long)min, (long)max,        \
24360 +               __FILE__, __LINE__);                    \
24361 +       } while (0)
24362 +
24363 +
24364 +void vx_update_sched_param(struct _vx_sched *sched,
24365 +       struct _vx_sched_pc *sched_pc)
24366 +{
24367 +       unsigned int set_mask = sched->update_mask;
24368 +
24369 +       if (set_mask & VXSM_FILL_RATE)
24370 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
24371 +       if (set_mask & VXSM_INTERVAL)
24372 +               sched_pc->interval[0] = sched->interval[0];
24373 +       if (set_mask & VXSM_FILL_RATE2)
24374 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
24375 +       if (set_mask & VXSM_INTERVAL2)
24376 +               sched_pc->interval[1] = sched->interval[1];
24377 +       if (set_mask & VXSM_TOKENS)
24378 +               sched_pc->tokens = sched->tokens;
24379 +       if (set_mask & VXSM_TOKENS_MIN)
24380 +               sched_pc->tokens_min = sched->tokens_min;
24381 +       if (set_mask & VXSM_TOKENS_MAX)
24382 +               sched_pc->tokens_max = sched->tokens_max;
24383 +       if (set_mask & VXSM_PRIO_BIAS)
24384 +               sched_pc->prio_bias = sched->prio_bias;
24385 +
24386 +       if (set_mask & VXSM_IDLE_TIME)
24387 +               sched_pc->flags |= VXSF_IDLE_TIME;
24388 +       else
24389 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
24390 +
24391 +       /* reset time */
24392 +       sched_pc->norm_time = jiffies;
24393 +}
24394 +
24395 +
24396 +/*
24397 + * recalculate the context's scheduling tokens
24398 + *
24399 + * ret > 0 : number of tokens available
24400 + * ret < 0 : on hold, check delta_min[]
24401 + *          -1 only jiffies
24402 + *          -2 also idle time
24403 + *
24404 + */
24405 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
24406 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
24407 +{
24408 +       long delta;
24409 +       long tokens = 0;
24410 +       int flags = sched_pc->flags;
24411 +
24412 +       /* how much time did pass? */
24413 +       delta = *norm_time - sched_pc->norm_time;
24414 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
24415 +       vxd_check_range(delta, 0, INT_MAX);
24416 +
24417 +       if (delta >= sched_pc->interval[0]) {
24418 +               long tokens, integral;
24419 +
24420 +               /* calc integral token part */
24421 +               tokens = delta / sched_pc->interval[0];
24422 +               integral = tokens * sched_pc->interval[0];
24423 +               tokens *= sched_pc->fill_rate[0];
24424 +#ifdef CONFIG_VSERVER_HARDCPU
24425 +               delta_min[0] = delta - integral;
24426 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
24427 +#endif
24428 +               /* advance time */
24429 +               sched_pc->norm_time += delta;
24430 +
24431 +               /* add tokens */
24432 +               sched_pc->tokens += tokens;
24433 +               sched_pc->token_time += tokens;
24434 +       } else
24435 +               delta_min[0] = delta;
24436 +
24437 +#ifdef CONFIG_VSERVER_IDLETIME
24438 +       if (!(flags & VXSF_IDLE_TIME))
24439 +               goto skip_idle;
24440 +
24441 +       /* how much was the idle skip? */
24442 +       delta = *idle_time - sched_pc->idle_time;
24443 +       vxd_check_range(delta, 0, INT_MAX);
24444 +
24445 +       if (delta >= sched_pc->interval[1]) {
24446 +               long tokens, integral;
24447 +
24448 +               /* calc fair share token part */
24449 +               tokens = delta / sched_pc->interval[1];
24450 +               integral = tokens * sched_pc->interval[1];
24451 +               tokens *= sched_pc->fill_rate[1];
24452 +               delta_min[1] = delta - integral;
24453 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
24454 +
24455 +               /* advance idle time */
24456 +               sched_pc->idle_time += integral;
24457 +
24458 +               /* add tokens */
24459 +               sched_pc->tokens += tokens;
24460 +               sched_pc->token_time += tokens;
24461 +       } else
24462 +               delta_min[1] = delta;
24463 +skip_idle:
24464 +#endif
24465 +
24466 +       /* clip at maximum */
24467 +       if (sched_pc->tokens > sched_pc->tokens_max)
24468 +               sched_pc->tokens = sched_pc->tokens_max;
24469 +       tokens = sched_pc->tokens;
24470 +
24471 +       if ((flags & VXSF_ONHOLD)) {
24472 +               /* can we unhold? */
24473 +               if (tokens >= sched_pc->tokens_min) {
24474 +                       flags &= ~VXSF_ONHOLD;
24475 +                       sched_pc->hold_ticks +=
24476 +                               *norm_time - sched_pc->onhold;
24477 +               } else
24478 +                       goto on_hold;
24479 +       } else {
24480 +               /* put on hold? */
24481 +               if (tokens <= 0) {
24482 +                       flags |= VXSF_ONHOLD;
24483 +                       sched_pc->onhold = *norm_time;
24484 +                       goto on_hold;
24485 +               }
24486 +       }
24487 +       sched_pc->flags = flags;
24488 +       return tokens;
24489 +
24490 +on_hold:
24491 +       tokens = sched_pc->tokens_min - tokens;
24492 +       sched_pc->flags = flags;
24493 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
24494 +
24495 +#ifdef CONFIG_VSERVER_HARDCPU
24496 +       /* next interval? */
24497 +       if (!sched_pc->fill_rate[0])
24498 +               delta_min[0] = HZ;
24499 +       else if (tokens > sched_pc->fill_rate[0])
24500 +               delta_min[0] += sched_pc->interval[0] *
24501 +                       tokens / sched_pc->fill_rate[0];
24502 +       else
24503 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24504 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24505 +
24506 +#ifdef CONFIG_VSERVER_IDLETIME
24507 +       if (!(flags & VXSF_IDLE_TIME))
24508 +               return -1;
24509 +
24510 +       /* next interval? */
24511 +       if (!sched_pc->fill_rate[1])
24512 +               delta_min[1] = HZ;
24513 +       else if (tokens > sched_pc->fill_rate[1])
24514 +               delta_min[1] += sched_pc->interval[1] *
24515 +                       tokens / sched_pc->fill_rate[1];
24516 +       else
24517 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24518 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24519 +
24520 +       return -2;
24521 +#else
24522 +       return -1;
24523 +#endif /* CONFIG_VSERVER_IDLETIME */
24524 +#else
24525 +       return 0;
24526 +#endif /* CONFIG_VSERVER_HARDCPU */
24527 +}
24528 +
24529 +static inline unsigned long msec_to_ticks(unsigned long msec)
24530 +{
24531 +       return msecs_to_jiffies(msec);
24532 +}
24533 +
24534 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24535 +{
24536 +       return jiffies_to_msecs(ticks);
24537 +}
24538 +
24539 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24540 +{
24541 +       return jiffies_to_usecs(ticks);
24542 +}
24543 +
24544 +
24545 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24546 +{
24547 +       unsigned int set_mask = data->mask;
24548 +       unsigned int update_mask;
24549 +       int i, cpu;
24550 +
24551 +       /* Sanity check data values */
24552 +       if (data->tokens_max <= 0)
24553 +               data->tokens_max = HZ;
24554 +       if (data->tokens_min < 0)
24555 +               data->tokens_min = HZ / 3;
24556 +       if (data->tokens_min >= data->tokens_max)
24557 +               data->tokens_min = data->tokens_max;
24558 +
24559 +       if (data->prio_bias > MAX_PRIO_BIAS)
24560 +               data->prio_bias = MAX_PRIO_BIAS;
24561 +       if (data->prio_bias < MIN_PRIO_BIAS)
24562 +               data->prio_bias = MIN_PRIO_BIAS;
24563 +
24564 +       spin_lock(&vxi->sched.tokens_lock);
24565 +
24566 +       /* sync up on delayed updates */
24567 +       for_each_cpu_mask(cpu, vxi->sched.update)
24568 +               vx_update_sched_param(&vxi->sched,
24569 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24570 +
24571 +       if (set_mask & VXSM_FILL_RATE)
24572 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24573 +       if (set_mask & VXSM_FILL_RATE2)
24574 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24575 +       if (set_mask & VXSM_INTERVAL)
24576 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24577 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24578 +       if (set_mask & VXSM_INTERVAL2)
24579 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24580 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24581 +       if (set_mask & VXSM_TOKENS)
24582 +               vxi->sched.tokens = data->tokens;
24583 +       if (set_mask & VXSM_TOKENS_MIN)
24584 +               vxi->sched.tokens_min = data->tokens_min;
24585 +       if (set_mask & VXSM_TOKENS_MAX)
24586 +               vxi->sched.tokens_max = data->tokens_max;
24587 +       if (set_mask & VXSM_PRIO_BIAS)
24588 +               vxi->sched.prio_bias = data->prio_bias;
24589 +
24590 +       /* Sanity check rate/interval */
24591 +       for (i = 0; i < 2; i++) {
24592 +               if (data->fill_rate[i] < 0)
24593 +                       data->fill_rate[i] = 0;
24594 +               if (data->interval[i] <= 0)
24595 +                       data->interval[i] = HZ;
24596 +       }
24597 +
24598 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24599 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24600 +       vxi->sched.update_mask = update_mask;
24601 +
24602 +#ifdef CONFIG_SMP
24603 +       rmb();
24604 +       if (set_mask & VXSM_CPU_ID) {
24605 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24606 +               cpus_and(vxi->sched.update, cpu_online_map,
24607 +                       vxi->sched.update);
24608 +       } else
24609 +               vxi->sched.update = cpu_online_map;
24610 +
24611 +       /* forced reload? */
24612 +       if (set_mask & VXSM_FORCE) {
24613 +               for_each_cpu_mask(cpu, vxi->sched.update)
24614 +                       vx_update_sched_param(&vxi->sched,
24615 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24616 +               vxi->sched.update = CPU_MASK_NONE;
24617 +       }
24618 +#else
24619 +       /* on UP we update immediately */
24620 +       vx_update_sched_param(&vxi->sched,
24621 +               &vx_per_cpu(vxi, sched_pc, 0));
24622 +#endif
24623 +
24624 +       spin_unlock(&vxi->sched.tokens_lock);
24625 +       return 0;
24626 +}
24627 +
24628 +
24629 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24630 +#define COPY_PRI(C) C(prio_bias)
24631 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24632 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24633 +                   C(fill_rate[1]); C(interval[1]);
24634 +
24635 +#define COPY_VALUE(name) vc_data.name = data->name
24636 +
24637 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24638 +{
24639 +       struct vcmd_sched_v5 vc_data;
24640 +
24641 +       vc_data.mask = data->set_mask;
24642 +       COPY_IDS(COPY_VALUE);
24643 +       COPY_PRI(COPY_VALUE);
24644 +       COPY_TOK(COPY_VALUE);
24645 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24646 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24647 +       return do_set_sched(vxi, &vc_data);
24648 +}
24649 +
24650 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24651 +{
24652 +       struct vcmd_set_sched_v4 vc_data;
24653 +
24654 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24655 +               return -EFAULT;
24656 +
24657 +       return do_set_sched_v4(vxi, &vc_data);
24658 +}
24659 +
24660 +       /* latest interface is v5 */
24661 +
24662 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24663 +{
24664 +       struct vcmd_sched_v5 vc_data;
24665 +
24666 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24667 +               return -EFAULT;
24668 +
24669 +       return do_set_sched(vxi, &vc_data);
24670 +}
24671 +
24672 +
24673 +#define COPY_PRI(C) C(prio_bias)
24674 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24675 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24676 +                   C(fill_rate[1]); C(interval[1]);
24677 +
24678 +#define COPY_VALUE(name) vc_data.name = data->name
24679 +
24680 +
24681 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24682 +{
24683 +       struct vcmd_sched_v5 vc_data;
24684 +
24685 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24686 +               return -EFAULT;
24687 +
24688 +       if (vc_data.mask & VXSM_CPU_ID) {
24689 +               int cpu = vc_data.cpu_id;
24690 +               struct _vx_sched_pc *data;
24691 +
24692 +               if (!cpu_possible(cpu))
24693 +                       return -EINVAL;
24694 +
24695 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24696 +               COPY_TOK(COPY_VALUE);
24697 +               COPY_PRI(COPY_VALUE);
24698 +               COPY_FRI(COPY_VALUE);
24699 +
24700 +               if (data->flags & VXSF_IDLE_TIME)
24701 +                       vc_data.mask |= VXSM_IDLE_TIME;
24702 +       } else {
24703 +               struct _vx_sched *data = &vxi->sched;
24704 +
24705 +               COPY_TOK(COPY_VALUE);
24706 +               COPY_PRI(COPY_VALUE);
24707 +               COPY_FRI(COPY_VALUE);
24708 +       }
24709 +
24710 +       if (vc_data.mask & VXSM_MSEC) {
24711 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24712 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24713 +       }
24714 +
24715 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24716 +               return -EFAULT;
24717 +       return 0;
24718 +}
24719 +
24720 +
24721 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24722 +{
24723 +       struct vcmd_sched_info vc_data;
24724 +       int cpu;
24725 +
24726 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24727 +               return -EFAULT;
24728 +
24729 +       cpu = vc_data.cpu_id;
24730 +       if (!cpu_possible(cpu))
24731 +               return -EINVAL;
24732 +
24733 +       if (vxi) {
24734 +               struct _vx_sched_pc *sched_pc =
24735 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24736 +
24737 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24738 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24739 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24740 +               vc_data.vavavoom = sched_pc->vavavoom;
24741 +       }
24742 +       vc_data.token_usec = ticks_to_usec(1);
24743 +
24744 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24745 +               return -EFAULT;
24746 +       return 0;
24747 +}
24748 +
24749 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/sched_init.h linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/sched_init.h
24750 --- linux-2.6.32.10/kernel/vserver/sched_init.h 1970-01-01 01:00:00.000000000 +0100
24751 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/sched_init.h 2009-12-03 20:04:56.000000000 +0100
24752 @@ -0,0 +1,50 @@
24753 +
24754 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24755 +{
24756 +       static struct lock_class_key tokens_lock_key;
24757 +
24758 +       /* scheduling; hard code starting values as constants */
24759 +       sched->fill_rate[0]     = 1;
24760 +       sched->interval[0]      = 4;
24761 +       sched->fill_rate[1]     = 1;
24762 +       sched->interval[1]      = 8;
24763 +       sched->tokens           = HZ >> 2;
24764 +       sched->tokens_min       = HZ >> 4;
24765 +       sched->tokens_max       = HZ >> 1;
24766 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24767 +       sched->prio_bias        = 0;
24768 +
24769 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24770 +}
24771 +
24772 +static inline
24773 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24774 +{
24775 +       sched_pc->fill_rate[0]  = 1;
24776 +       sched_pc->interval[0]   = 4;
24777 +       sched_pc->fill_rate[1]  = 1;
24778 +       sched_pc->interval[1]   = 8;
24779 +       sched_pc->tokens        = HZ >> 2;
24780 +       sched_pc->tokens_min    = HZ >> 4;
24781 +       sched_pc->tokens_max    = HZ >> 1;
24782 +       sched_pc->prio_bias     = 0;
24783 +       sched_pc->vavavoom      = 0;
24784 +       sched_pc->token_time    = 0;
24785 +       sched_pc->idle_time     = 0;
24786 +       sched_pc->norm_time     = jiffies;
24787 +
24788 +       sched_pc->user_ticks = 0;
24789 +       sched_pc->sys_ticks = 0;
24790 +       sched_pc->hold_ticks = 0;
24791 +}
24792 +
24793 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24794 +{
24795 +       return;
24796 +}
24797 +
24798 +static inline
24799 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24800 +{
24801 +       return;
24802 +}
24803 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/sched_proc.h linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/sched_proc.h
24804 --- linux-2.6.32.10/kernel/vserver/sched_proc.h 1970-01-01 01:00:00.000000000 +0100
24805 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/sched_proc.h 2009-12-03 20:04:56.000000000 +0100
24806 @@ -0,0 +1,57 @@
24807 +#ifndef _VX_SCHED_PROC_H
24808 +#define _VX_SCHED_PROC_H
24809 +
24810 +
24811 +static inline
24812 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24813 +{
24814 +       int length = 0;
24815 +
24816 +       length += sprintf(buffer,
24817 +               "FillRate:\t%8d,%d\n"
24818 +               "Interval:\t%8d,%d\n"
24819 +               "TokensMin:\t%8d\n"
24820 +               "TokensMax:\t%8d\n"
24821 +               "PrioBias:\t%8d\n",
24822 +               sched->fill_rate[0],
24823 +               sched->fill_rate[1],
24824 +               sched->interval[0],
24825 +               sched->interval[1],
24826 +               sched->tokens_min,
24827 +               sched->tokens_max,
24828 +               sched->prio_bias);
24829 +       return length;
24830 +}
24831 +
24832 +static inline
24833 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24834 +       char *buffer, int cpu)
24835 +{
24836 +       int length = 0;
24837 +
24838 +       length += sprintf(buffer + length,
24839 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24840 +               (unsigned long long)sched_pc->user_ticks,
24841 +               (unsigned long long)sched_pc->sys_ticks,
24842 +               (unsigned long long)sched_pc->hold_ticks,
24843 +               sched_pc->token_time,
24844 +               sched_pc->idle_time);
24845 +       length += sprintf(buffer + length,
24846 +               " %c%c %d %d %d %d/%d %d/%d",
24847 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24848 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24849 +               sched_pc->tokens,
24850 +               sched_pc->tokens_min,
24851 +               sched_pc->tokens_max,
24852 +               sched_pc->fill_rate[0],
24853 +               sched_pc->interval[0],
24854 +               sched_pc->fill_rate[1],
24855 +               sched_pc->interval[1]);
24856 +       length += sprintf(buffer + length,
24857 +               " %d %d\n",
24858 +               sched_pc->prio_bias,
24859 +               sched_pc->vavavoom);
24860 +       return length;
24861 +}
24862 +
24863 +#endif /* _VX_SCHED_PROC_H */
24864 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/signal.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/signal.c
24865 --- linux-2.6.32.10/kernel/vserver/signal.c     1970-01-01 01:00:00.000000000 +0100
24866 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/signal.c     2009-12-03 20:04:56.000000000 +0100
24867 @@ -0,0 +1,132 @@
24868 +/*
24869 + *  linux/kernel/vserver/signal.c
24870 + *
24871 + *  Virtual Server: Signal Support
24872 + *
24873 + *  Copyright (C) 2003-2007  Herbert Pötzl
24874 + *
24875 + *  V0.01  broken out from vcontext V0.05
24876 + *  V0.02  changed vcmds to vxi arg
24877 + *  V0.03  adjusted siginfo for kill
24878 + *
24879 + */
24880 +
24881 +#include <asm/uaccess.h>
24882 +
24883 +#include <linux/vs_context.h>
24884 +#include <linux/vs_pid.h>
24885 +#include <linux/vserver/signal_cmd.h>
24886 +
24887 +
24888 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24889 +{
24890 +       int retval, count = 0;
24891 +       struct task_struct *p;
24892 +       struct siginfo *sip = SEND_SIG_PRIV;
24893 +
24894 +       retval = -ESRCH;
24895 +       vxdprintk(VXD_CBIT(misc, 4),
24896 +               "vx_info_kill(%p[#%d],%d,%d)*",
24897 +               vxi, vxi->vx_id, pid, sig);
24898 +       read_lock(&tasklist_lock);
24899 +       switch (pid) {
24900 +       case  0:
24901 +       case -1:
24902 +               for_each_process(p) {
24903 +                       int err = 0;
24904 +
24905 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24906 +                               (pid && vxi->vx_initpid == p->pid))
24907 +                               continue;
24908 +
24909 +                       err = group_send_sig_info(sig, sip, p);
24910 +                       ++count;
24911 +                       if (err != -EPERM)
24912 +                               retval = err;
24913 +               }
24914 +               break;
24915 +
24916 +       case 1:
24917 +               if (vxi->vx_initpid) {
24918 +                       pid = vxi->vx_initpid;
24919 +                       /* for now, only SIGINT to private init ... */
24920 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24921 +                               /* ... as long as there are tasks left */
24922 +                               (atomic_read(&vxi->vx_tasks) > 1))
24923 +                               sig = SIGINT;
24924 +               }
24925 +               /* fallthrough */
24926 +       default:
24927 +               p = find_task_by_real_pid(pid);
24928 +               if (p) {
24929 +                       if (vx_task_xid(p) == vxi->vx_id)
24930 +                               retval = group_send_sig_info(sig, sip, p);
24931 +               }
24932 +               break;
24933 +       }
24934 +       read_unlock(&tasklist_lock);
24935 +       vxdprintk(VXD_CBIT(misc, 4),
24936 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24937 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24938 +       return retval;
24939 +}
24940 +
24941 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24942 +{
24943 +       struct vcmd_ctx_kill_v0 vc_data;
24944 +
24945 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24946 +               return -EFAULT;
24947 +
24948 +       /* special check to allow guest shutdown */
24949 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24950 +               /* forbid killall pid=0 when init is present */
24951 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24952 +               (vc_data.pid > 1)))
24953 +               return -EACCES;
24954 +
24955 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24956 +}
24957 +
24958 +
24959 +static int __wait_exit(struct vx_info *vxi)
24960 +{
24961 +       DECLARE_WAITQUEUE(wait, current);
24962 +       int ret = 0;
24963 +
24964 +       add_wait_queue(&vxi->vx_wait, &wait);
24965 +       set_current_state(TASK_INTERRUPTIBLE);
24966 +
24967 +wait:
24968 +       if (vx_info_state(vxi,
24969 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24970 +               goto out;
24971 +       if (signal_pending(current)) {
24972 +               ret = -ERESTARTSYS;
24973 +               goto out;
24974 +       }
24975 +       schedule();
24976 +       goto wait;
24977 +
24978 +out:
24979 +       set_current_state(TASK_RUNNING);
24980 +       remove_wait_queue(&vxi->vx_wait, &wait);
24981 +       return ret;
24982 +}
24983 +
24984 +
24985 +
24986 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24987 +{
24988 +       struct vcmd_wait_exit_v0 vc_data;
24989 +       int ret;
24990 +
24991 +       ret = __wait_exit(vxi);
24992 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24993 +       vc_data.exit_code = vxi->exit_code;
24994 +
24995 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24996 +               ret = -EFAULT;
24997 +       return ret;
24998 +}
24999 +
25000 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/space.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/space.c
25001 --- linux-2.6.32.10/kernel/vserver/space.c      1970-01-01 01:00:00.000000000 +0100
25002 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/space.c      2009-12-03 20:04:56.000000000 +0100
25003 @@ -0,0 +1,375 @@
25004 +/*
25005 + *  linux/kernel/vserver/space.c
25006 + *
25007 + *  Virtual Server: Context Space Support
25008 + *
25009 + *  Copyright (C) 2003-2007  Herbert Pötzl
25010 + *
25011 + *  V0.01  broken out from context.c 0.07
25012 + *  V0.02  added task locking for namespace
25013 + *  V0.03  broken out vx_enter_namespace
25014 + *  V0.04  added *space support and commands
25015 + *
25016 + */
25017 +
25018 +#include <linux/utsname.h>
25019 +#include <linux/nsproxy.h>
25020 +#include <linux/err.h>
25021 +#include <linux/fs_struct.h>
25022 +#include <asm/uaccess.h>
25023 +
25024 +#include <linux/vs_context.h>
25025 +#include <linux/vserver/space.h>
25026 +#include <linux/vserver/space_cmd.h>
25027 +
25028 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
25029 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
25030 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
25031 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
25032 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
25033 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
25034 +
25035 +
25036 +/* namespace functions */
25037 +
25038 +#include <linux/mnt_namespace.h>
25039 +#include <linux/user_namespace.h>
25040 +#include <linux/pid_namespace.h>
25041 +#include <linux/ipc_namespace.h>
25042 +#include <net/net_namespace.h>
25043 +
25044 +
25045 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
25046 +       .mask = CLONE_FS |
25047 +               CLONE_NEWNS |
25048 +               CLONE_NEWUTS |
25049 +               CLONE_NEWIPC |
25050 +               CLONE_NEWUSER |
25051 +               0
25052 +};
25053 +
25054 +static const struct vcmd_space_mask_v1 space_mask = {
25055 +       .mask = CLONE_FS |
25056 +               CLONE_NEWNS |
25057 +               CLONE_NEWUTS |
25058 +               CLONE_NEWIPC |
25059 +               CLONE_NEWUSER |
25060 +#ifdef CONFIG_PID_NS
25061 +               CLONE_NEWPID |
25062 +#endif
25063 +#ifdef CONFIG_NET_NS
25064 +               CLONE_NEWNET |
25065 +#endif
25066 +               0
25067 +};
25068 +
25069 +static const struct vcmd_space_mask_v1 default_space_mask = {
25070 +       .mask = CLONE_FS |
25071 +               CLONE_NEWNS |
25072 +               CLONE_NEWUTS |
25073 +               CLONE_NEWIPC |
25074 +               CLONE_NEWUSER |
25075 +#ifdef CONFIG_PID_NS
25076 +//             CLONE_NEWPID |
25077 +#endif
25078 +               0
25079 +};
25080 +
25081 +/*
25082 + *     build a new nsproxy mix
25083 + *      assumes that both proxies are 'const'
25084 + *     does not touch nsproxy refcounts
25085 + *     will hold a reference on the result.
25086 + */
25087 +
25088 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
25089 +       struct nsproxy *new_nsproxy, unsigned long mask)
25090 +{
25091 +       struct mnt_namespace *old_ns;
25092 +       struct uts_namespace *old_uts;
25093 +       struct ipc_namespace *old_ipc;
25094 +#ifdef CONFIG_PID_NS
25095 +       struct pid_namespace *old_pid;
25096 +#endif
25097 +#ifdef CONFIG_NET_NS
25098 +       struct net *old_net;
25099 +#endif
25100 +       struct nsproxy *nsproxy;
25101 +
25102 +       nsproxy = copy_nsproxy(old_nsproxy);
25103 +       if (!nsproxy)
25104 +               goto out;
25105 +
25106 +       if (mask & CLONE_NEWNS) {
25107 +               old_ns = nsproxy->mnt_ns;
25108 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
25109 +               if (nsproxy->mnt_ns)
25110 +                       get_mnt_ns(nsproxy->mnt_ns);
25111 +       } else
25112 +               old_ns = NULL;
25113 +
25114 +       if (mask & CLONE_NEWUTS) {
25115 +               old_uts = nsproxy->uts_ns;
25116 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
25117 +               if (nsproxy->uts_ns)
25118 +                       get_uts_ns(nsproxy->uts_ns);
25119 +       } else
25120 +               old_uts = NULL;
25121 +
25122 +       if (mask & CLONE_NEWIPC) {
25123 +               old_ipc = nsproxy->ipc_ns;
25124 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
25125 +               if (nsproxy->ipc_ns)
25126 +                       get_ipc_ns(nsproxy->ipc_ns);
25127 +       } else
25128 +               old_ipc = NULL;
25129 +
25130 +#ifdef CONFIG_PID_NS
25131 +       if (mask & CLONE_NEWPID) {
25132 +               old_pid = nsproxy->pid_ns;
25133 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
25134 +               if (nsproxy->pid_ns)
25135 +                       get_pid_ns(nsproxy->pid_ns);
25136 +       } else
25137 +               old_pid = NULL;
25138 +#endif
25139 +#ifdef CONFIG_NET_NS
25140 +       if (mask & CLONE_NEWNET) {
25141 +               old_net = nsproxy->net_ns;
25142 +               nsproxy->net_ns = new_nsproxy->net_ns;
25143 +               if (nsproxy->net_ns)
25144 +                       get_net(nsproxy->net_ns);
25145 +       } else
25146 +               old_net = NULL;
25147 +#endif
25148 +       if (old_ns)
25149 +               put_mnt_ns(old_ns);
25150 +       if (old_uts)
25151 +               put_uts_ns(old_uts);
25152 +       if (old_ipc)
25153 +               put_ipc_ns(old_ipc);
25154 +#ifdef CONFIG_PID_NS
25155 +       if (old_pid)
25156 +               put_pid_ns(old_pid);
25157 +#endif
25158 +#ifdef CONFIG_NET_NS
25159 +       if (old_net)
25160 +               put_net(old_net);
25161 +#endif
25162 +out:
25163 +       return nsproxy;
25164 +}
25165 +
25166 +
25167 +/*
25168 + *     merge two nsproxy structs into a new one.
25169 + *     will hold a reference on the result.
25170 + */
25171 +
25172 +static inline
25173 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
25174 +       struct nsproxy *proxy, unsigned long mask)
25175 +{
25176 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
25177 +
25178 +       if (!proxy)
25179 +               return NULL;
25180 +
25181 +       if (mask) {
25182 +               /* vs_mix_nsproxy returns with reference */
25183 +               return vs_mix_nsproxy(old ? old : &null_proxy,
25184 +                       proxy, mask);
25185 +       }
25186 +       get_nsproxy(proxy);
25187 +       return proxy;
25188 +}
25189 +
25190 +
25191 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25192 +{
25193 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
25194 +       struct fs_struct *fs_cur, *fs = NULL;
25195 +       int ret, kill = 0;
25196 +
25197 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
25198 +               vxi, vxi->vx_id, mask, index);
25199 +
25200 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
25201 +               return -EACCES;
25202 +
25203 +       if (!mask)
25204 +               mask = vxi->vx_nsmask[index];
25205 +
25206 +       if ((mask & vxi->vx_nsmask[index]) != mask)
25207 +               return -EINVAL;
25208 +
25209 +       if (mask & CLONE_FS) {
25210 +               fs = copy_fs_struct(vxi->vx_fs[index]);
25211 +               if (!fs)
25212 +                       return -ENOMEM;
25213 +       }
25214 +       proxy = vxi->vx_nsproxy[index];
25215 +
25216 +       vxdprintk(VXD_CBIT(space, 9),
25217 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
25218 +               vxi, vxi->vx_id, mask, index, proxy, fs);
25219 +
25220 +       task_lock(current);
25221 +       fs_cur = current->fs;
25222 +
25223 +       if (mask & CLONE_FS) {
25224 +               write_lock(&fs_cur->lock);
25225 +               current->fs = fs;
25226 +               kill = !--fs_cur->users;
25227 +               write_unlock(&fs_cur->lock);
25228 +       }
25229 +
25230 +       proxy_cur = current->nsproxy;
25231 +       get_nsproxy(proxy_cur);
25232 +       task_unlock(current);
25233 +
25234 +       if (kill)
25235 +               free_fs_struct(fs_cur);
25236 +
25237 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
25238 +       if (IS_ERR(proxy_new)) {
25239 +               ret = PTR_ERR(proxy_new);
25240 +               goto out_put;
25241 +       }
25242 +
25243 +       proxy_new = xchg(&current->nsproxy, proxy_new);
25244 +       ret = 0;
25245 +
25246 +       if (proxy_new)
25247 +               put_nsproxy(proxy_new);
25248 +out_put:
25249 +       if (proxy_cur)
25250 +               put_nsproxy(proxy_cur);
25251 +       return ret;
25252 +}
25253 +
25254 +
25255 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25256 +{
25257 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
25258 +       struct fs_struct *fs_vxi, *fs;
25259 +       int ret, kill = 0;
25260 +
25261 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
25262 +               vxi, vxi->vx_id, mask, index);
25263 +#if 0
25264 +       if (!mask)
25265 +               mask = default_space_mask.mask;
25266 +#endif
25267 +       if ((mask & space_mask.mask) != mask)
25268 +               return -EINVAL;
25269 +
25270 +       proxy_vxi = vxi->vx_nsproxy[index];
25271 +       fs_vxi = vxi->vx_fs[index];
25272 +
25273 +       if (mask & CLONE_FS) {
25274 +               fs = copy_fs_struct(current->fs);
25275 +               if (!fs)
25276 +                       return -ENOMEM;
25277 +       }
25278 +
25279 +       task_lock(current);
25280 +
25281 +       if (mask & CLONE_FS) {
25282 +               write_lock(&fs_vxi->lock);
25283 +               vxi->vx_fs[index] = fs;
25284 +               kill = !--fs_vxi->users;
25285 +               write_unlock(&fs_vxi->lock);
25286 +       }
25287 +
25288 +       proxy_cur = current->nsproxy;
25289 +       get_nsproxy(proxy_cur);
25290 +       task_unlock(current);
25291 +
25292 +       if (kill)
25293 +               free_fs_struct(fs_vxi);
25294 +
25295 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
25296 +       if (IS_ERR(proxy_new)) {
25297 +               ret = PTR_ERR(proxy_new);
25298 +               goto out_put;
25299 +       }
25300 +
25301 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
25302 +       vxi->vx_nsmask[index] |= mask;
25303 +       ret = 0;
25304 +
25305 +       if (proxy_new)
25306 +               put_nsproxy(proxy_new);
25307 +out_put:
25308 +       if (proxy_cur)
25309 +               put_nsproxy(proxy_cur);
25310 +       return ret;
25311 +}
25312 +
25313 +
25314 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
25315 +{
25316 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25317 +
25318 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25319 +               return -EFAULT;
25320 +
25321 +       return vx_enter_space(vxi, vc_data.mask, 0);
25322 +}
25323 +
25324 +int vc_enter_space(struct vx_info *vxi, void __user *data)
25325 +{
25326 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25327 +
25328 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25329 +               return -EFAULT;
25330 +
25331 +       if (vc_data.index >= VX_SPACES)
25332 +               return -EINVAL;
25333 +
25334 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
25335 +}
25336 +
25337 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
25338 +{
25339 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25340 +
25341 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25342 +               return -EFAULT;
25343 +
25344 +       return vx_set_space(vxi, vc_data.mask, 0);
25345 +}
25346 +
25347 +int vc_set_space(struct vx_info *vxi, void __user *data)
25348 +{
25349 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25350 +
25351 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25352 +               return -EFAULT;
25353 +
25354 +       if (vc_data.index >= VX_SPACES)
25355 +               return -EINVAL;
25356 +
25357 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
25358 +}
25359 +
25360 +int vc_get_space_mask(void __user *data, int type)
25361 +{
25362 +       const struct vcmd_space_mask_v1 *mask;
25363 +
25364 +       if (type == 0)
25365 +               mask = &space_mask_v0;
25366 +       else if (type == 1)
25367 +               mask = &space_mask;
25368 +       else
25369 +               mask = &default_space_mask;
25370 +
25371 +       vxdprintk(VXD_CBIT(space, 10),
25372 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
25373 +
25374 +       if (copy_to_user(data, mask, sizeof(*mask)))
25375 +               return -EFAULT;
25376 +       return 0;
25377 +}
25378 +
25379 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/switch.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/switch.c
25380 --- linux-2.6.32.10/kernel/vserver/switch.c     1970-01-01 01:00:00.000000000 +0100
25381 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/switch.c     2009-12-03 20:04:56.000000000 +0100
25382 @@ -0,0 +1,546 @@
25383 +/*
25384 + *  linux/kernel/vserver/switch.c
25385 + *
25386 + *  Virtual Server: Syscall Switch
25387 + *
25388 + *  Copyright (C) 2003-2007  Herbert Pötzl
25389 + *
25390 + *  V0.01  syscall switch
25391 + *  V0.02  added signal to context
25392 + *  V0.03  added rlimit functions
25393 + *  V0.04  added iattr, task/xid functions
25394 + *  V0.05  added debug/history stuff
25395 + *  V0.06  added compat32 layer
25396 + *  V0.07  vcmd args and perms
25397 + *  V0.08  added status commands
25398 + *  V0.09  added tag commands
25399 + *  V0.10  added oom bias
25400 + *  V0.11  added device commands
25401 + *
25402 + */
25403 +
25404 +#include <linux/vs_context.h>
25405 +#include <linux/vs_network.h>
25406 +#include <linux/vserver/switch.h>
25407 +
25408 +#include "vci_config.h"
25409 +
25410 +
25411 +static inline
25412 +int vc_get_version(uint32_t id)
25413 +{
25414 +       return VCI_VERSION;
25415 +}
25416 +
25417 +static inline
25418 +int vc_get_vci(uint32_t id)
25419 +{
25420 +       return vci_kernel_config();
25421 +}
25422 +
25423 +#include <linux/vserver/context_cmd.h>
25424 +#include <linux/vserver/cvirt_cmd.h>
25425 +#include <linux/vserver/cacct_cmd.h>
25426 +#include <linux/vserver/limit_cmd.h>
25427 +#include <linux/vserver/network_cmd.h>
25428 +#include <linux/vserver/sched_cmd.h>
25429 +#include <linux/vserver/debug_cmd.h>
25430 +#include <linux/vserver/inode_cmd.h>
25431 +#include <linux/vserver/dlimit_cmd.h>
25432 +#include <linux/vserver/signal_cmd.h>
25433 +#include <linux/vserver/space_cmd.h>
25434 +#include <linux/vserver/tag_cmd.h>
25435 +#include <linux/vserver/device_cmd.h>
25436 +
25437 +#include <linux/vserver/inode.h>
25438 +#include <linux/vserver/dlimit.h>
25439 +
25440 +
25441 +#ifdef CONFIG_COMPAT
25442 +#define __COMPAT(name, id, data, compat)       \
25443 +       (compat) ? name ## _x32(id, data) : name(id, data)
25444 +#define __COMPAT_NO_ID(name, data, compat)     \
25445 +       (compat) ? name ## _x32(data) : name(data)
25446 +#else
25447 +#define __COMPAT(name, id, data, compat)       \
25448 +       name(id, data)
25449 +#define __COMPAT_NO_ID(name, data, compat)     \
25450 +       name(data)
25451 +#endif
25452 +
25453 +
25454 +static inline
25455 +long do_vcmd(uint32_t cmd, uint32_t id,
25456 +       struct vx_info *vxi, struct nx_info *nxi,
25457 +       void __user *data, int compat)
25458 +{
25459 +       switch (cmd) {
25460 +
25461 +       case VCMD_get_version:
25462 +               return vc_get_version(id);
25463 +       case VCMD_get_vci:
25464 +               return vc_get_vci(id);
25465 +
25466 +       case VCMD_task_xid:
25467 +               return vc_task_xid(id);
25468 +       case VCMD_vx_info:
25469 +               return vc_vx_info(vxi, data);
25470 +
25471 +       case VCMD_task_nid:
25472 +               return vc_task_nid(id);
25473 +       case VCMD_nx_info:
25474 +               return vc_nx_info(nxi, data);
25475 +
25476 +       case VCMD_task_tag:
25477 +               return vc_task_tag(id);
25478 +
25479 +       case VCMD_set_space_v1:
25480 +               return vc_set_space_v1(vxi, data);
25481 +       /* this is version 2 */
25482 +       case VCMD_set_space:
25483 +               return vc_set_space(vxi, data);
25484 +
25485 +       case VCMD_get_space_mask_v0:
25486 +               return vc_get_space_mask(data, 0);
25487 +       /* this is version 1 */
25488 +       case VCMD_get_space_mask:
25489 +               return vc_get_space_mask(data, 1);
25490 +
25491 +       case VCMD_get_space_default:
25492 +               return vc_get_space_mask(data, -1);
25493 +
25494 +#ifdef CONFIG_IA32_EMULATION
25495 +       case VCMD_get_rlimit:
25496 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25497 +       case VCMD_set_rlimit:
25498 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25499 +#else
25500 +       case VCMD_get_rlimit:
25501 +               return vc_get_rlimit(vxi, data);
25502 +       case VCMD_set_rlimit:
25503 +               return vc_set_rlimit(vxi, data);
25504 +#endif
25505 +       case VCMD_get_rlimit_mask:
25506 +               return vc_get_rlimit_mask(id, data);
25507 +       case VCMD_reset_hits:
25508 +               return vc_reset_hits(vxi, data);
25509 +       case VCMD_reset_minmax:
25510 +               return vc_reset_minmax(vxi, data);
25511 +
25512 +       case VCMD_get_vhi_name:
25513 +               return vc_get_vhi_name(vxi, data);
25514 +       case VCMD_set_vhi_name:
25515 +               return vc_set_vhi_name(vxi, data);
25516 +
25517 +       case VCMD_ctx_stat:
25518 +               return vc_ctx_stat(vxi, data);
25519 +       case VCMD_virt_stat:
25520 +               return vc_virt_stat(vxi, data);
25521 +       case VCMD_sock_stat:
25522 +               return vc_sock_stat(vxi, data);
25523 +       case VCMD_rlimit_stat:
25524 +               return vc_rlimit_stat(vxi, data);
25525 +
25526 +       case VCMD_set_cflags:
25527 +               return vc_set_cflags(vxi, data);
25528 +       case VCMD_get_cflags:
25529 +               return vc_get_cflags(vxi, data);
25530 +
25531 +       /* this is version 1 */
25532 +       case VCMD_set_ccaps:
25533 +               return vc_set_ccaps(vxi, data);
25534 +       /* this is version 1 */
25535 +       case VCMD_get_ccaps:
25536 +               return vc_get_ccaps(vxi, data);
25537 +       case VCMD_set_bcaps:
25538 +               return vc_set_bcaps(vxi, data);
25539 +       case VCMD_get_bcaps:
25540 +               return vc_get_bcaps(vxi, data);
25541 +
25542 +       case VCMD_set_badness:
25543 +               return vc_set_badness(vxi, data);
25544 +       case VCMD_get_badness:
25545 +               return vc_get_badness(vxi, data);
25546 +
25547 +       case VCMD_set_nflags:
25548 +               return vc_set_nflags(nxi, data);
25549 +       case VCMD_get_nflags:
25550 +               return vc_get_nflags(nxi, data);
25551 +
25552 +       case VCMD_set_ncaps:
25553 +               return vc_set_ncaps(nxi, data);
25554 +       case VCMD_get_ncaps:
25555 +               return vc_get_ncaps(nxi, data);
25556 +
25557 +       case VCMD_set_sched_v4:
25558 +               return vc_set_sched_v4(vxi, data);
25559 +       /* this is version 5 */
25560 +       case VCMD_set_sched:
25561 +               return vc_set_sched(vxi, data);
25562 +       case VCMD_get_sched:
25563 +               return vc_get_sched(vxi, data);
25564 +       case VCMD_sched_info:
25565 +               return vc_sched_info(vxi, data);
25566 +
25567 +       case VCMD_add_dlimit:
25568 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25569 +       case VCMD_rem_dlimit:
25570 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25571 +       case VCMD_set_dlimit:
25572 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25573 +       case VCMD_get_dlimit:
25574 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25575 +
25576 +       case VCMD_ctx_kill:
25577 +               return vc_ctx_kill(vxi, data);
25578 +
25579 +       case VCMD_wait_exit:
25580 +               return vc_wait_exit(vxi, data);
25581 +
25582 +       case VCMD_get_iattr:
25583 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25584 +       case VCMD_set_iattr:
25585 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25586 +
25587 +       case VCMD_fget_iattr:
25588 +               return vc_fget_iattr(id, data);
25589 +       case VCMD_fset_iattr:
25590 +               return vc_fset_iattr(id, data);
25591 +
25592 +       case VCMD_enter_space_v0:
25593 +               return vc_enter_space_v1(vxi, NULL);
25594 +       case VCMD_enter_space_v1:
25595 +               return vc_enter_space_v1(vxi, data);
25596 +       /* this is version 2 */
25597 +       case VCMD_enter_space:
25598 +               return vc_enter_space(vxi, data);
25599 +
25600 +       case VCMD_ctx_create_v0:
25601 +               return vc_ctx_create(id, NULL);
25602 +       case VCMD_ctx_create:
25603 +               return vc_ctx_create(id, data);
25604 +       case VCMD_ctx_migrate_v0:
25605 +               return vc_ctx_migrate(vxi, NULL);
25606 +       case VCMD_ctx_migrate:
25607 +               return vc_ctx_migrate(vxi, data);
25608 +
25609 +       case VCMD_net_create_v0:
25610 +               return vc_net_create(id, NULL);
25611 +       case VCMD_net_create:
25612 +               return vc_net_create(id, data);
25613 +       case VCMD_net_migrate:
25614 +               return vc_net_migrate(nxi, data);
25615 +
25616 +       case VCMD_tag_migrate:
25617 +               return vc_tag_migrate(id);
25618 +
25619 +       case VCMD_net_add:
25620 +               return vc_net_add(nxi, data);
25621 +       case VCMD_net_remove:
25622 +               return vc_net_remove(nxi, data);
25623 +
25624 +       case VCMD_net_add_ipv4:
25625 +               return vc_net_add_ipv4(nxi, data);
25626 +       case VCMD_net_remove_ipv4:
25627 +               return vc_net_remove_ipv4(nxi, data);
25628 +#ifdef CONFIG_IPV6
25629 +       case VCMD_net_add_ipv6:
25630 +               return vc_net_add_ipv6(nxi, data);
25631 +       case VCMD_net_remove_ipv6:
25632 +               return vc_net_remove_ipv6(nxi, data);
25633 +#endif
25634 +/*     case VCMD_add_match_ipv4:
25635 +               return vc_add_match_ipv4(nxi, data);
25636 +       case VCMD_get_match_ipv4:
25637 +               return vc_get_match_ipv4(nxi, data);
25638 +#ifdef CONFIG_IPV6
25639 +       case VCMD_add_match_ipv6:
25640 +               return vc_add_match_ipv6(nxi, data);
25641 +       case VCMD_get_match_ipv6:
25642 +               return vc_get_match_ipv6(nxi, data);
25643 +#endif */
25644 +
25645 +#ifdef CONFIG_VSERVER_DEVICE
25646 +       case VCMD_set_mapping:
25647 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25648 +       case VCMD_unset_mapping:
25649 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25650 +#endif
25651 +#ifdef CONFIG_VSERVER_HISTORY
25652 +       case VCMD_dump_history:
25653 +               return vc_dump_history(id);
25654 +       case VCMD_read_history:
25655 +               return __COMPAT(vc_read_history, id, data, compat);
25656 +#endif
25657 +#ifdef CONFIG_VSERVER_MONITOR
25658 +       case VCMD_read_monitor:
25659 +               return __COMPAT(vc_read_monitor, id, data, compat);
25660 +#endif
25661 +       default:
25662 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25663 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25664 +       }
25665 +       return -ENOSYS;
25666 +}
25667 +
25668 +
25669 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25670 +       case VCMD_ ## vcmd: perm = _perm;               \
25671 +               args = _args; flags = _flags; break
25672 +
25673 +
25674 +#define VCA_NONE       0x00
25675 +#define VCA_VXI                0x01
25676 +#define VCA_NXI                0x02
25677 +
25678 +#define VCF_NONE       0x00
25679 +#define VCF_INFO       0x01
25680 +#define VCF_ADMIN      0x02
25681 +#define VCF_ARES       0x06    /* includes admin */
25682 +#define VCF_SETUP      0x08
25683 +
25684 +#define VCF_ZIDOK      0x10    /* zero id okay */
25685 +
25686 +
25687 +static inline
25688 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25689 +{
25690 +       long ret;
25691 +       int permit = -1, state = 0;
25692 +       int perm = -1, args = 0, flags = 0;
25693 +       struct vx_info *vxi = NULL;
25694 +       struct nx_info *nxi = NULL;
25695 +
25696 +       switch (cmd) {
25697 +       /* unpriviledged commands */
25698 +       __VCMD(get_version,      0, VCA_NONE,   0);
25699 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25700 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25701 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25702 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25703 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25704 +
25705 +       /* info commands */
25706 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25707 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
25708 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25709 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25710 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25711 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25712 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25713 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25714 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25715 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25716 +
25717 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25718 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25719 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25720 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25721 +
25722 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25723 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25724 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25725 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25726 +
25727 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25728 +
25729 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25730 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25731 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25732 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25733 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25734 +
25735 +       /* lower admin commands */
25736 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25737 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25738 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25739 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25740 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25741 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25742 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25743 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25744 +
25745 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25746 +       __VCMD(net_create,       5, VCA_NONE,   0);
25747 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25748 +
25749 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25750 +
25751 +       /* higher admin commands */
25752 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25753 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25754 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25755 +
25756 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25757 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25758 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25759 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25760 +
25761 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25762 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25763 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25764 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25765 +
25766 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25767 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25768 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25769 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25770 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25771 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25772 +#ifdef CONFIG_IPV6
25773 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25774 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25775 +#endif
25776 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25777 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25778 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25779 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25780 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25781 +
25782 +#ifdef CONFIG_VSERVER_DEVICE
25783 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25784 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25785 +#endif
25786 +       /* debug level admin commands */
25787 +#ifdef CONFIG_VSERVER_HISTORY
25788 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25789 +       __VCMD(read_history,     9, VCA_NONE,   0);
25790 +#endif
25791 +#ifdef CONFIG_VSERVER_MONITOR
25792 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25793 +#endif
25794 +
25795 +       default:
25796 +               perm = -1;
25797 +       }
25798 +
25799 +       vxdprintk(VXD_CBIT(switch, 0),
25800 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25801 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25802 +               VC_VERSION(cmd), id, data, compat,
25803 +               perm, args, flags);
25804 +
25805 +       ret = -ENOSYS;
25806 +       if (perm < 0)
25807 +               goto out;
25808 +
25809 +       state = 1;
25810 +       if (!capable(CAP_CONTEXT))
25811 +               goto out;
25812 +
25813 +       state = 2;
25814 +       /* moved here from the individual commands */
25815 +       ret = -EPERM;
25816 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25817 +               goto out;
25818 +
25819 +       state = 3;
25820 +       /* vcmd involves resource management  */
25821 +       ret = -EPERM;
25822 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25823 +               goto out;
25824 +
25825 +       state = 4;
25826 +       /* various legacy exceptions */
25827 +       switch (cmd) {
25828 +       /* will go away when spectator is a cap */
25829 +       case VCMD_ctx_migrate_v0:
25830 +       case VCMD_ctx_migrate:
25831 +               if (id == 1) {
25832 +                       current->xid = 1;
25833 +                       ret = 1;
25834 +                       goto out;
25835 +               }
25836 +               break;
25837 +
25838 +       /* will go away when spectator is a cap */
25839 +       case VCMD_net_migrate:
25840 +               if (id == 1) {
25841 +                       current->nid = 1;
25842 +                       ret = 1;
25843 +                       goto out;
25844 +               }
25845 +               break;
25846 +       }
25847 +
25848 +       /* vcmds are fine by default */
25849 +       permit = 1;
25850 +
25851 +       /* admin type vcmds require admin ... */
25852 +       if (flags & VCF_ADMIN)
25853 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25854 +
25855 +       /* ... but setup type vcmds override that */
25856 +       if (!permit && (flags & VCF_SETUP))
25857 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25858 +
25859 +       state = 5;
25860 +       ret = -EPERM;
25861 +       if (!permit)
25862 +               goto out;
25863 +
25864 +       state = 6;
25865 +       if (!id && (flags & VCF_ZIDOK))
25866 +               goto skip_id;
25867 +
25868 +       ret = -ESRCH;
25869 +       if (args & VCA_VXI) {
25870 +               vxi = lookup_vx_info(id);
25871 +               if (!vxi)
25872 +                       goto out;
25873 +
25874 +               if ((flags & VCF_ADMIN) &&
25875 +                       /* special case kill for shutdown */
25876 +                       (cmd != VCMD_ctx_kill) &&
25877 +                       /* can context be administrated? */
25878 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25879 +                       ret = -EACCES;
25880 +                       goto out_vxi;
25881 +               }
25882 +       }
25883 +       state = 7;
25884 +       if (args & VCA_NXI) {
25885 +               nxi = lookup_nx_info(id);
25886 +               if (!nxi)
25887 +                       goto out_vxi;
25888 +
25889 +               if ((flags & VCF_ADMIN) &&
25890 +                       /* can context be administrated? */
25891 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25892 +                       ret = -EACCES;
25893 +                       goto out_nxi;
25894 +               }
25895 +       }
25896 +skip_id:
25897 +       state = 8;
25898 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25899 +
25900 +out_nxi:
25901 +       if ((args & VCA_NXI) && nxi)
25902 +               put_nx_info(nxi);
25903 +out_vxi:
25904 +       if ((args & VCA_VXI) && vxi)
25905 +               put_vx_info(vxi);
25906 +out:
25907 +       vxdprintk(VXD_CBIT(switch, 1),
25908 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25909 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25910 +               VC_VERSION(cmd), ret, ret, state, permit);
25911 +       return ret;
25912 +}
25913 +
25914 +asmlinkage long
25915 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25916 +{
25917 +       return do_vserver(cmd, id, data, 0);
25918 +}
25919 +
25920 +#ifdef CONFIG_COMPAT
25921 +
25922 +asmlinkage long
25923 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25924 +{
25925 +       return do_vserver(cmd, id, data, 1);
25926 +}
25927 +
25928 +#endif /* CONFIG_COMPAT */
25929 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/sysctl.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/sysctl.c
25930 --- linux-2.6.32.10/kernel/vserver/sysctl.c     1970-01-01 01:00:00.000000000 +0100
25931 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/sysctl.c     2010-01-13 15:21:01.000000000 +0100
25932 @@ -0,0 +1,245 @@
25933 +/*
25934 + *  kernel/vserver/sysctl.c
25935 + *
25936 + *  Virtual Context Support
25937 + *
25938 + *  Copyright (C) 2004-2007  Herbert Pötzl
25939 + *
25940 + *  V0.01  basic structure
25941 + *
25942 + */
25943 +
25944 +#include <linux/module.h>
25945 +#include <linux/ctype.h>
25946 +#include <linux/sysctl.h>
25947 +#include <linux/parser.h>
25948 +#include <asm/uaccess.h>
25949 +
25950 +
25951 +enum {
25952 +       CTL_DEBUG_ERROR         = 0,
25953 +       CTL_DEBUG_SWITCH        = 1,
25954 +       CTL_DEBUG_XID,
25955 +       CTL_DEBUG_NID,
25956 +       CTL_DEBUG_TAG,
25957 +       CTL_DEBUG_NET,
25958 +       CTL_DEBUG_LIMIT,
25959 +       CTL_DEBUG_CRES,
25960 +       CTL_DEBUG_DLIM,
25961 +       CTL_DEBUG_QUOTA,
25962 +       CTL_DEBUG_CVIRT,
25963 +       CTL_DEBUG_SPACE,
25964 +       CTL_DEBUG_MISC,
25965 +};
25966 +
25967 +
25968 +unsigned int vx_debug_switch   = 0;
25969 +unsigned int vx_debug_xid      = 0;
25970 +unsigned int vx_debug_nid      = 0;
25971 +unsigned int vx_debug_tag      = 0;
25972 +unsigned int vx_debug_net      = 0;
25973 +unsigned int vx_debug_limit    = 0;
25974 +unsigned int vx_debug_cres     = 0;
25975 +unsigned int vx_debug_dlim     = 0;
25976 +unsigned int vx_debug_quota    = 0;
25977 +unsigned int vx_debug_cvirt    = 0;
25978 +unsigned int vx_debug_space    = 0;
25979 +unsigned int vx_debug_misc     = 0;
25980 +
25981 +
25982 +static struct ctl_table_header *vserver_table_header;
25983 +static ctl_table vserver_root_table[];
25984 +
25985 +
25986 +void vserver_register_sysctl(void)
25987 +{
25988 +       if (!vserver_table_header) {
25989 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25990 +       }
25991 +
25992 +}
25993 +
25994 +void vserver_unregister_sysctl(void)
25995 +{
25996 +       if (vserver_table_header) {
25997 +               unregister_sysctl_table(vserver_table_header);
25998 +               vserver_table_header = NULL;
25999 +       }
26000 +}
26001 +
26002 +
26003 +static int proc_dodebug(ctl_table *table, int write,
26004 +       void __user *buffer, size_t *lenp, loff_t *ppos)
26005 +{
26006 +       char            tmpbuf[20], *p, c;
26007 +       unsigned int    value;
26008 +       size_t          left, len;
26009 +
26010 +       if ((*ppos && !write) || !*lenp) {
26011 +               *lenp = 0;
26012 +               return 0;
26013 +       }
26014 +
26015 +       left = *lenp;
26016 +
26017 +       if (write) {
26018 +               if (!access_ok(VERIFY_READ, buffer, left))
26019 +                       return -EFAULT;
26020 +               p = (char *)buffer;
26021 +               while (left && __get_user(c, p) >= 0 && isspace(c))
26022 +                       left--, p++;
26023 +               if (!left)
26024 +                       goto done;
26025 +
26026 +               if (left > sizeof(tmpbuf) - 1)
26027 +                       return -EINVAL;
26028 +               if (copy_from_user(tmpbuf, p, left))
26029 +                       return -EFAULT;
26030 +               tmpbuf[left] = '\0';
26031 +
26032 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
26033 +                       value = 10 * value + (*p - '0');
26034 +               if (*p && !isspace(*p))
26035 +                       return -EINVAL;
26036 +               while (left && isspace(*p))
26037 +                       left--, p++;
26038 +               *(unsigned int *)table->data = value;
26039 +       } else {
26040 +               if (!access_ok(VERIFY_WRITE, buffer, left))
26041 +                       return -EFAULT;
26042 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
26043 +               if (len > left)
26044 +                       len = left;
26045 +               if (__copy_to_user(buffer, tmpbuf, len))
26046 +                       return -EFAULT;
26047 +               if ((left -= len) > 0) {
26048 +                       if (put_user('\n', (char *)buffer + len))
26049 +                               return -EFAULT;
26050 +                       left--;
26051 +               }
26052 +       }
26053 +
26054 +done:
26055 +       *lenp -= left;
26056 +       *ppos += *lenp;
26057 +       return 0;
26058 +}
26059 +
26060 +static int zero;
26061 +
26062 +#define        CTL_ENTRY(ctl, name)                            \
26063 +       {                                               \
26064 +               .ctl_name       = ctl,                  \
26065 +               .procname       = #name,                \
26066 +               .data           = &vx_ ## name,         \
26067 +               .maxlen         = sizeof(int),          \
26068 +               .mode           = 0644,                 \
26069 +               .proc_handler   = &proc_dodebug,        \
26070 +               .strategy       = &sysctl_intvec,       \
26071 +               .extra1         = &zero,                \
26072 +               .extra2         = &zero,                \
26073 +       }
26074 +
26075 +static ctl_table vserver_debug_table[] = {
26076 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
26077 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
26078 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
26079 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
26080 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
26081 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
26082 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
26083 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
26084 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
26085 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
26086 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
26087 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
26088 +       { .ctl_name = 0 }
26089 +};
26090 +
26091 +static ctl_table vserver_root_table[] = {
26092 +       {
26093 +               .ctl_name       = CTL_VSERVER,
26094 +               .procname       = "vserver",
26095 +               .mode           = 0555,
26096 +               .child          = vserver_debug_table
26097 +       },
26098 +       { .ctl_name = 0 }
26099 +};
26100 +
26101 +
26102 +static match_table_t tokens = {
26103 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
26104 +       { CTL_DEBUG_XID,        "xid=%x"        },
26105 +       { CTL_DEBUG_NID,        "nid=%x"        },
26106 +       { CTL_DEBUG_TAG,        "tag=%x"        },
26107 +       { CTL_DEBUG_NET,        "net=%x"        },
26108 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
26109 +       { CTL_DEBUG_CRES,       "cres=%x"       },
26110 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
26111 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
26112 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
26113 +       { CTL_DEBUG_SPACE,      "space=%x"      },
26114 +       { CTL_DEBUG_MISC,       "misc=%x"       },
26115 +       { CTL_DEBUG_ERROR,      NULL            }
26116 +};
26117 +
26118 +#define        HANDLE_CASE(id, name, val)                              \
26119 +       case CTL_DEBUG_ ## id:                                  \
26120 +               vx_debug_ ## name = val;                        \
26121 +               printk("vs_debug_" #name "=0x%x\n", val);       \
26122 +               break
26123 +
26124 +
26125 +static int __init vs_debug_setup(char *str)
26126 +{
26127 +       char *p;
26128 +       int token;
26129 +
26130 +       printk("vs_debug_setup(%s)\n", str);
26131 +       while ((p = strsep(&str, ",")) != NULL) {
26132 +               substring_t args[MAX_OPT_ARGS];
26133 +               unsigned int value;
26134 +
26135 +               if (!*p)
26136 +                       continue;
26137 +
26138 +               token = match_token(p, tokens, args);
26139 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
26140 +
26141 +               switch (token) {
26142 +               HANDLE_CASE(SWITCH, switch, value);
26143 +               HANDLE_CASE(XID,    xid,    value);
26144 +               HANDLE_CASE(NID,    nid,    value);
26145 +               HANDLE_CASE(TAG,    tag,    value);
26146 +               HANDLE_CASE(NET,    net,    value);
26147 +               HANDLE_CASE(LIMIT,  limit,  value);
26148 +               HANDLE_CASE(CRES,   cres,   value);
26149 +               HANDLE_CASE(DLIM,   dlim,   value);
26150 +               HANDLE_CASE(QUOTA,  quota,  value);
26151 +               HANDLE_CASE(CVIRT,  cvirt,  value);
26152 +               HANDLE_CASE(SPACE,  space,  value);
26153 +               HANDLE_CASE(MISC,   misc,   value);
26154 +               default:
26155 +                       return -EINVAL;
26156 +                       break;
26157 +               }
26158 +       }
26159 +       return 1;
26160 +}
26161 +
26162 +__setup("vsdebug=", vs_debug_setup);
26163 +
26164 +
26165 +
26166 +EXPORT_SYMBOL_GPL(vx_debug_switch);
26167 +EXPORT_SYMBOL_GPL(vx_debug_xid);
26168 +EXPORT_SYMBOL_GPL(vx_debug_nid);
26169 +EXPORT_SYMBOL_GPL(vx_debug_net);
26170 +EXPORT_SYMBOL_GPL(vx_debug_limit);
26171 +EXPORT_SYMBOL_GPL(vx_debug_cres);
26172 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
26173 +EXPORT_SYMBOL_GPL(vx_debug_quota);
26174 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
26175 +EXPORT_SYMBOL_GPL(vx_debug_space);
26176 +EXPORT_SYMBOL_GPL(vx_debug_misc);
26177 +
26178 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/tag.c linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/tag.c
26179 --- linux-2.6.32.10/kernel/vserver/tag.c        1970-01-01 01:00:00.000000000 +0100
26180 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/tag.c        2009-12-03 20:04:56.000000000 +0100
26181 @@ -0,0 +1,63 @@
26182 +/*
26183 + *  linux/kernel/vserver/tag.c
26184 + *
26185 + *  Virtual Server: Shallow Tag Space
26186 + *
26187 + *  Copyright (C) 2007  Herbert Pötzl
26188 + *
26189 + *  V0.01  basic implementation
26190 + *
26191 + */
26192 +
26193 +#include <linux/sched.h>
26194 +#include <linux/vserver/debug.h>
26195 +#include <linux/vs_pid.h>
26196 +#include <linux/vs_tag.h>
26197 +
26198 +#include <linux/vserver/tag_cmd.h>
26199 +
26200 +
26201 +int dx_migrate_task(struct task_struct *p, tag_t tag)
26202 +{
26203 +       if (!p)
26204 +               BUG();
26205 +
26206 +       vxdprintk(VXD_CBIT(tag, 5),
26207 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
26208 +
26209 +       task_lock(p);
26210 +       p->tag = tag;
26211 +       task_unlock(p);
26212 +
26213 +       vxdprintk(VXD_CBIT(tag, 5),
26214 +               "moved task %p into [#%d]", p, tag);
26215 +       return 0;
26216 +}
26217 +
26218 +/* vserver syscall commands below here */
26219 +
26220 +/* taks xid and vx_info functions */
26221 +
26222 +
26223 +int vc_task_tag(uint32_t id)
26224 +{
26225 +       tag_t tag;
26226 +
26227 +       if (id) {
26228 +               struct task_struct *tsk;
26229 +               read_lock(&tasklist_lock);
26230 +               tsk = find_task_by_real_pid(id);
26231 +               tag = (tsk) ? tsk->tag : -ESRCH;
26232 +               read_unlock(&tasklist_lock);
26233 +       } else
26234 +               tag = dx_current_tag();
26235 +       return tag;
26236 +}
26237 +
26238 +
26239 +int vc_tag_migrate(uint32_t tag)
26240 +{
26241 +       return dx_migrate_task(current, tag & 0xFFFF);
26242 +}
26243 +
26244 +
26245 diff -NurpP --minimal linux-2.6.32.10/kernel/vserver/vci_config.h linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/vci_config.h
26246 --- linux-2.6.32.10/kernel/vserver/vci_config.h 1970-01-01 01:00:00.000000000 +0100
26247 +++ linux-2.6.32.10-vs2.3.0.36.29.2/kernel/vserver/vci_config.h 2009-12-03 20:04:56.000000000 +0100
26248 @@ -0,0 +1,81 @@
26249 +
26250 +/*  interface version */
26251 +
26252 +#define VCI_VERSION            0x00020305
26253 +
26254 +
26255 +enum {
26256 +       VCI_KCBIT_NO_DYNAMIC = 0,
26257 +
26258 +       VCI_KCBIT_PROC_SECURE = 4,
26259 +       VCI_KCBIT_HARDCPU = 5,
26260 +       VCI_KCBIT_IDLELIMIT = 6,
26261 +       VCI_KCBIT_IDLETIME = 7,
26262 +
26263 +       VCI_KCBIT_COWBL = 8,
26264 +       VCI_KCBIT_FULLCOWBL = 9,
26265 +       VCI_KCBIT_SPACES = 10,
26266 +       VCI_KCBIT_NETV2 = 11,
26267 +
26268 +       VCI_KCBIT_DEBUG = 16,
26269 +       VCI_KCBIT_HISTORY = 20,
26270 +       VCI_KCBIT_TAGGED = 24,
26271 +       VCI_KCBIT_PPTAG = 28,
26272 +
26273 +       VCI_KCBIT_MORE = 31,
26274 +};
26275 +
26276 +
26277 +static inline uint32_t vci_kernel_config(void)
26278 +{
26279 +       return
26280 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
26281 +
26282 +       /* configured features */
26283 +#ifdef CONFIG_VSERVER_PROC_SECURE
26284 +       (1 << VCI_KCBIT_PROC_SECURE) |
26285 +#endif
26286 +#ifdef CONFIG_VSERVER_HARDCPU
26287 +       (1 << VCI_KCBIT_HARDCPU) |
26288 +#endif
26289 +#ifdef CONFIG_VSERVER_IDLELIMIT
26290 +       (1 << VCI_KCBIT_IDLELIMIT) |
26291 +#endif
26292 +#ifdef CONFIG_VSERVER_IDLETIME
26293 +       (1 << VCI_KCBIT_IDLETIME) |
26294 +#endif
26295 +#ifdef CONFIG_VSERVER_COWBL
26296 +       (1 << VCI_KCBIT_COWBL) |
26297 +       (1 << VCI_KCBIT_FULLCOWBL) |
26298 +#endif
26299 +       (1 << VCI_KCBIT_SPACES) |
26300 +       (1 << VCI_KCBIT_NETV2) |
26301 +
26302 +       /* debug options */
26303 +#ifdef CONFIG_VSERVER_DEBUG
26304 +       (1 << VCI_KCBIT_DEBUG) |
26305 +#endif
26306 +#ifdef CONFIG_VSERVER_HISTORY
26307 +       (1 << VCI_KCBIT_HISTORY) |
26308 +#endif
26309 +
26310 +       /* inode context tagging */
26311 +#if    defined(CONFIG_TAGGING_NONE)
26312 +       (0 << VCI_KCBIT_TAGGED) |
26313 +#elif  defined(CONFIG_TAGGING_UID16)
26314 +       (1 << VCI_KCBIT_TAGGED) |
26315 +#elif  defined(CONFIG_TAGGING_GID16)
26316 +       (2 << VCI_KCBIT_TAGGED) |
26317 +#elif  defined(CONFIG_TAGGING_ID24)
26318 +       (3 << VCI_KCBIT_TAGGED) |
26319 +#elif  defined(CONFIG_TAGGING_INTERN)
26320 +       (4 << VCI_KCBIT_TAGGED) |
26321 +#elif  defined(CONFIG_TAGGING_RUNTIME)
26322 +       (5 << VCI_KCBIT_TAGGED) |
26323 +#else
26324 +       (7 << VCI_KCBIT_TAGGED) |
26325 +#endif
26326 +       (1 << VCI_KCBIT_PPTAG) |
26327 +       0;
26328 +}
26329 +
26330 diff -NurpP --minimal linux-2.6.32.10/mm/allocpercpu.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/allocpercpu.c
26331 --- linux-2.6.32.10/mm/allocpercpu.c    2009-12-03 20:02:58.000000000 +0100
26332 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/allocpercpu.c    2009-12-03 20:04:56.000000000 +0100
26333 @@ -160,12 +160,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
26334  
26335  void __init setup_per_cpu_areas(void)
26336  {
26337 -       unsigned long size, i;
26338 +       unsigned long size, vspc, i;
26339         char *ptr;
26340         unsigned long nr_possible_cpus = num_possible_cpus();
26341  
26342 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
26343 +
26344         /* Copy section for each CPU (we discard the original) */
26345 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
26346 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
26347         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
26348  
26349         for_each_possible_cpu(i) {
26350 diff -NurpP --minimal linux-2.6.32.10/mm/filemap_xip.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/filemap_xip.c
26351 --- linux-2.6.32.10/mm/filemap_xip.c    2009-12-03 20:02:58.000000000 +0100
26352 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/filemap_xip.c    2009-12-03 20:04:56.000000000 +0100
26353 @@ -17,6 +17,7 @@
26354  #include <linux/sched.h>
26355  #include <linux/seqlock.h>
26356  #include <linux/mutex.h>
26357 +#include <linux/vs_memory.h>
26358  #include <asm/tlbflush.h>
26359  #include <asm/io.h>
26360  
26361 diff -NurpP --minimal linux-2.6.32.10/mm/fremap.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/fremap.c
26362 --- linux-2.6.32.10/mm/fremap.c 2009-03-24 14:22:45.000000000 +0100
26363 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/fremap.c 2009-12-03 20:04:56.000000000 +0100
26364 @@ -16,6 +16,7 @@
26365  #include <linux/module.h>
26366  #include <linux/syscalls.h>
26367  #include <linux/mmu_notifier.h>
26368 +#include <linux/vs_memory.h>
26369  
26370  #include <asm/mmu_context.h>
26371  #include <asm/cacheflush.h>
26372 diff -NurpP --minimal linux-2.6.32.10/mm/hugetlb.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/hugetlb.c
26373 --- linux-2.6.32.10/mm/hugetlb.c        2009-12-03 20:02:58.000000000 +0100
26374 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/hugetlb.c        2009-12-03 20:04:56.000000000 +0100
26375 @@ -24,6 +24,7 @@
26376  #include <asm/io.h>
26377  
26378  #include <linux/hugetlb.h>
26379 +#include <linux/vs_memory.h>
26380  #include "internal.h"
26381  
26382  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
26383 diff -NurpP --minimal linux-2.6.32.10/mm/memcontrol.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/memcontrol.c
26384 --- linux-2.6.32.10/mm/memcontrol.c     2010-03-18 16:17:38.000000000 +0100
26385 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/memcontrol.c     2010-02-05 02:26:48.000000000 +0100
26386 @@ -549,6 +549,31 @@ struct mem_cgroup *mem_cgroup_from_task(
26387                                 struct mem_cgroup, css);
26388  }
26389  
26390 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
26391 +{
26392 +       return res_counter_read_u64(&mem->res, member);
26393 +}
26394 +
26395 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
26396 +{
26397 +       return res_counter_read_u64(&mem->memsw, member);
26398 +}
26399 +
26400 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
26401 +{
26402 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_CACHE);
26403 +}
26404 +
26405 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
26406 +{
26407 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_RSS);
26408 +}
26409 +
26410 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
26411 +{
26412 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_MAPPED_FILE);
26413 +}
26414 +
26415  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
26416  {
26417         struct mem_cgroup *mem = NULL;
26418 diff -NurpP --minimal linux-2.6.32.10/mm/memory.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/memory.c
26419 --- linux-2.6.32.10/mm/memory.c 2010-03-18 16:17:38.000000000 +0100
26420 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/memory.c 2009-12-30 00:58:19.000000000 +0100
26421 @@ -56,6 +56,7 @@
26422  #include <linux/kallsyms.h>
26423  #include <linux/swapops.h>
26424  #include <linux/elf.h>
26425 +// #include <linux/vs_memory.h>
26426  
26427  #include <asm/io.h>
26428  #include <asm/pgalloc.h>
26429 @@ -647,6 +648,9 @@ static int copy_pte_range(struct mm_stru
26430         int progress = 0;
26431         int rss[2];
26432  
26433 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
26434 +               return -ENOMEM;
26435 +
26436  again:
26437         rss[1] = rss[0] = 0;
26438         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
26439 @@ -2645,6 +2649,8 @@ static int do_anonymous_page(struct mm_s
26440         /* Allocate our own private page. */
26441         pte_unmap(page_table);
26442  
26443 +       if (!vx_rss_avail(mm, 1))
26444 +               goto oom;
26445         if (unlikely(anon_vma_prepare(vma)))
26446                 goto oom;
26447         page = alloc_zeroed_user_highpage_movable(vma, address);
26448 @@ -2936,6 +2942,7 @@ static inline int handle_pte_fault(struc
26449  {
26450         pte_t entry;
26451         spinlock_t *ptl;
26452 +       int ret = 0, type = VXPT_UNKNOWN;
26453  
26454         entry = *pte;
26455         if (!pte_present(entry)) {
26456 @@ -2960,9 +2967,12 @@ static inline int handle_pte_fault(struc
26457         if (unlikely(!pte_same(*pte, entry)))
26458                 goto unlock;
26459         if (flags & FAULT_FLAG_WRITE) {
26460 -               if (!pte_write(entry))
26461 -                       return do_wp_page(mm, vma, address,
26462 +               if (!pte_write(entry)) {
26463 +                       ret = do_wp_page(mm, vma, address,
26464                                         pte, pmd, ptl, entry);
26465 +                       type = VXPT_WRITE;
26466 +                       goto out;
26467 +               }
26468                 entry = pte_mkdirty(entry);
26469         }
26470         entry = pte_mkyoung(entry);
26471 @@ -2980,7 +2990,10 @@ static inline int handle_pte_fault(struc
26472         }
26473  unlock:
26474         pte_unmap_unlock(pte, ptl);
26475 -       return 0;
26476 +       ret = 0;
26477 +out:
26478 +       vx_page_fault(mm, vma, type, ret);
26479 +       return ret;
26480  }
26481  
26482  /*
26483 diff -NurpP --minimal linux-2.6.32.10/mm/mlock.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/mlock.c
26484 --- linux-2.6.32.10/mm/mlock.c  2010-03-18 16:17:38.000000000 +0100
26485 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/mlock.c  2010-01-13 14:33:47.000000000 +0100
26486 @@ -18,6 +18,7 @@
26487  #include <linux/rmap.h>
26488  #include <linux/mmzone.h>
26489  #include <linux/hugetlb.h>
26490 +#include <linux/vs_memory.h>
26491  
26492  #include "internal.h"
26493  
26494 @@ -401,7 +402,7 @@ success:
26495         nr_pages = (end - start) >> PAGE_SHIFT;
26496         if (!lock)
26497                 nr_pages = -nr_pages;
26498 -       mm->locked_vm += nr_pages;
26499 +       vx_vmlocked_add(mm, nr_pages);
26500  
26501         /*
26502          * vm_flags is protected by the mmap_sem held in write mode.
26503 @@ -474,7 +475,7 @@ static int do_mlock(unsigned long start,
26504  
26505  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
26506  {
26507 -       unsigned long locked;
26508 +       unsigned long locked, grow;
26509         unsigned long lock_limit;
26510         int error = -ENOMEM;
26511  
26512 @@ -487,8 +488,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26513         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
26514         start &= PAGE_MASK;
26515  
26516 -       locked = len >> PAGE_SHIFT;
26517 -       locked += current->mm->locked_vm;
26518 +       grow = len >> PAGE_SHIFT;
26519 +       if (!vx_vmlocked_avail(current->mm, grow))
26520 +               goto out;
26521 +       locked = current->mm->locked_vm + grow;
26522  
26523         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26524         lock_limit >>= PAGE_SHIFT;
26525 @@ -496,6 +499,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26526         /* check against resource limits */
26527         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26528                 error = do_mlock(start, len, 1);
26529 +out:
26530         up_write(&current->mm->mmap_sem);
26531         return error;
26532  }
26533 @@ -557,6 +561,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
26534         lock_limit >>= PAGE_SHIFT;
26535  
26536         ret = -ENOMEM;
26537 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26538 +               goto out;
26539         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26540             capable(CAP_IPC_LOCK))
26541                 ret = do_mlockall(flags);
26542 @@ -631,8 +637,10 @@ int account_locked_memory(struct mm_stru
26543         if (lim < vm)
26544                 goto out;
26545  
26546 -       mm->total_vm  += pgsz;
26547 -       mm->locked_vm += pgsz;
26548 +       // mm->total_vm  += pgsz;
26549 +       vx_vmpages_add(mm, pgsz);
26550 +       // mm->locked_vm += pgsz;
26551 +       vx_vmlocked_add(mm, pgsz);
26552  
26553         error = 0;
26554   out:
26555 @@ -646,8 +654,10 @@ void refund_locked_memory(struct mm_stru
26556  
26557         down_write(&mm->mmap_sem);
26558  
26559 -       mm->total_vm  -= pgsz;
26560 -       mm->locked_vm -= pgsz;
26561 +       // mm->total_vm  -= pgsz;
26562 +       vx_vmpages_sub(mm, pgsz);
26563 +       // mm->locked_vm -= pgsz;
26564 +       vx_vmlocked_sub(mm, pgsz);
26565  
26566         up_write(&mm->mmap_sem);
26567  }
26568 diff -NurpP --minimal linux-2.6.32.10/mm/mmap.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/mmap.c
26569 --- linux-2.6.32.10/mm/mmap.c   2010-03-18 16:17:38.000000000 +0100
26570 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/mmap.c   2010-01-20 04:21:33.000000000 +0100
26571 @@ -1214,7 +1214,8 @@ munmap_back:
26572  out:
26573         perf_event_mmap(vma);
26574  
26575 -       mm->total_vm += len >> PAGE_SHIFT;
26576 +       // mm->total_vm += len >> PAGE_SHIFT;
26577 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26578         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26579         if (vm_flags & VM_LOCKED) {
26580                 /*
26581 @@ -1223,7 +1224,8 @@ out:
26582                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
26583                 if (nr_pages < 0)
26584                         return nr_pages;        /* vma gone! */
26585 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26586 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26587 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
26588         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26589                 make_pages_present(addr, addr + len);
26590         return addr;
26591 @@ -1578,9 +1580,9 @@ static int acct_stack_growth(struct vm_a
26592                 return -ENOMEM;
26593  
26594         /* Ok, everything looks good - let it rip */
26595 -       mm->total_vm += grow;
26596 +       vx_vmpages_add(mm, grow);
26597         if (vma->vm_flags & VM_LOCKED)
26598 -               mm->locked_vm += grow;
26599 +               vx_vmlocked_add(mm, grow);
26600         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26601         return 0;
26602  }
26603 @@ -1755,7 +1757,8 @@ static void remove_vma_list(struct mm_st
26604         do {
26605                 long nrpages = vma_pages(vma);
26606  
26607 -               mm->total_vm -= nrpages;
26608 +               // mm->total_vm -= nrpages;
26609 +               vx_vmpages_sub(mm, nrpages);
26610                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26611                 vma = remove_vma(vma);
26612         } while (vma);
26613 @@ -1927,7 +1930,8 @@ int do_munmap(struct mm_struct *mm, unsi
26614                 struct vm_area_struct *tmp = vma;
26615                 while (tmp && tmp->vm_start < end) {
26616                         if (tmp->vm_flags & VM_LOCKED) {
26617 -                               mm->locked_vm -= vma_pages(tmp);
26618 +                               // mm->locked_vm -= vma_pages(tmp);
26619 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
26620                                 munlock_vma_pages_all(tmp);
26621                         }
26622                         tmp = tmp->vm_next;
26623 @@ -2010,6 +2014,8 @@ unsigned long do_brk(unsigned long addr,
26624                 lock_limit >>= PAGE_SHIFT;
26625                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26626                         return -EAGAIN;
26627 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26628 +                       return -ENOMEM;
26629         }
26630  
26631         /*
26632 @@ -2036,7 +2042,8 @@ unsigned long do_brk(unsigned long addr,
26633         if (mm->map_count > sysctl_max_map_count)
26634                 return -ENOMEM;
26635  
26636 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26637 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26638 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26639                 return -ENOMEM;
26640  
26641         /* Can we just expand an old private anonymous mapping? */
26642 @@ -2062,10 +2069,13 @@ unsigned long do_brk(unsigned long addr,
26643         vma->vm_page_prot = vm_get_page_prot(flags);
26644         vma_link(mm, vma, prev, rb_link, rb_parent);
26645  out:
26646 -       mm->total_vm += len >> PAGE_SHIFT;
26647 +       // mm->total_vm += len >> PAGE_SHIFT;
26648 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26649 +
26650         if (flags & VM_LOCKED) {
26651                 if (!mlock_vma_pages_range(vma, addr, addr + len))
26652 -                       mm->locked_vm += (len >> PAGE_SHIFT);
26653 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
26654 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26655         }
26656         return addr;
26657  }
26658 @@ -2109,6 +2119,11 @@ void exit_mmap(struct mm_struct *mm)
26659         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26660         tlb_finish_mmu(tlb, 0, end);
26661  
26662 +       set_mm_counter(mm, file_rss, 0);
26663 +       set_mm_counter(mm, anon_rss, 0);
26664 +       vx_vmpages_sub(mm, mm->total_vm);
26665 +       vx_vmlocked_sub(mm, mm->locked_vm);
26666 +
26667         /*
26668          * Walk the list again, actually closing and freeing it,
26669          * with preemption enabled, without holding any MM locks.
26670 @@ -2148,7 +2163,8 @@ int insert_vm_struct(struct mm_struct * 
26671         if (__vma && __vma->vm_start < vma->vm_end)
26672                 return -ENOMEM;
26673         if ((vma->vm_flags & VM_ACCOUNT) &&
26674 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26675 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26676 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26677                 return -ENOMEM;
26678         vma_link(mm, vma, prev, rb_link, rb_parent);
26679         return 0;
26680 @@ -2224,6 +2240,8 @@ int may_expand_vm(struct mm_struct *mm, 
26681  
26682         if (cur + npages > lim)
26683                 return 0;
26684 +       if (!vx_vmpages_avail(mm, npages))
26685 +               return 0;
26686         return 1;
26687  }
26688  
26689 @@ -2301,7 +2319,7 @@ int install_special_mapping(struct mm_st
26690                 return -ENOMEM;
26691         }
26692  
26693 -       mm->total_vm += len >> PAGE_SHIFT;
26694 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26695  
26696         perf_event_mmap(vma);
26697  
26698 diff -NurpP --minimal linux-2.6.32.10/mm/mremap.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/mremap.c
26699 --- linux-2.6.32.10/mm/mremap.c 2010-03-18 16:17:38.000000000 +0100
26700 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/mremap.c 2010-01-20 04:28:22.000000000 +0100
26701 @@ -20,6 +20,7 @@
26702  #include <linux/security.h>
26703  #include <linux/syscalls.h>
26704  #include <linux/mmu_notifier.h>
26705 +#include <linux/vs_memory.h>
26706  
26707  #include <asm/uaccess.h>
26708  #include <asm/cacheflush.h>
26709 @@ -234,7 +235,7 @@ static unsigned long move_vma(struct vm_
26710          * If this were a serious issue, we'd add a flag to do_munmap().
26711          */
26712         hiwater_vm = mm->hiwater_vm;
26713 -       mm->total_vm += new_len >> PAGE_SHIFT;
26714 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26715         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26716  
26717         if (do_munmap(mm, old_addr, old_len) < 0) {
26718 @@ -252,7 +253,7 @@ static unsigned long move_vma(struct vm_
26719         }
26720  
26721         if (vm_flags & VM_LOCKED) {
26722 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26723 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26724                 if (new_len > old_len)
26725                         mlock_vma_pages_range(new_vma, new_addr + old_len,
26726                                                        new_addr + new_len);
26727 @@ -463,10 +464,12 @@ unsigned long do_mremap(unsigned long ad
26728                         vma_adjust(vma, vma->vm_start,
26729                                 addr + new_len, vma->vm_pgoff, NULL);
26730  
26731 -                       mm->total_vm += pages;
26732 +                       // mm->total_vm += pages;
26733 +                       vx_vmpages_add(mm, pages);
26734                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26735                         if (vma->vm_flags & VM_LOCKED) {
26736 -                               mm->locked_vm += pages;
26737 +                               // mm->locked_vm += pages;
26738 +                               vx_vmlocked_add(mm, pages);
26739                                 mlock_vma_pages_range(vma, addr + old_len,
26740                                                    addr + new_len);
26741                         }
26742 diff -NurpP --minimal linux-2.6.32.10/mm/nommu.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/nommu.c
26743 --- linux-2.6.32.10/mm/nommu.c  2009-12-03 20:02:58.000000000 +0100
26744 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/nommu.c  2009-12-03 20:04:56.000000000 +0100
26745 @@ -1346,7 +1346,7 @@ unsigned long do_mmap_pgoff(struct file 
26746         /* okay... we have a mapping; now we have to register it */
26747         result = vma->vm_start;
26748  
26749 -       current->mm->total_vm += len >> PAGE_SHIFT;
26750 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26751  
26752  share:
26753         add_vma_to_mm(current->mm, vma);
26754 @@ -1606,7 +1606,7 @@ void exit_mmap(struct mm_struct *mm)
26755  
26756         kenter("");
26757  
26758 -       mm->total_vm = 0;
26759 +       vx_vmpages_sub(mm, mm->total_vm);
26760  
26761         while ((vma = mm->mmap)) {
26762                 mm->mmap = vma->vm_next;
26763 diff -NurpP --minimal linux-2.6.32.10/mm/oom_kill.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/oom_kill.c
26764 --- linux-2.6.32.10/mm/oom_kill.c       2010-03-18 16:17:38.000000000 +0100
26765 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/oom_kill.c       2010-03-18 16:53:06.000000000 +0100
26766 @@ -27,6 +27,9 @@
26767  #include <linux/notifier.h>
26768  #include <linux/memcontrol.h>
26769  #include <linux/security.h>
26770 +#include <linux/reboot.h>
26771 +#include <linux/vs_memory.h>
26772 +#include <linux/vs_context.h>
26773  
26774  int sysctl_panic_on_oom;
26775  int sysctl_oom_kill_allocating_task;
26776 @@ -186,9 +189,21 @@ unsigned long badness(struct task_struct
26777                         points >>= -(oom_adj);
26778         }
26779  
26780 +       /*
26781 +        * add points for context badness and
26782 +        * reduce badness for processes belonging to
26783 +        * a different context
26784 +        */
26785 +
26786 +       points += vx_badness(p, mm);
26787 +
26788 +       if ((vx_current_xid() > 1) &&
26789 +               vx_current_xid() != vx_task_xid(p))
26790 +               points /= 16;
26791 +
26792  #ifdef DEBUG
26793 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26794 -       p->pid, p->comm, points);
26795 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26796 +               task_pid_nr(p), p->xid, p->comm, points);
26797  #endif
26798         return points;
26799  }
26800 @@ -230,6 +245,7 @@ static struct task_struct *select_bad_pr
26801         struct task_struct *p;
26802         struct task_struct *chosen = NULL;
26803         struct timespec uptime;
26804 +       unsigned xid = vx_current_xid();
26805         *ppoints = 0;
26806  
26807         do_posix_clock_monotonic_gettime(&uptime);
26808 @@ -242,11 +258,14 @@ static struct task_struct *select_bad_pr
26809                  */
26810                 if (!p->mm)
26811                         continue;
26812 -               /* skip the init task */
26813 -               if (is_global_init(p))
26814 +               /* skip the init task, global and per guest */
26815 +               if (task_is_init(p))
26816                         continue;
26817                 if (mem && !task_in_mem_cgroup(p, mem))
26818                         continue;
26819 +               /* skip other guest and host processes if oom in guest */
26820 +               if (xid && vx_task_xid(p) != xid)
26821 +                       continue;
26822  
26823                 /*
26824                  * This task already has access to memory reserves and is
26825 @@ -357,8 +376,8 @@ static void __oom_kill_task(struct task_
26826         }
26827  
26828         if (verbose)
26829 -               printk(KERN_ERR "Killed process %d (%s)\n",
26830 -                               task_pid_nr(p), p->comm);
26831 +               printk(KERN_ERR "Killed process %s(%d:#%u)\n",
26832 +                       p->comm, task_pid_nr(p), p->xid);
26833  
26834         /*
26835          * We give our sacrificial lamb high priority and access to
26836 @@ -419,8 +438,8 @@ static int oom_kill_process(struct task_
26837                 return 0;
26838         }
26839  
26840 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26841 -                                       message, task_pid_nr(p), p->comm, points);
26842 +       printk(KERN_ERR "%s: kill process %s(%d:#%u) score %li or a child\n",
26843 +               message, p->comm, task_pid_nr(p), p->xid, points);
26844  
26845         /* Try to kill a child first */
26846         list_for_each_entry(c, &p->children, sibling) {
26847 @@ -521,6 +540,8 @@ void clear_zonelist_oom(struct zonelist 
26848         spin_unlock(&zone_scan_lock);
26849  }
26850  
26851 +long vs_oom_action(unsigned int);
26852 +
26853  /*
26854   * Must be called with tasklist_lock held for read.
26855   */
26856 @@ -546,7 +567,11 @@ retry:
26857         /* Found nothing?!?! Either we hang forever, or we panic. */
26858         if (!p) {
26859                 read_unlock(&tasklist_lock);
26860 -               panic("Out of memory and no killable processes...\n");
26861 +               /* avoid panic for guest OOM */
26862 +               if (current->xid)
26863 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
26864 +               else
26865 +                       panic("Out of memory and no killable processes...\n");
26866         }
26867  
26868         if (oom_kill_process(p, gfp_mask, order, points, NULL,
26869 diff -NurpP --minimal linux-2.6.32.10/mm/page_alloc.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/page_alloc.c
26870 --- linux-2.6.32.10/mm/page_alloc.c     2010-03-18 16:17:38.000000000 +0100
26871 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/page_alloc.c     2010-02-12 10:59:55.000000000 +0100
26872 @@ -48,6 +48,8 @@
26873  #include <linux/page_cgroup.h>
26874  #include <linux/debugobjects.h>
26875  #include <linux/kmemleak.h>
26876 +#include <linux/vs_base.h>
26877 +#include <linux/vs_limit.h>
26878  #include <trace/events/kmem.h>
26879  
26880  #include <asm/tlbflush.h>
26881 @@ -2131,6 +2133,9 @@ void si_meminfo(struct sysinfo *val)
26882         val->totalhigh = totalhigh_pages;
26883         val->freehigh = nr_free_highpages();
26884         val->mem_unit = PAGE_SIZE;
26885 +
26886 +       if (vx_flags(VXF_VIRT_MEM, 0))
26887 +               vx_vsi_meminfo(val);
26888  }
26889  
26890  EXPORT_SYMBOL(si_meminfo);
26891 @@ -2151,6 +2156,9 @@ void si_meminfo_node(struct sysinfo *val
26892         val->freehigh = 0;
26893  #endif
26894         val->mem_unit = PAGE_SIZE;
26895 +
26896 +       if (vx_flags(VXF_VIRT_MEM, 0))
26897 +               vx_vsi_meminfo(val);
26898  }
26899  #endif
26900  
26901 diff -NurpP --minimal linux-2.6.32.10/mm/rmap.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/rmap.c
26902 --- linux-2.6.32.10/mm/rmap.c   2009-12-03 20:02:58.000000000 +0100
26903 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/rmap.c   2009-12-03 20:04:56.000000000 +0100
26904 @@ -55,6 +55,7 @@
26905  #include <linux/memcontrol.h>
26906  #include <linux/mmu_notifier.h>
26907  #include <linux/migrate.h>
26908 +#include <linux/vs_memory.h>
26909  
26910  #include <asm/tlbflush.h>
26911  
26912 diff -NurpP --minimal linux-2.6.32.10/mm/shmem.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/shmem.c
26913 --- linux-2.6.32.10/mm/shmem.c  2009-12-03 20:02:58.000000000 +0100
26914 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/shmem.c  2009-12-03 20:04:56.000000000 +0100
26915 @@ -1781,7 +1781,7 @@ static int shmem_statfs(struct dentry *d
26916  {
26917         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26918  
26919 -       buf->f_type = TMPFS_MAGIC;
26920 +       buf->f_type = TMPFS_SUPER_MAGIC;
26921         buf->f_bsize = PAGE_CACHE_SIZE;
26922         buf->f_namelen = NAME_MAX;
26923         spin_lock(&sbinfo->stat_lock);
26924 @@ -2346,7 +2346,7 @@ int shmem_fill_super(struct super_block 
26925         sb->s_maxbytes = SHMEM_MAX_BYTES;
26926         sb->s_blocksize = PAGE_CACHE_SIZE;
26927         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26928 -       sb->s_magic = TMPFS_MAGIC;
26929 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26930         sb->s_op = &shmem_ops;
26931         sb->s_time_gran = 1;
26932  #ifdef CONFIG_TMPFS_POSIX_ACL
26933 diff -NurpP --minimal linux-2.6.32.10/mm/slab.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/slab.c
26934 --- linux-2.6.32.10/mm/slab.c   2010-03-18 16:17:38.000000000 +0100
26935 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/slab.c   2010-03-18 16:53:06.000000000 +0100
26936 @@ -431,6 +431,8 @@ static void kmem_list3_init(struct kmem_
26937  #define STATS_INC_FREEMISS(x)  do { } while (0)
26938  #endif
26939  
26940 +#include "slab_vs.h"
26941 +
26942  #if DEBUG
26943  
26944  /*
26945 @@ -3251,6 +3253,7 @@ retry:
26946  
26947         obj = slab_get_obj(cachep, slabp, nodeid);
26948         check_slabp(cachep, slabp);
26949 +       vx_slab_alloc(cachep, flags);
26950         l3->free_objects--;
26951         /* move slabp to correct slabp list: */
26952         list_del(&slabp->list);
26953 @@ -3327,6 +3330,7 @@ __cache_alloc_node(struct kmem_cache *ca
26954         /* ___cache_alloc_node can fall back to other nodes */
26955         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26956    out:
26957 +       vx_slab_alloc(cachep, flags);
26958         local_irq_restore(save_flags);
26959         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26960         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
26961 @@ -3513,6 +3517,7 @@ static inline void __cache_free(struct k
26962         check_irq_off();
26963         kmemleak_free_recursive(objp, cachep->flags);
26964         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26965 +       vx_slab_free(cachep);
26966  
26967         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
26968  
26969 diff -NurpP --minimal linux-2.6.32.10/mm/slab_vs.h linux-2.6.32.10-vs2.3.0.36.29.2/mm/slab_vs.h
26970 --- linux-2.6.32.10/mm/slab_vs.h        1970-01-01 01:00:00.000000000 +0100
26971 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/slab_vs.h        2009-12-03 20:04:56.000000000 +0100
26972 @@ -0,0 +1,29 @@
26973 +
26974 +#include <linux/vserver/context.h>
26975 +
26976 +#include <linux/vs_context.h>
26977 +
26978 +static inline
26979 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26980 +{
26981 +       int what = gfp_zone(cachep->gfpflags);
26982 +       struct vx_info *vxi = current_vx_info();
26983 +
26984 +       if (!vxi)
26985 +               return;
26986 +
26987 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
26988 +}
26989 +
26990 +static inline
26991 +void vx_slab_free(struct kmem_cache *cachep)
26992 +{
26993 +       int what = gfp_zone(cachep->gfpflags);
26994 +       struct vx_info *vxi = current_vx_info();
26995 +
26996 +       if (!vxi)
26997 +               return;
26998 +
26999 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
27000 +}
27001 +
27002 diff -NurpP --minimal linux-2.6.32.10/mm/swapfile.c linux-2.6.32.10-vs2.3.0.36.29.2/mm/swapfile.c
27003 --- linux-2.6.32.10/mm/swapfile.c       2009-12-03 20:02:58.000000000 +0100
27004 +++ linux-2.6.32.10-vs2.3.0.36.29.2/mm/swapfile.c       2009-12-03 20:04:56.000000000 +0100
27005 @@ -34,6 +34,8 @@
27006  #include <asm/tlbflush.h>
27007  #include <linux/swapops.h>
27008  #include <linux/page_cgroup.h>
27009 +#include <linux/vs_base.h>
27010 +#include <linux/vs_memory.h>
27011  
27012  static DEFINE_SPINLOCK(swap_lock);
27013  static unsigned int nr_swapfiles;
27014 @@ -1680,6 +1682,8 @@ static void *swap_next(struct seq_file *
27015         if (v == SEQ_START_TOKEN)
27016                 ptr = swap_info;
27017         else {
27018 +               if (vx_flags(VXF_VIRT_MEM, 0))
27019 +                       return NULL;
27020                 ptr = v;
27021                 ptr++;
27022         }
27023 @@ -1707,6 +1711,16 @@ static int swap_show(struct seq_file *sw
27024  
27025         if (ptr == SEQ_START_TOKEN) {
27026                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
27027 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
27028 +                       struct sysinfo si;
27029 +
27030 +                       vx_vsi_swapinfo(&si);
27031 +                       if (si.totalswap < (1 << 10))
27032 +                               return 0;
27033 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
27034 +                               "hdv0", "partition", si.totalswap >> 10,
27035 +                               (si.totalswap - si.freeswap) >> 10, -1);
27036 +               }
27037                 return 0;
27038         }
27039  
27040 @@ -2064,6 +2078,8 @@ void si_swapinfo(struct sysinfo *val)
27041         val->freeswap = nr_swap_pages + nr_to_be_unused;
27042         val->totalswap = total_swap_pages + nr_to_be_unused;
27043         spin_unlock(&swap_lock);
27044 +       if (vx_flags(VXF_VIRT_MEM, 0))
27045 +               vx_vsi_swapinfo(val);
27046  }
27047  
27048  /*
27049 diff -NurpP --minimal linux-2.6.32.10/net/core/dev.c linux-2.6.32.10-vs2.3.0.36.29.2/net/core/dev.c
27050 --- linux-2.6.32.10/net/core/dev.c      2010-03-18 16:17:38.000000000 +0100
27051 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/core/dev.c      2010-03-18 16:53:06.000000000 +0100
27052 @@ -126,6 +126,7 @@
27053  #include <linux/in.h>
27054  #include <linux/jhash.h>
27055  #include <linux/random.h>
27056 +#include <linux/vs_inet.h>
27057  #include <trace/events/napi.h>
27058  
27059  #include "net-sysfs.h"
27060 @@ -591,7 +592,8 @@ struct net_device *__dev_get_by_name(str
27061         hlist_for_each(p, dev_name_hash(net, name)) {
27062                 struct net_device *dev
27063                         = hlist_entry(p, struct net_device, name_hlist);
27064 -               if (!strncmp(dev->name, name, IFNAMSIZ))
27065 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
27066 +                   nx_dev_visible(current_nx_info(), dev))
27067                         return dev;
27068         }
27069         return NULL;
27070 @@ -642,7 +644,8 @@ struct net_device *__dev_get_by_index(st
27071         hlist_for_each(p, dev_index_hash(net, ifindex)) {
27072                 struct net_device *dev
27073                         = hlist_entry(p, struct net_device, index_hlist);
27074 -               if (dev->ifindex == ifindex)
27075 +               if ((dev->ifindex == ifindex) &&
27076 +                   nx_dev_visible(current_nx_info(), dev))
27077                         return dev;
27078         }
27079         return NULL;
27080 @@ -695,10 +698,12 @@ struct net_device *dev_getbyhwaddr(struc
27081  
27082         ASSERT_RTNL();
27083  
27084 -       for_each_netdev(net, dev)
27085 +       for_each_netdev(net, dev) {
27086                 if (dev->type == type &&
27087 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
27088 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
27089 +                   nx_dev_visible(current_nx_info(), dev))
27090                         return dev;
27091 +       }
27092  
27093         return NULL;
27094  }
27095 @@ -709,9 +714,11 @@ struct net_device *__dev_getfirstbyhwtyp
27096         struct net_device *dev;
27097  
27098         ASSERT_RTNL();
27099 -       for_each_netdev(net, dev)
27100 -               if (dev->type == type)
27101 +       for_each_netdev(net, dev) {
27102 +               if ((dev->type == type) &&
27103 +                   nx_dev_visible(current_nx_info(), dev))
27104                         return dev;
27105 +       }
27106  
27107         return NULL;
27108  }
27109 @@ -830,6 +837,8 @@ static int __dev_alloc_name(struct net *
27110                                 continue;
27111                         if (i < 0 || i >= max_netdevices)
27112                                 continue;
27113 +                       if (!nx_dev_visible(current_nx_info(), d))
27114 +                               continue;
27115  
27116                         /*  avoid cases where sscanf is not exact inverse of printf */
27117                         snprintf(buf, IFNAMSIZ, name, i);
27118 @@ -2984,6 +2993,8 @@ static int dev_ifconf(struct net *net, c
27119  
27120         total = 0;
27121         for_each_netdev(net, dev) {
27122 +               if (!nx_dev_visible(current_nx_info(), dev))
27123 +                       continue;
27124                 for (i = 0; i < NPROTO; i++) {
27125                         if (gifconf_list[i]) {
27126                                 int done;
27127 @@ -3052,6 +3063,9 @@ static void dev_seq_printf_stats(struct 
27128  {
27129         const struct net_device_stats *stats = dev_get_stats(dev);
27130  
27131 +       if (!nx_dev_visible(current_nx_info(), dev))
27132 +               return;
27133 +
27134         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
27135                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
27136                    dev->name, stats->rx_bytes, stats->rx_packets,
27137 @@ -5317,7 +5331,6 @@ int dev_change_net_namespace(struct net_
27138         if (dev->dev.parent)
27139                 goto out;
27140  #endif
27141 -
27142         /* Ensure the device has been registrered */
27143         err = -EINVAL;
27144         if (dev->reg_state != NETREG_REGISTERED)
27145 diff -NurpP --minimal linux-2.6.32.10/net/core/rtnetlink.c linux-2.6.32.10-vs2.3.0.36.29.2/net/core/rtnetlink.c
27146 --- linux-2.6.32.10/net/core/rtnetlink.c        2010-03-18 16:17:38.000000000 +0100
27147 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/core/rtnetlink.c        2009-12-29 00:36:26.000000000 +0100
27148 @@ -688,6 +688,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
27149  
27150         idx = 0;
27151         for_each_netdev(net, dev) {
27152 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
27153 +                       continue;
27154                 if (idx < s_idx)
27155                         goto cont;
27156                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
27157 @@ -1222,6 +1224,9 @@ void rtmsg_ifinfo(int type, struct net_d
27158         struct sk_buff *skb;
27159         int err = -ENOBUFS;
27160  
27161 +       if (!nx_dev_visible(current_nx_info(), dev))
27162 +               return;
27163 +
27164         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
27165         if (skb == NULL)
27166                 goto errout;
27167 diff -NurpP --minimal linux-2.6.32.10/net/core/sock.c linux-2.6.32.10-vs2.3.0.36.29.2/net/core/sock.c
27168 --- linux-2.6.32.10/net/core/sock.c     2010-03-18 16:17:38.000000000 +0100
27169 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/core/sock.c     2010-02-12 10:59:55.000000000 +0100
27170 @@ -125,6 +125,10 @@
27171  #include <linux/ipsec.h>
27172  
27173  #include <linux/filter.h>
27174 +#include <linux/vs_socket.h>
27175 +#include <linux/vs_limit.h>
27176 +#include <linux/vs_context.h>
27177 +#include <linux/vs_network.h>
27178  
27179  #ifdef CONFIG_INET
27180  #include <net/tcp.h>
27181 @@ -984,6 +988,8 @@ static struct sock *sk_prot_alloc(struct
27182                 if (!try_module_get(prot->owner))
27183                         goto out_free_sec;
27184         }
27185 +               sock_vx_init(sk);
27186 +               sock_nx_init(sk);
27187  
27188         return sk;
27189  
27190 @@ -1063,6 +1069,11 @@ static void __sk_free(struct sock *sk)
27191                        __func__, atomic_read(&sk->sk_omem_alloc));
27192  
27193         put_net(sock_net(sk));
27194 +       vx_sock_dec(sk);
27195 +       clr_vx_info(&sk->sk_vx_info);
27196 +       sk->sk_xid = -1;
27197 +       clr_nx_info(&sk->sk_nx_info);
27198 +       sk->sk_nid = -1;
27199         sk_prot_free(sk->sk_prot_creator, sk);
27200  }
27201  
27202 @@ -1110,6 +1121,8 @@ struct sock *sk_clone(const struct sock 
27203  
27204                 /* SANITY */
27205                 get_net(sock_net(newsk));
27206 +               sock_vx_init(newsk);
27207 +               sock_nx_init(newsk);
27208                 sk_node_init(&newsk->sk_node);
27209                 sock_lock_init(newsk);
27210                 bh_lock_sock(newsk);
27211 @@ -1164,6 +1177,12 @@ struct sock *sk_clone(const struct sock 
27212                 smp_wmb();
27213                 atomic_set(&newsk->sk_refcnt, 2);
27214  
27215 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
27216 +               newsk->sk_xid = sk->sk_xid;
27217 +               vx_sock_inc(newsk);
27218 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
27219 +               newsk->sk_nid = sk->sk_nid;
27220 +
27221                 /*
27222                  * Increment the counter in the same struct proto as the master
27223                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
27224 @@ -1886,6 +1905,12 @@ void sock_init_data(struct socket *sock,
27225  
27226         sk->sk_stamp = ktime_set(-1L, 0);
27227  
27228 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
27229 +       sk->sk_xid = vx_current_xid();
27230 +       vx_sock_inc(sk);
27231 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
27232 +       sk->sk_nid = nx_current_nid();
27233 +
27234         /*
27235          * Before updating sk_refcnt, we must commit prior changes to memory
27236          * (Documentation/RCU/rculist_nulls.txt for details)
27237 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/af_inet.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/af_inet.c
27238 --- linux-2.6.32.10/net/ipv4/af_inet.c  2009-12-03 20:02:59.000000000 +0100
27239 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/af_inet.c  2009-12-03 20:04:56.000000000 +0100
27240 @@ -115,6 +115,7 @@
27241  #ifdef CONFIG_IP_MROUTE
27242  #include <linux/mroute.h>
27243  #endif
27244 +#include <linux/vs_limit.h>
27245  
27246  
27247  /* The inetsw table contains everything that inet_create needs to
27248 @@ -325,9 +326,12 @@ lookup_protocol:
27249         }
27250  
27251         err = -EPERM;
27252 +       if ((protocol == IPPROTO_ICMP) &&
27253 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27254 +               goto override;
27255         if (answer->capability > 0 && !capable(answer->capability))
27256                 goto out_rcu_unlock;
27257 -
27258 +override:
27259         err = -EAFNOSUPPORT;
27260         if (!inet_netns_ok(net, protocol))
27261                 goto out_rcu_unlock;
27262 @@ -447,6 +451,7 @@ int inet_bind(struct socket *sock, struc
27263         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
27264         struct sock *sk = sock->sk;
27265         struct inet_sock *inet = inet_sk(sk);
27266 +       struct nx_v4_sock_addr nsa;
27267         unsigned short snum;
27268         int chk_addr_ret;
27269         int err;
27270 @@ -460,7 +465,11 @@ int inet_bind(struct socket *sock, struc
27271         if (addr_len < sizeof(struct sockaddr_in))
27272                 goto out;
27273  
27274 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27275 +       err = v4_map_sock_addr(inet, addr, &nsa);
27276 +       if (err)
27277 +               goto out;
27278 +
27279 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27280  
27281         /* Not specified by any standard per-se, however it breaks too
27282          * many applications when removed.  It is unfortunate since
27283 @@ -472,7 +481,7 @@ int inet_bind(struct socket *sock, struc
27284         err = -EADDRNOTAVAIL;
27285         if (!sysctl_ip_nonlocal_bind &&
27286             !(inet->freebind || inet->transparent) &&
27287 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
27288 +           nsa.saddr != htonl(INADDR_ANY) &&
27289             chk_addr_ret != RTN_LOCAL &&
27290             chk_addr_ret != RTN_MULTICAST &&
27291             chk_addr_ret != RTN_BROADCAST)
27292 @@ -497,7 +506,7 @@ int inet_bind(struct socket *sock, struc
27293         if (sk->sk_state != TCP_CLOSE || inet->num)
27294                 goto out_release_sock;
27295  
27296 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27297 +       v4_set_sock_addr(inet, &nsa);
27298         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27299                 inet->saddr = 0;  /* Use device */
27300  
27301 @@ -694,11 +703,13 @@ int inet_getname(struct socket *sock, st
27302                      peer == 1))
27303                         return -ENOTCONN;
27304                 sin->sin_port = inet->dport;
27305 -               sin->sin_addr.s_addr = inet->daddr;
27306 +               sin->sin_addr.s_addr =
27307 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27308         } else {
27309                 __be32 addr = inet->rcv_saddr;
27310                 if (!addr)
27311                         addr = inet->saddr;
27312 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
27313                 sin->sin_port = inet->sport;
27314                 sin->sin_addr.s_addr = addr;
27315         }
27316 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/devinet.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/devinet.c
27317 --- linux-2.6.32.10/net/ipv4/devinet.c  2010-03-18 16:17:38.000000000 +0100
27318 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/devinet.c  2010-03-18 16:53:06.000000000 +0100
27319 @@ -413,6 +413,7 @@ struct in_device *inetdev_by_index(struc
27320         return in_dev;
27321  }
27322  
27323 +
27324  /* Called only from RTNL semaphored context. No locks. */
27325  
27326  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
27327 @@ -653,6 +654,8 @@ int devinet_ioctl(struct net *net, unsig
27328                 *colon = ':';
27329  
27330         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
27331 +               struct nx_info *nxi = current_nx_info();
27332 +
27333                 if (tryaddrmatch) {
27334                         /* Matthias Andree */
27335                         /* compare label and address (4.4BSD style) */
27336 @@ -661,6 +664,8 @@ int devinet_ioctl(struct net *net, unsig
27337                            This is checked above. */
27338                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27339                              ifap = &ifa->ifa_next) {
27340 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27341 +                                       continue;
27342                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
27343                                     sin_orig.sin_addr.s_addr ==
27344                                                         ifa->ifa_address) {
27345 @@ -673,9 +678,12 @@ int devinet_ioctl(struct net *net, unsig
27346                    comparing just the label */
27347                 if (!ifa) {
27348                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27349 -                            ifap = &ifa->ifa_next)
27350 +                            ifap = &ifa->ifa_next) {
27351 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27352 +                                       continue;
27353                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
27354                                         break;
27355 +                       }
27356                 }
27357         }
27358  
27359 @@ -826,6 +834,8 @@ static int inet_gifconf(struct net_devic
27360                 goto out;
27361  
27362         for (; ifa; ifa = ifa->ifa_next) {
27363 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
27364 +                       continue;
27365                 if (!buf) {
27366                         done += sizeof(ifr);
27367                         continue;
27368 @@ -1174,6 +1184,7 @@ static int inet_dump_ifaddr(struct sk_bu
27369         struct net_device *dev;
27370         struct in_device *in_dev;
27371         struct in_ifaddr *ifa;
27372 +       struct sock *sk = skb->sk;
27373         int s_ip_idx, s_idx = cb->args[0];
27374  
27375         s_ip_idx = ip_idx = cb->args[1];
27376 @@ -1188,6 +1199,8 @@ static int inet_dump_ifaddr(struct sk_bu
27377  
27378                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
27379                      ifa = ifa->ifa_next, ip_idx++) {
27380 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
27381 +                               continue;
27382                         if (ip_idx < s_ip_idx)
27383                                 continue;
27384                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
27385 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/fib_hash.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/fib_hash.c
27386 --- linux-2.6.32.10/net/ipv4/fib_hash.c 2009-09-10 15:26:29.000000000 +0200
27387 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/fib_hash.c 2009-12-03 20:04:56.000000000 +0100
27388 @@ -1021,7 +1021,7 @@ static int fib_seq_show(struct seq_file 
27389         prefix  = f->fn_key;
27390         mask    = FZ_MASK(iter->zone);
27391         flags   = fib_flag_trans(fa->fa_type, mask, fi);
27392 -       if (fi)
27393 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
27394                 seq_printf(seq,
27395                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
27396                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
27397 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/inet_connection_sock.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/inet_connection_sock.c
27398 --- linux-2.6.32.10/net/ipv4/inet_connection_sock.c     2009-12-03 20:02:59.000000000 +0100
27399 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/inet_connection_sock.c     2009-12-03 20:04:56.000000000 +0100
27400 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
27401  }
27402  EXPORT_SYMBOL(inet_get_local_port_range);
27403  
27404 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27405 +{
27406 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
27407 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
27408 +
27409 +       if (inet_v6_ipv6only(sk2))
27410 +               return 0;
27411 +
27412 +       if (sk1_rcv_saddr &&
27413 +           sk2_rcv_saddr &&
27414 +           sk1_rcv_saddr == sk2_rcv_saddr)
27415 +               return 1;
27416 +
27417 +       if (sk1_rcv_saddr &&
27418 +           !sk2_rcv_saddr &&
27419 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
27420 +               return 1;
27421 +
27422 +       if (sk2_rcv_saddr &&
27423 +           !sk1_rcv_saddr &&
27424 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
27425 +               return 1;
27426 +
27427 +       if (!sk1_rcv_saddr &&
27428 +           !sk2_rcv_saddr &&
27429 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
27430 +               return 1;
27431 +
27432 +       return 0;
27433 +}
27434 +
27435  int inet_csk_bind_conflict(const struct sock *sk,
27436                            const struct inet_bind_bucket *tb)
27437  {
27438 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
27439         struct sock *sk2;
27440         struct hlist_node *node;
27441         int reuse = sk->sk_reuse;
27442 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
27443                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
27444                         if (!reuse || !sk2->sk_reuse ||
27445                             sk2->sk_state == TCP_LISTEN) {
27446 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27447 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
27448 -                                   sk2_rcv_saddr == sk_rcv_saddr)
27449 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
27450                                         break;
27451                         }
27452                 }
27453 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/inet_diag.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/inet_diag.c
27454 --- linux-2.6.32.10/net/ipv4/inet_diag.c        2009-09-10 15:26:29.000000000 +0200
27455 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/inet_diag.c        2009-12-03 20:04:56.000000000 +0100
27456 @@ -32,6 +32,8 @@
27457  #include <linux/stddef.h>
27458  
27459  #include <linux/inet_diag.h>
27460 +#include <linux/vs_network.h>
27461 +#include <linux/vs_inet.h>
27462  
27463  static const struct inet_diag_handler **inet_diag_table;
27464  
27465 @@ -118,8 +120,8 @@ static int inet_csk_diag_fill(struct soc
27466  
27467         r->id.idiag_sport = inet->sport;
27468         r->id.idiag_dport = inet->dport;
27469 -       r->id.idiag_src[0] = inet->rcv_saddr;
27470 -       r->id.idiag_dst[0] = inet->daddr;
27471 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
27472 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27473  
27474  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27475         if (r->idiag_family == AF_INET6) {
27476 @@ -204,8 +206,8 @@ static int inet_twsk_diag_fill(struct in
27477         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
27478         r->id.idiag_sport     = tw->tw_sport;
27479         r->id.idiag_dport     = tw->tw_dport;
27480 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
27481 -       r->id.idiag_dst[0]    = tw->tw_daddr;
27482 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
27483 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
27484         r->idiag_state        = tw->tw_substate;
27485         r->idiag_timer        = 3;
27486         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
27487 @@ -262,6 +264,7 @@ static int inet_diag_get_exact(struct sk
27488         err = -EINVAL;
27489  
27490         if (req->idiag_family == AF_INET) {
27491 +               /* TODO: lback */
27492                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
27493                                  req->id.idiag_dport, req->id.idiag_src[0],
27494                                  req->id.idiag_sport, req->id.idiag_if);
27495 @@ -504,6 +507,7 @@ static int inet_csk_diag_dump(struct soc
27496                 } else
27497  #endif
27498                 {
27499 +                       /* TODO: lback */
27500                         entry.saddr = &inet->rcv_saddr;
27501                         entry.daddr = &inet->daddr;
27502                 }
27503 @@ -540,6 +544,7 @@ static int inet_twsk_diag_dump(struct in
27504                 } else
27505  #endif
27506                 {
27507 +                       /* TODO: lback */
27508                         entry.saddr = &tw->tw_rcv_saddr;
27509                         entry.daddr = &tw->tw_daddr;
27510                 }
27511 @@ -586,8 +591,8 @@ static int inet_diag_fill_req(struct sk_
27512  
27513         r->id.idiag_sport = inet->sport;
27514         r->id.idiag_dport = ireq->rmt_port;
27515 -       r->id.idiag_src[0] = ireq->loc_addr;
27516 -       r->id.idiag_dst[0] = ireq->rmt_addr;
27517 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
27518 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
27519         r->idiag_expires = jiffies_to_msecs(tmo);
27520         r->idiag_rqueue = 0;
27521         r->idiag_wqueue = 0;
27522 @@ -657,6 +662,7 @@ static int inet_diag_dump_reqs(struct sk
27523                                 continue;
27524  
27525                         if (bc) {
27526 +                               /* TODO: lback */
27527                                 entry.saddr =
27528  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27529                                         (entry.family == AF_INET6) ?
27530 @@ -727,6 +733,8 @@ static int inet_diag_dump(struct sk_buff
27531                         sk_nulls_for_each(sk, node, &ilb->head) {
27532                                 struct inet_sock *inet = inet_sk(sk);
27533  
27534 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27535 +                                       continue;
27536                                 if (num < s_num) {
27537                                         num++;
27538                                         continue;
27539 @@ -793,6 +801,8 @@ skip_listen_ht:
27540                 sk_nulls_for_each(sk, node, &head->chain) {
27541                         struct inet_sock *inet = inet_sk(sk);
27542  
27543 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27544 +                               continue;
27545                         if (num < s_num)
27546                                 goto next_normal;
27547                         if (!(r->idiag_states & (1 << sk->sk_state)))
27548 @@ -817,6 +827,8 @@ next_normal:
27549                         inet_twsk_for_each(tw, node,
27550                                     &head->twchain) {
27551  
27552 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27553 +                                       continue;
27554                                 if (num < s_num)
27555                                         goto next_dying;
27556                                 if (r->id.idiag_sport != tw->tw_sport &&
27557 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/inet_hashtables.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/inet_hashtables.c
27558 --- linux-2.6.32.10/net/ipv4/inet_hashtables.c  2009-06-11 17:13:29.000000000 +0200
27559 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/inet_hashtables.c  2009-12-03 20:04:56.000000000 +0100
27560 @@ -21,6 +21,7 @@
27561  
27562  #include <net/inet_connection_sock.h>
27563  #include <net/inet_hashtables.h>
27564 +#include <net/route.h>
27565  #include <net/ip.h>
27566  
27567  /*
27568 @@ -134,6 +135,11 @@ static inline int compute_score(struct s
27569                         if (rcv_saddr != daddr)
27570                                 return -1;
27571                         score += 2;
27572 +               } else {
27573 +                       /* block non nx_info ips */
27574 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27575 +                               daddr, NXA_MASK_BIND))
27576 +                               return -1;
27577                 }
27578                 if (sk->sk_bound_dev_if) {
27579                         if (sk->sk_bound_dev_if != dif)
27580 @@ -151,7 +157,6 @@ static inline int compute_score(struct s
27581   * wildcarded during the search since they can never be otherwise.
27582   */
27583  
27584 -
27585  struct sock *__inet_lookup_listener(struct net *net,
27586                                     struct inet_hashinfo *hashinfo,
27587                                     const __be32 daddr, const unsigned short hnum,
27588 @@ -174,6 +179,7 @@ begin:
27589                         hiscore = score;
27590                 }
27591         }
27592 +
27593         /*
27594          * if the nulls value we got at the end of this lookup is
27595          * not the expected one, we must restart lookup.
27596 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/netfilter/nf_nat_helper.c
27597 --- linux-2.6.32.10/net/ipv4/netfilter/nf_nat_helper.c  2009-12-03 20:02:59.000000000 +0100
27598 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/netfilter/nf_nat_helper.c  2009-12-03 20:04:56.000000000 +0100
27599 @@ -19,6 +19,7 @@
27600  #include <net/route.h>
27601  
27602  #include <linux/netfilter_ipv4.h>
27603 +#include <net/route.h>
27604  #include <net/netfilter/nf_conntrack.h>
27605  #include <net/netfilter/nf_conntrack_helper.h>
27606  #include <net/netfilter/nf_conntrack_ecache.h>
27607 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/netfilter.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/netfilter.c
27608 --- linux-2.6.32.10/net/ipv4/netfilter.c        2009-09-10 15:26:29.000000000 +0200
27609 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/netfilter.c        2009-12-03 20:04:56.000000000 +0100
27610 @@ -4,7 +4,7 @@
27611  #include <linux/netfilter_ipv4.h>
27612  #include <linux/ip.h>
27613  #include <linux/skbuff.h>
27614 -#include <net/route.h>
27615 +// #include <net/route.h>
27616  #include <net/xfrm.h>
27617  #include <net/ip.h>
27618  #include <net/netfilter/nf_queue.h>
27619 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/raw.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/raw.c
27620 --- linux-2.6.32.10/net/ipv4/raw.c      2009-12-03 20:02:59.000000000 +0100
27621 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/raw.c      2009-12-03 20:04:56.000000000 +0100
27622 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
27623  
27624                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
27625                     !(inet->daddr && inet->daddr != raddr)              &&
27626 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27627 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27628                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27629                         goto found; /* gotcha */
27630         }
27631 @@ -383,6 +383,12 @@ static int raw_send_hdrinc(struct sock *
27632                 icmp_out_count(net, ((struct icmphdr *)
27633                         skb_transport_header(skb))->type);
27634  
27635 +       err = -EPERM;
27636 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27637 +               sk->sk_nx_info &&
27638 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27639 +               goto error_free;
27640 +
27641         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27642                       dst_output);
27643         if (err > 0)
27644 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
27645                 }
27646  
27647                 security_sk_classify_flow(sk, &fl);
27648 +               if (sk->sk_nx_info) {
27649 +                       err = ip_v4_find_src(sock_net(sk),
27650 +                               sk->sk_nx_info, &rt, &fl);
27651 +
27652 +                       if (err)
27653 +                               goto done;
27654 +               }
27655                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
27656         }
27657         if (err)
27658 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
27659  {
27660         struct inet_sock *inet = inet_sk(sk);
27661         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27662 +       struct nx_v4_sock_addr nsa = { 0 };
27663         int ret = -EINVAL;
27664         int chk_addr_ret;
27665  
27666         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27667                 goto out;
27668 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27669 +       v4_map_sock_addr(inet, addr, &nsa);
27670 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27671         ret = -EADDRNOTAVAIL;
27672 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27673 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27674             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27675                 goto out;
27676 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27677 +       v4_set_sock_addr(inet, &nsa);
27678         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27679                 inet->saddr = 0;  /* Use device */
27680         sk_dst_reset(sk);
27681 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
27682         /* Copy the address. */
27683         if (sin) {
27684                 sin->sin_family = AF_INET;
27685 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27686 +               sin->sin_addr.s_addr =
27687 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27688                 sin->sin_port = 0;
27689                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27690         }
27691 @@ -875,7 +891,8 @@ static struct sock *raw_get_first(struct
27692                 struct hlist_node *node;
27693  
27694                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27695 -                       if (sock_net(sk) == seq_file_net(seq))
27696 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
27697 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27698                                 goto found;
27699         }
27700         sk = NULL;
27701 @@ -891,7 +908,8 @@ static struct sock *raw_get_next(struct 
27702                 sk = sk_next(sk);
27703  try_again:
27704                 ;
27705 -       } while (sk && sock_net(sk) != seq_file_net(seq));
27706 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
27707 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27708  
27709         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27710                 sk = sk_head(&state->h->ht[state->bucket]);
27711 @@ -950,7 +968,10 @@ static void raw_sock_seq_show(struct seq
27712  
27713         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
27714                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
27715 -               i, src, srcp, dest, destp, sp->sk_state,
27716 +               i,
27717 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27718 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27719 +               sp->sk_state,
27720                 sk_wmem_alloc_get(sp),
27721                 sk_rmem_alloc_get(sp),
27722                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27723 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/tcp.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/tcp.c
27724 --- linux-2.6.32.10/net/ipv4/tcp.c      2009-12-03 20:02:59.000000000 +0100
27725 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/tcp.c      2009-12-03 20:04:56.000000000 +0100
27726 @@ -264,6 +264,7 @@
27727  #include <linux/cache.h>
27728  #include <linux/err.h>
27729  #include <linux/crypto.h>
27730 +#include <linux/in.h>
27731  
27732  #include <net/icmp.h>
27733  #include <net/tcp.h>
27734 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/tcp_ipv4.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/tcp_ipv4.c
27735 --- linux-2.6.32.10/net/ipv4/tcp_ipv4.c 2009-12-03 20:03:00.000000000 +0100
27736 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/tcp_ipv4.c 2009-12-03 20:04:56.000000000 +0100
27737 @@ -1925,6 +1925,12 @@ static void *listening_get_next(struct s
27738                 req = req->dl_next;
27739                 while (1) {
27740                         while (req) {
27741 +                               vxdprintk(VXD_CBIT(net, 6),
27742 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27743 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27744 +                               if (req->sk &&
27745 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27746 +                                       continue;
27747                                 if (req->rsk_ops->family == st->family) {
27748                                         cur = req;
27749                                         goto out;
27750 @@ -1949,6 +1955,10 @@ get_req:
27751         }
27752  get_sk:
27753         sk_nulls_for_each_from(sk, node) {
27754 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27755 +                       sk, sk->sk_nid, nx_current_nid());
27756 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27757 +                       continue;
27758                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
27759                         cur = sk;
27760                         goto out;
27761 @@ -2012,6 +2022,11 @@ static void *established_get_first(struc
27762  
27763                 spin_lock_bh(lock);
27764                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27765 +                       vxdprintk(VXD_CBIT(net, 6),
27766 +                               "sk,egf: %p [#%d] (from %d)",
27767 +                               sk, sk->sk_nid, nx_current_nid());
27768 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27769 +                               continue;
27770                         if (sk->sk_family != st->family ||
27771                             !net_eq(sock_net(sk), net)) {
27772                                 continue;
27773 @@ -2022,6 +2037,11 @@ static void *established_get_first(struc
27774                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27775                 inet_twsk_for_each(tw, node,
27776                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27777 +                       vxdprintk(VXD_CBIT(net, 6),
27778 +                               "tw: %p [#%d] (from %d)",
27779 +                               tw, tw->tw_nid, nx_current_nid());
27780 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27781 +                               continue;
27782                         if (tw->tw_family != st->family ||
27783                             !net_eq(twsk_net(tw), net)) {
27784                                 continue;
27785 @@ -2050,7 +2070,9 @@ static void *established_get_next(struct
27786                 tw = cur;
27787                 tw = tw_next(tw);
27788  get_tw:
27789 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27790 +               while (tw && (tw->tw_family != st->family ||
27791 +                       !net_eq(twsk_net(tw), net) ||
27792 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27793                         tw = tw_next(tw);
27794                 }
27795                 if (tw) {
27796 @@ -2073,6 +2095,11 @@ get_tw:
27797                 sk = sk_nulls_next(sk);
27798  
27799         sk_nulls_for_each_from(sk, node) {
27800 +               vxdprintk(VXD_CBIT(net, 6),
27801 +                       "sk,egn: %p [#%d] (from %d)",
27802 +                       sk, sk->sk_nid, nx_current_nid());
27803 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27804 +                       continue;
27805                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27806                         goto found;
27807         }
27808 @@ -2224,9 +2251,9 @@ static void get_openreq4(struct sock *sk
27809         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27810                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
27811                 i,
27812 -               ireq->loc_addr,
27813 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27814                 ntohs(inet_sk(sk)->sport),
27815 -               ireq->rmt_addr,
27816 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27817                 ntohs(ireq->rmt_port),
27818                 TCP_SYN_RECV,
27819                 0, 0, /* could print option size, but that is af dependent. */
27820 @@ -2269,7 +2296,10 @@ static void get_tcp4_sock(struct sock *s
27821  
27822         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27823                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27824 -               i, src, srcp, dest, destp, sk->sk_state,
27825 +               i,
27826 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27827 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27828 +               sk->sk_state,
27829                 tp->write_seq - tp->snd_una,
27830                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27831                                              (tp->rcv_nxt - tp->copied_seq),
27832 @@ -2305,7 +2335,10 @@ static void get_timewait4_sock(struct in
27833  
27834         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27835                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27836 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27837 +               i,
27838 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27839 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27840 +               tw->tw_substate, 0, 0,
27841                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27842                 atomic_read(&tw->tw_refcnt), tw, len);
27843  }
27844 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/tcp_minisocks.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/tcp_minisocks.c
27845 --- linux-2.6.32.10/net/ipv4/tcp_minisocks.c    2009-12-03 20:03:00.000000000 +0100
27846 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/tcp_minisocks.c    2009-12-03 20:04:56.000000000 +0100
27847 @@ -26,6 +26,10 @@
27848  #include <net/inet_common.h>
27849  #include <net/xfrm.h>
27850  
27851 +#include <linux/vs_limit.h>
27852 +#include <linux/vs_socket.h>
27853 +#include <linux/vs_context.h>
27854 +
27855  #ifdef CONFIG_SYSCTL
27856  #define SYNC_INIT 0 /* let the user enable it */
27857  #else
27858 @@ -294,6 +298,11 @@ void tcp_time_wait(struct sock *sk, int 
27859                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27860                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27861  
27862 +               tw->tw_xid              = sk->sk_xid;
27863 +               tw->tw_vx_info          = NULL;
27864 +               tw->tw_nid              = sk->sk_nid;
27865 +               tw->tw_nx_info          = NULL;
27866 +
27867  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27868                 if (tw->tw_family == PF_INET6) {
27869                         struct ipv6_pinfo *np = inet6_sk(sk);
27870 diff -NurpP --minimal linux-2.6.32.10/net/ipv4/udp.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/udp.c
27871 --- linux-2.6.32.10/net/ipv4/udp.c      2009-12-03 20:03:00.000000000 +0100
27872 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv4/udp.c      2009-12-03 20:04:56.000000000 +0100
27873 @@ -224,14 +224,7 @@ fail:
27874  }
27875  EXPORT_SYMBOL(udp_lib_get_port);
27876  
27877 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27878 -{
27879 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27880 -
27881 -       return  (!ipv6_only_sock(sk2)  &&
27882 -                (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27883 -                  inet1->rcv_saddr == inet2->rcv_saddr));
27884 -}
27885 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27886  
27887  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27888  {
27889 @@ -253,6 +246,11 @@ static inline int compute_score(struct s
27890                         if (inet->rcv_saddr != daddr)
27891                                 return -1;
27892                         score += 2;
27893 +               } else {
27894 +                       /* block non nx_info ips */
27895 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27896 +                               daddr, NXA_MASK_BIND))
27897 +                               return -1;
27898                 }
27899                 if (inet->daddr) {
27900                         if (inet->daddr != saddr)
27901 @@ -273,6 +271,7 @@ static inline int compute_score(struct s
27902         return score;
27903  }
27904  
27905 +
27906  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27907   * harder than this. -DaveM
27908   */
27909 @@ -294,6 +293,11 @@ begin:
27910         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27911                 score = compute_score(sk, net, saddr, hnum, sport,
27912                                       daddr, dport, dif);
27913 +               /* FIXME: disabled?
27914 +               if (score == 9) {
27915 +                       result = sk;
27916 +                       break;
27917 +               } else */
27918                 if (score > badness) {
27919                         result = sk;
27920                         badness = score;
27921 @@ -307,6 +311,7 @@ begin:
27922         if (get_nulls_value(node) != hash)
27923                 goto begin;
27924  
27925 +
27926         if (result) {
27927                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
27928                         result = NULL;
27929 @@ -316,6 +321,7 @@ begin:
27930                         goto begin;
27931                 }
27932         }
27933 +
27934         rcu_read_unlock();
27935         return result;
27936  }
27937 @@ -358,7 +364,7 @@ static inline struct sock *udp_v4_mcast_
27938                     s->sk_hash != hnum                                  ||
27939                     (inet->daddr && inet->daddr != rmt_addr)            ||
27940                     (inet->dport != rmt_port && inet->dport)            ||
27941 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27942 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27943                     ipv6_only_sock(s)                                   ||
27944                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27945                         continue;
27946 @@ -707,8 +713,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27947                                                { .sport = inet->sport,
27948                                                  .dport = dport } } };
27949                 struct net *net = sock_net(sk);
27950 +               struct nx_info *nxi = sk->sk_nx_info;
27951  
27952                 security_sk_classify_flow(sk, &fl);
27953 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27954 +               if (err)
27955 +                       goto out;
27956 +
27957                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27958                 if (err) {
27959                         if (err == -ENETUNREACH)
27960 @@ -988,7 +999,8 @@ try_again:
27961         if (sin) {
27962                 sin->sin_family = AF_INET;
27963                 sin->sin_port = udp_hdr(skb)->source;
27964 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27965 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27966 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27967                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27968         }
27969         if (inet->cmsg_flags)
27970 @@ -1627,6 +1639,8 @@ static struct sock *udp_get_first(struct
27971                 sk_nulls_for_each(sk, node, &hslot->head) {
27972                         if (!net_eq(sock_net(sk), net))
27973                                 continue;
27974 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27975 +                               continue;
27976                         if (sk->sk_family == state->family)
27977                                 goto found;
27978                 }
27979 @@ -1644,7 +1658,9 @@ static struct sock *udp_get_next(struct 
27980  
27981         do {
27982                 sk = sk_nulls_next(sk);
27983 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27984 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27985 +               sk->sk_family != state->family ||
27986 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27987  
27988         if (!sk) {
27989                 if (state->bucket < UDP_HTABLE_SIZE)
27990 @@ -1751,7 +1767,10 @@ static void udp4_format_sock(struct sock
27991  
27992         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27993                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27994 -               bucket, src, srcp, dest, destp, sp->sk_state,
27995 +               bucket,
27996 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27997 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27998 +               sp->sk_state,
27999                 sk_wmem_alloc_get(sp),
28000                 sk_rmem_alloc_get(sp),
28001                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
28002 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/addrconf.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/addrconf.c
28003 --- linux-2.6.32.10/net/ipv6/addrconf.c 2010-03-18 16:17:38.000000000 +0100
28004 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/addrconf.c 2010-03-18 16:53:06.000000000 +0100
28005 @@ -86,6 +86,8 @@
28006  
28007  #include <linux/proc_fs.h>
28008  #include <linux/seq_file.h>
28009 +#include <linux/vs_network.h>
28010 +#include <linux/vs_inet6.h>
28011  
28012  /* Set to 3 to get tracing... */
28013  #define ACONF_DEBUG 2
28014 @@ -1122,7 +1124,7 @@ out:
28015  
28016  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
28017                        const struct in6_addr *daddr, unsigned int prefs,
28018 -                      struct in6_addr *saddr)
28019 +                      struct in6_addr *saddr, struct nx_info *nxi)
28020  {
28021         struct ipv6_saddr_score scores[2],
28022                                 *score = &scores[0], *hiscore = &scores[1];
28023 @@ -1195,6 +1197,8 @@ int ipv6_dev_get_saddr(struct net *net, 
28024                                                dev->name);
28025                                 continue;
28026                         }
28027 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
28028 +                               continue;
28029  
28030                         score->rule = -1;
28031                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
28032 @@ -3003,7 +3007,10 @@ static void if6_seq_stop(struct seq_file
28033  static int if6_seq_show(struct seq_file *seq, void *v)
28034  {
28035         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
28036 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
28037 +
28038 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
28039 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
28040 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
28041                    &ifp->addr,
28042                    ifp->idev->dev->ifindex,
28043                    ifp->prefix_len,
28044 @@ -3500,6 +3507,12 @@ static int inet6_dump_addr(struct sk_buf
28045         struct ifmcaddr6 *ifmca;
28046         struct ifacaddr6 *ifaca;
28047         struct net *net = sock_net(skb->sk);
28048 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
28049 +
28050 +       /* disable ipv6 on non v6 guests */
28051 +       if (nxi && !nx_info_has_v6(nxi))
28052 +               return skb->len;
28053 +
28054  
28055         s_idx = cb->args[0];
28056         s_ip_idx = ip_idx = cb->args[1];
28057 @@ -3521,6 +3534,8 @@ static int inet6_dump_addr(struct sk_buf
28058                              ifa = ifa->if_next, ip_idx++) {
28059                                 if (ip_idx < s_ip_idx)
28060                                         continue;
28061 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
28062 +                                       continue;
28063                                 err = inet6_fill_ifaddr(skb, ifa,
28064                                                         NETLINK_CB(cb->skb).pid,
28065                                                         cb->nlh->nlmsg_seq,
28066 @@ -3534,6 +3549,8 @@ static int inet6_dump_addr(struct sk_buf
28067                              ifmca = ifmca->next, ip_idx++) {
28068                                 if (ip_idx < s_ip_idx)
28069                                         continue;
28070 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
28071 +                                       continue;
28072                                 err = inet6_fill_ifmcaddr(skb, ifmca,
28073                                                           NETLINK_CB(cb->skb).pid,
28074                                                           cb->nlh->nlmsg_seq,
28075 @@ -3547,6 +3564,8 @@ static int inet6_dump_addr(struct sk_buf
28076                              ifaca = ifaca->aca_next, ip_idx++) {
28077                                 if (ip_idx < s_ip_idx)
28078                                         continue;
28079 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
28080 +                                       continue;
28081                                 err = inet6_fill_ifacaddr(skb, ifaca,
28082                                                           NETLINK_CB(cb->skb).pid,
28083                                                           cb->nlh->nlmsg_seq,
28084 @@ -3833,12 +3852,19 @@ static int inet6_dump_ifinfo(struct sk_b
28085         int s_idx = cb->args[0];
28086         struct net_device *dev;
28087         struct inet6_dev *idev;
28088 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
28089 +
28090 +       /* FIXME: maybe disable ipv6 on non v6 guests?
28091 +       if (skb->sk && skb->sk->sk_vx_info)
28092 +               return skb->len; */
28093  
28094         read_lock(&dev_base_lock);
28095         idx = 0;
28096         for_each_netdev(net, dev) {
28097                 if (idx < s_idx)
28098                         goto cont;
28099 +               if (!v6_dev_in_nx_info(dev, nxi))
28100 +                       goto cont;
28101                 if ((idev = in6_dev_get(dev)) == NULL)
28102                         goto cont;
28103                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
28104 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/af_inet6.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/af_inet6.c
28105 --- linux-2.6.32.10/net/ipv6/af_inet6.c 2009-12-03 20:03:00.000000000 +0100
28106 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/af_inet6.c 2009-12-03 20:04:56.000000000 +0100
28107 @@ -41,6 +41,8 @@
28108  #include <linux/netdevice.h>
28109  #include <linux/icmpv6.h>
28110  #include <linux/netfilter_ipv6.h>
28111 +#include <linux/vs_inet.h>
28112 +#include <linux/vs_inet6.h>
28113  
28114  #include <net/ip.h>
28115  #include <net/ipv6.h>
28116 @@ -158,9 +160,12 @@ lookup_protocol:
28117         }
28118  
28119         err = -EPERM;
28120 +       if ((protocol == IPPROTO_ICMPV6) &&
28121 +               nx_capable(answer->capability, NXC_RAW_ICMP))
28122 +               goto override;
28123         if (answer->capability > 0 && !capable(answer->capability))
28124                 goto out_rcu_unlock;
28125 -
28126 +override:
28127         sock->ops = answer->ops;
28128         answer_prot = answer->prot;
28129         answer_no_check = answer->no_check;
28130 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
28131         struct inet_sock *inet = inet_sk(sk);
28132         struct ipv6_pinfo *np = inet6_sk(sk);
28133         struct net *net = sock_net(sk);
28134 +       struct nx_v6_sock_addr nsa;
28135         __be32 v4addr = 0;
28136         unsigned short snum;
28137         int addr_type = 0;
28138 @@ -270,6 +276,11 @@ int inet6_bind(struct socket *sock, stru
28139  
28140         if (addr_len < SIN6_LEN_RFC2133)
28141                 return -EINVAL;
28142 +
28143 +       err = v6_map_sock_addr(inet, addr, &nsa);
28144 +       if (err)
28145 +               return err;
28146 +
28147         addr_type = ipv6_addr_type(&addr->sin6_addr);
28148         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
28149                 return -EINVAL;
28150 @@ -301,6 +312,7 @@ int inet6_bind(struct socket *sock, stru
28151                 /* Reproduce AF_INET checks to make the bindings consitant */
28152                 v4addr = addr->sin6_addr.s6_addr32[3];
28153                 chk_addr_ret = inet_addr_type(net, v4addr);
28154 +
28155                 if (!sysctl_ip_nonlocal_bind &&
28156                     !(inet->freebind || inet->transparent) &&
28157                     v4addr != htonl(INADDR_ANY) &&
28158 @@ -310,6 +322,10 @@ int inet6_bind(struct socket *sock, stru
28159                         err = -EADDRNOTAVAIL;
28160                         goto out;
28161                 }
28162 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
28163 +                       err = -EADDRNOTAVAIL;
28164 +                       goto out;
28165 +               }
28166         } else {
28167                 if (addr_type != IPV6_ADDR_ANY) {
28168                         struct net_device *dev = NULL;
28169 @@ -335,6 +351,11 @@ int inet6_bind(struct socket *sock, stru
28170                                 }
28171                         }
28172  
28173 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
28174 +                               err = -EADDRNOTAVAIL;
28175 +                               goto out;
28176 +                       }
28177 +
28178                         /* ipv4 addr of the socket is invalid.  Only the
28179                          * unspecified and mapped address have a v4 equivalent.
28180                          */
28181 @@ -353,6 +374,8 @@ int inet6_bind(struct socket *sock, stru
28182                 }
28183         }
28184  
28185 +       v6_set_sock_addr(inet, &nsa);
28186 +
28187         inet->rcv_saddr = v4addr;
28188         inet->saddr = v4addr;
28189  
28190 @@ -448,9 +471,11 @@ int inet6_getname(struct socket *sock, s
28191                         return -ENOTCONN;
28192                 sin->sin6_port = inet->dport;
28193                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
28194 +               /* FIXME: remap lback? */
28195                 if (np->sndflow)
28196                         sin->sin6_flowinfo = np->flow_label;
28197         } else {
28198 +               /* FIXME: remap lback? */
28199                 if (ipv6_addr_any(&np->rcv_saddr))
28200                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
28201                 else
28202 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/fib6_rules.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/fib6_rules.c
28203 --- linux-2.6.32.10/net/ipv6/fib6_rules.c       2009-09-10 15:26:30.000000000 +0200
28204 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/fib6_rules.c       2009-12-03 20:04:56.000000000 +0100
28205 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
28206                         if (ipv6_dev_get_saddr(net,
28207                                                ip6_dst_idev(&rt->u.dst)->dev,
28208                                                &flp->fl6_dst, srcprefs,
28209 -                                              &saddr))
28210 +                                              &saddr, NULL))
28211                                 goto again;
28212                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
28213                                                r->src.plen))
28214 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/inet6_hashtables.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/inet6_hashtables.c
28215 --- linux-2.6.32.10/net/ipv6/inet6_hashtables.c 2009-03-24 14:22:46.000000000 +0100
28216 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/inet6_hashtables.c 2009-12-03 20:04:56.000000000 +0100
28217 @@ -16,6 +16,7 @@
28218  
28219  #include <linux/module.h>
28220  #include <linux/random.h>
28221 +#include <linux/vs_inet6.h>
28222  
28223  #include <net/inet_connection_sock.h>
28224  #include <net/inet_hashtables.h>
28225 @@ -76,7 +77,6 @@ struct sock *__inet6_lookup_established(
28226         unsigned int slot = hash & (hashinfo->ehash_size - 1);
28227         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
28228  
28229 -
28230         rcu_read_lock();
28231  begin:
28232         sk_nulls_for_each_rcu(sk, node, &head->chain) {
28233 @@ -88,7 +88,7 @@ begin:
28234                                 sock_put(sk);
28235                                 goto begin;
28236                         }
28237 -               goto out;
28238 +                       goto out;
28239                 }
28240         }
28241         if (get_nulls_value(node) != slot)
28242 @@ -134,6 +134,9 @@ static int inline compute_score(struct s
28243                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28244                                 return -1;
28245                         score++;
28246 +               } else {
28247 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28248 +                               return -1;
28249                 }
28250                 if (sk->sk_bound_dev_if) {
28251                         if (sk->sk_bound_dev_if != dif)
28252 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/ip6_output.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/ip6_output.c
28253 --- linux-2.6.32.10/net/ipv6/ip6_output.c       2009-12-03 20:03:00.000000000 +0100
28254 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/ip6_output.c       2009-12-03 20:04:56.000000000 +0100
28255 @@ -934,7 +934,7 @@ static int ip6_dst_lookup_tail(struct so
28256                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
28257                                          &fl->fl6_dst,
28258                                          sk ? inet6_sk(sk)->srcprefs : 0,
28259 -                                        &fl->fl6_src);
28260 +                                        &fl->fl6_src, sk->sk_nx_info);
28261                 if (err)
28262                         goto out_err_release;
28263         }
28264 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/Kconfig linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/Kconfig
28265 --- linux-2.6.32.10/net/ipv6/Kconfig    2009-09-10 15:26:30.000000000 +0200
28266 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/Kconfig    2009-12-03 20:04:56.000000000 +0100
28267 @@ -4,8 +4,8 @@
28268  
28269  #   IPv6 as module will cause a CRASH if you try to unload it
28270  menuconfig IPV6
28271 -       tristate "The IPv6 protocol"
28272 -       default m
28273 +       bool "The IPv6 protocol"
28274 +       default n
28275         ---help---
28276           This is complemental support for the IP version 6.
28277           You will still be able to do traditional IPv4 networking as well.
28278 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/ndisc.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/ndisc.c
28279 --- linux-2.6.32.10/net/ipv6/ndisc.c    2009-12-03 20:03:00.000000000 +0100
28280 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/ndisc.c    2009-12-03 20:04:56.000000000 +0100
28281 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
28282         } else {
28283                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
28284                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
28285 -                                      &tmpaddr))
28286 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
28287                         return;
28288                 src_addr = &tmpaddr;
28289         }
28290 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/raw.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/raw.c
28291 --- linux-2.6.32.10/net/ipv6/raw.c      2009-12-03 20:03:00.000000000 +0100
28292 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/raw.c      2009-12-03 20:04:56.000000000 +0100
28293 @@ -29,6 +29,7 @@
28294  #include <linux/icmpv6.h>
28295  #include <linux/netfilter.h>
28296  #include <linux/netfilter_ipv6.h>
28297 +#include <linux/vs_inet6.h>
28298  #include <linux/skbuff.h>
28299  #include <asm/uaccess.h>
28300  #include <asm/ioctls.h>
28301 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
28302                         }
28303                 }
28304  
28305 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
28306 +                       err = -EADDRNOTAVAIL;
28307 +                       if (dev)
28308 +                               dev_put(dev);
28309 +                       goto out;
28310 +               }
28311 +
28312                 /* ipv4 addr of the socket is invalid.  Only the
28313                  * unspecified and mapped address have a v4 equivalent.
28314                  */
28315 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/route.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/route.c
28316 --- linux-2.6.32.10/net/ipv6/route.c    2009-12-03 20:03:00.000000000 +0100
28317 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/route.c    2009-12-03 20:04:56.000000000 +0100
28318 @@ -2257,7 +2257,8 @@ static int rt6_fill_node(struct net *net
28319                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
28320                 struct in6_addr saddr_buf;
28321                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
28322 -                                      dst, 0, &saddr_buf) == 0)
28323 +                       dst, 0, &saddr_buf,
28324 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
28325                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
28326         }
28327  
28328 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/tcp_ipv6.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/tcp_ipv6.c
28329 --- linux-2.6.32.10/net/ipv6/tcp_ipv6.c 2009-12-03 20:03:00.000000000 +0100
28330 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/tcp_ipv6.c 2009-12-03 20:04:56.000000000 +0100
28331 @@ -68,6 +68,7 @@
28332  
28333  #include <linux/crypto.h>
28334  #include <linux/scatterlist.h>
28335 +#include <linux/vs_inet6.h>
28336  
28337  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
28338  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
28339 @@ -156,8 +157,15 @@ static int tcp_v6_connect(struct sock *s
28340          *      connect() to INADDR_ANY means loopback (BSD'ism).
28341          */
28342  
28343 -       if(ipv6_addr_any(&usin->sin6_addr))
28344 -               usin->sin6_addr.s6_addr[15] = 0x1;
28345 +       if(ipv6_addr_any(&usin->sin6_addr)) {
28346 +               struct nx_info *nxi =  sk->sk_nx_info;
28347 +
28348 +               if (nxi && nx_info_has_v6(nxi))
28349 +                       /* FIXME: remap lback? */
28350 +                       usin->sin6_addr = nxi->v6.ip;
28351 +               else
28352 +                       usin->sin6_addr.s6_addr[15] = 0x1;
28353 +       }
28354  
28355         addr_type = ipv6_addr_type(&usin->sin6_addr);
28356  
28357 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/udp.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/udp.c
28358 --- linux-2.6.32.10/net/ipv6/udp.c      2009-12-03 20:03:00.000000000 +0100
28359 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/udp.c      2009-12-03 20:04:56.000000000 +0100
28360 @@ -47,6 +47,7 @@
28361  
28362  #include <linux/proc_fs.h>
28363  #include <linux/seq_file.h>
28364 +#include <linux/vs_inet6.h>
28365  #include "udp_impl.h"
28366  
28367  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
28368 @@ -61,24 +62,49 @@ int ipv6_rcv_saddr_equal(const struct so
28369         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
28370  
28371         /* if both are mapped, treat as IPv4 */
28372 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
28373 -               return (!sk2_ipv6only &&
28374 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
28375 +               if (!sk2_ipv6only &&
28376                         (!sk_rcv_saddr || !sk2_rcv_saddr ||
28377 -                         sk_rcv_saddr == sk2_rcv_saddr));
28378 +                         sk_rcv_saddr == sk2_rcv_saddr))
28379 +                       goto vs_v4;
28380 +               else
28381 +                       return 0;
28382 +       }
28383  
28384         if (addr_type2 == IPV6_ADDR_ANY &&
28385             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
28386 -               return 1;
28387 +               goto vs;
28388  
28389         if (addr_type == IPV6_ADDR_ANY &&
28390             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
28391 -               return 1;
28392 +               goto vs;
28393  
28394         if (sk2_rcv_saddr6 &&
28395             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
28396 -               return 1;
28397 +               goto vs;
28398  
28399         return 0;
28400 +
28401 +vs_v4:
28402 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
28403 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28404 +       if (!sk2_rcv_saddr)
28405 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
28406 +       if (!sk_rcv_saddr)
28407 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
28408 +       return 1;
28409 +vs:
28410 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
28411 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28412 +       else if (addr_type2 == IPV6_ADDR_ANY)
28413 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
28414 +       else if (addr_type == IPV6_ADDR_ANY) {
28415 +               if (addr_type2 == IPV6_ADDR_MAPPED)
28416 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28417 +               else
28418 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
28419 +       }
28420 +       return 1;
28421  }
28422  
28423  int udp_v6_get_port(struct sock *sk, unsigned short snum)
28424 @@ -109,6 +135,10 @@ static inline int compute_score(struct s
28425                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28426                                 return -1;
28427                         score++;
28428 +               } else {
28429 +                       /* block non nx_info ips */
28430 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28431 +                               return -1;
28432                 }
28433                 if (!ipv6_addr_any(&np->daddr)) {
28434                         if (!ipv6_addr_equal(&np->daddr, saddr))
28435 diff -NurpP --minimal linux-2.6.32.10/net/ipv6/xfrm6_policy.c linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/xfrm6_policy.c
28436 --- linux-2.6.32.10/net/ipv6/xfrm6_policy.c     2009-12-03 20:03:00.000000000 +0100
28437 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/ipv6/xfrm6_policy.c     2009-12-03 20:04:56.000000000 +0100
28438 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
28439         dev = ip6_dst_idev(dst)->dev;
28440         ipv6_dev_get_saddr(dev_net(dev), dev,
28441                            (struct in6_addr *)&daddr->a6, 0,
28442 -                          (struct in6_addr *)&saddr->a6);
28443 +                          (struct in6_addr *)&saddr->a6, NULL);
28444         dst_release(dst);
28445         return 0;
28446  }
28447 diff -NurpP --minimal linux-2.6.32.10/net/netlink/af_netlink.c linux-2.6.32.10-vs2.3.0.36.29.2/net/netlink/af_netlink.c
28448 --- linux-2.6.32.10/net/netlink/af_netlink.c    2009-12-03 20:03:01.000000000 +0100
28449 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/netlink/af_netlink.c    2009-12-03 20:04:56.000000000 +0100
28450 @@ -55,6 +55,9 @@
28451  #include <linux/types.h>
28452  #include <linux/audit.h>
28453  #include <linux/mutex.h>
28454 +#include <linux/vs_context.h>
28455 +#include <linux/vs_network.h>
28456 +#include <linux/vs_limit.h>
28457  
28458  #include <net/net_namespace.h>
28459  #include <net/sock.h>
28460 @@ -1899,6 +1902,8 @@ static struct sock *netlink_seq_socket_i
28461                         sk_for_each(s, node, &hash->table[j]) {
28462                                 if (sock_net(s) != seq_file_net(seq))
28463                                         continue;
28464 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28465 +                                       continue;
28466                                 if (off == pos) {
28467                                         iter->link = i;
28468                                         iter->hash_idx = j;
28469 @@ -1933,7 +1938,8 @@ static void *netlink_seq_next(struct seq
28470         s = v;
28471         do {
28472                 s = sk_next(s);
28473 -       } while (s && sock_net(s) != seq_file_net(seq));
28474 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
28475 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
28476         if (s)
28477                 return s;
28478  
28479 @@ -1945,7 +1951,8 @@ static void *netlink_seq_next(struct seq
28480  
28481                 for (; j <= hash->mask; j++) {
28482                         s = sk_head(&hash->table[j]);
28483 -                       while (s && sock_net(s) != seq_file_net(seq))
28484 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
28485 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
28486                                 s = sk_next(s);
28487                         if (s) {
28488                                 iter->link = i;
28489 diff -NurpP --minimal linux-2.6.32.10/net/sctp/ipv6.c linux-2.6.32.10-vs2.3.0.36.29.2/net/sctp/ipv6.c
28490 --- linux-2.6.32.10/net/sctp/ipv6.c     2009-12-03 20:03:01.000000000 +0100
28491 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/sctp/ipv6.c     2009-12-03 20:04:56.000000000 +0100
28492 @@ -316,7 +316,8 @@ static void sctp_v6_get_saddr(struct sct
28493                                    dst ? ip6_dst_idev(dst)->dev : NULL,
28494                                    &daddr->v6.sin6_addr,
28495                                    inet6_sk(&sk->inet.sk)->srcprefs,
28496 -                                  &saddr->v6.sin6_addr);
28497 +                                  &saddr->v6.sin6_addr,
28498 +                                  asoc->base.sk->sk_nx_info);
28499                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
28500                                   &saddr->v6.sin6_addr);
28501                 return;
28502 diff -NurpP --minimal linux-2.6.32.10/net/socket.c linux-2.6.32.10-vs2.3.0.36.29.2/net/socket.c
28503 --- linux-2.6.32.10/net/socket.c        2009-12-03 20:03:01.000000000 +0100
28504 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/socket.c        2009-12-03 20:04:56.000000000 +0100
28505 @@ -96,6 +96,10 @@
28506  
28507  #include <net/sock.h>
28508  #include <linux/netfilter.h>
28509 +#include <linux/vs_base.h>
28510 +#include <linux/vs_socket.h>
28511 +#include <linux/vs_inet.h>
28512 +#include <linux/vs_inet6.h>
28513  
28514  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
28515  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
28516 @@ -559,7 +563,7 @@ static inline int __sock_sendmsg(struct 
28517                                  struct msghdr *msg, size_t size)
28518  {
28519         struct sock_iocb *si = kiocb_to_siocb(iocb);
28520 -       int err;
28521 +       int err, len;
28522  
28523         si->sock = sock;
28524         si->scm = NULL;
28525 @@ -570,7 +574,22 @@ static inline int __sock_sendmsg(struct 
28526         if (err)
28527                 return err;
28528  
28529 -       return sock->ops->sendmsg(iocb, sock, msg, size);
28530 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
28531 +       if (sock->sk) {
28532 +               if (len == size)
28533 +                       vx_sock_send(sock->sk, size);
28534 +               else
28535 +                       vx_sock_fail(sock->sk, size);
28536 +       }
28537 +       vxdprintk(VXD_CBIT(net, 7),
28538 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28539 +               sock, sock->sk,
28540 +               (sock->sk)?sock->sk->sk_nx_info:0,
28541 +               (sock->sk)?sock->sk->sk_vx_info:0,
28542 +               (sock->sk)?sock->sk->sk_xid:0,
28543 +               (sock->sk)?sock->sk->sk_nid:0,
28544 +               (unsigned int)size, len);
28545 +       return len;
28546  }
28547  
28548  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
28549 @@ -671,7 +690,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
28550  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
28551                                  struct msghdr *msg, size_t size, int flags)
28552  {
28553 -       int err;
28554 +       int err, len;
28555         struct sock_iocb *si = kiocb_to_siocb(iocb);
28556  
28557         si->sock = sock;
28558 @@ -684,7 +703,18 @@ static inline int __sock_recvmsg(struct 
28559         if (err)
28560                 return err;
28561  
28562 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
28563 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
28564 +       if ((len >= 0) && sock->sk)
28565 +               vx_sock_recv(sock->sk, len);
28566 +       vxdprintk(VXD_CBIT(net, 7),
28567 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28568 +               sock, sock->sk,
28569 +               (sock->sk)?sock->sk->sk_nx_info:0,
28570 +               (sock->sk)?sock->sk->sk_vx_info:0,
28571 +               (sock->sk)?sock->sk->sk_xid:0,
28572 +               (sock->sk)?sock->sk->sk_nid:0,
28573 +               (unsigned int)size, len);
28574 +       return len;
28575  }
28576  
28577  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
28578 @@ -1155,6 +1185,13 @@ static int __sock_create(struct net *net
28579         if (type < 0 || type >= SOCK_MAX)
28580                 return -EINVAL;
28581  
28582 +       if (!nx_check(0, VS_ADMIN)) {
28583 +               if (family == PF_INET && !current_nx_info_has_v4())
28584 +                       return -EAFNOSUPPORT;
28585 +               if (family == PF_INET6 && !current_nx_info_has_v6())
28586 +                       return -EAFNOSUPPORT;
28587 +       }
28588 +
28589         /* Compatibility.
28590  
28591            This uglymoron is moved from INET layer to here to avoid
28592 @@ -1287,6 +1324,7 @@ SYSCALL_DEFINE3(socket, int, family, int
28593         if (retval < 0)
28594                 goto out;
28595  
28596 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
28597         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
28598         if (retval < 0)
28599                 goto out_release;
28600 @@ -1328,10 +1366,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
28601         err = sock_create(family, type, protocol, &sock1);
28602         if (err < 0)
28603                 goto out;
28604 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
28605  
28606         err = sock_create(family, type, protocol, &sock2);
28607         if (err < 0)
28608                 goto out_release_1;
28609 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
28610  
28611         err = sock1->ops->socketpair(sock1, sock2);
28612         if (err < 0)
28613 diff -NurpP --minimal linux-2.6.32.10/net/sunrpc/auth.c linux-2.6.32.10-vs2.3.0.36.29.2/net/sunrpc/auth.c
28614 --- linux-2.6.32.10/net/sunrpc/auth.c   2009-12-03 20:03:01.000000000 +0100
28615 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/sunrpc/auth.c   2009-12-03 20:04:56.000000000 +0100
28616 @@ -14,6 +14,7 @@
28617  #include <linux/hash.h>
28618  #include <linux/sunrpc/clnt.h>
28619  #include <linux/spinlock.h>
28620 +#include <linux/vs_tag.h>
28621  
28622  #ifdef RPC_DEBUG
28623  # define RPCDBG_FACILITY       RPCDBG_AUTH
28624 @@ -360,6 +361,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
28625         memset(&acred, 0, sizeof(acred));
28626         acred.uid = cred->fsuid;
28627         acred.gid = cred->fsgid;
28628 +       acred.tag = dx_current_tag();
28629         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
28630  
28631         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
28632 @@ -400,6 +402,7 @@ rpcauth_bind_root_cred(struct rpc_task *
28633         struct auth_cred acred = {
28634                 .uid = 0,
28635                 .gid = 0,
28636 +               .tag = dx_current_tag(),
28637         };
28638         struct rpc_cred *ret;
28639  
28640 diff -NurpP --minimal linux-2.6.32.10/net/sunrpc/auth_unix.c linux-2.6.32.10-vs2.3.0.36.29.2/net/sunrpc/auth_unix.c
28641 --- linux-2.6.32.10/net/sunrpc/auth_unix.c      2008-12-25 00:26:37.000000000 +0100
28642 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/sunrpc/auth_unix.c      2009-12-03 20:04:56.000000000 +0100
28643 @@ -11,12 +11,14 @@
28644  #include <linux/module.h>
28645  #include <linux/sunrpc/clnt.h>
28646  #include <linux/sunrpc/auth.h>
28647 +#include <linux/vs_tag.h>
28648  
28649  #define NFS_NGROUPS    16
28650  
28651  struct unx_cred {
28652         struct rpc_cred         uc_base;
28653         gid_t                   uc_gid;
28654 +       tag_t                   uc_tag;
28655         gid_t                   uc_gids[NFS_NGROUPS];
28656  };
28657  #define uc_uid                 uc_base.cr_uid
28658 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
28659                 groups = NFS_NGROUPS;
28660  
28661         cred->uc_gid = acred->gid;
28662 +       cred->uc_tag = acred->tag;
28663         for (i = 0; i < groups; i++)
28664                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28665         if (i < NFS_NGROUPS)
28666 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
28667         unsigned int i;
28668  
28669  
28670 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
28671 +       if (cred->uc_uid != acred->uid ||
28672 +               cred->uc_gid != acred->gid ||
28673 +               cred->uc_tag != acred->tag)
28674                 return 0;
28675  
28676         if (acred->group_info != NULL)
28677 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
28678         struct rpc_clnt *clnt = task->tk_client;
28679         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
28680         __be32          *base, *hold;
28681 -       int             i;
28682 +       int             i, tag;
28683  
28684         *p++ = htonl(RPC_AUTH_UNIX);
28685         base = p++;
28686 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
28687          * Copy the UTS nodename captured when the client was created.
28688          */
28689         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28690 +       tag = task->tk_client->cl_tag;
28691  
28692 -       *p++ = htonl((u32) cred->uc_uid);
28693 -       *p++ = htonl((u32) cred->uc_gid);
28694 +       *p++ = htonl((u32) TAGINO_UID(tag,
28695 +               cred->uc_uid, cred->uc_tag));
28696 +       *p++ = htonl((u32) TAGINO_GID(tag,
28697 +               cred->uc_gid, cred->uc_tag));
28698         hold = p++;
28699         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28700                 *p++ = htonl((u32) cred->uc_gids[i]);
28701 diff -NurpP --minimal linux-2.6.32.10/net/sunrpc/clnt.c linux-2.6.32.10-vs2.3.0.36.29.2/net/sunrpc/clnt.c
28702 --- linux-2.6.32.10/net/sunrpc/clnt.c   2009-12-03 20:03:01.000000000 +0100
28703 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/sunrpc/clnt.c   2009-12-03 20:04:56.000000000 +0100
28704 @@ -33,6 +33,7 @@
28705  #include <linux/utsname.h>
28706  #include <linux/workqueue.h>
28707  #include <linux/in6.h>
28708 +#include <linux/vs_cvirt.h>
28709  
28710  #include <linux/sunrpc/clnt.h>
28711  #include <linux/sunrpc/rpc_pipe_fs.h>
28712 @@ -358,6 +359,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28713         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
28714                 clnt->cl_chatty = 1;
28715  
28716 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28717 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28718 +               clnt->cl_tag = 1; */
28719         return clnt;
28720  }
28721  EXPORT_SYMBOL_GPL(rpc_create);
28722 diff -NurpP --minimal linux-2.6.32.10/net/unix/af_unix.c linux-2.6.32.10-vs2.3.0.36.29.2/net/unix/af_unix.c
28723 --- linux-2.6.32.10/net/unix/af_unix.c  2009-12-03 20:03:01.000000000 +0100
28724 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/unix/af_unix.c  2009-12-03 20:04:56.000000000 +0100
28725 @@ -114,6 +114,8 @@
28726  #include <linux/mount.h>
28727  #include <net/checksum.h>
28728  #include <linux/security.h>
28729 +#include <linux/vs_context.h>
28730 +#include <linux/vs_limit.h>
28731  
28732  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28733  static DEFINE_SPINLOCK(unix_table_lock);
28734 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
28735                 if (!net_eq(sock_net(s), net))
28736                         continue;
28737  
28738 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28739 +                       continue;
28740                 if (u->addr->len == len &&
28741                     !memcmp(u->addr->name, sunname, len))
28742                         goto found;
28743 @@ -2114,6 +2118,8 @@ static struct sock *unix_seq_idx(struct 
28744         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28745                 if (sock_net(s) != seq_file_net(seq))
28746                         continue;
28747 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28748 +                       continue;
28749                 if (off == pos)
28750                         return s;
28751                 ++off;
28752 @@ -2138,7 +2144,8 @@ static void *unix_seq_next(struct seq_fi
28753                 sk = first_unix_socket(&iter->i);
28754         else
28755                 sk = next_unix_socket(&iter->i, sk);
28756 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28757 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28758 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28759                 sk = next_unix_socket(&iter->i, sk);
28760         return sk;
28761  }
28762 diff -NurpP --minimal linux-2.6.32.10/net/x25/af_x25.c linux-2.6.32.10-vs2.3.0.36.29.2/net/x25/af_x25.c
28763 --- linux-2.6.32.10/net/x25/af_x25.c    2009-12-03 20:03:01.000000000 +0100
28764 +++ linux-2.6.32.10-vs2.3.0.36.29.2/net/x25/af_x25.c    2009-12-03 20:04:56.000000000 +0100
28765 @@ -519,7 +519,10 @@ static int x25_create(struct net *net, s
28766  
28767         x25 = x25_sk(sk);
28768  
28769 -       sock_init_data(sock, sk);
28770 +       sk->sk_socket = sock;
28771 +       sk->sk_type = sock->type;
28772 +       sk->sk_sleep = &sock->wait;
28773 +       sock->sk = sk;
28774  
28775         x25_init_timers(sk);
28776  
28777 diff -NurpP --minimal linux-2.6.32.10/scripts/checksyscalls.sh linux-2.6.32.10-vs2.3.0.36.29.2/scripts/checksyscalls.sh
28778 --- linux-2.6.32.10/scripts/checksyscalls.sh    2009-09-10 15:26:31.000000000 +0200
28779 +++ linux-2.6.32.10-vs2.3.0.36.29.2/scripts/checksyscalls.sh    2009-12-03 20:04:56.000000000 +0100
28780 @@ -194,7 +194,6 @@ cat << EOF
28781  #define __IGNORE_afs_syscall
28782  #define __IGNORE_getpmsg
28783  #define __IGNORE_putpmsg
28784 -#define __IGNORE_vserver
28785  EOF
28786  }
28787  
28788 diff -NurpP --minimal linux-2.6.32.10/security/commoncap.c linux-2.6.32.10-vs2.3.0.36.29.2/security/commoncap.c
28789 --- linux-2.6.32.10/security/commoncap.c        2009-12-03 20:03:02.000000000 +0100
28790 +++ linux-2.6.32.10-vs2.3.0.36.29.2/security/commoncap.c        2010-03-13 21:50:18.000000000 +0100
28791 @@ -27,6 +27,7 @@
28792  #include <linux/sched.h>
28793  #include <linux/prctl.h>
28794  #include <linux/securebits.h>
28795 +#include <linux/vs_context.h>
28796  
28797  /*
28798   * If a non-root user executes a setuid-root binary in
28799 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
28800  
28801  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28802  {
28803 -       NETLINK_CB(skb).eff_cap = current_cap();
28804 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
28805         return 0;
28806  }
28807  
28808 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
28809                 return -EPERM;
28810         return 0;
28811  }
28812 +
28813  EXPORT_SYMBOL(cap_netlink_recv);
28814  
28815  /**
28816 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
28817  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
28818                 int audit)
28819  {
28820 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
28821 +       struct vx_info *vxi = tsk->vx_info;
28822 +
28823 +#if 0
28824 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28825 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28826 +               cap_raised(tsk->cap_effective, cap),
28827 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28828 +#endif
28829 +
28830 +       /* special case SETUP */
28831 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28832 +               /* FIXME: maybe use cred instead? */
28833 +               cap_raised(tsk->cred->cap_effective, cap))
28834 +               return 0;
28835 +
28836 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
28837  }
28838  
28839  /**
28840 @@ -618,7 +635,7 @@ int cap_inode_setxattr(struct dentry *de
28841  
28842         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28843                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28844 -           !capable(CAP_SYS_ADMIN))
28845 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28846                 return -EPERM;
28847         return 0;
28848  }
28849 @@ -644,7 +661,7 @@ int cap_inode_removexattr(struct dentry 
28850  
28851         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28852                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28853 -           !capable(CAP_SYS_ADMIN))
28854 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28855                 return -EPERM;
28856         return 0;
28857  }
28858 @@ -962,7 +979,8 @@ error:
28859   */
28860  int cap_syslog(int type)
28861  {
28862 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28863 +       if ((type != 3 && type != 10) &&
28864 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28865                 return -EPERM;
28866         return 0;
28867  }
28868 diff -NurpP --minimal linux-2.6.32.10/security/selinux/hooks.c linux-2.6.32.10-vs2.3.0.36.29.2/security/selinux/hooks.c
28869 --- linux-2.6.32.10/security/selinux/hooks.c    2010-03-18 16:17:38.000000000 +0100
28870 +++ linux-2.6.32.10-vs2.3.0.36.29.2/security/selinux/hooks.c    2010-02-12 10:59:55.000000000 +0100
28871 @@ -64,7 +64,6 @@
28872  #include <linux/dccp.h>
28873  #include <linux/quota.h>
28874  #include <linux/un.h>          /* for Unix socket types */
28875 -#include <net/af_unix.h>       /* for Unix socket types */
28876  #include <linux/parser.h>
28877  #include <linux/nfs_mount.h>
28878  #include <net/ipv6.h>
28879 diff -NurpP --minimal linux-2.6.32.10/security/selinux/include/av_permissions.h linux-2.6.32.10-vs2.3.0.36.29.2/security/selinux/include/av_permissions.h
28880 --- linux-2.6.32.10/security/selinux/include/av_permissions.h   2009-12-03 20:03:02.000000000 +0100
28881 +++ linux-2.6.32.10-vs2.3.0.36.29.2/security/selinux/include/av_permissions.h   2009-12-03 20:04:56.000000000 +0100
28882 @@ -565,6 +565,7 @@
28883  #define CAPABILITY__SETFCAP                       0x80000000UL
28884  #define CAPABILITY2__MAC_OVERRIDE                 0x00000001UL
28885  #define CAPABILITY2__MAC_ADMIN                    0x00000002UL
28886 +#define CAPABILITY2__CONTEXT                      0x00000004UL
28887  #define NETLINK_ROUTE_SOCKET__IOCTL               0x00000001UL
28888  #define NETLINK_ROUTE_SOCKET__READ                0x00000002UL
28889  #define NETLINK_ROUTE_SOCKET__WRITE               0x00000004UL
28890 diff -NurpP --minimal linux-2.6.32.10/security/selinux/include/av_perm_to_string.h linux-2.6.32.10-vs2.3.0.36.29.2/security/selinux/include/av_perm_to_string.h
28891 --- linux-2.6.32.10/security/selinux/include/av_perm_to_string.h        2009-12-03 20:03:02.000000000 +0100
28892 +++ linux-2.6.32.10-vs2.3.0.36.29.2/security/selinux/include/av_perm_to_string.h        2009-12-03 20:04:56.000000000 +0100
28893 @@ -142,6 +142,7 @@
28894     S_(SECCLASS_CAPABILITY, CAPABILITY__SETFCAP, "setfcap")
28895     S_(SECCLASS_CAPABILITY2, CAPABILITY2__MAC_OVERRIDE, "mac_override")
28896     S_(SECCLASS_CAPABILITY2, CAPABILITY2__MAC_ADMIN, "mac_admin")
28897 +   S_(SECCLASS_CAPABILITY2, CAPABILITY2__CONTEXT, "context")
28898     S_(SECCLASS_NETLINK_ROUTE_SOCKET, NETLINK_ROUTE_SOCKET__NLMSG_READ, "nlmsg_read")
28899     S_(SECCLASS_NETLINK_ROUTE_SOCKET, NETLINK_ROUTE_SOCKET__NLMSG_WRITE, "nlmsg_write")
28900     S_(SECCLASS_NETLINK_FIREWALL_SOCKET, NETLINK_FIREWALL_SOCKET__NLMSG_READ, "nlmsg_read")
This page took 2.732201 seconds and 4 git commands to generate.