]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- http://vserver.13thfloor.at/Experimental/patch-2.6.32.24-vs2.3.0.36.29.6.diff
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.32.24/arch/alpha/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/alpha/Kconfig
2 --- linux-2.6.32.24/arch/alpha/Kconfig  2009-12-03 20:01:49.000000000 +0100
3 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/alpha/kernel/entry.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/alpha/kernel/entry.S
14 --- linux-2.6.32.24/arch/alpha/kernel/entry.S   2009-06-11 17:11:46.000000000 +0200
15 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/alpha/kernel/osf_sys.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.32.24/arch/alpha/kernel/osf_sys.c 2010-10-04 08:55:48.000000000 +0200
50 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/alpha/kernel/ptrace.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.32.24/arch/alpha/kernel/ptrace.c  2009-09-10 15:25:14.000000000 +0200
62 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/alpha/kernel/systbls.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/alpha/kernel/systbls.S
72 --- linux-2.6.32.24/arch/alpha/kernel/systbls.S 2009-03-24 14:18:08.000000000 +0100
73 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/alpha/kernel/traps.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/alpha/kernel/traps.c
84 --- linux-2.6.32.24/arch/alpha/kernel/traps.c   2009-06-11 17:11:46.000000000 +0200
85 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/alpha/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/alpha/mm/fault.c
97 --- linux-2.6.32.24/arch/alpha/mm/fault.c       2009-09-10 15:25:14.000000000 +0200
98 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/arm/include/asm/tlb.h linux-2.6.32.24-vs2.3.0.36.29.6/arch/arm/include/asm/tlb.h
111 --- linux-2.6.32.24/arch/arm/include/asm/tlb.h  2009-09-10 15:25:15.000000000 +0200
112 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/arm/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/arm/Kconfig
122 --- linux-2.6.32.24/arch/arm/Kconfig    2010-10-04 08:55:48.000000000 +0200
123 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/arm/Kconfig    2010-08-19 17:35:34.000000000 +0200
124 @@ -1524,6 +1524,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.24/arch/arm/kernel/calls.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/arm/kernel/calls.S
134 --- linux-2.6.32.24/arch/arm/kernel/calls.S     2010-10-04 08:55:49.000000000 +0200
135 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/arm/kernel/process.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/arm/kernel/process.c
146 --- linux-2.6.32.24/arch/arm/kernel/process.c   2009-12-03 20:01:50.000000000 +0100
147 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/arm/kernel/traps.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/arm/kernel/traps.c
159 --- linux-2.6.32.24/arch/arm/kernel/traps.c     2009-12-03 20:01:50.000000000 +0100
160 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/avr32/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/avr32/mm/fault.c
173 --- linux-2.6.32.24/arch/avr32/mm/fault.c       2009-09-10 15:25:20.000000000 +0200
174 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/cris/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/cris/Kconfig
186 --- linux-2.6.32.24/arch/cris/Kconfig   2009-06-11 17:11:56.000000000 +0200
187 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/cris/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/cris/mm/fault.c
198 --- linux-2.6.32.24/arch/cris/mm/fault.c        2009-12-03 20:01:56.000000000 +0100
199 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/frv/kernel/kernel_thread.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/frv/kernel/kernel_thread.S
211 --- linux-2.6.32.24/arch/frv/kernel/kernel_thread.S     2008-12-25 00:26:37.000000000 +0100
212 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/frv/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/frv/mm/fault.c
223 --- linux-2.6.32.24/arch/frv/mm/fault.c 2009-09-10 15:25:22.000000000 +0200
224 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/h8300/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/h8300/Kconfig
236 --- linux-2.6.32.24/arch/h8300/Kconfig  2009-03-24 14:18:24.000000000 +0100
237 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/ia64/ia32/ia32_entry.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/ia64/ia32/ia32_entry.S
248 --- linux-2.6.32.24/arch/ia64/ia32/ia32_entry.S 2009-06-11 17:11:57.000000000 +0200
249 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/ia64/include/asm/tlb.h linux-2.6.32.24-vs2.3.0.36.29.6/arch/ia64/include/asm/tlb.h
260 --- linux-2.6.32.24/arch/ia64/include/asm/tlb.h 2009-09-10 15:25:22.000000000 +0200
261 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/ia64/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/ia64/Kconfig
271 --- linux-2.6.32.24/arch/ia64/Kconfig   2009-12-03 20:01:56.000000000 +0100
272 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/ia64/kernel/entry.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/ia64/kernel/entry.S
283 --- linux-2.6.32.24/arch/ia64/kernel/entry.S    2009-09-10 15:25:22.000000000 +0200
284 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/ia64/kernel/perfmon.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/ia64/kernel/perfmon.c
295 --- linux-2.6.32.24/arch/ia64/kernel/perfmon.c  2009-09-10 15:25:22.000000000 +0200
296 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/ia64/kernel/process.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/ia64/kernel/process.c
315 --- linux-2.6.32.24/arch/ia64/kernel/process.c  2009-12-03 20:01:56.000000000 +0100
316 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/ia64/kernel/ptrace.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/ia64/kernel/ptrace.c
329 --- linux-2.6.32.24/arch/ia64/kernel/ptrace.c   2009-09-10 15:25:22.000000000 +0200
330 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/ia64/kernel/traps.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/ia64/kernel/traps.c
340 --- linux-2.6.32.24/arch/ia64/kernel/traps.c    2008-12-25 00:26:37.000000000 +0100
341 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/ia64/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/ia64/mm/fault.c
367 --- linux-2.6.32.24/arch/ia64/mm/fault.c        2009-09-10 15:25:23.000000000 +0200
368 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/m32r/kernel/traps.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/m32r/kernel/traps.c
388 --- linux-2.6.32.24/arch/m32r/kernel/traps.c    2009-12-03 20:01:57.000000000 +0100
389 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/m32r/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/m32r/mm/fault.c
403 --- linux-2.6.32.24/arch/m32r/mm/fault.c        2009-09-10 15:25:23.000000000 +0200
404 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/m68k/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/m68k/Kconfig
416 --- linux-2.6.32.24/arch/m68k/Kconfig   2009-12-03 20:01:57.000000000 +0100
417 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/m68k/kernel/ptrace.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/m68k/kernel/ptrace.c
428 --- linux-2.6.32.24/arch/m68k/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
429 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/m68k/kernel/traps.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/m68k/kernel/traps.c
448 --- linux-2.6.32.24/arch/m68k/kernel/traps.c    2009-09-10 15:25:23.000000000 +0200
449 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/m68k/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/m68k/mm/fault.c
462 --- linux-2.6.32.24/arch/m68k/mm/fault.c        2009-09-10 15:25:23.000000000 +0200
463 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/m68knommu/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/m68knommu/Kconfig
475 --- linux-2.6.32.24/arch/m68knommu/Kconfig      2009-12-03 20:01:57.000000000 +0100
476 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/m68knommu/kernel/traps.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/m68knommu/kernel/traps.c
487 --- linux-2.6.32.24/arch/m68knommu/kernel/traps.c       2009-09-10 15:25:23.000000000 +0200
488 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/microblaze/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/microblaze/mm/fault.c
502 --- linux-2.6.32.24/arch/microblaze/mm/fault.c  2009-09-10 15:25:24.000000000 +0200
503 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/mips/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/mips/Kconfig
515 --- linux-2.6.32.24/arch/mips/Kconfig   2009-12-03 20:01:58.000000000 +0100
516 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/mips/kernel/ptrace.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/mips/kernel/ptrace.c
527 --- linux-2.6.32.24/arch/mips/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
528 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/mips/kernel/scall32-o32.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/mips/kernel/scall32-o32.S
548 --- linux-2.6.32.24/arch/mips/kernel/scall32-o32.S      2009-12-03 20:01:59.000000000 +0100
549 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/mips/kernel/scall64-64.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/mips/kernel/scall64-64.S
560 --- linux-2.6.32.24/arch/mips/kernel/scall64-64.S       2009-12-03 20:01:59.000000000 +0100
561 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/mips/kernel/scall64-n32.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/mips/kernel/scall64-n32.S
572 --- linux-2.6.32.24/arch/mips/kernel/scall64-n32.S      2009-12-03 20:01:59.000000000 +0100
573 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/mips/kernel/scall64-o32.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/mips/kernel/scall64-o32.S
584 --- linux-2.6.32.24/arch/mips/kernel/scall64-o32.S      2009-12-03 20:01:59.000000000 +0100
585 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/mips/kernel/traps.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/mips/kernel/traps.c
596 --- linux-2.6.32.24/arch/mips/kernel/traps.c    2009-12-03 20:01:59.000000000 +0100
597 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/mn10300/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/mn10300/mm/fault.c
613 --- linux-2.6.32.24/arch/mn10300/mm/fault.c     2009-09-10 15:25:39.000000000 +0200
614 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/parisc/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/parisc/Kconfig
626 --- linux-2.6.32.24/arch/parisc/Kconfig 2009-12-03 20:02:00.000000000 +0100
627 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/parisc/kernel/syscall_table.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/parisc/kernel/syscall_table.S
638 --- linux-2.6.32.24/arch/parisc/kernel/syscall_table.S  2009-12-03 20:02:00.000000000 +0100
639 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/parisc/kernel/traps.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/parisc/kernel/traps.c
650 --- linux-2.6.32.24/arch/parisc/kernel/traps.c  2009-09-10 15:25:40.000000000 +0200
651 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/parisc/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/parisc/mm/fault.c
676 --- linux-2.6.32.24/arch/parisc/mm/fault.c      2009-09-10 15:25:40.000000000 +0200
677 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/powerpc/include/asm/unistd.h linux-2.6.32.24-vs2.3.0.36.29.6/arch/powerpc/include/asm/unistd.h
701 --- linux-2.6.32.24/arch/powerpc/include/asm/unistd.h   2009-12-03 20:02:01.000000000 +0100
702 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/powerpc/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/powerpc/Kconfig
713 --- linux-2.6.32.24/arch/powerpc/Kconfig        2009-12-03 20:02:00.000000000 +0100
714 +++ linux-2.6.32.24-vs2.3.0.36.29.6/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.24/arch/powerpc/kernel/process.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/powerpc/kernel/process.c
725 --- linux-2.6.32.24/arch/powerpc/kernel/process.c       2010-10-04 08:55:52.000000000 +0200
726 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/powerpc/kernel/process.c       2010-02-12 10:59:55.000000000 +0100
727 @@ -519,8 +519,9 @@ void show_regs(struct pt_regs * regs)
728  #else
729                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
730  #endif
731 -       printk("TASK = %p[%d] '%s' THREAD: %p",
732 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
733 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
734 +              current, task_pid_nr(current), current->xid,
735 +              current->comm, task_thread_info(current));
736  
737  #ifdef CONFIG_SMP
738         printk(" CPU: %d", raw_smp_processor_id());
739 diff -NurpP --minimal linux-2.6.32.24/arch/powerpc/kernel/traps.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/powerpc/kernel/traps.c
740 --- linux-2.6.32.24/arch/powerpc/kernel/traps.c 2009-09-10 15:25:41.000000000 +0200
741 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/powerpc/kernel/traps.c 2009-12-03 20:04:56.000000000 +0100
742 @@ -931,8 +931,9 @@ void nonrecoverable_exception(struct pt_
743  
744  void trace_syscall(struct pt_regs *regs)
745  {
746 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
747 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
748 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
749 +              current, task_pid_nr(current), current->xid,
750 +              regs->nip, regs->link, regs->gpr[0],
751                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
752  }
753  
754 diff -NurpP --minimal linux-2.6.32.24/arch/powerpc/kernel/vdso.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/powerpc/kernel/vdso.c
755 --- linux-2.6.32.24/arch/powerpc/kernel/vdso.c  2009-12-03 20:02:02.000000000 +0100
756 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/powerpc/kernel/vdso.c  2009-12-03 20:04:56.000000000 +0100
757 @@ -23,6 +23,7 @@
758  #include <linux/security.h>
759  #include <linux/bootmem.h>
760  #include <linux/lmb.h>
761 +#include <linux/vs_memory.h>
762  
763  #include <asm/pgtable.h>
764  #include <asm/system.h>
765 diff -NurpP --minimal linux-2.6.32.24/arch/powerpc/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/powerpc/mm/fault.c
766 --- linux-2.6.32.24/arch/powerpc/mm/fault.c     2009-12-03 20:02:02.000000000 +0100
767 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/powerpc/mm/fault.c     2009-12-03 20:04:56.000000000 +0100
768 @@ -358,7 +358,8 @@ out_of_memory:
769                 down_read(&mm->mmap_sem);
770                 goto survive;
771         }
772 -       printk("VM: killing process %s\n", current->comm);
773 +       printk("VM: killing process %s(%d:#%u)\n",
774 +               current->comm, current->pid, current->xid);
775         if (user_mode(regs))
776                 do_group_exit(SIGKILL);
777         return SIGKILL;
778 diff -NurpP --minimal linux-2.6.32.24/arch/s390/include/asm/tlb.h linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/include/asm/tlb.h
779 --- linux-2.6.32.24/arch/s390/include/asm/tlb.h 2009-09-10 15:25:43.000000000 +0200
780 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/include/asm/tlb.h 2009-12-31 14:37:21.000000000 +0100
781 @@ -23,6 +23,8 @@
782  
783  #include <linux/mm.h>
784  #include <linux/swap.h>
785 +#include <linux/vs_memory.h>
786 +
787  #include <asm/processor.h>
788  #include <asm/pgalloc.h>
789  #include <asm/smp.h>
790 diff -NurpP --minimal linux-2.6.32.24/arch/s390/include/asm/unistd.h linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/include/asm/unistd.h
791 --- linux-2.6.32.24/arch/s390/include/asm/unistd.h      2009-12-03 20:02:03.000000000 +0100
792 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/include/asm/unistd.h      2009-12-30 00:58:47.000000000 +0100
793 @@ -202,7 +202,7 @@
794  #define __NR_clock_gettime     (__NR_timer_create+6)
795  #define __NR_clock_getres      (__NR_timer_create+7)
796  #define __NR_clock_nanosleep   (__NR_timer_create+8)
797 -/* Number 263 is reserved for vserver */
798 +#define __NR_vserver           263
799  #define __NR_statfs64          265
800  #define __NR_fstatfs64         266
801  #define __NR_remap_file_pages  267
802 diff -NurpP --minimal linux-2.6.32.24/arch/s390/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/Kconfig
803 --- linux-2.6.32.24/arch/s390/Kconfig   2009-12-03 20:02:03.000000000 +0100
804 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/Kconfig   2009-12-03 20:04:56.000000000 +0100
805 @@ -616,6 +616,8 @@ source "fs/Kconfig"
806  
807  source "arch/s390/Kconfig.debug"
808  
809 +source "kernel/vserver/Kconfig"
810 +
811  source "security/Kconfig"
812  
813  source "crypto/Kconfig"
814 diff -NurpP --minimal linux-2.6.32.24/arch/s390/kernel/ptrace.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/kernel/ptrace.c
815 --- linux-2.6.32.24/arch/s390/kernel/ptrace.c   2010-10-04 08:55:53.000000000 +0200
816 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/kernel/ptrace.c   2010-05-27 19:21:36.000000000 +0200
817 @@ -36,6 +36,7 @@
818  #include <linux/regset.h>
819  #include <linux/tracehook.h>
820  #include <linux/seccomp.h>
821 +#include <linux/vs_base.h>
822  #include <trace/syscall.h>
823  #include <asm/compat.h>
824  #include <asm/segment.h>
825 diff -NurpP --minimal linux-2.6.32.24/arch/s390/kernel/syscalls.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/kernel/syscalls.S
826 --- linux-2.6.32.24/arch/s390/kernel/syscalls.S 2009-12-03 20:02:03.000000000 +0100
827 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/kernel/syscalls.S 2009-12-03 20:04:56.000000000 +0100
828 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
829  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
830  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
831  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
832 -NI_SYSCALL                                                     /* reserved for vserver */
833 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
834  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
835  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
836  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
837 diff -NurpP --minimal linux-2.6.32.24/arch/s390/lib/uaccess_pt.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/lib/uaccess_pt.c
838 --- linux-2.6.32.24/arch/s390/lib/uaccess_pt.c  2009-09-10 15:25:43.000000000 +0200
839 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/s390/lib/uaccess_pt.c  2009-12-03 20:04:56.000000000 +0100
840 @@ -90,7 +90,8 @@ out_of_memory:
841                 down_read(&mm->mmap_sem);
842                 goto survive;
843         }
844 -       printk("VM: killing process %s\n", current->comm);
845 +       printk("VM: killing process %s(%d:#%u)\n",
846 +               current->comm, task_pid_nr(current), current->xid);
847         return ret;
848  
849  out_sigbus:
850 diff -NurpP --minimal linux-2.6.32.24/arch/sh/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/sh/Kconfig
851 --- linux-2.6.32.24/arch/sh/Kconfig     2009-12-03 20:02:03.000000000 +0100
852 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/sh/Kconfig     2009-12-03 20:04:56.000000000 +0100
853 @@ -853,6 +853,8 @@ source "fs/Kconfig"
854  
855  source "arch/sh/Kconfig.debug"
856  
857 +source "kernel/vserver/Kconfig"
858 +
859  source "security/Kconfig"
860  
861  source "crypto/Kconfig"
862 diff -NurpP --minimal linux-2.6.32.24/arch/sh/kernel/irq.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/sh/kernel/irq.c
863 --- linux-2.6.32.24/arch/sh/kernel/irq.c        2009-12-03 20:02:10.000000000 +0100
864 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/sh/kernel/irq.c        2009-12-03 20:04:56.000000000 +0100
865 @@ -12,6 +12,7 @@
866  #include <linux/kernel_stat.h>
867  #include <linux/seq_file.h>
868  #include <linux/ftrace.h>
869 +// #include <linux/vs_context.h>
870  #include <asm/processor.h>
871  #include <asm/machvec.h>
872  #include <asm/uaccess.h>
873 diff -NurpP --minimal linux-2.6.32.24/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/sh/kernel/vsyscall/vsyscall.c
874 --- linux-2.6.32.24/arch/sh/kernel/vsyscall/vsyscall.c  2009-03-24 14:18:42.000000000 +0100
875 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/sh/kernel/vsyscall/vsyscall.c  2009-12-03 20:04:56.000000000 +0100
876 @@ -19,6 +19,7 @@
877  #include <linux/elf.h>
878  #include <linux/sched.h>
879  #include <linux/err.h>
880 +#include <linux/vs_memory.h>
881  
882  /*
883   * Should the kernel map a VDSO page into processes and pass its
884 diff -NurpP --minimal linux-2.6.32.24/arch/sh/mm/fault_32.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/sh/mm/fault_32.c
885 --- linux-2.6.32.24/arch/sh/mm/fault_32.c       2009-12-03 20:02:14.000000000 +0100
886 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/sh/mm/fault_32.c       2009-12-03 20:04:56.000000000 +0100
887 @@ -292,7 +292,8 @@ out_of_memory:
888                 down_read(&mm->mmap_sem);
889                 goto survive;
890         }
891 -       printk("VM: killing process %s\n", tsk->comm);
892 +       printk("VM: killing process %s(%d:#%u)\n",
893 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
894         if (user_mode(regs))
895                 do_group_exit(SIGKILL);
896         goto no_context;
897 diff -NurpP --minimal linux-2.6.32.24/arch/sh/mm/tlbflush_64.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/sh/mm/tlbflush_64.c
898 --- linux-2.6.32.24/arch/sh/mm/tlbflush_64.c    2009-12-03 20:02:14.000000000 +0100
899 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/sh/mm/tlbflush_64.c    2009-12-03 20:04:56.000000000 +0100
900 @@ -306,7 +306,8 @@ out_of_memory:
901                 down_read(&mm->mmap_sem);
902                 goto survive;
903         }
904 -       printk("VM: killing process %s\n", tsk->comm);
905 +       printk("VM: killing process %s(%d:#%u)\n",
906 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
907         if (user_mode(regs))
908                 do_group_exit(SIGKILL);
909         goto no_context;
910 diff -NurpP --minimal linux-2.6.32.24/arch/sparc/include/asm/tlb_64.h linux-2.6.32.24-vs2.3.0.36.29.6/arch/sparc/include/asm/tlb_64.h
911 --- linux-2.6.32.24/arch/sparc/include/asm/tlb_64.h     2009-09-10 15:25:45.000000000 +0200
912 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/sparc/include/asm/tlb_64.h     2009-12-03 20:04:56.000000000 +0100
913 @@ -3,6 +3,7 @@
914  
915  #include <linux/swap.h>
916  #include <linux/pagemap.h>
917 +#include <linux/vs_memory.h>
918  #include <asm/pgalloc.h>
919  #include <asm/tlbflush.h>
920  #include <asm/mmu_context.h>
921 diff -NurpP --minimal linux-2.6.32.24/arch/sparc/include/asm/unistd.h linux-2.6.32.24-vs2.3.0.36.29.6/arch/sparc/include/asm/unistd.h
922 --- linux-2.6.32.24/arch/sparc/include/asm/unistd.h     2009-12-03 20:02:15.000000000 +0100
923 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/sparc/include/asm/unistd.h     2009-12-03 20:04:56.000000000 +0100
924 @@ -335,7 +335,7 @@
925  #define __NR_timer_getoverrun  264
926  #define __NR_timer_delete      265
927  #define __NR_timer_create      266
928 -/* #define __NR_vserver                267 Reserved for VSERVER */
929 +#define __NR_vserver           267
930  #define __NR_io_setup          268
931  #define __NR_io_destroy                269
932  #define __NR_io_submit         270
933 diff -NurpP --minimal linux-2.6.32.24/arch/sparc/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/sparc/Kconfig
934 --- linux-2.6.32.24/arch/sparc/Kconfig  2009-12-03 20:02:14.000000000 +0100
935 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/sparc/Kconfig  2009-12-03 20:04:56.000000000 +0100
936 @@ -550,6 +550,8 @@ source "fs/Kconfig"
937  
938  source "arch/sparc/Kconfig.debug"
939  
940 +source "kernel/vserver/Kconfig"
941 +
942  source "security/Kconfig"
943  
944  source "crypto/Kconfig"
945 diff -NurpP --minimal linux-2.6.32.24/arch/sparc/kernel/systbls_32.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/sparc/kernel/systbls_32.S
946 --- linux-2.6.32.24/arch/sparc/kernel/systbls_32.S      2010-10-04 08:55:54.000000000 +0200
947 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/sparc/kernel/systbls_32.S      2010-01-20 04:21:33.000000000 +0100
948 @@ -70,7 +70,7 @@ sys_call_table:
949  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
950  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
951  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
952 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
953 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
954  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
955  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
956  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
957 diff -NurpP --minimal linux-2.6.32.24/arch/sparc/kernel/systbls_64.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/sparc/kernel/systbls_64.S
958 --- linux-2.6.32.24/arch/sparc/kernel/systbls_64.S      2010-10-04 08:55:54.000000000 +0200
959 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/sparc/kernel/systbls_64.S      2010-01-20 04:21:33.000000000 +0100
960 @@ -71,7 +71,7 @@ sys_call_table32:
961  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
962         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
963  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
964 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
965 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
966  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
967         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
968  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
969 @@ -146,7 +146,7 @@ sys_call_table:
970  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
971         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
972  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
973 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
974 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
975  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
976         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
977  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
978 diff -NurpP --minimal linux-2.6.32.24/arch/um/include/asm/tlb.h linux-2.6.32.24-vs2.3.0.36.29.6/arch/um/include/asm/tlb.h
979 --- linux-2.6.32.24/arch/um/include/asm/tlb.h   2009-09-10 15:25:46.000000000 +0200
980 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/um/include/asm/tlb.h   2010-03-13 21:49:04.000000000 +0100
981 @@ -3,6 +3,7 @@
982  
983  #include <linux/pagemap.h>
984  #include <linux/swap.h>
985 +#include <linux/vs_memory.h>
986  #include <asm/percpu.h>
987  #include <asm/pgalloc.h>
988  #include <asm/tlbflush.h>
989 diff -NurpP --minimal linux-2.6.32.24/arch/um/Kconfig.rest linux-2.6.32.24-vs2.3.0.36.29.6/arch/um/Kconfig.rest
990 --- linux-2.6.32.24/arch/um/Kconfig.rest        2009-06-11 17:12:19.000000000 +0200
991 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/um/Kconfig.rest        2010-03-13 21:49:04.000000000 +0100
992 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
993  
994  source "fs/Kconfig"
995  
996 +source "kernel/vserver/Kconfig"
997 +
998  source "security/Kconfig"
999  
1000  source "crypto/Kconfig"
1001 diff -NurpP --minimal linux-2.6.32.24/arch/x86/ia32/ia32entry.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/x86/ia32/ia32entry.S
1002 --- linux-2.6.32.24/arch/x86/ia32/ia32entry.S   2010-10-04 08:55:54.000000000 +0200
1003 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/x86/ia32/ia32entry.S   2010-09-22 00:48:38.000000000 +0200
1004 @@ -783,7 +783,7 @@ ia32_sys_call_table:
1005         .quad sys_tgkill                /* 270 */
1006         .quad compat_sys_utimes
1007         .quad sys32_fadvise64_64
1008 -       .quad quiet_ni_syscall  /* sys_vserver */
1009 +       .quad sys32_vserver
1010         .quad sys_mbind
1011         .quad compat_sys_get_mempolicy  /* 275 */
1012         .quad sys_set_mempolicy
1013 diff -NurpP --minimal linux-2.6.32.24/arch/x86/include/asm/unistd_64.h linux-2.6.32.24-vs2.3.0.36.29.6/arch/x86/include/asm/unistd_64.h
1014 --- linux-2.6.32.24/arch/x86/include/asm/unistd_64.h    2009-12-03 20:02:16.000000000 +0100
1015 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/x86/include/asm/unistd_64.h    2009-12-03 20:04:56.000000000 +0100
1016 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
1017  #define __NR_utimes                            235
1018  __SYSCALL(__NR_utimes, sys_utimes)
1019  #define __NR_vserver                           236
1020 -__SYSCALL(__NR_vserver, sys_ni_syscall)
1021 +__SYSCALL(__NR_vserver, sys_vserver)
1022  #define __NR_mbind                             237
1023  __SYSCALL(__NR_mbind, sys_mbind)
1024  #define __NR_set_mempolicy                     238
1025 diff -NurpP --minimal linux-2.6.32.24/arch/x86/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/arch/x86/Kconfig
1026 --- linux-2.6.32.24/arch/x86/Kconfig    2010-10-04 08:55:54.000000000 +0200
1027 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/x86/Kconfig    2010-09-05 21:24:17.000000000 +0200
1028 @@ -2089,6 +2089,8 @@ source "fs/Kconfig"
1029  
1030  source "arch/x86/Kconfig.debug"
1031  
1032 +source "kernel/vserver/Kconfig"
1033 +
1034  source "security/Kconfig"
1035  
1036  source "crypto/Kconfig"
1037 diff -NurpP --minimal linux-2.6.32.24/arch/x86/kernel/syscall_table_32.S linux-2.6.32.24-vs2.3.0.36.29.6/arch/x86/kernel/syscall_table_32.S
1038 --- linux-2.6.32.24/arch/x86/kernel/syscall_table_32.S  2010-10-04 08:55:55.000000000 +0200
1039 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/x86/kernel/syscall_table_32.S  2010-01-20 04:21:33.000000000 +0100
1040 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1041         .long sys_tgkill        /* 270 */
1042         .long sys_utimes
1043         .long sys_fadvise64_64
1044 -       .long sys_ni_syscall    /* sys_vserver */
1045 +       .long sys_vserver
1046         .long sys_mbind
1047         .long sys_get_mempolicy
1048         .long sys_set_mempolicy
1049 diff -NurpP --minimal linux-2.6.32.24/arch/xtensa/mm/fault.c linux-2.6.32.24-vs2.3.0.36.29.6/arch/xtensa/mm/fault.c
1050 --- linux-2.6.32.24/arch/xtensa/mm/fault.c      2009-09-10 15:25:48.000000000 +0200
1051 +++ linux-2.6.32.24-vs2.3.0.36.29.6/arch/xtensa/mm/fault.c      2009-12-03 20:04:56.000000000 +0100
1052 @@ -151,7 +151,8 @@ out_of_memory:
1053                 down_read(&mm->mmap_sem);
1054                 goto survive;
1055         }
1056 -       printk("VM: killing process %s\n", current->comm);
1057 +       printk("VM: killing process %s(%d:#%u)\n",
1058 +               current->comm, task_pid_nr(current), current->xid);
1059         if (user_mode(regs))
1060                 do_group_exit(SIGKILL);
1061         bad_page_fault(regs, address, SIGKILL);
1062 diff -NurpP --minimal linux-2.6.32.24/Documentation/scheduler/sched-cfs-hard-limits.txt linux-2.6.32.24-vs2.3.0.36.29.6/Documentation/scheduler/sched-cfs-hard-limits.txt
1063 --- linux-2.6.32.24/Documentation/scheduler/sched-cfs-hard-limits.txt   1970-01-01 01:00:00.000000000 +0100
1064 +++ linux-2.6.32.24-vs2.3.0.36.29.6/Documentation/scheduler/sched-cfs-hard-limits.txt   2009-12-03 20:04:56.000000000 +0100
1065 @@ -0,0 +1,48 @@
1066 +CPU HARD LIMITS FOR CFS GROUPS
1067 +==============================
1068 +
1069 +1. Overview
1070 +2. Interface
1071 +3. Examples
1072 +
1073 +1. Overview
1074 +-----------
1075 +
1076 +CFS is a proportional share scheduler which tries to divide the CPU time
1077 +proportionately between tasks or groups of tasks (task group/cgroup) depending
1078 +on the priority/weight of the task or shares assigned to groups of tasks.
1079 +In CFS, a task/task group can get more than its share of CPU if there are
1080 +enough idle CPU cycles available in the system, due to the work conserving
1081 +nature of the scheduler. However in certain scenarios (like pay-per-use),
1082 +it is desirable not to provide extra time to a group even in the presence
1083 +of idle CPU cycles. This is where hard limiting can be of use.
1084 +
1085 +Hard limits for task groups can be set by specifying how much CPU runtime a
1086 +group can consume within a given period. If the group consumes more CPU time
1087 +than the runtime in a given period, it gets throttled. None of the tasks of
1088 +the throttled group gets to run until the runtime of the group gets refreshed
1089 +at the beginning of the next period.
1090 +
1091 +2. Interface
1092 +------------
1093 +
1094 +Hard limit feature adds 2 cgroup files for CFS group scheduler:
1095 +
1096 +cfs_runtime_us: Hard limit for the group in microseconds.
1097 +
1098 +cfs_period_us: Time period in microseconds within which hard limits is
1099 +enforced.
1100 +
1101 +A group gets created with default values for runtime (infinite runtime which
1102 +means hard limits disabled) and period (0.5s). Each group can set its own
1103 +values for runtime and period independent of other groups in the system.
1104 +
1105 +3. Examples
1106 +-----------
1107 +
1108 +# mount -t cgroup -ocpu none /cgroups/
1109 +# cd /cgroups
1110 +# mkdir 1
1111 +# cd 1/
1112 +# echo 250000 > cfs_runtime_us /* set a 250ms runtime or limit */
1113 +# echo 500000 > cfs_period_us /* set a 500ms period */
1114 diff -NurpP --minimal linux-2.6.32.24/Documentation/vserver/debug.txt linux-2.6.32.24-vs2.3.0.36.29.6/Documentation/vserver/debug.txt
1115 --- linux-2.6.32.24/Documentation/vserver/debug.txt     1970-01-01 01:00:00.000000000 +0100
1116 +++ linux-2.6.32.24-vs2.3.0.36.29.6/Documentation/vserver/debug.txt     2009-12-03 20:04:56.000000000 +0100
1117 @@ -0,0 +1,154 @@
1118 +
1119 +debug_cvirt:
1120 +
1121 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
1122 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
1123 +
1124 +debug_dlim:
1125 +
1126 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
1127 +       "FREE  (%p,#%d)%c inode"
1128 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
1129 +       "FREE  (%p,#%d)%c %lld bytes"
1130 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
1131 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
1132 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
1133 +       "rcu_free_dl_info(%p)"
1134 + 4  10 "alloc_dl_info(%p,%d) = %p"
1135 +       "dealloc_dl_info(%p)"
1136 +       "get_dl_info(%p[#%d.%d])"
1137 +       "put_dl_info(%p[#%d.%d])"
1138 + 5  20 "alloc_dl_info(%p,%d)*"
1139 + 6  40 "__hash_dl_info: %p[#%d]"
1140 +       "__unhash_dl_info: %p[#%d]"
1141 + 7  80 "locate_dl_info(%p,#%d) = %p"
1142 +
1143 +debug_misc:
1144 +
1145 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
1146 +       "new_dqhash: %p [#0x%08x]"
1147 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
1148 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
1149 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
1150 +       "vroot_get_real_bdev not set"
1151 + 1   2 "cow_break_link(»%s«)"
1152 +       "temp copy Â»%s«"
1153 + 2   4 "dentry_open(new): %p"
1154 +       "dentry_open(old): %p"
1155 +       "lookup_create(new): %p"
1156 +       "old path Â»%s«"
1157 +       "path_lookup(old): %d"
1158 +       "vfs_create(new): %d"
1159 +       "vfs_rename: %d"
1160 +       "vfs_sendfile: %d"
1161 + 3   8 "fput(new_file=%p[#%d])"
1162 +       "fput(old_file=%p[#%d])"
1163 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
1164 +       "vx_info_kill(%p[#%d],%d,%d)*"
1165 + 5  20 "vs_reboot(%p[#%d],%d)"
1166 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
1167 +
1168 +debug_net:
1169 +
1170 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
1171 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
1172 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
1173 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
1174 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
1175 + 6  40 "sk,egf: %p [#%d] (from %d)"
1176 +       "sk,egn: %p [#%d] (from %d)"
1177 +       "sk,req: %p [#%d] (from %d)"
1178 +       "sk: %p [#%d] (from %d)"
1179 +       "tw: %p [#%d] (from %d)"
1180 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
1181 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
1182 +
1183 +debug_nid:
1184 +
1185 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
1186 +       "alloc_nx_info(%d) = %p"
1187 +       "create_nx_info(%d) (dynamic rejected)"
1188 +       "create_nx_info(%d) = %p (already there)"
1189 +       "create_nx_info(%d) = %p (new)"
1190 +       "dealloc_nx_info(%p)"
1191 + 1   2 "alloc_nx_info(%d)*"
1192 +       "create_nx_info(%d)*"
1193 + 2   4 "get_nx_info(%p[#%d.%d])"
1194 +       "put_nx_info(%p[#%d.%d])"
1195 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
1196 +       "clr_nx_info(%p[#%d.%d])"
1197 +       "init_nx_info(%p[#%d.%d])"
1198 +       "release_nx_info(%p[#%d.%d.%d]) %p"
1199 +       "set_nx_info(%p[#%d.%d])"
1200 + 4  10 "__hash_nx_info: %p[#%d]"
1201 +       "__nx_dynamic_id: [#%d]"
1202 +       "__unhash_nx_info: %p[#%d.%d.%d]"
1203 + 5  20 "moved task %p into nxi:%p[#%d]"
1204 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
1205 +       "task_get_nx_info(%p)"
1206 + 6  40 "nx_clear_persistent(%p[#%d])"
1207 +
1208 +debug_quota:
1209 +
1210 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
1211 + 1   2 "quota_sync_dqh(%p,%d)"
1212 +       "sync_dquots(%p,%d)"
1213 +       "sync_dquots_dqh(%p,%d)"
1214 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
1215 +
1216 +debug_switch:
1217 +
1218 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
1219 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
1220 + 4  10 "%s: (%s %s) returned %s with %d"
1221 +
1222 +debug_tag:
1223 +
1224 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
1225 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1226 +
1227 +debug_xid:
1228 +
1229 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1230 +       "alloc_vx_info(%d) = %p"
1231 +       "alloc_vx_info(%d)*"
1232 +       "create_vx_info(%d) (dynamic rejected)"
1233 +       "create_vx_info(%d) = %p (already there)"
1234 +       "create_vx_info(%d) = %p (new)"
1235 +       "dealloc_vx_info(%p)"
1236 +       "loc_vx_info(%d) = %p (found)"
1237 +       "loc_vx_info(%d) = %p (new)"
1238 +       "loc_vx_info(%d) = %p (not available)"
1239 + 1   2 "create_vx_info(%d)*"
1240 +       "loc_vx_info(%d)*"
1241 + 2   4 "get_vx_info(%p[#%d.%d])"
1242 +       "put_vx_info(%p[#%d.%d])"
1243 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1244 +       "clr_vx_info(%p[#%d.%d])"
1245 +       "init_vx_info(%p[#%d.%d])"
1246 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1247 +       "set_vx_info(%p[#%d.%d])"
1248 + 4  10 "__hash_vx_info: %p[#%d]"
1249 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1250 +       "__vx_dynamic_id: [#%d]"
1251 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1252 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1253 +       "moved task %p into vxi:%p[#%d]"
1254 +       "task_get_vx_info(%p)"
1255 +       "vx_migrate_task(%p,%p[#%d.%d])"
1256 + 6  40 "vx_clear_persistent(%p[#%d])"
1257 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1258 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1259 +       "vx_set_persistent(%p[#%d])"
1260 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1261 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1262 +
1263 +
1264 +debug_limit:
1265 +
1266 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1267 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1268 +
1269 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1270 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1271 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1272 diff -NurpP --minimal linux-2.6.32.24/drivers/block/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/drivers/block/Kconfig
1273 --- linux-2.6.32.24/drivers/block/Kconfig       2009-09-10 15:25:49.000000000 +0200
1274 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/block/Kconfig       2009-12-03 20:04:56.000000000 +0100
1275 @@ -271,6 +271,13 @@ config BLK_DEV_CRYPTOLOOP
1276           instead, which can be configured to be on-disk compatible with the
1277           cryptoloop device.
1278  
1279 +config BLK_DEV_VROOT
1280 +       tristate "Virtual Root device support"
1281 +       depends on QUOTACTL
1282 +       ---help---
1283 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1284 +         partition within a virtual server without compromising security.
1285 +
1286  config BLK_DEV_NBD
1287         tristate "Network block device support"
1288         depends on NET
1289 diff -NurpP --minimal linux-2.6.32.24/drivers/block/loop.c linux-2.6.32.24-vs2.3.0.36.29.6/drivers/block/loop.c
1290 --- linux-2.6.32.24/drivers/block/loop.c        2010-10-04 08:55:57.000000000 +0200
1291 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/block/loop.c        2010-08-19 17:35:34.000000000 +0200
1292 @@ -74,6 +74,7 @@
1293  #include <linux/gfp.h>
1294  #include <linux/kthread.h>
1295  #include <linux/splice.h>
1296 +#include <linux/vs_context.h>
1297  
1298  #include <asm/uaccess.h>
1299  
1300 @@ -814,6 +815,7 @@ static int loop_set_fd(struct loop_devic
1301         lo->lo_blocksize = lo_blocksize;
1302         lo->lo_device = bdev;
1303         lo->lo_flags = lo_flags;
1304 +       lo->lo_xid = vx_current_xid();
1305         lo->lo_backing_file = file;
1306         lo->transfer = transfer_none;
1307         lo->ioctl = NULL;
1308 @@ -939,6 +941,7 @@ static int loop_clr_fd(struct loop_devic
1309         lo->lo_encrypt_key_size = 0;
1310         lo->lo_flags = 0;
1311         lo->lo_thread = NULL;
1312 +       lo->lo_xid = 0;
1313         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1314         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1315         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1316 @@ -973,7 +976,7 @@ loop_set_status(struct loop_device *lo, 
1317  
1318         if (lo->lo_encrypt_key_size &&
1319             lo->lo_key_owner != uid &&
1320 -           !capable(CAP_SYS_ADMIN))
1321 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1322                 return -EPERM;
1323         if (lo->lo_state != Lo_bound)
1324                 return -ENXIO;
1325 @@ -1057,7 +1060,8 @@ loop_get_status(struct loop_device *lo, 
1326         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1327         info->lo_encrypt_type =
1328                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1329 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1330 +       if (lo->lo_encrypt_key_size &&
1331 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1332                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1333                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1334                        lo->lo_encrypt_key_size);
1335 @@ -1401,6 +1405,9 @@ static int lo_open(struct block_device *
1336  {
1337         struct loop_device *lo = bdev->bd_disk->private_data;
1338  
1339 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1340 +               return -EACCES;
1341 +
1342         mutex_lock(&lo->lo_ctl_mutex);
1343         lo->lo_refcnt++;
1344         mutex_unlock(&lo->lo_ctl_mutex);
1345 diff -NurpP --minimal linux-2.6.32.24/drivers/block/Makefile linux-2.6.32.24-vs2.3.0.36.29.6/drivers/block/Makefile
1346 --- linux-2.6.32.24/drivers/block/Makefile      2009-09-10 15:25:49.000000000 +0200
1347 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/block/Makefile      2009-12-03 20:04:56.000000000 +0100
1348 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1349  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1350  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1351  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1352 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1353  
1354  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1355  
1356 diff -NurpP --minimal linux-2.6.32.24/drivers/block/vroot.c linux-2.6.32.24-vs2.3.0.36.29.6/drivers/block/vroot.c
1357 --- linux-2.6.32.24/drivers/block/vroot.c       1970-01-01 01:00:00.000000000 +0100
1358 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/block/vroot.c       2009-12-03 20:04:56.000000000 +0100
1359 @@ -0,0 +1,281 @@
1360 +/*
1361 + *  linux/drivers/block/vroot.c
1362 + *
1363 + *  written by Herbert Pötzl, 9/11/2002
1364 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1365 + *
1366 + *  based on the loop.c code by Theodore Ts'o.
1367 + *
1368 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1369 + * Redistribution of this file is permitted under the
1370 + * GNU General Public License.
1371 + *
1372 + */
1373 +
1374 +#include <linux/module.h>
1375 +#include <linux/moduleparam.h>
1376 +#include <linux/file.h>
1377 +#include <linux/major.h>
1378 +#include <linux/blkdev.h>
1379 +
1380 +#include <linux/vroot.h>
1381 +#include <linux/vs_context.h>
1382 +
1383 +
1384 +static int max_vroot = 8;
1385 +
1386 +static struct vroot_device *vroot_dev;
1387 +static struct gendisk **disks;
1388 +
1389 +
1390 +static int vroot_set_dev(
1391 +       struct vroot_device *vr,
1392 +       struct block_device *bdev,
1393 +       unsigned int arg)
1394 +{
1395 +       struct block_device *real_bdev;
1396 +       struct file *file;
1397 +       struct inode *inode;
1398 +       int error;
1399 +
1400 +       error = -EBUSY;
1401 +       if (vr->vr_state != Vr_unbound)
1402 +               goto out;
1403 +
1404 +       error = -EBADF;
1405 +       file = fget(arg);
1406 +       if (!file)
1407 +               goto out;
1408 +
1409 +       error = -EINVAL;
1410 +       inode = file->f_dentry->d_inode;
1411 +
1412 +
1413 +       if (S_ISBLK(inode->i_mode)) {
1414 +               real_bdev = inode->i_bdev;
1415 +               vr->vr_device = real_bdev;
1416 +               __iget(real_bdev->bd_inode);
1417 +       } else
1418 +               goto out_fput;
1419 +
1420 +       vxdprintk(VXD_CBIT(misc, 0),
1421 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1422 +               vr->vr_number, VXD_DEV(real_bdev));
1423 +
1424 +       vr->vr_state = Vr_bound;
1425 +       error = 0;
1426 +
1427 + out_fput:
1428 +       fput(file);
1429 + out:
1430 +       return error;
1431 +}
1432 +
1433 +static int vroot_clr_dev(
1434 +       struct vroot_device *vr,
1435 +       struct block_device *bdev)
1436 +{
1437 +       struct block_device *real_bdev;
1438 +
1439 +       if (vr->vr_state != Vr_bound)
1440 +               return -ENXIO;
1441 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1442 +               return -EBUSY;
1443 +
1444 +       real_bdev = vr->vr_device;
1445 +
1446 +       vxdprintk(VXD_CBIT(misc, 0),
1447 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1448 +               vr->vr_number, VXD_DEV(real_bdev));
1449 +
1450 +       bdput(real_bdev);
1451 +       vr->vr_state = Vr_unbound;
1452 +       vr->vr_device = NULL;
1453 +       return 0;
1454 +}
1455 +
1456 +
1457 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1458 +       unsigned int cmd, unsigned long arg)
1459 +{
1460 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1461 +       int err;
1462 +
1463 +       down(&vr->vr_ctl_mutex);
1464 +       switch (cmd) {
1465 +       case VROOT_SET_DEV:
1466 +               err = vroot_set_dev(vr, bdev, arg);
1467 +               break;
1468 +       case VROOT_CLR_DEV:
1469 +               err = vroot_clr_dev(vr, bdev);
1470 +               break;
1471 +       default:
1472 +               err = -EINVAL;
1473 +               break;
1474 +       }
1475 +       up(&vr->vr_ctl_mutex);
1476 +       return err;
1477 +}
1478 +
1479 +static int vr_open(struct block_device *bdev, fmode_t mode)
1480 +{
1481 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1482 +
1483 +       down(&vr->vr_ctl_mutex);
1484 +       vr->vr_refcnt++;
1485 +       up(&vr->vr_ctl_mutex);
1486 +       return 0;
1487 +}
1488 +
1489 +static int vr_release(struct gendisk *disk, fmode_t mode)
1490 +{
1491 +       struct vroot_device *vr = disk->private_data;
1492 +
1493 +       down(&vr->vr_ctl_mutex);
1494 +       --vr->vr_refcnt;
1495 +       up(&vr->vr_ctl_mutex);
1496 +       return 0;
1497 +}
1498 +
1499 +static struct block_device_operations vr_fops = {
1500 +       .owner =        THIS_MODULE,
1501 +       .open =         vr_open,
1502 +       .release =      vr_release,
1503 +       .ioctl =        vr_ioctl,
1504 +};
1505 +
1506 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1507 +{
1508 +       struct inode *inode = bdev->bd_inode;
1509 +       struct vroot_device *vr;
1510 +       struct block_device *real_bdev;
1511 +       int minor = iminor(inode);
1512 +
1513 +       vr = &vroot_dev[minor];
1514 +       real_bdev = vr->vr_device;
1515 +
1516 +       vxdprintk(VXD_CBIT(misc, 0),
1517 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1518 +               vr->vr_number, VXD_DEV(real_bdev));
1519 +
1520 +       if (vr->vr_state != Vr_bound)
1521 +               return ERR_PTR(-ENXIO);
1522 +
1523 +       __iget(real_bdev->bd_inode);
1524 +       return real_bdev;
1525 +}
1526 +
1527 +/*
1528 + * And now the modules code and kernel interface.
1529 + */
1530 +
1531 +module_param(max_vroot, int, 0);
1532 +
1533 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1534 +MODULE_LICENSE("GPL");
1535 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1536 +
1537 +MODULE_AUTHOR ("Herbert Pötzl");
1538 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1539 +
1540 +
1541 +int __init vroot_init(void)
1542 +{
1543 +       int err, i;
1544 +
1545 +       if (max_vroot < 1 || max_vroot > 256) {
1546 +               max_vroot = MAX_VROOT_DEFAULT;
1547 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1548 +                       "(must be between 1 and 256), "
1549 +                       "using default (%d)\n", max_vroot);
1550 +       }
1551 +
1552 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1553 +               return -EIO;
1554 +
1555 +       err = -ENOMEM;
1556 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1557 +       if (!vroot_dev)
1558 +               goto out_mem1;
1559 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1560 +
1561 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1562 +       if (!disks)
1563 +               goto out_mem2;
1564 +
1565 +       for (i = 0; i < max_vroot; i++) {
1566 +               disks[i] = alloc_disk(1);
1567 +               if (!disks[i])
1568 +                       goto out_mem3;
1569 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1570 +               if (!disks[i]->queue)
1571 +                       goto out_mem3;
1572 +       }
1573 +
1574 +       for (i = 0; i < max_vroot; i++) {
1575 +               struct vroot_device *vr = &vroot_dev[i];
1576 +               struct gendisk *disk = disks[i];
1577 +
1578 +               memset(vr, 0, sizeof(*vr));
1579 +               init_MUTEX(&vr->vr_ctl_mutex);
1580 +               vr->vr_number = i;
1581 +               disk->major = VROOT_MAJOR;
1582 +               disk->first_minor = i;
1583 +               disk->fops = &vr_fops;
1584 +               sprintf(disk->disk_name, "vroot%d", i);
1585 +               disk->private_data = vr;
1586 +       }
1587 +
1588 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1589 +       if (err)
1590 +               goto out_mem3;
1591 +
1592 +       for (i = 0; i < max_vroot; i++)
1593 +               add_disk(disks[i]);
1594 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1595 +       return 0;
1596 +
1597 +out_mem3:
1598 +       while (i--)
1599 +               put_disk(disks[i]);
1600 +       kfree(disks);
1601 +out_mem2:
1602 +       kfree(vroot_dev);
1603 +out_mem1:
1604 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1605 +       printk(KERN_ERR "vroot: ran out of memory\n");
1606 +       return err;
1607 +}
1608 +
1609 +void vroot_exit(void)
1610 +{
1611 +       int i;
1612 +
1613 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1614 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1615 +
1616 +       for (i = 0; i < max_vroot; i++) {
1617 +               del_gendisk(disks[i]);
1618 +               put_disk(disks[i]);
1619 +       }
1620 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1621 +
1622 +       kfree(disks);
1623 +       kfree(vroot_dev);
1624 +}
1625 +
1626 +module_init(vroot_init);
1627 +module_exit(vroot_exit);
1628 +
1629 +#ifndef MODULE
1630 +
1631 +static int __init max_vroot_setup(char *str)
1632 +{
1633 +       max_vroot = simple_strtol(str, NULL, 0);
1634 +       return 1;
1635 +}
1636 +
1637 +__setup("max_vroot=", max_vroot_setup);
1638 +
1639 +#endif
1640 +
1641 diff -NurpP --minimal linux-2.6.32.24/drivers/char/sysrq.c linux-2.6.32.24-vs2.3.0.36.29.6/drivers/char/sysrq.c
1642 --- linux-2.6.32.24/drivers/char/sysrq.c        2009-12-03 20:02:20.000000000 +0100
1643 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/char/sysrq.c        2009-12-03 20:04:56.000000000 +0100
1644 @@ -38,6 +38,7 @@
1645  #include <linux/workqueue.h>
1646  #include <linux/hrtimer.h>
1647  #include <linux/oom.h>
1648 +#include <linux/vserver/debug.h>
1649  
1650  #include <asm/ptrace.h>
1651  #include <asm/irq_regs.h>
1652 @@ -391,6 +392,21 @@ static struct sysrq_key_op sysrq_unrt_op
1653         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1654  };
1655  
1656 +
1657 +#ifdef CONFIG_VSERVER_DEBUG
1658 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1659 +{
1660 +       dump_vx_info_inactive((key == 'x')?0:1);
1661 +}
1662 +
1663 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1664 +       .handler        = sysrq_handle_vxinfo,
1665 +       .help_msg       = "conteXt",
1666 +       .action_msg     = "Show Context Info",
1667 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1668 +};
1669 +#endif
1670 +
1671  /* Key Operations table and lock */
1672  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1673  
1674 @@ -445,7 +461,11 @@ static struct sysrq_key_op *sysrq_key_ta
1675         NULL,                           /* v */
1676         &sysrq_showstate_blocked_op,    /* w */
1677         /* x: May be registered on ppc/powerpc for xmon */
1678 +#ifdef CONFIG_VSERVER_DEBUG
1679 +       &sysrq_showvxinfo_op,           /* x */
1680 +#else
1681         NULL,                           /* x */
1682 +#endif
1683         /* y: May be registered on sparc64 for global register dump */
1684         NULL,                           /* y */
1685         &sysrq_ftrace_dump_op,          /* z */
1686 @@ -460,6 +480,8 @@ static int sysrq_key_table_key2index(int
1687                 retval = key - '0';
1688         else if ((key >= 'a') && (key <= 'z'))
1689                 retval = key + 10 - 'a';
1690 +       else if ((key >= 'A') && (key <= 'Z'))
1691 +               retval = key + 10 - 'A';
1692         else
1693                 retval = -1;
1694         return retval;
1695 diff -NurpP --minimal linux-2.6.32.24/drivers/char/tty_io.c linux-2.6.32.24-vs2.3.0.36.29.6/drivers/char/tty_io.c
1696 --- linux-2.6.32.24/drivers/char/tty_io.c       2010-10-04 08:55:58.000000000 +0200
1697 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/char/tty_io.c       2010-08-19 17:41:20.000000000 +0200
1698 @@ -106,6 +106,7 @@
1699  
1700  #include <linux/kmod.h>
1701  #include <linux/nsproxy.h>
1702 +#include <linux/vs_pid.h>
1703  
1704  #undef TTY_DEBUG_HANGUP
1705  
1706 @@ -1970,7 +1971,8 @@ static int tiocsti(struct tty_struct *tt
1707         char ch, mbz = 0;
1708         struct tty_ldisc *ld;
1709  
1710 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1711 +       if (((current->signal->tty != tty) &&
1712 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1713                 return -EPERM;
1714         if (get_user(ch, p))
1715                 return -EFAULT;
1716 @@ -2258,6 +2260,7 @@ static int tiocspgrp(struct tty_struct *
1717                 return -ENOTTY;
1718         if (get_user(pgrp_nr, p))
1719                 return -EFAULT;
1720 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1721         if (pgrp_nr < 0)
1722                 return -EINVAL;
1723         rcu_read_lock();
1724 diff -NurpP --minimal linux-2.6.32.24/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.32.24-vs2.3.0.36.29.6/drivers/infiniband/hw/ipath/ipath_user_pages.c
1725 --- linux-2.6.32.24/drivers/infiniband/hw/ipath/ipath_user_pages.c      2009-12-03 20:02:23.000000000 +0100
1726 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/infiniband/hw/ipath/ipath_user_pages.c      2009-12-04 23:31:17.000000000 +0100
1727 @@ -34,6 +34,7 @@
1728  #include <linux/mm.h>
1729  #include <linux/device.h>
1730  #include <linux/sched.h>
1731 +#include <linux/vs_memory.h>
1732  
1733  #include "ipath_kernel.h"
1734  
1735 @@ -62,7 +63,8 @@ static int __get_user_pages(unsigned lon
1736         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1737                 PAGE_SHIFT;
1738  
1739 -       if (num_pages > lock_limit) {
1740 +       if (num_pages > lock_limit ||
1741 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1742                 ret = -ENOMEM;
1743                 goto bail;
1744         }
1745 @@ -79,7 +81,7 @@ static int __get_user_pages(unsigned lon
1746                         goto bail_release;
1747         }
1748  
1749 -       current->mm->locked_vm += num_pages;
1750 +       vx_vmlocked_add(current->mm, num_pages);
1751  
1752         ret = 0;
1753         goto bail;
1754 @@ -178,7 +180,7 @@ void ipath_release_user_pages(struct pag
1755  
1756         __ipath_release_user_pages(p, num_pages, 1);
1757  
1758 -       current->mm->locked_vm -= num_pages;
1759 +       vx_vmlocked_sub(current->mm, num_pages);
1760  
1761         up_write(&current->mm->mmap_sem);
1762  }
1763 @@ -195,7 +197,7 @@ static void user_pages_account(struct wo
1764                 container_of(_work, struct ipath_user_pages_work, work);
1765  
1766         down_write(&work->mm->mmap_sem);
1767 -       work->mm->locked_vm -= work->num_pages;
1768 +       vx_vmlocked_sub(work->mm, work->num_pages);
1769         up_write(&work->mm->mmap_sem);
1770         mmput(work->mm);
1771         kfree(work);
1772 diff -NurpP --minimal linux-2.6.32.24/drivers/md/dm.c linux-2.6.32.24-vs2.3.0.36.29.6/drivers/md/dm.c
1773 --- linux-2.6.32.24/drivers/md/dm.c     2010-10-04 08:56:01.000000000 +0200
1774 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/md/dm.c     2010-04-28 10:19:30.000000000 +0200
1775 @@ -19,6 +19,7 @@
1776  #include <linux/slab.h>
1777  #include <linux/idr.h>
1778  #include <linux/hdreg.h>
1779 +#include <linux/vs_base.h>
1780  
1781  #include <trace/events/block.h>
1782  
1783 @@ -119,6 +120,7 @@ struct mapped_device {
1784         rwlock_t map_lock;
1785         atomic_t holders;
1786         atomic_t open_count;
1787 +       xid_t xid;
1788  
1789         unsigned long flags;
1790  
1791 @@ -323,6 +325,7 @@ static void __exit dm_exit(void)
1792  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1793  {
1794         struct mapped_device *md;
1795 +       int ret = -ENXIO;
1796  
1797         spin_lock(&_minor_lock);
1798  
1799 @@ -331,18 +334,19 @@ static int dm_blk_open(struct block_devi
1800                 goto out;
1801  
1802         if (test_bit(DMF_FREEING, &md->flags) ||
1803 -           test_bit(DMF_DELETING, &md->flags)) {
1804 -               md = NULL;
1805 +           test_bit(DMF_DELETING, &md->flags))
1806 +               goto out;
1807 +
1808 +       ret = -EACCES;
1809 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1810                 goto out;
1811 -       }
1812  
1813         dm_get(md);
1814         atomic_inc(&md->open_count);
1815 -
1816 +       ret = 0;
1817  out:
1818         spin_unlock(&_minor_lock);
1819 -
1820 -       return md ? 0 : -ENXIO;
1821 +       return ret;
1822  }
1823  
1824  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1825 @@ -553,6 +557,14 @@ int dm_set_geometry(struct mapped_device
1826         return 0;
1827  }
1828  
1829 +/*
1830 + * Get the xid associated with a dm device
1831 + */
1832 +xid_t dm_get_xid(struct mapped_device *md)
1833 +{
1834 +       return md->xid;
1835 +}
1836 +
1837  /*-----------------------------------------------------------------
1838   * CRUD START:
1839   *   A more elegant soln is in the works that uses the queue
1840 @@ -1775,6 +1787,7 @@ static struct mapped_device *alloc_dev(i
1841         INIT_LIST_HEAD(&md->uevent_list);
1842         spin_lock_init(&md->uevent_lock);
1843  
1844 +       md->xid = vx_current_xid();
1845         md->queue = blk_init_queue(dm_request_fn, NULL);
1846         if (!md->queue)
1847                 goto bad_queue;
1848 diff -NurpP --minimal linux-2.6.32.24/drivers/md/dm.h linux-2.6.32.24-vs2.3.0.36.29.6/drivers/md/dm.h
1849 --- linux-2.6.32.24/drivers/md/dm.h     2009-09-10 15:25:55.000000000 +0200
1850 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/md/dm.h     2009-12-03 20:04:56.000000000 +0100
1851 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1852  struct dm_table;
1853  struct dm_md_mempools;
1854  
1855 +xid_t dm_get_xid(struct mapped_device *md);
1856 +
1857  /*-----------------------------------------------------------------
1858   * Internal table functions.
1859   *---------------------------------------------------------------*/
1860 diff -NurpP --minimal linux-2.6.32.24/drivers/md/dm-ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/drivers/md/dm-ioctl.c
1861 --- linux-2.6.32.24/drivers/md/dm-ioctl.c       2010-10-04 08:56:01.000000000 +0200
1862 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/md/dm-ioctl.c       2010-09-05 21:24:17.000000000 +0200
1863 @@ -16,6 +16,7 @@
1864  #include <linux/dm-ioctl.h>
1865  #include <linux/hdreg.h>
1866  #include <linux/compat.h>
1867 +#include <linux/vs_context.h>
1868  
1869  #include <asm/uaccess.h>
1870  
1871 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1872         unsigned int h = hash_str(str);
1873  
1874         list_for_each_entry (hc, _name_buckets + h, name_list)
1875 -               if (!strcmp(hc->name, str)) {
1876 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1877 +                       !strcmp(hc->name, str)) {
1878                         dm_get(hc->md);
1879                         return hc;
1880                 }
1881 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1882         unsigned int h = hash_str(str);
1883  
1884         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1885 -               if (!strcmp(hc->uuid, str)) {
1886 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1887 +                       !strcmp(hc->uuid, str)) {
1888                         dm_get(hc->md);
1889                         return hc;
1890                 }
1891 @@ -369,6 +372,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1892  
1893  static int remove_all(struct dm_ioctl *param, size_t param_size)
1894  {
1895 +       if (!vx_check(0, VS_ADMIN))
1896 +               return -EPERM;
1897 +
1898         dm_hash_remove_all(1);
1899         param->data_size = 0;
1900         return 0;
1901 @@ -416,6 +422,8 @@ static int list_devices(struct dm_ioctl 
1902          */
1903         for (i = 0; i < NUM_BUCKETS; i++) {
1904                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1905 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1906 +                               continue;
1907                         needed += sizeof(struct dm_name_list);
1908                         needed += strlen(hc->name) + 1;
1909                         needed += ALIGN_MASK;
1910 @@ -439,6 +447,8 @@ static int list_devices(struct dm_ioctl 
1911          */
1912         for (i = 0; i < NUM_BUCKETS; i++) {
1913                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1914 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1915 +                               continue;
1916                         if (old_nl)
1917                                 old_nl->next = (uint32_t) ((void *) nl -
1918                                                            (void *) old_nl);
1919 @@ -629,10 +639,11 @@ static struct hash_cell *__find_device_h
1920         if (!md)
1921                 goto out;
1922  
1923 -       mdptr = dm_get_mdptr(md);
1924 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1925 +               mdptr = dm_get_mdptr(md);
1926 +
1927         if (!mdptr)
1928                 dm_put(md);
1929 -
1930  out:
1931         return mdptr;
1932  }
1933 @@ -1462,8 +1473,8 @@ static int ctl_ioctl(uint command, struc
1934         ioctl_fn fn = NULL;
1935         size_t param_size;
1936  
1937 -       /* only root can play with this */
1938 -       if (!capable(CAP_SYS_ADMIN))
1939 +       /* only root and certain contexts can play with this */
1940 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1941                 return -EACCES;
1942  
1943         if (_IOC_TYPE(command) != DM_IOCTL)
1944 diff -NurpP --minimal linux-2.6.32.24/drivers/net/tun.c linux-2.6.32.24-vs2.3.0.36.29.6/drivers/net/tun.c
1945 --- linux-2.6.32.24/drivers/net/tun.c   2010-10-04 08:56:04.000000000 +0200
1946 +++ linux-2.6.32.24-vs2.3.0.36.29.6/drivers/net/tun.c   2010-09-22 00:48:38.000000000 +0200
1947 @@ -61,6 +61,7 @@
1948  #include <linux/crc32.h>
1949  #include <linux/nsproxy.h>
1950  #include <linux/virtio_net.h>
1951 +#include <linux/vs_network.h>
1952  #include <net/net_namespace.h>
1953  #include <net/netns/generic.h>
1954  #include <net/rtnetlink.h>
1955 @@ -102,6 +103,7 @@ struct tun_struct {
1956         unsigned int            flags;
1957         uid_t                   owner;
1958         gid_t                   group;
1959 +       nid_t                   nid;
1960  
1961         struct net_device       *dev;
1962         struct fasync_struct    *fasync;
1963 @@ -816,6 +818,7 @@ static void tun_setup(struct net_device 
1964  
1965         tun->owner = -1;
1966         tun->group = -1;
1967 +       tun->nid = current->nid;
1968  
1969         dev->ethtool_ops = &tun_ethtool_ops;
1970         dev->destructor = tun_free_netdev;
1971 @@ -932,7 +935,7 @@ static int tun_set_iff(struct net *net, 
1972  
1973                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1974                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1975 -                   !capable(CAP_NET_ADMIN))
1976 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1977                         return -EPERM;
1978                 err = security_tun_dev_attach(tun->socket.sk);
1979                 if (err < 0)
1980 @@ -946,7 +949,7 @@ static int tun_set_iff(struct net *net, 
1981                 char *name;
1982                 unsigned long flags = 0;
1983  
1984 -               if (!capable(CAP_NET_ADMIN))
1985 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1986                         return -EPERM;
1987                 err = security_tun_dev_create();
1988                 if (err < 0)
1989 @@ -1014,6 +1017,9 @@ static int tun_set_iff(struct net *net, 
1990  
1991                 sk->sk_destruct = tun_sock_destruct;
1992  
1993 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1994 +                       return -EPERM;
1995 +
1996                 err = tun_attach(tun, file);
1997                 if (err < 0)
1998                         goto failed;
1999 @@ -1203,6 +1209,16 @@ static long tun_chr_ioctl(struct file *f
2000                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
2001                 break;
2002  
2003 +       case TUNSETNID:
2004 +               if (!capable(CAP_CONTEXT))
2005 +                       return -EPERM;
2006 +
2007 +               /* Set nid owner of the device */
2008 +               tun->nid = (nid_t) arg;
2009 +
2010 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
2011 +               break;
2012 +
2013         case TUNSETLINK:
2014                 /* Only allow setting the type when the interface is down */
2015                 if (tun->dev->flags & IFF_UP) {
2016 diff -NurpP --minimal linux-2.6.32.24/fs/attr.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/attr.c
2017 --- linux-2.6.32.24/fs/attr.c   2009-12-03 20:02:51.000000000 +0100
2018 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/attr.c   2009-12-03 20:04:56.000000000 +0100
2019 @@ -14,6 +14,9 @@
2020  #include <linux/fcntl.h>
2021  #include <linux/quotaops.h>
2022  #include <linux/security.h>
2023 +#include <linux/proc_fs.h>
2024 +#include <linux/devpts_fs.h>
2025 +#include <linux/vs_tag.h>
2026  
2027  /* Taken over from the old code... */
2028  
2029 @@ -55,6 +58,10 @@ int inode_change_ok(const struct inode *
2030                 if (!is_owner_or_cap(inode))
2031                         goto error;
2032         }
2033 +
2034 +       if (dx_permission(inode, MAY_WRITE))
2035 +               goto error;
2036 +
2037  fine:
2038         retval = 0;
2039  error:
2040 @@ -120,6 +127,8 @@ int inode_setattr(struct inode * inode, 
2041                 inode->i_uid = attr->ia_uid;
2042         if (ia_valid & ATTR_GID)
2043                 inode->i_gid = attr->ia_gid;
2044 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2045 +               inode->i_tag = attr->ia_tag;
2046         if (ia_valid & ATTR_ATIME)
2047                 inode->i_atime = timespec_trunc(attr->ia_atime,
2048                                                 inode->i_sb->s_time_gran);
2049 @@ -214,7 +223,8 @@ int notify_change(struct dentry * dentry
2050                 error = inode_change_ok(inode, attr);
2051                 if (!error) {
2052                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2053 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2054 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2055 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2056                                 error = vfs_dq_transfer(inode, attr) ?
2057                                         -EDQUOT : 0;
2058                         if (!error)
2059 diff -NurpP --minimal linux-2.6.32.24/fs/binfmt_aout.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/binfmt_aout.c
2060 --- linux-2.6.32.24/fs/binfmt_aout.c    2010-10-04 08:56:11.000000000 +0200
2061 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/binfmt_aout.c    2010-02-12 10:59:55.000000000 +0100
2062 @@ -24,6 +24,7 @@
2063  #include <linux/binfmts.h>
2064  #include <linux/personality.h>
2065  #include <linux/init.h>
2066 +#include <linux/vs_memory.h>
2067  
2068  #include <asm/system.h>
2069  #include <asm/uaccess.h>
2070 diff -NurpP --minimal linux-2.6.32.24/fs/binfmt_elf.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/binfmt_elf.c
2071 --- linux-2.6.32.24/fs/binfmt_elf.c     2010-10-04 08:56:11.000000000 +0200
2072 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/binfmt_elf.c     2010-02-12 10:59:55.000000000 +0100
2073 @@ -31,6 +31,7 @@
2074  #include <linux/random.h>
2075  #include <linux/elf.h>
2076  #include <linux/utsname.h>
2077 +#include <linux/vs_memory.h>
2078  #include <asm/uaccess.h>
2079  #include <asm/param.h>
2080  #include <asm/page.h>
2081 diff -NurpP --minimal linux-2.6.32.24/fs/binfmt_flat.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/binfmt_flat.c
2082 --- linux-2.6.32.24/fs/binfmt_flat.c    2010-10-04 08:56:11.000000000 +0200
2083 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/binfmt_flat.c    2010-02-12 10:59:55.000000000 +0100
2084 @@ -35,6 +35,7 @@
2085  #include <linux/init.h>
2086  #include <linux/flat.h>
2087  #include <linux/syscalls.h>
2088 +#include <linux/vs_memory.h>
2089  
2090  #include <asm/byteorder.h>
2091  #include <asm/system.h>
2092 diff -NurpP --minimal linux-2.6.32.24/fs/binfmt_som.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/binfmt_som.c
2093 --- linux-2.6.32.24/fs/binfmt_som.c     2010-10-04 08:56:11.000000000 +0200
2094 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/binfmt_som.c     2010-02-12 10:59:55.000000000 +0100
2095 @@ -28,6 +28,7 @@
2096  #include <linux/shm.h>
2097  #include <linux/personality.h>
2098  #include <linux/init.h>
2099 +#include <linux/vs_memory.h>
2100  
2101  #include <asm/uaccess.h>
2102  #include <asm/pgtable.h>
2103 diff -NurpP --minimal linux-2.6.32.24/fs/block_dev.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/block_dev.c
2104 --- linux-2.6.32.24/fs/block_dev.c      2010-10-04 08:56:11.000000000 +0200
2105 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/block_dev.c      2010-08-19 17:35:34.000000000 +0200
2106 @@ -26,6 +26,7 @@
2107  #include <linux/namei.h>
2108  #include <linux/log2.h>
2109  #include <linux/kmemleak.h>
2110 +#include <linux/vs_device.h>
2111  #include <asm/uaccess.h>
2112  #include "internal.h"
2113  
2114 @@ -557,6 +558,7 @@ struct block_device *bdget(dev_t dev)
2115                 bdev->bd_invalidated = 0;
2116                 inode->i_mode = S_IFBLK;
2117                 inode->i_rdev = dev;
2118 +               inode->i_mdev = dev;
2119                 inode->i_bdev = bdev;
2120                 inode->i_data.a_ops = &def_blk_aops;
2121                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2122 @@ -603,6 +605,11 @@ EXPORT_SYMBOL(bdput);
2123  static struct block_device *bd_acquire(struct inode *inode)
2124  {
2125         struct block_device *bdev;
2126 +       dev_t mdev;
2127 +
2128 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2129 +               return NULL;
2130 +       inode->i_mdev = mdev;
2131  
2132         spin_lock(&bdev_lock);
2133         bdev = inode->i_bdev;
2134 @@ -613,7 +620,7 @@ static struct block_device *bd_acquire(s
2135         }
2136         spin_unlock(&bdev_lock);
2137  
2138 -       bdev = bdget(inode->i_rdev);
2139 +       bdev = bdget(mdev);
2140         if (bdev) {
2141                 spin_lock(&bdev_lock);
2142                 if (!inode->i_bdev) {
2143 diff -NurpP --minimal linux-2.6.32.24/fs/btrfs/ctree.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/btrfs/ctree.h
2144 --- linux-2.6.32.24/fs/btrfs/ctree.h    2010-10-04 08:56:11.000000000 +0200
2145 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/btrfs/ctree.h    2010-08-19 17:35:34.000000000 +0200
2146 @@ -547,11 +547,14 @@ struct btrfs_inode_item {
2147         /* modification sequence number for NFS */
2148         __le64 sequence;
2149  
2150 +       __le16 tag;
2151         /*
2152          * a little future expansion, for more than this we can
2153          * just grow the inode item and version it
2154          */
2155 -       __le64 reserved[4];
2156 +       __le16 reserved16;
2157 +       __le32 reserved32;
2158 +       __le64 reserved[3];
2159         struct btrfs_timespec atime;
2160         struct btrfs_timespec ctime;
2161         struct btrfs_timespec mtime;
2162 @@ -1162,6 +1165,8 @@ struct btrfs_root {
2163  #define BTRFS_MOUNT_NOSSD              (1 << 9)
2164  #define BTRFS_MOUNT_DISCARD            (1 << 10)
2165  
2166 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2167 +
2168  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2169  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2170  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2171 @@ -1181,6 +1186,10 @@ struct btrfs_root {
2172  #define BTRFS_INODE_NOATIME            (1 << 9)
2173  #define BTRFS_INODE_DIRSYNC            (1 << 10)
2174  
2175 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2176 +#define BTRFS_INODE_BARRIER            (1 << 25)
2177 +#define BTRFS_INODE_COW                        (1 << 26)
2178 +
2179  
2180  /* some macros to generate set/get funcs for the struct fields.  This
2181   * assumes there is a lefoo_to_cpu for every type, so lets make a simple
2182 @@ -1383,6 +1392,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2183  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2184  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2185  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2186 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2187  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2188  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2189  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2190 @@ -2356,6 +2366,7 @@ extern const struct dentry_operations bt
2191  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2192  void btrfs_update_iflags(struct inode *inode);
2193  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2194 +int btrfs_sync_flags(struct inode *inode, int, int);
2195  
2196  /* file.c */
2197  int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync);
2198 diff -NurpP --minimal linux-2.6.32.24/fs/btrfs/disk-io.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/btrfs/disk-io.c
2199 --- linux-2.6.32.24/fs/btrfs/disk-io.c  2010-10-04 08:56:11.000000000 +0200
2200 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/btrfs/disk-io.c  2010-08-19 17:35:34.000000000 +0200
2201 @@ -1726,6 +1726,9 @@ struct btrfs_root *open_ctree(struct sup
2202                 goto fail_iput;
2203         }
2204  
2205 +       if (btrfs_test_opt(tree_root, TAGGED))
2206 +               sb->s_flags |= MS_TAGGED;
2207 +
2208         features = btrfs_super_incompat_flags(disk_super) &
2209                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2210         if (features) {
2211 diff -NurpP --minimal linux-2.6.32.24/fs/btrfs/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/btrfs/inode.c
2212 --- linux-2.6.32.24/fs/btrfs/inode.c    2010-10-04 08:56:11.000000000 +0200
2213 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/btrfs/inode.c    2010-08-19 17:35:34.000000000 +0200
2214 @@ -36,6 +36,8 @@
2215  #include <linux/xattr.h>
2216  #include <linux/posix_acl.h>
2217  #include <linux/falloc.h>
2218 +#include <linux/vs_tag.h>
2219 +
2220  #include "compat.h"
2221  #include "ctree.h"
2222  #include "disk-io.h"
2223 @@ -2263,6 +2265,8 @@ static void btrfs_read_locked_inode(stru
2224         int maybe_acls;
2225         u64 alloc_group_block;
2226         u32 rdev;
2227 +       uid_t uid;
2228 +       gid_t gid;
2229         int ret;
2230  
2231         path = btrfs_alloc_path();
2232 @@ -2279,8 +2283,13 @@ static void btrfs_read_locked_inode(stru
2233  
2234         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2235         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2236 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2237 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2238 +
2239 +       uid = btrfs_inode_uid(leaf, inode_item);
2240 +       gid = btrfs_inode_gid(leaf, inode_item);
2241 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2242 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2243 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2244 +               btrfs_inode_tag(leaf, inode_item));
2245         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2246  
2247         tspec = btrfs_inode_atime(inode_item);
2248 @@ -2362,8 +2371,15 @@ static void fill_inode_item(struct btrfs
2249                             struct btrfs_inode_item *item,
2250                             struct inode *inode)
2251  {
2252 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2253 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2254 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2255 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2256 +
2257 +       btrfs_set_inode_uid(leaf, item, uid);
2258 +       btrfs_set_inode_gid(leaf, item, gid);
2259 +#ifdef CONFIG_TAGGING_INTERN
2260 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2261 +#endif
2262 +
2263         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2264         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2265         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2266 @@ -4153,6 +4169,7 @@ static struct inode *btrfs_new_inode(str
2267         } else
2268                 inode->i_gid = current_fsgid();
2269  
2270 +       inode->i_tag = dx_current_fstag(root->fs_info->sb);
2271         inode->i_mode = mode;
2272         inode->i_ino = objectid;
2273         inode_set_bytes(inode, 0);
2274 @@ -5954,6 +5971,7 @@ static const struct inode_operations btr
2275         .listxattr      = btrfs_listxattr,
2276         .removexattr    = btrfs_removexattr,
2277         .permission     = btrfs_permission,
2278 +       .sync_flags     = btrfs_sync_flags,
2279  };
2280  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2281         .lookup         = btrfs_lookup,
2282 @@ -6029,6 +6047,7 @@ static const struct inode_operations btr
2283         .permission     = btrfs_permission,
2284         .fallocate      = btrfs_fallocate,
2285         .fiemap         = btrfs_fiemap,
2286 +       .sync_flags     = btrfs_sync_flags,
2287  };
2288  static const struct inode_operations btrfs_special_inode_operations = {
2289         .getattr        = btrfs_getattr,
2290 diff -NurpP --minimal linux-2.6.32.24/fs/btrfs/ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/btrfs/ioctl.c
2291 --- linux-2.6.32.24/fs/btrfs/ioctl.c    2010-10-04 08:56:11.000000000 +0200
2292 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/btrfs/ioctl.c    2010-08-19 17:35:34.000000000 +0200
2293 @@ -67,10 +67,13 @@ static unsigned int btrfs_flags_to_ioctl
2294  {
2295         unsigned int iflags = 0;
2296  
2297 -       if (flags & BTRFS_INODE_SYNC)
2298 -               iflags |= FS_SYNC_FL;
2299         if (flags & BTRFS_INODE_IMMUTABLE)
2300                 iflags |= FS_IMMUTABLE_FL;
2301 +       if (flags & BTRFS_INODE_IXUNLINK)
2302 +               iflags |= FS_IXUNLINK_FL;
2303 +
2304 +       if (flags & BTRFS_INODE_SYNC)
2305 +               iflags |= FS_SYNC_FL;
2306         if (flags & BTRFS_INODE_APPEND)
2307                 iflags |= FS_APPEND_FL;
2308         if (flags & BTRFS_INODE_NODUMP)
2309 @@ -80,28 +83,78 @@ static unsigned int btrfs_flags_to_ioctl
2310         if (flags & BTRFS_INODE_DIRSYNC)
2311                 iflags |= FS_DIRSYNC_FL;
2312  
2313 +       if (flags & BTRFS_INODE_BARRIER)
2314 +               iflags |= FS_BARRIER_FL;
2315 +       if (flags & BTRFS_INODE_COW)
2316 +               iflags |= FS_COW_FL;
2317         return iflags;
2318  }
2319  
2320  /*
2321 - * Update inode->i_flags based on the btrfs internal flags.
2322 + * Update inode->i_(v)flags based on the btrfs internal flags.
2323   */
2324  void btrfs_update_iflags(struct inode *inode)
2325  {
2326         struct btrfs_inode *ip = BTRFS_I(inode);
2327  
2328 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2329 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2330 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2331  
2332 -       if (ip->flags & BTRFS_INODE_SYNC)
2333 -               inode->i_flags |= S_SYNC;
2334         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2335                 inode->i_flags |= S_IMMUTABLE;
2336 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2337 +               inode->i_flags |= S_IXUNLINK;
2338 +
2339 +       if (ip->flags & BTRFS_INODE_SYNC)
2340 +               inode->i_flags |= S_SYNC;
2341         if (ip->flags & BTRFS_INODE_APPEND)
2342                 inode->i_flags |= S_APPEND;
2343         if (ip->flags & BTRFS_INODE_NOATIME)
2344                 inode->i_flags |= S_NOATIME;
2345         if (ip->flags & BTRFS_INODE_DIRSYNC)
2346                 inode->i_flags |= S_DIRSYNC;
2347 +
2348 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2349 +
2350 +       if (ip->flags & BTRFS_INODE_BARRIER)
2351 +               inode->i_vflags |= V_BARRIER;
2352 +       if (ip->flags & BTRFS_INODE_COW)
2353 +               inode->i_vflags |= V_COW;
2354 +}
2355 +
2356 +/*
2357 + * Update btrfs internal flags from inode->i_(v)flags.
2358 + */
2359 +void btrfs_update_flags(struct inode *inode)
2360 +{
2361 +       struct btrfs_inode *ip = BTRFS_I(inode);
2362 +
2363 +       unsigned int flags = inode->i_flags;
2364 +       unsigned int vflags = inode->i_vflags;
2365 +
2366 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2367 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2368 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2369 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2370 +
2371 +       if (flags & S_IMMUTABLE)
2372 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2373 +       if (flags & S_IXUNLINK)
2374 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2375 +
2376 +       if (flags & S_SYNC)
2377 +               ip->flags |= BTRFS_INODE_SYNC;
2378 +       if (flags & S_APPEND)
2379 +               ip->flags |= BTRFS_INODE_APPEND;
2380 +       if (flags & S_NOATIME)
2381 +               ip->flags |= BTRFS_INODE_NOATIME;
2382 +       if (flags & S_DIRSYNC)
2383 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2384 +
2385 +       if (vflags & V_BARRIER)
2386 +               ip->flags |= BTRFS_INODE_BARRIER;
2387 +       if (vflags & V_COW)
2388 +               ip->flags |= BTRFS_INODE_COW;
2389  }
2390  
2391  /*
2392 @@ -119,7 +172,7 @@ void btrfs_inherit_iflags(struct inode *
2393         flags = BTRFS_I(dir)->flags;
2394  
2395         if (S_ISREG(inode->i_mode))
2396 -               flags &= ~BTRFS_INODE_DIRSYNC;
2397 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2398         else if (!S_ISDIR(inode->i_mode))
2399                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2400  
2401 @@ -127,6 +180,30 @@ void btrfs_inherit_iflags(struct inode *
2402         btrfs_update_iflags(inode);
2403  }
2404  
2405 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2406 +{
2407 +       struct btrfs_inode *ip = BTRFS_I(inode);
2408 +       struct btrfs_root *root = ip->root;
2409 +       struct btrfs_trans_handle *trans;
2410 +       int ret;
2411 +
2412 +       trans = btrfs_join_transaction(root, 1);
2413 +       BUG_ON(!trans);
2414 +
2415 +       inode->i_flags = flags;
2416 +       inode->i_vflags = vflags;
2417 +       btrfs_update_flags(inode);
2418 +
2419 +       ret = btrfs_update_inode(trans, root, inode);
2420 +       BUG_ON(ret);
2421 +
2422 +       btrfs_update_iflags(inode);
2423 +       inode->i_ctime = CURRENT_TIME;
2424 +       btrfs_end_transaction(trans, root);
2425 +
2426 +       return 0;
2427 +}
2428 +
2429  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2430  {
2431         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2432 @@ -149,6 +226,7 @@ static int btrfs_ioctl_setflags(struct f
2433         if (copy_from_user(&flags, arg, sizeof(flags)))
2434                 return -EFAULT;
2435  
2436 +       /* maybe add FS_IXUNLINK_FL ? */
2437         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2438                       FS_NOATIME_FL | FS_NODUMP_FL | \
2439                       FS_SYNC_FL | FS_DIRSYNC_FL))
2440 @@ -161,7 +239,8 @@ static int btrfs_ioctl_setflags(struct f
2441  
2442         flags = btrfs_mask_flags(inode->i_mode, flags);
2443         oldflags = btrfs_flags_to_ioctl(ip->flags);
2444 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2445 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2446 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2447                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2448                         ret = -EPERM;
2449                         goto out_unlock;
2450 @@ -172,14 +251,19 @@ static int btrfs_ioctl_setflags(struct f
2451         if (ret)
2452                 goto out_unlock;
2453  
2454 -       if (flags & FS_SYNC_FL)
2455 -               ip->flags |= BTRFS_INODE_SYNC;
2456 -       else
2457 -               ip->flags &= ~BTRFS_INODE_SYNC;
2458         if (flags & FS_IMMUTABLE_FL)
2459                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2460         else
2461                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2462 +       if (flags & FS_IXUNLINK_FL)
2463 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2464 +       else
2465 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2466 +
2467 +       if (flags & FS_SYNC_FL)
2468 +               ip->flags |= BTRFS_INODE_SYNC;
2469 +       else
2470 +               ip->flags &= ~BTRFS_INODE_SYNC;
2471         if (flags & FS_APPEND_FL)
2472                 ip->flags |= BTRFS_INODE_APPEND;
2473         else
2474 diff -NurpP --minimal linux-2.6.32.24/fs/btrfs/super.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/btrfs/super.c
2475 --- linux-2.6.32.24/fs/btrfs/super.c    2010-10-04 08:56:12.000000000 +0200
2476 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/btrfs/super.c    2010-08-19 17:38:42.000000000 +0200
2477 @@ -67,7 +67,7 @@ enum {
2478         Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier,
2479         Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl,
2480         Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
2481 -       Opt_discard, Opt_err,
2482 +       Opt_tag, Opt_notag, Opt_tagid, Opt_discard, Opt_err,
2483  };
2484  
2485  static match_table_t tokens = {
2486 @@ -90,6 +90,9 @@ static match_table_t tokens = {
2487         {Opt_flushoncommit, "flushoncommit"},
2488         {Opt_ratio, "metadata_ratio=%d"},
2489         {Opt_discard, "discard"},
2490 +       {Opt_tag, "tag"},
2491 +       {Opt_notag, "notag"},
2492 +       {Opt_tagid, "tagid=%u"},
2493         {Opt_err, NULL},
2494  };
2495  
2496 @@ -264,6 +267,22 @@ int btrfs_parse_options(struct btrfs_roo
2497                 case Opt_discard:
2498                         btrfs_set_opt(info->mount_opt, DISCARD);
2499                         break;
2500 +#ifndef CONFIG_TAGGING_NONE
2501 +               case Opt_tag:
2502 +                       printk(KERN_INFO "btrfs: use tagging\n");
2503 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2504 +                       break;
2505 +               case Opt_notag:
2506 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2507 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2508 +                       break;
2509 +#endif
2510 +#ifdef CONFIG_PROPAGATE
2511 +               case Opt_tagid:
2512 +                       /* use args[0] */
2513 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2514 +                       break;
2515 +#endif
2516                 case Opt_err:
2517                         printk(KERN_INFO "btrfs: unrecognized mount option "
2518                                "'%s'\n", p);
2519 @@ -585,6 +604,12 @@ static int btrfs_remount(struct super_bl
2520         if (ret)
2521                 return -EINVAL;
2522  
2523 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2524 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2525 +                       sb->s_id);
2526 +               return -EINVAL;
2527 +       }
2528 +
2529         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2530                 return 0;
2531  
2532 diff -NurpP --minimal linux-2.6.32.24/fs/char_dev.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/char_dev.c
2533 --- linux-2.6.32.24/fs/char_dev.c       2010-10-04 08:56:12.000000000 +0200
2534 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/char_dev.c       2010-10-04 10:04:57.000000000 +0200
2535 @@ -20,6 +20,8 @@
2536  #include <linux/cdev.h>
2537  #include <linux/mutex.h>
2538  #include <linux/backing-dev.h>
2539 +#include <linux/vs_context.h>
2540 +#include <linux/vs_device.h>
2541  
2542  #include "internal.h"
2543  
2544 @@ -370,14 +372,21 @@ static int chrdev_open(struct inode *ino
2545         struct cdev *p;
2546         struct cdev *new = NULL;
2547         int ret = 0;
2548 +       dev_t mdev;
2549 +
2550 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2551 +               return -EPERM;
2552 +       inode->i_mdev = mdev;
2553  
2554         spin_lock(&cdev_lock);
2555         p = inode->i_cdev;
2556         if (!p) {
2557                 struct kobject *kobj;
2558                 int idx;
2559 +
2560                 spin_unlock(&cdev_lock);
2561 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2562 +
2563 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2564                 if (!kobj)
2565                         return -ENXIO;
2566                 new = container_of(kobj, struct cdev, kobj);
2567 diff -NurpP --minimal linux-2.6.32.24/fs/dcache.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/dcache.c
2568 --- linux-2.6.32.24/fs/dcache.c 2009-12-03 20:02:51.000000000 +0100
2569 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/dcache.c 2009-12-03 20:04:56.000000000 +0100
2570 @@ -33,6 +33,7 @@
2571  #include <linux/bootmem.h>
2572  #include <linux/fs_struct.h>
2573  #include <linux/hardirq.h>
2574 +#include <linux/vs_limit.h>
2575  #include "internal.h"
2576  
2577  int sysctl_vfs_cache_pressure __read_mostly = 100;
2578 @@ -230,6 +231,8 @@ repeat:
2579                 return;
2580         }
2581  
2582 +       vx_dentry_dec(dentry);
2583 +
2584         /*
2585          * AV: ->d_delete() is _NOT_ allowed to block now.
2586          */
2587 @@ -321,6 +324,7 @@ static inline struct dentry * __dget_loc
2588  {
2589         atomic_inc(&dentry->d_count);
2590         dentry_lru_del_init(dentry);
2591 +       vx_dentry_inc(dentry);
2592         return dentry;
2593  }
2594  
2595 @@ -919,6 +923,9 @@ struct dentry *d_alloc(struct dentry * p
2596         struct dentry *dentry;
2597         char *dname;
2598  
2599 +       if (!vx_dentry_avail(1))
2600 +               return NULL;
2601 +
2602         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2603         if (!dentry)
2604                 return NULL;
2605 @@ -964,6 +971,7 @@ struct dentry *d_alloc(struct dentry * p
2606         if (parent)
2607                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2608         dentry_stat.nr_dentry++;
2609 +       vx_dentry_inc(dentry);
2610         spin_unlock(&dcache_lock);
2611  
2612         return dentry;
2613 @@ -1407,6 +1415,7 @@ struct dentry * __d_lookup(struct dentry
2614                 }
2615  
2616                 atomic_inc(&dentry->d_count);
2617 +               vx_dentry_inc(dentry);
2618                 found = dentry;
2619                 spin_unlock(&dentry->d_lock);
2620                 break;
2621 diff -NurpP --minimal linux-2.6.32.24/fs/devpts/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/devpts/inode.c
2622 --- linux-2.6.32.24/fs/devpts/inode.c   2010-10-04 08:56:12.000000000 +0200
2623 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/devpts/inode.c   2009-12-29 00:36:26.000000000 +0100
2624 @@ -24,6 +24,7 @@
2625  #include <linux/parser.h>
2626  #include <linux/fsnotify.h>
2627  #include <linux/seq_file.h>
2628 +#include <linux/vs_base.h>
2629  
2630  #define DEVPTS_DEFAULT_MODE 0600
2631  /*
2632 @@ -35,6 +36,20 @@
2633  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2634  #define PTMX_MINOR     2
2635  
2636 +static int devpts_permission(struct inode *inode, int mask)
2637 +{
2638 +       int ret = -EACCES;
2639 +
2640 +       /* devpts is xid tagged */
2641 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2642 +               ret = generic_permission(inode, mask, NULL);
2643 +       return ret;
2644 +}
2645 +
2646 +static struct inode_operations devpts_file_inode_operations = {
2647 +       .permission     = devpts_permission,
2648 +};
2649 +
2650  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2651  static DEFINE_MUTEX(allocated_ptys_lock);
2652  
2653 @@ -262,6 +277,25 @@ static int devpts_show_options(struct se
2654         return 0;
2655  }
2656  
2657 +static int devpts_filter(struct dentry *de)
2658 +{
2659 +       /* devpts is xid tagged */
2660 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2661 +}
2662 +
2663 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2664 +{
2665 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2666 +}
2667 +
2668 +static struct file_operations devpts_dir_operations = {
2669 +       .open           = dcache_dir_open,
2670 +       .release        = dcache_dir_close,
2671 +       .llseek         = dcache_dir_lseek,
2672 +       .read           = generic_read_dir,
2673 +       .readdir        = devpts_readdir,
2674 +};
2675 +
2676  static const struct super_operations devpts_sops = {
2677         .statfs         = simple_statfs,
2678         .remount_fs     = devpts_remount,
2679 @@ -301,12 +335,15 @@ devpts_fill_super(struct super_block *s,
2680         inode = new_inode(s);
2681         if (!inode)
2682                 goto free_fsi;
2683 +
2684         inode->i_ino = 1;
2685         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2686         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2687         inode->i_op = &simple_dir_inode_operations;
2688 -       inode->i_fop = &simple_dir_operations;
2689 +       inode->i_fop = &devpts_dir_operations;
2690         inode->i_nlink = 2;
2691 +       /* devpts is xid tagged */
2692 +       inode->i_tag = (tag_t)vx_current_xid();
2693  
2694         s->s_root = d_alloc_root(inode);
2695         if (s->s_root)
2696 @@ -497,6 +534,9 @@ int devpts_pty_new(struct inode *ptmx_in
2697         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2698         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2699         init_special_inode(inode, S_IFCHR|opts->mode, device);
2700 +       /* devpts is xid tagged */
2701 +       inode->i_tag = (tag_t)vx_current_xid();
2702 +       inode->i_op = &devpts_file_inode_operations;
2703         inode->i_private = tty;
2704         tty->driver_data = inode;
2705  
2706 diff -NurpP --minimal linux-2.6.32.24/fs/exec.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/exec.c
2707 --- linux-2.6.32.24/fs/exec.c   2010-10-04 08:56:12.000000000 +0200
2708 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/exec.c   2010-05-27 19:21:36.000000000 +0200
2709 @@ -251,7 +251,9 @@ static int __bprm_mm_init(struct linux_b
2710         if (err)
2711                 goto err;
2712  
2713 -       mm->stack_vm = mm->total_vm = 1;
2714 +       mm->total_vm = 0;
2715 +       vx_vmpages_inc(mm);
2716 +       mm->stack_vm = 1;
2717         up_write(&mm->mmap_sem);
2718         bprm->p = vma->vm_end - sizeof(void *);
2719         return 0;
2720 @@ -1494,7 +1496,7 @@ static int format_corename(char *corenam
2721                         /* UNIX time of coredump */
2722                         case 't': {
2723                                 struct timeval tv;
2724 -                               do_gettimeofday(&tv);
2725 +                               vx_gettimeofday(&tv);
2726                                 rc = snprintf(out_ptr, out_end - out_ptr,
2727                                               "%lu", tv.tv_sec);
2728                                 if (rc > out_end - out_ptr)
2729 diff -NurpP --minimal linux-2.6.32.24/fs/ext2/balloc.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/balloc.c
2730 --- linux-2.6.32.24/fs/ext2/balloc.c    2009-06-11 17:13:03.000000000 +0200
2731 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/balloc.c    2009-12-03 20:04:56.000000000 +0100
2732 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2733                         start = 0;
2734                 end = EXT2_BLOCKS_PER_GROUP(sb);
2735         }
2736 -
2737         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2738  
2739  repeat:
2740 diff -NurpP --minimal linux-2.6.32.24/fs/ext2/ext2.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/ext2.h
2741 --- linux-2.6.32.24/fs/ext2/ext2.h      2009-09-10 15:26:21.000000000 +0200
2742 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/ext2.h      2009-12-03 20:04:56.000000000 +0100
2743 @@ -131,6 +131,7 @@ extern int ext2_fiemap(struct inode *ino
2744  int __ext2_write_begin(struct file *file, struct address_space *mapping,
2745                 loff_t pos, unsigned len, unsigned flags,
2746                 struct page **pagep, void **fsdata);
2747 +extern int ext2_sync_flags(struct inode *, int, int);
2748  
2749  /* ioctl.c */
2750  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2751 diff -NurpP --minimal linux-2.6.32.24/fs/ext2/file.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/file.c
2752 --- linux-2.6.32.24/fs/ext2/file.c      2009-12-03 20:02:51.000000000 +0100
2753 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/file.c      2009-12-03 20:04:56.000000000 +0100
2754 @@ -87,4 +87,5 @@ const struct inode_operations ext2_file_
2755         .setattr        = ext2_setattr,
2756         .check_acl      = ext2_check_acl,
2757         .fiemap         = ext2_fiemap,
2758 +       .sync_flags     = ext2_sync_flags,
2759  };
2760 diff -NurpP --minimal linux-2.6.32.24/fs/ext2/ialloc.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/ialloc.c
2761 --- linux-2.6.32.24/fs/ext2/ialloc.c    2009-06-11 17:13:03.000000000 +0200
2762 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/ialloc.c    2009-12-03 20:04:56.000000000 +0100
2763 @@ -17,6 +17,7 @@
2764  #include <linux/backing-dev.h>
2765  #include <linux/buffer_head.h>
2766  #include <linux/random.h>
2767 +#include <linux/vs_tag.h>
2768  #include "ext2.h"
2769  #include "xattr.h"
2770  #include "acl.h"
2771 @@ -560,6 +561,7 @@ got:
2772         } else
2773                 inode->i_gid = current_fsgid();
2774         inode->i_mode = mode;
2775 +       inode->i_tag = dx_current_fstag(sb);
2776  
2777         inode->i_ino = ino;
2778         inode->i_blocks = 0;
2779 diff -NurpP --minimal linux-2.6.32.24/fs/ext2/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/inode.c
2780 --- linux-2.6.32.24/fs/ext2/inode.c     2009-12-03 20:02:51.000000000 +0100
2781 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/inode.c     2009-12-03 20:04:56.000000000 +0100
2782 @@ -33,6 +33,7 @@
2783  #include <linux/mpage.h>
2784  #include <linux/fiemap.h>
2785  #include <linux/namei.h>
2786 +#include <linux/vs_tag.h>
2787  #include "ext2.h"
2788  #include "acl.h"
2789  #include "xip.h"
2790 @@ -1040,7 +1041,7 @@ void ext2_truncate(struct inode *inode)
2791                 return;
2792         if (ext2_inode_is_fast_symlink(inode))
2793                 return;
2794 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2795 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2796                 return;
2797  
2798         blocksize = inode->i_sb->s_blocksize;
2799 @@ -1178,36 +1179,61 @@ void ext2_set_inode_flags(struct inode *
2800  {
2801         unsigned int flags = EXT2_I(inode)->i_flags;
2802  
2803 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2804 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2805 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2806 +
2807 +
2808 +       if (flags & EXT2_IMMUTABLE_FL)
2809 +               inode->i_flags |= S_IMMUTABLE;
2810 +       if (flags & EXT2_IXUNLINK_FL)
2811 +               inode->i_flags |= S_IXUNLINK;
2812 +
2813         if (flags & EXT2_SYNC_FL)
2814                 inode->i_flags |= S_SYNC;
2815         if (flags & EXT2_APPEND_FL)
2816                 inode->i_flags |= S_APPEND;
2817 -       if (flags & EXT2_IMMUTABLE_FL)
2818 -               inode->i_flags |= S_IMMUTABLE;
2819         if (flags & EXT2_NOATIME_FL)
2820                 inode->i_flags |= S_NOATIME;
2821         if (flags & EXT2_DIRSYNC_FL)
2822                 inode->i_flags |= S_DIRSYNC;
2823 +
2824 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2825 +
2826 +       if (flags & EXT2_BARRIER_FL)
2827 +               inode->i_vflags |= V_BARRIER;
2828 +       if (flags & EXT2_COW_FL)
2829 +               inode->i_vflags |= V_COW;
2830  }
2831  
2832  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2833  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2834  {
2835         unsigned int flags = ei->vfs_inode.i_flags;
2836 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2837 +
2838 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2839 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2840 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2841 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2842 +
2843 +       if (flags & S_IMMUTABLE)
2844 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2845 +       if (flags & S_IXUNLINK)
2846 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2847  
2848 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2849 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2850         if (flags & S_SYNC)
2851                 ei->i_flags |= EXT2_SYNC_FL;
2852         if (flags & S_APPEND)
2853                 ei->i_flags |= EXT2_APPEND_FL;
2854 -       if (flags & S_IMMUTABLE)
2855 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2856         if (flags & S_NOATIME)
2857                 ei->i_flags |= EXT2_NOATIME_FL;
2858         if (flags & S_DIRSYNC)
2859                 ei->i_flags |= EXT2_DIRSYNC_FL;
2860 +
2861 +       if (vflags & V_BARRIER)
2862 +               ei->i_flags |= EXT2_BARRIER_FL;
2863 +       if (vflags & V_COW)
2864 +               ei->i_flags |= EXT2_COW_FL;
2865  }
2866  
2867  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2868 @@ -1217,6 +1243,8 @@ struct inode *ext2_iget (struct super_bl
2869         struct ext2_inode *raw_inode;
2870         struct inode *inode;
2871         long ret = -EIO;
2872 +       uid_t uid;
2873 +       gid_t gid;
2874         int n;
2875  
2876         inode = iget_locked(sb, ino);
2877 @@ -1235,12 +1263,17 @@ struct inode *ext2_iget (struct super_bl
2878         }
2879  
2880         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2881 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2882 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2883 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2884 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2885         if (!(test_opt (inode->i_sb, NO_UID32))) {
2886 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2887 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2888 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2889 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2890         }
2891 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2892 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2893 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2894 +               le16_to_cpu(raw_inode->i_raw_tag));
2895 +
2896         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2897         inode->i_size = le32_to_cpu(raw_inode->i_size);
2898         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2899 @@ -1338,8 +1371,8 @@ int ext2_write_inode(struct inode *inode
2900         struct ext2_inode_info *ei = EXT2_I(inode);
2901         struct super_block *sb = inode->i_sb;
2902         ino_t ino = inode->i_ino;
2903 -       uid_t uid = inode->i_uid;
2904 -       gid_t gid = inode->i_gid;
2905 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2906 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2907         struct buffer_head * bh;
2908         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2909         int n;
2910 @@ -1375,6 +1408,9 @@ int ext2_write_inode(struct inode *inode
2911                 raw_inode->i_uid_high = 0;
2912                 raw_inode->i_gid_high = 0;
2913         }
2914 +#ifdef CONFIG_TAGGING_INTERN
2915 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2916 +#endif
2917         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2918         raw_inode->i_size = cpu_to_le32(inode->i_size);
2919         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2920 @@ -1456,7 +1492,8 @@ int ext2_setattr(struct dentry *dentry, 
2921         if (error)
2922                 return error;
2923         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2924 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2925 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2926 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2927                 error = vfs_dq_transfer(inode, iattr) ? -EDQUOT : 0;
2928                 if (error)
2929                         return error;
2930 diff -NurpP --minimal linux-2.6.32.24/fs/ext2/ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/ioctl.c
2931 --- linux-2.6.32.24/fs/ext2/ioctl.c     2009-09-10 15:26:21.000000000 +0200
2932 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/ioctl.c     2009-12-03 20:04:56.000000000 +0100
2933 @@ -17,6 +17,16 @@
2934  #include <asm/uaccess.h>
2935  
2936  
2937 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2938 +{
2939 +       inode->i_flags = flags;
2940 +       inode->i_vflags = vflags;
2941 +       ext2_get_inode_flags(EXT2_I(inode));
2942 +       inode->i_ctime = CURRENT_TIME_SEC;
2943 +       mark_inode_dirty(inode);
2944 +       return 0;
2945 +}
2946 +
2947  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2948  {
2949         struct inode *inode = filp->f_dentry->d_inode;
2950 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2951  
2952                 flags = ext2_mask_flags(inode->i_mode, flags);
2953  
2954 +               if (IS_BARRIER(inode)) {
2955 +                       vxwprintk_task(1, "messing with the barrier.");
2956 +                       return -EACCES;
2957 +               }
2958 +
2959                 mutex_lock(&inode->i_mutex);
2960                 /* Is it quota file? Do not allow user to mess with it */
2961                 if (IS_NOQUOTA(inode)) {
2962 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2963                  *
2964                  * This test looks nicer. Thanks to Pauline Middelink
2965                  */
2966 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2967 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2968 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2969 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2970                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2971                                 mutex_unlock(&inode->i_mutex);
2972                                 ret = -EPERM;
2973 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2974                         }
2975                 }
2976  
2977 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2978 +               flags &= EXT2_FL_USER_MODIFIABLE;
2979                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2980                 ei->i_flags = flags;
2981                 mutex_unlock(&inode->i_mutex);
2982 diff -NurpP --minimal linux-2.6.32.24/fs/ext2/namei.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/namei.c
2983 --- linux-2.6.32.24/fs/ext2/namei.c     2009-12-03 20:02:51.000000000 +0100
2984 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/namei.c     2009-12-03 20:04:56.000000000 +0100
2985 @@ -31,6 +31,7 @@
2986   */
2987  
2988  #include <linux/pagemap.h>
2989 +#include <linux/vs_tag.h>
2990  #include "ext2.h"
2991  #include "xattr.h"
2992  #include "acl.h"
2993 @@ -74,6 +75,7 @@ static struct dentry *ext2_lookup(struct
2994                                 return ERR_PTR(-EIO);
2995                         } else {
2996                                 return ERR_CAST(inode);
2997 +               dx_propagate_tag(nd, inode);
2998                         }
2999                 }
3000         }
3001 @@ -401,6 +403,7 @@ const struct inode_operations ext2_dir_i
3002  #endif
3003         .setattr        = ext2_setattr,
3004         .check_acl      = ext2_check_acl,
3005 +       .sync_flags     = ext2_sync_flags,
3006  };
3007  
3008  const struct inode_operations ext2_special_inode_operations = {
3009 diff -NurpP --minimal linux-2.6.32.24/fs/ext2/super.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/super.c
3010 --- linux-2.6.32.24/fs/ext2/super.c     2009-09-10 15:26:21.000000000 +0200
3011 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext2/super.c     2009-12-03 20:04:56.000000000 +0100
3012 @@ -382,7 +382,8 @@ enum {
3013         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3014         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3015         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3016 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3017 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3018 +       Opt_tag, Opt_notag, Opt_tagid
3019  };
3020  
3021  static const match_table_t tokens = {
3022 @@ -410,6 +411,9 @@ static const match_table_t tokens = {
3023         {Opt_acl, "acl"},
3024         {Opt_noacl, "noacl"},
3025         {Opt_xip, "xip"},
3026 +       {Opt_tag, "tag"},
3027 +       {Opt_notag, "notag"},
3028 +       {Opt_tagid, "tagid=%u"},
3029         {Opt_grpquota, "grpquota"},
3030         {Opt_ignore, "noquota"},
3031         {Opt_quota, "quota"},
3032 @@ -480,6 +484,20 @@ static int parse_options (char * options
3033                 case Opt_nouid32:
3034                         set_opt (sbi->s_mount_opt, NO_UID32);
3035                         break;
3036 +#ifndef CONFIG_TAGGING_NONE
3037 +               case Opt_tag:
3038 +                       set_opt (sbi->s_mount_opt, TAGGED);
3039 +                       break;
3040 +               case Opt_notag:
3041 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3042 +                       break;
3043 +#endif
3044 +#ifdef CONFIG_PROPAGATE
3045 +               case Opt_tagid:
3046 +                       /* use args[0] */
3047 +                       set_opt (sbi->s_mount_opt, TAGGED);
3048 +                       break;
3049 +#endif
3050                 case Opt_nocheck:
3051                         clear_opt (sbi->s_mount_opt, CHECK);
3052                         break;
3053 @@ -829,6 +847,8 @@ static int ext2_fill_super(struct super_
3054         if (!parse_options ((char *) data, sbi))
3055                 goto failed_mount;
3056  
3057 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3058 +               sb->s_flags |= MS_TAGGED;
3059         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3060                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3061                  MS_POSIXACL : 0);
3062 @@ -1175,6 +1195,14 @@ static int ext2_remount (struct super_bl
3063                 goto restore_opts;
3064         }
3065  
3066 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3067 +               !(sb->s_flags & MS_TAGGED)) {
3068 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3069 +                      sb->s_id);
3070 +               err = -EINVAL;
3071 +               goto restore_opts;
3072 +       }
3073 +
3074         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3075                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3076  
3077 diff -NurpP --minimal linux-2.6.32.24/fs/ext3/file.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/file.c
3078 --- linux-2.6.32.24/fs/ext3/file.c      2009-12-03 20:02:51.000000000 +0100
3079 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/file.c      2009-12-03 20:04:56.000000000 +0100
3080 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
3081  #endif
3082         .check_acl      = ext3_check_acl,
3083         .fiemap         = ext3_fiemap,
3084 +       .sync_flags     = ext3_sync_flags,
3085  };
3086  
3087 diff -NurpP --minimal linux-2.6.32.24/fs/ext3/ialloc.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/ialloc.c
3088 --- linux-2.6.32.24/fs/ext3/ialloc.c    2009-09-10 15:26:21.000000000 +0200
3089 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/ialloc.c    2009-12-03 20:04:56.000000000 +0100
3090 @@ -23,6 +23,7 @@
3091  #include <linux/buffer_head.h>
3092  #include <linux/random.h>
3093  #include <linux/bitops.h>
3094 +#include <linux/vs_tag.h>
3095  
3096  #include <asm/byteorder.h>
3097  
3098 @@ -548,6 +549,7 @@ got:
3099         } else
3100                 inode->i_gid = current_fsgid();
3101         inode->i_mode = mode;
3102 +       inode->i_tag = dx_current_fstag(sb);
3103  
3104         inode->i_ino = ino;
3105         /* This is the optimal IO size (for stat), not the fs block size */
3106 diff -NurpP --minimal linux-2.6.32.24/fs/ext3/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/inode.c
3107 --- linux-2.6.32.24/fs/ext3/inode.c     2010-10-04 08:56:12.000000000 +0200
3108 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/inode.c     2009-12-29 00:36:26.000000000 +0100
3109 @@ -38,6 +38,7 @@
3110  #include <linux/bio.h>
3111  #include <linux/fiemap.h>
3112  #include <linux/namei.h>
3113 +#include <linux/vs_tag.h>
3114  #include "xattr.h"
3115  #include "acl.h"
3116  
3117 @@ -2343,7 +2344,7 @@ static void ext3_free_branches(handle_t 
3118  
3119  int ext3_can_truncate(struct inode *inode)
3120  {
3121 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3122 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3123                 return 0;
3124         if (S_ISREG(inode->i_mode))
3125                 return 1;
3126 @@ -2728,36 +2729,60 @@ void ext3_set_inode_flags(struct inode *
3127  {
3128         unsigned int flags = EXT3_I(inode)->i_flags;
3129  
3130 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3131 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3132 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3133 +
3134 +       if (flags & EXT3_IMMUTABLE_FL)
3135 +               inode->i_flags |= S_IMMUTABLE;
3136 +       if (flags & EXT3_IXUNLINK_FL)
3137 +               inode->i_flags |= S_IXUNLINK;
3138 +
3139         if (flags & EXT3_SYNC_FL)
3140                 inode->i_flags |= S_SYNC;
3141         if (flags & EXT3_APPEND_FL)
3142                 inode->i_flags |= S_APPEND;
3143 -       if (flags & EXT3_IMMUTABLE_FL)
3144 -               inode->i_flags |= S_IMMUTABLE;
3145         if (flags & EXT3_NOATIME_FL)
3146                 inode->i_flags |= S_NOATIME;
3147         if (flags & EXT3_DIRSYNC_FL)
3148                 inode->i_flags |= S_DIRSYNC;
3149 +
3150 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3151 +
3152 +       if (flags & EXT3_BARRIER_FL)
3153 +               inode->i_vflags |= V_BARRIER;
3154 +       if (flags & EXT3_COW_FL)
3155 +               inode->i_vflags |= V_COW;
3156  }
3157  
3158  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3159  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3160  {
3161         unsigned int flags = ei->vfs_inode.i_flags;
3162 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3163 +
3164 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3165 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3166 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3167 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3168 +
3169 +       if (flags & S_IMMUTABLE)
3170 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3171 +       if (flags & S_IXUNLINK)
3172 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3173  
3174 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3175 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3176         if (flags & S_SYNC)
3177                 ei->i_flags |= EXT3_SYNC_FL;
3178         if (flags & S_APPEND)
3179                 ei->i_flags |= EXT3_APPEND_FL;
3180 -       if (flags & S_IMMUTABLE)
3181 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3182         if (flags & S_NOATIME)
3183                 ei->i_flags |= EXT3_NOATIME_FL;
3184         if (flags & S_DIRSYNC)
3185                 ei->i_flags |= EXT3_DIRSYNC_FL;
3186 +
3187 +       if (vflags & V_BARRIER)
3188 +               ei->i_flags |= EXT3_BARRIER_FL;
3189 +       if (vflags & V_COW)
3190 +               ei->i_flags |= EXT3_COW_FL;
3191  }
3192  
3193  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3194 @@ -2771,6 +2796,8 @@ struct inode *ext3_iget(struct super_blo
3195         transaction_t *transaction;
3196         long ret;
3197         int block;
3198 +       uid_t uid;
3199 +       gid_t gid;
3200  
3201         inode = iget_locked(sb, ino);
3202         if (!inode)
3203 @@ -2787,12 +2814,17 @@ struct inode *ext3_iget(struct super_blo
3204         bh = iloc.bh;
3205         raw_inode = ext3_raw_inode(&iloc);
3206         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3207 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3208 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3209 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3210 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3211         if(!(test_opt (inode->i_sb, NO_UID32))) {
3212 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3213 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3214 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3215 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3216         }
3217 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3218 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3219 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3220 +               le16_to_cpu(raw_inode->i_raw_tag));
3221 +
3222         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3223         inode->i_size = le32_to_cpu(raw_inode->i_size);
3224         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3225 @@ -2947,6 +2979,8 @@ static int ext3_do_update_inode(handle_t
3226         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3227         struct ext3_inode_info *ei = EXT3_I(inode);
3228         struct buffer_head *bh = iloc->bh;
3229 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3230 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3231         int err = 0, rc, block;
3232  
3233  again:
3234 @@ -2961,29 +2995,32 @@ again:
3235         ext3_get_inode_flags(ei);
3236         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3237         if(!(test_opt(inode->i_sb, NO_UID32))) {
3238 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3239 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3240 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3241 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3242  /*
3243   * Fix up interoperability with old kernels. Otherwise, old inodes get
3244   * re-used with the upper 16 bits of the uid/gid intact
3245   */
3246                 if(!ei->i_dtime) {
3247                         raw_inode->i_uid_high =
3248 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3249 +                               cpu_to_le16(high_16_bits(uid));
3250                         raw_inode->i_gid_high =
3251 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3252 +                               cpu_to_le16(high_16_bits(gid));
3253                 } else {
3254                         raw_inode->i_uid_high = 0;
3255                         raw_inode->i_gid_high = 0;
3256                 }
3257         } else {
3258                 raw_inode->i_uid_low =
3259 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3260 +                       cpu_to_le16(fs_high2lowuid(uid));
3261                 raw_inode->i_gid_low =
3262 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3263 +                       cpu_to_le16(fs_high2lowgid(gid));
3264                 raw_inode->i_uid_high = 0;
3265                 raw_inode->i_gid_high = 0;
3266         }
3267 +#ifdef CONFIG_TAGGING_INTERN
3268 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3269 +#endif
3270         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3271         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3272         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3273 @@ -3141,7 +3178,8 @@ int ext3_setattr(struct dentry *dentry, 
3274                 return error;
3275  
3276         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3277 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3278 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3279 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3280                 handle_t *handle;
3281  
3282                 /* (user+group)*(old+new) structure, inode write (sb,
3283 @@ -3163,6 +3201,8 @@ int ext3_setattr(struct dentry *dentry, 
3284                         inode->i_uid = attr->ia_uid;
3285                 if (attr->ia_valid & ATTR_GID)
3286                         inode->i_gid = attr->ia_gid;
3287 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3288 +                       inode->i_tag = attr->ia_tag;
3289                 error = ext3_mark_inode_dirty(handle, inode);
3290                 ext3_journal_stop(handle);
3291         }
3292 diff -NurpP --minimal linux-2.6.32.24/fs/ext3/ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/ioctl.c
3293 --- linux-2.6.32.24/fs/ext3/ioctl.c     2009-06-11 17:13:03.000000000 +0200
3294 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/ioctl.c     2009-12-03 20:04:56.000000000 +0100
3295 @@ -8,6 +8,7 @@
3296   */
3297  
3298  #include <linux/fs.h>
3299 +#include <linux/mount.h>
3300  #include <linux/jbd.h>
3301  #include <linux/capability.h>
3302  #include <linux/ext3_fs.h>
3303 @@ -17,6 +18,34 @@
3304  #include <linux/compat.h>
3305  #include <asm/uaccess.h>
3306  
3307 +
3308 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3309 +{
3310 +       handle_t *handle = NULL;
3311 +       struct ext3_iloc iloc;
3312 +       int err;
3313 +
3314 +       handle = ext3_journal_start(inode, 1);
3315 +       if (IS_ERR(handle))
3316 +               return PTR_ERR(handle);
3317 +
3318 +       if (IS_SYNC(inode))
3319 +               handle->h_sync = 1;
3320 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3321 +       if (err)
3322 +               goto flags_err;
3323 +
3324 +       inode->i_flags = flags;
3325 +       inode->i_vflags = vflags;
3326 +       ext3_get_inode_flags(EXT3_I(inode));
3327 +       inode->i_ctime = CURRENT_TIME_SEC;
3328 +
3329 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3330 +flags_err:
3331 +       ext3_journal_stop(handle);
3332 +       return err;
3333 +}
3334 +
3335  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3336  {
3337         struct inode *inode = filp->f_dentry->d_inode;
3338 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3339  
3340                 flags = ext3_mask_flags(inode->i_mode, flags);
3341  
3342 +               if (IS_BARRIER(inode)) {
3343 +                       vxwprintk_task(1, "messing with the barrier.");
3344 +                       return -EACCES;
3345 +               }
3346 +
3347                 mutex_lock(&inode->i_mutex);
3348  
3349                 /* Is it quota file? Do not allow user to mess with it */
3350 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3351                  *
3352                  * This test looks nicer. Thanks to Pauline Middelink
3353                  */
3354 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3355 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3356 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3357 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3358                         if (!capable(CAP_LINUX_IMMUTABLE))
3359                                 goto flags_out;
3360                 }
3361 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3362                 if (err)
3363                         goto flags_err;
3364  
3365 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3366 +               flags &= EXT3_FL_USER_MODIFIABLE;
3367                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3368                 ei->i_flags = flags;
3369  
3370 diff -NurpP --minimal linux-2.6.32.24/fs/ext3/namei.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/namei.c
3371 --- linux-2.6.32.24/fs/ext3/namei.c     2009-12-03 20:02:51.000000000 +0100
3372 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/namei.c     2009-12-03 20:04:56.000000000 +0100
3373 @@ -36,6 +36,7 @@
3374  #include <linux/quotaops.h>
3375  #include <linux/buffer_head.h>
3376  #include <linux/bio.h>
3377 +#include <linux/vs_tag.h>
3378  
3379  #include "namei.h"
3380  #include "xattr.h"
3381 @@ -912,6 +913,7 @@ restart:
3382                                 if (bh)
3383                                         ll_rw_block(READ_META, 1, &bh);
3384                         }
3385 +               dx_propagate_tag(nd, inode);
3386                 }
3387                 if ((bh = bh_use[ra_ptr++]) == NULL)
3388                         goto next;
3389 @@ -2446,6 +2448,7 @@ const struct inode_operations ext3_dir_i
3390         .removexattr    = generic_removexattr,
3391  #endif
3392         .check_acl      = ext3_check_acl,
3393 +       .sync_flags     = ext3_sync_flags,
3394  };
3395  
3396  const struct inode_operations ext3_special_inode_operations = {
3397 diff -NurpP --minimal linux-2.6.32.24/fs/ext3/super.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/super.c
3398 --- linux-2.6.32.24/fs/ext3/super.c     2010-10-04 08:56:12.000000000 +0200
3399 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext3/super.c     2010-04-28 10:19:32.000000000 +0200
3400 @@ -789,7 +789,7 @@ enum {
3401         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3402         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3403         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3404 -       Opt_grpquota
3405 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3406  };
3407  
3408  static const match_table_t tokens = {
3409 @@ -842,6 +842,9 @@ static const match_table_t tokens = {
3410         {Opt_usrquota, "usrquota"},
3411         {Opt_barrier, "barrier=%u"},
3412         {Opt_resize, "resize"},
3413 +       {Opt_tag, "tag"},
3414 +       {Opt_notag, "notag"},
3415 +       {Opt_tagid, "tagid=%u"},
3416         {Opt_err, NULL},
3417  };
3418  
3419 @@ -934,6 +937,20 @@ static int parse_options (char *options,
3420                 case Opt_nouid32:
3421                         set_opt (sbi->s_mount_opt, NO_UID32);
3422                         break;
3423 +#ifndef CONFIG_TAGGING_NONE
3424 +               case Opt_tag:
3425 +                       set_opt (sbi->s_mount_opt, TAGGED);
3426 +                       break;
3427 +               case Opt_notag:
3428 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3429 +                       break;
3430 +#endif
3431 +#ifdef CONFIG_PROPAGATE
3432 +               case Opt_tagid:
3433 +                       /* use args[0] */
3434 +                       set_opt (sbi->s_mount_opt, TAGGED);
3435 +                       break;
3436 +#endif
3437                 case Opt_nocheck:
3438                         clear_opt (sbi->s_mount_opt, CHECK);
3439                         break;
3440 @@ -1658,6 +1675,9 @@ static int ext3_fill_super (struct super
3441                             NULL, 0))
3442                 goto failed_mount;
3443  
3444 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3445 +               sb->s_flags |= MS_TAGGED;
3446 +
3447         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3448                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3449  
3450 @@ -2527,6 +2547,14 @@ static int ext3_remount (struct super_bl
3451         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3452                 ext3_abort(sb, __func__, "Abort forced by user");
3453  
3454 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3455 +               !(sb->s_flags & MS_TAGGED)) {
3456 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3457 +                       sb->s_id);
3458 +               err = -EINVAL;
3459 +               goto restore_opts;
3460 +       }
3461 +
3462         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3463                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3464  
3465 diff -NurpP --minimal linux-2.6.32.24/fs/ext4/ext4.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/ext4.h
3466 --- linux-2.6.32.24/fs/ext4/ext4.h      2010-10-04 08:56:12.000000000 +0200
3467 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/ext4.h      2010-09-05 21:24:17.000000000 +0200
3468 @@ -289,8 +289,12 @@ struct flex_groups {
3469  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3470  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3471  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3472 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3473  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3474  
3475 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3476 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3477 +
3478  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3479  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3480  
3481 @@ -552,7 +556,8 @@ struct ext4_inode {
3482                         __le16  l_i_file_acl_high;
3483                         __le16  l_i_uid_high;   /* these 2 fields */
3484                         __le16  l_i_gid_high;   /* were reserved2[0] */
3485 -                       __u32   l_i_reserved2;
3486 +                       __le16  l_i_tag;        /* Context Tag */
3487 +                       __u16   l_i_reserved2;
3488                 } linux2;
3489                 struct {
3490                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3491 @@ -666,6 +671,7 @@ do {                                                                               \
3492  #define i_gid_low      i_gid
3493  #define i_uid_high     osd2.linux2.l_i_uid_high
3494  #define i_gid_high     osd2.linux2.l_i_gid_high
3495 +#define i_raw_tag      osd2.linux2.l_i_tag
3496  #define i_reserved2    osd2.linux2.l_i_reserved2
3497  
3498  #elif defined(__GNU__)
3499 @@ -840,6 +846,7 @@ struct ext4_inode_info {
3500  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3501  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3502  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3503 +#define EXT4_MOUNT_TAGGED              0x400000 /* Enable Context Tags */
3504  #define EXT4_MOUNT_JOURNAL_CHECKSUM    0x800000 /* Journal checksums */
3505  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
3506  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3507 @@ -1865,6 +1872,7 @@ extern int ext4_get_blocks(handle_t *han
3508                            struct buffer_head *bh, int flags);
3509  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3510                         __u64 start, __u64 len);
3511 +extern int ext4_sync_flags(struct inode *, int, int);
3512  /* move_extent.c */
3513  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3514                              __u64 start_orig, __u64 start_donor,
3515 diff -NurpP --minimal linux-2.6.32.24/fs/ext4/file.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/file.c
3516 --- linux-2.6.32.24/fs/ext4/file.c      2010-10-04 08:56:12.000000000 +0200
3517 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/file.c      2010-08-09 18:06:32.000000000 +0200
3518 @@ -161,5 +161,6 @@ const struct inode_operations ext4_file_
3519         .check_acl      = ext4_check_acl,
3520         .fallocate      = ext4_fallocate,
3521         .fiemap         = ext4_fiemap,
3522 +       .sync_flags     = ext4_sync_flags,
3523  };
3524  
3525 diff -NurpP --minimal linux-2.6.32.24/fs/ext4/ialloc.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/ialloc.c
3526 --- linux-2.6.32.24/fs/ext4/ialloc.c    2010-10-04 08:56:12.000000000 +0200
3527 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/ialloc.c    2010-08-09 18:06:32.000000000 +0200
3528 @@ -22,6 +22,7 @@
3529  #include <linux/random.h>
3530  #include <linux/bitops.h>
3531  #include <linux/blkdev.h>
3532 +#include <linux/vs_tag.h>
3533  #include <asm/byteorder.h>
3534  
3535  #include "ext4.h"
3536 @@ -988,6 +989,7 @@ got:
3537         } else
3538                 inode->i_gid = current_fsgid();
3539         inode->i_mode = mode;
3540 +       inode->i_tag = dx_current_fstag(sb);
3541  
3542         inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb);
3543         /* This is the optimal IO size (for stat), not the fs block size */
3544 diff -NurpP --minimal linux-2.6.32.24/fs/ext4/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/inode.c
3545 --- linux-2.6.32.24/fs/ext4/inode.c     2010-10-04 08:56:13.000000000 +0200
3546 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/inode.c     2010-10-04 10:16:00.000000000 +0200
3547 @@ -38,6 +38,7 @@
3548  #include <linux/uio.h>
3549  #include <linux/bio.h>
3550  #include <linux/workqueue.h>
3551 +#include <linux/vs_tag.h>
3552  
3553  #include "ext4_jbd2.h"
3554  #include "xattr.h"
3555 @@ -4446,7 +4447,7 @@ static void ext4_free_branches(handle_t 
3556  
3557  int ext4_can_truncate(struct inode *inode)
3558  {
3559 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3560 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3561                 return 0;
3562         if (S_ISREG(inode->i_mode))
3563                 return 1;
3564 @@ -4799,41 +4800,64 @@ void ext4_set_inode_flags(struct inode *
3565  {
3566         unsigned int flags = EXT4_I(inode)->i_flags;
3567  
3568 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3569 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3570 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3571 +
3572 +       if (flags & EXT4_IMMUTABLE_FL)
3573 +               inode->i_flags |= S_IMMUTABLE;
3574 +       if (flags & EXT4_IXUNLINK_FL)
3575 +               inode->i_flags |= S_IXUNLINK;
3576 +
3577         if (flags & EXT4_SYNC_FL)
3578                 inode->i_flags |= S_SYNC;
3579         if (flags & EXT4_APPEND_FL)
3580                 inode->i_flags |= S_APPEND;
3581 -       if (flags & EXT4_IMMUTABLE_FL)
3582 -               inode->i_flags |= S_IMMUTABLE;
3583         if (flags & EXT4_NOATIME_FL)
3584                 inode->i_flags |= S_NOATIME;
3585         if (flags & EXT4_DIRSYNC_FL)
3586                 inode->i_flags |= S_DIRSYNC;
3587 +
3588 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3589 +
3590 +       if (flags & EXT4_BARRIER_FL)
3591 +               inode->i_vflags |= V_BARRIER;
3592 +       if (flags & EXT4_COW_FL)
3593 +               inode->i_vflags |= V_COW;
3594  }
3595  
3596  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3597  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3598  {
3599 -       unsigned int vfs_fl;
3600 +       unsigned int vfs_fl, vflags;
3601         unsigned long old_fl, new_fl;
3602  
3603         do {
3604                 vfs_fl = ei->vfs_inode.i_flags;
3605 +               vflags = ei->vfs_inode.i_vflags;
3606                 old_fl = ei->i_flags;
3607 -               new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3608 -                               EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3609 -                               EXT4_DIRSYNC_FL);
3610 +               new_fl = old_fl & ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3611 +                               EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3612 +                               EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3613 +                               EXT4_BARRIER_FL | EXT4_COW_FL);
3614 +
3615 +               if (vfs_fl & S_IMMUTABLE)
3616 +                       new_fl |= EXT4_IMMUTABLE_FL;
3617 +               if (vfs_fl & S_IXUNLINK)
3618 +                       new_fl |= EXT4_IXUNLINK_FL;
3619 +
3620                 if (vfs_fl & S_SYNC)
3621                         new_fl |= EXT4_SYNC_FL;
3622                 if (vfs_fl & S_APPEND)
3623                         new_fl |= EXT4_APPEND_FL;
3624 -               if (vfs_fl & S_IMMUTABLE)
3625 -                       new_fl |= EXT4_IMMUTABLE_FL;
3626                 if (vfs_fl & S_NOATIME)
3627                         new_fl |= EXT4_NOATIME_FL;
3628                 if (vfs_fl & S_DIRSYNC)
3629                         new_fl |= EXT4_DIRSYNC_FL;
3630 +
3631 +               if (vflags & V_BARRIER)
3632 +                       new_fl |= EXT4_BARRIER_FL;
3633 +               if (vflags & V_COW)
3634 +                       new_fl |= EXT4_COW_FL;
3635         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3636  }
3637  
3638 @@ -4869,6 +4893,8 @@ struct inode *ext4_iget(struct super_blo
3639         journal_t *journal = EXT4_SB(sb)->s_journal;
3640         long ret;
3641         int block;
3642 +       uid_t uid;
3643 +       gid_t gid;
3644  
3645         inode = iget_locked(sb, ino);
3646         if (!inode)
3647 @@ -4884,12 +4910,16 @@ struct inode *ext4_iget(struct super_blo
3648                 goto bad_inode;
3649         raw_inode = ext4_raw_inode(&iloc);
3650         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3651 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3652 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3653 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3654 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3655         if (!(test_opt(inode->i_sb, NO_UID32))) {
3656 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3657 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3658 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3659 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3660         }
3661 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3662 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3663 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3664 +               le16_to_cpu(raw_inode->i_raw_tag));
3665         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3666  
3667         ei->i_state_flags = 0;
3668 @@ -5111,6 +5141,8 @@ static int ext4_do_update_inode(handle_t
3669         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3670         struct ext4_inode_info *ei = EXT4_I(inode);
3671         struct buffer_head *bh = iloc->bh;
3672 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3673 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3674         int err = 0, rc, block;
3675  
3676         /* For fields not not tracking in the in-memory inode,
3677 @@ -5121,29 +5153,32 @@ static int ext4_do_update_inode(handle_t
3678         ext4_get_inode_flags(ei);
3679         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3680         if (!(test_opt(inode->i_sb, NO_UID32))) {
3681 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3682 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3683 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3684 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3685  /*
3686   * Fix up interoperability with old kernels. Otherwise, old inodes get
3687   * re-used with the upper 16 bits of the uid/gid intact
3688   */
3689                 if (!ei->i_dtime) {
3690                         raw_inode->i_uid_high =
3691 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3692 +                               cpu_to_le16(high_16_bits(uid));
3693                         raw_inode->i_gid_high =
3694 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3695 +                               cpu_to_le16(high_16_bits(gid));
3696                 } else {
3697                         raw_inode->i_uid_high = 0;
3698                         raw_inode->i_gid_high = 0;
3699                 }
3700         } else {
3701                 raw_inode->i_uid_low =
3702 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3703 +                       cpu_to_le16(fs_high2lowuid(uid));
3704                 raw_inode->i_gid_low =
3705 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3706 +                       cpu_to_le16(fs_high2lowgid(gid));
3707                 raw_inode->i_uid_high = 0;
3708                 raw_inode->i_gid_high = 0;
3709         }
3710 +#ifdef CONFIG_TAGGING_INTERN
3711 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3712 +#endif
3713         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3714  
3715         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3716 @@ -5329,7 +5364,8 @@ int ext4_setattr(struct dentry *dentry, 
3717                 return error;
3718  
3719         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3720 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3721 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3722 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3723                 handle_t *handle;
3724  
3725                 /* (user+group)*(old+new) structure, inode write (sb,
3726 @@ -5351,6 +5387,8 @@ int ext4_setattr(struct dentry *dentry, 
3727                         inode->i_uid = attr->ia_uid;
3728                 if (attr->ia_valid & ATTR_GID)
3729                         inode->i_gid = attr->ia_gid;
3730 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3731 +                       inode->i_tag = attr->ia_tag;
3732                 error = ext4_mark_inode_dirty(handle, inode);
3733                 ext4_journal_stop(handle);
3734         }
3735 diff -NurpP --minimal linux-2.6.32.24/fs/ext4/ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/ioctl.c
3736 --- linux-2.6.32.24/fs/ext4/ioctl.c     2010-10-04 08:56:13.000000000 +0200
3737 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/ioctl.c     2010-08-09 18:06:32.000000000 +0200
3738 @@ -14,10 +14,39 @@
3739  #include <linux/compat.h>
3740  #include <linux/mount.h>
3741  #include <linux/file.h>
3742 +#include <linux/vs_tag.h>
3743  #include <asm/uaccess.h>
3744  #include "ext4_jbd2.h"
3745  #include "ext4.h"
3746  
3747 +
3748 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3749 +{
3750 +       handle_t *handle = NULL;
3751 +       struct ext4_iloc iloc;
3752 +       int err;
3753 +
3754 +       handle = ext4_journal_start(inode, 1);
3755 +       if (IS_ERR(handle))
3756 +               return PTR_ERR(handle);
3757 +
3758 +       if (IS_SYNC(inode))
3759 +               ext4_handle_sync(handle);
3760 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3761 +       if (err)
3762 +               goto flags_err;
3763 +
3764 +       inode->i_flags = flags;
3765 +       inode->i_vflags = vflags;
3766 +       ext4_get_inode_flags(EXT4_I(inode));
3767 +       inode->i_ctime = ext4_current_time(inode);
3768 +
3769 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3770 +flags_err:
3771 +       ext4_journal_stop(handle);
3772 +       return err;
3773 +}
3774 +
3775  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3776  {
3777         struct inode *inode = filp->f_dentry->d_inode;
3778 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3779  
3780                 flags = ext4_mask_flags(inode->i_mode, flags);
3781  
3782 +               if (IS_BARRIER(inode)) {
3783 +                       vxwprintk_task(1, "messing with the barrier.");
3784 +                       return -EACCES;
3785 +               }
3786 +
3787                 err = -EPERM;
3788                 mutex_lock(&inode->i_mutex);
3789                 /* Is it quota file? Do not allow user to mess with it */
3790 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3791                  *
3792                  * This test looks nicer. Thanks to Pauline Middelink
3793                  */
3794 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3795 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3796 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3797 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3798                         if (!capable(CAP_LINUX_IMMUTABLE))
3799                                 goto flags_out;
3800                 }
3801 diff -NurpP --minimal linux-2.6.32.24/fs/ext4/namei.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/namei.c
3802 --- linux-2.6.32.24/fs/ext4/namei.c     2010-10-04 08:56:13.000000000 +0200
3803 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/namei.c     2010-08-09 18:06:32.000000000 +0200
3804 @@ -34,6 +34,7 @@
3805  #include <linux/quotaops.h>
3806  #include <linux/buffer_head.h>
3807  #include <linux/bio.h>
3808 +#include <linux/vs_tag.h>
3809  #include "ext4.h"
3810  #include "ext4_jbd2.h"
3811  
3812 @@ -941,6 +942,7 @@ restart:
3813                                 if (bh)
3814                                         ll_rw_block(READ_META, 1, &bh);
3815                         }
3816 +               dx_propagate_tag(nd, inode);
3817                 }
3818                 if ((bh = bh_use[ra_ptr++]) == NULL)
3819                         goto next;
3820 @@ -2543,6 +2545,7 @@ const struct inode_operations ext4_dir_i
3821  #endif
3822         .check_acl      = ext4_check_acl,
3823         .fiemap         = ext4_fiemap,
3824 +       .sync_flags     = ext4_sync_flags,
3825  };
3826  
3827  const struct inode_operations ext4_special_inode_operations = {
3828 diff -NurpP --minimal linux-2.6.32.24/fs/ext4/super.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/super.c
3829 --- linux-2.6.32.24/fs/ext4/super.c     2010-10-04 08:56:13.000000000 +0200
3830 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ext4/super.c     2010-08-19 17:35:34.000000000 +0200
3831 @@ -1100,6 +1100,7 @@ enum {
3832         Opt_block_validity, Opt_noblock_validity,
3833         Opt_inode_readahead_blks, Opt_journal_ioprio,
3834         Opt_discard, Opt_nodiscard,
3835 +       Opt_tag, Opt_notag, Opt_tagid
3836  };
3837  
3838  static const match_table_t tokens = {
3839 @@ -1167,6 +1168,9 @@ static const match_table_t tokens = {
3840         {Opt_noauto_da_alloc, "noauto_da_alloc"},
3841         {Opt_discard, "discard"},
3842         {Opt_nodiscard, "nodiscard"},
3843 +       {Opt_tag, "tag"},
3844 +       {Opt_notag, "notag"},
3845 +       {Opt_tagid, "tagid=%u"},
3846         {Opt_err, NULL},
3847  };
3848  
3849 @@ -1269,6 +1273,20 @@ static int parse_options(char *options, 
3850                 case Opt_nouid32:
3851                         set_opt(sbi->s_mount_opt, NO_UID32);
3852                         break;
3853 +#ifndef CONFIG_TAGGING_NONE
3854 +               case Opt_tag:
3855 +                       set_opt (sbi->s_mount_opt, TAGGED);
3856 +                       break;
3857 +               case Opt_notag:
3858 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3859 +                       break;
3860 +#endif
3861 +#ifdef CONFIG_PROPAGATE
3862 +               case Opt_tagid:
3863 +                       /* use args[0] */
3864 +                       set_opt (sbi->s_mount_opt, TAGGED);
3865 +                       break;
3866 +#endif
3867                 case Opt_debug:
3868                         set_opt(sbi->s_mount_opt, DEBUG);
3869                         break;
3870 @@ -2471,6 +2489,9 @@ static int ext4_fill_super(struct super_
3871                            &journal_ioprio, NULL, 0))
3872                 goto failed_mount;
3873  
3874 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3875 +               sb->s_flags |= MS_TAGGED;
3876 +
3877         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3878                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3879  
3880 @@ -3522,6 +3543,14 @@ static int ext4_remount(struct super_blo
3881         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3882                 ext4_abort(sb, __func__, "Abort forced by user");
3883  
3884 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3885 +               !(sb->s_flags & MS_TAGGED)) {
3886 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3887 +                       sb->s_id);
3888 +               err = -EINVAL;
3889 +               goto restore_opts;
3890 +       }
3891 +
3892         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3893                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3894  
3895 diff -NurpP --minimal linux-2.6.32.24/fs/fcntl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/fcntl.c
3896 --- linux-2.6.32.24/fs/fcntl.c  2010-10-04 08:56:13.000000000 +0200
3897 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/fcntl.c  2010-02-24 12:32:54.000000000 +0100
3898 @@ -19,6 +19,7 @@
3899  #include <linux/signal.h>
3900  #include <linux/rcupdate.h>
3901  #include <linux/pid_namespace.h>
3902 +#include <linux/vs_limit.h>
3903  
3904  #include <asm/poll.h>
3905  #include <asm/siginfo.h>
3906 @@ -102,6 +103,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3907  
3908         if (tofree)
3909                 filp_close(tofree, files);
3910 +       else
3911 +               vx_openfd_inc(newfd);   /* fd was unused */
3912  
3913         return newfd;
3914  
3915 @@ -426,6 +429,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3916         filp = fget(fd);
3917         if (!filp)
3918                 goto out;
3919 +       if (!vx_files_avail(1))
3920 +               goto out;
3921  
3922         err = security_file_fcntl(filp, cmd, arg);
3923         if (err) {
3924 diff -NurpP --minimal linux-2.6.32.24/fs/file.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/file.c
3925 --- linux-2.6.32.24/fs/file.c   2009-12-03 20:02:51.000000000 +0100
3926 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/file.c   2009-12-03 20:04:56.000000000 +0100
3927 @@ -20,6 +20,7 @@
3928  #include <linux/spinlock.h>
3929  #include <linux/rcupdate.h>
3930  #include <linux/workqueue.h>
3931 +#include <linux/vs_limit.h>
3932  
3933  struct fdtable_defer {
3934         spinlock_t lock;
3935 @@ -368,6 +369,8 @@ struct files_struct *dup_fd(struct files
3936                 struct file *f = *old_fds++;
3937                 if (f) {
3938                         get_file(f);
3939 +                       /* TODO: sum it first for check and performance */
3940 +                       vx_openfd_inc(open_files - i);
3941                 } else {
3942                         /*
3943                          * The fd may be claimed in the fd bitmap but not yet
3944 @@ -476,6 +479,7 @@ repeat:
3945         else
3946                 FD_CLR(fd, fdt->close_on_exec);
3947         error = fd;
3948 +       vx_openfd_inc(fd);
3949  #if 1
3950         /* Sanity check */
3951         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3952 diff -NurpP --minimal linux-2.6.32.24/fs/file_table.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/file_table.c
3953 --- linux-2.6.32.24/fs/file_table.c     2010-10-04 08:56:13.000000000 +0200
3954 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/file_table.c     2010-03-18 16:53:06.000000000 +0100
3955 @@ -22,6 +22,8 @@
3956  #include <linux/fsnotify.h>
3957  #include <linux/sysctl.h>
3958  #include <linux/percpu_counter.h>
3959 +#include <linux/vs_limit.h>
3960 +#include <linux/vs_context.h>
3961  
3962  #include <asm/atomic.h>
3963  
3964 @@ -131,6 +133,8 @@ struct file *get_empty_filp(void)
3965         spin_lock_init(&f->f_lock);
3966         eventpoll_init_file(f);
3967         /* f->f_version: 0 */
3968 +       f->f_xid = vx_current_xid();
3969 +       vx_files_inc(f);
3970         return f;
3971  
3972  over:
3973 @@ -285,6 +289,8 @@ void __fput(struct file *file)
3974                 cdev_put(inode->i_cdev);
3975         fops_put(file->f_op);
3976         put_pid(file->f_owner.pid);
3977 +       vx_files_dec(file);
3978 +       file->f_xid = 0;
3979         file_kill(file);
3980         if (file->f_mode & FMODE_WRITE)
3981                 drop_file_write_access(file);
3982 @@ -352,6 +358,8 @@ void put_filp(struct file *file)
3983  {
3984         if (atomic_long_dec_and_test(&file->f_count)) {
3985                 security_file_free(file);
3986 +               vx_files_dec(file);
3987 +               file->f_xid = 0;
3988                 file_kill(file);
3989                 file_free(file);
3990         }
3991 diff -NurpP --minimal linux-2.6.32.24/fs/fs_struct.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/fs_struct.c
3992 --- linux-2.6.32.24/fs/fs_struct.c      2009-06-11 17:13:04.000000000 +0200
3993 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/fs_struct.c      2009-12-03 20:04:56.000000000 +0100
3994 @@ -4,6 +4,7 @@
3995  #include <linux/path.h>
3996  #include <linux/slab.h>
3997  #include <linux/fs_struct.h>
3998 +#include <linux/vserver/global.h>
3999  
4000  /*
4001   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
4002 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
4003  {
4004         path_put(&fs->root);
4005         path_put(&fs->pwd);
4006 +       atomic_dec(&vs_global_fs);
4007         kmem_cache_free(fs_cachep, fs);
4008  }
4009  
4010 @@ -112,6 +114,7 @@ struct fs_struct *copy_fs_struct(struct 
4011                 fs->pwd = old->pwd;
4012                 path_get(&old->pwd);
4013                 read_unlock(&old->lock);
4014 +               atomic_inc(&vs_global_fs);
4015         }
4016         return fs;
4017  }
4018 diff -NurpP --minimal linux-2.6.32.24/fs/gfs2/file.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/gfs2/file.c
4019 --- linux-2.6.32.24/fs/gfs2/file.c      2010-10-04 08:56:13.000000000 +0200
4020 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/gfs2/file.c      2010-07-08 02:22:31.000000000 +0200
4021 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
4022         [7] = GFS2_DIF_NOATIME,
4023         [12] = GFS2_DIF_EXHASH,
4024         [14] = GFS2_DIF_INHERIT_JDATA,
4025 +       [27] = GFS2_DIF_IXUNLINK,
4026 +       [26] = GFS2_DIF_BARRIER,
4027 +       [29] = GFS2_DIF_COW,
4028  };
4029  
4030  static const u32 gfs2_to_fsflags[32] = {
4031 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
4032         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4033         [gfs2fl_ExHash] = FS_INDEX_FL,
4034         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4035 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4036 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4037 +       [gfs2fl_Cow] = FS_COW_FL,
4038  };
4039  
4040  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4041 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
4042  {
4043         struct gfs2_inode *ip = GFS2_I(inode);
4044         unsigned int flags = inode->i_flags;
4045 +       unsigned int vflags = inode->i_vflags;
4046 +
4047 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4048 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4049  
4050 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4051         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4052                 flags |= S_IMMUTABLE;
4053 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4054 +               flags |= S_IXUNLINK;
4055 +
4056         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4057                 flags |= S_APPEND;
4058         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4059 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
4060         if (ip->i_diskflags & GFS2_DIF_SYNC)
4061                 flags |= S_SYNC;
4062         inode->i_flags = flags;
4063 +
4064 +       vflags &= ~(V_BARRIER | V_COW);
4065 +
4066 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4067 +               vflags |= V_BARRIER;
4068 +       if (ip->i_diskflags & GFS2_DIF_COW)
4069 +               vflags |= V_COW;
4070 +       inode->i_vflags = vflags;
4071 +}
4072 +
4073 +void gfs2_get_inode_flags(struct inode *inode)
4074 +{
4075 +       struct gfs2_inode *ip = GFS2_I(inode);
4076 +       unsigned int flags = inode->i_flags;
4077 +       unsigned int vflags = inode->i_vflags;
4078 +
4079 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4080 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4081 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4082 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4083 +
4084 +       if (flags & S_IMMUTABLE)
4085 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4086 +       if (flags & S_IXUNLINK)
4087 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4088 +
4089 +       if (flags & S_APPEND)
4090 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4091 +       if (flags & S_NOATIME)
4092 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4093 +       if (flags & S_SYNC)
4094 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4095 +
4096 +       if (vflags & V_BARRIER)
4097 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4098 +       if (vflags & V_COW)
4099 +               ip->i_diskflags |= GFS2_DIF_COW;
4100  }
4101  
4102  /* Flags that can be set by user space */
4103 @@ -293,6 +342,37 @@ static int gfs2_set_flags(struct file *f
4104         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4105  }
4106  
4107 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4108 +{
4109 +       struct gfs2_inode *ip = GFS2_I(inode);
4110 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4111 +       struct buffer_head *bh;
4112 +       struct gfs2_holder gh;
4113 +       int error;
4114 +
4115 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4116 +       if (error)
4117 +               return error;
4118 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4119 +       if (error)
4120 +               goto out;
4121 +       error = gfs2_meta_inode_buffer(ip, &bh);
4122 +       if (error)
4123 +               goto out_trans_end;
4124 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4125 +       inode->i_flags = flags;
4126 +       inode->i_vflags = vflags;
4127 +       gfs2_get_inode_flags(inode);
4128 +       gfs2_dinode_out(ip, bh->b_data);
4129 +       brelse(bh);
4130 +       gfs2_set_aops(inode);
4131 +out_trans_end:
4132 +       gfs2_trans_end(sdp);
4133 +out:
4134 +       gfs2_glock_dq_uninit(&gh);
4135 +       return error;
4136 +}
4137 +
4138  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4139  {
4140         switch(cmd) {
4141 diff -NurpP --minimal linux-2.6.32.24/fs/gfs2/inode.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/gfs2/inode.h
4142 --- linux-2.6.32.24/fs/gfs2/inode.h     2009-09-10 15:26:22.000000000 +0200
4143 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/gfs2/inode.h     2009-12-03 20:04:56.000000000 +0100
4144 @@ -109,6 +109,7 @@ extern const struct file_operations gfs2
4145  extern const struct file_operations gfs2_dir_fops_nolock;
4146  
4147  extern void gfs2_set_inode_flags(struct inode *inode);
4148 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4149   
4150  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4151  extern const struct file_operations gfs2_file_fops;
4152 diff -NurpP --minimal linux-2.6.32.24/fs/gfs2/ops_inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/gfs2/ops_inode.c
4153 --- linux-2.6.32.24/fs/gfs2/ops_inode.c 2009-12-03 20:02:52.000000000 +0100
4154 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/gfs2/ops_inode.c 2009-12-03 20:04:56.000000000 +0100
4155 @@ -1400,6 +1400,7 @@ const struct inode_operations gfs2_file_
4156         .listxattr = gfs2_listxattr,
4157         .removexattr = gfs2_removexattr,
4158         .fiemap = gfs2_fiemap,
4159 +       .sync_flags = gfs2_sync_flags,
4160  };
4161  
4162  const struct inode_operations gfs2_dir_iops = {
4163 @@ -1420,6 +1421,7 @@ const struct inode_operations gfs2_dir_i
4164         .listxattr = gfs2_listxattr,
4165         .removexattr = gfs2_removexattr,
4166         .fiemap = gfs2_fiemap,
4167 +       .sync_flags = gfs2_sync_flags,
4168  };
4169  
4170  const struct inode_operations gfs2_symlink_iops = {
4171 diff -NurpP --minimal linux-2.6.32.24/fs/hfsplus/ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/hfsplus/ioctl.c
4172 --- linux-2.6.32.24/fs/hfsplus/ioctl.c  2008-12-25 00:26:37.000000000 +0100
4173 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/hfsplus/ioctl.c  2009-12-03 20:04:56.000000000 +0100
4174 @@ -17,6 +17,7 @@
4175  #include <linux/mount.h>
4176  #include <linux/sched.h>
4177  #include <linux/xattr.h>
4178 +#include <linux/mount.h>
4179  #include <asm/uaccess.h>
4180  #include "hfsplus_fs.h"
4181  
4182 diff -NurpP --minimal linux-2.6.32.24/fs/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/inode.c
4183 --- linux-2.6.32.24/fs/inode.c  2009-12-03 20:02:52.000000000 +0100
4184 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/inode.c  2009-12-03 20:04:56.000000000 +0100
4185 @@ -133,6 +133,9 @@ int inode_init_always(struct super_block
4186         struct address_space *const mapping = &inode->i_data;
4187  
4188         inode->i_sb = sb;
4189 +
4190 +       /* essential because of inode slab reuse */
4191 +       inode->i_tag = 0;
4192         inode->i_blkbits = sb->s_blocksize_bits;
4193         inode->i_flags = 0;
4194         atomic_set(&inode->i_count, 1);
4195 @@ -153,6 +156,7 @@ int inode_init_always(struct super_block
4196         inode->i_bdev = NULL;
4197         inode->i_cdev = NULL;
4198         inode->i_rdev = 0;
4199 +       inode->i_mdev = 0;
4200         inode->dirtied_when = 0;
4201  
4202         if (security_inode_alloc(inode))
4203 @@ -307,6 +311,8 @@ void __iget(struct inode *inode)
4204         inodes_stat.nr_unused--;
4205  }
4206  
4207 +EXPORT_SYMBOL_GPL(__iget);
4208 +
4209  /**
4210   * clear_inode - clear an inode
4211   * @inode: inode to clear
4212 @@ -1611,9 +1617,11 @@ void init_special_inode(struct inode *in
4213         if (S_ISCHR(mode)) {
4214                 inode->i_fop = &def_chr_fops;
4215                 inode->i_rdev = rdev;
4216 +               inode->i_mdev = rdev;
4217         } else if (S_ISBLK(mode)) {
4218                 inode->i_fop = &def_blk_fops;
4219                 inode->i_rdev = rdev;
4220 +               inode->i_mdev = rdev;
4221         } else if (S_ISFIFO(mode))
4222                 inode->i_fop = &def_fifo_fops;
4223         else if (S_ISSOCK(mode))
4224 diff -NurpP --minimal linux-2.6.32.24/fs/ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ioctl.c
4225 --- linux-2.6.32.24/fs/ioctl.c  2009-12-03 20:02:52.000000000 +0100
4226 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ioctl.c  2009-12-03 20:04:56.000000000 +0100
4227 @@ -16,6 +16,9 @@
4228  #include <linux/writeback.h>
4229  #include <linux/buffer_head.h>
4230  #include <linux/falloc.h>
4231 +#include <linux/proc_fs.h>
4232 +#include <linux/vserver/inode.h>
4233 +#include <linux/vs_tag.h>
4234  
4235  #include <asm/ioctls.h>
4236  
4237 diff -NurpP --minimal linux-2.6.32.24/fs/ioprio.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ioprio.c
4238 --- linux-2.6.32.24/fs/ioprio.c 2009-03-24 14:22:26.000000000 +0100
4239 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ioprio.c 2009-12-03 20:04:56.000000000 +0100
4240 @@ -26,6 +26,7 @@
4241  #include <linux/syscalls.h>
4242  #include <linux/security.h>
4243  #include <linux/pid_namespace.h>
4244 +#include <linux/vs_base.h>
4245  
4246  int set_task_ioprio(struct task_struct *task, int ioprio)
4247  {
4248 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4249                         else
4250                                 pgrp = find_vpid(who);
4251                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4252 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4253 +                                       continue;
4254                                 ret = set_task_ioprio(p, ioprio);
4255                                 if (ret)
4256                                         break;
4257 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4258                         else
4259                                 pgrp = find_vpid(who);
4260                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4261 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4262 +                                       continue;
4263                                 tmpio = get_task_ioprio(p);
4264                                 if (tmpio < 0)
4265                                         continue;
4266 diff -NurpP --minimal linux-2.6.32.24/fs/jfs/acl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/acl.c
4267 --- linux-2.6.32.24/fs/jfs/acl.c        2009-12-03 20:02:52.000000000 +0100
4268 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/acl.c        2009-12-03 20:04:56.000000000 +0100
4269 @@ -216,7 +216,8 @@ int jfs_setattr(struct dentry *dentry, s
4270                 return rc;
4271  
4272         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4273 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4274 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4275 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4276                 if (vfs_dq_transfer(inode, iattr))
4277                         return -EDQUOT;
4278         }
4279 diff -NurpP --minimal linux-2.6.32.24/fs/jfs/file.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/file.c
4280 --- linux-2.6.32.24/fs/jfs/file.c       2009-12-03 20:02:52.000000000 +0100
4281 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/file.c       2009-12-03 20:04:56.000000000 +0100
4282 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4283         .setattr        = jfs_setattr,
4284         .check_acl      = jfs_check_acl,
4285  #endif
4286 +       .sync_flags     = jfs_sync_flags,
4287  };
4288  
4289  const struct file_operations jfs_file_operations = {
4290 diff -NurpP --minimal linux-2.6.32.24/fs/jfs/ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/ioctl.c
4291 --- linux-2.6.32.24/fs/jfs/ioctl.c      2008-12-25 00:26:37.000000000 +0100
4292 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/ioctl.c      2009-12-03 20:04:56.000000000 +0100
4293 @@ -11,6 +11,7 @@
4294  #include <linux/mount.h>
4295  #include <linux/time.h>
4296  #include <linux/sched.h>
4297 +#include <linux/mount.h>
4298  #include <asm/current.h>
4299  #include <asm/uaccess.h>
4300  
4301 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4302  }
4303  
4304  
4305 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4306 +{
4307 +       inode->i_flags = flags;
4308 +       inode->i_vflags = vflags;
4309 +       jfs_get_inode_flags(JFS_IP(inode));
4310 +       inode->i_ctime = CURRENT_TIME_SEC;
4311 +       mark_inode_dirty(inode);
4312 +       return 0;
4313 +}
4314 +
4315  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4316  {
4317         struct inode *inode = filp->f_dentry->d_inode;
4318 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4319                 if (!S_ISDIR(inode->i_mode))
4320                         flags &= ~JFS_DIRSYNC_FL;
4321  
4322 +               if (IS_BARRIER(inode)) {
4323 +                       vxwprintk_task(1, "messing with the barrier.");
4324 +                       return -EACCES;
4325 +               }
4326 +
4327                 /* Is it quota file? Do not allow user to mess with it */
4328                 if (IS_NOQUOTA(inode)) {
4329                         err = -EPERM;
4330 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4331                  * the relevant capability.
4332                  */
4333                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4334 -                       ((flags ^ oldflags) &
4335 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4336 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4337 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4338                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4339                                 mutex_unlock(&inode->i_mutex);
4340                                 err = -EPERM;
4341 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4342                         }
4343                 }
4344  
4345 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4346 +               flags &= JFS_FL_USER_MODIFIABLE;
4347                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4348                 jfs_inode->mode2 = flags;
4349  
4350 diff -NurpP --minimal linux-2.6.32.24/fs/jfs/jfs_dinode.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/jfs_dinode.h
4351 --- linux-2.6.32.24/fs/jfs/jfs_dinode.h 2008-12-25 00:26:37.000000000 +0100
4352 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/jfs_dinode.h 2009-12-03 20:04:56.000000000 +0100
4353 @@ -161,9 +161,13 @@ struct dinode {
4354  
4355  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4356  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4357 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4358  
4359 -#define JFS_FL_USER_VISIBLE    0x03F80000
4360 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4361 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4362 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4363 +
4364 +#define JFS_FL_USER_VISIBLE    0x07F80000
4365 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4366  #define JFS_FL_INHERIT         0x03C80000
4367  
4368  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4369 diff -NurpP --minimal linux-2.6.32.24/fs/jfs/jfs_filsys.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/jfs_filsys.h
4370 --- linux-2.6.32.24/fs/jfs/jfs_filsys.h 2008-12-25 00:26:37.000000000 +0100
4371 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/jfs_filsys.h 2009-12-03 20:04:56.000000000 +0100
4372 @@ -263,6 +263,7 @@
4373  #define JFS_NAME_MAX   255
4374  #define JFS_PATH_MAX   BPSIZE
4375  
4376 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4377  
4378  /*
4379   *     file system state (superblock state)
4380 diff -NurpP --minimal linux-2.6.32.24/fs/jfs/jfs_imap.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/jfs_imap.c
4381 --- linux-2.6.32.24/fs/jfs/jfs_imap.c   2009-09-10 15:26:22.000000000 +0200
4382 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/jfs_imap.c   2009-12-03 20:04:56.000000000 +0100
4383 @@ -45,6 +45,7 @@
4384  #include <linux/buffer_head.h>
4385  #include <linux/pagemap.h>
4386  #include <linux/quotaops.h>
4387 +#include <linux/vs_tag.h>
4388  
4389  #include "jfs_incore.h"
4390  #include "jfs_inode.h"
4391 @@ -3059,6 +3060,8 @@ static int copy_from_dinode(struct dinod
4392  {
4393         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4394         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4395 +       uid_t uid;
4396 +       gid_t gid;
4397  
4398         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4399         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4400 @@ -3079,14 +3082,18 @@ static int copy_from_dinode(struct dinod
4401         }
4402         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4403  
4404 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4405 +       uid = le32_to_cpu(dip->di_uid);
4406 +       gid = le32_to_cpu(dip->di_gid);
4407 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4408 +
4409 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4410         if (sbi->uid == -1)
4411                 ip->i_uid = jfs_ip->saved_uid;
4412         else {
4413                 ip->i_uid = sbi->uid;
4414         }
4415  
4416 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4417 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4418         if (sbi->gid == -1)
4419                 ip->i_gid = jfs_ip->saved_gid;
4420         else {
4421 @@ -3151,14 +3158,12 @@ static void copy_to_dinode(struct dinode
4422         dip->di_size = cpu_to_le64(ip->i_size);
4423         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4424         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4425 -       if (sbi->uid == -1)
4426 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4427 -       else
4428 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4429 -       if (sbi->gid == -1)
4430 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4431 -       else
4432 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4433 +
4434 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4435 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4436 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4437 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4438 +
4439         jfs_get_inode_flags(jfs_ip);
4440         /*
4441          * mode2 is only needed for storing the higher order bits.
4442 diff -NurpP --minimal linux-2.6.32.24/fs/jfs/jfs_inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/jfs_inode.c
4443 --- linux-2.6.32.24/fs/jfs/jfs_inode.c  2009-06-11 17:13:05.000000000 +0200
4444 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/jfs_inode.c  2009-12-03 20:04:56.000000000 +0100
4445 @@ -18,6 +18,7 @@
4446  
4447  #include <linux/fs.h>
4448  #include <linux/quotaops.h>
4449 +#include <linux/vs_tag.h>
4450  #include "jfs_incore.h"
4451  #include "jfs_inode.h"
4452  #include "jfs_filsys.h"
4453 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4454  {
4455         unsigned int flags = JFS_IP(inode)->mode2;
4456  
4457 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4458 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4459 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4460 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4461  
4462         if (flags & JFS_IMMUTABLE_FL)
4463                 inode->i_flags |= S_IMMUTABLE;
4464 +       if (flags & JFS_IXUNLINK_FL)
4465 +               inode->i_flags |= S_IXUNLINK;
4466 +
4467 +       if (flags & JFS_SYNC_FL)
4468 +               inode->i_flags |= S_SYNC;
4469         if (flags & JFS_APPEND_FL)
4470                 inode->i_flags |= S_APPEND;
4471         if (flags & JFS_NOATIME_FL)
4472                 inode->i_flags |= S_NOATIME;
4473         if (flags & JFS_DIRSYNC_FL)
4474                 inode->i_flags |= S_DIRSYNC;
4475 -       if (flags & JFS_SYNC_FL)
4476 -               inode->i_flags |= S_SYNC;
4477 +
4478 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4479 +
4480 +       if (flags & JFS_BARRIER_FL)
4481 +               inode->i_vflags |= V_BARRIER;
4482 +       if (flags & JFS_COW_FL)
4483 +               inode->i_vflags |= V_COW;
4484  }
4485  
4486  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4487  {
4488         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4489 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4490 +
4491 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4492 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4493 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4494 +                          JFS_BARRIER_FL | JFS_COW_FL);
4495  
4496 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4497 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4498         if (flags & S_IMMUTABLE)
4499                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4500 +       if (flags & S_IXUNLINK)
4501 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4502 +
4503         if (flags & S_APPEND)
4504                 jfs_ip->mode2 |= JFS_APPEND_FL;
4505         if (flags & S_NOATIME)
4506 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4507                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4508         if (flags & S_SYNC)
4509                 jfs_ip->mode2 |= JFS_SYNC_FL;
4510 +
4511 +       if (vflags & V_BARRIER)
4512 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4513 +       if (vflags & V_COW)
4514 +               jfs_ip->mode2 |= JFS_COW_FL;
4515  }
4516  
4517  /*
4518 @@ -105,6 +128,7 @@ struct inode *ialloc(struct inode *paren
4519                         mode |= S_ISGID;
4520         } else
4521                 inode->i_gid = current_fsgid();
4522 +       inode->i_tag = dx_current_fstag(sb);
4523  
4524         /*
4525          * New inodes need to save sane values on disk when
4526 diff -NurpP --minimal linux-2.6.32.24/fs/jfs/jfs_inode.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/jfs_inode.h
4527 --- linux-2.6.32.24/fs/jfs/jfs_inode.h  2009-06-11 17:13:05.000000000 +0200
4528 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/jfs_inode.h  2009-12-03 20:04:56.000000000 +0100
4529 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4530  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4531         int fh_len, int fh_type);
4532  extern void jfs_set_inode_flags(struct inode *);
4533 +extern int jfs_sync_flags(struct inode *, int, int);
4534  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4535  
4536  extern const struct address_space_operations jfs_aops;
4537 diff -NurpP --minimal linux-2.6.32.24/fs/jfs/namei.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/namei.c
4538 --- linux-2.6.32.24/fs/jfs/namei.c      2009-12-03 20:02:52.000000000 +0100
4539 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/namei.c      2009-12-03 20:04:56.000000000 +0100
4540 @@ -21,6 +21,7 @@
4541  #include <linux/ctype.h>
4542  #include <linux/quotaops.h>
4543  #include <linux/exportfs.h>
4544 +#include <linux/vs_tag.h>
4545  #include "jfs_incore.h"
4546  #include "jfs_superblock.h"
4547  #include "jfs_inode.h"
4548 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4549                 return ERR_CAST(ip);
4550         }
4551  
4552 +       dx_propagate_tag(nd, ip);
4553         dentry = d_splice_alias(ip, dentry);
4554  
4555         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4556 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4557         .setattr        = jfs_setattr,
4558         .check_acl      = jfs_check_acl,
4559  #endif
4560 +       .sync_flags     = jfs_sync_flags,
4561  };
4562  
4563  const struct file_operations jfs_dir_operations = {
4564 diff -NurpP --minimal linux-2.6.32.24/fs/jfs/super.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/super.c
4565 --- linux-2.6.32.24/fs/jfs/super.c      2009-12-03 20:02:52.000000000 +0100
4566 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/jfs/super.c      2009-12-03 20:04:56.000000000 +0100
4567 @@ -192,7 +192,8 @@ static void jfs_put_super(struct super_b
4568  enum {
4569         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4570         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4571 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4572 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4573 +       Opt_tag, Opt_notag, Opt_tagid
4574  };
4575  
4576  static const match_table_t tokens = {
4577 @@ -202,6 +203,10 @@ static const match_table_t tokens = {
4578         {Opt_resize, "resize=%u"},
4579         {Opt_resize_nosize, "resize"},
4580         {Opt_errors, "errors=%s"},
4581 +       {Opt_tag, "tag"},
4582 +       {Opt_notag, "notag"},
4583 +       {Opt_tagid, "tagid=%u"},
4584 +       {Opt_tag, "tagxid"},
4585         {Opt_ignore, "noquota"},
4586         {Opt_ignore, "quota"},
4587         {Opt_usrquota, "usrquota"},
4588 @@ -336,6 +341,20 @@ static int parse_options(char *options, 
4589                         }
4590                         break;
4591                 }
4592 +#ifndef CONFIG_TAGGING_NONE
4593 +               case Opt_tag:
4594 +                       *flag |= JFS_TAGGED;
4595 +                       break;
4596 +               case Opt_notag:
4597 +                       *flag &= JFS_TAGGED;
4598 +                       break;
4599 +#endif
4600 +#ifdef CONFIG_PROPAGATE
4601 +               case Opt_tagid:
4602 +                       /* use args[0] */
4603 +                       *flag |= JFS_TAGGED;
4604 +                       break;
4605 +#endif
4606                 default:
4607                         printk("jfs: Unrecognized mount option \"%s\" "
4608                                         " or missing value\n", p);
4609 @@ -366,6 +385,12 @@ static int jfs_remount(struct super_bloc
4610         if (!parse_options(data, sb, &newLVSize, &flag)) {
4611                 return -EINVAL;
4612         }
4613 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4614 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4615 +                       sb->s_id);
4616 +               return -EINVAL;
4617 +       }
4618 +
4619         lock_kernel();
4620         if (newLVSize) {
4621                 if (sb->s_flags & MS_RDONLY) {
4622 @@ -449,6 +474,9 @@ static int jfs_fill_super(struct super_b
4623  #ifdef CONFIG_JFS_POSIX_ACL
4624         sb->s_flags |= MS_POSIXACL;
4625  #endif
4626 +       /* map mount option tagxid */
4627 +       if (sbi->flag & JFS_TAGGED)
4628 +               sb->s_flags |= MS_TAGGED;
4629  
4630         if (newLVSize) {
4631                 printk(KERN_ERR "resize option for remount only\n");
4632 diff -NurpP --minimal linux-2.6.32.24/fs/libfs.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/libfs.c
4633 --- linux-2.6.32.24/fs/libfs.c  2010-10-04 08:56:13.000000000 +0200
4634 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/libfs.c  2010-07-08 02:22:31.000000000 +0200
4635 @@ -127,7 +127,8 @@ static inline unsigned char dt_type(stru
4636   * both impossible due to the lock on directory.
4637   */
4638  
4639 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4640 +static inline int do_dcache_readdir_filter(struct file *filp,
4641 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4642  {
4643         struct dentry *dentry = filp->f_path.dentry;
4644         struct dentry *cursor = filp->private_data;
4645 @@ -160,6 +161,8 @@ int dcache_readdir(struct file * filp, v
4646                                 next = list_entry(p, struct dentry, d_u.d_child);
4647                                 if (d_unhashed(next) || !next->d_inode)
4648                                         continue;
4649 +                               if (filter && !filter(next))
4650 +                                       continue;
4651  
4652                                 spin_unlock(&dcache_lock);
4653                                 if (filldir(dirent, next->d_name.name, 
4654 @@ -178,6 +181,18 @@ int dcache_readdir(struct file * filp, v
4655         return 0;
4656  }
4657  
4658 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4659 +{
4660 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4661 +}
4662 +
4663 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4664 +       int (*filter)(struct dentry *))
4665 +{
4666 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4667 +}
4668 +
4669 +
4670  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4671  {
4672         return -EISDIR;
4673 @@ -842,6 +857,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4674  EXPORT_SYMBOL(dcache_dir_lseek);
4675  EXPORT_SYMBOL(dcache_dir_open);
4676  EXPORT_SYMBOL(dcache_readdir);
4677 +EXPORT_SYMBOL(dcache_readdir_filter);
4678  EXPORT_SYMBOL(generic_read_dir);
4679  EXPORT_SYMBOL(get_sb_pseudo);
4680  EXPORT_SYMBOL(simple_write_begin);
4681 diff -NurpP --minimal linux-2.6.32.24/fs/locks.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/locks.c
4682 --- linux-2.6.32.24/fs/locks.c  2009-12-03 20:02:52.000000000 +0100
4683 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/locks.c  2009-12-03 20:04:56.000000000 +0100
4684 @@ -127,6 +127,8 @@
4685  #include <linux/time.h>
4686  #include <linux/rcupdate.h>
4687  #include <linux/pid_namespace.h>
4688 +#include <linux/vs_base.h>
4689 +#include <linux/vs_limit.h>
4690  
4691  #include <asm/uaccess.h>
4692  
4693 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4694  /* Allocate an empty lock structure. */
4695  static struct file_lock *locks_alloc_lock(void)
4696  {
4697 +       if (!vx_locks_avail(1))
4698 +               return NULL;
4699         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4700  }
4701  
4702 @@ -174,6 +178,7 @@ static void locks_free_lock(struct file_
4703         BUG_ON(!list_empty(&fl->fl_block));
4704         BUG_ON(!list_empty(&fl->fl_link));
4705  
4706 +       vx_locks_dec(fl);
4707         locks_release_private(fl);
4708         kmem_cache_free(filelock_cache, fl);
4709  }
4710 @@ -194,6 +199,7 @@ void locks_init_lock(struct file_lock *f
4711         fl->fl_start = fl->fl_end = 0;
4712         fl->fl_ops = NULL;
4713         fl->fl_lmops = NULL;
4714 +       fl->fl_xid = -1;
4715  }
4716  
4717  EXPORT_SYMBOL(locks_init_lock);
4718 @@ -248,6 +254,7 @@ void locks_copy_lock(struct file_lock *n
4719         new->fl_file = fl->fl_file;
4720         new->fl_ops = fl->fl_ops;
4721         new->fl_lmops = fl->fl_lmops;
4722 +       new->fl_xid = fl->fl_xid;
4723  
4724         locks_copy_private(new, fl);
4725  }
4726 @@ -286,6 +293,11 @@ static int flock_make_lock(struct file *
4727         fl->fl_flags = FL_FLOCK;
4728         fl->fl_type = type;
4729         fl->fl_end = OFFSET_MAX;
4730 +
4731 +       vxd_assert(filp->f_xid == vx_current_xid(),
4732 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4733 +       fl->fl_xid = filp->f_xid;
4734 +       vx_locks_inc(fl);
4735         
4736         *lock = fl;
4737         return 0;
4738 @@ -451,6 +463,7 @@ static int lease_init(struct file *filp,
4739  
4740         fl->fl_owner = current->files;
4741         fl->fl_pid = current->tgid;
4742 +       fl->fl_xid = vx_current_xid();
4743  
4744         fl->fl_file = filp;
4745         fl->fl_flags = FL_LEASE;
4746 @@ -470,6 +483,11 @@ static struct file_lock *lease_alloc(str
4747         if (fl == NULL)
4748                 return ERR_PTR(error);
4749  
4750 +       fl->fl_xid = vx_current_xid();
4751 +       if (filp)
4752 +               vxd_assert(filp->f_xid == fl->fl_xid,
4753 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4754 +       vx_locks_inc(fl);
4755         error = lease_init(filp, type, fl);
4756         if (error) {
4757                 locks_free_lock(fl);
4758 @@ -770,6 +788,7 @@ static int flock_lock_file(struct file *
4759         if (found)
4760                 cond_resched();
4761  
4762 +       new_fl->fl_xid = -1;
4763  find_conflict:
4764         for_each_lock(inode, before) {
4765                 struct file_lock *fl = *before;
4766 @@ -790,6 +809,7 @@ find_conflict:
4767                 goto out;
4768         locks_copy_lock(new_fl, request);
4769         locks_insert_lock(before, new_fl);
4770 +       vx_locks_inc(new_fl);
4771         new_fl = NULL;
4772         error = 0;
4773  
4774 @@ -800,7 +820,8 @@ out:
4775         return error;
4776  }
4777  
4778 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4779 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4780 +       struct file_lock *conflock, xid_t xid)
4781  {
4782         struct file_lock *fl;
4783         struct file_lock *new_fl = NULL;
4784 @@ -810,6 +831,8 @@ static int __posix_lock_file(struct inod
4785         struct file_lock **before;
4786         int error, added = 0;
4787  
4788 +       vxd_assert(xid == vx_current_xid(),
4789 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4790         /*
4791          * We may need two file_lock structures for this operation,
4792          * so we get them in advance to avoid races.
4793 @@ -820,7 +843,11 @@ static int __posix_lock_file(struct inod
4794             (request->fl_type != F_UNLCK ||
4795              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4796                 new_fl = locks_alloc_lock();
4797 +               new_fl->fl_xid = xid;
4798 +               vx_locks_inc(new_fl);
4799                 new_fl2 = locks_alloc_lock();
4800 +               new_fl2->fl_xid = xid;
4801 +               vx_locks_inc(new_fl2);
4802         }
4803  
4804         lock_kernel();
4805 @@ -1019,7 +1046,8 @@ static int __posix_lock_file(struct inod
4806  int posix_lock_file(struct file *filp, struct file_lock *fl,
4807                         struct file_lock *conflock)
4808  {
4809 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4810 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4811 +               fl, conflock, filp->f_xid);
4812  }
4813  EXPORT_SYMBOL(posix_lock_file);
4814  
4815 @@ -1109,7 +1137,7 @@ int locks_mandatory_area(int read_write,
4816         fl.fl_end = offset + count - 1;
4817  
4818         for (;;) {
4819 -               error = __posix_lock_file(inode, &fl, NULL);
4820 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4821                 if (error != FILE_LOCK_DEFERRED)
4822                         break;
4823                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4824 @@ -1424,6 +1452,7 @@ int generic_setlease(struct file *filp, 
4825  
4826         locks_copy_lock(new_fl, lease);
4827         locks_insert_lock(before, new_fl);
4828 +       vx_locks_inc(new_fl);
4829  
4830         *flp = new_fl;
4831         return 0;
4832 @@ -1779,6 +1808,11 @@ int fcntl_setlk(unsigned int fd, struct 
4833         if (file_lock == NULL)
4834                 return -ENOLCK;
4835  
4836 +       vxd_assert(filp->f_xid == vx_current_xid(),
4837 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4838 +       file_lock->fl_xid = filp->f_xid;
4839 +       vx_locks_inc(file_lock);
4840 +
4841         /*
4842          * This might block, so we do it before checking the inode.
4843          */
4844 @@ -1897,6 +1931,11 @@ int fcntl_setlk64(unsigned int fd, struc
4845         if (file_lock == NULL)
4846                 return -ENOLCK;
4847  
4848 +       vxd_assert(filp->f_xid == vx_current_xid(),
4849 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4850 +       file_lock->fl_xid = filp->f_xid;
4851 +       vx_locks_inc(file_lock);
4852 +
4853         /*
4854          * This might block, so we do it before checking the inode.
4855          */
4856 @@ -2162,8 +2201,11 @@ static int locks_show(struct seq_file *f
4857  
4858         lock_get_status(f, fl, (long)f->private, "");
4859  
4860 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4861 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4862 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4863 +                       continue;
4864                 lock_get_status(f, bfl, (long)f->private, " ->");
4865 +       }
4866  
4867         f->private++;
4868         return 0;
4869 diff -NurpP --minimal linux-2.6.32.24/fs/namei.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/namei.c
4870 --- linux-2.6.32.24/fs/namei.c  2010-10-04 08:56:13.000000000 +0200
4871 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/namei.c  2010-03-18 16:53:06.000000000 +0100
4872 @@ -33,6 +33,14 @@
4873  #include <linux/fcntl.h>
4874  #include <linux/device_cgroup.h>
4875  #include <linux/fs_struct.h>
4876 +#include <linux/proc_fs.h>
4877 +#include <linux/vserver/inode.h>
4878 +#include <linux/vs_base.h>
4879 +#include <linux/vs_tag.h>
4880 +#include <linux/vs_cowbl.h>
4881 +#include <linux/vs_device.h>
4882 +#include <linux/vs_context.h>
4883 +#include <linux/pid_namespace.h>
4884  #include <asm/uaccess.h>
4885  
4886  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
4887 @@ -169,6 +177,77 @@ void putname(const char *name)
4888  EXPORT_SYMBOL(putname);
4889  #endif
4890  
4891 +static inline int dx_barrier(const struct inode *inode)
4892 +{
4893 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4894 +               vxwprintk_task(1, "did hit the barrier.");
4895 +               return 1;
4896 +       }
4897 +       return 0;
4898 +}
4899 +
4900 +static int __dx_permission(const struct inode *inode, int mask)
4901 +{
4902 +       if (dx_barrier(inode))
4903 +               return -EACCES;
4904 +
4905 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4906 +               /* devpts is xid tagged */
4907 +               if (S_ISDIR(inode->i_mode) ||
4908 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4909 +                       return 0;
4910 +       }
4911 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4912 +               struct proc_dir_entry *de = PDE(inode);
4913 +
4914 +               if (de && !vx_hide_check(0, de->vx_flags))
4915 +                       goto out;
4916 +
4917 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4918 +                       struct pid *pid;
4919 +                       struct task_struct *tsk;
4920 +
4921 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4922 +                           vx_flags(VXF_STATE_SETUP, 0))
4923 +                               return 0;
4924 +
4925 +                       pid = PROC_I(inode)->pid;
4926 +                       if (!pid)
4927 +                               goto out;
4928 +
4929 +                       tsk = pid_task(pid, PIDTYPE_PID);
4930 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4931 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4932 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4933 +                               return 0;
4934 +               }
4935 +               else {
4936 +                       /* FIXME: Should we block some entries here? */
4937 +                       return 0;
4938 +               }
4939 +       }
4940 +       else {
4941 +               if (dx_notagcheck(inode->i_sb) ||
4942 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4943 +                            DX_IDENT))
4944 +                       return 0;
4945 +       }
4946 +
4947 +out:
4948 +       return -EACCES;
4949 +}
4950 +
4951 +int dx_permission(const struct inode *inode, int mask)
4952 +{
4953 +       int ret = __dx_permission(inode, mask);
4954 +       if (unlikely(ret)) {
4955 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4956 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4957 +                       inode->i_ino);
4958 +       }
4959 +       return ret;
4960 +}
4961 +
4962  /*
4963   * This does basic POSIX ACL permission checking
4964   */
4965 @@ -269,10 +348,14 @@ int inode_permission(struct inode *inode
4966                 /*
4967                  * Nobody gets write access to an immutable file.
4968                  */
4969 -               if (IS_IMMUTABLE(inode))
4970 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4971                         return -EACCES;
4972         }
4973  
4974 +       retval = dx_permission(inode, mask);
4975 +       if (retval)
4976 +               return retval;
4977 +
4978         if (inode->i_op->permission)
4979                 retval = inode->i_op->permission(inode, mask);
4980         else
4981 @@ -448,6 +531,9 @@ static int exec_permission_lite(struct i
4982  {
4983         int ret;
4984  
4985 +       if (dx_barrier(inode))
4986 +               return -EACCES;
4987 +
4988         if (inode->i_op->permission) {
4989                 ret = inode->i_op->permission(inode, MAY_EXEC);
4990                 if (!ret)
4991 @@ -763,7 +849,8 @@ static __always_inline void follow_dotdo
4992  
4993                 if (nd->path.dentry == nd->root.dentry &&
4994                     nd->path.mnt == nd->root.mnt) {
4995 -                       break;
4996 +                       /* for sane '/' avoid follow_mount() */
4997 +                       return;
4998                 }
4999                 spin_lock(&dcache_lock);
5000                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5001 @@ -799,16 +886,30 @@ static int do_lookup(struct nameidata *n
5002  {
5003         struct vfsmount *mnt = nd->path.mnt;
5004         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
5005 +       struct inode *inode;
5006  
5007         if (!dentry)
5008                 goto need_lookup;
5009         if (dentry->d_op && dentry->d_op->d_revalidate)
5010                 goto need_revalidate;
5011 +       inode = dentry->d_inode;
5012 +       if (!inode)
5013 +               goto done;
5014 +
5015 +       if (__dx_permission(inode, MAY_ACCESS))
5016 +               goto hidden;
5017 +
5018  done:
5019         path->mnt = mnt;
5020         path->dentry = dentry;
5021         __follow_mount(path);
5022         return 0;
5023 +hidden:
5024 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s/%.*s«.",
5025 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5026 +               vxd_path(&nd->path), name->len, name->name);
5027 +       dput(dentry);
5028 +       return -ENOENT;
5029  
5030  need_lookup:
5031         dentry = real_lookup(nd->path.dentry, name, nd);
5032 @@ -1400,7 +1501,7 @@ static int may_delete(struct inode *dir,
5033         if (IS_APPEND(dir))
5034                 return -EPERM;
5035         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5036 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5037 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5038                 return -EPERM;
5039         if (isdir) {
5040                 if (!S_ISDIR(victim->d_inode->i_mode))
5041 @@ -1540,6 +1641,14 @@ int may_open(struct path *path, int acc_
5042                 break;
5043         }
5044  
5045 +#ifdef CONFIG_VSERVER_COWBL
5046 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5047 +               if (IS_COW_LINK(inode))
5048 +                       return -EMLINK;
5049 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5050 +               mark_inode_dirty(inode);
5051 +       }
5052 +#endif
5053         error = inode_permission(inode, acc_mode);
5054         if (error)
5055                 return error;
5056 @@ -1688,7 +1797,11 @@ struct file *do_filp_open(int dfd, const
5057         int count = 0;
5058         int will_write;
5059         int flag = open_to_namei_flags(open_flag);
5060 -
5061 +#ifdef CONFIG_VSERVER_COWBL
5062 +       int rflag = flag;
5063 +       int rmode = mode;
5064 +restart:
5065 +#endif
5066         if (!acc_mode)
5067                 acc_mode = MAY_OPEN | ACC_MODE(flag);
5068  
5069 @@ -1836,6 +1949,25 @@ ok:
5070                         goto exit;
5071         }
5072         error = may_open(&nd.path, acc_mode, flag);
5073 +#ifdef CONFIG_VSERVER_COWBL
5074 +       if (error == -EMLINK) {
5075 +               struct dentry *dentry;
5076 +               dentry = cow_break_link(pathname);
5077 +               if (IS_ERR(dentry)) {
5078 +                       error = PTR_ERR(dentry);
5079 +                       goto exit_cow;
5080 +               }
5081 +               dput(dentry);
5082 +               if (will_write)
5083 +                       mnt_drop_write(nd.path.mnt);
5084 +               release_open_intent(&nd);
5085 +               path_put(&nd.path);
5086 +               flag = rflag;
5087 +               mode = rmode;
5088 +               goto restart;
5089 +       }
5090 +exit_cow:
5091 +#endif
5092         if (error) {
5093                 if (will_write)
5094                         mnt_drop_write(nd.path.mnt);
5095 @@ -1998,9 +2130,17 @@ int vfs_mknod(struct inode *dir, struct 
5096         if (error)
5097                 return error;
5098  
5099 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5100 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5101 +               goto okay;
5102 +
5103 +       if (!capable(CAP_MKNOD))
5104                 return -EPERM;
5105  
5106 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5107 +               return -EPERM;
5108 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5109 +               return -EPERM;
5110 +okay:
5111         if (!dir->i_op->mknod)
5112                 return -EPERM;
5113  
5114 @@ -2467,7 +2607,7 @@ int vfs_link(struct dentry *old_dentry, 
5115         /*
5116          * A link to an append-only or immutable file cannot be created.
5117          */
5118 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5119 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5120                 return -EPERM;
5121         if (!dir->i_op->link)
5122                 return -EPERM;
5123 @@ -2840,6 +2980,219 @@ int vfs_follow_link(struct nameidata *nd
5124         return __vfs_follow_link(nd, link);
5125  }
5126  
5127 +
5128 +#ifdef CONFIG_VSERVER_COWBL
5129 +
5130 +#include <linux/file.h>
5131 +
5132 +static inline
5133 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5134 +{
5135 +       loff_t ppos = 0;
5136 +
5137 +       return do_splice_direct(in, &ppos, out, len, 0);
5138 +}
5139 +
5140 +struct dentry *cow_break_link(const char *pathname)
5141 +{
5142 +       int ret, mode, pathlen, redo = 0;
5143 +       struct nameidata old_nd, dir_nd;
5144 +       struct path old_path, new_path;
5145 +       struct dentry *dir, *res = NULL;
5146 +       struct file *old_file;
5147 +       struct file *new_file;
5148 +       char *to, *path, pad='\251';
5149 +       loff_t size;
5150 +
5151 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5152 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5153 +       ret = -ENOMEM;
5154 +       if (!path)
5155 +               goto out;
5156 +
5157 +       /* old_nd will have refs to dentry and mnt */
5158 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5159 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5160 +       if (ret < 0)
5161 +               goto out_free_path;
5162 +
5163 +       old_path = old_nd.path;
5164 +       mode = old_path.dentry->d_inode->i_mode;
5165 +
5166 +       to = d_path(&old_path, path, PATH_MAX-2);
5167 +       pathlen = strlen(to);
5168 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5169 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5170 +               old_path.dentry->d_name.len);
5171 +
5172 +       to[pathlen + 1] = 0;
5173 +retry:
5174 +       to[pathlen] = pad--;
5175 +       ret = -EMLINK;
5176 +       if (pad <= '\240')
5177 +               goto out_rel_old;
5178 +
5179 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5180 +       /* dir_nd will have refs to dentry and mnt */
5181 +       ret = path_lookup(to,
5182 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5183 +       vxdprintk(VXD_CBIT(misc, 2),
5184 +               "path_lookup(new): %d", ret);
5185 +       if (ret < 0)
5186 +               goto retry;
5187 +
5188 +       /* this puppy downs the inode mutex */
5189 +       new_path.dentry = lookup_create(&dir_nd, 0);
5190 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5191 +               vxdprintk(VXD_CBIT(misc, 2),
5192 +                       "lookup_create(new): %p", new_path.dentry);
5193 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5194 +               path_put(&dir_nd.path);
5195 +               goto retry;
5196 +       }
5197 +       vxdprintk(VXD_CBIT(misc, 2),
5198 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5199 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5200 +               new_path.dentry->d_name.len);
5201 +       dir = dir_nd.path.dentry;
5202 +
5203 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5204 +       vxdprintk(VXD_CBIT(misc, 2),
5205 +               "vfs_create(new): %d", ret);
5206 +       if (ret == -EEXIST) {
5207 +               mutex_unlock(&dir->d_inode->i_mutex);
5208 +               dput(new_path.dentry);
5209 +               path_put(&dir_nd.path);
5210 +               goto retry;
5211 +       }
5212 +       else if (ret < 0)
5213 +               goto out_unlock_new;
5214 +
5215 +       /* drop out early, ret passes ENOENT */
5216 +       ret = -ENOENT;
5217 +       if ((redo = d_unhashed(old_path.dentry)))
5218 +               goto out_unlock_new;
5219 +
5220 +       new_path.mnt = dir_nd.path.mnt;
5221 +       dget(old_path.dentry);
5222 +       mntget(old_path.mnt);
5223 +       /* this one cleans up the dentry/mnt in case of failure */
5224 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5225 +               O_RDONLY, current_cred());
5226 +       vxdprintk(VXD_CBIT(misc, 2),
5227 +               "dentry_open(old): %p", old_file);
5228 +       if (!old_file || IS_ERR(old_file)) {
5229 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5230 +               goto out_unlock_new;
5231 +       }
5232 +
5233 +       dget(new_path.dentry);
5234 +       mntget(new_path.mnt);
5235 +       /* this one cleans up the dentry/mnt in case of failure */
5236 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5237 +               O_WRONLY, current_cred());
5238 +       vxdprintk(VXD_CBIT(misc, 2),
5239 +               "dentry_open(new): %p", new_file);
5240 +
5241 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5242 +       if (!new_file || IS_ERR(new_file))
5243 +               goto out_fput_old;
5244 +
5245 +       size = i_size_read(old_file->f_dentry->d_inode);
5246 +       ret = do_cow_splice(old_file, new_file, size);
5247 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5248 +       if (ret < 0) {
5249 +               goto out_fput_both;
5250 +       } else if (ret < size) {
5251 +               ret = -ENOSPC;
5252 +               goto out_fput_both;
5253 +       } else {
5254 +               struct inode *old_inode = old_path.dentry->d_inode;
5255 +               struct inode *new_inode = new_path.dentry->d_inode;
5256 +               struct iattr attr = {
5257 +                       .ia_uid = old_inode->i_uid,
5258 +                       .ia_gid = old_inode->i_gid,
5259 +                       .ia_valid = ATTR_UID | ATTR_GID
5260 +                       };
5261 +
5262 +               ret = inode_setattr(new_inode, &attr);
5263 +               if (ret)
5264 +                       goto out_fput_both;
5265 +       }
5266 +
5267 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5268 +
5269 +       /* drop out late */
5270 +       ret = -ENOENT;
5271 +       if ((redo = d_unhashed(old_path.dentry)))
5272 +               goto out_unlock;
5273 +
5274 +       vxdprintk(VXD_CBIT(misc, 2),
5275 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5276 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5277 +               new_path.dentry->d_name.len,
5278 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5279 +               old_path.dentry->d_name.len);
5280 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5281 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5282 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5283 +       res = new_path.dentry;
5284 +
5285 +out_unlock:
5286 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5287 +
5288 +out_fput_both:
5289 +       vxdprintk(VXD_CBIT(misc, 3),
5290 +               "fput(new_file=%p[#%ld])", new_file,
5291 +               atomic_long_read(&new_file->f_count));
5292 +       fput(new_file);
5293 +
5294 +out_fput_old:
5295 +       vxdprintk(VXD_CBIT(misc, 3),
5296 +               "fput(old_file=%p[#%ld])", old_file,
5297 +               atomic_long_read(&old_file->f_count));
5298 +       fput(old_file);
5299 +
5300 +out_unlock_new:
5301 +       mutex_unlock(&dir->d_inode->i_mutex);
5302 +       if (!ret)
5303 +               goto out_redo;
5304 +
5305 +       /* error path cleanup */
5306 +       vfs_unlink(dir->d_inode, new_path.dentry);
5307 +       dput(new_path.dentry);
5308 +
5309 +out_redo:
5310 +       if (!redo)
5311 +               goto out_rel_both;
5312 +       /* lookup dentry once again */
5313 +       path_put(&old_nd.path);
5314 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5315 +       if (ret)
5316 +               goto out_rel_both;
5317 +
5318 +       new_path.dentry = old_nd.path.dentry;
5319 +       vxdprintk(VXD_CBIT(misc, 2),
5320 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5321 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5322 +               new_path.dentry->d_name.len);
5323 +       dget(new_path.dentry);
5324 +       res = new_path.dentry;
5325 +
5326 +out_rel_both:
5327 +       path_put(&dir_nd.path);
5328 +out_rel_old:
5329 +       path_put(&old_nd.path);
5330 +out_free_path:
5331 +       kfree(path);
5332 +out:
5333 +       if (ret)
5334 +               res = ERR_PTR(ret);
5335 +       return res;
5336 +}
5337 +
5338 +#endif
5339 +
5340  /* get the link contents into pagecache */
5341  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5342  {
5343 diff -NurpP --minimal linux-2.6.32.24/fs/namespace.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/namespace.c
5344 --- linux-2.6.32.24/fs/namespace.c      2010-10-04 08:56:13.000000000 +0200
5345 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/namespace.c      2010-07-08 02:22:31.000000000 +0200
5346 @@ -29,6 +29,11 @@
5347  #include <linux/log2.h>
5348  #include <linux/idr.h>
5349  #include <linux/fs_struct.h>
5350 +#include <linux/vs_base.h>
5351 +#include <linux/vs_context.h>
5352 +#include <linux/vs_tag.h>
5353 +#include <linux/vserver/space.h>
5354 +#include <linux/vserver/global.h>
5355  #include <asm/uaccess.h>
5356  #include <asm/unistd.h>
5357  #include "pnode.h"
5358 @@ -567,6 +572,7 @@ static struct vfsmount *clone_mnt(struct
5359                 mnt->mnt_root = dget(root);
5360                 mnt->mnt_mountpoint = mnt->mnt_root;
5361                 mnt->mnt_parent = mnt;
5362 +               mnt->mnt_tag = old->mnt_tag;
5363  
5364                 if (flag & CL_SLAVE) {
5365                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5366 @@ -661,6 +667,31 @@ static inline void mangle(struct seq_fil
5367         seq_escape(m, s, " \t\n\\");
5368  }
5369  
5370 +static int mnt_is_reachable(struct vfsmount *mnt)
5371 +{
5372 +       struct path root;
5373 +       struct dentry *point;
5374 +       int ret;
5375 +
5376 +       if (mnt == mnt->mnt_ns->root)
5377 +               return 1;
5378 +
5379 +       spin_lock(&vfsmount_lock);
5380 +       root = current->fs->root;
5381 +       point = root.dentry;
5382 +
5383 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5384 +               point = mnt->mnt_mountpoint;
5385 +               mnt = mnt->mnt_parent;
5386 +       }
5387 +
5388 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5389 +
5390 +       spin_unlock(&vfsmount_lock);
5391 +
5392 +       return ret;
5393 +}
5394 +
5395  /*
5396   * Simple .show_options callback for filesystems which don't want to
5397   * implement more complex mount option showing.
5398 @@ -748,6 +779,8 @@ static int show_sb_opts(struct seq_file 
5399                 { MS_SYNCHRONOUS, ",sync" },
5400                 { MS_DIRSYNC, ",dirsync" },
5401                 { MS_MANDLOCK, ",mand" },
5402 +               { MS_TAGGED, ",tag" },
5403 +               { MS_NOTAGCHECK, ",notagcheck" },
5404                 { 0, NULL }
5405         };
5406         const struct proc_fs_info *fs_infop;
5407 @@ -795,10 +828,20 @@ static int show_vfsmnt(struct seq_file *
5408         int err = 0;
5409         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5410  
5411 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5412 -       seq_putc(m, ' ');
5413 -       seq_path(m, &mnt_path, " \t\n\\");
5414 -       seq_putc(m, ' ');
5415 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5416 +               return SEQ_SKIP;
5417 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5418 +               return SEQ_SKIP;
5419 +
5420 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5421 +               mnt == current->fs->root.mnt) {
5422 +               seq_puts(m, "/dev/root / ");
5423 +       } else {
5424 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5425 +               seq_putc(m, ' ');
5426 +               seq_path(m, &mnt_path, " \t\n\\");
5427 +               seq_putc(m, ' ');
5428 +       }
5429         show_type(m, mnt->mnt_sb);
5430         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5431         err = show_sb_opts(m, mnt->mnt_sb);
5432 @@ -828,6 +871,11 @@ static int show_mountinfo(struct seq_fil
5433         struct path root = p->root;
5434         int err = 0;
5435  
5436 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5437 +               return SEQ_SKIP;
5438 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5439 +               return SEQ_SKIP;
5440 +
5441         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5442                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5443         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5444 @@ -886,17 +934,27 @@ static int show_vfsstat(struct seq_file 
5445         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5446         int err = 0;
5447  
5448 -       /* device */
5449 -       if (mnt->mnt_devname) {
5450 -               seq_puts(m, "device ");
5451 -               mangle(m, mnt->mnt_devname);
5452 -       } else
5453 -               seq_puts(m, "no device");
5454 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5455 +               return SEQ_SKIP;
5456 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5457 +               return SEQ_SKIP;
5458  
5459 -       /* mount point */
5460 -       seq_puts(m, " mounted on ");
5461 -       seq_path(m, &mnt_path, " \t\n\\");
5462 -       seq_putc(m, ' ');
5463 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5464 +               mnt == current->fs->root.mnt) {
5465 +               seq_puts(m, "device /dev/root mounted on / ");
5466 +       } else {
5467 +               /* device */
5468 +               if (mnt->mnt_devname) {
5469 +                       seq_puts(m, "device ");
5470 +                       mangle(m, mnt->mnt_devname);
5471 +               } else
5472 +                       seq_puts(m, "no device");
5473 +
5474 +               /* mount point */
5475 +               seq_puts(m, " mounted on ");
5476 +               seq_path(m, &mnt_path, " \t\n\\");
5477 +               seq_putc(m, ' ');
5478 +       }
5479  
5480         /* file system type */
5481         seq_puts(m, "with fstype ");
5482 @@ -1137,7 +1195,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5483                 goto dput_and_out;
5484  
5485         retval = -EPERM;
5486 -       if (!capable(CAP_SYS_ADMIN))
5487 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5488                 goto dput_and_out;
5489  
5490         retval = do_umount(path.mnt, flags);
5491 @@ -1163,7 +1221,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5492  
5493  static int mount_is_safe(struct path *path)
5494  {
5495 -       if (capable(CAP_SYS_ADMIN))
5496 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5497                 return 0;
5498         return -EPERM;
5499  #ifdef notyet
5500 @@ -1427,7 +1485,7 @@ static int do_change_type(struct path *p
5501         int type = flag & ~MS_REC;
5502         int err = 0;
5503  
5504 -       if (!capable(CAP_SYS_ADMIN))
5505 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5506                 return -EPERM;
5507  
5508         if (path->dentry != path->mnt->mnt_root)
5509 @@ -1454,11 +1512,13 @@ static int do_change_type(struct path *p
5510   * do loopback mount.
5511   */
5512  static int do_loopback(struct path *path, char *old_name,
5513 -                               int recurse)
5514 +       tag_t tag, unsigned long flags, int mnt_flags)
5515  {
5516         struct path old_path;
5517         struct vfsmount *mnt = NULL;
5518         int err = mount_is_safe(path);
5519 +       int recurse = flags & MS_REC;
5520 +
5521         if (err)
5522                 return err;
5523         if (!old_name || !*old_name)
5524 @@ -1492,6 +1552,7 @@ static int do_loopback(struct path *path
5525                 spin_unlock(&vfsmount_lock);
5526                 release_mounts(&umount_list);
5527         }
5528 +       mnt->mnt_flags = mnt_flags;
5529  
5530  out:
5531         up_write(&namespace_sem);
5532 @@ -1522,12 +1583,12 @@ static int change_mount_flags(struct vfs
5533   * on it - tough luck.
5534   */
5535  static int do_remount(struct path *path, int flags, int mnt_flags,
5536 -                     void *data)
5537 +       void *data, xid_t xid)
5538  {
5539         int err;
5540         struct super_block *sb = path->mnt->mnt_sb;
5541  
5542 -       if (!capable(CAP_SYS_ADMIN))
5543 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5544                 return -EPERM;
5545  
5546         if (!check_mnt(path->mnt))
5547 @@ -1569,7 +1630,7 @@ static int do_move_mount(struct path *pa
5548         struct path old_path, parent_path;
5549         struct vfsmount *p;
5550         int err = 0;
5551 -       if (!capable(CAP_SYS_ADMIN))
5552 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5553                 return -EPERM;
5554         if (!old_name || !*old_name)
5555                 return -EINVAL;
5556 @@ -1651,7 +1712,7 @@ static int do_new_mount(struct path *pat
5557                 return -EINVAL;
5558  
5559         /* we need capabilities... */
5560 -       if (!capable(CAP_SYS_ADMIN))
5561 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5562                 return -EPERM;
5563  
5564         lock_kernel();
5565 @@ -1915,6 +1976,7 @@ long do_mount(char *dev_name, char *dir_
5566         struct path path;
5567         int retval = 0;
5568         int mnt_flags = 0;
5569 +       tag_t tag = 0;
5570  
5571         /* Discard magic */
5572         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5573 @@ -1932,6 +1994,12 @@ long do_mount(char *dev_name, char *dir_
5574         if (!(flags & MS_NOATIME))
5575                 mnt_flags |= MNT_RELATIME;
5576  
5577 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5578 +               /* FIXME: bind and re-mounts get the tag flag? */
5579 +               if (flags & (MS_BIND|MS_REMOUNT))
5580 +                       flags |= MS_TAGID;
5581 +       }
5582 +
5583         /* Separate the per-mountpoint flags */
5584         if (flags & MS_NOSUID)
5585                 mnt_flags |= MNT_NOSUID;
5586 @@ -1948,6 +2016,8 @@ long do_mount(char *dev_name, char *dir_
5587         if (flags & MS_RDONLY)
5588                 mnt_flags |= MNT_READONLY;
5589  
5590 +       if (!capable(CAP_SYS_ADMIN))
5591 +               mnt_flags |= MNT_NODEV;
5592         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5593                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5594                    MS_STRICTATIME);
5595 @@ -1964,9 +2034,9 @@ long do_mount(char *dev_name, char *dir_
5596  
5597         if (flags & MS_REMOUNT)
5598                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5599 -                                   data_page);
5600 +                                   data_page, tag);
5601         else if (flags & MS_BIND)
5602 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5603 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5604         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5605                 retval = do_change_type(&path, flags);
5606         else if (flags & MS_MOVE)
5607 @@ -2045,6 +2115,7 @@ static struct mnt_namespace *dup_mnt_ns(
5608                 q = next_mnt(q, new_ns->root);
5609         }
5610         up_write(&namespace_sem);
5611 +       atomic_inc(&vs_global_mnt_ns);
5612  
5613         if (rootmnt)
5614                 mntput(rootmnt);
5615 @@ -2189,9 +2260,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5616         down_write(&namespace_sem);
5617         mutex_lock(&old.dentry->d_inode->i_mutex);
5618         error = -EINVAL;
5619 -       if (IS_MNT_SHARED(old.mnt) ||
5620 +       if ((IS_MNT_SHARED(old.mnt) ||
5621                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5622 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5623 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5624 +               !vx_flags(VXF_STATE_SETUP, 0))
5625                 goto out2;
5626         if (!check_mnt(root.mnt))
5627                 goto out2;
5628 @@ -2327,6 +2399,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5629         spin_unlock(&vfsmount_lock);
5630         up_write(&namespace_sem);
5631         release_mounts(&umount_list);
5632 +       atomic_dec(&vs_global_mnt_ns);
5633         kfree(ns);
5634  }
5635  EXPORT_SYMBOL(put_mnt_ns);
5636 diff -NurpP --minimal linux-2.6.32.24/fs/nfs/client.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/client.c
5637 --- linux-2.6.32.24/fs/nfs/client.c     2010-10-04 08:56:13.000000000 +0200
5638 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/client.c     2010-09-22 00:48:38.000000000 +0200
5639 @@ -738,6 +738,9 @@ static int nfs_init_server_rpcclient(str
5640         if (server->flags & NFS_MOUNT_SOFT)
5641                 server->client->cl_softrtry = 1;
5642  
5643 +       server->client->cl_tag = 0;
5644 +       if (server->flags & NFS_MOUNT_TAGGED)
5645 +               server->client->cl_tag = 1;
5646         return 0;
5647  }
5648  
5649 @@ -909,6 +912,10 @@ static void nfs_server_set_fsinfo(struct
5650                 server->acdirmin = server->acdirmax = 0;
5651         }
5652  
5653 +       /* FIXME: needs fsinfo
5654 +       if (server->flags & NFS_MOUNT_TAGGED)
5655 +               sb->s_flags |= MS_TAGGED;       */
5656 +
5657         server->maxfilesize = fsinfo->maxfilesize;
5658  
5659         /* We're airborne Set socket buffersize */
5660 diff -NurpP --minimal linux-2.6.32.24/fs/nfs/dir.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/dir.c
5661 --- linux-2.6.32.24/fs/nfs/dir.c        2010-10-04 08:56:13.000000000 +0200
5662 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/dir.c        2010-05-21 13:20:19.000000000 +0200
5663 @@ -33,6 +33,7 @@
5664  #include <linux/namei.h>
5665  #include <linux/mount.h>
5666  #include <linux/sched.h>
5667 +#include <linux/vs_tag.h>
5668  
5669  #include "nfs4_fs.h"
5670  #include "delegation.h"
5671 @@ -951,6 +952,7 @@ static struct dentry *nfs_lookup(struct 
5672         if (IS_ERR(res))
5673                 goto out_unblock_sillyrename;
5674  
5675 +       dx_propagate_tag(nd, inode);
5676  no_entry:
5677         res = d_materialise_unique(dentry, inode);
5678         if (res != NULL) {
5679 diff -NurpP --minimal linux-2.6.32.24/fs/nfs/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/inode.c
5680 --- linux-2.6.32.24/fs/nfs/inode.c      2010-10-04 08:56:13.000000000 +0200
5681 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/inode.c      2010-04-05 20:56:22.000000000 +0200
5682 @@ -36,6 +36,7 @@
5683  #include <linux/vfs.h>
5684  #include <linux/inet.h>
5685  #include <linux/nfs_xdr.h>
5686 +#include <linux/vs_tag.h>
5687  
5688  #include <asm/system.h>
5689  #include <asm/uaccess.h>
5690 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5691         if (inode->i_state & I_NEW) {
5692                 struct nfs_inode *nfsi = NFS_I(inode);
5693                 unsigned long now = jiffies;
5694 +               uid_t uid;
5695 +               gid_t gid;
5696  
5697                 /* We set i_ino for the few things that still rely on it,
5698                  * such as stat(2) */
5699 @@ -327,8 +330,8 @@ nfs_fhget(struct super_block *sb, struct
5700                 nfsi->change_attr = 0;
5701                 inode->i_size = 0;
5702                 inode->i_nlink = 0;
5703 -               inode->i_uid = -2;
5704 -               inode->i_gid = -2;
5705 +               uid = -2;
5706 +               gid = -2;
5707                 inode->i_blocks = 0;
5708                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5709  
5710 @@ -365,13 +368,13 @@ nfs_fhget(struct super_block *sb, struct
5711                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5712                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5713                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5714 -                       inode->i_uid = fattr->uid;
5715 +                       uid = fattr->uid;
5716                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5717                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5718                                 | NFS_INO_INVALID_ACCESS
5719                                 | NFS_INO_INVALID_ACL;
5720                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5721 -                       inode->i_gid = fattr->gid;
5722 +                       gid = fattr->gid;
5723                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5724                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5725                                 | NFS_INO_INVALID_ACCESS
5726 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5727                          */
5728                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5729                 }
5730 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5731 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5732 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5733 +                               /* maybe fattr->xid someday */
5734 +
5735                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5736                 nfsi->attrtimeo_timestamp = now;
5737                 nfsi->access_cache = RB_ROOT;
5738 @@ -496,6 +504,8 @@ void nfs_setattr_update_inode(struct ino
5739                         inode->i_uid = attr->ia_uid;
5740                 if ((attr->ia_valid & ATTR_GID) != 0)
5741                         inode->i_gid = attr->ia_gid;
5742 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5743 +                       inode->i_tag = attr->ia_tag;
5744                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5745                 spin_unlock(&inode->i_lock);
5746         }
5747 @@ -906,6 +916,9 @@ static int nfs_check_inode_attributes(st
5748         struct nfs_inode *nfsi = NFS_I(inode);
5749         loff_t cur_size, new_isize;
5750         unsigned long invalid = 0;
5751 +       uid_t uid;
5752 +       gid_t gid;
5753 +       tag_t tag;
5754  
5755  
5756         /* Has the inode gone and changed behind our back? */
5757 @@ -929,13 +942,18 @@ static int nfs_check_inode_attributes(st
5758                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5759         }
5760  
5761 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5762 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5763 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5764 +
5765         /* Have any file permissions changed? */
5766         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5767                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5768 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5769 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5770                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5771 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5772 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5773                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5774 +               /* maybe check for tag too? */
5775  
5776         /* Has the link count changed? */
5777         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5778 @@ -1150,6 +1168,9 @@ static int nfs_update_inode(struct inode
5779         unsigned long invalid = 0;
5780         unsigned long now = jiffies;
5781         unsigned long save_cache_validity;
5782 +       uid_t uid;
5783 +       gid_t gid;
5784 +       tag_t tag;
5785  
5786         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5787                         __func__, inode->i_sb->s_id, inode->i_ino,
5788 @@ -1252,6 +1273,9 @@ static int nfs_update_inode(struct inode
5789                                 | NFS_INO_REVAL_PAGECACHE
5790                                 | NFS_INO_REVAL_FORCED);
5791  
5792 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5793 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5794 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5795  
5796         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5797                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5798 @@ -1271,9 +1295,9 @@ static int nfs_update_inode(struct inode
5799                                 | NFS_INO_REVAL_FORCED);
5800  
5801         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5802 -               if (inode->i_uid != fattr->uid) {
5803 +               if (uid != fattr->uid) {
5804                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5805 -                       inode->i_uid = fattr->uid;
5806 +                       uid = fattr->uid;
5807                 }
5808         } else if (server->caps & NFS_CAP_OWNER)
5809                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5810 @@ -1282,9 +1306,9 @@ static int nfs_update_inode(struct inode
5811                                 | NFS_INO_REVAL_FORCED);
5812  
5813         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5814 -               if (inode->i_gid != fattr->gid) {
5815 +               if (gid != fattr->gid) {
5816                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5817 -                       inode->i_gid = fattr->gid;
5818 +                       gid = fattr->gid;
5819                 }
5820         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5821                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5822 @@ -1292,6 +1316,10 @@ static int nfs_update_inode(struct inode
5823                                 | NFS_INO_INVALID_ACL
5824                                 | NFS_INO_REVAL_FORCED);
5825  
5826 +       inode->i_uid = uid;
5827 +       inode->i_gid = gid;
5828 +       inode->i_tag = tag;
5829 +
5830         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5831                 if (inode->i_nlink != fattr->nlink) {
5832                         invalid |= NFS_INO_INVALID_ATTR;
5833 diff -NurpP --minimal linux-2.6.32.24/fs/nfs/nfs3xdr.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/nfs3xdr.c
5834 --- linux-2.6.32.24/fs/nfs/nfs3xdr.c    2009-12-03 20:02:52.000000000 +0100
5835 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/nfs3xdr.c    2009-12-03 20:04:56.000000000 +0100
5836 @@ -21,6 +21,7 @@
5837  #include <linux/nfs3.h>
5838  #include <linux/nfs_fs.h>
5839  #include <linux/nfsacl.h>
5840 +#include <linux/vs_tag.h>
5841  #include "internal.h"
5842  
5843  #define NFSDBG_FACILITY                NFSDBG_XDR
5844 @@ -176,7 +177,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5845  }
5846  
5847  static inline __be32 *
5848 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5849 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5850  {
5851         if (attr->ia_valid & ATTR_MODE) {
5852                 *p++ = xdr_one;
5853 @@ -184,15 +185,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5854         } else {
5855                 *p++ = xdr_zero;
5856         }
5857 -       if (attr->ia_valid & ATTR_UID) {
5858 +       if (attr->ia_valid & ATTR_UID ||
5859 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5860                 *p++ = xdr_one;
5861 -               *p++ = htonl(attr->ia_uid);
5862 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5863         } else {
5864                 *p++ = xdr_zero;
5865         }
5866 -       if (attr->ia_valid & ATTR_GID) {
5867 +       if (attr->ia_valid & ATTR_GID ||
5868 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5869                 *p++ = xdr_one;
5870 -               *p++ = htonl(attr->ia_gid);
5871 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5872         } else {
5873                 *p++ = xdr_zero;
5874         }
5875 @@ -279,7 +282,8 @@ static int
5876  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5877  {
5878         p = xdr_encode_fhandle(p, args->fh);
5879 -       p = xdr_encode_sattr(p, args->sattr);
5880 +       p = xdr_encode_sattr(p, args->sattr,
5881 +               req->rq_task->tk_client->cl_tag);
5882         *p++ = htonl(args->guard);
5883         if (args->guard)
5884                 p = xdr_encode_time3(p, &args->guardtime);
5885 @@ -384,7 +388,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5886                 *p++ = args->verifier[0];
5887                 *p++ = args->verifier[1];
5888         } else
5889 -               p = xdr_encode_sattr(p, args->sattr);
5890 +               p = xdr_encode_sattr(p, args->sattr,
5891 +                       req->rq_task->tk_client->cl_tag);
5892  
5893         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5894         return 0;
5895 @@ -398,7 +403,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5896  {
5897         p = xdr_encode_fhandle(p, args->fh);
5898         p = xdr_encode_array(p, args->name, args->len);
5899 -       p = xdr_encode_sattr(p, args->sattr);
5900 +       p = xdr_encode_sattr(p, args->sattr,
5901 +               req->rq_task->tk_client->cl_tag);
5902         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5903         return 0;
5904  }
5905 @@ -411,7 +417,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5906  {
5907         p = xdr_encode_fhandle(p, args->fromfh);
5908         p = xdr_encode_array(p, args->fromname, args->fromlen);
5909 -       p = xdr_encode_sattr(p, args->sattr);
5910 +       p = xdr_encode_sattr(p, args->sattr,
5911 +               req->rq_task->tk_client->cl_tag);
5912         *p++ = htonl(args->pathlen);
5913         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5914  
5915 @@ -429,7 +436,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5916         p = xdr_encode_fhandle(p, args->fh);
5917         p = xdr_encode_array(p, args->name, args->len);
5918         *p++ = htonl(args->type);
5919 -       p = xdr_encode_sattr(p, args->sattr);
5920 +       p = xdr_encode_sattr(p, args->sattr,
5921 +               req->rq_task->tk_client->cl_tag);
5922         if (args->type == NF3CHR || args->type == NF3BLK) {
5923                 *p++ = htonl(MAJOR(args->rdev));
5924                 *p++ = htonl(MINOR(args->rdev));
5925 diff -NurpP --minimal linux-2.6.32.24/fs/nfs/nfsroot.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/nfsroot.c
5926 --- linux-2.6.32.24/fs/nfs/nfsroot.c    2009-09-10 15:26:23.000000000 +0200
5927 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/nfsroot.c    2009-12-03 20:04:56.000000000 +0100
5928 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
5929  enum {
5930         /* Options that take integer arguments */
5931         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
5932 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
5933 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
5934         /* Options that take no arguments */
5935         Opt_soft, Opt_hard, Opt_intr,
5936         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
5937         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
5938 -       Opt_acl, Opt_noacl,
5939 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
5940         /* Error token */
5941         Opt_err
5942  };
5943 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
5944         {Opt_tcp, "tcp"},
5945         {Opt_acl, "acl"},
5946         {Opt_noacl, "noacl"},
5947 +       {Opt_tag, "tag"},
5948 +       {Opt_notag, "notag"},
5949 +       {Opt_tagid, "tagid=%u"},
5950         {Opt_err, NULL}
5951         
5952  };
5953 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
5954                         case Opt_noacl:
5955                                 nfs_data.flags |= NFS_MOUNT_NOACL;
5956                                 break;
5957 +#ifndef CONFIG_TAGGING_NONE
5958 +                       case Opt_tag:
5959 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5960 +                               break;
5961 +                       case Opt_notag:
5962 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
5963 +                               break;
5964 +#endif
5965 +#ifdef CONFIG_PROPAGATE
5966 +                       case Opt_tagid:
5967 +                               /* use args[0] */
5968 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5969 +                               break;
5970 +#endif
5971                         default:
5972                                 printk(KERN_WARNING "Root-NFS: unknown "
5973                                         "option: %s\n", p);
5974 diff -NurpP --minimal linux-2.6.32.24/fs/nfs/super.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/super.c
5975 --- linux-2.6.32.24/fs/nfs/super.c      2010-10-04 08:56:14.000000000 +0200
5976 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfs/super.c      2010-09-05 21:24:17.000000000 +0200
5977 @@ -53,6 +53,7 @@
5978  #include <linux/nfs_xdr.h>
5979  #include <linux/magic.h>
5980  #include <linux/parser.h>
5981 +#include <linux/vs_tag.h>
5982  
5983  #include <asm/system.h>
5984  #include <asm/uaccess.h>
5985 @@ -570,6 +571,7 @@ static void nfs_show_mount_options(struc
5986                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5987                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5988                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5989 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5990                 { 0, NULL, NULL }
5991         };
5992         const struct proc_nfs_info *nfs_infop;
5993 diff -NurpP --minimal linux-2.6.32.24/fs/nfsd/auth.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfsd/auth.c
5994 --- linux-2.6.32.24/fs/nfsd/auth.c      2009-12-03 20:02:52.000000000 +0100
5995 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfsd/auth.c      2009-12-03 20:04:56.000000000 +0100
5996 @@ -10,6 +10,7 @@
5997  #include <linux/sunrpc/svcauth.h>
5998  #include <linux/nfsd/nfsd.h>
5999  #include <linux/nfsd/export.h>
6000 +#include <linux/vs_tag.h>
6001  #include "auth.h"
6002  
6003  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
6004 @@ -44,6 +45,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6005  
6006         new->fsuid = rqstp->rq_cred.cr_uid;
6007         new->fsgid = rqstp->rq_cred.cr_gid;
6008 +       /* FIXME: this desperately needs a tag :)
6009 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6010 +                       */
6011  
6012         rqgi = rqstp->rq_cred.cr_group_info;
6013  
6014 diff -NurpP --minimal linux-2.6.32.24/fs/nfsd/nfs3xdr.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfsd/nfs3xdr.c
6015 --- linux-2.6.32.24/fs/nfsd/nfs3xdr.c   2009-12-03 20:02:52.000000000 +0100
6016 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfsd/nfs3xdr.c   2009-12-03 20:04:56.000000000 +0100
6017 @@ -21,6 +21,7 @@
6018  #include <linux/sunrpc/svc.h>
6019  #include <linux/nfsd/nfsd.h>
6020  #include <linux/nfsd/xdr3.h>
6021 +#include <linux/vs_tag.h>
6022  #include "auth.h"
6023  
6024  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6025 @@ -108,6 +109,8 @@ static __be32 *
6026  decode_sattr3(__be32 *p, struct iattr *iap)
6027  {
6028         u32     tmp;
6029 +       uid_t   uid = 0;
6030 +       gid_t   gid = 0;
6031  
6032         iap->ia_valid = 0;
6033  
6034 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6035         }
6036         if (*p++) {
6037                 iap->ia_valid |= ATTR_UID;
6038 -               iap->ia_uid = ntohl(*p++);
6039 +               uid = ntohl(*p++);
6040         }
6041         if (*p++) {
6042                 iap->ia_valid |= ATTR_GID;
6043 -               iap->ia_gid = ntohl(*p++);
6044 +               gid = ntohl(*p++);
6045         }
6046 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6047 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6048 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6049         if (*p++) {
6050                 u64     newsize;
6051  
6052 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6053         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6054         *p++ = htonl((u32) stat->mode);
6055         *p++ = htonl((u32) stat->nlink);
6056 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6057 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6058 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6059 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6060 +               stat->uid, stat->tag)));
6061 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6062 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6063 +               stat->gid, stat->tag)));
6064         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6065                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6066         } else {
6067 diff -NurpP --minimal linux-2.6.32.24/fs/nfsd/nfs4xdr.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfsd/nfs4xdr.c
6068 --- linux-2.6.32.24/fs/nfsd/nfs4xdr.c   2010-10-04 08:56:14.000000000 +0200
6069 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfsd/nfs4xdr.c   2010-05-21 13:20:19.000000000 +0200
6070 @@ -57,6 +57,7 @@
6071  #include <linux/nfs4_acl.h>
6072  #include <linux/sunrpc/gss_api.h>
6073  #include <linux/sunrpc/svcauth_gss.h>
6074 +#include <linux/vs_tag.h>
6075  
6076  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6077  
6078 @@ -2050,14 +2051,18 @@ out_acl:
6079                 WRITE32(stat.nlink);
6080         }
6081         if (bmval1 & FATTR4_WORD1_OWNER) {
6082 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6083 +               status = nfsd4_encode_user(rqstp,
6084 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6085 +                       stat.uid, stat.tag), &p, &buflen);
6086                 if (status == nfserr_resource)
6087                         goto out_resource;
6088                 if (status)
6089                         goto out;
6090         }
6091         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6092 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6093 +               status = nfsd4_encode_group(rqstp,
6094 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6095 +                       stat.gid, stat.tag), &p, &buflen);
6096                 if (status == nfserr_resource)
6097                         goto out_resource;
6098                 if (status)
6099 diff -NurpP --minimal linux-2.6.32.24/fs/nfsd/nfsxdr.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfsd/nfsxdr.c
6100 --- linux-2.6.32.24/fs/nfsd/nfsxdr.c    2008-12-25 00:26:37.000000000 +0100
6101 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/nfsd/nfsxdr.c    2009-12-03 20:04:56.000000000 +0100
6102 @@ -15,6 +15,7 @@
6103  #include <linux/nfsd/nfsd.h>
6104  #include <linux/nfsd/xdr.h>
6105  #include <linux/mm.h>
6106 +#include <linux/vs_tag.h>
6107  #include "auth.h"
6108  
6109  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6110 @@ -98,6 +99,8 @@ static __be32 *
6111  decode_sattr(__be32 *p, struct iattr *iap)
6112  {
6113         u32     tmp, tmp1;
6114 +       uid_t   uid = 0;
6115 +       gid_t   gid = 0;
6116  
6117         iap->ia_valid = 0;
6118  
6119 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6120         }
6121         if ((tmp = ntohl(*p++)) != (u32)-1) {
6122                 iap->ia_valid |= ATTR_UID;
6123 -               iap->ia_uid = tmp;
6124 +               uid = tmp;
6125         }
6126         if ((tmp = ntohl(*p++)) != (u32)-1) {
6127                 iap->ia_valid |= ATTR_GID;
6128 -               iap->ia_gid = tmp;
6129 +               gid = tmp;
6130         }
6131 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6132 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6133 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6134         if ((tmp = ntohl(*p++)) != (u32)-1) {
6135                 iap->ia_valid |= ATTR_SIZE;
6136                 iap->ia_size = tmp;
6137 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6138         *p++ = htonl(nfs_ftypes[type >> 12]);
6139         *p++ = htonl((u32) stat->mode);
6140         *p++ = htonl((u32) stat->nlink);
6141 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6142 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6143 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6144 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6145 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6146 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6147  
6148         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6149                 *p++ = htonl(NFS_MAXPATHLEN);
6150 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/dlm/dlmfs.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/dlm/dlmfs.c
6151 --- linux-2.6.32.24/fs/ocfs2/dlm/dlmfs.c        2010-10-04 08:56:14.000000000 +0200
6152 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/dlm/dlmfs.c        2010-05-21 13:20:19.000000000 +0200
6153 @@ -43,6 +43,7 @@
6154  #include <linux/init.h>
6155  #include <linux/string.h>
6156  #include <linux/backing-dev.h>
6157 +#include <linux/vs_tag.h>
6158  
6159  #include <asm/uaccess.h>
6160  
6161 @@ -342,6 +343,7 @@ static struct inode *dlmfs_get_root_inod
6162                 inode->i_mode = mode;
6163                 inode->i_uid = current_fsuid();
6164                 inode->i_gid = current_fsgid();
6165 +               inode->i_tag = dx_current_fstag(sb);
6166                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6167                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6168                 inc_nlink(inode);
6169 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6170         inode->i_mode = mode;
6171         inode->i_uid = current_fsuid();
6172         inode->i_gid = current_fsgid();
6173 +       inode->i_tag = dx_current_fstag(sb);
6174         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6175         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6176  
6177 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/dlmglue.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/dlmglue.c
6178 --- linux-2.6.32.24/fs/ocfs2/dlmglue.c  2009-12-03 20:02:53.000000000 +0100
6179 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/dlmglue.c  2009-12-03 20:04:56.000000000 +0100
6180 @@ -1991,6 +1991,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6181         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6182         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6183         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6184 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6185         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6186         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6187         lvb->lvb_iatime_packed  =
6188 @@ -2045,6 +2046,7 @@ static void ocfs2_refresh_inode_from_lvb
6189  
6190         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6191         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6192 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6193         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6194         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6195         ocfs2_unpack_timespec(&inode->i_atime,
6196 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/dlmglue.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/dlmglue.h
6197 --- linux-2.6.32.24/fs/ocfs2/dlmglue.h  2009-12-03 20:02:53.000000000 +0100
6198 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/dlmglue.h  2009-12-03 20:04:56.000000000 +0100
6199 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6200         __be16       lvb_inlink;
6201         __be32       lvb_iattr;
6202         __be32       lvb_igeneration;
6203 -       __be32       lvb_reserved2;
6204 +       __be16       lvb_itag;
6205 +       __be16       lvb_reserved2;
6206  };
6207  
6208  #define OCFS2_QINFO_LVB_VERSION 1
6209 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/file.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/file.c
6210 --- linux-2.6.32.24/fs/ocfs2/file.c     2009-12-03 20:02:53.000000000 +0100
6211 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/file.c     2009-12-03 20:04:56.000000000 +0100
6212 @@ -960,13 +960,15 @@ int ocfs2_setattr(struct dentry *dentry,
6213                 mlog(0, "uid change: %d\n", attr->ia_uid);
6214         if (attr->ia_valid & ATTR_GID)
6215                 mlog(0, "gid change: %d\n", attr->ia_gid);
6216 +       if (attr->ia_valid & ATTR_TAG)
6217 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6218         if (attr->ia_valid & ATTR_SIZE)
6219                 mlog(0, "size change...\n");
6220         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6221                 mlog(0, "time change...\n");
6222  
6223  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6224 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6225 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6226         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6227                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6228                 return 0;
6229 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/inode.c
6230 --- linux-2.6.32.24/fs/ocfs2/inode.c    2010-10-04 08:56:14.000000000 +0200
6231 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/inode.c    2010-09-22 00:48:38.000000000 +0200
6232 @@ -29,6 +29,7 @@
6233  #include <linux/highmem.h>
6234  #include <linux/pagemap.h>
6235  #include <linux/quotaops.h>
6236 +#include <linux/vs_tag.h>
6237  
6238  #include <asm/byteorder.h>
6239  
6240 @@ -79,11 +80,13 @@ void ocfs2_set_inode_flags(struct inode 
6241  {
6242         unsigned int flags = OCFS2_I(inode)->ip_attr;
6243  
6244 -       inode->i_flags &= ~(S_IMMUTABLE |
6245 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6246                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6247  
6248         if (flags & OCFS2_IMMUTABLE_FL)
6249                 inode->i_flags |= S_IMMUTABLE;
6250 +       if (flags & OCFS2_IXUNLINK_FL)
6251 +               inode->i_flags |= S_IXUNLINK;
6252  
6253         if (flags & OCFS2_SYNC_FL)
6254                 inode->i_flags |= S_SYNC;
6255 @@ -93,25 +96,44 @@ void ocfs2_set_inode_flags(struct inode 
6256                 inode->i_flags |= S_NOATIME;
6257         if (flags & OCFS2_DIRSYNC_FL)
6258                 inode->i_flags |= S_DIRSYNC;
6259 +
6260 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6261 +
6262 +       if (flags & OCFS2_BARRIER_FL)
6263 +               inode->i_vflags |= V_BARRIER;
6264 +       if (flags & OCFS2_COW_FL)
6265 +               inode->i_vflags |= V_COW;
6266  }
6267  
6268  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6269  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6270  {
6271         unsigned int flags = oi->vfs_inode.i_flags;
6272 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6273 +
6274 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6275 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6276 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6277 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6278 +
6279 +       if (flags & S_IMMUTABLE)
6280 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6281 +       if (flags & S_IXUNLINK)
6282 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6283  
6284 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6285 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6286         if (flags & S_SYNC)
6287                 oi->ip_attr |= OCFS2_SYNC_FL;
6288         if (flags & S_APPEND)
6289                 oi->ip_attr |= OCFS2_APPEND_FL;
6290 -       if (flags & S_IMMUTABLE)
6291 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6292         if (flags & S_NOATIME)
6293                 oi->ip_attr |= OCFS2_NOATIME_FL;
6294         if (flags & S_DIRSYNC)
6295                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6296 +
6297 +       if (vflags & V_BARRIER)
6298 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6299 +       if (vflags & V_COW)
6300 +               oi->ip_attr |= OCFS2_COW_FL;
6301  }
6302  
6303  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6304 @@ -246,6 +268,8 @@ void ocfs2_populate_inode(struct inode *
6305         struct super_block *sb;
6306         struct ocfs2_super *osb;
6307         int use_plocks = 1;
6308 +       uid_t uid;
6309 +       gid_t gid;
6310  
6311         mlog_entry("(0x%p, size:%llu)\n", inode,
6312                    (unsigned long long)le64_to_cpu(fe->i_size));
6313 @@ -277,8 +301,12 @@ void ocfs2_populate_inode(struct inode *
6314         inode->i_generation = le32_to_cpu(fe->i_generation);
6315         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6316         inode->i_mode = le16_to_cpu(fe->i_mode);
6317 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6318 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6319 +       uid = le32_to_cpu(fe->i_uid);
6320 +       gid = le32_to_cpu(fe->i_gid);
6321 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6322 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6323 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6324 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6325  
6326         /* Fast symlinks will have i_size but no allocated clusters. */
6327         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6328 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/inode.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/inode.h
6329 --- linux-2.6.32.24/fs/ocfs2/inode.h    2009-12-03 20:02:53.000000000 +0100
6330 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/inode.h    2009-12-03 20:04:56.000000000 +0100
6331 @@ -150,6 +150,7 @@ struct buffer_head *ocfs2_bread(struct i
6332  
6333  void ocfs2_set_inode_flags(struct inode *inode);
6334  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6335 +int ocfs2_sync_flags(struct inode *inode, int, int);
6336  
6337  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6338  {
6339 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/ioctl.c
6340 --- linux-2.6.32.24/fs/ocfs2/ioctl.c    2009-12-03 20:02:53.000000000 +0100
6341 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/ioctl.c    2009-12-03 20:04:56.000000000 +0100
6342 @@ -42,7 +42,41 @@ static int ocfs2_get_inode_attr(struct i
6343         return status;
6344  }
6345  
6346 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6347 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6348 +{
6349 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6350 +       struct buffer_head *bh = NULL;
6351 +       handle_t *handle = NULL;
6352 +       int status;
6353 +
6354 +       status = ocfs2_inode_lock(inode, &bh, 1);
6355 +       if (status < 0) {
6356 +               mlog_errno(status);
6357 +               return status;
6358 +       }
6359 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6360 +       if (IS_ERR(handle)) {
6361 +               status = PTR_ERR(handle);
6362 +               mlog_errno(status);
6363 +               goto bail_unlock;
6364 +       }
6365 +
6366 +       inode->i_flags = flags;
6367 +       inode->i_vflags = vflags;
6368 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6369 +
6370 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6371 +       if (status < 0)
6372 +               mlog_errno(status);
6373 +
6374 +       ocfs2_commit_trans(osb, handle);
6375 +bail_unlock:
6376 +       ocfs2_inode_unlock(inode, 1);
6377 +       brelse(bh);
6378 +       return status;
6379 +}
6380 +
6381 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6382                                 unsigned mask)
6383  {
6384         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6385 @@ -67,6 +101,11 @@ static int ocfs2_set_inode_attr(struct i
6386         if (!S_ISDIR(inode->i_mode))
6387                 flags &= ~OCFS2_DIRSYNC_FL;
6388  
6389 +       if (IS_BARRIER(inode)) {
6390 +               vxwprintk_task(1, "messing with the barrier.");
6391 +               goto bail_unlock;
6392 +       }
6393 +
6394         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6395         if (IS_ERR(handle)) {
6396                 status = PTR_ERR(handle);
6397 @@ -108,6 +147,7 @@ bail:
6398         return status;
6399  }
6400  
6401 +
6402  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6403  {
6404         struct inode *inode = filp->f_path.dentry->d_inode;
6405 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/namei.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/namei.c
6406 --- linux-2.6.32.24/fs/ocfs2/namei.c    2009-12-03 20:02:53.000000000 +0100
6407 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/namei.c    2009-12-03 20:04:56.000000000 +0100
6408 @@ -41,6 +41,7 @@
6409  #include <linux/slab.h>
6410  #include <linux/highmem.h>
6411  #include <linux/quotaops.h>
6412 +#include <linux/vs_tag.h>
6413  
6414  #define MLOG_MASK_PREFIX ML_NAMEI
6415  #include <cluster/masklog.h>
6416 @@ -481,6 +482,7 @@ static int ocfs2_mknod_locked(struct ocf
6417         u64 fe_blkno = 0;
6418         u16 suballoc_bit;
6419         u16 feat;
6420 +       tag_t tag;
6421  
6422         *new_fe_bh = NULL;
6423  
6424 @@ -524,8 +526,11 @@ static int ocfs2_mknod_locked(struct ocf
6425         fe->i_blkno = cpu_to_le64(fe_blkno);
6426         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6427         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6428 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6429 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6430 +
6431 +       tag = dx_current_fstag(osb->sb);
6432 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6433 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6434 +       inode->i_tag = tag;
6435         fe->i_mode = cpu_to_le16(inode->i_mode);
6436         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6437                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6438 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/ocfs2_fs.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/ocfs2_fs.h
6439 --- linux-2.6.32.24/fs/ocfs2/ocfs2_fs.h 2009-12-03 20:02:53.000000000 +0100
6440 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/ocfs2_fs.h 2009-12-03 20:04:56.000000000 +0100
6441 @@ -231,18 +231,23 @@
6442  #define OCFS2_HAS_REFCOUNT_FL   (0x0010)
6443  
6444  /* Inode attributes, keep in sync with EXT2 */
6445 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6446 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6447 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6448 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6449 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6450 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6451 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6452 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6453 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6454 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6455 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6456 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6457 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6458 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6459 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6460 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6461 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6462  
6463 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6464 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6465 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6466 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6467 +
6468 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6469 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6470 +
6471 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6472 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6473  
6474  /*
6475   * Extent record flags (e_node.leaf.flags)
6476 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/ocfs2.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/ocfs2.h
6477 --- linux-2.6.32.24/fs/ocfs2/ocfs2.h    2009-12-03 20:02:53.000000000 +0100
6478 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/ocfs2.h    2009-12-03 20:04:56.000000000 +0100
6479 @@ -248,6 +248,7 @@ enum ocfs2_mount_options
6480         OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */
6481         OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */
6482         OCFS2_MOUNT_GRPQUOTA = 1 << 10, /* We support group quotas */
6483 +       OCFS2_MOUNT_TAGGED = 1 << 11, /* use tagging */
6484  };
6485  
6486  #define OCFS2_OSB_SOFT_RO                      0x0001
6487 diff -NurpP --minimal linux-2.6.32.24/fs/ocfs2/super.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/super.c
6488 --- linux-2.6.32.24/fs/ocfs2/super.c    2010-10-04 08:56:14.000000000 +0200
6489 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/ocfs2/super.c    2010-08-19 17:35:34.000000000 +0200
6490 @@ -173,6 +173,7 @@ enum {
6491         Opt_noacl,
6492         Opt_usrquota,
6493         Opt_grpquota,
6494 +       Opt_tag, Opt_notag, Opt_tagid,
6495         Opt_err,
6496  };
6497  
6498 @@ -199,6 +200,9 @@ static const match_table_t tokens = {
6499         {Opt_noacl, "noacl"},
6500         {Opt_usrquota, "usrquota"},
6501         {Opt_grpquota, "grpquota"},
6502 +       {Opt_tag, "tag"},
6503 +       {Opt_notag, "notag"},
6504 +       {Opt_tagid, "tagid=%u"},
6505         {Opt_err, NULL}
6506  };
6507  
6508 @@ -605,6 +609,13 @@ static int ocfs2_remount(struct super_bl
6509                 goto out;
6510         }
6511  
6512 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6513 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6514 +               ret = -EINVAL;
6515 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6516 +               goto out;
6517 +       }
6518 +
6519         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6520             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6521                 ret = -EINVAL;
6522 @@ -1152,6 +1163,9 @@ static int ocfs2_fill_super(struct super
6523  
6524         ocfs2_complete_mount_recovery(osb);
6525  
6526 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6527 +               sb->s_flags |= MS_TAGGED;
6528 +
6529         if (ocfs2_mount_local(osb))
6530                 snprintf(nodestr, sizeof(nodestr), "local");
6531         else
6532 @@ -1430,6 +1444,20 @@ static int ocfs2_parse_options(struct su
6533                         printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
6534                         break;
6535  #endif
6536 +#ifndef CONFIG_TAGGING_NONE
6537 +               case Opt_tag:
6538 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6539 +                       break;
6540 +               case Opt_notag:
6541 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6542 +                       break;
6543 +#endif
6544 +#ifdef CONFIG_PROPAGATE
6545 +               case Opt_tagid:
6546 +                       /* use args[0] */
6547 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6548 +                       break;
6549 +#endif
6550                 default:
6551                         mlog(ML_ERROR,
6552                              "Unrecognized mount option \"%s\" "
6553 diff -NurpP --minimal linux-2.6.32.24/fs/open.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/open.c
6554 --- linux-2.6.32.24/fs/open.c   2009-12-03 20:02:53.000000000 +0100
6555 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/open.c   2009-12-03 20:04:56.000000000 +0100
6556 @@ -30,22 +30,30 @@
6557  #include <linux/audit.h>
6558  #include <linux/falloc.h>
6559  #include <linux/fs_struct.h>
6560 +#include <linux/vs_base.h>
6561 +#include <linux/vs_limit.h>
6562 +#include <linux/vs_tag.h>
6563 +#include <linux/vs_cowbl.h>
6564  
6565  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6566  {
6567         int retval = -ENODEV;
6568  
6569         if (dentry) {
6570 +               struct super_block *sb = dentry->d_sb;
6571 +
6572                 retval = -ENOSYS;
6573 -               if (dentry->d_sb->s_op->statfs) {
6574 +               if (sb->s_op->statfs) {
6575                         memset(buf, 0, sizeof(*buf));
6576                         retval = security_sb_statfs(dentry);
6577                         if (retval)
6578                                 return retval;
6579 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6580 +                       retval = sb->s_op->statfs(dentry, buf);
6581                         if (retval == 0 && buf->f_frsize == 0)
6582                                 buf->f_frsize = buf->f_bsize;
6583                 }
6584 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6585 +                       vx_vsi_statfs(sb, buf);
6586         }
6587         return retval;
6588  }
6589 @@ -640,6 +648,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6590         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6591         if (error)
6592                 goto out;
6593 +
6594 +       error = cow_check_and_break(&path);
6595 +       if (error)
6596 +               goto dput_and_out;
6597         inode = path.dentry->d_inode;
6598  
6599         error = mnt_want_write(path.mnt);
6600 @@ -673,11 +685,11 @@ static int chown_common(struct dentry * 
6601         newattrs.ia_valid =  ATTR_CTIME;
6602         if (user != (uid_t) -1) {
6603                 newattrs.ia_valid |= ATTR_UID;
6604 -               newattrs.ia_uid = user;
6605 +               newattrs.ia_uid = dx_map_uid(user);
6606         }
6607         if (group != (gid_t) -1) {
6608                 newattrs.ia_valid |= ATTR_GID;
6609 -               newattrs.ia_gid = group;
6610 +               newattrs.ia_gid = dx_map_gid(group);
6611         }
6612         if (!S_ISDIR(inode->i_mode))
6613                 newattrs.ia_valid |=
6614 @@ -700,7 +712,11 @@ SYSCALL_DEFINE3(chown, const char __user
6615         error = mnt_want_write(path.mnt);
6616         if (error)
6617                 goto out_release;
6618 -       error = chown_common(path.dentry, user, group);
6619 +#ifdef CONFIG_VSERVER_COWBL
6620 +       error = cow_check_and_break(&path);
6621 +       if (!error)
6622 +#endif
6623 +               error = chown_common(path.dentry, user, group);
6624         mnt_drop_write(path.mnt);
6625  out_release:
6626         path_put(&path);
6627 @@ -725,7 +741,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6628         error = mnt_want_write(path.mnt);
6629         if (error)
6630                 goto out_release;
6631 -       error = chown_common(path.dentry, user, group);
6632 +#ifdef CONFIG_VSERVER_COWBL
6633 +       error = cow_check_and_break(&path);
6634 +       if (!error)
6635 +#endif
6636 +               error = chown_common(path.dentry, user, group);
6637         mnt_drop_write(path.mnt);
6638  out_release:
6639         path_put(&path);
6640 @@ -744,7 +764,11 @@ SYSCALL_DEFINE3(lchown, const char __use
6641         error = mnt_want_write(path.mnt);
6642         if (error)
6643                 goto out_release;
6644 -       error = chown_common(path.dentry, user, group);
6645 +#ifdef CONFIG_VSERVER_COWBL
6646 +       error = cow_check_and_break(&path);
6647 +       if (!error)
6648 +#endif
6649 +               error = chown_common(path.dentry, user, group);
6650         mnt_drop_write(path.mnt);
6651  out_release:
6652         path_put(&path);
6653 @@ -990,6 +1014,7 @@ static void __put_unused_fd(struct files
6654         __FD_CLR(fd, fdt->open_fds);
6655         if (fd < files->next_fd)
6656                 files->next_fd = fd;
6657 +       vx_openfd_dec(fd);
6658  }
6659  
6660  void put_unused_fd(unsigned int fd)
6661 diff -NurpP --minimal linux-2.6.32.24/fs/proc/array.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/array.c
6662 --- linux-2.6.32.24/fs/proc/array.c     2010-10-04 08:56:14.000000000 +0200
6663 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/array.c     2010-08-19 17:35:34.000000000 +0200
6664 @@ -82,6 +82,8 @@
6665  #include <linux/pid_namespace.h>
6666  #include <linux/ptrace.h>
6667  #include <linux/tracehook.h>
6668 +#include <linux/vs_context.h>
6669 +#include <linux/vs_network.h>
6670  
6671  #include <asm/pgtable.h>
6672  #include <asm/processor.h>
6673 @@ -166,6 +168,9 @@ static inline void task_state(struct seq
6674         rcu_read_lock();
6675         ppid = pid_alive(p) ?
6676                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6677 +       if (unlikely(vx_current_initpid(p->pid)))
6678 +               ppid = 0;
6679 +
6680         tpid = 0;
6681         if (pid_alive(p)) {
6682                 struct task_struct *tracer = tracehook_tracer_task(p);
6683 @@ -281,7 +286,7 @@ static inline void task_sig(struct seq_f
6684  }
6685  
6686  static void render_cap_t(struct seq_file *m, const char *header,
6687 -                       kernel_cap_t *a)
6688 +                       struct vx_info *vxi, kernel_cap_t *a)
6689  {
6690         unsigned __capi;
6691  
6692 @@ -306,10 +311,11 @@ static inline void task_cap(struct seq_f
6693         cap_bset        = cred->cap_bset;
6694         rcu_read_unlock();
6695  
6696 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6697 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6698 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6699 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6700 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6701 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6702 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6703 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6704 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6705  }
6706  
6707  static inline void task_context_switch_counts(struct seq_file *m,
6708 @@ -321,6 +327,43 @@ static inline void task_context_switch_c
6709                         p->nivcsw);
6710  }
6711  
6712 +
6713 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6714 +                       struct pid *pid, struct task_struct *task)
6715 +{
6716 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6717 +                       "Count:\t%u\n"
6718 +                       "uts:\t%p(%c)\n"
6719 +                       "ipc:\t%p(%c)\n"
6720 +                       "mnt:\t%p(%c)\n"
6721 +                       "pid:\t%p(%c)\n"
6722 +                       "net:\t%p(%c)\n",
6723 +                       task->nsproxy,
6724 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6725 +                       atomic_read(&task->nsproxy->count),
6726 +                       task->nsproxy->uts_ns,
6727 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6728 +                       task->nsproxy->ipc_ns,
6729 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6730 +                       task->nsproxy->mnt_ns,
6731 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6732 +                       task->nsproxy->pid_ns,
6733 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6734 +                       task->nsproxy->net_ns,
6735 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6736 +       return 0;
6737 +}
6738 +
6739 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6740 +{
6741 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6742 +               return;
6743 +
6744 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6745 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6746 +}
6747 +
6748 +
6749  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6750                         struct pid *pid, struct task_struct *task)
6751  {
6752 @@ -336,6 +379,7 @@ int proc_pid_status(struct seq_file *m, 
6753         task_sig(m, task);
6754         task_cap(m, task);
6755         cpuset_task_status_allowed(m, task);
6756 +       task_vs_id(m, task);
6757  #if defined(CONFIG_S390)
6758         task_show_regs(m, task);
6759  #endif
6760 @@ -449,6 +493,17 @@ static int do_task_stat(struct seq_file 
6761         /* convert nsec -> ticks */
6762         start_time = nsec_to_clock_t(start_time);
6763  
6764 +       /* fixup start time for virt uptime */
6765 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6766 +               unsigned long long bias =
6767 +                       current->vx_info->cvirt.bias_clock;
6768 +
6769 +               if (start_time > bias)
6770 +                       start_time -= bias;
6771 +               else
6772 +                       start_time = 0;
6773 +       }
6774 +
6775         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6776  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6777  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6778 diff -NurpP --minimal linux-2.6.32.24/fs/proc/base.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/base.c
6779 --- linux-2.6.32.24/fs/proc/base.c      2010-10-04 08:56:14.000000000 +0200
6780 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/base.c      2010-05-21 13:20:19.000000000 +0200
6781 @@ -81,6 +81,8 @@
6782  #include <linux/elf.h>
6783  #include <linux/pid_namespace.h>
6784  #include <linux/fs_struct.h>
6785 +#include <linux/vs_context.h>
6786 +#include <linux/vs_network.h>
6787  #include "internal.h"
6788  
6789  /* NOTE:
6790 @@ -1048,12 +1050,17 @@ static ssize_t oom_adjust_write(struct f
6791                 return -ESRCH;
6792         }
6793  
6794 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6795 +       if (oom_adjust < task->signal->oom_adj &&
6796 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6797                 unlock_task_sighand(task, &flags);
6798                 put_task_struct(task);
6799                 return -EACCES;
6800         }
6801  
6802 +       /* prevent guest processes from circumventing the oom killer */
6803 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6804 +               oom_adjust = OOM_ADJUST_MIN;
6805 +
6806         task->signal->oom_adj = oom_adjust;
6807  
6808         unlock_task_sighand(task, &flags);
6809 @@ -1093,7 +1100,7 @@ static ssize_t proc_loginuid_write(struc
6810         ssize_t length;
6811         uid_t loginuid;
6812  
6813 -       if (!capable(CAP_AUDIT_CONTROL))
6814 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6815                 return -EPERM;
6816  
6817         if (current != pid_task(proc_pid(inode), PIDTYPE_PID))
6818 @@ -1459,6 +1466,8 @@ static struct inode *proc_pid_make_inode
6819                 inode->i_gid = cred->egid;
6820                 rcu_read_unlock();
6821         }
6822 +       /* procfs is xid tagged */
6823 +       inode->i_tag = (tag_t)vx_task_xid(task);
6824         security_task_to_inode(task, inode);
6825  
6826  out:
6827 @@ -2009,6 +2018,13 @@ static struct dentry *proc_pident_lookup
6828         if (!task)
6829                 goto out_no_task;
6830  
6831 +       /* TODO: maybe we can come up with a generic approach? */
6832 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6833 +               (dentry->d_name.len == 5) &&
6834 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6835 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6836 +               goto out;
6837 +
6838         /*
6839          * Yes, it does not scale. And it should not. Don't add
6840          * new entries into /proc/<tgid>/ without very good reasons.
6841 @@ -2414,7 +2430,7 @@ out_iput:
6842  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6843  {
6844         struct dentry *error;
6845 -       struct task_struct *task = get_proc_task(dir);
6846 +       struct task_struct *task = get_proc_task_real(dir);
6847         const struct pid_entry *p, *last;
6848  
6849         error = ERR_PTR(-ENOENT);
6850 @@ -2504,6 +2520,9 @@ static int proc_pid_personality(struct s
6851  static const struct file_operations proc_task_operations;
6852  static const struct inode_operations proc_task_inode_operations;
6853  
6854 +extern int proc_pid_vx_info(struct task_struct *, char *);
6855 +extern int proc_pid_nx_info(struct task_struct *, char *);
6856 +
6857  static const struct pid_entry tgid_base_stuff[] = {
6858         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6859         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6860 @@ -2562,6 +2581,8 @@ static const struct pid_entry tgid_base_
6861  #ifdef CONFIG_CGROUPS
6862         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6863  #endif
6864 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6865 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6866         INF("oom_score",  S_IRUGO, proc_oom_score),
6867         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6868  #ifdef CONFIG_AUDITSYSCALL
6869 @@ -2577,6 +2598,7 @@ static const struct pid_entry tgid_base_
6870  #ifdef CONFIG_TASK_IO_ACCOUNTING
6871         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6872  #endif
6873 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6874  };
6875  
6876  static int proc_tgid_base_readdir(struct file * filp,
6877 @@ -2768,7 +2790,7 @@ retry:
6878         iter.task = NULL;
6879         pid = find_ge_pid(iter.tgid, ns);
6880         if (pid) {
6881 -               iter.tgid = pid_nr_ns(pid, ns);
6882 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6883                 iter.task = pid_task(pid, PIDTYPE_PID);
6884                 /* What we to know is if the pid we have find is the
6885                  * pid of a thread_group_leader.  Testing for task
6886 @@ -2798,7 +2820,7 @@ static int proc_pid_fill_cache(struct fi
6887         struct tgid_iter iter)
6888  {
6889         char name[PROC_NUMBUF];
6890 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6891 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6892         return proc_fill_cache(filp, dirent, filldir, name, len,
6893                                 proc_pid_instantiate, iter.task, NULL);
6894  }
6895 @@ -2807,7 +2829,7 @@ static int proc_pid_fill_cache(struct fi
6896  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6897  {
6898         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6899 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6900 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6901         struct tgid_iter iter;
6902         struct pid_namespace *ns;
6903  
6904 @@ -2827,6 +2849,8 @@ int proc_pid_readdir(struct file * filp,
6905              iter.task;
6906              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6907                 filp->f_pos = iter.tgid + TGID_OFFSET;
6908 +               if (!vx_proc_task_visible(iter.task))
6909 +                       continue;
6910                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6911                         put_task_struct(iter.task);
6912                         goto out;
6913 @@ -2973,6 +2997,8 @@ static struct dentry *proc_task_lookup(s
6914         tid = name_to_int(dentry);
6915         if (tid == ~0U)
6916                 goto out;
6917 +       if (vx_current_initpid(tid))
6918 +               goto out;
6919  
6920         ns = dentry->d_sb->s_fs_info;
6921         rcu_read_lock();
6922 diff -NurpP --minimal linux-2.6.32.24/fs/proc/generic.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/generic.c
6923 --- linux-2.6.32.24/fs/proc/generic.c   2009-06-11 17:13:07.000000000 +0200
6924 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/generic.c   2009-12-03 20:04:56.000000000 +0100
6925 @@ -20,6 +20,7 @@
6926  #include <linux/bitops.h>
6927  #include <linux/spinlock.h>
6928  #include <linux/completion.h>
6929 +#include <linux/vserver/inode.h>
6930  #include <asm/uaccess.h>
6931  
6932  #include "internal.h"
6933 @@ -425,6 +426,8 @@ struct dentry *proc_lookup_de(struct pro
6934         for (de = de->subdir; de ; de = de->next) {
6935                 if (de->namelen != dentry->d_name.len)
6936                         continue;
6937 +                       if (!vx_hide_check(0, de->vx_flags))
6938 +                               continue;
6939                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6940                         unsigned int ino;
6941  
6942 @@ -433,6 +436,8 @@ struct dentry *proc_lookup_de(struct pro
6943                         spin_unlock(&proc_subdir_lock);
6944                         error = -EINVAL;
6945                         inode = proc_get_inode(dir->i_sb, ino, de);
6946 +                               /* generic proc entries belong to the host */
6947 +                               inode->i_tag = 0;
6948                         goto out_unlock;
6949                 }
6950         }
6951 @@ -510,6 +515,8 @@ int proc_readdir_de(struct proc_dir_entr
6952  
6953                                 /* filldir passes info to user space */
6954                                 de_get(de);
6955 +                               if (!vx_hide_check(0, de->vx_flags))
6956 +                                       goto skip;
6957                                 spin_unlock(&proc_subdir_lock);
6958                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6959                                             de->low_ino, de->mode >> 12) < 0) {
6960 @@ -517,6 +524,7 @@ int proc_readdir_de(struct proc_dir_entr
6961                                         goto out;
6962                                 }
6963                                 spin_lock(&proc_subdir_lock);
6964 +                       skip:
6965                                 filp->f_pos++;
6966                                 next = de->next;
6967                                 de_put(de);
6968 @@ -631,6 +639,7 @@ static struct proc_dir_entry *__proc_cre
6969         ent->nlink = nlink;
6970         atomic_set(&ent->count, 1);
6971         ent->pde_users = 0;
6972 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6973         spin_lock_init(&ent->pde_unload_lock);
6974         ent->pde_unload_completion = NULL;
6975         INIT_LIST_HEAD(&ent->pde_openers);
6976 @@ -654,7 +663,8 @@ struct proc_dir_entry *proc_symlink(cons
6977                                 kfree(ent->data);
6978                                 kfree(ent);
6979                                 ent = NULL;
6980 -                       }
6981 +                       } else
6982 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6983                 } else {
6984                         kfree(ent);
6985                         ent = NULL;
6986 diff -NurpP --minimal linux-2.6.32.24/fs/proc/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/inode.c
6987 --- linux-2.6.32.24/fs/proc/inode.c     2009-06-11 17:13:07.000000000 +0200
6988 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/inode.c     2009-12-03 20:04:56.000000000 +0100
6989 @@ -459,6 +459,8 @@ struct inode *proc_get_inode(struct supe
6990                         inode->i_uid = de->uid;
6991                         inode->i_gid = de->gid;
6992                 }
6993 +               if (de->vx_flags)
6994 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6995                 if (de->size)
6996                         inode->i_size = de->size;
6997                 if (de->nlink)
6998 diff -NurpP --minimal linux-2.6.32.24/fs/proc/internal.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/internal.h
6999 --- linux-2.6.32.24/fs/proc/internal.h  2009-09-10 15:26:23.000000000 +0200
7000 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/internal.h  2009-12-03 20:04:56.000000000 +0100
7001 @@ -10,6 +10,7 @@
7002   */
7003  
7004  #include <linux/proc_fs.h>
7005 +#include <linux/vs_pid.h>
7006  
7007  extern struct proc_dir_entry proc_root;
7008  #ifdef CONFIG_PROC_SYSCTL
7009 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7010                                 struct pid *pid, struct task_struct *task);
7011  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7012                                 struct pid *pid, struct task_struct *task);
7013 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7014 +                               struct pid *pid, struct task_struct *task);
7015 +
7016  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7017  
7018  extern const struct file_operations proc_maps_operations;
7019 @@ -70,11 +74,16 @@ static inline struct pid *proc_pid(struc
7020         return PROC_I(inode)->pid;
7021  }
7022  
7023 -static inline struct task_struct *get_proc_task(struct inode *inode)
7024 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7025  {
7026         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7027  }
7028  
7029 +static inline struct task_struct *get_proc_task(struct inode *inode)
7030 +{
7031 +       return vx_get_proc_task(inode, proc_pid(inode));
7032 +}
7033 +
7034  static inline int proc_fd(struct inode *inode)
7035  {
7036         return PROC_I(inode)->fd;
7037 diff -NurpP --minimal linux-2.6.32.24/fs/proc/loadavg.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/loadavg.c
7038 --- linux-2.6.32.24/fs/proc/loadavg.c   2009-09-10 15:26:23.000000000 +0200
7039 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/loadavg.c   2009-12-03 20:04:56.000000000 +0100
7040 @@ -12,15 +12,27 @@
7041  
7042  static int loadavg_proc_show(struct seq_file *m, void *v)
7043  {
7044 +       unsigned long running;
7045 +       unsigned int threads;
7046         unsigned long avnrun[3];
7047  
7048         get_avenrun(avnrun, FIXED_1/200, 0);
7049  
7050 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7051 +               struct vx_info *vxi = current_vx_info();
7052 +
7053 +               running = atomic_read(&vxi->cvirt.nr_running);
7054 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7055 +       } else {
7056 +               running = nr_running();
7057 +               threads = nr_threads;
7058 +       }
7059 +
7060         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7061                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7062                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7063                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7064 -               nr_running(), nr_threads,
7065 +               running, threads,
7066                 task_active_pid_ns(current)->last_pid);
7067         return 0;
7068  }
7069 diff -NurpP --minimal linux-2.6.32.24/fs/proc/meminfo.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/meminfo.c
7070 --- linux-2.6.32.24/fs/proc/meminfo.c   2009-12-03 20:02:53.000000000 +0100
7071 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/meminfo.c   2010-02-05 00:31:48.000000000 +0100
7072 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7073         allowed = ((totalram_pages - hugetlb_total_pages())
7074                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7075  
7076 -       cached = global_page_state(NR_FILE_PAGES) -
7077 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7078 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7079                         total_swapcache_pages - i.bufferram;
7080         if (cached < 0)
7081                 cached = 0;
7082 diff -NurpP --minimal linux-2.6.32.24/fs/proc/root.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/root.c
7083 --- linux-2.6.32.24/fs/proc/root.c      2009-06-11 17:13:07.000000000 +0200
7084 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/root.c      2009-12-03 20:04:56.000000000 +0100
7085 @@ -18,9 +18,14 @@
7086  #include <linux/bitops.h>
7087  #include <linux/mount.h>
7088  #include <linux/pid_namespace.h>
7089 +#include <linux/vserver/inode.h>
7090  
7091  #include "internal.h"
7092  
7093 +struct proc_dir_entry *proc_virtual;
7094 +
7095 +extern void proc_vx_init(void);
7096 +
7097  static int proc_test_super(struct super_block *sb, void *data)
7098  {
7099         return sb->s_fs_info == data;
7100 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
7101  #endif
7102         proc_mkdir("bus", NULL);
7103         proc_sys_init();
7104 +       proc_vx_init();
7105  }
7106  
7107  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7108 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7109         .proc_iops      = &proc_root_inode_operations, 
7110         .proc_fops      = &proc_root_operations,
7111         .parent         = &proc_root,
7112 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7113  };
7114  
7115  int pid_ns_prepare_proc(struct pid_namespace *ns)
7116 diff -NurpP --minimal linux-2.6.32.24/fs/proc/uptime.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/uptime.c
7117 --- linux-2.6.32.24/fs/proc/uptime.c    2009-12-03 20:02:53.000000000 +0100
7118 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/proc/uptime.c    2009-12-03 20:04:56.000000000 +0100
7119 @@ -4,22 +4,22 @@
7120  #include <linux/sched.h>
7121  #include <linux/seq_file.h>
7122  #include <linux/time.h>
7123 -#include <linux/kernel_stat.h>
7124 +#include <linux/vserver/cvirt.h>
7125  #include <asm/cputime.h>
7126  
7127  static int uptime_proc_show(struct seq_file *m, void *v)
7128  {
7129         struct timespec uptime;
7130         struct timespec idle;
7131 -       int i;
7132 -       cputime_t idletime = cputime_zero;
7133 -
7134 -       for_each_possible_cpu(i)
7135 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7136 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7137  
7138         do_posix_clock_monotonic_gettime(&uptime);
7139         monotonic_to_bootbased(&uptime);
7140         cputime_to_timespec(idletime, &idle);
7141 +
7142 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7143 +               vx_vsi_uptime(&uptime, &idle);
7144 +
7145         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7146                         (unsigned long) uptime.tv_sec,
7147                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7148 diff -NurpP --minimal linux-2.6.32.24/fs/quota/quota.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/quota/quota.c
7149 --- linux-2.6.32.24/fs/quota/quota.c    2009-09-10 15:26:24.000000000 +0200
7150 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/quota/quota.c    2009-12-03 20:04:56.000000000 +0100
7151 @@ -18,6 +18,7 @@
7152  #include <linux/capability.h>
7153  #include <linux/quotaops.h>
7154  #include <linux/types.h>
7155 +#include <linux/vs_context.h>
7156  
7157  /* Check validity of generic quotactl commands */
7158  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd,
7159 @@ -83,11 +84,11 @@ static int generic_quotactl_valid(struct
7160         if (cmd == Q_GETQUOTA) {
7161                 if (((type == USRQUOTA && current_euid() != id) ||
7162                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7163 -                   !capable(CAP_SYS_ADMIN))
7164 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7165                         return -EPERM;
7166         }
7167         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7168 -               if (!capable(CAP_SYS_ADMIN))
7169 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7170                         return -EPERM;
7171  
7172         return 0;
7173 @@ -135,10 +136,10 @@ static int xqm_quotactl_valid(struct sup
7174         if (cmd == Q_XGETQUOTA) {
7175                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7176                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7177 -                    !capable(CAP_SYS_ADMIN))
7178 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7179                         return -EPERM;
7180         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7181 -               if (!capable(CAP_SYS_ADMIN))
7182 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7183                         return -EPERM;
7184         }
7185  
7186 @@ -351,6 +352,46 @@ static int do_quotactl(struct super_bloc
7187         return 0;
7188  }
7189  
7190 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7191 +
7192 +#include <linux/vroot.h>
7193 +#include <linux/major.h>
7194 +#include <linux/module.h>
7195 +#include <linux/kallsyms.h>
7196 +#include <linux/vserver/debug.h>
7197 +
7198 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7199 +
7200 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7201 +
7202 +int register_vroot_grb(vroot_grb_func *func) {
7203 +       int ret = -EBUSY;
7204 +
7205 +       spin_lock(&vroot_grb_lock);
7206 +       if (!vroot_get_real_bdev) {
7207 +               vroot_get_real_bdev = func;
7208 +               ret = 0;
7209 +       }
7210 +       spin_unlock(&vroot_grb_lock);
7211 +       return ret;
7212 +}
7213 +EXPORT_SYMBOL(register_vroot_grb);
7214 +
7215 +int unregister_vroot_grb(vroot_grb_func *func) {
7216 +       int ret = -EINVAL;
7217 +
7218 +       spin_lock(&vroot_grb_lock);
7219 +       if (vroot_get_real_bdev) {
7220 +               vroot_get_real_bdev = NULL;
7221 +               ret = 0;
7222 +       }
7223 +       spin_unlock(&vroot_grb_lock);
7224 +       return ret;
7225 +}
7226 +EXPORT_SYMBOL(unregister_vroot_grb);
7227 +
7228 +#endif
7229 +
7230  /*
7231   * look up a superblock on which quota ops will be performed
7232   * - use the name of a block device to find the superblock thereon
7233 @@ -368,6 +409,22 @@ static struct super_block *quotactl_bloc
7234         putname(tmp);
7235         if (IS_ERR(bdev))
7236                 return ERR_CAST(bdev);
7237 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7238 +       if (bdev && bdev->bd_inode &&
7239 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7240 +               struct block_device *bdnew = (void *)-EINVAL;
7241 +
7242 +               if (vroot_get_real_bdev)
7243 +                       bdnew = vroot_get_real_bdev(bdev);
7244 +               else
7245 +                       vxdprintk(VXD_CBIT(misc, 0),
7246 +                                       "vroot_get_real_bdev not set");
7247 +               bdput(bdev);
7248 +               if (IS_ERR(bdnew))
7249 +                       return ERR_PTR(PTR_ERR(bdnew));
7250 +               bdev = bdnew;
7251 +       }
7252 +#endif
7253         sb = get_super(bdev);
7254         bdput(bdev);
7255         if (!sb)
7256 diff -NurpP --minimal linux-2.6.32.24/fs/reiserfs/file.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/file.c
7257 --- linux-2.6.32.24/fs/reiserfs/file.c  2009-06-11 17:13:08.000000000 +0200
7258 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/file.c  2009-12-03 20:04:56.000000000 +0100
7259 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7260         .listxattr = reiserfs_listxattr,
7261         .removexattr = reiserfs_removexattr,
7262         .permission = reiserfs_permission,
7263 +       .sync_flags = reiserfs_sync_flags,
7264  };
7265 diff -NurpP --minimal linux-2.6.32.24/fs/reiserfs/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/inode.c
7266 --- linux-2.6.32.24/fs/reiserfs/inode.c 2010-10-04 08:56:14.000000000 +0200
7267 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/inode.c 2010-01-26 20:35:35.000000000 +0100
7268 @@ -18,6 +18,7 @@
7269  #include <linux/writeback.h>
7270  #include <linux/quotaops.h>
7271  #include <linux/swap.h>
7272 +#include <linux/vs_tag.h>
7273  
7274  int reiserfs_commit_write(struct file *f, struct page *page,
7275                           unsigned from, unsigned to);
7276 @@ -1117,6 +1118,8 @@ static void init_inode(struct inode *ino
7277         struct buffer_head *bh;
7278         struct item_head *ih;
7279         __u32 rdev;
7280 +       uid_t uid;
7281 +       gid_t gid;
7282         //int version = ITEM_VERSION_1;
7283  
7284         bh = PATH_PLAST_BUFFER(path);
7285 @@ -1138,12 +1141,13 @@ static void init_inode(struct inode *ino
7286                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7287                 unsigned long blocks;
7288  
7289 +               uid = sd_v1_uid(sd);
7290 +               gid = sd_v1_gid(sd);
7291 +
7292                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7293                 set_inode_sd_version(inode, STAT_DATA_V1);
7294                 inode->i_mode = sd_v1_mode(sd);
7295                 inode->i_nlink = sd_v1_nlink(sd);
7296 -               inode->i_uid = sd_v1_uid(sd);
7297 -               inode->i_gid = sd_v1_gid(sd);
7298                 inode->i_size = sd_v1_size(sd);
7299                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7300                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7301 @@ -1185,11 +1189,12 @@ static void init_inode(struct inode *ino
7302                 // (directories and symlinks)
7303                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7304  
7305 +               uid    = sd_v2_uid(sd);
7306 +               gid    = sd_v2_gid(sd);
7307 +
7308                 inode->i_mode = sd_v2_mode(sd);
7309                 inode->i_nlink = sd_v2_nlink(sd);
7310 -               inode->i_uid = sd_v2_uid(sd);
7311                 inode->i_size = sd_v2_size(sd);
7312 -               inode->i_gid = sd_v2_gid(sd);
7313                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7314                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7315                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7316 @@ -1219,6 +1224,10 @@ static void init_inode(struct inode *ino
7317                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7318         }
7319  
7320 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7321 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7322 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7323 +
7324         pathrelse(path);
7325         if (S_ISREG(inode->i_mode)) {
7326                 inode->i_op = &reiserfs_file_inode_operations;
7327 @@ -1241,13 +1250,15 @@ static void init_inode(struct inode *ino
7328  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7329  {
7330         struct stat_data *sd_v2 = (struct stat_data *)sd;
7331 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7332 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7333         __u16 flags;
7334  
7335 +       set_sd_v2_uid(sd_v2, uid);
7336 +       set_sd_v2_gid(sd_v2, gid);
7337         set_sd_v2_mode(sd_v2, inode->i_mode);
7338         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7339 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7340         set_sd_v2_size(sd_v2, size);
7341 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7342         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7343         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7344         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7345 @@ -2839,14 +2850,19 @@ int reiserfs_commit_write(struct file *f
7346  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7347  {
7348         if (reiserfs_attrs(inode->i_sb)) {
7349 -               if (sd_attrs & REISERFS_SYNC_FL)
7350 -                       inode->i_flags |= S_SYNC;
7351 -               else
7352 -                       inode->i_flags &= ~S_SYNC;
7353                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7354                         inode->i_flags |= S_IMMUTABLE;
7355                 else
7356                         inode->i_flags &= ~S_IMMUTABLE;
7357 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7358 +                       inode->i_flags |= S_IXUNLINK;
7359 +               else
7360 +                       inode->i_flags &= ~S_IXUNLINK;
7361 +
7362 +               if (sd_attrs & REISERFS_SYNC_FL)
7363 +                       inode->i_flags |= S_SYNC;
7364 +               else
7365 +                       inode->i_flags &= ~S_SYNC;
7366                 if (sd_attrs & REISERFS_APPEND_FL)
7367                         inode->i_flags |= S_APPEND;
7368                 else
7369 @@ -2859,6 +2875,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7370                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7371                 else
7372                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7373 +
7374 +               if (sd_attrs & REISERFS_BARRIER_FL)
7375 +                       inode->i_vflags |= V_BARRIER;
7376 +               else
7377 +                       inode->i_vflags &= ~V_BARRIER;
7378 +               if (sd_attrs & REISERFS_COW_FL)
7379 +                       inode->i_vflags |= V_COW;
7380 +               else
7381 +                       inode->i_vflags &= ~V_COW;
7382         }
7383  }
7384  
7385 @@ -2869,6 +2894,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7386                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7387                 else
7388                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7389 +               if (inode->i_flags & S_IXUNLINK)
7390 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7391 +               else
7392 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7393 +
7394                 if (inode->i_flags & S_SYNC)
7395                         *sd_attrs |= REISERFS_SYNC_FL;
7396                 else
7397 @@ -2881,6 +2911,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7398                         *sd_attrs |= REISERFS_NOTAIL_FL;
7399                 else
7400                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7401 +
7402 +               if (inode->i_vflags & V_BARRIER)
7403 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7404 +               else
7405 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7406 +               if (inode->i_vflags & V_COW)
7407 +                       *sd_attrs |= REISERFS_COW_FL;
7408 +               else
7409 +                       *sd_attrs &= ~REISERFS_COW_FL;
7410         }
7411  }
7412  
7413 @@ -3101,9 +3140,11 @@ int reiserfs_setattr(struct dentry *dent
7414         }
7415  
7416         error = inode_change_ok(inode, attr);
7417 +
7418         if (!error) {
7419                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7420 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7421 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7422 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7423                         error = reiserfs_chown_xattrs(inode, attr);
7424  
7425                         if (!error) {
7426 @@ -3133,6 +3174,9 @@ int reiserfs_setattr(struct dentry *dent
7427                                         inode->i_uid = attr->ia_uid;
7428                                 if (attr->ia_valid & ATTR_GID)
7429                                         inode->i_gid = attr->ia_gid;
7430 +                               if ((attr->ia_valid & ATTR_TAG) &&
7431 +                                       IS_TAGGED(inode))
7432 +                                       inode->i_tag = attr->ia_tag;
7433                                 mark_inode_dirty(inode);
7434                                 error =
7435                                     journal_end(&th, inode->i_sb, jbegin_count);
7436 diff -NurpP --minimal linux-2.6.32.24/fs/reiserfs/ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/ioctl.c
7437 --- linux-2.6.32.24/fs/reiserfs/ioctl.c 2009-06-11 17:13:08.000000000 +0200
7438 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/ioctl.c 2009-12-03 20:04:56.000000000 +0100
7439 @@ -7,11 +7,27 @@
7440  #include <linux/mount.h>
7441  #include <linux/reiserfs_fs.h>
7442  #include <linux/time.h>
7443 +#include <linux/mount.h>
7444  #include <asm/uaccess.h>
7445  #include <linux/pagemap.h>
7446  #include <linux/smp_lock.h>
7447  #include <linux/compat.h>
7448  
7449 +
7450 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7451 +{
7452 +       __u16 sd_attrs = 0;
7453 +
7454 +       inode->i_flags = flags;
7455 +       inode->i_vflags = vflags;
7456 +
7457 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7458 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7459 +       inode->i_ctime = CURRENT_TIME_SEC;
7460 +       mark_inode_dirty(inode);
7461 +       return 0;
7462 +}
7463 +
7464  /*
7465  ** reiserfs_ioctl - handler for ioctl for inode
7466  ** supported commands:
7467 @@ -23,7 +39,7 @@
7468  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7469                    unsigned long arg)
7470  {
7471 -       unsigned int flags;
7472 +       unsigned int flags, oldflags;
7473         int err = 0;
7474  
7475         switch (cmd) {
7476 @@ -43,6 +59,7 @@ int reiserfs_ioctl(struct inode *inode, 
7477  
7478                 flags = REISERFS_I(inode)->i_attrs;
7479                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7480 +               flags &= REISERFS_FL_USER_VISIBLE;
7481                 return put_user(flags, (int __user *)arg);
7482         case REISERFS_IOC_SETFLAGS:{
7483                         if (!reiserfs_attrs(inode->i_sb))
7484 @@ -60,6 +77,10 @@ int reiserfs_ioctl(struct inode *inode, 
7485                                 err = -EFAULT;
7486                                 goto setflags_out;
7487                         }
7488 +                       if (IS_BARRIER(inode)) {
7489 +                               vxwprintk_task(1, "messing with the barrier.");
7490 +                               return -EACCES;
7491 +                       }
7492                         /*
7493                          * Is it quota file? Do not allow user to mess with it
7494                          */
7495 @@ -84,6 +105,10 @@ int reiserfs_ioctl(struct inode *inode, 
7496                                         goto setflags_out;
7497                                 }
7498                         }
7499 +
7500 +                       oldflags = REISERFS_I(inode)->i_attrs;
7501 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7502 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7503                         sd_attrs_to_i_attrs(flags, inode);
7504                         REISERFS_I(inode)->i_attrs = flags;
7505                         inode->i_ctime = CURRENT_TIME_SEC;
7506 diff -NurpP --minimal linux-2.6.32.24/fs/reiserfs/namei.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/namei.c
7507 --- linux-2.6.32.24/fs/reiserfs/namei.c 2009-06-11 17:13:08.000000000 +0200
7508 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/namei.c 2009-12-03 20:04:56.000000000 +0100
7509 @@ -17,6 +17,7 @@
7510  #include <linux/reiserfs_acl.h>
7511  #include <linux/reiserfs_xattr.h>
7512  #include <linux/quotaops.h>
7513 +#include <linux/vs_tag.h>
7514  
7515  #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; }
7516  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7517 @@ -354,6 +355,7 @@ static struct dentry *reiserfs_lookup(st
7518         if (retval == IO_ERROR) {
7519                 return ERR_PTR(-EIO);
7520         }
7521 +               dx_propagate_tag(nd, inode);
7522  
7523         return d_splice_alias(inode, dentry);
7524  }
7525 @@ -570,6 +572,7 @@ static int new_inode_init(struct inode *
7526         } else {
7527                 inode->i_gid = current_fsgid();
7528         }
7529 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7530         vfs_dq_init(inode);
7531         return 0;
7532  }
7533 @@ -1515,6 +1518,7 @@ const struct inode_operations reiserfs_d
7534         .listxattr = reiserfs_listxattr,
7535         .removexattr = reiserfs_removexattr,
7536         .permission = reiserfs_permission,
7537 +       .sync_flags = reiserfs_sync_flags,
7538  };
7539  
7540  /*
7541 diff -NurpP --minimal linux-2.6.32.24/fs/reiserfs/super.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/super.c
7542 --- linux-2.6.32.24/fs/reiserfs/super.c 2009-12-03 20:02:53.000000000 +0100
7543 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/super.c 2009-12-03 20:04:56.000000000 +0100
7544 @@ -884,6 +884,14 @@ static int reiserfs_parse_options(struct
7545                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7546                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7547  #endif
7548 +#ifndef CONFIG_TAGGING_NONE
7549 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7550 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7551 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7552 +#endif
7553 +#ifdef CONFIG_PROPAGATE
7554 +               {"tag",.arg_required = 'T',.values = NULL},
7555 +#endif
7556  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7557                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7558                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7559 @@ -1190,6 +1198,14 @@ static int reiserfs_remount(struct super
7560         handle_quota_files(s, qf_names, &qfmt);
7561  #endif
7562  
7563 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7564 +               !(s->s_flags & MS_TAGGED)) {
7565 +               reiserfs_warning(s, "super-vs01",
7566 +                       "reiserfs: tagging not permitted on remount.");
7567 +               err = -EINVAL;
7568 +               goto out_err;
7569 +       }
7570 +
7571         handle_attrs(s);
7572  
7573         /* Add options that are safe here */
7574 @@ -1652,6 +1668,10 @@ static int reiserfs_fill_super(struct su
7575                 goto error;
7576         }
7577  
7578 +       /* map mount option tagxid */
7579 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7580 +               s->s_flags |= MS_TAGGED;
7581 +
7582         rs = SB_DISK_SUPER_BLOCK(s);
7583         /* Let's do basic sanity check to verify that underlying device is not
7584            smaller than the filesystem. If the check fails then abort and scream,
7585 diff -NurpP --minimal linux-2.6.32.24/fs/reiserfs/xattr.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/xattr.c
7586 --- linux-2.6.32.24/fs/reiserfs/xattr.c 2010-10-04 08:56:14.000000000 +0200
7587 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/reiserfs/xattr.c 2010-05-21 13:20:19.000000000 +0200
7588 @@ -39,6 +39,7 @@
7589  #include <linux/namei.h>
7590  #include <linux/errno.h>
7591  #include <linux/fs.h>
7592 +#include <linux/mount.h>
7593  #include <linux/file.h>
7594  #include <linux/pagemap.h>
7595  #include <linux/xattr.h>
7596 diff -NurpP --minimal linux-2.6.32.24/fs/stat.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/stat.c
7597 --- linux-2.6.32.24/fs/stat.c   2010-10-04 08:56:14.000000000 +0200
7598 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/stat.c   2010-01-13 14:33:47.000000000 +0100
7599 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7600         stat->nlink = inode->i_nlink;
7601         stat->uid = inode->i_uid;
7602         stat->gid = inode->i_gid;
7603 +       stat->tag = inode->i_tag;
7604         stat->rdev = inode->i_rdev;
7605         stat->atime = inode->i_atime;
7606         stat->mtime = inode->i_mtime;
7607 diff -NurpP --minimal linux-2.6.32.24/fs/super.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/super.c
7608 --- linux-2.6.32.24/fs/super.c  2010-10-04 08:56:14.000000000 +0200
7609 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/super.c  2010-02-12 10:59:55.000000000 +0100
7610 @@ -37,6 +37,9 @@
7611  #include <linux/kobject.h>
7612  #include <linux/mutex.h>
7613  #include <linux/file.h>
7614 +#include <linux/devpts_fs.h>
7615 +#include <linux/proc_fs.h>
7616 +#include <linux/vs_context.h>
7617  #include <asm/uaccess.h>
7618  #include "internal.h"
7619  
7620 @@ -914,12 +917,18 @@ struct vfsmount *
7621  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7622  {
7623         struct vfsmount *mnt;
7624 +       struct super_block *sb;
7625         char *secdata = NULL;
7626         int error;
7627  
7628         if (!type)
7629                 return ERR_PTR(-ENODEV);
7630  
7631 +       error = -EPERM;
7632 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7633 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7634 +               goto out;
7635 +
7636         error = -ENOMEM;
7637         mnt = alloc_vfsmnt(name);
7638         if (!mnt)
7639 @@ -938,9 +947,17 @@ vfs_kern_mount(struct file_system_type *
7640         error = type->get_sb(type, flags, name, data, mnt);
7641         if (error < 0)
7642                 goto out_free_secdata;
7643 -       BUG_ON(!mnt->mnt_sb);
7644  
7645 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7646 +       sb = mnt->mnt_sb;
7647 +       BUG_ON(!sb);
7648 +
7649 +       error = -EPERM;
7650 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7651 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7652 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7653 +               goto out_sb;
7654 +
7655 +       error = security_sb_kern_mount(sb, flags, secdata);
7656         if (error)
7657                 goto out_sb;
7658  
7659 diff -NurpP --minimal linux-2.6.32.24/fs/sysfs/mount.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/sysfs/mount.c
7660 --- linux-2.6.32.24/fs/sysfs/mount.c    2009-06-11 17:13:08.000000000 +0200
7661 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/sysfs/mount.c    2009-12-03 20:04:56.000000000 +0100
7662 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7663  
7664         sb->s_blocksize = PAGE_CACHE_SIZE;
7665         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7666 -       sb->s_magic = SYSFS_MAGIC;
7667 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7668         sb->s_op = &sysfs_ops;
7669         sb->s_time_gran = 1;
7670         sysfs_sb = sb;
7671 diff -NurpP --minimal linux-2.6.32.24/fs/utimes.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/utimes.c
7672 --- linux-2.6.32.24/fs/utimes.c 2009-03-24 14:22:37.000000000 +0100
7673 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/utimes.c 2009-12-03 20:04:56.000000000 +0100
7674 @@ -8,6 +8,8 @@
7675  #include <linux/stat.h>
7676  #include <linux/utime.h>
7677  #include <linux/syscalls.h>
7678 +#include <linux/mount.h>
7679 +#include <linux/vs_cowbl.h>
7680  #include <asm/uaccess.h>
7681  #include <asm/unistd.h>
7682  
7683 diff -NurpP --minimal linux-2.6.32.24/fs/xattr.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/xattr.c
7684 --- linux-2.6.32.24/fs/xattr.c  2009-12-03 20:02:53.000000000 +0100
7685 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xattr.c  2010-03-13 21:50:00.000000000 +0100
7686 @@ -18,6 +18,7 @@
7687  #include <linux/module.h>
7688  #include <linux/fsnotify.h>
7689  #include <linux/audit.h>
7690 +#include <linux/mount.h>
7691  #include <asm/uaccess.h>
7692  
7693  
7694 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7695          * The trusted.* namespace can only be accessed by a privileged user.
7696          */
7697         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
7698 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
7699 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
7700  
7701         /* In user.* namespace, only regular files and directories can have
7702          * extended attributes. For sticky directories, only the owner and
7703 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/linux-2.6/xfs_ioctl.c
7704 --- linux-2.6.32.24/fs/xfs/linux-2.6/xfs_ioctl.c        2010-10-04 08:56:15.000000000 +0200
7705 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/linux-2.6/xfs_ioctl.c        2010-10-04 10:04:57.000000000 +0200
7706 @@ -34,7 +34,6 @@
7707  #include "xfs_dir2_sf.h"
7708  #include "xfs_dinode.h"
7709  #include "xfs_inode.h"
7710 -#include "xfs_ioctl.h"
7711  #include "xfs_btree.h"
7712  #include "xfs_ialloc.h"
7713  #include "xfs_rtalloc.h"
7714 @@ -742,6 +741,10 @@ xfs_merge_ioc_xflags(
7715                 xflags |= XFS_XFLAG_IMMUTABLE;
7716         else
7717                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7718 +       if (flags & FS_IXUNLINK_FL)
7719 +               xflags |= XFS_XFLAG_IXUNLINK;
7720 +       else
7721 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7722         if (flags & FS_APPEND_FL)
7723                 xflags |= XFS_XFLAG_APPEND;
7724         else
7725 @@ -770,6 +773,8 @@ xfs_di2lxflags(
7726  
7727         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7728                 flags |= FS_IMMUTABLE_FL;
7729 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7730 +               flags |= FS_IXUNLINK_FL;
7731         if (di_flags & XFS_DIFLAG_APPEND)
7732                 flags |= FS_APPEND_FL;
7733         if (di_flags & XFS_DIFLAG_SYNC)
7734 @@ -830,6 +835,8 @@ xfs_set_diflags(
7735         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7736         if (xflags & XFS_XFLAG_IMMUTABLE)
7737                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7738 +       if (xflags & XFS_XFLAG_IXUNLINK)
7739 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7740         if (xflags & XFS_XFLAG_APPEND)
7741                 di_flags |= XFS_DIFLAG_APPEND;
7742         if (xflags & XFS_XFLAG_SYNC)
7743 @@ -872,6 +879,10 @@ xfs_diflags_to_linux(
7744                 inode->i_flags |= S_IMMUTABLE;
7745         else
7746                 inode->i_flags &= ~S_IMMUTABLE;
7747 +       if (xflags & XFS_XFLAG_IXUNLINK)
7748 +               inode->i_flags |= S_IXUNLINK;
7749 +       else
7750 +               inode->i_flags &= ~S_IXUNLINK;
7751         if (xflags & XFS_XFLAG_APPEND)
7752                 inode->i_flags |= S_APPEND;
7753         else
7754 @@ -1348,10 +1359,18 @@ xfs_file_ioctl(
7755         case XFS_IOC_FSGETXATTRA:
7756                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7757         case XFS_IOC_FSSETXATTR:
7758 +               if (IS_BARRIER(inode)) {
7759 +                       vxwprintk_task(1, "messing with the barrier.");
7760 +                       return -XFS_ERROR(EACCES);
7761 +               }
7762                 return xfs_ioc_fssetxattr(ip, filp, arg);
7763         case XFS_IOC_GETXFLAGS:
7764                 return xfs_ioc_getxflags(ip, arg);
7765         case XFS_IOC_SETXFLAGS:
7766 +               if (IS_BARRIER(inode)) {
7767 +                       vxwprintk_task(1, "messing with the barrier.");
7768 +                       return -XFS_ERROR(EACCES);
7769 +               }
7770                 return xfs_ioc_setxflags(ip, filp, arg);
7771  
7772         case XFS_IOC_FSSETDM: {
7773 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/linux-2.6/xfs_ioctl.h
7774 --- linux-2.6.32.24/fs/xfs/linux-2.6/xfs_ioctl.h        2009-03-24 14:22:37.000000000 +0100
7775 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/linux-2.6/xfs_ioctl.h        2009-12-03 20:04:56.000000000 +0100
7776 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7777         void __user             *uhandle,
7778         u32                     hlen);
7779  
7780 +extern int
7781 +xfs_sync_flags(
7782 +       struct inode            *inode,
7783 +       int                     flags,
7784 +       int                     vflags);
7785 +
7786  extern long
7787  xfs_file_ioctl(
7788         struct file             *filp,
7789 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/linux-2.6/xfs_iops.c
7790 --- linux-2.6.32.24/fs/xfs/linux-2.6/xfs_iops.c 2010-10-04 08:56:15.000000000 +0200
7791 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/linux-2.6/xfs_iops.c 2010-04-28 10:19:35.000000000 +0200
7792 @@ -36,6 +36,7 @@
7793  #include "xfs_attr_sf.h"
7794  #include "xfs_dinode.h"
7795  #include "xfs_inode.h"
7796 +#include "xfs_ioctl.h"
7797  #include "xfs_bmap.h"
7798  #include "xfs_btree.h"
7799  #include "xfs_ialloc.h"
7800 @@ -55,6 +56,7 @@
7801  #include <linux/security.h>
7802  #include <linux/falloc.h>
7803  #include <linux/fiemap.h>
7804 +#include <linux/vs_tag.h>
7805  
7806  /*
7807   * Bring the timestamps in the XFS inode uptodate.
7808 @@ -495,6 +497,7 @@ xfs_vn_getattr(
7809         stat->nlink = ip->i_d.di_nlink;
7810         stat->uid = ip->i_d.di_uid;
7811         stat->gid = ip->i_d.di_gid;
7812 +       stat->tag = ip->i_d.di_tag;
7813         stat->ino = ip->i_ino;
7814         stat->atime = inode->i_atime;
7815         stat->mtime = inode->i_mtime;
7816 @@ -686,6 +689,7 @@ static const struct inode_operations xfs
7817         .listxattr              = xfs_vn_listxattr,
7818         .fallocate              = xfs_vn_fallocate,
7819         .fiemap                 = xfs_vn_fiemap,
7820 +       .sync_flags             = xfs_sync_flags,
7821  };
7822  
7823  static const struct inode_operations xfs_dir_inode_operations = {
7824 @@ -711,6 +715,7 @@ static const struct inode_operations xfs
7825         .getxattr               = generic_getxattr,
7826         .removexattr            = generic_removexattr,
7827         .listxattr              = xfs_vn_listxattr,
7828 +       .sync_flags             = xfs_sync_flags,
7829  };
7830  
7831  static const struct inode_operations xfs_dir_ci_inode_operations = {
7832 @@ -760,6 +765,10 @@ xfs_diflags_to_iflags(
7833                 inode->i_flags |= S_IMMUTABLE;
7834         else
7835                 inode->i_flags &= ~S_IMMUTABLE;
7836 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7837 +               inode->i_flags |= S_IXUNLINK;
7838 +       else
7839 +               inode->i_flags &= ~S_IXUNLINK;
7840         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7841                 inode->i_flags |= S_APPEND;
7842         else
7843 @@ -772,6 +781,15 @@ xfs_diflags_to_iflags(
7844                 inode->i_flags |= S_NOATIME;
7845         else
7846                 inode->i_flags &= ~S_NOATIME;
7847 +
7848 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7849 +               inode->i_vflags |= V_BARRIER;
7850 +       else
7851 +               inode->i_vflags &= ~V_BARRIER;
7852 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7853 +               inode->i_vflags |= V_COW;
7854 +       else
7855 +               inode->i_vflags &= ~V_COW;
7856  }
7857  
7858  /*
7859 @@ -800,6 +818,7 @@ xfs_setup_inode(
7860         inode->i_nlink  = ip->i_d.di_nlink;
7861         inode->i_uid    = ip->i_d.di_uid;
7862         inode->i_gid    = ip->i_d.di_gid;
7863 +       inode->i_tag    = ip->i_d.di_tag;
7864  
7865         switch (inode->i_mode & S_IFMT) {
7866         case S_IFBLK:
7867 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/linux-2.6/xfs_linux.h
7868 --- linux-2.6.32.24/fs/xfs/linux-2.6/xfs_linux.h        2009-09-10 15:26:24.000000000 +0200
7869 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/linux-2.6/xfs_linux.h        2009-12-03 20:04:56.000000000 +0100
7870 @@ -119,6 +119,7 @@
7871  
7872  #define current_cpu()          (raw_smp_processor_id())
7873  #define current_pid()          (current->pid)
7874 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
7875  #define current_test_flags(f)  (current->flags & (f))
7876  #define current_set_flags_nested(sp, f)                \
7877                 (*(sp) = current->flags, current->flags |= (f))
7878 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/linux-2.6/xfs_super.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/linux-2.6/xfs_super.c
7879 --- linux-2.6.32.24/fs/xfs/linux-2.6/xfs_super.c        2010-10-04 08:56:15.000000000 +0200
7880 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/linux-2.6/xfs_super.c        2010-05-21 13:20:19.000000000 +0200
7881 @@ -117,6 +117,9 @@ mempool_t *xfs_ioend_pool;
7882  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
7883  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
7884  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
7885 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7886 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7887 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7888  
7889  /*
7890   * Table driven mount option parser.
7891 @@ -125,10 +128,14 @@ mempool_t *xfs_ioend_pool;
7892   * in the future, too.
7893   */
7894  enum {
7895 +       Opt_tag, Opt_notag,
7896         Opt_barrier, Opt_nobarrier, Opt_err
7897  };
7898  
7899  static const match_table_t tokens = {
7900 +       {Opt_tag, "tagxid"},
7901 +       {Opt_tag, "tag"},
7902 +       {Opt_notag, "notag"},
7903         {Opt_barrier, "barrier"},
7904         {Opt_nobarrier, "nobarrier"},
7905         {Opt_err, NULL}
7906 @@ -382,6 +389,19 @@ xfs_parseargs(
7907                 } else if (!strcmp(this_char, "irixsgid")) {
7908                         cmn_err(CE_WARN,
7909         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7910 +#ifndef CONFIG_TAGGING_NONE
7911 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7912 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7913 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7914 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7915 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7916 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7917 +#endif
7918 +#ifdef CONFIG_PROPAGATE
7919 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7920 +                       /* use value */
7921 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7922 +#endif
7923                 } else {
7924                         cmn_err(CE_WARN,
7925                                 "XFS: unknown mount option [%s].", this_char);
7926 @@ -1295,6 +1315,16 @@ xfs_fs_remount(
7927                 case Opt_nobarrier:
7928                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7929                         break;
7930 +               case Opt_tag:
7931 +                       if (!(sb->s_flags & MS_TAGGED)) {
7932 +                               printk(KERN_INFO
7933 +                                       "XFS: %s: tagging not permitted on remount.\n",
7934 +                                       sb->s_id);
7935 +                               return -EINVAL;
7936 +                       }
7937 +                       break;
7938 +               case Opt_notag:
7939 +                       break;
7940                 default:
7941                         /*
7942                          * Logically we would return an error here to prevent
7943 @@ -1530,6 +1560,9 @@ xfs_fs_fill_super(
7944  
7945         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
7946  
7947 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7948 +               sb->s_flags |= MS_TAGGED;
7949 +
7950         sb->s_magic = XFS_SB_MAGIC;
7951         sb->s_blocksize = mp->m_sb.sb_blocksize;
7952         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
7953 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/xfs_dinode.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_dinode.h
7954 --- linux-2.6.32.24/fs/xfs/xfs_dinode.h 2009-06-11 17:13:09.000000000 +0200
7955 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_dinode.h 2009-12-03 20:04:56.000000000 +0100
7956 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
7957         __be32          di_gid;         /* owner's group id */
7958         __be32          di_nlink;       /* number of links to file */
7959         __be16          di_projid;      /* owner's project id */
7960 -       __u8            di_pad[8];      /* unused, zeroed space */
7961 +       __be16          di_tag;         /* context tagging */
7962 +       __be16          di_vflags;      /* vserver specific flags */
7963 +       __u8            di_pad[4];      /* unused, zeroed space */
7964         __be16          di_flushiter;   /* incremented on flush */
7965         xfs_timestamp_t di_atime;       /* time last accessed */
7966         xfs_timestamp_t di_mtime;       /* time last modified */
7967 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
7968  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7969  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7970  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7971 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7972 +
7973  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7974  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7975  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7976 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
7977  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7978  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7979  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7980 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7981  
7982  #ifdef CONFIG_XFS_RT
7983  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7984 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
7985          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7986          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7987          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7988 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7989 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7990 +        XFS_DIFLAG_IXUNLINK)
7991 +
7992 +#define XFS_DIVFLAG_BARRIER    0x01
7993 +#define XFS_DIVFLAG_COW                0x02
7994  
7995  #endif /* __XFS_DINODE_H__ */
7996 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/xfs_fs.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_fs.h
7997 --- linux-2.6.32.24/fs/xfs/xfs_fs.h     2009-12-03 20:02:53.000000000 +0100
7998 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_fs.h     2009-12-03 20:04:56.000000000 +0100
7999 @@ -67,6 +67,9 @@ struct fsxattr {
8000  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8001  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8002  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8003 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8004 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8005 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8006  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8007  
8008  /*
8009 @@ -292,7 +295,8 @@ typedef struct xfs_bstat {
8010         __s32           bs_extents;     /* number of extents            */
8011         __u32           bs_gen;         /* generation count             */
8012         __u16           bs_projid;      /* project id                   */
8013 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8014 +       __u16           bs_tag;         /* context tagging              */
8015 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8016         __u32           bs_dmevmask;    /* DMIG event mask              */
8017         __u16           bs_dmstate;     /* DMIG state info              */
8018         __u16           bs_aextents;    /* attribute number of extents  */
8019 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/xfs_ialloc.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_ialloc.c
8020 --- linux-2.6.32.24/fs/xfs/xfs_ialloc.c 2009-12-03 20:02:53.000000000 +0100
8021 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_ialloc.c 2009-12-03 20:04:56.000000000 +0100
8022 @@ -41,7 +41,6 @@
8023  #include "xfs_error.h"
8024  #include "xfs_bmap.h"
8025  
8026 -
8027  /*
8028   * Allocation group level functions.
8029   */
8030 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/xfs_inode.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_inode.c
8031 --- linux-2.6.32.24/fs/xfs/xfs_inode.c  2010-10-04 08:56:15.000000000 +0200
8032 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_inode.c  2010-04-28 10:19:35.000000000 +0200
8033 @@ -249,6 +249,7 @@ xfs_inotobp(
8034         return 0;
8035  }
8036  
8037 +#include <linux/vs_tag.h>
8038  
8039  /*
8040   * This routine is called to map an inode to the buffer containing
8041 @@ -654,15 +655,25 @@ xfs_iformat_btree(
8042  STATIC void
8043  xfs_dinode_from_disk(
8044         xfs_icdinode_t          *to,
8045 -       xfs_dinode_t            *from)
8046 +       xfs_dinode_t            *from,
8047 +       int tagged)
8048  {
8049 +       uint32_t uid, gid, tag;
8050 +
8051         to->di_magic = be16_to_cpu(from->di_magic);
8052         to->di_mode = be16_to_cpu(from->di_mode);
8053         to->di_version = from ->di_version;
8054         to->di_format = from->di_format;
8055         to->di_onlink = be16_to_cpu(from->di_onlink);
8056 -       to->di_uid = be32_to_cpu(from->di_uid);
8057 -       to->di_gid = be32_to_cpu(from->di_gid);
8058 +
8059 +       uid = be32_to_cpu(from->di_uid);
8060 +       gid = be32_to_cpu(from->di_gid);
8061 +       tag = be16_to_cpu(from->di_tag);
8062 +
8063 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8064 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8065 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8066 +
8067         to->di_nlink = be32_to_cpu(from->di_nlink);
8068         to->di_projid = be16_to_cpu(from->di_projid);
8069         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8070 @@ -683,21 +694,26 @@ xfs_dinode_from_disk(
8071         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8072         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8073         to->di_flags    = be16_to_cpu(from->di_flags);
8074 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8075         to->di_gen      = be32_to_cpu(from->di_gen);
8076  }
8077  
8078  void
8079  xfs_dinode_to_disk(
8080         xfs_dinode_t            *to,
8081 -       xfs_icdinode_t          *from)
8082 +       xfs_icdinode_t          *from,
8083 +       int tagged)
8084  {
8085         to->di_magic = cpu_to_be16(from->di_magic);
8086         to->di_mode = cpu_to_be16(from->di_mode);
8087         to->di_version = from ->di_version;
8088         to->di_format = from->di_format;
8089         to->di_onlink = cpu_to_be16(from->di_onlink);
8090 -       to->di_uid = cpu_to_be32(from->di_uid);
8091 -       to->di_gid = cpu_to_be32(from->di_gid);
8092 +
8093 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8094 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8095 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8096 +
8097         to->di_nlink = cpu_to_be32(from->di_nlink);
8098         to->di_projid = cpu_to_be16(from->di_projid);
8099         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8100 @@ -718,12 +734,14 @@ xfs_dinode_to_disk(
8101         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8102         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8103         to->di_flags = cpu_to_be16(from->di_flags);
8104 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8105         to->di_gen = cpu_to_be32(from->di_gen);
8106  }
8107  
8108  STATIC uint
8109  _xfs_dic2xflags(
8110 -       __uint16_t              di_flags)
8111 +       __uint16_t              di_flags,
8112 +       __uint16_t              di_vflags)
8113  {
8114         uint                    flags = 0;
8115  
8116 @@ -734,6 +752,8 @@ _xfs_dic2xflags(
8117                         flags |= XFS_XFLAG_PREALLOC;
8118                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8119                         flags |= XFS_XFLAG_IMMUTABLE;
8120 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8121 +                       flags |= XFS_XFLAG_IXUNLINK;
8122                 if (di_flags & XFS_DIFLAG_APPEND)
8123                         flags |= XFS_XFLAG_APPEND;
8124                 if (di_flags & XFS_DIFLAG_SYNC)
8125 @@ -758,6 +778,10 @@ _xfs_dic2xflags(
8126                         flags |= XFS_XFLAG_FILESTREAM;
8127         }
8128  
8129 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8130 +               flags |= FS_BARRIER_FL;
8131 +       if (di_vflags & XFS_DIVFLAG_COW)
8132 +               flags |= FS_COW_FL;
8133         return flags;
8134  }
8135  
8136 @@ -767,7 +791,7 @@ xfs_ip2xflags(
8137  {
8138         xfs_icdinode_t          *dic = &ip->i_d;
8139  
8140 -       return _xfs_dic2xflags(dic->di_flags) |
8141 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8142                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8143  }
8144  
8145 @@ -775,7 +799,8 @@ uint
8146  xfs_dic2xflags(
8147         xfs_dinode_t            *dip)
8148  {
8149 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8150 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8151 +                               be16_to_cpu(dip->di_vflags)) |
8152                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8153  }
8154  
8155 @@ -811,7 +836,6 @@ xfs_iread(
8156         if (error)
8157                 return error;
8158         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8159 -
8160         /*
8161          * If we got something that isn't an inode it means someone
8162          * (nfs or dmi) has a stale handle.
8163 @@ -836,7 +860,8 @@ xfs_iread(
8164          * Otherwise, just get the truly permanent information.
8165          */
8166         if (dip->di_mode) {
8167 -               xfs_dinode_from_disk(&ip->i_d, dip);
8168 +               xfs_dinode_from_disk(&ip->i_d, dip,
8169 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8170                 error = xfs_iformat(ip, dip);
8171                 if (error)  {
8172  #ifdef DEBUG
8173 @@ -1036,6 +1061,7 @@ xfs_ialloc(
8174         ASSERT(ip->i_d.di_nlink == nlink);
8175         ip->i_d.di_uid = current_fsuid();
8176         ip->i_d.di_gid = current_fsgid();
8177 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8178         ip->i_d.di_projid = prid;
8179         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8180  
8181 @@ -1096,6 +1122,7 @@ xfs_ialloc(
8182         ip->i_d.di_dmevmask = 0;
8183         ip->i_d.di_dmstate = 0;
8184         ip->i_d.di_flags = 0;
8185 +       ip->i_d.di_vflags = 0;
8186         flags = XFS_ILOG_CORE;
8187         switch (mode & S_IFMT) {
8188         case S_IFIFO:
8189 @@ -2172,6 +2199,7 @@ xfs_ifree(
8190         }
8191         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8192         ip->i_d.di_flags = 0;
8193 +       ip->i_d.di_vflags = 0;
8194         ip->i_d.di_dmevmask = 0;
8195         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8196         ip->i_df.if_ext_max =
8197 @@ -3152,7 +3180,8 @@ xfs_iflush_int(
8198          * because if the inode is dirty at all the core must
8199          * be.
8200          */
8201 -       xfs_dinode_to_disk(dip, &ip->i_d);
8202 +       xfs_dinode_to_disk(dip, &ip->i_d,
8203 +               mp->m_flags & XFS_MOUNT_TAGGED);
8204  
8205         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8206         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8207 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/xfs_inode.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_inode.h
8208 --- linux-2.6.32.24/fs/xfs/xfs_inode.h  2009-12-03 20:02:54.000000000 +0100
8209 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_inode.h  2009-12-03 20:04:56.000000000 +0100
8210 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8211         __uint32_t      di_gid;         /* owner's group id */
8212         __uint32_t      di_nlink;       /* number of links to file */
8213         __uint16_t      di_projid;      /* owner's project id */
8214 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8215 +       __uint16_t      di_tag;         /* context tagging */
8216 +       __uint16_t      di_vflags;      /* vserver specific flags */
8217 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8218         __uint16_t      di_flushiter;   /* incremented on flush */
8219         xfs_ictimestamp_t di_atime;     /* time last accessed */
8220         xfs_ictimestamp_t di_mtime;     /* time last modified */
8221 @@ -569,7 +571,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8222  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8223                           struct xfs_inode *, xfs_daddr_t, uint);
8224  void           xfs_dinode_to_disk(struct xfs_dinode *,
8225 -                                  struct xfs_icdinode *);
8226 +                                  struct xfs_icdinode *, int);
8227  void           xfs_idestroy_fork(struct xfs_inode *, int);
8228  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8229  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8230 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/xfs_itable.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_itable.c
8231 --- linux-2.6.32.24/fs/xfs/xfs_itable.c 2009-12-03 20:02:54.000000000 +0100
8232 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_itable.c 2009-12-03 20:04:56.000000000 +0100
8233 @@ -84,6 +84,7 @@ xfs_bulkstat_one_iget(
8234         buf->bs_mode = dic->di_mode;
8235         buf->bs_uid = dic->di_uid;
8236         buf->bs_gid = dic->di_gid;
8237 +       buf->bs_tag = dic->di_tag;
8238         buf->bs_size = dic->di_size;
8239  
8240         /*
8241 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/xfs_log_recover.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_log_recover.c
8242 --- linux-2.6.32.24/fs/xfs/xfs_log_recover.c    2010-10-04 08:56:15.000000000 +0200
8243 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_log_recover.c    2010-04-28 10:19:35.000000000 +0200
8244 @@ -2467,7 +2467,8 @@ xlog_recover_do_inode_trans(
8245         }
8246  
8247         /* The core is in in-core format */
8248 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8249 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8250 +               mp->m_flags & XFS_MOUNT_TAGGED);
8251  
8252         /* the rest is in on-disk format */
8253         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8254 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/xfs_mount.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_mount.h
8255 --- linux-2.6.32.24/fs/xfs/xfs_mount.h  2010-10-04 08:56:15.000000000 +0200
8256 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_mount.h  2010-05-21 13:20:19.000000000 +0200
8257 @@ -285,6 +285,7 @@ typedef struct xfs_mount {
8258                                                    allocator */
8259  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8260  
8261 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8262  
8263  /*
8264   * Default minimum read and write sizes.
8265 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/xfs_vnodeops.c linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_vnodeops.c
8266 --- linux-2.6.32.24/fs/xfs/xfs_vnodeops.c       2010-10-04 08:56:15.000000000 +0200
8267 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_vnodeops.c       2010-04-28 10:20:09.000000000 +0200
8268 @@ -54,6 +54,80 @@
8269  #include "xfs_filestream.h"
8270  #include "xfs_vnodeops.h"
8271  
8272 +
8273 +STATIC void
8274 +xfs_get_inode_flags(
8275 +       xfs_inode_t     *ip)
8276 +{
8277 +       struct inode    *inode = VFS_I(ip);
8278 +       unsigned int    flags = inode->i_flags;
8279 +       unsigned int    vflags = inode->i_vflags;
8280 +
8281 +       if (flags & S_IMMUTABLE)
8282 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8283 +       else
8284 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8285 +       if (flags & S_IXUNLINK)
8286 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8287 +       else
8288 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8289 +
8290 +       if (vflags & V_BARRIER)
8291 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8292 +       else
8293 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8294 +       if (vflags & V_COW)
8295 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8296 +       else
8297 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8298 +}
8299 +
8300 +int
8301 +xfs_sync_flags(
8302 +       struct inode            *inode,
8303 +       int                     flags,
8304 +       int                     vflags)
8305 +{
8306 +       struct xfs_inode        *ip = XFS_I(inode);
8307 +       struct xfs_mount        *mp = ip->i_mount;
8308 +       struct xfs_trans        *tp;
8309 +       unsigned int            lock_flags = 0;
8310 +       int                     code;
8311 +
8312 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8313 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8314 +       if (code)
8315 +               goto error_out;
8316 +
8317 +       lock_flags = XFS_ILOCK_EXCL;
8318 +       xfs_ilock(ip, lock_flags);
8319 +
8320 +       xfs_trans_ijoin(tp, ip, lock_flags);
8321 +       xfs_trans_ihold(tp, ip);
8322 +
8323 +       inode->i_flags = flags;
8324 +       inode->i_vflags = vflags;
8325 +       xfs_get_inode_flags(ip);
8326 +
8327 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8328 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8329 +
8330 +       XFS_STATS_INC(xs_ig_attrchg);
8331 +
8332 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8333 +               xfs_trans_set_sync(tp);
8334 +       code = xfs_trans_commit(tp, 0);
8335 +       xfs_iunlock(ip, lock_flags);
8336 +       return code;
8337 +
8338 +error_out:
8339 +       xfs_trans_cancel(tp, 0);
8340 +       if (lock_flags)
8341 +               xfs_iunlock(ip, lock_flags);
8342 +       return code;
8343 +}
8344 +
8345 +
8346  int
8347  xfs_setattr(
8348         struct xfs_inode        *ip,
8349 @@ -69,6 +143,7 @@ xfs_setattr(
8350         uint                    commit_flags=0;
8351         uid_t                   uid=0, iuid=0;
8352         gid_t                   gid=0, igid=0;
8353 +       tag_t                   tag=0, itag=0;
8354         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8355         int                     need_iolock = 1;
8356  
8357 @@ -161,7 +236,7 @@ xfs_setattr(
8358         /*
8359          * Change file ownership.  Must be the owner or privileged.
8360          */
8361 -       if (mask & (ATTR_UID|ATTR_GID)) {
8362 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8363                 /*
8364                  * These IDs could have changed since we last looked at them.
8365                  * But, we're assured that if the ownership did change
8366 @@ -170,8 +245,10 @@ xfs_setattr(
8367                  */
8368                 iuid = ip->i_d.di_uid;
8369                 igid = ip->i_d.di_gid;
8370 +               itag = ip->i_d.di_tag;
8371                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8372                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8373 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8374  
8375                 /*
8376                  * Do a quota reservation only if uid/gid is actually
8377 @@ -179,7 +256,8 @@ xfs_setattr(
8378                  */
8379                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8380                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8381 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8382 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8383 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8384                         ASSERT(tp);
8385                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8386                                                 capable(CAP_FOWNER) ?
8387 @@ -340,7 +418,7 @@ xfs_setattr(
8388         /*
8389          * Change file ownership.  Must be the owner or privileged.
8390          */
8391 -       if (mask & (ATTR_UID|ATTR_GID)) {
8392 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8393                 /*
8394                  * CAP_FSETID overrides the following restrictions:
8395                  *
8396 @@ -356,6 +434,10 @@ xfs_setattr(
8397                  * Change the ownerships and register quota modifications
8398                  * in the transaction.
8399                  */
8400 +               if (itag != tag) {
8401 +                       ip->i_d.di_tag = tag;
8402 +                       inode->i_tag = tag;
8403 +               }
8404                 if (iuid != uid) {
8405                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8406                                 ASSERT(mask & ATTR_UID);
8407 diff -NurpP --minimal linux-2.6.32.24/fs/xfs/xfs_vnodeops.h linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_vnodeops.h
8408 --- linux-2.6.32.24/fs/xfs/xfs_vnodeops.h       2010-10-04 08:56:15.000000000 +0200
8409 +++ linux-2.6.32.24-vs2.3.0.36.29.6/fs/xfs/xfs_vnodeops.h       2010-04-28 10:19:38.000000000 +0200
8410 @@ -14,6 +14,7 @@ struct xfs_inode;
8411  struct xfs_iomap;
8412  
8413  
8414 +int xfs_sync_xflags(struct xfs_inode *ip);
8415  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8416  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8417  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8418 diff -NurpP --minimal linux-2.6.32.24/include/asm-generic/tlb.h linux-2.6.32.24-vs2.3.0.36.29.6/include/asm-generic/tlb.h
8419 --- linux-2.6.32.24/include/asm-generic/tlb.h   2009-09-10 15:26:24.000000000 +0200
8420 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/asm-generic/tlb.h   2009-12-03 20:04:56.000000000 +0100
8421 @@ -14,6 +14,7 @@
8422  #define _ASM_GENERIC__TLB_H
8423  
8424  #include <linux/swap.h>
8425 +#include <linux/vs_memory.h>
8426  #include <asm/pgalloc.h>
8427  #include <asm/tlbflush.h>
8428  
8429 diff -NurpP --minimal linux-2.6.32.24/include/linux/capability.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/capability.h
8430 --- linux-2.6.32.24/include/linux/capability.h  2009-12-03 20:02:54.000000000 +0100
8431 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/capability.h  2009-12-03 20:04:56.000000000 +0100
8432 @@ -285,6 +285,7 @@ struct cpu_vfs_cap_data {
8433     arbitrary SCSI commands */
8434  /* Allow setting encryption key on loopback filesystem */
8435  /* Allow setting zone reclaim policy */
8436 +/* Allow the selection of a security context */
8437  
8438  #define CAP_SYS_ADMIN        21
8439  
8440 @@ -357,7 +358,13 @@ struct cpu_vfs_cap_data {
8441  
8442  #define CAP_MAC_ADMIN        33
8443  
8444 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8445 +/* Allow context manipulations */
8446 +/* Allow changing context info on files */
8447 +
8448 +#define CAP_CONTEXT         34
8449 +
8450 +
8451 +#define CAP_LAST_CAP         CAP_CONTEXT
8452  
8453  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8454  
8455 diff -NurpP --minimal linux-2.6.32.24/include/linux/devpts_fs.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/devpts_fs.h
8456 --- linux-2.6.32.24/include/linux/devpts_fs.h   2008-12-25 00:26:37.000000000 +0100
8457 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/devpts_fs.h   2009-12-03 20:04:56.000000000 +0100
8458 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8459  
8460  #endif
8461  
8462 -
8463  #endif /* _LINUX_DEVPTS_FS_H */
8464 diff -NurpP --minimal linux-2.6.32.24/include/linux/ext2_fs.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/ext2_fs.h
8465 --- linux-2.6.32.24/include/linux/ext2_fs.h     2009-03-24 14:22:41.000000000 +0100
8466 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/ext2_fs.h     2009-12-03 20:04:56.000000000 +0100
8467 @@ -189,8 +189,12 @@ struct ext2_group_desc
8468  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8469  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8470  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8471 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8472  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8473  
8474 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8475 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8476 +
8477  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8478  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8479  
8480 @@ -274,7 +278,8 @@ struct ext2_inode {
8481                         __u16   i_pad1;
8482                         __le16  l_i_uid_high;   /* these 2 fields    */
8483                         __le16  l_i_gid_high;   /* were reserved2[0] */
8484 -                       __u32   l_i_reserved2;
8485 +                       __le16  l_i_tag;        /* Context Tag */
8486 +                       __u16   l_i_reserved2;
8487                 } linux2;
8488                 struct {
8489                         __u8    h_i_frag;       /* Fragment number */
8490 @@ -303,6 +308,7 @@ struct ext2_inode {
8491  #define i_gid_low      i_gid
8492  #define i_uid_high     osd2.linux2.l_i_uid_high
8493  #define i_gid_high     osd2.linux2.l_i_gid_high
8494 +#define i_raw_tag      osd2.linux2.l_i_tag
8495  #define i_reserved2    osd2.linux2.l_i_reserved2
8496  #endif
8497  
8498 @@ -347,6 +353,7 @@ struct ext2_inode {
8499  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8500  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8501  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8502 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8503  
8504  
8505  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8506 diff -NurpP --minimal linux-2.6.32.24/include/linux/ext3_fs.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/ext3_fs.h
8507 --- linux-2.6.32.24/include/linux/ext3_fs.h     2009-09-10 15:26:25.000000000 +0200
8508 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/ext3_fs.h     2009-12-03 20:04:56.000000000 +0100
8509 @@ -173,10 +173,14 @@ struct ext3_group_desc
8510  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8511  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8512  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8513 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8514  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8515  
8516 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8517 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8518 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8519 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8520 +
8521 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8522 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8523  
8524  /* Flags that should be inherited by new inodes from their parent. */
8525  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8526 @@ -320,7 +324,8 @@ struct ext3_inode {
8527                         __u16   i_pad1;
8528                         __le16  l_i_uid_high;   /* these 2 fields    */
8529                         __le16  l_i_gid_high;   /* were reserved2[0] */
8530 -                       __u32   l_i_reserved2;
8531 +                       __le16  l_i_tag;        /* Context Tag */
8532 +                       __u16   l_i_reserved2;
8533                 } linux2;
8534                 struct {
8535                         __u8    h_i_frag;       /* Fragment number */
8536 @@ -351,6 +356,7 @@ struct ext3_inode {
8537  #define i_gid_low      i_gid
8538  #define i_uid_high     osd2.linux2.l_i_uid_high
8539  #define i_gid_high     osd2.linux2.l_i_gid_high
8540 +#define i_raw_tag      osd2.linux2.l_i_tag
8541  #define i_reserved2    osd2.linux2.l_i_reserved2
8542  
8543  #elif defined(__GNU__)
8544 @@ -414,6 +420,7 @@ struct ext3_inode {
8545  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8546  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8547                                                   * error in ordered mode */
8548 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8549  
8550  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8551  #ifndef _LINUX_EXT2_FS_H
8552 @@ -892,6 +899,7 @@ extern void ext3_get_inode_flags(struct 
8553  extern void ext3_set_aops(struct inode *inode);
8554  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8555                        u64 start, u64 len);
8556 +extern int ext3_sync_flags(struct inode *, int, int);
8557  
8558  /* ioctl.c */
8559  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8560 diff -NurpP --minimal linux-2.6.32.24/include/linux/fs.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/fs.h
8561 --- linux-2.6.32.24/include/linux/fs.h  2010-10-04 08:56:16.000000000 +0200
8562 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/fs.h  2010-08-19 17:35:34.000000000 +0200
8563 @@ -208,6 +208,9 @@ struct inodes_stat_t {
8564  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8565  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8566  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8567 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8568 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8569 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8570  #define MS_ACTIVE      (1<<30)
8571  #define MS_NOUSER      (1<<31)
8572  
8573 @@ -234,6 +237,14 @@ struct inodes_stat_t {
8574  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8575  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8576  #define S_PRIVATE      512     /* Inode is fs-internal */
8577 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8578 +
8579 +/* Linux-VServer related Inode flags */
8580 +
8581 +#define V_VALID                1
8582 +#define V_XATTR                2
8583 +#define V_BARRIER      4       /* Barrier for chroot() */
8584 +#define V_COW          8       /* Copy on Write */
8585  
8586  /*
8587   * Note that nosuid etc flags are inode-specific: setting some file-system
8588 @@ -256,12 +267,15 @@ struct inodes_stat_t {
8589  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8590                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8591  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8592 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8593 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8594 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8595 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8596 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8597  
8598  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8599  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8600  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8601 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8602 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8603  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8604  
8605  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8606 @@ -269,6 +283,16 @@ struct inodes_stat_t {
8607  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8608  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8609  
8610 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8611 +
8612 +#ifdef CONFIG_VSERVER_COWBL
8613 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8614 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8615 +#else
8616 +#  define IS_COW(inode)                (0)
8617 +#  define IS_COW_LINK(inode)   (0)
8618 +#endif
8619 +
8620  /* the read-only stuff doesn't really belong here, but any other place is
8621     probably as bad and I don't want to create yet another include file. */
8622  
8623 @@ -350,11 +374,14 @@ struct inodes_stat_t {
8624  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8625  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8626  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8627 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8628  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8629  
8630 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8631 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8632 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8633 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8634  
8635 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8636 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8637  
8638  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8639  #define SYNC_FILE_RANGE_WRITE          2
8640 @@ -436,6 +463,7 @@ typedef void (dio_iodone_t)(struct kiocb
8641  #define ATTR_KILL_PRIV (1 << 14)
8642  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8643  #define ATTR_TIMES_SET (1 << 16)
8644 +#define ATTR_TAG       (1 << 17)
8645  
8646  /*
8647   * This is the Inode Attributes structure, used for notify_change().  It
8648 @@ -451,6 +479,7 @@ struct iattr {
8649         umode_t         ia_mode;
8650         uid_t           ia_uid;
8651         gid_t           ia_gid;
8652 +       tag_t           ia_tag;
8653         loff_t          ia_size;
8654         struct timespec ia_atime;
8655         struct timespec ia_mtime;
8656 @@ -464,6 +493,9 @@ struct iattr {
8657         struct file     *ia_file;
8658  };
8659  
8660 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8661 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8662 +
8663  /*
8664   * Includes for diskquotas.
8665   */
8666 @@ -729,7 +761,9 @@ struct inode {
8667         unsigned int            i_nlink;
8668         uid_t                   i_uid;
8669         gid_t                   i_gid;
8670 +       tag_t                   i_tag;
8671         dev_t                   i_rdev;
8672 +       dev_t                   i_mdev;
8673         u64                     i_version;
8674         loff_t                  i_size;
8675  #ifdef __NEED_I_SIZE_ORDERED
8676 @@ -776,7 +810,8 @@ struct inode {
8677         unsigned long           i_state;
8678         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8679  
8680 -       unsigned int            i_flags;
8681 +       unsigned short          i_flags;
8682 +       unsigned short          i_vflags;
8683  
8684         atomic_t                i_writecount;
8685  #ifdef CONFIG_SECURITY
8686 @@ -864,12 +899,12 @@ static inline void i_size_write(struct i
8687  
8688  static inline unsigned iminor(const struct inode *inode)
8689  {
8690 -       return MINOR(inode->i_rdev);
8691 +       return MINOR(inode->i_mdev);
8692  }
8693  
8694  static inline unsigned imajor(const struct inode *inode)
8695  {
8696 -       return MAJOR(inode->i_rdev);
8697 +       return MAJOR(inode->i_mdev);
8698  }
8699  
8700  extern struct block_device *I_BDEV(struct inode *inode);
8701 @@ -928,6 +963,7 @@ struct file {
8702         loff_t                  f_pos;
8703         struct fown_struct      f_owner;
8704         const struct cred       *f_cred;
8705 +       xid_t                   f_xid;
8706         struct file_ra_state    f_ra;
8707  
8708         u64                     f_version;
8709 @@ -1069,6 +1105,7 @@ struct file_lock {
8710         struct file *fl_file;
8711         loff_t fl_start;
8712         loff_t fl_end;
8713 +       xid_t fl_xid;
8714  
8715         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8716         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8717 @@ -1536,6 +1573,7 @@ struct inode_operations {
8718         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8719         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8720         int (*removexattr) (struct dentry *, const char *);
8721 +       int (*sync_flags) (struct inode *, int, int);
8722         void (*truncate_range)(struct inode *, loff_t, loff_t);
8723         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8724                           loff_t len);
8725 @@ -1556,6 +1594,7 @@ extern ssize_t vfs_readv(struct file *, 
8726                 unsigned long, loff_t *);
8727  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8728                 unsigned long, loff_t *);
8729 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8730  
8731  struct super_operations {
8732         struct inode *(*alloc_inode)(struct super_block *sb);
8733 @@ -2354,6 +2393,7 @@ extern int dcache_dir_open(struct inode 
8734  extern int dcache_dir_close(struct inode *, struct file *);
8735  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8736  extern int dcache_readdir(struct file *, void *, filldir_t);
8737 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8738  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8739  extern int simple_statfs(struct dentry *, struct kstatfs *);
8740  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8741 diff -NurpP --minimal linux-2.6.32.24/include/linux/gfs2_ondisk.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/gfs2_ondisk.h
8742 --- linux-2.6.32.24/include/linux/gfs2_ondisk.h 2009-12-03 20:02:55.000000000 +0100
8743 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/gfs2_ondisk.h 2009-12-03 20:04:56.000000000 +0100
8744 @@ -235,6 +235,9 @@ enum {
8745         gfs2fl_NoAtime          = 7,
8746         gfs2fl_Sync             = 8,
8747         gfs2fl_System           = 9,
8748 +       gfs2fl_IXUnlink         = 16,
8749 +       gfs2fl_Barrier          = 17,
8750 +       gfs2fl_Cow              = 18,
8751         gfs2fl_TruncInProg      = 29,
8752         gfs2fl_InheritDirectio  = 30,
8753         gfs2fl_InheritJdata     = 31,
8754 @@ -251,6 +254,9 @@ enum {
8755  #define GFS2_DIF_NOATIME               0x00000080
8756  #define GFS2_DIF_SYNC                  0x00000100
8757  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8758 +#define GFS2_DIF_IXUNLINK              0x00010000
8759 +#define GFS2_DIF_BARRIER               0x00020000
8760 +#define GFS2_DIF_COW                   0x00040000
8761  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8762  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8763  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8764 diff -NurpP --minimal linux-2.6.32.24/include/linux/if_tun.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/if_tun.h
8765 --- linux-2.6.32.24/include/linux/if_tun.h      2009-12-03 20:02:55.000000000 +0100
8766 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/if_tun.h      2009-12-03 20:04:56.000000000 +0100
8767 @@ -48,6 +48,7 @@
8768  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8769  #define TUNGETSNDBUF   _IOR('T', 211, int)
8770  #define TUNSETSNDBUF   _IOW('T', 212, int)
8771 +#define TUNSETNID     _IOW('T', 215, int)
8772  
8773  /* TUNSETIFF ifr flags */
8774  #define IFF_TUN                0x0001
8775 diff -NurpP --minimal linux-2.6.32.24/include/linux/init_task.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/init_task.h
8776 --- linux-2.6.32.24/include/linux/init_task.h   2009-12-03 20:02:55.000000000 +0100
8777 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/init_task.h   2009-12-03 20:04:56.000000000 +0100
8778 @@ -184,6 +184,10 @@ extern struct cred init_cred;
8779         INIT_FTRACE_GRAPH                                               \
8780         INIT_TRACE_RECURSION                                            \
8781         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8782 +       .xid            = 0,                                            \
8783 +       .vx_info        = NULL,                                         \
8784 +       .nid            = 0,                                            \
8785 +       .nx_info        = NULL,                                         \
8786  }
8787  
8788  
8789 diff -NurpP --minimal linux-2.6.32.24/include/linux/ipc.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/ipc.h
8790 --- linux-2.6.32.24/include/linux/ipc.h 2009-12-03 20:02:55.000000000 +0100
8791 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/ipc.h 2009-12-03 20:04:56.000000000 +0100
8792 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8793         key_t           key;
8794         uid_t           uid;
8795         gid_t           gid;
8796 +       xid_t           xid;
8797         uid_t           cuid;
8798         gid_t           cgid;
8799         mode_t          mode; 
8800 diff -NurpP --minimal linux-2.6.32.24/include/linux/Kbuild linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/Kbuild
8801 --- linux-2.6.32.24/include/linux/Kbuild        2009-12-03 20:02:54.000000000 +0100
8802 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/Kbuild        2009-12-03 20:04:56.000000000 +0100
8803 @@ -382,5 +382,8 @@ unifdef-y += xattr.h
8804  unifdef-y += xfrm.h
8805  
8806  objhdr-y += version.h
8807 +
8808 +header-y += vserver/
8809  header-y += wimax.h
8810  header-y += wimax/
8811 +
8812 diff -NurpP --minimal linux-2.6.32.24/include/linux/loop.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/loop.h
8813 --- linux-2.6.32.24/include/linux/loop.h        2009-09-10 15:26:25.000000000 +0200
8814 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/loop.h        2009-12-03 20:04:56.000000000 +0100
8815 @@ -45,6 +45,7 @@ struct loop_device {
8816         struct loop_func_table *lo_encryption;
8817         __u32           lo_init[2];
8818         uid_t           lo_key_owner;   /* Who set the key */
8819 +       xid_t           lo_xid;
8820         int             (*ioctl)(struct loop_device *, int cmd, 
8821                                  unsigned long arg); 
8822  
8823 diff -NurpP --minimal linux-2.6.32.24/include/linux/magic.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/magic.h
8824 --- linux-2.6.32.24/include/linux/magic.h       2009-12-03 20:02:55.000000000 +0100
8825 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/magic.h       2009-12-03 20:04:56.000000000 +0100
8826 @@ -3,7 +3,7 @@
8827  
8828  #define ADFS_SUPER_MAGIC       0xadf5
8829  #define AFFS_SUPER_MAGIC       0xadff
8830 -#define AFS_SUPER_MAGIC                0x5346414F
8831 +#define AFS_SUPER_MAGIC                0x5346414F
8832  #define AUTOFS_SUPER_MAGIC     0x0187
8833  #define CODA_SUPER_MAGIC       0x73757245
8834  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8835 @@ -38,6 +38,7 @@
8836  #define NFS_SUPER_MAGIC                0x6969
8837  #define OPENPROM_SUPER_MAGIC   0x9fa1
8838  #define PROC_SUPER_MAGIC       0x9fa0
8839 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8840  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8841  
8842  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8843 diff -NurpP --minimal linux-2.6.32.24/include/linux/major.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/major.h
8844 --- linux-2.6.32.24/include/linux/major.h       2009-09-10 15:26:25.000000000 +0200
8845 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/major.h       2009-12-03 20:04:56.000000000 +0100
8846 @@ -15,6 +15,7 @@
8847  #define HD_MAJOR               IDE0_MAJOR
8848  #define PTY_SLAVE_MAJOR                3
8849  #define TTY_MAJOR              4
8850 +#define VROOT_MAJOR            4
8851  #define TTYAUX_MAJOR           5
8852  #define LP_MAJOR               6
8853  #define VCS_MAJOR              7
8854 diff -NurpP --minimal linux-2.6.32.24/include/linux/memcontrol.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/memcontrol.h
8855 --- linux-2.6.32.24/include/linux/memcontrol.h  2009-12-03 20:02:55.000000000 +0100
8856 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/memcontrol.h  2010-02-05 00:15:49.000000000 +0100
8857 @@ -70,6 +70,13 @@ int task_in_mem_cgroup(struct task_struc
8858  
8859  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8860  
8861 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8862 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8863 +
8864 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8865 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8866 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8867 +
8868  static inline
8869  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8870  {
8871 diff -NurpP --minimal linux-2.6.32.24/include/linux/mm_types.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/mm_types.h
8872 --- linux-2.6.32.24/include/linux/mm_types.h    2010-10-04 08:56:16.000000000 +0200
8873 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/mm_types.h    2010-09-05 21:24:17.000000000 +0200
8874 @@ -246,6 +246,7 @@ struct mm_struct {
8875  
8876         /* Architecture-specific MM context */
8877         mm_context_t context;
8878 +       struct vx_info *mm_vx_info;
8879  
8880         /* Swap token stuff */
8881         /*
8882 diff -NurpP --minimal linux-2.6.32.24/include/linux/mount.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/mount.h
8883 --- linux-2.6.32.24/include/linux/mount.h       2009-09-10 15:26:25.000000000 +0200
8884 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/mount.h       2009-12-03 20:04:56.000000000 +0100
8885 @@ -36,6 +36,9 @@ struct mnt_namespace;
8886  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
8887  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
8888  
8889 +#define MNT_TAGID      0x10000
8890 +#define MNT_NOTAG      0x20000
8891 +
8892  struct vfsmount {
8893         struct list_head mnt_hash;
8894         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8895 @@ -70,6 +73,7 @@ struct vfsmount {
8896  #else
8897         int mnt_writers;
8898  #endif
8899 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8900  };
8901  
8902  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
8903 diff -NurpP --minimal linux-2.6.32.24/include/linux/net.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/net.h
8904 --- linux-2.6.32.24/include/linux/net.h 2009-12-03 20:02:55.000000000 +0100
8905 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/net.h 2009-12-03 20:04:56.000000000 +0100
8906 @@ -69,6 +69,7 @@ struct net;
8907  #define SOCK_NOSPACE           2
8908  #define SOCK_PASSCRED          3
8909  #define SOCK_PASSSEC           4
8910 +#define SOCK_USER_SOCKET       5
8911  
8912  #ifndef ARCH_HAS_SOCKET_TYPES
8913  /**
8914 diff -NurpP --minimal linux-2.6.32.24/include/linux/nfs_mount.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/nfs_mount.h
8915 --- linux-2.6.32.24/include/linux/nfs_mount.h   2009-03-24 14:22:43.000000000 +0100
8916 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/nfs_mount.h   2009-12-03 20:04:56.000000000 +0100
8917 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8918  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8919  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8920  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8921 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8922 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8923 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8924  
8925  /* The following are for internal use only */
8926  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8927 diff -NurpP --minimal linux-2.6.32.24/include/linux/nsproxy.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/nsproxy.h
8928 --- linux-2.6.32.24/include/linux/nsproxy.h     2009-06-11 17:13:17.000000000 +0200
8929 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/nsproxy.h     2009-12-03 20:04:56.000000000 +0100
8930 @@ -3,6 +3,7 @@
8931  
8932  #include <linux/spinlock.h>
8933  #include <linux/sched.h>
8934 +#include <linux/vserver/debug.h>
8935  
8936  struct mnt_namespace;
8937  struct uts_namespace;
8938 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8939  }
8940  
8941  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8942 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8943  void exit_task_namespaces(struct task_struct *tsk);
8944  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8945  void free_nsproxy(struct nsproxy *ns);
8946  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
8947         struct fs_struct *);
8948  
8949 -static inline void put_nsproxy(struct nsproxy *ns)
8950 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8951 +
8952 +static inline void __get_nsproxy(struct nsproxy *ns,
8953 +       const char *_file, int _line)
8954  {
8955 -       if (atomic_dec_and_test(&ns->count)) {
8956 -               free_nsproxy(ns);
8957 -       }
8958 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8959 +               ns, atomic_read(&ns->count), _file, _line);
8960 +       atomic_inc(&ns->count);
8961  }
8962  
8963 -static inline void get_nsproxy(struct nsproxy *ns)
8964 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8965 +
8966 +static inline void __put_nsproxy(struct nsproxy *ns,
8967 +       const char *_file, int _line)
8968  {
8969 -       atomic_inc(&ns->count);
8970 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8971 +               ns, atomic_read(&ns->count), _file, _line);
8972 +       if (atomic_dec_and_test(&ns->count)) {
8973 +               free_nsproxy(ns);
8974 +       }
8975  }
8976  
8977  #ifdef CONFIG_CGROUP_NS
8978 diff -NurpP --minimal linux-2.6.32.24/include/linux/pid.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/pid.h
8979 --- linux-2.6.32.24/include/linux/pid.h 2009-03-24 14:22:43.000000000 +0100
8980 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/pid.h 2009-12-03 20:04:56.000000000 +0100
8981 @@ -8,7 +8,8 @@ enum pid_type
8982         PIDTYPE_PID,
8983         PIDTYPE_PGID,
8984         PIDTYPE_SID,
8985 -       PIDTYPE_MAX
8986 +       PIDTYPE_MAX,
8987 +       PIDTYPE_REALPID
8988  };
8989  
8990  /*
8991 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
8992  }
8993  
8994  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8995 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8996  pid_t pid_vnr(struct pid *pid);
8997  
8998  #define do_each_pid_task(pid, type, task)                              \
8999 diff -NurpP --minimal linux-2.6.32.24/include/linux/proc_fs.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/proc_fs.h
9000 --- linux-2.6.32.24/include/linux/proc_fs.h     2009-12-03 20:02:56.000000000 +0100
9001 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/proc_fs.h     2009-12-03 20:04:56.000000000 +0100
9002 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9003         nlink_t nlink;
9004         uid_t uid;
9005         gid_t gid;
9006 +       int vx_flags;
9007         loff_t size;
9008         const struct inode_operations *proc_iops;
9009         /*
9010 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9011  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9012  #endif
9013  
9014 +struct vx_info;
9015 +struct nx_info;
9016 +
9017  union proc_op {
9018         int (*proc_get_link)(struct inode *, struct path *);
9019         int (*proc_read)(struct task_struct *task, char *page);
9020         int (*proc_show)(struct seq_file *m,
9021                 struct pid_namespace *ns, struct pid *pid,
9022                 struct task_struct *task);
9023 +       int (*proc_vs_read)(char *page);
9024 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9025 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9026  };
9027  
9028  struct ctl_table_header;
9029 @@ -263,6 +270,7 @@ struct ctl_table;
9030  
9031  struct proc_inode {
9032         struct pid *pid;
9033 +       int vx_flags;
9034         int fd;
9035         union proc_op op;
9036         struct proc_dir_entry *pde;
9037 diff -NurpP --minimal linux-2.6.32.24/include/linux/quotaops.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/quotaops.h
9038 --- linux-2.6.32.24/include/linux/quotaops.h    2010-10-04 08:56:16.000000000 +0200
9039 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/quotaops.h    2010-04-05 20:57:19.000000000 +0200
9040 @@ -8,6 +8,7 @@
9041  #define _LINUX_QUOTAOPS_
9042  
9043  #include <linux/fs.h>
9044 +#include <linux/vs_dlimit.h>
9045  
9046  static inline struct quota_info *sb_dqopt(struct super_block *sb)
9047  {
9048 @@ -157,10 +158,14 @@ static inline void vfs_dq_init(struct in
9049   * a transaction (deadlocks possible otherwise) */
9050  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9051  {
9052 +       if (dl_alloc_space(inode, nr))
9053 +               return 1;
9054         if (sb_any_quota_active(inode->i_sb)) {
9055                 /* Used space is updated in alloc_space() */
9056 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
9057 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) {
9058 +                       dl_free_space(inode, nr);
9059                         return 1;
9060 +               }
9061         }
9062         else
9063                 inode_add_bytes(inode, nr);
9064 @@ -177,10 +182,14 @@ static inline int vfs_dq_prealloc_space(
9065  
9066  static inline int vfs_dq_alloc_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, 0) == NO_QUOTA)
9073 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) {
9074 +                       dl_free_space(inode, nr);
9075                         return 1;
9076 +               }
9077         }
9078         else
9079                 inode_add_bytes(inode, nr);
9080 @@ -197,10 +206,14 @@ static inline int vfs_dq_alloc_space(str
9081  
9082  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9083  {
9084 +       if (dl_reserve_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->reserve_space(inode, nr, 0) == NO_QUOTA)
9089 +               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA) {
9090 +                       dl_release_space(inode, nr);
9091                         return 1;
9092 +               }
9093         }
9094         else
9095                 inode_add_rsv_space(inode, nr);
9096 @@ -209,10 +222,14 @@ static inline int vfs_dq_reserve_space(s
9097  
9098  static inline int vfs_dq_alloc_inode(struct inode *inode)
9099  {
9100 +       if (dl_alloc_inode(inode))
9101 +               return 1;
9102         if (sb_any_quota_active(inode->i_sb)) {
9103                 vfs_dq_init(inode);
9104 -               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
9105 +               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
9106 +                       dl_free_inode(inode);
9107                         return 1;
9108 +               }
9109         }
9110         return 0;
9111  }
9112 @@ -222,9 +239,13 @@ static inline int vfs_dq_alloc_inode(str
9113   */
9114  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9115  {
9116 +       if (dl_claim_space(inode, nr))
9117 +               return 1;
9118         if (sb_any_quota_active(inode->i_sb)) {
9119 -               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
9120 +               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA) {
9121 +                       dl_release_space(inode, nr);
9122                         return 1;
9123 +               }
9124         } else
9125                 inode_claim_rsv_space(inode, nr);
9126  
9127 @@ -242,6 +263,7 @@ void vfs_dq_release_reservation_space(st
9128                 inode->i_sb->dq_op->release_rsv(inode, nr);
9129         else
9130                 inode_sub_rsv_space(inode, nr);
9131 +       dl_release_space(inode, nr);
9132  }
9133  
9134  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9135 @@ -250,6 +272,7 @@ static inline void vfs_dq_free_space_nod
9136                 inode->i_sb->dq_op->free_space(inode, nr);
9137         else
9138                 inode_sub_bytes(inode, nr);
9139 +       dl_free_space(inode, nr);
9140  }
9141  
9142  static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
9143 @@ -262,6 +285,7 @@ static inline void vfs_dq_free_inode(str
9144  {
9145         if (sb_any_quota_active(inode->i_sb))
9146                 inode->i_sb->dq_op->free_inode(inode, 1);
9147 +       dl_free_inode(inode);
9148  }
9149  
9150  /* Cannot be called inside a transaction */
9151 @@ -365,6 +389,8 @@ static inline int vfs_dq_transfer(struct
9152  
9153  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9154  {
9155 +       if (dl_alloc_space(inode, nr))
9156 +               return 1;
9157         inode_add_bytes(inode, nr);
9158         return 0;
9159  }
9160 @@ -378,6 +404,8 @@ static inline int vfs_dq_prealloc_space(
9161  
9162  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9163  {
9164 +       if (dl_alloc_space(inode, nr))
9165 +               return 1;
9166         inode_add_bytes(inode, nr);
9167         return 0;
9168  }
9169 @@ -391,22 +419,28 @@ static inline int vfs_dq_alloc_space(str
9170  
9171  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9172  {
9173 +       if (dl_reserve_space(inode, nr))
9174 +               return 1;
9175         return 0;
9176  }
9177  
9178  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9179  {
9180 +       if (dl_claim_space(inode, nr))
9181 +               return 1;
9182         return vfs_dq_alloc_space(inode, nr);
9183  }
9184  
9185  static inline
9186  int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
9187  {
9188 +       dl_release_space(inode, nr);
9189         return 0;
9190  }
9191  
9192  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9193  {
9194 +       dl_free_space(inode, nr);
9195         inode_sub_bytes(inode, nr);
9196  }
9197  
9198 diff -NurpP --minimal linux-2.6.32.24/include/linux/reboot.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/reboot.h
9199 --- linux-2.6.32.24/include/linux/reboot.h      2008-12-25 00:26:37.000000000 +0100
9200 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/reboot.h      2009-12-03 22:06:59.000000000 +0100
9201 @@ -33,6 +33,7 @@
9202  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9203  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9204  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9205 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9206  
9207  
9208  #ifdef __KERNEL__
9209 diff -NurpP --minimal linux-2.6.32.24/include/linux/reiserfs_fs.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/reiserfs_fs.h
9210 --- linux-2.6.32.24/include/linux/reiserfs_fs.h 2009-09-10 15:26:26.000000000 +0200
9211 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/reiserfs_fs.h 2009-12-03 20:04:56.000000000 +0100
9212 @@ -899,6 +899,11 @@ struct stat_data_v1 {
9213  #define REISERFS_COMPR_FL     FS_COMPR_FL
9214  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9215  
9216 +/* unfortunately reiserfs sdattr is only 16 bit */
9217 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9218 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9219 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9220 +
9221  /* persistent flags that file inherits from the parent directory */
9222  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9223                                 REISERFS_SYNC_FL |      \
9224 @@ -908,6 +913,9 @@ struct stat_data_v1 {
9225                                 REISERFS_COMPR_FL |     \
9226                                 REISERFS_NOTAIL_FL )
9227  
9228 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9229 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9230 +
9231  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9232     address blocks) */
9233  struct stat_data {
9234 @@ -1989,6 +1997,7 @@ static inline void reiserfs_update_sd(st
9235  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9236  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9237  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9238 +int reiserfs_sync_flags(struct inode *inode, int, int);
9239  
9240  /* namei.c */
9241  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9242 diff -NurpP --minimal linux-2.6.32.24/include/linux/reiserfs_fs_sb.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/reiserfs_fs_sb.h
9243 --- linux-2.6.32.24/include/linux/reiserfs_fs_sb.h      2009-09-10 15:26:26.000000000 +0200
9244 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/reiserfs_fs_sb.h      2009-12-03 20:04:56.000000000 +0100
9245 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
9246         REISERFS_EXPOSE_PRIVROOT,
9247         REISERFS_BARRIER_NONE,
9248         REISERFS_BARRIER_FLUSH,
9249 +       REISERFS_TAGGED,
9250  
9251         /* Actions on error */
9252         REISERFS_ERROR_PANIC,
9253 diff -NurpP --minimal linux-2.6.32.24/include/linux/sched.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/sched.h
9254 --- linux-2.6.32.24/include/linux/sched.h       2010-10-04 08:56:16.000000000 +0200
9255 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/sched.h       2010-09-22 00:48:38.000000000 +0200
9256 @@ -389,25 +389,28 @@ extern void arch_unmap_area_topdown(stru
9257   * The mm counters are not protected by its page_table_lock,
9258   * so must be incremented atomically.
9259   */
9260 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9261 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9262 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9263 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9264 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9265 +#define __set_mm_counter(mm, member, value) \
9266 +       atomic_long_set(&(mm)->_##member, value)
9267 +#define get_mm_counter(mm, member) \
9268 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9269  
9270  #else  /* !USE_SPLIT_PTLOCKS */
9271  /*
9272   * The mm counters are protected by its page_table_lock,
9273   * so can be incremented directly.
9274   */
9275 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9276 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9277  #define get_mm_counter(mm, member) ((mm)->_##member)
9278 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9279 -#define inc_mm_counter(mm, member) (mm)->_##member++
9280 -#define dec_mm_counter(mm, member) (mm)->_##member--
9281  
9282  #endif /* !USE_SPLIT_PTLOCKS */
9283  
9284 +#define set_mm_counter(mm, member, value) \
9285 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9286 +#define add_mm_counter(mm, member, value) \
9287 +       vx_ ## member ## pages_add((mm), (value))
9288 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9289 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9290 +
9291  #define get_mm_rss(mm)                                 \
9292         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9293  #define update_hiwater_rss(mm) do {                    \
9294 @@ -1192,6 +1195,12 @@ struct sched_entity {
9295         u64                     nr_wakeups_affine_attempts;
9296         u64                     nr_wakeups_passive;
9297         u64                     nr_wakeups_idle;
9298 +#ifdef CONFIG_CFS_HARD_LIMITS
9299 +       u64                     throttle_start;
9300 +       u64                     throttle_max;
9301 +       u64                     throttle_count;
9302 +       u64                     throttle_sum;
9303 +#endif
9304  #endif
9305  
9306  #ifdef CONFIG_FAIR_GROUP_SCHED
9307 @@ -1402,6 +1411,14 @@ struct task_struct {
9308  #endif
9309         seccomp_t seccomp;
9310  
9311 +/* vserver context data */
9312 +       struct vx_info *vx_info;
9313 +       struct nx_info *nx_info;
9314 +
9315 +       xid_t xid;
9316 +       nid_t nid;
9317 +       tag_t tag;
9318 +
9319  /* Thread group tracking */
9320         u32 parent_exec_id;
9321         u32 self_exec_id;
9322 @@ -1626,6 +1643,11 @@ struct pid_namespace;
9323  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9324                         struct pid_namespace *ns);
9325  
9326 +#include <linux/vserver/base.h>
9327 +#include <linux/vserver/context.h>
9328 +#include <linux/vserver/debug.h>
9329 +#include <linux/vserver/pid.h>
9330 +
9331  static inline pid_t task_pid_nr(struct task_struct *tsk)
9332  {
9333         return tsk->pid;
9334 @@ -1639,7 +1661,8 @@ static inline pid_t task_pid_nr_ns(struc
9335  
9336  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9337  {
9338 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9339 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9340 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9341  }
9342  
9343  
9344 @@ -1652,7 +1675,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9345  
9346  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9347  {
9348 -       return pid_vnr(task_tgid(tsk));
9349 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9350  }
9351  
9352  
9353 diff -NurpP --minimal linux-2.6.32.24/include/linux/shmem_fs.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/shmem_fs.h
9354 --- linux-2.6.32.24/include/linux/shmem_fs.h    2009-12-03 20:02:56.000000000 +0100
9355 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/shmem_fs.h    2009-12-03 20:04:56.000000000 +0100
9356 @@ -8,6 +8,9 @@
9357  
9358  #define SHMEM_NR_DIRECT 16
9359  
9360 +#define TMPFS_SUPER_MAGIC      0x01021994
9361 +
9362 +
9363  struct shmem_inode_info {
9364         spinlock_t              lock;
9365         unsigned long           flags;
9366 diff -NurpP --minimal linux-2.6.32.24/include/linux/stat.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/stat.h
9367 --- linux-2.6.32.24/include/linux/stat.h        2008-12-25 00:26:37.000000000 +0100
9368 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/stat.h        2009-12-03 20:04:56.000000000 +0100
9369 @@ -66,6 +66,7 @@ struct kstat {
9370         unsigned int    nlink;
9371         uid_t           uid;
9372         gid_t           gid;
9373 +       tag_t           tag;
9374         dev_t           rdev;
9375         loff_t          size;
9376         struct timespec  atime;
9377 diff -NurpP --minimal linux-2.6.32.24/include/linux/sunrpc/auth.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/sunrpc/auth.h
9378 --- linux-2.6.32.24/include/linux/sunrpc/auth.h 2009-12-03 20:02:56.000000000 +0100
9379 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/sunrpc/auth.h 2009-12-03 20:04:56.000000000 +0100
9380 @@ -25,6 +25,7 @@
9381  struct auth_cred {
9382         uid_t   uid;
9383         gid_t   gid;
9384 +       tag_t   tag;
9385         struct group_info *group_info;
9386         unsigned char machine_cred : 1;
9387  };
9388 diff -NurpP --minimal linux-2.6.32.24/include/linux/sunrpc/clnt.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/sunrpc/clnt.h
9389 --- linux-2.6.32.24/include/linux/sunrpc/clnt.h 2009-12-03 20:02:56.000000000 +0100
9390 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/sunrpc/clnt.h 2009-12-03 20:04:56.000000000 +0100
9391 @@ -49,7 +49,8 @@ struct rpc_clnt {
9392         unsigned int            cl_softrtry : 1,/* soft timeouts */
9393                                 cl_discrtry : 1,/* disconnect before retry */
9394                                 cl_autobind : 1,/* use getport() */
9395 -                               cl_chatty   : 1;/* be verbose */
9396 +                               cl_chatty   : 1,/* be verbose */
9397 +                               cl_tag      : 1;/* context tagging */
9398  
9399         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9400         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9401 diff -NurpP --minimal linux-2.6.32.24/include/linux/syscalls.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/syscalls.h
9402 --- linux-2.6.32.24/include/linux/syscalls.h    2010-10-04 08:56:16.000000000 +0200
9403 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/syscalls.h    2010-05-21 13:20:19.000000000 +0200
9404 @@ -548,6 +548,8 @@ asmlinkage long sys_symlink(const char _
9405  asmlinkage long sys_unlink(const char __user *pathname);
9406  asmlinkage long sys_rename(const char __user *oldname,
9407                                 const char __user *newname);
9408 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9409 +                               umode_t mode);
9410  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9411  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9412  
9413 diff -NurpP --minimal linux-2.6.32.24/include/linux/sysctl.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/sysctl.h
9414 --- linux-2.6.32.24/include/linux/sysctl.h      2010-10-04 08:56:16.000000000 +0200
9415 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/sysctl.h      2010-02-12 10:59:55.000000000 +0100
9416 @@ -69,6 +69,7 @@ enum
9417         CTL_ABI=9,              /* Binary emulation */
9418         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9419         CTL_ARLAN=254,          /* arlan wireless driver */
9420 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9421         CTL_S390DBF=5677,       /* s390 debug */
9422         CTL_SUNRPC=7249,        /* sunrpc debug */
9423         CTL_PM=9899,            /* frv power management */
9424 @@ -103,6 +104,7 @@ enum
9425  
9426         KERN_PANIC=15,          /* int: panic timeout */
9427         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9428 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9429  
9430         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9431         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9432 diff -NurpP --minimal linux-2.6.32.24/include/linux/sysfs.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/sysfs.h
9433 --- linux-2.6.32.24/include/linux/sysfs.h       2008-12-25 00:26:37.000000000 +0100
9434 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/sysfs.h       2009-12-03 20:04:56.000000000 +0100
9435 @@ -17,6 +17,8 @@
9436  #include <linux/list.h>
9437  #include <asm/atomic.h>
9438  
9439 +#define SYSFS_SUPER_MAGIC      0x62656572
9440 +
9441  struct kobject;
9442  struct module;
9443  
9444 diff -NurpP --minimal linux-2.6.32.24/include/linux/time.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/time.h
9445 --- linux-2.6.32.24/include/linux/time.h        2010-10-04 08:56:16.000000000 +0200
9446 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/time.h        2010-02-12 10:59:55.000000000 +0100
9447 @@ -238,6 +238,9 @@ static __always_inline void timespec_add
9448         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9449         a->tv_nsec = ns;
9450  }
9451 +
9452 +#include <linux/vs_time.h>
9453 +
9454  #endif /* __KERNEL__ */
9455  
9456  #define NFDBITS                        __NFDBITS
9457 diff -NurpP --minimal linux-2.6.32.24/include/linux/types.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/types.h
9458 --- linux-2.6.32.24/include/linux/types.h       2009-09-10 15:26:26.000000000 +0200
9459 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/types.h       2009-12-03 20:04:56.000000000 +0100
9460 @@ -37,6 +37,9 @@ typedef __kernel_uid32_t      uid_t;
9461  typedef __kernel_gid32_t       gid_t;
9462  typedef __kernel_uid16_t        uid16_t;
9463  typedef __kernel_gid16_t        gid16_t;
9464 +typedef unsigned int           xid_t;
9465 +typedef unsigned int           nid_t;
9466 +typedef unsigned int           tag_t;
9467  
9468  typedef unsigned long          uintptr_t;
9469  
9470 diff -NurpP --minimal linux-2.6.32.24/include/linux/vroot.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vroot.h
9471 --- linux-2.6.32.24/include/linux/vroot.h       1970-01-01 01:00:00.000000000 +0100
9472 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vroot.h       2009-12-03 20:04:56.000000000 +0100
9473 @@ -0,0 +1,51 @@
9474 +
9475 +/*
9476 + * include/linux/vroot.h
9477 + *
9478 + * written by Herbert Pötzl, 9/11/2002
9479 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9480 + *
9481 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9482 + * Redistribution of this file is permitted under the
9483 + * GNU General Public License.
9484 + */
9485 +
9486 +#ifndef _LINUX_VROOT_H
9487 +#define _LINUX_VROOT_H
9488 +
9489 +
9490 +#ifdef __KERNEL__
9491 +
9492 +/* Possible states of device */
9493 +enum {
9494 +       Vr_unbound,
9495 +       Vr_bound,
9496 +};
9497 +
9498 +struct vroot_device {
9499 +       int             vr_number;
9500 +       int             vr_refcnt;
9501 +
9502 +       struct semaphore        vr_ctl_mutex;
9503 +       struct block_device    *vr_device;
9504 +       int                     vr_state;
9505 +};
9506 +
9507 +
9508 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9509 +
9510 +extern int register_vroot_grb(vroot_grb_func *);
9511 +extern int unregister_vroot_grb(vroot_grb_func *);
9512 +
9513 +#endif /* __KERNEL__ */
9514 +
9515 +#define MAX_VROOT_DEFAULT      8
9516 +
9517 +/*
9518 + * IOCTL commands --- we will commandeer 0x56 ('V')
9519 + */
9520 +
9521 +#define VROOT_SET_DEV          0x5600
9522 +#define VROOT_CLR_DEV          0x5601
9523 +
9524 +#endif /* _LINUX_VROOT_H */
9525 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_base.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_base.h
9526 --- linux-2.6.32.24/include/linux/vs_base.h     1970-01-01 01:00:00.000000000 +0100
9527 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_base.h     2009-12-03 20:04:56.000000000 +0100
9528 @@ -0,0 +1,10 @@
9529 +#ifndef _VS_BASE_H
9530 +#define _VS_BASE_H
9531 +
9532 +#include "vserver/base.h"
9533 +#include "vserver/check.h"
9534 +#include "vserver/debug.h"
9535 +
9536 +#else
9537 +#warning duplicate inclusion
9538 +#endif
9539 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_context.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_context.h
9540 --- linux-2.6.32.24/include/linux/vs_context.h  1970-01-01 01:00:00.000000000 +0100
9541 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_context.h  2009-12-03 20:04:56.000000000 +0100
9542 @@ -0,0 +1,242 @@
9543 +#ifndef _VS_CONTEXT_H
9544 +#define _VS_CONTEXT_H
9545 +
9546 +#include "vserver/base.h"
9547 +#include "vserver/check.h"
9548 +#include "vserver/context.h"
9549 +#include "vserver/history.h"
9550 +#include "vserver/debug.h"
9551 +
9552 +#include <linux/sched.h>
9553 +
9554 +
9555 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9556 +
9557 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9558 +       const char *_file, int _line, void *_here)
9559 +{
9560 +       if (!vxi)
9561 +               return NULL;
9562 +
9563 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9564 +               vxi, vxi ? vxi->vx_id : 0,
9565 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9566 +               _file, _line);
9567 +       __vxh_get_vx_info(vxi, _here);
9568 +
9569 +       atomic_inc(&vxi->vx_usecnt);
9570 +       return vxi;
9571 +}
9572 +
9573 +
9574 +extern void free_vx_info(struct vx_info *);
9575 +
9576 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9577 +
9578 +static inline void __put_vx_info(struct vx_info *vxi,
9579 +       const char *_file, int _line, void *_here)
9580 +{
9581 +       if (!vxi)
9582 +               return;
9583 +
9584 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9585 +               vxi, vxi ? vxi->vx_id : 0,
9586 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9587 +               _file, _line);
9588 +       __vxh_put_vx_info(vxi, _here);
9589 +
9590 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9591 +               free_vx_info(vxi);
9592 +}
9593 +
9594 +
9595 +#define init_vx_info(p, i) \
9596 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9597 +
9598 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9599 +       const char *_file, int _line, void *_here)
9600 +{
9601 +       if (vxi) {
9602 +               vxlprintk(VXD_CBIT(xid, 3),
9603 +                       "init_vx_info(%p[#%d.%d])",
9604 +                       vxi, vxi ? vxi->vx_id : 0,
9605 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9606 +                       _file, _line);
9607 +               __vxh_init_vx_info(vxi, vxp, _here);
9608 +
9609 +               atomic_inc(&vxi->vx_usecnt);
9610 +       }
9611 +       *vxp = vxi;
9612 +}
9613 +
9614 +
9615 +#define set_vx_info(p, i) \
9616 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9617 +
9618 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9619 +       const char *_file, int _line, void *_here)
9620 +{
9621 +       struct vx_info *vxo;
9622 +
9623 +       if (!vxi)
9624 +               return;
9625 +
9626 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9627 +               vxi, vxi ? vxi->vx_id : 0,
9628 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9629 +               _file, _line);
9630 +       __vxh_set_vx_info(vxi, vxp, _here);
9631 +
9632 +       atomic_inc(&vxi->vx_usecnt);
9633 +       vxo = xchg(vxp, vxi);
9634 +       BUG_ON(vxo);
9635 +}
9636 +
9637 +
9638 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9639 +
9640 +static inline void __clr_vx_info(struct vx_info **vxp,
9641 +       const char *_file, int _line, void *_here)
9642 +{
9643 +       struct vx_info *vxo;
9644 +
9645 +       vxo = xchg(vxp, NULL);
9646 +       if (!vxo)
9647 +               return;
9648 +
9649 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9650 +               vxo, vxo ? vxo->vx_id : 0,
9651 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9652 +               _file, _line);
9653 +       __vxh_clr_vx_info(vxo, vxp, _here);
9654 +
9655 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9656 +               free_vx_info(vxo);
9657 +}
9658 +
9659 +
9660 +#define claim_vx_info(v, p) \
9661 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9662 +
9663 +static inline void __claim_vx_info(struct vx_info *vxi,
9664 +       struct task_struct *task,
9665 +       const char *_file, int _line, void *_here)
9666 +{
9667 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9668 +               vxi, vxi ? vxi->vx_id : 0,
9669 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9670 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9671 +               task, _file, _line);
9672 +       __vxh_claim_vx_info(vxi, task, _here);
9673 +
9674 +       atomic_inc(&vxi->vx_tasks);
9675 +}
9676 +
9677 +
9678 +extern void unhash_vx_info(struct vx_info *);
9679 +
9680 +#define release_vx_info(v, p) \
9681 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9682 +
9683 +static inline void __release_vx_info(struct vx_info *vxi,
9684 +       struct task_struct *task,
9685 +       const char *_file, int _line, void *_here)
9686 +{
9687 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9688 +               vxi, vxi ? vxi->vx_id : 0,
9689 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9690 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9691 +               task, _file, _line);
9692 +       __vxh_release_vx_info(vxi, task, _here);
9693 +
9694 +       might_sleep();
9695 +
9696 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9697 +               unhash_vx_info(vxi);
9698 +}
9699 +
9700 +
9701 +#define task_get_vx_info(p) \
9702 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9703 +
9704 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9705 +       const char *_file, int _line, void *_here)
9706 +{
9707 +       struct vx_info *vxi;
9708 +
9709 +       task_lock(p);
9710 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9711 +               p, _file, _line);
9712 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9713 +       task_unlock(p);
9714 +       return vxi;
9715 +}
9716 +
9717 +
9718 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9719 +{
9720 +       if (waitqueue_active(&vxi->vx_wait))
9721 +               wake_up_interruptible(&vxi->vx_wait);
9722 +}
9723 +
9724 +
9725 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9726 +
9727 +static inline void __enter_vx_info(struct vx_info *vxi,
9728 +       struct vx_info_save *vxis, const char *_file, int _line)
9729 +{
9730 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9731 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9732 +               current->xid, current->vx_info, _file, _line);
9733 +       vxis->vxi = xchg(&current->vx_info, vxi);
9734 +       vxis->xid = current->xid;
9735 +       current->xid = vxi ? vxi->vx_id : 0;
9736 +}
9737 +
9738 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9739 +
9740 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9741 +       const char *_file, int _line)
9742 +{
9743 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9744 +               vxis, vxis->xid, vxis->vxi, current,
9745 +               current->xid, current->vx_info, _file, _line);
9746 +       (void)xchg(&current->vx_info, vxis->vxi);
9747 +       current->xid = vxis->xid;
9748 +}
9749 +
9750 +
9751 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9752 +{
9753 +       vxis->vxi = xchg(&current->vx_info, NULL);
9754 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9755 +}
9756 +
9757 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9758 +{
9759 +       (void)xchg(&current->xid, vxis->xid);
9760 +       (void)xchg(&current->vx_info, vxis->vxi);
9761 +}
9762 +
9763 +#define task_is_init(p) \
9764 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9765 +
9766 +static inline int __task_is_init(struct task_struct *p,
9767 +       const char *_file, int _line, void *_here)
9768 +{
9769 +       int is_init = is_global_init(p);
9770 +
9771 +       task_lock(p);
9772 +       if (p->vx_info)
9773 +               is_init = p->vx_info->vx_initpid == p->pid;
9774 +       task_unlock(p);
9775 +       return is_init;
9776 +}
9777 +
9778 +extern void exit_vx_info(struct task_struct *, int);
9779 +extern void exit_vx_info_early(struct task_struct *, int);
9780 +
9781 +
9782 +#else
9783 +#warning duplicate inclusion
9784 +#endif
9785 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_cowbl.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_cowbl.h
9786 --- linux-2.6.32.24/include/linux/vs_cowbl.h    1970-01-01 01:00:00.000000000 +0100
9787 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_cowbl.h    2009-12-03 20:04:56.000000000 +0100
9788 @@ -0,0 +1,47 @@
9789 +#ifndef _VS_COWBL_H
9790 +#define _VS_COWBL_H
9791 +
9792 +#include <linux/fs.h>
9793 +#include <linux/dcache.h>
9794 +#include <linux/namei.h>
9795 +
9796 +extern struct dentry *cow_break_link(const char *pathname);
9797 +
9798 +static inline int cow_check_and_break(struct path *path)
9799 +{
9800 +       struct inode *inode = path->dentry->d_inode;
9801 +       int error = 0;
9802 +
9803 +       /* do we need this check? */
9804 +       if (IS_RDONLY(inode))
9805 +               return -EROFS;
9806 +
9807 +       if (IS_COW(inode)) {
9808 +               if (IS_COW_LINK(inode)) {
9809 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9810 +                       char *pp, *buf;
9811 +
9812 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9813 +                       if (!buf) {
9814 +                               return -ENOMEM;
9815 +                       }
9816 +                       pp = d_path(path, buf, PATH_MAX);
9817 +                       new_dentry = cow_break_link(pp);
9818 +                       kfree(buf);
9819 +                       if (!IS_ERR(new_dentry)) {
9820 +                               path->dentry = new_dentry;
9821 +                               dput(old_dentry);
9822 +                       } else
9823 +                               error = PTR_ERR(new_dentry);
9824 +               } else {
9825 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9826 +                       inode->i_ctime = CURRENT_TIME;
9827 +                       mark_inode_dirty(inode);
9828 +               }
9829 +       }
9830 +       return error;
9831 +}
9832 +
9833 +#else
9834 +#warning duplicate inclusion
9835 +#endif
9836 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_cvirt.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_cvirt.h
9837 --- linux-2.6.32.24/include/linux/vs_cvirt.h    1970-01-01 01:00:00.000000000 +0100
9838 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_cvirt.h    2009-12-03 20:04:56.000000000 +0100
9839 @@ -0,0 +1,50 @@
9840 +#ifndef _VS_CVIRT_H
9841 +#define _VS_CVIRT_H
9842 +
9843 +#include "vserver/cvirt.h"
9844 +#include "vserver/context.h"
9845 +#include "vserver/base.h"
9846 +#include "vserver/check.h"
9847 +#include "vserver/debug.h"
9848 +
9849 +
9850 +static inline void vx_activate_task(struct task_struct *p)
9851 +{
9852 +       struct vx_info *vxi;
9853 +
9854 +       if ((vxi = p->vx_info)) {
9855 +               vx_update_load(vxi);
9856 +               atomic_inc(&vxi->cvirt.nr_running);
9857 +       }
9858 +}
9859 +
9860 +static inline void vx_deactivate_task(struct task_struct *p)
9861 +{
9862 +       struct vx_info *vxi;
9863 +
9864 +       if ((vxi = p->vx_info)) {
9865 +               vx_update_load(vxi);
9866 +               atomic_dec(&vxi->cvirt.nr_running);
9867 +       }
9868 +}
9869 +
9870 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9871 +{
9872 +       struct vx_info *vxi;
9873 +
9874 +       if ((vxi = p->vx_info))
9875 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9876 +}
9877 +
9878 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9879 +{
9880 +       struct vx_info *vxi;
9881 +
9882 +       if ((vxi = p->vx_info))
9883 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9884 +}
9885 +
9886 +
9887 +#else
9888 +#warning duplicate inclusion
9889 +#endif
9890 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_device.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_device.h
9891 --- linux-2.6.32.24/include/linux/vs_device.h   1970-01-01 01:00:00.000000000 +0100
9892 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_device.h   2009-12-03 20:04:56.000000000 +0100
9893 @@ -0,0 +1,45 @@
9894 +#ifndef _VS_DEVICE_H
9895 +#define _VS_DEVICE_H
9896 +
9897 +#include "vserver/base.h"
9898 +#include "vserver/device.h"
9899 +#include "vserver/debug.h"
9900 +
9901 +
9902 +#ifdef CONFIG_VSERVER_DEVICE
9903 +
9904 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9905 +
9906 +#define vs_device_perm(v, d, m, p) \
9907 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9908 +
9909 +#else
9910 +
9911 +static inline
9912 +int vs_map_device(struct vx_info *vxi,
9913 +       dev_t device, dev_t *target, umode_t mode)
9914 +{
9915 +       if (target)
9916 +               *target = device;
9917 +       return ~0;
9918 +}
9919 +
9920 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9921 +
9922 +#endif
9923 +
9924 +
9925 +#define vs_map_chrdev(d, t, p) \
9926 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9927 +#define vs_map_blkdev(d, t, p) \
9928 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9929 +
9930 +#define vs_chrdev_perm(d, p) \
9931 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9932 +#define vs_blkdev_perm(d, p) \
9933 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9934 +
9935 +
9936 +#else
9937 +#warning duplicate inclusion
9938 +#endif
9939 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_dlimit.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_dlimit.h
9940 --- linux-2.6.32.24/include/linux/vs_dlimit.h   1970-01-01 01:00:00.000000000 +0100
9941 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_dlimit.h   2010-03-21 06:19:38.000000000 +0100
9942 @@ -0,0 +1,215 @@
9943 +#ifndef _VS_DLIMIT_H
9944 +#define _VS_DLIMIT_H
9945 +
9946 +#include <linux/fs.h>
9947 +
9948 +#include "vserver/dlimit.h"
9949 +#include "vserver/base.h"
9950 +#include "vserver/debug.h"
9951 +
9952 +
9953 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9954 +
9955 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9956 +       const char *_file, int _line)
9957 +{
9958 +       if (!dli)
9959 +               return NULL;
9960 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9961 +               dli, dli ? dli->dl_tag : 0,
9962 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9963 +               _file, _line);
9964 +       atomic_inc(&dli->dl_usecnt);
9965 +       return dli;
9966 +}
9967 +
9968 +
9969 +#define free_dl_info(i) \
9970 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9971 +
9972 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9973 +
9974 +static inline void __put_dl_info(struct dl_info *dli,
9975 +       const char *_file, int _line)
9976 +{
9977 +       if (!dli)
9978 +               return;
9979 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9980 +               dli, dli ? dli->dl_tag : 0,
9981 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9982 +               _file, _line);
9983 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9984 +               free_dl_info(dli);
9985 +}
9986 +
9987 +
9988 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9989 +
9990 +static inline int __dl_alloc_space(struct super_block *sb,
9991 +       tag_t tag, dlsize_t nr, const char *file, int line)
9992 +{
9993 +       struct dl_info *dli = NULL;
9994 +       int ret = 0;
9995 +
9996 +       if (nr == 0)
9997 +               goto out;
9998 +       dli = locate_dl_info(sb, tag);
9999 +       if (!dli)
10000 +               goto out;
10001 +
10002 +       spin_lock(&dli->dl_lock);
10003 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10004 +       if (!ret)
10005 +               dli->dl_space_used += nr;
10006 +       spin_unlock(&dli->dl_lock);
10007 +       put_dl_info(dli);
10008 +out:
10009 +       vxlprintk(VXD_CBIT(dlim, 1),
10010 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10011 +               sb, tag, __dlimit_char(dli), (long long)nr,
10012 +               ret, file, line);
10013 +       return ret;
10014 +}
10015 +
10016 +static inline void __dl_free_space(struct super_block *sb,
10017 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10018 +{
10019 +       struct dl_info *dli = NULL;
10020 +
10021 +       if (nr == 0)
10022 +               goto out;
10023 +       dli = locate_dl_info(sb, tag);
10024 +       if (!dli)
10025 +               goto out;
10026 +
10027 +       spin_lock(&dli->dl_lock);
10028 +       if (dli->dl_space_used > nr)
10029 +               dli->dl_space_used -= nr;
10030 +       else
10031 +               dli->dl_space_used = 0;
10032 +       spin_unlock(&dli->dl_lock);
10033 +       put_dl_info(dli);
10034 +out:
10035 +       vxlprintk(VXD_CBIT(dlim, 1),
10036 +               "FREE  (%p,#%d)%c %lld bytes",
10037 +               sb, tag, __dlimit_char(dli), (long long)nr,
10038 +               _file, _line);
10039 +}
10040 +
10041 +static inline int __dl_alloc_inode(struct super_block *sb,
10042 +       tag_t tag, const char *_file, int _line)
10043 +{
10044 +       struct dl_info *dli;
10045 +       int ret = 0;
10046 +
10047 +       dli = locate_dl_info(sb, tag);
10048 +       if (!dli)
10049 +               goto out;
10050 +
10051 +       spin_lock(&dli->dl_lock);
10052 +       dli->dl_inodes_used++;
10053 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
10054 +       spin_unlock(&dli->dl_lock);
10055 +       put_dl_info(dli);
10056 +out:
10057 +       vxlprintk(VXD_CBIT(dlim, 0),
10058 +               "ALLOC (%p,#%d)%c inode (%d)",
10059 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10060 +       return ret;
10061 +}
10062 +
10063 +static inline void __dl_free_inode(struct super_block *sb,
10064 +       tag_t tag, const char *_file, int _line)
10065 +{
10066 +       struct dl_info *dli;
10067 +
10068 +       dli = locate_dl_info(sb, tag);
10069 +       if (!dli)
10070 +               goto out;
10071 +
10072 +       spin_lock(&dli->dl_lock);
10073 +       if (dli->dl_inodes_used > 1)
10074 +               dli->dl_inodes_used--;
10075 +       else
10076 +               dli->dl_inodes_used = 0;
10077 +       spin_unlock(&dli->dl_lock);
10078 +       put_dl_info(dli);
10079 +out:
10080 +       vxlprintk(VXD_CBIT(dlim, 0),
10081 +               "FREE  (%p,#%d)%c inode",
10082 +               sb, tag, __dlimit_char(dli), _file, _line);
10083 +}
10084 +
10085 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10086 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10087 +       const char *_file, int _line)
10088 +{
10089 +       struct dl_info *dli;
10090 +       uint64_t broot, bfree;
10091 +
10092 +       dli = locate_dl_info(sb, tag);
10093 +       if (!dli)
10094 +               return;
10095 +
10096 +       spin_lock(&dli->dl_lock);
10097 +       broot = (dli->dl_space_total -
10098 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10099 +               >> sb->s_blocksize_bits;
10100 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10101 +                       >> sb->s_blocksize_bits;
10102 +       spin_unlock(&dli->dl_lock);
10103 +
10104 +       vxlprintk(VXD_CBIT(dlim, 2),
10105 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10106 +               (long long)bfree, (long long)broot,
10107 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10108 +               _file, _line);
10109 +       if (free_blocks) {
10110 +               if (*free_blocks > bfree)
10111 +                       *free_blocks = bfree;
10112 +       }
10113 +       if (root_blocks) {
10114 +               if (*root_blocks > broot)
10115 +                       *root_blocks = broot;
10116 +       }
10117 +       put_dl_info(dli);
10118 +}
10119 +
10120 +#define dl_prealloc_space(in, bytes) \
10121 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10122 +               __FILE__, __LINE__ )
10123 +
10124 +#define dl_alloc_space(in, bytes) \
10125 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10126 +               __FILE__, __LINE__ )
10127 +
10128 +#define dl_reserve_space(in, bytes) \
10129 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10130 +               __FILE__, __LINE__ )
10131 +
10132 +#define dl_claim_space(in, bytes) (0)
10133 +
10134 +#define dl_release_space(in, bytes) \
10135 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10136 +               __FILE__, __LINE__ )
10137 +
10138 +#define dl_free_space(in, bytes) \
10139 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10140 +               __FILE__, __LINE__ )
10141 +
10142 +
10143 +
10144 +#define dl_alloc_inode(in) \
10145 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10146 +
10147 +#define dl_free_inode(in) \
10148 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10149 +
10150 +
10151 +#define dl_adjust_block(sb, tag, fb, rb) \
10152 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10153 +
10154 +
10155 +#else
10156 +#warning duplicate inclusion
10157 +#endif
10158 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/base.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/base.h
10159 --- linux-2.6.32.24/include/linux/vserver/base.h        1970-01-01 01:00:00.000000000 +0100
10160 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/base.h        2009-12-03 20:04:56.000000000 +0100
10161 @@ -0,0 +1,170 @@
10162 +#ifndef _VX_BASE_H
10163 +#define _VX_BASE_H
10164 +
10165 +
10166 +/* context state changes */
10167 +
10168 +enum {
10169 +       VSC_STARTUP = 1,
10170 +       VSC_SHUTDOWN,
10171 +
10172 +       VSC_NETUP,
10173 +       VSC_NETDOWN,
10174 +};
10175 +
10176 +
10177 +
10178 +#define vx_task_xid(t) ((t)->xid)
10179 +
10180 +#define vx_current_xid() vx_task_xid(current)
10181 +
10182 +#define current_vx_info() (current->vx_info)
10183 +
10184 +
10185 +#define nx_task_nid(t) ((t)->nid)
10186 +
10187 +#define nx_current_nid() nx_task_nid(current)
10188 +
10189 +#define current_nx_info() (current->nx_info)
10190 +
10191 +
10192 +/* generic flag merging */
10193 +
10194 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10195 +
10196 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10197 +
10198 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10199 +
10200 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10201 +
10202 +
10203 +/* context flags */
10204 +
10205 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10206 +
10207 +#define vx_current_flags()     __vx_flags(current_vx_info())
10208 +
10209 +#define vx_info_flags(v, m, f) \
10210 +       vs_check_flags(__vx_flags(v), m, f)
10211 +
10212 +#define task_vx_flags(t, m, f) \
10213 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10214 +
10215 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10216 +
10217 +
10218 +/* context caps */
10219 +
10220 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10221 +
10222 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10223 +
10224 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10225 +
10226 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10227 +
10228 +
10229 +
10230 +/* network flags */
10231 +
10232 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10233 +
10234 +#define nx_current_flags()     __nx_flags(current_nx_info())
10235 +
10236 +#define nx_info_flags(n, m, f) \
10237 +       vs_check_flags(__nx_flags(n), m, f)
10238 +
10239 +#define task_nx_flags(t, m, f) \
10240 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10241 +
10242 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10243 +
10244 +
10245 +/* network caps */
10246 +
10247 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10248 +
10249 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10250 +
10251 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10252 +
10253 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10254 +
10255 +
10256 +/* context mask capabilities */
10257 +
10258 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10259 +
10260 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10261 +
10262 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10263 +
10264 +
10265 +/* context bcap mask */
10266 +
10267 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10268 +
10269 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10270 +
10271 +
10272 +/* mask given bcaps */
10273 +
10274 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10275 +
10276 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10277 +
10278 +
10279 +/* masked cap_bset */
10280 +
10281 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10282 +
10283 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10284 +
10285 +#if 0
10286 +#define vx_info_mbcap(v, b) \
10287 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10288 +       vx_info_bcaps(v, b) : (b))
10289 +
10290 +#define task_vx_mbcap(t, b) \
10291 +       vx_info_mbcap((t)->vx_info, (t)->b)
10292 +
10293 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10294 +#endif
10295 +
10296 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10297 +
10298 +#define vx_capable(b, c) (capable(b) || \
10299 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10300 +
10301 +#define nx_capable(b, c) (capable(b) || \
10302 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10303 +
10304 +#define vx_task_initpid(t, n) \
10305 +       ((t)->vx_info && \
10306 +       ((t)->vx_info->vx_initpid == (n)))
10307 +
10308 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10309 +
10310 +
10311 +/* context unshare mask */
10312 +
10313 +#define __vx_umask(v)          ((v)->vx_umask)
10314 +
10315 +#define vx_current_umask()     __vx_umask(current_vx_info())
10316 +
10317 +#define vx_can_unshare(b, f) (capable(b) || \
10318 +       (cap_raised(current_cap(), b) && \
10319 +       !((f) & ~vx_current_umask())))
10320 +
10321 +
10322 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10323 +
10324 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10325 +
10326 +
10327 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10328 +
10329 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10330 +
10331 +#endif
10332 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/cacct_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cacct_cmd.h
10333 --- linux-2.6.32.24/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00.000000000 +0100
10334 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cacct_cmd.h   2009-12-03 20:04:56.000000000 +0100
10335 @@ -0,0 +1,23 @@
10336 +#ifndef _VX_CACCT_CMD_H
10337 +#define _VX_CACCT_CMD_H
10338 +
10339 +
10340 +/* virtual host info name commands */
10341 +
10342 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10343 +
10344 +struct vcmd_sock_stat_v0 {
10345 +       uint32_t field;
10346 +       uint32_t count[3];
10347 +       uint64_t total[3];
10348 +};
10349 +
10350 +
10351 +#ifdef __KERNEL__
10352 +
10353 +#include <linux/compiler.h>
10354 +
10355 +extern int vc_sock_stat(struct vx_info *, void __user *);
10356 +
10357 +#endif /* __KERNEL__ */
10358 +#endif /* _VX_CACCT_CMD_H */
10359 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/cacct_def.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cacct_def.h
10360 --- linux-2.6.32.24/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00.000000000 +0100
10361 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cacct_def.h   2009-12-03 20:04:56.000000000 +0100
10362 @@ -0,0 +1,43 @@
10363 +#ifndef _VX_CACCT_DEF_H
10364 +#define _VX_CACCT_DEF_H
10365 +
10366 +#include <asm/atomic.h>
10367 +#include <linux/vserver/cacct.h>
10368 +
10369 +
10370 +struct _vx_sock_acc {
10371 +       atomic_long_t count;
10372 +       atomic_long_t total;
10373 +};
10374 +
10375 +/* context sub struct */
10376 +
10377 +struct _vx_cacct {
10378 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10379 +       atomic_t slab[8];
10380 +       atomic_t page[6][8];
10381 +};
10382 +
10383 +#ifdef CONFIG_VSERVER_DEBUG
10384 +
10385 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10386 +{
10387 +       int i, j;
10388 +
10389 +       printk("\t_vx_cacct:");
10390 +       for (i = 0; i < 6; i++) {
10391 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10392 +
10393 +               printk("\t [%d] =", i);
10394 +               for (j = 0; j < 3; j++) {
10395 +                       printk(" [%d] = %8lu, %8lu", j,
10396 +                               atomic_long_read(&ptr[j].count),
10397 +                               atomic_long_read(&ptr[j].total));
10398 +               }
10399 +               printk("\n");
10400 +       }
10401 +}
10402 +
10403 +#endif
10404 +
10405 +#endif /* _VX_CACCT_DEF_H */
10406 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/cacct.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cacct.h
10407 --- linux-2.6.32.24/include/linux/vserver/cacct.h       1970-01-01 01:00:00.000000000 +0100
10408 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cacct.h       2009-12-03 20:04:56.000000000 +0100
10409 @@ -0,0 +1,15 @@
10410 +#ifndef _VX_CACCT_H
10411 +#define _VX_CACCT_H
10412 +
10413 +
10414 +enum sock_acc_field {
10415 +       VXA_SOCK_UNSPEC = 0,
10416 +       VXA_SOCK_UNIX,
10417 +       VXA_SOCK_INET,
10418 +       VXA_SOCK_INET6,
10419 +       VXA_SOCK_PACKET,
10420 +       VXA_SOCK_OTHER,
10421 +       VXA_SOCK_SIZE   /* array size */
10422 +};
10423 +
10424 +#endif /* _VX_CACCT_H */
10425 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/cacct_int.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cacct_int.h
10426 --- linux-2.6.32.24/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00.000000000 +0100
10427 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cacct_int.h   2009-12-03 20:04:56.000000000 +0100
10428 @@ -0,0 +1,21 @@
10429 +#ifndef _VX_CACCT_INT_H
10430 +#define _VX_CACCT_INT_H
10431 +
10432 +
10433 +#ifdef __KERNEL__
10434 +
10435 +static inline
10436 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10437 +{
10438 +       return atomic_long_read(&cacct->sock[type][pos].count);
10439 +}
10440 +
10441 +
10442 +static inline
10443 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10444 +{
10445 +       return atomic_long_read(&cacct->sock[type][pos].total);
10446 +}
10447 +
10448 +#endif /* __KERNEL__ */
10449 +#endif /* _VX_CACCT_INT_H */
10450 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/check.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/check.h
10451 --- linux-2.6.32.24/include/linux/vserver/check.h       1970-01-01 01:00:00.000000000 +0100
10452 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/check.h       2009-12-03 20:04:56.000000000 +0100
10453 @@ -0,0 +1,89 @@
10454 +#ifndef _VS_CHECK_H
10455 +#define _VS_CHECK_H
10456 +
10457 +
10458 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10459 +
10460 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10461 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10462 +#else
10463 +#define MIN_D_CONTEXT  65536
10464 +#endif
10465 +
10466 +/* check conditions */
10467 +
10468 +#define VS_ADMIN       0x0001
10469 +#define VS_WATCH       0x0002
10470 +#define VS_HIDE                0x0004
10471 +#define VS_HOSTID      0x0008
10472 +
10473 +#define VS_IDENT       0x0010
10474 +#define VS_EQUIV       0x0020
10475 +#define VS_PARENT      0x0040
10476 +#define VS_CHILD       0x0080
10477 +
10478 +#define VS_ARG_MASK    0x00F0
10479 +
10480 +#define VS_DYNAMIC     0x0100
10481 +#define VS_STATIC      0x0200
10482 +
10483 +#define VS_ATR_MASK    0x0F00
10484 +
10485 +#ifdef CONFIG_VSERVER_PRIVACY
10486 +#define VS_ADMIN_P     (0)
10487 +#define VS_WATCH_P     (0)
10488 +#else
10489 +#define VS_ADMIN_P     VS_ADMIN
10490 +#define VS_WATCH_P     VS_WATCH
10491 +#endif
10492 +
10493 +#define VS_HARDIRQ     0x1000
10494 +#define VS_SOFTIRQ     0x2000
10495 +#define VS_IRQ         0x4000
10496 +
10497 +#define VS_IRQ_MASK    0xF000
10498 +
10499 +#include <linux/hardirq.h>
10500 +
10501 +/*
10502 + * check current context for ADMIN/WATCH and
10503 + * optionally against supplied argument
10504 + */
10505 +static inline int __vs_check(int cid, int id, unsigned int mode)
10506 +{
10507 +       if (mode & VS_ARG_MASK) {
10508 +               if ((mode & VS_IDENT) && (id == cid))
10509 +                       return 1;
10510 +       }
10511 +       if (mode & VS_ATR_MASK) {
10512 +               if ((mode & VS_DYNAMIC) &&
10513 +                       (id >= MIN_D_CONTEXT) &&
10514 +                       (id <= MAX_S_CONTEXT))
10515 +                       return 1;
10516 +               if ((mode & VS_STATIC) &&
10517 +                       (id > 1) && (id < MIN_D_CONTEXT))
10518 +                       return 1;
10519 +       }
10520 +       if (mode & VS_IRQ_MASK) {
10521 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10522 +                       return 1;
10523 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10524 +                       return 1;
10525 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10526 +                       return 1;
10527 +       }
10528 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10529 +               ((mode & VS_WATCH) && (cid == 1)) ||
10530 +               ((mode & VS_HOSTID) && (id == 0)));
10531 +}
10532 +
10533 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10534 +
10535 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10536 +
10537 +
10538 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10539 +
10540 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10541 +
10542 +#endif
10543 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/context_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/context_cmd.h
10544 --- linux-2.6.32.24/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00.000000000 +0100
10545 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/context_cmd.h 2009-12-03 20:04:56.000000000 +0100
10546 @@ -0,0 +1,145 @@
10547 +#ifndef _VX_CONTEXT_CMD_H
10548 +#define _VX_CONTEXT_CMD_H
10549 +
10550 +
10551 +/* vinfo commands */
10552 +
10553 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10554 +
10555 +#ifdef __KERNEL__
10556 +extern int vc_task_xid(uint32_t);
10557 +
10558 +#endif /* __KERNEL__ */
10559 +
10560 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10561 +
10562 +struct vcmd_vx_info_v0 {
10563 +       uint32_t xid;
10564 +       uint32_t initpid;
10565 +       /* more to come */
10566 +};
10567 +
10568 +#ifdef __KERNEL__
10569 +extern int vc_vx_info(struct vx_info *, void __user *);
10570 +
10571 +#endif /* __KERNEL__ */
10572 +
10573 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10574 +
10575 +struct vcmd_ctx_stat_v0 {
10576 +       uint32_t usecnt;
10577 +       uint32_t tasks;
10578 +       /* more to come */
10579 +};
10580 +
10581 +#ifdef __KERNEL__
10582 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10583 +
10584 +#endif /* __KERNEL__ */
10585 +
10586 +/* context commands */
10587 +
10588 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10589 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10590 +
10591 +struct vcmd_ctx_create {
10592 +       uint64_t flagword;
10593 +};
10594 +
10595 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10596 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10597 +
10598 +struct vcmd_ctx_migrate {
10599 +       uint64_t flagword;
10600 +};
10601 +
10602 +#ifdef __KERNEL__
10603 +extern int vc_ctx_create(uint32_t, void __user *);
10604 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10605 +
10606 +#endif /* __KERNEL__ */
10607 +
10608 +
10609 +/* flag commands */
10610 +
10611 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10612 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10613 +
10614 +struct vcmd_ctx_flags_v0 {
10615 +       uint64_t flagword;
10616 +       uint64_t mask;
10617 +};
10618 +
10619 +#ifdef __KERNEL__
10620 +extern int vc_get_cflags(struct vx_info *, void __user *);
10621 +extern int vc_set_cflags(struct vx_info *, void __user *);
10622 +
10623 +#endif /* __KERNEL__ */
10624 +
10625 +
10626 +/* context caps commands */
10627 +
10628 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10629 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10630 +
10631 +struct vcmd_ctx_caps_v1 {
10632 +       uint64_t ccaps;
10633 +       uint64_t cmask;
10634 +};
10635 +
10636 +#ifdef __KERNEL__
10637 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10638 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10639 +
10640 +#endif /* __KERNEL__ */
10641 +
10642 +
10643 +/* bcaps commands */
10644 +
10645 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10646 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10647 +
10648 +struct vcmd_bcaps {
10649 +       uint64_t bcaps;
10650 +       uint64_t bmask;
10651 +};
10652 +
10653 +#ifdef __KERNEL__
10654 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10655 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10656 +
10657 +#endif /* __KERNEL__ */
10658 +
10659 +
10660 +/* umask commands */
10661 +
10662 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10663 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10664 +
10665 +struct vcmd_umask {
10666 +       uint64_t umask;
10667 +       uint64_t mask;
10668 +};
10669 +
10670 +#ifdef __KERNEL__
10671 +extern int vc_get_umask(struct vx_info *, void __user *);
10672 +extern int vc_set_umask(struct vx_info *, void __user *);
10673 +
10674 +#endif /* __KERNEL__ */
10675 +
10676 +
10677 +/* OOM badness */
10678 +
10679 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10680 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10681 +
10682 +struct vcmd_badness_v0 {
10683 +       int64_t bias;
10684 +};
10685 +
10686 +#ifdef __KERNEL__
10687 +extern int vc_get_badness(struct vx_info *, void __user *);
10688 +extern int vc_set_badness(struct vx_info *, void __user *);
10689 +
10690 +#endif /* __KERNEL__ */
10691 +#endif /* _VX_CONTEXT_CMD_H */
10692 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/context.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/context.h
10693 --- linux-2.6.32.24/include/linux/vserver/context.h     1970-01-01 01:00:00.000000000 +0100
10694 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/context.h     2010-03-13 21:50:00.000000000 +0100
10695 @@ -0,0 +1,184 @@
10696 +#ifndef _VX_CONTEXT_H
10697 +#define _VX_CONTEXT_H
10698 +
10699 +#include <linux/types.h>
10700 +#include <linux/capability.h>
10701 +
10702 +
10703 +/* context flags */
10704 +
10705 +#define VXF_INFO_SCHED         0x00000002
10706 +#define VXF_INFO_NPROC         0x00000004
10707 +#define VXF_INFO_PRIVATE       0x00000008
10708 +
10709 +#define VXF_INFO_INIT          0x00000010
10710 +#define VXF_INFO_HIDE          0x00000020
10711 +#define VXF_INFO_ULIMIT                0x00000040
10712 +#define VXF_INFO_NSPACE                0x00000080
10713 +
10714 +#define VXF_SCHED_HARD         0x00000100
10715 +#define VXF_SCHED_PRIO         0x00000200
10716 +#define VXF_SCHED_PAUSE                0x00000400
10717 +
10718 +#define VXF_VIRT_MEM           0x00010000
10719 +#define VXF_VIRT_UPTIME                0x00020000
10720 +#define VXF_VIRT_CPU           0x00040000
10721 +#define VXF_VIRT_LOAD          0x00080000
10722 +#define VXF_VIRT_TIME          0x00100000
10723 +
10724 +#define VXF_HIDE_MOUNT         0x01000000
10725 +/* was VXF_HIDE_NETIF          0x02000000 */
10726 +#define VXF_HIDE_VINFO         0x04000000
10727 +
10728 +#define VXF_STATE_SETUP                (1ULL << 32)
10729 +#define VXF_STATE_INIT         (1ULL << 33)
10730 +#define VXF_STATE_ADMIN                (1ULL << 34)
10731 +
10732 +#define VXF_SC_HELPER          (1ULL << 36)
10733 +#define VXF_REBOOT_KILL                (1ULL << 37)
10734 +#define VXF_PERSISTENT         (1ULL << 38)
10735 +
10736 +#define VXF_FORK_RSS           (1ULL << 48)
10737 +#define VXF_PROLIFIC           (1ULL << 49)
10738 +
10739 +#define VXF_IGNEG_NICE         (1ULL << 52)
10740 +
10741 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10742 +
10743 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10744 +
10745 +
10746 +/* context migration */
10747 +
10748 +#define VXM_SET_INIT           0x00000001
10749 +#define VXM_SET_REAPER         0x00000002
10750 +
10751 +/* context caps */
10752 +
10753 +#define VXC_CAP_MASK           0x00000000
10754 +
10755 +#define VXC_SET_UTSNAME                0x00000001
10756 +#define VXC_SET_RLIMIT         0x00000002
10757 +#define VXC_FS_SECURITY                0x00000004
10758 +#define VXC_FS_TRUSTED         0x00000008
10759 +#define VXC_TIOCSTI            0x00000010
10760 +
10761 +/* was VXC_RAW_ICMP            0x00000100 */
10762 +#define VXC_SYSLOG             0x00001000
10763 +#define VXC_OOM_ADJUST         0x00002000
10764 +#define VXC_AUDIT_CONTROL      0x00004000
10765 +
10766 +#define VXC_SECURE_MOUNT       0x00010000
10767 +#define VXC_SECURE_REMOUNT     0x00020000
10768 +#define VXC_BINARY_MOUNT       0x00040000
10769 +
10770 +#define VXC_QUOTA_CTL          0x00100000
10771 +#define VXC_ADMIN_MAPPER       0x00200000
10772 +#define VXC_ADMIN_CLOOP                0x00400000
10773 +
10774 +#define VXC_KTHREAD            0x01000000
10775 +#define VXC_NAMESPACE          0x02000000
10776 +
10777 +
10778 +#ifdef __KERNEL__
10779 +
10780 +#include <linux/list.h>
10781 +#include <linux/spinlock.h>
10782 +#include <linux/rcupdate.h>
10783 +
10784 +#include "limit_def.h"
10785 +#include "sched_def.h"
10786 +#include "cvirt_def.h"
10787 +#include "cacct_def.h"
10788 +#include "device_def.h"
10789 +
10790 +#define VX_SPACES      2
10791 +
10792 +struct _vx_info_pc {
10793 +       struct _vx_sched_pc sched_pc;
10794 +       struct _vx_cvirt_pc cvirt_pc;
10795 +};
10796 +
10797 +struct vx_info {
10798 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10799 +       xid_t vx_id;                            /* context id */
10800 +       atomic_t vx_usecnt;                     /* usage count */
10801 +       atomic_t vx_tasks;                      /* tasks count */
10802 +       struct vx_info *vx_parent;              /* parent context */
10803 +       int vx_state;                           /* context state */
10804 +
10805 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10806 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10807 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10808 +
10809 +       uint64_t vx_flags;                      /* context flags */
10810 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10811 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10812 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10813 +
10814 +       struct task_struct *vx_reaper;          /* guest reaper process */
10815 +       pid_t vx_initpid;                       /* PID of guest init */
10816 +       int64_t vx_badness_bias;                /* OOM points bias */
10817 +
10818 +       struct _vx_limit limit;                 /* vserver limits */
10819 +       struct _vx_sched sched;                 /* vserver scheduler */
10820 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10821 +       struct _vx_cacct cacct;                 /* context accounting */
10822 +
10823 +       struct _vx_device dmap;                 /* default device map targets */
10824 +
10825 +#ifndef CONFIG_SMP
10826 +       struct _vx_info_pc info_pc;             /* per cpu data */
10827 +#else
10828 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10829 +#endif
10830 +
10831 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10832 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10833 +       int exit_code;                          /* last process exit code */
10834 +
10835 +       char vx_name[65];                       /* vserver name */
10836 +};
10837 +
10838 +#ifndef CONFIG_SMP
10839 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10840 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10841 +#else
10842 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10843 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10844 +#endif
10845 +
10846 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10847 +
10848 +
10849 +struct vx_info_save {
10850 +       struct vx_info *vxi;
10851 +       xid_t xid;
10852 +};
10853 +
10854 +
10855 +/* status flags */
10856 +
10857 +#define VXS_HASHED     0x0001
10858 +#define VXS_PAUSED     0x0010
10859 +#define VXS_SHUTDOWN   0x0100
10860 +#define VXS_HELPER     0x1000
10861 +#define VXS_RELEASED   0x8000
10862 +
10863 +
10864 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10865 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10866 +
10867 +extern struct vx_info *lookup_vx_info(int);
10868 +extern struct vx_info *lookup_or_create_vx_info(int);
10869 +
10870 +extern int get_xid_list(int, unsigned int *, int);
10871 +extern int xid_is_hashed(xid_t);
10872 +
10873 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10874 +
10875 +extern long vs_state_change(struct vx_info *, unsigned int);
10876 +
10877 +
10878 +#endif /* __KERNEL__ */
10879 +#endif /* _VX_CONTEXT_H */
10880 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/cvirt_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cvirt_cmd.h
10881 --- linux-2.6.32.24/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00.000000000 +0100
10882 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cvirt_cmd.h   2009-12-03 20:04:56.000000000 +0100
10883 @@ -0,0 +1,53 @@
10884 +#ifndef _VX_CVIRT_CMD_H
10885 +#define _VX_CVIRT_CMD_H
10886 +
10887 +
10888 +/* virtual host info name commands */
10889 +
10890 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10891 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10892 +
10893 +struct vcmd_vhi_name_v0 {
10894 +       uint32_t field;
10895 +       char name[65];
10896 +};
10897 +
10898 +
10899 +enum vhi_name_field {
10900 +       VHIN_CONTEXT = 0,
10901 +       VHIN_SYSNAME,
10902 +       VHIN_NODENAME,
10903 +       VHIN_RELEASE,
10904 +       VHIN_VERSION,
10905 +       VHIN_MACHINE,
10906 +       VHIN_DOMAINNAME,
10907 +};
10908 +
10909 +
10910 +#ifdef __KERNEL__
10911 +
10912 +#include <linux/compiler.h>
10913 +
10914 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10915 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10916 +
10917 +#endif /* __KERNEL__ */
10918 +
10919 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10920 +
10921 +struct vcmd_virt_stat_v0 {
10922 +       uint64_t offset;
10923 +       uint64_t uptime;
10924 +       uint32_t nr_threads;
10925 +       uint32_t nr_running;
10926 +       uint32_t nr_uninterruptible;
10927 +       uint32_t nr_onhold;
10928 +       uint32_t nr_forks;
10929 +       uint32_t load[3];
10930 +};
10931 +
10932 +#ifdef __KERNEL__
10933 +extern int vc_virt_stat(struct vx_info *, void __user *);
10934 +
10935 +#endif /* __KERNEL__ */
10936 +#endif /* _VX_CVIRT_CMD_H */
10937 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/cvirt_def.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cvirt_def.h
10938 --- linux-2.6.32.24/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00.000000000 +0100
10939 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cvirt_def.h   2009-12-03 20:04:56.000000000 +0100
10940 @@ -0,0 +1,80 @@
10941 +#ifndef _VX_CVIRT_DEF_H
10942 +#define _VX_CVIRT_DEF_H
10943 +
10944 +#include <linux/jiffies.h>
10945 +#include <linux/spinlock.h>
10946 +#include <linux/wait.h>
10947 +#include <linux/time.h>
10948 +#include <asm/atomic.h>
10949 +
10950 +
10951 +struct _vx_usage_stat {
10952 +       uint64_t user;
10953 +       uint64_t nice;
10954 +       uint64_t system;
10955 +       uint64_t softirq;
10956 +       uint64_t irq;
10957 +       uint64_t idle;
10958 +       uint64_t iowait;
10959 +};
10960 +
10961 +struct _vx_syslog {
10962 +       wait_queue_head_t log_wait;
10963 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10964 +
10965 +       unsigned long log_start;        /* next char to be read by syslog() */
10966 +       unsigned long con_start;        /* next char to be sent to consoles */
10967 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10968 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10969 +
10970 +       char log_buf[1024];
10971 +};
10972 +
10973 +
10974 +/* context sub struct */
10975 +
10976 +struct _vx_cvirt {
10977 +       atomic_t nr_threads;            /* number of current threads */
10978 +       atomic_t nr_running;            /* number of running threads */
10979 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10980 +
10981 +       atomic_t nr_onhold;             /* processes on hold */
10982 +       uint32_t onhold_last;           /* jiffies when put on hold */
10983 +
10984 +       struct timeval bias_tv;         /* time offset to the host */
10985 +       struct timespec bias_idle;
10986 +       struct timespec bias_uptime;    /* context creation point */
10987 +       uint64_t bias_clock;            /* offset in clock_t */
10988 +
10989 +       spinlock_t load_lock;           /* lock for the load averages */
10990 +       atomic_t load_updates;          /* nr of load updates done so far */
10991 +       uint32_t load_last;             /* last time load was calculated */
10992 +       uint32_t load[3];               /* load averages 1,5,15 */
10993 +
10994 +       atomic_t total_forks;           /* number of forks so far */
10995 +
10996 +       struct _vx_syslog syslog;
10997 +};
10998 +
10999 +struct _vx_cvirt_pc {
11000 +       struct _vx_usage_stat cpustat;
11001 +};
11002 +
11003 +
11004 +#ifdef CONFIG_VSERVER_DEBUG
11005 +
11006 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11007 +{
11008 +       printk("\t_vx_cvirt:\n");
11009 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11010 +               atomic_read(&cvirt->nr_threads),
11011 +               atomic_read(&cvirt->nr_running),
11012 +               atomic_read(&cvirt->nr_uninterruptible),
11013 +               atomic_read(&cvirt->nr_onhold));
11014 +       /* add rest here */
11015 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11016 +}
11017 +
11018 +#endif
11019 +
11020 +#endif /* _VX_CVIRT_DEF_H */
11021 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/cvirt.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cvirt.h
11022 --- linux-2.6.32.24/include/linux/vserver/cvirt.h       1970-01-01 01:00:00.000000000 +0100
11023 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/cvirt.h       2009-12-03 20:04:56.000000000 +0100
11024 @@ -0,0 +1,20 @@
11025 +#ifndef _VX_CVIRT_H
11026 +#define _VX_CVIRT_H
11027 +
11028 +
11029 +#ifdef __KERNEL__
11030 +
11031 +struct timespec;
11032 +
11033 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11034 +
11035 +
11036 +struct vx_info;
11037 +
11038 +void vx_update_load(struct vx_info *);
11039 +
11040 +
11041 +int vx_do_syslog(int, char __user *, int);
11042 +
11043 +#endif /* __KERNEL__ */
11044 +#endif /* _VX_CVIRT_H */
11045 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/debug_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/debug_cmd.h
11046 --- linux-2.6.32.24/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00.000000000 +0100
11047 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/debug_cmd.h   2009-12-03 20:04:56.000000000 +0100
11048 @@ -0,0 +1,58 @@
11049 +#ifndef _VX_DEBUG_CMD_H
11050 +#define _VX_DEBUG_CMD_H
11051 +
11052 +
11053 +/* debug commands */
11054 +
11055 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11056 +
11057 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11058 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11059 +
11060 +struct  vcmd_read_history_v0 {
11061 +       uint32_t index;
11062 +       uint32_t count;
11063 +       char __user *data;
11064 +};
11065 +
11066 +struct  vcmd_read_monitor_v0 {
11067 +       uint32_t index;
11068 +       uint32_t count;
11069 +       char __user *data;
11070 +};
11071 +
11072 +
11073 +#ifdef __KERNEL__
11074 +
11075 +#ifdef CONFIG_COMPAT
11076 +
11077 +#include <asm/compat.h>
11078 +
11079 +struct vcmd_read_history_v0_x32 {
11080 +       uint32_t index;
11081 +       uint32_t count;
11082 +       compat_uptr_t data_ptr;
11083 +};
11084 +
11085 +struct vcmd_read_monitor_v0_x32 {
11086 +       uint32_t index;
11087 +       uint32_t count;
11088 +       compat_uptr_t data_ptr;
11089 +};
11090 +
11091 +#endif  /* CONFIG_COMPAT */
11092 +
11093 +extern int vc_dump_history(uint32_t);
11094 +
11095 +extern int vc_read_history(uint32_t, void __user *);
11096 +extern int vc_read_monitor(uint32_t, void __user *);
11097 +
11098 +#ifdef CONFIG_COMPAT
11099 +
11100 +extern int vc_read_history_x32(uint32_t, void __user *);
11101 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11102 +
11103 +#endif  /* CONFIG_COMPAT */
11104 +
11105 +#endif /* __KERNEL__ */
11106 +#endif /* _VX_DEBUG_CMD_H */
11107 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/debug.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/debug.h
11108 --- linux-2.6.32.24/include/linux/vserver/debug.h       1970-01-01 01:00:00.000000000 +0100
11109 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/debug.h       2009-12-03 20:04:56.000000000 +0100
11110 @@ -0,0 +1,127 @@
11111 +#ifndef _VX_DEBUG_H
11112 +#define _VX_DEBUG_H
11113 +
11114 +
11115 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11116 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11117 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11118 +
11119 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11120 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11121 +#define VXF_DEV                "%p[%lu,%d:%d]"
11122 +
11123 +
11124 +#define vxd_path(p)                                            \
11125 +       ({ static char _buffer[PATH_MAX];                       \
11126 +          d_path(p, _buffer, sizeof(_buffer)); })
11127 +
11128 +#define vxd_cond_path(n)                                       \
11129 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11130 +
11131 +
11132 +#ifdef CONFIG_VSERVER_DEBUG
11133 +
11134 +extern unsigned int vx_debug_switch;
11135 +extern unsigned int vx_debug_xid;
11136 +extern unsigned int vx_debug_nid;
11137 +extern unsigned int vx_debug_tag;
11138 +extern unsigned int vx_debug_net;
11139 +extern unsigned int vx_debug_limit;
11140 +extern unsigned int vx_debug_cres;
11141 +extern unsigned int vx_debug_dlim;
11142 +extern unsigned int vx_debug_quota;
11143 +extern unsigned int vx_debug_cvirt;
11144 +extern unsigned int vx_debug_space;
11145 +extern unsigned int vx_debug_misc;
11146 +
11147 +
11148 +#define VX_LOGLEVEL    "vxD: "
11149 +#define VX_PROC_FMT    "%p: "
11150 +#define VX_PROCESS     current
11151 +
11152 +#define vxdprintk(c, f, x...)                                  \
11153 +       do {                                                    \
11154 +               if (c)                                          \
11155 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11156 +                               VX_PROCESS , ##x);              \
11157 +       } while (0)
11158 +
11159 +#define vxlprintk(c, f, x...)                                  \
11160 +       do {                                                    \
11161 +               if (c)                                          \
11162 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11163 +       } while (0)
11164 +
11165 +#define vxfprintk(c, f, x...)                                  \
11166 +       do {                                                    \
11167 +               if (c)                                          \
11168 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11169 +       } while (0)
11170 +
11171 +
11172 +struct vx_info;
11173 +
11174 +void dump_vx_info(struct vx_info *, int);
11175 +void dump_vx_info_inactive(int);
11176 +
11177 +#else  /* CONFIG_VSERVER_DEBUG */
11178 +
11179 +#define vx_debug_switch 0
11180 +#define vx_debug_xid   0
11181 +#define vx_debug_nid   0
11182 +#define vx_debug_tag   0
11183 +#define vx_debug_net   0
11184 +#define vx_debug_limit 0
11185 +#define vx_debug_cres  0
11186 +#define vx_debug_dlim  0
11187 +#define vx_debug_cvirt 0
11188 +
11189 +#define vxdprintk(x...) do { } while (0)
11190 +#define vxlprintk(x...) do { } while (0)
11191 +#define vxfprintk(x...) do { } while (0)
11192 +
11193 +#endif /* CONFIG_VSERVER_DEBUG */
11194 +
11195 +
11196 +#ifdef CONFIG_VSERVER_WARN
11197 +
11198 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11199 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11200 +#define VX_WARN_XID    "[xid #%u] "
11201 +#define VX_WARN_NID    "[nid #%u] "
11202 +#define VX_WARN_TAG    "[tag #%u] "
11203 +
11204 +#define vxwprintk(c, f, x...)                                  \
11205 +       do {                                                    \
11206 +               if (c)                                          \
11207 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11208 +       } while (0)
11209 +
11210 +#else  /* CONFIG_VSERVER_WARN */
11211 +
11212 +#define vxwprintk(x...) do { } while (0)
11213 +
11214 +#endif /* CONFIG_VSERVER_WARN */
11215 +
11216 +#define vxwprintk_task(c, f, x...)                             \
11217 +       vxwprintk(c, VX_WARN_TASK f,                            \
11218 +               current->comm, current->pid,                    \
11219 +               current->xid, current->nid, current->tag, ##x)
11220 +#define vxwprintk_xid(c, f, x...)                              \
11221 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11222 +#define vxwprintk_nid(c, f, x...)                              \
11223 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11224 +#define vxwprintk_tag(c, f, x...)                              \
11225 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11226 +
11227 +#ifdef CONFIG_VSERVER_DEBUG
11228 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11229 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11230 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11231 +#else
11232 +#define vxd_assert_lock(l)     do { } while (0)
11233 +#define vxd_assert(c, f, x...) do { } while (0)
11234 +#endif
11235 +
11236 +
11237 +#endif /* _VX_DEBUG_H */
11238 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/device_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/device_cmd.h
11239 --- linux-2.6.32.24/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00.000000000 +0100
11240 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/device_cmd.h  2009-12-03 20:04:56.000000000 +0100
11241 @@ -0,0 +1,44 @@
11242 +#ifndef _VX_DEVICE_CMD_H
11243 +#define _VX_DEVICE_CMD_H
11244 +
11245 +
11246 +/*  device vserver commands */
11247 +
11248 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11249 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11250 +
11251 +struct vcmd_set_mapping_v0 {
11252 +       const char __user *device;
11253 +       const char __user *target;
11254 +       uint32_t flags;
11255 +};
11256 +
11257 +
11258 +#ifdef __KERNEL__
11259 +
11260 +#ifdef CONFIG_COMPAT
11261 +
11262 +#include <asm/compat.h>
11263 +
11264 +struct vcmd_set_mapping_v0_x32 {
11265 +       compat_uptr_t device_ptr;
11266 +       compat_uptr_t target_ptr;
11267 +       uint32_t flags;
11268 +};
11269 +
11270 +#endif /* CONFIG_COMPAT */
11271 +
11272 +#include <linux/compiler.h>
11273 +
11274 +extern int vc_set_mapping(struct vx_info *, void __user *);
11275 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11276 +
11277 +#ifdef CONFIG_COMPAT
11278 +
11279 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11280 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11281 +
11282 +#endif /* CONFIG_COMPAT */
11283 +
11284 +#endif /* __KERNEL__ */
11285 +#endif /* _VX_DEVICE_CMD_H */
11286 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/device_def.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/device_def.h
11287 --- linux-2.6.32.24/include/linux/vserver/device_def.h  1970-01-01 01:00:00.000000000 +0100
11288 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/device_def.h  2009-12-03 20:04:56.000000000 +0100
11289 @@ -0,0 +1,17 @@
11290 +#ifndef _VX_DEVICE_DEF_H
11291 +#define _VX_DEVICE_DEF_H
11292 +
11293 +#include <linux/types.h>
11294 +
11295 +struct vx_dmap_target {
11296 +       dev_t target;
11297 +       uint32_t flags;
11298 +};
11299 +
11300 +struct _vx_device {
11301 +#ifdef CONFIG_VSERVER_DEVICE
11302 +       struct vx_dmap_target targets[2];
11303 +#endif
11304 +};
11305 +
11306 +#endif /* _VX_DEVICE_DEF_H */
11307 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/device.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/device.h
11308 --- linux-2.6.32.24/include/linux/vserver/device.h      1970-01-01 01:00:00.000000000 +0100
11309 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/device.h      2009-12-03 20:04:56.000000000 +0100
11310 @@ -0,0 +1,15 @@
11311 +#ifndef _VX_DEVICE_H
11312 +#define _VX_DEVICE_H
11313 +
11314 +
11315 +#define DATTR_CREATE   0x00000001
11316 +#define DATTR_OPEN     0x00000002
11317 +
11318 +#define DATTR_REMAP    0x00000010
11319 +
11320 +#define DATTR_MASK     0x00000013
11321 +
11322 +
11323 +#else  /* _VX_DEVICE_H */
11324 +#warning duplicate inclusion
11325 +#endif /* _VX_DEVICE_H */
11326 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/dlimit_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/dlimit_cmd.h
11327 --- linux-2.6.32.24/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00.000000000 +0100
11328 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/dlimit_cmd.h  2009-12-10 16:43:43.000000000 +0100
11329 @@ -0,0 +1,109 @@
11330 +#ifndef _VX_DLIMIT_CMD_H
11331 +#define _VX_DLIMIT_CMD_H
11332 +
11333 +
11334 +/*  dlimit vserver commands */
11335 +
11336 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11337 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11338 +
11339 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11340 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11341 +
11342 +struct vcmd_ctx_dlimit_base_v0 {
11343 +       const char __user *name;
11344 +       uint32_t flags;
11345 +};
11346 +
11347 +struct vcmd_ctx_dlimit_v0 {
11348 +       const char __user *name;
11349 +       uint32_t space_used;                    /* used space in kbytes */
11350 +       uint32_t space_total;                   /* maximum space in kbytes */
11351 +       uint32_t inodes_used;                   /* used inodes */
11352 +       uint32_t inodes_total;                  /* maximum inodes */
11353 +       uint32_t reserved;                      /* reserved for root in % */
11354 +       uint32_t flags;
11355 +};
11356 +
11357 +#define CDLIM_UNSET            ((uint32_t)0UL)
11358 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11359 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11360 +
11361 +#define DLIME_UNIT     0
11362 +#define DLIME_KILO     1
11363 +#define DLIME_MEGA     2
11364 +#define DLIME_GIGA     3
11365 +
11366 +#define DLIMF_SHIFT    0x10
11367 +
11368 +#define DLIMS_USED     0
11369 +#define DLIMS_TOTAL    2
11370 +
11371 +static inline
11372 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11373 +{
11374 +       int exp = (flags & DLIMF_SHIFT) ?
11375 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11376 +       return ((uint64_t)val) << (10 * exp);
11377 +}
11378 +
11379 +static inline
11380 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11381 +{
11382 +       int exp = 0;
11383 +
11384 +       if (*flags & DLIMF_SHIFT) {
11385 +               while (val > (1LL << 32) && (exp < 3)) {
11386 +                       val >>= 10;
11387 +                       exp++;
11388 +               }
11389 +               *flags &= ~(DLIME_GIGA << shift);
11390 +               *flags |= exp << shift;
11391 +       } else
11392 +               val >>= 10;
11393 +       return val;
11394 +}
11395 +
11396 +#ifdef __KERNEL__
11397 +
11398 +#ifdef CONFIG_COMPAT
11399 +
11400 +#include <asm/compat.h>
11401 +
11402 +struct vcmd_ctx_dlimit_base_v0_x32 {
11403 +       compat_uptr_t name_ptr;
11404 +       uint32_t flags;
11405 +};
11406 +
11407 +struct vcmd_ctx_dlimit_v0_x32 {
11408 +       compat_uptr_t name_ptr;
11409 +       uint32_t space_used;                    /* used space in kbytes */
11410 +       uint32_t space_total;                   /* maximum space in kbytes */
11411 +       uint32_t inodes_used;                   /* used inodes */
11412 +       uint32_t inodes_total;                  /* maximum inodes */
11413 +       uint32_t reserved;                      /* reserved for root in % */
11414 +       uint32_t flags;
11415 +};
11416 +
11417 +#endif /* CONFIG_COMPAT */
11418 +
11419 +#include <linux/compiler.h>
11420 +
11421 +extern int vc_add_dlimit(uint32_t, void __user *);
11422 +extern int vc_rem_dlimit(uint32_t, void __user *);
11423 +
11424 +extern int vc_set_dlimit(uint32_t, void __user *);
11425 +extern int vc_get_dlimit(uint32_t, void __user *);
11426 +
11427 +#ifdef CONFIG_COMPAT
11428 +
11429 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11430 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11431 +
11432 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11433 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11434 +
11435 +#endif /* CONFIG_COMPAT */
11436 +
11437 +#endif /* __KERNEL__ */
11438 +#endif /* _VX_DLIMIT_CMD_H */
11439 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/dlimit.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/dlimit.h
11440 --- linux-2.6.32.24/include/linux/vserver/dlimit.h      1970-01-01 01:00:00.000000000 +0100
11441 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/dlimit.h      2009-12-03 20:04:56.000000000 +0100
11442 @@ -0,0 +1,54 @@
11443 +#ifndef _VX_DLIMIT_H
11444 +#define _VX_DLIMIT_H
11445 +
11446 +#include "switch.h"
11447 +
11448 +
11449 +#ifdef __KERNEL__
11450 +
11451 +/*      keep in sync with CDLIM_INFINITY       */
11452 +
11453 +#define DLIM_INFINITY          (~0ULL)
11454 +
11455 +#include <linux/spinlock.h>
11456 +#include <linux/rcupdate.h>
11457 +
11458 +struct super_block;
11459 +
11460 +struct dl_info {
11461 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11462 +       struct rcu_head dl_rcu;                 /* the rcu head */
11463 +       tag_t dl_tag;                           /* context tag */
11464 +       atomic_t dl_usecnt;                     /* usage count */
11465 +       atomic_t dl_refcnt;                     /* reference count */
11466 +
11467 +       struct super_block *dl_sb;              /* associated superblock */
11468 +
11469 +       spinlock_t dl_lock;                     /* protect the values */
11470 +
11471 +       unsigned long long dl_space_used;       /* used space in bytes */
11472 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11473 +       unsigned long dl_inodes_used;           /* used inodes */
11474 +       unsigned long dl_inodes_total;          /* maximum inodes */
11475 +
11476 +       unsigned int dl_nrlmult;                /* non root limit mult */
11477 +};
11478 +
11479 +struct rcu_head;
11480 +
11481 +extern void rcu_free_dl_info(struct rcu_head *);
11482 +extern void unhash_dl_info(struct dl_info *);
11483 +
11484 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11485 +
11486 +
11487 +struct kstatfs;
11488 +
11489 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11490 +
11491 +typedef uint64_t dlsize_t;
11492 +
11493 +#endif /* __KERNEL__ */
11494 +#else  /* _VX_DLIMIT_H */
11495 +#warning duplicate inclusion
11496 +#endif /* _VX_DLIMIT_H */
11497 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/global.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/global.h
11498 --- linux-2.6.32.24/include/linux/vserver/global.h      1970-01-01 01:00:00.000000000 +0100
11499 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/global.h      2009-12-03 20:04:56.000000000 +0100
11500 @@ -0,0 +1,19 @@
11501 +#ifndef _VX_GLOBAL_H
11502 +#define _VX_GLOBAL_H
11503 +
11504 +
11505 +extern atomic_t vx_global_ctotal;
11506 +extern atomic_t vx_global_cactive;
11507 +
11508 +extern atomic_t nx_global_ctotal;
11509 +extern atomic_t nx_global_cactive;
11510 +
11511 +extern atomic_t vs_global_nsproxy;
11512 +extern atomic_t vs_global_fs;
11513 +extern atomic_t vs_global_mnt_ns;
11514 +extern atomic_t vs_global_uts_ns;
11515 +extern atomic_t vs_global_user_ns;
11516 +extern atomic_t vs_global_pid_ns;
11517 +
11518 +
11519 +#endif /* _VX_GLOBAL_H */
11520 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/history.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/history.h
11521 --- linux-2.6.32.24/include/linux/vserver/history.h     1970-01-01 01:00:00.000000000 +0100
11522 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/history.h     2009-12-03 20:04:56.000000000 +0100
11523 @@ -0,0 +1,197 @@
11524 +#ifndef _VX_HISTORY_H
11525 +#define _VX_HISTORY_H
11526 +
11527 +
11528 +enum {
11529 +       VXH_UNUSED = 0,
11530 +       VXH_THROW_OOPS = 1,
11531 +
11532 +       VXH_GET_VX_INFO,
11533 +       VXH_PUT_VX_INFO,
11534 +       VXH_INIT_VX_INFO,
11535 +       VXH_SET_VX_INFO,
11536 +       VXH_CLR_VX_INFO,
11537 +       VXH_CLAIM_VX_INFO,
11538 +       VXH_RELEASE_VX_INFO,
11539 +       VXH_ALLOC_VX_INFO,
11540 +       VXH_DEALLOC_VX_INFO,
11541 +       VXH_HASH_VX_INFO,
11542 +       VXH_UNHASH_VX_INFO,
11543 +       VXH_LOC_VX_INFO,
11544 +       VXH_LOOKUP_VX_INFO,
11545 +       VXH_CREATE_VX_INFO,
11546 +};
11547 +
11548 +struct _vxhe_vxi {
11549 +       struct vx_info *ptr;
11550 +       unsigned xid;
11551 +       unsigned usecnt;
11552 +       unsigned tasks;
11553 +};
11554 +
11555 +struct _vxhe_set_clr {
11556 +       void *data;
11557 +};
11558 +
11559 +struct _vxhe_loc_lookup {
11560 +       unsigned arg;
11561 +};
11562 +
11563 +struct _vx_hist_entry {
11564 +       void *loc;
11565 +       unsigned short seq;
11566 +       unsigned short type;
11567 +       struct _vxhe_vxi vxi;
11568 +       union {
11569 +               struct _vxhe_set_clr sc;
11570 +               struct _vxhe_loc_lookup ll;
11571 +       };
11572 +};
11573 +
11574 +#ifdef CONFIG_VSERVER_HISTORY
11575 +
11576 +extern unsigned volatile int vxh_active;
11577 +
11578 +struct _vx_hist_entry *vxh_advance(void *loc);
11579 +
11580 +
11581 +static inline
11582 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11583 +{
11584 +       entry->vxi.ptr = vxi;
11585 +       if (vxi) {
11586 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11587 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11588 +               entry->vxi.xid = vxi->vx_id;
11589 +       }
11590 +}
11591 +
11592 +
11593 +#define        __HERE__ current_text_addr()
11594 +
11595 +#define __VXH_BODY(__type, __data, __here)     \
11596 +       struct _vx_hist_entry *entry;           \
11597 +                                               \
11598 +       preempt_disable();                      \
11599 +       entry = vxh_advance(__here);            \
11600 +       __data;                                 \
11601 +       entry->type = __type;                   \
11602 +       preempt_enable();
11603 +
11604 +
11605 +       /* pass vxi only */
11606 +
11607 +#define __VXH_SMPL                             \
11608 +       __vxh_copy_vxi(entry, vxi)
11609 +
11610 +static inline
11611 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11612 +{
11613 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11614 +}
11615 +
11616 +       /* pass vxi and data (void *) */
11617 +
11618 +#define __VXH_DATA                             \
11619 +       __vxh_copy_vxi(entry, vxi);             \
11620 +       entry->sc.data = data
11621 +
11622 +static inline
11623 +void   __vxh_data(struct vx_info *vxi, void *data,
11624 +                       int __type, void *__here)
11625 +{
11626 +       __VXH_BODY(__type, __VXH_DATA, __here)
11627 +}
11628 +
11629 +       /* pass vxi and arg (long) */
11630 +
11631 +#define __VXH_LONG                             \
11632 +       __vxh_copy_vxi(entry, vxi);             \
11633 +       entry->ll.arg = arg
11634 +
11635 +static inline
11636 +void   __vxh_long(struct vx_info *vxi, long arg,
11637 +                       int __type, void *__here)
11638 +{
11639 +       __VXH_BODY(__type, __VXH_LONG, __here)
11640 +}
11641 +
11642 +
11643 +static inline
11644 +void   __vxh_throw_oops(void *__here)
11645 +{
11646 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11647 +       /* prevent further acquisition */
11648 +       vxh_active = 0;
11649 +}
11650 +
11651 +
11652 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11653 +
11654 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11655 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11656 +
11657 +#define __vxh_init_vx_info(v, d, h) \
11658 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11659 +#define __vxh_set_vx_info(v, d, h) \
11660 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11661 +#define __vxh_clr_vx_info(v, d, h) \
11662 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11663 +
11664 +#define __vxh_claim_vx_info(v, d, h) \
11665 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11666 +#define __vxh_release_vx_info(v, d, h) \
11667 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11668 +
11669 +#define vxh_alloc_vx_info(v) \
11670 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11671 +#define vxh_dealloc_vx_info(v) \
11672 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11673 +
11674 +#define vxh_hash_vx_info(v) \
11675 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11676 +#define vxh_unhash_vx_info(v) \
11677 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11678 +
11679 +#define vxh_loc_vx_info(v, l) \
11680 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11681 +#define vxh_lookup_vx_info(v, l) \
11682 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11683 +#define vxh_create_vx_info(v, l) \
11684 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11685 +
11686 +extern void vxh_dump_history(void);
11687 +
11688 +
11689 +#else  /* CONFIG_VSERVER_HISTORY */
11690 +
11691 +#define        __HERE__        0
11692 +
11693 +#define vxh_throw_oops()               do { } while (0)
11694 +
11695 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11696 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11697 +
11698 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11699 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11700 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11701 +
11702 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11703 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11704 +
11705 +#define vxh_alloc_vx_info(v)           do { } while (0)
11706 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11707 +
11708 +#define vxh_hash_vx_info(v)            do { } while (0)
11709 +#define vxh_unhash_vx_info(v)          do { } while (0)
11710 +
11711 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11712 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11713 +#define vxh_create_vx_info(v, l)       do { } while (0)
11714 +
11715 +#define vxh_dump_history()             do { } while (0)
11716 +
11717 +
11718 +#endif /* CONFIG_VSERVER_HISTORY */
11719 +
11720 +#endif /* _VX_HISTORY_H */
11721 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/inode_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/inode_cmd.h
11722 --- linux-2.6.32.24/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00.000000000 +0100
11723 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/inode_cmd.h   2009-12-03 20:04:56.000000000 +0100
11724 @@ -0,0 +1,59 @@
11725 +#ifndef _VX_INODE_CMD_H
11726 +#define _VX_INODE_CMD_H
11727 +
11728 +
11729 +/*  inode vserver commands */
11730 +
11731 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11732 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11733 +
11734 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11735 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11736 +
11737 +struct vcmd_ctx_iattr_v1 {
11738 +       const char __user *name;
11739 +       uint32_t tag;
11740 +       uint32_t flags;
11741 +       uint32_t mask;
11742 +};
11743 +
11744 +struct vcmd_ctx_fiattr_v0 {
11745 +       uint32_t tag;
11746 +       uint32_t flags;
11747 +       uint32_t mask;
11748 +};
11749 +
11750 +
11751 +#ifdef __KERNEL__
11752 +
11753 +
11754 +#ifdef CONFIG_COMPAT
11755 +
11756 +#include <asm/compat.h>
11757 +
11758 +struct vcmd_ctx_iattr_v1_x32 {
11759 +       compat_uptr_t name_ptr;
11760 +       uint32_t tag;
11761 +       uint32_t flags;
11762 +       uint32_t mask;
11763 +};
11764 +
11765 +#endif /* CONFIG_COMPAT */
11766 +
11767 +#include <linux/compiler.h>
11768 +
11769 +extern int vc_get_iattr(void __user *);
11770 +extern int vc_set_iattr(void __user *);
11771 +
11772 +extern int vc_fget_iattr(uint32_t, void __user *);
11773 +extern int vc_fset_iattr(uint32_t, void __user *);
11774 +
11775 +#ifdef CONFIG_COMPAT
11776 +
11777 +extern int vc_get_iattr_x32(void __user *);
11778 +extern int vc_set_iattr_x32(void __user *);
11779 +
11780 +#endif /* CONFIG_COMPAT */
11781 +
11782 +#endif /* __KERNEL__ */
11783 +#endif /* _VX_INODE_CMD_H */
11784 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/inode.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/inode.h
11785 --- linux-2.6.32.24/include/linux/vserver/inode.h       1970-01-01 01:00:00.000000000 +0100
11786 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/inode.h       2009-12-03 20:04:56.000000000 +0100
11787 @@ -0,0 +1,39 @@
11788 +#ifndef _VX_INODE_H
11789 +#define _VX_INODE_H
11790 +
11791 +
11792 +#define IATTR_TAG      0x01000000
11793 +
11794 +#define IATTR_ADMIN    0x00000001
11795 +#define IATTR_WATCH    0x00000002
11796 +#define IATTR_HIDE     0x00000004
11797 +#define IATTR_FLAGS    0x00000007
11798 +
11799 +#define IATTR_BARRIER  0x00010000
11800 +#define IATTR_IXUNLINK 0x00020000
11801 +#define IATTR_IMMUTABLE 0x00040000
11802 +#define IATTR_COW      0x00080000
11803 +
11804 +#ifdef __KERNEL__
11805 +
11806 +
11807 +#ifdef CONFIG_VSERVER_PROC_SECURE
11808 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11809 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11810 +#else
11811 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11812 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11813 +#endif
11814 +
11815 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11816 +
11817 +#endif /* __KERNEL__ */
11818 +
11819 +/* inode ioctls */
11820 +
11821 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11822 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11823 +
11824 +#else  /* _VX_INODE_H */
11825 +#warning duplicate inclusion
11826 +#endif /* _VX_INODE_H */
11827 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/Kbuild linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/Kbuild
11828 --- linux-2.6.32.24/include/linux/vserver/Kbuild        1970-01-01 01:00:00.000000000 +0100
11829 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/Kbuild        2009-12-03 20:04:56.000000000 +0100
11830 @@ -0,0 +1,8 @@
11831 +
11832 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11833 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11834 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11835 +       debug_cmd.h device_cmd.h
11836 +
11837 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11838 +
11839 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/limit_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/limit_cmd.h
11840 --- linux-2.6.32.24/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00.000000000 +0100
11841 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/limit_cmd.h   2009-12-03 20:04:56.000000000 +0100
11842 @@ -0,0 +1,71 @@
11843 +#ifndef _VX_LIMIT_CMD_H
11844 +#define _VX_LIMIT_CMD_H
11845 +
11846 +
11847 +/*  rlimit vserver commands */
11848 +
11849 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11850 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11851 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11852 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11853 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11854 +
11855 +struct vcmd_ctx_rlimit_v0 {
11856 +       uint32_t id;
11857 +       uint64_t minimum;
11858 +       uint64_t softlimit;
11859 +       uint64_t maximum;
11860 +};
11861 +
11862 +struct vcmd_ctx_rlimit_mask_v0 {
11863 +       uint32_t minimum;
11864 +       uint32_t softlimit;
11865 +       uint32_t maximum;
11866 +};
11867 +
11868 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11869 +
11870 +struct vcmd_rlimit_stat_v0 {
11871 +       uint32_t id;
11872 +       uint32_t hits;
11873 +       uint64_t value;
11874 +       uint64_t minimum;
11875 +       uint64_t maximum;
11876 +};
11877 +
11878 +#define CRLIM_UNSET            (0ULL)
11879 +#define CRLIM_INFINITY         (~0ULL)
11880 +#define CRLIM_KEEP             (~1ULL)
11881 +
11882 +#ifdef __KERNEL__
11883 +
11884 +#ifdef CONFIG_IA32_EMULATION
11885 +
11886 +struct vcmd_ctx_rlimit_v0_x32 {
11887 +       uint32_t id;
11888 +       uint64_t minimum;
11889 +       uint64_t softlimit;
11890 +       uint64_t maximum;
11891 +} __attribute__ ((packed));
11892 +
11893 +#endif /* CONFIG_IA32_EMULATION */
11894 +
11895 +#include <linux/compiler.h>
11896 +
11897 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11898 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11899 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11900 +extern int vc_reset_hits(struct vx_info *, void __user *);
11901 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11902 +
11903 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11904 +
11905 +#ifdef CONFIG_IA32_EMULATION
11906 +
11907 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11908 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11909 +
11910 +#endif /* CONFIG_IA32_EMULATION */
11911 +
11912 +#endif /* __KERNEL__ */
11913 +#endif /* _VX_LIMIT_CMD_H */
11914 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/limit_def.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/limit_def.h
11915 --- linux-2.6.32.24/include/linux/vserver/limit_def.h   1970-01-01 01:00:00.000000000 +0100
11916 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/limit_def.h   2009-12-03 20:04:56.000000000 +0100
11917 @@ -0,0 +1,47 @@
11918 +#ifndef _VX_LIMIT_DEF_H
11919 +#define _VX_LIMIT_DEF_H
11920 +
11921 +#include <asm/atomic.h>
11922 +#include <asm/resource.h>
11923 +
11924 +#include "limit.h"
11925 +
11926 +
11927 +struct _vx_res_limit {
11928 +       rlim_t soft;            /* Context soft limit */
11929 +       rlim_t hard;            /* Context hard limit */
11930 +
11931 +       rlim_atomic_t rcur;     /* Current value */
11932 +       rlim_t rmin;            /* Context minimum */
11933 +       rlim_t rmax;            /* Context maximum */
11934 +
11935 +       atomic_t lhit;          /* Limit hits */
11936 +};
11937 +
11938 +/* context sub struct */
11939 +
11940 +struct _vx_limit {
11941 +       struct _vx_res_limit res[NUM_LIMITS];
11942 +};
11943 +
11944 +#ifdef CONFIG_VSERVER_DEBUG
11945 +
11946 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11947 +{
11948 +       int i;
11949 +
11950 +       printk("\t_vx_limit:");
11951 +       for (i = 0; i < NUM_LIMITS; i++) {
11952 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11953 +                       i, (unsigned long)__rlim_get(limit, i),
11954 +                       (unsigned long)__rlim_rmin(limit, i),
11955 +                       (unsigned long)__rlim_rmax(limit, i),
11956 +                       (long)__rlim_soft(limit, i),
11957 +                       (long)__rlim_hard(limit, i),
11958 +                       atomic_read(&__rlim_lhit(limit, i)));
11959 +       }
11960 +}
11961 +
11962 +#endif
11963 +
11964 +#endif /* _VX_LIMIT_DEF_H */
11965 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/limit.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/limit.h
11966 --- linux-2.6.32.24/include/linux/vserver/limit.h       1970-01-01 01:00:00.000000000 +0100
11967 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/limit.h       2010-02-05 00:34:02.000000000 +0100
11968 @@ -0,0 +1,71 @@
11969 +#ifndef _VX_LIMIT_H
11970 +#define _VX_LIMIT_H
11971 +
11972 +#define VLIMIT_NSOCK   16
11973 +#define VLIMIT_OPENFD  17
11974 +#define VLIMIT_ANON    18
11975 +#define VLIMIT_SHMEM   19
11976 +#define VLIMIT_SEMARY  20
11977 +#define VLIMIT_NSEMS   21
11978 +#define VLIMIT_DENTRY  22
11979 +#define VLIMIT_MAPPED  23
11980 +
11981 +
11982 +#ifdef __KERNEL__
11983 +
11984 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11985 +
11986 +/*     keep in sync with CRLIM_INFINITY */
11987 +
11988 +#define        VLIM_INFINITY   (~0ULL)
11989 +
11990 +#include <asm/atomic.h>
11991 +#include <asm/resource.h>
11992 +
11993 +#ifndef RLIM_INFINITY
11994 +#warning RLIM_INFINITY is undefined
11995 +#endif
11996 +
11997 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11998 +
11999 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12000 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12001 +
12002 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12003 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12004 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12005 +
12006 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12007 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12008 +
12009 +typedef atomic_long_t rlim_atomic_t;
12010 +typedef unsigned long rlim_t;
12011 +
12012 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12013 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12014 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12015 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12016 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12017 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12018 +
12019 +
12020 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12021 +#define        VX_VLIM(r) ((long long)(long)(r))
12022 +#define        VX_RLIM(v) ((rlim_t)(v))
12023 +#else
12024 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12025 +               ? VLIM_INFINITY : (long long)(r))
12026 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12027 +               ? RLIM_INFINITY : (rlim_t)(v))
12028 +#endif
12029 +
12030 +struct sysinfo;
12031 +
12032 +void vx_vsi_meminfo(struct sysinfo *);
12033 +void vx_vsi_swapinfo(struct sysinfo *);
12034 +long vx_vsi_cached(struct sysinfo *);
12035 +
12036 +#define NUM_LIMITS     24
12037 +
12038 +#endif /* __KERNEL__ */
12039 +#endif /* _VX_LIMIT_H */
12040 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/limit_int.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/limit_int.h
12041 --- linux-2.6.32.24/include/linux/vserver/limit_int.h   1970-01-01 01:00:00.000000000 +0100
12042 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/limit_int.h   2009-12-03 20:04:56.000000000 +0100
12043 @@ -0,0 +1,198 @@
12044 +#ifndef _VX_LIMIT_INT_H
12045 +#define _VX_LIMIT_INT_H
12046 +
12047 +#include "context.h"
12048 +
12049 +#ifdef __KERNEL__
12050 +
12051 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12052 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12053 +
12054 +extern const char *vlimit_name[NUM_LIMITS];
12055 +
12056 +static inline void __vx_acc_cres(struct vx_info *vxi,
12057 +       int res, int dir, void *_data, char *_file, int _line)
12058 +{
12059 +       if (VXD_RCRES_COND(res))
12060 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12061 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12062 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12063 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12064 +       if (!vxi)
12065 +               return;
12066 +
12067 +       if (dir > 0)
12068 +               __rlim_inc(&vxi->limit, res);
12069 +       else
12070 +               __rlim_dec(&vxi->limit, res);
12071 +}
12072 +
12073 +static inline void __vx_add_cres(struct vx_info *vxi,
12074 +       int res, int amount, void *_data, char *_file, int _line)
12075 +{
12076 +       if (VXD_RCRES_COND(res))
12077 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12078 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12079 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12080 +                       amount, _data, _file, _line);
12081 +       if (amount == 0)
12082 +               return;
12083 +       if (!vxi)
12084 +               return;
12085 +       __rlim_add(&vxi->limit, res, amount);
12086 +}
12087 +
12088 +static inline
12089 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12090 +{
12091 +       int cond = (value > __rlim_rmax(limit, res));
12092 +
12093 +       if (cond)
12094 +               __rlim_rmax(limit, res) = value;
12095 +       return cond;
12096 +}
12097 +
12098 +static inline
12099 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12100 +{
12101 +       int cond = (value < __rlim_rmin(limit, res));
12102 +
12103 +       if (cond)
12104 +               __rlim_rmin(limit, res) = value;
12105 +       return cond;
12106 +}
12107 +
12108 +static inline
12109 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12110 +{
12111 +       if (!__vx_cres_adjust_max(limit, res, value))
12112 +               __vx_cres_adjust_min(limit, res, value);
12113 +}
12114 +
12115 +
12116 +/*     return values:
12117 +        +1 ... no limit hit
12118 +        -1 ... over soft limit
12119 +         0 ... over hard limit         */
12120 +
12121 +static inline int __vx_cres_avail(struct vx_info *vxi,
12122 +       int res, int num, char *_file, int _line)
12123 +{
12124 +       struct _vx_limit *limit;
12125 +       rlim_t value;
12126 +
12127 +       if (VXD_RLIMIT_COND(res))
12128 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12129 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12130 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12131 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12132 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12133 +                       num, _file, _line);
12134 +       if (!vxi)
12135 +               return 1;
12136 +
12137 +       limit = &vxi->limit;
12138 +       value = __rlim_get(limit, res);
12139 +
12140 +       if (!__vx_cres_adjust_max(limit, res, value))
12141 +               __vx_cres_adjust_min(limit, res, value);
12142 +
12143 +       if (num == 0)
12144 +               return 1;
12145 +
12146 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12147 +               return -1;
12148 +       if (value + num <= __rlim_soft(limit, res))
12149 +               return -1;
12150 +
12151 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12152 +               return 1;
12153 +       if (value + num <= __rlim_hard(limit, res))
12154 +               return 1;
12155 +
12156 +       __rlim_hit(limit, res);
12157 +       return 0;
12158 +}
12159 +
12160 +
12161 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12162 +
12163 +static inline
12164 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12165 +{
12166 +       rlim_t value, sum = 0;
12167 +       int res;
12168 +
12169 +       while ((res = *array++)) {
12170 +               value = __rlim_get(limit, res);
12171 +               __vx_cres_fixup(limit, res, value);
12172 +               sum += value;
12173 +       }
12174 +       return sum;
12175 +}
12176 +
12177 +static inline
12178 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12179 +{
12180 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12181 +       int res = *array;
12182 +
12183 +       if (value == __rlim_get(limit, res))
12184 +               return value;
12185 +
12186 +       __rlim_set(limit, res, value);
12187 +       /* now adjust min/max */
12188 +       if (!__vx_cres_adjust_max(limit, res, value))
12189 +               __vx_cres_adjust_min(limit, res, value);
12190 +
12191 +       return value;
12192 +}
12193 +
12194 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12195 +       const int *array, int num, char *_file, int _line)
12196 +{
12197 +       struct _vx_limit *limit;
12198 +       rlim_t value = 0;
12199 +       int res;
12200 +
12201 +       if (num == 0)
12202 +               return 1;
12203 +       if (!vxi)
12204 +               return 1;
12205 +
12206 +       limit = &vxi->limit;
12207 +       res = *array;
12208 +       value = __vx_cres_array_sum(limit, array + 1);
12209 +
12210 +       __rlim_set(limit, res, value);
12211 +       __vx_cres_fixup(limit, res, value);
12212 +
12213 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12214 +}
12215 +
12216 +
12217 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12218 +{
12219 +       rlim_t value;
12220 +       int res;
12221 +
12222 +       /* complex resources first */
12223 +       if ((id < 0) || (id == RLIMIT_RSS))
12224 +               __vx_cres_array_fixup(limit, VLA_RSS);
12225 +
12226 +       for (res = 0; res < NUM_LIMITS; res++) {
12227 +               if ((id > 0) && (res != id))
12228 +                       continue;
12229 +
12230 +               value = __rlim_get(limit, res);
12231 +               __vx_cres_fixup(limit, res, value);
12232 +
12233 +               /* not supposed to happen, maybe warn? */
12234 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12235 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12236 +       }
12237 +}
12238 +
12239 +
12240 +#endif /* __KERNEL__ */
12241 +#endif /* _VX_LIMIT_INT_H */
12242 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/monitor.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/monitor.h
12243 --- linux-2.6.32.24/include/linux/vserver/monitor.h     1970-01-01 01:00:00.000000000 +0100
12244 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/monitor.h     2009-12-03 20:04:56.000000000 +0100
12245 @@ -0,0 +1,96 @@
12246 +#ifndef _VX_MONITOR_H
12247 +#define _VX_MONITOR_H
12248 +
12249 +#include <linux/types.h>
12250 +
12251 +enum {
12252 +       VXM_UNUSED = 0,
12253 +
12254 +       VXM_SYNC = 0x10,
12255 +
12256 +       VXM_UPDATE = 0x20,
12257 +       VXM_UPDATE_1,
12258 +       VXM_UPDATE_2,
12259 +
12260 +       VXM_RQINFO_1 = 0x24,
12261 +       VXM_RQINFO_2,
12262 +
12263 +       VXM_ACTIVATE = 0x40,
12264 +       VXM_DEACTIVATE,
12265 +       VXM_IDLE,
12266 +
12267 +       VXM_HOLD = 0x44,
12268 +       VXM_UNHOLD,
12269 +
12270 +       VXM_MIGRATE = 0x48,
12271 +       VXM_RESCHED,
12272 +
12273 +       /* all other bits are flags */
12274 +       VXM_SCHED = 0x80,
12275 +};
12276 +
12277 +struct _vxm_update_1 {
12278 +       uint32_t tokens_max;
12279 +       uint32_t fill_rate;
12280 +       uint32_t interval;
12281 +};
12282 +
12283 +struct _vxm_update_2 {
12284 +       uint32_t tokens_min;
12285 +       uint32_t fill_rate;
12286 +       uint32_t interval;
12287 +};
12288 +
12289 +struct _vxm_rqinfo_1 {
12290 +       uint16_t running;
12291 +       uint16_t onhold;
12292 +       uint16_t iowait;
12293 +       uint16_t uintr;
12294 +       uint32_t idle_tokens;
12295 +};
12296 +
12297 +struct _vxm_rqinfo_2 {
12298 +       uint32_t norm_time;
12299 +       uint32_t idle_time;
12300 +       uint32_t idle_skip;
12301 +};
12302 +
12303 +struct _vxm_sched {
12304 +       uint32_t tokens;
12305 +       uint32_t norm_time;
12306 +       uint32_t idle_time;
12307 +};
12308 +
12309 +struct _vxm_task {
12310 +       uint16_t pid;
12311 +       uint16_t state;
12312 +};
12313 +
12314 +struct _vxm_event {
12315 +       uint32_t jif;
12316 +       union {
12317 +               uint32_t seq;
12318 +               uint32_t sec;
12319 +       };
12320 +       union {
12321 +               uint32_t tokens;
12322 +               uint32_t nsec;
12323 +               struct _vxm_task tsk;
12324 +       };
12325 +};
12326 +
12327 +struct _vx_mon_entry {
12328 +       uint16_t type;
12329 +       uint16_t xid;
12330 +       union {
12331 +               struct _vxm_event ev;
12332 +               struct _vxm_sched sd;
12333 +               struct _vxm_update_1 u1;
12334 +               struct _vxm_update_2 u2;
12335 +               struct _vxm_rqinfo_1 q1;
12336 +               struct _vxm_rqinfo_2 q2;
12337 +       };
12338 +};
12339 +
12340 +
12341 +#endif /* _VX_MONITOR_H */
12342 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/network_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/network_cmd.h
12343 --- linux-2.6.32.24/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00.000000000 +0100
12344 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/network_cmd.h 2009-12-03 20:04:56.000000000 +0100
12345 @@ -0,0 +1,150 @@
12346 +#ifndef _VX_NETWORK_CMD_H
12347 +#define _VX_NETWORK_CMD_H
12348 +
12349 +
12350 +/* vinfo commands */
12351 +
12352 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12353 +
12354 +#ifdef __KERNEL__
12355 +extern int vc_task_nid(uint32_t);
12356 +
12357 +#endif /* __KERNEL__ */
12358 +
12359 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12360 +
12361 +struct vcmd_nx_info_v0 {
12362 +       uint32_t nid;
12363 +       /* more to come */
12364 +};
12365 +
12366 +#ifdef __KERNEL__
12367 +extern int vc_nx_info(struct nx_info *, void __user *);
12368 +
12369 +#endif /* __KERNEL__ */
12370 +
12371 +#include <linux/in.h>
12372 +#include <linux/in6.h>
12373 +
12374 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12375 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12376 +
12377 +struct  vcmd_net_create {
12378 +       uint64_t flagword;
12379 +};
12380 +
12381 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12382 +
12383 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12384 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12385 +
12386 +struct vcmd_net_addr_v0 {
12387 +       uint16_t type;
12388 +       uint16_t count;
12389 +       struct in_addr ip[4];
12390 +       struct in_addr mask[4];
12391 +};
12392 +
12393 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12394 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12395 +
12396 +struct vcmd_net_addr_ipv4_v1 {
12397 +       uint16_t type;
12398 +       uint16_t flags;
12399 +       struct in_addr ip;
12400 +       struct in_addr mask;
12401 +};
12402 +
12403 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12404 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12405 +
12406 +struct vcmd_net_addr_ipv6_v1 {
12407 +       uint16_t type;
12408 +       uint16_t flags;
12409 +       uint32_t prefix;
12410 +       struct in6_addr ip;
12411 +       struct in6_addr mask;
12412 +};
12413 +
12414 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12415 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12416 +
12417 +struct vcmd_match_ipv4_v0 {
12418 +       uint16_t type;
12419 +       uint16_t flags;
12420 +       uint16_t parent;
12421 +       uint16_t prefix;
12422 +       struct in_addr ip;
12423 +       struct in_addr ip2;
12424 +       struct in_addr mask;
12425 +};
12426 +
12427 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12428 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12429 +
12430 +struct vcmd_match_ipv6_v0 {
12431 +       uint16_t type;
12432 +       uint16_t flags;
12433 +       uint16_t parent;
12434 +       uint16_t prefix;
12435 +       struct in6_addr ip;
12436 +       struct in6_addr ip2;
12437 +       struct in6_addr mask;
12438 +};
12439 +
12440 +
12441 +#ifdef __KERNEL__
12442 +extern int vc_net_create(uint32_t, void __user *);
12443 +extern int vc_net_migrate(struct nx_info *, void __user *);
12444 +
12445 +extern int vc_net_add(struct nx_info *, void __user *);
12446 +extern int vc_net_remove(struct nx_info *, void __user *);
12447 +
12448 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12449 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12450 +
12451 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12452 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12453 +
12454 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12455 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12456 +
12457 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12458 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12459 +
12460 +#endif /* __KERNEL__ */
12461 +
12462 +
12463 +/* flag commands */
12464 +
12465 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12466 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12467 +
12468 +struct vcmd_net_flags_v0 {
12469 +       uint64_t flagword;
12470 +       uint64_t mask;
12471 +};
12472 +
12473 +#ifdef __KERNEL__
12474 +extern int vc_get_nflags(struct nx_info *, void __user *);
12475 +extern int vc_set_nflags(struct nx_info *, void __user *);
12476 +
12477 +#endif /* __KERNEL__ */
12478 +
12479 +
12480 +/* network caps commands */
12481 +
12482 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12483 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12484 +
12485 +struct vcmd_net_caps_v0 {
12486 +       uint64_t ncaps;
12487 +       uint64_t cmask;
12488 +};
12489 +
12490 +#ifdef __KERNEL__
12491 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12492 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12493 +
12494 +#endif /* __KERNEL__ */
12495 +#endif /* _VX_CONTEXT_CMD_H */
12496 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/network.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/network.h
12497 --- linux-2.6.32.24/include/linux/vserver/network.h     1970-01-01 01:00:00.000000000 +0100
12498 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/network.h     2009-12-03 20:04:56.000000000 +0100
12499 @@ -0,0 +1,146 @@
12500 +#ifndef _VX_NETWORK_H
12501 +#define _VX_NETWORK_H
12502 +
12503 +#include <linux/types.h>
12504 +
12505 +
12506 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12507 +
12508 +
12509 +/* network flags */
12510 +
12511 +#define NXF_INFO_PRIVATE       0x00000008
12512 +
12513 +#define NXF_SINGLE_IP          0x00000100
12514 +#define NXF_LBACK_REMAP                0x00000200
12515 +#define NXF_LBACK_ALLOW                0x00000400
12516 +
12517 +#define NXF_HIDE_NETIF         0x02000000
12518 +#define NXF_HIDE_LBACK         0x04000000
12519 +
12520 +#define NXF_STATE_SETUP                (1ULL << 32)
12521 +#define NXF_STATE_ADMIN                (1ULL << 34)
12522 +
12523 +#define NXF_SC_HELPER          (1ULL << 36)
12524 +#define NXF_PERSISTENT         (1ULL << 38)
12525 +
12526 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12527 +
12528 +
12529 +#define        NXF_INIT_SET            (__nxf_init_set())
12530 +
12531 +static inline uint64_t __nxf_init_set(void) {
12532 +       return    NXF_STATE_ADMIN
12533 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12534 +               | NXF_LBACK_REMAP
12535 +               | NXF_HIDE_LBACK
12536 +#endif
12537 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12538 +               | NXF_SINGLE_IP
12539 +#endif
12540 +               | NXF_HIDE_NETIF;
12541 +}
12542 +
12543 +
12544 +/* network caps */
12545 +
12546 +#define NXC_TUN_CREATE         0x00000001
12547 +
12548 +#define NXC_RAW_ICMP           0x00000100
12549 +
12550 +
12551 +/* address types */
12552 +
12553 +#define NXA_TYPE_IPV4          0x0001
12554 +#define NXA_TYPE_IPV6          0x0002
12555 +
12556 +#define NXA_TYPE_NONE          0x0000
12557 +#define NXA_TYPE_ANY           0x00FF
12558 +
12559 +#define NXA_TYPE_ADDR          0x0010
12560 +#define NXA_TYPE_MASK          0x0020
12561 +#define NXA_TYPE_RANGE         0x0040
12562 +
12563 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12564 +
12565 +#define NXA_MOD_BCAST          0x0100
12566 +#define NXA_MOD_LBACK          0x0200
12567 +
12568 +#define NXA_LOOPBACK           0x1000
12569 +
12570 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12571 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12572 +
12573 +#ifdef __KERNEL__
12574 +
12575 +#include <linux/list.h>
12576 +#include <linux/spinlock.h>
12577 +#include <linux/rcupdate.h>
12578 +#include <linux/in.h>
12579 +#include <linux/in6.h>
12580 +#include <asm/atomic.h>
12581 +
12582 +struct nx_addr_v4 {
12583 +       struct nx_addr_v4 *next;
12584 +       struct in_addr ip[2];
12585 +       struct in_addr mask;
12586 +       uint16_t type;
12587 +       uint16_t flags;
12588 +};
12589 +
12590 +struct nx_addr_v6 {
12591 +       struct nx_addr_v6 *next;
12592 +       struct in6_addr ip;
12593 +       struct in6_addr mask;
12594 +       uint32_t prefix;
12595 +       uint16_t type;
12596 +       uint16_t flags;
12597 +};
12598 +
12599 +struct nx_info {
12600 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12601 +       nid_t nx_id;                    /* vnet id */
12602 +       atomic_t nx_usecnt;             /* usage count */
12603 +       atomic_t nx_tasks;              /* tasks count */
12604 +       int nx_state;                   /* context state */
12605 +
12606 +       uint64_t nx_flags;              /* network flag word */
12607 +       uint64_t nx_ncaps;              /* network capabilities */
12608 +
12609 +       struct in_addr v4_lback;        /* Loopback address */
12610 +       struct in_addr v4_bcast;        /* Broadcast address */
12611 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12612 +#ifdef CONFIG_IPV6
12613 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12614 +#endif
12615 +       char nx_name[65];               /* network context name */
12616 +};
12617 +
12618 +
12619 +/* status flags */
12620 +
12621 +#define NXS_HASHED      0x0001
12622 +#define NXS_SHUTDOWN    0x0100
12623 +#define NXS_RELEASED    0x8000
12624 +
12625 +extern struct nx_info *lookup_nx_info(int);
12626 +
12627 +extern int get_nid_list(int, unsigned int *, int);
12628 +extern int nid_is_hashed(nid_t);
12629 +
12630 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12631 +
12632 +extern long vs_net_change(struct nx_info *, unsigned int);
12633 +
12634 +struct sock;
12635 +
12636 +
12637 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12638 +#ifdef  CONFIG_IPV6
12639 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12640 +#else
12641 +#define NX_IPV6(n)     (0)
12642 +#endif
12643 +
12644 +#endif /* __KERNEL__ */
12645 +#endif /* _VX_NETWORK_H */
12646 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/percpu.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/percpu.h
12647 --- linux-2.6.32.24/include/linux/vserver/percpu.h      1970-01-01 01:00:00.000000000 +0100
12648 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/percpu.h      2009-12-03 20:04:56.000000000 +0100
12649 @@ -0,0 +1,14 @@
12650 +#ifndef _VX_PERCPU_H
12651 +#define _VX_PERCPU_H
12652 +
12653 +#include "cvirt_def.h"
12654 +#include "sched_def.h"
12655 +
12656 +struct _vx_percpu {
12657 +       struct _vx_cvirt_pc cvirt;
12658 +       struct _vx_sched_pc sched;
12659 +};
12660 +
12661 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12662 +
12663 +#endif /* _VX_PERCPU_H */
12664 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/pid.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/pid.h
12665 --- linux-2.6.32.24/include/linux/vserver/pid.h 1970-01-01 01:00:00.000000000 +0100
12666 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/pid.h 2009-12-03 20:04:56.000000000 +0100
12667 @@ -0,0 +1,51 @@
12668 +#ifndef _VSERVER_PID_H
12669 +#define _VSERVER_PID_H
12670 +
12671 +/* pid faking stuff */
12672 +
12673 +#define vx_info_map_pid(v, p) \
12674 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12675 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12676 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12677 +#define vx_map_tgid(p) vx_map_pid(p)
12678 +
12679 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12680 +       const char *func, const char *file, int line)
12681 +{
12682 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12683 +               vxfprintk(VXD_CBIT(cvirt, 2),
12684 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12685 +                       vxi, (long long)vxi->vx_flags, pid,
12686 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12687 +                       func, file, line);
12688 +               if (pid == 0)
12689 +                       return 0;
12690 +               if (pid == vxi->vx_initpid)
12691 +                       return 1;
12692 +       }
12693 +       return pid;
12694 +}
12695 +
12696 +#define vx_info_rmap_pid(v, p) \
12697 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12698 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12699 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12700 +
12701 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12702 +       const char *func, const char *file, int line)
12703 +{
12704 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12705 +               vxfprintk(VXD_CBIT(cvirt, 2),
12706 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12707 +                       vxi, (long long)vxi->vx_flags, pid,
12708 +                       (pid == 1) ? vxi->vx_initpid : pid,
12709 +                       func, file, line);
12710 +               if ((pid == 1) && vxi->vx_initpid)
12711 +                       return vxi->vx_initpid;
12712 +               if (pid == vxi->vx_initpid)
12713 +                       return ~0U;
12714 +       }
12715 +       return pid;
12716 +}
12717 +
12718 +#endif
12719 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/sched_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/sched_cmd.h
12720 --- linux-2.6.32.24/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00.000000000 +0100
12721 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/sched_cmd.h   2009-12-03 20:04:56.000000000 +0100
12722 @@ -0,0 +1,108 @@
12723 +#ifndef _VX_SCHED_CMD_H
12724 +#define _VX_SCHED_CMD_H
12725 +
12726 +
12727 +/*  sched vserver commands */
12728 +
12729 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12730 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12731 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12732 +
12733 +struct vcmd_set_sched_v2 {
12734 +       int32_t fill_rate;
12735 +       int32_t interval;
12736 +       int32_t tokens;
12737 +       int32_t tokens_min;
12738 +       int32_t tokens_max;
12739 +       uint64_t cpu_mask;
12740 +};
12741 +
12742 +struct vcmd_set_sched_v3 {
12743 +       uint32_t set_mask;
12744 +       int32_t fill_rate;
12745 +       int32_t interval;
12746 +       int32_t tokens;
12747 +       int32_t tokens_min;
12748 +       int32_t tokens_max;
12749 +       int32_t priority_bias;
12750 +};
12751 +
12752 +struct vcmd_set_sched_v4 {
12753 +       uint32_t set_mask;
12754 +       int32_t fill_rate;
12755 +       int32_t interval;
12756 +       int32_t tokens;
12757 +       int32_t tokens_min;
12758 +       int32_t tokens_max;
12759 +       int32_t prio_bias;
12760 +       int32_t cpu_id;
12761 +       int32_t bucket_id;
12762 +};
12763 +
12764 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12765 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12766 +
12767 +struct vcmd_sched_v5 {
12768 +       uint32_t mask;
12769 +       int32_t cpu_id;
12770 +       int32_t bucket_id;
12771 +       int32_t fill_rate[2];
12772 +       int32_t interval[2];
12773 +       int32_t tokens;
12774 +       int32_t tokens_min;
12775 +       int32_t tokens_max;
12776 +       int32_t prio_bias;
12777 +};
12778 +
12779 +#define VXSM_FILL_RATE         0x0001
12780 +#define VXSM_INTERVAL          0x0002
12781 +#define VXSM_FILL_RATE2                0x0004
12782 +#define VXSM_INTERVAL2         0x0008
12783 +#define VXSM_TOKENS            0x0010
12784 +#define VXSM_TOKENS_MIN                0x0020
12785 +#define VXSM_TOKENS_MAX                0x0040
12786 +#define VXSM_PRIO_BIAS         0x0100
12787 +
12788 +#define VXSM_IDLE_TIME         0x0200
12789 +#define VXSM_FORCE             0x0400
12790 +
12791 +#define        VXSM_V3_MASK            0x0173
12792 +#define        VXSM_SET_MASK           0x01FF
12793 +
12794 +#define VXSM_CPU_ID            0x1000
12795 +#define VXSM_BUCKET_ID         0x2000
12796 +
12797 +#define VXSM_MSEC              0x4000
12798 +
12799 +#define SCHED_KEEP             (-2)    /* only for v2 */
12800 +
12801 +#ifdef __KERNEL__
12802 +
12803 +#include <linux/compiler.h>
12804 +
12805 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12806 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12807 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12808 +extern int vc_set_sched(struct vx_info *, void __user *);
12809 +extern int vc_get_sched(struct vx_info *, void __user *);
12810 +
12811 +#endif /* __KERNEL__ */
12812 +
12813 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12814 +
12815 +struct vcmd_sched_info {
12816 +       int32_t cpu_id;
12817 +       int32_t bucket_id;
12818 +       uint64_t user_msec;
12819 +       uint64_t sys_msec;
12820 +       uint64_t hold_msec;
12821 +       uint32_t token_usec;
12822 +       int32_t vavavoom;
12823 +};
12824 +
12825 +#ifdef __KERNEL__
12826 +
12827 +extern int vc_sched_info(struct vx_info *, void __user *);
12828 +
12829 +#endif /* __KERNEL__ */
12830 +#endif /* _VX_SCHED_CMD_H */
12831 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/sched_def.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/sched_def.h
12832 --- linux-2.6.32.24/include/linux/vserver/sched_def.h   1970-01-01 01:00:00.000000000 +0100
12833 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/sched_def.h   2009-12-03 20:04:56.000000000 +0100
12834 @@ -0,0 +1,68 @@
12835 +#ifndef _VX_SCHED_DEF_H
12836 +#define _VX_SCHED_DEF_H
12837 +
12838 +#include <linux/spinlock.h>
12839 +#include <linux/jiffies.h>
12840 +#include <linux/cpumask.h>
12841 +#include <asm/atomic.h>
12842 +#include <asm/param.h>
12843 +
12844 +
12845 +/* context sub struct */
12846 +
12847 +struct _vx_sched {
12848 +       spinlock_t tokens_lock;         /* lock for token bucket */
12849 +
12850 +       int tokens;                     /* number of CPU tokens */
12851 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12852 +       int interval[2];                /* Divisor:   per Y jiffies   */
12853 +       int tokens_min;                 /* Limit:     minimum for unhold */
12854 +       int tokens_max;                 /* Limit:     no more than N tokens */
12855 +
12856 +       int prio_bias;                  /* bias offset for priority */
12857 +
12858 +       unsigned update_mask;           /* which features should be updated */
12859 +       cpumask_t update;               /* CPUs which should update */
12860 +};
12861 +
12862 +struct _vx_sched_pc {
12863 +       int tokens;                     /* number of CPU tokens */
12864 +       int flags;                      /* bucket flags */
12865 +
12866 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12867 +       int interval[2];                /* Divisor:   per Y jiffies   */
12868 +       int tokens_min;                 /* Limit:     minimum for unhold */
12869 +       int tokens_max;                 /* Limit:     no more than N tokens */
12870 +
12871 +       int prio_bias;                  /* bias offset for priority */
12872 +       int vavavoom;                   /* last calculated vavavoom */
12873 +
12874 +       unsigned long norm_time;        /* last time accounted */
12875 +       unsigned long idle_time;        /* non linear time for fair sched */
12876 +       unsigned long token_time;       /* token time for accounting */
12877 +       unsigned long onhold;           /* jiffies when put on hold */
12878 +
12879 +       uint64_t user_ticks;            /* token tick events */
12880 +       uint64_t sys_ticks;             /* token tick events */
12881 +       uint64_t hold_ticks;            /* token ticks paused */
12882 +};
12883 +
12884 +
12885 +#define VXSF_ONHOLD    0x0001
12886 +#define VXSF_IDLE_TIME 0x0100
12887 +
12888 +#ifdef CONFIG_VSERVER_DEBUG
12889 +
12890 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12891 +{
12892 +       printk("\t_vx_sched:\n");
12893 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12894 +               sched->fill_rate[0], sched->interval[0],
12895 +               sched->fill_rate[1], sched->interval[1],
12896 +               sched->tokens_min, sched->tokens_max);
12897 +       printk("\t priority = %4d\n", sched->prio_bias);
12898 +}
12899 +
12900 +#endif
12901 +
12902 +#endif /* _VX_SCHED_DEF_H */
12903 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/sched.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/sched.h
12904 --- linux-2.6.32.24/include/linux/vserver/sched.h       1970-01-01 01:00:00.000000000 +0100
12905 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/sched.h       2009-12-03 20:04:56.000000000 +0100
12906 @@ -0,0 +1,26 @@
12907 +#ifndef _VX_SCHED_H
12908 +#define _VX_SCHED_H
12909 +
12910 +
12911 +#ifdef __KERNEL__
12912 +
12913 +struct timespec;
12914 +
12915 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12916 +
12917 +
12918 +struct vx_info;
12919 +
12920 +void vx_update_load(struct vx_info *);
12921 +
12922 +
12923 +int vx_tokens_recalc(struct _vx_sched_pc *,
12924 +       unsigned long *, unsigned long *, int [2]);
12925 +
12926 +void vx_update_sched_param(struct _vx_sched *sched,
12927 +       struct _vx_sched_pc *sched_pc);
12928 +
12929 +#endif /* __KERNEL__ */
12930 +#else  /* _VX_SCHED_H */
12931 +#warning duplicate inclusion
12932 +#endif /* _VX_SCHED_H */
12933 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/signal_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/signal_cmd.h
12934 --- linux-2.6.32.24/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00.000000000 +0100
12935 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/signal_cmd.h  2009-12-03 20:04:56.000000000 +0100
12936 @@ -0,0 +1,43 @@
12937 +#ifndef _VX_SIGNAL_CMD_H
12938 +#define _VX_SIGNAL_CMD_H
12939 +
12940 +
12941 +/*  signalling vserver commands */
12942 +
12943 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12944 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12945 +
12946 +struct vcmd_ctx_kill_v0 {
12947 +       int32_t pid;
12948 +       int32_t sig;
12949 +};
12950 +
12951 +struct vcmd_wait_exit_v0 {
12952 +       int32_t reboot_cmd;
12953 +       int32_t exit_code;
12954 +};
12955 +
12956 +#ifdef __KERNEL__
12957 +
12958 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12959 +extern int vc_wait_exit(struct vx_info *, void __user *);
12960 +
12961 +#endif /* __KERNEL__ */
12962 +
12963 +/*  process alteration commands */
12964 +
12965 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12966 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12967 +
12968 +struct vcmd_pflags_v0 {
12969 +       uint32_t flagword;
12970 +       uint32_t mask;
12971 +};
12972 +
12973 +#ifdef __KERNEL__
12974 +
12975 +extern int vc_get_pflags(uint32_t pid, void __user *);
12976 +extern int vc_set_pflags(uint32_t pid, void __user *);
12977 +
12978 +#endif /* __KERNEL__ */
12979 +#endif /* _VX_SIGNAL_CMD_H */
12980 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/signal.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/signal.h
12981 --- linux-2.6.32.24/include/linux/vserver/signal.h      1970-01-01 01:00:00.000000000 +0100
12982 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/signal.h      2009-12-03 20:04:56.000000000 +0100
12983 @@ -0,0 +1,14 @@
12984 +#ifndef _VX_SIGNAL_H
12985 +#define _VX_SIGNAL_H
12986 +
12987 +
12988 +#ifdef __KERNEL__
12989 +
12990 +struct vx_info;
12991 +
12992 +int vx_info_kill(struct vx_info *, int, int);
12993 +
12994 +#endif /* __KERNEL__ */
12995 +#else  /* _VX_SIGNAL_H */
12996 +#warning duplicate inclusion
12997 +#endif /* _VX_SIGNAL_H */
12998 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/space_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/space_cmd.h
12999 --- linux-2.6.32.24/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00.000000000 +0100
13000 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/space_cmd.h   2009-12-03 20:04:56.000000000 +0100
13001 @@ -0,0 +1,38 @@
13002 +#ifndef _VX_SPACE_CMD_H
13003 +#define _VX_SPACE_CMD_H
13004 +
13005 +
13006 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13007 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13008 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13009 +
13010 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13011 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13012 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13013 +
13014 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13015 +
13016 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13017 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13018 +
13019 +
13020 +struct vcmd_space_mask_v1 {
13021 +       uint64_t mask;
13022 +};
13023 +
13024 +struct vcmd_space_mask_v2 {
13025 +       uint64_t mask;
13026 +       uint32_t index;
13027 +};
13028 +
13029 +
13030 +#ifdef __KERNEL__
13031 +
13032 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13033 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13034 +extern int vc_enter_space(struct vx_info *, void __user *);
13035 +extern int vc_set_space(struct vx_info *, void __user *);
13036 +extern int vc_get_space_mask(void __user *, int);
13037 +
13038 +#endif /* __KERNEL__ */
13039 +#endif /* _VX_SPACE_CMD_H */
13040 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/space.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/space.h
13041 --- linux-2.6.32.24/include/linux/vserver/space.h       1970-01-01 01:00:00.000000000 +0100
13042 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/space.h       2009-12-03 20:04:56.000000000 +0100
13043 @@ -0,0 +1,12 @@
13044 +#ifndef _VX_SPACE_H
13045 +#define _VX_SPACE_H
13046 +
13047 +#include <linux/types.h>
13048 +
13049 +struct vx_info;
13050 +
13051 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13052 +
13053 +#else  /* _VX_SPACE_H */
13054 +#warning duplicate inclusion
13055 +#endif /* _VX_SPACE_H */
13056 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/switch.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/switch.h
13057 --- linux-2.6.32.24/include/linux/vserver/switch.h      1970-01-01 01:00:00.000000000 +0100
13058 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/switch.h      2009-12-03 20:04:56.000000000 +0100
13059 @@ -0,0 +1,98 @@
13060 +#ifndef _VX_SWITCH_H
13061 +#define _VX_SWITCH_H
13062 +
13063 +#include <linux/types.h>
13064 +
13065 +
13066 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13067 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13068 +#define VC_VERSION(c)          ((c) & 0xFFF)
13069 +
13070 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13071 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13072 +
13073 +/*
13074 +
13075 +  Syscall Matrix V2.8
13076 +
13077 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13078 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13079 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13080 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13081 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13082 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13083 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13084 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13085 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13086 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13087 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13088 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13089 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13090 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13091 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13092 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13093 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13094 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13095 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13096 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13097 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13098 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13099 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13100 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13101 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13102 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13103 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13104 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13105 +
13106 +*/
13107 +
13108 +#define VC_CAT_VERSION         0
13109 +
13110 +#define VC_CAT_VSETUP          1
13111 +#define VC_CAT_VHOST           2
13112 +
13113 +#define VC_CAT_DEVICE          6
13114 +
13115 +#define VC_CAT_VPROC           9
13116 +#define VC_CAT_PROCALT         10
13117 +#define VC_CAT_PROCMIG         11
13118 +#define VC_CAT_PROCTRL         12
13119 +
13120 +#define VC_CAT_SCHED           14
13121 +#define VC_CAT_MEMCTRL         20
13122 +
13123 +#define VC_CAT_VNET            25
13124 +#define VC_CAT_NETALT          26
13125 +#define VC_CAT_NETMIG          27
13126 +#define VC_CAT_NETCTRL         28
13127 +
13128 +#define VC_CAT_TAGMIG          35
13129 +#define VC_CAT_DLIMIT          36
13130 +#define VC_CAT_INODE           38
13131 +
13132 +#define VC_CAT_VSTAT           40
13133 +#define VC_CAT_VINFO           46
13134 +#define VC_CAT_EVENT           48
13135 +
13136 +#define VC_CAT_FLAGS           52
13137 +#define VC_CAT_VSPACE          54
13138 +#define VC_CAT_DEBUG           56
13139 +#define VC_CAT_RLIMIT          60
13140 +
13141 +#define VC_CAT_SYSTEST         61
13142 +#define VC_CAT_COMPAT          63
13143 +
13144 +/*  query version */
13145 +
13146 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13147 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13148 +
13149 +
13150 +#ifdef __KERNEL__
13151 +
13152 +#include <linux/errno.h>
13153 +
13154 +#endif /* __KERNEL__ */
13155 +
13156 +#endif /* _VX_SWITCH_H */
13157 +
13158 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/tag_cmd.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/tag_cmd.h
13159 --- linux-2.6.32.24/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00.000000000 +0100
13160 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/tag_cmd.h     2009-12-03 20:04:56.000000000 +0100
13161 @@ -0,0 +1,22 @@
13162 +#ifndef _VX_TAG_CMD_H
13163 +#define _VX_TAG_CMD_H
13164 +
13165 +
13166 +/* vinfo commands */
13167 +
13168 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13169 +
13170 +#ifdef __KERNEL__
13171 +extern int vc_task_tag(uint32_t);
13172 +
13173 +#endif /* __KERNEL__ */
13174 +
13175 +/* context commands */
13176 +
13177 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13178 +
13179 +#ifdef __KERNEL__
13180 +extern int vc_tag_migrate(uint32_t);
13181 +
13182 +#endif /* __KERNEL__ */
13183 +#endif /* _VX_TAG_CMD_H */
13184 diff -NurpP --minimal linux-2.6.32.24/include/linux/vserver/tag.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/tag.h
13185 --- linux-2.6.32.24/include/linux/vserver/tag.h 1970-01-01 01:00:00.000000000 +0100
13186 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vserver/tag.h 2009-12-03 20:04:56.000000000 +0100
13187 @@ -0,0 +1,143 @@
13188 +#ifndef _DX_TAG_H
13189 +#define _DX_TAG_H
13190 +
13191 +#include <linux/types.h>
13192 +
13193 +
13194 +#define DX_TAG(in)     (IS_TAGGED(in))
13195 +
13196 +
13197 +#ifdef CONFIG_TAG_NFSD
13198 +#define DX_TAG_NFSD    1
13199 +#else
13200 +#define DX_TAG_NFSD    0
13201 +#endif
13202 +
13203 +
13204 +#ifdef CONFIG_TAGGING_NONE
13205 +
13206 +#define MAX_UID                0xFFFFFFFF
13207 +#define MAX_GID                0xFFFFFFFF
13208 +
13209 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13210 +
13211 +#define TAGINO_UID(cond, uid, tag)     (uid)
13212 +#define TAGINO_GID(cond, gid, tag)     (gid)
13213 +
13214 +#endif
13215 +
13216 +
13217 +#ifdef CONFIG_TAGGING_GID16
13218 +
13219 +#define MAX_UID                0xFFFFFFFF
13220 +#define MAX_GID                0x0000FFFF
13221 +
13222 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13223 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13224 +
13225 +#define TAGINO_UID(cond, uid, tag)     (uid)
13226 +#define TAGINO_GID(cond, gid, tag)     \
13227 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13228 +
13229 +#endif
13230 +
13231 +
13232 +#ifdef CONFIG_TAGGING_ID24
13233 +
13234 +#define MAX_UID                0x00FFFFFF
13235 +#define MAX_GID                0x00FFFFFF
13236 +
13237 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13238 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13239 +
13240 +#define TAGINO_UID(cond, uid, tag)     \
13241 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13242 +#define TAGINO_GID(cond, gid, tag)     \
13243 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13244 +
13245 +#endif
13246 +
13247 +
13248 +#ifdef CONFIG_TAGGING_UID16
13249 +
13250 +#define MAX_UID                0x0000FFFF
13251 +#define MAX_GID                0xFFFFFFFF
13252 +
13253 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13254 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13255 +
13256 +#define TAGINO_UID(cond, uid, tag)     \
13257 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13258 +#define TAGINO_GID(cond, gid, tag)     (gid)
13259 +
13260 +#endif
13261 +
13262 +
13263 +#ifdef CONFIG_TAGGING_INTERN
13264 +
13265 +#define MAX_UID                0xFFFFFFFF
13266 +#define MAX_GID                0xFFFFFFFF
13267 +
13268 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13269 +       ((cond) ? (tag) : 0)
13270 +
13271 +#define TAGINO_UID(cond, uid, tag)     (uid)
13272 +#define TAGINO_GID(cond, gid, tag)     (gid)
13273 +
13274 +#endif
13275 +
13276 +
13277 +#ifndef CONFIG_TAGGING_NONE
13278 +#define dx_current_fstag(sb)   \
13279 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13280 +#else
13281 +#define dx_current_fstag(sb)   (0)
13282 +#endif
13283 +
13284 +#ifndef CONFIG_TAGGING_INTERN
13285 +#define TAGINO_TAG(cond, tag)  (0)
13286 +#else
13287 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13288 +#endif
13289 +
13290 +#define INOTAG_UID(cond, uid, gid)     \
13291 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13292 +#define INOTAG_GID(cond, uid, gid)     \
13293 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13294 +
13295 +
13296 +static inline uid_t dx_map_uid(uid_t uid)
13297 +{
13298 +       if ((uid > MAX_UID) && (uid != -1))
13299 +               uid = -2;
13300 +       return (uid & MAX_UID);
13301 +}
13302 +
13303 +static inline gid_t dx_map_gid(gid_t gid)
13304 +{
13305 +       if ((gid > MAX_GID) && (gid != -1))
13306 +               gid = -2;
13307 +       return (gid & MAX_GID);
13308 +}
13309 +
13310 +struct peer_tag {
13311 +       int32_t xid;
13312 +       int32_t nid;
13313 +};
13314 +
13315 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13316 +
13317 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13318 +                unsigned long *flags);
13319 +
13320 +#ifdef CONFIG_PROPAGATE
13321 +
13322 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13323 +
13324 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13325 +
13326 +#else
13327 +#define dx_propagate_tag(n, i) do { } while (0)
13328 +#endif
13329 +
13330 +#endif /* _DX_TAG_H */
13331 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_inet6.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_inet6.h
13332 --- linux-2.6.32.24/include/linux/vs_inet6.h    1970-01-01 01:00:00.000000000 +0100
13333 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_inet6.h    2009-12-03 20:04:56.000000000 +0100
13334 @@ -0,0 +1,246 @@
13335 +#ifndef _VS_INET6_H
13336 +#define _VS_INET6_H
13337 +
13338 +#include "vserver/base.h"
13339 +#include "vserver/network.h"
13340 +#include "vserver/debug.h"
13341 +
13342 +#include <net/ipv6.h>
13343 +
13344 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13345 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13346 +
13347 +
13348 +#ifdef CONFIG_IPV6
13349 +
13350 +static inline
13351 +int v6_addr_match(struct nx_addr_v6 *nxa,
13352 +       const struct in6_addr *addr, uint16_t mask)
13353 +{
13354 +       int ret = 0;
13355 +
13356 +       switch (nxa->type & mask) {
13357 +       case NXA_TYPE_MASK:
13358 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13359 +               break;
13360 +       case NXA_TYPE_ADDR:
13361 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13362 +               break;
13363 +       case NXA_TYPE_ANY:
13364 +               ret = 1;
13365 +               break;
13366 +       }
13367 +       vxdprintk(VXD_CBIT(net, 0),
13368 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13369 +               nxa, NXAV6(nxa), addr, mask, ret);
13370 +       return ret;
13371 +}
13372 +
13373 +static inline
13374 +int v6_addr_in_nx_info(struct nx_info *nxi,
13375 +       const struct in6_addr *addr, uint16_t mask)
13376 +{
13377 +       struct nx_addr_v6 *nxa;
13378 +       int ret = 1;
13379 +
13380 +       if (!nxi)
13381 +               goto out;
13382 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13383 +               if (v6_addr_match(nxa, addr, mask))
13384 +                       goto out;
13385 +       ret = 0;
13386 +out:
13387 +       vxdprintk(VXD_CBIT(net, 0),
13388 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13389 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13390 +       return ret;
13391 +}
13392 +
13393 +static inline
13394 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13395 +{
13396 +       /* FIXME: needs full range checks */
13397 +       return v6_addr_match(nxa, &addr->ip, mask);
13398 +}
13399 +
13400 +static inline
13401 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13402 +{
13403 +       struct nx_addr_v6 *ptr;
13404 +
13405 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13406 +               if (v6_nx_addr_match(ptr, nxa, mask))
13407 +                       return 1;
13408 +       return 0;
13409 +}
13410 +
13411 +
13412 +/*
13413 + *     Check if a given address matches for a socket
13414 + *
13415 + *     nxi:            the socket's nx_info if any
13416 + *     addr:           to be verified address
13417 + */
13418 +static inline
13419 +int v6_sock_addr_match (
13420 +       struct nx_info *nxi,
13421 +       struct inet_sock *inet,
13422 +       struct in6_addr *addr)
13423 +{
13424 +       struct sock *sk = &inet->sk;
13425 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13426 +
13427 +       if (!ipv6_addr_any(addr) &&
13428 +               ipv6_addr_equal(saddr, addr))
13429 +               return 1;
13430 +       if (ipv6_addr_any(saddr))
13431 +               return v6_addr_in_nx_info(nxi, addr, -1);
13432 +       return 0;
13433 +}
13434 +
13435 +/*
13436 + *     check if address is covered by socket
13437 + *
13438 + *     sk:     the socket to check against
13439 + *     addr:   the address in question (must be != 0)
13440 + */
13441 +
13442 +static inline
13443 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13444 +{
13445 +       struct nx_info *nxi = sk->sk_nx_info;
13446 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13447 +
13448 +       vxdprintk(VXD_CBIT(net, 5),
13449 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13450 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13451 +               (sk->sk_socket?sk->sk_socket->flags:0));
13452 +
13453 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13454 +               return v6_addr_match(nxa, saddr, -1);
13455 +       } else if (nxi) {               /* match against nx_info */
13456 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13457 +       } else {                        /* unrestricted any socket */
13458 +               return 1;
13459 +       }
13460 +}
13461 +
13462 +
13463 +/* inet related checks and helpers */
13464 +
13465 +
13466 +struct in_ifaddr;
13467 +struct net_device;
13468 +struct sock;
13469 +
13470 +
13471 +#include <linux/netdevice.h>
13472 +#include <linux/inetdevice.h>
13473 +#include <net/inet_timewait_sock.h>
13474 +
13475 +
13476 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13477 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13478 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13479 +
13480 +
13481 +
13482 +static inline
13483 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13484 +{
13485 +       if (!nxi)
13486 +               return 1;
13487 +       if (!ifa)
13488 +               return 0;
13489 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13490 +}
13491 +
13492 +static inline
13493 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13494 +{
13495 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13496 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13497 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13498 +
13499 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13500 +               return 1;
13501 +       if (v6_ifa_in_nx_info(ifa, nxi))
13502 +               return 1;
13503 +       return 0;
13504 +}
13505 +
13506 +
13507 +struct nx_v6_sock_addr {
13508 +       struct in6_addr saddr;  /* Address used for validation */
13509 +       struct in6_addr baddr;  /* Address used for socket bind */
13510 +};
13511 +
13512 +static inline
13513 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13514 +       struct nx_v6_sock_addr *nsa)
13515 +{
13516 +       // struct sock *sk = &inet->sk;
13517 +       // struct nx_info *nxi = sk->sk_nx_info;
13518 +       struct in6_addr saddr = addr->sin6_addr;
13519 +       struct in6_addr baddr = saddr;
13520 +
13521 +       nsa->saddr = saddr;
13522 +       nsa->baddr = baddr;
13523 +       return 0;
13524 +}
13525 +
13526 +static inline
13527 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13528 +{
13529 +       // struct sock *sk = &inet->sk;
13530 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13531 +
13532 +       // *saddr = nsa->baddr;
13533 +       // inet->saddr = nsa->baddr;
13534 +}
13535 +
13536 +static inline
13537 +int nx_info_has_v6(struct nx_info *nxi)
13538 +{
13539 +       if (!nxi)
13540 +               return 1;
13541 +       if (NX_IPV6(nxi))
13542 +               return 1;
13543 +       return 0;
13544 +}
13545 +
13546 +#else /* CONFIG_IPV6 */
13547 +
13548 +static inline
13549 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13550 +{
13551 +       return 1;
13552 +}
13553 +
13554 +
13555 +static inline
13556 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13557 +{
13558 +       return 1;
13559 +}
13560 +
13561 +static inline
13562 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13563 +{
13564 +       return 1;
13565 +}
13566 +
13567 +static inline
13568 +int nx_info_has_v6(struct nx_info *nxi)
13569 +{
13570 +       return 0;
13571 +}
13572 +
13573 +#endif /* CONFIG_IPV6 */
13574 +
13575 +#define current_nx_info_has_v6() \
13576 +       nx_info_has_v6(current_nx_info())
13577 +
13578 +#else
13579 +#warning duplicate inclusion
13580 +#endif
13581 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_inet.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_inet.h
13582 --- linux-2.6.32.24/include/linux/vs_inet.h     1970-01-01 01:00:00.000000000 +0100
13583 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_inet.h     2009-12-03 20:04:56.000000000 +0100
13584 @@ -0,0 +1,342 @@
13585 +#ifndef _VS_INET_H
13586 +#define _VS_INET_H
13587 +
13588 +#include "vserver/base.h"
13589 +#include "vserver/network.h"
13590 +#include "vserver/debug.h"
13591 +
13592 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13593 +
13594 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13595 +                       NIPQUAD((a)->mask), (a)->type
13596 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13597 +
13598 +
13599 +static inline
13600 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13601 +{
13602 +       __be32 ip = nxa->ip[0].s_addr;
13603 +       __be32 mask = nxa->mask.s_addr;
13604 +       __be32 bcast = ip | ~mask;
13605 +       int ret = 0;
13606 +
13607 +       switch (nxa->type & tmask) {
13608 +       case NXA_TYPE_MASK:
13609 +               ret = (ip == (addr & mask));
13610 +               break;
13611 +       case NXA_TYPE_ADDR:
13612 +               ret = 3;
13613 +               if (addr == ip)
13614 +                       break;
13615 +               /* fall through to broadcast */
13616 +       case NXA_MOD_BCAST:
13617 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13618 +               break;
13619 +       case NXA_TYPE_RANGE:
13620 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13621 +                       (nxa->ip[1].s_addr > addr));
13622 +               break;
13623 +       case NXA_TYPE_ANY:
13624 +               ret = 2;
13625 +               break;
13626 +       }
13627 +
13628 +       vxdprintk(VXD_CBIT(net, 0),
13629 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13630 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13631 +       return ret;
13632 +}
13633 +
13634 +static inline
13635 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13636 +{
13637 +       struct nx_addr_v4 *nxa;
13638 +       int ret = 1;
13639 +
13640 +       if (!nxi)
13641 +               goto out;
13642 +
13643 +       ret = 2;
13644 +       /* allow 127.0.0.1 when remapping lback */
13645 +       if ((tmask & NXA_LOOPBACK) &&
13646 +               (addr == IPI_LOOPBACK) &&
13647 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13648 +               goto out;
13649 +       ret = 3;
13650 +       /* check for lback address */
13651 +       if ((tmask & NXA_MOD_LBACK) &&
13652 +               (nxi->v4_lback.s_addr == addr))
13653 +               goto out;
13654 +       ret = 4;
13655 +       /* check for broadcast address */
13656 +       if ((tmask & NXA_MOD_BCAST) &&
13657 +               (nxi->v4_bcast.s_addr == addr))
13658 +               goto out;
13659 +       ret = 5;
13660 +       /* check for v4 addresses */
13661 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13662 +               if (v4_addr_match(nxa, addr, tmask))
13663 +                       goto out;
13664 +       ret = 0;
13665 +out:
13666 +       vxdprintk(VXD_CBIT(net, 0),
13667 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13668 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13669 +       return ret;
13670 +}
13671 +
13672 +static inline
13673 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13674 +{
13675 +       /* FIXME: needs full range checks */
13676 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13677 +}
13678 +
13679 +static inline
13680 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13681 +{
13682 +       struct nx_addr_v4 *ptr;
13683 +
13684 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13685 +               if (v4_nx_addr_match(ptr, nxa, mask))
13686 +                       return 1;
13687 +       return 0;
13688 +}
13689 +
13690 +#include <net/inet_sock.h>
13691 +
13692 +/*
13693 + *     Check if a given address matches for a socket
13694 + *
13695 + *     nxi:            the socket's nx_info if any
13696 + *     addr:           to be verified address
13697 + */
13698 +static inline
13699 +int v4_sock_addr_match (
13700 +       struct nx_info *nxi,
13701 +       struct inet_sock *inet,
13702 +       __be32 addr)
13703 +{
13704 +       __be32 saddr = inet->rcv_saddr;
13705 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13706 +
13707 +       if (addr && (saddr == addr || bcast == addr))
13708 +               return 1;
13709 +       if (!saddr)
13710 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13711 +       return 0;
13712 +}
13713 +
13714 +
13715 +/* inet related checks and helpers */
13716 +
13717 +
13718 +struct in_ifaddr;
13719 +struct net_device;
13720 +struct sock;
13721 +
13722 +#ifdef CONFIG_INET
13723 +
13724 +#include <linux/netdevice.h>
13725 +#include <linux/inetdevice.h>
13726 +#include <net/inet_sock.h>
13727 +#include <net/inet_timewait_sock.h>
13728 +
13729 +
13730 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13731 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13732 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13733 +
13734 +
13735 +/*
13736 + *     check if address is covered by socket
13737 + *
13738 + *     sk:     the socket to check against
13739 + *     addr:   the address in question (must be != 0)
13740 + */
13741 +
13742 +static inline
13743 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13744 +{
13745 +       struct nx_info *nxi = sk->sk_nx_info;
13746 +       __be32 saddr = inet_rcv_saddr(sk);
13747 +
13748 +       vxdprintk(VXD_CBIT(net, 5),
13749 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13750 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13751 +               (sk->sk_socket?sk->sk_socket->flags:0));
13752 +
13753 +       if (saddr) {            /* direct address match */
13754 +               return v4_addr_match(nxa, saddr, -1);
13755 +       } else if (nxi) {       /* match against nx_info */
13756 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13757 +       } else {                /* unrestricted any socket */
13758 +               return 1;
13759 +       }
13760 +}
13761 +
13762 +
13763 +
13764 +static inline
13765 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13766 +{
13767 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13768 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13769 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13770 +
13771 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13772 +               return 1;
13773 +       if (dev_in_nx_info(dev, nxi))
13774 +               return 1;
13775 +       return 0;
13776 +}
13777 +
13778 +
13779 +static inline
13780 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13781 +{
13782 +       if (!nxi)
13783 +               return 1;
13784 +       if (!ifa)
13785 +               return 0;
13786 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13787 +}
13788 +
13789 +static inline
13790 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13791 +{
13792 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13793 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13794 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13795 +
13796 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13797 +               return 1;
13798 +       if (v4_ifa_in_nx_info(ifa, nxi))
13799 +               return 1;
13800 +       return 0;
13801 +}
13802 +
13803 +
13804 +struct nx_v4_sock_addr {
13805 +       __be32 saddr;   /* Address used for validation */
13806 +       __be32 baddr;   /* Address used for socket bind */
13807 +};
13808 +
13809 +static inline
13810 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13811 +       struct nx_v4_sock_addr *nsa)
13812 +{
13813 +       struct sock *sk = &inet->sk;
13814 +       struct nx_info *nxi = sk->sk_nx_info;
13815 +       __be32 saddr = addr->sin_addr.s_addr;
13816 +       __be32 baddr = saddr;
13817 +
13818 +       vxdprintk(VXD_CBIT(net, 3),
13819 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13820 +               sk, sk->sk_nx_info, sk->sk_socket,
13821 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13822 +               NIPQUAD(saddr));
13823 +
13824 +       if (nxi) {
13825 +               if (saddr == INADDR_ANY) {
13826 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13827 +                               baddr = nxi->v4.ip[0].s_addr;
13828 +               } else if (saddr == IPI_LOOPBACK) {
13829 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13830 +                               baddr = nxi->v4_lback.s_addr;
13831 +               } else {        /* normal address bind */
13832 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13833 +                               return -EADDRNOTAVAIL;
13834 +               }
13835 +       }
13836 +
13837 +       vxdprintk(VXD_CBIT(net, 3),
13838 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13839 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13840 +
13841 +       nsa->saddr = saddr;
13842 +       nsa->baddr = baddr;
13843 +       return 0;
13844 +}
13845 +
13846 +static inline
13847 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13848 +{
13849 +       inet->saddr = nsa->baddr;
13850 +       inet->rcv_saddr = nsa->baddr;
13851 +}
13852 +
13853 +
13854 +/*
13855 + *      helper to simplify inet_lookup_listener
13856 + *
13857 + *      nxi:   the socket's nx_info if any
13858 + *      addr:  to be verified address
13859 + *      saddr: socket address
13860 + */
13861 +static inline int v4_inet_addr_match (
13862 +       struct nx_info *nxi,
13863 +       __be32 addr,
13864 +       __be32 saddr)
13865 +{
13866 +       if (addr && (saddr == addr))
13867 +               return 1;
13868 +       if (!saddr)
13869 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13870 +       return 0;
13871 +}
13872 +
13873 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13874 +{
13875 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13876 +               (addr == nxi->v4_lback.s_addr))
13877 +               return IPI_LOOPBACK;
13878 +       return addr;
13879 +}
13880 +
13881 +static inline
13882 +int nx_info_has_v4(struct nx_info *nxi)
13883 +{
13884 +       if (!nxi)
13885 +               return 1;
13886 +       if (NX_IPV4(nxi))
13887 +               return 1;
13888 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13889 +               return 1;
13890 +       return 0;
13891 +}
13892 +
13893 +#else /* CONFIG_INET */
13894 +
13895 +static inline
13896 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13897 +{
13898 +       return 1;
13899 +}
13900 +
13901 +static inline
13902 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13903 +{
13904 +       return 1;
13905 +}
13906 +
13907 +static inline
13908 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13909 +{
13910 +       return 1;
13911 +}
13912 +
13913 +static inline
13914 +int nx_info_has_v4(struct nx_info *nxi)
13915 +{
13916 +       return 0;
13917 +}
13918 +
13919 +#endif /* CONFIG_INET */
13920 +
13921 +#define current_nx_info_has_v4() \
13922 +       nx_info_has_v4(current_nx_info())
13923 +
13924 +#else
13925 +// #warning duplicate inclusion
13926 +#endif
13927 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_limit.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_limit.h
13928 --- linux-2.6.32.24/include/linux/vs_limit.h    1970-01-01 01:00:00.000000000 +0100
13929 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_limit.h    2009-12-03 20:04:56.000000000 +0100
13930 @@ -0,0 +1,140 @@
13931 +#ifndef _VS_LIMIT_H
13932 +#define _VS_LIMIT_H
13933 +
13934 +#include "vserver/limit.h"
13935 +#include "vserver/base.h"
13936 +#include "vserver/context.h"
13937 +#include "vserver/debug.h"
13938 +#include "vserver/context.h"
13939 +#include "vserver/limit_int.h"
13940 +
13941 +
13942 +#define vx_acc_cres(v, d, p, r) \
13943 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13944 +
13945 +#define vx_acc_cres_cond(x, d, p, r) \
13946 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13947 +       r, d, p, __FILE__, __LINE__)
13948 +
13949 +
13950 +#define vx_add_cres(v, a, p, r) \
13951 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13952 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13953 +
13954 +#define vx_add_cres_cond(x, a, p, r) \
13955 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13956 +       r, a, p, __FILE__, __LINE__)
13957 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13958 +
13959 +
13960 +/* process and file limits */
13961 +
13962 +#define vx_nproc_inc(p) \
13963 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13964 +
13965 +#define vx_nproc_dec(p) \
13966 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13967 +
13968 +#define vx_files_inc(f) \
13969 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13970 +
13971 +#define vx_files_dec(f) \
13972 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13973 +
13974 +#define vx_locks_inc(l) \
13975 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13976 +
13977 +#define vx_locks_dec(l) \
13978 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13979 +
13980 +#define vx_openfd_inc(f) \
13981 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13982 +
13983 +#define vx_openfd_dec(f) \
13984 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
13985 +
13986 +
13987 +#define vx_cres_avail(v, n, r) \
13988 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13989 +
13990 +
13991 +#define vx_nproc_avail(n) \
13992 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
13993 +
13994 +#define vx_files_avail(n) \
13995 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
13996 +
13997 +#define vx_locks_avail(n) \
13998 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
13999 +
14000 +#define vx_openfd_avail(n) \
14001 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
14002 +
14003 +
14004 +/* dentry limits */
14005 +
14006 +#define vx_dentry_inc(d) do {                                          \
14007 +       if (atomic_read(&d->d_count) == 1)                              \
14008 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
14009 +       } while (0)
14010 +
14011 +#define vx_dentry_dec(d) do {                                          \
14012 +       if (atomic_read(&d->d_count) == 0)                              \
14013 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
14014 +       } while (0)
14015 +
14016 +#define vx_dentry_avail(n) \
14017 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
14018 +
14019 +
14020 +/* socket limits */
14021 +
14022 +#define vx_sock_inc(s) \
14023 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
14024 +
14025 +#define vx_sock_dec(s) \
14026 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
14027 +
14028 +#define vx_sock_avail(n) \
14029 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
14030 +
14031 +
14032 +/* ipc resource limits */
14033 +
14034 +#define vx_ipcmsg_add(v, u, a) \
14035 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
14036 +
14037 +#define vx_ipcmsg_sub(v, u, a) \
14038 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
14039 +
14040 +#define vx_ipcmsg_avail(v, a) \
14041 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
14042 +
14043 +
14044 +#define vx_ipcshm_add(v, k, a) \
14045 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14046 +
14047 +#define vx_ipcshm_sub(v, k, a) \
14048 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14049 +
14050 +#define vx_ipcshm_avail(v, a) \
14051 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14052 +
14053 +
14054 +#define vx_semary_inc(a) \
14055 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
14056 +
14057 +#define vx_semary_dec(a) \
14058 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
14059 +
14060 +
14061 +#define vx_nsems_add(a,n) \
14062 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14063 +
14064 +#define vx_nsems_sub(a,n) \
14065 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14066 +
14067 +
14068 +#else
14069 +#warning duplicate inclusion
14070 +#endif
14071 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_memory.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_memory.h
14072 --- linux-2.6.32.24/include/linux/vs_memory.h   1970-01-01 01:00:00.000000000 +0100
14073 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_memory.h   2009-12-03 20:04:56.000000000 +0100
14074 @@ -0,0 +1,159 @@
14075 +#ifndef _VS_MEMORY_H
14076 +#define _VS_MEMORY_H
14077 +
14078 +#include "vserver/limit.h"
14079 +#include "vserver/base.h"
14080 +#include "vserver/context.h"
14081 +#include "vserver/debug.h"
14082 +#include "vserver/context.h"
14083 +#include "vserver/limit_int.h"
14084 +
14085 +
14086 +#define __acc_add_long(a, v)   (*(v) += (a))
14087 +#define __acc_inc_long(v)      (++*(v))
14088 +#define __acc_dec_long(v)      (--*(v))
14089 +
14090 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14091 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14092 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14093 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14094 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14095 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14096 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14097 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14098 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14099 +
14100 +
14101 +#define vx_acc_page(m, d, v, r) do {                                   \
14102 +       if ((d) > 0)                                                    \
14103 +               __acc_inc_long(&(m)->v);                                \
14104 +       else                                                            \
14105 +               __acc_dec_long(&(m)->v);                                \
14106 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14107 +} while (0)
14108 +
14109 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14110 +       if ((d) > 0)                                                    \
14111 +               __acc_inc_atomic(&(m)->v);                              \
14112 +       else                                                            \
14113 +               __acc_dec_atomic(&(m)->v);                              \
14114 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14115 +} while (0)
14116 +
14117 +
14118 +#define vx_acc_pages(m, p, v, r) do {                                  \
14119 +       unsigned long __p = (p);                                        \
14120 +       __acc_add_long(__p, &(m)->v);                                   \
14121 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14122 +} while (0)
14123 +
14124 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14125 +       unsigned long __p = (p);                                        \
14126 +       __acc_add_atomic(__p, &(m)->v);                                 \
14127 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14128 +} while (0)
14129 +
14130 +
14131 +
14132 +#define vx_acc_vmpage(m, d) \
14133 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14134 +#define vx_acc_vmlpage(m, d) \
14135 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14136 +#define vx_acc_file_rsspage(m, d) \
14137 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14138 +#define vx_acc_anon_rsspage(m, d) \
14139 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14140 +
14141 +#define vx_acc_vmpages(m, p) \
14142 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14143 +#define vx_acc_vmlpages(m, p) \
14144 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14145 +#define vx_acc_file_rsspages(m, p) \
14146 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14147 +#define vx_acc_anon_rsspages(m, p) \
14148 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14149 +
14150 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14151 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14152 +
14153 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14154 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14155 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14156 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14157 +
14158 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14159 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14160 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14161 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14162 +
14163 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14164 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14165 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14166 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14167 +
14168 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14169 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14170 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14171 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14172 +
14173 +
14174 +#define vx_pages_avail(m, p, r) \
14175 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14176 +
14177 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14178 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14179 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14180 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14181 +
14182 +#define vx_rss_avail(m, p) \
14183 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14184 +
14185 +
14186 +enum {
14187 +       VXPT_UNKNOWN = 0,
14188 +       VXPT_ANON,
14189 +       VXPT_NONE,
14190 +       VXPT_FILE,
14191 +       VXPT_SWAP,
14192 +       VXPT_WRITE
14193 +};
14194 +
14195 +#if 0
14196 +#define        vx_page_fault(mm, vma, type, ret)
14197 +#else
14198 +
14199 +static inline
14200 +void __vx_page_fault(struct mm_struct *mm,
14201 +       struct vm_area_struct *vma, int type, int ret)
14202 +{
14203 +       struct vx_info *vxi = mm->mm_vx_info;
14204 +       int what;
14205 +/*
14206 +       static char *page_type[6] =
14207 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14208 +       static char *page_what[4] =
14209 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14210 +*/
14211 +
14212 +       if (!vxi)
14213 +               return;
14214 +
14215 +       what = (ret & 0x3);
14216 +
14217 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14218 +               type, what, ret, page_type[type], page_what[what]);
14219 +*/
14220 +       if (ret & VM_FAULT_WRITE)
14221 +               what |= 0x4;
14222 +       atomic_inc(&vxi->cacct.page[type][what]);
14223 +}
14224 +
14225 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14226 +#endif
14227 +
14228 +
14229 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14230 +
14231 +#else
14232 +#warning duplicate inclusion
14233 +#endif
14234 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_network.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_network.h
14235 --- linux-2.6.32.24/include/linux/vs_network.h  1970-01-01 01:00:00.000000000 +0100
14236 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_network.h  2009-12-03 20:04:56.000000000 +0100
14237 @@ -0,0 +1,169 @@
14238 +#ifndef _NX_VS_NETWORK_H
14239 +#define _NX_VS_NETWORK_H
14240 +
14241 +#include "vserver/context.h"
14242 +#include "vserver/network.h"
14243 +#include "vserver/base.h"
14244 +#include "vserver/check.h"
14245 +#include "vserver/debug.h"
14246 +
14247 +#include <linux/sched.h>
14248 +
14249 +
14250 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14251 +
14252 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14253 +       const char *_file, int _line)
14254 +{
14255 +       if (!nxi)
14256 +               return NULL;
14257 +
14258 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14259 +               nxi, nxi ? nxi->nx_id : 0,
14260 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14261 +               _file, _line);
14262 +
14263 +       atomic_inc(&nxi->nx_usecnt);
14264 +       return nxi;
14265 +}
14266 +
14267 +
14268 +extern void free_nx_info(struct nx_info *);
14269 +
14270 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14271 +
14272 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14273 +{
14274 +       if (!nxi)
14275 +               return;
14276 +
14277 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14278 +               nxi, nxi ? nxi->nx_id : 0,
14279 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14280 +               _file, _line);
14281 +
14282 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14283 +               free_nx_info(nxi);
14284 +}
14285 +
14286 +
14287 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14288 +
14289 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14290 +               const char *_file, int _line)
14291 +{
14292 +       if (nxi) {
14293 +               vxlprintk(VXD_CBIT(nid, 3),
14294 +                       "init_nx_info(%p[#%d.%d])",
14295 +                       nxi, nxi ? nxi->nx_id : 0,
14296 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14297 +                       _file, _line);
14298 +
14299 +               atomic_inc(&nxi->nx_usecnt);
14300 +       }
14301 +       *nxp = nxi;
14302 +}
14303 +
14304 +
14305 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14306 +
14307 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14308 +       const char *_file, int _line)
14309 +{
14310 +       struct nx_info *nxo;
14311 +
14312 +       if (!nxi)
14313 +               return;
14314 +
14315 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14316 +               nxi, nxi ? nxi->nx_id : 0,
14317 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14318 +               _file, _line);
14319 +
14320 +       atomic_inc(&nxi->nx_usecnt);
14321 +       nxo = xchg(nxp, nxi);
14322 +       BUG_ON(nxo);
14323 +}
14324 +
14325 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14326 +
14327 +static inline void __clr_nx_info(struct nx_info **nxp,
14328 +       const char *_file, int _line)
14329 +{
14330 +       struct nx_info *nxo;
14331 +
14332 +       nxo = xchg(nxp, NULL);
14333 +       if (!nxo)
14334 +               return;
14335 +
14336 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14337 +               nxo, nxo ? nxo->nx_id : 0,
14338 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14339 +               _file, _line);
14340 +
14341 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14342 +               free_nx_info(nxo);
14343 +}
14344 +
14345 +
14346 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14347 +
14348 +static inline void __claim_nx_info(struct nx_info *nxi,
14349 +       struct task_struct *task, const char *_file, int _line)
14350 +{
14351 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14352 +               nxi, nxi ? nxi->nx_id : 0,
14353 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14354 +               nxi?atomic_read(&nxi->nx_tasks):0,
14355 +               task, _file, _line);
14356 +
14357 +       atomic_inc(&nxi->nx_tasks);
14358 +}
14359 +
14360 +
14361 +extern void unhash_nx_info(struct nx_info *);
14362 +
14363 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14364 +
14365 +static inline void __release_nx_info(struct nx_info *nxi,
14366 +       struct task_struct *task, const char *_file, int _line)
14367 +{
14368 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14369 +               nxi, nxi ? nxi->nx_id : 0,
14370 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14371 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14372 +               task, _file, _line);
14373 +
14374 +       might_sleep();
14375 +
14376 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14377 +               unhash_nx_info(nxi);
14378 +}
14379 +
14380 +
14381 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14382 +
14383 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14384 +       const char *_file, int _line)
14385 +{
14386 +       struct nx_info *nxi;
14387 +
14388 +       task_lock(p);
14389 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14390 +               p, _file, _line);
14391 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14392 +       task_unlock(p);
14393 +       return nxi;
14394 +}
14395 +
14396 +
14397 +static inline void exit_nx_info(struct task_struct *p)
14398 +{
14399 +       if (p->nx_info)
14400 +               release_nx_info(p->nx_info, p);
14401 +}
14402 +
14403 +
14404 +#else
14405 +#warning duplicate inclusion
14406 +#endif
14407 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_pid.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_pid.h
14408 --- linux-2.6.32.24/include/linux/vs_pid.h      1970-01-01 01:00:00.000000000 +0100
14409 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_pid.h      2009-12-03 20:04:56.000000000 +0100
14410 @@ -0,0 +1,95 @@
14411 +#ifndef _VS_PID_H
14412 +#define _VS_PID_H
14413 +
14414 +#include "vserver/base.h"
14415 +#include "vserver/check.h"
14416 +#include "vserver/context.h"
14417 +#include "vserver/debug.h"
14418 +#include "vserver/pid.h"
14419 +#include <linux/pid_namespace.h>
14420 +
14421 +
14422 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14423 +
14424 +static inline
14425 +int vx_proc_task_visible(struct task_struct *task)
14426 +{
14427 +       if ((task->pid == 1) &&
14428 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14429 +               /* show a blend through init */
14430 +               goto visible;
14431 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14432 +               goto visible;
14433 +       return 0;
14434 +visible:
14435 +       return 1;
14436 +}
14437 +
14438 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14439 +
14440 +#if 0
14441 +
14442 +static inline
14443 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14444 +{
14445 +       struct task_struct *task = find_task_by_real_pid(pid);
14446 +
14447 +       if (task && !vx_proc_task_visible(task)) {
14448 +               vxdprintk(VXD_CBIT(misc, 6),
14449 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14450 +                       task, task->xid, task->pid,
14451 +                       current, current->xid, current->pid);
14452 +               task = NULL;
14453 +       }
14454 +       return task;
14455 +}
14456 +
14457 +#endif
14458 +
14459 +static inline
14460 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14461 +{
14462 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14463 +
14464 +       if (task && !vx_proc_task_visible(task)) {
14465 +               vxdprintk(VXD_CBIT(misc, 6),
14466 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14467 +                       task, task->xid, task->pid,
14468 +                       current, current->xid, current->pid);
14469 +               put_task_struct(task);
14470 +               task = NULL;
14471 +       }
14472 +       return task;
14473 +}
14474 +
14475 +#if 0
14476 +
14477 +static inline
14478 +struct task_struct *vx_child_reaper(struct task_struct *p)
14479 +{
14480 +       struct vx_info *vxi = p->vx_info;
14481 +       struct task_struct *reaper = child_reaper(p);
14482 +
14483 +       if (!vxi)
14484 +               goto out;
14485 +
14486 +       BUG_ON(!p->vx_info->vx_reaper);
14487 +
14488 +       /* child reaper for the guest reaper */
14489 +       if (vxi->vx_reaper == p)
14490 +               goto out;
14491 +
14492 +       reaper = vxi->vx_reaper;
14493 +out:
14494 +       vxdprintk(VXD_CBIT(xid, 7),
14495 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14496 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14497 +       return reaper;
14498 +}
14499 +
14500 +#endif
14501 +
14502 +
14503 +#else
14504 +#warning duplicate inclusion
14505 +#endif
14506 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_sched.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_sched.h
14507 --- linux-2.6.32.24/include/linux/vs_sched.h    1970-01-01 01:00:00.000000000 +0100
14508 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_sched.h    2009-12-03 20:04:56.000000000 +0100
14509 @@ -0,0 +1,110 @@
14510 +#ifndef _VS_SCHED_H
14511 +#define _VS_SCHED_H
14512 +
14513 +#include "vserver/base.h"
14514 +#include "vserver/context.h"
14515 +#include "vserver/sched.h"
14516 +
14517 +
14518 +#define VAVAVOOM_RATIO          50
14519 +
14520 +#define MAX_PRIO_BIAS           20
14521 +#define MIN_PRIO_BIAS          -20
14522 +
14523 +
14524 +#ifdef CONFIG_VSERVER_HARDCPU
14525 +
14526 +/*
14527 + * effective_prio - return the priority that is based on the static
14528 + * priority but is modified by bonuses/penalties.
14529 + *
14530 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14531 + * into a -4 ... 0 ... +4 bonus/penalty range.
14532 + *
14533 + * Additionally, we scale another amount based on the number of
14534 + * CPU tokens currently held by the context, if the process is
14535 + * part of a context (and the appropriate SCHED flag is set).
14536 + * This ranges from -5 ... 0 ... +15, quadratically.
14537 + *
14538 + * So, the total bonus is -9 .. 0 .. +19
14539 + * We use ~50% of the full 0...39 priority range so that:
14540 + *
14541 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14542 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14543 + *    unless that context is far exceeding its CPU allocation.
14544 + *
14545 + * Both properties are important to certain workloads.
14546 + */
14547 +static inline
14548 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14549 +{
14550 +       int vavavoom, max;
14551 +
14552 +       /* lots of tokens = lots of vavavoom
14553 +        *      no tokens = no vavavoom      */
14554 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14555 +               max = sched_pc->tokens_max;
14556 +               vavavoom = max - vavavoom;
14557 +               max = max * max;
14558 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14559 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14560 +               return vavavoom;
14561 +       }
14562 +       return 0;
14563 +}
14564 +
14565 +
14566 +static inline
14567 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14568 +{
14569 +       struct vx_info *vxi = p->vx_info;
14570 +       struct _vx_sched_pc *sched_pc;
14571 +
14572 +       if (!vxi)
14573 +               return prio;
14574 +
14575 +       sched_pc = &vx_cpu(vxi, sched_pc);
14576 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14577 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14578 +
14579 +               sched_pc->vavavoom = vavavoom;
14580 +               prio += vavavoom;
14581 +       }
14582 +       prio += sched_pc->prio_bias;
14583 +       return prio;
14584 +}
14585 +
14586 +#else /* !CONFIG_VSERVER_HARDCPU */
14587 +
14588 +static inline
14589 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14590 +{
14591 +       struct vx_info *vxi = p->vx_info;
14592 +
14593 +       if (vxi)
14594 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14595 +       return prio;
14596 +}
14597 +
14598 +#endif /* CONFIG_VSERVER_HARDCPU */
14599 +
14600 +
14601 +static inline void vx_account_user(struct vx_info *vxi,
14602 +       cputime_t cputime, int nice)
14603 +{
14604 +       if (!vxi)
14605 +               return;
14606 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14607 +}
14608 +
14609 +static inline void vx_account_system(struct vx_info *vxi,
14610 +       cputime_t cputime, int idle)
14611 +{
14612 +       if (!vxi)
14613 +               return;
14614 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14615 +}
14616 +
14617 +#else
14618 +#warning duplicate inclusion
14619 +#endif
14620 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_socket.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_socket.h
14621 --- linux-2.6.32.24/include/linux/vs_socket.h   1970-01-01 01:00:00.000000000 +0100
14622 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_socket.h   2009-12-03 20:04:56.000000000 +0100
14623 @@ -0,0 +1,67 @@
14624 +#ifndef _VS_SOCKET_H
14625 +#define _VS_SOCKET_H
14626 +
14627 +#include "vserver/debug.h"
14628 +#include "vserver/base.h"
14629 +#include "vserver/cacct.h"
14630 +#include "vserver/context.h"
14631 +#include "vserver/tag.h"
14632 +
14633 +
14634 +/* socket accounting */
14635 +
14636 +#include <linux/socket.h>
14637 +
14638 +static inline int vx_sock_type(int family)
14639 +{
14640 +       switch (family) {
14641 +       case PF_UNSPEC:
14642 +               return VXA_SOCK_UNSPEC;
14643 +       case PF_UNIX:
14644 +               return VXA_SOCK_UNIX;
14645 +       case PF_INET:
14646 +               return VXA_SOCK_INET;
14647 +       case PF_INET6:
14648 +               return VXA_SOCK_INET6;
14649 +       case PF_PACKET:
14650 +               return VXA_SOCK_PACKET;
14651 +       default:
14652 +               return VXA_SOCK_OTHER;
14653 +       }
14654 +}
14655 +
14656 +#define vx_acc_sock(v, f, p, s) \
14657 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14658 +
14659 +static inline void __vx_acc_sock(struct vx_info *vxi,
14660 +       int family, int pos, int size, char *file, int line)
14661 +{
14662 +       if (vxi) {
14663 +               int type = vx_sock_type(family);
14664 +
14665 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14666 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14667 +       }
14668 +}
14669 +
14670 +#define vx_sock_recv(sk, s) \
14671 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14672 +#define vx_sock_send(sk, s) \
14673 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14674 +#define vx_sock_fail(sk, s) \
14675 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14676 +
14677 +
14678 +#define sock_vx_init(s) do {           \
14679 +       (s)->sk_xid = 0;                \
14680 +       (s)->sk_vx_info = NULL;         \
14681 +       } while (0)
14682 +
14683 +#define sock_nx_init(s) do {           \
14684 +       (s)->sk_nid = 0;                \
14685 +       (s)->sk_nx_info = NULL;         \
14686 +       } while (0)
14687 +
14688 +#else
14689 +#warning duplicate inclusion
14690 +#endif
14691 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_tag.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_tag.h
14692 --- linux-2.6.32.24/include/linux/vs_tag.h      1970-01-01 01:00:00.000000000 +0100
14693 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_tag.h      2009-12-03 20:04:56.000000000 +0100
14694 @@ -0,0 +1,47 @@
14695 +#ifndef _VS_TAG_H
14696 +#define _VS_TAG_H
14697 +
14698 +#include <linux/vserver/tag.h>
14699 +
14700 +/* check conditions */
14701 +
14702 +#define DX_ADMIN       0x0001
14703 +#define DX_WATCH       0x0002
14704 +#define DX_HOSTID      0x0008
14705 +
14706 +#define DX_IDENT       0x0010
14707 +
14708 +#define DX_ARG_MASK    0x0010
14709 +
14710 +
14711 +#define dx_task_tag(t) ((t)->tag)
14712 +
14713 +#define dx_current_tag() dx_task_tag(current)
14714 +
14715 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14716 +
14717 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14718 +
14719 +
14720 +/*
14721 + * check current context for ADMIN/WATCH and
14722 + * optionally against supplied argument
14723 + */
14724 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14725 +{
14726 +       if (mode & DX_ARG_MASK) {
14727 +               if ((mode & DX_IDENT) && (id == cid))
14728 +                       return 1;
14729 +       }
14730 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14731 +               ((mode & DX_WATCH) && (cid == 1)) ||
14732 +               ((mode & DX_HOSTID) && (id == 0)));
14733 +}
14734 +
14735 +struct inode;
14736 +int dx_permission(const struct inode *inode, int mask);
14737 +
14738 +
14739 +#else
14740 +#warning duplicate inclusion
14741 +#endif
14742 diff -NurpP --minimal linux-2.6.32.24/include/linux/vs_time.h linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_time.h
14743 --- linux-2.6.32.24/include/linux/vs_time.h     1970-01-01 01:00:00.000000000 +0100
14744 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/linux/vs_time.h     2009-12-03 20:04:56.000000000 +0100
14745 @@ -0,0 +1,19 @@
14746 +#ifndef _VS_TIME_H
14747 +#define _VS_TIME_H
14748 +
14749 +
14750 +/* time faking stuff */
14751 +
14752 +#ifdef CONFIG_VSERVER_VTIME
14753 +
14754 +extern void vx_gettimeofday(struct timeval *tv);
14755 +extern int vx_settimeofday(struct timespec *ts);
14756 +
14757 +#else
14758 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14759 +#define        vx_settimeofday(t)      do_settimeofday(t)
14760 +#endif
14761 +
14762 +#else
14763 +#warning duplicate inclusion
14764 +#endif
14765 diff -NurpP --minimal linux-2.6.32.24/include/net/addrconf.h linux-2.6.32.24-vs2.3.0.36.29.6/include/net/addrconf.h
14766 --- linux-2.6.32.24/include/net/addrconf.h      2009-12-03 20:02:57.000000000 +0100
14767 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/net/addrconf.h      2009-12-03 20:04:56.000000000 +0100
14768 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14769                                                struct net_device *dev,
14770                                                const struct in6_addr *daddr,
14771                                                unsigned int srcprefs,
14772 -                                              struct in6_addr *saddr);
14773 +                                              struct in6_addr *saddr,
14774 +                                              struct nx_info *nxi);
14775  extern int                     ipv6_get_lladdr(struct net_device *dev,
14776                                                 struct in6_addr *addr,
14777                                                 unsigned char banned_flags);
14778 diff -NurpP --minimal linux-2.6.32.24/include/net/af_unix.h linux-2.6.32.24-vs2.3.0.36.29.6/include/net/af_unix.h
14779 --- linux-2.6.32.24/include/net/af_unix.h       2008-12-25 00:26:37.000000000 +0100
14780 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/net/af_unix.h       2009-12-03 20:04:56.000000000 +0100
14781 @@ -4,6 +4,7 @@
14782  #include <linux/socket.h>
14783  #include <linux/un.h>
14784  #include <linux/mutex.h>
14785 +#include <linux/vs_base.h>
14786  #include <net/sock.h>
14787  
14788  extern void unix_inflight(struct file *fp);
14789 diff -NurpP --minimal linux-2.6.32.24/include/net/inet_timewait_sock.h linux-2.6.32.24-vs2.3.0.36.29.6/include/net/inet_timewait_sock.h
14790 --- linux-2.6.32.24/include/net/inet_timewait_sock.h    2009-12-03 20:02:57.000000000 +0100
14791 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/net/inet_timewait_sock.h    2009-12-03 20:04:56.000000000 +0100
14792 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14793  #define tw_hash                        __tw_common.skc_hash
14794  #define tw_prot                        __tw_common.skc_prot
14795  #define tw_net                 __tw_common.skc_net
14796 +#define tw_xid                 __tw_common.skc_xid
14797 +#define tw_vx_info             __tw_common.skc_vx_info
14798 +#define tw_nid                 __tw_common.skc_nid
14799 +#define tw_nx_info             __tw_common.skc_nx_info
14800         int                     tw_timeout;
14801         volatile unsigned char  tw_substate;
14802         /* 3 bits hole, try to pack */
14803 diff -NurpP --minimal linux-2.6.32.24/include/net/route.h linux-2.6.32.24-vs2.3.0.36.29.6/include/net/route.h
14804 --- linux-2.6.32.24/include/net/route.h 2009-09-10 15:26:27.000000000 +0200
14805 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/net/route.h 2009-12-03 20:04:56.000000000 +0100
14806 @@ -135,6 +135,9 @@ static inline void ip_rt_put(struct rtab
14807                 dst_release(&rt->u.dst);
14808  }
14809  
14810 +#include <linux/vs_base.h>
14811 +#include <linux/vs_inet.h>
14812 +
14813  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14814  
14815  extern const __u8 ip_tos2prio[16];
14816 @@ -144,6 +147,9 @@ static inline char rt_tos2priority(u8 to
14817         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14818  }
14819  
14820 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14821 +       struct rtable **, struct flowi *);
14822 +
14823  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14824                                    __be32 src, u32 tos, int oif, u8 protocol,
14825                                    __be16 sport, __be16 dport, struct sock *sk,
14826 @@ -161,11 +167,24 @@ static inline int ip_route_connect(struc
14827  
14828         int err;
14829         struct net *net = sock_net(sk);
14830 +       struct nx_info *nx_info = current_nx_info();
14831  
14832         if (inet_sk(sk)->transparent)
14833                 fl.flags |= FLOWI_FLAG_ANYSRC;
14834  
14835 -       if (!dst || !src) {
14836 +       if (sk)
14837 +               nx_info = sk->sk_nx_info;
14838 +
14839 +       vxdprintk(VXD_CBIT(net, 4),
14840 +               "ip_route_connect(%p) %p,%p;%lx",
14841 +               sk, nx_info, sk->sk_socket,
14842 +               (sk->sk_socket?sk->sk_socket->flags:0));
14843 +
14844 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14845 +       if (err)
14846 +               return err;
14847 +
14848 +       if (!fl.fl4_dst || !fl.fl4_src) {
14849                 err = __ip_route_output_key(net, rp, &fl);
14850                 if (err)
14851                         return err;
14852 diff -NurpP --minimal linux-2.6.32.24/include/net/sock.h linux-2.6.32.24-vs2.3.0.36.29.6/include/net/sock.h
14853 --- linux-2.6.32.24/include/net/sock.h  2009-12-03 20:02:57.000000000 +0100
14854 +++ linux-2.6.32.24-vs2.3.0.36.29.6/include/net/sock.h  2009-12-03 20:04:56.000000000 +0100
14855 @@ -139,6 +139,10 @@ struct sock_common {
14856  #ifdef CONFIG_NET_NS
14857         struct net              *skc_net;
14858  #endif
14859 +       xid_t                   skc_xid;
14860 +       struct vx_info          *skc_vx_info;
14861 +       nid_t                   skc_nid;
14862 +       struct nx_info          *skc_nx_info;
14863  };
14864  
14865  /**
14866 @@ -225,6 +229,10 @@ struct sock {
14867  #define sk_bind_node           __sk_common.skc_bind_node
14868  #define sk_prot                        __sk_common.skc_prot
14869  #define sk_net                 __sk_common.skc_net
14870 +#define sk_xid                 __sk_common.skc_xid
14871 +#define sk_vx_info             __sk_common.skc_vx_info
14872 +#define sk_nid                 __sk_common.skc_nid
14873 +#define sk_nx_info             __sk_common.skc_nx_info
14874         kmemcheck_bitfield_begin(flags);
14875         unsigned int            sk_shutdown  : 2,
14876                                 sk_no_check  : 2,
14877 diff -NurpP --minimal linux-2.6.32.24/init/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/init/Kconfig
14878 --- linux-2.6.32.24/init/Kconfig        2009-12-03 20:02:57.000000000 +0100
14879 +++ linux-2.6.32.24-vs2.3.0.36.29.6/init/Kconfig        2009-12-03 20:04:56.000000000 +0100
14880 @@ -477,6 +477,19 @@ config CGROUP_SCHED
14881  
14882  endchoice
14883  
14884 +config CFS_HARD_LIMITS
14885 +       bool "Hard Limits for CFS Group Scheduler"
14886 +       depends on EXPERIMENTAL
14887 +       depends on FAIR_GROUP_SCHED && CGROUP_SCHED
14888 +       default n
14889 +       help
14890 +         This option enables hard limiting of CPU time obtained by
14891 +         a fair task group. Use this if you want to throttle a group of tasks
14892 +         based on its CPU usage. For more details refer to
14893 +         Documentation/scheduler/sched-cfs-hard-limits.txt
14894 +
14895 +         Say N if unsure.
14896 +
14897  menuconfig CGROUPS
14898         boolean "Control Group support"
14899         help
14900 diff -NurpP --minimal linux-2.6.32.24/init/main.c linux-2.6.32.24-vs2.3.0.36.29.6/init/main.c
14901 --- linux-2.6.32.24/init/main.c 2010-10-04 08:56:17.000000000 +0200
14902 +++ linux-2.6.32.24-vs2.3.0.36.29.6/init/main.c 2010-04-05 20:56:22.000000000 +0200
14903 @@ -70,6 +70,7 @@
14904  #include <linux/sfi.h>
14905  #include <linux/shmem_fs.h>
14906  #include <trace/boot.h>
14907 +#include <linux/vserver/percpu.h>
14908  
14909  #include <asm/io.h>
14910  #include <asm/bugs.h>
14911 diff -NurpP --minimal linux-2.6.32.24/ipc/mqueue.c linux-2.6.32.24-vs2.3.0.36.29.6/ipc/mqueue.c
14912 --- linux-2.6.32.24/ipc/mqueue.c        2010-10-04 08:56:17.000000000 +0200
14913 +++ linux-2.6.32.24-vs2.3.0.36.29.6/ipc/mqueue.c        2010-04-05 20:56:22.000000000 +0200
14914 @@ -33,6 +33,8 @@
14915  #include <linux/pid.h>
14916  #include <linux/ipc_namespace.h>
14917  #include <linux/ima.h>
14918 +#include <linux/vs_context.h>
14919 +#include <linux/vs_limit.h>
14920  
14921  #include <net/sock.h>
14922  #include "util.h"
14923 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14924         struct sigevent notify;
14925         struct pid* notify_owner;
14926         struct user_struct *user;       /* user who created, for accounting */
14927 +       struct vx_info *vxi;
14928         struct sock *notify_sock;
14929         struct sk_buff *notify_cookie;
14930  
14931 @@ -125,6 +128,7 @@ static struct inode *mqueue_get_inode(st
14932                 if (S_ISREG(mode)) {
14933                         struct mqueue_inode_info *info;
14934                         struct task_struct *p = current;
14935 +                       struct vx_info *vxi = p->vx_info;
14936                         unsigned long mq_bytes, mq_msg_tblsz;
14937  
14938                         inode->i_fop = &mqueue_file_operations;
14939 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14940                         info->notify_owner = NULL;
14941                         info->qsize = 0;
14942                         info->user = NULL;      /* set when all is ok */
14943 +                       info->vxi = NULL;
14944                         memset(&info->attr, 0, sizeof(info->attr));
14945                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14946                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14947 @@ -153,22 +158,26 @@ static struct inode *mqueue_get_inode(st
14948                         spin_lock(&mq_lock);
14949                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14950                             u->mq_bytes + mq_bytes >
14951 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14952 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14953 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14954                                 spin_unlock(&mq_lock);
14955                                 goto out_inode;
14956                         }
14957                         u->mq_bytes += mq_bytes;
14958 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14959                         spin_unlock(&mq_lock);
14960  
14961                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14962                         if (!info->messages) {
14963                                 spin_lock(&mq_lock);
14964                                 u->mq_bytes -= mq_bytes;
14965 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14966                                 spin_unlock(&mq_lock);
14967                                 goto out_inode;
14968                         }
14969                         /* all is ok */
14970                         info->user = get_uid(u);
14971 +                       info->vxi = get_vx_info(vxi);
14972                 } else if (S_ISDIR(mode)) {
14973                         inc_nlink(inode);
14974                         /* Some things misbehave if size == 0 on a directory */
14975 @@ -269,8 +278,11 @@ static void mqueue_delete_inode(struct i
14976                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14977         user = info->user;
14978         if (user) {
14979 +               struct vx_info *vxi = info->vxi;
14980 +
14981                 spin_lock(&mq_lock);
14982                 user->mq_bytes -= mq_bytes;
14983 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14984                 /*
14985                  * get_ns_from_inode() ensures that the
14986                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14987 @@ -280,6 +292,7 @@ static void mqueue_delete_inode(struct i
14988                 if (ipc_ns)
14989                         ipc_ns->mq_queues_count--;
14990                 spin_unlock(&mq_lock);
14991 +               put_vx_info(vxi);
14992                 free_uid(user);
14993         }
14994         if (ipc_ns)
14995 diff -NurpP --minimal linux-2.6.32.24/ipc/msg.c linux-2.6.32.24-vs2.3.0.36.29.6/ipc/msg.c
14996 --- linux-2.6.32.24/ipc/msg.c   2010-10-04 08:56:17.000000000 +0200
14997 +++ linux-2.6.32.24-vs2.3.0.36.29.6/ipc/msg.c   2010-02-12 10:59:55.000000000 +0100
14998 @@ -38,6 +38,7 @@
14999  #include <linux/rwsem.h>
15000  #include <linux/nsproxy.h>
15001  #include <linux/ipc_namespace.h>
15002 +#include <linux/vs_base.h>
15003  
15004  #include <asm/current.h>
15005  #include <asm/uaccess.h>
15006 @@ -191,6 +192,7 @@ static int newque(struct ipc_namespace *
15007  
15008         msq->q_perm.mode = msgflg & S_IRWXUGO;
15009         msq->q_perm.key = key;
15010 +       msq->q_perm.xid = vx_current_xid();
15011  
15012         msq->q_perm.security = NULL;
15013         retval = security_msg_queue_alloc(msq);
15014 diff -NurpP --minimal linux-2.6.32.24/ipc/namespace.c linux-2.6.32.24-vs2.3.0.36.29.6/ipc/namespace.c
15015 --- linux-2.6.32.24/ipc/namespace.c     2009-09-10 15:26:27.000000000 +0200
15016 +++ linux-2.6.32.24-vs2.3.0.36.29.6/ipc/namespace.c     2009-12-03 20:04:56.000000000 +0100
15017 @@ -11,6 +11,8 @@
15018  #include <linux/slab.h>
15019  #include <linux/fs.h>
15020  #include <linux/mount.h>
15021 +#include <linux/vs_base.h>
15022 +#include <linux/vserver/global.h>
15023  
15024  #include "util.h"
15025  
15026 diff -NurpP --minimal linux-2.6.32.24/ipc/sem.c linux-2.6.32.24-vs2.3.0.36.29.6/ipc/sem.c
15027 --- linux-2.6.32.24/ipc/sem.c   2010-10-04 08:56:17.000000000 +0200
15028 +++ linux-2.6.32.24-vs2.3.0.36.29.6/ipc/sem.c   2010-02-12 10:59:55.000000000 +0100
15029 @@ -83,6 +83,8 @@
15030  #include <linux/rwsem.h>
15031  #include <linux/nsproxy.h>
15032  #include <linux/ipc_namespace.h>
15033 +#include <linux/vs_base.h>
15034 +#include <linux/vs_limit.h>
15035  
15036  #include <asm/uaccess.h>
15037  #include "util.h"
15038 @@ -256,6 +258,7 @@ static int newary(struct ipc_namespace *
15039  
15040         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15041         sma->sem_perm.key = key;
15042 +       sma->sem_perm.xid = vx_current_xid();
15043  
15044         sma->sem_perm.security = NULL;
15045         retval = security_sem_alloc(sma);
15046 @@ -271,6 +274,9 @@ static int newary(struct ipc_namespace *
15047                 return id;
15048         }
15049         ns->used_sems += nsems;
15050 +       /* FIXME: obsoleted? */
15051 +       vx_semary_inc(sma);
15052 +       vx_nsems_add(sma, nsems);
15053  
15054         sma->sem_base = (struct sem *) &sma[1];
15055         INIT_LIST_HEAD(&sma->sem_pending);
15056 @@ -547,6 +553,9 @@ static void freeary(struct ipc_namespace
15057         sem_unlock(sma);
15058  
15059         ns->used_sems -= sma->sem_nsems;
15060 +       /* FIXME: obsoleted? */
15061 +       vx_nsems_sub(sma, sma->sem_nsems);
15062 +       vx_semary_dec(sma);
15063         security_sem_free(sma);
15064         ipc_rcu_putref(sma);
15065  }
15066 diff -NurpP --minimal linux-2.6.32.24/ipc/shm.c linux-2.6.32.24-vs2.3.0.36.29.6/ipc/shm.c
15067 --- linux-2.6.32.24/ipc/shm.c   2010-10-04 08:56:17.000000000 +0200
15068 +++ linux-2.6.32.24-vs2.3.0.36.29.6/ipc/shm.c   2010-02-12 10:59:55.000000000 +0100
15069 @@ -40,6 +40,8 @@
15070  #include <linux/mount.h>
15071  #include <linux/ipc_namespace.h>
15072  #include <linux/ima.h>
15073 +#include <linux/vs_context.h>
15074 +#include <linux/vs_limit.h>
15075  
15076  #include <asm/uaccess.h>
15077  
15078 @@ -170,7 +172,12 @@ static void shm_open(struct vm_area_stru
15079   */
15080  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15081  {
15082 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15083 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15084 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15085 +
15086 +       vx_ipcshm_sub(vxi, shp, numpages);
15087 +       ns->shm_tot -= numpages;
15088 +
15089         shm_rmid(ns, shp);
15090         shm_unlock(shp);
15091         if (!is_file_hugepages(shp->shm_file))
15092 @@ -180,6 +187,7 @@ static void shm_destroy(struct ipc_names
15093                                                 shp->mlock_user);
15094         fput (shp->shm_file);
15095         security_shm_free(shp);
15096 +       put_vx_info(vxi);
15097         ipc_rcu_putref(shp);
15098  }
15099  
15100 @@ -350,11 +358,15 @@ static int newseg(struct ipc_namespace *
15101         if (ns->shm_tot + numpages > ns->shm_ctlall)
15102                 return -ENOSPC;
15103  
15104 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
15105 +               return -ENOSPC;
15106 +
15107         shp = ipc_rcu_alloc(sizeof(*shp));
15108         if (!shp)
15109                 return -ENOMEM;
15110  
15111         shp->shm_perm.key = key;
15112 +       shp->shm_perm.xid = vx_current_xid();
15113         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15114         shp->mlock_user = NULL;
15115  
15116 @@ -408,6 +420,7 @@ static int newseg(struct ipc_namespace *
15117         ns->shm_tot += numpages;
15118         error = shp->shm_perm.id;
15119         shm_unlock(shp);
15120 +       vx_ipcshm_add(current_vx_info(), key, numpages);
15121         return error;
15122  
15123  no_id:
15124 diff -NurpP --minimal linux-2.6.32.24/kernel/capability.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/capability.c
15125 --- linux-2.6.32.24/kernel/capability.c 2009-03-24 14:22:44.000000000 +0100
15126 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/capability.c 2009-12-03 20:04:56.000000000 +0100
15127 @@ -14,6 +14,7 @@
15128  #include <linux/security.h>
15129  #include <linux/syscalls.h>
15130  #include <linux/pid_namespace.h>
15131 +#include <linux/vs_context.h>
15132  #include <asm/uaccess.h>
15133  #include "cred-internals.h"
15134  
15135 @@ -122,6 +123,7 @@ static int cap_validate_magic(cap_user_h
15136         return 0;
15137  }
15138  
15139 +
15140  /*
15141   * The only thing that can change the capabilities of the current
15142   * process is the current process. As such, we can't be in this code
15143 @@ -289,6 +291,8 @@ error:
15144         return ret;
15145  }
15146  
15147 +#include <linux/vserver/base.h>
15148 +
15149  /**
15150   * capable - Determine if the current task has a superior capability in effect
15151   * @cap: The capability to be tested for
15152 @@ -301,6 +305,9 @@ error:
15153   */
15154  int capable(int cap)
15155  {
15156 +       /* here for now so we don't require task locking */
15157 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15158 +               return 0;
15159         if (unlikely(!cap_valid(cap))) {
15160                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15161                 BUG();
15162 diff -NurpP --minimal linux-2.6.32.24/kernel/compat.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/compat.c
15163 --- linux-2.6.32.24/kernel/compat.c     2010-10-04 08:56:18.000000000 +0200
15164 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/compat.c     2010-09-22 00:48:38.000000000 +0200
15165 @@ -900,7 +900,7 @@ asmlinkage long compat_sys_time(compat_t
15166         compat_time_t i;
15167         struct timeval tv;
15168  
15169 -       do_gettimeofday(&tv);
15170 +       vx_gettimeofday(&tv);
15171         i = tv.tv_sec;
15172  
15173         if (tloc) {
15174 @@ -925,7 +925,7 @@ asmlinkage long compat_sys_stime(compat_
15175         if (err)
15176                 return err;
15177  
15178 -       do_settimeofday(&tv);
15179 +       vx_settimeofday(&tv);
15180         return 0;
15181  }
15182  
15183 diff -NurpP --minimal linux-2.6.32.24/kernel/exit.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/exit.c
15184 --- linux-2.6.32.24/kernel/exit.c       2010-10-04 08:56:18.000000000 +0200
15185 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/exit.c       2010-10-04 10:04:57.000000000 +0200
15186 @@ -48,6 +48,10 @@
15187  #include <linux/fs_struct.h>
15188  #include <linux/init_task.h>
15189  #include <linux/perf_event.h>
15190 +#include <linux/vs_limit.h>
15191 +#include <linux/vs_context.h>
15192 +#include <linux/vs_network.h>
15193 +#include <linux/vs_pid.h>
15194  #include <trace/events/sched.h>
15195  
15196  #include <asm/uaccess.h>
15197 @@ -488,9 +492,11 @@ static void close_files(struct files_str
15198                                         filp_close(file, files);
15199                                         cond_resched();
15200                                 }
15201 +                               vx_openfd_dec(i);
15202                         }
15203                         i++;
15204                         set >>= 1;
15205 +                       cond_resched();
15206                 }
15207         }
15208  }
15209 @@ -1011,11 +1017,16 @@ NORET_TYPE void do_exit(long code)
15210  
15211         validate_creds_for_do_exit(tsk);
15212  
15213 +       /* needs to stay after exit_notify() */
15214 +       exit_vx_info(tsk, code);
15215 +       exit_nx_info(tsk);
15216 +
15217         preempt_disable();
15218         exit_rcu();
15219         /* causes final put_task_struct in finish_task_switch(). */
15220         tsk->state = TASK_DEAD;
15221         schedule();
15222 +       printk("bad task: %p [%lx]\n", current, current->state);
15223         BUG();
15224         /* Avoid "noreturn function does return".  */
15225         for (;;)
15226 diff -NurpP --minimal linux-2.6.32.24/kernel/fork.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/fork.c
15227 --- linux-2.6.32.24/kernel/fork.c       2010-10-04 08:56:18.000000000 +0200
15228 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/fork.c       2010-09-22 00:48:38.000000000 +0200
15229 @@ -64,6 +64,10 @@
15230  #include <linux/magic.h>
15231  #include <linux/perf_event.h>
15232  #include <linux/posix-timers.h>
15233 +#include <linux/vs_context.h>
15234 +#include <linux/vs_network.h>
15235 +#include <linux/vs_limit.h>
15236 +#include <linux/vs_memory.h>
15237  
15238  #include <asm/pgtable.h>
15239  #include <asm/pgalloc.h>
15240 @@ -151,6 +155,8 @@ void free_task(struct task_struct *tsk)
15241         account_kernel_stack(tsk->stack, -1);
15242         free_thread_info(tsk->stack);
15243         rt_mutex_debug_task_free(tsk);
15244 +       clr_vx_info(&tsk->vx_info);
15245 +       clr_nx_info(&tsk->nx_info);
15246         ftrace_graph_exit_task(tsk);
15247         free_task_struct(tsk);
15248  }
15249 @@ -296,6 +302,8 @@ static int dup_mmap(struct mm_struct *mm
15250         mm->free_area_cache = oldmm->mmap_base;
15251         mm->cached_hole_size = ~0UL;
15252         mm->map_count = 0;
15253 +       __set_mm_counter(mm, file_rss, 0);
15254 +       __set_mm_counter(mm, anon_rss, 0);
15255         cpumask_clear(mm_cpumask(mm));
15256         mm->mm_rb = RB_ROOT;
15257         rb_link = &mm->mm_rb.rb_node;
15258 @@ -311,7 +319,7 @@ static int dup_mmap(struct mm_struct *mm
15259  
15260                 if (mpnt->vm_flags & VM_DONTCOPY) {
15261                         long pages = vma_pages(mpnt);
15262 -                       mm->total_vm -= pages;
15263 +                       vx_vmpages_sub(mm, pages);
15264                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15265                                                                 -pages);
15266                         continue;
15267 @@ -455,8 +463,8 @@ static struct mm_struct * mm_init(struct
15268                 (current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
15269         mm->core_state = NULL;
15270         mm->nr_ptes = 0;
15271 -       set_mm_counter(mm, file_rss, 0);
15272 -       set_mm_counter(mm, anon_rss, 0);
15273 +       __set_mm_counter(mm, file_rss, 0);
15274 +       __set_mm_counter(mm, anon_rss, 0);
15275         spin_lock_init(&mm->page_table_lock);
15276         mm->free_area_cache = TASK_UNMAPPED_BASE;
15277         mm->cached_hole_size = ~0UL;
15278 @@ -466,6 +474,7 @@ static struct mm_struct * mm_init(struct
15279         if (likely(!mm_alloc_pgd(mm))) {
15280                 mm->def_flags = 0;
15281                 mmu_notifier_mm_init(mm);
15282 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15283                 return mm;
15284         }
15285  
15286 @@ -499,6 +508,7 @@ void __mmdrop(struct mm_struct *mm)
15287         mm_free_pgd(mm);
15288         destroy_context(mm);
15289         mmu_notifier_mm_destroy(mm);
15290 +       clr_vx_info(&mm->mm_vx_info);
15291         free_mm(mm);
15292  }
15293  EXPORT_SYMBOL_GPL(__mmdrop);
15294 @@ -634,6 +644,7 @@ struct mm_struct *dup_mm(struct task_str
15295                 goto fail_nomem;
15296  
15297         memcpy(mm, oldmm, sizeof(*mm));
15298 +       mm->mm_vx_info = NULL;
15299  
15300         /* Initializing for Swap token stuff */
15301         mm->token_priority = 0;
15302 @@ -672,6 +683,7 @@ fail_nocontext:
15303          * If init_new_context() failed, we cannot use mmput() to free the mm
15304          * because it calls destroy_context()
15305          */
15306 +       clr_vx_info(&mm->mm_vx_info);
15307         mm_free_pgd(mm);
15308         free_mm(mm);
15309         return NULL;
15310 @@ -986,6 +998,8 @@ static struct task_struct *copy_process(
15311         int retval;
15312         struct task_struct *p;
15313         int cgroup_callbacks_done = 0;
15314 +       struct vx_info *vxi;
15315 +       struct nx_info *nxi;
15316  
15317         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15318                 return ERR_PTR(-EINVAL);
15319 @@ -1032,12 +1046,28 @@ static struct task_struct *copy_process(
15320         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15321         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15322  #endif
15323 +       init_vx_info(&p->vx_info, current_vx_info());
15324 +       init_nx_info(&p->nx_info, current_nx_info());
15325 +
15326 +       /* check vserver memory */
15327 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15328 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15329 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15330 +               else
15331 +                       goto bad_fork_free;
15332 +       }
15333 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15334 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15335 +                       goto bad_fork_cleanup_vm;
15336 +       }
15337         retval = -EAGAIN;
15338 +       if (!vx_nproc_avail(1))
15339 +               goto bad_fork_cleanup_vm;
15340         if (atomic_read(&p->real_cred->user->processes) >=
15341                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15342                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15343                     p->real_cred->user != INIT_USER)
15344 -                       goto bad_fork_free;
15345 +                       goto bad_fork_cleanup_vm;
15346         }
15347  
15348         retval = copy_creds(p, clone_flags);
15349 @@ -1289,6 +1319,18 @@ static struct task_struct *copy_process(
15350  
15351         total_forks++;
15352         spin_unlock(&current->sighand->siglock);
15353 +
15354 +       /* p is copy of current */
15355 +       vxi = p->vx_info;
15356 +       if (vxi) {
15357 +               claim_vx_info(vxi, p);
15358 +               atomic_inc(&vxi->cvirt.nr_threads);
15359 +               atomic_inc(&vxi->cvirt.total_forks);
15360 +               vx_nproc_inc(p);
15361 +       }
15362 +       nxi = p->nx_info;
15363 +       if (nxi)
15364 +               claim_nx_info(nxi, p);
15365         write_unlock_irq(&tasklist_lock);
15366         proc_fork_connector(p);
15367         cgroup_post_fork(p);
15368 @@ -1330,6 +1372,9 @@ bad_fork_cleanup_cgroup:
15369  bad_fork_cleanup_count:
15370         atomic_dec(&p->cred->user->processes);
15371         exit_creds(p);
15372 +bad_fork_cleanup_vm:
15373 +       if (p->mm && !(clone_flags & CLONE_VM))
15374 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15375  bad_fork_free:
15376         free_task(p);
15377  fork_out:
15378 diff -NurpP --minimal linux-2.6.32.24/kernel/kthread.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/kthread.c
15379 --- linux-2.6.32.24/kernel/kthread.c    2010-10-04 08:56:18.000000000 +0200
15380 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/kthread.c    2010-04-05 20:56:22.000000000 +0200
15381 @@ -14,6 +14,7 @@
15382  #include <linux/file.h>
15383  #include <linux/module.h>
15384  #include <linux/mutex.h>
15385 +#include <linux/vs_pid.h>
15386  #include <trace/events/sched.h>
15387  
15388  static DEFINE_SPINLOCK(kthread_create_lock);
15389 diff -NurpP --minimal linux-2.6.32.24/kernel/Makefile linux-2.6.32.24-vs2.3.0.36.29.6/kernel/Makefile
15390 --- linux-2.6.32.24/kernel/Makefile     2009-12-03 20:02:57.000000000 +0100
15391 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/Makefile     2009-12-03 20:04:56.000000000 +0100
15392 @@ -23,6 +23,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
15393  CFLAGS_REMOVE_sched_clock.o = -pg
15394  endif
15395  
15396 +obj-y += vserver/
15397  obj-$(CONFIG_FREEZER) += freezer.o
15398  obj-$(CONFIG_PROFILING) += profile.o
15399  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15400 diff -NurpP --minimal linux-2.6.32.24/kernel/nsproxy.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/nsproxy.c
15401 --- linux-2.6.32.24/kernel/nsproxy.c    2009-09-10 15:26:28.000000000 +0200
15402 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/nsproxy.c    2009-12-03 20:04:56.000000000 +0100
15403 @@ -19,6 +19,8 @@
15404  #include <linux/mnt_namespace.h>
15405  #include <linux/utsname.h>
15406  #include <linux/pid_namespace.h>
15407 +#include <linux/vserver/global.h>
15408 +#include <linux/vserver/debug.h>
15409  #include <net/net_namespace.h>
15410  #include <linux/ipc_namespace.h>
15411  
15412 @@ -31,8 +33,11 @@ static inline struct nsproxy *create_nsp
15413         struct nsproxy *nsproxy;
15414  
15415         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15416 -       if (nsproxy)
15417 +       if (nsproxy) {
15418                 atomic_set(&nsproxy->count, 1);
15419 +               atomic_inc(&vs_global_nsproxy);
15420 +       }
15421 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15422         return nsproxy;
15423  }
15424  
15425 @@ -41,41 +46,52 @@ static inline struct nsproxy *create_nsp
15426   * Return the newly created nsproxy.  Do not attach this to the task,
15427   * leave it to the caller to do proper locking and attach it to task.
15428   */
15429 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15430 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15431 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15432 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15433  {
15434         struct nsproxy *new_nsp;
15435         int err;
15436  
15437 +       vxdprintk(VXD_CBIT(space, 4),
15438 +               "unshare_namespaces(0x%08lx,%p,%p)",
15439 +               flags, orig, new_fs);
15440 +
15441         new_nsp = create_nsproxy();
15442         if (!new_nsp)
15443                 return ERR_PTR(-ENOMEM);
15444  
15445 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15446 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15447         if (IS_ERR(new_nsp->mnt_ns)) {
15448                 err = PTR_ERR(new_nsp->mnt_ns);
15449                 goto out_ns;
15450         }
15451  
15452 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15453 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15454         if (IS_ERR(new_nsp->uts_ns)) {
15455                 err = PTR_ERR(new_nsp->uts_ns);
15456                 goto out_uts;
15457         }
15458  
15459 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15460 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15461         if (IS_ERR(new_nsp->ipc_ns)) {
15462                 err = PTR_ERR(new_nsp->ipc_ns);
15463                 goto out_ipc;
15464         }
15465  
15466 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15467 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15468         if (IS_ERR(new_nsp->pid_ns)) {
15469                 err = PTR_ERR(new_nsp->pid_ns);
15470                 goto out_pid;
15471         }
15472  
15473 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15474 +       /* disabled now?
15475 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15476 +       if (IS_ERR(new_nsp->user_ns)) {
15477 +               err = PTR_ERR(new_nsp->user_ns);
15478 +               goto out_user;
15479 +       } */
15480 +
15481 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15482         if (IS_ERR(new_nsp->net_ns)) {
15483                 err = PTR_ERR(new_nsp->net_ns);
15484                 goto out_net;
15485 @@ -100,6 +116,38 @@ out_ns:
15486         return ERR_PTR(err);
15487  }
15488  
15489 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15490 +                       struct fs_struct *new_fs)
15491 +{
15492 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15493 +}
15494 +
15495 +/*
15496 + * copies the nsproxy, setting refcount to 1, and grabbing a
15497 + * reference to all contained namespaces.
15498 + */
15499 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15500 +{
15501 +       struct nsproxy *ns = create_nsproxy();
15502 +
15503 +       if (ns) {
15504 +               memcpy(ns, orig, sizeof(struct nsproxy));
15505 +               atomic_set(&ns->count, 1);
15506 +
15507 +               if (ns->mnt_ns)
15508 +                       get_mnt_ns(ns->mnt_ns);
15509 +               if (ns->uts_ns)
15510 +                       get_uts_ns(ns->uts_ns);
15511 +               if (ns->ipc_ns)
15512 +                       get_ipc_ns(ns->ipc_ns);
15513 +               if (ns->pid_ns)
15514 +                       get_pid_ns(ns->pid_ns);
15515 +               if (ns->net_ns)
15516 +                       get_net(ns->net_ns);
15517 +       }
15518 +       return ns;
15519 +}
15520 +
15521  /*
15522   * called from clone.  This now handles copy for nsproxy and all
15523   * namespaces therein.
15524 @@ -107,9 +155,12 @@ out_ns:
15525  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15526  {
15527         struct nsproxy *old_ns = tsk->nsproxy;
15528 -       struct nsproxy *new_ns;
15529 +       struct nsproxy *new_ns = NULL;
15530         int err = 0;
15531  
15532 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15533 +               flags, tsk, old_ns);
15534 +
15535         if (!old_ns)
15536                 return 0;
15537  
15538 @@ -119,7 +170,7 @@ int copy_namespaces(unsigned long flags,
15539                                 CLONE_NEWPID | CLONE_NEWNET)))
15540                 return 0;
15541  
15542 -       if (!capable(CAP_SYS_ADMIN)) {
15543 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15544                 err = -EPERM;
15545                 goto out;
15546         }
15547 @@ -146,6 +197,9 @@ int copy_namespaces(unsigned long flags,
15548  
15549  out:
15550         put_nsproxy(old_ns);
15551 +       vxdprintk(VXD_CBIT(space, 3),
15552 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15553 +               flags, tsk, old_ns, err, new_ns);
15554         return err;
15555  }
15556  
15557 @@ -159,7 +213,9 @@ void free_nsproxy(struct nsproxy *ns)
15558                 put_ipc_ns(ns->ipc_ns);
15559         if (ns->pid_ns)
15560                 put_pid_ns(ns->pid_ns);
15561 -       put_net(ns->net_ns);
15562 +       if (ns->net_ns)
15563 +               put_net(ns->net_ns);
15564 +       atomic_dec(&vs_global_nsproxy);
15565         kmem_cache_free(nsproxy_cachep, ns);
15566  }
15567  
15568 @@ -172,11 +228,15 @@ int unshare_nsproxy_namespaces(unsigned 
15569  {
15570         int err = 0;
15571  
15572 +       vxdprintk(VXD_CBIT(space, 4),
15573 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15574 +               unshare_flags, current->nsproxy);
15575 +
15576         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15577                                CLONE_NEWNET)))
15578                 return 0;
15579  
15580 -       if (!capable(CAP_SYS_ADMIN))
15581 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15582                 return -EPERM;
15583  
15584         *new_nsp = create_new_namespaces(unshare_flags, current,
15585 diff -NurpP --minimal linux-2.6.32.24/kernel/pid.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/pid.c
15586 --- linux-2.6.32.24/kernel/pid.c        2009-12-03 20:02:58.000000000 +0100
15587 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/pid.c        2009-12-03 20:04:56.000000000 +0100
15588 @@ -36,6 +36,7 @@
15589  #include <linux/pid_namespace.h>
15590  #include <linux/init_task.h>
15591  #include <linux/syscalls.h>
15592 +#include <linux/vs_pid.h>
15593  
15594  #define pid_hashfn(nr, ns)     \
15595         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15596 @@ -305,7 +306,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15597  
15598  struct pid *find_vpid(int nr)
15599  {
15600 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15601 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15602  }
15603  EXPORT_SYMBOL_GPL(find_vpid);
15604  
15605 @@ -365,6 +366,9 @@ void transfer_pid(struct task_struct *ol
15606  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15607  {
15608         struct task_struct *result = NULL;
15609 +
15610 +       if (type == PIDTYPE_REALPID)
15611 +               type = PIDTYPE_PID;
15612         if (pid) {
15613                 struct hlist_node *first;
15614                 first = rcu_dereference(pid->tasks[type].first);
15615 @@ -380,7 +384,7 @@ EXPORT_SYMBOL(pid_task);
15616   */
15617  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15618  {
15619 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15620 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15621  }
15622  
15623  struct task_struct *find_task_by_vpid(pid_t vnr)
15624 @@ -422,7 +426,7 @@ struct pid *find_get_pid(pid_t nr)
15625  }
15626  EXPORT_SYMBOL_GPL(find_get_pid);
15627  
15628 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15629 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15630  {
15631         struct upid *upid;
15632         pid_t nr = 0;
15633 @@ -435,6 +439,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15634         return nr;
15635  }
15636  
15637 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15638 +{
15639 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15640 +}
15641 +
15642  pid_t pid_vnr(struct pid *pid)
15643  {
15644         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15645 diff -NurpP --minimal linux-2.6.32.24/kernel/pid_namespace.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/pid_namespace.c
15646 --- linux-2.6.32.24/kernel/pid_namespace.c      2009-12-03 20:02:58.000000000 +0100
15647 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/pid_namespace.c      2009-12-03 20:04:56.000000000 +0100
15648 @@ -13,6 +13,7 @@
15649  #include <linux/syscalls.h>
15650  #include <linux/err.h>
15651  #include <linux/acct.h>
15652 +#include <linux/vserver/global.h>
15653  
15654  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15655  
15656 @@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_
15657                 goto out_free_map;
15658  
15659         kref_init(&ns->kref);
15660 +       atomic_inc(&vs_global_pid_ns);
15661         ns->level = level;
15662         ns->parent = get_pid_ns(parent_pid_ns);
15663  
15664 @@ -111,6 +113,7 @@ static void destroy_pid_namespace(struct
15665  
15666         for (i = 0; i < PIDMAP_ENTRIES; i++)
15667                 kfree(ns->pidmap[i].page);
15668 +       atomic_dec(&vs_global_pid_ns);
15669         kmem_cache_free(pid_ns_cachep, ns);
15670  }
15671  
15672 diff -NurpP --minimal linux-2.6.32.24/kernel/posix-timers.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/posix-timers.c
15673 --- linux-2.6.32.24/kernel/posix-timers.c       2010-10-04 08:56:18.000000000 +0200
15674 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/posix-timers.c       2010-07-08 02:22:31.000000000 +0200
15675 @@ -46,6 +46,7 @@
15676  #include <linux/wait.h>
15677  #include <linux/workqueue.h>
15678  #include <linux/module.h>
15679 +#include <linux/vs_context.h>
15680  
15681  /*
15682   * Management arrays for POSIX timers.  Timers are kept in slab memory
15683 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15684  {
15685         struct task_struct *task;
15686         int shared, ret = -1;
15687 +
15688         /*
15689          * FIXME: if ->sigq is queued we can race with
15690          * dequeue_signal()->do_schedule_next_timer().
15691 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15692         rcu_read_lock();
15693         task = pid_task(timr->it_pid, PIDTYPE_PID);
15694         if (task) {
15695 +               struct vx_info_save vxis;
15696 +               struct vx_info *vxi;
15697 +
15698 +               vxi = get_vx_info(task->vx_info);
15699 +               enter_vx_info(vxi, &vxis);
15700                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15701                 ret = send_sigqueue(timr->sigq, task, shared);
15702 +               leave_vx_info(&vxis);
15703 +               put_vx_info(vxi);
15704         }
15705         rcu_read_unlock();
15706 +
15707         /* If we failed to send the signal the timer stops. */
15708         return ret > 0;
15709  }
15710 diff -NurpP --minimal linux-2.6.32.24/kernel/printk.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/printk.c
15711 --- linux-2.6.32.24/kernel/printk.c     2009-12-03 20:02:58.000000000 +0100
15712 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/printk.c     2009-12-03 20:04:56.000000000 +0100
15713 @@ -33,6 +33,7 @@
15714  #include <linux/bootmem.h>
15715  #include <linux/syscalls.h>
15716  #include <linux/kexec.h>
15717 +#include <linux/vs_cvirt.h>
15718  
15719  #include <asm/uaccess.h>
15720  
15721 @@ -276,18 +277,13 @@ int do_syslog(int type, char __user *buf
15722         unsigned i, j, limit, count;
15723         int do_clear = 0;
15724         char c;
15725 -       int error = 0;
15726 +       int error;
15727  
15728         error = security_syslog(type);
15729         if (error)
15730                 return error;
15731  
15732 -       switch (type) {
15733 -       case 0:         /* Close log */
15734 -               break;
15735 -       case 1:         /* Open log */
15736 -               break;
15737 -       case 2:         /* Read from log */
15738 +       if ((type >= 2) && (type <= 4)) {
15739                 error = -EINVAL;
15740                 if (!buf || len < 0)
15741                         goto out;
15742 @@ -298,6 +294,16 @@ int do_syslog(int type, char __user *buf
15743                         error = -EFAULT;
15744                         goto out;
15745                 }
15746 +       }
15747 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15748 +               return vx_do_syslog(type, buf, len);
15749 +
15750 +       switch (type) {
15751 +       case 0:         /* Close log */
15752 +               break;
15753 +       case 1:         /* Open log */
15754 +               break;
15755 +       case 2:         /* Read from log */
15756                 error = wait_event_interruptible(log_wait,
15757                                                         (log_start - log_end));
15758                 if (error)
15759 @@ -322,16 +328,6 @@ int do_syslog(int type, char __user *buf
15760                 do_clear = 1;
15761                 /* FALL THRU */
15762         case 3:         /* Read last kernel messages */
15763 -               error = -EINVAL;
15764 -               if (!buf || len < 0)
15765 -                       goto out;
15766 -               error = 0;
15767 -               if (!len)
15768 -                       goto out;
15769 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15770 -                       error = -EFAULT;
15771 -                       goto out;
15772 -               }
15773                 count = len;
15774                 if (count > log_buf_len)
15775                         count = log_buf_len;
15776 diff -NurpP --minimal linux-2.6.32.24/kernel/ptrace.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/ptrace.c
15777 --- linux-2.6.32.24/kernel/ptrace.c     2009-12-03 20:02:58.000000000 +0100
15778 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/ptrace.c     2009-12-03 20:04:56.000000000 +0100
15779 @@ -22,6 +22,7 @@
15780  #include <linux/pid_namespace.h>
15781  #include <linux/syscalls.h>
15782  #include <linux/uaccess.h>
15783 +#include <linux/vs_context.h>
15784  
15785  
15786  /*
15787 @@ -151,6 +152,11 @@ int __ptrace_may_access(struct task_stru
15788                 dumpable = get_dumpable(task->mm);
15789         if (!dumpable && !capable(CAP_SYS_PTRACE))
15790                 return -EPERM;
15791 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15792 +               return -EPERM;
15793 +       if (!vx_check(task->xid, VS_IDENT) &&
15794 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15795 +               return -EACCES;
15796  
15797         return security_ptrace_access_check(task, mode);
15798  }
15799 @@ -621,6 +627,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15800                 goto out;
15801         }
15802  
15803 +       ret = -EPERM;
15804 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15805 +               goto out_put_task_struct;
15806 +
15807         if (request == PTRACE_ATTACH) {
15808                 ret = ptrace_attach(child);
15809                 /*
15810 diff -NurpP --minimal linux-2.6.32.24/kernel/sched.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sched.c
15811 --- linux-2.6.32.24/kernel/sched.c      2010-10-04 08:56:18.000000000 +0200
15812 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sched.c      2010-10-04 10:04:57.000000000 +0200
15813 @@ -71,6 +71,8 @@
15814  #include <linux/debugfs.h>
15815  #include <linux/ctype.h>
15816  #include <linux/ftrace.h>
15817 +#include <linux/vs_sched.h>
15818 +#include <linux/vs_cvirt.h>
15819  
15820  #include <asm/tlb.h>
15821  #include <asm/irq_regs.h>
15822 @@ -237,6 +239,15 @@ static DEFINE_MUTEX(sched_domains_mutex)
15823  
15824  #include <linux/cgroup.h>
15825  
15826 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
15827 +struct cfs_bandwidth {
15828 +       spinlock_t              cfs_runtime_lock;
15829 +       ktime_t                 cfs_period;
15830 +       u64                     cfs_runtime;
15831 +       struct hrtimer          cfs_period_timer;
15832 +};
15833 +#endif
15834 +
15835  struct cfs_rq;
15836  
15837  static LIST_HEAD(task_groups);
15838 @@ -257,6 +268,9 @@ struct task_group {
15839         /* runqueue "owned" by this group on each cpu */
15840         struct cfs_rq **cfs_rq;
15841         unsigned long shares;
15842 +#ifdef CONFIG_CFS_HARD_LIMITS
15843 +       struct cfs_bandwidth cfs_bandwidth;
15844 +#endif
15845  #endif
15846  
15847  #ifdef CONFIG_RT_GROUP_SCHED
15848 @@ -446,6 +460,19 @@ struct cfs_rq {
15849         unsigned long rq_weight;
15850  #endif
15851  #endif
15852 +#ifdef CONFIG_CFS_HARD_LIMITS
15853 +       /* set when the group is throttled  on this cpu */
15854 +       int cfs_throttled;
15855 +
15856 +       /* runtime currently consumed by the group on this rq */
15857 +       u64 cfs_time;
15858 +
15859 +       /* runtime available to the group on this rq */
15860 +       u64 cfs_runtime;
15861 +
15862 +       /* Protects the cfs runtime related fields of this cfs_rq */
15863 +       spinlock_t cfs_runtime_lock;
15864 +#endif
15865  };
15866  
15867  /* Real-Time classes' related field in a runqueue: */
15868 @@ -1626,6 +1653,7 @@ static void update_group_shares_cpu(stru
15869         }
15870  }
15871  
15872 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq);
15873  /*
15874   * Re-compute the task group their per cpu shares over the given domain.
15875   * This needs to be done in a bottom-up fashion because the rq weight of a
15876 @@ -1654,8 +1682,10 @@ static int tg_shares_up(struct task_grou
15877                  * If there are currently no tasks on the cpu pretend there
15878                  * is one of average load so that when a new task gets to
15879                  * run here it will not get delayed by group starvation.
15880 +                * Also if the group is throttled on this cpu, pretend that
15881 +                * it has no tasks.
15882                  */
15883 -               if (!weight)
15884 +               if (!weight || cfs_rq_throttled(tg->cfs_rq[i]))
15885                         weight = NICE_0_LOAD;
15886  
15887                 sum_weight += weight;
15888 @@ -1832,6 +1862,175 @@ static void cfs_rq_set_shares(struct cfs
15889  static void calc_load_account_active(struct rq *this_rq);
15890  static void update_sysctl(void);
15891  
15892 +
15893 +#if defined(CONFIG_RT_GROUP_SCHED) || defined(CONFIG_FAIR_GROUP_SCHED)
15894 +
15895 +#ifdef CONFIG_SMP
15896 +static inline const struct cpumask *sched_bw_period_mask(void)
15897 +{
15898 +       return cpu_rq(smp_processor_id())->rd->span;
15899 +}
15900 +#else /* !CONFIG_SMP */
15901 +static inline const struct cpumask *sched_bw_period_mask(void)
15902 +{
15903 +       return cpu_online_mask;
15904 +}
15905 +#endif /* CONFIG_SMP */
15906 +
15907 +#else
15908 +static inline const struct cpumask *sched_bw_period_mask(void)
15909 +{
15910 +       return cpu_online_mask;
15911 +}
15912 +
15913 +#endif
15914 +
15915 +#ifdef CONFIG_FAIR_GROUP_SCHED
15916 +#ifdef CONFIG_CFS_HARD_LIMITS
15917 +
15918 +/*
15919 + * Runtime allowed for a cfs group before it is hard limited.
15920 + * default: Infinite which means no hard limiting.
15921 + */
15922 +u64 sched_cfs_runtime = RUNTIME_INF;
15923 +
15924 +/*
15925 + * period over which we hard limit the cfs group's bandwidth.
15926 + * default: 0.5s
15927 + */
15928 +u64 sched_cfs_period = 500000;
15929 +
15930 +static inline u64 global_cfs_period(void)
15931 +{
15932 +       return sched_cfs_period * NSEC_PER_USEC;
15933 +}
15934 +
15935 +static inline u64 global_cfs_runtime(void)
15936 +{
15937 +       return RUNTIME_INF;
15938 +}
15939 +
15940 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b);
15941 +
15942 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15943 +{
15944 +       spin_lock(&cfs_rq->cfs_runtime_lock);
15945 +}
15946 +
15947 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15948 +{
15949 +       spin_unlock(&cfs_rq->cfs_runtime_lock);
15950 +}
15951 +
15952 +/*
15953 + * Refresh the runtimes of the throttled groups.
15954 + * But nothing much to do now, will populate this in later patches.
15955 + */
15956 +static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer)
15957 +{
15958 +       struct cfs_bandwidth *cfs_b =
15959 +               container_of(timer, struct cfs_bandwidth, cfs_period_timer);
15960 +
15961 +       do_sched_cfs_period_timer(cfs_b);
15962 +       hrtimer_add_expires_ns(timer, ktime_to_ns(cfs_b->cfs_period));
15963 +       return HRTIMER_RESTART;
15964 +}
15965 +
15966 +/*
15967 + * TODO: Check if this kind of timer setup is sufficient for cfs or
15968 + * should we do what rt is doing.
15969 + */
15970 +static void start_cfs_bandwidth(struct task_group *tg)
15971 +{
15972 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15973 +
15974 +       /*
15975 +        * Timer isn't setup for groups with infinite runtime
15976 +        */
15977 +       if (cfs_b->cfs_runtime == RUNTIME_INF)
15978 +               return;
15979 +
15980 +       if (hrtimer_active(&cfs_b->cfs_period_timer))
15981 +               return;
15982 +
15983 +       hrtimer_start_range_ns(&cfs_b->cfs_period_timer, cfs_b->cfs_period,
15984 +                       0, HRTIMER_MODE_REL);
15985 +}
15986 +
15987 +static void init_cfs_bandwidth(struct task_group *tg)
15988 +{
15989 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15990 +
15991 +       cfs_b->cfs_period = ns_to_ktime(global_cfs_period());
15992 +       cfs_b->cfs_runtime = global_cfs_runtime();
15993 +
15994 +       spin_lock_init(&cfs_b->cfs_runtime_lock);
15995 +
15996 +       hrtimer_init(&cfs_b->cfs_period_timer,
15997 +                       CLOCK_MONOTONIC, HRTIMER_MODE_REL);
15998 +       cfs_b->cfs_period_timer.function = &sched_cfs_period_timer;
15999 +}
16000 +
16001 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
16002 +{
16003 +       hrtimer_cancel(&tg->cfs_bandwidth.cfs_period_timer);
16004 +}
16005 +
16006 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
16007 +{
16008 +       cfs_rq->cfs_time = 0;
16009 +       cfs_rq->cfs_throttled = 0;
16010 +       cfs_rq->cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
16011 +       spin_lock_init(&cfs_rq->cfs_runtime_lock);
16012 +}
16013 +
16014 +#else /* !CONFIG_CFS_HARD_LIMITS */
16015 +
16016 +static void init_cfs_bandwidth(struct task_group *tg)
16017 +{
16018 +       return;
16019 +}
16020 +
16021 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
16022 +{
16023 +       return;
16024 +}
16025 +
16026 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
16027 +{
16028 +       return;
16029 +}
16030 +
16031 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
16032 +{
16033 +       return;
16034 +}
16035 +
16036 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
16037 +{
16038 +       return;
16039 +}
16040 +
16041 +#endif /* CONFIG_CFS_HARD_LIMITS */
16042 +#else /* !CONFIG_FAIR_GROUP_SCHED */
16043 +
16044 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
16045 +{
16046 +       return;
16047 +}
16048 +
16049 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
16050 +{
16051 +       return;
16052 +}
16053 +
16054 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16055 +{
16056 +       return 0;
16057 +}
16058 +
16059 +#endif /* CONFIG_FAIR_GROUP_SCHED */
16060 +
16061  static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
16062  {
16063         set_task_rq(p, cpu);
16064 @@ -3060,9 +3259,17 @@ EXPORT_SYMBOL(avenrun);
16065   */
16066  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
16067  {
16068 -       loads[0] = (avenrun[0] + offset) << shift;
16069 -       loads[1] = (avenrun[1] + offset) << shift;
16070 -       loads[2] = (avenrun[2] + offset) << shift;
16071 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
16072 +               struct vx_info *vxi = current_vx_info();
16073 +
16074 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
16075 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
16076 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
16077 +       } else {
16078 +               loads[0] = (avenrun[0] + offset) << shift;
16079 +               loads[1] = (avenrun[1] + offset) << shift;
16080 +               loads[2] = (avenrun[2] + offset) << shift;
16081 +       }
16082  }
16083  
16084  static unsigned long
16085 @@ -5107,16 +5314,19 @@ void account_user_time(struct task_struc
16086                        cputime_t cputime_scaled)
16087  {
16088         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16089 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16090         cputime64_t tmp;
16091 +       int nice = (TASK_NICE(p) > 0);
16092  
16093         /* Add user time to process. */
16094         p->utime = cputime_add(p->utime, cputime);
16095         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
16096 +       vx_account_user(vxi, cputime, nice);
16097         account_group_user_time(p, cputime);
16098  
16099         /* Add user time to cpustat. */
16100         tmp = cputime_to_cputime64(cputime);
16101 -       if (TASK_NICE(p) > 0)
16102 +       if (nice)
16103                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16104         else
16105                 cpustat->user = cputime64_add(cpustat->user, tmp);
16106 @@ -5162,6 +5372,7 @@ void account_system_time(struct task_str
16107                          cputime_t cputime, cputime_t cputime_scaled)
16108  {
16109         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16110 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16111         cputime64_t tmp;
16112  
16113         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
16114 @@ -5172,6 +5383,7 @@ void account_system_time(struct task_str
16115         /* Add system time to process. */
16116         p->stime = cputime_add(p->stime, cputime);
16117         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
16118 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
16119         account_group_system_time(p, cputime);
16120  
16121         /* Add system time to cpustat. */
16122 @@ -6255,7 +6467,7 @@ SYSCALL_DEFINE1(nice, int, increment)
16123                 nice = 19;
16124  
16125         if (increment < 0 && !can_nice(current, nice))
16126 -               return -EPERM;
16127 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16128  
16129         retval = security_task_setnice(current, nice);
16130         if (retval)
16131 @@ -9323,6 +9535,32 @@ static int update_sched_domains(struct n
16132  }
16133  #endif
16134  
16135 +#ifdef CONFIG_SMP
16136 +static void disable_runtime(struct rq *rq)
16137 +{
16138 +       unsigned long flags;
16139 +
16140 +       spin_lock_irqsave(&rq->lock, flags);
16141 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16142 +       disable_runtime_cfs(rq);
16143 +#endif
16144 +       disable_runtime_rt(rq);
16145 +       spin_unlock_irqrestore(&rq->lock, flags);
16146 +}
16147 +
16148 +static void enable_runtime(struct rq *rq)
16149 +{
16150 +       unsigned long flags;
16151 +
16152 +       spin_lock_irqsave(&rq->lock, flags);
16153 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16154 +       enable_runtime_cfs(rq);
16155 +#endif
16156 +       enable_runtime_rt(rq);
16157 +       spin_unlock_irqrestore(&rq->lock, flags);
16158 +}
16159 +#endif
16160 +
16161  static int update_runtime(struct notifier_block *nfb,
16162                                 unsigned long action, void *hcpu)
16163  {
16164 @@ -9455,6 +9693,7 @@ static void init_tg_cfs_entry(struct tas
16165         struct rq *rq = cpu_rq(cpu);
16166         tg->cfs_rq[cpu] = cfs_rq;
16167         init_cfs_rq(cfs_rq, rq);
16168 +       init_cfs_hard_limits(cfs_rq, tg);
16169         cfs_rq->tg = tg;
16170         if (add)
16171                 list_add(&cfs_rq->leaf_cfs_rq_list, &rq->leaf_cfs_rq_list);
16172 @@ -9584,6 +9823,10 @@ void __init sched_init(void)
16173  #endif /* CONFIG_USER_SCHED */
16174  #endif /* CONFIG_RT_GROUP_SCHED */
16175  
16176 +#ifdef CONFIG_FAIR_GROUP_SCHED
16177 +       init_cfs_bandwidth(&init_task_group);
16178 +#endif
16179 +
16180  #ifdef CONFIG_GROUP_SCHED
16181         list_add(&init_task_group.list, &task_groups);
16182         INIT_LIST_HEAD(&init_task_group.children);
16183 @@ -9610,6 +9853,7 @@ void __init sched_init(void)
16184                 init_cfs_rq(&rq->cfs, rq);
16185                 init_rt_rq(&rq->rt, rq);
16186  #ifdef CONFIG_FAIR_GROUP_SCHED
16187 +               init_cfs_hard_limits(&rq->cfs, &init_task_group);
16188                 init_task_group.shares = init_task_group_load;
16189                 INIT_LIST_HEAD(&rq->leaf_cfs_rq_list);
16190  #ifdef CONFIG_CGROUP_SCHED
16191 @@ -9889,6 +10133,7 @@ static void free_fair_sched_group(struct
16192  {
16193         int i;
16194  
16195 +       destroy_cfs_bandwidth(tg);
16196         for_each_possible_cpu(i) {
16197                 if (tg->cfs_rq)
16198                         kfree(tg->cfs_rq[i]);
16199 @@ -9915,6 +10160,7 @@ int alloc_fair_sched_group(struct task_g
16200         if (!tg->se)
16201                 goto err;
16202  
16203 +       init_cfs_bandwidth(tg);
16204         tg->shares = NICE_0_LOAD;
16205  
16206         for_each_possible_cpu(i) {
16207 @@ -10638,6 +10884,100 @@ static u64 cpu_shares_read_u64(struct cg
16208  
16209         return (u64) tg->shares;
16210  }
16211 +
16212 +#ifdef CONFIG_CFS_HARD_LIMITS
16213 +
16214 +static int tg_set_cfs_bandwidth(struct task_group *tg,
16215 +               u64 cfs_period, u64 cfs_runtime)
16216 +{
16217 +       int i;
16218 +
16219 +       spin_lock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16220 +       tg->cfs_bandwidth.cfs_period = ns_to_ktime(cfs_period);
16221 +       tg->cfs_bandwidth.cfs_runtime = cfs_runtime;
16222 +
16223 +       for_each_possible_cpu(i) {
16224 +               struct cfs_rq *cfs_rq = tg->cfs_rq[i];
16225 +
16226 +               cfs_rq_runtime_lock(cfs_rq);
16227 +               cfs_rq->cfs_runtime = cfs_runtime;
16228 +               cfs_rq_runtime_unlock(cfs_rq);
16229 +       }
16230 +
16231 +       start_cfs_bandwidth(tg);
16232 +       spin_unlock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16233 +       return 0;
16234 +}
16235 +
16236 +int tg_set_cfs_runtime(struct task_group *tg, long cfs_runtime_us)
16237 +{
16238 +       u64 cfs_runtime, cfs_period;
16239 +
16240 +       cfs_period = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16241 +       cfs_runtime = (u64)cfs_runtime_us * NSEC_PER_USEC;
16242 +       if (cfs_runtime_us < 0)
16243 +               cfs_runtime = RUNTIME_INF;
16244 +
16245 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16246 +}
16247 +
16248 +long tg_get_cfs_runtime(struct task_group *tg)
16249 +{
16250 +       u64 cfs_runtime_us;
16251 +
16252 +       if (tg->cfs_bandwidth.cfs_runtime == RUNTIME_INF)
16253 +               return -1;
16254 +
16255 +       cfs_runtime_us = tg->cfs_bandwidth.cfs_runtime;
16256 +       do_div(cfs_runtime_us, NSEC_PER_USEC);
16257 +       return cfs_runtime_us;
16258 +}
16259 +
16260 +int tg_set_cfs_period(struct task_group *tg, long cfs_period_us)
16261 +{
16262 +       u64 cfs_runtime, cfs_period;
16263 +
16264 +       cfs_period = (u64)cfs_period_us * NSEC_PER_USEC;
16265 +       cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
16266 +
16267 +       if (cfs_period == 0)
16268 +               return -EINVAL;
16269 +
16270 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16271 +}
16272 +
16273 +long tg_get_cfs_period(struct task_group *tg)
16274 +{
16275 +       u64 cfs_period_us;
16276 +
16277 +       cfs_period_us = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16278 +       do_div(cfs_period_us, NSEC_PER_USEC);
16279 +       return cfs_period_us;
16280 +}
16281 +
16282 +static s64 cpu_cfs_runtime_read_s64(struct cgroup *cgrp, struct cftype *cft)
16283 +{
16284 +       return tg_get_cfs_runtime(cgroup_tg(cgrp));
16285 +}
16286 +
16287 +static int cpu_cfs_runtime_write_s64(struct cgroup *cgrp, struct cftype *cftype,
16288 +                               s64 cfs_runtime_us)
16289 +{
16290 +       return tg_set_cfs_runtime(cgroup_tg(cgrp), cfs_runtime_us);
16291 +}
16292 +
16293 +static u64 cpu_cfs_period_read_u64(struct cgroup *cgrp, struct cftype *cft)
16294 +{
16295 +       return tg_get_cfs_period(cgroup_tg(cgrp));
16296 +}
16297 +
16298 +static int cpu_cfs_period_write_u64(struct cgroup *cgrp, struct cftype *cftype,
16299 +                               u64 cfs_period_us)
16300 +{
16301 +       return tg_set_cfs_period(cgroup_tg(cgrp), cfs_period_us);
16302 +}
16303 +
16304 +#endif /* CONFIG_CFS_HARD_LIMITS */
16305  #endif /* CONFIG_FAIR_GROUP_SCHED */
16306  
16307  #ifdef CONFIG_RT_GROUP_SCHED
16308 @@ -10671,6 +11011,18 @@ static struct cftype cpu_files[] = {
16309                 .read_u64 = cpu_shares_read_u64,
16310                 .write_u64 = cpu_shares_write_u64,
16311         },
16312 +#ifdef CONFIG_CFS_HARD_LIMITS
16313 +       {
16314 +               .name = "cfs_runtime_us",
16315 +               .read_s64 = cpu_cfs_runtime_read_s64,
16316 +               .write_s64 = cpu_cfs_runtime_write_s64,
16317 +       },
16318 +       {
16319 +               .name = "cfs_period_us",
16320 +               .read_u64 = cpu_cfs_period_read_u64,
16321 +               .write_u64 = cpu_cfs_period_write_u64,
16322 +       },
16323 +#endif /* CONFIG_CFS_HARD_LIMITS */
16324  #endif
16325  #ifdef CONFIG_RT_GROUP_SCHED
16326         {
16327 diff -NurpP --minimal linux-2.6.32.24/kernel/sched_debug.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sched_debug.c
16328 --- linux-2.6.32.24/kernel/sched_debug.c        2010-10-04 08:56:18.000000000 +0200
16329 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sched_debug.c        2010-09-22 00:48:38.000000000 +0200
16330 @@ -80,6 +80,11 @@ static void print_cfs_group_stats(struct
16331         PN(se->wait_max);
16332         PN(se->wait_sum);
16333         P(se->wait_count);
16334 +#ifdef CONFIG_CFS_HARD_LIMITS
16335 +       PN(se->throttle_max);
16336 +       PN(se->throttle_sum);
16337 +       P(se->throttle_count);
16338 +#endif
16339  #endif
16340         P(se->load.weight);
16341  #undef PN
16342 @@ -214,6 +219,16 @@ void print_cfs_rq(struct seq_file *m, in
16343  #ifdef CONFIG_SMP
16344         SEQ_printf(m, "  .%-30s: %lu\n", "shares", cfs_rq->shares);
16345  #endif
16346 +#ifdef CONFIG_CFS_HARD_LIMITS
16347 +       spin_lock_irqsave(&rq->lock, flags);
16348 +       SEQ_printf(m, "  .%-30s: %d\n", "cfs_throttled",
16349 +                       cfs_rq->cfs_throttled);
16350 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_time",
16351 +                       SPLIT_NS(cfs_rq->cfs_time));
16352 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_runtime",
16353 +                       SPLIT_NS(cfs_rq->cfs_runtime));
16354 +       spin_unlock_irqrestore(&rq->lock, flags);
16355 +#endif /* CONFIG_CFS_HARD_LIMITS */
16356         print_cfs_group_stats(m, cpu, cfs_rq->tg);
16357  #endif
16358  }
16359 @@ -314,7 +329,7 @@ static int sched_debug_show(struct seq_f
16360         u64 now = ktime_to_ns(ktime_get());
16361         int cpu;
16362  
16363 -       SEQ_printf(m, "Sched Debug Version: v0.09, %s %.*s\n",
16364 +       SEQ_printf(m, "Sched Debug Version: v0.10, %s %.*s\n",
16365                 init_utsname()->release,
16366                 (int)strcspn(init_utsname()->version, " "),
16367                 init_utsname()->version);
16368 diff -NurpP --minimal linux-2.6.32.24/kernel/sched_fair.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sched_fair.c
16369 --- linux-2.6.32.24/kernel/sched_fair.c 2010-10-04 08:56:18.000000000 +0200
16370 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sched_fair.c 2010-09-22 01:14:22.000000000 +0200
16371 @@ -192,7 +192,308 @@ find_matching_se(struct sched_entity **s
16372         }
16373  }
16374  
16375 -#else  /* !CONFIG_FAIR_GROUP_SCHED */
16376 +#ifdef CONFIG_CFS_HARD_LIMITS
16377 +
16378 +static inline void update_stats_throttle_start(struct cfs_rq *cfs_rq,
16379 +                       struct sched_entity *se)
16380 +{
16381 +       schedstat_set(se->throttle_start, rq_of(cfs_rq)->clock);
16382 +}
16383 +
16384 +static inline void update_stats_throttle_end(struct cfs_rq *cfs_rq,
16385 +                       struct sched_entity *se)
16386 +{
16387 +       schedstat_set(se->throttle_max, max(se->throttle_max,
16388 +                       rq_of(cfs_rq)->clock - se->throttle_start));
16389 +       schedstat_set(se->throttle_count, se->throttle_count + 1);
16390 +       schedstat_set(se->throttle_sum, se->throttle_sum +
16391 +                       rq_of(cfs_rq)->clock - se->throttle_start);
16392 +       schedstat_set(se->throttle_start, 0);
16393 +}
16394 +
16395 +static inline
16396 +struct cfs_rq *sched_cfs_period_cfs_rq(struct cfs_bandwidth *cfs_b, int cpu)
16397 +{
16398 +       return container_of(cfs_b, struct task_group,
16399 +                       cfs_bandwidth)->cfs_rq[cpu];
16400 +}
16401 +
16402 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16403 +{
16404 +       return cfs_rq->cfs_throttled;
16405 +}
16406 +
16407 +#ifdef CONFIG_SMP
16408 +/*
16409 + * Ensure this RQ takes back all the runtime it lend to its neighbours.
16410 + */
16411 +static void disable_runtime_cfs(struct rq *rq)
16412 +{
16413 +       struct root_domain *rd = rq->rd;
16414 +       struct cfs_rq *cfs_rq;
16415 +
16416 +       if (unlikely(!scheduler_running))
16417 +               return;
16418 +
16419 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16420 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16421 +               s64 want;
16422 +               int i;
16423 +
16424 +               spin_lock(&cfs_b->cfs_runtime_lock);
16425 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16426 +
16427 +               /*
16428 +                * Either we're all are infinity and nobody needs to borrow,
16429 +                * or we're already disabled and this have nothing to do, or
16430 +                * we have exactly the right amount of runtime to take out.
16431 +                */
16432 +                if (cfs_rq->cfs_runtime == RUNTIME_INF ||
16433 +                               cfs_rq->cfs_runtime == cfs_b->cfs_runtime)
16434 +                       goto balanced;
16435 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16436 +
16437 +               /*
16438 +                * Calculate the difference between what we started out with
16439 +                * and what we current have, that's the amount of runtime
16440 +                * we lend and now have to reclaim.
16441 +                */
16442 +                want = cfs_b->cfs_runtime - cfs_rq->cfs_runtime;
16443 +
16444 +               /*
16445 +                * Greedy reclaim, take back as much as possible.
16446 +                */
16447 +               for_each_cpu(i, rd->span) {
16448 +                       struct cfs_rq *iter = sched_cfs_period_cfs_rq(cfs_b, i);
16449 +                       s64 diff;
16450 +
16451 +                       /*
16452 +                        * Can't reclaim from ourselves or disabled runqueues.
16453 +                        */
16454 +                       if (iter == cfs_rq || iter->cfs_runtime == RUNTIME_INF)
16455 +                               continue;
16456 +
16457 +                       spin_lock(&iter->cfs_runtime_lock);
16458 +                       if (want > 0) {
16459 +                               diff = min_t(s64, iter->cfs_runtime, want);
16460 +                               iter->cfs_runtime -= diff;
16461 +                               want -= diff;
16462 +                       } else {
16463 +                               iter->cfs_runtime -= want;
16464 +                               want -= want;
16465 +                       }
16466 +
16467 +                       spin_unlock(&iter->cfs_runtime_lock);
16468 +                       if (!want)
16469 +                               break;
16470 +               }
16471 +
16472 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16473 +               /*
16474 +                * We cannot be left wanting - that would mean some
16475 +                * runtime leaked out of the system.
16476 +                */
16477 +               BUG_ON(want);
16478 +balanced:
16479 +               /*
16480 +                * Disable all the borrow logic by pretending we have infinite
16481 +                * runtime - in which case borrowing doesn't make sense.
16482 +                */
16483 +                cfs_rq->cfs_runtime = RUNTIME_INF;
16484 +                spin_unlock(&cfs_rq->cfs_runtime_lock);
16485 +                spin_unlock(&cfs_b->cfs_runtime_lock);
16486 +       }
16487 +}
16488 +
16489 +static void enable_runtime_cfs(struct rq *rq)
16490 +{
16491 +       struct cfs_rq *cfs_rq;
16492 +
16493 +       if (unlikely(!scheduler_running))
16494 +               return;
16495 +
16496 +       /*
16497 +        * Reset each runqueue's bandwidth settings
16498 +        */
16499 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16500 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16501 +
16502 +               spin_lock(&cfs_b->cfs_runtime_lock);
16503 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16504 +               cfs_rq->cfs_runtime = cfs_b->cfs_runtime;
16505 +               cfs_rq->cfs_time = 0;
16506 +               cfs_rq->cfs_throttled = 0;
16507 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16508 +               spin_unlock(&cfs_b->cfs_runtime_lock);
16509 +       }
16510 +}
16511 +
16512 +/*
16513 + * Ran out of runtime, check if we can borrow some from others
16514 + * instead of getting throttled right away.
16515 + */
16516 +static void do_cfs_balance_runtime(struct cfs_rq *cfs_rq)
16517 +{
16518 +       struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16519 +       const struct cpumask *span = sched_bw_period_mask();
16520 +       int i, weight;
16521 +       u64 cfs_period;
16522 +
16523 +       weight = cpumask_weight(span);
16524 +       spin_lock(&cfs_b->cfs_runtime_lock);
16525 +       cfs_period = ktime_to_ns(cfs_b->cfs_period);
16526 +
16527 +       for_each_cpu(i, span) {
16528 +               struct cfs_rq *borrow_cfs_rq =
16529 +                               sched_cfs_period_cfs_rq(cfs_b, i);
16530 +               s64 diff;
16531 +
16532 +               if (borrow_cfs_rq == cfs_rq)
16533 +                       continue;
16534 +
16535 +               cfs_rq_runtime_lock(borrow_cfs_rq);
16536 +               if (borrow_cfs_rq->cfs_runtime == RUNTIME_INF) {
16537 +                       cfs_rq_runtime_unlock(borrow_cfs_rq);
16538 +                       continue;
16539 +               }
16540 +
16541 +               diff = borrow_cfs_rq->cfs_runtime - borrow_cfs_rq->cfs_time;
16542 +               if (diff > 0) {
16543 +                       diff = div_u64((u64)diff, weight);
16544 +                       if (cfs_rq->cfs_runtime + diff > cfs_period)
16545 +                               diff = cfs_period - cfs_rq->cfs_runtime;
16546 +                       borrow_cfs_rq->cfs_runtime -= diff;
16547 +                       cfs_rq->cfs_runtime += diff;
16548 +                       if (cfs_rq->cfs_runtime == cfs_period) {
16549 +                               cfs_rq_runtime_unlock(borrow_cfs_rq);
16550 +                               break;
16551 +                       }
16552 +               }
16553 +               cfs_rq_runtime_unlock(borrow_cfs_rq);
16554 +       }
16555 +       spin_unlock(&cfs_b->cfs_runtime_lock);
16556 +}
16557 +
16558 +/*
16559 + * Called with rq->runtime_lock held.
16560 + */
16561 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16562 +{
16563 +       cfs_rq_runtime_unlock(cfs_rq);
16564 +       do_cfs_balance_runtime(cfs_rq);
16565 +       cfs_rq_runtime_lock(cfs_rq);
16566 +}
16567 +
16568 +#else /* !CONFIG_SMP */
16569 +
16570 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16571 +{
16572 +       return;
16573 +}
16574 +#endif /* CONFIG_SMP */
16575 +
16576 +/*
16577 + * Check if group entity exceeded its runtime. If so, mark the cfs_rq as
16578 + * throttled mark the current task for reschedling.
16579 + */
16580 +static void sched_cfs_runtime_exceeded(struct sched_entity *se,
16581 +       struct task_struct *tsk_curr, unsigned long delta_exec)
16582 +{
16583 +       struct cfs_rq *cfs_rq;
16584 +
16585 +       cfs_rq = group_cfs_rq(se);
16586 +
16587 +       if (cfs_rq->cfs_runtime == RUNTIME_INF)
16588 +               return;
16589 +
16590 +       cfs_rq->cfs_time += delta_exec;
16591 +
16592 +       if (cfs_rq_throttled(cfs_rq))
16593 +               return;
16594 +
16595 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime)
16596 +               cfs_balance_runtime(cfs_rq);
16597 +
16598 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime) {
16599 +               cfs_rq->cfs_throttled = 1;
16600 +               update_stats_throttle_start(cfs_rq, se);
16601 +               resched_task(tsk_curr);
16602 +       }
16603 +}
16604 +
16605 +static inline void update_curr_group(struct sched_entity *curr,
16606 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16607 +{
16608 +       sched_cfs_runtime_exceeded(curr, tsk_curr, delta_exec);
16609 +}
16610 +
16611 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16612 +               struct sched_entity *se, int flags);
16613 +
16614 +static void enqueue_throttled_entity(struct rq *rq, struct sched_entity *se)
16615 +{
16616 +       for_each_sched_entity(se) {
16617 +               struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16618 +
16619 +               if (se->on_rq || cfs_rq_throttled(gcfs_rq) ||
16620 +                               !gcfs_rq->nr_running)
16621 +                       break;
16622 +               enqueue_entity_locked(cfs_rq_of(se), se, 0);
16623 +       }
16624 +}
16625 +
16626 +/*
16627 + * Refresh runtimes of all cfs_rqs in this group, i,e.,
16628 + * refresh runtimes of the representative cfs_rq of this
16629 + * tg on all cpus. Enqueue any throttled entity back.
16630 + */
16631 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b)
16632 +{
16633 +       int i;
16634 +       const struct cpumask *span = sched_bw_period_mask();
16635 +       unsigned long flags;
16636 +
16637 +       for_each_cpu(i, span) {
16638 +               struct rq *rq = cpu_rq(i);
16639 +               struct cfs_rq *cfs_rq = sched_cfs_period_cfs_rq(cfs_b, i);
16640 +               struct sched_entity *se = cfs_rq->tg->se[i];
16641 +
16642 +               spin_lock_irqsave(&rq->lock, flags);
16643 +               cfs_rq_runtime_lock(cfs_rq);
16644 +               cfs_rq->cfs_time = 0;
16645 +               if (cfs_rq_throttled(cfs_rq)) {
16646 +                       update_rq_clock(rq);
16647 +                       update_stats_throttle_end(cfs_rq, se);
16648 +                       cfs_rq->cfs_throttled = 0;
16649 +                       enqueue_throttled_entity(rq, se);
16650 +               }
16651 +               cfs_rq_runtime_unlock(cfs_rq);
16652 +               spin_unlock_irqrestore(&rq->lock, flags);
16653 +       }
16654 +}
16655 +
16656 +#else
16657 +
16658 +static inline void update_curr_group(struct sched_entity *curr,
16659 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16660 +{
16661 +       return;
16662 +}
16663 +
16664 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16665 +{
16666 +       return 0;
16667 +}
16668 +
16669 +#endif /* CONFIG_CFS_HARD_LIMITS */
16670 +
16671 +#else  /* CONFIG_FAIR_GROUP_SCHED */
16672 +
16673 +static inline void update_curr_group(struct sched_entity *curr,
16674 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16675 +{
16676 +       return;
16677 +}
16678  
16679  static inline struct task_struct *task_of(struct sched_entity *se)
16680  {
16681 @@ -254,7 +555,6 @@ find_matching_se(struct sched_entity **s
16682  
16683  #endif /* CONFIG_FAIR_GROUP_SCHED */
16684  
16685 -
16686  /**************************************************************
16687   * Scheduling class tree data structure manipulation methods:
16688   */
16689 @@ -493,14 +793,25 @@ __update_curr(struct cfs_rq *cfs_rq, str
16690         update_min_vruntime(cfs_rq);
16691  }
16692  
16693 -static void update_curr(struct cfs_rq *cfs_rq)
16694 +static void update_curr_task(struct sched_entity *curr,
16695 +               unsigned long delta_exec)
16696 +{
16697 +       struct task_struct *curtask = task_of(curr);
16698 +
16699 +       trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16700 +       cpuacct_charge(curtask, delta_exec);
16701 +       account_group_exec_runtime(curtask, delta_exec);
16702 +}
16703 +
16704 +static int update_curr_common(struct cfs_rq *cfs_rq, unsigned long *delta)
16705  {
16706         struct sched_entity *curr = cfs_rq->curr;
16707 -       u64 now = rq_of(cfs_rq)->clock;
16708 +       struct rq *rq = rq_of(cfs_rq);
16709 +       u64 now = rq->clock;
16710         unsigned long delta_exec;
16711  
16712         if (unlikely(!curr))
16713 -               return;
16714 +               return 1;
16715  
16716         /*
16717          * Get the amount of time the current task was running
16718 @@ -509,17 +820,29 @@ static void update_curr(struct cfs_rq *c
16719          */
16720         delta_exec = (unsigned long)(now - curr->exec_start);
16721         if (!delta_exec)
16722 -               return;
16723 +               return 1;
16724  
16725         __update_curr(cfs_rq, curr, delta_exec);
16726         curr->exec_start = now;
16727 +       *delta = delta_exec;
16728 +       return 0;
16729 +}
16730  
16731 -       if (entity_is_task(curr)) {
16732 -               struct task_struct *curtask = task_of(curr);
16733 +static void update_curr(struct cfs_rq *cfs_rq)
16734 +{
16735 +       struct sched_entity *curr = cfs_rq->curr;
16736 +       struct rq *rq = rq_of(cfs_rq);
16737 +       unsigned long delta_exec;
16738  
16739 -               trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16740 -               cpuacct_charge(curtask, delta_exec);
16741 -               account_group_exec_runtime(curtask, delta_exec);
16742 +       if (update_curr_common(cfs_rq, &delta_exec))
16743 +               return ;
16744 +
16745 +       if (entity_is_task(curr))
16746 +               update_curr_task(curr, delta_exec);
16747 +       else {
16748 +               cfs_rq_runtime_lock(group_cfs_rq(curr));
16749 +               update_curr_group(curr, delta_exec, rq->curr);
16750 +               cfs_rq_runtime_unlock(group_cfs_rq(curr));
16751         }
16752  }
16753  
16754 @@ -747,7 +1070,26 @@ place_entity(struct cfs_rq *cfs_rq, stru
16755  #define ENQUEUE_WAKEUP 1
16756  #define ENQUEUE_MIGRATE 2
16757  
16758 -static void
16759 +static void
16760 +enqueue_entity_common(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
16761 +{
16762 +       account_entity_enqueue(cfs_rq, se);
16763 +
16764 +       if (flags & ENQUEUE_WAKEUP) {
16765 +               place_entity(cfs_rq, se, 0);
16766 +               enqueue_sleeper(cfs_rq, se);
16767 +       }
16768 +
16769 +       update_stats_enqueue(cfs_rq, se);
16770 +       check_spread(cfs_rq, se);
16771 +       if (se != cfs_rq->curr)
16772 +               __enqueue_entity(cfs_rq, se);
16773 +
16774 +       if (entity_is_task(se))
16775 +               vx_activate_task(task_of(se));
16776 +}
16777 +
16778 +static void
16779  enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
16780  {
16781         /*
16782 @@ -761,17 +1103,17 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16783          * Update run-time statistics of the 'current'.
16784          */
16785         update_curr(cfs_rq);
16786 -       account_entity_enqueue(cfs_rq, se);
16787 -
16788 -       if (flags & ENQUEUE_WAKEUP) {
16789 -               place_entity(cfs_rq, se, 0);
16790 -               enqueue_sleeper(cfs_rq, se);
16791 -       }
16792 +       enqueue_entity_common(cfs_rq, se, flags);
16793 +}
16794  
16795 -       update_stats_enqueue(cfs_rq, se);
16796 -       check_spread(cfs_rq, se);
16797 -       if (se != cfs_rq->curr)
16798 -               __enqueue_entity(cfs_rq, se);
16799 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16800 +               struct sched_entity *se, int flags)
16801 +{
16802 +       /*
16803 +        * Update run-time statistics of the 'current'.
16804 +        */
16805 +       // update_curr_locked(cfs_rq);
16806 +       enqueue_entity_common(cfs_rq, se, flags);
16807  }
16808  
16809  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
16810 @@ -815,6 +1157,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16811  
16812         if (se != cfs_rq->curr)
16813                 __dequeue_entity(cfs_rq, se);
16814 +       if (entity_is_task(se))
16815 +               vx_deactivate_task(task_of(se));
16816         account_entity_dequeue(cfs_rq, se);
16817         update_min_vruntime(cfs_rq);
16818  
16819 @@ -919,6 +1263,32 @@ static struct sched_entity *pick_next_en
16820         return se;
16821  }
16822  
16823 +/*
16824 + * Called from put_prev_entity()
16825 + * If a group entity (@se) is found to be throttled, it will not be put back
16826 + * on @cfs_rq, which is equivalent to dequeing it.
16827 + */
16828 +static int dequeue_throttled_entity(struct cfs_rq *cfs_rq,
16829 +               struct sched_entity *se)
16830 +{
16831 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16832 +
16833 +       if (entity_is_task(se))
16834 +               return 0;
16835 +
16836 +       cfs_rq_runtime_lock(gcfs_rq);
16837 +       if (!cfs_rq_throttled(gcfs_rq) && gcfs_rq->nr_running) {
16838 +               cfs_rq_runtime_unlock(gcfs_rq);
16839 +               return 0;
16840 +       }
16841 +
16842 +       __clear_buddies(cfs_rq, se);
16843 +       account_entity_dequeue(cfs_rq, se);
16844 +       cfs_rq->curr = NULL;
16845 +       cfs_rq_runtime_unlock(gcfs_rq);
16846 +       return 1;
16847 +}
16848 +
16849  static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
16850  {
16851         /*
16852 @@ -930,6 +1300,8 @@ static void put_prev_entity(struct cfs_r
16853  
16854         check_spread(cfs_rq, prev);
16855         if (prev->on_rq) {
16856 +               if (dequeue_throttled_entity(cfs_rq, prev))
16857 +                       return;
16858                 update_stats_wait_start(cfs_rq, prev);
16859                 /* Put 'current' back into the tree. */
16860                 __enqueue_entity(cfs_rq, prev);
16861 @@ -1026,10 +1398,28 @@ static inline void hrtick_update(struct 
16862  }
16863  #endif
16864  
16865 +static int enqueue_group_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
16866 +                int flags)
16867 +{
16868 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16869 +       int ret = 0;
16870 +
16871 +       cfs_rq_runtime_lock(gcfs_rq);
16872 +       if (cfs_rq_throttled(gcfs_rq)) {
16873 +               ret = 1;
16874 +               goto out;
16875 +       }
16876 +       enqueue_entity_locked(cfs_rq, se, flags);
16877 +out:
16878 +       cfs_rq_runtime_unlock(gcfs_rq);
16879 +       return ret;
16880 +}
16881 +
16882  /*
16883   * The enqueue_task method is called before nr_running is
16884   * increased. Here we update the fair scheduling stats and
16885   * then put the task into the rbtree:
16886 + * Don't enqueue a throttled entity further into the hierarchy.
16887   */
16888  static void
16889  enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup, bool head)
16890 @@ -1046,11 +1436,15 @@ enqueue_task_fair(struct rq *rq, struct 
16891         for_each_sched_entity(se) {
16892                 if (se->on_rq)
16893                         break;
16894 +
16895                 cfs_rq = cfs_rq_of(se);
16896 -               enqueue_entity(cfs_rq, se, flags);
16897 +               if (entity_is_task(se))
16898 +                       enqueue_entity(cfs_rq, se, flags);
16899 +               else
16900 +                       if (enqueue_group_entity(cfs_rq, se, flags))
16901 +                               break;
16902                 flags = ENQUEUE_WAKEUP;
16903         }
16904 -
16905         hrtick_update(rq);
16906  }
16907  
16908 @@ -1070,6 +1464,17 @@ static void dequeue_task_fair(struct rq 
16909                 /* Don't dequeue parent if it has other entities besides us */
16910                 if (cfs_rq->load.weight)
16911                         break;
16912 +
16913 +               /*
16914 +                * If this cfs_rq is throttled, then it is already
16915 +                * dequeued.
16916 +                */
16917 +               cfs_rq_runtime_lock(cfs_rq);
16918 +               if (cfs_rq_throttled(cfs_rq)) {
16919 +                       cfs_rq_runtime_unlock(cfs_rq);
16920 +                       break;
16921 +               }
16922 +               cfs_rq_runtime_unlock(cfs_rq);
16923                 sleep = 1;
16924         }
16925  
16926 @@ -1886,9 +2291,10 @@ load_balance_fair(struct rq *this_rq, in
16927                 u64 rem_load, moved_load;
16928  
16929                 /*
16930 -                * empty group
16931 +                * empty group or throttled group
16932                  */
16933 -               if (!busiest_cfs_rq->task_weight)
16934 +               if (!busiest_cfs_rq->task_weight ||
16935 +                               cfs_rq_throttled(busiest_cfs_rq))
16936                         continue;
16937  
16938                 rem_load = (u64)rem_load_move * busiest_weight;
16939 @@ -1937,6 +2343,12 @@ move_one_task_fair(struct rq *this_rq, i
16940  
16941         for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
16942                 /*
16943 +                * Don't move task from a throttled cfs_rq
16944 +                */
16945 +               if (cfs_rq_throttled(busy_cfs_rq))
16946 +                       continue;
16947 +
16948 +               /*
16949                  * pass busy_cfs_rq argument into
16950                  * load_balance_[start|next]_fair iterators
16951                  */
16952 diff -NurpP --minimal linux-2.6.32.24/kernel/sched_rt.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sched_rt.c
16953 --- linux-2.6.32.24/kernel/sched_rt.c   2010-10-04 08:56:18.000000000 +0200
16954 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sched_rt.c   2010-09-22 00:48:38.000000000 +0200
16955 @@ -235,18 +235,6 @@ static int rt_se_boosted(struct sched_rt
16956         return p->prio != p->normal_prio;
16957  }
16958  
16959 -#ifdef CONFIG_SMP
16960 -static inline const struct cpumask *sched_rt_period_mask(void)
16961 -{
16962 -       return cpu_rq(smp_processor_id())->rd->span;
16963 -}
16964 -#else
16965 -static inline const struct cpumask *sched_rt_period_mask(void)
16966 -{
16967 -       return cpu_online_mask;
16968 -}
16969 -#endif
16970 -
16971  static inline
16972  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16973  {
16974 @@ -296,11 +284,6 @@ static inline int rt_rq_throttled(struct
16975         return rt_rq->rt_throttled;
16976  }
16977  
16978 -static inline const struct cpumask *sched_rt_period_mask(void)
16979 -{
16980 -       return cpu_online_mask;
16981 -}
16982 -
16983  static inline
16984  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16985  {
16986 @@ -373,7 +356,7 @@ next:
16987  /*
16988   * Ensure this RQ takes back all the runtime it lend to its neighbours.
16989   */
16990 -static void __disable_runtime(struct rq *rq)
16991 +static void disable_runtime_rt(struct rq *rq)
16992  {
16993         struct root_domain *rd = rq->rd;
16994         struct rt_rq *rt_rq;
16995 @@ -450,16 +433,7 @@ balanced:
16996         }
16997  }
16998  
16999 -static void disable_runtime(struct rq *rq)
17000 -{
17001 -       unsigned long flags;
17002 -
17003 -       spin_lock_irqsave(&rq->lock, flags);
17004 -       __disable_runtime(rq);
17005 -       spin_unlock_irqrestore(&rq->lock, flags);
17006 -}
17007 -
17008 -static void __enable_runtime(struct rq *rq)
17009 +static void enable_runtime_rt(struct rq *rq)
17010  {
17011         struct rt_rq *rt_rq;
17012  
17013 @@ -482,15 +456,6 @@ static void __enable_runtime(struct rq *
17014         }
17015  }
17016  
17017 -static void enable_runtime(struct rq *rq)
17018 -{
17019 -       unsigned long flags;
17020 -
17021 -       spin_lock_irqsave(&rq->lock, flags);
17022 -       __enable_runtime(rq);
17023 -       spin_unlock_irqrestore(&rq->lock, flags);
17024 -}
17025 -
17026  static int balance_runtime(struct rt_rq *rt_rq)
17027  {
17028         int more = 0;
17029 @@ -518,7 +483,7 @@ static int do_sched_rt_period_timer(stru
17030         if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
17031                 return 1;
17032  
17033 -       span = sched_rt_period_mask();
17034 +       span = sched_bw_period_mask();
17035         for_each_cpu(i, span) {
17036                 int enqueue = 0;
17037                 struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
17038 @@ -1567,7 +1532,7 @@ static void rq_online_rt(struct rq *rq)
17039         if (rq->rt.overloaded)
17040                 rt_set_overload(rq);
17041  
17042 -       __enable_runtime(rq);
17043 +       enable_runtime_rt(rq);
17044  
17045         cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
17046  }
17047 @@ -1578,7 +1543,7 @@ static void rq_offline_rt(struct rq *rq)
17048         if (rq->rt.overloaded)
17049                 rt_clear_overload(rq);
17050  
17051 -       __disable_runtime(rq);
17052 +       disable_runtime_rt(rq);
17053  
17054         cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
17055  }
17056 diff -NurpP --minimal linux-2.6.32.24/kernel/signal.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/signal.c
17057 --- linux-2.6.32.24/kernel/signal.c     2010-10-04 08:56:18.000000000 +0200
17058 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/signal.c     2010-07-08 02:22:31.000000000 +0200
17059 @@ -27,6 +27,8 @@
17060  #include <linux/freezer.h>
17061  #include <linux/pid_namespace.h>
17062  #include <linux/nsproxy.h>
17063 +#include <linux/vs_context.h>
17064 +#include <linux/vs_pid.h>
17065  #include <trace/events/sched.h>
17066  
17067  #include <asm/param.h>
17068 @@ -598,6 +600,14 @@ static int check_kill_permission(int sig
17069         if (!valid_signal(sig))
17070                 return -EINVAL;
17071  
17072 +       if ((info != SEND_SIG_NOINFO) &&
17073 +               (is_si_special(info) || !SI_FROMUSER(info)))
17074 +               goto skip;
17075 +
17076 +       vxdprintk(VXD_CBIT(misc, 7),
17077 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
17078 +               sig, info, t, vx_task_xid(t), t->pid);
17079 +
17080         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
17081                 return 0;
17082  
17083 @@ -627,6 +637,20 @@ static int check_kill_permission(int sig
17084                 }
17085         }
17086  
17087 +       error = -EPERM;
17088 +       if (t->pid == 1 && current->xid)
17089 +               return error;
17090 +
17091 +       error = -ESRCH;
17092 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
17093 +                 loops, maybe ENOENT or EACCES? */
17094 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
17095 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
17096 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
17097 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
17098 +               return error;
17099 +       }
17100 +skip:
17101         return security_task_kill(t, info, sig, 0);
17102  }
17103  
17104 @@ -1115,7 +1139,7 @@ int kill_pid_info(int sig, struct siginf
17105         rcu_read_lock();
17106  retry:
17107         p = pid_task(pid, PIDTYPE_PID);
17108 -       if (p) {
17109 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
17110                 error = group_send_sig_info(sig, info, p);
17111                 if (unlikely(error == -ESRCH))
17112                         /*
17113 @@ -1154,7 +1178,7 @@ int kill_pid_info_as_uid(int sig, struct
17114  
17115         read_lock(&tasklist_lock);
17116         p = pid_task(pid, PIDTYPE_PID);
17117 -       if (!p) {
17118 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
17119                 ret = -ESRCH;
17120                 goto out_unlock;
17121         }
17122 @@ -1208,8 +1232,10 @@ static int kill_something_info(int sig, 
17123                 struct task_struct * p;
17124  
17125                 for_each_process(p) {
17126 -                       if (task_pid_vnr(p) > 1 &&
17127 -                                       !same_thread_group(p, current)) {
17128 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
17129 +                               task_pid_vnr(p) > 1 &&
17130 +                               !same_thread_group(p, current) &&
17131 +                               !vx_current_initpid(p->pid)) {
17132                                 int err = group_send_sig_info(sig, info, p);
17133                                 ++count;
17134                                 if (err != -EPERM)
17135 @@ -1874,6 +1900,11 @@ relock:
17136                                 !sig_kernel_only(signr))
17137                         continue;
17138  
17139 +               /* virtual init is protected against user signals */
17140 +               if ((info->si_code == SI_USER) &&
17141 +                       vx_current_initpid(current->pid))
17142 +                       continue;
17143 +
17144                 if (sig_kernel_stop(signr)) {
17145                         /*
17146                          * The default action is to stop all threads in
17147 diff -NurpP --minimal linux-2.6.32.24/kernel/softirq.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/softirq.c
17148 --- linux-2.6.32.24/kernel/softirq.c    2009-12-03 20:02:58.000000000 +0100
17149 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/softirq.c    2009-12-03 20:04:56.000000000 +0100
17150 @@ -24,6 +24,7 @@
17151  #include <linux/ftrace.h>
17152  #include <linux/smp.h>
17153  #include <linux/tick.h>
17154 +#include <linux/vs_context.h>
17155  
17156  #define CREATE_TRACE_POINTS
17157  #include <trace/events/irq.h>
17158 diff -NurpP --minimal linux-2.6.32.24/kernel/sys.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sys.c
17159 --- linux-2.6.32.24/kernel/sys.c        2010-10-04 08:56:18.000000000 +0200
17160 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sys.c        2010-10-04 10:04:57.000000000 +0200
17161 @@ -41,6 +41,7 @@
17162  #include <linux/syscalls.h>
17163  #include <linux/kprobes.h>
17164  #include <linux/user_namespace.h>
17165 +#include <linux/vs_pid.h>
17166  
17167  #include <asm/uaccess.h>
17168  #include <asm/io.h>
17169 @@ -130,7 +131,10 @@ static int set_one_prio(struct task_stru
17170                 goto out;
17171         }
17172         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17173 -               error = -EACCES;
17174 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17175 +                       error = 0;
17176 +               else
17177 +                       error = -EACCES;
17178                 goto out;
17179         }
17180         no_nice = security_task_setnice(p, niceval);
17181 @@ -179,6 +183,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
17182                         else
17183                                 pgrp = task_pgrp(current);
17184                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17185 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17186 +                                       continue;
17187                                 error = set_one_prio(p, niceval, error);
17188                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
17189                         break;
17190 @@ -240,6 +246,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
17191                         else
17192                                 pgrp = task_pgrp(current);
17193                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17194 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17195 +                                       continue;
17196                                 niceval = 20 - task_nice(p);
17197                                 if (niceval > retval)
17198                                         retval = niceval;
17199 @@ -349,6 +357,9 @@ void kernel_power_off(void)
17200         machine_power_off();
17201  }
17202  EXPORT_SYMBOL_GPL(kernel_power_off);
17203 +
17204 +long vs_reboot(unsigned int, void __user *);
17205 +
17206  /*
17207   * Reboot system call: for obvious reasons only root may call it,
17208   * and even root needs to set up some magic numbers in the registers
17209 @@ -381,6 +392,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
17210         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17211                 cmd = LINUX_REBOOT_CMD_HALT;
17212  
17213 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17214 +               return vs_reboot(cmd, arg);
17215 +
17216         lock_kernel();
17217         switch (cmd) {
17218         case LINUX_REBOOT_CMD_RESTART:
17219 @@ -1134,7 +1148,7 @@ SYSCALL_DEFINE2(sethostname, char __user
17220         int errno;
17221         char tmp[__NEW_UTS_LEN];
17222  
17223 -       if (!capable(CAP_SYS_ADMIN))
17224 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17225                 return -EPERM;
17226         if (len < 0 || len > __NEW_UTS_LEN)
17227                 return -EINVAL;
17228 @@ -1183,7 +1197,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
17229         int errno;
17230         char tmp[__NEW_UTS_LEN];
17231  
17232 -       if (!capable(CAP_SYS_ADMIN))
17233 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17234                 return -EPERM;
17235         if (len < 0 || len > __NEW_UTS_LEN)
17236                 return -EINVAL;
17237 @@ -1252,7 +1266,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
17238                 return -EINVAL;
17239         old_rlim = current->signal->rlim + resource;
17240         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
17241 -           !capable(CAP_SYS_RESOURCE))
17242 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17243                 return -EPERM;
17244         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
17245                 return -EPERM;
17246 diff -NurpP --minimal linux-2.6.32.24/kernel/sysctl.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sysctl.c
17247 --- linux-2.6.32.24/kernel/sysctl.c     2010-10-04 08:56:18.000000000 +0200
17248 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sysctl.c     2010-01-20 04:21:33.000000000 +0100
17249 @@ -124,6 +124,7 @@ static int ngroups_max = NGROUPS_MAX;
17250  extern char modprobe_path[];
17251  extern int modules_disabled;
17252  #endif
17253 +extern char vshelper_path[];
17254  #ifdef CONFIG_CHR_DEV_SG
17255  extern int sg_big_buff;
17256  #endif
17257 @@ -593,6 +594,15 @@ static struct ctl_table kern_table[] = {
17258                 .strategy       = &sysctl_string,
17259         },
17260  #endif
17261 +       {
17262 +               .ctl_name       = KERN_VSHELPER,
17263 +               .procname       = "vshelper",
17264 +               .data           = &vshelper_path,
17265 +               .maxlen         = 256,
17266 +               .mode           = 0644,
17267 +               .proc_handler   = &proc_dostring,
17268 +               .strategy       = &sysctl_string,
17269 +       },
17270  #ifdef CONFIG_CHR_DEV_SG
17271         {
17272                 .ctl_name       = KERN_SG_BIG_BUFF,
17273 diff -NurpP --minimal linux-2.6.32.24/kernel/sysctl_check.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sysctl_check.c
17274 --- linux-2.6.32.24/kernel/sysctl_check.c       2010-10-04 08:56:18.000000000 +0200
17275 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/sysctl_check.c       2010-02-12 10:59:55.000000000 +0100
17276 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
17277  
17278         { KERN_PANIC,                   "panic" },
17279         { KERN_REALROOTDEV,             "real-root-dev" },
17280 +       { KERN_VSHELPER,                "vshelper", },
17281  
17282         { KERN_SPARC_REBOOT,            "reboot-cmd" },
17283         { KERN_CTLALTDEL,               "ctrl-alt-del" },
17284 @@ -1218,6 +1219,22 @@ static const struct trans_ctl_table tran
17285         {}
17286  };
17287  
17288 +static struct trans_ctl_table trans_vserver_table[] = {
17289 +       { 1,    "debug_switch" },
17290 +       { 2,    "debug_xid" },
17291 +       { 3,    "debug_nid" },
17292 +       { 4,    "debug_tag" },
17293 +       { 5,    "debug_net" },
17294 +       { 6,    "debug_limit" },
17295 +       { 7,    "debug_cres" },
17296 +       { 8,    "debug_dlim" },
17297 +       { 9,    "debug_quota" },
17298 +       { 10,   "debug_cvirt" },
17299 +       { 11,   "debug_space" },
17300 +       { 12,   "debug_misc" },
17301 +       {}
17302 +};
17303 +
17304  static const struct trans_ctl_table trans_root_table[] = {
17305         { CTL_KERN,     "kernel",       trans_kern_table },
17306         { CTL_VM,       "vm",           trans_vm_table },
17307 @@ -1234,6 +1251,7 @@ static const struct trans_ctl_table tran
17308         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
17309         { CTL_PM,       "pm",           trans_pm_table },
17310         { CTL_FRV,      "frv",          trans_frv_table },
17311 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
17312         {}
17313  };
17314  
17315 diff -NurpP --minimal linux-2.6.32.24/kernel/time.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/time.c
17316 --- linux-2.6.32.24/kernel/time.c       2009-12-03 20:02:58.000000000 +0100
17317 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/time.c       2009-12-03 20:04:56.000000000 +0100
17318 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
17319  SYSCALL_DEFINE1(time, time_t __user *, tloc)
17320  {
17321         time_t i = get_seconds();
17322 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
17323  
17324         if (tloc) {
17325                 if (put_user(i,tloc))
17326 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
17327         if (err)
17328                 return err;
17329  
17330 -       do_settimeofday(&tv);
17331 +       vx_settimeofday(&tv);
17332         return 0;
17333  }
17334  
17335 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
17336  {
17337         if (likely(tv != NULL)) {
17338                 struct timeval ktv;
17339 -               do_gettimeofday(&ktv);
17340 +               vx_gettimeofday(&ktv);
17341                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
17342                         return -EFAULT;
17343         }
17344 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
17345                 /* SMP safe, again the code in arch/foo/time.c should
17346                  * globally block out interrupts when it runs.
17347                  */
17348 -               return do_settimeofday(tv);
17349 +               return vx_settimeofday(tv);
17350         }
17351         return 0;
17352  }
17353 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
17354  {
17355         struct timeval x;
17356  
17357 -       do_gettimeofday(&x);
17358 +       vx_gettimeofday(&x);
17359         tv->tv_sec = x.tv_sec;
17360         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17361  }
17362 diff -NurpP --minimal linux-2.6.32.24/kernel/timer.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/timer.c
17363 --- linux-2.6.32.24/kernel/timer.c      2009-12-03 20:02:58.000000000 +0100
17364 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/timer.c      2009-12-03 20:04:56.000000000 +0100
17365 @@ -39,6 +39,10 @@
17366  #include <linux/kallsyms.h>
17367  #include <linux/perf_event.h>
17368  #include <linux/sched.h>
17369 +#include <linux/vs_base.h>
17370 +#include <linux/vs_cvirt.h>
17371 +#include <linux/vs_pid.h>
17372 +#include <linux/vserver/sched.h>
17373  
17374  #include <asm/uaccess.h>
17375  #include <asm/unistd.h>
17376 @@ -1255,12 +1259,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17377  
17378  #endif
17379  
17380 -#ifndef __alpha__
17381 -
17382 -/*
17383 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17384 - * should be moved into arch/i386 instead?
17385 - */
17386  
17387  /**
17388   * sys_getpid - return the thread group id of the current process
17389 @@ -1289,10 +1287,23 @@ SYSCALL_DEFINE0(getppid)
17390         rcu_read_lock();
17391         pid = task_tgid_vnr(current->real_parent);
17392         rcu_read_unlock();
17393 +       return vx_map_pid(pid);
17394 +}
17395  
17396 -       return pid;
17397 +#ifdef __alpha__
17398 +
17399 +/*
17400 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17401 + */
17402 +
17403 +asmlinkage long do_getxpid(long *ppid)
17404 +{
17405 +       *ppid = sys_getppid();
17406 +       return sys_getpid();
17407  }
17408  
17409 +#else /* _alpha_ */
17410 +
17411  SYSCALL_DEFINE0(getuid)
17412  {
17413         /* Only we change this so SMP safe */
17414 diff -NurpP --minimal linux-2.6.32.24/kernel/user.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/user.c
17415 --- linux-2.6.32.24/kernel/user.c       2009-12-03 20:02:58.000000000 +0100
17416 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/user.c       2009-12-03 20:04:56.000000000 +0100
17417 @@ -251,10 +251,10 @@ static struct kobj_type uids_ktype = {
17418   *
17419   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
17420   */
17421 -static int uids_user_create(struct user_struct *up)
17422 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
17423  {
17424         struct kobject *kobj = &up->kobj;
17425 -       int error;
17426 +       int error = 0;
17427  
17428         memset(kobj, 0, sizeof(struct kobject));
17429         if (up->user_ns != &init_user_ns)
17430 @@ -282,7 +282,7 @@ int __init uids_sysfs_init(void)
17431         if (!uids_kset)
17432                 return -ENOMEM;
17433  
17434 -       return uids_user_create(&root_user);
17435 +       return uids_user_create(NULL, &root_user);
17436  }
17437  
17438  /* delayed work function to remove sysfs directory for a user and free up
17439 @@ -353,7 +353,8 @@ static struct user_struct *uid_hash_find
17440  }
17441  
17442  int uids_sysfs_init(void) { return 0; }
17443 -static inline int uids_user_create(struct user_struct *up) { return 0; }
17444 +static inline int uids_user_create(struct user_namespace *ns,
17445 +       struct user_struct *up) { return 0; }
17446  static inline void uids_mutex_lock(void) { }
17447  static inline void uids_mutex_unlock(void) { }
17448  
17449 @@ -450,7 +451,7 @@ struct user_struct *alloc_uid(struct use
17450  
17451                 new->user_ns = get_user_ns(ns);
17452  
17453 -               if (uids_user_create(new))
17454 +               if (uids_user_create(ns, new))
17455                         goto out_destoy_sched;
17456  
17457                 /*
17458 diff -NurpP --minimal linux-2.6.32.24/kernel/user_namespace.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/user_namespace.c
17459 --- linux-2.6.32.24/kernel/user_namespace.c     2009-03-24 14:22:45.000000000 +0100
17460 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/user_namespace.c     2009-12-03 20:04:56.000000000 +0100
17461 @@ -10,6 +10,7 @@
17462  #include <linux/slab.h>
17463  #include <linux/user_namespace.h>
17464  #include <linux/cred.h>
17465 +#include <linux/vserver/global.h>
17466  
17467  /*
17468   * Create a new user namespace, deriving the creator from the user in the
17469 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
17470                 return -ENOMEM;
17471  
17472         kref_init(&ns->kref);
17473 +       atomic_inc(&vs_global_user_ns);
17474  
17475         for (n = 0; n < UIDHASH_SZ; ++n)
17476                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17477 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
17478         struct user_namespace *ns =
17479                 container_of(kref, struct user_namespace, kref);
17480  
17481 +       /* FIXME: maybe move into destroyer? */
17482 +       atomic_dec(&vs_global_user_ns);
17483         INIT_WORK(&ns->destroyer, free_user_ns_work);
17484         schedule_work(&ns->destroyer);
17485  }
17486 diff -NurpP --minimal linux-2.6.32.24/kernel/utsname.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/utsname.c
17487 --- linux-2.6.32.24/kernel/utsname.c    2009-09-10 15:26:28.000000000 +0200
17488 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/utsname.c    2009-12-03 20:04:56.000000000 +0100
17489 @@ -14,14 +14,17 @@
17490  #include <linux/utsname.h>
17491  #include <linux/err.h>
17492  #include <linux/slab.h>
17493 +#include <linux/vserver/global.h>
17494  
17495  static struct uts_namespace *create_uts_ns(void)
17496  {
17497         struct uts_namespace *uts_ns;
17498  
17499         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
17500 -       if (uts_ns)
17501 +       if (uts_ns) {
17502                 kref_init(&uts_ns->kref);
17503 +               atomic_inc(&vs_global_uts_ns);
17504 +       }
17505         return uts_ns;
17506  }
17507  
17508 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
17509         struct uts_namespace *ns;
17510  
17511         ns = container_of(kref, struct uts_namespace, kref);
17512 +       atomic_dec(&vs_global_uts_ns);
17513         kfree(ns);
17514  }
17515 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/cacct.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cacct.c
17516 --- linux-2.6.32.24/kernel/vserver/cacct.c      1970-01-01 01:00:00.000000000 +0100
17517 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cacct.c      2009-12-03 20:04:56.000000000 +0100
17518 @@ -0,0 +1,42 @@
17519 +/*
17520 + *  linux/kernel/vserver/cacct.c
17521 + *
17522 + *  Virtual Server: Context Accounting
17523 + *
17524 + *  Copyright (C) 2006-2007 Herbert Pötzl
17525 + *
17526 + *  V0.01  added accounting stats
17527 + *
17528 + */
17529 +
17530 +#include <linux/types.h>
17531 +#include <linux/vs_context.h>
17532 +#include <linux/vserver/cacct_cmd.h>
17533 +#include <linux/vserver/cacct_int.h>
17534 +
17535 +#include <asm/errno.h>
17536 +#include <asm/uaccess.h>
17537 +
17538 +
17539 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17540 +{
17541 +       struct vcmd_sock_stat_v0 vc_data;
17542 +       int j, field;
17543 +
17544 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17545 +               return -EFAULT;
17546 +
17547 +       field = vc_data.field;
17548 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17549 +               return -EINVAL;
17550 +
17551 +       for (j = 0; j < 3; j++) {
17552 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17553 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17554 +       }
17555 +
17556 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17557 +               return -EFAULT;
17558 +       return 0;
17559 +}
17560 +
17561 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/cacct_init.h linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cacct_init.h
17562 --- linux-2.6.32.24/kernel/vserver/cacct_init.h 1970-01-01 01:00:00.000000000 +0100
17563 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cacct_init.h 2009-12-03 20:04:56.000000000 +0100
17564 @@ -0,0 +1,25 @@
17565 +
17566 +
17567 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17568 +{
17569 +       int i, j;
17570 +
17571 +
17572 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17573 +               for (j = 0; j < 3; j++) {
17574 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
17575 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
17576 +               }
17577 +       }
17578 +       for (i = 0; i < 8; i++)
17579 +               atomic_set(&cacct->slab[i], 0);
17580 +       for (i = 0; i < 5; i++)
17581 +               for (j = 0; j < 4; j++)
17582 +                       atomic_set(&cacct->page[i][j], 0);
17583 +}
17584 +
17585 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17586 +{
17587 +       return;
17588 +}
17589 +
17590 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/cacct_proc.h linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cacct_proc.h
17591 --- linux-2.6.32.24/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00.000000000 +0100
17592 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cacct_proc.h 2009-12-03 20:04:56.000000000 +0100
17593 @@ -0,0 +1,53 @@
17594 +#ifndef _VX_CACCT_PROC_H
17595 +#define _VX_CACCT_PROC_H
17596 +
17597 +#include <linux/vserver/cacct_int.h>
17598 +
17599 +
17600 +#define VX_SOCKA_TOP   \
17601 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17602 +
17603 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17604 +{
17605 +       int i, j, length = 0;
17606 +       static char *type[VXA_SOCK_SIZE] = {
17607 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17608 +       };
17609 +
17610 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17611 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17612 +               length += sprintf(buffer + length, "%s:", type[i]);
17613 +               for (j = 0; j < 3; j++) {
17614 +                       length += sprintf(buffer + length,
17615 +                               "\t%10lu/%-10lu",
17616 +                               vx_sock_count(cacct, i, j),
17617 +                               vx_sock_total(cacct, i, j));
17618 +               }
17619 +               buffer[length++] = '\n';
17620 +       }
17621 +
17622 +       length += sprintf(buffer + length, "\n");
17623 +       length += sprintf(buffer + length,
17624 +               "slab:\t %8u %8u %8u %8u\n",
17625 +               atomic_read(&cacct->slab[1]),
17626 +               atomic_read(&cacct->slab[4]),
17627 +               atomic_read(&cacct->slab[0]),
17628 +               atomic_read(&cacct->slab[2]));
17629 +
17630 +       length += sprintf(buffer + length, "\n");
17631 +       for (i = 0; i < 5; i++) {
17632 +               length += sprintf(buffer + length,
17633 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17634 +                       atomic_read(&cacct->page[i][0]),
17635 +                       atomic_read(&cacct->page[i][1]),
17636 +                       atomic_read(&cacct->page[i][2]),
17637 +                       atomic_read(&cacct->page[i][3]),
17638 +                       atomic_read(&cacct->page[i][4]),
17639 +                       atomic_read(&cacct->page[i][5]),
17640 +                       atomic_read(&cacct->page[i][6]),
17641 +                       atomic_read(&cacct->page[i][7]));
17642 +       }
17643 +       return length;
17644 +}
17645 +
17646 +#endif /* _VX_CACCT_PROC_H */
17647 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/context.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/context.c
17648 --- linux-2.6.32.24/kernel/vserver/context.c    1970-01-01 01:00:00.000000000 +0100
17649 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/context.c    2010-03-13 21:49:35.000000000 +0100
17650 @@ -0,0 +1,1058 @@
17651 +/*
17652 + *  linux/kernel/vserver/context.c
17653 + *
17654 + *  Virtual Server: Context Support
17655 + *
17656 + *  Copyright (C) 2003-2007  Herbert Pötzl
17657 + *
17658 + *  V0.01  context helper
17659 + *  V0.02  vx_ctx_kill syscall command
17660 + *  V0.03  replaced context_info calls
17661 + *  V0.04  redesign of struct (de)alloc
17662 + *  V0.05  rlimit basic implementation
17663 + *  V0.06  task_xid and info commands
17664 + *  V0.07  context flags and caps
17665 + *  V0.08  switch to RCU based hash
17666 + *  V0.09  revert to non RCU for now
17667 + *  V0.10  and back to working RCU hash
17668 + *  V0.11  and back to locking again
17669 + *  V0.12  referenced context store
17670 + *  V0.13  separate per cpu data
17671 + *  V0.14  changed vcmds to vxi arg
17672 + *  V0.15  added context stat
17673 + *  V0.16  have __create claim() the vxi
17674 + *  V0.17  removed older and legacy stuff
17675 + *
17676 + */
17677 +
17678 +#include <linux/slab.h>
17679 +#include <linux/types.h>
17680 +#include <linux/security.h>
17681 +#include <linux/pid_namespace.h>
17682 +
17683 +#include <linux/vserver/context.h>
17684 +#include <linux/vserver/network.h>
17685 +#include <linux/vserver/debug.h>
17686 +#include <linux/vserver/limit.h>
17687 +#include <linux/vserver/limit_int.h>
17688 +#include <linux/vserver/space.h>
17689 +#include <linux/init_task.h>
17690 +#include <linux/fs_struct.h>
17691 +
17692 +#include <linux/vs_context.h>
17693 +#include <linux/vs_limit.h>
17694 +#include <linux/vs_pid.h>
17695 +#include <linux/vserver/context_cmd.h>
17696 +
17697 +#include "cvirt_init.h"
17698 +#include "cacct_init.h"
17699 +#include "limit_init.h"
17700 +#include "sched_init.h"
17701 +
17702 +
17703 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17704 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17705 +
17706 +
17707 +/*     now inactive context structures */
17708 +
17709 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17710 +
17711 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17712 +
17713 +
17714 +/*     __alloc_vx_info()
17715 +
17716 +       * allocate an initialized vx_info struct
17717 +       * doesn't make it visible (hash)                        */
17718 +
17719 +static struct vx_info *__alloc_vx_info(xid_t xid)
17720 +{
17721 +       struct vx_info *new = NULL;
17722 +       int cpu, index;
17723 +
17724 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17725 +
17726 +       /* would this benefit from a slab cache? */
17727 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17728 +       if (!new)
17729 +               return 0;
17730 +
17731 +       memset(new, 0, sizeof(struct vx_info));
17732 +#ifdef CONFIG_SMP
17733 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17734 +       if (!new->ptr_pc)
17735 +               goto error;
17736 +#endif
17737 +       new->vx_id = xid;
17738 +       INIT_HLIST_NODE(&new->vx_hlist);
17739 +       atomic_set(&new->vx_usecnt, 0);
17740 +       atomic_set(&new->vx_tasks, 0);
17741 +       new->vx_parent = NULL;
17742 +       new->vx_state = 0;
17743 +       init_waitqueue_head(&new->vx_wait);
17744 +
17745 +       /* prepare reaper */
17746 +       get_task_struct(init_pid_ns.child_reaper);
17747 +       new->vx_reaper = init_pid_ns.child_reaper;
17748 +       new->vx_badness_bias = 0;
17749 +
17750 +       /* rest of init goes here */
17751 +       vx_info_init_limit(&new->limit);
17752 +       vx_info_init_sched(&new->sched);
17753 +       vx_info_init_cvirt(&new->cvirt);
17754 +       vx_info_init_cacct(&new->cacct);
17755 +
17756 +       /* per cpu data structures */
17757 +       for_each_possible_cpu(cpu) {
17758 +               vx_info_init_sched_pc(
17759 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17760 +               vx_info_init_cvirt_pc(
17761 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17762 +       }
17763 +
17764 +       new->vx_flags = VXF_INIT_SET;
17765 +       cap_set_init_eff(new->vx_bcaps);
17766 +       new->vx_ccaps = 0;
17767 +       new->vx_umask = 0;
17768 +
17769 +       new->reboot_cmd = 0;
17770 +       new->exit_code = 0;
17771 +
17772 +       // preconfig fs entries
17773 +       for (index = 0; index < VX_SPACES; index++) {
17774 +               write_lock(&init_fs.lock);
17775 +               init_fs.users++;
17776 +               write_unlock(&init_fs.lock);
17777 +               new->vx_fs[index] = &init_fs;
17778 +       }
17779 +
17780 +       vxdprintk(VXD_CBIT(xid, 0),
17781 +               "alloc_vx_info(%d) = %p", xid, new);
17782 +       vxh_alloc_vx_info(new);
17783 +       atomic_inc(&vx_global_ctotal);
17784 +       return new;
17785 +#ifdef CONFIG_SMP
17786 +error:
17787 +       kfree(new);
17788 +       return 0;
17789 +#endif
17790 +}
17791 +
17792 +/*     __dealloc_vx_info()
17793 +
17794 +       * final disposal of vx_info                             */
17795 +
17796 +static void __dealloc_vx_info(struct vx_info *vxi)
17797 +{
17798 +#ifdef CONFIG_VSERVER_WARN
17799 +       struct vx_info_save vxis;
17800 +       int cpu;
17801 +#endif
17802 +       vxdprintk(VXD_CBIT(xid, 0),
17803 +               "dealloc_vx_info(%p)", vxi);
17804 +       vxh_dealloc_vx_info(vxi);
17805 +
17806 +#ifdef CONFIG_VSERVER_WARN
17807 +       enter_vx_info(vxi, &vxis);
17808 +       vx_info_exit_limit(&vxi->limit);
17809 +       vx_info_exit_sched(&vxi->sched);
17810 +       vx_info_exit_cvirt(&vxi->cvirt);
17811 +       vx_info_exit_cacct(&vxi->cacct);
17812 +
17813 +       for_each_possible_cpu(cpu) {
17814 +               vx_info_exit_sched_pc(
17815 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17816 +               vx_info_exit_cvirt_pc(
17817 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17818 +       }
17819 +       leave_vx_info(&vxis);
17820 +#endif
17821 +
17822 +       vxi->vx_id = -1;
17823 +       vxi->vx_state |= VXS_RELEASED;
17824 +
17825 +#ifdef CONFIG_SMP
17826 +       free_percpu(vxi->ptr_pc);
17827 +#endif
17828 +       kfree(vxi);
17829 +       atomic_dec(&vx_global_ctotal);
17830 +}
17831 +
17832 +static void __shutdown_vx_info(struct vx_info *vxi)
17833 +{
17834 +       struct nsproxy *nsproxy;
17835 +       struct fs_struct *fs;
17836 +       int index, kill;
17837 +
17838 +       might_sleep();
17839 +
17840 +       vxi->vx_state |= VXS_SHUTDOWN;
17841 +       vs_state_change(vxi, VSC_SHUTDOWN);
17842 +
17843 +       for (index = 0; index < VX_SPACES; index++) {
17844 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17845 +               if (nsproxy)
17846 +                       put_nsproxy(nsproxy);
17847 +
17848 +               fs = xchg(&vxi->vx_fs[index], NULL);
17849 +               write_lock(&fs->lock);
17850 +               kill = !--fs->users;
17851 +               write_unlock(&fs->lock);
17852 +               if (kill)
17853 +                       free_fs_struct(fs);
17854 +       }
17855 +}
17856 +
17857 +/* exported stuff */
17858 +
17859 +void free_vx_info(struct vx_info *vxi)
17860 +{
17861 +       unsigned long flags;
17862 +       unsigned index;
17863 +
17864 +       /* check for reference counts first */
17865 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17866 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17867 +
17868 +       /* context must not be hashed */
17869 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17870 +
17871 +       /* context shutdown is mandatory */
17872 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17873 +
17874 +       /* nsproxy and fs check */
17875 +       for (index = 0; index < VX_SPACES; index++) {
17876 +               BUG_ON(vxi->vx_nsproxy[index]);
17877 +               BUG_ON(vxi->vx_fs[index]);
17878 +       }
17879 +
17880 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17881 +       hlist_del(&vxi->vx_hlist);
17882 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17883 +
17884 +       __dealloc_vx_info(vxi);
17885 +}
17886 +
17887 +
17888 +/*     hash table for vx_info hash */
17889 +
17890 +#define VX_HASH_SIZE   13
17891 +
17892 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17893 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17894 +
17895 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17896 +
17897 +
17898 +static inline unsigned int __hashval(xid_t xid)
17899 +{
17900 +       return (xid % VX_HASH_SIZE);
17901 +}
17902 +
17903 +
17904 +
17905 +/*     __hash_vx_info()
17906 +
17907 +       * add the vxi to the global hash table
17908 +       * requires the hash_lock to be held                     */
17909 +
17910 +static inline void __hash_vx_info(struct vx_info *vxi)
17911 +{
17912 +       struct hlist_head *head;
17913 +
17914 +       vxd_assert_lock(&vx_info_hash_lock);
17915 +       vxdprintk(VXD_CBIT(xid, 4),
17916 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17917 +       vxh_hash_vx_info(vxi);
17918 +
17919 +       /* context must not be hashed */
17920 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17921 +
17922 +       vxi->vx_state |= VXS_HASHED;
17923 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17924 +       hlist_add_head(&vxi->vx_hlist, head);
17925 +       atomic_inc(&vx_global_cactive);
17926 +}
17927 +
17928 +/*     __unhash_vx_info()
17929 +
17930 +       * remove the vxi from the global hash table
17931 +       * requires the hash_lock to be held                     */
17932 +
17933 +static inline void __unhash_vx_info(struct vx_info *vxi)
17934 +{
17935 +       unsigned long flags;
17936 +
17937 +       vxd_assert_lock(&vx_info_hash_lock);
17938 +       vxdprintk(VXD_CBIT(xid, 4),
17939 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17940 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17941 +       vxh_unhash_vx_info(vxi);
17942 +
17943 +       /* context must be hashed */
17944 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17945 +       /* but without tasks */
17946 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17947 +
17948 +       vxi->vx_state &= ~VXS_HASHED;
17949 +       hlist_del_init(&vxi->vx_hlist);
17950 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17951 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17952 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17953 +       atomic_dec(&vx_global_cactive);
17954 +}
17955 +
17956 +
17957 +/*     __lookup_vx_info()
17958 +
17959 +       * requires the hash_lock to be held
17960 +       * doesn't increment the vx_refcnt                       */
17961 +
17962 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17963 +{
17964 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17965 +       struct hlist_node *pos;
17966 +       struct vx_info *vxi;
17967 +
17968 +       vxd_assert_lock(&vx_info_hash_lock);
17969 +       hlist_for_each(pos, head) {
17970 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17971 +
17972 +               if (vxi->vx_id == xid)
17973 +                       goto found;
17974 +       }
17975 +       vxi = NULL;
17976 +found:
17977 +       vxdprintk(VXD_CBIT(xid, 0),
17978 +               "__lookup_vx_info(#%u): %p[#%u]",
17979 +               xid, vxi, vxi ? vxi->vx_id : 0);
17980 +       vxh_lookup_vx_info(vxi, xid);
17981 +       return vxi;
17982 +}
17983 +
17984 +
17985 +/*     __create_vx_info()
17986 +
17987 +       * create the requested context
17988 +       * get(), claim() and hash it                            */
17989 +
17990 +static struct vx_info *__create_vx_info(int id)
17991 +{
17992 +       struct vx_info *new, *vxi = NULL;
17993 +
17994 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17995 +
17996 +       if (!(new = __alloc_vx_info(id)))
17997 +               return ERR_PTR(-ENOMEM);
17998 +
17999 +       /* required to make dynamic xids unique */
18000 +       spin_lock(&vx_info_hash_lock);
18001 +
18002 +       /* static context requested */
18003 +       if ((vxi = __lookup_vx_info(id))) {
18004 +               vxdprintk(VXD_CBIT(xid, 0),
18005 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
18006 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18007 +                       vxi = ERR_PTR(-EBUSY);
18008 +               else
18009 +                       vxi = ERR_PTR(-EEXIST);
18010 +               goto out_unlock;
18011 +       }
18012 +       /* new context */
18013 +       vxdprintk(VXD_CBIT(xid, 0),
18014 +               "create_vx_info(%d) = %p (new)", id, new);
18015 +       claim_vx_info(new, NULL);
18016 +       __hash_vx_info(get_vx_info(new));
18017 +       vxi = new, new = NULL;
18018 +
18019 +out_unlock:
18020 +       spin_unlock(&vx_info_hash_lock);
18021 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
18022 +       if (new)
18023 +               __dealloc_vx_info(new);
18024 +       return vxi;
18025 +}
18026 +
18027 +
18028 +/*     exported stuff                                          */
18029 +
18030 +
18031 +void unhash_vx_info(struct vx_info *vxi)
18032 +{
18033 +       __shutdown_vx_info(vxi);
18034 +       spin_lock(&vx_info_hash_lock);
18035 +       __unhash_vx_info(vxi);
18036 +       spin_unlock(&vx_info_hash_lock);
18037 +       __wakeup_vx_info(vxi);
18038 +}
18039 +
18040 +
18041 +/*     lookup_vx_info()
18042 +
18043 +       * search for a vx_info and get() it
18044 +       * negative id means current                             */
18045 +
18046 +struct vx_info *lookup_vx_info(int id)
18047 +{
18048 +       struct vx_info *vxi = NULL;
18049 +
18050 +       if (id < 0) {
18051 +               vxi = get_vx_info(current_vx_info());
18052 +       } else if (id > 1) {
18053 +               spin_lock(&vx_info_hash_lock);
18054 +               vxi = get_vx_info(__lookup_vx_info(id));
18055 +               spin_unlock(&vx_info_hash_lock);
18056 +       }
18057 +       return vxi;
18058 +}
18059 +
18060 +/*     xid_is_hashed()
18061 +
18062 +       * verify that xid is still hashed                       */
18063 +
18064 +int xid_is_hashed(xid_t xid)
18065 +{
18066 +       int hashed;
18067 +
18068 +       spin_lock(&vx_info_hash_lock);
18069 +       hashed = (__lookup_vx_info(xid) != NULL);
18070 +       spin_unlock(&vx_info_hash_lock);
18071 +       return hashed;
18072 +}
18073 +
18074 +#ifdef CONFIG_PROC_FS
18075 +
18076 +/*     get_xid_list()
18077 +
18078 +       * get a subset of hashed xids for proc
18079 +       * assumes size is at least one                          */
18080 +
18081 +int get_xid_list(int index, unsigned int *xids, int size)
18082 +{
18083 +       int hindex, nr_xids = 0;
18084 +
18085 +       /* only show current and children */
18086 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18087 +               if (index > 0)
18088 +                       return 0;
18089 +               xids[nr_xids] = vx_current_xid();
18090 +               return 1;
18091 +       }
18092 +
18093 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18094 +               struct hlist_head *head = &vx_info_hash[hindex];
18095 +               struct hlist_node *pos;
18096 +
18097 +               spin_lock(&vx_info_hash_lock);
18098 +               hlist_for_each(pos, head) {
18099 +                       struct vx_info *vxi;
18100 +
18101 +                       if (--index > 0)
18102 +                               continue;
18103 +
18104 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18105 +                       xids[nr_xids] = vxi->vx_id;
18106 +                       if (++nr_xids >= size) {
18107 +                               spin_unlock(&vx_info_hash_lock);
18108 +                               goto out;
18109 +                       }
18110 +               }
18111 +               /* keep the lock time short */
18112 +               spin_unlock(&vx_info_hash_lock);
18113 +       }
18114 +out:
18115 +       return nr_xids;
18116 +}
18117 +#endif
18118 +
18119 +#ifdef CONFIG_VSERVER_DEBUG
18120 +
18121 +void   dump_vx_info_inactive(int level)
18122 +{
18123 +       struct hlist_node *entry, *next;
18124 +
18125 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18126 +               struct vx_info *vxi =
18127 +                       list_entry(entry, struct vx_info, vx_hlist);
18128 +
18129 +               dump_vx_info(vxi, level);
18130 +       }
18131 +}
18132 +
18133 +#endif
18134 +
18135 +#if 0
18136 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18137 +{
18138 +       struct user_struct *new_user, *old_user;
18139 +
18140 +       if (!p || !vxi)
18141 +               BUG();
18142 +
18143 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18144 +               return -EACCES;
18145 +
18146 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18147 +       if (!new_user)
18148 +               return -ENOMEM;
18149 +
18150 +       old_user = p->user;
18151 +       if (new_user != old_user) {
18152 +               atomic_inc(&new_user->processes);
18153 +               atomic_dec(&old_user->processes);
18154 +               p->user = new_user;
18155 +       }
18156 +       free_uid(old_user);
18157 +       return 0;
18158 +}
18159 +#endif
18160 +
18161 +#if 0
18162 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18163 +{
18164 +       // p->cap_effective &= vxi->vx_cap_bset;
18165 +       p->cap_effective =
18166 +               cap_intersect(p->cap_effective, vxi->cap_bset);
18167 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18168 +       p->cap_inheritable =
18169 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18170 +       // p->cap_permitted &= vxi->vx_cap_bset;
18171 +       p->cap_permitted =
18172 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18173 +}
18174 +#endif
18175 +
18176 +
18177 +#include <linux/file.h>
18178 +#include <linux/fdtable.h>
18179 +
18180 +static int vx_openfd_task(struct task_struct *tsk)
18181 +{
18182 +       struct files_struct *files = tsk->files;
18183 +       struct fdtable *fdt;
18184 +       const unsigned long *bptr;
18185 +       int count, total;
18186 +
18187 +       /* no rcu_read_lock() because of spin_lock() */
18188 +       spin_lock(&files->file_lock);
18189 +       fdt = files_fdtable(files);
18190 +       bptr = fdt->open_fds->fds_bits;
18191 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18192 +       for (total = 0; count > 0; count--) {
18193 +               if (*bptr)
18194 +                       total += hweight_long(*bptr);
18195 +               bptr++;
18196 +       }
18197 +       spin_unlock(&files->file_lock);
18198 +       return total;
18199 +}
18200 +
18201 +
18202 +/*     for *space compatibility */
18203 +
18204 +asmlinkage long sys_unshare(unsigned long);
18205 +
18206 +/*
18207 + *     migrate task to new context
18208 + *     gets vxi, puts old_vxi on change
18209 + *     optionally unshares namespaces (hack)
18210 + */
18211 +
18212 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18213 +{
18214 +       struct vx_info *old_vxi;
18215 +       int ret = 0;
18216 +
18217 +       if (!p || !vxi)
18218 +               BUG();
18219 +
18220 +       vxdprintk(VXD_CBIT(xid, 5),
18221 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18222 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18223 +
18224 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18225 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18226 +               return -EACCES;
18227 +
18228 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18229 +               return -EFAULT;
18230 +
18231 +       old_vxi = task_get_vx_info(p);
18232 +       if (old_vxi == vxi)
18233 +               goto out;
18234 +
18235 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18236 +       {
18237 +               int openfd;
18238 +
18239 +               task_lock(p);
18240 +               openfd = vx_openfd_task(p);
18241 +
18242 +               if (old_vxi) {
18243 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18244 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18245 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18246 +                       /* FIXME: what about the struct files here? */
18247 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18248 +                       /* account for the executable */
18249 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18250 +               }
18251 +               atomic_inc(&vxi->cvirt.nr_threads);
18252 +               atomic_inc(&vxi->cvirt.nr_running);
18253 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18254 +               /* FIXME: what about the struct files here? */
18255 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18256 +               /* account for the executable */
18257 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18258 +
18259 +               if (old_vxi) {
18260 +                       release_vx_info(old_vxi, p);
18261 +                       clr_vx_info(&p->vx_info);
18262 +               }
18263 +               claim_vx_info(vxi, p);
18264 +               set_vx_info(&p->vx_info, vxi);
18265 +               p->xid = vxi->vx_id;
18266 +
18267 +               vxdprintk(VXD_CBIT(xid, 5),
18268 +                       "moved task %p into vxi:%p[#%d]",
18269 +                       p, vxi, vxi->vx_id);
18270 +
18271 +               // vx_mask_cap_bset(vxi, p);
18272 +               task_unlock(p);
18273 +
18274 +               /* hack for *spaces to provide compatibility */
18275 +               if (unshare) {
18276 +                       struct nsproxy *old_nsp, *new_nsp;
18277 +
18278 +                       ret = unshare_nsproxy_namespaces(
18279 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18280 +                               &new_nsp, NULL);
18281 +                       if (ret)
18282 +                               goto out;
18283 +
18284 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18285 +                       vx_set_space(vxi,
18286 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
18287 +                       put_nsproxy(old_nsp);
18288 +               }
18289 +       }
18290 +out:
18291 +       put_vx_info(old_vxi);
18292 +       return ret;
18293 +}
18294 +
18295 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18296 +{
18297 +       struct task_struct *old_reaper;
18298 +
18299 +       if (!vxi)
18300 +               return -EINVAL;
18301 +
18302 +       vxdprintk(VXD_CBIT(xid, 6),
18303 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18304 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18305 +
18306 +       old_reaper = vxi->vx_reaper;
18307 +       if (old_reaper == p)
18308 +               return 0;
18309 +
18310 +       /* set new child reaper */
18311 +       get_task_struct(p);
18312 +       vxi->vx_reaper = p;
18313 +       put_task_struct(old_reaper);
18314 +       return 0;
18315 +}
18316 +
18317 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18318 +{
18319 +       if (!vxi)
18320 +               return -EINVAL;
18321 +
18322 +       vxdprintk(VXD_CBIT(xid, 6),
18323 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18324 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18325 +
18326 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18327 +       // vxi->vx_initpid = p->tgid;
18328 +       vxi->vx_initpid = p->pid;
18329 +       return 0;
18330 +}
18331 +
18332 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18333 +{
18334 +       vxdprintk(VXD_CBIT(xid, 6),
18335 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18336 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18337 +
18338 +       vxi->exit_code = code;
18339 +       vxi->vx_initpid = 0;
18340 +}
18341 +
18342 +
18343 +void vx_set_persistent(struct vx_info *vxi)
18344 +{
18345 +       vxdprintk(VXD_CBIT(xid, 6),
18346 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18347 +
18348 +       get_vx_info(vxi);
18349 +       claim_vx_info(vxi, NULL);
18350 +}
18351 +
18352 +void vx_clear_persistent(struct vx_info *vxi)
18353 +{
18354 +       vxdprintk(VXD_CBIT(xid, 6),
18355 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18356 +
18357 +       release_vx_info(vxi, NULL);
18358 +       put_vx_info(vxi);
18359 +}
18360 +
18361 +void vx_update_persistent(struct vx_info *vxi)
18362 +{
18363 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18364 +               vx_set_persistent(vxi);
18365 +       else
18366 +               vx_clear_persistent(vxi);
18367 +}
18368 +
18369 +
18370 +/*     task must be current or locked          */
18371 +
18372 +void   exit_vx_info(struct task_struct *p, int code)
18373 +{
18374 +       struct vx_info *vxi = p->vx_info;
18375 +
18376 +       if (vxi) {
18377 +               atomic_dec(&vxi->cvirt.nr_threads);
18378 +               vx_nproc_dec(p);
18379 +
18380 +               vxi->exit_code = code;
18381 +               release_vx_info(vxi, p);
18382 +       }
18383 +}
18384 +
18385 +void   exit_vx_info_early(struct task_struct *p, int code)
18386 +{
18387 +       struct vx_info *vxi = p->vx_info;
18388 +
18389 +       if (vxi) {
18390 +               if (vxi->vx_initpid == p->pid)
18391 +                       vx_exit_init(vxi, p, code);
18392 +               if (vxi->vx_reaper == p)
18393 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18394 +       }
18395 +}
18396 +
18397 +
18398 +/* vserver syscall commands below here */
18399 +
18400 +/* taks xid and vx_info functions */
18401 +
18402 +#include <asm/uaccess.h>
18403 +
18404 +
18405 +int vc_task_xid(uint32_t id)
18406 +{
18407 +       xid_t xid;
18408 +
18409 +       if (id) {
18410 +               struct task_struct *tsk;
18411 +
18412 +               read_lock(&tasklist_lock);
18413 +               tsk = find_task_by_real_pid(id);
18414 +               xid = (tsk) ? tsk->xid : -ESRCH;
18415 +               read_unlock(&tasklist_lock);
18416 +       } else
18417 +               xid = vx_current_xid();
18418 +       return xid;
18419 +}
18420 +
18421 +
18422 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18423 +{
18424 +       struct vcmd_vx_info_v0 vc_data;
18425 +
18426 +       vc_data.xid = vxi->vx_id;
18427 +       vc_data.initpid = vxi->vx_initpid;
18428 +
18429 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18430 +               return -EFAULT;
18431 +       return 0;
18432 +}
18433 +
18434 +
18435 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18436 +{
18437 +       struct vcmd_ctx_stat_v0 vc_data;
18438 +
18439 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18440 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18441 +
18442 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18443 +               return -EFAULT;
18444 +       return 0;
18445 +}
18446 +
18447 +
18448 +/* context functions */
18449 +
18450 +int vc_ctx_create(uint32_t xid, void __user *data)
18451 +{
18452 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18453 +       struct vx_info *new_vxi;
18454 +       int ret;
18455 +
18456 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18457 +               return -EFAULT;
18458 +
18459 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18460 +               return -EINVAL;
18461 +
18462 +       new_vxi = __create_vx_info(xid);
18463 +       if (IS_ERR(new_vxi))
18464 +               return PTR_ERR(new_vxi);
18465 +
18466 +       /* initial flags */
18467 +       new_vxi->vx_flags = vc_data.flagword;
18468 +
18469 +       ret = -ENOEXEC;
18470 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18471 +               goto out;
18472 +
18473 +       ret = vx_migrate_task(current, new_vxi, (!data));
18474 +       if (ret)
18475 +               goto out;
18476 +
18477 +       /* return context id on success */
18478 +       ret = new_vxi->vx_id;
18479 +
18480 +       /* get a reference for persistent contexts */
18481 +       if ((vc_data.flagword & VXF_PERSISTENT))
18482 +               vx_set_persistent(new_vxi);
18483 +out:
18484 +       release_vx_info(new_vxi, NULL);
18485 +       put_vx_info(new_vxi);
18486 +       return ret;
18487 +}
18488 +
18489 +
18490 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18491 +{
18492 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18493 +       int ret;
18494 +
18495 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18496 +               return -EFAULT;
18497 +
18498 +       ret = vx_migrate_task(current, vxi, 0);
18499 +       if (ret)
18500 +               return ret;
18501 +       if (vc_data.flagword & VXM_SET_INIT)
18502 +               ret = vx_set_init(vxi, current);
18503 +       if (ret)
18504 +               return ret;
18505 +       if (vc_data.flagword & VXM_SET_REAPER)
18506 +               ret = vx_set_reaper(vxi, current);
18507 +       return ret;
18508 +}
18509 +
18510 +
18511 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18512 +{
18513 +       struct vcmd_ctx_flags_v0 vc_data;
18514 +
18515 +       vc_data.flagword = vxi->vx_flags;
18516 +
18517 +       /* special STATE flag handling */
18518 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18519 +
18520 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18521 +               return -EFAULT;
18522 +       return 0;
18523 +}
18524 +
18525 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18526 +{
18527 +       struct vcmd_ctx_flags_v0 vc_data;
18528 +       uint64_t mask, trigger;
18529 +
18530 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18531 +               return -EFAULT;
18532 +
18533 +       /* special STATE flag handling */
18534 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18535 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18536 +
18537 +       if (vxi == current_vx_info()) {
18538 +               /* if (trigger & VXF_STATE_SETUP)
18539 +                       vx_mask_cap_bset(vxi, current); */
18540 +               if (trigger & VXF_STATE_INIT) {
18541 +                       int ret;
18542 +
18543 +                       ret = vx_set_init(vxi, current);
18544 +                       if (ret)
18545 +                               return ret;
18546 +                       ret = vx_set_reaper(vxi, current);
18547 +                       if (ret)
18548 +                               return ret;
18549 +               }
18550 +       }
18551 +
18552 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18553 +               vc_data.flagword, mask);
18554 +       if (trigger & VXF_PERSISTENT)
18555 +               vx_update_persistent(vxi);
18556 +
18557 +       return 0;
18558 +}
18559 +
18560 +
18561 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18562 +{
18563 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18564 +
18565 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18566 +       return v;
18567 +}
18568 +
18569 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18570 +{
18571 +       kernel_cap_t c = __cap_empty_set;
18572 +
18573 +       c.cap[0] = v & 0xFFFFFFFF;
18574 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18575 +
18576 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18577 +       return c;
18578 +}
18579 +
18580 +
18581 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18582 +{
18583 +       if (bcaps)
18584 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18585 +       if (ccaps)
18586 +               *ccaps = vxi->vx_ccaps;
18587 +
18588 +       return 0;
18589 +}
18590 +
18591 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18592 +{
18593 +       struct vcmd_ctx_caps_v1 vc_data;
18594 +       int ret;
18595 +
18596 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18597 +       if (ret)
18598 +               return ret;
18599 +       vc_data.cmask = ~0ULL;
18600 +
18601 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18602 +               return -EFAULT;
18603 +       return 0;
18604 +}
18605 +
18606 +static int do_set_caps(struct vx_info *vxi,
18607 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18608 +{
18609 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18610 +
18611 +#if 0
18612 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18613 +               bcaps, bmask, ccaps, cmask);
18614 +#endif
18615 +       vxi->vx_bcaps = cap_t_from_caps(
18616 +               vs_mask_flags(bcold, bcaps, bmask));
18617 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18618 +
18619 +       return 0;
18620 +}
18621 +
18622 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18623 +{
18624 +       struct vcmd_ctx_caps_v1 vc_data;
18625 +
18626 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18627 +               return -EFAULT;
18628 +
18629 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18630 +}
18631 +
18632 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18633 +{
18634 +       struct vcmd_bcaps vc_data;
18635 +       int ret;
18636 +
18637 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18638 +       if (ret)
18639 +               return ret;
18640 +       vc_data.bmask = ~0ULL;
18641 +
18642 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18643 +               return -EFAULT;
18644 +       return 0;
18645 +}
18646 +
18647 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18648 +{
18649 +       struct vcmd_bcaps vc_data;
18650 +
18651 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18652 +               return -EFAULT;
18653 +
18654 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18655 +}
18656 +
18657 +
18658 +int vc_get_umask(struct vx_info *vxi, void __user *data)
18659 +{
18660 +       struct vcmd_umask vc_data;
18661 +
18662 +       vc_data.umask = vxi->vx_umask;
18663 +       vc_data.mask = ~0ULL;
18664 +
18665 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18666 +               return -EFAULT;
18667 +       return 0;
18668 +}
18669 +
18670 +int vc_set_umask(struct vx_info *vxi, void __user *data)
18671 +{
18672 +       struct vcmd_umask vc_data;
18673 +
18674 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18675 +               return -EFAULT;
18676 +
18677 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
18678 +               vc_data.umask, vc_data.mask);
18679 +       return 0;
18680 +}
18681 +
18682 +
18683 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18684 +{
18685 +       struct vcmd_badness_v0 vc_data;
18686 +
18687 +       vc_data.bias = vxi->vx_badness_bias;
18688 +
18689 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18690 +               return -EFAULT;
18691 +       return 0;
18692 +}
18693 +
18694 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18695 +{
18696 +       struct vcmd_badness_v0 vc_data;
18697 +
18698 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18699 +               return -EFAULT;
18700 +
18701 +       vxi->vx_badness_bias = vc_data.bias;
18702 +       return 0;
18703 +}
18704 +
18705 +#include <linux/module.h>
18706 +
18707 +EXPORT_SYMBOL_GPL(free_vx_info);
18708 +
18709 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/cvirt.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cvirt.c
18710 --- linux-2.6.32.24/kernel/vserver/cvirt.c      1970-01-01 01:00:00.000000000 +0100
18711 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cvirt.c      2009-12-03 20:04:56.000000000 +0100
18712 @@ -0,0 +1,304 @@
18713 +/*
18714 + *  linux/kernel/vserver/cvirt.c
18715 + *
18716 + *  Virtual Server: Context Virtualization
18717 + *
18718 + *  Copyright (C) 2004-2007  Herbert Pötzl
18719 + *
18720 + *  V0.01  broken out from limit.c
18721 + *  V0.02  added utsname stuff
18722 + *  V0.03  changed vcmds to vxi arg
18723 + *
18724 + */
18725 +
18726 +#include <linux/types.h>
18727 +#include <linux/utsname.h>
18728 +#include <linux/vs_cvirt.h>
18729 +#include <linux/vserver/switch.h>
18730 +#include <linux/vserver/cvirt_cmd.h>
18731 +
18732 +#include <asm/uaccess.h>
18733 +
18734 +
18735 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18736 +{
18737 +       struct vx_info *vxi = current_vx_info();
18738 +
18739 +       set_normalized_timespec(uptime,
18740 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18741 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18742 +       if (!idle)
18743 +               return;
18744 +       set_normalized_timespec(idle,
18745 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18746 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18747 +       return;
18748 +}
18749 +
18750 +uint64_t vx_idle_jiffies(void)
18751 +{
18752 +       return init_task.utime + init_task.stime;
18753 +}
18754 +
18755 +
18756 +
18757 +static inline uint32_t __update_loadavg(uint32_t load,
18758 +       int wsize, int delta, int n)
18759 +{
18760 +       unsigned long long calc, prev;
18761 +
18762 +       /* just set it to n */
18763 +       if (unlikely(delta >= wsize))
18764 +               return (n << FSHIFT);
18765 +
18766 +       calc = delta * n;
18767 +       calc <<= FSHIFT;
18768 +       prev = (wsize - delta);
18769 +       prev *= load;
18770 +       calc += prev;
18771 +       do_div(calc, wsize);
18772 +       return calc;
18773 +}
18774 +
18775 +
18776 +void vx_update_load(struct vx_info *vxi)
18777 +{
18778 +       uint32_t now, last, delta;
18779 +       unsigned int nr_running, nr_uninterruptible;
18780 +       unsigned int total;
18781 +       unsigned long flags;
18782 +
18783 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18784 +
18785 +       now = jiffies;
18786 +       last = vxi->cvirt.load_last;
18787 +       delta = now - last;
18788 +
18789 +       if (delta < 5*HZ)
18790 +               goto out;
18791 +
18792 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18793 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18794 +       total = nr_running + nr_uninterruptible;
18795 +
18796 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18797 +               60*HZ, delta, total);
18798 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18799 +               5*60*HZ, delta, total);
18800 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18801 +               15*60*HZ, delta, total);
18802 +
18803 +       vxi->cvirt.load_last = now;
18804 +out:
18805 +       atomic_inc(&vxi->cvirt.load_updates);
18806 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18807 +}
18808 +
18809 +
18810 +/*
18811 + * Commands to do_syslog:
18812 + *
18813 + *      0 -- Close the log.  Currently a NOP.
18814 + *      1 -- Open the log. Currently a NOP.
18815 + *      2 -- Read from the log.
18816 + *      3 -- Read all messages remaining in the ring buffer.
18817 + *      4 -- Read and clear all messages remaining in the ring buffer
18818 + *      5 -- Clear ring buffer.
18819 + *      6 -- Disable printk's to console
18820 + *      7 -- Enable printk's to console
18821 + *      8 -- Set level of messages printed to console
18822 + *      9 -- Return number of unread characters in the log buffer
18823 + *     10 -- Return size of the log buffer
18824 + */
18825 +int vx_do_syslog(int type, char __user *buf, int len)
18826 +{
18827 +       int error = 0;
18828 +       int do_clear = 0;
18829 +       struct vx_info *vxi = current_vx_info();
18830 +       struct _vx_syslog *log;
18831 +
18832 +       if (!vxi)
18833 +               return -EINVAL;
18834 +       log = &vxi->cvirt.syslog;
18835 +
18836 +       switch (type) {
18837 +       case 0:         /* Close log */
18838 +       case 1:         /* Open log */
18839 +               break;
18840 +       case 2:         /* Read from log */
18841 +               error = wait_event_interruptible(log->log_wait,
18842 +                       (log->log_start - log->log_end));
18843 +               if (error)
18844 +                       break;
18845 +               spin_lock_irq(&log->logbuf_lock);
18846 +               spin_unlock_irq(&log->logbuf_lock);
18847 +               break;
18848 +       case 4:         /* Read/clear last kernel messages */
18849 +               do_clear = 1;
18850 +               /* fall through */
18851 +       case 3:         /* Read last kernel messages */
18852 +               return 0;
18853 +
18854 +       case 5:         /* Clear ring buffer */
18855 +               return 0;
18856 +
18857 +       case 6:         /* Disable logging to console */
18858 +       case 7:         /* Enable logging to console */
18859 +       case 8:         /* Set level of messages printed to console */
18860 +               break;
18861 +
18862 +       case 9:         /* Number of chars in the log buffer */
18863 +               return 0;
18864 +       case 10:        /* Size of the log buffer */
18865 +               return 0;
18866 +       default:
18867 +               error = -EINVAL;
18868 +               break;
18869 +       }
18870 +       return error;
18871 +}
18872 +
18873 +
18874 +/* virtual host info names */
18875 +
18876 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18877 +{
18878 +       struct nsproxy *nsproxy;
18879 +       struct uts_namespace *uts;
18880 +
18881 +       if (id == VHIN_CONTEXT)
18882 +               return vxi->vx_name;
18883 +
18884 +       nsproxy = vxi->vx_nsproxy[0];
18885 +       if (!nsproxy)
18886 +               return NULL;
18887 +
18888 +       uts = nsproxy->uts_ns;
18889 +       if (!uts)
18890 +               return NULL;
18891 +
18892 +       switch (id) {
18893 +       case VHIN_SYSNAME:
18894 +               return uts->name.sysname;
18895 +       case VHIN_NODENAME:
18896 +               return uts->name.nodename;
18897 +       case VHIN_RELEASE:
18898 +               return uts->name.release;
18899 +       case VHIN_VERSION:
18900 +               return uts->name.version;
18901 +       case VHIN_MACHINE:
18902 +               return uts->name.machine;
18903 +       case VHIN_DOMAINNAME:
18904 +               return uts->name.domainname;
18905 +       default:
18906 +               return NULL;
18907 +       }
18908 +       return NULL;
18909 +}
18910 +
18911 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18912 +{
18913 +       struct vcmd_vhi_name_v0 vc_data;
18914 +       char *name;
18915 +
18916 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18917 +               return -EFAULT;
18918 +
18919 +       name = vx_vhi_name(vxi, vc_data.field);
18920 +       if (!name)
18921 +               return -EINVAL;
18922 +
18923 +       memcpy(name, vc_data.name, 65);
18924 +       return 0;
18925 +}
18926 +
18927 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18928 +{
18929 +       struct vcmd_vhi_name_v0 vc_data;
18930 +       char *name;
18931 +
18932 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18933 +               return -EFAULT;
18934 +
18935 +       name = vx_vhi_name(vxi, vc_data.field);
18936 +       if (!name)
18937 +               return -EINVAL;
18938 +
18939 +       memcpy(vc_data.name, name, 65);
18940 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18941 +               return -EFAULT;
18942 +       return 0;
18943 +}
18944 +
18945 +
18946 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18947 +{
18948 +       struct vcmd_virt_stat_v0 vc_data;
18949 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18950 +       struct timespec uptime;
18951 +
18952 +       do_posix_clock_monotonic_gettime(&uptime);
18953 +       set_normalized_timespec(&uptime,
18954 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18955 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18956 +
18957 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18958 +       vc_data.uptime = timespec_to_ns(&uptime);
18959 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18960 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18961 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18962 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18963 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18964 +       vc_data.load[0] = cvirt->load[0];
18965 +       vc_data.load[1] = cvirt->load[1];
18966 +       vc_data.load[2] = cvirt->load[2];
18967 +
18968 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18969 +               return -EFAULT;
18970 +       return 0;
18971 +}
18972 +
18973 +
18974 +#ifdef CONFIG_VSERVER_VTIME
18975 +
18976 +/* virtualized time base */
18977 +
18978 +void vx_gettimeofday(struct timeval *tv)
18979 +{
18980 +       struct vx_info *vxi;
18981 +
18982 +       do_gettimeofday(tv);
18983 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18984 +               return;
18985 +
18986 +       vxi = current_vx_info();
18987 +       tv->tv_sec += vxi->cvirt.bias_tv.tv_sec;
18988 +       tv->tv_usec += vxi->cvirt.bias_tv.tv_usec;
18989 +
18990 +       if (tv->tv_usec >= USEC_PER_SEC) {
18991 +               tv->tv_sec++;
18992 +               tv->tv_usec -= USEC_PER_SEC;
18993 +       } else if (tv->tv_usec < 0) {
18994 +               tv->tv_sec--;
18995 +               tv->tv_usec += USEC_PER_SEC;
18996 +       }
18997 +}
18998 +
18999 +int vx_settimeofday(struct timespec *ts)
19000 +{
19001 +       struct timeval tv;
19002 +       struct vx_info *vxi;
19003 +
19004 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19005 +               return do_settimeofday(ts);
19006 +
19007 +       do_gettimeofday(&tv);
19008 +       vxi = current_vx_info();
19009 +       vxi->cvirt.bias_tv.tv_sec = ts->tv_sec - tv.tv_sec;
19010 +       vxi->cvirt.bias_tv.tv_usec =
19011 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
19012 +       return 0;
19013 +}
19014 +
19015 +#endif
19016 +
19017 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/cvirt_init.h linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cvirt_init.h
19018 --- linux-2.6.32.24/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00.000000000 +0100
19019 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cvirt_init.h 2009-12-03 20:04:56.000000000 +0100
19020 @@ -0,0 +1,69 @@
19021 +
19022 +
19023 +extern uint64_t vx_idle_jiffies(void);
19024 +
19025 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
19026 +{
19027 +       uint64_t idle_jiffies = vx_idle_jiffies();
19028 +       uint64_t nsuptime;
19029 +
19030 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
19031 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
19032 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
19033 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
19034 +       cvirt->bias_tv.tv_sec = 0;
19035 +       cvirt->bias_tv.tv_usec = 0;
19036 +
19037 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
19038 +       atomic_set(&cvirt->nr_threads, 0);
19039 +       atomic_set(&cvirt->nr_running, 0);
19040 +       atomic_set(&cvirt->nr_uninterruptible, 0);
19041 +       atomic_set(&cvirt->nr_onhold, 0);
19042 +
19043 +       spin_lock_init(&cvirt->load_lock);
19044 +       cvirt->load_last = jiffies;
19045 +       atomic_set(&cvirt->load_updates, 0);
19046 +       cvirt->load[0] = 0;
19047 +       cvirt->load[1] = 0;
19048 +       cvirt->load[2] = 0;
19049 +       atomic_set(&cvirt->total_forks, 0);
19050 +
19051 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
19052 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19053 +       cvirt->syslog.log_start = 0;
19054 +       cvirt->syslog.log_end = 0;
19055 +       cvirt->syslog.con_start = 0;
19056 +       cvirt->syslog.logged_chars = 0;
19057 +}
19058 +
19059 +static inline
19060 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19061 +{
19062 +       // cvirt_pc->cpustat = { 0 };
19063 +}
19064 +
19065 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19066 +{
19067 +       int value;
19068 +
19069 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19070 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19071 +               cvirt, value);
19072 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19073 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19074 +               cvirt, value);
19075 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19076 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19077 +               cvirt, value);
19078 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19079 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19080 +               cvirt, value);
19081 +       return;
19082 +}
19083 +
19084 +static inline
19085 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19086 +{
19087 +       return;
19088 +}
19089 +
19090 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/cvirt_proc.h linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cvirt_proc.h
19091 --- linux-2.6.32.24/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00.000000000 +0100
19092 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/cvirt_proc.h 2009-12-03 20:04:56.000000000 +0100
19093 @@ -0,0 +1,135 @@
19094 +#ifndef _VX_CVIRT_PROC_H
19095 +#define _VX_CVIRT_PROC_H
19096 +
19097 +#include <linux/nsproxy.h>
19098 +#include <linux/mnt_namespace.h>
19099 +#include <linux/ipc_namespace.h>
19100 +#include <linux/utsname.h>
19101 +#include <linux/ipc.h>
19102 +
19103 +
19104 +static inline
19105 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19106 +{
19107 +       struct mnt_namespace *ns;
19108 +       struct uts_namespace *uts;
19109 +       struct ipc_namespace *ipc;
19110 +       struct path path;
19111 +       char *pstr, *root;
19112 +       int length = 0;
19113 +
19114 +       if (!nsproxy)
19115 +               goto out;
19116 +
19117 +       length += sprintf(buffer + length,
19118 +               "NSProxy:\t%p [%p,%p,%p]\n",
19119 +               nsproxy, nsproxy->mnt_ns,
19120 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19121 +
19122 +       ns = nsproxy->mnt_ns;
19123 +       if (!ns)
19124 +               goto skip_ns;
19125 +
19126 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
19127 +       if (!pstr)
19128 +               goto skip_ns;
19129 +
19130 +       path.mnt = ns->root;
19131 +       path.dentry = ns->root->mnt_root;
19132 +       root = d_path(&path, pstr, PATH_MAX - 2);
19133 +       length += sprintf(buffer + length,
19134 +               "Namespace:\t%p [#%u]\n"
19135 +               "RootPath:\t%s\n",
19136 +               ns, atomic_read(&ns->count),
19137 +               root);
19138 +       kfree(pstr);
19139 +skip_ns:
19140 +
19141 +       uts = nsproxy->uts_ns;
19142 +       if (!uts)
19143 +               goto skip_uts;
19144 +
19145 +       length += sprintf(buffer + length,
19146 +               "SysName:\t%.*s\n"
19147 +               "NodeName:\t%.*s\n"
19148 +               "Release:\t%.*s\n"
19149 +               "Version:\t%.*s\n"
19150 +               "Machine:\t%.*s\n"
19151 +               "DomainName:\t%.*s\n",
19152 +               __NEW_UTS_LEN, uts->name.sysname,
19153 +               __NEW_UTS_LEN, uts->name.nodename,
19154 +               __NEW_UTS_LEN, uts->name.release,
19155 +               __NEW_UTS_LEN, uts->name.version,
19156 +               __NEW_UTS_LEN, uts->name.machine,
19157 +               __NEW_UTS_LEN, uts->name.domainname);
19158 +skip_uts:
19159 +
19160 +       ipc = nsproxy->ipc_ns;
19161 +       if (!ipc)
19162 +               goto skip_ipc;
19163 +
19164 +       length += sprintf(buffer + length,
19165 +               "SEMS:\t\t%d %d %d %d  %d\n"
19166 +               "MSG:\t\t%d %d %d\n"
19167 +               "SHM:\t\t%lu %lu  %d %d\n",
19168 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19169 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19170 +               ipc->used_sems,
19171 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19172 +               (unsigned long)ipc->shm_ctlmax,
19173 +               (unsigned long)ipc->shm_ctlall,
19174 +               ipc->shm_ctlmni, ipc->shm_tot);
19175 +skip_ipc:
19176 +out:
19177 +       return length;
19178 +}
19179 +
19180 +
19181 +#include <linux/sched.h>
19182 +
19183 +#define LOAD_INT(x) ((x) >> FSHIFT)
19184 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19185 +
19186 +static inline
19187 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19188 +{
19189 +       int length = 0;
19190 +       int a, b, c;
19191 +
19192 +       length += sprintf(buffer + length,
19193 +               "BiasUptime:\t%lu.%02lu\n",
19194 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19195 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19196 +
19197 +       a = cvirt->load[0] + (FIXED_1 / 200);
19198 +       b = cvirt->load[1] + (FIXED_1 / 200);
19199 +       c = cvirt->load[2] + (FIXED_1 / 200);
19200 +       length += sprintf(buffer + length,
19201 +               "nr_threads:\t%d\n"
19202 +               "nr_running:\t%d\n"
19203 +               "nr_unintr:\t%d\n"
19204 +               "nr_onhold:\t%d\n"
19205 +               "load_updates:\t%d\n"
19206 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19207 +               "total_forks:\t%d\n",
19208 +               atomic_read(&cvirt->nr_threads),
19209 +               atomic_read(&cvirt->nr_running),
19210 +               atomic_read(&cvirt->nr_uninterruptible),
19211 +               atomic_read(&cvirt->nr_onhold),
19212 +               atomic_read(&cvirt->load_updates),
19213 +               LOAD_INT(a), LOAD_FRAC(a),
19214 +               LOAD_INT(b), LOAD_FRAC(b),
19215 +               LOAD_INT(c), LOAD_FRAC(c),
19216 +               atomic_read(&cvirt->total_forks));
19217 +       return length;
19218 +}
19219 +
19220 +static inline
19221 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19222 +       char *buffer, int cpu)
19223 +{
19224 +       int length = 0;
19225 +       return length;
19226 +}
19227 +
19228 +#endif /* _VX_CVIRT_PROC_H */
19229 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/debug.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/debug.c
19230 --- linux-2.6.32.24/kernel/vserver/debug.c      1970-01-01 01:00:00.000000000 +0100
19231 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/debug.c      2009-12-03 20:04:56.000000000 +0100
19232 @@ -0,0 +1,32 @@
19233 +/*
19234 + *  kernel/vserver/debug.c
19235 + *
19236 + *  Copyright (C) 2005-2007 Herbert Pötzl
19237 + *
19238 + *  V0.01  vx_info dump support
19239 + *
19240 + */
19241 +
19242 +#include <linux/module.h>
19243 +
19244 +#include <linux/vserver/context.h>
19245 +
19246 +
19247 +void   dump_vx_info(struct vx_info *vxi, int level)
19248 +{
19249 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19250 +               atomic_read(&vxi->vx_usecnt),
19251 +               atomic_read(&vxi->vx_tasks),
19252 +               vxi->vx_state);
19253 +       if (level > 0) {
19254 +               __dump_vx_limit(&vxi->limit);
19255 +               __dump_vx_sched(&vxi->sched);
19256 +               __dump_vx_cvirt(&vxi->cvirt);
19257 +               __dump_vx_cacct(&vxi->cacct);
19258 +       }
19259 +       printk("---\n");
19260 +}
19261 +
19262 +
19263 +EXPORT_SYMBOL_GPL(dump_vx_info);
19264 +
19265 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/device.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/device.c
19266 --- linux-2.6.32.24/kernel/vserver/device.c     1970-01-01 01:00:00.000000000 +0100
19267 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/device.c     2009-12-03 20:04:56.000000000 +0100
19268 @@ -0,0 +1,443 @@
19269 +/*
19270 + *  linux/kernel/vserver/device.c
19271 + *
19272 + *  Linux-VServer: Device Support
19273 + *
19274 + *  Copyright (C) 2006  Herbert Pötzl
19275 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19276 + *
19277 + *  V0.01  device mapping basics
19278 + *  V0.02  added defaults
19279 + *
19280 + */
19281 +
19282 +#include <linux/slab.h>
19283 +#include <linux/rcupdate.h>
19284 +#include <linux/fs.h>
19285 +#include <linux/namei.h>
19286 +#include <linux/hash.h>
19287 +
19288 +#include <asm/errno.h>
19289 +#include <asm/uaccess.h>
19290 +#include <linux/vserver/base.h>
19291 +#include <linux/vserver/debug.h>
19292 +#include <linux/vserver/context.h>
19293 +#include <linux/vserver/device.h>
19294 +#include <linux/vserver/device_cmd.h>
19295 +
19296 +
19297 +#define DMAP_HASH_BITS 4
19298 +
19299 +
19300 +struct vs_mapping {
19301 +       union {
19302 +               struct hlist_node hlist;
19303 +               struct list_head list;
19304 +       } u;
19305 +#define dm_hlist       u.hlist
19306 +#define dm_list                u.list
19307 +       xid_t xid;
19308 +       dev_t device;
19309 +       struct vx_dmap_target target;
19310 +};
19311 +
19312 +
19313 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19314 +
19315 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
19316 +
19317 +static struct vx_dmap_target dmap_defaults[2] = {
19318 +       { .flags = DATTR_OPEN },
19319 +       { .flags = DATTR_OPEN },
19320 +};
19321 +
19322 +
19323 +struct kmem_cache *dmap_cachep __read_mostly;
19324 +
19325 +int __init dmap_cache_init(void)
19326 +{
19327 +       dmap_cachep = kmem_cache_create("dmap_cache",
19328 +               sizeof(struct vs_mapping), 0,
19329 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19330 +       return 0;
19331 +}
19332 +
19333 +__initcall(dmap_cache_init);
19334 +
19335 +
19336 +static inline unsigned int __hashval(dev_t dev, int bits)
19337 +{
19338 +       return hash_long((unsigned long)dev, bits);
19339 +}
19340 +
19341 +
19342 +/*     __hash_mapping()
19343 + *     add the mapping to the hash table
19344 + */
19345 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19346 +{
19347 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19348 +       struct hlist_head *head, *hash = dmap_main_hash;
19349 +       int device = vdm->device;
19350 +
19351 +       spin_lock(hash_lock);
19352 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19353 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19354 +
19355 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19356 +       hlist_add_head(&vdm->dm_hlist, head);
19357 +       spin_unlock(hash_lock);
19358 +}
19359 +
19360 +
19361 +static inline int __mode_to_default(umode_t mode)
19362 +{
19363 +       switch (mode) {
19364 +       case S_IFBLK:
19365 +               return 0;
19366 +       case S_IFCHR:
19367 +               return 1;
19368 +       default:
19369 +               BUG();
19370 +       }
19371 +}
19372 +
19373 +
19374 +/*     __set_default()
19375 + *     set a default
19376 + */
19377 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19378 +       struct vx_dmap_target *vdmt)
19379 +{
19380 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19381 +       spin_lock(hash_lock);
19382 +
19383 +       if (vxi)
19384 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19385 +       else
19386 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19387 +
19388 +
19389 +       spin_unlock(hash_lock);
19390 +
19391 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19392 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19393 +}
19394 +
19395 +
19396 +/*     __remove_default()
19397 + *     remove a default
19398 + */
19399 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19400 +{
19401 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19402 +       spin_lock(hash_lock);
19403 +
19404 +       if (vxi)
19405 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19406 +       else    /* remove == reset */
19407 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19408 +
19409 +       spin_unlock(hash_lock);
19410 +       return 0;
19411 +}
19412 +
19413 +
19414 +/*     __find_mapping()
19415 + *     find a mapping in the hash table
19416 + *
19417 + *     caller must hold hash_lock
19418 + */
19419 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19420 +       struct vs_mapping **local, struct vs_mapping **global)
19421 +{
19422 +       struct hlist_head *hash = dmap_main_hash;
19423 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19424 +       struct hlist_node *pos;
19425 +       struct vs_mapping *vdm;
19426 +
19427 +       *local = NULL;
19428 +       if (global)
19429 +               *global = NULL;
19430 +
19431 +       hlist_for_each(pos, head) {
19432 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19433 +
19434 +               if ((vdm->device == device) &&
19435 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19436 +                       if (vdm->xid == xid) {
19437 +                               *local = vdm;
19438 +                               return 1;
19439 +                       } else if (global && vdm->xid == 0)
19440 +                               *global = vdm;
19441 +               }
19442 +       }
19443 +
19444 +       if (global && *global)
19445 +               return 0;
19446 +       else
19447 +               return -ENOENT;
19448 +}
19449 +
19450 +
19451 +/*     __lookup_mapping()
19452 + *     find a mapping and store the result in target and flags
19453 + */
19454 +static inline int __lookup_mapping(struct vx_info *vxi,
19455 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19456 +{
19457 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19458 +       struct vs_mapping *vdm, *global;
19459 +       struct vx_dmap_target *vdmt;
19460 +       int ret = 0;
19461 +       xid_t xid = vxi->vx_id;
19462 +       int index;
19463 +
19464 +       spin_lock(hash_lock);
19465 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19466 +               ret = 1;
19467 +               vdmt = &vdm->target;
19468 +               goto found;
19469 +       }
19470 +
19471 +       index = __mode_to_default(mode);
19472 +       if (vxi && vxi->dmap.targets[index].flags) {
19473 +               ret = 2;
19474 +               vdmt = &vxi->dmap.targets[index];
19475 +       } else if (global) {
19476 +               ret = 3;
19477 +               vdmt = &global->target;
19478 +               goto found;
19479 +       } else {
19480 +               ret = 4;
19481 +               vdmt = &dmap_defaults[index];
19482 +       }
19483 +
19484 +found:
19485 +       if (target && (vdmt->flags & DATTR_REMAP))
19486 +               *target = vdmt->target;
19487 +       else if (target)
19488 +               *target = device;
19489 +       if (flags)
19490 +               *flags = vdmt->flags;
19491 +
19492 +       spin_unlock(hash_lock);
19493 +
19494 +       return ret;
19495 +}
19496 +
19497 +
19498 +/*     __remove_mapping()
19499 + *     remove a mapping from the hash table
19500 + */
19501 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19502 +       umode_t mode)
19503 +{
19504 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19505 +       struct vs_mapping *vdm = NULL;
19506 +       int ret = 0;
19507 +
19508 +       spin_lock(hash_lock);
19509 +
19510 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19511 +               NULL);
19512 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19513 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19514 +       if (ret < 0)
19515 +               goto out;
19516 +       hlist_del(&vdm->dm_hlist);
19517 +
19518 +out:
19519 +       spin_unlock(hash_lock);
19520 +       if (vdm)
19521 +               kmem_cache_free(dmap_cachep, vdm);
19522 +       return ret;
19523 +}
19524 +
19525 +
19526 +
19527 +int vs_map_device(struct vx_info *vxi,
19528 +       dev_t device, dev_t *target, umode_t mode)
19529 +{
19530 +       int ret, flags = DATTR_MASK;
19531 +
19532 +       if (!vxi) {
19533 +               if (target)
19534 +                       *target = device;
19535 +               goto out;
19536 +       }
19537 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19538 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19539 +               device, target ? *target : 0, flags, mode, ret);
19540 +out:
19541 +       return (flags & DATTR_MASK);
19542 +}
19543 +
19544 +
19545 +
19546 +static int do_set_mapping(struct vx_info *vxi,
19547 +       dev_t device, dev_t target, int flags, umode_t mode)
19548 +{
19549 +       if (device) {
19550 +               struct vs_mapping *new;
19551 +
19552 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19553 +               if (!new)
19554 +                       return -ENOMEM;
19555 +
19556 +               INIT_HLIST_NODE(&new->dm_hlist);
19557 +               new->device = device;
19558 +               new->target.target = target;
19559 +               new->target.flags = flags | mode;
19560 +               new->xid = (vxi ? vxi->vx_id : 0);
19561 +
19562 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19563 +               __hash_mapping(vxi, new);
19564 +       } else {
19565 +               struct vx_dmap_target new = {
19566 +                       .target = target,
19567 +                       .flags = flags | mode,
19568 +               };
19569 +               __set_default(vxi, mode, &new);
19570 +       }
19571 +       return 0;
19572 +}
19573 +
19574 +
19575 +static int do_unset_mapping(struct vx_info *vxi,
19576 +       dev_t device, dev_t target, int flags, umode_t mode)
19577 +{
19578 +       int ret = -EINVAL;
19579 +
19580 +       if (device) {
19581 +               ret = __remove_mapping(vxi, device, mode);
19582 +               if (ret < 0)
19583 +                       goto out;
19584 +       } else {
19585 +               ret = __remove_default(vxi, mode);
19586 +               if (ret < 0)
19587 +                       goto out;
19588 +       }
19589 +
19590 +out:
19591 +       return ret;
19592 +}
19593 +
19594 +
19595 +static inline int __user_device(const char __user *name, dev_t *dev,
19596 +       umode_t *mode)
19597 +{
19598 +       struct nameidata nd;
19599 +       int ret;
19600 +
19601 +       if (!name) {
19602 +               *dev = 0;
19603 +               return 0;
19604 +       }
19605 +       ret = user_lpath(name, &nd.path);
19606 +       if (ret)
19607 +               return ret;
19608 +       if (nd.path.dentry->d_inode) {
19609 +               *dev = nd.path.dentry->d_inode->i_rdev;
19610 +               *mode = nd.path.dentry->d_inode->i_mode;
19611 +       }
19612 +       path_put(&nd.path);
19613 +       return 0;
19614 +}
19615 +
19616 +static inline int __mapping_mode(dev_t device, dev_t target,
19617 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19618 +{
19619 +       if (device)
19620 +               *mode = device_mode & S_IFMT;
19621 +       else if (target)
19622 +               *mode = target_mode & S_IFMT;
19623 +       else
19624 +               return -EINVAL;
19625 +
19626 +       /* if both given, device and target mode have to match */
19627 +       if (device && target &&
19628 +               ((device_mode ^ target_mode) & S_IFMT))
19629 +               return -EINVAL;
19630 +       return 0;
19631 +}
19632 +
19633 +
19634 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19635 +       const char __user *target_path, int flags, int set)
19636 +{
19637 +       dev_t device = ~0, target = ~0;
19638 +       umode_t device_mode = 0, target_mode = 0, mode;
19639 +       int ret;
19640 +
19641 +       ret = __user_device(device_path, &device, &device_mode);
19642 +       if (ret)
19643 +               return ret;
19644 +       ret = __user_device(target_path, &target, &target_mode);
19645 +       if (ret)
19646 +               return ret;
19647 +
19648 +       ret = __mapping_mode(device, target,
19649 +               device_mode, target_mode, &mode);
19650 +       if (ret)
19651 +               return ret;
19652 +
19653 +       if (set)
19654 +               return do_set_mapping(vxi, device, target,
19655 +                       flags, mode);
19656 +       else
19657 +               return do_unset_mapping(vxi, device, target,
19658 +                       flags, mode);
19659 +}
19660 +
19661 +
19662 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19663 +{
19664 +       struct vcmd_set_mapping_v0 vc_data;
19665 +
19666 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19667 +               return -EFAULT;
19668 +
19669 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19670 +               vc_data.flags, 1);
19671 +}
19672 +
19673 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19674 +{
19675 +       struct vcmd_set_mapping_v0 vc_data;
19676 +
19677 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19678 +               return -EFAULT;
19679 +
19680 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19681 +               vc_data.flags, 0);
19682 +}
19683 +
19684 +
19685 +#ifdef CONFIG_COMPAT
19686 +
19687 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19688 +{
19689 +       struct vcmd_set_mapping_v0_x32 vc_data;
19690 +
19691 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19692 +               return -EFAULT;
19693 +
19694 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19695 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19696 +}
19697 +
19698 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19699 +{
19700 +       struct vcmd_set_mapping_v0_x32 vc_data;
19701 +
19702 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19703 +               return -EFAULT;
19704 +
19705 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19706 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19707 +}
19708 +
19709 +#endif /* CONFIG_COMPAT */
19710 +
19711 +
19712 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/dlimit.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/dlimit.c
19713 --- linux-2.6.32.24/kernel/vserver/dlimit.c     1970-01-01 01:00:00.000000000 +0100
19714 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/dlimit.c     2009-12-03 20:04:56.000000000 +0100
19715 @@ -0,0 +1,529 @@
19716 +/*
19717 + *  linux/kernel/vserver/dlimit.c
19718 + *
19719 + *  Virtual Server: Context Disk Limits
19720 + *
19721 + *  Copyright (C) 2004-2009  Herbert Pötzl
19722 + *
19723 + *  V0.01  initial version
19724 + *  V0.02  compat32 splitup
19725 + *  V0.03  extended interface
19726 + *
19727 + */
19728 +
19729 +#include <linux/statfs.h>
19730 +#include <linux/sched.h>
19731 +#include <linux/namei.h>
19732 +#include <linux/vs_tag.h>
19733 +#include <linux/vs_dlimit.h>
19734 +#include <linux/vserver/dlimit_cmd.h>
19735 +
19736 +#include <asm/uaccess.h>
19737 +
19738 +/*     __alloc_dl_info()
19739 +
19740 +       * allocate an initialized dl_info struct
19741 +       * doesn't make it visible (hash)                        */
19742 +
19743 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19744 +{
19745 +       struct dl_info *new = NULL;
19746 +
19747 +       vxdprintk(VXD_CBIT(dlim, 5),
19748 +               "alloc_dl_info(%p,%d)*", sb, tag);
19749 +
19750 +       /* would this benefit from a slab cache? */
19751 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19752 +       if (!new)
19753 +               return 0;
19754 +
19755 +       memset(new, 0, sizeof(struct dl_info));
19756 +       new->dl_tag = tag;
19757 +       new->dl_sb = sb;
19758 +       INIT_RCU_HEAD(&new->dl_rcu);
19759 +       INIT_HLIST_NODE(&new->dl_hlist);
19760 +       spin_lock_init(&new->dl_lock);
19761 +       atomic_set(&new->dl_refcnt, 0);
19762 +       atomic_set(&new->dl_usecnt, 0);
19763 +
19764 +       /* rest of init goes here */
19765 +
19766 +       vxdprintk(VXD_CBIT(dlim, 4),
19767 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19768 +       return new;
19769 +}
19770 +
19771 +/*     __dealloc_dl_info()
19772 +
19773 +       * final disposal of dl_info                             */
19774 +
19775 +static void __dealloc_dl_info(struct dl_info *dli)
19776 +{
19777 +       vxdprintk(VXD_CBIT(dlim, 4),
19778 +               "dealloc_dl_info(%p)", dli);
19779 +
19780 +       dli->dl_hlist.next = LIST_POISON1;
19781 +       dli->dl_tag = -1;
19782 +       dli->dl_sb = 0;
19783 +
19784 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19785 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19786 +
19787 +       kfree(dli);
19788 +}
19789 +
19790 +
19791 +/*     hash table for dl_info hash */
19792 +
19793 +#define DL_HASH_SIZE   13
19794 +
19795 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19796 +
19797 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19798 +
19799 +
19800 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19801 +{
19802 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19803 +}
19804 +
19805 +
19806 +
19807 +/*     __hash_dl_info()
19808 +
19809 +       * add the dli to the global hash table
19810 +       * requires the hash_lock to be held                     */
19811 +
19812 +static inline void __hash_dl_info(struct dl_info *dli)
19813 +{
19814 +       struct hlist_head *head;
19815 +
19816 +       vxdprintk(VXD_CBIT(dlim, 6),
19817 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19818 +       get_dl_info(dli);
19819 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19820 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19821 +}
19822 +
19823 +/*     __unhash_dl_info()
19824 +
19825 +       * remove the dli from the global hash table
19826 +       * requires the hash_lock to be held                     */
19827 +
19828 +static inline void __unhash_dl_info(struct dl_info *dli)
19829 +{
19830 +       vxdprintk(VXD_CBIT(dlim, 6),
19831 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19832 +       hlist_del_rcu(&dli->dl_hlist);
19833 +       put_dl_info(dli);
19834 +}
19835 +
19836 +
19837 +/*     __lookup_dl_info()
19838 +
19839 +       * requires the rcu_read_lock()
19840 +       * doesn't increment the dl_refcnt                       */
19841 +
19842 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19843 +{
19844 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19845 +       struct hlist_node *pos;
19846 +       struct dl_info *dli;
19847 +
19848 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19849 +
19850 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19851 +                       return dli;
19852 +               }
19853 +       }
19854 +       return NULL;
19855 +}
19856 +
19857 +
19858 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19859 +{
19860 +       struct dl_info *dli;
19861 +
19862 +       rcu_read_lock();
19863 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19864 +       vxdprintk(VXD_CBIT(dlim, 7),
19865 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19866 +       rcu_read_unlock();
19867 +       return dli;
19868 +}
19869 +
19870 +void rcu_free_dl_info(struct rcu_head *head)
19871 +{
19872 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19873 +       int usecnt, refcnt;
19874 +
19875 +       BUG_ON(!dli || !head);
19876 +
19877 +       usecnt = atomic_read(&dli->dl_usecnt);
19878 +       BUG_ON(usecnt < 0);
19879 +
19880 +       refcnt = atomic_read(&dli->dl_refcnt);
19881 +       BUG_ON(refcnt < 0);
19882 +
19883 +       vxdprintk(VXD_CBIT(dlim, 3),
19884 +               "rcu_free_dl_info(%p)", dli);
19885 +       if (!usecnt)
19886 +               __dealloc_dl_info(dli);
19887 +       else
19888 +               printk("!!! rcu didn't free\n");
19889 +}
19890 +
19891 +
19892 +
19893 +
19894 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19895 +       uint32_t flags, int add)
19896 +{
19897 +       struct path path;
19898 +       int ret;
19899 +
19900 +       ret = user_lpath(name, &path);
19901 +       if (!ret) {
19902 +               struct super_block *sb;
19903 +               struct dl_info *dli;
19904 +
19905 +               ret = -EINVAL;
19906 +               if (!path.dentry->d_inode)
19907 +                       goto out_release;
19908 +               if (!(sb = path.dentry->d_inode->i_sb))
19909 +                       goto out_release;
19910 +
19911 +               if (add) {
19912 +                       dli = __alloc_dl_info(sb, id);
19913 +                       spin_lock(&dl_info_hash_lock);
19914 +
19915 +                       ret = -EEXIST;
19916 +                       if (__lookup_dl_info(sb, id))
19917 +                               goto out_unlock;
19918 +                       __hash_dl_info(dli);
19919 +                       dli = NULL;
19920 +               } else {
19921 +                       spin_lock(&dl_info_hash_lock);
19922 +                       dli = __lookup_dl_info(sb, id);
19923 +
19924 +                       ret = -ESRCH;
19925 +                       if (!dli)
19926 +                               goto out_unlock;
19927 +                       __unhash_dl_info(dli);
19928 +               }
19929 +               ret = 0;
19930 +       out_unlock:
19931 +               spin_unlock(&dl_info_hash_lock);
19932 +               if (add && dli)
19933 +                       __dealloc_dl_info(dli);
19934 +       out_release:
19935 +               path_put(&path);
19936 +       }
19937 +       return ret;
19938 +}
19939 +
19940 +int vc_add_dlimit(uint32_t id, void __user *data)
19941 +{
19942 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19943 +
19944 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19945 +               return -EFAULT;
19946 +
19947 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19948 +}
19949 +
19950 +int vc_rem_dlimit(uint32_t id, void __user *data)
19951 +{
19952 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19953 +
19954 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19955 +               return -EFAULT;
19956 +
19957 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19958 +}
19959 +
19960 +#ifdef CONFIG_COMPAT
19961 +
19962 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19963 +{
19964 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19965 +
19966 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19967 +               return -EFAULT;
19968 +
19969 +       return do_addrem_dlimit(id,
19970 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19971 +}
19972 +
19973 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19974 +{
19975 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19976 +
19977 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19978 +               return -EFAULT;
19979 +
19980 +       return do_addrem_dlimit(id,
19981 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19982 +}
19983 +
19984 +#endif /* CONFIG_COMPAT */
19985 +
19986 +
19987 +static inline
19988 +int do_set_dlimit(uint32_t id, const char __user *name,
19989 +       uint32_t space_used, uint32_t space_total,
19990 +       uint32_t inodes_used, uint32_t inodes_total,
19991 +       uint32_t reserved, uint32_t flags)
19992 +{
19993 +       struct path path;
19994 +       int ret;
19995 +
19996 +       ret = user_lpath(name, &path);
19997 +       if (!ret) {
19998 +               struct super_block *sb;
19999 +               struct dl_info *dli;
20000 +
20001 +               ret = -EINVAL;
20002 +               if (!path.dentry->d_inode)
20003 +                       goto out_release;
20004 +               if (!(sb = path.dentry->d_inode->i_sb))
20005 +                       goto out_release;
20006 +
20007 +               /* sanity checks */
20008 +               if ((reserved != CDLIM_KEEP &&
20009 +                       reserved > 100) ||
20010 +                       (inodes_used != CDLIM_KEEP &&
20011 +                       inodes_used > inodes_total) ||
20012 +                       (space_used != CDLIM_KEEP &&
20013 +                       space_used > space_total))
20014 +                       goto out_release;
20015 +
20016 +               ret = -ESRCH;
20017 +               dli = locate_dl_info(sb, id);
20018 +               if (!dli)
20019 +                       goto out_release;
20020 +
20021 +               spin_lock(&dli->dl_lock);
20022 +
20023 +               if (inodes_used != CDLIM_KEEP)
20024 +                       dli->dl_inodes_used = inodes_used;
20025 +               if (inodes_total != CDLIM_KEEP)
20026 +                       dli->dl_inodes_total = inodes_total;
20027 +               if (space_used != CDLIM_KEEP)
20028 +                       dli->dl_space_used = dlimit_space_32to64(
20029 +                               space_used, flags, DLIMS_USED);
20030 +
20031 +               if (space_total == CDLIM_INFINITY)
20032 +                       dli->dl_space_total = DLIM_INFINITY;
20033 +               else if (space_total != CDLIM_KEEP)
20034 +                       dli->dl_space_total = dlimit_space_32to64(
20035 +                               space_total, flags, DLIMS_TOTAL);
20036 +
20037 +               if (reserved != CDLIM_KEEP)
20038 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
20039 +
20040 +               spin_unlock(&dli->dl_lock);
20041 +
20042 +               put_dl_info(dli);
20043 +               ret = 0;
20044 +
20045 +       out_release:
20046 +               path_put(&path);
20047 +       }
20048 +       return ret;
20049 +}
20050 +
20051 +int vc_set_dlimit(uint32_t id, void __user *data)
20052 +{
20053 +       struct vcmd_ctx_dlimit_v0 vc_data;
20054 +
20055 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20056 +               return -EFAULT;
20057 +
20058 +       return do_set_dlimit(id, vc_data.name,
20059 +               vc_data.space_used, vc_data.space_total,
20060 +               vc_data.inodes_used, vc_data.inodes_total,
20061 +               vc_data.reserved, vc_data.flags);
20062 +}
20063 +
20064 +#ifdef CONFIG_COMPAT
20065 +
20066 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20067 +{
20068 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20069 +
20070 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20071 +               return -EFAULT;
20072 +
20073 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
20074 +               vc_data.space_used, vc_data.space_total,
20075 +               vc_data.inodes_used, vc_data.inodes_total,
20076 +               vc_data.reserved, vc_data.flags);
20077 +}
20078 +
20079 +#endif /* CONFIG_COMPAT */
20080 +
20081 +
20082 +static inline
20083 +int do_get_dlimit(uint32_t id, const char __user *name,
20084 +       uint32_t *space_used, uint32_t *space_total,
20085 +       uint32_t *inodes_used, uint32_t *inodes_total,
20086 +       uint32_t *reserved, uint32_t *flags)
20087 +{
20088 +       struct path path;
20089 +       int ret;
20090 +
20091 +       ret = user_lpath(name, &path);
20092 +       if (!ret) {
20093 +               struct super_block *sb;
20094 +               struct dl_info *dli;
20095 +
20096 +               ret = -EINVAL;
20097 +               if (!path.dentry->d_inode)
20098 +                       goto out_release;
20099 +               if (!(sb = path.dentry->d_inode->i_sb))
20100 +                       goto out_release;
20101 +
20102 +               ret = -ESRCH;
20103 +               dli = locate_dl_info(sb, id);
20104 +               if (!dli)
20105 +                       goto out_release;
20106 +
20107 +               spin_lock(&dli->dl_lock);
20108 +               *inodes_used = dli->dl_inodes_used;
20109 +               *inodes_total = dli->dl_inodes_total;
20110 +
20111 +               *space_used = dlimit_space_64to32(
20112 +                       dli->dl_space_used, flags, DLIMS_USED);
20113 +
20114 +               if (dli->dl_space_total == DLIM_INFINITY)
20115 +                       *space_total = CDLIM_INFINITY;
20116 +               else
20117 +                       *space_total = dlimit_space_64to32(
20118 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
20119 +
20120 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20121 +               spin_unlock(&dli->dl_lock);
20122 +
20123 +               put_dl_info(dli);
20124 +               ret = -EFAULT;
20125 +
20126 +               ret = 0;
20127 +       out_release:
20128 +               path_put(&path);
20129 +       }
20130 +       return ret;
20131 +}
20132 +
20133 +
20134 +int vc_get_dlimit(uint32_t id, void __user *data)
20135 +{
20136 +       struct vcmd_ctx_dlimit_v0 vc_data;
20137 +       int ret;
20138 +
20139 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20140 +               return -EFAULT;
20141 +
20142 +       ret = do_get_dlimit(id, vc_data.name,
20143 +               &vc_data.space_used, &vc_data.space_total,
20144 +               &vc_data.inodes_used, &vc_data.inodes_total,
20145 +               &vc_data.reserved, &vc_data.flags);
20146 +       if (ret)
20147 +               return ret;
20148 +
20149 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20150 +               return -EFAULT;
20151 +       return 0;
20152 +}
20153 +
20154 +#ifdef CONFIG_COMPAT
20155 +
20156 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20157 +{
20158 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20159 +       int ret;
20160 +
20161 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20162 +               return -EFAULT;
20163 +
20164 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20165 +               &vc_data.space_used, &vc_data.space_total,
20166 +               &vc_data.inodes_used, &vc_data.inodes_total,
20167 +               &vc_data.reserved, &vc_data.flags);
20168 +       if (ret)
20169 +               return ret;
20170 +
20171 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20172 +               return -EFAULT;
20173 +       return 0;
20174 +}
20175 +
20176 +#endif /* CONFIG_COMPAT */
20177 +
20178 +
20179 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20180 +{
20181 +       struct dl_info *dli;
20182 +       __u64 blimit, bfree, bavail;
20183 +       __u32 ifree;
20184 +
20185 +       dli = locate_dl_info(sb, dx_current_tag());
20186 +       if (!dli)
20187 +               return;
20188 +
20189 +       spin_lock(&dli->dl_lock);
20190 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20191 +               goto no_ilim;
20192 +
20193 +       /* reduce max inodes available to limit */
20194 +       if (buf->f_files > dli->dl_inodes_total)
20195 +               buf->f_files = dli->dl_inodes_total;
20196 +
20197 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20198 +       /* reduce free inodes to min */
20199 +       if (ifree < buf->f_ffree)
20200 +               buf->f_ffree = ifree;
20201 +
20202 +no_ilim:
20203 +       if (dli->dl_space_total == DLIM_INFINITY)
20204 +               goto no_blim;
20205 +
20206 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20207 +
20208 +       if (dli->dl_space_total < dli->dl_space_used)
20209 +               bfree = 0;
20210 +       else
20211 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20212 +                       >> sb->s_blocksize_bits;
20213 +
20214 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20215 +       if (bavail < dli->dl_space_used)
20216 +               bavail = 0;
20217 +       else
20218 +               bavail = (bavail - dli->dl_space_used)
20219 +                       >> sb->s_blocksize_bits;
20220 +
20221 +       /* reduce max space available to limit */
20222 +       if (buf->f_blocks > blimit)
20223 +               buf->f_blocks = blimit;
20224 +
20225 +       /* reduce free space to min */
20226 +       if (bfree < buf->f_bfree)
20227 +               buf->f_bfree = bfree;
20228 +
20229 +       /* reduce avail space to min */
20230 +       if (bavail < buf->f_bavail)
20231 +               buf->f_bavail = bavail;
20232 +
20233 +no_blim:
20234 +       spin_unlock(&dli->dl_lock);
20235 +       put_dl_info(dli);
20236 +
20237 +       return;
20238 +}
20239 +
20240 +#include <linux/module.h>
20241 +
20242 +EXPORT_SYMBOL_GPL(locate_dl_info);
20243 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20244 +
20245 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/helper.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/helper.c
20246 --- linux-2.6.32.24/kernel/vserver/helper.c     1970-01-01 01:00:00.000000000 +0100
20247 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/helper.c     2009-12-03 22:20:22.000000000 +0100
20248 @@ -0,0 +1,223 @@
20249 +/*
20250 + *  linux/kernel/vserver/helper.c
20251 + *
20252 + *  Virtual Context Support
20253 + *
20254 + *  Copyright (C) 2004-2007  Herbert Pötzl
20255 + *
20256 + *  V0.01  basic helper
20257 + *
20258 + */
20259 +
20260 +#include <linux/kmod.h>
20261 +#include <linux/reboot.h>
20262 +#include <linux/vs_context.h>
20263 +#include <linux/vs_network.h>
20264 +#include <linux/vserver/signal.h>
20265 +
20266 +
20267 +char vshelper_path[255] = "/sbin/vshelper";
20268 +
20269 +
20270 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20271 +{
20272 +       int ret;
20273 +
20274 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20275 +               printk( KERN_WARNING
20276 +                       "%s: (%s %s) returned %s with %d\n",
20277 +                       name, argv[1], argv[2],
20278 +                       sync ? "sync" : "async", ret);
20279 +       }
20280 +       vxdprintk(VXD_CBIT(switch, 4),
20281 +               "%s: (%s %s) returned %s with %d",
20282 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20283 +       return ret;
20284 +}
20285 +
20286 +/*
20287 + *      vshelper path is set via /proc/sys
20288 + *      invoked by vserver sys_reboot(), with
20289 + *      the following arguments
20290 + *
20291 + *      argv [0] = vshelper_path;
20292 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20293 + *      argv [2] = context identifier
20294 + *
20295 + *      envp [*] = type-specific parameters
20296 + */
20297 +
20298 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20299 +{
20300 +       char id_buf[8], cmd_buf[16];
20301 +       char uid_buf[16], pid_buf[16];
20302 +       int ret;
20303 +
20304 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20305 +       char *envp[] = {"HOME=/", "TERM=linux",
20306 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20307 +                       uid_buf, pid_buf, cmd_buf, 0};
20308 +
20309 +       if (vx_info_state(vxi, VXS_HELPER))
20310 +               return -EAGAIN;
20311 +       vxi->vx_state |= VXS_HELPER;
20312 +
20313 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20314 +
20315 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20316 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
20317 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20318 +
20319 +       switch (cmd) {
20320 +       case LINUX_REBOOT_CMD_RESTART:
20321 +               argv[1] = "restart";
20322 +               break;
20323 +
20324 +       case LINUX_REBOOT_CMD_HALT:
20325 +               argv[1] = "halt";
20326 +               break;
20327 +
20328 +       case LINUX_REBOOT_CMD_POWER_OFF:
20329 +               argv[1] = "poweroff";
20330 +               break;
20331 +
20332 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20333 +               argv[1] = "swsusp";
20334 +               break;
20335 +
20336 +       case LINUX_REBOOT_CMD_OOM:
20337 +               argv[1] = "oom";
20338 +               break;
20339 +
20340 +       default:
20341 +               vxi->vx_state &= ~VXS_HELPER;
20342 +               return 0;
20343 +       }
20344 +
20345 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20346 +       vxi->vx_state &= ~VXS_HELPER;
20347 +       __wakeup_vx_info(vxi);
20348 +       return (ret) ? -EPERM : 0;
20349 +}
20350 +
20351 +
20352 +long vs_reboot(unsigned int cmd, void __user *arg)
20353 +{
20354 +       struct vx_info *vxi = current_vx_info();
20355 +       long ret = 0;
20356 +
20357 +       vxdprintk(VXD_CBIT(misc, 5),
20358 +               "vs_reboot(%p[#%d],%u)",
20359 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20360 +
20361 +       ret = vs_reboot_helper(vxi, cmd, arg);
20362 +       if (ret)
20363 +               return ret;
20364 +
20365 +       vxi->reboot_cmd = cmd;
20366 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20367 +               switch (cmd) {
20368 +               case LINUX_REBOOT_CMD_RESTART:
20369 +               case LINUX_REBOOT_CMD_HALT:
20370 +               case LINUX_REBOOT_CMD_POWER_OFF:
20371 +                       vx_info_kill(vxi, 0, SIGKILL);
20372 +                       vx_info_kill(vxi, 1, SIGKILL);
20373 +               default:
20374 +                       break;
20375 +               }
20376 +       }
20377 +       return 0;
20378 +}
20379 +
20380 +long vs_oom_action(unsigned int cmd)
20381 +{
20382 +       struct vx_info *vxi = current_vx_info();
20383 +       long ret = 0;
20384 +
20385 +       vxdprintk(VXD_CBIT(misc, 5),
20386 +               "vs_oom_action(%p[#%d],%u)",
20387 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20388 +
20389 +       ret = vs_reboot_helper(vxi, cmd, NULL);
20390 +       if (ret)
20391 +               return ret;
20392 +
20393 +       vxi->reboot_cmd = cmd;
20394 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20395 +               vx_info_kill(vxi, 0, SIGKILL);
20396 +               vx_info_kill(vxi, 1, SIGKILL);
20397 +       }
20398 +       return 0;
20399 +}
20400 +
20401 +/*
20402 + *      argv [0] = vshelper_path;
20403 + *      argv [1] = action: "startup", "shutdown"
20404 + *      argv [2] = context identifier
20405 + *
20406 + *      envp [*] = type-specific parameters
20407 + */
20408 +
20409 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20410 +{
20411 +       char id_buf[8], cmd_buf[16];
20412 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20413 +       char *envp[] = {"HOME=/", "TERM=linux",
20414 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20415 +
20416 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20417 +               return 0;
20418 +
20419 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20420 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20421 +
20422 +       switch (cmd) {
20423 +       case VSC_STARTUP:
20424 +               argv[1] = "startup";
20425 +               break;
20426 +       case VSC_SHUTDOWN:
20427 +               argv[1] = "shutdown";
20428 +               break;
20429 +       default:
20430 +               return 0;
20431 +       }
20432 +
20433 +       return do_vshelper(vshelper_path, argv, envp, 1);
20434 +}
20435 +
20436 +
20437 +/*
20438 + *      argv [0] = vshelper_path;
20439 + *      argv [1] = action: "netup", "netdown"
20440 + *      argv [2] = context identifier
20441 + *
20442 + *      envp [*] = type-specific parameters
20443 + */
20444 +
20445 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20446 +{
20447 +       char id_buf[8], cmd_buf[16];
20448 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20449 +       char *envp[] = {"HOME=/", "TERM=linux",
20450 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20451 +
20452 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20453 +               return 0;
20454 +
20455 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20456 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20457 +
20458 +       switch (cmd) {
20459 +       case VSC_NETUP:
20460 +               argv[1] = "netup";
20461 +               break;
20462 +       case VSC_NETDOWN:
20463 +               argv[1] = "netdown";
20464 +               break;
20465 +       default:
20466 +               return 0;
20467 +       }
20468 +
20469 +       return do_vshelper(vshelper_path, argv, envp, 1);
20470 +}
20471 +
20472 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/history.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/history.c
20473 --- linux-2.6.32.24/kernel/vserver/history.c    1970-01-01 01:00:00.000000000 +0100
20474 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/history.c    2009-12-03 20:04:56.000000000 +0100
20475 @@ -0,0 +1,258 @@
20476 +/*
20477 + *  kernel/vserver/history.c
20478 + *
20479 + *  Virtual Context History Backtrace
20480 + *
20481 + *  Copyright (C) 2004-2007  Herbert Pötzl
20482 + *
20483 + *  V0.01  basic structure
20484 + *  V0.02  hash/unhash and trace
20485 + *  V0.03  preemption fixes
20486 + *
20487 + */
20488 +
20489 +#include <linux/module.h>
20490 +#include <asm/uaccess.h>
20491 +
20492 +#include <linux/vserver/context.h>
20493 +#include <linux/vserver/debug.h>
20494 +#include <linux/vserver/debug_cmd.h>
20495 +#include <linux/vserver/history.h>
20496 +
20497 +
20498 +#ifdef CONFIG_VSERVER_HISTORY
20499 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20500 +#else
20501 +#define VXH_SIZE       64
20502 +#endif
20503 +
20504 +struct _vx_history {
20505 +       unsigned int counter;
20506 +
20507 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20508 +};
20509 +
20510 +
20511 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20512 +
20513 +unsigned volatile int vxh_active = 1;
20514 +
20515 +static atomic_t sequence = ATOMIC_INIT(0);
20516 +
20517 +
20518 +/*     vxh_advance()
20519 +
20520 +       * requires disabled preemption                          */
20521 +
20522 +struct _vx_hist_entry *vxh_advance(void *loc)
20523 +{
20524 +       unsigned int cpu = smp_processor_id();
20525 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20526 +       struct _vx_hist_entry *entry;
20527 +       unsigned int index;
20528 +
20529 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20530 +       entry = &hist->entry[index];
20531 +
20532 +       entry->seq = atomic_inc_return(&sequence);
20533 +       entry->loc = loc;
20534 +       return entry;
20535 +}
20536 +
20537 +EXPORT_SYMBOL_GPL(vxh_advance);
20538 +
20539 +
20540 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20541 +
20542 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20543 +
20544 +
20545 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20546 +
20547 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20548 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20549 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20550 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20551 +
20552 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20553 +{
20554 +       switch (e->type) {
20555 +       case VXH_THROW_OOPS:
20556 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20557 +               break;
20558 +
20559 +       case VXH_GET_VX_INFO:
20560 +       case VXH_PUT_VX_INFO:
20561 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20562 +                       VXH_LOC_ARGS(e),
20563 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20564 +                       VXH_VXI_ARGS(e));
20565 +               break;
20566 +
20567 +       case VXH_INIT_VX_INFO:
20568 +       case VXH_SET_VX_INFO:
20569 +       case VXH_CLR_VX_INFO:
20570 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20571 +                       VXH_LOC_ARGS(e),
20572 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20573 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20574 +                       VXH_VXI_ARGS(e), e->sc.data);
20575 +               break;
20576 +
20577 +       case VXH_CLAIM_VX_INFO:
20578 +       case VXH_RELEASE_VX_INFO:
20579 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20580 +                       VXH_LOC_ARGS(e),
20581 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20582 +                       VXH_VXI_ARGS(e), e->sc.data);
20583 +               break;
20584 +
20585 +       case VXH_ALLOC_VX_INFO:
20586 +       case VXH_DEALLOC_VX_INFO:
20587 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20588 +                       VXH_LOC_ARGS(e),
20589 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20590 +                       VXH_VXI_ARGS(e));
20591 +               break;
20592 +
20593 +       case VXH_HASH_VX_INFO:
20594 +       case VXH_UNHASH_VX_INFO:
20595 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20596 +                       VXH_LOC_ARGS(e),
20597 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20598 +                       VXH_VXI_ARGS(e));
20599 +               break;
20600 +
20601 +       case VXH_LOC_VX_INFO:
20602 +       case VXH_LOOKUP_VX_INFO:
20603 +       case VXH_CREATE_VX_INFO:
20604 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20605 +                       VXH_LOC_ARGS(e),
20606 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20607 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20608 +                       e->ll.arg, VXH_VXI_ARGS(e));
20609 +               break;
20610 +       }
20611 +}
20612 +
20613 +static void __vxh_dump_history(void)
20614 +{
20615 +       unsigned int i, cpu;
20616 +
20617 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20618 +               atomic_read(&sequence), NR_CPUS);
20619 +
20620 +       for (i = 0; i < VXH_SIZE; i++) {
20621 +               for_each_online_cpu(cpu) {
20622 +                       struct _vx_history *hist =
20623 +                               &per_cpu(vx_history_buffer, cpu);
20624 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20625 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20626 +
20627 +                       vxh_dump_entry(entry, cpu);
20628 +               }
20629 +       }
20630 +}
20631 +
20632 +void   vxh_dump_history(void)
20633 +{
20634 +       vxh_active = 0;
20635 +#ifdef CONFIG_SMP
20636 +       local_irq_enable();
20637 +       smp_send_stop();
20638 +       local_irq_disable();
20639 +#endif
20640 +       __vxh_dump_history();
20641 +}
20642 +
20643 +
20644 +/* vserver syscall commands below here */
20645 +
20646 +
20647 +int vc_dump_history(uint32_t id)
20648 +{
20649 +       vxh_active = 0;
20650 +       __vxh_dump_history();
20651 +       vxh_active = 1;
20652 +
20653 +       return 0;
20654 +}
20655 +
20656 +
20657 +int do_read_history(struct __user _vx_hist_entry *data,
20658 +       int cpu, uint32_t *index, uint32_t *count)
20659 +{
20660 +       int pos, ret = 0;
20661 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20662 +       int end = hist->counter;
20663 +       int start = end - VXH_SIZE + 2;
20664 +       int idx = *index;
20665 +
20666 +       /* special case: get current pos */
20667 +       if (!*count) {
20668 +               *index = end;
20669 +               return 0;
20670 +       }
20671 +
20672 +       /* have we lost some data? */
20673 +       if (idx < start)
20674 +               idx = start;
20675 +
20676 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20677 +               struct _vx_hist_entry *entry =
20678 +                       &hist->entry[idx % VXH_SIZE];
20679 +
20680 +               /* send entry to userspace */
20681 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20682 +               if (ret)
20683 +                       break;
20684 +       }
20685 +       /* save new index and count */
20686 +       *index = idx;
20687 +       *count = pos;
20688 +       return ret ? ret : (*index < end);
20689 +}
20690 +
20691 +int vc_read_history(uint32_t id, void __user *data)
20692 +{
20693 +       struct vcmd_read_history_v0 vc_data;
20694 +       int ret;
20695 +
20696 +       if (id >= NR_CPUS)
20697 +               return -EINVAL;
20698 +
20699 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20700 +               return -EFAULT;
20701 +
20702 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20703 +               id, &vc_data.index, &vc_data.count);
20704 +
20705 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20706 +               return -EFAULT;
20707 +       return ret;
20708 +}
20709 +
20710 +#ifdef CONFIG_COMPAT
20711 +
20712 +int vc_read_history_x32(uint32_t id, void __user *data)
20713 +{
20714 +       struct vcmd_read_history_v0_x32 vc_data;
20715 +       int ret;
20716 +
20717 +       if (id >= NR_CPUS)
20718 +               return -EINVAL;
20719 +
20720 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20721 +               return -EFAULT;
20722 +
20723 +       ret = do_read_history((struct __user _vx_hist_entry *)
20724 +               compat_ptr(vc_data.data_ptr),
20725 +               id, &vc_data.index, &vc_data.count);
20726 +
20727 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20728 +               return -EFAULT;
20729 +       return ret;
20730 +}
20731 +
20732 +#endif /* CONFIG_COMPAT */
20733 +
20734 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/inet.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/inet.c
20735 --- linux-2.6.32.24/kernel/vserver/inet.c       1970-01-01 01:00:00.000000000 +0100
20736 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/inet.c       2009-12-03 20:04:56.000000000 +0100
20737 @@ -0,0 +1,225 @@
20738 +
20739 +#include <linux/in.h>
20740 +#include <linux/inetdevice.h>
20741 +#include <linux/vs_inet.h>
20742 +#include <linux/vs_inet6.h>
20743 +#include <linux/vserver/debug.h>
20744 +#include <net/route.h>
20745 +#include <net/addrconf.h>
20746 +
20747 +
20748 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20749 +{
20750 +       int ret = 0;
20751 +
20752 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20753 +               ret = 1;
20754 +       else {
20755 +               struct nx_addr_v4 *ptr;
20756 +
20757 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20758 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20759 +                               ret = 1;
20760 +                               break;
20761 +                       }
20762 +               }
20763 +       }
20764 +
20765 +       vxdprintk(VXD_CBIT(net, 2),
20766 +               "nx_v4_addr_conflict(%p,%p): %d",
20767 +               nxi1, nxi2, ret);
20768 +
20769 +       return ret;
20770 +}
20771 +
20772 +
20773 +#ifdef CONFIG_IPV6
20774 +
20775 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20776 +{
20777 +       int ret = 0;
20778 +
20779 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20780 +               ret = 1;
20781 +       else {
20782 +               struct nx_addr_v6 *ptr;
20783 +
20784 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20785 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20786 +                               ret = 1;
20787 +                               break;
20788 +                       }
20789 +               }
20790 +       }
20791 +
20792 +       vxdprintk(VXD_CBIT(net, 2),
20793 +               "nx_v6_addr_conflict(%p,%p): %d",
20794 +               nxi1, nxi2, ret);
20795 +
20796 +       return ret;
20797 +}
20798 +
20799 +#endif
20800 +
20801 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20802 +{
20803 +       struct in_device *in_dev;
20804 +       struct in_ifaddr **ifap;
20805 +       struct in_ifaddr *ifa;
20806 +       int ret = 0;
20807 +
20808 +       if (!dev)
20809 +               goto out;
20810 +       in_dev = in_dev_get(dev);
20811 +       if (!in_dev)
20812 +               goto out;
20813 +
20814 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20815 +               ifap = &ifa->ifa_next) {
20816 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20817 +                       ret = 1;
20818 +                       break;
20819 +               }
20820 +       }
20821 +       in_dev_put(in_dev);
20822 +out:
20823 +       return ret;
20824 +}
20825 +
20826 +
20827 +#ifdef CONFIG_IPV6
20828 +
20829 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20830 +{
20831 +       struct inet6_dev *in_dev;
20832 +       struct inet6_ifaddr **ifap;
20833 +       struct inet6_ifaddr *ifa;
20834 +       int ret = 0;
20835 +
20836 +       if (!dev)
20837 +               goto out;
20838 +       in_dev = in6_dev_get(dev);
20839 +       if (!in_dev)
20840 +               goto out;
20841 +
20842 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20843 +               ifap = &ifa->if_next) {
20844 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20845 +                       ret = 1;
20846 +                       break;
20847 +               }
20848 +       }
20849 +       in6_dev_put(in_dev);
20850 +out:
20851 +       return ret;
20852 +}
20853 +
20854 +#endif
20855 +
20856 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20857 +{
20858 +       int ret = 1;
20859 +
20860 +       if (!nxi)
20861 +               goto out;
20862 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20863 +               goto out;
20864 +#ifdef CONFIG_IPV6
20865 +       ret = 2;
20866 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20867 +               goto out;
20868 +#endif
20869 +       ret = 0;
20870 +out:
20871 +       vxdprintk(VXD_CBIT(net, 3),
20872 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20873 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20874 +       return ret;
20875 +}
20876 +
20877 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20878 +       struct rtable **rp, struct flowi *fl)
20879 +{
20880 +       if (!nxi)
20881 +               return 0;
20882 +
20883 +       /* FIXME: handle lback only case */
20884 +       if (!NX_IPV4(nxi))
20885 +               return -EPERM;
20886 +
20887 +       vxdprintk(VXD_CBIT(net, 4),
20888 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20889 +               nxi, nxi ? nxi->nx_id : 0,
20890 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20891 +
20892 +       /* single IP is unconditional */
20893 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20894 +               (fl->fl4_src == INADDR_ANY))
20895 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20896 +
20897 +       if (fl->fl4_src == INADDR_ANY) {
20898 +               struct nx_addr_v4 *ptr;
20899 +               __be32 found = 0;
20900 +               int err;
20901 +
20902 +               err = __ip_route_output_key(net, rp, fl);
20903 +               if (!err) {
20904 +                       found = (*rp)->rt_src;
20905 +                       ip_rt_put(*rp);
20906 +                       vxdprintk(VXD_CBIT(net, 4),
20907 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20908 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20909 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20910 +                               goto found;
20911 +               }
20912 +
20913 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20914 +                       __be32 primary = ptr->ip[0].s_addr;
20915 +                       __be32 mask = ptr->mask.s_addr;
20916 +                       __be32 neta = primary & mask;
20917 +
20918 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20919 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20920 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20921 +                               NIPQUAD(mask), NIPQUAD(neta));
20922 +                       if ((found & mask) != neta)
20923 +                               continue;
20924 +
20925 +                       fl->fl4_src = primary;
20926 +                       err = __ip_route_output_key(net, rp, fl);
20927 +                       vxdprintk(VXD_CBIT(net, 4),
20928 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20929 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20930 +                       if (!err) {
20931 +                               found = (*rp)->rt_src;
20932 +                               ip_rt_put(*rp);
20933 +                               if (found == primary)
20934 +                                       goto found;
20935 +                       }
20936 +               }
20937 +               /* still no source ip? */
20938 +               found = ipv4_is_loopback(fl->fl4_dst)
20939 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20940 +       found:
20941 +               /* assign src ip to flow */
20942 +               fl->fl4_src = found;
20943 +
20944 +       } else {
20945 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20946 +                       return -EPERM;
20947 +       }
20948 +
20949 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20950 +               if (ipv4_is_loopback(fl->fl4_dst))
20951 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20952 +               if (ipv4_is_loopback(fl->fl4_src))
20953 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20954 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20955 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20956 +               return -EPERM;
20957 +
20958 +       return 0;
20959 +}
20960 +
20961 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20962 +
20963 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/init.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/init.c
20964 --- linux-2.6.32.24/kernel/vserver/init.c       1970-01-01 01:00:00.000000000 +0100
20965 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/init.c       2009-12-03 20:04:56.000000000 +0100
20966 @@ -0,0 +1,45 @@
20967 +/*
20968 + *  linux/kernel/init.c
20969 + *
20970 + *  Virtual Server Init
20971 + *
20972 + *  Copyright (C) 2004-2007  Herbert Pötzl
20973 + *
20974 + *  V0.01  basic structure
20975 + *
20976 + */
20977 +
20978 +#include <linux/init.h>
20979 +
20980 +int    vserver_register_sysctl(void);
20981 +void   vserver_unregister_sysctl(void);
20982 +
20983 +
20984 +static int __init init_vserver(void)
20985 +{
20986 +       int ret = 0;
20987 +
20988 +#ifdef CONFIG_VSERVER_DEBUG
20989 +       vserver_register_sysctl();
20990 +#endif
20991 +       return ret;
20992 +}
20993 +
20994 +
20995 +static void __exit exit_vserver(void)
20996 +{
20997 +
20998 +#ifdef CONFIG_VSERVER_DEBUG
20999 +       vserver_unregister_sysctl();
21000 +#endif
21001 +       return;
21002 +}
21003 +
21004 +/* FIXME: GFP_ZONETYPES gone
21005 +long vx_slab[GFP_ZONETYPES]; */
21006 +long vx_area;
21007 +
21008 +
21009 +module_init(init_vserver);
21010 +module_exit(exit_vserver);
21011 +
21012 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/inode.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/inode.c
21013 --- linux-2.6.32.24/kernel/vserver/inode.c      1970-01-01 01:00:00.000000000 +0100
21014 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/inode.c      2009-12-03 20:04:56.000000000 +0100
21015 @@ -0,0 +1,433 @@
21016 +/*
21017 + *  linux/kernel/vserver/inode.c
21018 + *
21019 + *  Virtual Server: File System Support
21020 + *
21021 + *  Copyright (C) 2004-2007  Herbert Pötzl
21022 + *
21023 + *  V0.01  separated from vcontext V0.05
21024 + *  V0.02  moved to tag (instead of xid)
21025 + *
21026 + */
21027 +
21028 +#include <linux/tty.h>
21029 +#include <linux/proc_fs.h>
21030 +#include <linux/devpts_fs.h>
21031 +#include <linux/fs.h>
21032 +#include <linux/file.h>
21033 +#include <linux/mount.h>
21034 +#include <linux/parser.h>
21035 +#include <linux/namei.h>
21036 +#include <linux/vserver/inode.h>
21037 +#include <linux/vserver/inode_cmd.h>
21038 +#include <linux/vs_base.h>
21039 +#include <linux/vs_tag.h>
21040 +
21041 +#include <asm/uaccess.h>
21042 +
21043 +
21044 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21045 +{
21046 +       struct proc_dir_entry *entry;
21047 +
21048 +       if (!in || !in->i_sb)
21049 +               return -ESRCH;
21050 +
21051 +       *flags = IATTR_TAG
21052 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
21053 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
21054 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
21055 +               | (IS_COW(in) ? IATTR_COW : 0);
21056 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
21057 +
21058 +       if (S_ISDIR(in->i_mode))
21059 +               *mask |= IATTR_BARRIER;
21060 +
21061 +       if (IS_TAGGED(in)) {
21062 +               *tag = in->i_tag;
21063 +               *mask |= IATTR_TAG;
21064 +       }
21065 +
21066 +       switch (in->i_sb->s_magic) {
21067 +       case PROC_SUPER_MAGIC:
21068 +               entry = PROC_I(in)->pde;
21069 +
21070 +               /* check for specific inodes? */
21071 +               if (entry)
21072 +                       *mask |= IATTR_FLAGS;
21073 +               if (entry)
21074 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
21075 +               else
21076 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21077 +               break;
21078 +
21079 +       case DEVPTS_SUPER_MAGIC:
21080 +               *tag = in->i_tag;
21081 +               *mask |= IATTR_TAG;
21082 +               break;
21083 +
21084 +       default:
21085 +               break;
21086 +       }
21087 +       return 0;
21088 +}
21089 +
21090 +int vc_get_iattr(void __user *data)
21091 +{
21092 +       struct path path;
21093 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
21094 +       int ret;
21095 +
21096 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21097 +               return -EFAULT;
21098 +
21099 +       ret = user_lpath(vc_data.name, &path);
21100 +       if (!ret) {
21101 +               ret = __vc_get_iattr(path.dentry->d_inode,
21102 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21103 +               path_put(&path);
21104 +       }
21105 +       if (ret)
21106 +               return ret;
21107 +
21108 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21109 +               ret = -EFAULT;
21110 +       return ret;
21111 +}
21112 +
21113 +#ifdef CONFIG_COMPAT
21114 +
21115 +int vc_get_iattr_x32(void __user *data)
21116 +{
21117 +       struct path path;
21118 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
21119 +       int ret;
21120 +
21121 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21122 +               return -EFAULT;
21123 +
21124 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21125 +       if (!ret) {
21126 +               ret = __vc_get_iattr(path.dentry->d_inode,
21127 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21128 +               path_put(&path);
21129 +       }
21130 +       if (ret)
21131 +               return ret;
21132 +
21133 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21134 +               ret = -EFAULT;
21135 +       return ret;
21136 +}
21137 +
21138 +#endif /* CONFIG_COMPAT */
21139 +
21140 +
21141 +int vc_fget_iattr(uint32_t fd, void __user *data)
21142 +{
21143 +       struct file *filp;
21144 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
21145 +       int ret;
21146 +
21147 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21148 +               return -EFAULT;
21149 +
21150 +       filp = fget(fd);
21151 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21152 +               return -EBADF;
21153 +
21154 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21155 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
21156 +
21157 +       fput(filp);
21158 +
21159 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21160 +               ret = -EFAULT;
21161 +       return ret;
21162 +}
21163 +
21164 +
21165 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21166 +{
21167 +       struct inode *in = de->d_inode;
21168 +       int error = 0, is_proc = 0, has_tag = 0;
21169 +       struct iattr attr = { 0 };
21170 +
21171 +       if (!in || !in->i_sb)
21172 +               return -ESRCH;
21173 +
21174 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21175 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21176 +               return -EINVAL;
21177 +
21178 +       has_tag = IS_TAGGED(in) ||
21179 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21180 +       if ((*mask & IATTR_TAG) && !has_tag)
21181 +               return -EINVAL;
21182 +
21183 +       mutex_lock(&in->i_mutex);
21184 +       if (*mask & IATTR_TAG) {
21185 +               attr.ia_tag = *tag;
21186 +               attr.ia_valid |= ATTR_TAG;
21187 +       }
21188 +
21189 +       if (*mask & IATTR_FLAGS) {
21190 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21191 +               unsigned int iflags = PROC_I(in)->vx_flags;
21192 +
21193 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21194 +                       | (*flags & IATTR_FLAGS);
21195 +               PROC_I(in)->vx_flags = iflags;
21196 +               if (entry)
21197 +                       entry->vx_flags = iflags;
21198 +       }
21199 +
21200 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
21201 +               IATTR_BARRIER | IATTR_COW)) {
21202 +               int iflags = in->i_flags;
21203 +               int vflags = in->i_vflags;
21204 +
21205 +               if (*mask & IATTR_IMMUTABLE) {
21206 +                       if (*flags & IATTR_IMMUTABLE)
21207 +                               iflags |= S_IMMUTABLE;
21208 +                       else
21209 +                               iflags &= ~S_IMMUTABLE;
21210 +               }
21211 +               if (*mask & IATTR_IXUNLINK) {
21212 +                       if (*flags & IATTR_IXUNLINK)
21213 +                               iflags |= S_IXUNLINK;
21214 +                       else
21215 +                               iflags &= ~S_IXUNLINK;
21216 +               }
21217 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21218 +                       if (*flags & IATTR_BARRIER)
21219 +                               vflags |= V_BARRIER;
21220 +                       else
21221 +                               vflags &= ~V_BARRIER;
21222 +               }
21223 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
21224 +                       if (*flags & IATTR_COW)
21225 +                               vflags |= V_COW;
21226 +                       else
21227 +                               vflags &= ~V_COW;
21228 +               }
21229 +               if (in->i_op && in->i_op->sync_flags) {
21230 +                       error = in->i_op->sync_flags(in, iflags, vflags);
21231 +                       if (error)
21232 +                               goto out;
21233 +               }
21234 +       }
21235 +
21236 +       if (attr.ia_valid) {
21237 +               if (in->i_op && in->i_op->setattr)
21238 +                       error = in->i_op->setattr(de, &attr);
21239 +               else {
21240 +                       error = inode_change_ok(in, &attr);
21241 +                       if (!error)
21242 +                               error = inode_setattr(in, &attr);
21243 +               }
21244 +       }
21245 +
21246 +out:
21247 +       mutex_unlock(&in->i_mutex);
21248 +       return error;
21249 +}
21250 +
21251 +int vc_set_iattr(void __user *data)
21252 +{
21253 +       struct path path;
21254 +       struct vcmd_ctx_iattr_v1 vc_data;
21255 +       int ret;
21256 +
21257 +       if (!capable(CAP_LINUX_IMMUTABLE))
21258 +               return -EPERM;
21259 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21260 +               return -EFAULT;
21261 +
21262 +       ret = user_lpath(vc_data.name, &path);
21263 +       if (!ret) {
21264 +               ret = __vc_set_iattr(path.dentry,
21265 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21266 +               path_put(&path);
21267 +       }
21268 +
21269 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21270 +               ret = -EFAULT;
21271 +       return ret;
21272 +}
21273 +
21274 +#ifdef CONFIG_COMPAT
21275 +
21276 +int vc_set_iattr_x32(void __user *data)
21277 +{
21278 +       struct path path;
21279 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21280 +       int ret;
21281 +
21282 +       if (!capable(CAP_LINUX_IMMUTABLE))
21283 +               return -EPERM;
21284 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21285 +               return -EFAULT;
21286 +
21287 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21288 +       if (!ret) {
21289 +               ret = __vc_set_iattr(path.dentry,
21290 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21291 +               path_put(&path);
21292 +       }
21293 +
21294 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21295 +               ret = -EFAULT;
21296 +       return ret;
21297 +}
21298 +
21299 +#endif /* CONFIG_COMPAT */
21300 +
21301 +int vc_fset_iattr(uint32_t fd, void __user *data)
21302 +{
21303 +       struct file *filp;
21304 +       struct vcmd_ctx_fiattr_v0 vc_data;
21305 +       int ret;
21306 +
21307 +       if (!capable(CAP_LINUX_IMMUTABLE))
21308 +               return -EPERM;
21309 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21310 +               return -EFAULT;
21311 +
21312 +       filp = fget(fd);
21313 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21314 +               return -EBADF;
21315 +
21316 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21317 +               &vc_data.flags, &vc_data.mask);
21318 +
21319 +       fput(filp);
21320 +
21321 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21322 +               return -EFAULT;
21323 +       return ret;
21324 +}
21325 +
21326 +
21327 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21328 +
21329 +static match_table_t tokens = {
21330 +       {Opt_notagcheck, "notagcheck"},
21331 +#ifdef CONFIG_PROPAGATE
21332 +       {Opt_notag, "notag"},
21333 +       {Opt_tag, "tag"},
21334 +       {Opt_tagid, "tagid=%u"},
21335 +#endif
21336 +       {Opt_err, NULL}
21337 +};
21338 +
21339 +
21340 +static void __dx_parse_remove(char *string, char *opt)
21341 +{
21342 +       char *p = strstr(string, opt);
21343 +       char *q = p;
21344 +
21345 +       if (p) {
21346 +               while (*q != '\0' && *q != ',')
21347 +                       q++;
21348 +               while (*q)
21349 +                       *p++ = *q++;
21350 +               while (*p)
21351 +                       *p++ = '\0';
21352 +       }
21353 +}
21354 +
21355 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
21356 +                unsigned long *flags)
21357 +{
21358 +       int set = 0;
21359 +       substring_t args[MAX_OPT_ARGS];
21360 +       int token, option = 0;
21361 +       char *s, *p, *opts;
21362 +
21363 +       if (!string)
21364 +               return 0;
21365 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
21366 +       if (!s)
21367 +               return 0;
21368 +
21369 +       opts = s;
21370 +       while ((p = strsep(&opts, ",")) != NULL) {
21371 +               token = match_token(p, tokens, args);
21372 +
21373 +               vxdprintk(VXD_CBIT(tag, 7),
21374 +                       "dx_parse_tag(»%s«): %d:#%d",
21375 +                       p, token, option);
21376 +
21377 +               switch (token) {
21378 +#ifdef CONFIG_PROPAGATE
21379 +               case Opt_tag:
21380 +                       if (tag)
21381 +                               *tag = 0;
21382 +                       if (remove)
21383 +                               __dx_parse_remove(s, "tag");
21384 +                       *mnt_flags |= MNT_TAGID;
21385 +                       set |= MNT_TAGID;
21386 +                       break;
21387 +               case Opt_notag:
21388 +                       if (remove)
21389 +                               __dx_parse_remove(s, "notag");
21390 +                       *mnt_flags |= MNT_NOTAG;
21391 +                       set |= MNT_NOTAG;
21392 +                       break;
21393 +               case Opt_tagid:
21394 +                       if (tag && !match_int(args, &option))
21395 +                               *tag = option;
21396 +                       if (remove)
21397 +                               __dx_parse_remove(s, "tagid");
21398 +                       *mnt_flags |= MNT_TAGID;
21399 +                       set |= MNT_TAGID;
21400 +                       break;
21401 +#endif
21402 +               case Opt_notagcheck:
21403 +                       if (remove)
21404 +                               __dx_parse_remove(s, "notagcheck");
21405 +                       *flags |= MS_NOTAGCHECK;
21406 +                       set |= MS_NOTAGCHECK;
21407 +                       break;
21408 +               }
21409 +       }
21410 +       if (set)
21411 +               strcpy(string, s);
21412 +       kfree(s);
21413 +       return set;
21414 +}
21415 +
21416 +#ifdef CONFIG_PROPAGATE
21417 +
21418 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21419 +{
21420 +       tag_t new_tag = 0;
21421 +       struct vfsmount *mnt;
21422 +       int propagate;
21423 +
21424 +       if (!nd)
21425 +               return;
21426 +       mnt = nd->path.mnt;
21427 +       if (!mnt)
21428 +               return;
21429 +
21430 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21431 +       if (propagate)
21432 +               new_tag = mnt->mnt_tag;
21433 +
21434 +       vxdprintk(VXD_CBIT(tag, 7),
21435 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21436 +               inode, inode->i_ino, inode->i_tag,
21437 +               new_tag, (propagate) ? 1 : 0);
21438 +
21439 +       if (propagate)
21440 +               inode->i_tag = new_tag;
21441 +}
21442 +
21443 +#include <linux/module.h>
21444 +
21445 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21446 +
21447 +#endif /* CONFIG_PROPAGATE */
21448 +
21449 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/Kconfig
21450 --- linux-2.6.32.24/kernel/vserver/Kconfig      1970-01-01 01:00:00.000000000 +0100
21451 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/Kconfig      2010-02-14 01:02:13.000000000 +0100
21452 @@ -0,0 +1,251 @@
21453 +#
21454 +# Linux VServer configuration
21455 +#
21456 +
21457 +menu "Linux VServer"
21458 +
21459 +config VSERVER_AUTO_LBACK
21460 +       bool    "Automatically Assign Loopback IP"
21461 +       default y
21462 +       help
21463 +         Automatically assign a guest specific loopback
21464 +         IP and add it to the kernel network stack on
21465 +         startup.
21466 +
21467 +config VSERVER_AUTO_SINGLE
21468 +       bool    "Automatic Single IP Special Casing"
21469 +       depends on EXPERIMENTAL
21470 +       default y
21471 +       help
21472 +         This allows network contexts with a single IP to
21473 +         automatically remap 0.0.0.0 bindings to that IP,
21474 +         avoiding further network checks and improving
21475 +         performance.
21476 +
21477 +         (note: such guests do not allow to change the ip
21478 +          on the fly and do not show loopback addresses)
21479 +
21480 +config VSERVER_COWBL
21481 +       bool    "Enable COW Immutable Link Breaking"
21482 +       default y
21483 +       help
21484 +         This enables the COW (Copy-On-Write) link break code.
21485 +         It allows you to treat unified files like normal files
21486 +         when writing to them (which will implicitely break the
21487 +         link and create a copy of the unified file)
21488 +
21489 +config VSERVER_VTIME
21490 +       bool    "Enable Virtualized Guest Time"
21491 +       depends on EXPERIMENTAL
21492 +       default n
21493 +       help
21494 +         This enables per guest time offsets to allow for
21495 +         adjusting the system clock individually per guest.
21496 +         this adds some overhead to the time functions and
21497 +         therefore should not be enabled without good reason.
21498 +
21499 +config VSERVER_DEVICE
21500 +       bool    "Enable Guest Device Mapping"
21501 +       depends on EXPERIMENTAL
21502 +       default n
21503 +       help
21504 +         This enables generic device remapping.
21505 +
21506 +config VSERVER_PROC_SECURE
21507 +       bool    "Enable Proc Security"
21508 +       depends on PROC_FS
21509 +       default y
21510 +       help
21511 +         This configures ProcFS security to initially hide
21512 +         non-process entries for all contexts except the main and
21513 +         spectator context (i.e. for all guests), which is a secure
21514 +         default.
21515 +
21516 +         (note: on 1.2x the entries were visible by default)
21517 +
21518 +config VSERVER_HARDCPU
21519 +       bool    "Enable Hard CPU Limits"
21520 +       default y
21521 +       help
21522 +         Activate the Hard CPU Limits
21523 +
21524 +         This will compile in code that allows the Token Bucket
21525 +         Scheduler to put processes on hold when a context's
21526 +         tokens are depleted (provided that its per-context
21527 +         sched_hard flag is set).
21528 +
21529 +         Processes belonging to that context will not be able
21530 +         to consume CPU resources again until a per-context
21531 +         configured minimum of tokens has been reached.
21532 +
21533 +config VSERVER_IDLETIME
21534 +       bool    "Avoid idle CPUs by skipping Time"
21535 +       depends on VSERVER_HARDCPU
21536 +       default y
21537 +       help
21538 +         This option allows the scheduler to artificially
21539 +         advance time (per cpu) when otherwise the idle
21540 +         task would be scheduled, thus keeping the cpu
21541 +         busy and sharing the available resources among
21542 +         certain contexts.
21543 +
21544 +config VSERVER_IDLELIMIT
21545 +       bool    "Limit the IDLE task"
21546 +       depends on VSERVER_HARDCPU
21547 +       default n
21548 +       help
21549 +         Limit the idle slices, so the the next context
21550 +         will be scheduled as soon as possible.
21551 +
21552 +         This might improve interactivity and latency, but
21553 +         will also marginally increase scheduling overhead.
21554 +
21555 +choice
21556 +       prompt  "Persistent Inode Tagging"
21557 +       default TAGGING_ID24
21558 +       help
21559 +         This adds persistent context information to filesystems
21560 +         mounted with the tagxid option. Tagging is a requirement
21561 +         for per-context disk limits and per-context quota.
21562 +
21563 +
21564 +config TAGGING_NONE
21565 +       bool    "Disabled"
21566 +       help
21567 +         do not store per-context information in inodes.
21568 +
21569 +config TAGGING_UID16
21570 +       bool    "UID16/GID32"
21571 +       help
21572 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21573 +
21574 +config TAGGING_GID16
21575 +       bool    "UID32/GID16"
21576 +       help
21577 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21578 +
21579 +config TAGGING_ID24
21580 +       bool    "UID24/GID24"
21581 +       help
21582 +         uses the upper 8bit from UID and GID for XID tagging
21583 +         which leaves 24bit for UID/GID each, which should be
21584 +         more than sufficient for normal use.
21585 +
21586 +config TAGGING_INTERN
21587 +       bool    "UID32/GID32"
21588 +       help
21589 +         this uses otherwise reserved inode fields in the on
21590 +         disk representation, which limits the use to a few
21591 +         filesystems (currently ext2 and ext3)
21592 +
21593 +endchoice
21594 +
21595 +config TAG_NFSD
21596 +       bool    "Tag NFSD User Auth and Files"
21597 +       default n
21598 +       help
21599 +         Enable this if you do want the in-kernel NFS
21600 +         Server to use the tagging specified above.
21601 +         (will require patched clients too)
21602 +
21603 +config VSERVER_PRIVACY
21604 +       bool    "Honor Privacy Aspects of Guests"
21605 +       default n
21606 +       help
21607 +         When enabled, most context checks will disallow
21608 +         access to structures assigned to a specific context,
21609 +         like ptys or loop devices.
21610 +
21611 +config VSERVER_CONTEXTS
21612 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21613 +       range 1 65533
21614 +       default "768"   if 64BIT
21615 +       default "256"
21616 +       help
21617 +         This setting will optimize certain data structures
21618 +         and memory allocations according to the expected
21619 +         maximum.
21620 +
21621 +         note: this is not a strict upper limit.
21622 +
21623 +config VSERVER_WARN
21624 +       bool    "VServer Warnings"
21625 +       default y
21626 +       help
21627 +         This enables various runtime warnings, which will
21628 +         notify about potential manipulation attempts or
21629 +         resource shortage. It is generally considered to
21630 +         be a good idea to have that enabled.
21631 +
21632 +config VSERVER_DEBUG
21633 +       bool    "VServer Debugging Code"
21634 +       default n
21635 +       help
21636 +         Set this to yes if you want to be able to activate
21637 +         debugging output at runtime. It adds a very small
21638 +         overhead to all vserver related functions and
21639 +         increases the kernel size by about 20k.
21640 +
21641 +config VSERVER_HISTORY
21642 +       bool    "VServer History Tracing"
21643 +       depends on VSERVER_DEBUG
21644 +       default n
21645 +       help
21646 +         Set this to yes if you want to record the history of
21647 +         linux-vserver activities, so they can be replayed in
21648 +         the event of a kernel panic or oops.
21649 +
21650 +config VSERVER_HISTORY_SIZE
21651 +       int     "Per-CPU History Size (32-65536)"
21652 +       depends on VSERVER_HISTORY
21653 +       range 32 65536
21654 +       default 64
21655 +       help
21656 +         This allows you to specify the number of entries in
21657 +         the per-CPU history buffer.
21658 +
21659 +config VSERVER_MONITOR
21660 +       bool    "VServer Scheduling Monitor"
21661 +       depends on VSERVER_DISABLED
21662 +       default n
21663 +       help
21664 +         Set this to yes if you want to record the scheduling
21665 +         decisions, so that they can be relayed to userspace
21666 +         for detailed analysis.
21667 +
21668 +config VSERVER_MONITOR_SIZE
21669 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21670 +       depends on VSERVER_MONITOR
21671 +       range 32 65536
21672 +       default 1024
21673 +       help
21674 +         This allows you to specify the number of entries in
21675 +         the per-CPU scheduling monitor buffer.
21676 +
21677 +config VSERVER_MONITOR_SYNC
21678 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21679 +       depends on VSERVER_MONITOR
21680 +       range 0 65536
21681 +       default 256
21682 +       help
21683 +         This allows you to specify the interval in ticks
21684 +         when a time sync entry is inserted.
21685 +
21686 +endmenu
21687 +
21688 +
21689 +config VSERVER
21690 +       bool
21691 +       default y
21692 +       select NAMESPACES
21693 +       select UTS_NS
21694 +       select IPC_NS
21695 +       select USER_NS
21696 +       select SYSVIPC
21697 +
21698 +config VSERVER_SECURITY
21699 +       bool
21700 +       depends on SECURITY
21701 +       default y
21702 +       select SECURITY_CAPABILITIES
21703 +
21704 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/limit.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/limit.c
21705 --- linux-2.6.32.24/kernel/vserver/limit.c      1970-01-01 01:00:00.000000000 +0100
21706 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/limit.c      2010-04-05 21:24:21.000000000 +0200
21707 @@ -0,0 +1,392 @@
21708 +/*
21709 + *  linux/kernel/vserver/limit.c
21710 + *
21711 + *  Virtual Server: Context Limits
21712 + *
21713 + *  Copyright (C) 2004-2010  Herbert Pötzl
21714 + *
21715 + *  V0.01  broken out from vcontext V0.05
21716 + *  V0.02  changed vcmds to vxi arg
21717 + *  V0.03  added memory cgroup support
21718 + *
21719 + */
21720 +
21721 +#include <linux/sched.h>
21722 +#include <linux/module.h>
21723 +#include <linux/memcontrol.h>
21724 +#include <linux/res_counter.h>
21725 +#include <linux/vs_limit.h>
21726 +#include <linux/vserver/limit.h>
21727 +#include <linux/vserver/limit_cmd.h>
21728 +
21729 +#include <asm/uaccess.h>
21730 +
21731 +
21732 +const char *vlimit_name[NUM_LIMITS] = {
21733 +       [RLIMIT_CPU]            = "CPU",
21734 +       [RLIMIT_RSS]            = "RSS",
21735 +       [RLIMIT_NPROC]          = "NPROC",
21736 +       [RLIMIT_NOFILE]         = "NOFILE",
21737 +       [RLIMIT_MEMLOCK]        = "VML",
21738 +       [RLIMIT_AS]             = "VM",
21739 +       [RLIMIT_LOCKS]          = "LOCKS",
21740 +       [RLIMIT_SIGPENDING]     = "SIGP",
21741 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21742 +
21743 +       [VLIMIT_NSOCK]          = "NSOCK",
21744 +       [VLIMIT_OPENFD]         = "OPENFD",
21745 +       [VLIMIT_ANON]           = "ANON",
21746 +       [VLIMIT_SHMEM]          = "SHMEM",
21747 +       [VLIMIT_DENTRY]         = "DENTRY",
21748 +};
21749 +
21750 +EXPORT_SYMBOL_GPL(vlimit_name);
21751 +
21752 +#define MASK_ENTRY(x)  (1 << (x))
21753 +
21754 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21755 +               /* minimum */
21756 +       0
21757 +       ,       /* softlimit */
21758 +       MASK_ENTRY( RLIMIT_RSS          ) |
21759 +       MASK_ENTRY( VLIMIT_ANON         ) |
21760 +       0
21761 +       ,       /* maximum */
21762 +       MASK_ENTRY( RLIMIT_RSS          ) |
21763 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21764 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21765 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21766 +       MASK_ENTRY( RLIMIT_AS           ) |
21767 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21768 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21769 +
21770 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21771 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21772 +       MASK_ENTRY( VLIMIT_ANON         ) |
21773 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21774 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21775 +       0
21776 +};
21777 +               /* accounting only */
21778 +uint32_t account_mask =
21779 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21780 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21781 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21782 +       0;
21783 +
21784 +
21785 +static int is_valid_vlimit(int id)
21786 +{
21787 +       uint32_t mask = vlimit_mask.minimum |
21788 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21789 +       return mask & (1 << id);
21790 +}
21791 +
21792 +static int is_accounted_vlimit(int id)
21793 +{
21794 +       if (is_valid_vlimit(id))
21795 +               return 1;
21796 +       return account_mask & (1 << id);
21797 +}
21798 +
21799 +
21800 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21801 +{
21802 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21803 +       return VX_VLIM(limit);
21804 +}
21805 +
21806 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21807 +{
21808 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21809 +       return VX_VLIM(limit);
21810 +}
21811 +
21812 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21813 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21814 +{
21815 +       if (!is_valid_vlimit(id))
21816 +               return -EINVAL;
21817 +
21818 +       if (minimum)
21819 +               *minimum = CRLIM_UNSET;
21820 +       if (softlimit)
21821 +               *softlimit = vc_get_soft(vxi, id);
21822 +       if (maximum)
21823 +               *maximum = vc_get_hard(vxi, id);
21824 +       return 0;
21825 +}
21826 +
21827 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21828 +{
21829 +       struct vcmd_ctx_rlimit_v0 vc_data;
21830 +       int ret;
21831 +
21832 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21833 +               return -EFAULT;
21834 +
21835 +       ret = do_get_rlimit(vxi, vc_data.id,
21836 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21837 +       if (ret)
21838 +               return ret;
21839 +
21840 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21841 +               return -EFAULT;
21842 +       return 0;
21843 +}
21844 +
21845 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21846 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21847 +{
21848 +       if (!is_valid_vlimit(id))
21849 +               return -EINVAL;
21850 +
21851 +       if (maximum != CRLIM_KEEP)
21852 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21853 +       if (softlimit != CRLIM_KEEP)
21854 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21855 +
21856 +       /* clamp soft limit */
21857 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21858 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21859 +
21860 +       return 0;
21861 +}
21862 +
21863 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21864 +{
21865 +       struct vcmd_ctx_rlimit_v0 vc_data;
21866 +
21867 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21868 +               return -EFAULT;
21869 +
21870 +       return do_set_rlimit(vxi, vc_data.id,
21871 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21872 +}
21873 +
21874 +#ifdef CONFIG_IA32_EMULATION
21875 +
21876 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21877 +{
21878 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21879 +
21880 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21881 +               return -EFAULT;
21882 +
21883 +       return do_set_rlimit(vxi, vc_data.id,
21884 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21885 +}
21886 +
21887 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21888 +{
21889 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21890 +       int ret;
21891 +
21892 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21893 +               return -EFAULT;
21894 +
21895 +       ret = do_get_rlimit(vxi, vc_data.id,
21896 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21897 +       if (ret)
21898 +               return ret;
21899 +
21900 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21901 +               return -EFAULT;
21902 +       return 0;
21903 +}
21904 +
21905 +#endif /* CONFIG_IA32_EMULATION */
21906 +
21907 +
21908 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21909 +{
21910 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21911 +               return -EFAULT;
21912 +       return 0;
21913 +}
21914 +
21915 +
21916 +static inline void vx_reset_hits(struct _vx_limit *limit)
21917 +{
21918 +       int lim;
21919 +
21920 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21921 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21922 +       }
21923 +}
21924 +
21925 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
21926 +{
21927 +       vx_reset_hits(&vxi->limit);
21928 +       return 0;
21929 +}
21930 +
21931 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21932 +{
21933 +       rlim_t value;
21934 +       int lim;
21935 +
21936 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21937 +               value = __rlim_get(limit, lim);
21938 +               __rlim_rmax(limit, lim) = value;
21939 +               __rlim_rmin(limit, lim) = value;
21940 +       }
21941 +}
21942 +
21943 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21944 +{
21945 +       vx_reset_minmax(&vxi->limit);
21946 +       return 0;
21947 +}
21948 +
21949 +
21950 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21951 +{
21952 +       struct vcmd_rlimit_stat_v0 vc_data;
21953 +       struct _vx_limit *limit = &vxi->limit;
21954 +       int id;
21955 +
21956 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21957 +               return -EFAULT;
21958 +
21959 +       id = vc_data.id;
21960 +       if (!is_accounted_vlimit(id))
21961 +               return -EINVAL;
21962 +
21963 +       vx_limit_fixup(limit, id);
21964 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21965 +       vc_data.value = __rlim_get(limit, id);
21966 +       vc_data.minimum = __rlim_rmin(limit, id);
21967 +       vc_data.maximum = __rlim_rmax(limit, id);
21968 +
21969 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21970 +               return -EFAULT;
21971 +       return 0;
21972 +}
21973 +
21974 +
21975 +void vx_vsi_meminfo(struct sysinfo *val)
21976 +{
21977 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
21978 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
21979 +       u64 res_limit, res_usage;
21980 +
21981 +       if (!mcg)
21982 +               return;
21983 +
21984 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
21985 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
21986 +
21987 +       if (res_limit != RESOURCE_MAX)
21988 +               val->totalram = (res_limit >> PAGE_SHIFT);
21989 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
21990 +       val->bufferram = 0;
21991 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR */
21992 +       struct vx_info *vxi = current_vx_info();
21993 +       unsigned long totalram, freeram;
21994 +       rlim_t v;
21995 +
21996 +       /* we blindly accept the max */
21997 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21998 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21999 +
22000 +       /* total minus used equals free */
22001 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22002 +       freeram = (v < totalram) ? totalram - v : 0;
22003 +
22004 +       val->totalram = totalram;
22005 +       val->freeram = freeram;
22006 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
22007 +       val->totalhigh = 0;
22008 +       val->freehigh = 0;
22009 +       return;
22010 +}
22011 +
22012 +void vx_vsi_swapinfo(struct sysinfo *val)
22013 +{
22014 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22015 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
22016 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22017 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
22018 +       s64 swap_limit, swap_usage;
22019 +
22020 +       if (!mcg)
22021 +               return;
22022 +
22023 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
22024 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
22025 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
22026 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
22027 +
22028 +       if (res_limit == RESOURCE_MAX)
22029 +               return;
22030 +
22031 +       swap_limit = memsw_limit - res_limit;
22032 +       if (memsw_limit != RESOURCE_MAX)
22033 +               val->totalswap = swap_limit >> PAGE_SHIFT;
22034 +
22035 +       swap_usage = memsw_usage - res_usage;
22036 +       val->freeswap = (swap_usage < swap_limit) ?
22037 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
22038 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
22039 +       val->totalswap = 0;
22040 +       val->freeswap = 0;
22041 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
22042 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR */
22043 +       struct vx_info *vxi = current_vx_info();
22044 +       unsigned long totalswap, freeswap;
22045 +       rlim_t v, w;
22046 +
22047 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22048 +       if (v == RLIM_INFINITY) {
22049 +               val->freeswap = val->totalswap;
22050 +               return;
22051 +       }
22052 +
22053 +       /* we blindly accept the max */
22054 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
22055 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
22056 +
22057 +       /* currently 'used' swap */
22058 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22059 +       w -= (w > v) ? v : w;
22060 +
22061 +       /* total minus used equals free */
22062 +       freeswap = (w < totalswap) ? totalswap - w : 0;
22063 +
22064 +       val->totalswap = totalswap;
22065 +       val->freeswap = freeswap;
22066 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
22067 +       return;
22068 +}
22069 +
22070 +long vx_vsi_cached(struct sysinfo *val)
22071 +{
22072 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22073 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22074 +
22075 +       return mem_cgroup_stat_read_cache(mcg);
22076 +#else
22077 +       return 0;
22078 +#endif
22079 +}
22080 +
22081 +
22082 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
22083 +{
22084 +       struct vx_info *vxi = mm->mm_vx_info;
22085 +       unsigned long points;
22086 +       rlim_t v, w;
22087 +
22088 +       if (!vxi)
22089 +               return 0;
22090 +
22091 +       points = vxi->vx_badness_bias;
22092 +
22093 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22094 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22095 +       points += (v > w) ? (v - w) : 0;
22096 +
22097 +       return points;
22098 +}
22099 +
22100 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/limit_init.h linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/limit_init.h
22101 --- linux-2.6.32.24/kernel/vserver/limit_init.h 1970-01-01 01:00:00.000000000 +0100
22102 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/limit_init.h 2009-12-03 20:04:56.000000000 +0100
22103 @@ -0,0 +1,31 @@
22104 +
22105 +
22106 +static inline void vx_info_init_limit(struct _vx_limit *limit)
22107 +{
22108 +       int lim;
22109 +
22110 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22111 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
22112 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
22113 +               __rlim_set(limit, lim, 0);
22114 +               atomic_set(&__rlim_lhit(limit, lim), 0);
22115 +               __rlim_rmin(limit, lim) = 0;
22116 +               __rlim_rmax(limit, lim) = 0;
22117 +       }
22118 +}
22119 +
22120 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
22121 +{
22122 +       rlim_t value;
22123 +       int lim;
22124 +
22125 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22126 +               if ((1 << lim) & VLIM_NOCHECK)
22127 +                       continue;
22128 +               value = __rlim_get(limit, lim);
22129 +               vxwprintk_xid(value,
22130 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
22131 +                       limit, vlimit_name[lim], lim, (long)value);
22132 +       }
22133 +}
22134 +
22135 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/limit_proc.h linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/limit_proc.h
22136 --- linux-2.6.32.24/kernel/vserver/limit_proc.h 1970-01-01 01:00:00.000000000 +0100
22137 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/limit_proc.h 2009-12-03 20:04:56.000000000 +0100
22138 @@ -0,0 +1,57 @@
22139 +#ifndef _VX_LIMIT_PROC_H
22140 +#define _VX_LIMIT_PROC_H
22141 +
22142 +#include <linux/vserver/limit_int.h>
22143 +
22144 +
22145 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
22146 +#define VX_LIMIT_TOP   \
22147 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
22148 +
22149 +#define VX_LIMIT_ARG(r)                                \
22150 +       (unsigned long)__rlim_get(limit, r),    \
22151 +       (unsigned long)__rlim_rmin(limit, r),   \
22152 +       (unsigned long)__rlim_rmax(limit, r),   \
22153 +       VX_VLIM(__rlim_soft(limit, r)),         \
22154 +       VX_VLIM(__rlim_hard(limit, r)),         \
22155 +       atomic_read(&__rlim_lhit(limit, r))
22156 +
22157 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
22158 +{
22159 +       vx_limit_fixup(limit, -1);
22160 +       return sprintf(buffer, VX_LIMIT_TOP
22161 +               "PROC"  VX_LIMIT_FMT
22162 +               "VM"    VX_LIMIT_FMT
22163 +               "VML"   VX_LIMIT_FMT
22164 +               "RSS"   VX_LIMIT_FMT
22165 +               "ANON"  VX_LIMIT_FMT
22166 +               "RMAP"  VX_LIMIT_FMT
22167 +               "FILES" VX_LIMIT_FMT
22168 +               "OFD"   VX_LIMIT_FMT
22169 +               "LOCKS" VX_LIMIT_FMT
22170 +               "SOCK"  VX_LIMIT_FMT
22171 +               "MSGQ"  VX_LIMIT_FMT
22172 +               "SHM"   VX_LIMIT_FMT
22173 +               "SEMA"  VX_LIMIT_FMT
22174 +               "SEMS"  VX_LIMIT_FMT
22175 +               "DENT"  VX_LIMIT_FMT,
22176 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22177 +               VX_LIMIT_ARG(RLIMIT_AS),
22178 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22179 +               VX_LIMIT_ARG(RLIMIT_RSS),
22180 +               VX_LIMIT_ARG(VLIMIT_ANON),
22181 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22182 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22183 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22184 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22185 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22186 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22187 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22188 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22189 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22190 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22191 +}
22192 +
22193 +#endif /* _VX_LIMIT_PROC_H */
22194 +
22195 +
22196 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/Makefile linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/Makefile
22197 --- linux-2.6.32.24/kernel/vserver/Makefile     1970-01-01 01:00:00.000000000 +0100
22198 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/Makefile     2009-12-03 20:04:56.000000000 +0100
22199 @@ -0,0 +1,18 @@
22200 +#
22201 +# Makefile for the Linux vserver routines.
22202 +#
22203 +
22204 +
22205 +obj-y          += vserver.o
22206 +
22207 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
22208 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
22209 +                  dlimit.o tag.o
22210 +
22211 +vserver-$(CONFIG_INET) += inet.o
22212 +vserver-$(CONFIG_PROC_FS) += proc.o
22213 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
22214 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
22215 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
22216 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
22217 +
22218 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/monitor.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/monitor.c
22219 --- linux-2.6.32.24/kernel/vserver/monitor.c    1970-01-01 01:00:00.000000000 +0100
22220 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/monitor.c    2009-12-03 20:04:56.000000000 +0100
22221 @@ -0,0 +1,138 @@
22222 +/*
22223 + *  kernel/vserver/monitor.c
22224 + *
22225 + *  Virtual Context Scheduler Monitor
22226 + *
22227 + *  Copyright (C) 2006-2007 Herbert Pötzl
22228 + *
22229 + *  V0.01  basic design
22230 + *
22231 + */
22232 +
22233 +#include <linux/module.h>
22234 +#include <linux/jiffies.h>
22235 +#include <asm/uaccess.h>
22236 +#include <asm/atomic.h>
22237 +
22238 +#include <linux/vserver/monitor.h>
22239 +#include <linux/vserver/debug_cmd.h>
22240 +
22241 +
22242 +#ifdef CONFIG_VSERVER_MONITOR
22243 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
22244 +#else
22245 +#define VXM_SIZE       64
22246 +#endif
22247 +
22248 +struct _vx_monitor {
22249 +       unsigned int counter;
22250 +
22251 +       struct _vx_mon_entry entry[VXM_SIZE+1];
22252 +};
22253 +
22254 +
22255 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
22256 +
22257 +unsigned volatile int vxm_active = 1;
22258 +
22259 +static atomic_t sequence = ATOMIC_INIT(0);
22260 +
22261 +
22262 +/*     vxm_advance()
22263 +
22264 +       * requires disabled preemption                          */
22265 +
22266 +struct _vx_mon_entry *vxm_advance(int cpu)
22267 +{
22268 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22269 +       struct _vx_mon_entry *entry;
22270 +       unsigned int index;
22271 +
22272 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
22273 +       entry = &mon->entry[index];
22274 +
22275 +       entry->ev.seq = atomic_inc_return(&sequence);
22276 +       entry->ev.jif = jiffies;
22277 +       return entry;
22278 +}
22279 +
22280 +EXPORT_SYMBOL_GPL(vxm_advance);
22281 +
22282 +
22283 +int do_read_monitor(struct __user _vx_mon_entry *data,
22284 +       int cpu, uint32_t *index, uint32_t *count)
22285 +{
22286 +       int pos, ret = 0;
22287 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22288 +       int end = mon->counter;
22289 +       int start = end - VXM_SIZE + 2;
22290 +       int idx = *index;
22291 +
22292 +       /* special case: get current pos */
22293 +       if (!*count) {
22294 +               *index = end;
22295 +               return 0;
22296 +       }
22297 +
22298 +       /* have we lost some data? */
22299 +       if (idx < start)
22300 +               idx = start;
22301 +
22302 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22303 +               struct _vx_mon_entry *entry =
22304 +                       &mon->entry[idx % VXM_SIZE];
22305 +
22306 +               /* send entry to userspace */
22307 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22308 +               if (ret)
22309 +                       break;
22310 +       }
22311 +       /* save new index and count */
22312 +       *index = idx;
22313 +       *count = pos;
22314 +       return ret ? ret : (*index < end);
22315 +}
22316 +
22317 +int vc_read_monitor(uint32_t id, void __user *data)
22318 +{
22319 +       struct vcmd_read_monitor_v0 vc_data;
22320 +       int ret;
22321 +
22322 +       if (id >= NR_CPUS)
22323 +               return -EINVAL;
22324 +
22325 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22326 +               return -EFAULT;
22327 +
22328 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
22329 +               id, &vc_data.index, &vc_data.count);
22330 +
22331 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22332 +               return -EFAULT;
22333 +       return ret;
22334 +}
22335 +
22336 +#ifdef CONFIG_COMPAT
22337 +
22338 +int vc_read_monitor_x32(uint32_t id, void __user *data)
22339 +{
22340 +       struct vcmd_read_monitor_v0_x32 vc_data;
22341 +       int ret;
22342 +
22343 +       if (id >= NR_CPUS)
22344 +               return -EINVAL;
22345 +
22346 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22347 +               return -EFAULT;
22348 +
22349 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
22350 +               compat_ptr(vc_data.data_ptr),
22351 +               id, &vc_data.index, &vc_data.count);
22352 +
22353 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22354 +               return -EFAULT;
22355 +       return ret;
22356 +}
22357 +
22358 +#endif /* CONFIG_COMPAT */
22359 +
22360 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/network.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/network.c
22361 --- linux-2.6.32.24/kernel/vserver/network.c    1970-01-01 01:00:00.000000000 +0100
22362 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/network.c    2009-12-03 20:04:56.000000000 +0100
22363 @@ -0,0 +1,864 @@
22364 +/*
22365 + *  linux/kernel/vserver/network.c
22366 + *
22367 + *  Virtual Server: Network Support
22368 + *
22369 + *  Copyright (C) 2003-2007  Herbert Pötzl
22370 + *
22371 + *  V0.01  broken out from vcontext V0.05
22372 + *  V0.02  cleaned up implementation
22373 + *  V0.03  added equiv nx commands
22374 + *  V0.04  switch to RCU based hash
22375 + *  V0.05  and back to locking again
22376 + *  V0.06  changed vcmds to nxi arg
22377 + *  V0.07  have __create claim() the nxi
22378 + *
22379 + */
22380 +
22381 +#include <linux/err.h>
22382 +#include <linux/slab.h>
22383 +#include <linux/rcupdate.h>
22384 +
22385 +#include <linux/vs_network.h>
22386 +#include <linux/vs_pid.h>
22387 +#include <linux/vserver/network_cmd.h>
22388 +
22389 +
22390 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22391 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22392 +
22393 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22394 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22395 +
22396 +
22397 +static int __init init_network(void)
22398 +{
22399 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22400 +               sizeof(struct nx_addr_v4), 0,
22401 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22402 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22403 +               sizeof(struct nx_addr_v6), 0,
22404 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22405 +       return 0;
22406 +}
22407 +
22408 +
22409 +/*     __alloc_nx_addr_v4()                                    */
22410 +
22411 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22412 +{
22413 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22414 +               nx_addr_v4_cachep, GFP_KERNEL);
22415 +
22416 +       if (!IS_ERR(nxa))
22417 +               memset(nxa, 0, sizeof(*nxa));
22418 +       return nxa;
22419 +}
22420 +
22421 +/*     __dealloc_nx_addr_v4()                                  */
22422 +
22423 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22424 +{
22425 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22426 +}
22427 +
22428 +/*     __dealloc_nx_addr_v4_all()                              */
22429 +
22430 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22431 +{
22432 +       while (nxa) {
22433 +               struct nx_addr_v4 *next = nxa->next;
22434 +
22435 +               __dealloc_nx_addr_v4(nxa);
22436 +               nxa = next;
22437 +       }
22438 +}
22439 +
22440 +
22441 +#ifdef CONFIG_IPV6
22442 +
22443 +/*     __alloc_nx_addr_v6()                                    */
22444 +
22445 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22446 +{
22447 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22448 +               nx_addr_v6_cachep, GFP_KERNEL);
22449 +
22450 +       if (!IS_ERR(nxa))
22451 +               memset(nxa, 0, sizeof(*nxa));
22452 +       return nxa;
22453 +}
22454 +
22455 +/*     __dealloc_nx_addr_v6()                                  */
22456 +
22457 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22458 +{
22459 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22460 +}
22461 +
22462 +/*     __dealloc_nx_addr_v6_all()                              */
22463 +
22464 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22465 +{
22466 +       while (nxa) {
22467 +               struct nx_addr_v6 *next = nxa->next;
22468 +
22469 +               __dealloc_nx_addr_v6(nxa);
22470 +               nxa = next;
22471 +       }
22472 +}
22473 +
22474 +#endif /* CONFIG_IPV6 */
22475 +
22476 +/*     __alloc_nx_info()
22477 +
22478 +       * allocate an initialized nx_info struct
22479 +       * doesn't make it visible (hash)                        */
22480 +
22481 +static struct nx_info *__alloc_nx_info(nid_t nid)
22482 +{
22483 +       struct nx_info *new = NULL;
22484 +
22485 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22486 +
22487 +       /* would this benefit from a slab cache? */
22488 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22489 +       if (!new)
22490 +               return 0;
22491 +
22492 +       memset(new, 0, sizeof(struct nx_info));
22493 +       new->nx_id = nid;
22494 +       INIT_HLIST_NODE(&new->nx_hlist);
22495 +       atomic_set(&new->nx_usecnt, 0);
22496 +       atomic_set(&new->nx_tasks, 0);
22497 +       new->nx_state = 0;
22498 +
22499 +       new->nx_flags = NXF_INIT_SET;
22500 +
22501 +       /* rest of init goes here */
22502 +
22503 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22504 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22505 +
22506 +       vxdprintk(VXD_CBIT(nid, 0),
22507 +               "alloc_nx_info(%d) = %p", nid, new);
22508 +       atomic_inc(&nx_global_ctotal);
22509 +       return new;
22510 +}
22511 +
22512 +/*     __dealloc_nx_info()
22513 +
22514 +       * final disposal of nx_info                             */
22515 +
22516 +static void __dealloc_nx_info(struct nx_info *nxi)
22517 +{
22518 +       vxdprintk(VXD_CBIT(nid, 0),
22519 +               "dealloc_nx_info(%p)", nxi);
22520 +
22521 +       nxi->nx_hlist.next = LIST_POISON1;
22522 +       nxi->nx_id = -1;
22523 +
22524 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22525 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22526 +
22527 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22528 +
22529 +       nxi->nx_state |= NXS_RELEASED;
22530 +       kfree(nxi);
22531 +       atomic_dec(&nx_global_ctotal);
22532 +}
22533 +
22534 +static void __shutdown_nx_info(struct nx_info *nxi)
22535 +{
22536 +       nxi->nx_state |= NXS_SHUTDOWN;
22537 +       vs_net_change(nxi, VSC_NETDOWN);
22538 +}
22539 +
22540 +/*     exported stuff                                          */
22541 +
22542 +void free_nx_info(struct nx_info *nxi)
22543 +{
22544 +       /* context shutdown is mandatory */
22545 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22546 +
22547 +       /* context must not be hashed */
22548 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22549 +
22550 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22551 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22552 +
22553 +       __dealloc_nx_info(nxi);
22554 +}
22555 +
22556 +
22557 +void __nx_set_lback(struct nx_info *nxi)
22558 +{
22559 +       int nid = nxi->nx_id;
22560 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22561 +
22562 +       nxi->v4_lback.s_addr = lback;
22563 +}
22564 +
22565 +extern int __nx_inet_add_lback(__be32 addr);
22566 +extern int __nx_inet_del_lback(__be32 addr);
22567 +
22568 +
22569 +/*     hash table for nx_info hash */
22570 +
22571 +#define NX_HASH_SIZE   13
22572 +
22573 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22574 +
22575 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22576 +
22577 +
22578 +static inline unsigned int __hashval(nid_t nid)
22579 +{
22580 +       return (nid % NX_HASH_SIZE);
22581 +}
22582 +
22583 +
22584 +
22585 +/*     __hash_nx_info()
22586 +
22587 +       * add the nxi to the global hash table
22588 +       * requires the hash_lock to be held                     */
22589 +
22590 +static inline void __hash_nx_info(struct nx_info *nxi)
22591 +{
22592 +       struct hlist_head *head;
22593 +
22594 +       vxd_assert_lock(&nx_info_hash_lock);
22595 +       vxdprintk(VXD_CBIT(nid, 4),
22596 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22597 +
22598 +       /* context must not be hashed */
22599 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22600 +
22601 +       nxi->nx_state |= NXS_HASHED;
22602 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22603 +       hlist_add_head(&nxi->nx_hlist, head);
22604 +       atomic_inc(&nx_global_cactive);
22605 +}
22606 +
22607 +/*     __unhash_nx_info()
22608 +
22609 +       * remove the nxi from the global hash table
22610 +       * requires the hash_lock to be held                     */
22611 +
22612 +static inline void __unhash_nx_info(struct nx_info *nxi)
22613 +{
22614 +       vxd_assert_lock(&nx_info_hash_lock);
22615 +       vxdprintk(VXD_CBIT(nid, 4),
22616 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22617 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22618 +
22619 +       /* context must be hashed */
22620 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22621 +       /* but without tasks */
22622 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22623 +
22624 +       nxi->nx_state &= ~NXS_HASHED;
22625 +       hlist_del(&nxi->nx_hlist);
22626 +       atomic_dec(&nx_global_cactive);
22627 +}
22628 +
22629 +
22630 +/*     __lookup_nx_info()
22631 +
22632 +       * requires the hash_lock to be held
22633 +       * doesn't increment the nx_refcnt                       */
22634 +
22635 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22636 +{
22637 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22638 +       struct hlist_node *pos;
22639 +       struct nx_info *nxi;
22640 +
22641 +       vxd_assert_lock(&nx_info_hash_lock);
22642 +       hlist_for_each(pos, head) {
22643 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22644 +
22645 +               if (nxi->nx_id == nid)
22646 +                       goto found;
22647 +       }
22648 +       nxi = NULL;
22649 +found:
22650 +       vxdprintk(VXD_CBIT(nid, 0),
22651 +               "__lookup_nx_info(#%u): %p[#%u]",
22652 +               nid, nxi, nxi ? nxi->nx_id : 0);
22653 +       return nxi;
22654 +}
22655 +
22656 +
22657 +/*     __create_nx_info()
22658 +
22659 +       * create the requested context
22660 +       * get(), claim() and hash it                            */
22661 +
22662 +static struct nx_info *__create_nx_info(int id)
22663 +{
22664 +       struct nx_info *new, *nxi = NULL;
22665 +
22666 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22667 +
22668 +       if (!(new = __alloc_nx_info(id)))
22669 +               return ERR_PTR(-ENOMEM);
22670 +
22671 +       /* required to make dynamic xids unique */
22672 +       spin_lock(&nx_info_hash_lock);
22673 +
22674 +       /* static context requested */
22675 +       if ((nxi = __lookup_nx_info(id))) {
22676 +               vxdprintk(VXD_CBIT(nid, 0),
22677 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22678 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22679 +                       nxi = ERR_PTR(-EBUSY);
22680 +               else
22681 +                       nxi = ERR_PTR(-EEXIST);
22682 +               goto out_unlock;
22683 +       }
22684 +       /* new context */
22685 +       vxdprintk(VXD_CBIT(nid, 0),
22686 +               "create_nx_info(%d) = %p (new)", id, new);
22687 +       claim_nx_info(new, NULL);
22688 +       __nx_set_lback(new);
22689 +       __hash_nx_info(get_nx_info(new));
22690 +       nxi = new, new = NULL;
22691 +
22692 +out_unlock:
22693 +       spin_unlock(&nx_info_hash_lock);
22694 +       if (new)
22695 +               __dealloc_nx_info(new);
22696 +       return nxi;
22697 +}
22698 +
22699 +
22700 +
22701 +/*     exported stuff                                          */
22702 +
22703 +
22704 +void unhash_nx_info(struct nx_info *nxi)
22705 +{
22706 +       __shutdown_nx_info(nxi);
22707 +       spin_lock(&nx_info_hash_lock);
22708 +       __unhash_nx_info(nxi);
22709 +       spin_unlock(&nx_info_hash_lock);
22710 +}
22711 +
22712 +/*     lookup_nx_info()
22713 +
22714 +       * search for a nx_info and get() it
22715 +       * negative id means current                             */
22716 +
22717 +struct nx_info *lookup_nx_info(int id)
22718 +{
22719 +       struct nx_info *nxi = NULL;
22720 +
22721 +       if (id < 0) {
22722 +               nxi = get_nx_info(current_nx_info());
22723 +       } else if (id > 1) {
22724 +               spin_lock(&nx_info_hash_lock);
22725 +               nxi = get_nx_info(__lookup_nx_info(id));
22726 +               spin_unlock(&nx_info_hash_lock);
22727 +       }
22728 +       return nxi;
22729 +}
22730 +
22731 +/*     nid_is_hashed()
22732 +
22733 +       * verify that nid is still hashed                       */
22734 +
22735 +int nid_is_hashed(nid_t nid)
22736 +{
22737 +       int hashed;
22738 +
22739 +       spin_lock(&nx_info_hash_lock);
22740 +       hashed = (__lookup_nx_info(nid) != NULL);
22741 +       spin_unlock(&nx_info_hash_lock);
22742 +       return hashed;
22743 +}
22744 +
22745 +
22746 +#ifdef CONFIG_PROC_FS
22747 +
22748 +/*     get_nid_list()
22749 +
22750 +       * get a subset of hashed nids for proc
22751 +       * assumes size is at least one                          */
22752 +
22753 +int get_nid_list(int index, unsigned int *nids, int size)
22754 +{
22755 +       int hindex, nr_nids = 0;
22756 +
22757 +       /* only show current and children */
22758 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22759 +               if (index > 0)
22760 +                       return 0;
22761 +               nids[nr_nids] = nx_current_nid();
22762 +               return 1;
22763 +       }
22764 +
22765 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22766 +               struct hlist_head *head = &nx_info_hash[hindex];
22767 +               struct hlist_node *pos;
22768 +
22769 +               spin_lock(&nx_info_hash_lock);
22770 +               hlist_for_each(pos, head) {
22771 +                       struct nx_info *nxi;
22772 +
22773 +                       if (--index > 0)
22774 +                               continue;
22775 +
22776 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22777 +                       nids[nr_nids] = nxi->nx_id;
22778 +                       if (++nr_nids >= size) {
22779 +                               spin_unlock(&nx_info_hash_lock);
22780 +                               goto out;
22781 +                       }
22782 +               }
22783 +               /* keep the lock time short */
22784 +               spin_unlock(&nx_info_hash_lock);
22785 +       }
22786 +out:
22787 +       return nr_nids;
22788 +}
22789 +#endif
22790 +
22791 +
22792 +/*
22793 + *     migrate task to new network
22794 + *     gets nxi, puts old_nxi on change
22795 + */
22796 +
22797 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22798 +{
22799 +       struct nx_info *old_nxi;
22800 +       int ret = 0;
22801 +
22802 +       if (!p || !nxi)
22803 +               BUG();
22804 +
22805 +       vxdprintk(VXD_CBIT(nid, 5),
22806 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22807 +               p, nxi, nxi->nx_id,
22808 +               atomic_read(&nxi->nx_usecnt),
22809 +               atomic_read(&nxi->nx_tasks));
22810 +
22811 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22812 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22813 +               return -EACCES;
22814 +
22815 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22816 +               return -EFAULT;
22817 +
22818 +       /* maybe disallow this completely? */
22819 +       old_nxi = task_get_nx_info(p);
22820 +       if (old_nxi == nxi)
22821 +               goto out;
22822 +
22823 +       task_lock(p);
22824 +       if (old_nxi)
22825 +               clr_nx_info(&p->nx_info);
22826 +       claim_nx_info(nxi, p);
22827 +       set_nx_info(&p->nx_info, nxi);
22828 +       p->nid = nxi->nx_id;
22829 +       task_unlock(p);
22830 +
22831 +       vxdprintk(VXD_CBIT(nid, 5),
22832 +               "moved task %p into nxi:%p[#%d]",
22833 +               p, nxi, nxi->nx_id);
22834 +
22835 +       if (old_nxi)
22836 +               release_nx_info(old_nxi, p);
22837 +       ret = 0;
22838 +out:
22839 +       put_nx_info(old_nxi);
22840 +       return ret;
22841 +}
22842 +
22843 +
22844 +void nx_set_persistent(struct nx_info *nxi)
22845 +{
22846 +       vxdprintk(VXD_CBIT(nid, 6),
22847 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22848 +
22849 +       get_nx_info(nxi);
22850 +       claim_nx_info(nxi, NULL);
22851 +}
22852 +
22853 +void nx_clear_persistent(struct nx_info *nxi)
22854 +{
22855 +       vxdprintk(VXD_CBIT(nid, 6),
22856 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22857 +
22858 +       release_nx_info(nxi, NULL);
22859 +       put_nx_info(nxi);
22860 +}
22861 +
22862 +void nx_update_persistent(struct nx_info *nxi)
22863 +{
22864 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22865 +               nx_set_persistent(nxi);
22866 +       else
22867 +               nx_clear_persistent(nxi);
22868 +}
22869 +
22870 +/* vserver syscall commands below here */
22871 +
22872 +/* taks nid and nx_info functions */
22873 +
22874 +#include <asm/uaccess.h>
22875 +
22876 +
22877 +int vc_task_nid(uint32_t id)
22878 +{
22879 +       nid_t nid;
22880 +
22881 +       if (id) {
22882 +               struct task_struct *tsk;
22883 +
22884 +               read_lock(&tasklist_lock);
22885 +               tsk = find_task_by_real_pid(id);
22886 +               nid = (tsk) ? tsk->nid : -ESRCH;
22887 +               read_unlock(&tasklist_lock);
22888 +       } else
22889 +               nid = nx_current_nid();
22890 +       return nid;
22891 +}
22892 +
22893 +
22894 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22895 +{
22896 +       struct vcmd_nx_info_v0 vc_data;
22897 +
22898 +       vc_data.nid = nxi->nx_id;
22899 +
22900 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22901 +               return -EFAULT;
22902 +       return 0;
22903 +}
22904 +
22905 +
22906 +/* network functions */
22907 +
22908 +int vc_net_create(uint32_t nid, void __user *data)
22909 +{
22910 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22911 +       struct nx_info *new_nxi;
22912 +       int ret;
22913 +
22914 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22915 +               return -EFAULT;
22916 +
22917 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22918 +               return -EINVAL;
22919 +
22920 +       new_nxi = __create_nx_info(nid);
22921 +       if (IS_ERR(new_nxi))
22922 +               return PTR_ERR(new_nxi);
22923 +
22924 +       /* initial flags */
22925 +       new_nxi->nx_flags = vc_data.flagword;
22926 +
22927 +       ret = -ENOEXEC;
22928 +       if (vs_net_change(new_nxi, VSC_NETUP))
22929 +               goto out;
22930 +
22931 +       ret = nx_migrate_task(current, new_nxi);
22932 +       if (ret)
22933 +               goto out;
22934 +
22935 +       /* return context id on success */
22936 +       ret = new_nxi->nx_id;
22937 +
22938 +       /* get a reference for persistent contexts */
22939 +       if ((vc_data.flagword & NXF_PERSISTENT))
22940 +               nx_set_persistent(new_nxi);
22941 +out:
22942 +       release_nx_info(new_nxi, NULL);
22943 +       put_nx_info(new_nxi);
22944 +       return ret;
22945 +}
22946 +
22947 +
22948 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22949 +{
22950 +       return nx_migrate_task(current, nxi);
22951 +}
22952 +
22953 +
22954 +
22955 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22956 +       uint16_t type, uint16_t flags)
22957 +{
22958 +       struct nx_addr_v4 *nxa = &nxi->v4;
22959 +
22960 +       if (NX_IPV4(nxi)) {
22961 +               /* locate last entry */
22962 +               for (; nxa->next; nxa = nxa->next);
22963 +               nxa->next = __alloc_nx_addr_v4();
22964 +               nxa = nxa->next;
22965 +
22966 +               if (IS_ERR(nxa))
22967 +                       return PTR_ERR(nxa);
22968 +       }
22969 +
22970 +       if (nxi->v4.next)
22971 +               /* remove single ip for ip list */
22972 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22973 +
22974 +       nxa->ip[0].s_addr = ip;
22975 +       nxa->ip[1].s_addr = ip2;
22976 +       nxa->mask.s_addr = mask;
22977 +       nxa->type = type;
22978 +       nxa->flags = flags;
22979 +       return 0;
22980 +}
22981 +
22982 +
22983 +int vc_net_add(struct nx_info *nxi, void __user *data)
22984 +{
22985 +       struct vcmd_net_addr_v0 vc_data;
22986 +       int index, ret = 0;
22987 +
22988 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22989 +               return -EFAULT;
22990 +
22991 +       switch (vc_data.type) {
22992 +       case NXA_TYPE_IPV4:
22993 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22994 +                       return -EINVAL;
22995 +
22996 +               index = 0;
22997 +               while (index < vc_data.count) {
22998 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22999 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
23000 +                       if (ret)
23001 +                               return ret;
23002 +                       index++;
23003 +               }
23004 +               ret = index;
23005 +               break;
23006 +
23007 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
23008 +               nxi->v4_bcast = vc_data.ip[0];
23009 +               ret = 1;
23010 +               break;
23011 +
23012 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
23013 +               nxi->v4_lback = vc_data.ip[0];
23014 +               ret = 1;
23015 +               break;
23016 +
23017 +       default:
23018 +               ret = -EINVAL;
23019 +               break;
23020 +       }
23021 +       return ret;
23022 +}
23023 +
23024 +int vc_net_remove(struct nx_info *nxi, void __user *data)
23025 +{
23026 +       struct vcmd_net_addr_v0 vc_data;
23027 +
23028 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23029 +               return -EFAULT;
23030 +
23031 +       switch (vc_data.type) {
23032 +       case NXA_TYPE_ANY:
23033 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
23034 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
23035 +               break;
23036 +
23037 +       default:
23038 +               return -EINVAL;
23039 +       }
23040 +       return 0;
23041 +}
23042 +
23043 +
23044 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
23045 +{
23046 +       struct vcmd_net_addr_ipv4_v1 vc_data;
23047 +
23048 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23049 +               return -EFAULT;
23050 +
23051 +       switch (vc_data.type) {
23052 +       case NXA_TYPE_ADDR:
23053 +       case NXA_TYPE_RANGE:
23054 +       case NXA_TYPE_MASK:
23055 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
23056 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
23057 +
23058 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
23059 +               nxi->v4_bcast = vc_data.ip;
23060 +               break;
23061 +
23062 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
23063 +               nxi->v4_lback = vc_data.ip;
23064 +               break;
23065 +
23066 +       default:
23067 +               return -EINVAL;
23068 +       }
23069 +       return 0;
23070 +}
23071 +
23072 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
23073 +{
23074 +       struct vcmd_net_addr_ipv4_v1 vc_data;
23075 +
23076 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23077 +               return -EFAULT;
23078 +
23079 +       switch (vc_data.type) {
23080 +/*     case NXA_TYPE_ADDR:
23081 +               break;          */
23082 +
23083 +       case NXA_TYPE_ANY:
23084 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
23085 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
23086 +               break;
23087 +
23088 +       default:
23089 +               return -EINVAL;
23090 +       }
23091 +       return 0;
23092 +}
23093 +
23094 +
23095 +#ifdef CONFIG_IPV6
23096 +
23097 +int do_add_v6_addr(struct nx_info *nxi,
23098 +       struct in6_addr *ip, struct in6_addr *mask,
23099 +       uint32_t prefix, uint16_t type, uint16_t flags)
23100 +{
23101 +       struct nx_addr_v6 *nxa = &nxi->v6;
23102 +
23103 +       if (NX_IPV6(nxi)) {
23104 +               /* locate last entry */
23105 +               for (; nxa->next; nxa = nxa->next);
23106 +               nxa->next = __alloc_nx_addr_v6();
23107 +               nxa = nxa->next;
23108 +
23109 +               if (IS_ERR(nxa))
23110 +                       return PTR_ERR(nxa);
23111 +       }
23112 +
23113 +       nxa->ip = *ip;
23114 +       nxa->mask = *mask;
23115 +       nxa->prefix = prefix;
23116 +       nxa->type = type;
23117 +       nxa->flags = flags;
23118 +       return 0;
23119 +}
23120 +
23121 +
23122 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
23123 +{
23124 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23125 +
23126 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23127 +               return -EFAULT;
23128 +
23129 +       switch (vc_data.type) {
23130 +       case NXA_TYPE_ADDR:
23131 +       case NXA_TYPE_MASK:
23132 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
23133 +                       vc_data.prefix, vc_data.type, vc_data.flags);
23134 +       default:
23135 +               return -EINVAL;
23136 +       }
23137 +       return 0;
23138 +}
23139 +
23140 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
23141 +{
23142 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23143 +
23144 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23145 +               return -EFAULT;
23146 +
23147 +       switch (vc_data.type) {
23148 +       case NXA_TYPE_ANY:
23149 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
23150 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
23151 +               break;
23152 +
23153 +       default:
23154 +               return -EINVAL;
23155 +       }
23156 +       return 0;
23157 +}
23158 +
23159 +#endif /* CONFIG_IPV6 */
23160 +
23161 +
23162 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
23163 +{
23164 +       struct vcmd_net_flags_v0 vc_data;
23165 +
23166 +       vc_data.flagword = nxi->nx_flags;
23167 +
23168 +       /* special STATE flag handling */
23169 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
23170 +
23171 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23172 +               return -EFAULT;
23173 +       return 0;
23174 +}
23175 +
23176 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
23177 +{
23178 +       struct vcmd_net_flags_v0 vc_data;
23179 +       uint64_t mask, trigger;
23180 +
23181 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23182 +               return -EFAULT;
23183 +
23184 +       /* special STATE flag handling */
23185 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
23186 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
23187 +
23188 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
23189 +               vc_data.flagword, mask);
23190 +       if (trigger & NXF_PERSISTENT)
23191 +               nx_update_persistent(nxi);
23192 +
23193 +       return 0;
23194 +}
23195 +
23196 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
23197 +{
23198 +       struct vcmd_net_caps_v0 vc_data;
23199 +
23200 +       vc_data.ncaps = nxi->nx_ncaps;
23201 +       vc_data.cmask = ~0ULL;
23202 +
23203 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23204 +               return -EFAULT;
23205 +       return 0;
23206 +}
23207 +
23208 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
23209 +{
23210 +       struct vcmd_net_caps_v0 vc_data;
23211 +
23212 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23213 +               return -EFAULT;
23214 +
23215 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
23216 +               vc_data.ncaps, vc_data.cmask);
23217 +       return 0;
23218 +}
23219 +
23220 +
23221 +#include <linux/module.h>
23222 +
23223 +module_init(init_network);
23224 +
23225 +EXPORT_SYMBOL_GPL(free_nx_info);
23226 +EXPORT_SYMBOL_GPL(unhash_nx_info);
23227 +
23228 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/proc.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/proc.c
23229 --- linux-2.6.32.24/kernel/vserver/proc.c       1970-01-01 01:00:00.000000000 +0100
23230 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/proc.c       2009-12-03 20:04:56.000000000 +0100
23231 @@ -0,0 +1,1098 @@
23232 +/*
23233 + *  linux/kernel/vserver/proc.c
23234 + *
23235 + *  Virtual Context Support
23236 + *
23237 + *  Copyright (C) 2003-2007  Herbert Pötzl
23238 + *
23239 + *  V0.01  basic structure
23240 + *  V0.02  adaptation vs1.3.0
23241 + *  V0.03  proc permissions
23242 + *  V0.04  locking/generic
23243 + *  V0.05  next generation procfs
23244 + *  V0.06  inode validation
23245 + *  V0.07  generic rewrite vid
23246 + *  V0.08  remove inode type
23247 + *
23248 + */
23249 +
23250 +#include <linux/proc_fs.h>
23251 +#include <linux/fs_struct.h>
23252 +#include <linux/mount.h>
23253 +#include <asm/unistd.h>
23254 +
23255 +#include <linux/vs_context.h>
23256 +#include <linux/vs_network.h>
23257 +#include <linux/vs_cvirt.h>
23258 +
23259 +#include <linux/in.h>
23260 +#include <linux/inetdevice.h>
23261 +#include <linux/vs_inet.h>
23262 +#include <linux/vs_inet6.h>
23263 +
23264 +#include <linux/vserver/global.h>
23265 +
23266 +#include "cvirt_proc.h"
23267 +#include "cacct_proc.h"
23268 +#include "limit_proc.h"
23269 +#include "sched_proc.h"
23270 +#include "vci_config.h"
23271 +
23272 +
23273 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
23274 +{
23275 +       unsigned __capi;
23276 +
23277 +       CAP_FOR_EACH_U32(__capi) {
23278 +               buffer += sprintf(buffer, "%08x",
23279 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
23280 +       }
23281 +       return buffer;
23282 +}
23283 +
23284 +
23285 +static struct proc_dir_entry *proc_virtual;
23286 +
23287 +static struct proc_dir_entry *proc_virtnet;
23288 +
23289 +
23290 +/* first the actual feeds */
23291 +
23292 +
23293 +static int proc_vci(char *buffer)
23294 +{
23295 +       return sprintf(buffer,
23296 +               "VCIVersion:\t%04x:%04x\n"
23297 +               "VCISyscall:\t%d\n"
23298 +               "VCIKernel:\t%08x\n",
23299 +               VCI_VERSION >> 16,
23300 +               VCI_VERSION & 0xFFFF,
23301 +               __NR_vserver,
23302 +               vci_kernel_config());
23303 +}
23304 +
23305 +static int proc_virtual_info(char *buffer)
23306 +{
23307 +       return proc_vci(buffer);
23308 +}
23309 +
23310 +static int proc_virtual_status(char *buffer)
23311 +{
23312 +       return sprintf(buffer,
23313 +               "#CTotal:\t%d\n"
23314 +               "#CActive:\t%d\n"
23315 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
23316 +               "#InitTask:\t%d\t%d %d\n",
23317 +               atomic_read(&vx_global_ctotal),
23318 +               atomic_read(&vx_global_cactive),
23319 +               atomic_read(&vs_global_nsproxy),
23320 +               atomic_read(&vs_global_fs),
23321 +               atomic_read(&vs_global_mnt_ns),
23322 +               atomic_read(&vs_global_uts_ns),
23323 +               atomic_read(&nr_ipc_ns),
23324 +               atomic_read(&vs_global_user_ns),
23325 +               atomic_read(&vs_global_pid_ns),
23326 +               atomic_read(&init_task.usage),
23327 +               atomic_read(&init_task.nsproxy->count),
23328 +               init_task.fs->users);
23329 +}
23330 +
23331 +
23332 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23333 +{
23334 +       int length;
23335 +
23336 +       length = sprintf(buffer,
23337 +               "ID:\t%d\n"
23338 +               "Info:\t%p\n"
23339 +               "Init:\t%d\n"
23340 +               "OOM:\t%lld\n",
23341 +               vxi->vx_id,
23342 +               vxi,
23343 +               vxi->vx_initpid,
23344 +               vxi->vx_badness_bias);
23345 +       return length;
23346 +}
23347 +
23348 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23349 +{
23350 +       char *orig = buffer;
23351 +
23352 +       buffer += sprintf(buffer,
23353 +               "UseCnt:\t%d\n"
23354 +               "Tasks:\t%d\n"
23355 +               "Flags:\t%016llx\n",
23356 +               atomic_read(&vxi->vx_usecnt),
23357 +               atomic_read(&vxi->vx_tasks),
23358 +               (unsigned long long)vxi->vx_flags);
23359 +
23360 +       buffer += sprintf(buffer, "BCaps:\t");
23361 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23362 +       buffer += sprintf(buffer, "\n");
23363 +
23364 +       buffer += sprintf(buffer,
23365 +               "CCaps:\t%016llx\n"
23366 +               "Spaces:\t%08lx %08lx\n",
23367 +               (unsigned long long)vxi->vx_ccaps,
23368 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
23369 +       return buffer - orig;
23370 +}
23371 +
23372 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23373 +{
23374 +       return vx_info_proc_limit(&vxi->limit, buffer);
23375 +}
23376 +
23377 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23378 +{
23379 +       int cpu, length;
23380 +
23381 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23382 +       for_each_online_cpu(cpu) {
23383 +               length += vx_info_proc_sched_pc(
23384 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23385 +                       buffer + length, cpu);
23386 +       }
23387 +       return length;
23388 +}
23389 +
23390 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
23391 +{
23392 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
23393 +}
23394 +
23395 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
23396 +{
23397 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
23398 +}
23399 +
23400 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23401 +{
23402 +       int cpu, length;
23403 +
23404 +       vx_update_load(vxi);
23405 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23406 +       for_each_online_cpu(cpu) {
23407 +               length += vx_info_proc_cvirt_pc(
23408 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23409 +                       buffer + length, cpu);
23410 +       }
23411 +       return length;
23412 +}
23413 +
23414 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23415 +{
23416 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23417 +}
23418 +
23419 +
23420 +static int proc_virtnet_info(char *buffer)
23421 +{
23422 +       return proc_vci(buffer);
23423 +}
23424 +
23425 +static int proc_virtnet_status(char *buffer)
23426 +{
23427 +       return sprintf(buffer,
23428 +               "#CTotal:\t%d\n"
23429 +               "#CActive:\t%d\n",
23430 +               atomic_read(&nx_global_ctotal),
23431 +               atomic_read(&nx_global_cactive));
23432 +}
23433 +
23434 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23435 +{
23436 +       struct nx_addr_v4 *v4a;
23437 +#ifdef CONFIG_IPV6
23438 +       struct nx_addr_v6 *v6a;
23439 +#endif
23440 +       int length, i;
23441 +
23442 +       length = sprintf(buffer,
23443 +               "ID:\t%d\n"
23444 +               "Info:\t%p\n"
23445 +               "Bcast:\t" NIPQUAD_FMT "\n"
23446 +               "Lback:\t" NIPQUAD_FMT "\n",
23447 +               nxi->nx_id,
23448 +               nxi,
23449 +               NIPQUAD(nxi->v4_bcast.s_addr),
23450 +               NIPQUAD(nxi->v4_lback.s_addr));
23451 +
23452 +       if (!NX_IPV4(nxi))
23453 +               goto skip_v4;
23454 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23455 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23456 +                       i, NXAV4(v4a));
23457 +skip_v4:
23458 +#ifdef CONFIG_IPV6
23459 +       if (!NX_IPV6(nxi))
23460 +               goto skip_v6;
23461 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23462 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23463 +                       i, NXAV6(v6a));
23464 +skip_v6:
23465 +#endif
23466 +       return length;
23467 +}
23468 +
23469 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23470 +{
23471 +       int length;
23472 +
23473 +       length = sprintf(buffer,
23474 +               "UseCnt:\t%d\n"
23475 +               "Tasks:\t%d\n"
23476 +               "Flags:\t%016llx\n"
23477 +               "NCaps:\t%016llx\n",
23478 +               atomic_read(&nxi->nx_usecnt),
23479 +               atomic_read(&nxi->nx_tasks),
23480 +               (unsigned long long)nxi->nx_flags,
23481 +               (unsigned long long)nxi->nx_ncaps);
23482 +       return length;
23483 +}
23484 +
23485 +
23486 +
23487 +/* here the inode helpers */
23488 +
23489 +struct vs_entry {
23490 +       int len;
23491 +       char *name;
23492 +       mode_t mode;
23493 +       struct inode_operations *iop;
23494 +       struct file_operations *fop;
23495 +       union proc_op op;
23496 +};
23497 +
23498 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23499 +{
23500 +       struct inode *inode = new_inode(sb);
23501 +
23502 +       if (!inode)
23503 +               goto out;
23504 +
23505 +       inode->i_mode = p->mode;
23506 +       if (p->iop)
23507 +               inode->i_op = p->iop;
23508 +       if (p->fop)
23509 +               inode->i_fop = p->fop;
23510 +
23511 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23512 +       inode->i_flags |= S_IMMUTABLE;
23513 +
23514 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23515 +
23516 +       inode->i_uid = 0;
23517 +       inode->i_gid = 0;
23518 +       inode->i_tag = 0;
23519 +out:
23520 +       return inode;
23521 +}
23522 +
23523 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23524 +       struct dentry *dentry, int id, void *ptr)
23525 +{
23526 +       struct vs_entry *p = ptr;
23527 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23528 +       struct dentry *error = ERR_PTR(-EINVAL);
23529 +
23530 +       if (!inode)
23531 +               goto out;
23532 +
23533 +       PROC_I(inode)->op = p->op;
23534 +       PROC_I(inode)->fd = id;
23535 +       d_add(dentry, inode);
23536 +       error = NULL;
23537 +out:
23538 +       return error;
23539 +}
23540 +
23541 +/* Lookups */
23542 +
23543 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23544 +
23545 +/*
23546 + * Fill a directory entry.
23547 + *
23548 + * If possible create the dcache entry and derive our inode number and
23549 + * file type from dcache entry.
23550 + *
23551 + * Since all of the proc inode numbers are dynamically generated, the inode
23552 + * numbers do not exist until the inode is cache.  This means creating the
23553 + * the dcache entry in readdir is necessary to keep the inode numbers
23554 + * reported by readdir in sync with the inode numbers reported
23555 + * by stat.
23556 + */
23557 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23558 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23559 +{
23560 +       struct dentry *child, *dir = filp->f_dentry;
23561 +       struct inode *inode;
23562 +       struct qstr qname;
23563 +       ino_t ino = 0;
23564 +       unsigned type = DT_UNKNOWN;
23565 +
23566 +       qname.name = name;
23567 +       qname.len  = len;
23568 +       qname.hash = full_name_hash(name, len);
23569 +
23570 +       child = d_lookup(dir, &qname);
23571 +       if (!child) {
23572 +               struct dentry *new;
23573 +               new = d_alloc(dir, &qname);
23574 +               if (new) {
23575 +                       child = instantiate(dir->d_inode, new, id, ptr);
23576 +                       if (child)
23577 +                               dput(new);
23578 +                       else
23579 +                               child = new;
23580 +               }
23581 +       }
23582 +       if (!child || IS_ERR(child) || !child->d_inode)
23583 +               goto end_instantiate;
23584 +       inode = child->d_inode;
23585 +       if (inode) {
23586 +               ino = inode->i_ino;
23587 +               type = inode->i_mode >> 12;
23588 +       }
23589 +       dput(child);
23590 +end_instantiate:
23591 +       if (!ino)
23592 +               ino = find_inode_number(dir, &qname);
23593 +       if (!ino)
23594 +               ino = 1;
23595 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23596 +}
23597 +
23598 +
23599 +
23600 +/* get and revalidate vx_info/xid */
23601 +
23602 +static inline
23603 +struct vx_info *get_proc_vx_info(struct inode *inode)
23604 +{
23605 +       return lookup_vx_info(PROC_I(inode)->fd);
23606 +}
23607 +
23608 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23609 +{
23610 +       struct inode *inode = dentry->d_inode;
23611 +       xid_t xid = PROC_I(inode)->fd;
23612 +
23613 +       if (!xid || xid_is_hashed(xid))
23614 +               return 1;
23615 +       d_drop(dentry);
23616 +       return 0;
23617 +}
23618 +
23619 +
23620 +/* get and revalidate nx_info/nid */
23621 +
23622 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23623 +{
23624 +       struct inode *inode = dentry->d_inode;
23625 +       nid_t nid = PROC_I(inode)->fd;
23626 +
23627 +       if (!nid || nid_is_hashed(nid))
23628 +               return 1;
23629 +       d_drop(dentry);
23630 +       return 0;
23631 +}
23632 +
23633 +
23634 +
23635 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23636 +
23637 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23638 +                         size_t count, loff_t *ppos)
23639 +{
23640 +       struct inode *inode = file->f_dentry->d_inode;
23641 +       unsigned long page;
23642 +       ssize_t length = 0;
23643 +
23644 +       if (count > PROC_BLOCK_SIZE)
23645 +               count = PROC_BLOCK_SIZE;
23646 +
23647 +       /* fade that out as soon as stable */
23648 +       WARN_ON(PROC_I(inode)->fd);
23649 +
23650 +       if (!(page = __get_free_page(GFP_KERNEL)))
23651 +               return -ENOMEM;
23652 +
23653 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23654 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23655 +
23656 +       if (length >= 0)
23657 +               length = simple_read_from_buffer(buf, count, ppos,
23658 +                       (char *)page, length);
23659 +
23660 +       free_page(page);
23661 +       return length;
23662 +}
23663 +
23664 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23665 +                         size_t count, loff_t *ppos)
23666 +{
23667 +       struct inode *inode = file->f_dentry->d_inode;
23668 +       struct vx_info *vxi = NULL;
23669 +       xid_t xid = PROC_I(inode)->fd;
23670 +       unsigned long page;
23671 +       ssize_t length = 0;
23672 +
23673 +       if (count > PROC_BLOCK_SIZE)
23674 +               count = PROC_BLOCK_SIZE;
23675 +
23676 +       /* fade that out as soon as stable */
23677 +       WARN_ON(!xid);
23678 +       vxi = lookup_vx_info(xid);
23679 +       if (!vxi)
23680 +               goto out;
23681 +
23682 +       length = -ENOMEM;
23683 +       if (!(page = __get_free_page(GFP_KERNEL)))
23684 +               goto out_put;
23685 +
23686 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23687 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23688 +
23689 +       if (length >= 0)
23690 +               length = simple_read_from_buffer(buf, count, ppos,
23691 +                       (char *)page, length);
23692 +
23693 +       free_page(page);
23694 +out_put:
23695 +       put_vx_info(vxi);
23696 +out:
23697 +       return length;
23698 +}
23699 +
23700 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23701 +                         size_t count, loff_t *ppos)
23702 +{
23703 +       struct inode *inode = file->f_dentry->d_inode;
23704 +       struct nx_info *nxi = NULL;
23705 +       nid_t nid = PROC_I(inode)->fd;
23706 +       unsigned long page;
23707 +       ssize_t length = 0;
23708 +
23709 +       if (count > PROC_BLOCK_SIZE)
23710 +               count = PROC_BLOCK_SIZE;
23711 +
23712 +       /* fade that out as soon as stable */
23713 +       WARN_ON(!nid);
23714 +       nxi = lookup_nx_info(nid);
23715 +       if (!nxi)
23716 +               goto out;
23717 +
23718 +       length = -ENOMEM;
23719 +       if (!(page = __get_free_page(GFP_KERNEL)))
23720 +               goto out_put;
23721 +
23722 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23723 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23724 +
23725 +       if (length >= 0)
23726 +               length = simple_read_from_buffer(buf, count, ppos,
23727 +                       (char *)page, length);
23728 +
23729 +       free_page(page);
23730 +out_put:
23731 +       put_nx_info(nxi);
23732 +out:
23733 +       return length;
23734 +}
23735 +
23736 +
23737 +
23738 +/* here comes the lower level */
23739 +
23740 +
23741 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23742 +       .len  = sizeof(NAME) - 1,       \
23743 +       .name = (NAME),                 \
23744 +       .mode = MODE,                   \
23745 +       .iop  = IOP,                    \
23746 +       .fop  = FOP,                    \
23747 +       .op   = OP,                     \
23748 +}
23749 +
23750 +
23751 +#define DIR(NAME, MODE, OTYPE)                         \
23752 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23753 +               &proc_ ## OTYPE ## _inode_operations,   \
23754 +               &proc_ ## OTYPE ## _file_operations, { } )
23755 +
23756 +#define INF(NAME, MODE, OTYPE)                         \
23757 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23758 +               &proc_vs_info_file_operations,          \
23759 +               { .proc_vs_read = &proc_##OTYPE } )
23760 +
23761 +#define VINF(NAME, MODE, OTYPE)                                \
23762 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23763 +               &proc_vx_info_file_operations,          \
23764 +               { .proc_vxi_read = &proc_##OTYPE } )
23765 +
23766 +#define NINF(NAME, MODE, OTYPE)                                \
23767 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23768 +               &proc_nx_info_file_operations,          \
23769 +               { .proc_nxi_read = &proc_##OTYPE } )
23770 +
23771 +
23772 +static struct file_operations proc_vs_info_file_operations = {
23773 +       .read =         proc_vs_info_read,
23774 +};
23775 +
23776 +static struct file_operations proc_vx_info_file_operations = {
23777 +       .read =         proc_vx_info_read,
23778 +};
23779 +
23780 +static struct dentry_operations proc_xid_dentry_operations = {
23781 +       .d_revalidate = proc_xid_revalidate,
23782 +};
23783 +
23784 +static struct vs_entry vx_base_stuff[] = {
23785 +       VINF("info",    S_IRUGO, vxi_info),
23786 +       VINF("status",  S_IRUGO, vxi_status),
23787 +       VINF("limit",   S_IRUGO, vxi_limit),
23788 +       VINF("sched",   S_IRUGO, vxi_sched),
23789 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23790 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23791 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23792 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23793 +       {}
23794 +};
23795 +
23796 +
23797 +
23798 +
23799 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23800 +       struct dentry *dentry, int id, void *ptr)
23801 +{
23802 +       dentry->d_op = &proc_xid_dentry_operations;
23803 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23804 +}
23805 +
23806 +static struct dentry *proc_xid_lookup(struct inode *dir,
23807 +       struct dentry *dentry, struct nameidata *nd)
23808 +{
23809 +       struct vs_entry *p = vx_base_stuff;
23810 +       struct dentry *error = ERR_PTR(-ENOENT);
23811 +
23812 +       for (; p->name; p++) {
23813 +               if (p->len != dentry->d_name.len)
23814 +                       continue;
23815 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23816 +                       break;
23817 +       }
23818 +       if (!p->name)
23819 +               goto out;
23820 +
23821 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23822 +out:
23823 +       return error;
23824 +}
23825 +
23826 +static int proc_xid_readdir(struct file *filp,
23827 +       void *dirent, filldir_t filldir)
23828 +{
23829 +       struct dentry *dentry = filp->f_dentry;
23830 +       struct inode *inode = dentry->d_inode;
23831 +       struct vs_entry *p = vx_base_stuff;
23832 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23833 +       int pos, index;
23834 +       u64 ino;
23835 +
23836 +       pos = filp->f_pos;
23837 +       switch (pos) {
23838 +       case 0:
23839 +               ino = inode->i_ino;
23840 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23841 +                       goto out;
23842 +               pos++;
23843 +               /* fall through */
23844 +       case 1:
23845 +               ino = parent_ino(dentry);
23846 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23847 +                       goto out;
23848 +               pos++;
23849 +               /* fall through */
23850 +       default:
23851 +               index = pos - 2;
23852 +               if (index >= size)
23853 +                       goto out;
23854 +               for (p += index; p->name; p++) {
23855 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23856 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23857 +                               goto out;
23858 +                       pos++;
23859 +               }
23860 +       }
23861 +out:
23862 +       filp->f_pos = pos;
23863 +       return 1;
23864 +}
23865 +
23866 +
23867 +
23868 +static struct file_operations proc_nx_info_file_operations = {
23869 +       .read =         proc_nx_info_read,
23870 +};
23871 +
23872 +static struct dentry_operations proc_nid_dentry_operations = {
23873 +       .d_revalidate = proc_nid_revalidate,
23874 +};
23875 +
23876 +static struct vs_entry nx_base_stuff[] = {
23877 +       NINF("info",    S_IRUGO, nxi_info),
23878 +       NINF("status",  S_IRUGO, nxi_status),
23879 +       {}
23880 +};
23881 +
23882 +
23883 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23884 +       struct dentry *dentry, int id, void *ptr)
23885 +{
23886 +       dentry->d_op = &proc_nid_dentry_operations;
23887 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23888 +}
23889 +
23890 +static struct dentry *proc_nid_lookup(struct inode *dir,
23891 +       struct dentry *dentry, struct nameidata *nd)
23892 +{
23893 +       struct vs_entry *p = nx_base_stuff;
23894 +       struct dentry *error = ERR_PTR(-ENOENT);
23895 +
23896 +       for (; p->name; p++) {
23897 +               if (p->len != dentry->d_name.len)
23898 +                       continue;
23899 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23900 +                       break;
23901 +       }
23902 +       if (!p->name)
23903 +               goto out;
23904 +
23905 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23906 +out:
23907 +       return error;
23908 +}
23909 +
23910 +static int proc_nid_readdir(struct file *filp,
23911 +       void *dirent, filldir_t filldir)
23912 +{
23913 +       struct dentry *dentry = filp->f_dentry;
23914 +       struct inode *inode = dentry->d_inode;
23915 +       struct vs_entry *p = nx_base_stuff;
23916 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23917 +       int pos, index;
23918 +       u64 ino;
23919 +
23920 +       pos = filp->f_pos;
23921 +       switch (pos) {
23922 +       case 0:
23923 +               ino = inode->i_ino;
23924 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23925 +                       goto out;
23926 +               pos++;
23927 +               /* fall through */
23928 +       case 1:
23929 +               ino = parent_ino(dentry);
23930 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23931 +                       goto out;
23932 +               pos++;
23933 +               /* fall through */
23934 +       default:
23935 +               index = pos - 2;
23936 +               if (index >= size)
23937 +                       goto out;
23938 +               for (p += index; p->name; p++) {
23939 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23940 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23941 +                               goto out;
23942 +                       pos++;
23943 +               }
23944 +       }
23945 +out:
23946 +       filp->f_pos = pos;
23947 +       return 1;
23948 +}
23949 +
23950 +
23951 +#define MAX_MULBY10    ((~0U - 9) / 10)
23952 +
23953 +static inline int atovid(const char *str, int len)
23954 +{
23955 +       int vid, c;
23956 +
23957 +       vid = 0;
23958 +       while (len-- > 0) {
23959 +               c = *str - '0';
23960 +               str++;
23961 +               if (c > 9)
23962 +                       return -1;
23963 +               if (vid >= MAX_MULBY10)
23964 +                       return -1;
23965 +               vid *= 10;
23966 +               vid += c;
23967 +               if (!vid)
23968 +                       return -1;
23969 +       }
23970 +       return vid;
23971 +}
23972 +
23973 +/* now the upper level (virtual) */
23974 +
23975 +
23976 +static struct file_operations proc_xid_file_operations = {
23977 +       .read =         generic_read_dir,
23978 +       .readdir =      proc_xid_readdir,
23979 +};
23980 +
23981 +static struct inode_operations proc_xid_inode_operations = {
23982 +       .lookup =       proc_xid_lookup,
23983 +};
23984 +
23985 +static struct vs_entry vx_virtual_stuff[] = {
23986 +       INF("info",     S_IRUGO, virtual_info),
23987 +       INF("status",   S_IRUGO, virtual_status),
23988 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23989 +};
23990 +
23991 +
23992 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23993 +       struct dentry *dentry, struct nameidata *nd)
23994 +{
23995 +       struct vs_entry *p = vx_virtual_stuff;
23996 +       struct dentry *error = ERR_PTR(-ENOENT);
23997 +       int id = 0;
23998 +
23999 +       for (; p->name; p++) {
24000 +               if (p->len != dentry->d_name.len)
24001 +                       continue;
24002 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24003 +                       break;
24004 +       }
24005 +       if (p->name)
24006 +               goto instantiate;
24007 +
24008 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
24009 +       if ((id < 0) || !xid_is_hashed(id))
24010 +               goto out;
24011 +
24012 +instantiate:
24013 +       error = proc_xid_instantiate(dir, dentry, id, p);
24014 +out:
24015 +       return error;
24016 +}
24017 +
24018 +static struct file_operations proc_nid_file_operations = {
24019 +       .read =         generic_read_dir,
24020 +       .readdir =      proc_nid_readdir,
24021 +};
24022 +
24023 +static struct inode_operations proc_nid_inode_operations = {
24024 +       .lookup =       proc_nid_lookup,
24025 +};
24026 +
24027 +static struct vs_entry nx_virtnet_stuff[] = {
24028 +       INF("info",     S_IRUGO, virtnet_info),
24029 +       INF("status",   S_IRUGO, virtnet_status),
24030 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
24031 +};
24032 +
24033 +
24034 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
24035 +       struct dentry *dentry, struct nameidata *nd)
24036 +{
24037 +       struct vs_entry *p = nx_virtnet_stuff;
24038 +       struct dentry *error = ERR_PTR(-ENOENT);
24039 +       int id = 0;
24040 +
24041 +       for (; p->name; p++) {
24042 +               if (p->len != dentry->d_name.len)
24043 +                       continue;
24044 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
24045 +                       break;
24046 +       }
24047 +       if (p->name)
24048 +               goto instantiate;
24049 +
24050 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
24051 +       if ((id < 0) || !nid_is_hashed(id))
24052 +               goto out;
24053 +
24054 +instantiate:
24055 +       error = proc_nid_instantiate(dir, dentry, id, p);
24056 +out:
24057 +       return error;
24058 +}
24059 +
24060 +
24061 +#define PROC_MAXVIDS 32
24062 +
24063 +int proc_virtual_readdir(struct file *filp,
24064 +       void *dirent, filldir_t filldir)
24065 +{
24066 +       struct dentry *dentry = filp->f_dentry;
24067 +       struct inode *inode = dentry->d_inode;
24068 +       struct vs_entry *p = vx_virtual_stuff;
24069 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
24070 +       int pos, index;
24071 +       unsigned int xid_array[PROC_MAXVIDS];
24072 +       char buf[PROC_NUMBUF];
24073 +       unsigned int nr_xids, i;
24074 +       u64 ino;
24075 +
24076 +       pos = filp->f_pos;
24077 +       switch (pos) {
24078 +       case 0:
24079 +               ino = inode->i_ino;
24080 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24081 +                       goto out;
24082 +               pos++;
24083 +               /* fall through */
24084 +       case 1:
24085 +               ino = parent_ino(dentry);
24086 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24087 +                       goto out;
24088 +               pos++;
24089 +               /* fall through */
24090 +       default:
24091 +               index = pos - 2;
24092 +               if (index >= size)
24093 +                       goto entries;
24094 +               for (p += index; p->name; p++) {
24095 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24096 +                               vs_proc_instantiate, 0, p))
24097 +                               goto out;
24098 +                       pos++;
24099 +               }
24100 +       entries:
24101 +               index = pos - size;
24102 +               p = &vx_virtual_stuff[size - 1];
24103 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
24104 +               for (i = 0; i < nr_xids; i++) {
24105 +                       int n, xid = xid_array[i];
24106 +                       unsigned int j = PROC_NUMBUF;
24107 +
24108 +                       n = xid;
24109 +                       do
24110 +                               buf[--j] = '0' + (n % 10);
24111 +                       while (n /= 10);
24112 +
24113 +                       if (proc_fill_cache(filp, dirent, filldir,
24114 +                               buf + j, PROC_NUMBUF - j,
24115 +                               vs_proc_instantiate, xid, p))
24116 +                               goto out;
24117 +                       pos++;
24118 +               }
24119 +       }
24120 +out:
24121 +       filp->f_pos = pos;
24122 +       return 0;
24123 +}
24124 +
24125 +static int proc_virtual_getattr(struct vfsmount *mnt,
24126 +       struct dentry *dentry, struct kstat *stat)
24127 +{
24128 +       struct inode *inode = dentry->d_inode;
24129 +
24130 +       generic_fillattr(inode, stat);
24131 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
24132 +       return 0;
24133 +}
24134 +
24135 +static struct file_operations proc_virtual_dir_operations = {
24136 +       .read =         generic_read_dir,
24137 +       .readdir =      proc_virtual_readdir,
24138 +};
24139 +
24140 +static struct inode_operations proc_virtual_dir_inode_operations = {
24141 +       .getattr =      proc_virtual_getattr,
24142 +       .lookup =       proc_virtual_lookup,
24143 +};
24144 +
24145 +
24146 +
24147 +
24148 +
24149 +int proc_virtnet_readdir(struct file *filp,
24150 +       void *dirent, filldir_t filldir)
24151 +{
24152 +       struct dentry *dentry = filp->f_dentry;
24153 +       struct inode *inode = dentry->d_inode;
24154 +       struct vs_entry *p = nx_virtnet_stuff;
24155 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
24156 +       int pos, index;
24157 +       unsigned int nid_array[PROC_MAXVIDS];
24158 +       char buf[PROC_NUMBUF];
24159 +       unsigned int nr_nids, i;
24160 +       u64 ino;
24161 +
24162 +       pos = filp->f_pos;
24163 +       switch (pos) {
24164 +       case 0:
24165 +               ino = inode->i_ino;
24166 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24167 +                       goto out;
24168 +               pos++;
24169 +               /* fall through */
24170 +       case 1:
24171 +               ino = parent_ino(dentry);
24172 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24173 +                       goto out;
24174 +               pos++;
24175 +               /* fall through */
24176 +       default:
24177 +               index = pos - 2;
24178 +               if (index >= size)
24179 +                       goto entries;
24180 +               for (p += index; p->name; p++) {
24181 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24182 +                               vs_proc_instantiate, 0, p))
24183 +                               goto out;
24184 +                       pos++;
24185 +               }
24186 +       entries:
24187 +               index = pos - size;
24188 +               p = &nx_virtnet_stuff[size - 1];
24189 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
24190 +               for (i = 0; i < nr_nids; i++) {
24191 +                       int n, nid = nid_array[i];
24192 +                       unsigned int j = PROC_NUMBUF;
24193 +
24194 +                       n = nid;
24195 +                       do
24196 +                               buf[--j] = '0' + (n % 10);
24197 +                       while (n /= 10);
24198 +
24199 +                       if (proc_fill_cache(filp, dirent, filldir,
24200 +                               buf + j, PROC_NUMBUF - j,
24201 +                               vs_proc_instantiate, nid, p))
24202 +                               goto out;
24203 +                       pos++;
24204 +               }
24205 +       }
24206 +out:
24207 +       filp->f_pos = pos;
24208 +       return 0;
24209 +}
24210 +
24211 +static int proc_virtnet_getattr(struct vfsmount *mnt,
24212 +       struct dentry *dentry, struct kstat *stat)
24213 +{
24214 +       struct inode *inode = dentry->d_inode;
24215 +
24216 +       generic_fillattr(inode, stat);
24217 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
24218 +       return 0;
24219 +}
24220 +
24221 +static struct file_operations proc_virtnet_dir_operations = {
24222 +       .read =         generic_read_dir,
24223 +       .readdir =      proc_virtnet_readdir,
24224 +};
24225 +
24226 +static struct inode_operations proc_virtnet_dir_inode_operations = {
24227 +       .getattr =      proc_virtnet_getattr,
24228 +       .lookup =       proc_virtnet_lookup,
24229 +};
24230 +
24231 +
24232 +
24233 +void proc_vx_init(void)
24234 +{
24235 +       struct proc_dir_entry *ent;
24236 +
24237 +       ent = proc_mkdir("virtual", 0);
24238 +       if (ent) {
24239 +               ent->proc_fops = &proc_virtual_dir_operations;
24240 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
24241 +       }
24242 +       proc_virtual = ent;
24243 +
24244 +       ent = proc_mkdir("virtnet", 0);
24245 +       if (ent) {
24246 +               ent->proc_fops = &proc_virtnet_dir_operations;
24247 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
24248 +       }
24249 +       proc_virtnet = ent;
24250 +}
24251 +
24252 +
24253 +
24254 +
24255 +/* per pid info */
24256 +
24257 +
24258 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
24259 +{
24260 +       struct vx_info *vxi;
24261 +       char *orig = buffer;
24262 +
24263 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
24264 +
24265 +       vxi = task_get_vx_info(p);
24266 +       if (!vxi)
24267 +               goto out;
24268 +
24269 +       buffer += sprintf(buffer, "BCaps:\t");
24270 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
24271 +       buffer += sprintf(buffer, "\n");
24272 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
24273 +               (unsigned long long)vxi->vx_ccaps);
24274 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
24275 +               (unsigned long long)vxi->vx_flags);
24276 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
24277 +
24278 +       put_vx_info(vxi);
24279 +out:
24280 +       return buffer - orig;
24281 +}
24282 +
24283 +
24284 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24285 +{
24286 +       struct nx_info *nxi;
24287 +       struct nx_addr_v4 *v4a;
24288 +#ifdef CONFIG_IPV6
24289 +       struct nx_addr_v6 *v6a;
24290 +#endif
24291 +       char *orig = buffer;
24292 +       int i;
24293 +
24294 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24295 +
24296 +       nxi = task_get_nx_info(p);
24297 +       if (!nxi)
24298 +               goto out;
24299 +
24300 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24301 +               (unsigned long long)nxi->nx_ncaps);
24302 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24303 +               (unsigned long long)nxi->nx_flags);
24304 +
24305 +       buffer += sprintf(buffer,
24306 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24307 +               NIPQUAD(nxi->v4_bcast.s_addr));
24308 +       buffer += sprintf (buffer,
24309 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
24310 +               NIPQUAD(nxi->v4_lback.s_addr));
24311 +       if (!NX_IPV4(nxi))
24312 +               goto skip_v4;
24313 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24314 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
24315 +                       i, NXAV4(v4a));
24316 +skip_v4:
24317 +#ifdef CONFIG_IPV6
24318 +       if (!NX_IPV6(nxi))
24319 +               goto skip_v6;
24320 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24321 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24322 +                       i, NXAV6(v6a));
24323 +skip_v6:
24324 +#endif
24325 +       put_nx_info(nxi);
24326 +out:
24327 +       return buffer - orig;
24328 +}
24329 +
24330 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/sched.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/sched.c
24331 --- linux-2.6.32.24/kernel/vserver/sched.c      1970-01-01 01:00:00.000000000 +0100
24332 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/sched.c      2009-12-03 20:04:56.000000000 +0100
24333 @@ -0,0 +1,414 @@
24334 +/*
24335 + *  linux/kernel/vserver/sched.c
24336 + *
24337 + *  Virtual Server: Scheduler Support
24338 + *
24339 + *  Copyright (C) 2004-2007  Herbert Pötzl
24340 + *
24341 + *  V0.01  adapted Sam Vilains version to 2.6.3
24342 + *  V0.02  removed legacy interface
24343 + *  V0.03  changed vcmds to vxi arg
24344 + *  V0.04  removed older and legacy interfaces
24345 + *
24346 + */
24347 +
24348 +#include <linux/vs_context.h>
24349 +#include <linux/vs_sched.h>
24350 +#include <linux/vserver/sched_cmd.h>
24351 +
24352 +#include <asm/uaccess.h>
24353 +
24354 +
24355 +#define vxd_check_range(val, min, max) do {            \
24356 +       vxlprintk((val < min) || (val > max),           \
24357 +               "check_range(%ld,%ld,%ld)",             \
24358 +               (long)val, (long)min, (long)max,        \
24359 +               __FILE__, __LINE__);                    \
24360 +       } while (0)
24361 +
24362 +
24363 +void vx_update_sched_param(struct _vx_sched *sched,
24364 +       struct _vx_sched_pc *sched_pc)
24365 +{
24366 +       unsigned int set_mask = sched->update_mask;
24367 +
24368 +       if (set_mask & VXSM_FILL_RATE)
24369 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
24370 +       if (set_mask & VXSM_INTERVAL)
24371 +               sched_pc->interval[0] = sched->interval[0];
24372 +       if (set_mask & VXSM_FILL_RATE2)
24373 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
24374 +       if (set_mask & VXSM_INTERVAL2)
24375 +               sched_pc->interval[1] = sched->interval[1];
24376 +       if (set_mask & VXSM_TOKENS)
24377 +               sched_pc->tokens = sched->tokens;
24378 +       if (set_mask & VXSM_TOKENS_MIN)
24379 +               sched_pc->tokens_min = sched->tokens_min;
24380 +       if (set_mask & VXSM_TOKENS_MAX)
24381 +               sched_pc->tokens_max = sched->tokens_max;
24382 +       if (set_mask & VXSM_PRIO_BIAS)
24383 +               sched_pc->prio_bias = sched->prio_bias;
24384 +
24385 +       if (set_mask & VXSM_IDLE_TIME)
24386 +               sched_pc->flags |= VXSF_IDLE_TIME;
24387 +       else
24388 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
24389 +
24390 +       /* reset time */
24391 +       sched_pc->norm_time = jiffies;
24392 +}
24393 +
24394 +
24395 +/*
24396 + * recalculate the context's scheduling tokens
24397 + *
24398 + * ret > 0 : number of tokens available
24399 + * ret < 0 : on hold, check delta_min[]
24400 + *          -1 only jiffies
24401 + *          -2 also idle time
24402 + *
24403 + */
24404 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
24405 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
24406 +{
24407 +       long delta;
24408 +       long tokens = 0;
24409 +       int flags = sched_pc->flags;
24410 +
24411 +       /* how much time did pass? */
24412 +       delta = *norm_time - sched_pc->norm_time;
24413 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
24414 +       vxd_check_range(delta, 0, INT_MAX);
24415 +
24416 +       if (delta >= sched_pc->interval[0]) {
24417 +               long tokens, integral;
24418 +
24419 +               /* calc integral token part */
24420 +               tokens = delta / sched_pc->interval[0];
24421 +               integral = tokens * sched_pc->interval[0];
24422 +               tokens *= sched_pc->fill_rate[0];
24423 +#ifdef CONFIG_VSERVER_HARDCPU
24424 +               delta_min[0] = delta - integral;
24425 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
24426 +#endif
24427 +               /* advance time */
24428 +               sched_pc->norm_time += delta;
24429 +
24430 +               /* add tokens */
24431 +               sched_pc->tokens += tokens;
24432 +               sched_pc->token_time += tokens;
24433 +       } else
24434 +               delta_min[0] = delta;
24435 +
24436 +#ifdef CONFIG_VSERVER_IDLETIME
24437 +       if (!(flags & VXSF_IDLE_TIME))
24438 +               goto skip_idle;
24439 +
24440 +       /* how much was the idle skip? */
24441 +       delta = *idle_time - sched_pc->idle_time;
24442 +       vxd_check_range(delta, 0, INT_MAX);
24443 +
24444 +       if (delta >= sched_pc->interval[1]) {
24445 +               long tokens, integral;
24446 +
24447 +               /* calc fair share token part */
24448 +               tokens = delta / sched_pc->interval[1];
24449 +               integral = tokens * sched_pc->interval[1];
24450 +               tokens *= sched_pc->fill_rate[1];
24451 +               delta_min[1] = delta - integral;
24452 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
24453 +
24454 +               /* advance idle time */
24455 +               sched_pc->idle_time += integral;
24456 +
24457 +               /* add tokens */
24458 +               sched_pc->tokens += tokens;
24459 +               sched_pc->token_time += tokens;
24460 +       } else
24461 +               delta_min[1] = delta;
24462 +skip_idle:
24463 +#endif
24464 +
24465 +       /* clip at maximum */
24466 +       if (sched_pc->tokens > sched_pc->tokens_max)
24467 +               sched_pc->tokens = sched_pc->tokens_max;
24468 +       tokens = sched_pc->tokens;
24469 +
24470 +       if ((flags & VXSF_ONHOLD)) {
24471 +               /* can we unhold? */
24472 +               if (tokens >= sched_pc->tokens_min) {
24473 +                       flags &= ~VXSF_ONHOLD;
24474 +                       sched_pc->hold_ticks +=
24475 +                               *norm_time - sched_pc->onhold;
24476 +               } else
24477 +                       goto on_hold;
24478 +       } else {
24479 +               /* put on hold? */
24480 +               if (tokens <= 0) {
24481 +                       flags |= VXSF_ONHOLD;
24482 +                       sched_pc->onhold = *norm_time;
24483 +                       goto on_hold;
24484 +               }
24485 +       }
24486 +       sched_pc->flags = flags;
24487 +       return tokens;
24488 +
24489 +on_hold:
24490 +       tokens = sched_pc->tokens_min - tokens;
24491 +       sched_pc->flags = flags;
24492 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
24493 +
24494 +#ifdef CONFIG_VSERVER_HARDCPU
24495 +       /* next interval? */
24496 +       if (!sched_pc->fill_rate[0])
24497 +               delta_min[0] = HZ;
24498 +       else if (tokens > sched_pc->fill_rate[0])
24499 +               delta_min[0] += sched_pc->interval[0] *
24500 +                       tokens / sched_pc->fill_rate[0];
24501 +       else
24502 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24503 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24504 +
24505 +#ifdef CONFIG_VSERVER_IDLETIME
24506 +       if (!(flags & VXSF_IDLE_TIME))
24507 +               return -1;
24508 +
24509 +       /* next interval? */
24510 +       if (!sched_pc->fill_rate[1])
24511 +               delta_min[1] = HZ;
24512 +       else if (tokens > sched_pc->fill_rate[1])
24513 +               delta_min[1] += sched_pc->interval[1] *
24514 +                       tokens / sched_pc->fill_rate[1];
24515 +       else
24516 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24517 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24518 +
24519 +       return -2;
24520 +#else
24521 +       return -1;
24522 +#endif /* CONFIG_VSERVER_IDLETIME */
24523 +#else
24524 +       return 0;
24525 +#endif /* CONFIG_VSERVER_HARDCPU */
24526 +}
24527 +
24528 +static inline unsigned long msec_to_ticks(unsigned long msec)
24529 +{
24530 +       return msecs_to_jiffies(msec);
24531 +}
24532 +
24533 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24534 +{
24535 +       return jiffies_to_msecs(ticks);
24536 +}
24537 +
24538 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24539 +{
24540 +       return jiffies_to_usecs(ticks);
24541 +}
24542 +
24543 +
24544 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24545 +{
24546 +       unsigned int set_mask = data->mask;
24547 +       unsigned int update_mask;
24548 +       int i, cpu;
24549 +
24550 +       /* Sanity check data values */
24551 +       if (data->tokens_max <= 0)
24552 +               data->tokens_max = HZ;
24553 +       if (data->tokens_min < 0)
24554 +               data->tokens_min = HZ / 3;
24555 +       if (data->tokens_min >= data->tokens_max)
24556 +               data->tokens_min = data->tokens_max;
24557 +
24558 +       if (data->prio_bias > MAX_PRIO_BIAS)
24559 +               data->prio_bias = MAX_PRIO_BIAS;
24560 +       if (data->prio_bias < MIN_PRIO_BIAS)
24561 +               data->prio_bias = MIN_PRIO_BIAS;
24562 +
24563 +       spin_lock(&vxi->sched.tokens_lock);
24564 +
24565 +       /* sync up on delayed updates */
24566 +       for_each_cpu_mask(cpu, vxi->sched.update)
24567 +               vx_update_sched_param(&vxi->sched,
24568 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24569 +
24570 +       if (set_mask & VXSM_FILL_RATE)
24571 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24572 +       if (set_mask & VXSM_FILL_RATE2)
24573 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24574 +       if (set_mask & VXSM_INTERVAL)
24575 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24576 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24577 +       if (set_mask & VXSM_INTERVAL2)
24578 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24579 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24580 +       if (set_mask & VXSM_TOKENS)
24581 +               vxi->sched.tokens = data->tokens;
24582 +       if (set_mask & VXSM_TOKENS_MIN)
24583 +               vxi->sched.tokens_min = data->tokens_min;
24584 +       if (set_mask & VXSM_TOKENS_MAX)
24585 +               vxi->sched.tokens_max = data->tokens_max;
24586 +       if (set_mask & VXSM_PRIO_BIAS)
24587 +               vxi->sched.prio_bias = data->prio_bias;
24588 +
24589 +       /* Sanity check rate/interval */
24590 +       for (i = 0; i < 2; i++) {
24591 +               if (data->fill_rate[i] < 0)
24592 +                       data->fill_rate[i] = 0;
24593 +               if (data->interval[i] <= 0)
24594 +                       data->interval[i] = HZ;
24595 +       }
24596 +
24597 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24598 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24599 +       vxi->sched.update_mask = update_mask;
24600 +
24601 +#ifdef CONFIG_SMP
24602 +       rmb();
24603 +       if (set_mask & VXSM_CPU_ID) {
24604 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24605 +               cpus_and(vxi->sched.update, cpu_online_map,
24606 +                       vxi->sched.update);
24607 +       } else
24608 +               vxi->sched.update = cpu_online_map;
24609 +
24610 +       /* forced reload? */
24611 +       if (set_mask & VXSM_FORCE) {
24612 +               for_each_cpu_mask(cpu, vxi->sched.update)
24613 +                       vx_update_sched_param(&vxi->sched,
24614 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24615 +               vxi->sched.update = CPU_MASK_NONE;
24616 +       }
24617 +#else
24618 +       /* on UP we update immediately */
24619 +       vx_update_sched_param(&vxi->sched,
24620 +               &vx_per_cpu(vxi, sched_pc, 0));
24621 +#endif
24622 +
24623 +       spin_unlock(&vxi->sched.tokens_lock);
24624 +       return 0;
24625 +}
24626 +
24627 +
24628 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24629 +#define COPY_PRI(C) C(prio_bias)
24630 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24631 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24632 +                   C(fill_rate[1]); C(interval[1]);
24633 +
24634 +#define COPY_VALUE(name) vc_data.name = data->name
24635 +
24636 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24637 +{
24638 +       struct vcmd_sched_v5 vc_data;
24639 +
24640 +       vc_data.mask = data->set_mask;
24641 +       COPY_IDS(COPY_VALUE);
24642 +       COPY_PRI(COPY_VALUE);
24643 +       COPY_TOK(COPY_VALUE);
24644 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24645 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24646 +       return do_set_sched(vxi, &vc_data);
24647 +}
24648 +
24649 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24650 +{
24651 +       struct vcmd_set_sched_v4 vc_data;
24652 +
24653 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24654 +               return -EFAULT;
24655 +
24656 +       return do_set_sched_v4(vxi, &vc_data);
24657 +}
24658 +
24659 +       /* latest interface is v5 */
24660 +
24661 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24662 +{
24663 +       struct vcmd_sched_v5 vc_data;
24664 +
24665 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24666 +               return -EFAULT;
24667 +
24668 +       return do_set_sched(vxi, &vc_data);
24669 +}
24670 +
24671 +
24672 +#define COPY_PRI(C) C(prio_bias)
24673 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24674 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24675 +                   C(fill_rate[1]); C(interval[1]);
24676 +
24677 +#define COPY_VALUE(name) vc_data.name = data->name
24678 +
24679 +
24680 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24681 +{
24682 +       struct vcmd_sched_v5 vc_data;
24683 +
24684 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24685 +               return -EFAULT;
24686 +
24687 +       if (vc_data.mask & VXSM_CPU_ID) {
24688 +               int cpu = vc_data.cpu_id;
24689 +               struct _vx_sched_pc *data;
24690 +
24691 +               if (!cpu_possible(cpu))
24692 +                       return -EINVAL;
24693 +
24694 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24695 +               COPY_TOK(COPY_VALUE);
24696 +               COPY_PRI(COPY_VALUE);
24697 +               COPY_FRI(COPY_VALUE);
24698 +
24699 +               if (data->flags & VXSF_IDLE_TIME)
24700 +                       vc_data.mask |= VXSM_IDLE_TIME;
24701 +       } else {
24702 +               struct _vx_sched *data = &vxi->sched;
24703 +
24704 +               COPY_TOK(COPY_VALUE);
24705 +               COPY_PRI(COPY_VALUE);
24706 +               COPY_FRI(COPY_VALUE);
24707 +       }
24708 +
24709 +       if (vc_data.mask & VXSM_MSEC) {
24710 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24711 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24712 +       }
24713 +
24714 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24715 +               return -EFAULT;
24716 +       return 0;
24717 +}
24718 +
24719 +
24720 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24721 +{
24722 +       struct vcmd_sched_info vc_data;
24723 +       int cpu;
24724 +
24725 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24726 +               return -EFAULT;
24727 +
24728 +       cpu = vc_data.cpu_id;
24729 +       if (!cpu_possible(cpu))
24730 +               return -EINVAL;
24731 +
24732 +       if (vxi) {
24733 +               struct _vx_sched_pc *sched_pc =
24734 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24735 +
24736 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24737 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24738 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24739 +               vc_data.vavavoom = sched_pc->vavavoom;
24740 +       }
24741 +       vc_data.token_usec = ticks_to_usec(1);
24742 +
24743 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24744 +               return -EFAULT;
24745 +       return 0;
24746 +}
24747 +
24748 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/sched_init.h linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/sched_init.h
24749 --- linux-2.6.32.24/kernel/vserver/sched_init.h 1970-01-01 01:00:00.000000000 +0100
24750 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/sched_init.h 2009-12-03 20:04:56.000000000 +0100
24751 @@ -0,0 +1,50 @@
24752 +
24753 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24754 +{
24755 +       static struct lock_class_key tokens_lock_key;
24756 +
24757 +       /* scheduling; hard code starting values as constants */
24758 +       sched->fill_rate[0]     = 1;
24759 +       sched->interval[0]      = 4;
24760 +       sched->fill_rate[1]     = 1;
24761 +       sched->interval[1]      = 8;
24762 +       sched->tokens           = HZ >> 2;
24763 +       sched->tokens_min       = HZ >> 4;
24764 +       sched->tokens_max       = HZ >> 1;
24765 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24766 +       sched->prio_bias        = 0;
24767 +
24768 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24769 +}
24770 +
24771 +static inline
24772 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24773 +{
24774 +       sched_pc->fill_rate[0]  = 1;
24775 +       sched_pc->interval[0]   = 4;
24776 +       sched_pc->fill_rate[1]  = 1;
24777 +       sched_pc->interval[1]   = 8;
24778 +       sched_pc->tokens        = HZ >> 2;
24779 +       sched_pc->tokens_min    = HZ >> 4;
24780 +       sched_pc->tokens_max    = HZ >> 1;
24781 +       sched_pc->prio_bias     = 0;
24782 +       sched_pc->vavavoom      = 0;
24783 +       sched_pc->token_time    = 0;
24784 +       sched_pc->idle_time     = 0;
24785 +       sched_pc->norm_time     = jiffies;
24786 +
24787 +       sched_pc->user_ticks = 0;
24788 +       sched_pc->sys_ticks = 0;
24789 +       sched_pc->hold_ticks = 0;
24790 +}
24791 +
24792 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24793 +{
24794 +       return;
24795 +}
24796 +
24797 +static inline
24798 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24799 +{
24800 +       return;
24801 +}
24802 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/sched_proc.h linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/sched_proc.h
24803 --- linux-2.6.32.24/kernel/vserver/sched_proc.h 1970-01-01 01:00:00.000000000 +0100
24804 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/sched_proc.h 2009-12-03 20:04:56.000000000 +0100
24805 @@ -0,0 +1,57 @@
24806 +#ifndef _VX_SCHED_PROC_H
24807 +#define _VX_SCHED_PROC_H
24808 +
24809 +
24810 +static inline
24811 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24812 +{
24813 +       int length = 0;
24814 +
24815 +       length += sprintf(buffer,
24816 +               "FillRate:\t%8d,%d\n"
24817 +               "Interval:\t%8d,%d\n"
24818 +               "TokensMin:\t%8d\n"
24819 +               "TokensMax:\t%8d\n"
24820 +               "PrioBias:\t%8d\n",
24821 +               sched->fill_rate[0],
24822 +               sched->fill_rate[1],
24823 +               sched->interval[0],
24824 +               sched->interval[1],
24825 +               sched->tokens_min,
24826 +               sched->tokens_max,
24827 +               sched->prio_bias);
24828 +       return length;
24829 +}
24830 +
24831 +static inline
24832 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24833 +       char *buffer, int cpu)
24834 +{
24835 +       int length = 0;
24836 +
24837 +       length += sprintf(buffer + length,
24838 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24839 +               (unsigned long long)sched_pc->user_ticks,
24840 +               (unsigned long long)sched_pc->sys_ticks,
24841 +               (unsigned long long)sched_pc->hold_ticks,
24842 +               sched_pc->token_time,
24843 +               sched_pc->idle_time);
24844 +       length += sprintf(buffer + length,
24845 +               " %c%c %d %d %d %d/%d %d/%d",
24846 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24847 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24848 +               sched_pc->tokens,
24849 +               sched_pc->tokens_min,
24850 +               sched_pc->tokens_max,
24851 +               sched_pc->fill_rate[0],
24852 +               sched_pc->interval[0],
24853 +               sched_pc->fill_rate[1],
24854 +               sched_pc->interval[1]);
24855 +       length += sprintf(buffer + length,
24856 +               " %d %d\n",
24857 +               sched_pc->prio_bias,
24858 +               sched_pc->vavavoom);
24859 +       return length;
24860 +}
24861 +
24862 +#endif /* _VX_SCHED_PROC_H */
24863 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/signal.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/signal.c
24864 --- linux-2.6.32.24/kernel/vserver/signal.c     1970-01-01 01:00:00.000000000 +0100
24865 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/signal.c     2009-12-03 20:04:56.000000000 +0100
24866 @@ -0,0 +1,132 @@
24867 +/*
24868 + *  linux/kernel/vserver/signal.c
24869 + *
24870 + *  Virtual Server: Signal Support
24871 + *
24872 + *  Copyright (C) 2003-2007  Herbert Pötzl
24873 + *
24874 + *  V0.01  broken out from vcontext V0.05
24875 + *  V0.02  changed vcmds to vxi arg
24876 + *  V0.03  adjusted siginfo for kill
24877 + *
24878 + */
24879 +
24880 +#include <asm/uaccess.h>
24881 +
24882 +#include <linux/vs_context.h>
24883 +#include <linux/vs_pid.h>
24884 +#include <linux/vserver/signal_cmd.h>
24885 +
24886 +
24887 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24888 +{
24889 +       int retval, count = 0;
24890 +       struct task_struct *p;
24891 +       struct siginfo *sip = SEND_SIG_PRIV;
24892 +
24893 +       retval = -ESRCH;
24894 +       vxdprintk(VXD_CBIT(misc, 4),
24895 +               "vx_info_kill(%p[#%d],%d,%d)*",
24896 +               vxi, vxi->vx_id, pid, sig);
24897 +       read_lock(&tasklist_lock);
24898 +       switch (pid) {
24899 +       case  0:
24900 +       case -1:
24901 +               for_each_process(p) {
24902 +                       int err = 0;
24903 +
24904 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24905 +                               (pid && vxi->vx_initpid == p->pid))
24906 +                               continue;
24907 +
24908 +                       err = group_send_sig_info(sig, sip, p);
24909 +                       ++count;
24910 +                       if (err != -EPERM)
24911 +                               retval = err;
24912 +               }
24913 +               break;
24914 +
24915 +       case 1:
24916 +               if (vxi->vx_initpid) {
24917 +                       pid = vxi->vx_initpid;
24918 +                       /* for now, only SIGINT to private init ... */
24919 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24920 +                               /* ... as long as there are tasks left */
24921 +                               (atomic_read(&vxi->vx_tasks) > 1))
24922 +                               sig = SIGINT;
24923 +               }
24924 +               /* fallthrough */
24925 +       default:
24926 +               p = find_task_by_real_pid(pid);
24927 +               if (p) {
24928 +                       if (vx_task_xid(p) == vxi->vx_id)
24929 +                               retval = group_send_sig_info(sig, sip, p);
24930 +               }
24931 +               break;
24932 +       }
24933 +       read_unlock(&tasklist_lock);
24934 +       vxdprintk(VXD_CBIT(misc, 4),
24935 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24936 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24937 +       return retval;
24938 +}
24939 +
24940 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24941 +{
24942 +       struct vcmd_ctx_kill_v0 vc_data;
24943 +
24944 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24945 +               return -EFAULT;
24946 +
24947 +       /* special check to allow guest shutdown */
24948 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24949 +               /* forbid killall pid=0 when init is present */
24950 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24951 +               (vc_data.pid > 1)))
24952 +               return -EACCES;
24953 +
24954 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24955 +}
24956 +
24957 +
24958 +static int __wait_exit(struct vx_info *vxi)
24959 +{
24960 +       DECLARE_WAITQUEUE(wait, current);
24961 +       int ret = 0;
24962 +
24963 +       add_wait_queue(&vxi->vx_wait, &wait);
24964 +       set_current_state(TASK_INTERRUPTIBLE);
24965 +
24966 +wait:
24967 +       if (vx_info_state(vxi,
24968 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24969 +               goto out;
24970 +       if (signal_pending(current)) {
24971 +               ret = -ERESTARTSYS;
24972 +               goto out;
24973 +       }
24974 +       schedule();
24975 +       goto wait;
24976 +
24977 +out:
24978 +       set_current_state(TASK_RUNNING);
24979 +       remove_wait_queue(&vxi->vx_wait, &wait);
24980 +       return ret;
24981 +}
24982 +
24983 +
24984 +
24985 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24986 +{
24987 +       struct vcmd_wait_exit_v0 vc_data;
24988 +       int ret;
24989 +
24990 +       ret = __wait_exit(vxi);
24991 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24992 +       vc_data.exit_code = vxi->exit_code;
24993 +
24994 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24995 +               ret = -EFAULT;
24996 +       return ret;
24997 +}
24998 +
24999 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/space.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/space.c
25000 --- linux-2.6.32.24/kernel/vserver/space.c      1970-01-01 01:00:00.000000000 +0100
25001 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/space.c      2009-12-03 20:04:56.000000000 +0100
25002 @@ -0,0 +1,375 @@
25003 +/*
25004 + *  linux/kernel/vserver/space.c
25005 + *
25006 + *  Virtual Server: Context Space Support
25007 + *
25008 + *  Copyright (C) 2003-2007  Herbert Pötzl
25009 + *
25010 + *  V0.01  broken out from context.c 0.07
25011 + *  V0.02  added task locking for namespace
25012 + *  V0.03  broken out vx_enter_namespace
25013 + *  V0.04  added *space support and commands
25014 + *
25015 + */
25016 +
25017 +#include <linux/utsname.h>
25018 +#include <linux/nsproxy.h>
25019 +#include <linux/err.h>
25020 +#include <linux/fs_struct.h>
25021 +#include <asm/uaccess.h>
25022 +
25023 +#include <linux/vs_context.h>
25024 +#include <linux/vserver/space.h>
25025 +#include <linux/vserver/space_cmd.h>
25026 +
25027 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
25028 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
25029 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
25030 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
25031 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
25032 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
25033 +
25034 +
25035 +/* namespace functions */
25036 +
25037 +#include <linux/mnt_namespace.h>
25038 +#include <linux/user_namespace.h>
25039 +#include <linux/pid_namespace.h>
25040 +#include <linux/ipc_namespace.h>
25041 +#include <net/net_namespace.h>
25042 +
25043 +
25044 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
25045 +       .mask = CLONE_FS |
25046 +               CLONE_NEWNS |
25047 +               CLONE_NEWUTS |
25048 +               CLONE_NEWIPC |
25049 +               CLONE_NEWUSER |
25050 +               0
25051 +};
25052 +
25053 +static const struct vcmd_space_mask_v1 space_mask = {
25054 +       .mask = CLONE_FS |
25055 +               CLONE_NEWNS |
25056 +               CLONE_NEWUTS |
25057 +               CLONE_NEWIPC |
25058 +               CLONE_NEWUSER |
25059 +#ifdef CONFIG_PID_NS
25060 +               CLONE_NEWPID |
25061 +#endif
25062 +#ifdef CONFIG_NET_NS
25063 +               CLONE_NEWNET |
25064 +#endif
25065 +               0
25066 +};
25067 +
25068 +static const struct vcmd_space_mask_v1 default_space_mask = {
25069 +       .mask = CLONE_FS |
25070 +               CLONE_NEWNS |
25071 +               CLONE_NEWUTS |
25072 +               CLONE_NEWIPC |
25073 +               CLONE_NEWUSER |
25074 +#ifdef CONFIG_PID_NS
25075 +//             CLONE_NEWPID |
25076 +#endif
25077 +               0
25078 +};
25079 +
25080 +/*
25081 + *     build a new nsproxy mix
25082 + *      assumes that both proxies are 'const'
25083 + *     does not touch nsproxy refcounts
25084 + *     will hold a reference on the result.
25085 + */
25086 +
25087 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
25088 +       struct nsproxy *new_nsproxy, unsigned long mask)
25089 +{
25090 +       struct mnt_namespace *old_ns;
25091 +       struct uts_namespace *old_uts;
25092 +       struct ipc_namespace *old_ipc;
25093 +#ifdef CONFIG_PID_NS
25094 +       struct pid_namespace *old_pid;
25095 +#endif
25096 +#ifdef CONFIG_NET_NS
25097 +       struct net *old_net;
25098 +#endif
25099 +       struct nsproxy *nsproxy;
25100 +
25101 +       nsproxy = copy_nsproxy(old_nsproxy);
25102 +       if (!nsproxy)
25103 +               goto out;
25104 +
25105 +       if (mask & CLONE_NEWNS) {
25106 +               old_ns = nsproxy->mnt_ns;
25107 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
25108 +               if (nsproxy->mnt_ns)
25109 +                       get_mnt_ns(nsproxy->mnt_ns);
25110 +       } else
25111 +               old_ns = NULL;
25112 +
25113 +       if (mask & CLONE_NEWUTS) {
25114 +               old_uts = nsproxy->uts_ns;
25115 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
25116 +               if (nsproxy->uts_ns)
25117 +                       get_uts_ns(nsproxy->uts_ns);
25118 +       } else
25119 +               old_uts = NULL;
25120 +
25121 +       if (mask & CLONE_NEWIPC) {
25122 +               old_ipc = nsproxy->ipc_ns;
25123 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
25124 +               if (nsproxy->ipc_ns)
25125 +                       get_ipc_ns(nsproxy->ipc_ns);
25126 +       } else
25127 +               old_ipc = NULL;
25128 +
25129 +#ifdef CONFIG_PID_NS
25130 +       if (mask & CLONE_NEWPID) {
25131 +               old_pid = nsproxy->pid_ns;
25132 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
25133 +               if (nsproxy->pid_ns)
25134 +                       get_pid_ns(nsproxy->pid_ns);
25135 +       } else
25136 +               old_pid = NULL;
25137 +#endif
25138 +#ifdef CONFIG_NET_NS
25139 +       if (mask & CLONE_NEWNET) {
25140 +               old_net = nsproxy->net_ns;
25141 +               nsproxy->net_ns = new_nsproxy->net_ns;
25142 +               if (nsproxy->net_ns)
25143 +                       get_net(nsproxy->net_ns);
25144 +       } else
25145 +               old_net = NULL;
25146 +#endif
25147 +       if (old_ns)
25148 +               put_mnt_ns(old_ns);
25149 +       if (old_uts)
25150 +               put_uts_ns(old_uts);
25151 +       if (old_ipc)
25152 +               put_ipc_ns(old_ipc);
25153 +#ifdef CONFIG_PID_NS
25154 +       if (old_pid)
25155 +               put_pid_ns(old_pid);
25156 +#endif
25157 +#ifdef CONFIG_NET_NS
25158 +       if (old_net)
25159 +               put_net(old_net);
25160 +#endif
25161 +out:
25162 +       return nsproxy;
25163 +}
25164 +
25165 +
25166 +/*
25167 + *     merge two nsproxy structs into a new one.
25168 + *     will hold a reference on the result.
25169 + */
25170 +
25171 +static inline
25172 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
25173 +       struct nsproxy *proxy, unsigned long mask)
25174 +{
25175 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
25176 +
25177 +       if (!proxy)
25178 +               return NULL;
25179 +
25180 +       if (mask) {
25181 +               /* vs_mix_nsproxy returns with reference */
25182 +               return vs_mix_nsproxy(old ? old : &null_proxy,
25183 +                       proxy, mask);
25184 +       }
25185 +       get_nsproxy(proxy);
25186 +       return proxy;
25187 +}
25188 +
25189 +
25190 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25191 +{
25192 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
25193 +       struct fs_struct *fs_cur, *fs = NULL;
25194 +       int ret, kill = 0;
25195 +
25196 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
25197 +               vxi, vxi->vx_id, mask, index);
25198 +
25199 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
25200 +               return -EACCES;
25201 +
25202 +       if (!mask)
25203 +               mask = vxi->vx_nsmask[index];
25204 +
25205 +       if ((mask & vxi->vx_nsmask[index]) != mask)
25206 +               return -EINVAL;
25207 +
25208 +       if (mask & CLONE_FS) {
25209 +               fs = copy_fs_struct(vxi->vx_fs[index]);
25210 +               if (!fs)
25211 +                       return -ENOMEM;
25212 +       }
25213 +       proxy = vxi->vx_nsproxy[index];
25214 +
25215 +       vxdprintk(VXD_CBIT(space, 9),
25216 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
25217 +               vxi, vxi->vx_id, mask, index, proxy, fs);
25218 +
25219 +       task_lock(current);
25220 +       fs_cur = current->fs;
25221 +
25222 +       if (mask & CLONE_FS) {
25223 +               write_lock(&fs_cur->lock);
25224 +               current->fs = fs;
25225 +               kill = !--fs_cur->users;
25226 +               write_unlock(&fs_cur->lock);
25227 +       }
25228 +
25229 +       proxy_cur = current->nsproxy;
25230 +       get_nsproxy(proxy_cur);
25231 +       task_unlock(current);
25232 +
25233 +       if (kill)
25234 +               free_fs_struct(fs_cur);
25235 +
25236 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
25237 +       if (IS_ERR(proxy_new)) {
25238 +               ret = PTR_ERR(proxy_new);
25239 +               goto out_put;
25240 +       }
25241 +
25242 +       proxy_new = xchg(&current->nsproxy, proxy_new);
25243 +       ret = 0;
25244 +
25245 +       if (proxy_new)
25246 +               put_nsproxy(proxy_new);
25247 +out_put:
25248 +       if (proxy_cur)
25249 +               put_nsproxy(proxy_cur);
25250 +       return ret;
25251 +}
25252 +
25253 +
25254 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25255 +{
25256 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
25257 +       struct fs_struct *fs_vxi, *fs;
25258 +       int ret, kill = 0;
25259 +
25260 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
25261 +               vxi, vxi->vx_id, mask, index);
25262 +#if 0
25263 +       if (!mask)
25264 +               mask = default_space_mask.mask;
25265 +#endif
25266 +       if ((mask & space_mask.mask) != mask)
25267 +               return -EINVAL;
25268 +
25269 +       proxy_vxi = vxi->vx_nsproxy[index];
25270 +       fs_vxi = vxi->vx_fs[index];
25271 +
25272 +       if (mask & CLONE_FS) {
25273 +               fs = copy_fs_struct(current->fs);
25274 +               if (!fs)
25275 +                       return -ENOMEM;
25276 +       }
25277 +
25278 +       task_lock(current);
25279 +
25280 +       if (mask & CLONE_FS) {
25281 +               write_lock(&fs_vxi->lock);
25282 +               vxi->vx_fs[index] = fs;
25283 +               kill = !--fs_vxi->users;
25284 +               write_unlock(&fs_vxi->lock);
25285 +       }
25286 +
25287 +       proxy_cur = current->nsproxy;
25288 +       get_nsproxy(proxy_cur);
25289 +       task_unlock(current);
25290 +
25291 +       if (kill)
25292 +               free_fs_struct(fs_vxi);
25293 +
25294 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
25295 +       if (IS_ERR(proxy_new)) {
25296 +               ret = PTR_ERR(proxy_new);
25297 +               goto out_put;
25298 +       }
25299 +
25300 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
25301 +       vxi->vx_nsmask[index] |= mask;
25302 +       ret = 0;
25303 +
25304 +       if (proxy_new)
25305 +               put_nsproxy(proxy_new);
25306 +out_put:
25307 +       if (proxy_cur)
25308 +               put_nsproxy(proxy_cur);
25309 +       return ret;
25310 +}
25311 +
25312 +
25313 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
25314 +{
25315 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25316 +
25317 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25318 +               return -EFAULT;
25319 +
25320 +       return vx_enter_space(vxi, vc_data.mask, 0);
25321 +}
25322 +
25323 +int vc_enter_space(struct vx_info *vxi, void __user *data)
25324 +{
25325 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25326 +
25327 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25328 +               return -EFAULT;
25329 +
25330 +       if (vc_data.index >= VX_SPACES)
25331 +               return -EINVAL;
25332 +
25333 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
25334 +}
25335 +
25336 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
25337 +{
25338 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25339 +
25340 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25341 +               return -EFAULT;
25342 +
25343 +       return vx_set_space(vxi, vc_data.mask, 0);
25344 +}
25345 +
25346 +int vc_set_space(struct vx_info *vxi, void __user *data)
25347 +{
25348 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25349 +
25350 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25351 +               return -EFAULT;
25352 +
25353 +       if (vc_data.index >= VX_SPACES)
25354 +               return -EINVAL;
25355 +
25356 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
25357 +}
25358 +
25359 +int vc_get_space_mask(void __user *data, int type)
25360 +{
25361 +       const struct vcmd_space_mask_v1 *mask;
25362 +
25363 +       if (type == 0)
25364 +               mask = &space_mask_v0;
25365 +       else if (type == 1)
25366 +               mask = &space_mask;
25367 +       else
25368 +               mask = &default_space_mask;
25369 +
25370 +       vxdprintk(VXD_CBIT(space, 10),
25371 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
25372 +
25373 +       if (copy_to_user(data, mask, sizeof(*mask)))
25374 +               return -EFAULT;
25375 +       return 0;
25376 +}
25377 +
25378 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/switch.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/switch.c
25379 --- linux-2.6.32.24/kernel/vserver/switch.c     1970-01-01 01:00:00.000000000 +0100
25380 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/switch.c     2009-12-03 20:04:56.000000000 +0100
25381 @@ -0,0 +1,546 @@
25382 +/*
25383 + *  linux/kernel/vserver/switch.c
25384 + *
25385 + *  Virtual Server: Syscall Switch
25386 + *
25387 + *  Copyright (C) 2003-2007  Herbert Pötzl
25388 + *
25389 + *  V0.01  syscall switch
25390 + *  V0.02  added signal to context
25391 + *  V0.03  added rlimit functions
25392 + *  V0.04  added iattr, task/xid functions
25393 + *  V0.05  added debug/history stuff
25394 + *  V0.06  added compat32 layer
25395 + *  V0.07  vcmd args and perms
25396 + *  V0.08  added status commands
25397 + *  V0.09  added tag commands
25398 + *  V0.10  added oom bias
25399 + *  V0.11  added device commands
25400 + *
25401 + */
25402 +
25403 +#include <linux/vs_context.h>
25404 +#include <linux/vs_network.h>
25405 +#include <linux/vserver/switch.h>
25406 +
25407 +#include "vci_config.h"
25408 +
25409 +
25410 +static inline
25411 +int vc_get_version(uint32_t id)
25412 +{
25413 +       return VCI_VERSION;
25414 +}
25415 +
25416 +static inline
25417 +int vc_get_vci(uint32_t id)
25418 +{
25419 +       return vci_kernel_config();
25420 +}
25421 +
25422 +#include <linux/vserver/context_cmd.h>
25423 +#include <linux/vserver/cvirt_cmd.h>
25424 +#include <linux/vserver/cacct_cmd.h>
25425 +#include <linux/vserver/limit_cmd.h>
25426 +#include <linux/vserver/network_cmd.h>
25427 +#include <linux/vserver/sched_cmd.h>
25428 +#include <linux/vserver/debug_cmd.h>
25429 +#include <linux/vserver/inode_cmd.h>
25430 +#include <linux/vserver/dlimit_cmd.h>
25431 +#include <linux/vserver/signal_cmd.h>
25432 +#include <linux/vserver/space_cmd.h>
25433 +#include <linux/vserver/tag_cmd.h>
25434 +#include <linux/vserver/device_cmd.h>
25435 +
25436 +#include <linux/vserver/inode.h>
25437 +#include <linux/vserver/dlimit.h>
25438 +
25439 +
25440 +#ifdef CONFIG_COMPAT
25441 +#define __COMPAT(name, id, data, compat)       \
25442 +       (compat) ? name ## _x32(id, data) : name(id, data)
25443 +#define __COMPAT_NO_ID(name, data, compat)     \
25444 +       (compat) ? name ## _x32(data) : name(data)
25445 +#else
25446 +#define __COMPAT(name, id, data, compat)       \
25447 +       name(id, data)
25448 +#define __COMPAT_NO_ID(name, data, compat)     \
25449 +       name(data)
25450 +#endif
25451 +
25452 +
25453 +static inline
25454 +long do_vcmd(uint32_t cmd, uint32_t id,
25455 +       struct vx_info *vxi, struct nx_info *nxi,
25456 +       void __user *data, int compat)
25457 +{
25458 +       switch (cmd) {
25459 +
25460 +       case VCMD_get_version:
25461 +               return vc_get_version(id);
25462 +       case VCMD_get_vci:
25463 +               return vc_get_vci(id);
25464 +
25465 +       case VCMD_task_xid:
25466 +               return vc_task_xid(id);
25467 +       case VCMD_vx_info:
25468 +               return vc_vx_info(vxi, data);
25469 +
25470 +       case VCMD_task_nid:
25471 +               return vc_task_nid(id);
25472 +       case VCMD_nx_info:
25473 +               return vc_nx_info(nxi, data);
25474 +
25475 +       case VCMD_task_tag:
25476 +               return vc_task_tag(id);
25477 +
25478 +       case VCMD_set_space_v1:
25479 +               return vc_set_space_v1(vxi, data);
25480 +       /* this is version 2 */
25481 +       case VCMD_set_space:
25482 +               return vc_set_space(vxi, data);
25483 +
25484 +       case VCMD_get_space_mask_v0:
25485 +               return vc_get_space_mask(data, 0);
25486 +       /* this is version 1 */
25487 +       case VCMD_get_space_mask:
25488 +               return vc_get_space_mask(data, 1);
25489 +
25490 +       case VCMD_get_space_default:
25491 +               return vc_get_space_mask(data, -1);
25492 +
25493 +#ifdef CONFIG_IA32_EMULATION
25494 +       case VCMD_get_rlimit:
25495 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25496 +       case VCMD_set_rlimit:
25497 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25498 +#else
25499 +       case VCMD_get_rlimit:
25500 +               return vc_get_rlimit(vxi, data);
25501 +       case VCMD_set_rlimit:
25502 +               return vc_set_rlimit(vxi, data);
25503 +#endif
25504 +       case VCMD_get_rlimit_mask:
25505 +               return vc_get_rlimit_mask(id, data);
25506 +       case VCMD_reset_hits:
25507 +               return vc_reset_hits(vxi, data);
25508 +       case VCMD_reset_minmax:
25509 +               return vc_reset_minmax(vxi, data);
25510 +
25511 +       case VCMD_get_vhi_name:
25512 +               return vc_get_vhi_name(vxi, data);
25513 +       case VCMD_set_vhi_name:
25514 +               return vc_set_vhi_name(vxi, data);
25515 +
25516 +       case VCMD_ctx_stat:
25517 +               return vc_ctx_stat(vxi, data);
25518 +       case VCMD_virt_stat:
25519 +               return vc_virt_stat(vxi, data);
25520 +       case VCMD_sock_stat:
25521 +               return vc_sock_stat(vxi, data);
25522 +       case VCMD_rlimit_stat:
25523 +               return vc_rlimit_stat(vxi, data);
25524 +
25525 +       case VCMD_set_cflags:
25526 +               return vc_set_cflags(vxi, data);
25527 +       case VCMD_get_cflags:
25528 +               return vc_get_cflags(vxi, data);
25529 +
25530 +       /* this is version 1 */
25531 +       case VCMD_set_ccaps:
25532 +               return vc_set_ccaps(vxi, data);
25533 +       /* this is version 1 */
25534 +       case VCMD_get_ccaps:
25535 +               return vc_get_ccaps(vxi, data);
25536 +       case VCMD_set_bcaps:
25537 +               return vc_set_bcaps(vxi, data);
25538 +       case VCMD_get_bcaps:
25539 +               return vc_get_bcaps(vxi, data);
25540 +
25541 +       case VCMD_set_badness:
25542 +               return vc_set_badness(vxi, data);
25543 +       case VCMD_get_badness:
25544 +               return vc_get_badness(vxi, data);
25545 +
25546 +       case VCMD_set_nflags:
25547 +               return vc_set_nflags(nxi, data);
25548 +       case VCMD_get_nflags:
25549 +               return vc_get_nflags(nxi, data);
25550 +
25551 +       case VCMD_set_ncaps:
25552 +               return vc_set_ncaps(nxi, data);
25553 +       case VCMD_get_ncaps:
25554 +               return vc_get_ncaps(nxi, data);
25555 +
25556 +       case VCMD_set_sched_v4:
25557 +               return vc_set_sched_v4(vxi, data);
25558 +       /* this is version 5 */
25559 +       case VCMD_set_sched:
25560 +               return vc_set_sched(vxi, data);
25561 +       case VCMD_get_sched:
25562 +               return vc_get_sched(vxi, data);
25563 +       case VCMD_sched_info:
25564 +               return vc_sched_info(vxi, data);
25565 +
25566 +       case VCMD_add_dlimit:
25567 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25568 +       case VCMD_rem_dlimit:
25569 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25570 +       case VCMD_set_dlimit:
25571 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25572 +       case VCMD_get_dlimit:
25573 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25574 +
25575 +       case VCMD_ctx_kill:
25576 +               return vc_ctx_kill(vxi, data);
25577 +
25578 +       case VCMD_wait_exit:
25579 +               return vc_wait_exit(vxi, data);
25580 +
25581 +       case VCMD_get_iattr:
25582 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25583 +       case VCMD_set_iattr:
25584 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25585 +
25586 +       case VCMD_fget_iattr:
25587 +               return vc_fget_iattr(id, data);
25588 +       case VCMD_fset_iattr:
25589 +               return vc_fset_iattr(id, data);
25590 +
25591 +       case VCMD_enter_space_v0:
25592 +               return vc_enter_space_v1(vxi, NULL);
25593 +       case VCMD_enter_space_v1:
25594 +               return vc_enter_space_v1(vxi, data);
25595 +       /* this is version 2 */
25596 +       case VCMD_enter_space:
25597 +               return vc_enter_space(vxi, data);
25598 +
25599 +       case VCMD_ctx_create_v0:
25600 +               return vc_ctx_create(id, NULL);
25601 +       case VCMD_ctx_create:
25602 +               return vc_ctx_create(id, data);
25603 +       case VCMD_ctx_migrate_v0:
25604 +               return vc_ctx_migrate(vxi, NULL);
25605 +       case VCMD_ctx_migrate:
25606 +               return vc_ctx_migrate(vxi, data);
25607 +
25608 +       case VCMD_net_create_v0:
25609 +               return vc_net_create(id, NULL);
25610 +       case VCMD_net_create:
25611 +               return vc_net_create(id, data);
25612 +       case VCMD_net_migrate:
25613 +               return vc_net_migrate(nxi, data);
25614 +
25615 +       case VCMD_tag_migrate:
25616 +               return vc_tag_migrate(id);
25617 +
25618 +       case VCMD_net_add:
25619 +               return vc_net_add(nxi, data);
25620 +       case VCMD_net_remove:
25621 +               return vc_net_remove(nxi, data);
25622 +
25623 +       case VCMD_net_add_ipv4:
25624 +               return vc_net_add_ipv4(nxi, data);
25625 +       case VCMD_net_remove_ipv4:
25626 +               return vc_net_remove_ipv4(nxi, data);
25627 +#ifdef CONFIG_IPV6
25628 +       case VCMD_net_add_ipv6:
25629 +               return vc_net_add_ipv6(nxi, data);
25630 +       case VCMD_net_remove_ipv6:
25631 +               return vc_net_remove_ipv6(nxi, data);
25632 +#endif
25633 +/*     case VCMD_add_match_ipv4:
25634 +               return vc_add_match_ipv4(nxi, data);
25635 +       case VCMD_get_match_ipv4:
25636 +               return vc_get_match_ipv4(nxi, data);
25637 +#ifdef CONFIG_IPV6
25638 +       case VCMD_add_match_ipv6:
25639 +               return vc_add_match_ipv6(nxi, data);
25640 +       case VCMD_get_match_ipv6:
25641 +               return vc_get_match_ipv6(nxi, data);
25642 +#endif */
25643 +
25644 +#ifdef CONFIG_VSERVER_DEVICE
25645 +       case VCMD_set_mapping:
25646 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25647 +       case VCMD_unset_mapping:
25648 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25649 +#endif
25650 +#ifdef CONFIG_VSERVER_HISTORY
25651 +       case VCMD_dump_history:
25652 +               return vc_dump_history(id);
25653 +       case VCMD_read_history:
25654 +               return __COMPAT(vc_read_history, id, data, compat);
25655 +#endif
25656 +#ifdef CONFIG_VSERVER_MONITOR
25657 +       case VCMD_read_monitor:
25658 +               return __COMPAT(vc_read_monitor, id, data, compat);
25659 +#endif
25660 +       default:
25661 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25662 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25663 +       }
25664 +       return -ENOSYS;
25665 +}
25666 +
25667 +
25668 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25669 +       case VCMD_ ## vcmd: perm = _perm;               \
25670 +               args = _args; flags = _flags; break
25671 +
25672 +
25673 +#define VCA_NONE       0x00
25674 +#define VCA_VXI                0x01
25675 +#define VCA_NXI                0x02
25676 +
25677 +#define VCF_NONE       0x00
25678 +#define VCF_INFO       0x01
25679 +#define VCF_ADMIN      0x02
25680 +#define VCF_ARES       0x06    /* includes admin */
25681 +#define VCF_SETUP      0x08
25682 +
25683 +#define VCF_ZIDOK      0x10    /* zero id okay */
25684 +
25685 +
25686 +static inline
25687 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25688 +{
25689 +       long ret;
25690 +       int permit = -1, state = 0;
25691 +       int perm = -1, args = 0, flags = 0;
25692 +       struct vx_info *vxi = NULL;
25693 +       struct nx_info *nxi = NULL;
25694 +
25695 +       switch (cmd) {
25696 +       /* unpriviledged commands */
25697 +       __VCMD(get_version,      0, VCA_NONE,   0);
25698 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25699 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25700 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25701 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25702 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25703 +
25704 +       /* info commands */
25705 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25706 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
25707 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25708 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25709 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25710 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25711 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25712 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25713 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25714 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25715 +
25716 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25717 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25718 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25719 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25720 +
25721 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25722 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25723 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25724 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25725 +
25726 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25727 +
25728 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25729 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25730 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25731 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25732 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25733 +
25734 +       /* lower admin commands */
25735 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25736 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25737 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25738 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25739 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25740 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25741 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25742 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25743 +
25744 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25745 +       __VCMD(net_create,       5, VCA_NONE,   0);
25746 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25747 +
25748 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25749 +
25750 +       /* higher admin commands */
25751 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25752 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25753 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25754 +
25755 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25756 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25757 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25758 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25759 +
25760 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25761 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25762 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25763 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25764 +
25765 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25766 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25767 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25768 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25769 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25770 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25771 +#ifdef CONFIG_IPV6
25772 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25773 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25774 +#endif
25775 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25776 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25777 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25778 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25779 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25780 +
25781 +#ifdef CONFIG_VSERVER_DEVICE
25782 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25783 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25784 +#endif
25785 +       /* debug level admin commands */
25786 +#ifdef CONFIG_VSERVER_HISTORY
25787 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25788 +       __VCMD(read_history,     9, VCA_NONE,   0);
25789 +#endif
25790 +#ifdef CONFIG_VSERVER_MONITOR
25791 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25792 +#endif
25793 +
25794 +       default:
25795 +               perm = -1;
25796 +       }
25797 +
25798 +       vxdprintk(VXD_CBIT(switch, 0),
25799 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25800 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25801 +               VC_VERSION(cmd), id, data, compat,
25802 +               perm, args, flags);
25803 +
25804 +       ret = -ENOSYS;
25805 +       if (perm < 0)
25806 +               goto out;
25807 +
25808 +       state = 1;
25809 +       if (!capable(CAP_CONTEXT))
25810 +               goto out;
25811 +
25812 +       state = 2;
25813 +       /* moved here from the individual commands */
25814 +       ret = -EPERM;
25815 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25816 +               goto out;
25817 +
25818 +       state = 3;
25819 +       /* vcmd involves resource management  */
25820 +       ret = -EPERM;
25821 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25822 +               goto out;
25823 +
25824 +       state = 4;
25825 +       /* various legacy exceptions */
25826 +       switch (cmd) {
25827 +       /* will go away when spectator is a cap */
25828 +       case VCMD_ctx_migrate_v0:
25829 +       case VCMD_ctx_migrate:
25830 +               if (id == 1) {
25831 +                       current->xid = 1;
25832 +                       ret = 1;
25833 +                       goto out;
25834 +               }
25835 +               break;
25836 +
25837 +       /* will go away when spectator is a cap */
25838 +       case VCMD_net_migrate:
25839 +               if (id == 1) {
25840 +                       current->nid = 1;
25841 +                       ret = 1;
25842 +                       goto out;
25843 +               }
25844 +               break;
25845 +       }
25846 +
25847 +       /* vcmds are fine by default */
25848 +       permit = 1;
25849 +
25850 +       /* admin type vcmds require admin ... */
25851 +       if (flags & VCF_ADMIN)
25852 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25853 +
25854 +       /* ... but setup type vcmds override that */
25855 +       if (!permit && (flags & VCF_SETUP))
25856 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25857 +
25858 +       state = 5;
25859 +       ret = -EPERM;
25860 +       if (!permit)
25861 +               goto out;
25862 +
25863 +       state = 6;
25864 +       if (!id && (flags & VCF_ZIDOK))
25865 +               goto skip_id;
25866 +
25867 +       ret = -ESRCH;
25868 +       if (args & VCA_VXI) {
25869 +               vxi = lookup_vx_info(id);
25870 +               if (!vxi)
25871 +                       goto out;
25872 +
25873 +               if ((flags & VCF_ADMIN) &&
25874 +                       /* special case kill for shutdown */
25875 +                       (cmd != VCMD_ctx_kill) &&
25876 +                       /* can context be administrated? */
25877 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25878 +                       ret = -EACCES;
25879 +                       goto out_vxi;
25880 +               }
25881 +       }
25882 +       state = 7;
25883 +       if (args & VCA_NXI) {
25884 +               nxi = lookup_nx_info(id);
25885 +               if (!nxi)
25886 +                       goto out_vxi;
25887 +
25888 +               if ((flags & VCF_ADMIN) &&
25889 +                       /* can context be administrated? */
25890 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25891 +                       ret = -EACCES;
25892 +                       goto out_nxi;
25893 +               }
25894 +       }
25895 +skip_id:
25896 +       state = 8;
25897 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25898 +
25899 +out_nxi:
25900 +       if ((args & VCA_NXI) && nxi)
25901 +               put_nx_info(nxi);
25902 +out_vxi:
25903 +       if ((args & VCA_VXI) && vxi)
25904 +               put_vx_info(vxi);
25905 +out:
25906 +       vxdprintk(VXD_CBIT(switch, 1),
25907 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25908 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25909 +               VC_VERSION(cmd), ret, ret, state, permit);
25910 +       return ret;
25911 +}
25912 +
25913 +asmlinkage long
25914 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25915 +{
25916 +       return do_vserver(cmd, id, data, 0);
25917 +}
25918 +
25919 +#ifdef CONFIG_COMPAT
25920 +
25921 +asmlinkage long
25922 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25923 +{
25924 +       return do_vserver(cmd, id, data, 1);
25925 +}
25926 +
25927 +#endif /* CONFIG_COMPAT */
25928 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/sysctl.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/sysctl.c
25929 --- linux-2.6.32.24/kernel/vserver/sysctl.c     1970-01-01 01:00:00.000000000 +0100
25930 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/sysctl.c     2010-01-13 15:21:01.000000000 +0100
25931 @@ -0,0 +1,245 @@
25932 +/*
25933 + *  kernel/vserver/sysctl.c
25934 + *
25935 + *  Virtual Context Support
25936 + *
25937 + *  Copyright (C) 2004-2007  Herbert Pötzl
25938 + *
25939 + *  V0.01  basic structure
25940 + *
25941 + */
25942 +
25943 +#include <linux/module.h>
25944 +#include <linux/ctype.h>
25945 +#include <linux/sysctl.h>
25946 +#include <linux/parser.h>
25947 +#include <asm/uaccess.h>
25948 +
25949 +
25950 +enum {
25951 +       CTL_DEBUG_ERROR         = 0,
25952 +       CTL_DEBUG_SWITCH        = 1,
25953 +       CTL_DEBUG_XID,
25954 +       CTL_DEBUG_NID,
25955 +       CTL_DEBUG_TAG,
25956 +       CTL_DEBUG_NET,
25957 +       CTL_DEBUG_LIMIT,
25958 +       CTL_DEBUG_CRES,
25959 +       CTL_DEBUG_DLIM,
25960 +       CTL_DEBUG_QUOTA,
25961 +       CTL_DEBUG_CVIRT,
25962 +       CTL_DEBUG_SPACE,
25963 +       CTL_DEBUG_MISC,
25964 +};
25965 +
25966 +
25967 +unsigned int vx_debug_switch   = 0;
25968 +unsigned int vx_debug_xid      = 0;
25969 +unsigned int vx_debug_nid      = 0;
25970 +unsigned int vx_debug_tag      = 0;
25971 +unsigned int vx_debug_net      = 0;
25972 +unsigned int vx_debug_limit    = 0;
25973 +unsigned int vx_debug_cres     = 0;
25974 +unsigned int vx_debug_dlim     = 0;
25975 +unsigned int vx_debug_quota    = 0;
25976 +unsigned int vx_debug_cvirt    = 0;
25977 +unsigned int vx_debug_space    = 0;
25978 +unsigned int vx_debug_misc     = 0;
25979 +
25980 +
25981 +static struct ctl_table_header *vserver_table_header;
25982 +static ctl_table vserver_root_table[];
25983 +
25984 +
25985 +void vserver_register_sysctl(void)
25986 +{
25987 +       if (!vserver_table_header) {
25988 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25989 +       }
25990 +
25991 +}
25992 +
25993 +void vserver_unregister_sysctl(void)
25994 +{
25995 +       if (vserver_table_header) {
25996 +               unregister_sysctl_table(vserver_table_header);
25997 +               vserver_table_header = NULL;
25998 +       }
25999 +}
26000 +
26001 +
26002 +static int proc_dodebug(ctl_table *table, int write,
26003 +       void __user *buffer, size_t *lenp, loff_t *ppos)
26004 +{
26005 +       char            tmpbuf[20], *p, c;
26006 +       unsigned int    value;
26007 +       size_t          left, len;
26008 +
26009 +       if ((*ppos && !write) || !*lenp) {
26010 +               *lenp = 0;
26011 +               return 0;
26012 +       }
26013 +
26014 +       left = *lenp;
26015 +
26016 +       if (write) {
26017 +               if (!access_ok(VERIFY_READ, buffer, left))
26018 +                       return -EFAULT;
26019 +               p = (char *)buffer;
26020 +               while (left && __get_user(c, p) >= 0 && isspace(c))
26021 +                       left--, p++;
26022 +               if (!left)
26023 +                       goto done;
26024 +
26025 +               if (left > sizeof(tmpbuf) - 1)
26026 +                       return -EINVAL;
26027 +               if (copy_from_user(tmpbuf, p, left))
26028 +                       return -EFAULT;
26029 +               tmpbuf[left] = '\0';
26030 +
26031 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
26032 +                       value = 10 * value + (*p - '0');
26033 +               if (*p && !isspace(*p))
26034 +                       return -EINVAL;
26035 +               while (left && isspace(*p))
26036 +                       left--, p++;
26037 +               *(unsigned int *)table->data = value;
26038 +       } else {
26039 +               if (!access_ok(VERIFY_WRITE, buffer, left))
26040 +                       return -EFAULT;
26041 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
26042 +               if (len > left)
26043 +                       len = left;
26044 +               if (__copy_to_user(buffer, tmpbuf, len))
26045 +                       return -EFAULT;
26046 +               if ((left -= len) > 0) {
26047 +                       if (put_user('\n', (char *)buffer + len))
26048 +                               return -EFAULT;
26049 +                       left--;
26050 +               }
26051 +       }
26052 +
26053 +done:
26054 +       *lenp -= left;
26055 +       *ppos += *lenp;
26056 +       return 0;
26057 +}
26058 +
26059 +static int zero;
26060 +
26061 +#define        CTL_ENTRY(ctl, name)                            \
26062 +       {                                               \
26063 +               .ctl_name       = ctl,                  \
26064 +               .procname       = #name,                \
26065 +               .data           = &vx_ ## name,         \
26066 +               .maxlen         = sizeof(int),          \
26067 +               .mode           = 0644,                 \
26068 +               .proc_handler   = &proc_dodebug,        \
26069 +               .strategy       = &sysctl_intvec,       \
26070 +               .extra1         = &zero,                \
26071 +               .extra2         = &zero,                \
26072 +       }
26073 +
26074 +static ctl_table vserver_debug_table[] = {
26075 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
26076 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
26077 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
26078 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
26079 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
26080 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
26081 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
26082 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
26083 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
26084 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
26085 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
26086 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
26087 +       { .ctl_name = 0 }
26088 +};
26089 +
26090 +static ctl_table vserver_root_table[] = {
26091 +       {
26092 +               .ctl_name       = CTL_VSERVER,
26093 +               .procname       = "vserver",
26094 +               .mode           = 0555,
26095 +               .child          = vserver_debug_table
26096 +       },
26097 +       { .ctl_name = 0 }
26098 +};
26099 +
26100 +
26101 +static match_table_t tokens = {
26102 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
26103 +       { CTL_DEBUG_XID,        "xid=%x"        },
26104 +       { CTL_DEBUG_NID,        "nid=%x"        },
26105 +       { CTL_DEBUG_TAG,        "tag=%x"        },
26106 +       { CTL_DEBUG_NET,        "net=%x"        },
26107 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
26108 +       { CTL_DEBUG_CRES,       "cres=%x"       },
26109 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
26110 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
26111 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
26112 +       { CTL_DEBUG_SPACE,      "space=%x"      },
26113 +       { CTL_DEBUG_MISC,       "misc=%x"       },
26114 +       { CTL_DEBUG_ERROR,      NULL            }
26115 +};
26116 +
26117 +#define        HANDLE_CASE(id, name, val)                              \
26118 +       case CTL_DEBUG_ ## id:                                  \
26119 +               vx_debug_ ## name = val;                        \
26120 +               printk("vs_debug_" #name "=0x%x\n", val);       \
26121 +               break
26122 +
26123 +
26124 +static int __init vs_debug_setup(char *str)
26125 +{
26126 +       char *p;
26127 +       int token;
26128 +
26129 +       printk("vs_debug_setup(%s)\n", str);
26130 +       while ((p = strsep(&str, ",")) != NULL) {
26131 +               substring_t args[MAX_OPT_ARGS];
26132 +               unsigned int value;
26133 +
26134 +               if (!*p)
26135 +                       continue;
26136 +
26137 +               token = match_token(p, tokens, args);
26138 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
26139 +
26140 +               switch (token) {
26141 +               HANDLE_CASE(SWITCH, switch, value);
26142 +               HANDLE_CASE(XID,    xid,    value);
26143 +               HANDLE_CASE(NID,    nid,    value);
26144 +               HANDLE_CASE(TAG,    tag,    value);
26145 +               HANDLE_CASE(NET,    net,    value);
26146 +               HANDLE_CASE(LIMIT,  limit,  value);
26147 +               HANDLE_CASE(CRES,   cres,   value);
26148 +               HANDLE_CASE(DLIM,   dlim,   value);
26149 +               HANDLE_CASE(QUOTA,  quota,  value);
26150 +               HANDLE_CASE(CVIRT,  cvirt,  value);
26151 +               HANDLE_CASE(SPACE,  space,  value);
26152 +               HANDLE_CASE(MISC,   misc,   value);
26153 +               default:
26154 +                       return -EINVAL;
26155 +                       break;
26156 +               }
26157 +       }
26158 +       return 1;
26159 +}
26160 +
26161 +__setup("vsdebug=", vs_debug_setup);
26162 +
26163 +
26164 +
26165 +EXPORT_SYMBOL_GPL(vx_debug_switch);
26166 +EXPORT_SYMBOL_GPL(vx_debug_xid);
26167 +EXPORT_SYMBOL_GPL(vx_debug_nid);
26168 +EXPORT_SYMBOL_GPL(vx_debug_net);
26169 +EXPORT_SYMBOL_GPL(vx_debug_limit);
26170 +EXPORT_SYMBOL_GPL(vx_debug_cres);
26171 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
26172 +EXPORT_SYMBOL_GPL(vx_debug_quota);
26173 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
26174 +EXPORT_SYMBOL_GPL(vx_debug_space);
26175 +EXPORT_SYMBOL_GPL(vx_debug_misc);
26176 +
26177 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/tag.c linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/tag.c
26178 --- linux-2.6.32.24/kernel/vserver/tag.c        1970-01-01 01:00:00.000000000 +0100
26179 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/tag.c        2009-12-03 20:04:56.000000000 +0100
26180 @@ -0,0 +1,63 @@
26181 +/*
26182 + *  linux/kernel/vserver/tag.c
26183 + *
26184 + *  Virtual Server: Shallow Tag Space
26185 + *
26186 + *  Copyright (C) 2007  Herbert Pötzl
26187 + *
26188 + *  V0.01  basic implementation
26189 + *
26190 + */
26191 +
26192 +#include <linux/sched.h>
26193 +#include <linux/vserver/debug.h>
26194 +#include <linux/vs_pid.h>
26195 +#include <linux/vs_tag.h>
26196 +
26197 +#include <linux/vserver/tag_cmd.h>
26198 +
26199 +
26200 +int dx_migrate_task(struct task_struct *p, tag_t tag)
26201 +{
26202 +       if (!p)
26203 +               BUG();
26204 +
26205 +       vxdprintk(VXD_CBIT(tag, 5),
26206 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
26207 +
26208 +       task_lock(p);
26209 +       p->tag = tag;
26210 +       task_unlock(p);
26211 +
26212 +       vxdprintk(VXD_CBIT(tag, 5),
26213 +               "moved task %p into [#%d]", p, tag);
26214 +       return 0;
26215 +}
26216 +
26217 +/* vserver syscall commands below here */
26218 +
26219 +/* taks xid and vx_info functions */
26220 +
26221 +
26222 +int vc_task_tag(uint32_t id)
26223 +{
26224 +       tag_t tag;
26225 +
26226 +       if (id) {
26227 +               struct task_struct *tsk;
26228 +               read_lock(&tasklist_lock);
26229 +               tsk = find_task_by_real_pid(id);
26230 +               tag = (tsk) ? tsk->tag : -ESRCH;
26231 +               read_unlock(&tasklist_lock);
26232 +       } else
26233 +               tag = dx_current_tag();
26234 +       return tag;
26235 +}
26236 +
26237 +
26238 +int vc_tag_migrate(uint32_t tag)
26239 +{
26240 +       return dx_migrate_task(current, tag & 0xFFFF);
26241 +}
26242 +
26243 +
26244 diff -NurpP --minimal linux-2.6.32.24/kernel/vserver/vci_config.h linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/vci_config.h
26245 --- linux-2.6.32.24/kernel/vserver/vci_config.h 1970-01-01 01:00:00.000000000 +0100
26246 +++ linux-2.6.32.24-vs2.3.0.36.29.6/kernel/vserver/vci_config.h 2009-12-03 20:04:56.000000000 +0100
26247 @@ -0,0 +1,81 @@
26248 +
26249 +/*  interface version */
26250 +
26251 +#define VCI_VERSION            0x00020305
26252 +
26253 +
26254 +enum {
26255 +       VCI_KCBIT_NO_DYNAMIC = 0,
26256 +
26257 +       VCI_KCBIT_PROC_SECURE = 4,
26258 +       VCI_KCBIT_HARDCPU = 5,
26259 +       VCI_KCBIT_IDLELIMIT = 6,
26260 +       VCI_KCBIT_IDLETIME = 7,
26261 +
26262 +       VCI_KCBIT_COWBL = 8,
26263 +       VCI_KCBIT_FULLCOWBL = 9,
26264 +       VCI_KCBIT_SPACES = 10,
26265 +       VCI_KCBIT_NETV2 = 11,
26266 +
26267 +       VCI_KCBIT_DEBUG = 16,
26268 +       VCI_KCBIT_HISTORY = 20,
26269 +       VCI_KCBIT_TAGGED = 24,
26270 +       VCI_KCBIT_PPTAG = 28,
26271 +
26272 +       VCI_KCBIT_MORE = 31,
26273 +};
26274 +
26275 +
26276 +static inline uint32_t vci_kernel_config(void)
26277 +{
26278 +       return
26279 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
26280 +
26281 +       /* configured features */
26282 +#ifdef CONFIG_VSERVER_PROC_SECURE
26283 +       (1 << VCI_KCBIT_PROC_SECURE) |
26284 +#endif
26285 +#ifdef CONFIG_VSERVER_HARDCPU
26286 +       (1 << VCI_KCBIT_HARDCPU) |
26287 +#endif
26288 +#ifdef CONFIG_VSERVER_IDLELIMIT
26289 +       (1 << VCI_KCBIT_IDLELIMIT) |
26290 +#endif
26291 +#ifdef CONFIG_VSERVER_IDLETIME
26292 +       (1 << VCI_KCBIT_IDLETIME) |
26293 +#endif
26294 +#ifdef CONFIG_VSERVER_COWBL
26295 +       (1 << VCI_KCBIT_COWBL) |
26296 +       (1 << VCI_KCBIT_FULLCOWBL) |
26297 +#endif
26298 +       (1 << VCI_KCBIT_SPACES) |
26299 +       (1 << VCI_KCBIT_NETV2) |
26300 +
26301 +       /* debug options */
26302 +#ifdef CONFIG_VSERVER_DEBUG
26303 +       (1 << VCI_KCBIT_DEBUG) |
26304 +#endif
26305 +#ifdef CONFIG_VSERVER_HISTORY
26306 +       (1 << VCI_KCBIT_HISTORY) |
26307 +#endif
26308 +
26309 +       /* inode context tagging */
26310 +#if    defined(CONFIG_TAGGING_NONE)
26311 +       (0 << VCI_KCBIT_TAGGED) |
26312 +#elif  defined(CONFIG_TAGGING_UID16)
26313 +       (1 << VCI_KCBIT_TAGGED) |
26314 +#elif  defined(CONFIG_TAGGING_GID16)
26315 +       (2 << VCI_KCBIT_TAGGED) |
26316 +#elif  defined(CONFIG_TAGGING_ID24)
26317 +       (3 << VCI_KCBIT_TAGGED) |
26318 +#elif  defined(CONFIG_TAGGING_INTERN)
26319 +       (4 << VCI_KCBIT_TAGGED) |
26320 +#elif  defined(CONFIG_TAGGING_RUNTIME)
26321 +       (5 << VCI_KCBIT_TAGGED) |
26322 +#else
26323 +       (7 << VCI_KCBIT_TAGGED) |
26324 +#endif
26325 +       (1 << VCI_KCBIT_PPTAG) |
26326 +       0;
26327 +}
26328 +
26329 diff -NurpP --minimal linux-2.6.32.24/mm/allocpercpu.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/allocpercpu.c
26330 --- linux-2.6.32.24/mm/allocpercpu.c    2009-12-03 20:02:58.000000000 +0100
26331 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/allocpercpu.c    2009-12-03 20:04:56.000000000 +0100
26332 @@ -160,12 +160,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
26333  
26334  void __init setup_per_cpu_areas(void)
26335  {
26336 -       unsigned long size, i;
26337 +       unsigned long size, vspc, i;
26338         char *ptr;
26339         unsigned long nr_possible_cpus = num_possible_cpus();
26340  
26341 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
26342 +
26343         /* Copy section for each CPU (we discard the original) */
26344 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
26345 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
26346         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
26347  
26348         for_each_possible_cpu(i) {
26349 diff -NurpP --minimal linux-2.6.32.24/mm/filemap_xip.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/filemap_xip.c
26350 --- linux-2.6.32.24/mm/filemap_xip.c    2009-12-03 20:02:58.000000000 +0100
26351 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/filemap_xip.c    2009-12-03 20:04:56.000000000 +0100
26352 @@ -17,6 +17,7 @@
26353  #include <linux/sched.h>
26354  #include <linux/seqlock.h>
26355  #include <linux/mutex.h>
26356 +#include <linux/vs_memory.h>
26357  #include <asm/tlbflush.h>
26358  #include <asm/io.h>
26359  
26360 diff -NurpP --minimal linux-2.6.32.24/mm/fremap.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/fremap.c
26361 --- linux-2.6.32.24/mm/fremap.c 2009-03-24 14:22:45.000000000 +0100
26362 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/fremap.c 2009-12-03 20:04:56.000000000 +0100
26363 @@ -16,6 +16,7 @@
26364  #include <linux/module.h>
26365  #include <linux/syscalls.h>
26366  #include <linux/mmu_notifier.h>
26367 +#include <linux/vs_memory.h>
26368  
26369  #include <asm/mmu_context.h>
26370  #include <asm/cacheflush.h>
26371 diff -NurpP --minimal linux-2.6.32.24/mm/hugetlb.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/hugetlb.c
26372 --- linux-2.6.32.24/mm/hugetlb.c        2010-10-04 08:56:18.000000000 +0200
26373 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/hugetlb.c        2010-07-08 02:22:31.000000000 +0200
26374 @@ -24,6 +24,7 @@
26375  #include <asm/io.h>
26376  
26377  #include <linux/hugetlb.h>
26378 +#include <linux/vs_memory.h>
26379  #include "internal.h"
26380  
26381  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
26382 diff -NurpP --minimal linux-2.6.32.24/mm/memcontrol.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/memcontrol.c
26383 --- linux-2.6.32.24/mm/memcontrol.c     2010-10-04 08:56:18.000000000 +0200
26384 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/memcontrol.c     2010-05-21 13:20:19.000000000 +0200
26385 @@ -549,6 +549,31 @@ struct mem_cgroup *mem_cgroup_from_task(
26386                                 struct mem_cgroup, css);
26387  }
26388  
26389 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
26390 +{
26391 +       return res_counter_read_u64(&mem->res, member);
26392 +}
26393 +
26394 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
26395 +{
26396 +       return res_counter_read_u64(&mem->memsw, member);
26397 +}
26398 +
26399 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
26400 +{
26401 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_CACHE);
26402 +}
26403 +
26404 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
26405 +{
26406 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_RSS);
26407 +}
26408 +
26409 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
26410 +{
26411 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_MAPPED_FILE);
26412 +}
26413 +
26414  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
26415  {
26416         struct mem_cgroup *mem = NULL;
26417 diff -NurpP --minimal linux-2.6.32.24/mm/memory.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/memory.c
26418 --- linux-2.6.32.24/mm/memory.c 2010-10-04 08:56:18.000000000 +0200
26419 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/memory.c 2010-10-04 10:04:57.000000000 +0200
26420 @@ -56,6 +56,7 @@
26421  #include <linux/kallsyms.h>
26422  #include <linux/swapops.h>
26423  #include <linux/elf.h>
26424 +// #include <linux/vs_memory.h>
26425  
26426  #include <asm/io.h>
26427  #include <asm/pgalloc.h>
26428 @@ -647,6 +648,9 @@ static int copy_pte_range(struct mm_stru
26429         int progress = 0;
26430         int rss[2];
26431  
26432 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
26433 +               return -ENOMEM;
26434 +
26435  again:
26436         rss[1] = rss[0] = 0;
26437         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
26438 @@ -2678,10 +2682,13 @@ static int do_anonymous_page(struct mm_s
26439  
26440         pte_unmap(page_table);
26441  
26442 +       if (!vx_rss_avail(mm, 1))
26443 +               goto oom;
26444 +
26445         /* Check if we need to add a guard page to the stack */
26446         if (check_stack_guard_page(vma, address) < 0)
26447                 return VM_FAULT_SIGBUS;
26448 -
26449 +
26450         /* Use the zero-page for reads */
26451         if (!(flags & FAULT_FLAG_WRITE)) {
26452                 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
26453 @@ -2984,6 +2991,7 @@ static inline int handle_pte_fault(struc
26454  {
26455         pte_t entry;
26456         spinlock_t *ptl;
26457 +       int ret = 0, type = VXPT_UNKNOWN;
26458  
26459         entry = *pte;
26460         if (!pte_present(entry)) {
26461 @@ -3008,9 +3016,12 @@ static inline int handle_pte_fault(struc
26462         if (unlikely(!pte_same(*pte, entry)))
26463                 goto unlock;
26464         if (flags & FAULT_FLAG_WRITE) {
26465 -               if (!pte_write(entry))
26466 -                       return do_wp_page(mm, vma, address,
26467 +               if (!pte_write(entry)) {
26468 +                       ret = do_wp_page(mm, vma, address,
26469                                         pte, pmd, ptl, entry);
26470 +                       type = VXPT_WRITE;
26471 +                       goto out;
26472 +               }
26473                 entry = pte_mkdirty(entry);
26474         }
26475         entry = pte_mkyoung(entry);
26476 @@ -3028,7 +3039,10 @@ static inline int handle_pte_fault(struc
26477         }
26478  unlock:
26479         pte_unmap_unlock(pte, ptl);
26480 -       return 0;
26481 +       ret = 0;
26482 +out:
26483 +       vx_page_fault(mm, vma, type, ret);
26484 +       return ret;
26485  }
26486  
26487  /*
26488 diff -NurpP --minimal linux-2.6.32.24/mm/mlock.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/mlock.c
26489 --- linux-2.6.32.24/mm/mlock.c  2010-10-04 08:56:18.000000000 +0200
26490 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/mlock.c  2010-09-05 21:24:17.000000000 +0200
26491 @@ -18,6 +18,7 @@
26492  #include <linux/rmap.h>
26493  #include <linux/mmzone.h>
26494  #include <linux/hugetlb.h>
26495 +#include <linux/vs_memory.h>
26496  
26497  #include "internal.h"
26498  
26499 @@ -420,7 +421,7 @@ success:
26500         nr_pages = (end - start) >> PAGE_SHIFT;
26501         if (!lock)
26502                 nr_pages = -nr_pages;
26503 -       mm->locked_vm += nr_pages;
26504 +       vx_vmlocked_add(mm, nr_pages);
26505  
26506         /*
26507          * vm_flags is protected by the mmap_sem held in write mode.
26508 @@ -493,7 +494,7 @@ static int do_mlock(unsigned long start,
26509  
26510  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
26511  {
26512 -       unsigned long locked;
26513 +       unsigned long locked, grow;
26514         unsigned long lock_limit;
26515         int error = -ENOMEM;
26516  
26517 @@ -506,8 +507,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26518         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
26519         start &= PAGE_MASK;
26520  
26521 -       locked = len >> PAGE_SHIFT;
26522 -       locked += current->mm->locked_vm;
26523 +       grow = len >> PAGE_SHIFT;
26524 +       if (!vx_vmlocked_avail(current->mm, grow))
26525 +               goto out;
26526 +       locked = current->mm->locked_vm + grow;
26527  
26528         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26529         lock_limit >>= PAGE_SHIFT;
26530 @@ -515,6 +518,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26531         /* check against resource limits */
26532         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26533                 error = do_mlock(start, len, 1);
26534 +out:
26535         up_write(&current->mm->mmap_sem);
26536         return error;
26537  }
26538 @@ -576,6 +580,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
26539         lock_limit >>= PAGE_SHIFT;
26540  
26541         ret = -ENOMEM;
26542 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26543 +               goto out;
26544         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26545             capable(CAP_IPC_LOCK))
26546                 ret = do_mlockall(flags);
26547 @@ -650,8 +656,10 @@ int account_locked_memory(struct mm_stru
26548         if (lim < vm)
26549                 goto out;
26550  
26551 -       mm->total_vm  += pgsz;
26552 -       mm->locked_vm += pgsz;
26553 +       // mm->total_vm  += pgsz;
26554 +       vx_vmpages_add(mm, pgsz);
26555 +       // mm->locked_vm += pgsz;
26556 +       vx_vmlocked_add(mm, pgsz);
26557  
26558         error = 0;
26559   out:
26560 @@ -665,8 +673,10 @@ void refund_locked_memory(struct mm_stru
26561  
26562         down_write(&mm->mmap_sem);
26563  
26564 -       mm->total_vm  -= pgsz;
26565 -       mm->locked_vm -= pgsz;
26566 +       // mm->total_vm  -= pgsz;
26567 +       vx_vmpages_sub(mm, pgsz);
26568 +       // mm->locked_vm -= pgsz;
26569 +       vx_vmlocked_sub(mm, pgsz);
26570  
26571         up_write(&mm->mmap_sem);
26572  }
26573 diff -NurpP --minimal linux-2.6.32.24/mm/mmap.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/mmap.c
26574 --- linux-2.6.32.24/mm/mmap.c   2010-10-04 08:56:18.000000000 +0200
26575 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/mmap.c   2010-10-04 10:04:57.000000000 +0200
26576 @@ -1224,7 +1224,8 @@ munmap_back:
26577  out:
26578         perf_event_mmap(vma);
26579  
26580 -       mm->total_vm += len >> PAGE_SHIFT;
26581 +       // mm->total_vm += len >> PAGE_SHIFT;
26582 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26583         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26584         if (vm_flags & VM_LOCKED) {
26585                 /*
26586 @@ -1233,7 +1234,8 @@ out:
26587                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
26588                 if (nr_pages < 0)
26589                         return nr_pages;        /* vma gone! */
26590 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26591 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26592 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
26593         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26594                 make_pages_present(addr, addr + len);
26595         return addr;
26596 @@ -1588,9 +1590,9 @@ static int acct_stack_growth(struct vm_a
26597                 return -ENOMEM;
26598  
26599         /* Ok, everything looks good - let it rip */
26600 -       mm->total_vm += grow;
26601 +       vx_vmpages_add(mm, grow);
26602         if (vma->vm_flags & VM_LOCKED)
26603 -               mm->locked_vm += grow;
26604 +               vx_vmlocked_add(mm, grow);
26605         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26606         return 0;
26607  }
26608 @@ -1762,7 +1764,8 @@ static void remove_vma_list(struct mm_st
26609         do {
26610                 long nrpages = vma_pages(vma);
26611  
26612 -               mm->total_vm -= nrpages;
26613 +               // mm->total_vm -= nrpages;
26614 +               vx_vmpages_sub(mm, nrpages);
26615                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26616                 vma = remove_vma(vma);
26617         } while (vma);
26618 @@ -1937,7 +1940,8 @@ int do_munmap(struct mm_struct *mm, unsi
26619                 struct vm_area_struct *tmp = vma;
26620                 while (tmp && tmp->vm_start < end) {
26621                         if (tmp->vm_flags & VM_LOCKED) {
26622 -                               mm->locked_vm -= vma_pages(tmp);
26623 +                               // mm->locked_vm -= vma_pages(tmp);
26624 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
26625                                 munlock_vma_pages_all(tmp);
26626                         }
26627                         tmp = tmp->vm_next;
26628 @@ -2020,6 +2024,8 @@ unsigned long do_brk(unsigned long addr,
26629                 lock_limit >>= PAGE_SHIFT;
26630                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26631                         return -EAGAIN;
26632 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26633 +                       return -ENOMEM;
26634         }
26635  
26636         /*
26637 @@ -2046,7 +2052,8 @@ unsigned long do_brk(unsigned long addr,
26638         if (mm->map_count > sysctl_max_map_count)
26639                 return -ENOMEM;
26640  
26641 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26642 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26643 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26644                 return -ENOMEM;
26645  
26646         /* Can we just expand an old private anonymous mapping? */
26647 @@ -2072,10 +2079,13 @@ unsigned long do_brk(unsigned long addr,
26648         vma->vm_page_prot = vm_get_page_prot(flags);
26649         vma_link(mm, vma, prev, rb_link, rb_parent);
26650  out:
26651 -       mm->total_vm += len >> PAGE_SHIFT;
26652 +       // mm->total_vm += len >> PAGE_SHIFT;
26653 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26654 +
26655         if (flags & VM_LOCKED) {
26656                 if (!mlock_vma_pages_range(vma, addr, addr + len))
26657 -                       mm->locked_vm += (len >> PAGE_SHIFT);
26658 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
26659 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26660         }
26661         return addr;
26662  }
26663 @@ -2119,6 +2129,11 @@ void exit_mmap(struct mm_struct *mm)
26664         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26665         tlb_finish_mmu(tlb, 0, end);
26666  
26667 +       set_mm_counter(mm, file_rss, 0);
26668 +       set_mm_counter(mm, anon_rss, 0);
26669 +       vx_vmpages_sub(mm, mm->total_vm);
26670 +       vx_vmlocked_sub(mm, mm->locked_vm);
26671 +
26672         /*
26673          * Walk the list again, actually closing and freeing it,
26674          * with preemption enabled, without holding any MM locks.
26675 @@ -2158,7 +2173,8 @@ int insert_vm_struct(struct mm_struct * 
26676         if (__vma && __vma->vm_start < vma->vm_end)
26677                 return -ENOMEM;
26678         if ((vma->vm_flags & VM_ACCOUNT) &&
26679 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26680 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26681 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26682                 return -ENOMEM;
26683         vma_link(mm, vma, prev, rb_link, rb_parent);
26684         return 0;
26685 @@ -2234,6 +2250,8 @@ int may_expand_vm(struct mm_struct *mm, 
26686  
26687         if (cur + npages > lim)
26688                 return 0;
26689 +       if (!vx_vmpages_avail(mm, npages))
26690 +               return 0;
26691         return 1;
26692  }
26693  
26694 @@ -2311,7 +2329,7 @@ int install_special_mapping(struct mm_st
26695                 return -ENOMEM;
26696         }
26697  
26698 -       mm->total_vm += len >> PAGE_SHIFT;
26699 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26700  
26701         perf_event_mmap(vma);
26702  
26703 diff -NurpP --minimal linux-2.6.32.24/mm/mremap.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/mremap.c
26704 --- linux-2.6.32.24/mm/mremap.c 2010-10-04 08:56:18.000000000 +0200
26705 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/mremap.c 2010-01-20 04:28:22.000000000 +0100
26706 @@ -20,6 +20,7 @@
26707  #include <linux/security.h>
26708  #include <linux/syscalls.h>
26709  #include <linux/mmu_notifier.h>
26710 +#include <linux/vs_memory.h>
26711  
26712  #include <asm/uaccess.h>
26713  #include <asm/cacheflush.h>
26714 @@ -234,7 +235,7 @@ static unsigned long move_vma(struct vm_
26715          * If this were a serious issue, we'd add a flag to do_munmap().
26716          */
26717         hiwater_vm = mm->hiwater_vm;
26718 -       mm->total_vm += new_len >> PAGE_SHIFT;
26719 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26720         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26721  
26722         if (do_munmap(mm, old_addr, old_len) < 0) {
26723 @@ -252,7 +253,7 @@ static unsigned long move_vma(struct vm_
26724         }
26725  
26726         if (vm_flags & VM_LOCKED) {
26727 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26728 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26729                 if (new_len > old_len)
26730                         mlock_vma_pages_range(new_vma, new_addr + old_len,
26731                                                        new_addr + new_len);
26732 @@ -463,10 +464,12 @@ unsigned long do_mremap(unsigned long ad
26733                         vma_adjust(vma, vma->vm_start,
26734                                 addr + new_len, vma->vm_pgoff, NULL);
26735  
26736 -                       mm->total_vm += pages;
26737 +                       // mm->total_vm += pages;
26738 +                       vx_vmpages_add(mm, pages);
26739                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26740                         if (vma->vm_flags & VM_LOCKED) {
26741 -                               mm->locked_vm += pages;
26742 +                               // mm->locked_vm += pages;
26743 +                               vx_vmlocked_add(mm, pages);
26744                                 mlock_vma_pages_range(vma, addr + old_len,
26745                                                    addr + new_len);
26746                         }
26747 diff -NurpP --minimal linux-2.6.32.24/mm/nommu.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/nommu.c
26748 --- linux-2.6.32.24/mm/nommu.c  2010-10-04 08:56:18.000000000 +0200
26749 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/nommu.c  2010-09-05 21:24:17.000000000 +0200
26750 @@ -1349,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file 
26751         /* okay... we have a mapping; now we have to register it */
26752         result = vma->vm_start;
26753  
26754 -       current->mm->total_vm += len >> PAGE_SHIFT;
26755 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26756  
26757  share:
26758         add_vma_to_mm(current->mm, vma);
26759 @@ -1609,7 +1609,7 @@ void exit_mmap(struct mm_struct *mm)
26760  
26761         kenter("");
26762  
26763 -       mm->total_vm = 0;
26764 +       vx_vmpages_sub(mm, mm->total_vm);
26765  
26766         while ((vma = mm->mmap)) {
26767                 mm->mmap = vma->vm_next;
26768 diff -NurpP --minimal linux-2.6.32.24/mm/oom_kill.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/oom_kill.c
26769 --- linux-2.6.32.24/mm/oom_kill.c       2010-10-04 08:56:18.000000000 +0200
26770 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/oom_kill.c       2010-03-18 16:53:06.000000000 +0100
26771 @@ -27,6 +27,9 @@
26772  #include <linux/notifier.h>
26773  #include <linux/memcontrol.h>
26774  #include <linux/security.h>
26775 +#include <linux/reboot.h>
26776 +#include <linux/vs_memory.h>
26777 +#include <linux/vs_context.h>
26778  
26779  int sysctl_panic_on_oom;
26780  int sysctl_oom_kill_allocating_task;
26781 @@ -186,9 +189,21 @@ unsigned long badness(struct task_struct
26782                         points >>= -(oom_adj);
26783         }
26784  
26785 +       /*
26786 +        * add points for context badness and
26787 +        * reduce badness for processes belonging to
26788 +        * a different context
26789 +        */
26790 +
26791 +       points += vx_badness(p, mm);
26792 +
26793 +       if ((vx_current_xid() > 1) &&
26794 +               vx_current_xid() != vx_task_xid(p))
26795 +               points /= 16;
26796 +
26797  #ifdef DEBUG
26798 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26799 -       p->pid, p->comm, points);
26800 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26801 +               task_pid_nr(p), p->xid, p->comm, points);
26802  #endif
26803         return points;
26804  }
26805 @@ -230,6 +245,7 @@ static struct task_struct *select_bad_pr
26806         struct task_struct *p;
26807         struct task_struct *chosen = NULL;
26808         struct timespec uptime;
26809 +       unsigned xid = vx_current_xid();
26810         *ppoints = 0;
26811  
26812         do_posix_clock_monotonic_gettime(&uptime);
26813 @@ -242,11 +258,14 @@ static struct task_struct *select_bad_pr
26814                  */
26815                 if (!p->mm)
26816                         continue;
26817 -               /* skip the init task */
26818 -               if (is_global_init(p))
26819 +               /* skip the init task, global and per guest */
26820 +               if (task_is_init(p))
26821                         continue;
26822                 if (mem && !task_in_mem_cgroup(p, mem))
26823                         continue;
26824 +               /* skip other guest and host processes if oom in guest */
26825 +               if (xid && vx_task_xid(p) != xid)
26826 +                       continue;
26827  
26828                 /*
26829                  * This task already has access to memory reserves and is
26830 @@ -357,8 +376,8 @@ static void __oom_kill_task(struct task_
26831         }
26832  
26833         if (verbose)
26834 -               printk(KERN_ERR "Killed process %d (%s)\n",
26835 -                               task_pid_nr(p), p->comm);
26836 +               printk(KERN_ERR "Killed process %s(%d:#%u)\n",
26837 +                       p->comm, task_pid_nr(p), p->xid);
26838  
26839         /*
26840          * We give our sacrificial lamb high priority and access to
26841 @@ -419,8 +438,8 @@ static int oom_kill_process(struct task_
26842                 return 0;
26843         }
26844  
26845 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26846 -                                       message, task_pid_nr(p), p->comm, points);
26847 +       printk(KERN_ERR "%s: kill process %s(%d:#%u) score %li or a child\n",
26848 +               message, p->comm, task_pid_nr(p), p->xid, points);
26849  
26850         /* Try to kill a child first */
26851         list_for_each_entry(c, &p->children, sibling) {
26852 @@ -521,6 +540,8 @@ void clear_zonelist_oom(struct zonelist 
26853         spin_unlock(&zone_scan_lock);
26854  }
26855  
26856 +long vs_oom_action(unsigned int);
26857 +
26858  /*
26859   * Must be called with tasklist_lock held for read.
26860   */
26861 @@ -546,7 +567,11 @@ retry:
26862         /* Found nothing?!?! Either we hang forever, or we panic. */
26863         if (!p) {
26864                 read_unlock(&tasklist_lock);
26865 -               panic("Out of memory and no killable processes...\n");
26866 +               /* avoid panic for guest OOM */
26867 +               if (current->xid)
26868 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
26869 +               else
26870 +                       panic("Out of memory and no killable processes...\n");
26871         }
26872  
26873         if (oom_kill_process(p, gfp_mask, order, points, NULL,
26874 diff -NurpP --minimal linux-2.6.32.24/mm/page_alloc.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/page_alloc.c
26875 --- linux-2.6.32.24/mm/page_alloc.c     2010-10-04 08:56:18.000000000 +0200
26876 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/page_alloc.c     2010-10-04 10:04:57.000000000 +0200
26877 @@ -48,6 +48,8 @@
26878  #include <linux/page_cgroup.h>
26879  #include <linux/debugobjects.h>
26880  #include <linux/kmemleak.h>
26881 +#include <linux/vs_base.h>
26882 +#include <linux/vs_limit.h>
26883  #include <trace/events/kmem.h>
26884  
26885  #include <asm/tlbflush.h>
26886 @@ -2144,6 +2146,9 @@ void si_meminfo(struct sysinfo *val)
26887         val->totalhigh = totalhigh_pages;
26888         val->freehigh = nr_free_highpages();
26889         val->mem_unit = PAGE_SIZE;
26890 +
26891 +       if (vx_flags(VXF_VIRT_MEM, 0))
26892 +               vx_vsi_meminfo(val);
26893  }
26894  
26895  EXPORT_SYMBOL(si_meminfo);
26896 @@ -2164,6 +2169,9 @@ void si_meminfo_node(struct sysinfo *val
26897         val->freehigh = 0;
26898  #endif
26899         val->mem_unit = PAGE_SIZE;
26900 +
26901 +       if (vx_flags(VXF_VIRT_MEM, 0))
26902 +               vx_vsi_meminfo(val);
26903  }
26904  #endif
26905  
26906 diff -NurpP --minimal linux-2.6.32.24/mm/rmap.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/rmap.c
26907 --- linux-2.6.32.24/mm/rmap.c   2009-12-03 20:02:58.000000000 +0100
26908 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/rmap.c   2009-12-03 20:04:56.000000000 +0100
26909 @@ -55,6 +55,7 @@
26910  #include <linux/memcontrol.h>
26911  #include <linux/mmu_notifier.h>
26912  #include <linux/migrate.h>
26913 +#include <linux/vs_memory.h>
26914  
26915  #include <asm/tlbflush.h>
26916  
26917 diff -NurpP --minimal linux-2.6.32.24/mm/shmem.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/shmem.c
26918 --- linux-2.6.32.24/mm/shmem.c  2009-12-03 20:02:58.000000000 +0100
26919 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/shmem.c  2009-12-03 20:04:56.000000000 +0100
26920 @@ -1781,7 +1781,7 @@ static int shmem_statfs(struct dentry *d
26921  {
26922         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26923  
26924 -       buf->f_type = TMPFS_MAGIC;
26925 +       buf->f_type = TMPFS_SUPER_MAGIC;
26926         buf->f_bsize = PAGE_CACHE_SIZE;
26927         buf->f_namelen = NAME_MAX;
26928         spin_lock(&sbinfo->stat_lock);
26929 @@ -2346,7 +2346,7 @@ int shmem_fill_super(struct super_block 
26930         sb->s_maxbytes = SHMEM_MAX_BYTES;
26931         sb->s_blocksize = PAGE_CACHE_SIZE;
26932         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26933 -       sb->s_magic = TMPFS_MAGIC;
26934 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26935         sb->s_op = &shmem_ops;
26936         sb->s_time_gran = 1;
26937  #ifdef CONFIG_TMPFS_POSIX_ACL
26938 diff -NurpP --minimal linux-2.6.32.24/mm/slab.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/slab.c
26939 --- linux-2.6.32.24/mm/slab.c   2010-10-04 08:56:18.000000000 +0200
26940 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/slab.c   2010-09-05 21:24:17.000000000 +0200
26941 @@ -431,6 +431,8 @@ static void kmem_list3_init(struct kmem_
26942  #define STATS_INC_FREEMISS(x)  do { } while (0)
26943  #endif
26944  
26945 +#include "slab_vs.h"
26946 +
26947  #if DEBUG
26948  
26949  /*
26950 @@ -3251,6 +3253,7 @@ retry:
26951  
26952         obj = slab_get_obj(cachep, slabp, nodeid);
26953         check_slabp(cachep, slabp);
26954 +       vx_slab_alloc(cachep, flags);
26955         l3->free_objects--;
26956         /* move slabp to correct slabp list: */
26957         list_del(&slabp->list);
26958 @@ -3327,6 +3330,7 @@ __cache_alloc_node(struct kmem_cache *ca
26959         /* ___cache_alloc_node can fall back to other nodes */
26960         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26961    out:
26962 +       vx_slab_alloc(cachep, flags);
26963         local_irq_restore(save_flags);
26964         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26965         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
26966 @@ -3513,6 +3517,7 @@ static inline void __cache_free(struct k
26967         check_irq_off();
26968         kmemleak_free_recursive(objp, cachep->flags);
26969         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26970 +       vx_slab_free(cachep);
26971  
26972         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
26973  
26974 diff -NurpP --minimal linux-2.6.32.24/mm/slab_vs.h linux-2.6.32.24-vs2.3.0.36.29.6/mm/slab_vs.h
26975 --- linux-2.6.32.24/mm/slab_vs.h        1970-01-01 01:00:00.000000000 +0100
26976 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/slab_vs.h        2009-12-03 20:04:56.000000000 +0100
26977 @@ -0,0 +1,29 @@
26978 +
26979 +#include <linux/vserver/context.h>
26980 +
26981 +#include <linux/vs_context.h>
26982 +
26983 +static inline
26984 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26985 +{
26986 +       int what = gfp_zone(cachep->gfpflags);
26987 +       struct vx_info *vxi = current_vx_info();
26988 +
26989 +       if (!vxi)
26990 +               return;
26991 +
26992 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
26993 +}
26994 +
26995 +static inline
26996 +void vx_slab_free(struct kmem_cache *cachep)
26997 +{
26998 +       int what = gfp_zone(cachep->gfpflags);
26999 +       struct vx_info *vxi = current_vx_info();
27000 +
27001 +       if (!vxi)
27002 +               return;
27003 +
27004 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
27005 +}
27006 +
27007 diff -NurpP --minimal linux-2.6.32.24/mm/swapfile.c linux-2.6.32.24-vs2.3.0.36.29.6/mm/swapfile.c
27008 --- linux-2.6.32.24/mm/swapfile.c       2010-10-04 08:56:18.000000000 +0200
27009 +++ linux-2.6.32.24-vs2.3.0.36.29.6/mm/swapfile.c       2010-08-19 17:35:34.000000000 +0200
27010 @@ -34,6 +34,8 @@
27011  #include <asm/tlbflush.h>
27012  #include <linux/swapops.h>
27013  #include <linux/page_cgroup.h>
27014 +#include <linux/vs_base.h>
27015 +#include <linux/vs_memory.h>
27016  
27017  static DEFINE_SPINLOCK(swap_lock);
27018  static unsigned int nr_swapfiles;
27019 @@ -1682,6 +1684,8 @@ static void *swap_next(struct seq_file *
27020         if (v == SEQ_START_TOKEN)
27021                 ptr = swap_info;
27022         else {
27023 +               if (vx_flags(VXF_VIRT_MEM, 0))
27024 +                       return NULL;
27025                 ptr = v;
27026                 ptr++;
27027         }
27028 @@ -1709,6 +1713,16 @@ static int swap_show(struct seq_file *sw
27029  
27030         if (ptr == SEQ_START_TOKEN) {
27031                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
27032 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
27033 +                       struct sysinfo si;
27034 +
27035 +                       vx_vsi_swapinfo(&si);
27036 +                       if (si.totalswap < (1 << 10))
27037 +                               return 0;
27038 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
27039 +                               "hdv0", "partition", si.totalswap >> 10,
27040 +                               (si.totalswap - si.freeswap) >> 10, -1);
27041 +               }
27042                 return 0;
27043         }
27044  
27045 @@ -2066,6 +2080,8 @@ void si_swapinfo(struct sysinfo *val)
27046         val->freeswap = nr_swap_pages + nr_to_be_unused;
27047         val->totalswap = total_swap_pages + nr_to_be_unused;
27048         spin_unlock(&swap_lock);
27049 +       if (vx_flags(VXF_VIRT_MEM, 0))
27050 +               vx_vsi_swapinfo(val);
27051  }
27052  
27053  /*
27054 diff -NurpP --minimal linux-2.6.32.24/net/core/dev.c linux-2.6.32.24-vs2.3.0.36.29.6/net/core/dev.c
27055 --- linux-2.6.32.24/net/core/dev.c      2010-10-04 08:56:19.000000000 +0200
27056 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/core/dev.c      2010-09-05 21:24:17.000000000 +0200
27057 @@ -126,6 +126,7 @@
27058  #include <linux/in.h>
27059  #include <linux/jhash.h>
27060  #include <linux/random.h>
27061 +#include <linux/vs_inet.h>
27062  #include <trace/events/napi.h>
27063  
27064  #include "net-sysfs.h"
27065 @@ -591,7 +592,8 @@ struct net_device *__dev_get_by_name(str
27066         hlist_for_each(p, dev_name_hash(net, name)) {
27067                 struct net_device *dev
27068                         = hlist_entry(p, struct net_device, name_hlist);
27069 -               if (!strncmp(dev->name, name, IFNAMSIZ))
27070 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
27071 +                   nx_dev_visible(current_nx_info(), dev))
27072                         return dev;
27073         }
27074         return NULL;
27075 @@ -642,7 +644,8 @@ struct net_device *__dev_get_by_index(st
27076         hlist_for_each(p, dev_index_hash(net, ifindex)) {
27077                 struct net_device *dev
27078                         = hlist_entry(p, struct net_device, index_hlist);
27079 -               if (dev->ifindex == ifindex)
27080 +               if ((dev->ifindex == ifindex) &&
27081 +                   nx_dev_visible(current_nx_info(), dev))
27082                         return dev;
27083         }
27084         return NULL;
27085 @@ -695,10 +698,12 @@ struct net_device *dev_getbyhwaddr(struc
27086  
27087         ASSERT_RTNL();
27088  
27089 -       for_each_netdev(net, dev)
27090 +       for_each_netdev(net, dev) {
27091                 if (dev->type == type &&
27092 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
27093 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
27094 +                   nx_dev_visible(current_nx_info(), dev))
27095                         return dev;
27096 +       }
27097  
27098         return NULL;
27099  }
27100 @@ -709,9 +714,11 @@ struct net_device *__dev_getfirstbyhwtyp
27101         struct net_device *dev;
27102  
27103         ASSERT_RTNL();
27104 -       for_each_netdev(net, dev)
27105 -               if (dev->type == type)
27106 +       for_each_netdev(net, dev) {
27107 +               if ((dev->type == type) &&
27108 +                   nx_dev_visible(current_nx_info(), dev))
27109                         return dev;
27110 +       }
27111  
27112         return NULL;
27113  }
27114 @@ -830,6 +837,8 @@ static int __dev_alloc_name(struct net *
27115                                 continue;
27116                         if (i < 0 || i >= max_netdevices)
27117                                 continue;
27118 +                       if (!nx_dev_visible(current_nx_info(), d))
27119 +                               continue;
27120  
27121                         /*  avoid cases where sscanf is not exact inverse of printf */
27122                         snprintf(buf, IFNAMSIZ, name, i);
27123 @@ -2984,6 +2993,8 @@ static int dev_ifconf(struct net *net, c
27124  
27125         total = 0;
27126         for_each_netdev(net, dev) {
27127 +               if (!nx_dev_visible(current_nx_info(), dev))
27128 +                       continue;
27129                 for (i = 0; i < NPROTO; i++) {
27130                         if (gifconf_list[i]) {
27131                                 int done;
27132 @@ -3052,6 +3063,9 @@ static void dev_seq_printf_stats(struct 
27133  {
27134         const struct net_device_stats *stats = dev_get_stats(dev);
27135  
27136 +       if (!nx_dev_visible(current_nx_info(), dev))
27137 +               return;
27138 +
27139         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
27140                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
27141                    dev->name, stats->rx_bytes, stats->rx_packets,
27142 @@ -5317,7 +5331,6 @@ int dev_change_net_namespace(struct net_
27143         if (dev->dev.parent)
27144                 goto out;
27145  #endif
27146 -
27147         /* Ensure the device has been registrered */
27148         err = -EINVAL;
27149         if (dev->reg_state != NETREG_REGISTERED)
27150 diff -NurpP --minimal linux-2.6.32.24/net/core/rtnetlink.c linux-2.6.32.24-vs2.3.0.36.29.6/net/core/rtnetlink.c
27151 --- linux-2.6.32.24/net/core/rtnetlink.c        2010-10-04 08:56:19.000000000 +0200
27152 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/core/rtnetlink.c        2009-12-29 00:36:26.000000000 +0100
27153 @@ -688,6 +688,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
27154  
27155         idx = 0;
27156         for_each_netdev(net, dev) {
27157 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
27158 +                       continue;
27159                 if (idx < s_idx)
27160                         goto cont;
27161                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
27162 @@ -1222,6 +1224,9 @@ void rtmsg_ifinfo(int type, struct net_d
27163         struct sk_buff *skb;
27164         int err = -ENOBUFS;
27165  
27166 +       if (!nx_dev_visible(current_nx_info(), dev))
27167 +               return;
27168 +
27169         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
27170         if (skb == NULL)
27171                 goto errout;
27172 diff -NurpP --minimal linux-2.6.32.24/net/core/sock.c linux-2.6.32.24-vs2.3.0.36.29.6/net/core/sock.c
27173 --- linux-2.6.32.24/net/core/sock.c     2010-10-04 08:56:19.000000000 +0200
27174 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/core/sock.c     2010-02-12 10:59:55.000000000 +0100
27175 @@ -125,6 +125,10 @@
27176  #include <linux/ipsec.h>
27177  
27178  #include <linux/filter.h>
27179 +#include <linux/vs_socket.h>
27180 +#include <linux/vs_limit.h>
27181 +#include <linux/vs_context.h>
27182 +#include <linux/vs_network.h>
27183  
27184  #ifdef CONFIG_INET
27185  #include <net/tcp.h>
27186 @@ -984,6 +988,8 @@ static struct sock *sk_prot_alloc(struct
27187                 if (!try_module_get(prot->owner))
27188                         goto out_free_sec;
27189         }
27190 +               sock_vx_init(sk);
27191 +               sock_nx_init(sk);
27192  
27193         return sk;
27194  
27195 @@ -1063,6 +1069,11 @@ static void __sk_free(struct sock *sk)
27196                        __func__, atomic_read(&sk->sk_omem_alloc));
27197  
27198         put_net(sock_net(sk));
27199 +       vx_sock_dec(sk);
27200 +       clr_vx_info(&sk->sk_vx_info);
27201 +       sk->sk_xid = -1;
27202 +       clr_nx_info(&sk->sk_nx_info);
27203 +       sk->sk_nid = -1;
27204         sk_prot_free(sk->sk_prot_creator, sk);
27205  }
27206  
27207 @@ -1110,6 +1121,8 @@ struct sock *sk_clone(const struct sock 
27208  
27209                 /* SANITY */
27210                 get_net(sock_net(newsk));
27211 +               sock_vx_init(newsk);
27212 +               sock_nx_init(newsk);
27213                 sk_node_init(&newsk->sk_node);
27214                 sock_lock_init(newsk);
27215                 bh_lock_sock(newsk);
27216 @@ -1164,6 +1177,12 @@ struct sock *sk_clone(const struct sock 
27217                 smp_wmb();
27218                 atomic_set(&newsk->sk_refcnt, 2);
27219  
27220 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
27221 +               newsk->sk_xid = sk->sk_xid;
27222 +               vx_sock_inc(newsk);
27223 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
27224 +               newsk->sk_nid = sk->sk_nid;
27225 +
27226                 /*
27227                  * Increment the counter in the same struct proto as the master
27228                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
27229 @@ -1886,6 +1905,12 @@ void sock_init_data(struct socket *sock,
27230  
27231         sk->sk_stamp = ktime_set(-1L, 0);
27232  
27233 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
27234 +       sk->sk_xid = vx_current_xid();
27235 +       vx_sock_inc(sk);
27236 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
27237 +       sk->sk_nid = nx_current_nid();
27238 +
27239         /*
27240          * Before updating sk_refcnt, we must commit prior changes to memory
27241          * (Documentation/RCU/rculist_nulls.txt for details)
27242 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/af_inet.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/af_inet.c
27243 --- linux-2.6.32.24/net/ipv4/af_inet.c  2009-12-03 20:02:59.000000000 +0100
27244 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/af_inet.c  2009-12-03 20:04:56.000000000 +0100
27245 @@ -115,6 +115,7 @@
27246  #ifdef CONFIG_IP_MROUTE
27247  #include <linux/mroute.h>
27248  #endif
27249 +#include <linux/vs_limit.h>
27250  
27251  
27252  /* The inetsw table contains everything that inet_create needs to
27253 @@ -325,9 +326,12 @@ lookup_protocol:
27254         }
27255  
27256         err = -EPERM;
27257 +       if ((protocol == IPPROTO_ICMP) &&
27258 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27259 +               goto override;
27260         if (answer->capability > 0 && !capable(answer->capability))
27261                 goto out_rcu_unlock;
27262 -
27263 +override:
27264         err = -EAFNOSUPPORT;
27265         if (!inet_netns_ok(net, protocol))
27266                 goto out_rcu_unlock;
27267 @@ -447,6 +451,7 @@ int inet_bind(struct socket *sock, struc
27268         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
27269         struct sock *sk = sock->sk;
27270         struct inet_sock *inet = inet_sk(sk);
27271 +       struct nx_v4_sock_addr nsa;
27272         unsigned short snum;
27273         int chk_addr_ret;
27274         int err;
27275 @@ -460,7 +465,11 @@ int inet_bind(struct socket *sock, struc
27276         if (addr_len < sizeof(struct sockaddr_in))
27277                 goto out;
27278  
27279 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27280 +       err = v4_map_sock_addr(inet, addr, &nsa);
27281 +       if (err)
27282 +               goto out;
27283 +
27284 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27285  
27286         /* Not specified by any standard per-se, however it breaks too
27287          * many applications when removed.  It is unfortunate since
27288 @@ -472,7 +481,7 @@ int inet_bind(struct socket *sock, struc
27289         err = -EADDRNOTAVAIL;
27290         if (!sysctl_ip_nonlocal_bind &&
27291             !(inet->freebind || inet->transparent) &&
27292 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
27293 +           nsa.saddr != htonl(INADDR_ANY) &&
27294             chk_addr_ret != RTN_LOCAL &&
27295             chk_addr_ret != RTN_MULTICAST &&
27296             chk_addr_ret != RTN_BROADCAST)
27297 @@ -497,7 +506,7 @@ int inet_bind(struct socket *sock, struc
27298         if (sk->sk_state != TCP_CLOSE || inet->num)
27299                 goto out_release_sock;
27300  
27301 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27302 +       v4_set_sock_addr(inet, &nsa);
27303         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27304                 inet->saddr = 0;  /* Use device */
27305  
27306 @@ -694,11 +703,13 @@ int inet_getname(struct socket *sock, st
27307                      peer == 1))
27308                         return -ENOTCONN;
27309                 sin->sin_port = inet->dport;
27310 -               sin->sin_addr.s_addr = inet->daddr;
27311 +               sin->sin_addr.s_addr =
27312 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27313         } else {
27314                 __be32 addr = inet->rcv_saddr;
27315                 if (!addr)
27316                         addr = inet->saddr;
27317 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
27318                 sin->sin_port = inet->sport;
27319                 sin->sin_addr.s_addr = addr;
27320         }
27321 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/devinet.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/devinet.c
27322 --- linux-2.6.32.24/net/ipv4/devinet.c  2010-10-04 08:56:19.000000000 +0200
27323 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/devinet.c  2010-08-19 17:35:34.000000000 +0200
27324 @@ -413,6 +413,7 @@ struct in_device *inetdev_by_index(struc
27325         return in_dev;
27326  }
27327  
27328 +
27329  /* Called only from RTNL semaphored context. No locks. */
27330  
27331  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
27332 @@ -653,6 +654,8 @@ int devinet_ioctl(struct net *net, unsig
27333                 *colon = ':';
27334  
27335         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
27336 +               struct nx_info *nxi = current_nx_info();
27337 +
27338                 if (tryaddrmatch) {
27339                         /* Matthias Andree */
27340                         /* compare label and address (4.4BSD style) */
27341 @@ -661,6 +664,8 @@ int devinet_ioctl(struct net *net, unsig
27342                            This is checked above. */
27343                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27344                              ifap = &ifa->ifa_next) {
27345 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27346 +                                       continue;
27347                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
27348                                     sin_orig.sin_addr.s_addr ==
27349                                                         ifa->ifa_address) {
27350 @@ -673,9 +678,12 @@ int devinet_ioctl(struct net *net, unsig
27351                    comparing just the label */
27352                 if (!ifa) {
27353                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27354 -                            ifap = &ifa->ifa_next)
27355 +                            ifap = &ifa->ifa_next) {
27356 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27357 +                                       continue;
27358                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
27359                                         break;
27360 +                       }
27361                 }
27362         }
27363  
27364 @@ -826,6 +834,8 @@ static int inet_gifconf(struct net_devic
27365                 goto out;
27366  
27367         for (; ifa; ifa = ifa->ifa_next) {
27368 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
27369 +                       continue;
27370                 if (!buf) {
27371                         done += sizeof(ifr);
27372                         continue;
27373 @@ -1175,6 +1185,7 @@ static int inet_dump_ifaddr(struct sk_bu
27374         struct net_device *dev;
27375         struct in_device *in_dev;
27376         struct in_ifaddr *ifa;
27377 +       struct sock *sk = skb->sk;
27378         int s_ip_idx, s_idx = cb->args[0];
27379  
27380         s_ip_idx = ip_idx = cb->args[1];
27381 @@ -1189,6 +1200,8 @@ static int inet_dump_ifaddr(struct sk_bu
27382  
27383                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
27384                      ifa = ifa->ifa_next, ip_idx++) {
27385 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
27386 +                               continue;
27387                         if (ip_idx < s_ip_idx)
27388                                 continue;
27389                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
27390 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/fib_hash.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/fib_hash.c
27391 --- linux-2.6.32.24/net/ipv4/fib_hash.c 2009-09-10 15:26:29.000000000 +0200
27392 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/fib_hash.c 2009-12-03 20:04:56.000000000 +0100
27393 @@ -1021,7 +1021,7 @@ static int fib_seq_show(struct seq_file 
27394         prefix  = f->fn_key;
27395         mask    = FZ_MASK(iter->zone);
27396         flags   = fib_flag_trans(fa->fa_type, mask, fi);
27397 -       if (fi)
27398 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
27399                 seq_printf(seq,
27400                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
27401                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
27402 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/inet_connection_sock.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/inet_connection_sock.c
27403 --- linux-2.6.32.24/net/ipv4/inet_connection_sock.c     2009-12-03 20:02:59.000000000 +0100
27404 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/inet_connection_sock.c     2009-12-03 20:04:56.000000000 +0100
27405 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
27406  }
27407  EXPORT_SYMBOL(inet_get_local_port_range);
27408  
27409 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27410 +{
27411 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
27412 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
27413 +
27414 +       if (inet_v6_ipv6only(sk2))
27415 +               return 0;
27416 +
27417 +       if (sk1_rcv_saddr &&
27418 +           sk2_rcv_saddr &&
27419 +           sk1_rcv_saddr == sk2_rcv_saddr)
27420 +               return 1;
27421 +
27422 +       if (sk1_rcv_saddr &&
27423 +           !sk2_rcv_saddr &&
27424 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
27425 +               return 1;
27426 +
27427 +       if (sk2_rcv_saddr &&
27428 +           !sk1_rcv_saddr &&
27429 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
27430 +               return 1;
27431 +
27432 +       if (!sk1_rcv_saddr &&
27433 +           !sk2_rcv_saddr &&
27434 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
27435 +               return 1;
27436 +
27437 +       return 0;
27438 +}
27439 +
27440  int inet_csk_bind_conflict(const struct sock *sk,
27441                            const struct inet_bind_bucket *tb)
27442  {
27443 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
27444         struct sock *sk2;
27445         struct hlist_node *node;
27446         int reuse = sk->sk_reuse;
27447 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
27448                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
27449                         if (!reuse || !sk2->sk_reuse ||
27450                             sk2->sk_state == TCP_LISTEN) {
27451 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27452 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
27453 -                                   sk2_rcv_saddr == sk_rcv_saddr)
27454 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
27455                                         break;
27456                         }
27457                 }
27458 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/inet_diag.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/inet_diag.c
27459 --- linux-2.6.32.24/net/ipv4/inet_diag.c        2009-09-10 15:26:29.000000000 +0200
27460 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/inet_diag.c        2009-12-03 20:04:56.000000000 +0100
27461 @@ -32,6 +32,8 @@
27462  #include <linux/stddef.h>
27463  
27464  #include <linux/inet_diag.h>
27465 +#include <linux/vs_network.h>
27466 +#include <linux/vs_inet.h>
27467  
27468  static const struct inet_diag_handler **inet_diag_table;
27469  
27470 @@ -118,8 +120,8 @@ static int inet_csk_diag_fill(struct soc
27471  
27472         r->id.idiag_sport = inet->sport;
27473         r->id.idiag_dport = inet->dport;
27474 -       r->id.idiag_src[0] = inet->rcv_saddr;
27475 -       r->id.idiag_dst[0] = inet->daddr;
27476 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
27477 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27478  
27479  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27480         if (r->idiag_family == AF_INET6) {
27481 @@ -204,8 +206,8 @@ static int inet_twsk_diag_fill(struct in
27482         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
27483         r->id.idiag_sport     = tw->tw_sport;
27484         r->id.idiag_dport     = tw->tw_dport;
27485 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
27486 -       r->id.idiag_dst[0]    = tw->tw_daddr;
27487 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
27488 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
27489         r->idiag_state        = tw->tw_substate;
27490         r->idiag_timer        = 3;
27491         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
27492 @@ -262,6 +264,7 @@ static int inet_diag_get_exact(struct sk
27493         err = -EINVAL;
27494  
27495         if (req->idiag_family == AF_INET) {
27496 +               /* TODO: lback */
27497                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
27498                                  req->id.idiag_dport, req->id.idiag_src[0],
27499                                  req->id.idiag_sport, req->id.idiag_if);
27500 @@ -504,6 +507,7 @@ static int inet_csk_diag_dump(struct soc
27501                 } else
27502  #endif
27503                 {
27504 +                       /* TODO: lback */
27505                         entry.saddr = &inet->rcv_saddr;
27506                         entry.daddr = &inet->daddr;
27507                 }
27508 @@ -540,6 +544,7 @@ static int inet_twsk_diag_dump(struct in
27509                 } else
27510  #endif
27511                 {
27512 +                       /* TODO: lback */
27513                         entry.saddr = &tw->tw_rcv_saddr;
27514                         entry.daddr = &tw->tw_daddr;
27515                 }
27516 @@ -586,8 +591,8 @@ static int inet_diag_fill_req(struct sk_
27517  
27518         r->id.idiag_sport = inet->sport;
27519         r->id.idiag_dport = ireq->rmt_port;
27520 -       r->id.idiag_src[0] = ireq->loc_addr;
27521 -       r->id.idiag_dst[0] = ireq->rmt_addr;
27522 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
27523 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
27524         r->idiag_expires = jiffies_to_msecs(tmo);
27525         r->idiag_rqueue = 0;
27526         r->idiag_wqueue = 0;
27527 @@ -657,6 +662,7 @@ static int inet_diag_dump_reqs(struct sk
27528                                 continue;
27529  
27530                         if (bc) {
27531 +                               /* TODO: lback */
27532                                 entry.saddr =
27533  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27534                                         (entry.family == AF_INET6) ?
27535 @@ -727,6 +733,8 @@ static int inet_diag_dump(struct sk_buff
27536                         sk_nulls_for_each(sk, node, &ilb->head) {
27537                                 struct inet_sock *inet = inet_sk(sk);
27538  
27539 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27540 +                                       continue;
27541                                 if (num < s_num) {
27542                                         num++;
27543                                         continue;
27544 @@ -793,6 +801,8 @@ skip_listen_ht:
27545                 sk_nulls_for_each(sk, node, &head->chain) {
27546                         struct inet_sock *inet = inet_sk(sk);
27547  
27548 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27549 +                               continue;
27550                         if (num < s_num)
27551                                 goto next_normal;
27552                         if (!(r->idiag_states & (1 << sk->sk_state)))
27553 @@ -817,6 +827,8 @@ next_normal:
27554                         inet_twsk_for_each(tw, node,
27555                                     &head->twchain) {
27556  
27557 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27558 +                                       continue;
27559                                 if (num < s_num)
27560                                         goto next_dying;
27561                                 if (r->id.idiag_sport != tw->tw_sport &&
27562 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/inet_hashtables.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/inet_hashtables.c
27563 --- linux-2.6.32.24/net/ipv4/inet_hashtables.c  2009-06-11 17:13:29.000000000 +0200
27564 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/inet_hashtables.c  2009-12-03 20:04:56.000000000 +0100
27565 @@ -21,6 +21,7 @@
27566  
27567  #include <net/inet_connection_sock.h>
27568  #include <net/inet_hashtables.h>
27569 +#include <net/route.h>
27570  #include <net/ip.h>
27571  
27572  /*
27573 @@ -134,6 +135,11 @@ static inline int compute_score(struct s
27574                         if (rcv_saddr != daddr)
27575                                 return -1;
27576                         score += 2;
27577 +               } else {
27578 +                       /* block non nx_info ips */
27579 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27580 +                               daddr, NXA_MASK_BIND))
27581 +                               return -1;
27582                 }
27583                 if (sk->sk_bound_dev_if) {
27584                         if (sk->sk_bound_dev_if != dif)
27585 @@ -151,7 +157,6 @@ static inline int compute_score(struct s
27586   * wildcarded during the search since they can never be otherwise.
27587   */
27588  
27589 -
27590  struct sock *__inet_lookup_listener(struct net *net,
27591                                     struct inet_hashinfo *hashinfo,
27592                                     const __be32 daddr, const unsigned short hnum,
27593 @@ -174,6 +179,7 @@ begin:
27594                         hiscore = score;
27595                 }
27596         }
27597 +
27598         /*
27599          * if the nulls value we got at the end of this lookup is
27600          * not the expected one, we must restart lookup.
27601 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/netfilter/nf_nat_helper.c
27602 --- linux-2.6.32.24/net/ipv4/netfilter/nf_nat_helper.c  2009-12-03 20:02:59.000000000 +0100
27603 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/netfilter/nf_nat_helper.c  2009-12-03 20:04:56.000000000 +0100
27604 @@ -19,6 +19,7 @@
27605  #include <net/route.h>
27606  
27607  #include <linux/netfilter_ipv4.h>
27608 +#include <net/route.h>
27609  #include <net/netfilter/nf_conntrack.h>
27610  #include <net/netfilter/nf_conntrack_helper.h>
27611  #include <net/netfilter/nf_conntrack_ecache.h>
27612 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/netfilter.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/netfilter.c
27613 --- linux-2.6.32.24/net/ipv4/netfilter.c        2009-09-10 15:26:29.000000000 +0200
27614 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/netfilter.c        2009-12-03 20:04:56.000000000 +0100
27615 @@ -4,7 +4,7 @@
27616  #include <linux/netfilter_ipv4.h>
27617  #include <linux/ip.h>
27618  #include <linux/skbuff.h>
27619 -#include <net/route.h>
27620 +// #include <net/route.h>
27621  #include <net/xfrm.h>
27622  #include <net/ip.h>
27623  #include <net/netfilter/nf_queue.h>
27624 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/raw.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/raw.c
27625 --- linux-2.6.32.24/net/ipv4/raw.c      2009-12-03 20:02:59.000000000 +0100
27626 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/raw.c      2009-12-03 20:04:56.000000000 +0100
27627 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
27628  
27629                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
27630                     !(inet->daddr && inet->daddr != raddr)              &&
27631 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27632 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27633                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27634                         goto found; /* gotcha */
27635         }
27636 @@ -383,6 +383,12 @@ static int raw_send_hdrinc(struct sock *
27637                 icmp_out_count(net, ((struct icmphdr *)
27638                         skb_transport_header(skb))->type);
27639  
27640 +       err = -EPERM;
27641 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27642 +               sk->sk_nx_info &&
27643 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27644 +               goto error_free;
27645 +
27646         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27647                       dst_output);
27648         if (err > 0)
27649 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
27650                 }
27651  
27652                 security_sk_classify_flow(sk, &fl);
27653 +               if (sk->sk_nx_info) {
27654 +                       err = ip_v4_find_src(sock_net(sk),
27655 +                               sk->sk_nx_info, &rt, &fl);
27656 +
27657 +                       if (err)
27658 +                               goto done;
27659 +               }
27660                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
27661         }
27662         if (err)
27663 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
27664  {
27665         struct inet_sock *inet = inet_sk(sk);
27666         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27667 +       struct nx_v4_sock_addr nsa = { 0 };
27668         int ret = -EINVAL;
27669         int chk_addr_ret;
27670  
27671         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27672                 goto out;
27673 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27674 +       v4_map_sock_addr(inet, addr, &nsa);
27675 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27676         ret = -EADDRNOTAVAIL;
27677 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27678 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27679             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27680                 goto out;
27681 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27682 +       v4_set_sock_addr(inet, &nsa);
27683         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27684                 inet->saddr = 0;  /* Use device */
27685         sk_dst_reset(sk);
27686 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
27687         /* Copy the address. */
27688         if (sin) {
27689                 sin->sin_family = AF_INET;
27690 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27691 +               sin->sin_addr.s_addr =
27692 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27693                 sin->sin_port = 0;
27694                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27695         }
27696 @@ -875,7 +891,8 @@ static struct sock *raw_get_first(struct
27697                 struct hlist_node *node;
27698  
27699                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27700 -                       if (sock_net(sk) == seq_file_net(seq))
27701 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
27702 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27703                                 goto found;
27704         }
27705         sk = NULL;
27706 @@ -891,7 +908,8 @@ static struct sock *raw_get_next(struct 
27707                 sk = sk_next(sk);
27708  try_again:
27709                 ;
27710 -       } while (sk && sock_net(sk) != seq_file_net(seq));
27711 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
27712 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27713  
27714         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27715                 sk = sk_head(&state->h->ht[state->bucket]);
27716 @@ -950,7 +968,10 @@ static void raw_sock_seq_show(struct seq
27717  
27718         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
27719                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
27720 -               i, src, srcp, dest, destp, sp->sk_state,
27721 +               i,
27722 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27723 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27724 +               sp->sk_state,
27725                 sk_wmem_alloc_get(sp),
27726                 sk_rmem_alloc_get(sp),
27727                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27728 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/tcp.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/tcp.c
27729 --- linux-2.6.32.24/net/ipv4/tcp.c      2010-10-04 08:56:19.000000000 +0200
27730 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/tcp.c      2010-10-04 10:04:57.000000000 +0200
27731 @@ -264,6 +264,7 @@
27732  #include <linux/cache.h>
27733  #include <linux/err.h>
27734  #include <linux/crypto.h>
27735 +#include <linux/in.h>
27736  
27737  #include <net/icmp.h>
27738  #include <net/tcp.h>
27739 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/tcp_ipv4.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/tcp_ipv4.c
27740 --- linux-2.6.32.24/net/ipv4/tcp_ipv4.c 2009-12-03 20:03:00.000000000 +0100
27741 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/tcp_ipv4.c 2009-12-03 20:04:56.000000000 +0100
27742 @@ -1925,6 +1925,12 @@ static void *listening_get_next(struct s
27743                 req = req->dl_next;
27744                 while (1) {
27745                         while (req) {
27746 +                               vxdprintk(VXD_CBIT(net, 6),
27747 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27748 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27749 +                               if (req->sk &&
27750 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27751 +                                       continue;
27752                                 if (req->rsk_ops->family == st->family) {
27753                                         cur = req;
27754                                         goto out;
27755 @@ -1949,6 +1955,10 @@ get_req:
27756         }
27757  get_sk:
27758         sk_nulls_for_each_from(sk, node) {
27759 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27760 +                       sk, sk->sk_nid, nx_current_nid());
27761 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27762 +                       continue;
27763                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
27764                         cur = sk;
27765                         goto out;
27766 @@ -2012,6 +2022,11 @@ static void *established_get_first(struc
27767  
27768                 spin_lock_bh(lock);
27769                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27770 +                       vxdprintk(VXD_CBIT(net, 6),
27771 +                               "sk,egf: %p [#%d] (from %d)",
27772 +                               sk, sk->sk_nid, nx_current_nid());
27773 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27774 +                               continue;
27775                         if (sk->sk_family != st->family ||
27776                             !net_eq(sock_net(sk), net)) {
27777                                 continue;
27778 @@ -2022,6 +2037,11 @@ static void *established_get_first(struc
27779                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27780                 inet_twsk_for_each(tw, node,
27781                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27782 +                       vxdprintk(VXD_CBIT(net, 6),
27783 +                               "tw: %p [#%d] (from %d)",
27784 +                               tw, tw->tw_nid, nx_current_nid());
27785 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27786 +                               continue;
27787                         if (tw->tw_family != st->family ||
27788                             !net_eq(twsk_net(tw), net)) {
27789                                 continue;
27790 @@ -2050,7 +2070,9 @@ static void *established_get_next(struct
27791                 tw = cur;
27792                 tw = tw_next(tw);
27793  get_tw:
27794 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27795 +               while (tw && (tw->tw_family != st->family ||
27796 +                       !net_eq(twsk_net(tw), net) ||
27797 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27798                         tw = tw_next(tw);
27799                 }
27800                 if (tw) {
27801 @@ -2073,6 +2095,11 @@ get_tw:
27802                 sk = sk_nulls_next(sk);
27803  
27804         sk_nulls_for_each_from(sk, node) {
27805 +               vxdprintk(VXD_CBIT(net, 6),
27806 +                       "sk,egn: %p [#%d] (from %d)",
27807 +                       sk, sk->sk_nid, nx_current_nid());
27808 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27809 +                       continue;
27810                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27811                         goto found;
27812         }
27813 @@ -2224,9 +2251,9 @@ static void get_openreq4(struct sock *sk
27814         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27815                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
27816                 i,
27817 -               ireq->loc_addr,
27818 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27819                 ntohs(inet_sk(sk)->sport),
27820 -               ireq->rmt_addr,
27821 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27822                 ntohs(ireq->rmt_port),
27823                 TCP_SYN_RECV,
27824                 0, 0, /* could print option size, but that is af dependent. */
27825 @@ -2269,7 +2296,10 @@ static void get_tcp4_sock(struct sock *s
27826  
27827         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27828                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27829 -               i, src, srcp, dest, destp, sk->sk_state,
27830 +               i,
27831 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27832 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27833 +               sk->sk_state,
27834                 tp->write_seq - tp->snd_una,
27835                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27836                                              (tp->rcv_nxt - tp->copied_seq),
27837 @@ -2305,7 +2335,10 @@ static void get_timewait4_sock(struct in
27838  
27839         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27840                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27841 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27842 +               i,
27843 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27844 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27845 +               tw->tw_substate, 0, 0,
27846                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27847                 atomic_read(&tw->tw_refcnt), tw, len);
27848  }
27849 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/tcp_minisocks.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/tcp_minisocks.c
27850 --- linux-2.6.32.24/net/ipv4/tcp_minisocks.c    2009-12-03 20:03:00.000000000 +0100
27851 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/tcp_minisocks.c    2009-12-03 20:04:56.000000000 +0100
27852 @@ -26,6 +26,10 @@
27853  #include <net/inet_common.h>
27854  #include <net/xfrm.h>
27855  
27856 +#include <linux/vs_limit.h>
27857 +#include <linux/vs_socket.h>
27858 +#include <linux/vs_context.h>
27859 +
27860  #ifdef CONFIG_SYSCTL
27861  #define SYNC_INIT 0 /* let the user enable it */
27862  #else
27863 @@ -294,6 +298,11 @@ void tcp_time_wait(struct sock *sk, int 
27864                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27865                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27866  
27867 +               tw->tw_xid              = sk->sk_xid;
27868 +               tw->tw_vx_info          = NULL;
27869 +               tw->tw_nid              = sk->sk_nid;
27870 +               tw->tw_nx_info          = NULL;
27871 +
27872  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27873                 if (tw->tw_family == PF_INET6) {
27874                         struct ipv6_pinfo *np = inet6_sk(sk);
27875 diff -NurpP --minimal linux-2.6.32.24/net/ipv4/udp.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/udp.c
27876 --- linux-2.6.32.24/net/ipv4/udp.c      2010-10-04 08:56:19.000000000 +0200
27877 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv4/udp.c      2010-05-27 19:21:36.000000000 +0200
27878 @@ -224,14 +224,7 @@ fail:
27879  }
27880  EXPORT_SYMBOL(udp_lib_get_port);
27881  
27882 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27883 -{
27884 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27885 -
27886 -       return  (!ipv6_only_sock(sk2)  &&
27887 -                (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27888 -                  inet1->rcv_saddr == inet2->rcv_saddr));
27889 -}
27890 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27891  
27892  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27893  {
27894 @@ -253,6 +246,11 @@ static inline int compute_score(struct s
27895                         if (inet->rcv_saddr != daddr)
27896                                 return -1;
27897                         score += 2;
27898 +               } else {
27899 +                       /* block non nx_info ips */
27900 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27901 +                               daddr, NXA_MASK_BIND))
27902 +                               return -1;
27903                 }
27904                 if (inet->daddr) {
27905                         if (inet->daddr != saddr)
27906 @@ -273,6 +271,7 @@ static inline int compute_score(struct s
27907         return score;
27908  }
27909  
27910 +
27911  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27912   * harder than this. -DaveM
27913   */
27914 @@ -294,6 +293,11 @@ begin:
27915         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27916                 score = compute_score(sk, net, saddr, hnum, sport,
27917                                       daddr, dport, dif);
27918 +               /* FIXME: disabled?
27919 +               if (score == 9) {
27920 +                       result = sk;
27921 +                       break;
27922 +               } else */
27923                 if (score > badness) {
27924                         result = sk;
27925                         badness = score;
27926 @@ -307,6 +311,7 @@ begin:
27927         if (get_nulls_value(node) != hash)
27928                 goto begin;
27929  
27930 +
27931         if (result) {
27932                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
27933                         result = NULL;
27934 @@ -316,6 +321,7 @@ begin:
27935                         goto begin;
27936                 }
27937         }
27938 +
27939         rcu_read_unlock();
27940         return result;
27941  }
27942 @@ -358,7 +364,7 @@ static inline struct sock *udp_v4_mcast_
27943                     s->sk_hash != hnum                                  ||
27944                     (inet->daddr && inet->daddr != rmt_addr)            ||
27945                     (inet->dport != rmt_port && inet->dport)            ||
27946 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27947 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27948                     ipv6_only_sock(s)                                   ||
27949                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27950                         continue;
27951 @@ -707,8 +713,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27952                                                { .sport = inet->sport,
27953                                                  .dport = dport } } };
27954                 struct net *net = sock_net(sk);
27955 +               struct nx_info *nxi = sk->sk_nx_info;
27956  
27957                 security_sk_classify_flow(sk, &fl);
27958 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27959 +               if (err)
27960 +                       goto out;
27961 +
27962                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27963                 if (err) {
27964                         if (err == -ENETUNREACH)
27965 @@ -988,7 +999,8 @@ try_again:
27966         if (sin) {
27967                 sin->sin_family = AF_INET;
27968                 sin->sin_port = udp_hdr(skb)->source;
27969 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27970 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27971 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27972                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27973         }
27974         if (inet->cmsg_flags)
27975 @@ -1627,6 +1639,8 @@ static struct sock *udp_get_first(struct
27976                 sk_nulls_for_each(sk, node, &hslot->head) {
27977                         if (!net_eq(sock_net(sk), net))
27978                                 continue;
27979 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27980 +                               continue;
27981                         if (sk->sk_family == state->family)
27982                                 goto found;
27983                 }
27984 @@ -1644,7 +1658,9 @@ static struct sock *udp_get_next(struct 
27985  
27986         do {
27987                 sk = sk_nulls_next(sk);
27988 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27989 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27990 +               sk->sk_family != state->family ||
27991 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27992  
27993         if (!sk) {
27994                 if (state->bucket < UDP_HTABLE_SIZE)
27995 @@ -1751,7 +1767,10 @@ static void udp4_format_sock(struct sock
27996  
27997         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27998                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27999 -               bucket, src, srcp, dest, destp, sp->sk_state,
28000 +               bucket,
28001 +               nx_map_sock_lback(current_nx_info(), src), srcp,
28002 +               nx_map_sock_lback(current_nx_info(), dest), destp,
28003 +               sp->sk_state,
28004                 sk_wmem_alloc_get(sp),
28005                 sk_rmem_alloc_get(sp),
28006                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
28007 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/addrconf.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/addrconf.c
28008 --- linux-2.6.32.24/net/ipv6/addrconf.c 2010-10-04 08:56:19.000000000 +0200
28009 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/addrconf.c 2010-03-18 16:53:06.000000000 +0100
28010 @@ -86,6 +86,8 @@
28011  
28012  #include <linux/proc_fs.h>
28013  #include <linux/seq_file.h>
28014 +#include <linux/vs_network.h>
28015 +#include <linux/vs_inet6.h>
28016  
28017  /* Set to 3 to get tracing... */
28018  #define ACONF_DEBUG 2
28019 @@ -1122,7 +1124,7 @@ out:
28020  
28021  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
28022                        const struct in6_addr *daddr, unsigned int prefs,
28023 -                      struct in6_addr *saddr)
28024 +                      struct in6_addr *saddr, struct nx_info *nxi)
28025  {
28026         struct ipv6_saddr_score scores[2],
28027                                 *score = &scores[0], *hiscore = &scores[1];
28028 @@ -1195,6 +1197,8 @@ int ipv6_dev_get_saddr(struct net *net, 
28029                                                dev->name);
28030                                 continue;
28031                         }
28032 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
28033 +                               continue;
28034  
28035                         score->rule = -1;
28036                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
28037 @@ -3003,7 +3007,10 @@ static void if6_seq_stop(struct seq_file
28038  static int if6_seq_show(struct seq_file *seq, void *v)
28039  {
28040         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
28041 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
28042 +
28043 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
28044 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
28045 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
28046                    &ifp->addr,
28047                    ifp->idev->dev->ifindex,
28048                    ifp->prefix_len,
28049 @@ -3500,6 +3507,12 @@ static int inet6_dump_addr(struct sk_buf
28050         struct ifmcaddr6 *ifmca;
28051         struct ifacaddr6 *ifaca;
28052         struct net *net = sock_net(skb->sk);
28053 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
28054 +
28055 +       /* disable ipv6 on non v6 guests */
28056 +       if (nxi && !nx_info_has_v6(nxi))
28057 +               return skb->len;
28058 +
28059  
28060         s_idx = cb->args[0];
28061         s_ip_idx = ip_idx = cb->args[1];
28062 @@ -3521,6 +3534,8 @@ static int inet6_dump_addr(struct sk_buf
28063                              ifa = ifa->if_next, ip_idx++) {
28064                                 if (ip_idx < s_ip_idx)
28065                                         continue;
28066 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
28067 +                                       continue;
28068                                 err = inet6_fill_ifaddr(skb, ifa,
28069                                                         NETLINK_CB(cb->skb).pid,
28070                                                         cb->nlh->nlmsg_seq,
28071 @@ -3534,6 +3549,8 @@ static int inet6_dump_addr(struct sk_buf
28072                              ifmca = ifmca->next, ip_idx++) {
28073                                 if (ip_idx < s_ip_idx)
28074                                         continue;
28075 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
28076 +                                       continue;
28077                                 err = inet6_fill_ifmcaddr(skb, ifmca,
28078                                                           NETLINK_CB(cb->skb).pid,
28079                                                           cb->nlh->nlmsg_seq,
28080 @@ -3547,6 +3564,8 @@ static int inet6_dump_addr(struct sk_buf
28081                              ifaca = ifaca->aca_next, ip_idx++) {
28082                                 if (ip_idx < s_ip_idx)
28083                                         continue;
28084 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
28085 +                                       continue;
28086                                 err = inet6_fill_ifacaddr(skb, ifaca,
28087                                                           NETLINK_CB(cb->skb).pid,
28088                                                           cb->nlh->nlmsg_seq,
28089 @@ -3833,12 +3852,19 @@ static int inet6_dump_ifinfo(struct sk_b
28090         int s_idx = cb->args[0];
28091         struct net_device *dev;
28092         struct inet6_dev *idev;
28093 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
28094 +
28095 +       /* FIXME: maybe disable ipv6 on non v6 guests?
28096 +       if (skb->sk && skb->sk->sk_vx_info)
28097 +               return skb->len; */
28098  
28099         read_lock(&dev_base_lock);
28100         idx = 0;
28101         for_each_netdev(net, dev) {
28102                 if (idx < s_idx)
28103                         goto cont;
28104 +               if (!v6_dev_in_nx_info(dev, nxi))
28105 +                       goto cont;
28106                 if ((idev = in6_dev_get(dev)) == NULL)
28107                         goto cont;
28108                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
28109 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/af_inet6.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/af_inet6.c
28110 --- linux-2.6.32.24/net/ipv6/af_inet6.c 2009-12-03 20:03:00.000000000 +0100
28111 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/af_inet6.c 2009-12-03 20:04:56.000000000 +0100
28112 @@ -41,6 +41,8 @@
28113  #include <linux/netdevice.h>
28114  #include <linux/icmpv6.h>
28115  #include <linux/netfilter_ipv6.h>
28116 +#include <linux/vs_inet.h>
28117 +#include <linux/vs_inet6.h>
28118  
28119  #include <net/ip.h>
28120  #include <net/ipv6.h>
28121 @@ -158,9 +160,12 @@ lookup_protocol:
28122         }
28123  
28124         err = -EPERM;
28125 +       if ((protocol == IPPROTO_ICMPV6) &&
28126 +               nx_capable(answer->capability, NXC_RAW_ICMP))
28127 +               goto override;
28128         if (answer->capability > 0 && !capable(answer->capability))
28129                 goto out_rcu_unlock;
28130 -
28131 +override:
28132         sock->ops = answer->ops;
28133         answer_prot = answer->prot;
28134         answer_no_check = answer->no_check;
28135 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
28136         struct inet_sock *inet = inet_sk(sk);
28137         struct ipv6_pinfo *np = inet6_sk(sk);
28138         struct net *net = sock_net(sk);
28139 +       struct nx_v6_sock_addr nsa;
28140         __be32 v4addr = 0;
28141         unsigned short snum;
28142         int addr_type = 0;
28143 @@ -270,6 +276,11 @@ int inet6_bind(struct socket *sock, stru
28144  
28145         if (addr_len < SIN6_LEN_RFC2133)
28146                 return -EINVAL;
28147 +
28148 +       err = v6_map_sock_addr(inet, addr, &nsa);
28149 +       if (err)
28150 +               return err;
28151 +
28152         addr_type = ipv6_addr_type(&addr->sin6_addr);
28153         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
28154                 return -EINVAL;
28155 @@ -301,6 +312,7 @@ int inet6_bind(struct socket *sock, stru
28156                 /* Reproduce AF_INET checks to make the bindings consitant */
28157                 v4addr = addr->sin6_addr.s6_addr32[3];
28158                 chk_addr_ret = inet_addr_type(net, v4addr);
28159 +
28160                 if (!sysctl_ip_nonlocal_bind &&
28161                     !(inet->freebind || inet->transparent) &&
28162                     v4addr != htonl(INADDR_ANY) &&
28163 @@ -310,6 +322,10 @@ int inet6_bind(struct socket *sock, stru
28164                         err = -EADDRNOTAVAIL;
28165                         goto out;
28166                 }
28167 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
28168 +                       err = -EADDRNOTAVAIL;
28169 +                       goto out;
28170 +               }
28171         } else {
28172                 if (addr_type != IPV6_ADDR_ANY) {
28173                         struct net_device *dev = NULL;
28174 @@ -335,6 +351,11 @@ int inet6_bind(struct socket *sock, stru
28175                                 }
28176                         }
28177  
28178 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
28179 +                               err = -EADDRNOTAVAIL;
28180 +                               goto out;
28181 +                       }
28182 +
28183                         /* ipv4 addr of the socket is invalid.  Only the
28184                          * unspecified and mapped address have a v4 equivalent.
28185                          */
28186 @@ -353,6 +374,8 @@ int inet6_bind(struct socket *sock, stru
28187                 }
28188         }
28189  
28190 +       v6_set_sock_addr(inet, &nsa);
28191 +
28192         inet->rcv_saddr = v4addr;
28193         inet->saddr = v4addr;
28194  
28195 @@ -448,9 +471,11 @@ int inet6_getname(struct socket *sock, s
28196                         return -ENOTCONN;
28197                 sin->sin6_port = inet->dport;
28198                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
28199 +               /* FIXME: remap lback? */
28200                 if (np->sndflow)
28201                         sin->sin6_flowinfo = np->flow_label;
28202         } else {
28203 +               /* FIXME: remap lback? */
28204                 if (ipv6_addr_any(&np->rcv_saddr))
28205                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
28206                 else
28207 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/fib6_rules.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/fib6_rules.c
28208 --- linux-2.6.32.24/net/ipv6/fib6_rules.c       2009-09-10 15:26:30.000000000 +0200
28209 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/fib6_rules.c       2009-12-03 20:04:56.000000000 +0100
28210 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
28211                         if (ipv6_dev_get_saddr(net,
28212                                                ip6_dst_idev(&rt->u.dst)->dev,
28213                                                &flp->fl6_dst, srcprefs,
28214 -                                              &saddr))
28215 +                                              &saddr, NULL))
28216                                 goto again;
28217                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
28218                                                r->src.plen))
28219 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/inet6_hashtables.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/inet6_hashtables.c
28220 --- linux-2.6.32.24/net/ipv6/inet6_hashtables.c 2009-03-24 14:22:46.000000000 +0100
28221 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/inet6_hashtables.c 2009-12-03 20:04:56.000000000 +0100
28222 @@ -16,6 +16,7 @@
28223  
28224  #include <linux/module.h>
28225  #include <linux/random.h>
28226 +#include <linux/vs_inet6.h>
28227  
28228  #include <net/inet_connection_sock.h>
28229  #include <net/inet_hashtables.h>
28230 @@ -76,7 +77,6 @@ struct sock *__inet6_lookup_established(
28231         unsigned int slot = hash & (hashinfo->ehash_size - 1);
28232         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
28233  
28234 -
28235         rcu_read_lock();
28236  begin:
28237         sk_nulls_for_each_rcu(sk, node, &head->chain) {
28238 @@ -88,7 +88,7 @@ begin:
28239                                 sock_put(sk);
28240                                 goto begin;
28241                         }
28242 -               goto out;
28243 +                       goto out;
28244                 }
28245         }
28246         if (get_nulls_value(node) != slot)
28247 @@ -134,6 +134,9 @@ static int inline compute_score(struct s
28248                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28249                                 return -1;
28250                         score++;
28251 +               } else {
28252 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28253 +                               return -1;
28254                 }
28255                 if (sk->sk_bound_dev_if) {
28256                         if (sk->sk_bound_dev_if != dif)
28257 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/ip6_output.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/ip6_output.c
28258 --- linux-2.6.32.24/net/ipv6/ip6_output.c       2009-12-03 20:03:00.000000000 +0100
28259 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/ip6_output.c       2009-12-03 20:04:56.000000000 +0100
28260 @@ -934,7 +934,7 @@ static int ip6_dst_lookup_tail(struct so
28261                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
28262                                          &fl->fl6_dst,
28263                                          sk ? inet6_sk(sk)->srcprefs : 0,
28264 -                                        &fl->fl6_src);
28265 +                                        &fl->fl6_src, sk->sk_nx_info);
28266                 if (err)
28267                         goto out_err_release;
28268         }
28269 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/Kconfig linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/Kconfig
28270 --- linux-2.6.32.24/net/ipv6/Kconfig    2009-09-10 15:26:30.000000000 +0200
28271 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/Kconfig    2009-12-03 20:04:56.000000000 +0100
28272 @@ -4,8 +4,8 @@
28273  
28274  #   IPv6 as module will cause a CRASH if you try to unload it
28275  menuconfig IPV6
28276 -       tristate "The IPv6 protocol"
28277 -       default m
28278 +       bool "The IPv6 protocol"
28279 +       default n
28280         ---help---
28281           This is complemental support for the IP version 6.
28282           You will still be able to do traditional IPv4 networking as well.
28283 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/ndisc.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/ndisc.c
28284 --- linux-2.6.32.24/net/ipv6/ndisc.c    2009-12-03 20:03:00.000000000 +0100
28285 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/ndisc.c    2009-12-03 20:04:56.000000000 +0100
28286 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
28287         } else {
28288                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
28289                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
28290 -                                      &tmpaddr))
28291 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
28292                         return;
28293                 src_addr = &tmpaddr;
28294         }
28295 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/raw.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/raw.c
28296 --- linux-2.6.32.24/net/ipv6/raw.c      2009-12-03 20:03:00.000000000 +0100
28297 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/raw.c      2009-12-03 20:04:56.000000000 +0100
28298 @@ -29,6 +29,7 @@
28299  #include <linux/icmpv6.h>
28300  #include <linux/netfilter.h>
28301  #include <linux/netfilter_ipv6.h>
28302 +#include <linux/vs_inet6.h>
28303  #include <linux/skbuff.h>
28304  #include <asm/uaccess.h>
28305  #include <asm/ioctls.h>
28306 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
28307                         }
28308                 }
28309  
28310 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
28311 +                       err = -EADDRNOTAVAIL;
28312 +                       if (dev)
28313 +                               dev_put(dev);
28314 +                       goto out;
28315 +               }
28316 +
28317                 /* ipv4 addr of the socket is invalid.  Only the
28318                  * unspecified and mapped address have a v4 equivalent.
28319                  */
28320 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/route.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/route.c
28321 --- linux-2.6.32.24/net/ipv6/route.c    2009-12-03 20:03:00.000000000 +0100
28322 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/route.c    2009-12-03 20:04:56.000000000 +0100
28323 @@ -2257,7 +2257,8 @@ static int rt6_fill_node(struct net *net
28324                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
28325                 struct in6_addr saddr_buf;
28326                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
28327 -                                      dst, 0, &saddr_buf) == 0)
28328 +                       dst, 0, &saddr_buf,
28329 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
28330                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
28331         }
28332  
28333 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/tcp_ipv6.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/tcp_ipv6.c
28334 --- linux-2.6.32.24/net/ipv6/tcp_ipv6.c 2009-12-03 20:03:00.000000000 +0100
28335 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/tcp_ipv6.c 2009-12-03 20:04:56.000000000 +0100
28336 @@ -68,6 +68,7 @@
28337  
28338  #include <linux/crypto.h>
28339  #include <linux/scatterlist.h>
28340 +#include <linux/vs_inet6.h>
28341  
28342  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
28343  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
28344 @@ -156,8 +157,15 @@ static int tcp_v6_connect(struct sock *s
28345          *      connect() to INADDR_ANY means loopback (BSD'ism).
28346          */
28347  
28348 -       if(ipv6_addr_any(&usin->sin6_addr))
28349 -               usin->sin6_addr.s6_addr[15] = 0x1;
28350 +       if(ipv6_addr_any(&usin->sin6_addr)) {
28351 +               struct nx_info *nxi =  sk->sk_nx_info;
28352 +
28353 +               if (nxi && nx_info_has_v6(nxi))
28354 +                       /* FIXME: remap lback? */
28355 +                       usin->sin6_addr = nxi->v6.ip;
28356 +               else
28357 +                       usin->sin6_addr.s6_addr[15] = 0x1;
28358 +       }
28359  
28360         addr_type = ipv6_addr_type(&usin->sin6_addr);
28361  
28362 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/udp.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/udp.c
28363 --- linux-2.6.32.24/net/ipv6/udp.c      2009-12-03 20:03:00.000000000 +0100
28364 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/udp.c      2009-12-03 20:04:56.000000000 +0100
28365 @@ -47,6 +47,7 @@
28366  
28367  #include <linux/proc_fs.h>
28368  #include <linux/seq_file.h>
28369 +#include <linux/vs_inet6.h>
28370  #include "udp_impl.h"
28371  
28372  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
28373 @@ -61,24 +62,49 @@ int ipv6_rcv_saddr_equal(const struct so
28374         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
28375  
28376         /* if both are mapped, treat as IPv4 */
28377 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
28378 -               return (!sk2_ipv6only &&
28379 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
28380 +               if (!sk2_ipv6only &&
28381                         (!sk_rcv_saddr || !sk2_rcv_saddr ||
28382 -                         sk_rcv_saddr == sk2_rcv_saddr));
28383 +                         sk_rcv_saddr == sk2_rcv_saddr))
28384 +                       goto vs_v4;
28385 +               else
28386 +                       return 0;
28387 +       }
28388  
28389         if (addr_type2 == IPV6_ADDR_ANY &&
28390             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
28391 -               return 1;
28392 +               goto vs;
28393  
28394         if (addr_type == IPV6_ADDR_ANY &&
28395             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
28396 -               return 1;
28397 +               goto vs;
28398  
28399         if (sk2_rcv_saddr6 &&
28400             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
28401 -               return 1;
28402 +               goto vs;
28403  
28404         return 0;
28405 +
28406 +vs_v4:
28407 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
28408 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28409 +       if (!sk2_rcv_saddr)
28410 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
28411 +       if (!sk_rcv_saddr)
28412 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
28413 +       return 1;
28414 +vs:
28415 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
28416 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28417 +       else if (addr_type2 == IPV6_ADDR_ANY)
28418 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
28419 +       else if (addr_type == IPV6_ADDR_ANY) {
28420 +               if (addr_type2 == IPV6_ADDR_MAPPED)
28421 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28422 +               else
28423 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
28424 +       }
28425 +       return 1;
28426  }
28427  
28428  int udp_v6_get_port(struct sock *sk, unsigned short snum)
28429 @@ -109,6 +135,10 @@ static inline int compute_score(struct s
28430                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28431                                 return -1;
28432                         score++;
28433 +               } else {
28434 +                       /* block non nx_info ips */
28435 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28436 +                               return -1;
28437                 }
28438                 if (!ipv6_addr_any(&np->daddr)) {
28439                         if (!ipv6_addr_equal(&np->daddr, saddr))
28440 diff -NurpP --minimal linux-2.6.32.24/net/ipv6/xfrm6_policy.c linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/xfrm6_policy.c
28441 --- linux-2.6.32.24/net/ipv6/xfrm6_policy.c     2009-12-03 20:03:00.000000000 +0100
28442 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/ipv6/xfrm6_policy.c     2009-12-03 20:04:56.000000000 +0100
28443 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
28444         dev = ip6_dst_idev(dst)->dev;
28445         ipv6_dev_get_saddr(dev_net(dev), dev,
28446                            (struct in6_addr *)&daddr->a6, 0,
28447 -                          (struct in6_addr *)&saddr->a6);
28448 +                          (struct in6_addr *)&saddr->a6, NULL);
28449         dst_release(dst);
28450         return 0;
28451  }
28452 diff -NurpP --minimal linux-2.6.32.24/net/netlink/af_netlink.c linux-2.6.32.24-vs2.3.0.36.29.6/net/netlink/af_netlink.c
28453 --- linux-2.6.32.24/net/netlink/af_netlink.c    2010-10-04 08:56:19.000000000 +0200
28454 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/netlink/af_netlink.c    2010-09-05 21:24:17.000000000 +0200
28455 @@ -55,6 +55,9 @@
28456  #include <linux/types.h>
28457  #include <linux/audit.h>
28458  #include <linux/mutex.h>
28459 +#include <linux/vs_context.h>
28460 +#include <linux/vs_network.h>
28461 +#include <linux/vs_limit.h>
28462  
28463  #include <net/net_namespace.h>
28464  #include <net/sock.h>
28465 @@ -1885,6 +1888,8 @@ static struct sock *netlink_seq_socket_i
28466                         sk_for_each(s, node, &hash->table[j]) {
28467                                 if (sock_net(s) != seq_file_net(seq))
28468                                         continue;
28469 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28470 +                                       continue;
28471                                 if (off == pos) {
28472                                         iter->link = i;
28473                                         iter->hash_idx = j;
28474 @@ -1919,7 +1924,8 @@ static void *netlink_seq_next(struct seq
28475         s = v;
28476         do {
28477                 s = sk_next(s);
28478 -       } while (s && sock_net(s) != seq_file_net(seq));
28479 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
28480 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
28481         if (s)
28482                 return s;
28483  
28484 @@ -1931,7 +1937,8 @@ static void *netlink_seq_next(struct seq
28485  
28486                 for (; j <= hash->mask; j++) {
28487                         s = sk_head(&hash->table[j]);
28488 -                       while (s && sock_net(s) != seq_file_net(seq))
28489 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
28490 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
28491                                 s = sk_next(s);
28492                         if (s) {
28493                                 iter->link = i;
28494 diff -NurpP --minimal linux-2.6.32.24/net/sctp/ipv6.c linux-2.6.32.24-vs2.3.0.36.29.6/net/sctp/ipv6.c
28495 --- linux-2.6.32.24/net/sctp/ipv6.c     2009-12-03 20:03:01.000000000 +0100
28496 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/sctp/ipv6.c     2009-12-03 20:04:56.000000000 +0100
28497 @@ -316,7 +316,8 @@ static void sctp_v6_get_saddr(struct sct
28498                                    dst ? ip6_dst_idev(dst)->dev : NULL,
28499                                    &daddr->v6.sin6_addr,
28500                                    inet6_sk(&sk->inet.sk)->srcprefs,
28501 -                                  &saddr->v6.sin6_addr);
28502 +                                  &saddr->v6.sin6_addr,
28503 +                                  asoc->base.sk->sk_nx_info);
28504                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
28505                                   &saddr->v6.sin6_addr);
28506                 return;
28507 diff -NurpP --minimal linux-2.6.32.24/net/socket.c linux-2.6.32.24-vs2.3.0.36.29.6/net/socket.c
28508 --- linux-2.6.32.24/net/socket.c        2009-12-03 20:03:01.000000000 +0100
28509 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/socket.c        2009-12-03 20:04:56.000000000 +0100
28510 @@ -96,6 +96,10 @@
28511  
28512  #include <net/sock.h>
28513  #include <linux/netfilter.h>
28514 +#include <linux/vs_base.h>
28515 +#include <linux/vs_socket.h>
28516 +#include <linux/vs_inet.h>
28517 +#include <linux/vs_inet6.h>
28518  
28519  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
28520  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
28521 @@ -559,7 +563,7 @@ static inline int __sock_sendmsg(struct 
28522                                  struct msghdr *msg, size_t size)
28523  {
28524         struct sock_iocb *si = kiocb_to_siocb(iocb);
28525 -       int err;
28526 +       int err, len;
28527  
28528         si->sock = sock;
28529         si->scm = NULL;
28530 @@ -570,7 +574,22 @@ static inline int __sock_sendmsg(struct 
28531         if (err)
28532                 return err;
28533  
28534 -       return sock->ops->sendmsg(iocb, sock, msg, size);
28535 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
28536 +       if (sock->sk) {
28537 +               if (len == size)
28538 +                       vx_sock_send(sock->sk, size);
28539 +               else
28540 +                       vx_sock_fail(sock->sk, size);
28541 +       }
28542 +       vxdprintk(VXD_CBIT(net, 7),
28543 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28544 +               sock, sock->sk,
28545 +               (sock->sk)?sock->sk->sk_nx_info:0,
28546 +               (sock->sk)?sock->sk->sk_vx_info:0,
28547 +               (sock->sk)?sock->sk->sk_xid:0,
28548 +               (sock->sk)?sock->sk->sk_nid:0,
28549 +               (unsigned int)size, len);
28550 +       return len;
28551  }
28552  
28553  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
28554 @@ -671,7 +690,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
28555  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
28556                                  struct msghdr *msg, size_t size, int flags)
28557  {
28558 -       int err;
28559 +       int err, len;
28560         struct sock_iocb *si = kiocb_to_siocb(iocb);
28561  
28562         si->sock = sock;
28563 @@ -684,7 +703,18 @@ static inline int __sock_recvmsg(struct 
28564         if (err)
28565                 return err;
28566  
28567 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
28568 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
28569 +       if ((len >= 0) && sock->sk)
28570 +               vx_sock_recv(sock->sk, len);
28571 +       vxdprintk(VXD_CBIT(net, 7),
28572 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28573 +               sock, sock->sk,
28574 +               (sock->sk)?sock->sk->sk_nx_info:0,
28575 +               (sock->sk)?sock->sk->sk_vx_info:0,
28576 +               (sock->sk)?sock->sk->sk_xid:0,
28577 +               (sock->sk)?sock->sk->sk_nid:0,
28578 +               (unsigned int)size, len);
28579 +       return len;
28580  }
28581  
28582  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
28583 @@ -1155,6 +1185,13 @@ static int __sock_create(struct net *net
28584         if (type < 0 || type >= SOCK_MAX)
28585                 return -EINVAL;
28586  
28587 +       if (!nx_check(0, VS_ADMIN)) {
28588 +               if (family == PF_INET && !current_nx_info_has_v4())
28589 +                       return -EAFNOSUPPORT;
28590 +               if (family == PF_INET6 && !current_nx_info_has_v6())
28591 +                       return -EAFNOSUPPORT;
28592 +       }
28593 +
28594         /* Compatibility.
28595  
28596            This uglymoron is moved from INET layer to here to avoid
28597 @@ -1287,6 +1324,7 @@ SYSCALL_DEFINE3(socket, int, family, int
28598         if (retval < 0)
28599                 goto out;
28600  
28601 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
28602         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
28603         if (retval < 0)
28604                 goto out_release;
28605 @@ -1328,10 +1366,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
28606         err = sock_create(family, type, protocol, &sock1);
28607         if (err < 0)
28608                 goto out;
28609 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
28610  
28611         err = sock_create(family, type, protocol, &sock2);
28612         if (err < 0)
28613                 goto out_release_1;
28614 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
28615  
28616         err = sock1->ops->socketpair(sock1, sock2);
28617         if (err < 0)
28618 diff -NurpP --minimal linux-2.6.32.24/net/sunrpc/auth.c linux-2.6.32.24-vs2.3.0.36.29.6/net/sunrpc/auth.c
28619 --- linux-2.6.32.24/net/sunrpc/auth.c   2009-12-03 20:03:01.000000000 +0100
28620 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/sunrpc/auth.c   2009-12-03 20:04:56.000000000 +0100
28621 @@ -14,6 +14,7 @@
28622  #include <linux/hash.h>
28623  #include <linux/sunrpc/clnt.h>
28624  #include <linux/spinlock.h>
28625 +#include <linux/vs_tag.h>
28626  
28627  #ifdef RPC_DEBUG
28628  # define RPCDBG_FACILITY       RPCDBG_AUTH
28629 @@ -360,6 +361,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
28630         memset(&acred, 0, sizeof(acred));
28631         acred.uid = cred->fsuid;
28632         acred.gid = cred->fsgid;
28633 +       acred.tag = dx_current_tag();
28634         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
28635  
28636         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
28637 @@ -400,6 +402,7 @@ rpcauth_bind_root_cred(struct rpc_task *
28638         struct auth_cred acred = {
28639                 .uid = 0,
28640                 .gid = 0,
28641 +               .tag = dx_current_tag(),
28642         };
28643         struct rpc_cred *ret;
28644  
28645 diff -NurpP --minimal linux-2.6.32.24/net/sunrpc/auth_unix.c linux-2.6.32.24-vs2.3.0.36.29.6/net/sunrpc/auth_unix.c
28646 --- linux-2.6.32.24/net/sunrpc/auth_unix.c      2008-12-25 00:26:37.000000000 +0100
28647 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/sunrpc/auth_unix.c      2009-12-03 20:04:56.000000000 +0100
28648 @@ -11,12 +11,14 @@
28649  #include <linux/module.h>
28650  #include <linux/sunrpc/clnt.h>
28651  #include <linux/sunrpc/auth.h>
28652 +#include <linux/vs_tag.h>
28653  
28654  #define NFS_NGROUPS    16
28655  
28656  struct unx_cred {
28657         struct rpc_cred         uc_base;
28658         gid_t                   uc_gid;
28659 +       tag_t                   uc_tag;
28660         gid_t                   uc_gids[NFS_NGROUPS];
28661  };
28662  #define uc_uid                 uc_base.cr_uid
28663 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
28664                 groups = NFS_NGROUPS;
28665  
28666         cred->uc_gid = acred->gid;
28667 +       cred->uc_tag = acred->tag;
28668         for (i = 0; i < groups; i++)
28669                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28670         if (i < NFS_NGROUPS)
28671 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
28672         unsigned int i;
28673  
28674  
28675 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
28676 +       if (cred->uc_uid != acred->uid ||
28677 +               cred->uc_gid != acred->gid ||
28678 +               cred->uc_tag != acred->tag)
28679                 return 0;
28680  
28681         if (acred->group_info != NULL)
28682 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
28683         struct rpc_clnt *clnt = task->tk_client;
28684         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
28685         __be32          *base, *hold;
28686 -       int             i;
28687 +       int             i, tag;
28688  
28689         *p++ = htonl(RPC_AUTH_UNIX);
28690         base = p++;
28691 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
28692          * Copy the UTS nodename captured when the client was created.
28693          */
28694         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28695 +       tag = task->tk_client->cl_tag;
28696  
28697 -       *p++ = htonl((u32) cred->uc_uid);
28698 -       *p++ = htonl((u32) cred->uc_gid);
28699 +       *p++ = htonl((u32) TAGINO_UID(tag,
28700 +               cred->uc_uid, cred->uc_tag));
28701 +       *p++ = htonl((u32) TAGINO_GID(tag,
28702 +               cred->uc_gid, cred->uc_tag));
28703         hold = p++;
28704         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28705                 *p++ = htonl((u32) cred->uc_gids[i]);
28706 diff -NurpP --minimal linux-2.6.32.24/net/sunrpc/clnt.c linux-2.6.32.24-vs2.3.0.36.29.6/net/sunrpc/clnt.c
28707 --- linux-2.6.32.24/net/sunrpc/clnt.c   2009-12-03 20:03:01.000000000 +0100
28708 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/sunrpc/clnt.c   2009-12-03 20:04:56.000000000 +0100
28709 @@ -33,6 +33,7 @@
28710  #include <linux/utsname.h>
28711  #include <linux/workqueue.h>
28712  #include <linux/in6.h>
28713 +#include <linux/vs_cvirt.h>
28714  
28715  #include <linux/sunrpc/clnt.h>
28716  #include <linux/sunrpc/rpc_pipe_fs.h>
28717 @@ -358,6 +359,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28718         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
28719                 clnt->cl_chatty = 1;
28720  
28721 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28722 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28723 +               clnt->cl_tag = 1; */
28724         return clnt;
28725  }
28726  EXPORT_SYMBOL_GPL(rpc_create);
28727 diff -NurpP --minimal linux-2.6.32.24/net/unix/af_unix.c linux-2.6.32.24-vs2.3.0.36.29.6/net/unix/af_unix.c
28728 --- linux-2.6.32.24/net/unix/af_unix.c  2010-10-04 08:56:20.000000000 +0200
28729 +++ linux-2.6.32.24-vs2.3.0.36.29.6/net/unix/af_unix.c  2010-10-04 10:04:57.000000000 +0200
28730 @@ -114,6 +114,8 @@
28731  #include <linux/mount.h>
28732  #include <net/checksum.h>
28733  #include <linux/security.h>
28734 +#include <linux/vs_context.h>
28735 +#include <linux/vs_limit.h>
28736  
28737  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28738  static DEFINE_SPINLOCK(unix_table_lock);
28739 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
28740                 if (!net_eq(sock_net(s), net))
28741                         continue;
28742  
28743 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28744 +                       continue;
28745                 if (u->addr->len == len &&
28746                     !memcmp(u->addr->name, sunname, len))
28747                         goto found;
28748 @@ -2123,6 +2127,8 @@ static struct sock *unix_seq_idx(struct 
28749         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28750                 if (sock_net(s) != seq_file_net(seq))
28751                         continue;
28752 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28753 +                       continue;
28754                 if (off == pos)
28755                         return s;
28756                 ++off;
28757 @@ -2147,7 +2153,8 @@ static void *unix_seq_next(struct seq_fi
28758                 sk = first_unix_socket(&iter->i);
28759         else
28760                 sk = next_unix_socket(&iter->i, sk);
28761 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28762 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28763 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28764                 sk = next_unix_socket(&iter->i, sk);
28765         return sk;
28766  }
28767 diff -NurpP --minimal linux-2.6.32.24/scripts/checksyscalls.sh linux-2.6.32.24-vs2.3.0.36.29.6/scripts/checksyscalls.sh
28768 --- linux-2.6.32.24/scripts/checksyscalls.sh    2009-09-10 15:26:31.000000000 +0200
28769 +++ linux-2.6.32.24-vs2.3.0.36.29.6/scripts/checksyscalls.sh    2009-12-03 20:04:56.000000000 +0100
28770 @@ -194,7 +194,6 @@ cat << EOF
28771  #define __IGNORE_afs_syscall
28772  #define __IGNORE_getpmsg
28773  #define __IGNORE_putpmsg
28774 -#define __IGNORE_vserver
28775  EOF
28776  }
28777  
28778 diff -NurpP --minimal linux-2.6.32.24/security/commoncap.c linux-2.6.32.24-vs2.3.0.36.29.6/security/commoncap.c
28779 --- linux-2.6.32.24/security/commoncap.c        2009-12-03 20:03:02.000000000 +0100
28780 +++ linux-2.6.32.24-vs2.3.0.36.29.6/security/commoncap.c        2010-03-13 21:50:18.000000000 +0100
28781 @@ -27,6 +27,7 @@
28782  #include <linux/sched.h>
28783  #include <linux/prctl.h>
28784  #include <linux/securebits.h>
28785 +#include <linux/vs_context.h>
28786  
28787  /*
28788   * If a non-root user executes a setuid-root binary in
28789 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
28790  
28791  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28792  {
28793 -       NETLINK_CB(skb).eff_cap = current_cap();
28794 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
28795         return 0;
28796  }
28797  
28798 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
28799                 return -EPERM;
28800         return 0;
28801  }
28802 +
28803  EXPORT_SYMBOL(cap_netlink_recv);
28804  
28805  /**
28806 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
28807  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
28808                 int audit)
28809  {
28810 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
28811 +       struct vx_info *vxi = tsk->vx_info;
28812 +
28813 +#if 0
28814 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28815 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28816 +               cap_raised(tsk->cap_effective, cap),
28817 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28818 +#endif
28819 +
28820 +       /* special case SETUP */
28821 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28822 +               /* FIXME: maybe use cred instead? */
28823 +               cap_raised(tsk->cred->cap_effective, cap))
28824 +               return 0;
28825 +
28826 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
28827  }
28828  
28829  /**
28830 @@ -618,7 +635,7 @@ int cap_inode_setxattr(struct dentry *de
28831  
28832         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28833                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28834 -           !capable(CAP_SYS_ADMIN))
28835 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28836                 return -EPERM;
28837         return 0;
28838  }
28839 @@ -644,7 +661,7 @@ int cap_inode_removexattr(struct dentry 
28840  
28841         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28842                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28843 -           !capable(CAP_SYS_ADMIN))
28844 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28845                 return -EPERM;
28846         return 0;
28847  }
28848 @@ -962,7 +979,8 @@ error:
28849   */
28850  int cap_syslog(int type)
28851  {
28852 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28853 +       if ((type != 3 && type != 10) &&
28854 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28855                 return -EPERM;
28856         return 0;
28857  }
28858 diff -NurpP --minimal linux-2.6.32.24/security/selinux/hooks.c linux-2.6.32.24-vs2.3.0.36.29.6/security/selinux/hooks.c
28859 --- linux-2.6.32.24/security/selinux/hooks.c    2010-10-04 08:56:20.000000000 +0200
28860 +++ linux-2.6.32.24-vs2.3.0.36.29.6/security/selinux/hooks.c    2010-02-12 10:59:55.000000000 +0100
28861 @@ -64,7 +64,6 @@
28862  #include <linux/dccp.h>
28863  #include <linux/quota.h>
28864  #include <linux/un.h>          /* for Unix socket types */
28865 -#include <net/af_unix.h>       /* for Unix socket types */
28866  #include <linux/parser.h>
28867  #include <linux/nfs_mount.h>
28868  #include <net/ipv6.h>
28869 diff -NurpP --minimal linux-2.6.32.24/security/selinux/include/av_permissions.h linux-2.6.32.24-vs2.3.0.36.29.6/security/selinux/include/av_permissions.h
28870 --- linux-2.6.32.24/security/selinux/include/av_permissions.h   2009-12-03 20:03:02.000000000 +0100
28871 +++ linux-2.6.32.24-vs2.3.0.36.29.6/security/selinux/include/av_permissions.h   2009-12-03 20:04:56.000000000 +0100
28872 @@ -565,6 +565,7 @@
28873  #define CAPABILITY__SETFCAP                       0x80000000UL
28874  #define CAPABILITY2__MAC_OVERRIDE                 0x00000001UL
28875  #define CAPABILITY2__MAC_ADMIN                    0x00000002UL
28876 +#define CAPABILITY2__CONTEXT                      0x00000004UL
28877  #define NETLINK_ROUTE_SOCKET__IOCTL               0x00000001UL
28878  #define NETLINK_ROUTE_SOCKET__READ                0x00000002UL
28879  #define NETLINK_ROUTE_SOCKET__WRITE               0x00000004UL
28880 diff -NurpP --minimal linux-2.6.32.24/security/selinux/include/av_perm_to_string.h linux-2.6.32.24-vs2.3.0.36.29.6/security/selinux/include/av_perm_to_string.h
28881 --- linux-2.6.32.24/security/selinux/include/av_perm_to_string.h        2009-12-03 20:03:02.000000000 +0100
28882 +++ linux-2.6.32.24-vs2.3.0.36.29.6/security/selinux/include/av_perm_to_string.h        2009-12-03 20:04:56.000000000 +0100
28883 @@ -142,6 +142,7 @@
28884     S_(SECCLASS_CAPABILITY, CAPABILITY__SETFCAP, "setfcap")
28885     S_(SECCLASS_CAPABILITY2, CAPABILITY2__MAC_OVERRIDE, "mac_override")
28886     S_(SECCLASS_CAPABILITY2, CAPABILITY2__MAC_ADMIN, "mac_admin")
28887 +   S_(SECCLASS_CAPABILITY2, CAPABILITY2__CONTEXT, "context")
28888     S_(SECCLASS_NETLINK_ROUTE_SOCKET, NETLINK_ROUTE_SOCKET__NLMSG_READ, "nlmsg_read")
28889     S_(SECCLASS_NETLINK_ROUTE_SOCKET, NETLINK_ROUTE_SOCKET__NLMSG_WRITE, "nlmsg_write")
28890     S_(SECCLASS_NETLINK_FIREWALL_SOCKET, NETLINK_FIREWALL_SOCKET__NLMSG_READ, "nlmsg_read")
This page took 2.949838 seconds and 4 git commands to generate.