]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- rel 3; updated vserver (credentials fixed) and grsecurity
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.37/arch/alpha/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/alpha/Kconfig
2 --- linux-2.6.37/arch/alpha/Kconfig     2011-01-05 21:48:40.000000000 +0100
3 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/alpha/Kconfig      2010-11-23 02:09:40.000000000 +0100
4 @@ -677,6 +677,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.37/arch/alpha/kernel/entry.S linux-2.6.37-vs2.3.0.37-rc3/arch/alpha/kernel/entry.S
14 --- linux-2.6.37/arch/alpha/kernel/entry.S      2010-10-21 13:06:45.000000000 +0200
15 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/alpha/kernel/entry.S       2010-11-23 02:09:40.000000000 +0100
16 @@ -860,24 +860,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.37/arch/alpha/kernel/ptrace.c linux-2.6.37-vs2.3.0.37-rc3/arch/alpha/kernel/ptrace.c
49 --- linux-2.6.37/arch/alpha/kernel/ptrace.c     2011-01-05 21:48:40.000000000 +0100
50 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/alpha/kernel/ptrace.c      2010-11-23 02:09:40.000000000 +0100
51 @@ -13,6 +13,7 @@
52  #include <linux/user.h>
53  #include <linux/security.h>
54  #include <linux/signal.h>
55 +#include <linux/vs_base.h>
56  
57  #include <asm/uaccess.h>
58  #include <asm/pgtable.h>
59 diff -NurpP --minimal linux-2.6.37/arch/alpha/kernel/systbls.S linux-2.6.37-vs2.3.0.37-rc3/arch/alpha/kernel/systbls.S
60 --- linux-2.6.37/arch/alpha/kernel/systbls.S    2010-10-21 13:06:46.000000000 +0200
61 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/alpha/kernel/systbls.S     2010-11-23 02:09:40.000000000 +0100
62 @@ -446,7 +446,7 @@ sys_call_table:
63         .quad sys_stat64                        /* 425 */
64         .quad sys_lstat64
65         .quad sys_fstat64
66 -       .quad sys_ni_syscall                    /* sys_vserver */
67 +       .quad sys_vserver                       /* sys_vserver */
68         .quad sys_ni_syscall                    /* sys_mbind */
69         .quad sys_ni_syscall                    /* sys_get_mempolicy */
70         .quad sys_ni_syscall                    /* sys_set_mempolicy */
71 diff -NurpP --minimal linux-2.6.37/arch/alpha/kernel/traps.c linux-2.6.37-vs2.3.0.37-rc3/arch/alpha/kernel/traps.c
72 --- linux-2.6.37/arch/alpha/kernel/traps.c      2010-10-21 13:06:46.000000000 +0200
73 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/alpha/kernel/traps.c       2010-11-23 02:09:40.000000000 +0100
74 @@ -183,7 +183,8 @@ die_if_kernel(char * str, struct pt_regs
75  #ifdef CONFIG_SMP
76         printk("CPU %d ", hard_smp_processor_id());
77  #endif
78 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
79 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
80 +               task_pid_nr(current), current->xid, str, err);
81         dik_show_regs(regs, r9_15);
82         add_taint(TAINT_DIE);
83         dik_show_trace((unsigned long *)(regs+1));
84 diff -NurpP --minimal linux-2.6.37/arch/arm/include/asm/tlb.h linux-2.6.37-vs2.3.0.37-rc3/arch/arm/include/asm/tlb.h
85 --- linux-2.6.37/arch/arm/include/asm/tlb.h     2009-09-10 15:25:15.000000000 +0200
86 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/arm/include/asm/tlb.h      2010-11-23 02:09:40.000000000 +0100
87 @@ -27,6 +27,7 @@
88  
89  #else /* !CONFIG_MMU */
90  
91 +#include <linux/vs_memory.h>
92  #include <asm/pgalloc.h>
93  
94  /*
95 diff -NurpP --minimal linux-2.6.37/arch/arm/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/arm/Kconfig
96 --- linux-2.6.37/arch/arm/Kconfig       2011-01-05 21:48:40.000000000 +0100
97 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/arm/Kconfig        2011-01-05 22:30:25.000000000 +0100
98 @@ -1854,6 +1854,8 @@ source "fs/Kconfig"
99  
100  source "arch/arm/Kconfig.debug"
101  
102 +source "kernel/vserver/Kconfig"
103 +
104  source "security/Kconfig"
105  
106  source "crypto/Kconfig"
107 diff -NurpP --minimal linux-2.6.37/arch/arm/kernel/calls.S linux-2.6.37-vs2.3.0.37-rc3/arch/arm/kernel/calls.S
108 --- linux-2.6.37/arch/arm/kernel/calls.S        2010-10-21 13:06:46.000000000 +0200
109 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/arm/kernel/calls.S 2010-11-23 02:09:40.000000000 +0100
110 @@ -322,7 +322,7 @@
111  /* 310 */      CALL(sys_request_key)
112                 CALL(sys_keyctl)
113                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
114 -/* vserver */  CALL(sys_ni_syscall)
115 +               CALL(sys_vserver)
116                 CALL(sys_ioprio_set)
117  /* 315 */      CALL(sys_ioprio_get)
118                 CALL(sys_inotify_init)
119 diff -NurpP --minimal linux-2.6.37/arch/arm/kernel/process.c linux-2.6.37-vs2.3.0.37-rc3/arch/arm/kernel/process.c
120 --- linux-2.6.37/arch/arm/kernel/process.c      2011-01-05 21:48:42.000000000 +0100
121 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/arm/kernel/process.c       2010-11-23 02:09:40.000000000 +0100
122 @@ -315,7 +315,8 @@ void __show_regs(struct pt_regs *regs)
123  void show_regs(struct pt_regs * regs)
124  {
125         printk("\n");
126 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
127 +       printk("Pid: %d[#%u], comm: %20s\n",
128 +               task_pid_nr(current), current->xid, current->comm);
129         __show_regs(regs);
130         __backtrace();
131  }
132 diff -NurpP --minimal linux-2.6.37/arch/arm/kernel/traps.c linux-2.6.37-vs2.3.0.37-rc3/arch/arm/kernel/traps.c
133 --- linux-2.6.37/arch/arm/kernel/traps.c        2011-01-05 21:48:42.000000000 +0100
134 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/arm/kernel/traps.c 2010-11-23 02:09:40.000000000 +0100
135 @@ -241,8 +241,8 @@ static int __die(const char *str, int er
136  
137         print_modules();
138         __show_regs(regs);
139 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
140 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
141 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
142 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
143  
144         if (!user_mode(regs) || in_interrupt()) {
145                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
146 diff -NurpP --minimal linux-2.6.37/arch/cris/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/cris/Kconfig
147 --- linux-2.6.37/arch/cris/Kconfig      2011-01-05 21:48:58.000000000 +0100
148 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/cris/Kconfig       2010-11-23 02:09:40.000000000 +0100
149 @@ -687,6 +687,8 @@ source "drivers/staging/Kconfig"
150  
151  source "arch/cris/Kconfig.debug"
152  
153 +source "kernel/vserver/Kconfig"
154 +
155  source "security/Kconfig"
156  
157  source "crypto/Kconfig"
158 diff -NurpP --minimal linux-2.6.37/arch/frv/kernel/kernel_thread.S linux-2.6.37-vs2.3.0.37-rc3/arch/frv/kernel/kernel_thread.S
159 --- linux-2.6.37/arch/frv/kernel/kernel_thread.S        2008-12-25 00:26:37.000000000 +0100
160 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/frv/kernel/kernel_thread.S 2010-11-23 02:09:40.000000000 +0100
161 @@ -37,7 +37,7 @@ kernel_thread:
162  
163         # start by forking the current process, but with shared VM
164         setlos.p        #__NR_clone,gr7         ; syscall number
165 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
166 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
167         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
168         setlo           #0xe4e4,gr9
169         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
170 diff -NurpP --minimal linux-2.6.37/arch/h8300/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/h8300/Kconfig
171 --- linux-2.6.37/arch/h8300/Kconfig     2011-01-05 21:48:59.000000000 +0100
172 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/h8300/Kconfig      2010-11-23 02:09:40.000000000 +0100
173 @@ -219,6 +219,8 @@ source "fs/Kconfig"
174  
175  source "arch/h8300/Kconfig.debug"
176  
177 +source "kernel/vserver/Kconfig"
178 +
179  source "security/Kconfig"
180  
181  source "crypto/Kconfig"
182 diff -NurpP --minimal linux-2.6.37/arch/ia64/include/asm/tlb.h linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/include/asm/tlb.h
183 --- linux-2.6.37/arch/ia64/include/asm/tlb.h    2010-02-25 11:51:26.000000000 +0100
184 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/include/asm/tlb.h     2010-11-23 02:09:40.000000000 +0100
185 @@ -40,6 +40,7 @@
186  #include <linux/mm.h>
187  #include <linux/pagemap.h>
188  #include <linux/swap.h>
189 +#include <linux/vs_memory.h>
190  
191  #include <asm/pgalloc.h>
192  #include <asm/processor.h>
193 diff -NurpP --minimal linux-2.6.37/arch/ia64/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/Kconfig
194 --- linux-2.6.37/arch/ia64/Kconfig      2011-01-05 21:48:59.000000000 +0100
195 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/Kconfig       2010-11-23 02:09:40.000000000 +0100
196 @@ -670,6 +670,8 @@ source "fs/Kconfig"
197  
198  source "arch/ia64/Kconfig.debug"
199  
200 +source "kernel/vserver/Kconfig"
201 +
202  source "security/Kconfig"
203  
204  source "crypto/Kconfig"
205 diff -NurpP --minimal linux-2.6.37/arch/ia64/kernel/entry.S linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/kernel/entry.S
206 --- linux-2.6.37/arch/ia64/kernel/entry.S       2010-10-21 13:06:52.000000000 +0200
207 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/kernel/entry.S        2010-11-23 02:09:40.000000000 +0100
208 @@ -1714,7 +1714,7 @@ sys_call_table:
209         data8 sys_mq_notify
210         data8 sys_mq_getsetattr
211         data8 sys_kexec_load
212 -       data8 sys_ni_syscall                    // reserved for vserver
213 +       data8 sys_vserver
214         data8 sys_waitid                        // 1270
215         data8 sys_add_key
216         data8 sys_request_key
217 diff -NurpP --minimal linux-2.6.37/arch/ia64/kernel/perfmon.c linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/kernel/perfmon.c
218 --- linux-2.6.37/arch/ia64/kernel/perfmon.c     2011-01-05 21:48:59.000000000 +0100
219 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/kernel/perfmon.c      2010-11-23 02:09:40.000000000 +0100
220 @@ -42,6 +42,7 @@
221  #include <linux/completion.h>
222  #include <linux/tracehook.h>
223  #include <linux/slab.h>
224 +#include <linux/vs_memory.h>
225  
226  #include <asm/errno.h>
227  #include <asm/intrinsics.h>
228 diff -NurpP --minimal linux-2.6.37/arch/ia64/kernel/process.c linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/kernel/process.c
229 --- linux-2.6.37/arch/ia64/kernel/process.c     2010-10-21 13:06:52.000000000 +0200
230 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/kernel/process.c      2010-11-23 02:09:40.000000000 +0100
231 @@ -113,8 +113,8 @@ show_regs (struct pt_regs *regs)
232         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
233  
234         print_modules();
235 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
236 -                       smp_processor_id(), current->comm);
237 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
238 +                       current->xid, smp_processor_id(), current->comm);
239         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
240                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
241                init_utsname()->release);
242 diff -NurpP --minimal linux-2.6.37/arch/ia64/kernel/ptrace.c linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/kernel/ptrace.c
243 --- linux-2.6.37/arch/ia64/kernel/ptrace.c      2011-01-05 21:48:59.000000000 +0100
244 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/kernel/ptrace.c       2010-11-23 02:09:40.000000000 +0100
245 @@ -21,6 +21,7 @@
246  #include <linux/regset.h>
247  #include <linux/elf.h>
248  #include <linux/tracehook.h>
249 +#include <linux/vs_base.h>
250  
251  #include <asm/pgtable.h>
252  #include <asm/processor.h>
253 diff -NurpP --minimal linux-2.6.37/arch/ia64/kernel/traps.c linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/kernel/traps.c
254 --- linux-2.6.37/arch/ia64/kernel/traps.c       2010-07-07 18:31:01.000000000 +0200
255 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/kernel/traps.c        2010-11-23 02:09:40.000000000 +0100
256 @@ -59,8 +59,9 @@ die (const char *str, struct pt_regs *re
257         put_cpu();
258  
259         if (++die.lock_owner_depth < 3) {
260 -               printk("%s[%d]: %s %ld [%d]\n",
261 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
262 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
263 +                       current->comm, task_pid_nr(current), current->xid,
264 +                       str, err, ++die_counter);
265                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
266                     != NOTIFY_STOP)
267                         show_regs(regs);
268 @@ -323,8 +324,9 @@ handle_fpu_swa (int fp_fault, struct pt_
269                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
270                                 last.time = current_jiffies + 5 * HZ;
271                                 printk(KERN_WARNING
272 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
273 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
274 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
275 +                                       current->comm, task_pid_nr(current), current->xid,
276 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
277                         }
278                 }
279         }
280 diff -NurpP --minimal linux-2.6.37/arch/ia64/mm/fault.c linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/mm/fault.c
281 --- linux-2.6.37/arch/ia64/mm/fault.c   2010-08-02 16:52:04.000000000 +0200
282 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/ia64/mm/fault.c    2010-11-23 02:09:40.000000000 +0100
283 @@ -10,6 +10,7 @@
284  #include <linux/interrupt.h>
285  #include <linux/kprobes.h>
286  #include <linux/kdebug.h>
287 +#include <linux/vs_memory.h>
288  
289  #include <asm/pgtable.h>
290  #include <asm/processor.h>
291 diff -NurpP --minimal linux-2.6.37/arch/m32r/kernel/traps.c linux-2.6.37-vs2.3.0.37-rc3/arch/m32r/kernel/traps.c
292 --- linux-2.6.37/arch/m32r/kernel/traps.c       2009-12-03 20:01:57.000000000 +0100
293 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/m32r/kernel/traps.c        2010-11-23 02:09:40.000000000 +0100
294 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
295         } else {
296                 printk("SPI: %08lx\n", sp);
297         }
298 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
299 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
300 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
301 +               current->comm, task_pid_nr(current), current->xid,
302 +               0xffff & i, 4096+(unsigned long)current);
303  
304         /*
305          * When in-kernel, we also print out the stack and code at the
306 diff -NurpP --minimal linux-2.6.37/arch/m68k/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/m68k/Kconfig
307 --- linux-2.6.37/arch/m68k/Kconfig      2011-01-05 21:49:00.000000000 +0100
308 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/m68k/Kconfig       2010-11-23 02:09:40.000000000 +0100
309 @@ -610,6 +610,8 @@ source "fs/Kconfig"
310  
311  source "arch/m68k/Kconfig.debug"
312  
313 +source "kernel/vserver/Kconfig"
314 +
315  source "security/Kconfig"
316  
317  source "crypto/Kconfig"
318 diff -NurpP --minimal linux-2.6.37/arch/m68k/kernel/ptrace.c linux-2.6.37-vs2.3.0.37-rc3/arch/m68k/kernel/ptrace.c
319 --- linux-2.6.37/arch/m68k/kernel/ptrace.c      2011-01-05 21:49:01.000000000 +0100
320 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/m68k/kernel/ptrace.c       2010-11-23 02:09:40.000000000 +0100
321 @@ -18,6 +18,7 @@
322  #include <linux/ptrace.h>
323  #include <linux/user.h>
324  #include <linux/signal.h>
325 +#include <linux/vs_base.h>
326  
327  #include <asm/uaccess.h>
328  #include <asm/page.h>
329 @@ -255,6 +256,8 @@ long arch_ptrace(struct task_struct *chi
330                 ret = ptrace_request(child, request, addr, data);
331                 break;
332         }
333 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
334 +               goto out_tsk;
335  
336         return ret;
337  out_eio:
338 diff -NurpP --minimal linux-2.6.37/arch/m68k/kernel/traps.c linux-2.6.37-vs2.3.0.37-rc3/arch/m68k/kernel/traps.c
339 --- linux-2.6.37/arch/m68k/kernel/traps.c       2010-08-02 16:52:04.000000000 +0200
340 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/m68k/kernel/traps.c        2010-11-23 02:09:40.000000000 +0100
341 @@ -906,8 +906,8 @@ void show_registers(struct pt_regs *regs
342         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
343                regs->d4, regs->d5, regs->a0, regs->a1);
344  
345 -       printk("Process %s (pid: %d, task=%p)\n",
346 -               current->comm, task_pid_nr(current), current);
347 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
348 +               current->comm, task_pid_nr(current), current->xid, current);
349         addr = (unsigned long)&fp->un;
350         printk("Frame format=%X ", regs->format);
351         switch (regs->format) {
352 diff -NurpP --minimal linux-2.6.37/arch/m68knommu/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/m68knommu/Kconfig
353 --- linux-2.6.37/arch/m68knommu/Kconfig 2011-01-05 21:49:01.000000000 +0100
354 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/m68knommu/Kconfig  2010-11-23 02:09:40.000000000 +0100
355 @@ -732,6 +732,8 @@ source "fs/Kconfig"
356  
357  source "arch/m68knommu/Kconfig.debug"
358  
359 +source "kernel/vserver/Kconfig"
360 +
361  source "security/Kconfig"
362  
363  source "crypto/Kconfig"
364 diff -NurpP --minimal linux-2.6.37/arch/m68knommu/kernel/traps.c linux-2.6.37-vs2.3.0.37-rc3/arch/m68knommu/kernel/traps.c
365 --- linux-2.6.37/arch/m68knommu/kernel/traps.c  2011-01-05 21:49:01.000000000 +0100
366 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/m68knommu/kernel/traps.c   2010-11-23 02:09:40.000000000 +0100
367 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
368         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
369                fp->d4, fp->d5, fp->a0, fp->a1);
370  
371 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
372 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
373 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
374 +               current->comm, task_pid_nr(current), current->xid,
375 +               PAGE_SIZE+(unsigned long)current);
376         show_stack(NULL, (unsigned long *)(fp + 1));
377         add_taint(TAINT_DIE);
378         do_exit(SIGSEGV);
379 diff -NurpP --minimal linux-2.6.37/arch/mips/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/mips/Kconfig
380 --- linux-2.6.37/arch/mips/Kconfig      2011-01-05 21:49:03.000000000 +0100
381 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/mips/Kconfig       2011-01-05 22:30:26.000000000 +0100
382 @@ -2396,6 +2396,8 @@ source "fs/Kconfig"
383  
384  source "arch/mips/Kconfig.debug"
385  
386 +source "kernel/vserver/Kconfig"
387 +
388  source "security/Kconfig"
389  
390  source "crypto/Kconfig"
391 diff -NurpP --minimal linux-2.6.37/arch/mips/kernel/ptrace.c linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/ptrace.c
392 --- linux-2.6.37/arch/mips/kernel/ptrace.c      2011-01-05 21:49:06.000000000 +0100
393 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/ptrace.c       2010-11-23 02:09:40.000000000 +0100
394 @@ -25,6 +25,7 @@
395  #include <linux/security.h>
396  #include <linux/audit.h>
397  #include <linux/seccomp.h>
398 +#include <linux/vs_base.h>
399  
400  #include <asm/byteorder.h>
401  #include <asm/cpu.h>
402 @@ -263,6 +264,9 @@ long arch_ptrace(struct task_struct *chi
403         void __user *datavp = (void __user *) data;
404         unsigned long __user *datalp = (void __user *) data;
405  
406 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
407 +               goto out;
408 +
409         switch (request) {
410         /* when I and D space are separate, these will need to be fixed. */
411         case PTRACE_PEEKTEXT: /* read word at location addr. */
412 diff -NurpP --minimal linux-2.6.37/arch/mips/kernel/scall32-o32.S linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/scall32-o32.S
413 --- linux-2.6.37/arch/mips/kernel/scall32-o32.S 2010-10-21 13:06:54.000000000 +0200
414 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/scall32-o32.S  2010-11-23 02:09:40.000000000 +0100
415 @@ -524,7 +524,7 @@ einval:     li      v0, -ENOSYS
416         sys     sys_mq_timedreceive     5
417         sys     sys_mq_notify           2       /* 4275 */
418         sys     sys_mq_getsetattr       3
419 -       sys     sys_ni_syscall          0       /* sys_vserver */
420 +       sys     sys_vserver             3
421         sys     sys_waitid              5
422         sys     sys_ni_syscall          0       /* available, was setaltroot */
423         sys     sys_add_key             5       /* 4280 */
424 diff -NurpP --minimal linux-2.6.37/arch/mips/kernel/scall64-64.S linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/scall64-64.S
425 --- linux-2.6.37/arch/mips/kernel/scall64-64.S  2010-10-21 13:06:54.000000000 +0200
426 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/scall64-64.S   2010-11-23 02:09:40.000000000 +0100
427 @@ -363,7 +363,7 @@ sys_call_table:
428         PTR     sys_mq_timedreceive
429         PTR     sys_mq_notify
430         PTR     sys_mq_getsetattr               /* 5235 */
431 -       PTR     sys_ni_syscall                  /* sys_vserver */
432 +       PTR     sys_vserver
433         PTR     sys_waitid
434         PTR     sys_ni_syscall                  /* available, was setaltroot */
435         PTR     sys_add_key
436 diff -NurpP --minimal linux-2.6.37/arch/mips/kernel/scall64-n32.S linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/scall64-n32.S
437 --- linux-2.6.37/arch/mips/kernel/scall64-n32.S 2010-10-21 13:06:54.000000000 +0200
438 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/scall64-n32.S  2010-11-23 02:09:40.000000000 +0100
439 @@ -362,7 +362,7 @@ EXPORT(sysn32_call_table)
440         PTR     compat_sys_mq_timedreceive
441         PTR     compat_sys_mq_notify
442         PTR     compat_sys_mq_getsetattr
443 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
444 +       PTR     sys32_vserver                   /* 6240 */
445         PTR     compat_sys_waitid
446         PTR     sys_ni_syscall                  /* available, was setaltroot */
447         PTR     sys_add_key
448 diff -NurpP --minimal linux-2.6.37/arch/mips/kernel/scall64-o32.S linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/scall64-o32.S
449 --- linux-2.6.37/arch/mips/kernel/scall64-o32.S 2010-10-21 13:06:54.000000000 +0200
450 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/scall64-o32.S  2010-11-23 02:09:40.000000000 +0100
451 @@ -481,7 +481,7 @@ sys_call_table:
452         PTR     compat_sys_mq_timedreceive
453         PTR     compat_sys_mq_notify            /* 4275 */
454         PTR     compat_sys_mq_getsetattr
455 -       PTR     sys_ni_syscall                  /* sys_vserver */
456 +       PTR     sys32_vserver
457         PTR     sys_32_waitid
458         PTR     sys_ni_syscall                  /* available, was setaltroot */
459         PTR     sys_add_key                     /* 4280 */
460 diff -NurpP --minimal linux-2.6.37/arch/mips/kernel/traps.c linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/traps.c
461 --- linux-2.6.37/arch/mips/kernel/traps.c       2011-01-05 21:49:06.000000000 +0100
462 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/mips/kernel/traps.c        2011-01-05 22:30:26.000000000 +0100
463 @@ -343,9 +343,10 @@ void show_registers(struct pt_regs *regs
464  
465         __show_regs(regs);
466         print_modules();
467 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
468 -              current->comm, current->pid, current_thread_info(), current,
469 -             field, current_thread_info()->tp_value);
470 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
471 +               current->comm, task_pid_nr(current), current->xid,
472 +               current_thread_info(), current,
473 +               field, current_thread_info()->tp_value);
474         if (cpu_has_userlocal) {
475                 unsigned long tls;
476  
477 diff -NurpP --minimal linux-2.6.37/arch/parisc/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/parisc/Kconfig
478 --- linux-2.6.37/arch/parisc/Kconfig    2011-01-05 21:49:08.000000000 +0100
479 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/parisc/Kconfig     2010-11-23 02:09:40.000000000 +0100
480 @@ -293,6 +293,8 @@ source "fs/Kconfig"
481  
482  source "arch/parisc/Kconfig.debug"
483  
484 +source "kernel/vserver/Kconfig"
485 +
486  source "security/Kconfig"
487  
488  source "crypto/Kconfig"
489 diff -NurpP --minimal linux-2.6.37/arch/parisc/kernel/syscall_table.S linux-2.6.37-vs2.3.0.37-rc3/arch/parisc/kernel/syscall_table.S
490 --- linux-2.6.37/arch/parisc/kernel/syscall_table.S     2011-01-05 21:49:09.000000000 +0100
491 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/parisc/kernel/syscall_table.S      2010-11-23 02:09:40.000000000 +0100
492 @@ -361,7 +361,7 @@
493         ENTRY_COMP(mbind)               /* 260 */
494         ENTRY_COMP(get_mempolicy)
495         ENTRY_COMP(set_mempolicy)
496 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
497 +       ENTRY_DIFF(vserver)
498         ENTRY_SAME(add_key)
499         ENTRY_SAME(request_key)         /* 265 */
500         ENTRY_SAME(keyctl)
501 diff -NurpP --minimal linux-2.6.37/arch/parisc/kernel/traps.c linux-2.6.37-vs2.3.0.37-rc3/arch/parisc/kernel/traps.c
502 --- linux-2.6.37/arch/parisc/kernel/traps.c     2009-09-10 15:25:40.000000000 +0200
503 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/parisc/kernel/traps.c      2010-11-23 02:09:40.000000000 +0100
504 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
505                 if (err == 0)
506                         return; /* STFU */
507  
508 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
509 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
510 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
511 +                       current->comm, task_pid_nr(current), current->xid,
512 +                       str, err, regs->iaoq[0]);
513  #ifdef PRINT_USER_FAULTS
514                 /* XXX for debugging only */
515                 show_regs(regs);
516 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
517                 pdc_console_restart();
518         
519         if (err)
520 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
521 -                       current->comm, task_pid_nr(current), str, err);
522 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
523 +                       current->comm, task_pid_nr(current), current->xid, str, err);
524  
525         /* Wot's wrong wif bein' racy? */
526         if (current->thread.flags & PARISC_KERNEL_DEATH) {
527 diff -NurpP --minimal linux-2.6.37/arch/parisc/mm/fault.c linux-2.6.37-vs2.3.0.37-rc3/arch/parisc/mm/fault.c
528 --- linux-2.6.37/arch/parisc/mm/fault.c 2010-08-02 16:52:06.000000000 +0200
529 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/parisc/mm/fault.c  2010-11-23 02:09:40.000000000 +0100
530 @@ -237,8 +237,9 @@ bad_area:
531  
532  #ifdef PRINT_USER_FAULTS
533                 printk(KERN_DEBUG "\n");
534 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
535 -                   task_pid_nr(tsk), tsk->comm, code, address);
536 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
537 +                   "command='%s' type=%lu address=0x%08lx\n",
538 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
539                 if (vma) {
540                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
541                                         vma->vm_start, vma->vm_end);
542 diff -NurpP --minimal linux-2.6.37/arch/powerpc/include/asm/unistd.h linux-2.6.37-vs2.3.0.37-rc3/arch/powerpc/include/asm/unistd.h
543 --- linux-2.6.37/arch/powerpc/include/asm/unistd.h      2011-01-05 21:49:10.000000000 +0100
544 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/powerpc/include/asm/unistd.h       2010-11-23 02:09:40.000000000 +0100
545 @@ -275,7 +275,7 @@
546  #endif
547  #define __NR_rtas              255
548  #define __NR_sys_debug_setcontext 256
549 -/* Number 257 is reserved for vserver */
550 +#define __NR_vserver           257
551  #define __NR_migrate_pages     258
552  #define __NR_mbind             259
553  #define __NR_get_mempolicy     260
554 diff -NurpP --minimal linux-2.6.37/arch/powerpc/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/powerpc/Kconfig
555 --- linux-2.6.37/arch/powerpc/Kconfig   2011-01-05 21:49:09.000000000 +0100
556 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/powerpc/Kconfig    2010-11-23 02:09:40.000000000 +0100
557 @@ -976,6 +976,8 @@ source "lib/Kconfig"
558  
559  source "arch/powerpc/Kconfig.debug"
560  
561 +source "kernel/vserver/Kconfig"
562 +
563  source "security/Kconfig"
564  
565  config KEYS_COMPAT
566 diff -NurpP --minimal linux-2.6.37/arch/powerpc/kernel/process.c linux-2.6.37-vs2.3.0.37-rc3/arch/powerpc/kernel/process.c
567 --- linux-2.6.37/arch/powerpc/kernel/process.c  2011-01-05 21:49:11.000000000 +0100
568 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/powerpc/kernel/process.c   2010-11-23 02:09:40.000000000 +0100
569 @@ -633,8 +633,9 @@ void show_regs(struct pt_regs * regs)
570  #else
571                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
572  #endif
573 -       printk("TASK = %p[%d] '%s' THREAD: %p",
574 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
575 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
576 +              current, task_pid_nr(current), current->xid,
577 +              current->comm, task_thread_info(current));
578  
579  #ifdef CONFIG_SMP
580         printk(" CPU: %d", raw_smp_processor_id());
581 diff -NurpP --minimal linux-2.6.37/arch/powerpc/kernel/traps.c linux-2.6.37-vs2.3.0.37-rc3/arch/powerpc/kernel/traps.c
582 --- linux-2.6.37/arch/powerpc/kernel/traps.c    2011-01-05 21:49:11.000000000 +0100
583 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/powerpc/kernel/traps.c     2010-11-23 02:09:40.000000000 +0100
584 @@ -1053,8 +1053,9 @@ void nonrecoverable_exception(struct pt_
585  
586  void trace_syscall(struct pt_regs *regs)
587  {
588 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
589 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
590 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
591 +              current, task_pid_nr(current), current->xid,
592 +              regs->nip, regs->link, regs->gpr[0],
593                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
594  }
595  
596 diff -NurpP --minimal linux-2.6.37/arch/powerpc/kernel/vdso.c linux-2.6.37-vs2.3.0.37-rc3/arch/powerpc/kernel/vdso.c
597 --- linux-2.6.37/arch/powerpc/kernel/vdso.c     2011-01-05 21:49:11.000000000 +0100
598 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/powerpc/kernel/vdso.c      2010-11-23 02:09:40.000000000 +0100
599 @@ -23,6 +23,7 @@
600  #include <linux/security.h>
601  #include <linux/bootmem.h>
602  #include <linux/memblock.h>
603 +#include <linux/vs_memory.h>
604  
605  #include <asm/pgtable.h>
606  #include <asm/system.h>
607 diff -NurpP --minimal linux-2.6.37/arch/s390/include/asm/tlb.h linux-2.6.37-vs2.3.0.37-rc3/arch/s390/include/asm/tlb.h
608 --- linux-2.6.37/arch/s390/include/asm/tlb.h    2011-01-05 21:49:13.000000000 +0100
609 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/s390/include/asm/tlb.h     2010-11-23 02:09:40.000000000 +0100
610 @@ -23,6 +23,8 @@
611  
612  #include <linux/mm.h>
613  #include <linux/swap.h>
614 +#include <linux/vs_memory.h>
615 +
616  #include <asm/processor.h>
617  #include <asm/pgalloc.h>
618  #include <asm/smp.h>
619 diff -NurpP --minimal linux-2.6.37/arch/s390/include/asm/unistd.h linux-2.6.37-vs2.3.0.37-rc3/arch/s390/include/asm/unistd.h
620 --- linux-2.6.37/arch/s390/include/asm/unistd.h 2010-10-21 13:06:58.000000000 +0200
621 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/s390/include/asm/unistd.h  2010-11-23 02:09:40.000000000 +0100
622 @@ -202,7 +202,7 @@
623  #define __NR_clock_gettime     (__NR_timer_create+6)
624  #define __NR_clock_getres      (__NR_timer_create+7)
625  #define __NR_clock_nanosleep   (__NR_timer_create+8)
626 -/* Number 263 is reserved for vserver */
627 +#define __NR_vserver           263
628  #define __NR_statfs64          265
629  #define __NR_fstatfs64         266
630  #define __NR_remap_file_pages  267
631 diff -NurpP --minimal linux-2.6.37/arch/s390/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/s390/Kconfig
632 --- linux-2.6.37/arch/s390/Kconfig      2011-01-05 21:49:12.000000000 +0100
633 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/s390/Kconfig       2010-11-23 02:09:40.000000000 +0100
634 @@ -640,6 +640,8 @@ source "fs/Kconfig"
635  
636  source "arch/s390/Kconfig.debug"
637  
638 +source "kernel/vserver/Kconfig"
639 +
640  source "security/Kconfig"
641  
642  source "crypto/Kconfig"
643 diff -NurpP --minimal linux-2.6.37/arch/s390/kernel/ptrace.c linux-2.6.37-vs2.3.0.37-rc3/arch/s390/kernel/ptrace.c
644 --- linux-2.6.37/arch/s390/kernel/ptrace.c      2011-01-05 21:49:13.000000000 +0100
645 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/s390/kernel/ptrace.c       2010-11-23 02:09:40.000000000 +0100
646 @@ -36,6 +36,7 @@
647  #include <linux/regset.h>
648  #include <linux/tracehook.h>
649  #include <linux/seccomp.h>
650 +#include <linux/vs_base.h>
651  #include <trace/syscall.h>
652  #include <asm/compat.h>
653  #include <asm/segment.h>
654 diff -NurpP --minimal linux-2.6.37/arch/s390/kernel/syscalls.S linux-2.6.37-vs2.3.0.37-rc3/arch/s390/kernel/syscalls.S
655 --- linux-2.6.37/arch/s390/kernel/syscalls.S    2010-10-21 13:06:58.000000000 +0200
656 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/s390/kernel/syscalls.S     2010-11-23 02:09:40.000000000 +0100
657 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
658  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
659  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
660  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
661 -NI_SYSCALL                                                     /* reserved for vserver */
662 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
663  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
664  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
665  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
666 diff -NurpP --minimal linux-2.6.37/arch/sh/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/sh/Kconfig
667 --- linux-2.6.37/arch/sh/Kconfig        2011-01-05 21:49:13.000000000 +0100
668 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/sh/Kconfig 2011-01-05 22:30:27.000000000 +0100
669 @@ -883,6 +883,8 @@ source "fs/Kconfig"
670  
671  source "arch/sh/Kconfig.debug"
672  
673 +source "kernel/vserver/Kconfig"
674 +
675  source "security/Kconfig"
676  
677  source "crypto/Kconfig"
678 diff -NurpP --minimal linux-2.6.37/arch/sh/kernel/irq.c linux-2.6.37-vs2.3.0.37-rc3/arch/sh/kernel/irq.c
679 --- linux-2.6.37/arch/sh/kernel/irq.c   2011-01-05 21:49:16.000000000 +0100
680 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/sh/kernel/irq.c    2010-11-23 02:09:40.000000000 +0100
681 @@ -13,6 +13,7 @@
682  #include <linux/seq_file.h>
683  #include <linux/ftrace.h>
684  #include <linux/delay.h>
685 +// #include <linux/vs_context.h>
686  #include <asm/processor.h>
687  #include <asm/machvec.h>
688  #include <asm/uaccess.h>
689 diff -NurpP --minimal linux-2.6.37/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.37-vs2.3.0.37-rc3/arch/sh/kernel/vsyscall/vsyscall.c
690 --- linux-2.6.37/arch/sh/kernel/vsyscall/vsyscall.c     2010-07-07 18:31:10.000000000 +0200
691 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/sh/kernel/vsyscall/vsyscall.c      2010-11-23 02:09:40.000000000 +0100
692 @@ -18,6 +18,7 @@
693  #include <linux/elf.h>
694  #include <linux/sched.h>
695  #include <linux/err.h>
696 +#include <linux/vs_memory.h>
697  
698  /*
699   * Should the kernel map a VDSO page into processes and pass its
700 diff -NurpP --minimal linux-2.6.37/arch/sparc/include/asm/tlb_64.h linux-2.6.37-vs2.3.0.37-rc3/arch/sparc/include/asm/tlb_64.h
701 --- linux-2.6.37/arch/sparc/include/asm/tlb_64.h        2009-09-10 15:25:45.000000000 +0200
702 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/sparc/include/asm/tlb_64.h 2010-11-23 02:09:40.000000000 +0100
703 @@ -3,6 +3,7 @@
704  
705  #include <linux/swap.h>
706  #include <linux/pagemap.h>
707 +#include <linux/vs_memory.h>
708  #include <asm/pgalloc.h>
709  #include <asm/tlbflush.h>
710  #include <asm/mmu_context.h>
711 diff -NurpP --minimal linux-2.6.37/arch/sparc/include/asm/unistd.h linux-2.6.37-vs2.3.0.37-rc3/arch/sparc/include/asm/unistd.h
712 --- linux-2.6.37/arch/sparc/include/asm/unistd.h        2010-10-21 13:06:58.000000000 +0200
713 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/sparc/include/asm/unistd.h 2010-11-23 02:09:40.000000000 +0100
714 @@ -335,7 +335,7 @@
715  #define __NR_timer_getoverrun  264
716  #define __NR_timer_delete      265
717  #define __NR_timer_create      266
718 -/* #define __NR_vserver                267 Reserved for VSERVER */
719 +#define __NR_vserver           267
720  #define __NR_io_setup          268
721  #define __NR_io_destroy                269
722  #define __NR_io_submit         270
723 diff -NurpP --minimal linux-2.6.37/arch/sparc/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/sparc/Kconfig
724 --- linux-2.6.37/arch/sparc/Kconfig     2011-01-05 21:49:17.000000000 +0100
725 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/sparc/Kconfig      2010-11-23 02:09:40.000000000 +0100
726 @@ -560,6 +560,8 @@ source "fs/Kconfig"
727  
728  source "arch/sparc/Kconfig.debug"
729  
730 +source "kernel/vserver/Kconfig"
731 +
732  source "security/Kconfig"
733  
734  source "crypto/Kconfig"
735 diff -NurpP --minimal linux-2.6.37/arch/sparc/kernel/systbls_32.S linux-2.6.37-vs2.3.0.37-rc3/arch/sparc/kernel/systbls_32.S
736 --- linux-2.6.37/arch/sparc/kernel/systbls_32.S 2010-10-21 13:06:59.000000000 +0200
737 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/sparc/kernel/systbls_32.S  2010-11-23 02:09:40.000000000 +0100
738 @@ -70,7 +70,7 @@ sys_call_table:
739  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
740  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
741  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
742 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
743 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
744  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
745  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
746  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
747 diff -NurpP --minimal linux-2.6.37/arch/sparc/kernel/systbls_64.S linux-2.6.37-vs2.3.0.37-rc3/arch/sparc/kernel/systbls_64.S
748 --- linux-2.6.37/arch/sparc/kernel/systbls_64.S 2010-10-21 13:06:59.000000000 +0200
749 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/sparc/kernel/systbls_64.S  2010-11-23 02:09:41.000000000 +0100
750 @@ -71,7 +71,7 @@ sys_call_table32:
751  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
752         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
753  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
754 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
755 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
756  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
757         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
758  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
759 @@ -147,7 +147,7 @@ sys_call_table:
760  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
761         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
762  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
763 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
764 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
765  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
766         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
767  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
768 diff -NurpP --minimal linux-2.6.37/arch/um/include/asm/tlb.h linux-2.6.37-vs2.3.0.37-rc3/arch/um/include/asm/tlb.h
769 --- linux-2.6.37/arch/um/include/asm/tlb.h      2009-09-10 15:25:46.000000000 +0200
770 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/um/include/asm/tlb.h       2010-11-23 02:09:41.000000000 +0100
771 @@ -3,6 +3,7 @@
772  
773  #include <linux/pagemap.h>
774  #include <linux/swap.h>
775 +#include <linux/vs_memory.h>
776  #include <asm/percpu.h>
777  #include <asm/pgalloc.h>
778  #include <asm/tlbflush.h>
779 diff -NurpP --minimal linux-2.6.37/arch/um/include/shared/kern_constants.h linux-2.6.37-vs2.3.0.37-rc3/arch/um/include/shared/kern_constants.h
780 --- linux-2.6.37/arch/um/include/shared/kern_constants.h        1970-01-01 01:00:00.000000000 +0100
781 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/um/include/shared/kern_constants.h 2010-11-23 02:09:41.000000000 +0100
782 @@ -0,0 +1 @@
783 +#include "../../../../include/generated/asm-offsets.h"
784 diff -NurpP --minimal linux-2.6.37/arch/um/include/shared/user_constants.h linux-2.6.37-vs2.3.0.37-rc3/arch/um/include/shared/user_constants.h
785 --- linux-2.6.37/arch/um/include/shared/user_constants.h        1970-01-01 01:00:00.000000000 +0100
786 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/um/include/shared/user_constants.h 2010-11-23 02:09:41.000000000 +0100
787 @@ -0,0 +1,40 @@
788 +/*
789 + * DO NOT MODIFY.
790 + *
791 + * This file was generated by arch/um/Makefile
792 + *
793 + */
794 +
795 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
796 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
797 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
798 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
799 +#define HOST_RBX 5 /* RBX      # */
800 +#define HOST_RCX 11 /* RCX     # */
801 +#define HOST_RDI 14 /* RDI     # */
802 +#define HOST_RSI 13 /* RSI     # */
803 +#define HOST_RDX 12 /* RDX     # */
804 +#define HOST_RBP 4 /* RBP      # */
805 +#define HOST_RAX 10 /* RAX     # */
806 +#define HOST_R8 9 /* R8        # */
807 +#define HOST_R9 8 /* R9        # */
808 +#define HOST_R10 7 /* R10      # */
809 +#define HOST_R11 6 /* R11      # */
810 +#define HOST_R12 3 /* R12      # */
811 +#define HOST_R13 2 /* R13      # */
812 +#define HOST_R14 1 /* R14      # */
813 +#define HOST_R15 0 /* R15      # */
814 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
815 +#define HOST_CS 17 /* CS       # */
816 +#define HOST_SS 20 /* SS       # */
817 +#define HOST_EFLAGS 18 /* EFLAGS       # */
818 +#define HOST_IP 16 /* RIP      # */
819 +#define HOST_SP 19 /* RSP      # */
820 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
821 +#define UM_POLLIN 1 /* POLLIN  # */
822 +#define UM_POLLPRI 2 /* POLLPRI        # */
823 +#define UM_POLLOUT 4 /* POLLOUT        # */
824 +#define UM_PROT_READ 1 /* PROT_READ    # */
825 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
826 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
827 +
828 diff -NurpP --minimal linux-2.6.37/arch/um/Kconfig.rest linux-2.6.37-vs2.3.0.37-rc3/arch/um/Kconfig.rest
829 --- linux-2.6.37/arch/um/Kconfig.rest   2009-06-11 17:12:19.000000000 +0200
830 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/um/Kconfig.rest    2010-11-23 02:09:41.000000000 +0100
831 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
832  
833  source "fs/Kconfig"
834  
835 +source "kernel/vserver/Kconfig"
836 +
837  source "security/Kconfig"
838  
839  source "crypto/Kconfig"
840 diff -NurpP --minimal linux-2.6.37/arch/x86/ia32/ia32entry.S linux-2.6.37-vs2.3.0.37-rc3/arch/x86/ia32/ia32entry.S
841 --- linux-2.6.37/arch/x86/ia32/ia32entry.S      2010-10-21 13:06:59.000000000 +0200
842 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/x86/ia32/ia32entry.S       2010-11-23 02:09:41.000000000 +0100
843 @@ -783,7 +783,7 @@ ia32_sys_call_table:
844         .quad sys_tgkill                /* 270 */
845         .quad compat_sys_utimes
846         .quad sys32_fadvise64_64
847 -       .quad quiet_ni_syscall  /* sys_vserver */
848 +       .quad sys32_vserver
849         .quad sys_mbind
850         .quad compat_sys_get_mempolicy  /* 275 */
851         .quad sys_set_mempolicy
852 diff -NurpP --minimal linux-2.6.37/arch/x86/include/asm/unistd_64.h linux-2.6.37-vs2.3.0.37-rc3/arch/x86/include/asm/unistd_64.h
853 --- linux-2.6.37/arch/x86/include/asm/unistd_64.h       2010-10-21 13:06:59.000000000 +0200
854 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/x86/include/asm/unistd_64.h        2010-11-23 02:09:41.000000000 +0100
855 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
856  #define __NR_utimes                            235
857  __SYSCALL(__NR_utimes, sys_utimes)
858  #define __NR_vserver                           236
859 -__SYSCALL(__NR_vserver, sys_ni_syscall)
860 +__SYSCALL(__NR_vserver, sys_vserver)
861  #define __NR_mbind                             237
862  __SYSCALL(__NR_mbind, sys_mbind)
863  #define __NR_set_mempolicy                     238
864 diff -NurpP --minimal linux-2.6.37/arch/x86/Kconfig linux-2.6.37-vs2.3.0.37-rc3/arch/x86/Kconfig
865 --- linux-2.6.37/arch/x86/Kconfig       2011-01-05 21:49:19.000000000 +0100
866 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/x86/Kconfig        2011-01-05 22:30:27.000000000 +0100
867 @@ -2119,6 +2119,8 @@ source "fs/Kconfig"
868  
869  source "arch/x86/Kconfig.debug"
870  
871 +source "kernel/vserver/Kconfig"
872 +
873  source "security/Kconfig"
874  
875  source "crypto/Kconfig"
876 diff -NurpP --minimal linux-2.6.37/arch/x86/kernel/syscall_table_32.S linux-2.6.37-vs2.3.0.37-rc3/arch/x86/kernel/syscall_table_32.S
877 --- linux-2.6.37/arch/x86/kernel/syscall_table_32.S     2010-10-21 13:07:00.000000000 +0200
878 +++ linux-2.6.37-vs2.3.0.37-rc3/arch/x86/kernel/syscall_table_32.S      2010-11-23 02:09:41.000000000 +0100
879 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
880         .long sys_tgkill        /* 270 */
881         .long sys_utimes
882         .long sys_fadvise64_64
883 -       .long sys_ni_syscall    /* sys_vserver */
884 +       .long sys_vserver
885         .long sys_mbind
886         .long sys_get_mempolicy
887         .long sys_set_mempolicy
888 diff -NurpP --minimal linux-2.6.37/Documentation/vserver/debug.txt linux-2.6.37-vs2.3.0.37-rc3/Documentation/vserver/debug.txt
889 --- linux-2.6.37/Documentation/vserver/debug.txt        1970-01-01 01:00:00.000000000 +0100
890 +++ linux-2.6.37-vs2.3.0.37-rc3/Documentation/vserver/debug.txt 2010-11-23 02:09:40.000000000 +0100
891 @@ -0,0 +1,154 @@
892 +
893 +debug_cvirt:
894 +
895 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
896 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
897 +
898 +debug_dlim:
899 +
900 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
901 +       "FREE  (%p,#%d)%c inode"
902 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
903 +       "FREE  (%p,#%d)%c %lld bytes"
904 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
905 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
906 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
907 +       "rcu_free_dl_info(%p)"
908 + 4  10 "alloc_dl_info(%p,%d) = %p"
909 +       "dealloc_dl_info(%p)"
910 +       "get_dl_info(%p[#%d.%d])"
911 +       "put_dl_info(%p[#%d.%d])"
912 + 5  20 "alloc_dl_info(%p,%d)*"
913 + 6  40 "__hash_dl_info: %p[#%d]"
914 +       "__unhash_dl_info: %p[#%d]"
915 + 7  80 "locate_dl_info(%p,#%d) = %p"
916 +
917 +debug_misc:
918 +
919 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
920 +       "new_dqhash: %p [#0x%08x]"
921 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
922 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
923 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
924 +       "vroot_get_real_bdev not set"
925 + 1   2 "cow_break_link(»%s«)"
926 +       "temp copy Â»%s«"
927 + 2   4 "dentry_open(new): %p"
928 +       "dentry_open(old): %p"
929 +       "lookup_create(new): %p"
930 +       "old path Â»%s«"
931 +       "path_lookup(old): %d"
932 +       "vfs_create(new): %d"
933 +       "vfs_rename: %d"
934 +       "vfs_sendfile: %d"
935 + 3   8 "fput(new_file=%p[#%d])"
936 +       "fput(old_file=%p[#%d])"
937 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
938 +       "vx_info_kill(%p[#%d],%d,%d)*"
939 + 5  20 "vs_reboot(%p[#%d],%d)"
940 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
941 +
942 +debug_net:
943 +
944 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
945 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
946 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
947 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
948 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
949 + 6  40 "sk,egf: %p [#%d] (from %d)"
950 +       "sk,egn: %p [#%d] (from %d)"
951 +       "sk,req: %p [#%d] (from %d)"
952 +       "sk: %p [#%d] (from %d)"
953 +       "tw: %p [#%d] (from %d)"
954 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
955 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
956 +
957 +debug_nid:
958 +
959 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
960 +       "alloc_nx_info(%d) = %p"
961 +       "create_nx_info(%d) (dynamic rejected)"
962 +       "create_nx_info(%d) = %p (already there)"
963 +       "create_nx_info(%d) = %p (new)"
964 +       "dealloc_nx_info(%p)"
965 + 1   2 "alloc_nx_info(%d)*"
966 +       "create_nx_info(%d)*"
967 + 2   4 "get_nx_info(%p[#%d.%d])"
968 +       "put_nx_info(%p[#%d.%d])"
969 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
970 +       "clr_nx_info(%p[#%d.%d])"
971 +       "init_nx_info(%p[#%d.%d])"
972 +       "release_nx_info(%p[#%d.%d.%d]) %p"
973 +       "set_nx_info(%p[#%d.%d])"
974 + 4  10 "__hash_nx_info: %p[#%d]"
975 +       "__nx_dynamic_id: [#%d]"
976 +       "__unhash_nx_info: %p[#%d.%d.%d]"
977 + 5  20 "moved task %p into nxi:%p[#%d]"
978 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
979 +       "task_get_nx_info(%p)"
980 + 6  40 "nx_clear_persistent(%p[#%d])"
981 +
982 +debug_quota:
983 +
984 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
985 + 1   2 "quota_sync_dqh(%p,%d)"
986 +       "sync_dquots(%p,%d)"
987 +       "sync_dquots_dqh(%p,%d)"
988 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
989 +
990 +debug_switch:
991 +
992 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
993 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
994 + 4  10 "%s: (%s %s) returned %s with %d"
995 +
996 +debug_tag:
997 +
998 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
999 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1000 +
1001 +debug_xid:
1002 +
1003 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1004 +       "alloc_vx_info(%d) = %p"
1005 +       "alloc_vx_info(%d)*"
1006 +       "create_vx_info(%d) (dynamic rejected)"
1007 +       "create_vx_info(%d) = %p (already there)"
1008 +       "create_vx_info(%d) = %p (new)"
1009 +       "dealloc_vx_info(%p)"
1010 +       "loc_vx_info(%d) = %p (found)"
1011 +       "loc_vx_info(%d) = %p (new)"
1012 +       "loc_vx_info(%d) = %p (not available)"
1013 + 1   2 "create_vx_info(%d)*"
1014 +       "loc_vx_info(%d)*"
1015 + 2   4 "get_vx_info(%p[#%d.%d])"
1016 +       "put_vx_info(%p[#%d.%d])"
1017 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1018 +       "clr_vx_info(%p[#%d.%d])"
1019 +       "init_vx_info(%p[#%d.%d])"
1020 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1021 +       "set_vx_info(%p[#%d.%d])"
1022 + 4  10 "__hash_vx_info: %p[#%d]"
1023 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1024 +       "__vx_dynamic_id: [#%d]"
1025 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1026 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1027 +       "moved task %p into vxi:%p[#%d]"
1028 +       "task_get_vx_info(%p)"
1029 +       "vx_migrate_task(%p,%p[#%d.%d])"
1030 + 6  40 "vx_clear_persistent(%p[#%d])"
1031 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1032 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1033 +       "vx_set_persistent(%p[#%d])"
1034 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1035 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1036 +
1037 +
1038 +debug_limit:
1039 +
1040 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1041 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1042 +
1043 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1044 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1045 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1046 diff -NurpP --minimal linux-2.6.37/drivers/block/Kconfig linux-2.6.37-vs2.3.0.37-rc3/drivers/block/Kconfig
1047 --- linux-2.6.37/drivers/block/Kconfig  2011-01-05 21:49:25.000000000 +0100
1048 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/block/Kconfig   2010-11-23 02:09:41.000000000 +0100
1049 @@ -273,6 +273,13 @@ config BLK_DEV_CRYPTOLOOP
1050  
1051  source "drivers/block/drbd/Kconfig"
1052  
1053 +config BLK_DEV_VROOT
1054 +       tristate "Virtual Root device support"
1055 +       depends on QUOTACTL
1056 +       ---help---
1057 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1058 +         partition within a virtual server without compromising security.
1059 +
1060  config BLK_DEV_NBD
1061         tristate "Network block device support"
1062         depends on NET
1063 diff -NurpP --minimal linux-2.6.37/drivers/block/loop.c linux-2.6.37-vs2.3.0.37-rc3/drivers/block/loop.c
1064 --- linux-2.6.37/drivers/block/loop.c   2011-01-05 21:49:25.000000000 +0100
1065 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/block/loop.c    2010-11-23 02:15:37.000000000 +0100
1066 @@ -75,6 +75,7 @@
1067  #include <linux/kthread.h>
1068  #include <linux/splice.h>
1069  #include <linux/sysfs.h>
1070 +#include <linux/vs_context.h>
1071  
1072  #include <asm/uaccess.h>
1073  
1074 @@ -907,6 +908,7 @@ static int loop_set_fd(struct loop_devic
1075         lo->lo_blocksize = lo_blocksize;
1076         lo->lo_device = bdev;
1077         lo->lo_flags = lo_flags;
1078 +       lo->lo_xid = vx_current_xid();
1079         lo->lo_backing_file = file;
1080         lo->transfer = transfer_none;
1081         lo->ioctl = NULL;
1082 @@ -1037,6 +1039,7 @@ static int loop_clr_fd(struct loop_devic
1083         lo->lo_encrypt_key_size = 0;
1084         lo->lo_flags = 0;
1085         lo->lo_thread = NULL;
1086 +       lo->lo_xid = 0;
1087         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1088         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1089         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1090 @@ -1075,7 +1078,7 @@ loop_set_status(struct loop_device *lo, 
1091  
1092         if (lo->lo_encrypt_key_size &&
1093             lo->lo_key_owner != uid &&
1094 -           !capable(CAP_SYS_ADMIN))
1095 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1096                 return -EPERM;
1097         if (lo->lo_state != Lo_bound)
1098                 return -ENXIO;
1099 @@ -1159,7 +1162,8 @@ loop_get_status(struct loop_device *lo, 
1100         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1101         info->lo_encrypt_type =
1102                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1103 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1104 +       if (lo->lo_encrypt_key_size &&
1105 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1106                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1107                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1108                        lo->lo_encrypt_key_size);
1109 @@ -1505,6 +1509,9 @@ static int lo_open(struct block_device *
1110  {
1111         struct loop_device *lo = bdev->bd_disk->private_data;
1112  
1113 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1114 +               return -EACCES;
1115 +
1116         mutex_lock(&loop_mutex);
1117         mutex_lock(&lo->lo_ctl_mutex);
1118         lo->lo_refcnt++;
1119 diff -NurpP --minimal linux-2.6.37/drivers/block/Makefile linux-2.6.37-vs2.3.0.37-rc3/drivers/block/Makefile
1120 --- linux-2.6.37/drivers/block/Makefile 2011-01-05 21:49:25.000000000 +0100
1121 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/block/Makefile  2010-11-23 02:09:41.000000000 +0100
1122 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1123  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1124  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1125  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1126 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1127  
1128  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1129  obj-$(CONFIG_BLK_DEV_DRBD)     += drbd/
1130 diff -NurpP --minimal linux-2.6.37/drivers/block/vroot.c linux-2.6.37-vs2.3.0.37-rc3/drivers/block/vroot.c
1131 --- linux-2.6.37/drivers/block/vroot.c  1970-01-01 01:00:00.000000000 +0100
1132 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/block/vroot.c   2011-01-08 04:12:17.000000000 +0100
1133 @@ -0,0 +1,282 @@
1134 +/*
1135 + *  linux/drivers/block/vroot.c
1136 + *
1137 + *  written by Herbert Pötzl, 9/11/2002
1138 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1139 + *
1140 + *  based on the loop.c code by Theodore Ts'o.
1141 + *
1142 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1143 + * Redistribution of this file is permitted under the
1144 + * GNU General Public License.
1145 + *
1146 + */
1147 +
1148 +#include <linux/module.h>
1149 +#include <linux/moduleparam.h>
1150 +#include <linux/file.h>
1151 +#include <linux/major.h>
1152 +#include <linux/blkdev.h>
1153 +#include <linux/slab.h>
1154 +
1155 +#include <linux/vroot.h>
1156 +#include <linux/vs_context.h>
1157 +
1158 +
1159 +static int max_vroot = 8;
1160 +
1161 +static struct vroot_device *vroot_dev;
1162 +static struct gendisk **disks;
1163 +
1164 +
1165 +static int vroot_set_dev(
1166 +       struct vroot_device *vr,
1167 +       struct block_device *bdev,
1168 +       unsigned int arg)
1169 +{
1170 +       struct block_device *real_bdev;
1171 +       struct file *file;
1172 +       struct inode *inode;
1173 +       int error;
1174 +
1175 +       error = -EBUSY;
1176 +       if (vr->vr_state != Vr_unbound)
1177 +               goto out;
1178 +
1179 +       error = -EBADF;
1180 +       file = fget(arg);
1181 +       if (!file)
1182 +               goto out;
1183 +
1184 +       error = -EINVAL;
1185 +       inode = file->f_dentry->d_inode;
1186 +
1187 +
1188 +       if (S_ISBLK(inode->i_mode)) {
1189 +               real_bdev = inode->i_bdev;
1190 +               vr->vr_device = real_bdev;
1191 +               __iget(real_bdev->bd_inode);
1192 +       } else
1193 +               goto out_fput;
1194 +
1195 +       vxdprintk(VXD_CBIT(misc, 0),
1196 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1197 +               vr->vr_number, VXD_DEV(real_bdev));
1198 +
1199 +       vr->vr_state = Vr_bound;
1200 +       error = 0;
1201 +
1202 + out_fput:
1203 +       fput(file);
1204 + out:
1205 +       return error;
1206 +}
1207 +
1208 +static int vroot_clr_dev(
1209 +       struct vroot_device *vr,
1210 +       struct block_device *bdev)
1211 +{
1212 +       struct block_device *real_bdev;
1213 +
1214 +       if (vr->vr_state != Vr_bound)
1215 +               return -ENXIO;
1216 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1217 +               return -EBUSY;
1218 +
1219 +       real_bdev = vr->vr_device;
1220 +
1221 +       vxdprintk(VXD_CBIT(misc, 0),
1222 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1223 +               vr->vr_number, VXD_DEV(real_bdev));
1224 +
1225 +       bdput(real_bdev);
1226 +       vr->vr_state = Vr_unbound;
1227 +       vr->vr_device = NULL;
1228 +       return 0;
1229 +}
1230 +
1231 +
1232 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1233 +       unsigned int cmd, unsigned long arg)
1234 +{
1235 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1236 +       int err;
1237 +
1238 +       down(&vr->vr_ctl_mutex);
1239 +       switch (cmd) {
1240 +       case VROOT_SET_DEV:
1241 +               err = vroot_set_dev(vr, bdev, arg);
1242 +               break;
1243 +       case VROOT_CLR_DEV:
1244 +               err = vroot_clr_dev(vr, bdev);
1245 +               break;
1246 +       default:
1247 +               err = -EINVAL;
1248 +               break;
1249 +       }
1250 +       up(&vr->vr_ctl_mutex);
1251 +       return err;
1252 +}
1253 +
1254 +static int vr_open(struct block_device *bdev, fmode_t mode)
1255 +{
1256 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1257 +
1258 +       down(&vr->vr_ctl_mutex);
1259 +       vr->vr_refcnt++;
1260 +       up(&vr->vr_ctl_mutex);
1261 +       return 0;
1262 +}
1263 +
1264 +static int vr_release(struct gendisk *disk, fmode_t mode)
1265 +{
1266 +       struct vroot_device *vr = disk->private_data;
1267 +
1268 +       down(&vr->vr_ctl_mutex);
1269 +       --vr->vr_refcnt;
1270 +       up(&vr->vr_ctl_mutex);
1271 +       return 0;
1272 +}
1273 +
1274 +static struct block_device_operations vr_fops = {
1275 +       .owner =        THIS_MODULE,
1276 +       .open =         vr_open,
1277 +       .release =      vr_release,
1278 +       .ioctl =        vr_ioctl,
1279 +};
1280 +
1281 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1282 +{
1283 +       struct inode *inode = bdev->bd_inode;
1284 +       struct vroot_device *vr;
1285 +       struct block_device *real_bdev;
1286 +       int minor = iminor(inode);
1287 +
1288 +       vr = &vroot_dev[minor];
1289 +       real_bdev = vr->vr_device;
1290 +
1291 +       vxdprintk(VXD_CBIT(misc, 0),
1292 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1293 +               vr->vr_number, VXD_DEV(real_bdev));
1294 +
1295 +       if (vr->vr_state != Vr_bound)
1296 +               return ERR_PTR(-ENXIO);
1297 +
1298 +       __iget(real_bdev->bd_inode);
1299 +       return real_bdev;
1300 +}
1301 +
1302 +/*
1303 + * And now the modules code and kernel interface.
1304 + */
1305 +
1306 +module_param(max_vroot, int, 0);
1307 +
1308 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1309 +MODULE_LICENSE("GPL");
1310 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1311 +
1312 +MODULE_AUTHOR ("Herbert Pötzl");
1313 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1314 +
1315 +
1316 +int __init vroot_init(void)
1317 +{
1318 +       int err, i;
1319 +
1320 +       if (max_vroot < 1 || max_vroot > 256) {
1321 +               max_vroot = MAX_VROOT_DEFAULT;
1322 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1323 +                       "(must be between 1 and 256), "
1324 +                       "using default (%d)\n", max_vroot);
1325 +       }
1326 +
1327 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1328 +               return -EIO;
1329 +
1330 +       err = -ENOMEM;
1331 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1332 +       if (!vroot_dev)
1333 +               goto out_mem1;
1334 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1335 +
1336 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1337 +       if (!disks)
1338 +               goto out_mem2;
1339 +
1340 +       for (i = 0; i < max_vroot; i++) {
1341 +               disks[i] = alloc_disk(1);
1342 +               if (!disks[i])
1343 +                       goto out_mem3;
1344 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1345 +               if (!disks[i]->queue)
1346 +                       goto out_mem3;
1347 +       }
1348 +
1349 +       for (i = 0; i < max_vroot; i++) {
1350 +               struct vroot_device *vr = &vroot_dev[i];
1351 +               struct gendisk *disk = disks[i];
1352 +
1353 +               memset(vr, 0, sizeof(*vr));
1354 +               sema_init(&vr->vr_ctl_mutex, 1);
1355 +               vr->vr_number = i;
1356 +               disk->major = VROOT_MAJOR;
1357 +               disk->first_minor = i;
1358 +               disk->fops = &vr_fops;
1359 +               sprintf(disk->disk_name, "vroot%d", i);
1360 +               disk->private_data = vr;
1361 +       }
1362 +
1363 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1364 +       if (err)
1365 +               goto out_mem3;
1366 +
1367 +       for (i = 0; i < max_vroot; i++)
1368 +               add_disk(disks[i]);
1369 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1370 +       return 0;
1371 +
1372 +out_mem3:
1373 +       while (i--)
1374 +               put_disk(disks[i]);
1375 +       kfree(disks);
1376 +out_mem2:
1377 +       kfree(vroot_dev);
1378 +out_mem1:
1379 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1380 +       printk(KERN_ERR "vroot: ran out of memory\n");
1381 +       return err;
1382 +}
1383 +
1384 +void vroot_exit(void)
1385 +{
1386 +       int i;
1387 +
1388 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1389 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1390 +
1391 +       for (i = 0; i < max_vroot; i++) {
1392 +               del_gendisk(disks[i]);
1393 +               put_disk(disks[i]);
1394 +       }
1395 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1396 +
1397 +       kfree(disks);
1398 +       kfree(vroot_dev);
1399 +}
1400 +
1401 +module_init(vroot_init);
1402 +module_exit(vroot_exit);
1403 +
1404 +#ifndef MODULE
1405 +
1406 +static int __init max_vroot_setup(char *str)
1407 +{
1408 +       max_vroot = simple_strtol(str, NULL, 0);
1409 +       return 1;
1410 +}
1411 +
1412 +__setup("max_vroot=", max_vroot_setup);
1413 +
1414 +#endif
1415 +
1416 diff -NurpP --minimal linux-2.6.37/drivers/gpu/drm/radeon/r100_reg_safe.h linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/r100_reg_safe.h
1417 --- linux-2.6.37/drivers/gpu/drm/radeon/r100_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1418 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/r100_reg_safe.h  2010-11-23 02:09:41.000000000 +0100
1419 @@ -0,0 +1,28 @@
1420 +static const unsigned r100_reg_safe_bm[102] = {
1421 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1422 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1423 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1424 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1425 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1426 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1427 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1428 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1429 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1430 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1431 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1432 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1433 +       0xFFFFFFCF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1434 +       0xFFFFFF9F, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1435 +       0x38E7FE1F, 0xFFC3FF8E, 0x7FF8FFFF, 0xFFFF803C,
1436 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1437 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFFFF, 0xFFFFFFFF,
1438 +       0x00000000, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF,
1439 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1440 +       0xFFFFFFFF, 0xFFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1441 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1442 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1443 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1444 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1445 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1446 +       0xFFFFFFFF, 0xFFFFFFEF,
1447 +};
1448 diff -NurpP --minimal linux-2.6.37/drivers/gpu/drm/radeon/r200_reg_safe.h linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/r200_reg_safe.h
1449 --- linux-2.6.37/drivers/gpu/drm/radeon/r200_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1450 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/r200_reg_safe.h  2010-11-23 02:09:41.000000000 +0100
1451 @@ -0,0 +1,28 @@
1452 +static const unsigned r200_reg_safe_bm[102] = {
1453 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1454 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1455 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1456 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1457 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1458 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1459 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1460 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1461 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1462 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1463 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1464 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1465 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1466 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1467 +       0xFFE7FE1F, 0xF003FFFF, 0x7EFFFFFF, 0xFFFF803C,
1468 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1469 +       0xFFFFFFFF, 0xFFFFEFCE, 0xFFFEFFFF, 0xFFFFFFFE,
1470 +       0x020E0FF0, 0xFFCC83FD, 0xFFFFFFFF, 0xFFFFFFFF,
1471 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1472 +       0xFFFBFFFF, 0xEFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1473 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1474 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1475 +       0xDFDFDFDF, 0x3FFDDFDF, 0xFFFFFFFF, 0xFFFFFF7F,
1476 +       0xFFFFFFFF, 0x00FFFFFF, 0x00000000, 0x00000000,
1477 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1478 +       0xFFFFFE3F, 0xFFFFFFEF,
1479 +};
1480 diff -NurpP --minimal linux-2.6.37/drivers/gpu/drm/radeon/r300_reg_safe.h linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/r300_reg_safe.h
1481 --- linux-2.6.37/drivers/gpu/drm/radeon/r300_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1482 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/r300_reg_safe.h  2010-11-23 02:09:41.000000000 +0100
1483 @@ -0,0 +1,42 @@
1484 +static const unsigned r300_reg_safe_bm[159] = {
1485 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1486 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1487 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1488 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1489 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1490 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1491 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1492 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1493 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1494 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1495 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1496 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1497 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1498 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1499 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1500 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1501 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1502 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1503 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1504 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1505 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1506 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1507 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1508 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1509 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1510 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1511 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1512 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1513 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1514 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1515 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1516 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1517 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1518 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1519 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1520 +       0x00000000, 0x0000C100, 0x00000000, 0x00000000,
1521 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1522 +       0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0xFF80FFFF,
1523 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1524 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1525 +};
1526 diff -NurpP --minimal linux-2.6.37/drivers/gpu/drm/radeon/r420_reg_safe.h linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/r420_reg_safe.h
1527 --- linux-2.6.37/drivers/gpu/drm/radeon/r420_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1528 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/r420_reg_safe.h  2010-11-23 02:09:41.000000000 +0100
1529 @@ -0,0 +1,42 @@
1530 +static const unsigned r420_reg_safe_bm[159] = {
1531 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1532 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1533 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1534 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1535 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1536 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1537 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1538 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1539 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1540 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1541 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1542 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1543 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1544 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1545 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1546 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1547 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1548 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1549 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1550 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1551 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1552 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1553 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1554 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1555 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1556 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1557 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1558 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1559 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1560 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1561 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1562 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1563 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1564 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1565 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1566 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1567 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1568 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1569 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1570 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1571 +};
1572 diff -NurpP --minimal linux-2.6.37/drivers/gpu/drm/radeon/rn50_reg_safe.h linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/rn50_reg_safe.h
1573 --- linux-2.6.37/drivers/gpu/drm/radeon/rn50_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1574 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/rn50_reg_safe.h  2010-11-23 02:09:41.000000000 +0100
1575 @@ -0,0 +1,28 @@
1576 +static const unsigned rn50_reg_safe_bm[102] = {
1577 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1578 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1579 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1580 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1581 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1582 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1583 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1584 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1585 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1586 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1587 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1588 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1589 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1590 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1591 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1592 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1593 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1594 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1595 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1596 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1597 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1598 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1599 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1600 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1601 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1602 +       0xFFFFFFFF, 0xFFFFFFFF,
1603 +};
1604 diff -NurpP --minimal linux-2.6.37/drivers/gpu/drm/radeon/rs600_reg_safe.h linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/rs600_reg_safe.h
1605 --- linux-2.6.37/drivers/gpu/drm/radeon/rs600_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1606 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/rs600_reg_safe.h 2010-11-23 02:09:41.000000000 +0100
1607 @@ -0,0 +1,57 @@
1608 +static const unsigned rs600_reg_safe_bm[219] = {
1609 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1610 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1611 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1612 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1613 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1614 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1615 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1616 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1617 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1618 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1619 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1620 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1621 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1622 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1623 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1624 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1625 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1626 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1627 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1628 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1629 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1630 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1631 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1632 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1633 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1634 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1635 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1636 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1637 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1638 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1639 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1640 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1641 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1642 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1643 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1644 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1645 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1646 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1647 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1648 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19, 0xFFFFFFFF,
1649 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1650 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1651 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1652 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1653 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1654 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1655 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1656 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1657 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1658 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1659 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1660 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1661 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1662 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1663 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1664 +};
1665 diff -NurpP --minimal linux-2.6.37/drivers/gpu/drm/radeon/rv515_reg_safe.h linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/rv515_reg_safe.h
1666 --- linux-2.6.37/drivers/gpu/drm/radeon/rv515_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1667 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/gpu/drm/radeon/rv515_reg_safe.h 2010-11-23 02:09:41.000000000 +0100
1668 @@ -0,0 +1,57 @@
1669 +static const unsigned rv515_reg_safe_bm[219] = {
1670 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1671 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1672 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1673 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1674 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1675 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1676 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1677 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1678 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1679 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1680 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1681 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1682 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1683 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1684 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1685 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1686 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1687 +       0xF0000038, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1688 +       0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF,
1689 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1690 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1691 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1692 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1693 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1694 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1695 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1696 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1697 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1698 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1699 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1700 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1701 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1702 +       0x1FFFF878, 0xFFFFE000, 0xFFFFFE1E, 0xFFFFFFFF,
1703 +       0x388F8F50, 0xFFF88082, 0xFF0000FC, 0xFAE009FF,
1704 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1705 +       0xFFFF8CFC, 0xFFFFC1FF, 0xFFFFFFFF, 0xFFFFFFFF,
1706 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1707 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF80FFFF,
1708 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1709 +       0x0003FC01, 0x3FFFFCF8, 0xFF800B19, 0xFFDFFFFF,
1710 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1711 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1712 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1713 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1714 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1715 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1716 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1717 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1718 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1719 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1720 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1721 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1722 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1723 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1724 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1725 +};
1726 diff -NurpP --minimal linux-2.6.37/drivers/infiniband/core/addr.c linux-2.6.37-vs2.3.0.37-rc3/drivers/infiniband/core/addr.c
1727 --- linux-2.6.37/drivers/infiniband/core/addr.c 2010-10-21 13:07:05.000000000 +0200
1728 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/infiniband/core/addr.c  2010-11-23 02:09:41.000000000 +0100
1729 @@ -252,7 +252,7 @@ static int addr6_resolve(struct sockaddr
1730  
1731         if (ipv6_addr_any(&fl.fl6_src)) {
1732                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1733 -                                        &fl.fl6_dst, 0, &fl.fl6_src);
1734 +                                        &fl.fl6_dst, 0, &fl.fl6_src, NULL);
1735                 if (ret)
1736                         goto put;
1737  
1738 diff -NurpP --minimal linux-2.6.37/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.37-vs2.3.0.37-rc3/drivers/infiniband/hw/ipath/ipath_user_pages.c
1739 --- linux-2.6.37/drivers/infiniband/hw/ipath/ipath_user_pages.c 2010-07-07 18:31:19.000000000 +0200
1740 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/infiniband/hw/ipath/ipath_user_pages.c  2010-11-23 02:09:41.000000000 +0100
1741 @@ -35,6 +35,7 @@
1742  #include <linux/device.h>
1743  #include <linux/slab.h>
1744  #include <linux/sched.h>
1745 +#include <linux/vs_memory.h>
1746  
1747  #include "ipath_kernel.h"
1748  
1749 diff -NurpP --minimal linux-2.6.37/drivers/md/dm.c linux-2.6.37-vs2.3.0.37-rc3/drivers/md/dm.c
1750 --- linux-2.6.37/drivers/md/dm.c        2011-01-05 21:49:35.000000000 +0100
1751 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/md/dm.c 2010-11-23 02:18:36.000000000 +0100
1752 @@ -20,6 +20,7 @@
1753  #include <linux/idr.h>
1754  #include <linux/hdreg.h>
1755  #include <linux/delay.h>
1756 +#include <linux/vs_base.h>
1757  
1758  #include <trace/events/block.h>
1759  
1760 @@ -120,6 +121,7 @@ struct mapped_device {
1761         rwlock_t map_lock;
1762         atomic_t holders;
1763         atomic_t open_count;
1764 +       xid_t xid;
1765  
1766         unsigned long flags;
1767  
1768 @@ -327,6 +329,7 @@ int dm_deleting_md(struct mapped_device 
1769  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1770  {
1771         struct mapped_device *md;
1772 +       int ret = -ENXIO;
1773  
1774         mutex_lock(&dm_mutex);
1775         spin_lock(&_minor_lock);
1776 @@ -336,19 +339,20 @@ static int dm_blk_open(struct block_devi
1777                 goto out;
1778  
1779         if (test_bit(DMF_FREEING, &md->flags) ||
1780 -           dm_deleting_md(md)) {
1781 -               md = NULL;
1782 +           dm_deleting_md(md))
1783 +               goto out;
1784 +
1785 +       ret = -EACCES;
1786 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1787                 goto out;
1788 -       }
1789  
1790         dm_get(md);
1791         atomic_inc(&md->open_count);
1792 -
1793 +       ret = 0;
1794  out:
1795         spin_unlock(&_minor_lock);
1796         mutex_unlock(&dm_mutex);
1797 -
1798 -       return md ? 0 : -ENXIO;
1799 +       return ret;
1800  }
1801  
1802  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1803 @@ -566,6 +570,14 @@ int dm_set_geometry(struct mapped_device
1804         return 0;
1805  }
1806  
1807 +/*
1808 + * Get the xid associated with a dm device
1809 + */
1810 +xid_t dm_get_xid(struct mapped_device *md)
1811 +{
1812 +       return md->xid;
1813 +}
1814 +
1815  /*-----------------------------------------------------------------
1816   * CRUD START:
1817   *   A more elegant soln is in the works that uses the queue
1818 @@ -1859,6 +1871,7 @@ static struct mapped_device *alloc_dev(i
1819         INIT_LIST_HEAD(&md->uevent_list);
1820         spin_lock_init(&md->uevent_lock);
1821  
1822 +       md->xid = vx_current_xid();
1823         md->queue = blk_alloc_queue(GFP_KERNEL);
1824         if (!md->queue)
1825                 goto bad_queue;
1826 diff -NurpP --minimal linux-2.6.37/drivers/md/dm.h linux-2.6.37-vs2.3.0.37-rc3/drivers/md/dm.h
1827 --- linux-2.6.37/drivers/md/dm.h        2010-10-21 13:07:07.000000000 +0200
1828 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/md/dm.h 2010-11-23 02:09:41.000000000 +0100
1829 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1830  struct dm_table;
1831  struct dm_md_mempools;
1832  
1833 +xid_t dm_get_xid(struct mapped_device *md);
1834 +
1835  /*-----------------------------------------------------------------
1836   * Internal table functions.
1837   *---------------------------------------------------------------*/
1838 diff -NurpP --minimal linux-2.6.37/drivers/md/dm-ioctl.c linux-2.6.37-vs2.3.0.37-rc3/drivers/md/dm-ioctl.c
1839 --- linux-2.6.37/drivers/md/dm-ioctl.c  2011-01-05 21:49:35.000000000 +0100
1840 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/md/dm-ioctl.c   2010-11-23 02:09:41.000000000 +0100
1841 @@ -16,6 +16,7 @@
1842  #include <linux/dm-ioctl.h>
1843  #include <linux/hdreg.h>
1844  #include <linux/compat.h>
1845 +#include <linux/vs_context.h>
1846  
1847  #include <asm/uaccess.h>
1848  
1849 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1850         unsigned int h = hash_str(str);
1851  
1852         list_for_each_entry (hc, _name_buckets + h, name_list)
1853 -               if (!strcmp(hc->name, str)) {
1854 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1855 +                       !strcmp(hc->name, str)) {
1856                         dm_get(hc->md);
1857                         return hc;
1858                 }
1859 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1860         unsigned int h = hash_str(str);
1861  
1862         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1863 -               if (!strcmp(hc->uuid, str)) {
1864 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1865 +                       !strcmp(hc->uuid, str)) {
1866                         dm_get(hc->md);
1867                         return hc;
1868                 }
1869 @@ -377,6 +380,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1870  
1871  static int remove_all(struct dm_ioctl *param, size_t param_size)
1872  {
1873 +       if (!vx_check(0, VS_ADMIN))
1874 +               return -EPERM;
1875 +
1876         dm_hash_remove_all(1);
1877         param->data_size = 0;
1878         return 0;
1879 @@ -424,6 +430,8 @@ static int list_devices(struct dm_ioctl 
1880          */
1881         for (i = 0; i < NUM_BUCKETS; i++) {
1882                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1883 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1884 +                               continue;
1885                         needed += sizeof(struct dm_name_list);
1886                         needed += strlen(hc->name) + 1;
1887                         needed += ALIGN_MASK;
1888 @@ -447,6 +455,8 @@ static int list_devices(struct dm_ioctl 
1889          */
1890         for (i = 0; i < NUM_BUCKETS; i++) {
1891                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1892 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1893 +                               continue;
1894                         if (old_nl)
1895                                 old_nl->next = (uint32_t) ((void *) nl -
1896                                                            (void *) old_nl);
1897 @@ -681,10 +691,11 @@ static struct hash_cell *__find_device_h
1898         if (!md)
1899                 goto out;
1900  
1901 -       mdptr = dm_get_mdptr(md);
1902 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1903 +               mdptr = dm_get_mdptr(md);
1904 +
1905         if (!mdptr)
1906                 dm_put(md);
1907 -
1908  out:
1909         return mdptr;
1910  }
1911 @@ -1513,8 +1524,8 @@ static int ctl_ioctl(uint command, struc
1912         ioctl_fn fn = NULL;
1913         size_t param_size;
1914  
1915 -       /* only root can play with this */
1916 -       if (!capable(CAP_SYS_ADMIN))
1917 +       /* only root and certain contexts can play with this */
1918 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1919                 return -EACCES;
1920  
1921         if (_IOC_TYPE(command) != DM_IOCTL)
1922 diff -NurpP --minimal linux-2.6.37/drivers/net/tun.c linux-2.6.37-vs2.3.0.37-rc3/drivers/net/tun.c
1923 --- linux-2.6.37/drivers/net/tun.c      2010-10-21 13:07:15.000000000 +0200
1924 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/net/tun.c       2010-11-23 02:09:41.000000000 +0100
1925 @@ -62,6 +62,7 @@
1926  #include <linux/nsproxy.h>
1927  #include <linux/virtio_net.h>
1928  #include <linux/rcupdate.h>
1929 +#include <linux/vs_network.h>
1930  #include <net/net_namespace.h>
1931  #include <net/netns/generic.h>
1932  #include <net/rtnetlink.h>
1933 @@ -103,6 +104,7 @@ struct tun_struct {
1934         unsigned int            flags;
1935         uid_t                   owner;
1936         gid_t                   group;
1937 +       nid_t                   nid;
1938  
1939         struct net_device       *dev;
1940         struct fasync_struct    *fasync;
1941 @@ -853,6 +855,7 @@ static void tun_setup(struct net_device 
1942  
1943         tun->owner = -1;
1944         tun->group = -1;
1945 +       tun->nid = current->nid;
1946  
1947         dev->ethtool_ops = &tun_ethtool_ops;
1948         dev->destructor = tun_free_netdev;
1949 @@ -1003,7 +1006,7 @@ static int tun_set_iff(struct net *net, 
1950  
1951                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1952                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1953 -                   !capable(CAP_NET_ADMIN))
1954 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1955                         return -EPERM;
1956                 err = security_tun_dev_attach(tun->socket.sk);
1957                 if (err < 0)
1958 @@ -1017,7 +1020,7 @@ static int tun_set_iff(struct net *net, 
1959                 char *name;
1960                 unsigned long flags = 0;
1961  
1962 -               if (!capable(CAP_NET_ADMIN))
1963 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1964                         return -EPERM;
1965                 err = security_tun_dev_create();
1966                 if (err < 0)
1967 @@ -1087,6 +1090,9 @@ static int tun_set_iff(struct net *net, 
1968  
1969                 sk->sk_destruct = tun_sock_destruct;
1970  
1971 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1972 +                       return -EPERM;
1973 +
1974                 err = tun_attach(tun, file);
1975                 if (err < 0)
1976                         goto failed;
1977 @@ -1278,6 +1284,16 @@ static long __tun_chr_ioctl(struct file 
1978                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1979                 break;
1980  
1981 +       case TUNSETNID:
1982 +               if (!capable(CAP_CONTEXT))
1983 +                       return -EPERM;
1984 +
1985 +               /* Set nid owner of the device */
1986 +               tun->nid = (nid_t) arg;
1987 +
1988 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1989 +               break;
1990 +
1991         case TUNSETLINK:
1992                 /* Only allow setting the type when the interface is down */
1993                 if (tun->dev->flags & IFF_UP) {
1994 diff -NurpP --minimal linux-2.6.37/drivers/tty/sysrq.c linux-2.6.37-vs2.3.0.37-rc3/drivers/tty/sysrq.c
1995 --- linux-2.6.37/drivers/tty/sysrq.c    2011-01-05 21:50:13.000000000 +0100
1996 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/tty/sysrq.c     2010-11-23 02:09:41.000000000 +0100
1997 @@ -41,6 +41,7 @@
1998  #include <linux/oom.h>
1999  #include <linux/slab.h>
2000  #include <linux/input.h>
2001 +#include <linux/vserver/debug.h>
2002  
2003  #include <asm/ptrace.h>
2004  #include <asm/irq_regs.h>
2005 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
2006         .enable_mask    = SYSRQ_ENABLE_RTNICE,
2007  };
2008  
2009 +
2010 +#ifdef CONFIG_VSERVER_DEBUG
2011 +static void sysrq_handle_vxinfo(int key)
2012 +{
2013 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
2014 +}
2015 +
2016 +static struct sysrq_key_op sysrq_showvxinfo_op = {
2017 +       .handler        = sysrq_handle_vxinfo,
2018 +       .help_msg       = "conteXt",
2019 +       .action_msg     = "Show Context Info",
2020 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
2021 +};
2022 +#endif
2023 +
2024  /* Key Operations table and lock */
2025  static DEFINE_SPINLOCK(sysrq_key_table_lock);
2026  
2027 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
2028         NULL,                           /* v */
2029         &sysrq_showstate_blocked_op,    /* w */
2030         /* x: May be registered on ppc/powerpc for xmon */
2031 +#ifdef CONFIG_VSERVER_DEBUG
2032 +       &sysrq_showvxinfo_op,           /* x */
2033 +#else
2034         NULL,                           /* x */
2035 +#endif
2036         /* y: May be registered on sparc64 for global register dump */
2037         NULL,                           /* y */
2038         &sysrq_ftrace_dump_op,          /* z */
2039 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
2040                 retval = key - '0';
2041         else if ((key >= 'a') && (key <= 'z'))
2042                 retval = key + 10 - 'a';
2043 +       else if ((key >= 'A') && (key <= 'Z'))
2044 +               retval = key + 10 - 'A';
2045         else
2046                 retval = -1;
2047         return retval;
2048 diff -NurpP --minimal linux-2.6.37/drivers/tty/tty_io.c linux-2.6.37-vs2.3.0.37-rc3/drivers/tty/tty_io.c
2049 --- linux-2.6.37/drivers/tty/tty_io.c   2011-01-05 21:50:13.000000000 +0100
2050 +++ linux-2.6.37-vs2.3.0.37-rc3/drivers/tty/tty_io.c    2011-01-05 22:30:36.000000000 +0100
2051 @@ -107,6 +107,7 @@
2052  
2053  #include <linux/kmod.h>
2054  #include <linux/nsproxy.h>
2055 +#include <linux/vs_pid.h>
2056  
2057  #undef TTY_DEBUG_HANGUP
2058  
2059 @@ -2057,7 +2058,8 @@ static int tiocsti(struct tty_struct *tt
2060         char ch, mbz = 0;
2061         struct tty_ldisc *ld;
2062  
2063 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
2064 +       if (((current->signal->tty != tty) &&
2065 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
2066                 return -EPERM;
2067         if (get_user(ch, p))
2068                 return -EFAULT;
2069 @@ -2345,6 +2347,7 @@ static int tiocspgrp(struct tty_struct *
2070                 return -ENOTTY;
2071         if (get_user(pgrp_nr, p))
2072                 return -EFAULT;
2073 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
2074         if (pgrp_nr < 0)
2075                 return -EINVAL;
2076         rcu_read_lock();
2077 diff -NurpP --minimal linux-2.6.37/fs/attr.c linux-2.6.37-vs2.3.0.37-rc3/fs/attr.c
2078 --- linux-2.6.37/fs/attr.c      2010-10-21 13:07:47.000000000 +0200
2079 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/attr.c       2010-11-23 02:09:41.000000000 +0100
2080 @@ -13,6 +13,9 @@
2081  #include <linux/fsnotify.h>
2082  #include <linux/fcntl.h>
2083  #include <linux/security.h>
2084 +#include <linux/proc_fs.h>
2085 +#include <linux/devpts_fs.h>
2086 +#include <linux/vs_tag.h>
2087  
2088  /**
2089   * inode_change_ok - check if attribute changes to an inode are allowed
2090 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
2091                         return -EPERM;
2092         }
2093  
2094 +       /* check for inode tag permission */
2095 +       if (dx_permission(inode, MAY_WRITE))
2096 +               return -EACCES;
2097 +
2098         return 0;
2099  }
2100  EXPORT_SYMBOL(inode_change_ok);
2101 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
2102                 inode->i_uid = attr->ia_uid;
2103         if (ia_valid & ATTR_GID)
2104                 inode->i_gid = attr->ia_gid;
2105 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2106 +               inode->i_tag = attr->ia_tag;
2107         if (ia_valid & ATTR_ATIME)
2108                 inode->i_atime = timespec_trunc(attr->ia_atime,
2109                                                 inode->i_sb->s_time_gran);
2110 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
2111         struct timespec now;
2112         unsigned int ia_valid = attr->ia_valid;
2113  
2114 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
2115 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
2116 +               ATTR_TAG | ATTR_TIMES_SET)) {
2117                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2118                         return -EPERM;
2119         }
2120 diff -NurpP --minimal linux-2.6.37/fs/binfmt_aout.c linux-2.6.37-vs2.3.0.37-rc3/fs/binfmt_aout.c
2121 --- linux-2.6.37/fs/binfmt_aout.c       2010-10-21 13:07:47.000000000 +0200
2122 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/binfmt_aout.c        2010-11-23 02:09:41.000000000 +0100
2123 @@ -25,6 +25,7 @@
2124  #include <linux/init.h>
2125  #include <linux/coredump.h>
2126  #include <linux/slab.h>
2127 +#include <linux/vs_memory.h>
2128  
2129  #include <asm/system.h>
2130  #include <asm/uaccess.h>
2131 diff -NurpP --minimal linux-2.6.37/fs/binfmt_elf.c linux-2.6.37-vs2.3.0.37-rc3/fs/binfmt_elf.c
2132 --- linux-2.6.37/fs/binfmt_elf.c        2011-01-05 21:50:20.000000000 +0100
2133 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/binfmt_elf.c 2010-11-23 02:09:41.000000000 +0100
2134 @@ -32,6 +32,7 @@
2135  #include <linux/elf.h>
2136  #include <linux/utsname.h>
2137  #include <linux/coredump.h>
2138 +#include <linux/vs_memory.h>
2139  #include <asm/uaccess.h>
2140  #include <asm/param.h>
2141  #include <asm/page.h>
2142 diff -NurpP --minimal linux-2.6.37/fs/binfmt_flat.c linux-2.6.37-vs2.3.0.37-rc3/fs/binfmt_flat.c
2143 --- linux-2.6.37/fs/binfmt_flat.c       2010-08-02 16:52:47.000000000 +0200
2144 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/binfmt_flat.c        2010-11-23 02:09:41.000000000 +0100
2145 @@ -35,6 +35,7 @@
2146  #include <linux/init.h>
2147  #include <linux/flat.h>
2148  #include <linux/syscalls.h>
2149 +#include <linux/vs_memory.h>
2150  
2151  #include <asm/byteorder.h>
2152  #include <asm/system.h>
2153 diff -NurpP --minimal linux-2.6.37/fs/binfmt_som.c linux-2.6.37-vs2.3.0.37-rc3/fs/binfmt_som.c
2154 --- linux-2.6.37/fs/binfmt_som.c        2010-02-25 11:52:04.000000000 +0100
2155 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/binfmt_som.c 2010-11-23 02:09:41.000000000 +0100
2156 @@ -28,6 +28,7 @@
2157  #include <linux/shm.h>
2158  #include <linux/personality.h>
2159  #include <linux/init.h>
2160 +#include <linux/vs_memory.h>
2161  
2162  #include <asm/uaccess.h>
2163  #include <asm/pgtable.h>
2164 diff -NurpP --minimal linux-2.6.37/fs/block_dev.c linux-2.6.37-vs2.3.0.37-rc3/fs/block_dev.c
2165 --- linux-2.6.37/fs/block_dev.c 2011-01-05 21:50:20.000000000 +0100
2166 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/block_dev.c  2010-11-23 02:09:41.000000000 +0100
2167 @@ -25,6 +25,7 @@
2168  #include <linux/namei.h>
2169  #include <linux/log2.h>
2170  #include <linux/kmemleak.h>
2171 +#include <linux/vs_device.h>
2172  #include <asm/uaccess.h>
2173  #include "internal.h"
2174  
2175 @@ -544,6 +545,7 @@ struct block_device *bdget(dev_t dev)
2176                 bdev->bd_invalidated = 0;
2177                 inode->i_mode = S_IFBLK;
2178                 inode->i_rdev = dev;
2179 +               inode->i_mdev = dev;
2180                 inode->i_bdev = bdev;
2181                 inode->i_data.a_ops = &def_blk_aops;
2182                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2183 @@ -590,6 +592,11 @@ EXPORT_SYMBOL(bdput);
2184  static struct block_device *bd_acquire(struct inode *inode)
2185  {
2186         struct block_device *bdev;
2187 +       dev_t mdev;
2188 +
2189 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2190 +               return NULL;
2191 +       inode->i_mdev = mdev;
2192  
2193         spin_lock(&bdev_lock);
2194         bdev = inode->i_bdev;
2195 @@ -600,7 +607,7 @@ static struct block_device *bd_acquire(s
2196         }
2197         spin_unlock(&bdev_lock);
2198  
2199 -       bdev = bdget(inode->i_rdev);
2200 +       bdev = bdget(mdev);
2201         if (bdev) {
2202                 spin_lock(&bdev_lock);
2203                 if (!inode->i_bdev) {
2204 diff -NurpP --minimal linux-2.6.37/fs/btrfs/ctree.h linux-2.6.37-vs2.3.0.37-rc3/fs/btrfs/ctree.h
2205 --- linux-2.6.37/fs/btrfs/ctree.h       2011-01-05 21:50:20.000000000 +0100
2206 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/btrfs/ctree.h        2011-01-05 22:30:38.000000000 +0100
2207 @@ -574,11 +574,14 @@ struct btrfs_inode_item {
2208         /* modification sequence number for NFS */
2209         __le64 sequence;
2210  
2211 +       __le16 tag;
2212         /*
2213          * a little future expansion, for more than this we can
2214          * just grow the inode item and version it
2215          */
2216 -       __le64 reserved[4];
2217 +       __le16 reserved16;
2218 +       __le32 reserved32;
2219 +       __le64 reserved[3];
2220         struct btrfs_timespec atime;
2221         struct btrfs_timespec ctime;
2222         struct btrfs_timespec mtime;
2223 @@ -1236,6 +1239,8 @@ struct btrfs_root {
2224  #define BTRFS_MOUNT_CLEAR_CACHE                (1 << 13)
2225  #define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 14)
2226  
2227 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2228 +
2229  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2230  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2231  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2232 @@ -1456,6 +1461,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2233  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2234  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2235  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2236 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2237  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2238  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2239  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2240 @@ -1517,6 +1523,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
2241  
2242  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
2243  
2244 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2245 +#define BTRFS_INODE_BARRIER            (1 << 25)
2246 +#define BTRFS_INODE_COW                        (1 << 26)
2247 +
2248  
2249  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
2250  
2251 @@ -2510,6 +2520,7 @@ extern const struct dentry_operations bt
2252  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2253  void btrfs_update_iflags(struct inode *inode);
2254  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2255 +int btrfs_sync_flags(struct inode *inode, int, int);
2256  
2257  /* file.c */
2258  int btrfs_sync_file(struct file *file, int datasync);
2259 diff -NurpP --minimal linux-2.6.37/fs/btrfs/disk-io.c linux-2.6.37-vs2.3.0.37-rc3/fs/btrfs/disk-io.c
2260 --- linux-2.6.37/fs/btrfs/disk-io.c     2011-01-05 21:50:20.000000000 +0100
2261 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/btrfs/disk-io.c      2011-01-05 22:30:38.000000000 +0100
2262 @@ -1733,6 +1733,9 @@ struct btrfs_root *open_ctree(struct sup
2263                 goto fail_iput;
2264         }
2265  
2266 +       if (btrfs_test_opt(tree_root, TAGGED))
2267 +               sb->s_flags |= MS_TAGGED;
2268 +
2269         features = btrfs_super_incompat_flags(disk_super) &
2270                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2271         if (features) {
2272 diff -NurpP --minimal linux-2.6.37/fs/btrfs/inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/btrfs/inode.c
2273 --- linux-2.6.37/fs/btrfs/inode.c       2011-01-05 21:50:21.000000000 +0100
2274 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/btrfs/inode.c        2011-01-05 22:30:38.000000000 +0100
2275 @@ -37,6 +37,8 @@
2276  #include <linux/posix_acl.h>
2277  #include <linux/falloc.h>
2278  #include <linux/slab.h>
2279 +#include <linux/vs_tag.h>
2280 +
2281  #include "compat.h"
2282  #include "ctree.h"
2283  #include "disk-io.h"
2284 @@ -2440,6 +2442,8 @@ static void btrfs_read_locked_inode(stru
2285         int maybe_acls;
2286         u64 alloc_group_block;
2287         u32 rdev;
2288 +       uid_t uid;
2289 +       gid_t gid;
2290         int ret;
2291  
2292         path = btrfs_alloc_path();
2293 @@ -2456,8 +2460,13 @@ static void btrfs_read_locked_inode(stru
2294  
2295         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2296         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2297 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2298 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2299 +
2300 +       uid = btrfs_inode_uid(leaf, inode_item);
2301 +       gid = btrfs_inode_gid(leaf, inode_item);
2302 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2303 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2304 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2305 +               btrfs_inode_tag(leaf, inode_item));
2306         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2307  
2308         tspec = btrfs_inode_atime(inode_item);
2309 @@ -2539,8 +2548,15 @@ static void fill_inode_item(struct btrfs
2310                             struct btrfs_inode_item *item,
2311                             struct inode *inode)
2312  {
2313 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2314 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2315 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2316 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2317 +
2318 +       btrfs_set_inode_uid(leaf, item, uid);
2319 +       btrfs_set_inode_gid(leaf, item, gid);
2320 +#ifdef CONFIG_TAGGING_INTERN
2321 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2322 +#endif
2323 +
2324         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2325         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2326         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2327 @@ -7228,6 +7244,7 @@ static const struct inode_operations btr
2328         .listxattr      = btrfs_listxattr,
2329         .removexattr    = btrfs_removexattr,
2330         .permission     = btrfs_permission,
2331 +       .sync_flags     = btrfs_sync_flags,
2332  };
2333  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2334         .lookup         = btrfs_lookup,
2335 @@ -7303,6 +7320,7 @@ static const struct inode_operations btr
2336         .permission     = btrfs_permission,
2337         .fallocate      = btrfs_fallocate,
2338         .fiemap         = btrfs_fiemap,
2339 +       .sync_flags     = btrfs_sync_flags,
2340  };
2341  static const struct inode_operations btrfs_special_inode_operations = {
2342         .getattr        = btrfs_getattr,
2343 diff -NurpP --minimal linux-2.6.37/fs/btrfs/ioctl.c linux-2.6.37-vs2.3.0.37-rc3/fs/btrfs/ioctl.c
2344 --- linux-2.6.37/fs/btrfs/ioctl.c       2011-01-05 21:50:21.000000000 +0100
2345 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/btrfs/ioctl.c        2011-01-05 22:30:39.000000000 +0100
2346 @@ -68,10 +68,13 @@ static unsigned int btrfs_flags_to_ioctl
2347  {
2348         unsigned int iflags = 0;
2349  
2350 -       if (flags & BTRFS_INODE_SYNC)
2351 -               iflags |= FS_SYNC_FL;
2352         if (flags & BTRFS_INODE_IMMUTABLE)
2353                 iflags |= FS_IMMUTABLE_FL;
2354 +       if (flags & BTRFS_INODE_IXUNLINK)
2355 +               iflags |= FS_IXUNLINK_FL;
2356 +
2357 +       if (flags & BTRFS_INODE_SYNC)
2358 +               iflags |= FS_SYNC_FL;
2359         if (flags & BTRFS_INODE_APPEND)
2360                 iflags |= FS_APPEND_FL;
2361         if (flags & BTRFS_INODE_NODUMP)
2362 @@ -81,28 +84,78 @@ static unsigned int btrfs_flags_to_ioctl
2363         if (flags & BTRFS_INODE_DIRSYNC)
2364                 iflags |= FS_DIRSYNC_FL;
2365  
2366 +       if (flags & BTRFS_INODE_BARRIER)
2367 +               iflags |= FS_BARRIER_FL;
2368 +       if (flags & BTRFS_INODE_COW)
2369 +               iflags |= FS_COW_FL;
2370         return iflags;
2371  }
2372  
2373  /*
2374 - * Update inode->i_flags based on the btrfs internal flags.
2375 + * Update inode->i_(v)flags based on the btrfs internal flags.
2376   */
2377  void btrfs_update_iflags(struct inode *inode)
2378  {
2379         struct btrfs_inode *ip = BTRFS_I(inode);
2380  
2381 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2382 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2383 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2384  
2385 -       if (ip->flags & BTRFS_INODE_SYNC)
2386 -               inode->i_flags |= S_SYNC;
2387         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2388                 inode->i_flags |= S_IMMUTABLE;
2389 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2390 +               inode->i_flags |= S_IXUNLINK;
2391 +
2392 +       if (ip->flags & BTRFS_INODE_SYNC)
2393 +               inode->i_flags |= S_SYNC;
2394         if (ip->flags & BTRFS_INODE_APPEND)
2395                 inode->i_flags |= S_APPEND;
2396         if (ip->flags & BTRFS_INODE_NOATIME)
2397                 inode->i_flags |= S_NOATIME;
2398         if (ip->flags & BTRFS_INODE_DIRSYNC)
2399                 inode->i_flags |= S_DIRSYNC;
2400 +
2401 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2402 +
2403 +       if (ip->flags & BTRFS_INODE_BARRIER)
2404 +               inode->i_vflags |= V_BARRIER;
2405 +       if (ip->flags & BTRFS_INODE_COW)
2406 +               inode->i_vflags |= V_COW;
2407 +}
2408 +
2409 +/*
2410 + * Update btrfs internal flags from inode->i_(v)flags.
2411 + */
2412 +void btrfs_update_flags(struct inode *inode)
2413 +{
2414 +       struct btrfs_inode *ip = BTRFS_I(inode);
2415 +
2416 +       unsigned int flags = inode->i_flags;
2417 +       unsigned int vflags = inode->i_vflags;
2418 +
2419 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2420 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2421 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2422 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2423 +
2424 +       if (flags & S_IMMUTABLE)
2425 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2426 +       if (flags & S_IXUNLINK)
2427 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2428 +
2429 +       if (flags & S_SYNC)
2430 +               ip->flags |= BTRFS_INODE_SYNC;
2431 +       if (flags & S_APPEND)
2432 +               ip->flags |= BTRFS_INODE_APPEND;
2433 +       if (flags & S_NOATIME)
2434 +               ip->flags |= BTRFS_INODE_NOATIME;
2435 +       if (flags & S_DIRSYNC)
2436 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2437 +
2438 +       if (vflags & V_BARRIER)
2439 +               ip->flags |= BTRFS_INODE_BARRIER;
2440 +       if (vflags & V_COW)
2441 +               ip->flags |= BTRFS_INODE_COW;
2442  }
2443  
2444  /*
2445 @@ -120,7 +173,7 @@ void btrfs_inherit_iflags(struct inode *
2446         flags = BTRFS_I(dir)->flags;
2447  
2448         if (S_ISREG(inode->i_mode))
2449 -               flags &= ~BTRFS_INODE_DIRSYNC;
2450 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2451         else if (!S_ISDIR(inode->i_mode))
2452                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2453  
2454 @@ -128,6 +181,30 @@ void btrfs_inherit_iflags(struct inode *
2455         btrfs_update_iflags(inode);
2456  }
2457  
2458 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2459 +{
2460 +       struct btrfs_inode *ip = BTRFS_I(inode);
2461 +       struct btrfs_root *root = ip->root;
2462 +       struct btrfs_trans_handle *trans;
2463 +       int ret;
2464 +
2465 +       trans = btrfs_join_transaction(root, 1);
2466 +       BUG_ON(!trans);
2467 +
2468 +       inode->i_flags = flags;
2469 +       inode->i_vflags = vflags;
2470 +       btrfs_update_flags(inode);
2471 +
2472 +       ret = btrfs_update_inode(trans, root, inode);
2473 +       BUG_ON(ret);
2474 +
2475 +       btrfs_update_iflags(inode);
2476 +       inode->i_ctime = CURRENT_TIME;
2477 +       btrfs_end_transaction(trans, root);
2478 +
2479 +       return 0;
2480 +}
2481 +
2482  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2483  {
2484         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2485 @@ -150,6 +227,7 @@ static int btrfs_ioctl_setflags(struct f
2486         if (copy_from_user(&flags, arg, sizeof(flags)))
2487                 return -EFAULT;
2488  
2489 +       /* maybe add FS_IXUNLINK_FL ? */
2490         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2491                       FS_NOATIME_FL | FS_NODUMP_FL | \
2492                       FS_SYNC_FL | FS_DIRSYNC_FL))
2493 @@ -162,7 +240,8 @@ static int btrfs_ioctl_setflags(struct f
2494  
2495         flags = btrfs_mask_flags(inode->i_mode, flags);
2496         oldflags = btrfs_flags_to_ioctl(ip->flags);
2497 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2498 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2499 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2500                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2501                         ret = -EPERM;
2502                         goto out_unlock;
2503 @@ -173,14 +252,19 @@ static int btrfs_ioctl_setflags(struct f
2504         if (ret)
2505                 goto out_unlock;
2506  
2507 -       if (flags & FS_SYNC_FL)
2508 -               ip->flags |= BTRFS_INODE_SYNC;
2509 -       else
2510 -               ip->flags &= ~BTRFS_INODE_SYNC;
2511         if (flags & FS_IMMUTABLE_FL)
2512                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2513         else
2514                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2515 +       if (flags & FS_IXUNLINK_FL)
2516 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2517 +       else
2518 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2519 +
2520 +       if (flags & FS_SYNC_FL)
2521 +               ip->flags |= BTRFS_INODE_SYNC;
2522 +       else
2523 +               ip->flags &= ~BTRFS_INODE_SYNC;
2524         if (flags & FS_APPEND_FL)
2525                 ip->flags |= BTRFS_INODE_APPEND;
2526         else
2527 diff -NurpP --minimal linux-2.6.37/fs/btrfs/super.c linux-2.6.37-vs2.3.0.37-rc3/fs/btrfs/super.c
2528 --- linux-2.6.37/fs/btrfs/super.c       2011-01-05 21:50:21.000000000 +0100
2529 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/btrfs/super.c        2011-01-05 23:28:17.000000000 +0100
2530 @@ -70,8 +70,9 @@ enum {
2531         Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd,
2532         Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
2533         Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
2534 -       Opt_discard, Opt_space_cache, Opt_clear_cache, Opt_err,
2535 +       Opt_discard, Opt_space_cache, Opt_clear_cache,
2536         Opt_user_subvol_rm_allowed,
2537 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2538  };
2539  
2540  static match_table_t tokens = {
2541 @@ -98,6 +99,9 @@ static match_table_t tokens = {
2542         {Opt_space_cache, "space_cache"},
2543         {Opt_clear_cache, "clear_cache"},
2544         {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
2545 +       {Opt_tag, "tag"},
2546 +       {Opt_notag, "notag"},
2547 +       {Opt_tagid, "tagid=%u"},
2548         {Opt_err, NULL},
2549  };
2550  
2551 @@ -252,6 +256,22 @@ int btrfs_parse_options(struct btrfs_roo
2552                 case Opt_user_subvol_rm_allowed:
2553                         btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED);
2554                         break;
2555 +#ifndef CONFIG_TAGGING_NONE
2556 +               case Opt_tag:
2557 +                       printk(KERN_INFO "btrfs: use tagging\n");
2558 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2559 +                       break;
2560 +               case Opt_notag:
2561 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2562 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2563 +                       break;
2564 +#endif
2565 +#ifdef CONFIG_PROPAGATE
2566 +               case Opt_tagid:
2567 +                       /* use args[0] */
2568 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2569 +                       break;
2570 +#endif
2571                 case Opt_err:
2572                         printk(KERN_INFO "btrfs: unrecognized mount option "
2573                                "'%s'\n", p);
2574 @@ -724,6 +744,12 @@ static int btrfs_remount(struct super_bl
2575         if (ret)
2576                 return -EINVAL;
2577  
2578 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2579 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2580 +                       sb->s_id);
2581 +               return -EINVAL;
2582 +       }
2583 +
2584         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2585                 return 0;
2586  
2587 diff -NurpP --minimal linux-2.6.37/fs/char_dev.c linux-2.6.37-vs2.3.0.37-rc3/fs/char_dev.c
2588 --- linux-2.6.37/fs/char_dev.c  2011-01-05 21:50:22.000000000 +0100
2589 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/char_dev.c   2010-11-23 02:09:41.000000000 +0100
2590 @@ -21,6 +21,8 @@
2591  #include <linux/mutex.h>
2592  #include <linux/backing-dev.h>
2593  #include <linux/tty.h>
2594 +#include <linux/vs_context.h>
2595 +#include <linux/vs_device.h>
2596  
2597  #include "internal.h"
2598  
2599 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2600         struct cdev *p;
2601         struct cdev *new = NULL;
2602         int ret = 0;
2603 +       dev_t mdev;
2604 +
2605 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2606 +               return -EPERM;
2607 +       inode->i_mdev = mdev;
2608  
2609         spin_lock(&cdev_lock);
2610         p = inode->i_cdev;
2611         if (!p) {
2612                 struct kobject *kobj;
2613                 int idx;
2614 +
2615                 spin_unlock(&cdev_lock);
2616 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2617 +
2618 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2619                 if (!kobj)
2620                         return -ENXIO;
2621                 new = container_of(kobj, struct cdev, kobj);
2622 diff -NurpP --minimal linux-2.6.37/fs/dcache.c linux-2.6.37-vs2.3.0.37-rc3/fs/dcache.c
2623 --- linux-2.6.37/fs/dcache.c    2011-01-05 21:50:22.000000000 +0100
2624 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/dcache.c     2010-11-23 03:34:02.000000000 +0100
2625 @@ -33,6 +33,7 @@
2626  #include <linux/bootmem.h>
2627  #include <linux/fs_struct.h>
2628  #include <linux/hardirq.h>
2629 +#include <linux/vs_limit.h>
2630  #include "internal.h"
2631  
2632  int sysctl_vfs_cache_pressure __read_mostly = 100;
2633 @@ -236,6 +237,8 @@ repeat:
2634                 return;
2635         }
2636  
2637 +       vx_dentry_dec(dentry);
2638 +
2639         /*
2640          * AV: ->d_delete() is _NOT_ allowed to block now.
2641          */
2642 @@ -330,6 +333,7 @@ static inline struct dentry * __dget_loc
2643  {
2644         atomic_inc(&dentry->d_count);
2645         dentry_lru_del(dentry);
2646 +       vx_dentry_inc(dentry);
2647         return dentry;
2648  }
2649  
2650 @@ -940,6 +944,9 @@ struct dentry *d_alloc(struct dentry * p
2651         struct dentry *dentry;
2652         char *dname;
2653  
2654 +       if (!vx_dentry_avail(1))
2655 +               return NULL;
2656 +
2657         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2658         if (!dentry)
2659                 return NULL;
2660 @@ -961,6 +968,7 @@ struct dentry *d_alloc(struct dentry * p
2661         dname[name->len] = 0;
2662  
2663         atomic_set(&dentry->d_count, 1);
2664 +       vx_dentry_inc(dentry);
2665         dentry->d_flags = DCACHE_UNHASHED;
2666         spin_lock_init(&dentry->d_lock);
2667         dentry->d_inode = NULL;
2668 @@ -1445,6 +1453,7 @@ struct dentry * __d_lookup(struct dentry
2669                 }
2670  
2671                 atomic_inc(&dentry->d_count);
2672 +               vx_dentry_inc(dentry);
2673                 found = dentry;
2674                 spin_unlock(&dentry->d_lock);
2675                 break;
2676 diff -NurpP --minimal linux-2.6.37/fs/devpts/inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/devpts/inode.c
2677 --- linux-2.6.37/fs/devpts/inode.c      2011-01-05 21:50:22.000000000 +0100
2678 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/devpts/inode.c       2010-11-23 02:09:41.000000000 +0100
2679 @@ -25,6 +25,7 @@
2680  #include <linux/parser.h>
2681  #include <linux/fsnotify.h>
2682  #include <linux/seq_file.h>
2683 +#include <linux/vs_base.h>
2684  
2685  #define DEVPTS_DEFAULT_MODE 0600
2686  /*
2687 @@ -36,6 +37,20 @@
2688  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2689  #define PTMX_MINOR     2
2690  
2691 +static int devpts_permission(struct inode *inode, int mask)
2692 +{
2693 +       int ret = -EACCES;
2694 +
2695 +       /* devpts is xid tagged */
2696 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2697 +               ret = generic_permission(inode, mask, NULL);
2698 +       return ret;
2699 +}
2700 +
2701 +static struct inode_operations devpts_file_inode_operations = {
2702 +       .permission     = devpts_permission,
2703 +};
2704 +
2705  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2706  static DEFINE_MUTEX(allocated_ptys_lock);
2707  
2708 @@ -263,6 +278,25 @@ static int devpts_show_options(struct se
2709         return 0;
2710  }
2711  
2712 +static int devpts_filter(struct dentry *de)
2713 +{
2714 +       /* devpts is xid tagged */
2715 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2716 +}
2717 +
2718 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2719 +{
2720 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2721 +}
2722 +
2723 +static struct file_operations devpts_dir_operations = {
2724 +       .open           = dcache_dir_open,
2725 +       .release        = dcache_dir_close,
2726 +       .llseek         = dcache_dir_lseek,
2727 +       .read           = generic_read_dir,
2728 +       .readdir        = devpts_readdir,
2729 +};
2730 +
2731  static const struct super_operations devpts_sops = {
2732         .statfs         = simple_statfs,
2733         .remount_fs     = devpts_remount,
2734 @@ -302,12 +336,15 @@ devpts_fill_super(struct super_block *s,
2735         inode = new_inode(s);
2736         if (!inode)
2737                 goto free_fsi;
2738 +
2739         inode->i_ino = 1;
2740         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2741         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2742         inode->i_op = &simple_dir_inode_operations;
2743 -       inode->i_fop = &simple_dir_operations;
2744 +       inode->i_fop = &devpts_dir_operations;
2745         inode->i_nlink = 2;
2746 +       /* devpts is xid tagged */
2747 +       inode->i_tag = (tag_t)vx_current_xid();
2748  
2749         s->s_root = d_alloc_root(inode);
2750         if (s->s_root)
2751 @@ -493,6 +530,9 @@ int devpts_pty_new(struct inode *ptmx_in
2752         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2753         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2754         init_special_inode(inode, S_IFCHR|opts->mode, device);
2755 +       /* devpts is xid tagged */
2756 +       inode->i_tag = (tag_t)vx_current_xid();
2757 +       inode->i_op = &devpts_file_inode_operations;
2758         inode->i_private = tty;
2759         tty->driver_data = inode;
2760  
2761 diff -NurpP --minimal linux-2.6.37/fs/ext2/balloc.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/balloc.c
2762 --- linux-2.6.37/fs/ext2/balloc.c       2011-01-05 21:50:22.000000000 +0100
2763 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/balloc.c        2010-11-23 02:09:41.000000000 +0100
2764 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2765                         start = 0;
2766                 end = EXT2_BLOCKS_PER_GROUP(sb);
2767         }
2768 -
2769         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2770  
2771  repeat:
2772 diff -NurpP --minimal linux-2.6.37/fs/ext2/ext2.h linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/ext2.h
2773 --- linux-2.6.37/fs/ext2/ext2.h 2011-01-05 21:50:22.000000000 +0100
2774 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/ext2.h  2010-11-23 02:09:41.000000000 +0100
2775 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2776  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2777  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2778                        u64 start, u64 len);
2779 +extern int ext2_sync_flags(struct inode *, int, int);
2780  
2781  /* ioctl.c */
2782  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2783 diff -NurpP --minimal linux-2.6.37/fs/ext2/file.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/file.c
2784 --- linux-2.6.37/fs/ext2/file.c 2010-08-02 16:52:48.000000000 +0200
2785 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/file.c  2010-11-23 02:09:41.000000000 +0100
2786 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2787         .setattr        = ext2_setattr,
2788         .check_acl      = ext2_check_acl,
2789         .fiemap         = ext2_fiemap,
2790 +       .sync_flags     = ext2_sync_flags,
2791  };
2792 diff -NurpP --minimal linux-2.6.37/fs/ext2/ialloc.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/ialloc.c
2793 --- linux-2.6.37/fs/ext2/ialloc.c       2010-10-21 13:07:48.000000000 +0200
2794 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/ialloc.c        2010-11-23 02:09:41.000000000 +0100
2795 @@ -17,6 +17,7 @@
2796  #include <linux/backing-dev.h>
2797  #include <linux/buffer_head.h>
2798  #include <linux/random.h>
2799 +#include <linux/vs_tag.h>
2800  #include "ext2.h"
2801  #include "xattr.h"
2802  #include "acl.h"
2803 @@ -548,6 +549,7 @@ got:
2804                 inode->i_mode = mode;
2805                 inode->i_uid = current_fsuid();
2806                 inode->i_gid = dir->i_gid;
2807 +               inode->i_tag = dx_current_fstag(sb);
2808         } else
2809                 inode_init_owner(inode, dir, mode);
2810  
2811 diff -NurpP --minimal linux-2.6.37/fs/ext2/inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/inode.c
2812 --- linux-2.6.37/fs/ext2/inode.c        2011-01-05 21:50:22.000000000 +0100
2813 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/inode.c 2010-11-23 02:09:41.000000000 +0100
2814 @@ -32,6 +32,7 @@
2815  #include <linux/mpage.h>
2816  #include <linux/fiemap.h>
2817  #include <linux/namei.h>
2818 +#include <linux/vs_tag.h>
2819  #include "ext2.h"
2820  #include "acl.h"
2821  #include "xip.h"
2822 @@ -1169,7 +1170,7 @@ static void ext2_truncate_blocks(struct 
2823                 return;
2824         if (ext2_inode_is_fast_symlink(inode))
2825                 return;
2826 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2827 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2828                 return;
2829         __ext2_truncate_blocks(inode, offset);
2830  }
2831 @@ -1258,36 +1259,61 @@ void ext2_set_inode_flags(struct inode *
2832  {
2833         unsigned int flags = EXT2_I(inode)->i_flags;
2834  
2835 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2836 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2837 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2838 +
2839 +
2840 +       if (flags & EXT2_IMMUTABLE_FL)
2841 +               inode->i_flags |= S_IMMUTABLE;
2842 +       if (flags & EXT2_IXUNLINK_FL)
2843 +               inode->i_flags |= S_IXUNLINK;
2844 +
2845         if (flags & EXT2_SYNC_FL)
2846                 inode->i_flags |= S_SYNC;
2847         if (flags & EXT2_APPEND_FL)
2848                 inode->i_flags |= S_APPEND;
2849 -       if (flags & EXT2_IMMUTABLE_FL)
2850 -               inode->i_flags |= S_IMMUTABLE;
2851         if (flags & EXT2_NOATIME_FL)
2852                 inode->i_flags |= S_NOATIME;
2853         if (flags & EXT2_DIRSYNC_FL)
2854                 inode->i_flags |= S_DIRSYNC;
2855 +
2856 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2857 +
2858 +       if (flags & EXT2_BARRIER_FL)
2859 +               inode->i_vflags |= V_BARRIER;
2860 +       if (flags & EXT2_COW_FL)
2861 +               inode->i_vflags |= V_COW;
2862  }
2863  
2864  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2865  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2866  {
2867         unsigned int flags = ei->vfs_inode.i_flags;
2868 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2869 +
2870 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2871 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2872 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2873 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2874 +
2875 +       if (flags & S_IMMUTABLE)
2876 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2877 +       if (flags & S_IXUNLINK)
2878 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2879  
2880 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2881 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2882         if (flags & S_SYNC)
2883                 ei->i_flags |= EXT2_SYNC_FL;
2884         if (flags & S_APPEND)
2885                 ei->i_flags |= EXT2_APPEND_FL;
2886 -       if (flags & S_IMMUTABLE)
2887 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2888         if (flags & S_NOATIME)
2889                 ei->i_flags |= EXT2_NOATIME_FL;
2890         if (flags & S_DIRSYNC)
2891                 ei->i_flags |= EXT2_DIRSYNC_FL;
2892 +
2893 +       if (vflags & V_BARRIER)
2894 +               ei->i_flags |= EXT2_BARRIER_FL;
2895 +       if (vflags & V_COW)
2896 +               ei->i_flags |= EXT2_COW_FL;
2897  }
2898  
2899  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2900 @@ -1297,6 +1323,8 @@ struct inode *ext2_iget (struct super_bl
2901         struct ext2_inode *raw_inode;
2902         struct inode *inode;
2903         long ret = -EIO;
2904 +       uid_t uid;
2905 +       gid_t gid;
2906         int n;
2907  
2908         inode = iget_locked(sb, ino);
2909 @@ -1315,12 +1343,17 @@ struct inode *ext2_iget (struct super_bl
2910         }
2911  
2912         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2913 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2914 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2915 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2916 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2917         if (!(test_opt (inode->i_sb, NO_UID32))) {
2918 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2919 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2920 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2921 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2922         }
2923 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2924 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2925 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2926 +               le16_to_cpu(raw_inode->i_raw_tag));
2927 +
2928         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2929         inode->i_size = le32_to_cpu(raw_inode->i_size);
2930         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2931 @@ -1418,8 +1451,8 @@ static int __ext2_write_inode(struct ino
2932         struct ext2_inode_info *ei = EXT2_I(inode);
2933         struct super_block *sb = inode->i_sb;
2934         ino_t ino = inode->i_ino;
2935 -       uid_t uid = inode->i_uid;
2936 -       gid_t gid = inode->i_gid;
2937 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2938 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2939         struct buffer_head * bh;
2940         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2941         int n;
2942 @@ -1455,6 +1488,9 @@ static int __ext2_write_inode(struct ino
2943                 raw_inode->i_uid_high = 0;
2944                 raw_inode->i_gid_high = 0;
2945         }
2946 +#ifdef CONFIG_TAGGING_INTERN
2947 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2948 +#endif
2949         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2950         raw_inode->i_size = cpu_to_le32(inode->i_size);
2951         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2952 @@ -1535,7 +1571,8 @@ int ext2_setattr(struct dentry *dentry, 
2953         if (is_quota_modification(inode, iattr))
2954                 dquot_initialize(inode);
2955         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2956 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2957 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2958 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2959                 error = dquot_transfer(inode, iattr);
2960                 if (error)
2961                         return error;
2962 diff -NurpP --minimal linux-2.6.37/fs/ext2/ioctl.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/ioctl.c
2963 --- linux-2.6.37/fs/ext2/ioctl.c        2009-09-10 15:26:21.000000000 +0200
2964 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/ioctl.c 2010-11-23 02:09:41.000000000 +0100
2965 @@ -17,6 +17,16 @@
2966  #include <asm/uaccess.h>
2967  
2968  
2969 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2970 +{
2971 +       inode->i_flags = flags;
2972 +       inode->i_vflags = vflags;
2973 +       ext2_get_inode_flags(EXT2_I(inode));
2974 +       inode->i_ctime = CURRENT_TIME_SEC;
2975 +       mark_inode_dirty(inode);
2976 +       return 0;
2977 +}
2978 +
2979  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2980  {
2981         struct inode *inode = filp->f_dentry->d_inode;
2982 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2983  
2984                 flags = ext2_mask_flags(inode->i_mode, flags);
2985  
2986 +               if (IS_BARRIER(inode)) {
2987 +                       vxwprintk_task(1, "messing with the barrier.");
2988 +                       return -EACCES;
2989 +               }
2990 +
2991                 mutex_lock(&inode->i_mutex);
2992                 /* Is it quota file? Do not allow user to mess with it */
2993                 if (IS_NOQUOTA(inode)) {
2994 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2995                  *
2996                  * This test looks nicer. Thanks to Pauline Middelink
2997                  */
2998 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2999 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
3000 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
3001 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
3002                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3003                                 mutex_unlock(&inode->i_mutex);
3004                                 ret = -EPERM;
3005 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
3006                         }
3007                 }
3008  
3009 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
3010 +               flags &= EXT2_FL_USER_MODIFIABLE;
3011                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
3012                 ei->i_flags = flags;
3013                 mutex_unlock(&inode->i_mutex);
3014 diff -NurpP --minimal linux-2.6.37/fs/ext2/namei.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/namei.c
3015 --- linux-2.6.37/fs/ext2/namei.c        2011-01-05 21:50:22.000000000 +0100
3016 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/namei.c 2010-11-23 02:09:41.000000000 +0100
3017 @@ -32,6 +32,7 @@
3018  
3019  #include <linux/pagemap.h>
3020  #include <linux/quotaops.h>
3021 +#include <linux/vs_tag.h>
3022  #include "ext2.h"
3023  #include "xattr.h"
3024  #include "acl.h"
3025 @@ -75,6 +76,7 @@ static struct dentry *ext2_lookup(struct
3026                                 return ERR_PTR(-EIO);
3027                         } else {
3028                                 return ERR_CAST(inode);
3029 +               dx_propagate_tag(nd, inode);
3030                         }
3031                 }
3032         }
3033 @@ -418,6 +420,7 @@ const struct inode_operations ext2_dir_i
3034  #endif
3035         .setattr        = ext2_setattr,
3036         .check_acl      = ext2_check_acl,
3037 +       .sync_flags     = ext2_sync_flags,
3038  };
3039  
3040  const struct inode_operations ext2_special_inode_operations = {
3041 diff -NurpP --minimal linux-2.6.37/fs/ext2/super.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/super.c
3042 --- linux-2.6.37/fs/ext2/super.c        2011-01-05 21:50:22.000000000 +0100
3043 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext2/super.c 2010-11-23 02:09:41.000000000 +0100
3044 @@ -378,7 +378,8 @@ enum {
3045         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3046         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3047         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3048 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3049 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3050 +       Opt_tag, Opt_notag, Opt_tagid
3051  };
3052  
3053  static const match_table_t tokens = {
3054 @@ -406,6 +407,9 @@ static const match_table_t tokens = {
3055         {Opt_acl, "acl"},
3056         {Opt_noacl, "noacl"},
3057         {Opt_xip, "xip"},
3058 +       {Opt_tag, "tag"},
3059 +       {Opt_notag, "notag"},
3060 +       {Opt_tagid, "tagid=%u"},
3061         {Opt_grpquota, "grpquota"},
3062         {Opt_ignore, "noquota"},
3063         {Opt_quota, "quota"},
3064 @@ -476,6 +480,20 @@ static int parse_options(char *options, 
3065                 case Opt_nouid32:
3066                         set_opt (sbi->s_mount_opt, NO_UID32);
3067                         break;
3068 +#ifndef CONFIG_TAGGING_NONE
3069 +               case Opt_tag:
3070 +                       set_opt (sbi->s_mount_opt, TAGGED);
3071 +                       break;
3072 +               case Opt_notag:
3073 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3074 +                       break;
3075 +#endif
3076 +#ifdef CONFIG_PROPAGATE
3077 +               case Opt_tagid:
3078 +                       /* use args[0] */
3079 +                       set_opt (sbi->s_mount_opt, TAGGED);
3080 +                       break;
3081 +#endif
3082                 case Opt_nocheck:
3083                         clear_opt (sbi->s_mount_opt, CHECK);
3084                         break;
3085 @@ -834,6 +852,8 @@ static int ext2_fill_super(struct super_
3086         if (!parse_options((char *) data, sb))
3087                 goto failed_mount;
3088  
3089 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3090 +               sb->s_flags |= MS_TAGGED;
3091         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3092                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3093                  MS_POSIXACL : 0);
3094 @@ -1207,6 +1227,14 @@ static int ext2_remount (struct super_bl
3095                 goto restore_opts;
3096         }
3097  
3098 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3099 +               !(sb->s_flags & MS_TAGGED)) {
3100 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3101 +                      sb->s_id);
3102 +               err = -EINVAL;
3103 +               goto restore_opts;
3104 +       }
3105 +
3106         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3107                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3108  
3109 diff -NurpP --minimal linux-2.6.37/fs/ext3/file.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/file.c
3110 --- linux-2.6.37/fs/ext3/file.c 2010-07-07 18:31:51.000000000 +0200
3111 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/file.c  2010-11-23 02:09:41.000000000 +0100
3112 @@ -81,5 +81,6 @@ const struct inode_operations ext3_file_
3113  #endif
3114         .check_acl      = ext3_check_acl,
3115         .fiemap         = ext3_fiemap,
3116 +       .sync_flags     = ext3_sync_flags,
3117  };
3118  
3119 diff -NurpP --minimal linux-2.6.37/fs/ext3/ialloc.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/ialloc.c
3120 --- linux-2.6.37/fs/ext3/ialloc.c       2011-01-05 21:50:22.000000000 +0100
3121 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/ialloc.c        2010-11-23 02:09:41.000000000 +0100
3122 @@ -23,6 +23,7 @@
3123  #include <linux/buffer_head.h>
3124  #include <linux/random.h>
3125  #include <linux/bitops.h>
3126 +#include <linux/vs_tag.h>
3127  
3128  #include <asm/byteorder.h>
3129  
3130 @@ -531,6 +532,7 @@ got:
3131                 inode->i_mode = mode;
3132                 inode->i_uid = current_fsuid();
3133                 inode->i_gid = dir->i_gid;
3134 +               inode->i_tag = dx_current_fstag(sb);
3135         } else
3136                 inode_init_owner(inode, dir, mode);
3137  
3138 diff -NurpP --minimal linux-2.6.37/fs/ext3/inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/inode.c
3139 --- linux-2.6.37/fs/ext3/inode.c        2011-01-05 21:50:22.000000000 +0100
3140 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/inode.c 2010-11-23 02:09:41.000000000 +0100
3141 @@ -38,6 +38,7 @@
3142  #include <linux/bio.h>
3143  #include <linux/fiemap.h>
3144  #include <linux/namei.h>
3145 +#include <linux/vs_tag.h>
3146  #include "xattr.h"
3147  #include "acl.h"
3148  
3149 @@ -2392,7 +2393,7 @@ static void ext3_free_branches(handle_t 
3150  
3151  int ext3_can_truncate(struct inode *inode)
3152  {
3153 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3154 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3155                 return 0;
3156         if (S_ISREG(inode->i_mode))
3157                 return 1;
3158 @@ -2776,36 +2777,60 @@ void ext3_set_inode_flags(struct inode *
3159  {
3160         unsigned int flags = EXT3_I(inode)->i_flags;
3161  
3162 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3163 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3164 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3165 +
3166 +       if (flags & EXT3_IMMUTABLE_FL)
3167 +               inode->i_flags |= S_IMMUTABLE;
3168 +       if (flags & EXT3_IXUNLINK_FL)
3169 +               inode->i_flags |= S_IXUNLINK;
3170 +
3171         if (flags & EXT3_SYNC_FL)
3172                 inode->i_flags |= S_SYNC;
3173         if (flags & EXT3_APPEND_FL)
3174                 inode->i_flags |= S_APPEND;
3175 -       if (flags & EXT3_IMMUTABLE_FL)
3176 -               inode->i_flags |= S_IMMUTABLE;
3177         if (flags & EXT3_NOATIME_FL)
3178                 inode->i_flags |= S_NOATIME;
3179         if (flags & EXT3_DIRSYNC_FL)
3180                 inode->i_flags |= S_DIRSYNC;
3181 +
3182 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3183 +
3184 +       if (flags & EXT3_BARRIER_FL)
3185 +               inode->i_vflags |= V_BARRIER;
3186 +       if (flags & EXT3_COW_FL)
3187 +               inode->i_vflags |= V_COW;
3188  }
3189  
3190  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3191  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3192  {
3193         unsigned int flags = ei->vfs_inode.i_flags;
3194 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3195 +
3196 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3197 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3198 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3199 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3200 +
3201 +       if (flags & S_IMMUTABLE)
3202 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3203 +       if (flags & S_IXUNLINK)
3204 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3205  
3206 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3207 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3208         if (flags & S_SYNC)
3209                 ei->i_flags |= EXT3_SYNC_FL;
3210         if (flags & S_APPEND)
3211                 ei->i_flags |= EXT3_APPEND_FL;
3212 -       if (flags & S_IMMUTABLE)
3213 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3214         if (flags & S_NOATIME)
3215                 ei->i_flags |= EXT3_NOATIME_FL;
3216         if (flags & S_DIRSYNC)
3217                 ei->i_flags |= EXT3_DIRSYNC_FL;
3218 +
3219 +       if (vflags & V_BARRIER)
3220 +               ei->i_flags |= EXT3_BARRIER_FL;
3221 +       if (vflags & V_COW)
3222 +               ei->i_flags |= EXT3_COW_FL;
3223  }
3224  
3225  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3226 @@ -2819,6 +2844,8 @@ struct inode *ext3_iget(struct super_blo
3227         transaction_t *transaction;
3228         long ret;
3229         int block;
3230 +       uid_t uid;
3231 +       gid_t gid;
3232  
3233         inode = iget_locked(sb, ino);
3234         if (!inode)
3235 @@ -2835,12 +2862,17 @@ struct inode *ext3_iget(struct super_blo
3236         bh = iloc.bh;
3237         raw_inode = ext3_raw_inode(&iloc);
3238         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3239 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3240 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3241 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3242 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3243         if(!(test_opt (inode->i_sb, NO_UID32))) {
3244 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3245 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3246 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3247 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3248         }
3249 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3250 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3251 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3252 +               le16_to_cpu(raw_inode->i_raw_tag));
3253 +
3254         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3255         inode->i_size = le32_to_cpu(raw_inode->i_size);
3256         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3257 @@ -2995,6 +3027,8 @@ static int ext3_do_update_inode(handle_t
3258         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3259         struct ext3_inode_info *ei = EXT3_I(inode);
3260         struct buffer_head *bh = iloc->bh;
3261 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3262 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3263         int err = 0, rc, block;
3264  
3265  again:
3266 @@ -3009,29 +3043,32 @@ again:
3267         ext3_get_inode_flags(ei);
3268         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3269         if(!(test_opt(inode->i_sb, NO_UID32))) {
3270 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3271 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3272 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3273 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3274  /*
3275   * Fix up interoperability with old kernels. Otherwise, old inodes get
3276   * re-used with the upper 16 bits of the uid/gid intact
3277   */
3278                 if(!ei->i_dtime) {
3279                         raw_inode->i_uid_high =
3280 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3281 +                               cpu_to_le16(high_16_bits(uid));
3282                         raw_inode->i_gid_high =
3283 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3284 +                               cpu_to_le16(high_16_bits(gid));
3285                 } else {
3286                         raw_inode->i_uid_high = 0;
3287                         raw_inode->i_gid_high = 0;
3288                 }
3289         } else {
3290                 raw_inode->i_uid_low =
3291 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3292 +                       cpu_to_le16(fs_high2lowuid(uid));
3293                 raw_inode->i_gid_low =
3294 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3295 +                       cpu_to_le16(fs_high2lowgid(gid));
3296                 raw_inode->i_uid_high = 0;
3297                 raw_inode->i_gid_high = 0;
3298         }
3299 +#ifdef CONFIG_TAGGING_INTERN
3300 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3301 +#endif
3302         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3303         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3304         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3305 @@ -3191,7 +3228,8 @@ int ext3_setattr(struct dentry *dentry, 
3306         if (is_quota_modification(inode, attr))
3307                 dquot_initialize(inode);
3308         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3309 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3310 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3311 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3312                 handle_t *handle;
3313  
3314                 /* (user+group)*(old+new) structure, inode write (sb,
3315 @@ -3213,6 +3251,8 @@ int ext3_setattr(struct dentry *dentry, 
3316                         inode->i_uid = attr->ia_uid;
3317                 if (attr->ia_valid & ATTR_GID)
3318                         inode->i_gid = attr->ia_gid;
3319 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3320 +                       inode->i_tag = attr->ia_tag;
3321                 error = ext3_mark_inode_dirty(handle, inode);
3322                 ext3_journal_stop(handle);
3323         }
3324 diff -NurpP --minimal linux-2.6.37/fs/ext3/ioctl.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/ioctl.c
3325 --- linux-2.6.37/fs/ext3/ioctl.c        2009-06-11 17:13:03.000000000 +0200
3326 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/ioctl.c 2010-11-23 02:09:41.000000000 +0100
3327 @@ -8,6 +8,7 @@
3328   */
3329  
3330  #include <linux/fs.h>
3331 +#include <linux/mount.h>
3332  #include <linux/jbd.h>
3333  #include <linux/capability.h>
3334  #include <linux/ext3_fs.h>
3335 @@ -17,6 +18,34 @@
3336  #include <linux/compat.h>
3337  #include <asm/uaccess.h>
3338  
3339 +
3340 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3341 +{
3342 +       handle_t *handle = NULL;
3343 +       struct ext3_iloc iloc;
3344 +       int err;
3345 +
3346 +       handle = ext3_journal_start(inode, 1);
3347 +       if (IS_ERR(handle))
3348 +               return PTR_ERR(handle);
3349 +
3350 +       if (IS_SYNC(inode))
3351 +               handle->h_sync = 1;
3352 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3353 +       if (err)
3354 +               goto flags_err;
3355 +
3356 +       inode->i_flags = flags;
3357 +       inode->i_vflags = vflags;
3358 +       ext3_get_inode_flags(EXT3_I(inode));
3359 +       inode->i_ctime = CURRENT_TIME_SEC;
3360 +
3361 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3362 +flags_err:
3363 +       ext3_journal_stop(handle);
3364 +       return err;
3365 +}
3366 +
3367  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3368  {
3369         struct inode *inode = filp->f_dentry->d_inode;
3370 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3371  
3372                 flags = ext3_mask_flags(inode->i_mode, flags);
3373  
3374 +               if (IS_BARRIER(inode)) {
3375 +                       vxwprintk_task(1, "messing with the barrier.");
3376 +                       return -EACCES;
3377 +               }
3378 +
3379                 mutex_lock(&inode->i_mutex);
3380  
3381                 /* Is it quota file? Do not allow user to mess with it */
3382 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3383                  *
3384                  * This test looks nicer. Thanks to Pauline Middelink
3385                  */
3386 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3387 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3388 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3389 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3390                         if (!capable(CAP_LINUX_IMMUTABLE))
3391                                 goto flags_out;
3392                 }
3393 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3394                 if (err)
3395                         goto flags_err;
3396  
3397 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3398 +               flags &= EXT3_FL_USER_MODIFIABLE;
3399                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3400                 ei->i_flags = flags;
3401  
3402 diff -NurpP --minimal linux-2.6.37/fs/ext3/namei.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/namei.c
3403 --- linux-2.6.37/fs/ext3/namei.c        2011-01-05 21:50:22.000000000 +0100
3404 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/namei.c 2010-11-23 02:09:41.000000000 +0100
3405 @@ -36,6 +36,7 @@
3406  #include <linux/quotaops.h>
3407  #include <linux/buffer_head.h>
3408  #include <linux/bio.h>
3409 +#include <linux/vs_tag.h>
3410  
3411  #include "namei.h"
3412  #include "xattr.h"
3413 @@ -912,6 +913,7 @@ restart:
3414                                 if (bh)
3415                                         ll_rw_block(READ_META, 1, &bh);
3416                         }
3417 +               dx_propagate_tag(nd, inode);
3418                 }
3419                 if ((bh = bh_use[ra_ptr++]) == NULL)
3420                         goto next;
3421 @@ -2465,6 +2467,7 @@ const struct inode_operations ext3_dir_i
3422         .removexattr    = generic_removexattr,
3423  #endif
3424         .check_acl      = ext3_check_acl,
3425 +       .sync_flags     = ext3_sync_flags,
3426  };
3427  
3428  const struct inode_operations ext3_special_inode_operations = {
3429 diff -NurpP --minimal linux-2.6.37/fs/ext3/super.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/super.c
3430 --- linux-2.6.37/fs/ext3/super.c        2011-01-05 21:50:23.000000000 +0100
3431 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext3/super.c 2010-11-23 02:09:41.000000000 +0100
3432 @@ -796,7 +796,8 @@ enum {
3433         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3434         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3435         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
3436 -       Opt_resize, Opt_usrquota, Opt_grpquota
3437 +       Opt_resize, Opt_usrquota, Opt_grpquota,
3438 +       Opt_tag, Opt_notag, Opt_tagid
3439  };
3440  
3441  static const match_table_t tokens = {
3442 @@ -853,6 +854,9 @@ static const match_table_t tokens = {
3443         {Opt_barrier, "barrier"},
3444         {Opt_nobarrier, "nobarrier"},
3445         {Opt_resize, "resize"},
3446 +       {Opt_tag, "tag"},
3447 +       {Opt_notag, "notag"},
3448 +       {Opt_tagid, "tagid=%u"},
3449         {Opt_err, NULL},
3450  };
3451  
3452 @@ -1005,6 +1009,20 @@ static int parse_options (char *options,
3453                 case Opt_nouid32:
3454                         set_opt (sbi->s_mount_opt, NO_UID32);
3455                         break;
3456 +#ifndef CONFIG_TAGGING_NONE
3457 +               case Opt_tag:
3458 +                       set_opt (sbi->s_mount_opt, TAGGED);
3459 +                       break;
3460 +               case Opt_notag:
3461 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3462 +                       break;
3463 +#endif
3464 +#ifdef CONFIG_PROPAGATE
3465 +               case Opt_tagid:
3466 +                       /* use args[0] */
3467 +                       set_opt (sbi->s_mount_opt, TAGGED);
3468 +                       break;
3469 +#endif
3470                 case Opt_nocheck:
3471                         clear_opt (sbi->s_mount_opt, CHECK);
3472                         break;
3473 @@ -1691,6 +1709,9 @@ static int ext3_fill_super (struct super
3474                             NULL, 0))
3475                 goto failed_mount;
3476  
3477 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3478 +               sb->s_flags |= MS_TAGGED;
3479 +
3480         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3481                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3482  
3483 @@ -2575,6 +2596,14 @@ static int ext3_remount (struct super_bl
3484         if (test_opt(sb, ABORT))
3485                 ext3_abort(sb, __func__, "Abort forced by user");
3486  
3487 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3488 +               !(sb->s_flags & MS_TAGGED)) {
3489 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3490 +                       sb->s_id);
3491 +               err = -EINVAL;
3492 +               goto restore_opts;
3493 +       }
3494 +
3495         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3496                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3497  
3498 diff -NurpP --minimal linux-2.6.37/fs/ext4/ext4.h linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/ext4.h
3499 --- linux-2.6.37/fs/ext4/ext4.h 2011-01-05 21:50:23.000000000 +0100
3500 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/ext4.h  2011-01-05 22:32:19.000000000 +0100
3501 @@ -347,8 +347,12 @@ struct flex_groups {
3502  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3503  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3504  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3505 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3506  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3507  
3508 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3509 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3510 +
3511  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3512  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3513  
3514 @@ -617,7 +621,8 @@ struct ext4_inode {
3515                         __le16  l_i_file_acl_high;
3516                         __le16  l_i_uid_high;   /* these 2 fields */
3517                         __le16  l_i_gid_high;   /* were reserved2[0] */
3518 -                       __u32   l_i_reserved2;
3519 +                       __le16  l_i_tag;        /* Context Tag */
3520 +                       __u16   l_i_reserved2;
3521                 } linux2;
3522                 struct {
3523                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3524 @@ -731,6 +736,7 @@ do {                                                                               \
3525  #define i_gid_low      i_gid
3526  #define i_uid_high     osd2.linux2.l_i_uid_high
3527  #define i_gid_high     osd2.linux2.l_i_gid_high
3528 +#define i_raw_tag      osd2.linux2.l_i_tag
3529  #define i_reserved2    osd2.linux2.l_i_reserved2
3530  
3531  #elif defined(__GNU__)
3532 @@ -903,6 +909,7 @@ struct ext4_inode_info {
3533  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3534  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3535  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3536 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3537  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3538  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3539  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3540 @@ -2054,6 +2061,7 @@ extern int ext4_map_blocks(handle_t *han
3541                            struct ext4_map_blocks *map, int flags);
3542  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3543                         __u64 start, __u64 len);
3544 +extern int ext4_sync_flags(struct inode *, int, int);
3545  /* move_extent.c */
3546  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3547                              __u64 start_orig, __u64 start_donor,
3548 diff -NurpP --minimal linux-2.6.37/fs/ext4/file.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/file.c
3549 --- linux-2.6.37/fs/ext4/file.c 2011-01-05 21:50:23.000000000 +0100
3550 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/file.c  2010-11-23 02:09:41.000000000 +0100
3551 @@ -203,5 +203,6 @@ const struct inode_operations ext4_file_
3552         .check_acl      = ext4_check_acl,
3553         .fallocate      = ext4_fallocate,
3554         .fiemap         = ext4_fiemap,
3555 +       .sync_flags     = ext4_sync_flags,
3556  };
3557  
3558 diff -NurpP --minimal linux-2.6.37/fs/ext4/ialloc.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/ialloc.c
3559 --- linux-2.6.37/fs/ext4/ialloc.c       2011-01-05 21:50:23.000000000 +0100
3560 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/ialloc.c        2010-11-23 02:09:41.000000000 +0100
3561 @@ -22,6 +22,7 @@
3562  #include <linux/random.h>
3563  #include <linux/bitops.h>
3564  #include <linux/blkdev.h>
3565 +#include <linux/vs_tag.h>
3566  #include <asm/byteorder.h>
3567  
3568  #include "ext4.h"
3569 @@ -991,6 +992,7 @@ got:
3570                 inode->i_mode = mode;
3571                 inode->i_uid = current_fsuid();
3572                 inode->i_gid = dir->i_gid;
3573 +               inode->i_tag = dx_current_fstag(sb);
3574         } else
3575                 inode_init_owner(inode, dir, mode);
3576  
3577 diff -NurpP --minimal linux-2.6.37/fs/ext4/inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/inode.c
3578 --- linux-2.6.37/fs/ext4/inode.c        2011-01-05 21:50:23.000000000 +0100
3579 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/inode.c 2011-01-05 22:30:39.000000000 +0100
3580 @@ -40,6 +40,7 @@
3581  #include <linux/workqueue.h>
3582  #include <linux/kernel.h>
3583  #include <linux/slab.h>
3584 +#include <linux/vs_tag.h>
3585  
3586  #include "ext4_jbd2.h"
3587  #include "xattr.h"
3588 @@ -4415,7 +4416,7 @@ static void ext4_free_branches(handle_t 
3589  
3590  int ext4_can_truncate(struct inode *inode)
3591  {
3592 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3593 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3594                 return 0;
3595         if (S_ISREG(inode->i_mode))
3596                 return 1;
3597 @@ -4766,41 +4767,64 @@ void ext4_set_inode_flags(struct inode *
3598  {
3599         unsigned int flags = EXT4_I(inode)->i_flags;
3600  
3601 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3602 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3603 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3604 +
3605 +       if (flags & EXT4_IMMUTABLE_FL)
3606 +               inode->i_flags |= S_IMMUTABLE;
3607 +       if (flags & EXT4_IXUNLINK_FL)
3608 +               inode->i_flags |= S_IXUNLINK;
3609 +
3610         if (flags & EXT4_SYNC_FL)
3611                 inode->i_flags |= S_SYNC;
3612         if (flags & EXT4_APPEND_FL)
3613                 inode->i_flags |= S_APPEND;
3614 -       if (flags & EXT4_IMMUTABLE_FL)
3615 -               inode->i_flags |= S_IMMUTABLE;
3616         if (flags & EXT4_NOATIME_FL)
3617                 inode->i_flags |= S_NOATIME;
3618         if (flags & EXT4_DIRSYNC_FL)
3619                 inode->i_flags |= S_DIRSYNC;
3620 +
3621 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3622 +
3623 +       if (flags & EXT4_BARRIER_FL)
3624 +               inode->i_vflags |= V_BARRIER;
3625 +       if (flags & EXT4_COW_FL)
3626 +               inode->i_vflags |= V_COW;
3627  }
3628  
3629  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3630  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3631  {
3632 -       unsigned int vfs_fl;
3633 +       unsigned int vfs_fl, vfs_vf;
3634         unsigned long old_fl, new_fl;
3635  
3636         do {
3637                 vfs_fl = ei->vfs_inode.i_flags;
3638 +               vfs_vf = ei->vfs_inode.i_vflags;
3639                 old_fl = ei->i_flags;
3640                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3641                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3642 -                               EXT4_DIRSYNC_FL);
3643 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3644 +                               EXT4_COW_FL);
3645 +
3646 +               if (vfs_fl & S_IMMUTABLE)
3647 +                       new_fl |= EXT4_IMMUTABLE_FL;
3648 +               if (vfs_fl & S_IXUNLINK)
3649 +                       new_fl |= EXT4_IXUNLINK_FL;
3650 +
3651                 if (vfs_fl & S_SYNC)
3652                         new_fl |= EXT4_SYNC_FL;
3653                 if (vfs_fl & S_APPEND)
3654                         new_fl |= EXT4_APPEND_FL;
3655 -               if (vfs_fl & S_IMMUTABLE)
3656 -                       new_fl |= EXT4_IMMUTABLE_FL;
3657                 if (vfs_fl & S_NOATIME)
3658                         new_fl |= EXT4_NOATIME_FL;
3659                 if (vfs_fl & S_DIRSYNC)
3660                         new_fl |= EXT4_DIRSYNC_FL;
3661 +
3662 +               if (vfs_vf & V_BARRIER)
3663 +                       new_fl |= EXT4_BARRIER_FL;
3664 +               if (vfs_vf & V_COW)
3665 +                       new_fl |= EXT4_COW_FL;
3666         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3667  }
3668  
3669 @@ -4836,6 +4860,8 @@ struct inode *ext4_iget(struct super_blo
3670         journal_t *journal = EXT4_SB(sb)->s_journal;
3671         long ret;
3672         int block;
3673 +       uid_t uid;
3674 +       gid_t gid;
3675  
3676         inode = iget_locked(sb, ino);
3677         if (!inode)
3678 @@ -4851,12 +4877,16 @@ struct inode *ext4_iget(struct super_blo
3679                 goto bad_inode;
3680         raw_inode = ext4_raw_inode(&iloc);
3681         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3682 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3683 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3684 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3685 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3686         if (!(test_opt(inode->i_sb, NO_UID32))) {
3687 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3688 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3689 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3690 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3691         }
3692 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3693 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3694 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3695 +               le16_to_cpu(raw_inode->i_raw_tag));
3696         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3697  
3698         ei->i_state_flags = 0;
3699 @@ -5075,6 +5105,8 @@ static int ext4_do_update_inode(handle_t
3700         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3701         struct ext4_inode_info *ei = EXT4_I(inode);
3702         struct buffer_head *bh = iloc->bh;
3703 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3704 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3705         int err = 0, rc, block;
3706  
3707         /* For fields not not tracking in the in-memory inode,
3708 @@ -5085,29 +5117,32 @@ static int ext4_do_update_inode(handle_t
3709         ext4_get_inode_flags(ei);
3710         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3711         if (!(test_opt(inode->i_sb, NO_UID32))) {
3712 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3713 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3714 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3715 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3716  /*
3717   * Fix up interoperability with old kernels. Otherwise, old inodes get
3718   * re-used with the upper 16 bits of the uid/gid intact
3719   */
3720                 if (!ei->i_dtime) {
3721                         raw_inode->i_uid_high =
3722 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3723 +                               cpu_to_le16(high_16_bits(uid));
3724                         raw_inode->i_gid_high =
3725 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3726 +                               cpu_to_le16(high_16_bits(gid));
3727                 } else {
3728                         raw_inode->i_uid_high = 0;
3729                         raw_inode->i_gid_high = 0;
3730                 }
3731         } else {
3732                 raw_inode->i_uid_low =
3733 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3734 +                       cpu_to_le16(fs_high2lowuid(uid));
3735                 raw_inode->i_gid_low =
3736 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3737 +                       cpu_to_le16(fs_high2lowgid(gid));
3738                 raw_inode->i_uid_high = 0;
3739                 raw_inode->i_gid_high = 0;
3740         }
3741 +#ifdef CONFIG_TAGGING_INTERN
3742 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3743 +#endif
3744         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3745  
3746         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3747 @@ -5293,7 +5328,8 @@ int ext4_setattr(struct dentry *dentry, 
3748         if (is_quota_modification(inode, attr))
3749                 dquot_initialize(inode);
3750         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3751 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3752 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3753 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3754                 handle_t *handle;
3755  
3756                 /* (user+group)*(old+new) structure, inode write (sb,
3757 @@ -5315,6 +5351,8 @@ int ext4_setattr(struct dentry *dentry, 
3758                         inode->i_uid = attr->ia_uid;
3759                 if (attr->ia_valid & ATTR_GID)
3760                         inode->i_gid = attr->ia_gid;
3761 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3762 +                       inode->i_tag = attr->ia_tag;
3763                 error = ext4_mark_inode_dirty(handle, inode);
3764                 ext4_journal_stop(handle);
3765         }
3766 diff -NurpP --minimal linux-2.6.37/fs/ext4/ioctl.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/ioctl.c
3767 --- linux-2.6.37/fs/ext4/ioctl.c        2011-01-05 21:50:23.000000000 +0100
3768 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/ioctl.c 2010-11-23 02:09:41.000000000 +0100
3769 @@ -14,10 +14,39 @@
3770  #include <linux/compat.h>
3771  #include <linux/mount.h>
3772  #include <linux/file.h>
3773 +#include <linux/vs_tag.h>
3774  #include <asm/uaccess.h>
3775  #include "ext4_jbd2.h"
3776  #include "ext4.h"
3777  
3778 +
3779 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3780 +{
3781 +       handle_t *handle = NULL;
3782 +       struct ext4_iloc iloc;
3783 +       int err;
3784 +
3785 +       handle = ext4_journal_start(inode, 1);
3786 +       if (IS_ERR(handle))
3787 +               return PTR_ERR(handle);
3788 +
3789 +       if (IS_SYNC(inode))
3790 +               ext4_handle_sync(handle);
3791 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3792 +       if (err)
3793 +               goto flags_err;
3794 +
3795 +       inode->i_flags = flags;
3796 +       inode->i_vflags = vflags;
3797 +       ext4_get_inode_flags(EXT4_I(inode));
3798 +       inode->i_ctime = ext4_current_time(inode);
3799 +
3800 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3801 +flags_err:
3802 +       ext4_journal_stop(handle);
3803 +       return err;
3804 +}
3805 +
3806  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3807  {
3808         struct inode *inode = filp->f_dentry->d_inode;
3809 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3810  
3811                 flags = ext4_mask_flags(inode->i_mode, flags);
3812  
3813 +               if (IS_BARRIER(inode)) {
3814 +                       vxwprintk_task(1, "messing with the barrier.");
3815 +                       return -EACCES;
3816 +               }
3817 +
3818                 err = -EPERM;
3819                 mutex_lock(&inode->i_mutex);
3820                 /* Is it quota file? Do not allow user to mess with it */
3821 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3822                  *
3823                  * This test looks nicer. Thanks to Pauline Middelink
3824                  */
3825 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3826 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3827 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3828 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3829                         if (!capable(CAP_LINUX_IMMUTABLE))
3830                                 goto flags_out;
3831                 }
3832 diff -NurpP --minimal linux-2.6.37/fs/ext4/namei.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/namei.c
3833 --- linux-2.6.37/fs/ext4/namei.c        2011-01-05 21:50:23.000000000 +0100
3834 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/namei.c 2011-01-05 22:30:39.000000000 +0100
3835 @@ -34,6 +34,7 @@
3836  #include <linux/quotaops.h>
3837  #include <linux/buffer_head.h>
3838  #include <linux/bio.h>
3839 +#include <linux/vs_tag.h>
3840  #include "ext4.h"
3841  #include "ext4_jbd2.h"
3842  
3843 @@ -923,6 +924,7 @@ restart:
3844                                 if (bh)
3845                                         ll_rw_block(READ_META, 1, &bh);
3846                         }
3847 +               dx_propagate_tag(nd, inode);
3848                 }
3849                 if ((bh = bh_use[ra_ptr++]) == NULL)
3850                         goto next;
3851 @@ -2513,6 +2515,7 @@ const struct inode_operations ext4_dir_i
3852  #endif
3853         .check_acl      = ext4_check_acl,
3854         .fiemap         = ext4_fiemap,
3855 +       .sync_flags     = ext4_sync_flags,
3856  };
3857  
3858  const struct inode_operations ext4_special_inode_operations = {
3859 diff -NurpP --minimal linux-2.6.37/fs/ext4/super.c linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/super.c
3860 --- linux-2.6.37/fs/ext4/super.c        2011-01-05 21:50:23.000000000 +0100
3861 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ext4/super.c 2011-01-05 22:30:39.000000000 +0100
3862 @@ -1247,6 +1247,7 @@ enum {
3863         Opt_dioread_nolock, Opt_dioread_lock,
3864         Opt_discard, Opt_nodiscard,
3865         Opt_init_inode_table, Opt_noinit_inode_table,
3866 +       Opt_tag, Opt_notag, Opt_tagid
3867  };
3868  
3869  static const match_table_t tokens = {
3870 @@ -1322,6 +1323,9 @@ static const match_table_t tokens = {
3871         {Opt_init_inode_table, "init_itable=%u"},
3872         {Opt_init_inode_table, "init_itable"},
3873         {Opt_noinit_inode_table, "noinit_itable"},
3874 +       {Opt_tag, "tag"},
3875 +       {Opt_notag, "notag"},
3876 +       {Opt_tagid, "tagid=%u"},
3877         {Opt_err, NULL},
3878  };
3879  
3880 @@ -1490,6 +1494,20 @@ static int parse_options(char *options, 
3881                 case Opt_nouid32:
3882                         set_opt(sbi->s_mount_opt, NO_UID32);
3883                         break;
3884 +#ifndef CONFIG_TAGGING_NONE
3885 +               case Opt_tag:
3886 +                       set_opt (sbi->s_mount_opt, TAGGED);
3887 +                       break;
3888 +               case Opt_notag:
3889 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3890 +                       break;
3891 +#endif
3892 +#ifdef CONFIG_PROPAGATE
3893 +               case Opt_tagid:
3894 +                       /* use args[0] */
3895 +                       set_opt (sbi->s_mount_opt, TAGGED);
3896 +                       break;
3897 +#endif
3898                 case Opt_debug:
3899                         set_opt(sbi->s_mount_opt, DEBUG);
3900                         break;
3901 @@ -3134,6 +3152,9 @@ static int ext4_fill_super(struct super_
3902                            &journal_ioprio, NULL, 0))
3903                 goto failed_mount;
3904  
3905 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3906 +               sb->s_flags |= MS_TAGGED;
3907 +
3908         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3909                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3910  
3911 @@ -4211,6 +4232,14 @@ static int ext4_remount(struct super_blo
3912         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3913                 ext4_abort(sb, "Abort forced by user");
3914  
3915 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3916 +               !(sb->s_flags & MS_TAGGED)) {
3917 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3918 +                       sb->s_id);
3919 +               err = -EINVAL;
3920 +               goto restore_opts;
3921 +       }
3922 +
3923         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3924                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3925  
3926 diff -NurpP --minimal linux-2.6.37/fs/fcntl.c linux-2.6.37-vs2.3.0.37-rc3/fs/fcntl.c
3927 --- linux-2.6.37/fs/fcntl.c     2011-01-05 21:50:23.000000000 +0100
3928 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/fcntl.c      2010-11-23 02:09:41.000000000 +0100
3929 @@ -20,6 +20,7 @@
3930  #include <linux/signal.h>
3931  #include <linux/rcupdate.h>
3932  #include <linux/pid_namespace.h>
3933 +#include <linux/vs_limit.h>
3934  
3935  #include <asm/poll.h>
3936  #include <asm/siginfo.h>
3937 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3938  
3939         if (tofree)
3940                 filp_close(tofree, files);
3941 +       else
3942 +               vx_openfd_inc(newfd);   /* fd was unused */
3943  
3944         return newfd;
3945  
3946 @@ -434,6 +437,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3947         filp = fget(fd);
3948         if (!filp)
3949                 goto out;
3950 +       if (!vx_files_avail(1))
3951 +               goto out;
3952  
3953         err = security_file_fcntl(filp, cmd, arg);
3954         if (err) {
3955 diff -NurpP --minimal linux-2.6.37/fs/file.c linux-2.6.37-vs2.3.0.37-rc3/fs/file.c
3956 --- linux-2.6.37/fs/file.c      2010-10-21 13:07:48.000000000 +0200
3957 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/file.c       2010-11-23 02:09:41.000000000 +0100
3958 @@ -20,6 +20,7 @@
3959  #include <linux/spinlock.h>
3960  #include <linux/rcupdate.h>
3961  #include <linux/workqueue.h>
3962 +#include <linux/vs_limit.h>
3963  
3964  struct fdtable_defer {
3965         spinlock_t lock;
3966 @@ -355,6 +356,8 @@ struct files_struct *dup_fd(struct files
3967                 struct file *f = *old_fds++;
3968                 if (f) {
3969                         get_file(f);
3970 +                       /* TODO: sum it first for check and performance */
3971 +                       vx_openfd_inc(open_files - i);
3972                 } else {
3973                         /*
3974                          * The fd may be claimed in the fd bitmap but not yet
3975 @@ -462,6 +465,7 @@ repeat:
3976         else
3977                 FD_CLR(fd, fdt->close_on_exec);
3978         error = fd;
3979 +       vx_openfd_inc(fd);
3980  #if 1
3981         /* Sanity check */
3982         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3983 diff -NurpP --minimal linux-2.6.37/fs/file_table.c linux-2.6.37-vs2.3.0.37-rc3/fs/file_table.c
3984 --- linux-2.6.37/fs/file_table.c        2011-01-05 21:50:23.000000000 +0100
3985 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/file_table.c 2010-11-23 02:09:41.000000000 +0100
3986 @@ -24,6 +24,8 @@
3987  #include <linux/percpu_counter.h>
3988  #include <linux/percpu.h>
3989  #include <linux/ima.h>
3990 +#include <linux/vs_limit.h>
3991 +#include <linux/vs_context.h>
3992  
3993  #include <asm/atomic.h>
3994  
3995 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3996         spin_lock_init(&f->f_lock);
3997         eventpoll_init_file(f);
3998         /* f->f_version: 0 */
3999 +       f->f_xid = vx_current_xid();
4000 +       vx_files_inc(f);
4001         return f;
4002  
4003  over:
4004 @@ -250,6 +254,8 @@ static void __fput(struct file *file)
4005                 cdev_put(inode->i_cdev);
4006         fops_put(file->f_op);
4007         put_pid(file->f_owner.pid);
4008 +       vx_files_dec(file);
4009 +       file->f_xid = 0;
4010         file_sb_list_del(file);
4011         if (file->f_mode & FMODE_WRITE)
4012                 drop_file_write_access(file);
4013 @@ -333,6 +339,8 @@ void put_filp(struct file *file)
4014  {
4015         if (atomic_long_dec_and_test(&file->f_count)) {
4016                 security_file_free(file);
4017 +               vx_files_dec(file);
4018 +               file->f_xid = 0;
4019                 file_sb_list_del(file);
4020                 file_free(file);
4021         }
4022 diff -NurpP --minimal linux-2.6.37/fs/fs_struct.c linux-2.6.37-vs2.3.0.37-rc3/fs/fs_struct.c
4023 --- linux-2.6.37/fs/fs_struct.c 2010-10-21 13:07:48.000000000 +0200
4024 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/fs_struct.c  2010-11-23 02:09:41.000000000 +0100
4025 @@ -4,6 +4,7 @@
4026  #include <linux/path.h>
4027  #include <linux/slab.h>
4028  #include <linux/fs_struct.h>
4029 +#include <linux/vserver/global.h>
4030  
4031  /*
4032   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
4033 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
4034  {
4035         path_put(&fs->root);
4036         path_put(&fs->pwd);
4037 +       atomic_dec(&vs_global_fs);
4038         kmem_cache_free(fs_cachep, fs);
4039  }
4040  
4041 @@ -107,6 +109,7 @@ struct fs_struct *copy_fs_struct(struct 
4042                 spin_lock_init(&fs->lock);
4043                 fs->umask = old->umask;
4044                 get_fs_root_and_pwd(old, &fs->root, &fs->pwd);
4045 +               atomic_inc(&vs_global_fs);
4046         }
4047         return fs;
4048  }
4049 diff -NurpP --minimal linux-2.6.37/fs/gfs2/file.c linux-2.6.37-vs2.3.0.37-rc3/fs/gfs2/file.c
4050 --- linux-2.6.37/fs/gfs2/file.c 2011-01-05 21:50:23.000000000 +0100
4051 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/gfs2/file.c  2010-11-23 02:09:41.000000000 +0100
4052 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
4053         [7] = GFS2_DIF_NOATIME,
4054         [12] = GFS2_DIF_EXHASH,
4055         [14] = GFS2_DIF_INHERIT_JDATA,
4056 +       [27] = GFS2_DIF_IXUNLINK,
4057 +       [26] = GFS2_DIF_BARRIER,
4058 +       [29] = GFS2_DIF_COW,
4059  };
4060  
4061  static const u32 gfs2_to_fsflags[32] = {
4062 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
4063         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4064         [gfs2fl_ExHash] = FS_INDEX_FL,
4065         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4066 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4067 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4068 +       [gfs2fl_Cow] = FS_COW_FL,
4069  };
4070  
4071  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4072 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
4073  {
4074         struct gfs2_inode *ip = GFS2_I(inode);
4075         unsigned int flags = inode->i_flags;
4076 +       unsigned int vflags = inode->i_vflags;
4077 +
4078 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4079 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4080  
4081 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4082         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4083                 flags |= S_IMMUTABLE;
4084 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4085 +               flags |= S_IXUNLINK;
4086 +
4087         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4088                 flags |= S_APPEND;
4089         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4090 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
4091         if (ip->i_diskflags & GFS2_DIF_SYNC)
4092                 flags |= S_SYNC;
4093         inode->i_flags = flags;
4094 +
4095 +       vflags &= ~(V_BARRIER | V_COW);
4096 +
4097 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4098 +               vflags |= V_BARRIER;
4099 +       if (ip->i_diskflags & GFS2_DIF_COW)
4100 +               vflags |= V_COW;
4101 +       inode->i_vflags = vflags;
4102 +}
4103 +
4104 +void gfs2_get_inode_flags(struct inode *inode)
4105 +{
4106 +       struct gfs2_inode *ip = GFS2_I(inode);
4107 +       unsigned int flags = inode->i_flags;
4108 +       unsigned int vflags = inode->i_vflags;
4109 +
4110 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4111 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4112 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4113 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4114 +
4115 +       if (flags & S_IMMUTABLE)
4116 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4117 +       if (flags & S_IXUNLINK)
4118 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4119 +
4120 +       if (flags & S_APPEND)
4121 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4122 +       if (flags & S_NOATIME)
4123 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4124 +       if (flags & S_SYNC)
4125 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4126 +
4127 +       if (vflags & V_BARRIER)
4128 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4129 +       if (vflags & V_COW)
4130 +               ip->i_diskflags |= GFS2_DIF_COW;
4131  }
4132  
4133  /* Flags that can be set by user space */
4134 @@ -293,6 +342,37 @@ static int gfs2_set_flags(struct file *f
4135         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4136  }
4137  
4138 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4139 +{
4140 +       struct gfs2_inode *ip = GFS2_I(inode);
4141 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4142 +       struct buffer_head *bh;
4143 +       struct gfs2_holder gh;
4144 +       int error;
4145 +
4146 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4147 +       if (error)
4148 +               return error;
4149 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4150 +       if (error)
4151 +               goto out;
4152 +       error = gfs2_meta_inode_buffer(ip, &bh);
4153 +       if (error)
4154 +               goto out_trans_end;
4155 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4156 +       inode->i_flags = flags;
4157 +       inode->i_vflags = vflags;
4158 +       gfs2_get_inode_flags(inode);
4159 +       gfs2_dinode_out(ip, bh->b_data);
4160 +       brelse(bh);
4161 +       gfs2_set_aops(inode);
4162 +out_trans_end:
4163 +       gfs2_trans_end(sdp);
4164 +out:
4165 +       gfs2_glock_dq_uninit(&gh);
4166 +       return error;
4167 +}
4168 +
4169  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4170  {
4171         switch(cmd) {
4172 diff -NurpP --minimal linux-2.6.37/fs/gfs2/inode.h linux-2.6.37-vs2.3.0.37-rc3/fs/gfs2/inode.h
4173 --- linux-2.6.37/fs/gfs2/inode.h        2011-01-05 21:50:23.000000000 +0100
4174 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/gfs2/inode.h 2010-11-23 02:09:41.000000000 +0100
4175 @@ -126,6 +126,7 @@ extern const struct file_operations gfs2
4176  extern const struct file_operations gfs2_dir_fops_nolock;
4177  
4178  extern void gfs2_set_inode_flags(struct inode *inode);
4179 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4180   
4181  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4182  extern const struct file_operations gfs2_file_fops;
4183 diff -NurpP --minimal linux-2.6.37/fs/gfs2/ops_inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/gfs2/ops_inode.c
4184 --- linux-2.6.37/fs/gfs2/ops_inode.c    2011-01-05 21:50:23.000000000 +0100
4185 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/gfs2/ops_inode.c     2010-11-23 02:09:41.000000000 +0100
4186 @@ -1594,6 +1594,8 @@ const struct inode_operations gfs2_dir_i
4187         .listxattr = gfs2_listxattr,
4188         .removexattr = gfs2_removexattr,
4189         .fiemap = gfs2_fiemap,
4190 +       .sync_flags = gfs2_sync_flags,
4191 +       .sync_flags = gfs2_sync_flags,
4192  };
4193  
4194  const struct inode_operations gfs2_symlink_iops = {
4195 diff -NurpP --minimal linux-2.6.37/fs/inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/inode.c
4196 --- linux-2.6.37/fs/inode.c     2011-01-05 21:50:24.000000000 +0100
4197 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/inode.c      2010-11-23 03:34:25.000000000 +0100
4198 @@ -25,6 +25,7 @@
4199  #include <linux/async.h>
4200  #include <linux/posix_acl.h>
4201  #include <linux/ima.h>
4202 +#include <linux/vs_tag.h>
4203  
4204  /*
4205   * This is needed for the following functions:
4206 @@ -162,6 +163,9 @@ int inode_init_always(struct super_block
4207         struct address_space *const mapping = &inode->i_data;
4208  
4209         inode->i_sb = sb;
4210 +
4211 +       /* essential because of inode slab reuse */
4212 +       inode->i_tag = 0;
4213         inode->i_blkbits = sb->s_blocksize_bits;
4214         inode->i_flags = 0;
4215         atomic_set(&inode->i_count, 1);
4216 @@ -182,6 +186,7 @@ int inode_init_always(struct super_block
4217         inode->i_bdev = NULL;
4218         inode->i_cdev = NULL;
4219         inode->i_rdev = 0;
4220 +       inode->i_mdev = 0;
4221         inode->dirtied_when = 0;
4222  
4223         if (security_inode_alloc(inode))
4224 @@ -408,6 +413,8 @@ static void __remove_inode_hash(struct i
4225         hlist_del_init(&inode->i_hash);
4226  }
4227  
4228 +EXPORT_SYMBOL_GPL(__iget);
4229 +
4230  /**
4231   *     remove_inode_hash - remove an inode from the hash
4232   *     @inode: inode to unhash
4233 @@ -1675,9 +1682,11 @@ void init_special_inode(struct inode *in
4234         if (S_ISCHR(mode)) {
4235                 inode->i_fop = &def_chr_fops;
4236                 inode->i_rdev = rdev;
4237 +               inode->i_mdev = rdev;
4238         } else if (S_ISBLK(mode)) {
4239                 inode->i_fop = &def_blk_fops;
4240                 inode->i_rdev = rdev;
4241 +               inode->i_mdev = rdev;
4242         } else if (S_ISFIFO(mode))
4243                 inode->i_fop = &def_fifo_fops;
4244         else if (S_ISSOCK(mode))
4245 @@ -1706,5 +1715,6 @@ void inode_init_owner(struct inode *inod
4246         } else
4247                 inode->i_gid = current_fsgid();
4248         inode->i_mode = mode;
4249 +       inode->i_tag = dx_current_fstag(inode->i_sb);
4250  }
4251  EXPORT_SYMBOL(inode_init_owner);
4252 diff -NurpP --minimal linux-2.6.37/fs/ioctl.c linux-2.6.37-vs2.3.0.37-rc3/fs/ioctl.c
4253 --- linux-2.6.37/fs/ioctl.c     2011-01-05 21:50:24.000000000 +0100
4254 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ioctl.c      2010-11-23 02:09:41.000000000 +0100
4255 @@ -15,6 +15,9 @@
4256  #include <linux/writeback.h>
4257  #include <linux/buffer_head.h>
4258  #include <linux/falloc.h>
4259 +#include <linux/proc_fs.h>
4260 +#include <linux/vserver/inode.h>
4261 +#include <linux/vs_tag.h>
4262  
4263  #include <asm/ioctls.h>
4264  
4265 diff -NurpP --minimal linux-2.6.37/fs/ioprio.c linux-2.6.37-vs2.3.0.37-rc3/fs/ioprio.c
4266 --- linux-2.6.37/fs/ioprio.c    2011-01-05 21:50:24.000000000 +0100
4267 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ioprio.c     2011-01-05 22:30:39.000000000 +0100
4268 @@ -27,6 +27,7 @@
4269  #include <linux/syscalls.h>
4270  #include <linux/security.h>
4271  #include <linux/pid_namespace.h>
4272 +#include <linux/vs_base.h>
4273  
4274  int set_task_ioprio(struct task_struct *task, int ioprio)
4275  {
4276 @@ -119,6 +120,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4277                         else
4278                                 pgrp = find_vpid(who);
4279                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4280 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4281 +                                       continue;
4282                                 ret = set_task_ioprio(p, ioprio);
4283                                 if (ret)
4284                                         break;
4285 @@ -208,6 +211,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4286                         else
4287                                 pgrp = find_vpid(who);
4288                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4289 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4290 +                                       continue;
4291                                 tmpio = get_task_ioprio(p);
4292                                 if (tmpio < 0)
4293                                         continue;
4294 diff -NurpP --minimal linux-2.6.37/fs/jfs/file.c linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/file.c
4295 --- linux-2.6.37/fs/jfs/file.c  2010-10-21 13:07:50.000000000 +0200
4296 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/file.c   2010-11-23 02:09:41.000000000 +0100
4297 @@ -102,7 +102,8 @@ int jfs_setattr(struct dentry *dentry, s
4298         if (is_quota_modification(inode, iattr))
4299                 dquot_initialize(inode);
4300         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4301 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4302 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4303 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4304                 rc = dquot_transfer(inode, iattr);
4305                 if (rc)
4306                         return rc;
4307 @@ -133,6 +134,7 @@ const struct inode_operations jfs_file_i
4308  #ifdef CONFIG_JFS_POSIX_ACL
4309         .check_acl      = jfs_check_acl,
4310  #endif
4311 +       .sync_flags     = jfs_sync_flags,
4312  };
4313  
4314  const struct file_operations jfs_file_operations = {
4315 diff -NurpP --minimal linux-2.6.37/fs/jfs/ioctl.c linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/ioctl.c
4316 --- linux-2.6.37/fs/jfs/ioctl.c 2008-12-25 00:26:37.000000000 +0100
4317 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/ioctl.c  2010-11-23 02:09:41.000000000 +0100
4318 @@ -11,6 +11,7 @@
4319  #include <linux/mount.h>
4320  #include <linux/time.h>
4321  #include <linux/sched.h>
4322 +#include <linux/mount.h>
4323  #include <asm/current.h>
4324  #include <asm/uaccess.h>
4325  
4326 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4327  }
4328  
4329  
4330 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4331 +{
4332 +       inode->i_flags = flags;
4333 +       inode->i_vflags = vflags;
4334 +       jfs_get_inode_flags(JFS_IP(inode));
4335 +       inode->i_ctime = CURRENT_TIME_SEC;
4336 +       mark_inode_dirty(inode);
4337 +       return 0;
4338 +}
4339 +
4340  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4341  {
4342         struct inode *inode = filp->f_dentry->d_inode;
4343 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4344                 if (!S_ISDIR(inode->i_mode))
4345                         flags &= ~JFS_DIRSYNC_FL;
4346  
4347 +               if (IS_BARRIER(inode)) {
4348 +                       vxwprintk_task(1, "messing with the barrier.");
4349 +                       return -EACCES;
4350 +               }
4351 +
4352                 /* Is it quota file? Do not allow user to mess with it */
4353                 if (IS_NOQUOTA(inode)) {
4354                         err = -EPERM;
4355 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4356                  * the relevant capability.
4357                  */
4358                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4359 -                       ((flags ^ oldflags) &
4360 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4361 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4362 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4363                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4364                                 mutex_unlock(&inode->i_mutex);
4365                                 err = -EPERM;
4366 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4367                         }
4368                 }
4369  
4370 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4371 +               flags &= JFS_FL_USER_MODIFIABLE;
4372                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4373                 jfs_inode->mode2 = flags;
4374  
4375 diff -NurpP --minimal linux-2.6.37/fs/jfs/jfs_dinode.h linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/jfs_dinode.h
4376 --- linux-2.6.37/fs/jfs/jfs_dinode.h    2008-12-25 00:26:37.000000000 +0100
4377 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/jfs_dinode.h     2010-11-23 02:09:41.000000000 +0100
4378 @@ -161,9 +161,13 @@ struct dinode {
4379  
4380  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4381  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4382 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4383  
4384 -#define JFS_FL_USER_VISIBLE    0x03F80000
4385 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4386 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4387 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4388 +
4389 +#define JFS_FL_USER_VISIBLE    0x07F80000
4390 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4391  #define JFS_FL_INHERIT         0x03C80000
4392  
4393  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4394 diff -NurpP --minimal linux-2.6.37/fs/jfs/jfs_filsys.h linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/jfs_filsys.h
4395 --- linux-2.6.37/fs/jfs/jfs_filsys.h    2008-12-25 00:26:37.000000000 +0100
4396 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/jfs_filsys.h     2010-11-23 02:09:41.000000000 +0100
4397 @@ -263,6 +263,7 @@
4398  #define JFS_NAME_MAX   255
4399  #define JFS_PATH_MAX   BPSIZE
4400  
4401 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4402  
4403  /*
4404   *     file system state (superblock state)
4405 diff -NurpP --minimal linux-2.6.37/fs/jfs/jfs_imap.c linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/jfs_imap.c
4406 --- linux-2.6.37/fs/jfs/jfs_imap.c      2011-01-05 21:50:24.000000000 +0100
4407 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/jfs_imap.c       2010-11-23 02:09:41.000000000 +0100
4408 @@ -46,6 +46,7 @@
4409  #include <linux/pagemap.h>
4410  #include <linux/quotaops.h>
4411  #include <linux/slab.h>
4412 +#include <linux/vs_tag.h>
4413  
4414  #include "jfs_incore.h"
4415  #include "jfs_inode.h"
4416 @@ -3060,6 +3061,8 @@ static int copy_from_dinode(struct dinod
4417  {
4418         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4419         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4420 +       uid_t uid;
4421 +       gid_t gid;
4422  
4423         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4424         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4425 @@ -3080,14 +3083,18 @@ static int copy_from_dinode(struct dinod
4426         }
4427         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4428  
4429 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4430 +       uid = le32_to_cpu(dip->di_uid);
4431 +       gid = le32_to_cpu(dip->di_gid);
4432 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4433 +
4434 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4435         if (sbi->uid == -1)
4436                 ip->i_uid = jfs_ip->saved_uid;
4437         else {
4438                 ip->i_uid = sbi->uid;
4439         }
4440  
4441 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4442 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4443         if (sbi->gid == -1)
4444                 ip->i_gid = jfs_ip->saved_gid;
4445         else {
4446 @@ -3152,14 +3159,12 @@ static void copy_to_dinode(struct dinode
4447         dip->di_size = cpu_to_le64(ip->i_size);
4448         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4449         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4450 -       if (sbi->uid == -1)
4451 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4452 -       else
4453 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4454 -       if (sbi->gid == -1)
4455 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4456 -       else
4457 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4458 +
4459 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4460 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4461 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4462 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4463 +
4464         jfs_get_inode_flags(jfs_ip);
4465         /*
4466          * mode2 is only needed for storing the higher order bits.
4467 diff -NurpP --minimal linux-2.6.37/fs/jfs/jfs_inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/jfs_inode.c
4468 --- linux-2.6.37/fs/jfs/jfs_inode.c     2010-08-02 16:52:49.000000000 +0200
4469 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/jfs_inode.c      2010-11-23 02:09:41.000000000 +0100
4470 @@ -18,6 +18,7 @@
4471  
4472  #include <linux/fs.h>
4473  #include <linux/quotaops.h>
4474 +#include <linux/vs_tag.h>
4475  #include "jfs_incore.h"
4476  #include "jfs_inode.h"
4477  #include "jfs_filsys.h"
4478 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4479  {
4480         unsigned int flags = JFS_IP(inode)->mode2;
4481  
4482 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4483 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4484 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4485 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4486  
4487         if (flags & JFS_IMMUTABLE_FL)
4488                 inode->i_flags |= S_IMMUTABLE;
4489 +       if (flags & JFS_IXUNLINK_FL)
4490 +               inode->i_flags |= S_IXUNLINK;
4491 +
4492 +       if (flags & JFS_SYNC_FL)
4493 +               inode->i_flags |= S_SYNC;
4494         if (flags & JFS_APPEND_FL)
4495                 inode->i_flags |= S_APPEND;
4496         if (flags & JFS_NOATIME_FL)
4497                 inode->i_flags |= S_NOATIME;
4498         if (flags & JFS_DIRSYNC_FL)
4499                 inode->i_flags |= S_DIRSYNC;
4500 -       if (flags & JFS_SYNC_FL)
4501 -               inode->i_flags |= S_SYNC;
4502 +
4503 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4504 +
4505 +       if (flags & JFS_BARRIER_FL)
4506 +               inode->i_vflags |= V_BARRIER;
4507 +       if (flags & JFS_COW_FL)
4508 +               inode->i_vflags |= V_COW;
4509  }
4510  
4511  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4512  {
4513         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4514 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4515 +
4516 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4517 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4518 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4519 +                          JFS_BARRIER_FL | JFS_COW_FL);
4520  
4521 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4522 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4523         if (flags & S_IMMUTABLE)
4524                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4525 +       if (flags & S_IXUNLINK)
4526 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4527 +
4528         if (flags & S_APPEND)
4529                 jfs_ip->mode2 |= JFS_APPEND_FL;
4530         if (flags & S_NOATIME)
4531 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4532                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4533         if (flags & S_SYNC)
4534                 jfs_ip->mode2 |= JFS_SYNC_FL;
4535 +
4536 +       if (vflags & V_BARRIER)
4537 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4538 +       if (vflags & V_COW)
4539 +               jfs_ip->mode2 |= JFS_COW_FL;
4540  }
4541  
4542  /*
4543 diff -NurpP --minimal linux-2.6.37/fs/jfs/jfs_inode.h linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/jfs_inode.h
4544 --- linux-2.6.37/fs/jfs/jfs_inode.h     2010-10-21 13:07:50.000000000 +0200
4545 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/jfs_inode.h      2010-11-23 02:09:41.000000000 +0100
4546 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4547  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4548         int fh_len, int fh_type);
4549  extern void jfs_set_inode_flags(struct inode *);
4550 +extern int jfs_sync_flags(struct inode *, int, int);
4551  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4552  extern int jfs_setattr(struct dentry *, struct iattr *);
4553  
4554 diff -NurpP --minimal linux-2.6.37/fs/jfs/namei.c linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/namei.c
4555 --- linux-2.6.37/fs/jfs/namei.c 2011-01-05 21:50:24.000000000 +0100
4556 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/namei.c  2010-11-23 02:09:41.000000000 +0100
4557 @@ -21,6 +21,7 @@
4558  #include <linux/ctype.h>
4559  #include <linux/quotaops.h>
4560  #include <linux/exportfs.h>
4561 +#include <linux/vs_tag.h>
4562  #include "jfs_incore.h"
4563  #include "jfs_superblock.h"
4564  #include "jfs_inode.h"
4565 @@ -1491,6 +1492,7 @@ static struct dentry *jfs_lookup(struct 
4566                 return ERR_CAST(ip);
4567         }
4568  
4569 +       dx_propagate_tag(nd, ip);
4570         dentry = d_splice_alias(ip, dentry);
4571  
4572         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4573 @@ -1560,6 +1562,7 @@ const struct inode_operations jfs_dir_in
4574  #ifdef CONFIG_JFS_POSIX_ACL
4575         .check_acl      = jfs_check_acl,
4576  #endif
4577 +       .sync_flags     = jfs_sync_flags,
4578  };
4579  
4580  const struct file_operations jfs_dir_operations = {
4581 diff -NurpP --minimal linux-2.6.37/fs/jfs/super.c linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/super.c
4582 --- linux-2.6.37/fs/jfs/super.c 2011-01-05 21:50:24.000000000 +0100
4583 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/jfs/super.c  2010-11-23 03:40:34.000000000 +0100
4584 @@ -190,7 +190,8 @@ static void jfs_put_super(struct super_b
4585  enum {
4586         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4587         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4588 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4589 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4590 +       Opt_tag, Opt_notag, Opt_tagid
4591  };
4592  
4593  static const match_table_t tokens = {
4594 @@ -200,6 +201,10 @@ static const match_table_t tokens = {
4595         {Opt_resize, "resize=%u"},
4596         {Opt_resize_nosize, "resize"},
4597         {Opt_errors, "errors=%s"},
4598 +       {Opt_tag, "tag"},
4599 +       {Opt_notag, "notag"},
4600 +       {Opt_tagid, "tagid=%u"},
4601 +       {Opt_tag, "tagxid"},
4602         {Opt_ignore, "noquota"},
4603         {Opt_ignore, "quota"},
4604         {Opt_usrquota, "usrquota"},
4605 @@ -334,6 +339,20 @@ static int parse_options(char *options, 
4606                         }
4607                         break;
4608                 }
4609 +#ifndef CONFIG_TAGGING_NONE
4610 +               case Opt_tag:
4611 +                       *flag |= JFS_TAGGED;
4612 +                       break;
4613 +               case Opt_notag:
4614 +                       *flag &= JFS_TAGGED;
4615 +                       break;
4616 +#endif
4617 +#ifdef CONFIG_PROPAGATE
4618 +               case Opt_tagid:
4619 +                       /* use args[0] */
4620 +                       *flag |= JFS_TAGGED;
4621 +                       break;
4622 +#endif
4623                 default:
4624                         printk("jfs: Unrecognized mount option \"%s\" "
4625                                         " or missing value\n", p);
4626 @@ -365,6 +384,12 @@ static int jfs_remount(struct super_bloc
4627                 return -EINVAL;
4628         }
4629  
4630 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4631 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4632 +                       sb->s_id);
4633 +               return -EINVAL;
4634 +       }
4635 +
4636         if (newLVSize) {
4637                 if (sb->s_flags & MS_RDONLY) {
4638                         printk(KERN_ERR
4639 @@ -447,6 +472,9 @@ static int jfs_fill_super(struct super_b
4640  #ifdef CONFIG_JFS_POSIX_ACL
4641         sb->s_flags |= MS_POSIXACL;
4642  #endif
4643 +       /* map mount option tagxid */
4644 +       if (sbi->flag & JFS_TAGGED)
4645 +               sb->s_flags |= MS_TAGGED;
4646  
4647         if (newLVSize) {
4648                 printk(KERN_ERR "resize option for remount only\n");
4649 diff -NurpP --minimal linux-2.6.37/fs/libfs.c linux-2.6.37-vs2.3.0.37-rc3/fs/libfs.c
4650 --- linux-2.6.37/fs/libfs.c     2011-01-05 21:50:24.000000000 +0100
4651 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/libfs.c      2010-11-23 02:09:41.000000000 +0100
4652 @@ -124,7 +124,8 @@ static inline unsigned char dt_type(stru
4653   * both impossible due to the lock on directory.
4654   */
4655  
4656 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4657 +static inline int do_dcache_readdir_filter(struct file *filp,
4658 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4659  {
4660         struct dentry *dentry = filp->f_path.dentry;
4661         struct dentry *cursor = filp->private_data;
4662 @@ -157,6 +158,8 @@ int dcache_readdir(struct file * filp, v
4663                                 next = list_entry(p, struct dentry, d_u.d_child);
4664                                 if (d_unhashed(next) || !next->d_inode)
4665                                         continue;
4666 +                               if (filter && !filter(next))
4667 +                                       continue;
4668  
4669                                 spin_unlock(&dcache_lock);
4670                                 if (filldir(dirent, next->d_name.name, 
4671 @@ -175,6 +178,18 @@ int dcache_readdir(struct file * filp, v
4672         return 0;
4673  }
4674  
4675 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4676 +{
4677 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4678 +}
4679 +
4680 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4681 +       int (*filter)(struct dentry *))
4682 +{
4683 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4684 +}
4685 +
4686 +
4687  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4688  {
4689         return -EISDIR;
4690 @@ -948,6 +963,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4691  EXPORT_SYMBOL(dcache_dir_lseek);
4692  EXPORT_SYMBOL(dcache_dir_open);
4693  EXPORT_SYMBOL(dcache_readdir);
4694 +EXPORT_SYMBOL(dcache_readdir_filter);
4695  EXPORT_SYMBOL(generic_read_dir);
4696  EXPORT_SYMBOL(mount_pseudo);
4697  EXPORT_SYMBOL(simple_write_begin);
4698 diff -NurpP --minimal linux-2.6.37/fs/locks.c linux-2.6.37-vs2.3.0.37-rc3/fs/locks.c
4699 --- linux-2.6.37/fs/locks.c     2011-01-05 21:50:24.000000000 +0100
4700 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/locks.c      2010-11-23 03:38:48.000000000 +0100
4701 @@ -126,6 +126,8 @@
4702  #include <linux/time.h>
4703  #include <linux/rcupdate.h>
4704  #include <linux/pid_namespace.h>
4705 +#include <linux/vs_base.h>
4706 +#include <linux/vs_limit.h>
4707  
4708  #include <asm/uaccess.h>
4709  
4710 @@ -164,6 +166,8 @@ static struct kmem_cache *filelock_cache
4711  /* Allocate an empty lock structure. */
4712  struct file_lock *locks_alloc_lock(void)
4713  {
4714 +       if (!vx_locks_avail(1))
4715 +               return NULL;
4716         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4717  }
4718  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4719 @@ -191,6 +195,7 @@ void locks_free_lock(struct file_lock *f
4720         BUG_ON(!list_empty(&fl->fl_block));
4721         BUG_ON(!list_empty(&fl->fl_link));
4722  
4723 +       vx_locks_dec(fl);
4724         locks_release_private(fl);
4725         kmem_cache_free(filelock_cache, fl);
4726  }
4727 @@ -212,6 +217,7 @@ void locks_init_lock(struct file_lock *f
4728         fl->fl_start = fl->fl_end = 0;
4729         fl->fl_ops = NULL;
4730         fl->fl_lmops = NULL;
4731 +       fl->fl_xid = -1;
4732  }
4733  
4734  EXPORT_SYMBOL(locks_init_lock);
4735 @@ -263,6 +269,7 @@ void locks_copy_lock(struct file_lock *n
4736         new->fl_file = fl->fl_file;
4737         new->fl_ops = fl->fl_ops;
4738         new->fl_lmops = fl->fl_lmops;
4739 +       new->fl_xid = fl->fl_xid;
4740  
4741         locks_copy_private(new, fl);
4742  }
4743 @@ -301,6 +308,11 @@ static int flock_make_lock(struct file *
4744         fl->fl_flags = FL_FLOCK;
4745         fl->fl_type = type;
4746         fl->fl_end = OFFSET_MAX;
4747 +
4748 +       vxd_assert(filp->f_xid == vx_current_xid(),
4749 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4750 +       fl->fl_xid = filp->f_xid;
4751 +       vx_locks_inc(fl);
4752         
4753         *lock = fl;
4754         return 0;
4755 @@ -466,6 +478,7 @@ static int lease_init(struct file *filp,
4756  
4757         fl->fl_owner = current->files;
4758         fl->fl_pid = current->tgid;
4759 +       fl->fl_xid = vx_current_xid();
4760  
4761         fl->fl_file = filp;
4762         fl->fl_flags = FL_LEASE;
4763 @@ -485,6 +498,11 @@ static struct file_lock *lease_alloc(str
4764         if (fl == NULL)
4765                 return ERR_PTR(error);
4766  
4767 +       fl->fl_xid = vx_current_xid();
4768 +       if (filp)
4769 +               vxd_assert(filp->f_xid == fl->fl_xid,
4770 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4771 +       vx_locks_inc(fl);
4772         error = lease_init(filp, type, fl);
4773         if (error) {
4774                 locks_free_lock(fl);
4775 @@ -786,6 +804,7 @@ static int flock_lock_file(struct file *
4776                 lock_flocks();
4777         }
4778  
4779 +       new_fl->fl_xid = -1;
4780  find_conflict:
4781         for_each_lock(inode, before) {
4782                 struct file_lock *fl = *before;
4783 @@ -806,6 +825,7 @@ find_conflict:
4784                 goto out;
4785         locks_copy_lock(new_fl, request);
4786         locks_insert_lock(before, new_fl);
4787 +       vx_locks_inc(new_fl);
4788         new_fl = NULL;
4789         error = 0;
4790  
4791 @@ -816,7 +836,8 @@ out:
4792         return error;
4793  }
4794  
4795 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4796 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4797 +       struct file_lock *conflock, xid_t xid)
4798  {
4799         struct file_lock *fl;
4800         struct file_lock *new_fl = NULL;
4801 @@ -826,6 +847,8 @@ static int __posix_lock_file(struct inod
4802         struct file_lock **before;
4803         int error, added = 0;
4804  
4805 +       vxd_assert(xid == vx_current_xid(),
4806 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4807         /*
4808          * We may need two file_lock structures for this operation,
4809          * so we get them in advance to avoid races.
4810 @@ -836,7 +859,11 @@ static int __posix_lock_file(struct inod
4811             (request->fl_type != F_UNLCK ||
4812              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4813                 new_fl = locks_alloc_lock();
4814 +               new_fl->fl_xid = xid;
4815 +               vx_locks_inc(new_fl);
4816                 new_fl2 = locks_alloc_lock();
4817 +               new_fl2->fl_xid = xid;
4818 +               vx_locks_inc(new_fl2);
4819         }
4820  
4821         lock_flocks();
4822 @@ -1035,7 +1062,8 @@ static int __posix_lock_file(struct inod
4823  int posix_lock_file(struct file *filp, struct file_lock *fl,
4824                         struct file_lock *conflock)
4825  {
4826 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4827 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4828 +               fl, conflock, filp->f_xid);
4829  }
4830  EXPORT_SYMBOL(posix_lock_file);
4831  
4832 @@ -1125,7 +1153,7 @@ int locks_mandatory_area(int read_write,
4833         fl.fl_end = offset + count - 1;
4834  
4835         for (;;) {
4836 -               error = __posix_lock_file(inode, &fl, NULL);
4837 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4838                 if (error != FILE_LOCK_DEFERRED)
4839                         break;
4840                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4841 @@ -1438,6 +1466,7 @@ int generic_setlease(struct file *filp, 
4842                 goto out;
4843  
4844         locks_insert_lock(before, lease);
4845 +       vx_locks_inc(lease);
4846         return 0;
4847  
4848  out:
4849 @@ -1822,6 +1851,11 @@ int fcntl_setlk(unsigned int fd, struct 
4850         if (file_lock == NULL)
4851                 return -ENOLCK;
4852  
4853 +       vxd_assert(filp->f_xid == vx_current_xid(),
4854 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4855 +       file_lock->fl_xid = filp->f_xid;
4856 +       vx_locks_inc(file_lock);
4857 +
4858         /*
4859          * This might block, so we do it before checking the inode.
4860          */
4861 @@ -1940,6 +1974,11 @@ int fcntl_setlk64(unsigned int fd, struc
4862         if (file_lock == NULL)
4863                 return -ENOLCK;
4864  
4865 +       vxd_assert(filp->f_xid == vx_current_xid(),
4866 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4867 +       file_lock->fl_xid = filp->f_xid;
4868 +       vx_locks_inc(file_lock);
4869 +
4870         /*
4871          * This might block, so we do it before checking the inode.
4872          */
4873 @@ -2205,8 +2244,11 @@ static int locks_show(struct seq_file *f
4874  
4875         lock_get_status(f, fl, *((loff_t *)f->private), "");
4876  
4877 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4878 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4879 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4880 +                       continue;
4881                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4882 +       }
4883  
4884         return 0;
4885  }
4886 diff -NurpP --minimal linux-2.6.37/fs/namei.c linux-2.6.37-vs2.3.0.37-rc3/fs/namei.c
4887 --- linux-2.6.37/fs/namei.c     2011-01-05 21:50:24.000000000 +0100
4888 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/namei.c      2011-01-05 22:30:39.000000000 +0100
4889 @@ -32,6 +32,14 @@
4890  #include <linux/fcntl.h>
4891  #include <linux/device_cgroup.h>
4892  #include <linux/fs_struct.h>
4893 +#include <linux/proc_fs.h>
4894 +#include <linux/vserver/inode.h>
4895 +#include <linux/vs_base.h>
4896 +#include <linux/vs_tag.h>
4897 +#include <linux/vs_cowbl.h>
4898 +#include <linux/vs_device.h>
4899 +#include <linux/vs_context.h>
4900 +#include <linux/pid_namespace.h>
4901  #include <asm/uaccess.h>
4902  
4903  #include "internal.h"
4904 @@ -166,6 +174,84 @@ void putname(const char *name)
4905  EXPORT_SYMBOL(putname);
4906  #endif
4907  
4908 +static inline int dx_barrier(const struct inode *inode)
4909 +{
4910 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4911 +               vxwprintk_task(1, "did hit the barrier.");
4912 +               return 1;
4913 +       }
4914 +       return 0;
4915 +}
4916 +
4917 +static int __dx_permission(const struct inode *inode, int mask)
4918 +{
4919 +       if (dx_barrier(inode))
4920 +               return -EACCES;
4921 +
4922 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4923 +               /* devpts is xid tagged */
4924 +               if (S_ISDIR(inode->i_mode) ||
4925 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4926 +                       return 0;
4927 +
4928 +               /* just pretend we didn't find anything */
4929 +               return -ENOENT;
4930 +       }
4931 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4932 +               struct proc_dir_entry *de = PDE(inode);
4933 +
4934 +               if (de && !vx_hide_check(0, de->vx_flags))
4935 +                       goto out;
4936 +
4937 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4938 +                       struct pid *pid;
4939 +                       struct task_struct *tsk;
4940 +
4941 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4942 +                           vx_flags(VXF_STATE_SETUP, 0))
4943 +                               return 0;
4944 +
4945 +                       pid = PROC_I(inode)->pid;
4946 +                       if (!pid)
4947 +                               goto out;
4948 +
4949 +                       tsk = pid_task(pid, PIDTYPE_PID);
4950 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4951 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4952 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4953 +                               return 0;
4954 +               }
4955 +               else {
4956 +                       /* FIXME: Should we block some entries here? */
4957 +                       return 0;
4958 +               }
4959 +       }
4960 +       else {
4961 +               if (dx_notagcheck(inode->i_sb) ||
4962 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4963 +                            DX_IDENT))
4964 +                       return 0;
4965 +       }
4966 +
4967 +out:
4968 +       return -EACCES;
4969 +}
4970 +
4971 +int dx_permission(const struct inode *inode, int mask)
4972 +{
4973 +       int ret = __dx_permission(inode, mask);
4974 +       if (unlikely(ret)) {
4975 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4976 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4977 +#endif
4978 +                   vxwprintk_task(1,
4979 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4980 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4981 +                       inode->i_ino);
4982 +       }
4983 +       return ret;
4984 +}
4985 +
4986  /*
4987   * This does basic POSIX ACL permission checking
4988   */
4989 @@ -266,10 +352,14 @@ int inode_permission(struct inode *inode
4990                 /*
4991                  * Nobody gets write access to an immutable file.
4992                  */
4993 -               if (IS_IMMUTABLE(inode))
4994 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4995                         return -EACCES;
4996         }
4997  
4998 +       retval = dx_permission(inode, mask);
4999 +       if (retval)
5000 +               return retval;
5001 +
5002         if (inode->i_op->permission)
5003                 retval = inode->i_op->permission(inode, mask);
5004         else
5005 @@ -463,6 +553,9 @@ static int exec_permission(struct inode 
5006  {
5007         int ret;
5008  
5009 +       if (dx_barrier(inode))
5010 +               return -EACCES;
5011 +
5012         if (inode->i_op->permission) {
5013                 ret = inode->i_op->permission(inode, MAY_EXEC);
5014                 if (!ret)
5015 @@ -672,7 +765,8 @@ static __always_inline void follow_dotdo
5016  
5017                 if (nd->path.dentry == nd->root.dentry &&
5018                     nd->path.mnt == nd->root.mnt) {
5019 -                       break;
5020 +                       /* for sane '/' avoid follow_mount() */
5021 +                       return;
5022                 }
5023                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5024                         /* rare case of legitimate dget_parent()... */
5025 @@ -725,7 +819,7 @@ static int do_lookup(struct nameidata *n
5026  {
5027         struct vfsmount *mnt = nd->path.mnt;
5028         struct dentry *dentry, *parent;
5029 -       struct inode *dir;
5030 +       struct inode *dir, *inode;
5031         /*
5032          * See if the low-level filesystem might want
5033          * to use its own hash..
5034 @@ -747,12 +841,31 @@ static int do_lookup(struct nameidata *n
5035  found:
5036         if (dentry->d_op && dentry->d_op->d_revalidate)
5037                 goto need_revalidate;
5038 +
5039 +       inode = dentry->d_inode;
5040 +       if (!inode)
5041 +               goto done;
5042 +
5043 +       if (__dx_permission(inode, MAY_ACCESS))
5044 +               goto hidden;
5045  done:
5046         path->mnt = mnt;
5047         path->dentry = dentry;
5048         __follow_mount(path);
5049         return 0;
5050  
5051 +hidden:
5052 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
5053 +       if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
5054 +#endif
5055 +           vxwprintk_task(1,
5056 +               "did lookup hidden %s:%p[#%d,%lu] " VS_Q("%s/%.*s") ".",
5057 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5058 +               vxd_path(&nd->path), name->len, name->name);
5059 +
5060 +       dput(dentry);
5061 +       return -ENOENT;
5062 +
5063  need_lookup:
5064         parent = nd->path.dentry;
5065         dir = parent->d_inode;
5066 @@ -1301,7 +1414,7 @@ static int may_delete(struct inode *dir,
5067         if (IS_APPEND(dir))
5068                 return -EPERM;
5069         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5070 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5071 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5072                 return -EPERM;
5073         if (isdir) {
5074                 if (!S_ISDIR(victim->d_inode->i_mode))
5075 @@ -1424,6 +1537,14 @@ int may_open(struct path *path, int acc_
5076                 break;
5077         }
5078  
5079 +#ifdef CONFIG_VSERVER_COWBL
5080 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5081 +               if (IS_COW_LINK(inode))
5082 +                       return -EMLINK;
5083 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5084 +               mark_inode_dirty(inode);
5085 +       }
5086 +#endif
5087         error = inode_permission(inode, acc_mode);
5088         if (error)
5089                 return error;
5090 @@ -1532,7 +1653,8 @@ static int open_will_truncate(int flag, 
5091  }
5092  
5093  static struct file *finish_open(struct nameidata *nd,
5094 -                               int open_flag, int acc_mode)
5095 +                               int open_flag, int acc_mode,
5096 +                               const char *pathname)
5097  {
5098         struct file *filp;
5099         int will_truncate;
5100 @@ -1545,6 +1667,23 @@ static struct file *finish_open(struct n
5101                         goto exit;
5102         }
5103         error = may_open(&nd->path, acc_mode, open_flag);
5104 +#ifdef CONFIG_VSERVER_COWBL
5105 +       if (error == -EMLINK) {
5106 +               struct dentry *dentry;
5107 +               dentry = cow_break_link(pathname);
5108 +               if (IS_ERR(dentry)) {
5109 +                       error = PTR_ERR(dentry);
5110 +                       goto exit_cow;
5111 +               }
5112 +               dput(dentry);
5113 +               if (will_truncate)
5114 +                       mnt_drop_write(nd->path.mnt);
5115 +               release_open_intent(nd);
5116 +               path_put(&nd->path);
5117 +               return ERR_PTR(-EMLINK);
5118 +       }
5119 +exit_cow:
5120 +#endif
5121         if (error) {
5122                 if (will_truncate)
5123                         mnt_drop_write(nd->path.mnt);
5124 @@ -1715,7 +1854,7 @@ static struct file *do_last(struct namei
5125         if (S_ISDIR(path->dentry->d_inode->i_mode))
5126                 goto exit;
5127  ok:
5128 -       filp = finish_open(nd, open_flag, acc_mode);
5129 +       filp = finish_open(nd, open_flag, acc_mode, pathname);
5130         return filp;
5131  
5132  exit_mutex_unlock:
5133 @@ -1744,7 +1883,11 @@ struct file *do_filp_open(int dfd, const
5134         int count = 0;
5135         int flag = open_to_namei_flags(open_flag);
5136         int force_reval = 0;
5137 -
5138 +#ifdef CONFIG_VSERVER_COWBL
5139 +       int rflag = flag;
5140 +       int rmode = mode;
5141 +restart:
5142 +#endif
5143         if (!(open_flag & O_CREAT))
5144                 mode = 0;
5145  
5146 @@ -1813,6 +1956,13 @@ reval:
5147         if (!(open_flag & O_NOFOLLOW))
5148                 nd.flags |= LOOKUP_FOLLOW;
5149         filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5150 +#ifdef CONFIG_VSERVER_COWBL
5151 +       if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5152 +               flag = rflag;
5153 +               mode = rmode;
5154 +               goto restart;
5155 +       }
5156 +#endif
5157         while (unlikely(!filp)) { /* trailing symlink */
5158                 struct path holder;
5159                 struct inode *inode = path.dentry->d_inode;
5160 @@ -1851,6 +2001,13 @@ reval:
5161                 holder = path;
5162                 nd.flags &= ~LOOKUP_PARENT;
5163                 filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5164 +#ifdef CONFIG_VSERVER_COWBL
5165 +               if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5166 +                       flag = rflag;
5167 +                       mode = rmode;
5168 +                       goto restart;
5169 +               }
5170 +#endif
5171                 if (inode->i_op->put_link)
5172                         inode->i_op->put_link(holder.dentry, &nd, cookie);
5173                 path_put(&holder);
5174 @@ -1951,9 +2108,17 @@ int vfs_mknod(struct inode *dir, struct 
5175         if (error)
5176                 return error;
5177  
5178 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5179 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5180 +               goto okay;
5181 +
5182 +       if (!capable(CAP_MKNOD))
5183                 return -EPERM;
5184  
5185 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5186 +               return -EPERM;
5187 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5188 +               return -EPERM;
5189 +okay:
5190         if (!dir->i_op->mknod)
5191                 return -EPERM;
5192  
5193 @@ -2418,7 +2583,7 @@ int vfs_link(struct dentry *old_dentry, 
5194         /*
5195          * A link to an append-only or immutable file cannot be created.
5196          */
5197 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5198 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5199                 return -EPERM;
5200         if (!dir->i_op->link)
5201                 return -EPERM;
5202 @@ -2790,6 +2955,222 @@ int vfs_follow_link(struct nameidata *nd
5203         return __vfs_follow_link(nd, link);
5204  }
5205  
5206 +
5207 +#ifdef CONFIG_VSERVER_COWBL
5208 +
5209 +#include <linux/file.h>
5210 +
5211 +static inline
5212 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5213 +{
5214 +       loff_t ppos = 0;
5215 +
5216 +       return do_splice_direct(in, &ppos, out, len, 0);
5217 +}
5218 +
5219 +struct dentry *cow_break_link(const char *pathname)
5220 +{
5221 +       int ret, mode, pathlen, redo = 0;
5222 +       struct nameidata old_nd, dir_nd;
5223 +       struct path old_path, new_path;
5224 +       struct dentry *dir, *res = NULL;
5225 +       struct file *old_file;
5226 +       struct file *new_file;
5227 +       char *to, *path, pad='\251';
5228 +       loff_t size;
5229 +
5230 +       vxdprintk(VXD_CBIT(misc, 1),
5231 +               "cow_break_link(" VS_Q("%s") ")", pathname);
5232 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5233 +       ret = -ENOMEM;
5234 +       if (!path)
5235 +               goto out;
5236 +
5237 +       /* old_nd will have refs to dentry and mnt */
5238 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5239 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5240 +       if (ret < 0)
5241 +               goto out_free_path;
5242 +
5243 +       old_path = old_nd.path;
5244 +       mode = old_path.dentry->d_inode->i_mode;
5245 +
5246 +       to = d_path(&old_path, path, PATH_MAX-2);
5247 +       pathlen = strlen(to);
5248 +       vxdprintk(VXD_CBIT(misc, 2),
5249 +               "old path " VS_Q("%s") " [" VS_Q("%.*s") ":%d]", to,
5250 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5251 +               old_path.dentry->d_name.len);
5252 +
5253 +       to[pathlen + 1] = 0;
5254 +retry:
5255 +       to[pathlen] = pad--;
5256 +       ret = -EMLINK;
5257 +       if (pad <= '\240')
5258 +               goto out_rel_old;
5259 +
5260 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
5261 +       /* dir_nd will have refs to dentry and mnt */
5262 +       ret = path_lookup(to,
5263 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5264 +       vxdprintk(VXD_CBIT(misc, 2),
5265 +               "path_lookup(new): %d", ret);
5266 +       if (ret < 0)
5267 +               goto retry;
5268 +
5269 +       /* this puppy downs the inode mutex */
5270 +       new_path.dentry = lookup_create(&dir_nd, 0);
5271 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5272 +               vxdprintk(VXD_CBIT(misc, 2),
5273 +                       "lookup_create(new): %p", new_path.dentry);
5274 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5275 +               path_put(&dir_nd.path);
5276 +               goto retry;
5277 +       }
5278 +       vxdprintk(VXD_CBIT(misc, 2),
5279 +               "lookup_create(new): %p [" VS_Q("%.*s") ":%d]",
5280 +               new_path.dentry,
5281 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5282 +               new_path.dentry->d_name.len);
5283 +       dir = dir_nd.path.dentry;
5284 +
5285 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5286 +       vxdprintk(VXD_CBIT(misc, 2),
5287 +               "vfs_create(new): %d", ret);
5288 +       if (ret == -EEXIST) {
5289 +               mutex_unlock(&dir->d_inode->i_mutex);
5290 +               dput(new_path.dentry);
5291 +               path_put(&dir_nd.path);
5292 +               goto retry;
5293 +       }
5294 +       else if (ret < 0)
5295 +               goto out_unlock_new;
5296 +
5297 +       /* drop out early, ret passes ENOENT */
5298 +       ret = -ENOENT;
5299 +       if ((redo = d_unhashed(old_path.dentry)))
5300 +               goto out_unlock_new;
5301 +
5302 +       new_path.mnt = dir_nd.path.mnt;
5303 +       dget(old_path.dentry);
5304 +       mntget(old_path.mnt);
5305 +       /* this one cleans up the dentry/mnt in case of failure */
5306 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5307 +               O_RDONLY, current_cred());
5308 +       vxdprintk(VXD_CBIT(misc, 2),
5309 +               "dentry_open(old): %p", old_file);
5310 +       if (!old_file || IS_ERR(old_file)) {
5311 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5312 +               goto out_unlock_new;
5313 +       }
5314 +
5315 +       dget(new_path.dentry);
5316 +       mntget(new_path.mnt);
5317 +       /* this one cleans up the dentry/mnt in case of failure */
5318 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5319 +               O_WRONLY, current_cred());
5320 +       vxdprintk(VXD_CBIT(misc, 2),
5321 +               "dentry_open(new): %p", new_file);
5322 +
5323 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5324 +       if (!new_file || IS_ERR(new_file))
5325 +               goto out_fput_old;
5326 +
5327 +       size = i_size_read(old_file->f_dentry->d_inode);
5328 +       ret = do_cow_splice(old_file, new_file, size);
5329 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5330 +       if (ret < 0) {
5331 +               goto out_fput_both;
5332 +       } else if (ret < size) {
5333 +               ret = -ENOSPC;
5334 +               goto out_fput_both;
5335 +       } else {
5336 +               struct inode *old_inode = old_path.dentry->d_inode;
5337 +               struct inode *new_inode = new_path.dentry->d_inode;
5338 +               struct iattr attr = {
5339 +                       .ia_uid = old_inode->i_uid,
5340 +                       .ia_gid = old_inode->i_gid,
5341 +                       .ia_valid = ATTR_UID | ATTR_GID
5342 +                       };
5343 +
5344 +               setattr_copy(new_inode, &attr);
5345 +               mark_inode_dirty(new_inode);
5346 +       }
5347 +
5348 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5349 +
5350 +       /* drop out late */
5351 +       ret = -ENOENT;
5352 +       if ((redo = d_unhashed(old_path.dentry)))
5353 +               goto out_unlock;
5354 +
5355 +       vxdprintk(VXD_CBIT(misc, 2),
5356 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
5357 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5358 +               new_path.dentry->d_name.len,
5359 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5360 +               old_path.dentry->d_name.len);
5361 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5362 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5363 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5364 +       res = new_path.dentry;
5365 +
5366 +out_unlock:
5367 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5368 +
5369 +out_fput_both:
5370 +       vxdprintk(VXD_CBIT(misc, 3),
5371 +               "fput(new_file=%p[#%ld])", new_file,
5372 +               atomic_long_read(&new_file->f_count));
5373 +       fput(new_file);
5374 +
5375 +out_fput_old:
5376 +       vxdprintk(VXD_CBIT(misc, 3),
5377 +               "fput(old_file=%p[#%ld])", old_file,
5378 +               atomic_long_read(&old_file->f_count));
5379 +       fput(old_file);
5380 +
5381 +out_unlock_new:
5382 +       mutex_unlock(&dir->d_inode->i_mutex);
5383 +       if (!ret)
5384 +               goto out_redo;
5385 +
5386 +       /* error path cleanup */
5387 +       vfs_unlink(dir->d_inode, new_path.dentry);
5388 +       dput(new_path.dentry);
5389 +
5390 +out_redo:
5391 +       if (!redo)
5392 +               goto out_rel_both;
5393 +       /* lookup dentry once again */
5394 +       path_put(&old_nd.path);
5395 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5396 +       if (ret)
5397 +               goto out_rel_both;
5398 +
5399 +       new_path.dentry = old_nd.path.dentry;
5400 +       vxdprintk(VXD_CBIT(misc, 2),
5401 +               "path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
5402 +               new_path.dentry,
5403 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5404 +               new_path.dentry->d_name.len);
5405 +       dget(new_path.dentry);
5406 +       res = new_path.dentry;
5407 +
5408 +out_rel_both:
5409 +       path_put(&dir_nd.path);
5410 +out_rel_old:
5411 +       path_put(&old_nd.path);
5412 +out_free_path:
5413 +       kfree(path);
5414 +out:
5415 +       if (ret)
5416 +               res = ERR_PTR(ret);
5417 +       return res;
5418 +}
5419 +
5420 +#endif
5421 +
5422  /* get the link contents into pagecache */
5423  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5424  {
5425 diff -NurpP --minimal linux-2.6.37/fs/namespace.c linux-2.6.37-vs2.3.0.37-rc3/fs/namespace.c
5426 --- linux-2.6.37/fs/namespace.c 2011-01-05 21:50:24.000000000 +0100
5427 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/namespace.c  2010-11-23 02:09:41.000000000 +0100
5428 @@ -31,6 +31,11 @@
5429  #include <linux/idr.h>
5430  #include <linux/fs_struct.h>
5431  #include <linux/fsnotify.h>
5432 +#include <linux/vs_base.h>
5433 +#include <linux/vs_context.h>
5434 +#include <linux/vs_tag.h>
5435 +#include <linux/vserver/space.h>
5436 +#include <linux/vserver/global.h>
5437  #include <asm/uaccess.h>
5438  #include <asm/unistd.h>
5439  #include "pnode.h"
5440 @@ -600,6 +605,7 @@ static struct vfsmount *clone_mnt(struct
5441                 mnt->mnt_root = dget(root);
5442                 mnt->mnt_mountpoint = mnt->mnt_root;
5443                 mnt->mnt_parent = mnt;
5444 +               mnt->mnt_tag = old->mnt_tag;
5445  
5446                 if (flag & CL_SLAVE) {
5447                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5448 @@ -698,6 +704,31 @@ static inline void mangle(struct seq_fil
5449         seq_escape(m, s, " \t\n\\");
5450  }
5451  
5452 +static int mnt_is_reachable(struct vfsmount *mnt)
5453 +{
5454 +       struct path root;
5455 +       struct dentry *point;
5456 +       int ret;
5457 +
5458 +       if (mnt == mnt->mnt_ns->root)
5459 +               return 1;
5460 +
5461 +       br_read_lock(vfsmount_lock);
5462 +       root = current->fs->root;
5463 +       point = root.dentry;
5464 +
5465 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5466 +               point = mnt->mnt_mountpoint;
5467 +               mnt = mnt->mnt_parent;
5468 +       }
5469 +
5470 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5471 +
5472 +       br_read_unlock(vfsmount_lock);
5473 +
5474 +       return ret;
5475 +}
5476 +
5477  /*
5478   * Simple .show_options callback for filesystems which don't want to
5479   * implement more complex mount option showing.
5480 @@ -800,6 +831,8 @@ static int show_sb_opts(struct seq_file 
5481                 { MS_SYNCHRONOUS, ",sync" },
5482                 { MS_DIRSYNC, ",dirsync" },
5483                 { MS_MANDLOCK, ",mand" },
5484 +               { MS_TAGGED, ",tag" },
5485 +               { MS_NOTAGCHECK, ",notagcheck" },
5486                 { 0, NULL }
5487         };
5488         const struct proc_fs_info *fs_infop;
5489 @@ -846,10 +879,20 @@ static int show_vfsmnt(struct seq_file *
5490         int err = 0;
5491         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5492  
5493 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5494 -       seq_putc(m, ' ');
5495 -       seq_path(m, &mnt_path, " \t\n\\");
5496 -       seq_putc(m, ' ');
5497 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5498 +               return SEQ_SKIP;
5499 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5500 +               return SEQ_SKIP;
5501 +
5502 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5503 +               mnt == current->fs->root.mnt) {
5504 +               seq_puts(m, "/dev/root / ");
5505 +       } else {
5506 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5507 +               seq_putc(m, ' ');
5508 +               seq_path(m, &mnt_path, " \t\n\\");
5509 +               seq_putc(m, ' ');
5510 +       }
5511         show_type(m, mnt->mnt_sb);
5512         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5513         err = show_sb_opts(m, mnt->mnt_sb);
5514 @@ -879,6 +922,11 @@ static int show_mountinfo(struct seq_fil
5515         struct path root = p->root;
5516         int err = 0;
5517  
5518 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5519 +               return SEQ_SKIP;
5520 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5521 +               return SEQ_SKIP;
5522 +
5523         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5524                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5525         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5526 @@ -937,17 +985,27 @@ static int show_vfsstat(struct seq_file 
5527         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5528         int err = 0;
5529  
5530 -       /* device */
5531 -       if (mnt->mnt_devname) {
5532 -               seq_puts(m, "device ");
5533 -               mangle(m, mnt->mnt_devname);
5534 -       } else
5535 -               seq_puts(m, "no device");
5536 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5537 +               return SEQ_SKIP;
5538 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5539 +               return SEQ_SKIP;
5540  
5541 -       /* mount point */
5542 -       seq_puts(m, " mounted on ");
5543 -       seq_path(m, &mnt_path, " \t\n\\");
5544 -       seq_putc(m, ' ');
5545 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5546 +               mnt == current->fs->root.mnt) {
5547 +               seq_puts(m, "device /dev/root mounted on / ");
5548 +       } else {
5549 +               /* device */
5550 +               if (mnt->mnt_devname) {
5551 +                       seq_puts(m, "device ");
5552 +                       mangle(m, mnt->mnt_devname);
5553 +               } else
5554 +                       seq_puts(m, "no device");
5555 +
5556 +               /* mount point */
5557 +               seq_puts(m, " mounted on ");
5558 +               seq_path(m, &mnt_path, " \t\n\\");
5559 +               seq_putc(m, ' ');
5560 +       }
5561  
5562         /* file system type */
5563         seq_puts(m, "with fstype ");
5564 @@ -1193,7 +1251,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5565                 goto dput_and_out;
5566  
5567         retval = -EPERM;
5568 -       if (!capable(CAP_SYS_ADMIN))
5569 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5570                 goto dput_and_out;
5571  
5572         retval = do_umount(path.mnt, flags);
5573 @@ -1219,7 +1277,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5574  
5575  static int mount_is_safe(struct path *path)
5576  {
5577 -       if (capable(CAP_SYS_ADMIN))
5578 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5579                 return 0;
5580         return -EPERM;
5581  #ifdef notyet
5582 @@ -1509,7 +1567,7 @@ static int do_change_type(struct path *p
5583         int type;
5584         int err = 0;
5585  
5586 -       if (!capable(CAP_SYS_ADMIN))
5587 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5588                 return -EPERM;
5589  
5590         if (path->dentry != path->mnt->mnt_root)
5591 @@ -1540,11 +1598,13 @@ static int do_change_type(struct path *p
5592   * do loopback mount.
5593   */
5594  static int do_loopback(struct path *path, char *old_name,
5595 -                               int recurse)
5596 +       tag_t tag, unsigned long flags, int mnt_flags)
5597  {
5598         struct path old_path;
5599         struct vfsmount *mnt = NULL;
5600         int err = mount_is_safe(path);
5601 +       int recurse = flags & MS_REC;
5602 +
5603         if (err)
5604                 return err;
5605         if (!old_name || !*old_name)
5606 @@ -1579,6 +1639,7 @@ static int do_loopback(struct path *path
5607                 br_write_unlock(vfsmount_lock);
5608                 release_mounts(&umount_list);
5609         }
5610 +       mnt->mnt_flags = mnt_flags;
5611  
5612  out:
5613         up_write(&namespace_sem);
5614 @@ -1609,12 +1670,12 @@ static int change_mount_flags(struct vfs
5615   * on it - tough luck.
5616   */
5617  static int do_remount(struct path *path, int flags, int mnt_flags,
5618 -                     void *data)
5619 +       void *data, xid_t xid)
5620  {
5621         int err;
5622         struct super_block *sb = path->mnt->mnt_sb;
5623  
5624 -       if (!capable(CAP_SYS_ADMIN))
5625 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5626                 return -EPERM;
5627  
5628         if (!check_mnt(path->mnt))
5629 @@ -1658,7 +1719,7 @@ static int do_move_mount(struct path *pa
5630         struct path old_path, parent_path;
5631         struct vfsmount *p;
5632         int err = 0;
5633 -       if (!capable(CAP_SYS_ADMIN))
5634 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5635                 return -EPERM;
5636         if (!old_name || !*old_name)
5637                 return -EINVAL;
5638 @@ -1740,7 +1801,7 @@ static int do_new_mount(struct path *pat
5639                 return -EINVAL;
5640  
5641         /* we need capabilities... */
5642 -       if (!capable(CAP_SYS_ADMIN))
5643 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5644                 return -EPERM;
5645  
5646         mnt = do_kern_mount(type, flags, name, data);
5647 @@ -2006,6 +2067,7 @@ long do_mount(char *dev_name, char *dir_
5648         struct path path;
5649         int retval = 0;
5650         int mnt_flags = 0;
5651 +       tag_t tag = 0;
5652  
5653         /* Discard magic */
5654         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5655 @@ -2033,6 +2095,12 @@ long do_mount(char *dev_name, char *dir_
5656         if (!(flags & MS_NOATIME))
5657                 mnt_flags |= MNT_RELATIME;
5658  
5659 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5660 +               /* FIXME: bind and re-mounts get the tag flag? */
5661 +               if (flags & (MS_BIND|MS_REMOUNT))
5662 +                       flags |= MS_TAGID;
5663 +       }
5664 +
5665         /* Separate the per-mountpoint flags */
5666         if (flags & MS_NOSUID)
5667                 mnt_flags |= MNT_NOSUID;
5668 @@ -2049,15 +2117,17 @@ long do_mount(char *dev_name, char *dir_
5669         if (flags & MS_RDONLY)
5670                 mnt_flags |= MNT_READONLY;
5671  
5672 +       if (!capable(CAP_SYS_ADMIN))
5673 +               mnt_flags |= MNT_NODEV;
5674         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5675                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5676                    MS_STRICTATIME);
5677  
5678         if (flags & MS_REMOUNT)
5679                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5680 -                                   data_page);
5681 +                                   data_page, tag);
5682         else if (flags & MS_BIND)
5683 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5684 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5685         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5686                 retval = do_change_type(&path, flags);
5687         else if (flags & MS_MOVE)
5688 @@ -2136,6 +2206,7 @@ static struct mnt_namespace *dup_mnt_ns(
5689                 q = next_mnt(q, new_ns->root);
5690         }
5691         up_write(&namespace_sem);
5692 +       atomic_inc(&vs_global_mnt_ns);
5693  
5694         if (rootmnt)
5695                 mntput(rootmnt);
5696 @@ -2277,9 +2348,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5697         down_write(&namespace_sem);
5698         mutex_lock(&old.dentry->d_inode->i_mutex);
5699         error = -EINVAL;
5700 -       if (IS_MNT_SHARED(old.mnt) ||
5701 +       if ((IS_MNT_SHARED(old.mnt) ||
5702                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5703 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5704 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5705 +               !vx_flags(VXF_STATE_SETUP, 0))
5706                 goto out2;
5707         if (!check_mnt(root.mnt))
5708                 goto out2;
5709 @@ -2412,6 +2484,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5710         br_write_unlock(vfsmount_lock);
5711         up_write(&namespace_sem);
5712         release_mounts(&umount_list);
5713 +       atomic_dec(&vs_global_mnt_ns);
5714         kfree(ns);
5715  }
5716  EXPORT_SYMBOL(put_mnt_ns);
5717 diff -NurpP --minimal linux-2.6.37/fs/nfs/client.c linux-2.6.37-vs2.3.0.37-rc3/fs/nfs/client.c
5718 --- linux-2.6.37/fs/nfs/client.c        2011-01-05 21:50:24.000000000 +0100
5719 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/nfs/client.c 2010-11-23 02:09:41.000000000 +0100
5720 @@ -747,6 +747,9 @@ static int nfs_init_server_rpcclient(str
5721         if (server->flags & NFS_MOUNT_SOFT)
5722                 server->client->cl_softrtry = 1;
5723  
5724 +       server->client->cl_tag = 0;
5725 +       if (server->flags & NFS_MOUNT_TAGGED)
5726 +               server->client->cl_tag = 1;
5727         return 0;
5728  }
5729  
5730 @@ -920,6 +923,10 @@ static void nfs_server_set_fsinfo(struct
5731                 server->acdirmin = server->acdirmax = 0;
5732         }
5733  
5734 +       /* FIXME: needs fsinfo
5735 +       if (server->flags & NFS_MOUNT_TAGGED)
5736 +               sb->s_flags |= MS_TAGGED;       */
5737 +
5738         server->maxfilesize = fsinfo->maxfilesize;
5739  
5740         server->time_delta = fsinfo->time_delta;
5741 diff -NurpP --minimal linux-2.6.37/fs/nfs/dir.c linux-2.6.37-vs2.3.0.37-rc3/fs/nfs/dir.c
5742 --- linux-2.6.37/fs/nfs/dir.c   2011-01-05 21:50:25.000000000 +0100
5743 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/nfs/dir.c    2011-01-05 22:30:39.000000000 +0100
5744 @@ -35,6 +35,7 @@
5745  #include <linux/sched.h>
5746  #include <linux/vmalloc.h>
5747  #include <linux/kmemleak.h>
5748 +#include <linux/vs_tag.h>
5749  
5750  #include "delegation.h"
5751  #include "iostat.h"
5752 @@ -1221,6 +1222,7 @@ static struct dentry *nfs_lookup(struct 
5753         if (IS_ERR(res))
5754                 goto out_unblock_sillyrename;
5755  
5756 +       dx_propagate_tag(nd, inode);
5757  no_entry:
5758         res = d_materialise_unique(dentry, inode);
5759         if (res != NULL) {
5760 diff -NurpP --minimal linux-2.6.37/fs/nfs/inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/nfs/inode.c
5761 --- linux-2.6.37/fs/nfs/inode.c 2011-01-05 21:50:25.000000000 +0100
5762 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/nfs/inode.c  2011-01-05 22:30:39.000000000 +0100
5763 @@ -37,6 +37,7 @@
5764  #include <linux/inet.h>
5765  #include <linux/nfs_xdr.h>
5766  #include <linux/slab.h>
5767 +#include <linux/vs_tag.h>
5768  
5769  #include <asm/system.h>
5770  #include <asm/uaccess.h>
5771 @@ -265,6 +266,8 @@ nfs_fhget(struct super_block *sb, struct
5772         if (inode->i_state & I_NEW) {
5773                 struct nfs_inode *nfsi = NFS_I(inode);
5774                 unsigned long now = jiffies;
5775 +               uid_t uid;
5776 +               gid_t gid;
5777  
5778                 /* We set i_ino for the few things that still rely on it,
5779                  * such as stat(2) */
5780 @@ -313,8 +316,8 @@ nfs_fhget(struct super_block *sb, struct
5781                 nfsi->change_attr = 0;
5782                 inode->i_size = 0;
5783                 inode->i_nlink = 0;
5784 -               inode->i_uid = -2;
5785 -               inode->i_gid = -2;
5786 +               uid = -2;
5787 +               gid = -2;
5788                 inode->i_blocks = 0;
5789                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5790  
5791 @@ -351,13 +354,13 @@ nfs_fhget(struct super_block *sb, struct
5792                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5793                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5794                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5795 -                       inode->i_uid = fattr->uid;
5796 +                       uid = fattr->uid;
5797                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5798                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5799                                 | NFS_INO_INVALID_ACCESS
5800                                 | NFS_INO_INVALID_ACL;
5801                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5802 -                       inode->i_gid = fattr->gid;
5803 +                       gid = fattr->gid;
5804                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5805                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5806                                 | NFS_INO_INVALID_ACCESS
5807 @@ -370,6 +373,11 @@ nfs_fhget(struct super_block *sb, struct
5808                          */
5809                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5810                 }
5811 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5812 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5813 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5814 +                               /* maybe fattr->xid someday */
5815 +
5816                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5817                 nfsi->attrtimeo_timestamp = now;
5818                 nfsi->access_cache = RB_ROOT;
5819 @@ -486,6 +494,8 @@ void nfs_setattr_update_inode(struct ino
5820                         inode->i_uid = attr->ia_uid;
5821                 if ((attr->ia_valid & ATTR_GID) != 0)
5822                         inode->i_gid = attr->ia_gid;
5823 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5824 +                       inode->i_tag = attr->ia_tag;
5825                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5826                 spin_unlock(&inode->i_lock);
5827         }
5828 @@ -926,6 +936,9 @@ static int nfs_check_inode_attributes(st
5829         struct nfs_inode *nfsi = NFS_I(inode);
5830         loff_t cur_size, new_isize;
5831         unsigned long invalid = 0;
5832 +       uid_t uid;
5833 +       gid_t gid;
5834 +       tag_t tag;
5835  
5836  
5837         /* Has the inode gone and changed behind our back? */
5838 @@ -949,13 +962,18 @@ static int nfs_check_inode_attributes(st
5839                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5840         }
5841  
5842 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5843 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5844 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5845 +
5846         /* Have any file permissions changed? */
5847         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5848                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5849 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5850 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5851                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5852 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5853 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5854                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5855 +               /* maybe check for tag too? */
5856  
5857         /* Has the link count changed? */
5858         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5859 @@ -1190,6 +1208,9 @@ static int nfs_update_inode(struct inode
5860         unsigned long invalid = 0;
5861         unsigned long now = jiffies;
5862         unsigned long save_cache_validity;
5863 +       uid_t uid;
5864 +       gid_t gid;
5865 +       tag_t tag;
5866  
5867         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5868                         __func__, inode->i_sb->s_id, inode->i_ino,
5869 @@ -1292,6 +1313,9 @@ static int nfs_update_inode(struct inode
5870                                 | NFS_INO_REVAL_PAGECACHE
5871                                 | NFS_INO_REVAL_FORCED);
5872  
5873 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5874 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5875 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5876  
5877         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5878                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5879 @@ -1313,9 +1337,9 @@ static int nfs_update_inode(struct inode
5880                                 | NFS_INO_REVAL_FORCED);
5881  
5882         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5883 -               if (inode->i_uid != fattr->uid) {
5884 +               if (uid != fattr->uid) {
5885                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5886 -                       inode->i_uid = fattr->uid;
5887 +                       uid = fattr->uid;
5888                 }
5889         } else if (server->caps & NFS_CAP_OWNER)
5890                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5891 @@ -1324,9 +1348,9 @@ static int nfs_update_inode(struct inode
5892                                 | NFS_INO_REVAL_FORCED);
5893  
5894         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5895 -               if (inode->i_gid != fattr->gid) {
5896 +               if (gid != fattr->gid) {
5897                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5898 -                       inode->i_gid = fattr->gid;
5899 +                       gid = fattr->gid;
5900                 }
5901         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5902                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5903 @@ -1334,6 +1358,10 @@ static int nfs_update_inode(struct inode
5904                                 | NFS_INO_INVALID_ACL
5905                                 | NFS_INO_REVAL_FORCED);
5906  
5907 +       inode->i_uid = uid;
5908 +       inode->i_gid = gid;
5909 +       inode->i_tag = tag;
5910 +
5911         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5912                 if (inode->i_nlink != fattr->nlink) {
5913                         invalid |= NFS_INO_INVALID_ATTR;
5914 diff -NurpP --minimal linux-2.6.37/fs/nfs/nfs3xdr.c linux-2.6.37-vs2.3.0.37-rc3/fs/nfs/nfs3xdr.c
5915 --- linux-2.6.37/fs/nfs/nfs3xdr.c       2011-01-05 21:50:25.000000000 +0100
5916 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/nfs/nfs3xdr.c        2011-01-05 22:30:39.000000000 +0100
5917 @@ -20,6 +20,7 @@
5918  #include <linux/nfs3.h>
5919  #include <linux/nfs_fs.h>
5920  #include <linux/nfsacl.h>
5921 +#include <linux/vs_tag.h>
5922  #include "internal.h"
5923  
5924  #define NFSDBG_FACILITY                NFSDBG_XDR
5925 @@ -205,7 +206,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5926  }
5927  
5928  static inline __be32 *
5929 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5930 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5931  {
5932         if (attr->ia_valid & ATTR_MODE) {
5933                 *p++ = xdr_one;
5934 @@ -213,15 +214,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5935         } else {
5936                 *p++ = xdr_zero;
5937         }
5938 -       if (attr->ia_valid & ATTR_UID) {
5939 +       if (attr->ia_valid & ATTR_UID ||
5940 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5941                 *p++ = xdr_one;
5942 -               *p++ = htonl(attr->ia_uid);
5943 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5944         } else {
5945                 *p++ = xdr_zero;
5946         }
5947 -       if (attr->ia_valid & ATTR_GID) {
5948 +       if (attr->ia_valid & ATTR_GID ||
5949 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5950                 *p++ = xdr_one;
5951 -               *p++ = htonl(attr->ia_gid);
5952 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5953         } else {
5954                 *p++ = xdr_zero;
5955         }
5956 @@ -328,7 +331,8 @@ static int
5957  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5958  {
5959         p = xdr_encode_fhandle(p, args->fh);
5960 -       p = xdr_encode_sattr(p, args->sattr);
5961 +       p = xdr_encode_sattr(p, args->sattr,
5962 +               req->rq_task->tk_client->cl_tag);
5963         *p++ = htonl(args->guard);
5964         if (args->guard)
5965                 p = xdr_encode_time3(p, &args->guardtime);
5966 @@ -433,7 +437,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5967                 *p++ = args->verifier[0];
5968                 *p++ = args->verifier[1];
5969         } else
5970 -               p = xdr_encode_sattr(p, args->sattr);
5971 +               p = xdr_encode_sattr(p, args->sattr,
5972 +                       req->rq_task->tk_client->cl_tag);
5973  
5974         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5975         return 0;
5976 @@ -447,7 +452,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5977  {
5978         p = xdr_encode_fhandle(p, args->fh);
5979         p = xdr_encode_array(p, args->name, args->len);
5980 -       p = xdr_encode_sattr(p, args->sattr);
5981 +       p = xdr_encode_sattr(p, args->sattr,
5982 +               req->rq_task->tk_client->cl_tag);
5983         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5984         return 0;
5985  }
5986 @@ -460,7 +466,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5987  {
5988         p = xdr_encode_fhandle(p, args->fromfh);
5989         p = xdr_encode_array(p, args->fromname, args->fromlen);
5990 -       p = xdr_encode_sattr(p, args->sattr);
5991 +       p = xdr_encode_sattr(p, args->sattr,
5992 +               req->rq_task->tk_client->cl_tag);
5993         *p++ = htonl(args->pathlen);
5994         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5995  
5996 @@ -478,7 +485,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5997         p = xdr_encode_fhandle(p, args->fh);
5998         p = xdr_encode_array(p, args->name, args->len);
5999         *p++ = htonl(args->type);
6000 -       p = xdr_encode_sattr(p, args->sattr);
6001 +       p = xdr_encode_sattr(p, args->sattr,
6002 +               req->rq_task->tk_client->cl_tag);
6003         if (args->type == NF3CHR || args->type == NF3BLK) {
6004                 *p++ = htonl(MAJOR(args->rdev));
6005                 *p++ = htonl(MINOR(args->rdev));
6006 diff -NurpP --minimal linux-2.6.37/fs/nfs/super.c linux-2.6.37-vs2.3.0.37-rc3/fs/nfs/super.c
6007 --- linux-2.6.37/fs/nfs/super.c 2011-01-05 21:50:25.000000000 +0100
6008 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/nfs/super.c  2011-01-05 23:44:00.000000000 +0100
6009 @@ -53,6 +53,7 @@
6010  #include <linux/nfs_xdr.h>
6011  #include <linux/magic.h>
6012  #include <linux/parser.h>
6013 +#include <linux/vs_tag.h>
6014  
6015  #include <asm/system.h>
6016  #include <asm/uaccess.h>
6017 @@ -86,6 +87,7 @@ enum {
6018         Opt_sharecache, Opt_nosharecache,
6019         Opt_resvport, Opt_noresvport,
6020         Opt_fscache, Opt_nofscache,
6021 +       Opt_tag, Opt_notag,
6022  
6023         /* Mount options that take integer arguments */
6024         Opt_port,
6025 @@ -99,6 +101,7 @@ enum {
6026         Opt_mountvers,
6027         Opt_nfsvers,
6028         Opt_minorversion,
6029 +       Opt_tagid,
6030  
6031         /* Mount options that take string arguments */
6032         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
6033 @@ -179,6 +182,10 @@ static const match_table_t nfs_mount_opt
6034         { Opt_fscache_uniq, "fsc=%s" },
6035         { Opt_local_lock, "local_lock=%s" },
6036  
6037 +       { Opt_tag, "tag" },
6038 +       { Opt_notag, "notag" },
6039 +       { Opt_tagid, "tagid=%u" },
6040 +
6041         { Opt_err, NULL }
6042  };
6043  
6044 @@ -640,6 +647,7 @@ static void nfs_show_mount_options(struc
6045                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6046                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
6047                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
6048 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6049                 { 0, NULL, NULL }
6050         };
6051         const struct proc_nfs_info *nfs_infop;
6052 @@ -1120,6 +1128,14 @@ static int nfs_parse_mount_options(char 
6053                         kfree(mnt->fscache_uniq);
6054                         mnt->fscache_uniq = NULL;
6055                         break;
6056 +#ifndef CONFIG_TAGGING_NONE
6057 +               case Opt_tag:
6058 +                       mnt->flags |= NFS_MOUNT_TAGGED;
6059 +                       break;
6060 +               case Opt_notag:
6061 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
6062 +                       break;
6063 +#endif
6064  
6065                 /*
6066                  * options that take numeric values
6067 @@ -1304,6 +1320,12 @@ static int nfs_parse_mount_options(char 
6068                                 goto out_invalid_value;
6069                         mnt->minorversion = option;
6070                         break;
6071 +#ifdef CONFIG_PROPAGATE
6072 +               case Opt_tagid:
6073 +                       /* use args[0] */
6074 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
6075 +                       break;
6076 +#endif
6077  
6078                 /*
6079                  * options that take text values
6080 diff -NurpP --minimal linux-2.6.37/fs/nfsd/auth.c linux-2.6.37-vs2.3.0.37-rc3/fs/nfsd/auth.c
6081 --- linux-2.6.37/fs/nfsd/auth.c 2010-02-25 11:52:05.000000000 +0100
6082 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/nfsd/auth.c  2010-11-23 02:09:41.000000000 +0100
6083 @@ -1,6 +1,7 @@
6084  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
6085  
6086  #include <linux/sched.h>
6087 +#include <linux/vs_tag.h>
6088  #include "nfsd.h"
6089  #include "auth.h"
6090  
6091 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6092  
6093         new->fsuid = rqstp->rq_cred.cr_uid;
6094         new->fsgid = rqstp->rq_cred.cr_gid;
6095 +       /* FIXME: this desperately needs a tag :)
6096 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6097 +                       */
6098  
6099         rqgi = rqstp->rq_cred.cr_group_info;
6100  
6101 diff -NurpP --minimal linux-2.6.37/fs/nfsd/nfs3xdr.c linux-2.6.37-vs2.3.0.37-rc3/fs/nfsd/nfs3xdr.c
6102 --- linux-2.6.37/fs/nfsd/nfs3xdr.c      2011-01-05 21:50:25.000000000 +0100
6103 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/nfsd/nfs3xdr.c       2011-01-05 22:30:39.000000000 +0100
6104 @@ -7,6 +7,7 @@
6105   */
6106  
6107  #include <linux/namei.h>
6108 +#include <linux/vs_tag.h>
6109  #include "xdr3.h"
6110  #include "auth.h"
6111  
6112 @@ -95,6 +96,8 @@ static __be32 *
6113  decode_sattr3(__be32 *p, struct iattr *iap)
6114  {
6115         u32     tmp;
6116 +       uid_t   uid = 0;
6117 +       gid_t   gid = 0;
6118  
6119         iap->ia_valid = 0;
6120  
6121 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6122         }
6123         if (*p++) {
6124                 iap->ia_valid |= ATTR_UID;
6125 -               iap->ia_uid = ntohl(*p++);
6126 +               uid = ntohl(*p++);
6127         }
6128         if (*p++) {
6129                 iap->ia_valid |= ATTR_GID;
6130 -               iap->ia_gid = ntohl(*p++);
6131 +               gid = ntohl(*p++);
6132         }
6133 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6134 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6135 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6136         if (*p++) {
6137                 u64     newsize;
6138  
6139 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6140         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6141         *p++ = htonl((u32) stat->mode);
6142         *p++ = htonl((u32) stat->nlink);
6143 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6144 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6145 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6146 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6147 +               stat->uid, stat->tag)));
6148 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6149 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6150 +               stat->gid, stat->tag)));
6151         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6152                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6153         } else {
6154 diff -NurpP --minimal linux-2.6.37/fs/nfsd/nfs4xdr.c linux-2.6.37-vs2.3.0.37-rc3/fs/nfsd/nfs4xdr.c
6155 --- linux-2.6.37/fs/nfsd/nfs4xdr.c      2011-01-05 21:50:25.000000000 +0100
6156 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/nfsd/nfs4xdr.c       2010-11-23 02:09:41.000000000 +0100
6157 @@ -47,6 +47,7 @@
6158  #include <linux/nfsd_idmap.h>
6159  #include <linux/nfs4_acl.h>
6160  #include <linux/sunrpc/svcauth_gss.h>
6161 +#include <linux/vs_tag.h>
6162  
6163  #include "xdr4.h"
6164  #include "vfs.h"
6165 @@ -2063,14 +2064,18 @@ out_acl:
6166                 WRITE32(stat.nlink);
6167         }
6168         if (bmval1 & FATTR4_WORD1_OWNER) {
6169 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6170 +               status = nfsd4_encode_user(rqstp,
6171 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6172 +                       stat.uid, stat.tag), &p, &buflen);
6173                 if (status == nfserr_resource)
6174                         goto out_resource;
6175                 if (status)
6176                         goto out;
6177         }
6178         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6179 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6180 +               status = nfsd4_encode_group(rqstp,
6181 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6182 +                       stat.gid, stat.tag), &p, &buflen);
6183                 if (status == nfserr_resource)
6184                         goto out_resource;
6185                 if (status)
6186 diff -NurpP --minimal linux-2.6.37/fs/nfsd/nfsxdr.c linux-2.6.37-vs2.3.0.37-rc3/fs/nfsd/nfsxdr.c
6187 --- linux-2.6.37/fs/nfsd/nfsxdr.c       2010-02-25 11:52:05.000000000 +0100
6188 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/nfsd/nfsxdr.c        2010-11-23 02:09:41.000000000 +0100
6189 @@ -6,6 +6,7 @@
6190  
6191  #include "xdr.h"
6192  #include "auth.h"
6193 +#include <linux/vs_tag.h>
6194  
6195  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6196  
6197 @@ -88,6 +89,8 @@ static __be32 *
6198  decode_sattr(__be32 *p, struct iattr *iap)
6199  {
6200         u32     tmp, tmp1;
6201 +       uid_t   uid = 0;
6202 +       gid_t   gid = 0;
6203  
6204         iap->ia_valid = 0;
6205  
6206 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6207         }
6208         if ((tmp = ntohl(*p++)) != (u32)-1) {
6209                 iap->ia_valid |= ATTR_UID;
6210 -               iap->ia_uid = tmp;
6211 +               uid = tmp;
6212         }
6213         if ((tmp = ntohl(*p++)) != (u32)-1) {
6214                 iap->ia_valid |= ATTR_GID;
6215 -               iap->ia_gid = tmp;
6216 +               gid = tmp;
6217         }
6218 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6219 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6220 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6221         if ((tmp = ntohl(*p++)) != (u32)-1) {
6222                 iap->ia_valid |= ATTR_SIZE;
6223                 iap->ia_size = tmp;
6224 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6225         *p++ = htonl(nfs_ftypes[type >> 12]);
6226         *p++ = htonl((u32) stat->mode);
6227         *p++ = htonl((u32) stat->nlink);
6228 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6229 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6230 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6231 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6232 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6233 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6234  
6235         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6236                 *p++ = htonl(NFS_MAXPATHLEN);
6237 diff -NurpP --minimal linux-2.6.37/fs/ocfs2/dlmglue.c linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/dlmglue.c
6238 --- linux-2.6.37/fs/ocfs2/dlmglue.c     2011-01-05 21:50:26.000000000 +0100
6239 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/dlmglue.c      2010-11-23 02:09:41.000000000 +0100
6240 @@ -2114,6 +2114,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6241         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6242         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6243         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6244 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6245         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6246         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6247         lvb->lvb_iatime_packed  =
6248 @@ -2168,6 +2169,7 @@ static void ocfs2_refresh_inode_from_lvb
6249  
6250         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6251         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6252 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6253         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6254         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6255         ocfs2_unpack_timespec(&inode->i_atime,
6256 diff -NurpP --minimal linux-2.6.37/fs/ocfs2/dlmglue.h linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/dlmglue.h
6257 --- linux-2.6.37/fs/ocfs2/dlmglue.h     2010-10-21 13:07:50.000000000 +0200
6258 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/dlmglue.h      2010-11-23 02:09:41.000000000 +0100
6259 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6260         __be16       lvb_inlink;
6261         __be32       lvb_iattr;
6262         __be32       lvb_igeneration;
6263 -       __be32       lvb_reserved2;
6264 +       __be16       lvb_itag;
6265 +       __be16       lvb_reserved2;
6266  };
6267  
6268  #define OCFS2_QINFO_LVB_VERSION 1
6269 diff -NurpP --minimal linux-2.6.37/fs/ocfs2/file.c linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/file.c
6270 --- linux-2.6.37/fs/ocfs2/file.c        2011-01-05 21:50:26.000000000 +0100
6271 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/file.c 2011-01-05 22:30:39.000000000 +0100
6272 @@ -1126,13 +1126,15 @@ int ocfs2_setattr(struct dentry *dentry,
6273                 mlog(0, "uid change: %d\n", attr->ia_uid);
6274         if (attr->ia_valid & ATTR_GID)
6275                 mlog(0, "gid change: %d\n", attr->ia_gid);
6276 +       if (attr->ia_valid & ATTR_TAG)
6277 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6278         if (attr->ia_valid & ATTR_SIZE)
6279                 mlog(0, "size change...\n");
6280         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6281                 mlog(0, "time change...\n");
6282  
6283  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6284 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6285 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6286         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6287                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6288                 return 0;
6289 diff -NurpP --minimal linux-2.6.37/fs/ocfs2/inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/inode.c
6290 --- linux-2.6.37/fs/ocfs2/inode.c       2011-01-05 21:50:26.000000000 +0100
6291 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/inode.c        2010-11-23 02:09:41.000000000 +0100
6292 @@ -28,6 +28,7 @@
6293  #include <linux/highmem.h>
6294  #include <linux/pagemap.h>
6295  #include <linux/quotaops.h>
6296 +#include <linux/vs_tag.h>
6297  
6298  #include <asm/byteorder.h>
6299  
6300 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6301  {
6302         unsigned int flags = OCFS2_I(inode)->ip_attr;
6303  
6304 -       inode->i_flags &= ~(S_IMMUTABLE |
6305 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6306                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6307  
6308         if (flags & OCFS2_IMMUTABLE_FL)
6309                 inode->i_flags |= S_IMMUTABLE;
6310 +       if (flags & OCFS2_IXUNLINK_FL)
6311 +               inode->i_flags |= S_IXUNLINK;
6312  
6313         if (flags & OCFS2_SYNC_FL)
6314                 inode->i_flags |= S_SYNC;
6315 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
6316                 inode->i_flags |= S_NOATIME;
6317         if (flags & OCFS2_DIRSYNC_FL)
6318                 inode->i_flags |= S_DIRSYNC;
6319 +
6320 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6321 +
6322 +       if (flags & OCFS2_BARRIER_FL)
6323 +               inode->i_vflags |= V_BARRIER;
6324 +       if (flags & OCFS2_COW_FL)
6325 +               inode->i_vflags |= V_COW;
6326  }
6327  
6328  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6329  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6330  {
6331         unsigned int flags = oi->vfs_inode.i_flags;
6332 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6333 +
6334 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6335 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6336 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6337 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6338 +
6339 +       if (flags & S_IMMUTABLE)
6340 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6341 +       if (flags & S_IXUNLINK)
6342 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6343  
6344 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6345 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6346         if (flags & S_SYNC)
6347                 oi->ip_attr |= OCFS2_SYNC_FL;
6348         if (flags & S_APPEND)
6349                 oi->ip_attr |= OCFS2_APPEND_FL;
6350 -       if (flags & S_IMMUTABLE)
6351 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6352         if (flags & S_NOATIME)
6353                 oi->ip_attr |= OCFS2_NOATIME_FL;
6354         if (flags & S_DIRSYNC)
6355                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6356 +
6357 +       if (vflags & V_BARRIER)
6358 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6359 +       if (vflags & V_COW)
6360 +               oi->ip_attr |= OCFS2_COW_FL;
6361  }
6362  
6363  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6364 @@ -245,6 +267,8 @@ void ocfs2_populate_inode(struct inode *
6365         struct super_block *sb;
6366         struct ocfs2_super *osb;
6367         int use_plocks = 1;
6368 +       uid_t uid;
6369 +       gid_t gid;
6370  
6371         mlog_entry("(0x%p, size:%llu)\n", inode,
6372                    (unsigned long long)le64_to_cpu(fe->i_size));
6373 @@ -276,8 +300,12 @@ void ocfs2_populate_inode(struct inode *
6374         inode->i_generation = le32_to_cpu(fe->i_generation);
6375         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6376         inode->i_mode = le16_to_cpu(fe->i_mode);
6377 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6378 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6379 +       uid = le32_to_cpu(fe->i_uid);
6380 +       gid = le32_to_cpu(fe->i_gid);
6381 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6382 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6383 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6384 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6385  
6386         /* Fast symlinks will have i_size but no allocated clusters. */
6387         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6388 diff -NurpP --minimal linux-2.6.37/fs/ocfs2/inode.h linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/inode.h
6389 --- linux-2.6.37/fs/ocfs2/inode.h       2011-01-05 21:50:26.000000000 +0100
6390 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/inode.h        2010-11-23 02:09:41.000000000 +0100
6391 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
6392  
6393  void ocfs2_set_inode_flags(struct inode *inode);
6394  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6395 +int ocfs2_sync_flags(struct inode *inode, int, int);
6396  
6397  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6398  {
6399 diff -NurpP --minimal linux-2.6.37/fs/ocfs2/ioctl.c linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/ioctl.c
6400 --- linux-2.6.37/fs/ocfs2/ioctl.c       2011-01-05 21:50:26.000000000 +0100
6401 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/ioctl.c        2010-11-23 02:09:41.000000000 +0100
6402 @@ -63,7 +63,41 @@ static int ocfs2_get_inode_attr(struct i
6403         return status;
6404  }
6405  
6406 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6407 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6408 +{
6409 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6410 +       struct buffer_head *bh = NULL;
6411 +       handle_t *handle = NULL;
6412 +       int status;
6413 +
6414 +       status = ocfs2_inode_lock(inode, &bh, 1);
6415 +       if (status < 0) {
6416 +               mlog_errno(status);
6417 +               return status;
6418 +       }
6419 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6420 +       if (IS_ERR(handle)) {
6421 +               status = PTR_ERR(handle);
6422 +               mlog_errno(status);
6423 +               goto bail_unlock;
6424 +       }
6425 +
6426 +       inode->i_flags = flags;
6427 +       inode->i_vflags = vflags;
6428 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6429 +
6430 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6431 +       if (status < 0)
6432 +               mlog_errno(status);
6433 +
6434 +       ocfs2_commit_trans(osb, handle);
6435 +bail_unlock:
6436 +       ocfs2_inode_unlock(inode, 1);
6437 +       brelse(bh);
6438 +       return status;
6439 +}
6440 +
6441 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6442                                 unsigned mask)
6443  {
6444         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6445 @@ -88,6 +122,11 @@ static int ocfs2_set_inode_attr(struct i
6446         if (!S_ISDIR(inode->i_mode))
6447                 flags &= ~OCFS2_DIRSYNC_FL;
6448  
6449 +       if (IS_BARRIER(inode)) {
6450 +               vxwprintk_task(1, "messing with the barrier.");
6451 +               goto bail_unlock;
6452 +       }
6453 +
6454         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6455         if (IS_ERR(handle)) {
6456                 status = PTR_ERR(handle);
6457 @@ -451,6 +490,7 @@ bail:
6458         return status;
6459  }
6460  
6461 +
6462  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6463  {
6464         struct inode *inode = filp->f_path.dentry->d_inode;
6465 diff -NurpP --minimal linux-2.6.37/fs/ocfs2/namei.c linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/namei.c
6466 --- linux-2.6.37/fs/ocfs2/namei.c       2011-01-05 21:50:26.000000000 +0100
6467 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/namei.c        2010-11-23 02:09:41.000000000 +0100
6468 @@ -41,6 +41,7 @@
6469  #include <linux/slab.h>
6470  #include <linux/highmem.h>
6471  #include <linux/quotaops.h>
6472 +#include <linux/vs_tag.h>
6473  
6474  #define MLOG_MASK_PREFIX ML_NAMEI
6475  #include <cluster/masklog.h>
6476 @@ -487,6 +488,7 @@ static int __ocfs2_mknod_locked(struct i
6477         struct ocfs2_dinode *fe = NULL;
6478         struct ocfs2_extent_list *fel;
6479         u16 feat;
6480 +       tag_t tag;
6481  
6482         *new_fe_bh = NULL;
6483  
6484 @@ -524,8 +526,11 @@ static int __ocfs2_mknod_locked(struct i
6485         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6486         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6487         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6488 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6489 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6490 +
6491 +       tag = dx_current_fstag(osb->sb);
6492 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6493 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6494 +       inode->i_tag = tag;
6495         fe->i_mode = cpu_to_le16(inode->i_mode);
6496         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6497                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6498 diff -NurpP --minimal linux-2.6.37/fs/ocfs2/ocfs2_fs.h linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/ocfs2_fs.h
6499 --- linux-2.6.37/fs/ocfs2/ocfs2_fs.h    2011-01-05 21:50:26.000000000 +0100
6500 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/ocfs2_fs.h     2011-01-05 22:30:39.000000000 +0100
6501 @@ -266,6 +266,11 @@
6502  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6503  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6504  
6505 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6506 +
6507 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6508 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6509 +
6510  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6511  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6512  
6513 diff -NurpP --minimal linux-2.6.37/fs/ocfs2/ocfs2.h linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/ocfs2.h
6514 --- linux-2.6.37/fs/ocfs2/ocfs2.h       2011-01-05 21:50:26.000000000 +0100
6515 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/ocfs2.h        2011-01-05 22:30:39.000000000 +0100
6516 @@ -267,6 +267,7 @@ enum ocfs2_mount_options
6517                                                      writes */
6518         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6519         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6520 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6521  };
6522  
6523  #define OCFS2_OSB_SOFT_RO                      0x0001
6524 diff -NurpP --minimal linux-2.6.37/fs/ocfs2/super.c linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/super.c
6525 --- linux-2.6.37/fs/ocfs2/super.c       2011-01-05 21:50:26.000000000 +0100
6526 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/ocfs2/super.c        2010-11-23 03:14:32.000000000 +0100
6527 @@ -181,6 +181,7 @@ enum {
6528         Opt_coherency_full,
6529         Opt_resv_level,
6530         Opt_dir_resv_level,
6531 +       Opt_tag, Opt_notag, Opt_tagid,
6532         Opt_err,
6533  };
6534  
6535 @@ -212,6 +213,9 @@ static const match_table_t tokens = {
6536         {Opt_coherency_full, "coherency=full"},
6537         {Opt_resv_level, "resv_level=%u"},
6538         {Opt_dir_resv_level, "dir_resv_level=%u"},
6539 +       {Opt_tag, "tag"},
6540 +       {Opt_notag, "notag"},
6541 +       {Opt_tagid, "tagid=%u"},
6542         {Opt_err, NULL}
6543  };
6544  
6545 @@ -659,6 +663,13 @@ static int ocfs2_remount(struct super_bl
6546                 goto out;
6547         }
6548  
6549 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6550 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6551 +               ret = -EINVAL;
6552 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6553 +               goto out;
6554 +       }
6555 +
6556         /* We're going to/from readonly mode. */
6557         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6558                 /* Disable quota accounting before remounting RO */
6559 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
6560  
6561         ocfs2_complete_mount_recovery(osb);
6562  
6563 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6564 +               sb->s_flags |= MS_TAGGED;
6565 +
6566         if (ocfs2_mount_local(osb))
6567                 snprintf(nodestr, sizeof(nodestr), "local");
6568         else
6569 @@ -1499,6 +1513,20 @@ static int ocfs2_parse_options(struct su
6570                             option < OCFS2_MAX_RESV_LEVEL)
6571                                 mopt->dir_resv_level = option;
6572                         break;
6573 +#ifndef CONFIG_TAGGING_NONE
6574 +               case Opt_tag:
6575 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6576 +                       break;
6577 +               case Opt_notag:
6578 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6579 +                       break;
6580 +#endif
6581 +#ifdef CONFIG_PROPAGATE
6582 +               case Opt_tagid:
6583 +                       /* use args[0] */
6584 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6585 +                       break;
6586 +#endif
6587                 default:
6588                         mlog(ML_ERROR,
6589                              "Unrecognized mount option \"%s\" "
6590 diff -NurpP --minimal linux-2.6.37/fs/open.c linux-2.6.37-vs2.3.0.37-rc3/fs/open.c
6591 --- linux-2.6.37/fs/open.c      2011-01-05 21:50:26.000000000 +0100
6592 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/open.c       2010-11-23 02:09:41.000000000 +0100
6593 @@ -30,6 +30,11 @@
6594  #include <linux/fs_struct.h>
6595  #include <linux/ima.h>
6596  #include <linux/dnotify.h>
6597 +#include <linux/vs_base.h>
6598 +#include <linux/vs_limit.h>
6599 +#include <linux/vs_tag.h>
6600 +#include <linux/vs_cowbl.h>
6601 +#include <linux/vserver/dlimit.h>
6602  
6603  #include "internal.h"
6604  
6605 @@ -481,6 +486,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6606         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6607         if (error)
6608                 goto out;
6609 +
6610 +#ifdef CONFIG_VSERVER_COWBL
6611 +       error = cow_check_and_break(&path);
6612 +       if (error)
6613 +               goto dput_and_out;
6614 +#endif
6615         inode = path.dentry->d_inode;
6616  
6617         error = mnt_want_write(path.mnt);
6618 @@ -518,11 +529,11 @@ static int chown_common(struct path *pat
6619         newattrs.ia_valid =  ATTR_CTIME;
6620         if (user != (uid_t) -1) {
6621                 newattrs.ia_valid |= ATTR_UID;
6622 -               newattrs.ia_uid = user;
6623 +               newattrs.ia_uid = dx_map_uid(user);
6624         }
6625         if (group != (gid_t) -1) {
6626                 newattrs.ia_valid |= ATTR_GID;
6627 -               newattrs.ia_gid = group;
6628 +               newattrs.ia_gid = dx_map_gid(group);
6629         }
6630         if (!S_ISDIR(inode->i_mode))
6631                 newattrs.ia_valid |=
6632 @@ -547,6 +558,10 @@ SYSCALL_DEFINE3(chown, const char __user
6633         error = mnt_want_write(path.mnt);
6634         if (error)
6635                 goto out_release;
6636 +#ifdef CONFIG_VSERVER_COWBL
6637 +       error = cow_check_and_break(&path);
6638 +       if (!error)
6639 +#endif
6640         error = chown_common(&path, user, group);
6641         mnt_drop_write(path.mnt);
6642  out_release:
6643 @@ -572,6 +587,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6644         error = mnt_want_write(path.mnt);
6645         if (error)
6646                 goto out_release;
6647 +#ifdef CONFIG_VSERVER_COWBL
6648 +       error = cow_check_and_break(&path);
6649 +       if (!error)
6650 +#endif
6651         error = chown_common(&path, user, group);
6652         mnt_drop_write(path.mnt);
6653  out_release:
6654 @@ -591,6 +610,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6655         error = mnt_want_write(path.mnt);
6656         if (error)
6657                 goto out_release;
6658 +#ifdef CONFIG_VSERVER_COWBL
6659 +       error = cow_check_and_break(&path);
6660 +       if (!error)
6661 +#endif
6662         error = chown_common(&path, user, group);
6663         mnt_drop_write(path.mnt);
6664  out_release:
6665 @@ -837,6 +860,7 @@ static void __put_unused_fd(struct files
6666         __FD_CLR(fd, fdt->open_fds);
6667         if (fd < files->next_fd)
6668                 files->next_fd = fd;
6669 +       vx_openfd_dec(fd);
6670  }
6671  
6672  void put_unused_fd(unsigned int fd)
6673 diff -NurpP --minimal linux-2.6.37/fs/proc/array.c linux-2.6.37-vs2.3.0.37-rc3/fs/proc/array.c
6674 --- linux-2.6.37/fs/proc/array.c        2010-08-02 16:52:51.000000000 +0200
6675 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/proc/array.c 2010-11-23 02:09:41.000000000 +0100
6676 @@ -81,6 +81,8 @@
6677  #include <linux/pid_namespace.h>
6678  #include <linux/ptrace.h>
6679  #include <linux/tracehook.h>
6680 +#include <linux/vs_context.h>
6681 +#include <linux/vs_network.h>
6682  
6683  #include <asm/pgtable.h>
6684  #include <asm/processor.h>
6685 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6686         rcu_read_lock();
6687         ppid = pid_alive(p) ?
6688                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6689 +       if (unlikely(vx_current_initpid(p->pid)))
6690 +               ppid = 0;
6691 +
6692         tpid = 0;
6693         if (pid_alive(p)) {
6694                 struct task_struct *tracer = tracehook_tracer_task(p);
6695 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6696  }
6697  
6698  static void render_cap_t(struct seq_file *m, const char *header,
6699 -                       kernel_cap_t *a)
6700 +                       struct vx_info *vxi, kernel_cap_t *a)
6701  {
6702         unsigned __capi;
6703  
6704 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6705         cap_bset        = cred->cap_bset;
6706         rcu_read_unlock();
6707  
6708 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6709 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6710 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6711 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6712 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6713 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6714 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6715 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6716 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6717  }
6718  
6719  static inline void task_context_switch_counts(struct seq_file *m,
6720 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6721         seq_printf(m, "\n");
6722  }
6723  
6724 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6725 +                       struct pid *pid, struct task_struct *task)
6726 +{
6727 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6728 +                       "Count:\t%u\n"
6729 +                       "uts:\t%p(%c)\n"
6730 +                       "ipc:\t%p(%c)\n"
6731 +                       "mnt:\t%p(%c)\n"
6732 +                       "pid:\t%p(%c)\n"
6733 +                       "net:\t%p(%c)\n",
6734 +                       task->nsproxy,
6735 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6736 +                       atomic_read(&task->nsproxy->count),
6737 +                       task->nsproxy->uts_ns,
6738 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6739 +                       task->nsproxy->ipc_ns,
6740 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6741 +                       task->nsproxy->mnt_ns,
6742 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6743 +                       task->nsproxy->pid_ns,
6744 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6745 +                       task->nsproxy->net_ns,
6746 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6747 +       return 0;
6748 +}
6749 +
6750 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6751 +{
6752 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6753 +               return;
6754 +
6755 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6756 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6757 +}
6758 +
6759 +
6760  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6761                         struct pid *pid, struct task_struct *task)
6762  {
6763 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6764         task_cap(m, task);
6765         task_cpus_allowed(m, task);
6766         cpuset_task_status_allowed(m, task);
6767 +       task_vs_id(m, task);
6768  #if defined(CONFIG_S390)
6769         task_show_regs(m, task);
6770  #endif
6771 @@ -465,6 +508,17 @@ static int do_task_stat(struct seq_file 
6772         /* convert nsec -> ticks */
6773         start_time = nsec_to_clock_t(start_time);
6774  
6775 +       /* fixup start time for virt uptime */
6776 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6777 +               unsigned long long bias =
6778 +                       current->vx_info->cvirt.bias_clock;
6779 +
6780 +               if (start_time > bias)
6781 +                       start_time -= bias;
6782 +               else
6783 +                       start_time = 0;
6784 +       }
6785 +
6786         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6787  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6788  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6789 diff -NurpP --minimal linux-2.6.37/fs/proc/base.c linux-2.6.37-vs2.3.0.37-rc3/fs/proc/base.c
6790 --- linux-2.6.37/fs/proc/base.c 2011-01-05 21:50:26.000000000 +0100
6791 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/proc/base.c  2011-01-05 22:30:39.000000000 +0100
6792 @@ -83,6 +83,8 @@
6793  #include <linux/pid_namespace.h>
6794  #include <linux/fs_struct.h>
6795  #include <linux/slab.h>
6796 +#include <linux/vs_context.h>
6797 +#include <linux/vs_network.h>
6798  #include "internal.h"
6799  
6800  /* NOTE:
6801 @@ -1056,11 +1058,16 @@ static ssize_t oom_adjust_write(struct f
6802                 goto err_task_lock;
6803         }
6804  
6805 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6806 +       if (oom_adjust < task->signal->oom_adj &&
6807 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6808                 err = -EACCES;
6809                 goto err_sighand;
6810         }
6811  
6812 +       /* prevent guest processes from circumventing the oom killer */
6813 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6814 +               oom_adjust = OOM_ADJUST_MIN;
6815 +
6816         if (oom_adjust != task->signal->oom_adj) {
6817                 if (oom_adjust == OOM_DISABLE)
6818                         atomic_inc(&task->mm->oom_disable_count);
6819 @@ -1227,7 +1234,7 @@ static ssize_t proc_loginuid_write(struc
6820         ssize_t length;
6821         uid_t loginuid;
6822  
6823 -       if (!capable(CAP_AUDIT_CONTROL))
6824 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6825                 return -EPERM;
6826  
6827         rcu_read_lock();
6828 @@ -1666,6 +1673,8 @@ static struct inode *proc_pid_make_inode
6829                 inode->i_gid = cred->egid;
6830                 rcu_read_unlock();
6831         }
6832 +       /* procfs is xid tagged */
6833 +       inode->i_tag = (tag_t)vx_task_xid(task);
6834         security_task_to_inode(task, inode);
6835  
6836  out:
6837 @@ -2219,6 +2228,13 @@ static struct dentry *proc_pident_lookup
6838         if (!task)
6839                 goto out_no_task;
6840  
6841 +       /* TODO: maybe we can come up with a generic approach? */
6842 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6843 +               (dentry->d_name.len == 5) &&
6844 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6845 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6846 +               goto out;
6847 +
6848         /*
6849          * Yes, it does not scale. And it should not. Don't add
6850          * new entries into /proc/<tgid>/ without very good reasons.
6851 @@ -2628,7 +2644,7 @@ out_iput:
6852  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6853  {
6854         struct dentry *error;
6855 -       struct task_struct *task = get_proc_task(dir);
6856 +       struct task_struct *task = get_proc_task_real(dir);
6857         const struct pid_entry *p, *last;
6858  
6859         error = ERR_PTR(-ENOENT);
6860 @@ -2718,6 +2734,9 @@ static int proc_pid_personality(struct s
6861  static const struct file_operations proc_task_operations;
6862  static const struct inode_operations proc_task_inode_operations;
6863  
6864 +extern int proc_pid_vx_info(struct task_struct *, char *);
6865 +extern int proc_pid_nx_info(struct task_struct *, char *);
6866 +
6867  static const struct pid_entry tgid_base_stuff[] = {
6868         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6869         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6870 @@ -2777,6 +2796,8 @@ static const struct pid_entry tgid_base_
6871  #ifdef CONFIG_CGROUPS
6872         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6873  #endif
6874 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6875 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6876         INF("oom_score",  S_IRUGO, proc_oom_score),
6877         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6878         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6879 @@ -2793,6 +2814,7 @@ static const struct pid_entry tgid_base_
6880  #ifdef CONFIG_TASK_IO_ACCOUNTING
6881         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6882  #endif
6883 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6884  };
6885  
6886  static int proc_tgid_base_readdir(struct file * filp,
6887 @@ -2985,7 +3007,7 @@ retry:
6888         iter.task = NULL;
6889         pid = find_ge_pid(iter.tgid, ns);
6890         if (pid) {
6891 -               iter.tgid = pid_nr_ns(pid, ns);
6892 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6893                 iter.task = pid_task(pid, PIDTYPE_PID);
6894                 /* What we to know is if the pid we have find is the
6895                  * pid of a thread_group_leader.  Testing for task
6896 @@ -3015,7 +3037,7 @@ static int proc_pid_fill_cache(struct fi
6897         struct tgid_iter iter)
6898  {
6899         char name[PROC_NUMBUF];
6900 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6901 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6902         return proc_fill_cache(filp, dirent, filldir, name, len,
6903                                 proc_pid_instantiate, iter.task, NULL);
6904  }
6905 @@ -3024,7 +3046,7 @@ static int proc_pid_fill_cache(struct fi
6906  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6907  {
6908         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6909 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6910 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6911         struct tgid_iter iter;
6912         struct pid_namespace *ns;
6913  
6914 @@ -3044,6 +3066,8 @@ int proc_pid_readdir(struct file * filp,
6915              iter.task;
6916              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6917                 filp->f_pos = iter.tgid + TGID_OFFSET;
6918 +               if (!vx_proc_task_visible(iter.task))
6919 +                       continue;
6920                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6921                         put_task_struct(iter.task);
6922                         goto out;
6923 @@ -3193,6 +3217,8 @@ static struct dentry *proc_task_lookup(s
6924         tid = name_to_int(dentry);
6925         if (tid == ~0U)
6926                 goto out;
6927 +       if (vx_current_initpid(tid))
6928 +               goto out;
6929  
6930         ns = dentry->d_sb->s_fs_info;
6931         rcu_read_lock();
6932 diff -NurpP --minimal linux-2.6.37/fs/proc/generic.c linux-2.6.37-vs2.3.0.37-rc3/fs/proc/generic.c
6933 --- linux-2.6.37/fs/proc/generic.c      2010-10-21 13:07:51.000000000 +0200
6934 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/proc/generic.c       2010-11-23 02:09:41.000000000 +0100
6935 @@ -22,6 +22,7 @@
6936  #include <linux/bitops.h>
6937  #include <linux/spinlock.h>
6938  #include <linux/completion.h>
6939 +#include <linux/vserver/inode.h>
6940  #include <asm/uaccess.h>
6941  
6942  #include "internal.h"
6943 @@ -424,6 +425,8 @@ struct dentry *proc_lookup_de(struct pro
6944         for (de = de->subdir; de ; de = de->next) {
6945                 if (de->namelen != dentry->d_name.len)
6946                         continue;
6947 +               if (!vx_hide_check(0, de->vx_flags))
6948 +                       continue;
6949                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6950                         unsigned int ino;
6951  
6952 @@ -432,6 +435,8 @@ struct dentry *proc_lookup_de(struct pro
6953                         spin_unlock(&proc_subdir_lock);
6954                         error = -EINVAL;
6955                         inode = proc_get_inode(dir->i_sb, ino, de);
6956 +                       /* generic proc entries belong to the host */
6957 +                       inode->i_tag = 0;
6958                         goto out_unlock;
6959                 }
6960         }
6961 @@ -509,6 +514,8 @@ int proc_readdir_de(struct proc_dir_entr
6962  
6963                                 /* filldir passes info to user space */
6964                                 pde_get(de);
6965 +                               if (!vx_hide_check(0, de->vx_flags))
6966 +                                       goto skip;
6967                                 spin_unlock(&proc_subdir_lock);
6968                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6969                                             de->low_ino, de->mode >> 12) < 0) {
6970 @@ -516,6 +523,7 @@ int proc_readdir_de(struct proc_dir_entr
6971                                         goto out;
6972                                 }
6973                                 spin_lock(&proc_subdir_lock);
6974 +                       skip:
6975                                 filp->f_pos++;
6976                                 next = de->next;
6977                                 pde_put(de);
6978 @@ -630,6 +638,7 @@ static struct proc_dir_entry *__proc_cre
6979         ent->nlink = nlink;
6980         atomic_set(&ent->count, 1);
6981         ent->pde_users = 0;
6982 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6983         spin_lock_init(&ent->pde_unload_lock);
6984         ent->pde_unload_completion = NULL;
6985         INIT_LIST_HEAD(&ent->pde_openers);
6986 @@ -653,7 +662,8 @@ struct proc_dir_entry *proc_symlink(cons
6987                                 kfree(ent->data);
6988                                 kfree(ent);
6989                                 ent = NULL;
6990 -                       }
6991 +                       } else
6992 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6993                 } else {
6994                         kfree(ent);
6995                         ent = NULL;
6996 diff -NurpP --minimal linux-2.6.37/fs/proc/inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/proc/inode.c
6997 --- linux-2.6.37/fs/proc/inode.c        2011-01-05 21:50:26.000000000 +0100
6998 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/proc/inode.c 2010-11-23 02:09:41.000000000 +0100
6999 @@ -427,6 +427,8 @@ struct inode *proc_get_inode(struct supe
7000                         inode->i_uid = de->uid;
7001                         inode->i_gid = de->gid;
7002                 }
7003 +               if (de->vx_flags)
7004 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7005                 if (de->size)
7006                         inode->i_size = de->size;
7007                 if (de->nlink)
7008 diff -NurpP --minimal linux-2.6.37/fs/proc/internal.h linux-2.6.37-vs2.3.0.37-rc3/fs/proc/internal.h
7009 --- linux-2.6.37/fs/proc/internal.h     2010-02-25 11:52:06.000000000 +0100
7010 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/proc/internal.h      2010-11-23 02:09:41.000000000 +0100
7011 @@ -10,6 +10,7 @@
7012   */
7013  
7014  #include <linux/proc_fs.h>
7015 +#include <linux/vs_pid.h>
7016  
7017  extern struct proc_dir_entry proc_root;
7018  #ifdef CONFIG_PROC_SYSCTL
7019 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7020                                 struct pid *pid, struct task_struct *task);
7021  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7022                                 struct pid *pid, struct task_struct *task);
7023 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7024 +                               struct pid *pid, struct task_struct *task);
7025 +
7026  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7027  
7028  extern const struct file_operations proc_maps_operations;
7029 @@ -68,11 +72,16 @@ static inline struct pid *proc_pid(struc
7030         return PROC_I(inode)->pid;
7031  }
7032  
7033 -static inline struct task_struct *get_proc_task(struct inode *inode)
7034 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7035  {
7036         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7037  }
7038  
7039 +static inline struct task_struct *get_proc_task(struct inode *inode)
7040 +{
7041 +       return vx_get_proc_task(inode, proc_pid(inode));
7042 +}
7043 +
7044  static inline int proc_fd(struct inode *inode)
7045  {
7046         return PROC_I(inode)->fd;
7047 diff -NurpP --minimal linux-2.6.37/fs/proc/loadavg.c linux-2.6.37-vs2.3.0.37-rc3/fs/proc/loadavg.c
7048 --- linux-2.6.37/fs/proc/loadavg.c      2009-09-10 15:26:23.000000000 +0200
7049 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/proc/loadavg.c       2010-11-23 02:09:41.000000000 +0100
7050 @@ -12,15 +12,27 @@
7051  
7052  static int loadavg_proc_show(struct seq_file *m, void *v)
7053  {
7054 +       unsigned long running;
7055 +       unsigned int threads;
7056         unsigned long avnrun[3];
7057  
7058         get_avenrun(avnrun, FIXED_1/200, 0);
7059  
7060 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7061 +               struct vx_info *vxi = current_vx_info();
7062 +
7063 +               running = atomic_read(&vxi->cvirt.nr_running);
7064 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7065 +       } else {
7066 +               running = nr_running();
7067 +               threads = nr_threads;
7068 +       }
7069 +
7070         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7071                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7072                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7073                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7074 -               nr_running(), nr_threads,
7075 +               running, threads,
7076                 task_active_pid_ns(current)->last_pid);
7077         return 0;
7078  }
7079 diff -NurpP --minimal linux-2.6.37/fs/proc/meminfo.c linux-2.6.37-vs2.3.0.37-rc3/fs/proc/meminfo.c
7080 --- linux-2.6.37/fs/proc/meminfo.c      2009-12-03 20:02:53.000000000 +0100
7081 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/proc/meminfo.c       2010-11-23 02:09:41.000000000 +0100
7082 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7083         allowed = ((totalram_pages - hugetlb_total_pages())
7084                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7085  
7086 -       cached = global_page_state(NR_FILE_PAGES) -
7087 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7088 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7089                         total_swapcache_pages - i.bufferram;
7090         if (cached < 0)
7091                 cached = 0;
7092 diff -NurpP --minimal linux-2.6.37/fs/proc/root.c linux-2.6.37-vs2.3.0.37-rc3/fs/proc/root.c
7093 --- linux-2.6.37/fs/proc/root.c 2011-01-05 21:50:26.000000000 +0100
7094 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/proc/root.c  2010-11-23 02:09:41.000000000 +0100
7095 @@ -18,9 +18,14 @@
7096  #include <linux/bitops.h>
7097  #include <linux/mount.h>
7098  #include <linux/pid_namespace.h>
7099 +#include <linux/vserver/inode.h>
7100  
7101  #include "internal.h"
7102  
7103 +struct proc_dir_entry *proc_virtual;
7104 +
7105 +extern void proc_vx_init(void);
7106 +
7107  static int proc_test_super(struct super_block *sb, void *data)
7108  {
7109         return sb->s_fs_info == data;
7110 @@ -134,6 +139,7 @@ void __init proc_root_init(void)
7111  #endif
7112         proc_mkdir("bus", NULL);
7113         proc_sys_init();
7114 +       proc_vx_init();
7115  }
7116  
7117  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7118 @@ -202,6 +208,7 @@ struct proc_dir_entry proc_root = {
7119         .proc_iops      = &proc_root_inode_operations, 
7120         .proc_fops      = &proc_root_operations,
7121         .parent         = &proc_root,
7122 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7123  };
7124  
7125  int pid_ns_prepare_proc(struct pid_namespace *ns)
7126 diff -NurpP --minimal linux-2.6.37/fs/proc/uptime.c linux-2.6.37-vs2.3.0.37-rc3/fs/proc/uptime.c
7127 --- linux-2.6.37/fs/proc/uptime.c       2009-12-03 20:02:53.000000000 +0100
7128 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/proc/uptime.c        2010-11-23 02:09:41.000000000 +0100
7129 @@ -4,22 +4,22 @@
7130  #include <linux/sched.h>
7131  #include <linux/seq_file.h>
7132  #include <linux/time.h>
7133 -#include <linux/kernel_stat.h>
7134 +#include <linux/vserver/cvirt.h>
7135  #include <asm/cputime.h>
7136  
7137  static int uptime_proc_show(struct seq_file *m, void *v)
7138  {
7139         struct timespec uptime;
7140         struct timespec idle;
7141 -       int i;
7142 -       cputime_t idletime = cputime_zero;
7143 -
7144 -       for_each_possible_cpu(i)
7145 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7146 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7147  
7148         do_posix_clock_monotonic_gettime(&uptime);
7149         monotonic_to_bootbased(&uptime);
7150         cputime_to_timespec(idletime, &idle);
7151 +
7152 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7153 +               vx_vsi_uptime(&uptime, &idle);
7154 +
7155         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7156                         (unsigned long) uptime.tv_sec,
7157                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7158 diff -NurpP --minimal linux-2.6.37/fs/quota/dquot.c linux-2.6.37-vs2.3.0.37-rc3/fs/quota/dquot.c
7159 --- linux-2.6.37/fs/quota/dquot.c       2011-01-05 21:50:26.000000000 +0100
7160 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/quota/dquot.c        2010-11-23 02:09:41.000000000 +0100
7161 @@ -1541,6 +1541,9 @@ int __dquot_alloc_space(struct inode *in
7162         int reserve = flags & DQUOT_SPACE_RESERVE;
7163         int nofail = flags & DQUOT_SPACE_NOFAIL;
7164  
7165 +       if ((ret = dl_alloc_space(inode, number)))
7166 +               return ret;
7167 +
7168         /*
7169          * First test before acquiring mutex - solves deadlocks when we
7170          * re-enter the quota code and are already holding the mutex
7171 @@ -1595,6 +1598,9 @@ int dquot_alloc_inode(const struct inode
7172         int cnt, ret = 0;
7173         char warntype[MAXQUOTAS];
7174  
7175 +       if ((ret = dl_alloc_inode(inode)))
7176 +               return ret;
7177 +
7178         /* First test before acquiring mutex - solves deadlocks when we
7179           * re-enter the quota code and are already holding the mutex */
7180         if (!dquot_active(inode))
7181 @@ -1665,6 +1671,8 @@ void __dquot_free_space(struct inode *in
7182         char warntype[MAXQUOTAS];
7183         int reserve = flags & DQUOT_SPACE_RESERVE;
7184  
7185 +       dl_free_space(inode, number);
7186 +
7187         /* First test before acquiring mutex - solves deadlocks when we
7188           * re-enter the quota code and are already holding the mutex */
7189         if (!dquot_active(inode)) {
7190 @@ -1703,6 +1711,8 @@ void dquot_free_inode(const struct inode
7191         unsigned int cnt;
7192         char warntype[MAXQUOTAS];
7193  
7194 +       dl_free_inode(inode);
7195 +
7196         /* First test before acquiring mutex - solves deadlocks when we
7197           * re-enter the quota code and are already holding the mutex */
7198         if (!dquot_active(inode))
7199 diff -NurpP --minimal linux-2.6.37/fs/quota/quota.c linux-2.6.37-vs2.3.0.37-rc3/fs/quota/quota.c
7200 --- linux-2.6.37/fs/quota/quota.c       2010-08-02 16:52:51.000000000 +0200
7201 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/quota/quota.c        2010-11-23 02:09:41.000000000 +0100
7202 @@ -8,6 +8,7 @@
7203  #include <linux/fs.h>
7204  #include <linux/namei.h>
7205  #include <linux/slab.h>
7206 +#include <linux/vs_context.h>
7207  #include <asm/current.h>
7208  #include <asm/uaccess.h>
7209  #include <linux/kernel.h>
7210 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
7211                         break;
7212                 /*FALLTHROUGH*/
7213         default:
7214 -               if (!capable(CAP_SYS_ADMIN))
7215 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7216                         return -EPERM;
7217         }
7218  
7219 @@ -296,6 +297,46 @@ static int do_quotactl(struct super_bloc
7220         }
7221  }
7222  
7223 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7224 +
7225 +#include <linux/vroot.h>
7226 +#include <linux/major.h>
7227 +#include <linux/module.h>
7228 +#include <linux/kallsyms.h>
7229 +#include <linux/vserver/debug.h>
7230 +
7231 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7232 +
7233 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7234 +
7235 +int register_vroot_grb(vroot_grb_func *func) {
7236 +       int ret = -EBUSY;
7237 +
7238 +       spin_lock(&vroot_grb_lock);
7239 +       if (!vroot_get_real_bdev) {
7240 +               vroot_get_real_bdev = func;
7241 +               ret = 0;
7242 +       }
7243 +       spin_unlock(&vroot_grb_lock);
7244 +       return ret;
7245 +}
7246 +EXPORT_SYMBOL(register_vroot_grb);
7247 +
7248 +int unregister_vroot_grb(vroot_grb_func *func) {
7249 +       int ret = -EINVAL;
7250 +
7251 +       spin_lock(&vroot_grb_lock);
7252 +       if (vroot_get_real_bdev) {
7253 +               vroot_get_real_bdev = NULL;
7254 +               ret = 0;
7255 +       }
7256 +       spin_unlock(&vroot_grb_lock);
7257 +       return ret;
7258 +}
7259 +EXPORT_SYMBOL(unregister_vroot_grb);
7260 +
7261 +#endif
7262 +
7263  /*
7264   * look up a superblock on which quota ops will be performed
7265   * - use the name of a block device to find the superblock thereon
7266 @@ -313,6 +354,22 @@ static struct super_block *quotactl_bloc
7267         putname(tmp);
7268         if (IS_ERR(bdev))
7269                 return ERR_CAST(bdev);
7270 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7271 +       if (bdev && bdev->bd_inode &&
7272 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7273 +               struct block_device *bdnew = (void *)-EINVAL;
7274 +
7275 +               if (vroot_get_real_bdev)
7276 +                       bdnew = vroot_get_real_bdev(bdev);
7277 +               else
7278 +                       vxdprintk(VXD_CBIT(misc, 0),
7279 +                                       "vroot_get_real_bdev not set");
7280 +               bdput(bdev);
7281 +               if (IS_ERR(bdnew))
7282 +                       return ERR_PTR(PTR_ERR(bdnew));
7283 +               bdev = bdnew;
7284 +       }
7285 +#endif
7286         sb = get_super(bdev);
7287         bdput(bdev);
7288         if (!sb)
7289 diff -NurpP --minimal linux-2.6.37/fs/reiserfs/file.c linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/file.c
7290 --- linux-2.6.37/fs/reiserfs/file.c     2011-01-05 21:50:26.000000000 +0100
7291 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/file.c      2010-11-23 02:09:41.000000000 +0100
7292 @@ -312,4 +312,5 @@ const struct inode_operations reiserfs_f
7293         .listxattr = reiserfs_listxattr,
7294         .removexattr = reiserfs_removexattr,
7295         .permission = reiserfs_permission,
7296 +       .sync_flags = reiserfs_sync_flags,
7297  };
7298 diff -NurpP --minimal linux-2.6.37/fs/reiserfs/inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/inode.c
7299 --- linux-2.6.37/fs/reiserfs/inode.c    2011-01-05 21:50:26.000000000 +0100
7300 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/inode.c     2010-11-23 02:09:41.000000000 +0100
7301 @@ -18,6 +18,7 @@
7302  #include <linux/writeback.h>
7303  #include <linux/quotaops.h>
7304  #include <linux/swap.h>
7305 +#include <linux/vs_tag.h>
7306  
7307  int reiserfs_commit_write(struct file *f, struct page *page,
7308                           unsigned from, unsigned to);
7309 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
7310         struct buffer_head *bh;
7311         struct item_head *ih;
7312         __u32 rdev;
7313 +       uid_t uid;
7314 +       gid_t gid;
7315         //int version = ITEM_VERSION_1;
7316  
7317         bh = PATH_PLAST_BUFFER(path);
7318 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
7319                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7320                 unsigned long blocks;
7321  
7322 +               uid = sd_v1_uid(sd);
7323 +               gid = sd_v1_gid(sd);
7324 +
7325                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7326                 set_inode_sd_version(inode, STAT_DATA_V1);
7327                 inode->i_mode = sd_v1_mode(sd);
7328                 inode->i_nlink = sd_v1_nlink(sd);
7329 -               inode->i_uid = sd_v1_uid(sd);
7330 -               inode->i_gid = sd_v1_gid(sd);
7331                 inode->i_size = sd_v1_size(sd);
7332                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7333                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7334 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
7335                 // (directories and symlinks)
7336                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7337  
7338 +               uid    = sd_v2_uid(sd);
7339 +               gid    = sd_v2_gid(sd);
7340 +
7341                 inode->i_mode = sd_v2_mode(sd);
7342                 inode->i_nlink = sd_v2_nlink(sd);
7343 -               inode->i_uid = sd_v2_uid(sd);
7344                 inode->i_size = sd_v2_size(sd);
7345 -               inode->i_gid = sd_v2_gid(sd);
7346                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7347                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7348                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7349 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
7350                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7351         }
7352  
7353 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7354 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7355 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7356 +
7357         pathrelse(path);
7358         if (S_ISREG(inode->i_mode)) {
7359                 inode->i_op = &reiserfs_file_inode_operations;
7360 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
7361  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7362  {
7363         struct stat_data *sd_v2 = (struct stat_data *)sd;
7364 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7365 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7366         __u16 flags;
7367  
7368 +       set_sd_v2_uid(sd_v2, uid);
7369 +       set_sd_v2_gid(sd_v2, gid);
7370         set_sd_v2_mode(sd_v2, inode->i_mode);
7371         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7372 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7373         set_sd_v2_size(sd_v2, size);
7374 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7375         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7376         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7377         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7378 @@ -2858,14 +2869,19 @@ int reiserfs_commit_write(struct file *f
7379  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7380  {
7381         if (reiserfs_attrs(inode->i_sb)) {
7382 -               if (sd_attrs & REISERFS_SYNC_FL)
7383 -                       inode->i_flags |= S_SYNC;
7384 -               else
7385 -                       inode->i_flags &= ~S_SYNC;
7386                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7387                         inode->i_flags |= S_IMMUTABLE;
7388                 else
7389                         inode->i_flags &= ~S_IMMUTABLE;
7390 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7391 +                       inode->i_flags |= S_IXUNLINK;
7392 +               else
7393 +                       inode->i_flags &= ~S_IXUNLINK;
7394 +
7395 +               if (sd_attrs & REISERFS_SYNC_FL)
7396 +                       inode->i_flags |= S_SYNC;
7397 +               else
7398 +                       inode->i_flags &= ~S_SYNC;
7399                 if (sd_attrs & REISERFS_APPEND_FL)
7400                         inode->i_flags |= S_APPEND;
7401                 else
7402 @@ -2878,6 +2894,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7403                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7404                 else
7405                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7406 +
7407 +               if (sd_attrs & REISERFS_BARRIER_FL)
7408 +                       inode->i_vflags |= V_BARRIER;
7409 +               else
7410 +                       inode->i_vflags &= ~V_BARRIER;
7411 +               if (sd_attrs & REISERFS_COW_FL)
7412 +                       inode->i_vflags |= V_COW;
7413 +               else
7414 +                       inode->i_vflags &= ~V_COW;
7415         }
7416  }
7417  
7418 @@ -2888,6 +2913,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7419                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7420                 else
7421                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7422 +               if (inode->i_flags & S_IXUNLINK)
7423 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7424 +               else
7425 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7426 +
7427                 if (inode->i_flags & S_SYNC)
7428                         *sd_attrs |= REISERFS_SYNC_FL;
7429                 else
7430 @@ -2900,6 +2930,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7431                         *sd_attrs |= REISERFS_NOTAIL_FL;
7432                 else
7433                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7434 +
7435 +               if (inode->i_vflags & V_BARRIER)
7436 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7437 +               else
7438 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7439 +               if (inode->i_vflags & V_COW)
7440 +                       *sd_attrs |= REISERFS_COW_FL;
7441 +               else
7442 +                       *sd_attrs &= ~REISERFS_COW_FL;
7443         }
7444  }
7445  
7446 @@ -3143,7 +3182,8 @@ int reiserfs_setattr(struct dentry *dent
7447         }
7448  
7449         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7450 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7451 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7452 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7453                 struct reiserfs_transaction_handle th;
7454                 int jbegin_count =
7455                     2 *
7456 @@ -3172,6 +3212,9 @@ int reiserfs_setattr(struct dentry *dent
7457                         inode->i_uid = attr->ia_uid;
7458                 if (attr->ia_valid & ATTR_GID)
7459                         inode->i_gid = attr->ia_gid;
7460 +                               if ((attr->ia_valid & ATTR_TAG) &&
7461 +                                       IS_TAGGED(inode))
7462 +                                       inode->i_tag = attr->ia_tag;
7463                 mark_inode_dirty(inode);
7464                 error = journal_end(&th, inode->i_sb, jbegin_count);
7465                 if (error)
7466 diff -NurpP --minimal linux-2.6.37/fs/reiserfs/ioctl.c linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/ioctl.c
7467 --- linux-2.6.37/fs/reiserfs/ioctl.c    2011-01-05 21:50:26.000000000 +0100
7468 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/ioctl.c     2011-01-05 22:30:39.000000000 +0100
7469 @@ -11,6 +11,21 @@
7470  #include <linux/pagemap.h>
7471  #include <linux/compat.h>
7472  
7473 +
7474 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7475 +{
7476 +       __u16 sd_attrs = 0;
7477 +
7478 +       inode->i_flags = flags;
7479 +       inode->i_vflags = vflags;
7480 +
7481 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7482 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7483 +       inode->i_ctime = CURRENT_TIME_SEC;
7484 +       mark_inode_dirty(inode);
7485 +       return 0;
7486 +}
7487 +
7488  /*
7489   * reiserfs_ioctl - handler for ioctl for inode
7490   * supported commands:
7491 @@ -22,7 +37,7 @@
7492  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7493  {
7494         struct inode *inode = filp->f_path.dentry->d_inode;
7495 -       unsigned int flags;
7496 +       unsigned int flags, oldflags;
7497         int err = 0;
7498  
7499         reiserfs_write_lock(inode->i_sb);
7500 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7501  
7502                 flags = REISERFS_I(inode)->i_attrs;
7503                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7504 +               flags &= REISERFS_FL_USER_VISIBLE;
7505                 err = put_user(flags, (int __user *)arg);
7506                 break;
7507         case REISERFS_IOC_SETFLAGS:{
7508 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7509                                 err = -EFAULT;
7510                                 goto setflags_out;
7511                         }
7512 +                       if (IS_BARRIER(inode)) {
7513 +                               vxwprintk_task(1, "messing with the barrier.");
7514 +                               return -EACCES;
7515 +                       }
7516                         /*
7517                          * Is it quota file? Do not allow user to mess with it
7518                          */
7519 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7520                                         goto setflags_out;
7521                                 }
7522                         }
7523 +
7524 +                       oldflags = REISERFS_I(inode)->i_attrs;
7525 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7526 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7527                         sd_attrs_to_i_attrs(flags, inode);
7528                         REISERFS_I(inode)->i_attrs = flags;
7529                         inode->i_ctime = CURRENT_TIME_SEC;
7530 diff -NurpP --minimal linux-2.6.37/fs/reiserfs/namei.c linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/namei.c
7531 --- linux-2.6.37/fs/reiserfs/namei.c    2011-01-05 21:50:26.000000000 +0100
7532 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/namei.c     2010-11-23 02:09:41.000000000 +0100
7533 @@ -18,6 +18,7 @@
7534  #include <linux/reiserfs_acl.h>
7535  #include <linux/reiserfs_xattr.h>
7536  #include <linux/quotaops.h>
7537 +#include <linux/vs_tag.h>
7538  
7539  #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; }
7540  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7541 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7542         if (retval == IO_ERROR) {
7543                 return ERR_PTR(-EIO);
7544         }
7545 +               dx_propagate_tag(nd, inode);
7546  
7547         return d_splice_alias(inode, dentry);
7548  }
7549 @@ -1532,6 +1534,7 @@ const struct inode_operations reiserfs_d
7550         .listxattr = reiserfs_listxattr,
7551         .removexattr = reiserfs_removexattr,
7552         .permission = reiserfs_permission,
7553 +       .sync_flags = reiserfs_sync_flags,
7554  };
7555  
7556  /*
7557 diff -NurpP --minimal linux-2.6.37/fs/reiserfs/super.c linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/super.c
7558 --- linux-2.6.37/fs/reiserfs/super.c    2011-01-05 21:50:26.000000000 +0100
7559 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/super.c     2010-11-23 02:09:41.000000000 +0100
7560 @@ -892,6 +892,14 @@ static int reiserfs_parse_options(struct
7561                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7562                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7563  #endif
7564 +#ifndef CONFIG_TAGGING_NONE
7565 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7566 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7567 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7568 +#endif
7569 +#ifdef CONFIG_PROPAGATE
7570 +               {"tag",.arg_required = 'T',.values = NULL},
7571 +#endif
7572  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7573                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7574                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7575 @@ -1201,6 +1209,14 @@ static int reiserfs_remount(struct super
7576         handle_quota_files(s, qf_names, &qfmt);
7577  #endif
7578  
7579 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7580 +               !(s->s_flags & MS_TAGGED)) {
7581 +               reiserfs_warning(s, "super-vs01",
7582 +                       "reiserfs: tagging not permitted on remount.");
7583 +               err = -EINVAL;
7584 +               goto out_err;
7585 +       }
7586 +
7587         handle_attrs(s);
7588  
7589         /* Add options that are safe here */
7590 @@ -1683,6 +1699,10 @@ static int reiserfs_fill_super(struct su
7591                 goto error;
7592         }
7593  
7594 +       /* map mount option tagxid */
7595 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7596 +               s->s_flags |= MS_TAGGED;
7597 +
7598         rs = SB_DISK_SUPER_BLOCK(s);
7599         /* Let's do basic sanity check to verify that underlying device is not
7600            smaller than the filesystem. If the check fails then abort and scream,
7601 diff -NurpP --minimal linux-2.6.37/fs/reiserfs/xattr.c linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/xattr.c
7602 --- linux-2.6.37/fs/reiserfs/xattr.c    2011-01-05 21:50:26.000000000 +0100
7603 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/reiserfs/xattr.c     2010-11-23 02:09:41.000000000 +0100
7604 @@ -40,6 +40,7 @@
7605  #include <linux/errno.h>
7606  #include <linux/gfp.h>
7607  #include <linux/fs.h>
7608 +#include <linux/mount.h>
7609  #include <linux/file.h>
7610  #include <linux/pagemap.h>
7611  #include <linux/xattr.h>
7612 diff -NurpP --minimal linux-2.6.37/fs/stat.c linux-2.6.37-vs2.3.0.37-rc3/fs/stat.c
7613 --- linux-2.6.37/fs/stat.c      2010-10-21 13:07:51.000000000 +0200
7614 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/stat.c       2010-11-23 02:09:41.000000000 +0100
7615 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7616         stat->nlink = inode->i_nlink;
7617         stat->uid = inode->i_uid;
7618         stat->gid = inode->i_gid;
7619 +       stat->tag = inode->i_tag;
7620         stat->rdev = inode->i_rdev;
7621         stat->atime = inode->i_atime;
7622         stat->mtime = inode->i_mtime;
7623 diff -NurpP --minimal linux-2.6.37/fs/statfs.c linux-2.6.37-vs2.3.0.37-rc3/fs/statfs.c
7624 --- linux-2.6.37/fs/statfs.c    2010-10-21 13:07:51.000000000 +0200
7625 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/statfs.c     2010-11-23 02:09:41.000000000 +0100
7626 @@ -7,6 +7,8 @@
7627  #include <linux/statfs.h>
7628  #include <linux/security.h>
7629  #include <linux/uaccess.h>
7630 +#include <linux/vs_base.h>
7631 +#include <linux/vs_dlimit.h>
7632  
7633  static int flags_by_mnt(int mnt_flags)
7634  {
7635 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7636         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7637         if (retval == 0 && buf->f_frsize == 0)
7638                 buf->f_frsize = buf->f_bsize;
7639 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7640 +               vx_vsi_statfs(dentry->d_sb, buf);
7641         return retval;
7642  }
7643  
7644 diff -NurpP --minimal linux-2.6.37/fs/super.c linux-2.6.37-vs2.3.0.37-rc3/fs/super.c
7645 --- linux-2.6.37/fs/super.c     2011-01-05 21:50:27.000000000 +0100
7646 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/super.c      2010-11-23 03:09:36.000000000 +0100
7647 @@ -30,6 +30,9 @@
7648  #include <linux/idr.h>
7649  #include <linux/mutex.h>
7650  #include <linux/backing-dev.h>
7651 +#include <linux/devpts_fs.h>
7652 +#include <linux/proc_fs.h>
7653 +#include <linux/vs_context.h>
7654  #include "internal.h"
7655  
7656  
7657 @@ -956,6 +959,7 @@ struct vfsmount *
7658  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7659  {
7660         struct vfsmount *mnt;
7661 +       struct super_block *sb;
7662         struct dentry *root;
7663         char *secdata = NULL;
7664         int error;
7665 @@ -963,6 +967,11 @@ vfs_kern_mount(struct file_system_type *
7666         if (!type)
7667                 return ERR_PTR(-ENODEV);
7668  
7669 +       error = -EPERM;
7670 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7671 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7672 +               goto out;
7673 +
7674         error = -ENOMEM;
7675         mnt = alloc_vfsmnt(name);
7676         if (!mnt)
7677 @@ -994,11 +1003,19 @@ vfs_kern_mount(struct file_system_type *
7678                 if (error < 0)
7679                         goto out_free_secdata;
7680         }
7681 -       BUG_ON(!mnt->mnt_sb);
7682 -       WARN_ON(!mnt->mnt_sb->s_bdi);
7683 +
7684 +       sb = mnt->mnt_sb;
7685 +       BUG_ON(!sb);
7686 +       WARN_ON(!sb->s_bdi);
7687         mnt->mnt_sb->s_flags |= MS_BORN;
7688  
7689 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7690 +       error = -EPERM;
7691 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7692 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7693 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7694 +               goto out_sb;
7695 +
7696 +       error = security_sb_kern_mount(sb, flags, secdata);
7697         if (error)
7698                 goto out_sb;
7699  
7700 diff -NurpP --minimal linux-2.6.37/fs/sysfs/mount.c linux-2.6.37-vs2.3.0.37-rc3/fs/sysfs/mount.c
7701 --- linux-2.6.37/fs/sysfs/mount.c       2011-01-05 21:50:27.000000000 +0100
7702 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/sysfs/mount.c        2010-11-23 02:09:41.000000000 +0100
7703 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7704  
7705         sb->s_blocksize = PAGE_CACHE_SIZE;
7706         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7707 -       sb->s_magic = SYSFS_MAGIC;
7708 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7709         sb->s_op = &sysfs_ops;
7710         sb->s_time_gran = 1;
7711  
7712 diff -NurpP --minimal linux-2.6.37/fs/utimes.c linux-2.6.37-vs2.3.0.37-rc3/fs/utimes.c
7713 --- linux-2.6.37/fs/utimes.c    2010-10-21 13:07:51.000000000 +0200
7714 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/utimes.c     2010-11-23 02:09:41.000000000 +0100
7715 @@ -8,6 +8,8 @@
7716  #include <linux/stat.h>
7717  #include <linux/utime.h>
7718  #include <linux/syscalls.h>
7719 +#include <linux/mount.h>
7720 +#include <linux/vs_cowbl.h>
7721  #include <asm/uaccess.h>
7722  #include <asm/unistd.h>
7723  
7724 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7725  {
7726         int error;
7727         struct iattr newattrs;
7728 -       struct inode *inode = path->dentry->d_inode;
7729 +       struct inode *inode;
7730  
7731         error = mnt_want_write(path->mnt);
7732         if (error)
7733                 goto out;
7734  
7735 +       error = cow_check_and_break(path);
7736 +       if (error)
7737 +               goto mnt_drop_write_and_out;
7738 +
7739 +       inode = path->dentry->d_inode;
7740 +
7741         if (times && times[0].tv_nsec == UTIME_NOW &&
7742                      times[1].tv_nsec == UTIME_NOW)
7743                 times = NULL;
7744 diff -NurpP --minimal linux-2.6.37/fs/xattr.c linux-2.6.37-vs2.3.0.37-rc3/fs/xattr.c
7745 --- linux-2.6.37/fs/xattr.c     2010-08-02 16:52:52.000000000 +0200
7746 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xattr.c      2010-11-23 02:09:41.000000000 +0100
7747 @@ -18,6 +18,7 @@
7748  #include <linux/module.h>
7749  #include <linux/fsnotify.h>
7750  #include <linux/audit.h>
7751 +#include <linux/mount.h>
7752  #include <asm/uaccess.h>
7753  
7754  
7755 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7756          * The trusted.* namespace can only be accessed by a privileged user.
7757          */
7758         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
7759 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
7760 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
7761  
7762         /* In user.* namespace, only regular files and directories can have
7763          * extended attributes. For sticky directories, only the owner and
7764 diff -NurpP --minimal linux-2.6.37/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/linux-2.6/xfs_ioctl.c
7765 --- linux-2.6.37/fs/xfs/linux-2.6/xfs_ioctl.c   2011-01-05 21:50:27.000000000 +0100
7766 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/linux-2.6/xfs_ioctl.c    2010-11-23 02:09:41.000000000 +0100
7767 @@ -28,7 +28,7 @@
7768  #include "xfs_bmap_btree.h"
7769  #include "xfs_dinode.h"
7770  #include "xfs_inode.h"
7771 -#include "xfs_ioctl.h"
7772 +// #include "xfs_ioctl.h"
7773  #include "xfs_rtalloc.h"
7774  #include "xfs_itable.h"
7775  #include "xfs_error.h"
7776 @@ -738,6 +738,10 @@ xfs_merge_ioc_xflags(
7777                 xflags |= XFS_XFLAG_IMMUTABLE;
7778         else
7779                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7780 +       if (flags & FS_IXUNLINK_FL)
7781 +               xflags |= XFS_XFLAG_IXUNLINK;
7782 +       else
7783 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7784         if (flags & FS_APPEND_FL)
7785                 xflags |= XFS_XFLAG_APPEND;
7786         else
7787 @@ -766,6 +770,8 @@ xfs_di2lxflags(
7788  
7789         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7790                 flags |= FS_IMMUTABLE_FL;
7791 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7792 +               flags |= FS_IXUNLINK_FL;
7793         if (di_flags & XFS_DIFLAG_APPEND)
7794                 flags |= FS_APPEND_FL;
7795         if (di_flags & XFS_DIFLAG_SYNC)
7796 @@ -826,6 +832,8 @@ xfs_set_diflags(
7797         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7798         if (xflags & XFS_XFLAG_IMMUTABLE)
7799                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7800 +       if (xflags & XFS_XFLAG_IXUNLINK)
7801 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7802         if (xflags & XFS_XFLAG_APPEND)
7803                 di_flags |= XFS_DIFLAG_APPEND;
7804         if (xflags & XFS_XFLAG_SYNC)
7805 @@ -868,6 +876,10 @@ xfs_diflags_to_linux(
7806                 inode->i_flags |= S_IMMUTABLE;
7807         else
7808                 inode->i_flags &= ~S_IMMUTABLE;
7809 +       if (xflags & XFS_XFLAG_IXUNLINK)
7810 +               inode->i_flags |= S_IXUNLINK;
7811 +       else
7812 +               inode->i_flags &= ~S_IXUNLINK;
7813         if (xflags & XFS_XFLAG_APPEND)
7814                 inode->i_flags |= S_APPEND;
7815         else
7816 @@ -1342,10 +1354,18 @@ xfs_file_ioctl(
7817         case XFS_IOC_FSGETXATTRA:
7818                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7819         case XFS_IOC_FSSETXATTR:
7820 +               if (IS_BARRIER(inode)) {
7821 +                       vxwprintk_task(1, "messing with the barrier.");
7822 +                       return -XFS_ERROR(EACCES);
7823 +               }
7824                 return xfs_ioc_fssetxattr(ip, filp, arg);
7825         case XFS_IOC_GETXFLAGS:
7826                 return xfs_ioc_getxflags(ip, arg);
7827         case XFS_IOC_SETXFLAGS:
7828 +               if (IS_BARRIER(inode)) {
7829 +                       vxwprintk_task(1, "messing with the barrier.");
7830 +                       return -XFS_ERROR(EACCES);
7831 +               }
7832                 return xfs_ioc_setxflags(ip, filp, arg);
7833  
7834         case XFS_IOC_FSSETDM: {
7835 diff -NurpP --minimal linux-2.6.37/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/linux-2.6/xfs_ioctl.h
7836 --- linux-2.6.37/fs/xfs/linux-2.6/xfs_ioctl.h   2010-07-07 18:31:54.000000000 +0200
7837 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/linux-2.6/xfs_ioctl.h    2010-11-23 02:09:41.000000000 +0100
7838 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7839         void __user             *uhandle,
7840         u32                     hlen);
7841  
7842 +extern int
7843 +xfs_sync_flags(
7844 +       struct inode            *inode,
7845 +       int                     flags,
7846 +       int                     vflags);
7847 +
7848  extern long
7849  xfs_file_ioctl(
7850         struct file             *filp,
7851 diff -NurpP --minimal linux-2.6.37/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/linux-2.6/xfs_iops.c
7852 --- linux-2.6.37/fs/xfs/linux-2.6/xfs_iops.c    2011-01-05 21:50:27.000000000 +0100
7853 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/linux-2.6/xfs_iops.c     2010-11-23 02:09:41.000000000 +0100
7854 @@ -30,6 +30,7 @@
7855  #include "xfs_bmap_btree.h"
7856  #include "xfs_dinode.h"
7857  #include "xfs_inode.h"
7858 +#include "xfs_ioctl.h"
7859  #include "xfs_bmap.h"
7860  #include "xfs_rtalloc.h"
7861  #include "xfs_error.h"
7862 @@ -49,6 +50,7 @@
7863  #include <linux/falloc.h>
7864  #include <linux/fiemap.h>
7865  #include <linux/slab.h>
7866 +#include <linux/vs_tag.h>
7867  
7868  /*
7869   * Bring the timestamps in the XFS inode uptodate.
7870 @@ -464,6 +466,7 @@ xfs_vn_getattr(
7871         stat->nlink = ip->i_d.di_nlink;
7872         stat->uid = ip->i_d.di_uid;
7873         stat->gid = ip->i_d.di_gid;
7874 +       stat->tag = ip->i_d.di_tag;
7875         stat->ino = ip->i_ino;
7876         stat->atime = inode->i_atime;
7877         stat->mtime = inode->i_mtime;
7878 @@ -652,6 +655,7 @@ static const struct inode_operations xfs
7879         .listxattr              = xfs_vn_listxattr,
7880         .fallocate              = xfs_vn_fallocate,
7881         .fiemap                 = xfs_vn_fiemap,
7882 +       .sync_flags             = xfs_sync_flags,
7883  };
7884  
7885  static const struct inode_operations xfs_dir_inode_operations = {
7886 @@ -677,6 +681,7 @@ static const struct inode_operations xfs
7887         .getxattr               = generic_getxattr,
7888         .removexattr            = generic_removexattr,
7889         .listxattr              = xfs_vn_listxattr,
7890 +       .sync_flags             = xfs_sync_flags,
7891  };
7892  
7893  static const struct inode_operations xfs_dir_ci_inode_operations = {
7894 @@ -726,6 +731,10 @@ xfs_diflags_to_iflags(
7895                 inode->i_flags |= S_IMMUTABLE;
7896         else
7897                 inode->i_flags &= ~S_IMMUTABLE;
7898 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7899 +               inode->i_flags |= S_IXUNLINK;
7900 +       else
7901 +               inode->i_flags &= ~S_IXUNLINK;
7902         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7903                 inode->i_flags |= S_APPEND;
7904         else
7905 @@ -738,6 +747,15 @@ xfs_diflags_to_iflags(
7906                 inode->i_flags |= S_NOATIME;
7907         else
7908                 inode->i_flags &= ~S_NOATIME;
7909 +
7910 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7911 +               inode->i_vflags |= V_BARRIER;
7912 +       else
7913 +               inode->i_vflags &= ~V_BARRIER;
7914 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7915 +               inode->i_vflags |= V_COW;
7916 +       else
7917 +               inode->i_vflags &= ~V_COW;
7918  }
7919  
7920  /*
7921 @@ -769,6 +787,7 @@ xfs_setup_inode(
7922         inode->i_nlink  = ip->i_d.di_nlink;
7923         inode->i_uid    = ip->i_d.di_uid;
7924         inode->i_gid    = ip->i_d.di_gid;
7925 +       inode->i_tag    = ip->i_d.di_tag;
7926  
7927         switch (inode->i_mode & S_IFMT) {
7928         case S_IFBLK:
7929 diff -NurpP --minimal linux-2.6.37/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/linux-2.6/xfs_linux.h
7930 --- linux-2.6.37/fs/xfs/linux-2.6/xfs_linux.h   2011-01-05 21:50:27.000000000 +0100
7931 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/linux-2.6/xfs_linux.h    2010-11-23 03:28:16.000000000 +0100
7932 @@ -115,6 +115,7 @@
7933  
7934  #define current_cpu()          (raw_smp_processor_id())
7935  #define current_pid()          (current->pid)
7936 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7937  #define current_test_flags(f)  (current->flags & (f))
7938  #define current_set_flags_nested(sp, f)                \
7939                 (*(sp) = current->flags, current->flags |= (f))
7940 diff -NurpP --minimal linux-2.6.37/fs/xfs/linux-2.6/xfs_super.c linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/linux-2.6/xfs_super.c
7941 --- linux-2.6.37/fs/xfs/linux-2.6/xfs_super.c   2011-01-05 21:50:27.000000000 +0100
7942 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/linux-2.6/xfs_super.c    2010-11-23 02:09:41.000000000 +0100
7943 @@ -112,6 +112,9 @@ mempool_t *xfs_ioend_pool;
7944  #define MNTOPT_QUOTANOENF  "qnoenforce"        /* same as uqnoenforce */
7945  #define MNTOPT_DELAYLOG   "delaylog"   /* Delayed loging enabled */
7946  #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
7947 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7948 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7949 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7950  
7951  /*
7952   * Table driven mount option parser.
7953 @@ -120,10 +123,14 @@ mempool_t *xfs_ioend_pool;
7954   * in the future, too.
7955   */
7956  enum {
7957 +       Opt_tag, Opt_notag,
7958         Opt_barrier, Opt_nobarrier, Opt_err
7959  };
7960  
7961  static const match_table_t tokens = {
7962 +       {Opt_tag, "tagxid"},
7963 +       {Opt_tag, "tag"},
7964 +       {Opt_notag, "notag"},
7965         {Opt_barrier, "barrier"},
7966         {Opt_nobarrier, "nobarrier"},
7967         {Opt_err, NULL}
7968 @@ -367,6 +374,19 @@ xfs_parseargs(
7969                 } else if (!strcmp(this_char, "irixsgid")) {
7970                         cmn_err(CE_WARN,
7971         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7972 +#ifndef CONFIG_TAGGING_NONE
7973 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7974 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7975 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7976 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7977 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7978 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7979 +#endif
7980 +#ifdef CONFIG_PROPAGATE
7981 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7982 +                       /* use value */
7983 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7984 +#endif
7985                 } else {
7986                         cmn_err(CE_WARN,
7987                                 "XFS: unknown mount option [%s].", this_char);
7988 @@ -1312,6 +1332,16 @@ xfs_fs_remount(
7989                 case Opt_nobarrier:
7990                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7991                         break;
7992 +               case Opt_tag:
7993 +                       if (!(sb->s_flags & MS_TAGGED)) {
7994 +                               printk(KERN_INFO
7995 +                                       "XFS: %s: tagging not permitted on remount.\n",
7996 +                                       sb->s_id);
7997 +                               return -EINVAL;
7998 +                       }
7999 +                       break;
8000 +               case Opt_notag:
8001 +                       break;
8002                 default:
8003                         /*
8004                          * Logically we would return an error here to prevent
8005 @@ -1540,6 +1570,9 @@ xfs_fs_fill_super(
8006         if (error)
8007                 goto out_filestream_unmount;
8008  
8009 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8010 +               sb->s_flags |= MS_TAGGED;
8011 +
8012         sb->s_magic = XFS_SB_MAGIC;
8013         sb->s_blocksize = mp->m_sb.sb_blocksize;
8014         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
8015 diff -NurpP --minimal linux-2.6.37/fs/xfs/xfs_dinode.h linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_dinode.h
8016 --- linux-2.6.37/fs/xfs/xfs_dinode.h    2011-01-05 21:50:28.000000000 +0100
8017 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_dinode.h     2010-11-23 03:21:21.000000000 +0100
8018 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
8019         __be32          di_nlink;       /* number of links to file */
8020         __be16          di_projid_lo;   /* lower part of owner's project id */
8021         __be16          di_projid_hi;   /* higher part owner's project id */
8022 -       __u8            di_pad[6];      /* unused, zeroed space */
8023 +       __u8            di_pad[2];      /* unused, zeroed space */
8024 +       __be16          di_tag;         /* context tagging */
8025 +       __be16          di_vflags;      /* vserver specific flags */
8026         __be16          di_flushiter;   /* incremented on flush */
8027         xfs_timestamp_t di_atime;       /* time last accessed */
8028         xfs_timestamp_t di_mtime;       /* time last modified */
8029 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
8030  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8031  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8032  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8033 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8034 +
8035  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8036  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8037  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8038 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
8039  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8040  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8041  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8042 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8043  
8044  #ifdef CONFIG_XFS_RT
8045  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8046 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
8047          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8048          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8049          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8050 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8051 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8052 +        XFS_DIFLAG_IXUNLINK)
8053 +
8054 +#define XFS_DIVFLAG_BARRIER    0x01
8055 +#define XFS_DIVFLAG_COW                0x02
8056  
8057  #endif /* __XFS_DINODE_H__ */
8058 diff -NurpP --minimal linux-2.6.37/fs/xfs/xfs_fs.h linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_fs.h
8059 --- linux-2.6.37/fs/xfs/xfs_fs.h        2011-01-05 21:50:28.000000000 +0100
8060 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_fs.h 2010-11-23 03:16:13.000000000 +0100
8061 @@ -67,6 +67,9 @@ struct fsxattr {
8062  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8063  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8064  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8065 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8066 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8067 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8068  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8069  
8070  /*
8071 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
8072  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
8073         __u16           bs_forkoff;     /* inode fork offset in bytes   */
8074         __u16           bs_projid_hi;   /* higher part of project id    */
8075 -       unsigned char   bs_pad[10];     /* pad space, unused            */
8076 +       unsigned char   bs_pad[8];      /* pad space, unused            */
8077 +       __u16           bs_tag;         /* context tagging              */
8078         __u32           bs_dmevmask;    /* DMIG event mask              */
8079         __u16           bs_dmstate;     /* DMIG state info              */
8080         __u16           bs_aextents;    /* attribute number of extents  */
8081 diff -NurpP --minimal linux-2.6.37/fs/xfs/xfs_ialloc.c linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_ialloc.c
8082 --- linux-2.6.37/fs/xfs/xfs_ialloc.c    2011-01-05 21:50:28.000000000 +0100
8083 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_ialloc.c     2010-11-23 02:09:41.000000000 +0100
8084 @@ -37,7 +37,6 @@
8085  #include "xfs_error.h"
8086  #include "xfs_bmap.h"
8087  
8088 -
8089  /*
8090   * Allocation group level functions.
8091   */
8092 diff -NurpP --minimal linux-2.6.37/fs/xfs/xfs_inode.c linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_inode.c
8093 --- linux-2.6.37/fs/xfs/xfs_inode.c     2011-01-05 21:50:28.000000000 +0100
8094 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_inode.c      2010-11-23 03:28:30.000000000 +0100
8095 @@ -245,6 +245,7 @@ xfs_inotobp(
8096         return 0;
8097  }
8098  
8099 +#include <linux/vs_tag.h>
8100  
8101  /*
8102   * This routine is called to map an inode to the buffer containing
8103 @@ -650,15 +651,25 @@ xfs_iformat_btree(
8104  STATIC void
8105  xfs_dinode_from_disk(
8106         xfs_icdinode_t          *to,
8107 -       xfs_dinode_t            *from)
8108 +       xfs_dinode_t            *from,
8109 +       int tagged)
8110  {
8111 +       uint32_t uid, gid, tag;
8112 +
8113         to->di_magic = be16_to_cpu(from->di_magic);
8114         to->di_mode = be16_to_cpu(from->di_mode);
8115         to->di_version = from ->di_version;
8116         to->di_format = from->di_format;
8117         to->di_onlink = be16_to_cpu(from->di_onlink);
8118 -       to->di_uid = be32_to_cpu(from->di_uid);
8119 -       to->di_gid = be32_to_cpu(from->di_gid);
8120 +
8121 +       uid = be32_to_cpu(from->di_uid);
8122 +       gid = be32_to_cpu(from->di_gid);
8123 +       tag = be16_to_cpu(from->di_tag);
8124 +
8125 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8126 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8127 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8128 +
8129         to->di_nlink = be32_to_cpu(from->di_nlink);
8130         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
8131         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
8132 @@ -680,21 +691,26 @@ xfs_dinode_from_disk(
8133         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8134         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8135         to->di_flags    = be16_to_cpu(from->di_flags);
8136 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8137         to->di_gen      = be32_to_cpu(from->di_gen);
8138  }
8139  
8140  void
8141  xfs_dinode_to_disk(
8142         xfs_dinode_t            *to,
8143 -       xfs_icdinode_t          *from)
8144 +       xfs_icdinode_t          *from,
8145 +       int tagged)
8146  {
8147         to->di_magic = cpu_to_be16(from->di_magic);
8148         to->di_mode = cpu_to_be16(from->di_mode);
8149         to->di_version = from ->di_version;
8150         to->di_format = from->di_format;
8151         to->di_onlink = cpu_to_be16(from->di_onlink);
8152 -       to->di_uid = cpu_to_be32(from->di_uid);
8153 -       to->di_gid = cpu_to_be32(from->di_gid);
8154 +
8155 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8156 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8157 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8158 +
8159         to->di_nlink = cpu_to_be32(from->di_nlink);
8160         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
8161         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
8162 @@ -716,12 +732,14 @@ xfs_dinode_to_disk(
8163         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8164         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8165         to->di_flags = cpu_to_be16(from->di_flags);
8166 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8167         to->di_gen = cpu_to_be32(from->di_gen);
8168  }
8169  
8170  STATIC uint
8171  _xfs_dic2xflags(
8172 -       __uint16_t              di_flags)
8173 +       __uint16_t              di_flags,
8174 +       __uint16_t              di_vflags)
8175  {
8176         uint                    flags = 0;
8177  
8178 @@ -732,6 +750,8 @@ _xfs_dic2xflags(
8179                         flags |= XFS_XFLAG_PREALLOC;
8180                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8181                         flags |= XFS_XFLAG_IMMUTABLE;
8182 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8183 +                       flags |= XFS_XFLAG_IXUNLINK;
8184                 if (di_flags & XFS_DIFLAG_APPEND)
8185                         flags |= XFS_XFLAG_APPEND;
8186                 if (di_flags & XFS_DIFLAG_SYNC)
8187 @@ -756,6 +776,10 @@ _xfs_dic2xflags(
8188                         flags |= XFS_XFLAG_FILESTREAM;
8189         }
8190  
8191 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8192 +               flags |= FS_BARRIER_FL;
8193 +       if (di_vflags & XFS_DIVFLAG_COW)
8194 +               flags |= FS_COW_FL;
8195         return flags;
8196  }
8197  
8198 @@ -765,7 +789,7 @@ xfs_ip2xflags(
8199  {
8200         xfs_icdinode_t          *dic = &ip->i_d;
8201  
8202 -       return _xfs_dic2xflags(dic->di_flags) |
8203 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8204                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8205  }
8206  
8207 @@ -773,7 +797,8 @@ uint
8208  xfs_dic2xflags(
8209         xfs_dinode_t            *dip)
8210  {
8211 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8212 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8213 +                               be16_to_cpu(dip->di_vflags)) |
8214                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8215  }
8216  
8217 @@ -806,7 +831,6 @@ xfs_iread(
8218         if (error)
8219                 return error;
8220         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8221 -
8222         /*
8223          * If we got something that isn't an inode it means someone
8224          * (nfs or dmi) has a stale handle.
8225 @@ -831,7 +855,8 @@ xfs_iread(
8226          * Otherwise, just get the truly permanent information.
8227          */
8228         if (dip->di_mode) {
8229 -               xfs_dinode_from_disk(&ip->i_d, dip);
8230 +               xfs_dinode_from_disk(&ip->i_d, dip,
8231 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8232                 error = xfs_iformat(ip, dip);
8233                 if (error)  {
8234  #ifdef DEBUG
8235 @@ -1028,6 +1053,7 @@ xfs_ialloc(
8236         ASSERT(ip->i_d.di_nlink == nlink);
8237         ip->i_d.di_uid = current_fsuid();
8238         ip->i_d.di_gid = current_fsgid();
8239 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
8240         xfs_set_projid(ip, prid);
8241         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8242  
8243 @@ -1088,6 +1114,7 @@ xfs_ialloc(
8244         ip->i_d.di_dmevmask = 0;
8245         ip->i_d.di_dmstate = 0;
8246         ip->i_d.di_flags = 0;
8247 +       ip->i_d.di_vflags = 0;
8248         flags = XFS_ILOG_CORE;
8249         switch (mode & S_IFMT) {
8250         case S_IFIFO:
8251 @@ -2106,6 +2133,7 @@ xfs_ifree(
8252         }
8253         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8254         ip->i_d.di_flags = 0;
8255 +       ip->i_d.di_vflags = 0;
8256         ip->i_d.di_dmevmask = 0;
8257         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8258         ip->i_df.if_ext_max =
8259 @@ -2976,7 +3004,8 @@ xfs_iflush_int(
8260          * because if the inode is dirty at all the core must
8261          * be.
8262          */
8263 -       xfs_dinode_to_disk(dip, &ip->i_d);
8264 +       xfs_dinode_to_disk(dip, &ip->i_d,
8265 +               mp->m_flags & XFS_MOUNT_TAGGED);
8266  
8267         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8268         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8269 diff -NurpP --minimal linux-2.6.37/fs/xfs/xfs_inode.h linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_inode.h
8270 --- linux-2.6.37/fs/xfs/xfs_inode.h     2011-01-05 21:50:28.000000000 +0100
8271 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_inode.h      2010-11-23 03:29:08.000000000 +0100
8272 @@ -136,7 +136,9 @@ typedef struct xfs_icdinode {
8273         __uint32_t      di_nlink;       /* number of links to file */
8274         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
8275         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
8276 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
8277 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
8278 +       __uint16_t      di_tag;         /* context tagging */
8279 +       __uint16_t      di_vflags;      /* vserver specific flags */
8280         __uint16_t      di_flushiter;   /* incremented on flush */
8281         xfs_ictimestamp_t di_atime;     /* time last accessed */
8282         xfs_ictimestamp_t di_mtime;     /* time last modified */
8283 @@ -527,7 +529,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8284  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8285                           struct xfs_inode *, uint);
8286  void           xfs_dinode_to_disk(struct xfs_dinode *,
8287 -                                  struct xfs_icdinode *);
8288 +                                  struct xfs_icdinode *, int);
8289  void           xfs_idestroy_fork(struct xfs_inode *, int);
8290  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8291  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8292 diff -NurpP --minimal linux-2.6.37/fs/xfs/xfs_itable.c linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_itable.c
8293 --- linux-2.6.37/fs/xfs/xfs_itable.c    2011-01-05 21:50:28.000000000 +0100
8294 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_itable.c     2010-11-23 02:09:41.000000000 +0100
8295 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
8296         buf->bs_mode = dic->di_mode;
8297         buf->bs_uid = dic->di_uid;
8298         buf->bs_gid = dic->di_gid;
8299 +       buf->bs_tag = dic->di_tag;
8300         buf->bs_size = dic->di_size;
8301  
8302         /*
8303 diff -NurpP --minimal linux-2.6.37/fs/xfs/xfs_log_recover.c linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_log_recover.c
8304 --- linux-2.6.37/fs/xfs/xfs_log_recover.c       2011-01-05 21:50:28.000000000 +0100
8305 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_log_recover.c        2010-11-23 02:09:41.000000000 +0100
8306 @@ -2451,7 +2451,8 @@ xlog_recover_do_inode_trans(
8307         }
8308  
8309         /* The core is in in-core format */
8310 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
8311 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
8312 +               mp->m_flags & XFS_MOUNT_TAGGED);
8313  
8314         /* the rest is in on-disk format */
8315         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8316 diff -NurpP --minimal linux-2.6.37/fs/xfs/xfs_mount.h linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_mount.h
8317 --- linux-2.6.37/fs/xfs/xfs_mount.h     2011-01-05 21:50:28.000000000 +0100
8318 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_mount.h      2010-11-23 02:09:41.000000000 +0100
8319 @@ -239,6 +239,7 @@ typedef struct xfs_mount {
8320                                                    allocator */
8321  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8322  
8323 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8324  
8325  /*
8326   * Default minimum read and write sizes.
8327 diff -NurpP --minimal linux-2.6.37/fs/xfs/xfs_vnodeops.c linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_vnodeops.c
8328 --- linux-2.6.37/fs/xfs/xfs_vnodeops.c  2011-01-05 21:50:28.000000000 +0100
8329 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_vnodeops.c   2011-01-06 00:07:49.000000000 +0100
8330 @@ -50,6 +50,78 @@
8331  #include "xfs_vnodeops.h"
8332  #include "xfs_trace.h"
8333  
8334 +
8335 +STATIC void
8336 +xfs_get_inode_flags(
8337 +       xfs_inode_t     *ip)
8338 +{
8339 +       struct inode    *inode = VFS_I(ip);
8340 +       unsigned int    flags = inode->i_flags;
8341 +       unsigned int    vflags = inode->i_vflags;
8342 +
8343 +       if (flags & S_IMMUTABLE)
8344 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8345 +       else
8346 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8347 +       if (flags & S_IXUNLINK)
8348 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8349 +       else
8350 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8351 +
8352 +       if (vflags & V_BARRIER)
8353 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8354 +       else
8355 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8356 +       if (vflags & V_COW)
8357 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8358 +       else
8359 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8360 +}
8361 +
8362 +int
8363 +xfs_sync_flags(
8364 +       struct inode            *inode,
8365 +       int                     flags,
8366 +       int                     vflags)
8367 +{
8368 +       struct xfs_inode        *ip = XFS_I(inode);
8369 +       struct xfs_mount        *mp = ip->i_mount;
8370 +       struct xfs_trans        *tp;
8371 +       unsigned int            lock_flags = 0;
8372 +       int                     code;
8373 +
8374 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8375 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8376 +       if (code)
8377 +               goto error_out;
8378 +
8379 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
8380 +
8381 +       xfs_trans_ijoin(tp, ip);
8382 +
8383 +       inode->i_flags = flags;
8384 +       inode->i_vflags = vflags;
8385 +       xfs_get_inode_flags(ip);
8386 +
8387 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8388 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
8389 +
8390 +       XFS_STATS_INC(xs_ig_attrchg);
8391 +
8392 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8393 +               xfs_trans_set_sync(tp);
8394 +       code = xfs_trans_commit(tp, 0);
8395 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
8396 +       return code;
8397 +
8398 +error_out:
8399 +       xfs_trans_cancel(tp, 0);
8400 +       if (lock_flags)
8401 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8402 +       return code;
8403 +}
8404 +
8405 +
8406  int
8407  xfs_setattr(
8408         struct xfs_inode        *ip,
8409 @@ -65,6 +137,7 @@ xfs_setattr(
8410         uint                    commit_flags=0;
8411         uid_t                   uid=0, iuid=0;
8412         gid_t                   gid=0, igid=0;
8413 +       tag_t                   tag=0, itag=0;
8414         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8415         int                     need_iolock = 1;
8416  
8417 @@ -147,7 +220,7 @@ xfs_setattr(
8418         /*
8419          * Change file ownership.  Must be the owner or privileged.
8420          */
8421 -       if (mask & (ATTR_UID|ATTR_GID)) {
8422 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8423                 /*
8424                  * These IDs could have changed since we last looked at them.
8425                  * But, we're assured that if the ownership did change
8426 @@ -156,8 +229,10 @@ xfs_setattr(
8427                  */
8428                 iuid = ip->i_d.di_uid;
8429                 igid = ip->i_d.di_gid;
8430 +               itag = ip->i_d.di_tag;
8431                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8432                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8433 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8434  
8435                 /*
8436                  * Do a quota reservation only if uid/gid is actually
8437 @@ -165,7 +240,8 @@ xfs_setattr(
8438                  */
8439                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8440                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8441 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8442 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8443 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8444                         ASSERT(tp);
8445                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8446                                                 capable(CAP_FOWNER) ?
8447 @@ -329,7 +405,7 @@ xfs_setattr(
8448         /*
8449          * Change file ownership.  Must be the owner or privileged.
8450          */
8451 -       if (mask & (ATTR_UID|ATTR_GID)) {
8452 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8453                 /*
8454                  * CAP_FSETID overrides the following restrictions:
8455                  *
8456 @@ -345,6 +421,10 @@ xfs_setattr(
8457                  * Change the ownerships and register quota modifications
8458                  * in the transaction.
8459                  */
8460 +               if (itag != tag) {
8461 +                       ip->i_d.di_tag = tag;
8462 +                       inode->i_tag = tag;
8463 +               }
8464                 if (iuid != uid) {
8465                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8466                                 ASSERT(mask & ATTR_UID);
8467 diff -NurpP --minimal linux-2.6.37/fs/xfs/xfs_vnodeops.h linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_vnodeops.h
8468 --- linux-2.6.37/fs/xfs/xfs_vnodeops.h  2011-01-05 21:50:28.000000000 +0100
8469 +++ linux-2.6.37-vs2.3.0.37-rc3/fs/xfs/xfs_vnodeops.h   2010-11-23 02:09:41.000000000 +0100
8470 @@ -13,6 +13,7 @@ struct xfs_inode;
8471  struct xfs_iomap;
8472  
8473  
8474 +int xfs_sync_xflags(struct xfs_inode *ip);
8475  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8476  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8477  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8478 diff -NurpP --minimal linux-2.6.37/include/asm-generic/tlb.h linux-2.6.37-vs2.3.0.37-rc3/include/asm-generic/tlb.h
8479 --- linux-2.6.37/include/asm-generic/tlb.h      2009-09-10 15:26:24.000000000 +0200
8480 +++ linux-2.6.37-vs2.3.0.37-rc3/include/asm-generic/tlb.h       2010-11-23 02:09:41.000000000 +0100
8481 @@ -14,6 +14,7 @@
8482  #define _ASM_GENERIC__TLB_H
8483  
8484  #include <linux/swap.h>
8485 +#include <linux/vs_memory.h>
8486  #include <asm/pgalloc.h>
8487  #include <asm/tlbflush.h>
8488  
8489 diff -NurpP --minimal linux-2.6.37/include/linux/capability.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/capability.h
8490 --- linux-2.6.37/include/linux/capability.h     2010-10-21 13:07:52.000000000 +0200
8491 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/capability.h      2011-01-06 01:44:43.000000000 +0100
8492 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
8493     arbitrary SCSI commands */
8494  /* Allow setting encryption key on loopback filesystem */
8495  /* Allow setting zone reclaim policy */
8496 +/* Allow the selection of a security context */
8497  
8498  #define CAP_SYS_ADMIN        21
8499  
8500 @@ -354,7 +355,12 @@ struct cpu_vfs_cap_data {
8501  
8502  #define CAP_LAST_CAP         CAP_MAC_ADMIN
8503  
8504 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8505 +/* Allow context manipulations */
8506 +/* Allow changing context info on files */
8507 +
8508 +#define CAP_CONTEXT         63
8509 +
8510 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
8511  
8512  /*
8513   * Bit location of each capability (used by user-space library and kernel)
8514 diff -NurpP --minimal linux-2.6.37/include/linux/cred.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/cred.h
8515 --- linux-2.6.37/include/linux/cred.h   2011-01-05 21:50:29.000000000 +0100
8516 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/cred.h    2011-01-31 21:05:40.000000000 +0100
8517 @@ -155,6 +155,7 @@ extern void exit_creds(struct task_struc
8518  extern int copy_creds(struct task_struct *, unsigned long);
8519  extern const struct cred *get_task_cred(struct task_struct *);
8520  extern struct cred *cred_alloc_blank(void);
8521 +extern struct cred *__prepare_creds(const struct cred *);
8522  extern struct cred *prepare_creds(void);
8523  extern struct cred *prepare_exec_creds(void);
8524  extern int commit_creds(struct cred *);
8525 @@ -208,6 +209,31 @@ static inline void validate_process_cred
8526  }
8527  #endif
8528  
8529 +static inline void set_cred_subscribers(struct cred *cred, int n)
8530 +{
8531 +#ifdef CONFIG_DEBUG_CREDENTIALS
8532 +       atomic_set(&cred->subscribers, n);
8533 +#endif
8534 +}
8535 +
8536 +static inline int read_cred_subscribers(const struct cred *cred)
8537 +{
8538 +#ifdef CONFIG_DEBUG_CREDENTIALS
8539 +       return atomic_read(&cred->subscribers);
8540 +#else
8541 +       return 0;
8542 +#endif
8543 +}
8544 +
8545 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8546 +{
8547 +#ifdef CONFIG_DEBUG_CREDENTIALS
8548 +       struct cred *cred = (struct cred *) _cred;
8549 +
8550 +       atomic_add(n, &cred->subscribers);
8551 +#endif
8552 +}
8553 +
8554  /**
8555   * get_new_cred - Get a reference on a new set of credentials
8556   * @cred: The new credentials to reference
8557 diff -NurpP --minimal linux-2.6.37/include/linux/devpts_fs.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/devpts_fs.h
8558 --- linux-2.6.37/include/linux/devpts_fs.h      2008-12-25 00:26:37.000000000 +0100
8559 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/devpts_fs.h       2010-11-23 02:09:41.000000000 +0100
8560 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8561  
8562  #endif
8563  
8564 -
8565  #endif /* _LINUX_DEVPTS_FS_H */
8566 diff -NurpP --minimal linux-2.6.37/include/linux/ext2_fs.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/ext2_fs.h
8567 --- linux-2.6.37/include/linux/ext2_fs.h        2010-02-25 11:52:07.000000000 +0100
8568 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/ext2_fs.h 2010-11-23 02:09:41.000000000 +0100
8569 @@ -189,8 +189,12 @@ struct ext2_group_desc
8570  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8571  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8572  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8573 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8574  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8575  
8576 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8577 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8578 +
8579  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8580  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8581  
8582 @@ -274,7 +278,8 @@ struct ext2_inode {
8583                         __u16   i_pad1;
8584                         __le16  l_i_uid_high;   /* these 2 fields    */
8585                         __le16  l_i_gid_high;   /* were reserved2[0] */
8586 -                       __u32   l_i_reserved2;
8587 +                       __le16  l_i_tag;        /* Context Tag */
8588 +                       __u16   l_i_reserved2;
8589                 } linux2;
8590                 struct {
8591                         __u8    h_i_frag;       /* Fragment number */
8592 @@ -303,6 +308,7 @@ struct ext2_inode {
8593  #define i_gid_low      i_gid
8594  #define i_uid_high     osd2.linux2.l_i_uid_high
8595  #define i_gid_high     osd2.linux2.l_i_gid_high
8596 +#define i_raw_tag      osd2.linux2.l_i_tag
8597  #define i_reserved2    osd2.linux2.l_i_reserved2
8598  #endif
8599  
8600 @@ -347,6 +353,7 @@ struct ext2_inode {
8601  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8602  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8603  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8604 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8605  
8606  
8607  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8608 diff -NurpP --minimal linux-2.6.37/include/linux/ext3_fs.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/ext3_fs.h
8609 --- linux-2.6.37/include/linux/ext3_fs.h        2010-10-21 13:07:53.000000000 +0200
8610 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/ext3_fs.h 2010-11-23 02:09:41.000000000 +0100
8611 @@ -173,10 +173,14 @@ struct ext3_group_desc
8612  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8613  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8614  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8615 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8616  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8617  
8618 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8619 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8620 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8621 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8622 +
8623 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8624 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8625  
8626  /* Flags that should be inherited by new inodes from their parent. */
8627  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8628 @@ -312,7 +316,8 @@ struct ext3_inode {
8629                         __u16   i_pad1;
8630                         __le16  l_i_uid_high;   /* these 2 fields    */
8631                         __le16  l_i_gid_high;   /* were reserved2[0] */
8632 -                       __u32   l_i_reserved2;
8633 +                       __le16  l_i_tag;        /* Context Tag */
8634 +                       __u16   l_i_reserved2;
8635                 } linux2;
8636                 struct {
8637                         __u8    h_i_frag;       /* Fragment number */
8638 @@ -343,6 +348,7 @@ struct ext3_inode {
8639  #define i_gid_low      i_gid
8640  #define i_uid_high     osd2.linux2.l_i_uid_high
8641  #define i_gid_high     osd2.linux2.l_i_gid_high
8642 +#define i_raw_tag      osd2.linux2.l_i_tag
8643  #define i_reserved2    osd2.linux2.l_i_reserved2
8644  
8645  #elif defined(__GNU__)
8646 @@ -405,6 +411,7 @@ struct ext3_inode {
8647  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8648  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8649                                                   * error in ordered mode */
8650 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8651  
8652  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8653  #ifndef _LINUX_EXT2_FS_H
8654 @@ -908,6 +915,7 @@ extern void ext3_get_inode_flags(struct 
8655  extern void ext3_set_aops(struct inode *inode);
8656  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8657                        u64 start, u64 len);
8658 +extern int ext3_sync_flags(struct inode *, int, int);
8659  
8660  /* ioctl.c */
8661  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8662 diff -NurpP --minimal linux-2.6.37/include/linux/fs.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/fs.h
8663 --- linux-2.6.37/include/linux/fs.h     2011-01-05 21:50:30.000000000 +0100
8664 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/fs.h      2011-01-05 22:30:40.000000000 +0100
8665 @@ -214,6 +214,9 @@ struct inodes_stat_t {
8666  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8667  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8668  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8669 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8670 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8671 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8672  #define MS_BORN                (1<<29)
8673  #define MS_ACTIVE      (1<<30)
8674  #define MS_NOUSER      (1<<31)
8675 @@ -242,6 +245,14 @@ struct inodes_stat_t {
8676  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8677  #define S_PRIVATE      512     /* Inode is fs-internal */
8678  #define S_IMA          1024    /* Inode has an associated IMA struct */
8679 +#define S_IXUNLINK     2048    /* Immutable Invert on unlink */
8680 +
8681 +/* Linux-VServer related Inode flags */
8682 +
8683 +#define V_VALID                1
8684 +#define V_XATTR                2
8685 +#define V_BARRIER      4       /* Barrier for chroot() */
8686 +#define V_COW          8       /* Copy on Write */
8687  
8688  /*
8689   * Note that nosuid etc flags are inode-specific: setting some file-system
8690 @@ -264,12 +275,15 @@ struct inodes_stat_t {
8691  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8692                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8693  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8694 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8695 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8696 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8697 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8698 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8699  
8700  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8701  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8702  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8703 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8704 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8705  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8706  
8707  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8708 @@ -278,6 +292,16 @@ struct inodes_stat_t {
8709  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8710  #define IS_IMA(inode)          ((inode)->i_flags & S_IMA)
8711  
8712 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8713 +
8714 +#ifdef CONFIG_VSERVER_COWBL
8715 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8716 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8717 +#else
8718 +#  define IS_COW(inode)                (0)
8719 +#  define IS_COW_LINK(inode)   (0)
8720 +#endif
8721 +
8722  /* the read-only stuff doesn't really belong here, but any other place is
8723     probably as bad and I don't want to create yet another include file. */
8724  
8725 @@ -362,11 +386,14 @@ struct inodes_stat_t {
8726  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8727  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8728  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8729 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8730  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8731  
8732 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8733 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8734 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8735 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8736  
8737 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8738 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8739  
8740  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8741  #define SYNC_FILE_RANGE_WRITE          2
8742 @@ -446,6 +473,7 @@ typedef void (dio_iodone_t)(struct kiocb
8743  #define ATTR_KILL_PRIV (1 << 14)
8744  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8745  #define ATTR_TIMES_SET (1 << 16)
8746 +#define ATTR_TAG       (1 << 17)
8747  
8748  /*
8749   * This is the Inode Attributes structure, used for notify_change().  It
8750 @@ -461,6 +489,7 @@ struct iattr {
8751         umode_t         ia_mode;
8752         uid_t           ia_uid;
8753         gid_t           ia_gid;
8754 +       tag_t           ia_tag;
8755         loff_t          ia_size;
8756         struct timespec ia_atime;
8757         struct timespec ia_mtime;
8758 @@ -474,6 +503,9 @@ struct iattr {
8759         struct file     *ia_file;
8760  };
8761  
8762 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8763 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8764 +
8765  /*
8766   * Includes for diskquotas.
8767   */
8768 @@ -743,7 +775,9 @@ struct inode {
8769         unsigned int            i_nlink;
8770         uid_t                   i_uid;
8771         gid_t                   i_gid;
8772 +       tag_t                   i_tag;
8773         dev_t                   i_rdev;
8774 +       dev_t                   i_mdev;
8775         unsigned int            i_blkbits;
8776         u64                     i_version;
8777         loff_t                  i_size;
8778 @@ -785,7 +819,8 @@ struct inode {
8779         unsigned long           i_state;
8780         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8781  
8782 -       unsigned int            i_flags;
8783 +       unsigned short          i_flags;
8784 +       unsigned short          i_vflags;
8785  
8786  #ifdef CONFIG_IMA
8787         /* protected by i_lock */
8788 @@ -882,12 +917,12 @@ static inline void i_size_write(struct i
8789  
8790  static inline unsigned iminor(const struct inode *inode)
8791  {
8792 -       return MINOR(inode->i_rdev);
8793 +       return MINOR(inode->i_mdev);
8794  }
8795  
8796  static inline unsigned imajor(const struct inode *inode)
8797  {
8798 -       return MAJOR(inode->i_rdev);
8799 +       return MAJOR(inode->i_mdev);
8800  }
8801  
8802  extern struct block_device *I_BDEV(struct inode *inode);
8803 @@ -949,6 +984,7 @@ struct file {
8804         loff_t                  f_pos;
8805         struct fown_struct      f_owner;
8806         const struct cred       *f_cred;
8807 +       xid_t                   f_xid;
8808         struct file_ra_state    f_ra;
8809  
8810         u64                     f_version;
8811 @@ -1087,6 +1123,7 @@ struct file_lock {
8812         struct file *fl_file;
8813         loff_t fl_start;
8814         loff_t fl_end;
8815 +       xid_t fl_xid;
8816  
8817         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8818         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8819 @@ -1568,6 +1605,7 @@ struct inode_operations {
8820         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8821         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8822         int (*removexattr) (struct dentry *, const char *);
8823 +       int (*sync_flags) (struct inode *, int, int);
8824         void (*truncate_range)(struct inode *, loff_t, loff_t);
8825         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8826                           loff_t len);
8827 @@ -1588,6 +1626,7 @@ extern ssize_t vfs_readv(struct file *, 
8828                 unsigned long, loff_t *);
8829  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8830                 unsigned long, loff_t *);
8831 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8832  
8833  struct super_operations {
8834         struct inode *(*alloc_inode)(struct super_block *sb);
8835 @@ -2389,6 +2428,7 @@ extern int dcache_dir_open(struct inode 
8836  extern int dcache_dir_close(struct inode *, struct file *);
8837  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8838  extern int dcache_readdir(struct file *, void *, filldir_t);
8839 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8840  extern int simple_setattr(struct dentry *, struct iattr *);
8841  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8842  extern int simple_statfs(struct dentry *, struct kstatfs *);
8843 diff -NurpP --minimal linux-2.6.37/include/linux/gfs2_ondisk.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/gfs2_ondisk.h
8844 --- linux-2.6.37/include/linux/gfs2_ondisk.h    2010-07-07 18:31:55.000000000 +0200
8845 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/gfs2_ondisk.h     2010-11-23 02:09:41.000000000 +0100
8846 @@ -211,6 +211,9 @@ enum {
8847         gfs2fl_NoAtime          = 7,
8848         gfs2fl_Sync             = 8,
8849         gfs2fl_System           = 9,
8850 +       gfs2fl_IXUnlink         = 16,
8851 +       gfs2fl_Barrier          = 17,
8852 +       gfs2fl_Cow              = 18,
8853         gfs2fl_TruncInProg      = 29,
8854         gfs2fl_InheritDirectio  = 30,
8855         gfs2fl_InheritJdata     = 31,
8856 @@ -227,6 +230,9 @@ enum {
8857  #define GFS2_DIF_NOATIME               0x00000080
8858  #define GFS2_DIF_SYNC                  0x00000100
8859  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8860 +#define GFS2_DIF_IXUNLINK              0x00010000
8861 +#define GFS2_DIF_BARRIER               0x00020000
8862 +#define GFS2_DIF_COW                   0x00040000
8863  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8864  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8865  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8866 diff -NurpP --minimal linux-2.6.37/include/linux/if_tun.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/if_tun.h
8867 --- linux-2.6.37/include/linux/if_tun.h 2010-08-02 16:52:54.000000000 +0200
8868 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/if_tun.h  2010-11-23 02:09:41.000000000 +0100
8869 @@ -53,6 +53,7 @@
8870  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8871  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8872  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8873 +#define TUNSETNID     _IOW('T', 217, int)
8874  
8875  /* TUNSETIFF ifr flags */
8876  #define IFF_TUN                0x0001
8877 diff -NurpP --minimal linux-2.6.37/include/linux/init_task.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/init_task.h
8878 --- linux-2.6.37/include/linux/init_task.h      2011-01-05 21:50:30.000000000 +0100
8879 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/init_task.h       2010-11-23 02:09:41.000000000 +0100
8880 @@ -178,6 +178,10 @@ extern struct cred init_cred;
8881         INIT_FTRACE_GRAPH                                               \
8882         INIT_TRACE_RECURSION                                            \
8883         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8884 +       .xid            = 0,                                            \
8885 +       .vx_info        = NULL,                                         \
8886 +       .nid            = 0,                                            \
8887 +       .nx_info        = NULL,                                         \
8888  }
8889  
8890  
8891 diff -NurpP --minimal linux-2.6.37/include/linux/ipc.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/ipc.h
8892 --- linux-2.6.37/include/linux/ipc.h    2009-12-03 20:02:55.000000000 +0100
8893 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/ipc.h     2010-11-23 02:09:41.000000000 +0100
8894 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8895         key_t           key;
8896         uid_t           uid;
8897         gid_t           gid;
8898 +       xid_t           xid;
8899         uid_t           cuid;
8900         gid_t           cgid;
8901         mode_t          mode; 
8902 diff -NurpP --minimal linux-2.6.37/include/linux/Kbuild linux-2.6.37-vs2.3.0.37-rc3/include/linux/Kbuild
8903 --- linux-2.6.37/include/linux/Kbuild   2011-01-05 21:50:28.000000000 +0100
8904 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/Kbuild    2010-11-23 02:09:41.000000000 +0100
8905 @@ -15,6 +15,7 @@ header-y += netfilter_bridge/
8906  header-y += netfilter_ipv4/
8907  header-y += netfilter_ipv6/
8908  header-y += usb/
8909 +header-y += vserver/
8910  header-y += wimax/
8911  
8912  objhdr-y += version.h
8913 diff -NurpP --minimal linux-2.6.37/include/linux/loop.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/loop.h
8914 --- linux-2.6.37/include/linux/loop.h   2009-09-10 15:26:25.000000000 +0200
8915 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/loop.h    2010-11-23 02:09:41.000000000 +0100
8916 @@ -45,6 +45,7 @@ struct loop_device {
8917         struct loop_func_table *lo_encryption;
8918         __u32           lo_init[2];
8919         uid_t           lo_key_owner;   /* Who set the key */
8920 +       xid_t           lo_xid;
8921         int             (*ioctl)(struct loop_device *, int cmd, 
8922                                  unsigned long arg); 
8923  
8924 diff -NurpP --minimal linux-2.6.37/include/linux/magic.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/magic.h
8925 --- linux-2.6.37/include/linux/magic.h  2011-01-05 21:50:30.000000000 +0100
8926 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/magic.h   2010-11-23 02:09:41.000000000 +0100
8927 @@ -3,7 +3,7 @@
8928  
8929  #define ADFS_SUPER_MAGIC       0xadf5
8930  #define AFFS_SUPER_MAGIC       0xadff
8931 -#define AFS_SUPER_MAGIC                0x5346414F
8932 +#define AFS_SUPER_MAGIC                0x5346414F
8933  #define AUTOFS_SUPER_MAGIC     0x0187
8934  #define CODA_SUPER_MAGIC       0x73757245
8935  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8936 @@ -38,6 +38,7 @@
8937  #define NFS_SUPER_MAGIC                0x6969
8938  #define OPENPROM_SUPER_MAGIC   0x9fa1
8939  #define PROC_SUPER_MAGIC       0x9fa0
8940 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8941  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8942  
8943  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8944 diff -NurpP --minimal linux-2.6.37/include/linux/major.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/major.h
8945 --- linux-2.6.37/include/linux/major.h  2009-09-10 15:26:25.000000000 +0200
8946 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/major.h   2010-11-23 02:09:41.000000000 +0100
8947 @@ -15,6 +15,7 @@
8948  #define HD_MAJOR               IDE0_MAJOR
8949  #define PTY_SLAVE_MAJOR                3
8950  #define TTY_MAJOR              4
8951 +#define VROOT_MAJOR            4
8952  #define TTYAUX_MAJOR           5
8953  #define LP_MAJOR               6
8954  #define VCS_MAJOR              7
8955 diff -NurpP --minimal linux-2.6.37/include/linux/memcontrol.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/memcontrol.h
8956 --- linux-2.6.37/include/linux/memcontrol.h     2010-10-21 13:07:53.000000000 +0200
8957 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/memcontrol.h      2010-11-23 02:09:41.000000000 +0100
8958 @@ -77,6 +77,13 @@ int task_in_mem_cgroup(struct task_struc
8959  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
8960  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8961  
8962 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8963 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8964 +
8965 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8966 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8967 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8968 +
8969  static inline
8970  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8971  {
8972 diff -NurpP --minimal linux-2.6.37/include/linux/mm_types.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/mm_types.h
8973 --- linux-2.6.37/include/linux/mm_types.h       2011-01-05 21:50:31.000000000 +0100
8974 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/mm_types.h        2010-11-23 02:09:41.000000000 +0100
8975 @@ -269,6 +269,7 @@ struct mm_struct {
8976  
8977         /* Architecture-specific MM context */
8978         mm_context_t context;
8979 +       struct vx_info *mm_vx_info;
8980  
8981         /* Swap token stuff */
8982         /*
8983 diff -NurpP --minimal linux-2.6.37/include/linux/mount.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/mount.h
8984 --- linux-2.6.37/include/linux/mount.h  2010-10-21 13:07:53.000000000 +0200
8985 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/mount.h   2010-11-23 02:09:41.000000000 +0100
8986 @@ -46,6 +46,9 @@ struct mnt_namespace;
8987  
8988  #define MNT_INTERNAL   0x4000
8989  
8990 +#define MNT_TAGID      0x10000
8991 +#define MNT_NOTAG      0x20000
8992 +
8993  struct vfsmount {
8994         struct list_head mnt_hash;
8995         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8996 @@ -84,6 +87,7 @@ struct vfsmount {
8997  #else
8998         int mnt_writers;
8999  #endif
9000 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9001  };
9002  
9003  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
9004 diff -NurpP --minimal linux-2.6.37/include/linux/net.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/net.h
9005 --- linux-2.6.37/include/linux/net.h    2011-01-05 21:50:31.000000000 +0100
9006 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/net.h     2010-11-23 02:09:41.000000000 +0100
9007 @@ -71,6 +71,7 @@ struct net;
9008  #define SOCK_NOSPACE           2
9009  #define SOCK_PASSCRED          3
9010  #define SOCK_PASSSEC           4
9011 +#define SOCK_USER_SOCKET       5
9012  
9013  #ifndef ARCH_HAS_SOCKET_TYPES
9014  /**
9015 diff -NurpP --minimal linux-2.6.37/include/linux/nfs_mount.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/nfs_mount.h
9016 --- linux-2.6.37/include/linux/nfs_mount.h      2011-01-05 21:50:31.000000000 +0100
9017 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/nfs_mount.h       2010-11-23 02:09:41.000000000 +0100
9018 @@ -63,7 +63,8 @@ struct nfs_mount_data {
9019  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9020  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9021  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9022 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9023 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9024 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9025  
9026  /* The following are for internal use only */
9027  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9028 diff -NurpP --minimal linux-2.6.37/include/linux/nsproxy.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/nsproxy.h
9029 --- linux-2.6.37/include/linux/nsproxy.h        2009-06-11 17:13:17.000000000 +0200
9030 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/nsproxy.h 2010-11-23 02:09:41.000000000 +0100
9031 @@ -3,6 +3,7 @@
9032  
9033  #include <linux/spinlock.h>
9034  #include <linux/sched.h>
9035 +#include <linux/vserver/debug.h>
9036  
9037  struct mnt_namespace;
9038  struct uts_namespace;
9039 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9040  }
9041  
9042  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9043 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9044  void exit_task_namespaces(struct task_struct *tsk);
9045  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9046  void free_nsproxy(struct nsproxy *ns);
9047  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9048         struct fs_struct *);
9049  
9050 -static inline void put_nsproxy(struct nsproxy *ns)
9051 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9052 +
9053 +static inline void __get_nsproxy(struct nsproxy *ns,
9054 +       const char *_file, int _line)
9055  {
9056 -       if (atomic_dec_and_test(&ns->count)) {
9057 -               free_nsproxy(ns);
9058 -       }
9059 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9060 +               ns, atomic_read(&ns->count), _file, _line);
9061 +       atomic_inc(&ns->count);
9062  }
9063  
9064 -static inline void get_nsproxy(struct nsproxy *ns)
9065 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9066 +
9067 +static inline void __put_nsproxy(struct nsproxy *ns,
9068 +       const char *_file, int _line)
9069  {
9070 -       atomic_inc(&ns->count);
9071 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9072 +               ns, atomic_read(&ns->count), _file, _line);
9073 +       if (atomic_dec_and_test(&ns->count)) {
9074 +               free_nsproxy(ns);
9075 +       }
9076  }
9077  
9078  #ifdef CONFIG_CGROUP_NS
9079 diff -NurpP --minimal linux-2.6.37/include/linux/pid.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/pid.h
9080 --- linux-2.6.37/include/linux/pid.h    2009-03-24 14:22:43.000000000 +0100
9081 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/pid.h     2010-11-23 02:09:41.000000000 +0100
9082 @@ -8,7 +8,8 @@ enum pid_type
9083         PIDTYPE_PID,
9084         PIDTYPE_PGID,
9085         PIDTYPE_SID,
9086 -       PIDTYPE_MAX
9087 +       PIDTYPE_MAX,
9088 +       PIDTYPE_REALPID
9089  };
9090  
9091  /*
9092 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9093  }
9094  
9095  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9096 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9097  pid_t pid_vnr(struct pid *pid);
9098  
9099  #define do_each_pid_task(pid, type, task)                              \
9100 diff -NurpP --minimal linux-2.6.37/include/linux/proc_fs.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/proc_fs.h
9101 --- linux-2.6.37/include/linux/proc_fs.h        2009-12-03 20:02:56.000000000 +0100
9102 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/proc_fs.h 2010-11-23 02:09:41.000000000 +0100
9103 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9104         nlink_t nlink;
9105         uid_t uid;
9106         gid_t gid;
9107 +       int vx_flags;
9108         loff_t size;
9109         const struct inode_operations *proc_iops;
9110         /*
9111 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9112  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9113  #endif
9114  
9115 +struct vx_info;
9116 +struct nx_info;
9117 +
9118  union proc_op {
9119         int (*proc_get_link)(struct inode *, struct path *);
9120         int (*proc_read)(struct task_struct *task, char *page);
9121         int (*proc_show)(struct seq_file *m,
9122                 struct pid_namespace *ns, struct pid *pid,
9123                 struct task_struct *task);
9124 +       int (*proc_vs_read)(char *page);
9125 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9126 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9127  };
9128  
9129  struct ctl_table_header;
9130 @@ -263,6 +270,7 @@ struct ctl_table;
9131  
9132  struct proc_inode {
9133         struct pid *pid;
9134 +       int vx_flags;
9135         int fd;
9136         union proc_op op;
9137         struct proc_dir_entry *pde;
9138 diff -NurpP --minimal linux-2.6.37/include/linux/quotaops.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/quotaops.h
9139 --- linux-2.6.37/include/linux/quotaops.h       2010-10-21 13:07:54.000000000 +0200
9140 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/quotaops.h        2010-11-23 02:09:41.000000000 +0100
9141 @@ -8,6 +8,7 @@
9142  #define _LINUX_QUOTAOPS_
9143  
9144  #include <linux/fs.h>
9145 +#include <linux/vs_dlimit.h>
9146  
9147  #define DQUOT_SPACE_WARN       0x1
9148  #define DQUOT_SPACE_RESERVE    0x2
9149 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
9150  
9151  static inline int dquot_alloc_inode(const struct inode *inode)
9152  {
9153 -       return 0;
9154 +       return dl_alloc_inode(inode);
9155  }
9156  
9157  static inline void dquot_free_inode(const struct inode *inode)
9158  {
9159 +       dl_free_inode(inode);
9160  }
9161  
9162  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
9163 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct 
9164  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
9165                 int flags)
9166  {
9167 +       int ret = 0;
9168 +
9169 +       if ((ret = dl_alloc_space(inode, number)))
9170 +               return ret;
9171         if (!(flags & DQUOT_SPACE_RESERVE))
9172                 inode_add_bytes(inode, number);
9173         return 0;
9174 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
9175  {
9176         if (!(flags & DQUOT_SPACE_RESERVE))
9177                 inode_sub_bytes(inode, number);
9178 +       dl_free_space(inode, number);
9179  }
9180  
9181  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
9182 diff -NurpP --minimal linux-2.6.37/include/linux/reboot.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/reboot.h
9183 --- linux-2.6.37/include/linux/reboot.h 2010-07-07 18:31:56.000000000 +0200
9184 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/reboot.h  2010-11-23 02:09:41.000000000 +0100
9185 @@ -33,6 +33,7 @@
9186  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9187  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9188  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9189 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9190  
9191  
9192  #ifdef __KERNEL__
9193 diff -NurpP --minimal linux-2.6.37/include/linux/reiserfs_fs.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/reiserfs_fs.h
9194 --- linux-2.6.37/include/linux/reiserfs_fs.h    2011-01-05 21:50:32.000000000 +0100
9195 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/reiserfs_fs.h     2010-11-23 02:09:41.000000000 +0100
9196 @@ -976,6 +976,11 @@ struct stat_data_v1 {
9197  #define REISERFS_COMPR_FL     FS_COMPR_FL
9198  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9199  
9200 +/* unfortunately reiserfs sdattr is only 16 bit */
9201 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9202 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9203 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9204 +
9205  /* persistent flags that file inherits from the parent directory */
9206  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9207                                 REISERFS_SYNC_FL |      \
9208 @@ -985,6 +990,9 @@ struct stat_data_v1 {
9209                                 REISERFS_COMPR_FL |     \
9210                                 REISERFS_NOTAIL_FL )
9211  
9212 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9213 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9214 +
9215  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9216     address blocks) */
9217  struct stat_data {
9218 @@ -2070,6 +2078,7 @@ static inline void reiserfs_update_sd(st
9219  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9220  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9221  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9222 +int reiserfs_sync_flags(struct inode *inode, int, int);
9223  
9224  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
9225  
9226 diff -NurpP --minimal linux-2.6.37/include/linux/reiserfs_fs_sb.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/reiserfs_fs_sb.h
9227 --- linux-2.6.37/include/linux/reiserfs_fs_sb.h 2010-02-25 11:52:07.000000000 +0100
9228 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/reiserfs_fs_sb.h  2010-11-23 02:09:41.000000000 +0100
9229 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9230         REISERFS_EXPOSE_PRIVROOT,
9231         REISERFS_BARRIER_NONE,
9232         REISERFS_BARRIER_FLUSH,
9233 +       REISERFS_TAGGED,
9234  
9235         /* Actions on error */
9236         REISERFS_ERROR_PANIC,
9237 diff -NurpP --minimal linux-2.6.37/include/linux/sched.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/sched.h
9238 --- linux-2.6.37/include/linux/sched.h  2011-01-05 21:50:32.000000000 +0100
9239 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/sched.h   2011-01-05 22:30:40.000000000 +0100
9240 @@ -1357,6 +1357,14 @@ struct task_struct {
9241  #endif
9242         seccomp_t seccomp;
9243  
9244 +/* vserver context data */
9245 +       struct vx_info *vx_info;
9246 +       struct nx_info *nx_info;
9247 +
9248 +       xid_t xid;
9249 +       nid_t nid;
9250 +       tag_t tag;
9251 +
9252  /* Thread group tracking */
9253         u32 parent_exec_id;
9254         u32 self_exec_id;
9255 @@ -1591,6 +1599,11 @@ struct pid_namespace;
9256  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9257                         struct pid_namespace *ns);
9258  
9259 +#include <linux/vserver/base.h>
9260 +#include <linux/vserver/context.h>
9261 +#include <linux/vserver/debug.h>
9262 +#include <linux/vserver/pid.h>
9263 +
9264  static inline pid_t task_pid_nr(struct task_struct *tsk)
9265  {
9266         return tsk->pid;
9267 @@ -1604,7 +1617,8 @@ static inline pid_t task_pid_nr_ns(struc
9268  
9269  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9270  {
9271 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9272 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9273 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9274  }
9275  
9276  
9277 @@ -1617,7 +1631,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9278  
9279  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9280  {
9281 -       return pid_vnr(task_tgid(tsk));
9282 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9283  }
9284  
9285  
9286 diff -NurpP --minimal linux-2.6.37/include/linux/shmem_fs.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/shmem_fs.h
9287 --- linux-2.6.37/include/linux/shmem_fs.h       2010-10-21 13:07:55.000000000 +0200
9288 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/shmem_fs.h        2010-11-23 02:09:41.000000000 +0100
9289 @@ -9,6 +9,9 @@
9290  
9291  #define SHMEM_NR_DIRECT 16
9292  
9293 +#define TMPFS_SUPER_MAGIC      0x01021994
9294 +
9295 +
9296  struct shmem_inode_info {
9297         spinlock_t              lock;
9298         unsigned long           flags;
9299 diff -NurpP --minimal linux-2.6.37/include/linux/stat.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/stat.h
9300 --- linux-2.6.37/include/linux/stat.h   2008-12-25 00:26:37.000000000 +0100
9301 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/stat.h    2010-11-23 02:09:41.000000000 +0100
9302 @@ -66,6 +66,7 @@ struct kstat {
9303         unsigned int    nlink;
9304         uid_t           uid;
9305         gid_t           gid;
9306 +       tag_t           tag;
9307         dev_t           rdev;
9308         loff_t          size;
9309         struct timespec  atime;
9310 diff -NurpP --minimal linux-2.6.37/include/linux/sunrpc/auth.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/sunrpc/auth.h
9311 --- linux-2.6.37/include/linux/sunrpc/auth.h    2011-01-05 21:50:33.000000000 +0100
9312 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/sunrpc/auth.h     2010-11-23 02:09:41.000000000 +0100
9313 @@ -25,6 +25,7 @@
9314  struct auth_cred {
9315         uid_t   uid;
9316         gid_t   gid;
9317 +       tag_t   tag;
9318         struct group_info *group_info;
9319         unsigned char machine_cred : 1;
9320  };
9321 diff -NurpP --minimal linux-2.6.37/include/linux/sunrpc/clnt.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/sunrpc/clnt.h
9322 --- linux-2.6.37/include/linux/sunrpc/clnt.h    2011-01-05 21:50:33.000000000 +0100
9323 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/sunrpc/clnt.h     2010-11-23 02:09:41.000000000 +0100
9324 @@ -49,7 +49,8 @@ struct rpc_clnt {
9325         unsigned int            cl_softrtry : 1,/* soft timeouts */
9326                                 cl_discrtry : 1,/* disconnect before retry */
9327                                 cl_autobind : 1,/* use getport() */
9328 -                               cl_chatty   : 1;/* be verbose */
9329 +                               cl_chatty   : 1,/* be verbose */
9330 +                               cl_tag      : 1;/* context tagging */
9331  
9332         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9333         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9334 diff -NurpP --minimal linux-2.6.37/include/linux/syscalls.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/syscalls.h
9335 --- linux-2.6.37/include/linux/syscalls.h       2011-01-05 21:50:34.000000000 +0100
9336 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/syscalls.h        2010-11-23 02:09:41.000000000 +0100
9337 @@ -478,6 +478,8 @@ asmlinkage long sys_symlink(const char _
9338  asmlinkage long sys_unlink(const char __user *pathname);
9339  asmlinkage long sys_rename(const char __user *oldname,
9340                                 const char __user *newname);
9341 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9342 +                               umode_t mode);
9343  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9344  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9345  
9346 diff -NurpP --minimal linux-2.6.37/include/linux/sysctl.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/sysctl.h
9347 --- linux-2.6.37/include/linux/sysctl.h 2010-08-02 16:52:56.000000000 +0200
9348 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/sysctl.h  2010-11-23 02:09:41.000000000 +0100
9349 @@ -60,6 +60,7 @@ enum
9350         CTL_ABI=9,              /* Binary emulation */
9351         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9352         CTL_ARLAN=254,          /* arlan wireless driver */
9353 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9354         CTL_S390DBF=5677,       /* s390 debug */
9355         CTL_SUNRPC=7249,        /* sunrpc debug */
9356         CTL_PM=9899,            /* frv power management */
9357 @@ -94,6 +95,7 @@ enum
9358  
9359         KERN_PANIC=15,          /* int: panic timeout */
9360         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9361 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9362  
9363         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9364         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9365 diff -NurpP --minimal linux-2.6.37/include/linux/sysfs.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/sysfs.h
9366 --- linux-2.6.37/include/linux/sysfs.h  2011-01-05 21:50:34.000000000 +0100
9367 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/sysfs.h   2010-11-23 02:09:41.000000000 +0100
9368 @@ -19,6 +19,8 @@
9369  #include <linux/kobject_ns.h>
9370  #include <asm/atomic.h>
9371  
9372 +#define SYSFS_SUPER_MAGIC      0x62656572
9373 +
9374  struct kobject;
9375  struct module;
9376  enum kobj_ns_type;
9377 diff -NurpP --minimal linux-2.6.37/include/linux/time.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/time.h
9378 --- linux-2.6.37/include/linux/time.h   2010-10-21 13:07:55.000000000 +0200
9379 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/time.h    2010-11-23 02:09:41.000000000 +0100
9380 @@ -252,6 +252,9 @@ static __always_inline void timespec_add
9381         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9382         a->tv_nsec = ns;
9383  }
9384 +
9385 +#include <linux/vs_time.h>
9386 +
9387  #endif /* __KERNEL__ */
9388  
9389  #define NFDBITS                        __NFDBITS
9390 diff -NurpP --minimal linux-2.6.37/include/linux/types.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/types.h
9391 --- linux-2.6.37/include/linux/types.h  2011-01-05 21:50:34.000000000 +0100
9392 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/types.h   2010-11-23 02:09:41.000000000 +0100
9393 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
9394  typedef __kernel_gid32_t       gid_t;
9395  typedef __kernel_uid16_t        uid16_t;
9396  typedef __kernel_gid16_t        gid16_t;
9397 +typedef unsigned int           xid_t;
9398 +typedef unsigned int           nid_t;
9399 +typedef unsigned int           tag_t;
9400  
9401  typedef unsigned long          uintptr_t;
9402  
9403 diff -NurpP --minimal linux-2.6.37/include/linux/vroot.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vroot.h
9404 --- linux-2.6.37/include/linux/vroot.h  1970-01-01 01:00:00.000000000 +0100
9405 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vroot.h   2010-11-23 02:09:41.000000000 +0100
9406 @@ -0,0 +1,51 @@
9407 +
9408 +/*
9409 + * include/linux/vroot.h
9410 + *
9411 + * written by Herbert Pötzl, 9/11/2002
9412 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9413 + *
9414 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9415 + * Redistribution of this file is permitted under the
9416 + * GNU General Public License.
9417 + */
9418 +
9419 +#ifndef _LINUX_VROOT_H
9420 +#define _LINUX_VROOT_H
9421 +
9422 +
9423 +#ifdef __KERNEL__
9424 +
9425 +/* Possible states of device */
9426 +enum {
9427 +       Vr_unbound,
9428 +       Vr_bound,
9429 +};
9430 +
9431 +struct vroot_device {
9432 +       int             vr_number;
9433 +       int             vr_refcnt;
9434 +
9435 +       struct semaphore        vr_ctl_mutex;
9436 +       struct block_device    *vr_device;
9437 +       int                     vr_state;
9438 +};
9439 +
9440 +
9441 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9442 +
9443 +extern int register_vroot_grb(vroot_grb_func *);
9444 +extern int unregister_vroot_grb(vroot_grb_func *);
9445 +
9446 +#endif /* __KERNEL__ */
9447 +
9448 +#define MAX_VROOT_DEFAULT      8
9449 +
9450 +/*
9451 + * IOCTL commands --- we will commandeer 0x56 ('V')
9452 + */
9453 +
9454 +#define VROOT_SET_DEV          0x5600
9455 +#define VROOT_CLR_DEV          0x5601
9456 +
9457 +#endif /* _LINUX_VROOT_H */
9458 diff -NurpP --minimal linux-2.6.37/include/linux/vs_base.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_base.h
9459 --- linux-2.6.37/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
9460 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_base.h 2010-11-23 02:09:41.000000000 +0100
9461 @@ -0,0 +1,10 @@
9462 +#ifndef _VS_BASE_H
9463 +#define _VS_BASE_H
9464 +
9465 +#include "vserver/base.h"
9466 +#include "vserver/check.h"
9467 +#include "vserver/debug.h"
9468 +
9469 +#else
9470 +#warning duplicate inclusion
9471 +#endif
9472 diff -NurpP --minimal linux-2.6.37/include/linux/vs_context.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_context.h
9473 --- linux-2.6.37/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
9474 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_context.h      2010-11-23 02:09:41.000000000 +0100
9475 @@ -0,0 +1,242 @@
9476 +#ifndef _VS_CONTEXT_H
9477 +#define _VS_CONTEXT_H
9478 +
9479 +#include "vserver/base.h"
9480 +#include "vserver/check.h"
9481 +#include "vserver/context.h"
9482 +#include "vserver/history.h"
9483 +#include "vserver/debug.h"
9484 +
9485 +#include <linux/sched.h>
9486 +
9487 +
9488 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9489 +
9490 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9491 +       const char *_file, int _line, void *_here)
9492 +{
9493 +       if (!vxi)
9494 +               return NULL;
9495 +
9496 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9497 +               vxi, vxi ? vxi->vx_id : 0,
9498 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9499 +               _file, _line);
9500 +       __vxh_get_vx_info(vxi, _here);
9501 +
9502 +       atomic_inc(&vxi->vx_usecnt);
9503 +       return vxi;
9504 +}
9505 +
9506 +
9507 +extern void free_vx_info(struct vx_info *);
9508 +
9509 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9510 +
9511 +static inline void __put_vx_info(struct vx_info *vxi,
9512 +       const char *_file, int _line, void *_here)
9513 +{
9514 +       if (!vxi)
9515 +               return;
9516 +
9517 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9518 +               vxi, vxi ? vxi->vx_id : 0,
9519 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9520 +               _file, _line);
9521 +       __vxh_put_vx_info(vxi, _here);
9522 +
9523 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9524 +               free_vx_info(vxi);
9525 +}
9526 +
9527 +
9528 +#define init_vx_info(p, i) \
9529 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9530 +
9531 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9532 +       const char *_file, int _line, void *_here)
9533 +{
9534 +       if (vxi) {
9535 +               vxlprintk(VXD_CBIT(xid, 3),
9536 +                       "init_vx_info(%p[#%d.%d])",
9537 +                       vxi, vxi ? vxi->vx_id : 0,
9538 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9539 +                       _file, _line);
9540 +               __vxh_init_vx_info(vxi, vxp, _here);
9541 +
9542 +               atomic_inc(&vxi->vx_usecnt);
9543 +       }
9544 +       *vxp = vxi;
9545 +}
9546 +
9547 +
9548 +#define set_vx_info(p, i) \
9549 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9550 +
9551 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9552 +       const char *_file, int _line, void *_here)
9553 +{
9554 +       struct vx_info *vxo;
9555 +
9556 +       if (!vxi)
9557 +               return;
9558 +
9559 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9560 +               vxi, vxi ? vxi->vx_id : 0,
9561 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9562 +               _file, _line);
9563 +       __vxh_set_vx_info(vxi, vxp, _here);
9564 +
9565 +       atomic_inc(&vxi->vx_usecnt);
9566 +       vxo = xchg(vxp, vxi);
9567 +       BUG_ON(vxo);
9568 +}
9569 +
9570 +
9571 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9572 +
9573 +static inline void __clr_vx_info(struct vx_info **vxp,
9574 +       const char *_file, int _line, void *_here)
9575 +{
9576 +       struct vx_info *vxo;
9577 +
9578 +       vxo = xchg(vxp, NULL);
9579 +       if (!vxo)
9580 +               return;
9581 +
9582 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9583 +               vxo, vxo ? vxo->vx_id : 0,
9584 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9585 +               _file, _line);
9586 +       __vxh_clr_vx_info(vxo, vxp, _here);
9587 +
9588 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9589 +               free_vx_info(vxo);
9590 +}
9591 +
9592 +
9593 +#define claim_vx_info(v, p) \
9594 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9595 +
9596 +static inline void __claim_vx_info(struct vx_info *vxi,
9597 +       struct task_struct *task,
9598 +       const char *_file, int _line, void *_here)
9599 +{
9600 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9601 +               vxi, vxi ? vxi->vx_id : 0,
9602 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9603 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9604 +               task, _file, _line);
9605 +       __vxh_claim_vx_info(vxi, task, _here);
9606 +
9607 +       atomic_inc(&vxi->vx_tasks);
9608 +}
9609 +
9610 +
9611 +extern void unhash_vx_info(struct vx_info *);
9612 +
9613 +#define release_vx_info(v, p) \
9614 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9615 +
9616 +static inline void __release_vx_info(struct vx_info *vxi,
9617 +       struct task_struct *task,
9618 +       const char *_file, int _line, void *_here)
9619 +{
9620 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9621 +               vxi, vxi ? vxi->vx_id : 0,
9622 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9623 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9624 +               task, _file, _line);
9625 +       __vxh_release_vx_info(vxi, task, _here);
9626 +
9627 +       might_sleep();
9628 +
9629 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9630 +               unhash_vx_info(vxi);
9631 +}
9632 +
9633 +
9634 +#define task_get_vx_info(p) \
9635 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9636 +
9637 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9638 +       const char *_file, int _line, void *_here)
9639 +{
9640 +       struct vx_info *vxi;
9641 +
9642 +       task_lock(p);
9643 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9644 +               p, _file, _line);
9645 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9646 +       task_unlock(p);
9647 +       return vxi;
9648 +}
9649 +
9650 +
9651 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9652 +{
9653 +       if (waitqueue_active(&vxi->vx_wait))
9654 +               wake_up_interruptible(&vxi->vx_wait);
9655 +}
9656 +
9657 +
9658 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9659 +
9660 +static inline void __enter_vx_info(struct vx_info *vxi,
9661 +       struct vx_info_save *vxis, const char *_file, int _line)
9662 +{
9663 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9664 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9665 +               current->xid, current->vx_info, _file, _line);
9666 +       vxis->vxi = xchg(&current->vx_info, vxi);
9667 +       vxis->xid = current->xid;
9668 +       current->xid = vxi ? vxi->vx_id : 0;
9669 +}
9670 +
9671 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9672 +
9673 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9674 +       const char *_file, int _line)
9675 +{
9676 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9677 +               vxis, vxis->xid, vxis->vxi, current,
9678 +               current->xid, current->vx_info, _file, _line);
9679 +       (void)xchg(&current->vx_info, vxis->vxi);
9680 +       current->xid = vxis->xid;
9681 +}
9682 +
9683 +
9684 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9685 +{
9686 +       vxis->vxi = xchg(&current->vx_info, NULL);
9687 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9688 +}
9689 +
9690 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9691 +{
9692 +       (void)xchg(&current->xid, vxis->xid);
9693 +       (void)xchg(&current->vx_info, vxis->vxi);
9694 +}
9695 +
9696 +#define task_is_init(p) \
9697 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9698 +
9699 +static inline int __task_is_init(struct task_struct *p,
9700 +       const char *_file, int _line, void *_here)
9701 +{
9702 +       int is_init = is_global_init(p);
9703 +
9704 +       task_lock(p);
9705 +       if (p->vx_info)
9706 +               is_init = p->vx_info->vx_initpid == p->pid;
9707 +       task_unlock(p);
9708 +       return is_init;
9709 +}
9710 +
9711 +extern void exit_vx_info(struct task_struct *, int);
9712 +extern void exit_vx_info_early(struct task_struct *, int);
9713 +
9714 +
9715 +#else
9716 +#warning duplicate inclusion
9717 +#endif
9718 diff -NurpP --minimal linux-2.6.37/include/linux/vs_cowbl.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_cowbl.h
9719 --- linux-2.6.37/include/linux/vs_cowbl.h       1970-01-01 01:00:00.000000000 +0100
9720 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_cowbl.h        2010-11-23 02:09:41.000000000 +0100
9721 @@ -0,0 +1,48 @@
9722 +#ifndef _VS_COWBL_H
9723 +#define _VS_COWBL_H
9724 +
9725 +#include <linux/fs.h>
9726 +#include <linux/dcache.h>
9727 +#include <linux/namei.h>
9728 +#include <linux/slab.h>
9729 +
9730 +extern struct dentry *cow_break_link(const char *pathname);
9731 +
9732 +static inline int cow_check_and_break(struct path *path)
9733 +{
9734 +       struct inode *inode = path->dentry->d_inode;
9735 +       int error = 0;
9736 +
9737 +       /* do we need this check? */
9738 +       if (IS_RDONLY(inode))
9739 +               return -EROFS;
9740 +
9741 +       if (IS_COW(inode)) {
9742 +               if (IS_COW_LINK(inode)) {
9743 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9744 +                       char *pp, *buf;
9745 +
9746 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9747 +                       if (!buf) {
9748 +                               return -ENOMEM;
9749 +                       }
9750 +                       pp = d_path(path, buf, PATH_MAX);
9751 +                       new_dentry = cow_break_link(pp);
9752 +                       kfree(buf);
9753 +                       if (!IS_ERR(new_dentry)) {
9754 +                               path->dentry = new_dentry;
9755 +                               dput(old_dentry);
9756 +                       } else
9757 +                               error = PTR_ERR(new_dentry);
9758 +               } else {
9759 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9760 +                       inode->i_ctime = CURRENT_TIME;
9761 +                       mark_inode_dirty(inode);
9762 +               }
9763 +       }
9764 +       return error;
9765 +}
9766 +
9767 +#else
9768 +#warning duplicate inclusion
9769 +#endif
9770 diff -NurpP --minimal linux-2.6.37/include/linux/vs_cvirt.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_cvirt.h
9771 --- linux-2.6.37/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
9772 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_cvirt.h        2010-11-23 02:09:41.000000000 +0100
9773 @@ -0,0 +1,50 @@
9774 +#ifndef _VS_CVIRT_H
9775 +#define _VS_CVIRT_H
9776 +
9777 +#include "vserver/cvirt.h"
9778 +#include "vserver/context.h"
9779 +#include "vserver/base.h"
9780 +#include "vserver/check.h"
9781 +#include "vserver/debug.h"
9782 +
9783 +
9784 +static inline void vx_activate_task(struct task_struct *p)
9785 +{
9786 +       struct vx_info *vxi;
9787 +
9788 +       if ((vxi = p->vx_info)) {
9789 +               vx_update_load(vxi);
9790 +               atomic_inc(&vxi->cvirt.nr_running);
9791 +       }
9792 +}
9793 +
9794 +static inline void vx_deactivate_task(struct task_struct *p)
9795 +{
9796 +       struct vx_info *vxi;
9797 +
9798 +       if ((vxi = p->vx_info)) {
9799 +               vx_update_load(vxi);
9800 +               atomic_dec(&vxi->cvirt.nr_running);
9801 +       }
9802 +}
9803 +
9804 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9805 +{
9806 +       struct vx_info *vxi;
9807 +
9808 +       if ((vxi = p->vx_info))
9809 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9810 +}
9811 +
9812 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9813 +{
9814 +       struct vx_info *vxi;
9815 +
9816 +       if ((vxi = p->vx_info))
9817 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9818 +}
9819 +
9820 +
9821 +#else
9822 +#warning duplicate inclusion
9823 +#endif
9824 diff -NurpP --minimal linux-2.6.37/include/linux/vs_device.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_device.h
9825 --- linux-2.6.37/include/linux/vs_device.h      1970-01-01 01:00:00.000000000 +0100
9826 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_device.h       2010-11-23 02:09:41.000000000 +0100
9827 @@ -0,0 +1,45 @@
9828 +#ifndef _VS_DEVICE_H
9829 +#define _VS_DEVICE_H
9830 +
9831 +#include "vserver/base.h"
9832 +#include "vserver/device.h"
9833 +#include "vserver/debug.h"
9834 +
9835 +
9836 +#ifdef CONFIG_VSERVER_DEVICE
9837 +
9838 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9839 +
9840 +#define vs_device_perm(v, d, m, p) \
9841 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9842 +
9843 +#else
9844 +
9845 +static inline
9846 +int vs_map_device(struct vx_info *vxi,
9847 +       dev_t device, dev_t *target, umode_t mode)
9848 +{
9849 +       if (target)
9850 +               *target = device;
9851 +       return ~0;
9852 +}
9853 +
9854 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9855 +
9856 +#endif
9857 +
9858 +
9859 +#define vs_map_chrdev(d, t, p) \
9860 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9861 +#define vs_map_blkdev(d, t, p) \
9862 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9863 +
9864 +#define vs_chrdev_perm(d, p) \
9865 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9866 +#define vs_blkdev_perm(d, p) \
9867 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9868 +
9869 +
9870 +#else
9871 +#warning duplicate inclusion
9872 +#endif
9873 diff -NurpP --minimal linux-2.6.37/include/linux/vs_dlimit.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_dlimit.h
9874 --- linux-2.6.37/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
9875 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_dlimit.h       2010-11-23 02:09:41.000000000 +0100
9876 @@ -0,0 +1,215 @@
9877 +#ifndef _VS_DLIMIT_H
9878 +#define _VS_DLIMIT_H
9879 +
9880 +#include <linux/fs.h>
9881 +
9882 +#include "vserver/dlimit.h"
9883 +#include "vserver/base.h"
9884 +#include "vserver/debug.h"
9885 +
9886 +
9887 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9888 +
9889 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9890 +       const char *_file, int _line)
9891 +{
9892 +       if (!dli)
9893 +               return NULL;
9894 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9895 +               dli, dli ? dli->dl_tag : 0,
9896 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9897 +               _file, _line);
9898 +       atomic_inc(&dli->dl_usecnt);
9899 +       return dli;
9900 +}
9901 +
9902 +
9903 +#define free_dl_info(i) \
9904 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9905 +
9906 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9907 +
9908 +static inline void __put_dl_info(struct dl_info *dli,
9909 +       const char *_file, int _line)
9910 +{
9911 +       if (!dli)
9912 +               return;
9913 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9914 +               dli, dli ? dli->dl_tag : 0,
9915 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9916 +               _file, _line);
9917 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9918 +               free_dl_info(dli);
9919 +}
9920 +
9921 +
9922 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9923 +
9924 +static inline int __dl_alloc_space(struct super_block *sb,
9925 +       tag_t tag, dlsize_t nr, const char *file, int line)
9926 +{
9927 +       struct dl_info *dli = NULL;
9928 +       int ret = 0;
9929 +
9930 +       if (nr == 0)
9931 +               goto out;
9932 +       dli = locate_dl_info(sb, tag);
9933 +       if (!dli)
9934 +               goto out;
9935 +
9936 +       spin_lock(&dli->dl_lock);
9937 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9938 +       if (!ret)
9939 +               dli->dl_space_used += nr;
9940 +       spin_unlock(&dli->dl_lock);
9941 +       put_dl_info(dli);
9942 +out:
9943 +       vxlprintk(VXD_CBIT(dlim, 1),
9944 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9945 +               sb, tag, __dlimit_char(dli), (long long)nr,
9946 +               ret, file, line);
9947 +       return ret ? -ENOSPC : 0;
9948 +}
9949 +
9950 +static inline void __dl_free_space(struct super_block *sb,
9951 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9952 +{
9953 +       struct dl_info *dli = NULL;
9954 +
9955 +       if (nr == 0)
9956 +               goto out;
9957 +       dli = locate_dl_info(sb, tag);
9958 +       if (!dli)
9959 +               goto out;
9960 +
9961 +       spin_lock(&dli->dl_lock);
9962 +       if (dli->dl_space_used > nr)
9963 +               dli->dl_space_used -= nr;
9964 +       else
9965 +               dli->dl_space_used = 0;
9966 +       spin_unlock(&dli->dl_lock);
9967 +       put_dl_info(dli);
9968 +out:
9969 +       vxlprintk(VXD_CBIT(dlim, 1),
9970 +               "FREE  (%p,#%d)%c %lld bytes",
9971 +               sb, tag, __dlimit_char(dli), (long long)nr,
9972 +               _file, _line);
9973 +}
9974 +
9975 +static inline int __dl_alloc_inode(struct super_block *sb,
9976 +       tag_t tag, const char *_file, int _line)
9977 +{
9978 +       struct dl_info *dli;
9979 +       int ret = 0;
9980 +
9981 +       dli = locate_dl_info(sb, tag);
9982 +       if (!dli)
9983 +               goto out;
9984 +
9985 +       spin_lock(&dli->dl_lock);
9986 +       dli->dl_inodes_used++;
9987 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9988 +       spin_unlock(&dli->dl_lock);
9989 +       put_dl_info(dli);
9990 +out:
9991 +       vxlprintk(VXD_CBIT(dlim, 0),
9992 +               "ALLOC (%p,#%d)%c inode (%d)",
9993 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9994 +       return ret ? -ENOSPC : 0;
9995 +}
9996 +
9997 +static inline void __dl_free_inode(struct super_block *sb,
9998 +       tag_t tag, const char *_file, int _line)
9999 +{
10000 +       struct dl_info *dli;
10001 +
10002 +       dli = locate_dl_info(sb, tag);
10003 +       if (!dli)
10004 +               goto out;
10005 +
10006 +       spin_lock(&dli->dl_lock);
10007 +       if (dli->dl_inodes_used > 1)
10008 +               dli->dl_inodes_used--;
10009 +       else
10010 +               dli->dl_inodes_used = 0;
10011 +       spin_unlock(&dli->dl_lock);
10012 +       put_dl_info(dli);
10013 +out:
10014 +       vxlprintk(VXD_CBIT(dlim, 0),
10015 +               "FREE  (%p,#%d)%c inode",
10016 +               sb, tag, __dlimit_char(dli), _file, _line);
10017 +}
10018 +
10019 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10020 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10021 +       const char *_file, int _line)
10022 +{
10023 +       struct dl_info *dli;
10024 +       uint64_t broot, bfree;
10025 +
10026 +       dli = locate_dl_info(sb, tag);
10027 +       if (!dli)
10028 +               return;
10029 +
10030 +       spin_lock(&dli->dl_lock);
10031 +       broot = (dli->dl_space_total -
10032 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10033 +               >> sb->s_blocksize_bits;
10034 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10035 +                       >> sb->s_blocksize_bits;
10036 +       spin_unlock(&dli->dl_lock);
10037 +
10038 +       vxlprintk(VXD_CBIT(dlim, 2),
10039 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10040 +               (long long)bfree, (long long)broot,
10041 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10042 +               _file, _line);
10043 +       if (free_blocks) {
10044 +               if (*free_blocks > bfree)
10045 +                       *free_blocks = bfree;
10046 +       }
10047 +       if (root_blocks) {
10048 +               if (*root_blocks > broot)
10049 +                       *root_blocks = broot;
10050 +       }
10051 +       put_dl_info(dli);
10052 +}
10053 +
10054 +#define dl_prealloc_space(in, bytes) \
10055 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10056 +               __FILE__, __LINE__ )
10057 +
10058 +#define dl_alloc_space(in, bytes) \
10059 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10060 +               __FILE__, __LINE__ )
10061 +
10062 +#define dl_reserve_space(in, bytes) \
10063 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10064 +               __FILE__, __LINE__ )
10065 +
10066 +#define dl_claim_space(in, bytes) (0)
10067 +
10068 +#define dl_release_space(in, bytes) \
10069 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10070 +               __FILE__, __LINE__ )
10071 +
10072 +#define dl_free_space(in, bytes) \
10073 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10074 +               __FILE__, __LINE__ )
10075 +
10076 +
10077 +
10078 +#define dl_alloc_inode(in) \
10079 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10080 +
10081 +#define dl_free_inode(in) \
10082 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10083 +
10084 +
10085 +#define dl_adjust_block(sb, tag, fb, rb) \
10086 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10087 +
10088 +
10089 +#else
10090 +#warning duplicate inclusion
10091 +#endif
10092 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/base.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/base.h
10093 --- linux-2.6.37/include/linux/vserver/base.h   1970-01-01 01:00:00.000000000 +0100
10094 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/base.h    2010-11-23 02:09:41.000000000 +0100
10095 @@ -0,0 +1,170 @@
10096 +#ifndef _VX_BASE_H
10097 +#define _VX_BASE_H
10098 +
10099 +
10100 +/* context state changes */
10101 +
10102 +enum {
10103 +       VSC_STARTUP = 1,
10104 +       VSC_SHUTDOWN,
10105 +
10106 +       VSC_NETUP,
10107 +       VSC_NETDOWN,
10108 +};
10109 +
10110 +
10111 +
10112 +#define vx_task_xid(t) ((t)->xid)
10113 +
10114 +#define vx_current_xid() vx_task_xid(current)
10115 +
10116 +#define current_vx_info() (current->vx_info)
10117 +
10118 +
10119 +#define nx_task_nid(t) ((t)->nid)
10120 +
10121 +#define nx_current_nid() nx_task_nid(current)
10122 +
10123 +#define current_nx_info() (current->nx_info)
10124 +
10125 +
10126 +/* generic flag merging */
10127 +
10128 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10129 +
10130 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10131 +
10132 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10133 +
10134 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10135 +
10136 +
10137 +/* context flags */
10138 +
10139 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10140 +
10141 +#define vx_current_flags()     __vx_flags(current_vx_info())
10142 +
10143 +#define vx_info_flags(v, m, f) \
10144 +       vs_check_flags(__vx_flags(v), m, f)
10145 +
10146 +#define task_vx_flags(t, m, f) \
10147 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10148 +
10149 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10150 +
10151 +
10152 +/* context caps */
10153 +
10154 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10155 +
10156 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10157 +
10158 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10159 +
10160 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10161 +
10162 +
10163 +
10164 +/* network flags */
10165 +
10166 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10167 +
10168 +#define nx_current_flags()     __nx_flags(current_nx_info())
10169 +
10170 +#define nx_info_flags(n, m, f) \
10171 +       vs_check_flags(__nx_flags(n), m, f)
10172 +
10173 +#define task_nx_flags(t, m, f) \
10174 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10175 +
10176 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10177 +
10178 +
10179 +/* network caps */
10180 +
10181 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10182 +
10183 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10184 +
10185 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10186 +
10187 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10188 +
10189 +
10190 +/* context mask capabilities */
10191 +
10192 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10193 +
10194 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10195 +
10196 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10197 +
10198 +
10199 +/* context bcap mask */
10200 +
10201 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10202 +
10203 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10204 +
10205 +
10206 +/* mask given bcaps */
10207 +
10208 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10209 +
10210 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10211 +
10212 +
10213 +/* masked cap_bset */
10214 +
10215 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10216 +
10217 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10218 +
10219 +#if 0
10220 +#define vx_info_mbcap(v, b) \
10221 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10222 +       vx_info_bcaps(v, b) : (b))
10223 +
10224 +#define task_vx_mbcap(t, b) \
10225 +       vx_info_mbcap((t)->vx_info, (t)->b)
10226 +
10227 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10228 +#endif
10229 +
10230 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10231 +
10232 +#define vx_capable(b, c) (capable(b) || \
10233 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10234 +
10235 +#define nx_capable(b, c) (capable(b) || \
10236 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10237 +
10238 +#define vx_task_initpid(t, n) \
10239 +       ((t)->vx_info && \
10240 +       ((t)->vx_info->vx_initpid == (n)))
10241 +
10242 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10243 +
10244 +
10245 +/* context unshare mask */
10246 +
10247 +#define __vx_umask(v)          ((v)->vx_umask)
10248 +
10249 +#define vx_current_umask()     __vx_umask(current_vx_info())
10250 +
10251 +#define vx_can_unshare(b, f) (capable(b) || \
10252 +       (cap_raised(current_cap(), b) && \
10253 +       !((f) & ~vx_current_umask())))
10254 +
10255 +
10256 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10257 +
10258 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10259 +
10260 +
10261 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10262 +
10263 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10264 +
10265 +#endif
10266 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cacct_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cacct_cmd.h
10267 --- linux-2.6.37/include/linux/vserver/cacct_cmd.h      1970-01-01 01:00:00.000000000 +0100
10268 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cacct_cmd.h       2010-11-23 02:09:41.000000000 +0100
10269 @@ -0,0 +1,23 @@
10270 +#ifndef _VX_CACCT_CMD_H
10271 +#define _VX_CACCT_CMD_H
10272 +
10273 +
10274 +/* virtual host info name commands */
10275 +
10276 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10277 +
10278 +struct vcmd_sock_stat_v0 {
10279 +       uint32_t field;
10280 +       uint32_t count[3];
10281 +       uint64_t total[3];
10282 +};
10283 +
10284 +
10285 +#ifdef __KERNEL__
10286 +
10287 +#include <linux/compiler.h>
10288 +
10289 +extern int vc_sock_stat(struct vx_info *, void __user *);
10290 +
10291 +#endif /* __KERNEL__ */
10292 +#endif /* _VX_CACCT_CMD_H */
10293 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cacct_def.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cacct_def.h
10294 --- linux-2.6.37/include/linux/vserver/cacct_def.h      1970-01-01 01:00:00.000000000 +0100
10295 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cacct_def.h       2010-11-23 02:09:41.000000000 +0100
10296 @@ -0,0 +1,43 @@
10297 +#ifndef _VX_CACCT_DEF_H
10298 +#define _VX_CACCT_DEF_H
10299 +
10300 +#include <asm/atomic.h>
10301 +#include <linux/vserver/cacct.h>
10302 +
10303 +
10304 +struct _vx_sock_acc {
10305 +       atomic_long_t count;
10306 +       atomic_long_t total;
10307 +};
10308 +
10309 +/* context sub struct */
10310 +
10311 +struct _vx_cacct {
10312 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10313 +       atomic_t slab[8];
10314 +       atomic_t page[6][8];
10315 +};
10316 +
10317 +#ifdef CONFIG_VSERVER_DEBUG
10318 +
10319 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10320 +{
10321 +       int i, j;
10322 +
10323 +       printk("\t_vx_cacct:");
10324 +       for (i = 0; i < 6; i++) {
10325 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10326 +
10327 +               printk("\t [%d] =", i);
10328 +               for (j = 0; j < 3; j++) {
10329 +                       printk(" [%d] = %8lu, %8lu", j,
10330 +                               atomic_long_read(&ptr[j].count),
10331 +                               atomic_long_read(&ptr[j].total));
10332 +               }
10333 +               printk("\n");
10334 +       }
10335 +}
10336 +
10337 +#endif
10338 +
10339 +#endif /* _VX_CACCT_DEF_H */
10340 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cacct.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cacct.h
10341 --- linux-2.6.37/include/linux/vserver/cacct.h  1970-01-01 01:00:00.000000000 +0100
10342 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cacct.h   2010-11-23 02:09:41.000000000 +0100
10343 @@ -0,0 +1,15 @@
10344 +#ifndef _VX_CACCT_H
10345 +#define _VX_CACCT_H
10346 +
10347 +
10348 +enum sock_acc_field {
10349 +       VXA_SOCK_UNSPEC = 0,
10350 +       VXA_SOCK_UNIX,
10351 +       VXA_SOCK_INET,
10352 +       VXA_SOCK_INET6,
10353 +       VXA_SOCK_PACKET,
10354 +       VXA_SOCK_OTHER,
10355 +       VXA_SOCK_SIZE   /* array size */
10356 +};
10357 +
10358 +#endif /* _VX_CACCT_H */
10359 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cacct_int.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cacct_int.h
10360 --- linux-2.6.37/include/linux/vserver/cacct_int.h      1970-01-01 01:00:00.000000000 +0100
10361 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cacct_int.h       2010-11-23 02:09:41.000000000 +0100
10362 @@ -0,0 +1,21 @@
10363 +#ifndef _VX_CACCT_INT_H
10364 +#define _VX_CACCT_INT_H
10365 +
10366 +
10367 +#ifdef __KERNEL__
10368 +
10369 +static inline
10370 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10371 +{
10372 +       return atomic_long_read(&cacct->sock[type][pos].count);
10373 +}
10374 +
10375 +
10376 +static inline
10377 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10378 +{
10379 +       return atomic_long_read(&cacct->sock[type][pos].total);
10380 +}
10381 +
10382 +#endif /* __KERNEL__ */
10383 +#endif /* _VX_CACCT_INT_H */
10384 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/check.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/check.h
10385 --- linux-2.6.37/include/linux/vserver/check.h  1970-01-01 01:00:00.000000000 +0100
10386 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/check.h   2010-11-23 02:09:41.000000000 +0100
10387 @@ -0,0 +1,89 @@
10388 +#ifndef _VS_CHECK_H
10389 +#define _VS_CHECK_H
10390 +
10391 +
10392 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10393 +
10394 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10395 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10396 +#else
10397 +#define MIN_D_CONTEXT  65536
10398 +#endif
10399 +
10400 +/* check conditions */
10401 +
10402 +#define VS_ADMIN       0x0001
10403 +#define VS_WATCH       0x0002
10404 +#define VS_HIDE                0x0004
10405 +#define VS_HOSTID      0x0008
10406 +
10407 +#define VS_IDENT       0x0010
10408 +#define VS_EQUIV       0x0020
10409 +#define VS_PARENT      0x0040
10410 +#define VS_CHILD       0x0080
10411 +
10412 +#define VS_ARG_MASK    0x00F0
10413 +
10414 +#define VS_DYNAMIC     0x0100
10415 +#define VS_STATIC      0x0200
10416 +
10417 +#define VS_ATR_MASK    0x0F00
10418 +
10419 +#ifdef CONFIG_VSERVER_PRIVACY
10420 +#define VS_ADMIN_P     (0)
10421 +#define VS_WATCH_P     (0)
10422 +#else
10423 +#define VS_ADMIN_P     VS_ADMIN
10424 +#define VS_WATCH_P     VS_WATCH
10425 +#endif
10426 +
10427 +#define VS_HARDIRQ     0x1000
10428 +#define VS_SOFTIRQ     0x2000
10429 +#define VS_IRQ         0x4000
10430 +
10431 +#define VS_IRQ_MASK    0xF000
10432 +
10433 +#include <linux/hardirq.h>
10434 +
10435 +/*
10436 + * check current context for ADMIN/WATCH and
10437 + * optionally against supplied argument
10438 + */
10439 +static inline int __vs_check(int cid, int id, unsigned int mode)
10440 +{
10441 +       if (mode & VS_ARG_MASK) {
10442 +               if ((mode & VS_IDENT) && (id == cid))
10443 +                       return 1;
10444 +       }
10445 +       if (mode & VS_ATR_MASK) {
10446 +               if ((mode & VS_DYNAMIC) &&
10447 +                       (id >= MIN_D_CONTEXT) &&
10448 +                       (id <= MAX_S_CONTEXT))
10449 +                       return 1;
10450 +               if ((mode & VS_STATIC) &&
10451 +                       (id > 1) && (id < MIN_D_CONTEXT))
10452 +                       return 1;
10453 +       }
10454 +       if (mode & VS_IRQ_MASK) {
10455 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10456 +                       return 1;
10457 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10458 +                       return 1;
10459 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10460 +                       return 1;
10461 +       }
10462 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10463 +               ((mode & VS_WATCH) && (cid == 1)) ||
10464 +               ((mode & VS_HOSTID) && (id == 0)));
10465 +}
10466 +
10467 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10468 +
10469 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10470 +
10471 +
10472 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10473 +
10474 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10475 +
10476 +#endif
10477 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/context_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/context_cmd.h
10478 --- linux-2.6.37/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
10479 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/context_cmd.h     2010-11-23 02:09:41.000000000 +0100
10480 @@ -0,0 +1,145 @@
10481 +#ifndef _VX_CONTEXT_CMD_H
10482 +#define _VX_CONTEXT_CMD_H
10483 +
10484 +
10485 +/* vinfo commands */
10486 +
10487 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10488 +
10489 +#ifdef __KERNEL__
10490 +extern int vc_task_xid(uint32_t);
10491 +
10492 +#endif /* __KERNEL__ */
10493 +
10494 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10495 +
10496 +struct vcmd_vx_info_v0 {
10497 +       uint32_t xid;
10498 +       uint32_t initpid;
10499 +       /* more to come */
10500 +};
10501 +
10502 +#ifdef __KERNEL__
10503 +extern int vc_vx_info(struct vx_info *, void __user *);
10504 +
10505 +#endif /* __KERNEL__ */
10506 +
10507 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10508 +
10509 +struct vcmd_ctx_stat_v0 {
10510 +       uint32_t usecnt;
10511 +       uint32_t tasks;
10512 +       /* more to come */
10513 +};
10514 +
10515 +#ifdef __KERNEL__
10516 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10517 +
10518 +#endif /* __KERNEL__ */
10519 +
10520 +/* context commands */
10521 +
10522 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10523 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10524 +
10525 +struct vcmd_ctx_create {
10526 +       uint64_t flagword;
10527 +};
10528 +
10529 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10530 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10531 +
10532 +struct vcmd_ctx_migrate {
10533 +       uint64_t flagword;
10534 +};
10535 +
10536 +#ifdef __KERNEL__
10537 +extern int vc_ctx_create(uint32_t, void __user *);
10538 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10539 +
10540 +#endif /* __KERNEL__ */
10541 +
10542 +
10543 +/* flag commands */
10544 +
10545 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10546 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10547 +
10548 +struct vcmd_ctx_flags_v0 {
10549 +       uint64_t flagword;
10550 +       uint64_t mask;
10551 +};
10552 +
10553 +#ifdef __KERNEL__
10554 +extern int vc_get_cflags(struct vx_info *, void __user *);
10555 +extern int vc_set_cflags(struct vx_info *, void __user *);
10556 +
10557 +#endif /* __KERNEL__ */
10558 +
10559 +
10560 +/* context caps commands */
10561 +
10562 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10563 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10564 +
10565 +struct vcmd_ctx_caps_v1 {
10566 +       uint64_t ccaps;
10567 +       uint64_t cmask;
10568 +};
10569 +
10570 +#ifdef __KERNEL__
10571 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10572 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10573 +
10574 +#endif /* __KERNEL__ */
10575 +
10576 +
10577 +/* bcaps commands */
10578 +
10579 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10580 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10581 +
10582 +struct vcmd_bcaps {
10583 +       uint64_t bcaps;
10584 +       uint64_t bmask;
10585 +};
10586 +
10587 +#ifdef __KERNEL__
10588 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10589 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10590 +
10591 +#endif /* __KERNEL__ */
10592 +
10593 +
10594 +/* umask commands */
10595 +
10596 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10597 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10598 +
10599 +struct vcmd_umask {
10600 +       uint64_t umask;
10601 +       uint64_t mask;
10602 +};
10603 +
10604 +#ifdef __KERNEL__
10605 +extern int vc_get_umask(struct vx_info *, void __user *);
10606 +extern int vc_set_umask(struct vx_info *, void __user *);
10607 +
10608 +#endif /* __KERNEL__ */
10609 +
10610 +
10611 +/* OOM badness */
10612 +
10613 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10614 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10615 +
10616 +struct vcmd_badness_v0 {
10617 +       int64_t bias;
10618 +};
10619 +
10620 +#ifdef __KERNEL__
10621 +extern int vc_get_badness(struct vx_info *, void __user *);
10622 +extern int vc_set_badness(struct vx_info *, void __user *);
10623 +
10624 +#endif /* __KERNEL__ */
10625 +#endif /* _VX_CONTEXT_CMD_H */
10626 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/context.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/context.h
10627 --- linux-2.6.37/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
10628 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/context.h 2011-01-31 21:05:40.000000000 +0100
10629 @@ -0,0 +1,190 @@
10630 +#ifndef _VX_CONTEXT_H
10631 +#define _VX_CONTEXT_H
10632 +
10633 +#include <linux/types.h>
10634 +#include <linux/capability.h>
10635 +
10636 +
10637 +/* context flags */
10638 +
10639 +#define VXF_INFO_SCHED         0x00000002
10640 +#define VXF_INFO_NPROC         0x00000004
10641 +#define VXF_INFO_PRIVATE       0x00000008
10642 +
10643 +#define VXF_INFO_INIT          0x00000010
10644 +#define VXF_INFO_HIDE          0x00000020
10645 +#define VXF_INFO_ULIMIT                0x00000040
10646 +#define VXF_INFO_NSPACE                0x00000080
10647 +
10648 +#define VXF_SCHED_HARD         0x00000100
10649 +#define VXF_SCHED_PRIO         0x00000200
10650 +#define VXF_SCHED_PAUSE                0x00000400
10651 +
10652 +#define VXF_VIRT_MEM           0x00010000
10653 +#define VXF_VIRT_UPTIME                0x00020000
10654 +#define VXF_VIRT_CPU           0x00040000
10655 +#define VXF_VIRT_LOAD          0x00080000
10656 +#define VXF_VIRT_TIME          0x00100000
10657 +
10658 +#define VXF_HIDE_MOUNT         0x01000000
10659 +/* was VXF_HIDE_NETIF          0x02000000 */
10660 +#define VXF_HIDE_VINFO         0x04000000
10661 +
10662 +#define VXF_STATE_SETUP                (1ULL << 32)
10663 +#define VXF_STATE_INIT         (1ULL << 33)
10664 +#define VXF_STATE_ADMIN                (1ULL << 34)
10665 +
10666 +#define VXF_SC_HELPER          (1ULL << 36)
10667 +#define VXF_REBOOT_KILL                (1ULL << 37)
10668 +#define VXF_PERSISTENT         (1ULL << 38)
10669 +
10670 +#define VXF_FORK_RSS           (1ULL << 48)
10671 +#define VXF_PROLIFIC           (1ULL << 49)
10672 +
10673 +#define VXF_IGNEG_NICE         (1ULL << 52)
10674 +
10675 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10676 +
10677 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10678 +
10679 +
10680 +/* context migration */
10681 +
10682 +#define VXM_SET_INIT           0x00000001
10683 +#define VXM_SET_REAPER         0x00000002
10684 +
10685 +/* context caps */
10686 +
10687 +#define VXC_CAP_MASK           0x00000000
10688 +
10689 +#define VXC_SET_UTSNAME                0x00000001
10690 +#define VXC_SET_RLIMIT         0x00000002
10691 +#define VXC_FS_SECURITY                0x00000004
10692 +#define VXC_FS_TRUSTED         0x00000008
10693 +#define VXC_TIOCSTI            0x00000010
10694 +
10695 +/* was VXC_RAW_ICMP            0x00000100 */
10696 +#define VXC_SYSLOG             0x00001000
10697 +#define VXC_OOM_ADJUST         0x00002000
10698 +#define VXC_AUDIT_CONTROL      0x00004000
10699 +
10700 +#define VXC_SECURE_MOUNT       0x00010000
10701 +#define VXC_SECURE_REMOUNT     0x00020000
10702 +#define VXC_BINARY_MOUNT       0x00040000
10703 +
10704 +#define VXC_QUOTA_CTL          0x00100000
10705 +#define VXC_ADMIN_MAPPER       0x00200000
10706 +#define VXC_ADMIN_CLOOP                0x00400000
10707 +
10708 +#define VXC_KTHREAD            0x01000000
10709 +#define VXC_NAMESPACE          0x02000000
10710 +
10711 +
10712 +#ifdef __KERNEL__
10713 +
10714 +#include <linux/list.h>
10715 +#include <linux/spinlock.h>
10716 +#include <linux/rcupdate.h>
10717 +
10718 +#include "limit_def.h"
10719 +#include "sched_def.h"
10720 +#include "cvirt_def.h"
10721 +#include "cacct_def.h"
10722 +#include "device_def.h"
10723 +
10724 +#define VX_SPACES      2
10725 +
10726 +struct _vx_info_pc {
10727 +       struct _vx_sched_pc sched_pc;
10728 +       struct _vx_cvirt_pc cvirt_pc;
10729 +};
10730 +
10731 +struct _vx_space {
10732 +       unsigned long vx_nsmask;                /* assignment mask */
10733 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10734 +       struct fs_struct *vx_fs;                /* private namespace fs */
10735 +//     const struct cred *vx_real_cred;        /* real task credentials */
10736 +       const struct cred *vx_cred;             /* task credentials */
10737 +};
10738 +
10739 +struct vx_info {
10740 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10741 +       xid_t vx_id;                            /* context id */
10742 +       atomic_t vx_usecnt;                     /* usage count */
10743 +       atomic_t vx_tasks;                      /* tasks count */
10744 +       struct vx_info *vx_parent;              /* parent context */
10745 +       int vx_state;                           /* context state */
10746 +
10747 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10748 +
10749 +       uint64_t vx_flags;                      /* context flags */
10750 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10751 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10752 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10753 +
10754 +       struct task_struct *vx_reaper;          /* guest reaper process */
10755 +       pid_t vx_initpid;                       /* PID of guest init */
10756 +       int64_t vx_badness_bias;                /* OOM points bias */
10757 +
10758 +       struct _vx_limit limit;                 /* vserver limits */
10759 +       struct _vx_sched sched;                 /* vserver scheduler */
10760 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10761 +       struct _vx_cacct cacct;                 /* context accounting */
10762 +
10763 +       struct _vx_device dmap;                 /* default device map targets */
10764 +
10765 +#ifndef CONFIG_SMP
10766 +       struct _vx_info_pc info_pc;             /* per cpu data */
10767 +#else
10768 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10769 +#endif
10770 +
10771 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10772 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10773 +       int exit_code;                          /* last process exit code */
10774 +
10775 +       char vx_name[65];                       /* vserver name */
10776 +};
10777 +
10778 +#ifndef CONFIG_SMP
10779 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10780 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10781 +#else
10782 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10783 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10784 +#endif
10785 +
10786 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10787 +
10788 +
10789 +struct vx_info_save {
10790 +       struct vx_info *vxi;
10791 +       xid_t xid;
10792 +};
10793 +
10794 +
10795 +/* status flags */
10796 +
10797 +#define VXS_HASHED     0x0001
10798 +#define VXS_PAUSED     0x0010
10799 +#define VXS_SHUTDOWN   0x0100
10800 +#define VXS_HELPER     0x1000
10801 +#define VXS_RELEASED   0x8000
10802 +
10803 +
10804 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10805 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10806 +
10807 +extern struct vx_info *lookup_vx_info(int);
10808 +extern struct vx_info *lookup_or_create_vx_info(int);
10809 +
10810 +extern int get_xid_list(int, unsigned int *, int);
10811 +extern int xid_is_hashed(xid_t);
10812 +
10813 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10814 +
10815 +extern long vs_state_change(struct vx_info *, unsigned int);
10816 +
10817 +
10818 +#endif /* __KERNEL__ */
10819 +#endif /* _VX_CONTEXT_H */
10820 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cvirt_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cvirt_cmd.h
10821 --- linux-2.6.37/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
10822 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cvirt_cmd.h       2010-11-23 02:09:41.000000000 +0100
10823 @@ -0,0 +1,53 @@
10824 +#ifndef _VX_CVIRT_CMD_H
10825 +#define _VX_CVIRT_CMD_H
10826 +
10827 +
10828 +/* virtual host info name commands */
10829 +
10830 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10831 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10832 +
10833 +struct vcmd_vhi_name_v0 {
10834 +       uint32_t field;
10835 +       char name[65];
10836 +};
10837 +
10838 +
10839 +enum vhi_name_field {
10840 +       VHIN_CONTEXT = 0,
10841 +       VHIN_SYSNAME,
10842 +       VHIN_NODENAME,
10843 +       VHIN_RELEASE,
10844 +       VHIN_VERSION,
10845 +       VHIN_MACHINE,
10846 +       VHIN_DOMAINNAME,
10847 +};
10848 +
10849 +
10850 +#ifdef __KERNEL__
10851 +
10852 +#include <linux/compiler.h>
10853 +
10854 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10855 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10856 +
10857 +#endif /* __KERNEL__ */
10858 +
10859 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10860 +
10861 +struct vcmd_virt_stat_v0 {
10862 +       uint64_t offset;
10863 +       uint64_t uptime;
10864 +       uint32_t nr_threads;
10865 +       uint32_t nr_running;
10866 +       uint32_t nr_uninterruptible;
10867 +       uint32_t nr_onhold;
10868 +       uint32_t nr_forks;
10869 +       uint32_t load[3];
10870 +};
10871 +
10872 +#ifdef __KERNEL__
10873 +extern int vc_virt_stat(struct vx_info *, void __user *);
10874 +
10875 +#endif /* __KERNEL__ */
10876 +#endif /* _VX_CVIRT_CMD_H */
10877 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cvirt_def.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cvirt_def.h
10878 --- linux-2.6.37/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
10879 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cvirt_def.h       2010-11-23 02:09:41.000000000 +0100
10880 @@ -0,0 +1,80 @@
10881 +#ifndef _VX_CVIRT_DEF_H
10882 +#define _VX_CVIRT_DEF_H
10883 +
10884 +#include <linux/jiffies.h>
10885 +#include <linux/spinlock.h>
10886 +#include <linux/wait.h>
10887 +#include <linux/time.h>
10888 +#include <asm/atomic.h>
10889 +
10890 +
10891 +struct _vx_usage_stat {
10892 +       uint64_t user;
10893 +       uint64_t nice;
10894 +       uint64_t system;
10895 +       uint64_t softirq;
10896 +       uint64_t irq;
10897 +       uint64_t idle;
10898 +       uint64_t iowait;
10899 +};
10900 +
10901 +struct _vx_syslog {
10902 +       wait_queue_head_t log_wait;
10903 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10904 +
10905 +       unsigned long log_start;        /* next char to be read by syslog() */
10906 +       unsigned long con_start;        /* next char to be sent to consoles */
10907 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10908 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10909 +
10910 +       char log_buf[1024];
10911 +};
10912 +
10913 +
10914 +/* context sub struct */
10915 +
10916 +struct _vx_cvirt {
10917 +       atomic_t nr_threads;            /* number of current threads */
10918 +       atomic_t nr_running;            /* number of running threads */
10919 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10920 +
10921 +       atomic_t nr_onhold;             /* processes on hold */
10922 +       uint32_t onhold_last;           /* jiffies when put on hold */
10923 +
10924 +       struct timespec bias_ts;        /* time offset to the host */
10925 +       struct timespec bias_idle;
10926 +       struct timespec bias_uptime;    /* context creation point */
10927 +       uint64_t bias_clock;            /* offset in clock_t */
10928 +
10929 +       spinlock_t load_lock;           /* lock for the load averages */
10930 +       atomic_t load_updates;          /* nr of load updates done so far */
10931 +       uint32_t load_last;             /* last time load was calculated */
10932 +       uint32_t load[3];               /* load averages 1,5,15 */
10933 +
10934 +       atomic_t total_forks;           /* number of forks so far */
10935 +
10936 +       struct _vx_syslog syslog;
10937 +};
10938 +
10939 +struct _vx_cvirt_pc {
10940 +       struct _vx_usage_stat cpustat;
10941 +};
10942 +
10943 +
10944 +#ifdef CONFIG_VSERVER_DEBUG
10945 +
10946 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10947 +{
10948 +       printk("\t_vx_cvirt:\n");
10949 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10950 +               atomic_read(&cvirt->nr_threads),
10951 +               atomic_read(&cvirt->nr_running),
10952 +               atomic_read(&cvirt->nr_uninterruptible),
10953 +               atomic_read(&cvirt->nr_onhold));
10954 +       /* add rest here */
10955 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10956 +}
10957 +
10958 +#endif
10959 +
10960 +#endif /* _VX_CVIRT_DEF_H */
10961 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cvirt.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cvirt.h
10962 --- linux-2.6.37/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
10963 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/cvirt.h   2010-11-23 02:09:41.000000000 +0100
10964 @@ -0,0 +1,20 @@
10965 +#ifndef _VX_CVIRT_H
10966 +#define _VX_CVIRT_H
10967 +
10968 +
10969 +#ifdef __KERNEL__
10970 +
10971 +struct timespec;
10972 +
10973 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10974 +
10975 +
10976 +struct vx_info;
10977 +
10978 +void vx_update_load(struct vx_info *);
10979 +
10980 +
10981 +int vx_do_syslog(int, char __user *, int);
10982 +
10983 +#endif /* __KERNEL__ */
10984 +#endif /* _VX_CVIRT_H */
10985 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/debug_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/debug_cmd.h
10986 --- linux-2.6.37/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
10987 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/debug_cmd.h       2010-11-23 02:09:41.000000000 +0100
10988 @@ -0,0 +1,58 @@
10989 +#ifndef _VX_DEBUG_CMD_H
10990 +#define _VX_DEBUG_CMD_H
10991 +
10992 +
10993 +/* debug commands */
10994 +
10995 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
10996 +
10997 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
10998 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
10999 +
11000 +struct  vcmd_read_history_v0 {
11001 +       uint32_t index;
11002 +       uint32_t count;
11003 +       char __user *data;
11004 +};
11005 +
11006 +struct  vcmd_read_monitor_v0 {
11007 +       uint32_t index;
11008 +       uint32_t count;
11009 +       char __user *data;
11010 +};
11011 +
11012 +
11013 +#ifdef __KERNEL__
11014 +
11015 +#ifdef CONFIG_COMPAT
11016 +
11017 +#include <asm/compat.h>
11018 +
11019 +struct vcmd_read_history_v0_x32 {
11020 +       uint32_t index;
11021 +       uint32_t count;
11022 +       compat_uptr_t data_ptr;
11023 +};
11024 +
11025 +struct vcmd_read_monitor_v0_x32 {
11026 +       uint32_t index;
11027 +       uint32_t count;
11028 +       compat_uptr_t data_ptr;
11029 +};
11030 +
11031 +#endif  /* CONFIG_COMPAT */
11032 +
11033 +extern int vc_dump_history(uint32_t);
11034 +
11035 +extern int vc_read_history(uint32_t, void __user *);
11036 +extern int vc_read_monitor(uint32_t, void __user *);
11037 +
11038 +#ifdef CONFIG_COMPAT
11039 +
11040 +extern int vc_read_history_x32(uint32_t, void __user *);
11041 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11042 +
11043 +#endif  /* CONFIG_COMPAT */
11044 +
11045 +#endif /* __KERNEL__ */
11046 +#endif /* _VX_DEBUG_CMD_H */
11047 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/debug.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/debug.h
11048 --- linux-2.6.37/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
11049 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/debug.h   2010-11-23 02:09:41.000000000 +0100
11050 @@ -0,0 +1,140 @@
11051 +#ifndef _VX_DEBUG_H
11052 +#define _VX_DEBUG_H
11053 +
11054 +
11055 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11056 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11057 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11058 +
11059 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11060 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11061 +#define VXF_DEV                "%p[%lu,%d:%d]"
11062 +
11063 +#if    defined(CONFIG_QUOTES_UTF8)
11064 +#define        VS_Q_LQM        "\xc2\xbb"
11065 +#define        VS_Q_RQM        "\xc2\xab"
11066 +#elif  defined(CONFIG_QUOTES_ASCII)
11067 +#define        VS_Q_LQM        "\x27"
11068 +#define        VS_Q_RQM        "\x27"
11069 +#else
11070 +#define        VS_Q_LQM        "\xbb"
11071 +#define        VS_Q_RQM        "\xab"
11072 +#endif
11073 +
11074 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11075 +
11076 +
11077 +#define vxd_path(p)                                            \
11078 +       ({ static char _buffer[PATH_MAX];                       \
11079 +          d_path(p, _buffer, sizeof(_buffer)); })
11080 +
11081 +#define vxd_cond_path(n)                                       \
11082 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11083 +
11084 +
11085 +#ifdef CONFIG_VSERVER_DEBUG
11086 +
11087 +extern unsigned int vx_debug_switch;
11088 +extern unsigned int vx_debug_xid;
11089 +extern unsigned int vx_debug_nid;
11090 +extern unsigned int vx_debug_tag;
11091 +extern unsigned int vx_debug_net;
11092 +extern unsigned int vx_debug_limit;
11093 +extern unsigned int vx_debug_cres;
11094 +extern unsigned int vx_debug_dlim;
11095 +extern unsigned int vx_debug_quota;
11096 +extern unsigned int vx_debug_cvirt;
11097 +extern unsigned int vx_debug_space;
11098 +extern unsigned int vx_debug_misc;
11099 +
11100 +
11101 +#define VX_LOGLEVEL    "vxD: "
11102 +#define VX_PROC_FMT    "%p: "
11103 +#define VX_PROCESS     current
11104 +
11105 +#define vxdprintk(c, f, x...)                                  \
11106 +       do {                                                    \
11107 +               if (c)                                          \
11108 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11109 +                               VX_PROCESS , ##x);              \
11110 +       } while (0)
11111 +
11112 +#define vxlprintk(c, f, x...)                                  \
11113 +       do {                                                    \
11114 +               if (c)                                          \
11115 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11116 +       } while (0)
11117 +
11118 +#define vxfprintk(c, f, x...)                                  \
11119 +       do {                                                    \
11120 +               if (c)                                          \
11121 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11122 +       } while (0)
11123 +
11124 +
11125 +struct vx_info;
11126 +
11127 +void dump_vx_info(struct vx_info *, int);
11128 +void dump_vx_info_inactive(int);
11129 +
11130 +#else  /* CONFIG_VSERVER_DEBUG */
11131 +
11132 +#define vx_debug_switch 0
11133 +#define vx_debug_xid   0
11134 +#define vx_debug_nid   0
11135 +#define vx_debug_tag   0
11136 +#define vx_debug_net   0
11137 +#define vx_debug_limit 0
11138 +#define vx_debug_cres  0
11139 +#define vx_debug_dlim  0
11140 +#define vx_debug_cvirt 0
11141 +
11142 +#define vxdprintk(x...) do { } while (0)
11143 +#define vxlprintk(x...) do { } while (0)
11144 +#define vxfprintk(x...) do { } while (0)
11145 +
11146 +#endif /* CONFIG_VSERVER_DEBUG */
11147 +
11148 +
11149 +#ifdef CONFIG_VSERVER_WARN
11150 +
11151 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11152 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11153 +#define VX_WARN_XID    "[xid #%u] "
11154 +#define VX_WARN_NID    "[nid #%u] "
11155 +#define VX_WARN_TAG    "[tag #%u] "
11156 +
11157 +#define vxwprintk(c, f, x...)                                  \
11158 +       do {                                                    \
11159 +               if (c)                                          \
11160 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11161 +       } while (0)
11162 +
11163 +#else  /* CONFIG_VSERVER_WARN */
11164 +
11165 +#define vxwprintk(x...) do { } while (0)
11166 +
11167 +#endif /* CONFIG_VSERVER_WARN */
11168 +
11169 +#define vxwprintk_task(c, f, x...)                             \
11170 +       vxwprintk(c, VX_WARN_TASK f,                            \
11171 +               current->comm, current->pid,                    \
11172 +               current->xid, current->nid, current->tag, ##x)
11173 +#define vxwprintk_xid(c, f, x...)                              \
11174 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11175 +#define vxwprintk_nid(c, f, x...)                              \
11176 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11177 +#define vxwprintk_tag(c, f, x...)                              \
11178 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11179 +
11180 +#ifdef CONFIG_VSERVER_DEBUG
11181 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11182 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11183 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11184 +#else
11185 +#define vxd_assert_lock(l)     do { } while (0)
11186 +#define vxd_assert(c, f, x...) do { } while (0)
11187 +#endif
11188 +
11189 +
11190 +#endif /* _VX_DEBUG_H */
11191 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/device_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/device_cmd.h
11192 --- linux-2.6.37/include/linux/vserver/device_cmd.h     1970-01-01 01:00:00.000000000 +0100
11193 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/device_cmd.h      2010-11-23 02:09:41.000000000 +0100
11194 @@ -0,0 +1,44 @@
11195 +#ifndef _VX_DEVICE_CMD_H
11196 +#define _VX_DEVICE_CMD_H
11197 +
11198 +
11199 +/*  device vserver commands */
11200 +
11201 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11202 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11203 +
11204 +struct vcmd_set_mapping_v0 {
11205 +       const char __user *device;
11206 +       const char __user *target;
11207 +       uint32_t flags;
11208 +};
11209 +
11210 +
11211 +#ifdef __KERNEL__
11212 +
11213 +#ifdef CONFIG_COMPAT
11214 +
11215 +#include <asm/compat.h>
11216 +
11217 +struct vcmd_set_mapping_v0_x32 {
11218 +       compat_uptr_t device_ptr;
11219 +       compat_uptr_t target_ptr;
11220 +       uint32_t flags;
11221 +};
11222 +
11223 +#endif /* CONFIG_COMPAT */
11224 +
11225 +#include <linux/compiler.h>
11226 +
11227 +extern int vc_set_mapping(struct vx_info *, void __user *);
11228 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11229 +
11230 +#ifdef CONFIG_COMPAT
11231 +
11232 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11233 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11234 +
11235 +#endif /* CONFIG_COMPAT */
11236 +
11237 +#endif /* __KERNEL__ */
11238 +#endif /* _VX_DEVICE_CMD_H */
11239 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/device_def.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/device_def.h
11240 --- linux-2.6.37/include/linux/vserver/device_def.h     1970-01-01 01:00:00.000000000 +0100
11241 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/device_def.h      2010-11-23 02:09:41.000000000 +0100
11242 @@ -0,0 +1,17 @@
11243 +#ifndef _VX_DEVICE_DEF_H
11244 +#define _VX_DEVICE_DEF_H
11245 +
11246 +#include <linux/types.h>
11247 +
11248 +struct vx_dmap_target {
11249 +       dev_t target;
11250 +       uint32_t flags;
11251 +};
11252 +
11253 +struct _vx_device {
11254 +#ifdef CONFIG_VSERVER_DEVICE
11255 +       struct vx_dmap_target targets[2];
11256 +#endif
11257 +};
11258 +
11259 +#endif /* _VX_DEVICE_DEF_H */
11260 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/device.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/device.h
11261 --- linux-2.6.37/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
11262 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/device.h  2010-11-23 02:09:41.000000000 +0100
11263 @@ -0,0 +1,15 @@
11264 +#ifndef _VX_DEVICE_H
11265 +#define _VX_DEVICE_H
11266 +
11267 +
11268 +#define DATTR_CREATE   0x00000001
11269 +#define DATTR_OPEN     0x00000002
11270 +
11271 +#define DATTR_REMAP    0x00000010
11272 +
11273 +#define DATTR_MASK     0x00000013
11274 +
11275 +
11276 +#else  /* _VX_DEVICE_H */
11277 +#warning duplicate inclusion
11278 +#endif /* _VX_DEVICE_H */
11279 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/dlimit_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/dlimit_cmd.h
11280 --- linux-2.6.37/include/linux/vserver/dlimit_cmd.h     1970-01-01 01:00:00.000000000 +0100
11281 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/dlimit_cmd.h      2010-11-23 02:09:41.000000000 +0100
11282 @@ -0,0 +1,109 @@
11283 +#ifndef _VX_DLIMIT_CMD_H
11284 +#define _VX_DLIMIT_CMD_H
11285 +
11286 +
11287 +/*  dlimit vserver commands */
11288 +
11289 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11290 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11291 +
11292 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11293 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11294 +
11295 +struct vcmd_ctx_dlimit_base_v0 {
11296 +       const char __user *name;
11297 +       uint32_t flags;
11298 +};
11299 +
11300 +struct vcmd_ctx_dlimit_v0 {
11301 +       const char __user *name;
11302 +       uint32_t space_used;                    /* used space in kbytes */
11303 +       uint32_t space_total;                   /* maximum space in kbytes */
11304 +       uint32_t inodes_used;                   /* used inodes */
11305 +       uint32_t inodes_total;                  /* maximum inodes */
11306 +       uint32_t reserved;                      /* reserved for root in % */
11307 +       uint32_t flags;
11308 +};
11309 +
11310 +#define CDLIM_UNSET            ((uint32_t)0UL)
11311 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11312 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11313 +
11314 +#define DLIME_UNIT     0
11315 +#define DLIME_KILO     1
11316 +#define DLIME_MEGA     2
11317 +#define DLIME_GIGA     3
11318 +
11319 +#define DLIMF_SHIFT    0x10
11320 +
11321 +#define DLIMS_USED     0
11322 +#define DLIMS_TOTAL    2
11323 +
11324 +static inline
11325 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11326 +{
11327 +       int exp = (flags & DLIMF_SHIFT) ?
11328 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11329 +       return ((uint64_t)val) << (10 * exp);
11330 +}
11331 +
11332 +static inline
11333 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11334 +{
11335 +       int exp = 0;
11336 +
11337 +       if (*flags & DLIMF_SHIFT) {
11338 +               while (val > (1LL << 32) && (exp < 3)) {
11339 +                       val >>= 10;
11340 +                       exp++;
11341 +               }
11342 +               *flags &= ~(DLIME_GIGA << shift);
11343 +               *flags |= exp << shift;
11344 +       } else
11345 +               val >>= 10;
11346 +       return val;
11347 +}
11348 +
11349 +#ifdef __KERNEL__
11350 +
11351 +#ifdef CONFIG_COMPAT
11352 +
11353 +#include <asm/compat.h>
11354 +
11355 +struct vcmd_ctx_dlimit_base_v0_x32 {
11356 +       compat_uptr_t name_ptr;
11357 +       uint32_t flags;
11358 +};
11359 +
11360 +struct vcmd_ctx_dlimit_v0_x32 {
11361 +       compat_uptr_t name_ptr;
11362 +       uint32_t space_used;                    /* used space in kbytes */
11363 +       uint32_t space_total;                   /* maximum space in kbytes */
11364 +       uint32_t inodes_used;                   /* used inodes */
11365 +       uint32_t inodes_total;                  /* maximum inodes */
11366 +       uint32_t reserved;                      /* reserved for root in % */
11367 +       uint32_t flags;
11368 +};
11369 +
11370 +#endif /* CONFIG_COMPAT */
11371 +
11372 +#include <linux/compiler.h>
11373 +
11374 +extern int vc_add_dlimit(uint32_t, void __user *);
11375 +extern int vc_rem_dlimit(uint32_t, void __user *);
11376 +
11377 +extern int vc_set_dlimit(uint32_t, void __user *);
11378 +extern int vc_get_dlimit(uint32_t, void __user *);
11379 +
11380 +#ifdef CONFIG_COMPAT
11381 +
11382 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11383 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11384 +
11385 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11386 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11387 +
11388 +#endif /* CONFIG_COMPAT */
11389 +
11390 +#endif /* __KERNEL__ */
11391 +#endif /* _VX_DLIMIT_CMD_H */
11392 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/dlimit.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/dlimit.h
11393 --- linux-2.6.37/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
11394 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/dlimit.h  2010-11-23 02:09:41.000000000 +0100
11395 @@ -0,0 +1,54 @@
11396 +#ifndef _VX_DLIMIT_H
11397 +#define _VX_DLIMIT_H
11398 +
11399 +#include "switch.h"
11400 +
11401 +
11402 +#ifdef __KERNEL__
11403 +
11404 +/*      keep in sync with CDLIM_INFINITY       */
11405 +
11406 +#define DLIM_INFINITY          (~0ULL)
11407 +
11408 +#include <linux/spinlock.h>
11409 +#include <linux/rcupdate.h>
11410 +
11411 +struct super_block;
11412 +
11413 +struct dl_info {
11414 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11415 +       struct rcu_head dl_rcu;                 /* the rcu head */
11416 +       tag_t dl_tag;                           /* context tag */
11417 +       atomic_t dl_usecnt;                     /* usage count */
11418 +       atomic_t dl_refcnt;                     /* reference count */
11419 +
11420 +       struct super_block *dl_sb;              /* associated superblock */
11421 +
11422 +       spinlock_t dl_lock;                     /* protect the values */
11423 +
11424 +       unsigned long long dl_space_used;       /* used space in bytes */
11425 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11426 +       unsigned long dl_inodes_used;           /* used inodes */
11427 +       unsigned long dl_inodes_total;          /* maximum inodes */
11428 +
11429 +       unsigned int dl_nrlmult;                /* non root limit mult */
11430 +};
11431 +
11432 +struct rcu_head;
11433 +
11434 +extern void rcu_free_dl_info(struct rcu_head *);
11435 +extern void unhash_dl_info(struct dl_info *);
11436 +
11437 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11438 +
11439 +
11440 +struct kstatfs;
11441 +
11442 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11443 +
11444 +typedef uint64_t dlsize_t;
11445 +
11446 +#endif /* __KERNEL__ */
11447 +#else  /* _VX_DLIMIT_H */
11448 +#warning duplicate inclusion
11449 +#endif /* _VX_DLIMIT_H */
11450 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/global.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/global.h
11451 --- linux-2.6.37/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
11452 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/global.h  2010-11-23 02:09:41.000000000 +0100
11453 @@ -0,0 +1,19 @@
11454 +#ifndef _VX_GLOBAL_H
11455 +#define _VX_GLOBAL_H
11456 +
11457 +
11458 +extern atomic_t vx_global_ctotal;
11459 +extern atomic_t vx_global_cactive;
11460 +
11461 +extern atomic_t nx_global_ctotal;
11462 +extern atomic_t nx_global_cactive;
11463 +
11464 +extern atomic_t vs_global_nsproxy;
11465 +extern atomic_t vs_global_fs;
11466 +extern atomic_t vs_global_mnt_ns;
11467 +extern atomic_t vs_global_uts_ns;
11468 +extern atomic_t vs_global_user_ns;
11469 +extern atomic_t vs_global_pid_ns;
11470 +
11471 +
11472 +#endif /* _VX_GLOBAL_H */
11473 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/history.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/history.h
11474 --- linux-2.6.37/include/linux/vserver/history.h        1970-01-01 01:00:00.000000000 +0100
11475 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/history.h 2010-11-23 02:09:41.000000000 +0100
11476 @@ -0,0 +1,197 @@
11477 +#ifndef _VX_HISTORY_H
11478 +#define _VX_HISTORY_H
11479 +
11480 +
11481 +enum {
11482 +       VXH_UNUSED = 0,
11483 +       VXH_THROW_OOPS = 1,
11484 +
11485 +       VXH_GET_VX_INFO,
11486 +       VXH_PUT_VX_INFO,
11487 +       VXH_INIT_VX_INFO,
11488 +       VXH_SET_VX_INFO,
11489 +       VXH_CLR_VX_INFO,
11490 +       VXH_CLAIM_VX_INFO,
11491 +       VXH_RELEASE_VX_INFO,
11492 +       VXH_ALLOC_VX_INFO,
11493 +       VXH_DEALLOC_VX_INFO,
11494 +       VXH_HASH_VX_INFO,
11495 +       VXH_UNHASH_VX_INFO,
11496 +       VXH_LOC_VX_INFO,
11497 +       VXH_LOOKUP_VX_INFO,
11498 +       VXH_CREATE_VX_INFO,
11499 +};
11500 +
11501 +struct _vxhe_vxi {
11502 +       struct vx_info *ptr;
11503 +       unsigned xid;
11504 +       unsigned usecnt;
11505 +       unsigned tasks;
11506 +};
11507 +
11508 +struct _vxhe_set_clr {
11509 +       void *data;
11510 +};
11511 +
11512 +struct _vxhe_loc_lookup {
11513 +       unsigned arg;
11514 +};
11515 +
11516 +struct _vx_hist_entry {
11517 +       void *loc;
11518 +       unsigned short seq;
11519 +       unsigned short type;
11520 +       struct _vxhe_vxi vxi;
11521 +       union {
11522 +               struct _vxhe_set_clr sc;
11523 +               struct _vxhe_loc_lookup ll;
11524 +       };
11525 +};
11526 +
11527 +#ifdef CONFIG_VSERVER_HISTORY
11528 +
11529 +extern unsigned volatile int vxh_active;
11530 +
11531 +struct _vx_hist_entry *vxh_advance(void *loc);
11532 +
11533 +
11534 +static inline
11535 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11536 +{
11537 +       entry->vxi.ptr = vxi;
11538 +       if (vxi) {
11539 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11540 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11541 +               entry->vxi.xid = vxi->vx_id;
11542 +       }
11543 +}
11544 +
11545 +
11546 +#define        __HERE__ current_text_addr()
11547 +
11548 +#define __VXH_BODY(__type, __data, __here)     \
11549 +       struct _vx_hist_entry *entry;           \
11550 +                                               \
11551 +       preempt_disable();                      \
11552 +       entry = vxh_advance(__here);            \
11553 +       __data;                                 \
11554 +       entry->type = __type;                   \
11555 +       preempt_enable();
11556 +
11557 +
11558 +       /* pass vxi only */
11559 +
11560 +#define __VXH_SMPL                             \
11561 +       __vxh_copy_vxi(entry, vxi)
11562 +
11563 +static inline
11564 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11565 +{
11566 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11567 +}
11568 +
11569 +       /* pass vxi and data (void *) */
11570 +
11571 +#define __VXH_DATA                             \
11572 +       __vxh_copy_vxi(entry, vxi);             \
11573 +       entry->sc.data = data
11574 +
11575 +static inline
11576 +void   __vxh_data(struct vx_info *vxi, void *data,
11577 +                       int __type, void *__here)
11578 +{
11579 +       __VXH_BODY(__type, __VXH_DATA, __here)
11580 +}
11581 +
11582 +       /* pass vxi and arg (long) */
11583 +
11584 +#define __VXH_LONG                             \
11585 +       __vxh_copy_vxi(entry, vxi);             \
11586 +       entry->ll.arg = arg
11587 +
11588 +static inline
11589 +void   __vxh_long(struct vx_info *vxi, long arg,
11590 +                       int __type, void *__here)
11591 +{
11592 +       __VXH_BODY(__type, __VXH_LONG, __here)
11593 +}
11594 +
11595 +
11596 +static inline
11597 +void   __vxh_throw_oops(void *__here)
11598 +{
11599 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11600 +       /* prevent further acquisition */
11601 +       vxh_active = 0;
11602 +}
11603 +
11604 +
11605 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11606 +
11607 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11608 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11609 +
11610 +#define __vxh_init_vx_info(v, d, h) \
11611 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11612 +#define __vxh_set_vx_info(v, d, h) \
11613 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11614 +#define __vxh_clr_vx_info(v, d, h) \
11615 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11616 +
11617 +#define __vxh_claim_vx_info(v, d, h) \
11618 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11619 +#define __vxh_release_vx_info(v, d, h) \
11620 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11621 +
11622 +#define vxh_alloc_vx_info(v) \
11623 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11624 +#define vxh_dealloc_vx_info(v) \
11625 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11626 +
11627 +#define vxh_hash_vx_info(v) \
11628 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11629 +#define vxh_unhash_vx_info(v) \
11630 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11631 +
11632 +#define vxh_loc_vx_info(v, l) \
11633 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11634 +#define vxh_lookup_vx_info(v, l) \
11635 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11636 +#define vxh_create_vx_info(v, l) \
11637 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11638 +
11639 +extern void vxh_dump_history(void);
11640 +
11641 +
11642 +#else  /* CONFIG_VSERVER_HISTORY */
11643 +
11644 +#define        __HERE__        0
11645 +
11646 +#define vxh_throw_oops()               do { } while (0)
11647 +
11648 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11649 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11650 +
11651 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11652 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11653 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11654 +
11655 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11656 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11657 +
11658 +#define vxh_alloc_vx_info(v)           do { } while (0)
11659 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11660 +
11661 +#define vxh_hash_vx_info(v)            do { } while (0)
11662 +#define vxh_unhash_vx_info(v)          do { } while (0)
11663 +
11664 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11665 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11666 +#define vxh_create_vx_info(v, l)       do { } while (0)
11667 +
11668 +#define vxh_dump_history()             do { } while (0)
11669 +
11670 +
11671 +#endif /* CONFIG_VSERVER_HISTORY */
11672 +
11673 +#endif /* _VX_HISTORY_H */
11674 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/inode_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/inode_cmd.h
11675 --- linux-2.6.37/include/linux/vserver/inode_cmd.h      1970-01-01 01:00:00.000000000 +0100
11676 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/inode_cmd.h       2010-11-23 02:09:41.000000000 +0100
11677 @@ -0,0 +1,59 @@
11678 +#ifndef _VX_INODE_CMD_H
11679 +#define _VX_INODE_CMD_H
11680 +
11681 +
11682 +/*  inode vserver commands */
11683 +
11684 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11685 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11686 +
11687 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11688 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11689 +
11690 +struct vcmd_ctx_iattr_v1 {
11691 +       const char __user *name;
11692 +       uint32_t tag;
11693 +       uint32_t flags;
11694 +       uint32_t mask;
11695 +};
11696 +
11697 +struct vcmd_ctx_fiattr_v0 {
11698 +       uint32_t tag;
11699 +       uint32_t flags;
11700 +       uint32_t mask;
11701 +};
11702 +
11703 +
11704 +#ifdef __KERNEL__
11705 +
11706 +
11707 +#ifdef CONFIG_COMPAT
11708 +
11709 +#include <asm/compat.h>
11710 +
11711 +struct vcmd_ctx_iattr_v1_x32 {
11712 +       compat_uptr_t name_ptr;
11713 +       uint32_t tag;
11714 +       uint32_t flags;
11715 +       uint32_t mask;
11716 +};
11717 +
11718 +#endif /* CONFIG_COMPAT */
11719 +
11720 +#include <linux/compiler.h>
11721 +
11722 +extern int vc_get_iattr(void __user *);
11723 +extern int vc_set_iattr(void __user *);
11724 +
11725 +extern int vc_fget_iattr(uint32_t, void __user *);
11726 +extern int vc_fset_iattr(uint32_t, void __user *);
11727 +
11728 +#ifdef CONFIG_COMPAT
11729 +
11730 +extern int vc_get_iattr_x32(void __user *);
11731 +extern int vc_set_iattr_x32(void __user *);
11732 +
11733 +#endif /* CONFIG_COMPAT */
11734 +
11735 +#endif /* __KERNEL__ */
11736 +#endif /* _VX_INODE_CMD_H */
11737 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/inode.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/inode.h
11738 --- linux-2.6.37/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
11739 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/inode.h   2010-11-23 02:09:41.000000000 +0100
11740 @@ -0,0 +1,39 @@
11741 +#ifndef _VX_INODE_H
11742 +#define _VX_INODE_H
11743 +
11744 +
11745 +#define IATTR_TAG      0x01000000
11746 +
11747 +#define IATTR_ADMIN    0x00000001
11748 +#define IATTR_WATCH    0x00000002
11749 +#define IATTR_HIDE     0x00000004
11750 +#define IATTR_FLAGS    0x00000007
11751 +
11752 +#define IATTR_BARRIER  0x00010000
11753 +#define IATTR_IXUNLINK 0x00020000
11754 +#define IATTR_IMMUTABLE 0x00040000
11755 +#define IATTR_COW      0x00080000
11756 +
11757 +#ifdef __KERNEL__
11758 +
11759 +
11760 +#ifdef CONFIG_VSERVER_PROC_SECURE
11761 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11762 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11763 +#else
11764 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11765 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11766 +#endif
11767 +
11768 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11769 +
11770 +#endif /* __KERNEL__ */
11771 +
11772 +/* inode ioctls */
11773 +
11774 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11775 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11776 +
11777 +#else  /* _VX_INODE_H */
11778 +#warning duplicate inclusion
11779 +#endif /* _VX_INODE_H */
11780 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/Kbuild linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/Kbuild
11781 --- linux-2.6.37/include/linux/vserver/Kbuild   1970-01-01 01:00:00.000000000 +0100
11782 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/Kbuild    2010-11-23 02:09:41.000000000 +0100
11783 @@ -0,0 +1,8 @@
11784 +
11785 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11786 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11787 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11788 +       debug_cmd.h device_cmd.h
11789 +
11790 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11791 +
11792 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/limit_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/limit_cmd.h
11793 --- linux-2.6.37/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
11794 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/limit_cmd.h       2010-11-23 02:09:41.000000000 +0100
11795 @@ -0,0 +1,71 @@
11796 +#ifndef _VX_LIMIT_CMD_H
11797 +#define _VX_LIMIT_CMD_H
11798 +
11799 +
11800 +/*  rlimit vserver commands */
11801 +
11802 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11803 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11804 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11805 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11806 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11807 +
11808 +struct vcmd_ctx_rlimit_v0 {
11809 +       uint32_t id;
11810 +       uint64_t minimum;
11811 +       uint64_t softlimit;
11812 +       uint64_t maximum;
11813 +};
11814 +
11815 +struct vcmd_ctx_rlimit_mask_v0 {
11816 +       uint32_t minimum;
11817 +       uint32_t softlimit;
11818 +       uint32_t maximum;
11819 +};
11820 +
11821 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11822 +
11823 +struct vcmd_rlimit_stat_v0 {
11824 +       uint32_t id;
11825 +       uint32_t hits;
11826 +       uint64_t value;
11827 +       uint64_t minimum;
11828 +       uint64_t maximum;
11829 +};
11830 +
11831 +#define CRLIM_UNSET            (0ULL)
11832 +#define CRLIM_INFINITY         (~0ULL)
11833 +#define CRLIM_KEEP             (~1ULL)
11834 +
11835 +#ifdef __KERNEL__
11836 +
11837 +#ifdef CONFIG_IA32_EMULATION
11838 +
11839 +struct vcmd_ctx_rlimit_v0_x32 {
11840 +       uint32_t id;
11841 +       uint64_t minimum;
11842 +       uint64_t softlimit;
11843 +       uint64_t maximum;
11844 +} __attribute__ ((packed));
11845 +
11846 +#endif /* CONFIG_IA32_EMULATION */
11847 +
11848 +#include <linux/compiler.h>
11849 +
11850 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11851 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11852 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11853 +extern int vc_reset_hits(struct vx_info *, void __user *);
11854 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11855 +
11856 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11857 +
11858 +#ifdef CONFIG_IA32_EMULATION
11859 +
11860 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11861 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11862 +
11863 +#endif /* CONFIG_IA32_EMULATION */
11864 +
11865 +#endif /* __KERNEL__ */
11866 +#endif /* _VX_LIMIT_CMD_H */
11867 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/limit_def.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/limit_def.h
11868 --- linux-2.6.37/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
11869 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/limit_def.h       2010-11-23 02:09:41.000000000 +0100
11870 @@ -0,0 +1,47 @@
11871 +#ifndef _VX_LIMIT_DEF_H
11872 +#define _VX_LIMIT_DEF_H
11873 +
11874 +#include <asm/atomic.h>
11875 +#include <asm/resource.h>
11876 +
11877 +#include "limit.h"
11878 +
11879 +
11880 +struct _vx_res_limit {
11881 +       rlim_t soft;            /* Context soft limit */
11882 +       rlim_t hard;            /* Context hard limit */
11883 +
11884 +       rlim_atomic_t rcur;     /* Current value */
11885 +       rlim_t rmin;            /* Context minimum */
11886 +       rlim_t rmax;            /* Context maximum */
11887 +
11888 +       atomic_t lhit;          /* Limit hits */
11889 +};
11890 +
11891 +/* context sub struct */
11892 +
11893 +struct _vx_limit {
11894 +       struct _vx_res_limit res[NUM_LIMITS];
11895 +};
11896 +
11897 +#ifdef CONFIG_VSERVER_DEBUG
11898 +
11899 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11900 +{
11901 +       int i;
11902 +
11903 +       printk("\t_vx_limit:");
11904 +       for (i = 0; i < NUM_LIMITS; i++) {
11905 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11906 +                       i, (unsigned long)__rlim_get(limit, i),
11907 +                       (unsigned long)__rlim_rmin(limit, i),
11908 +                       (unsigned long)__rlim_rmax(limit, i),
11909 +                       (long)__rlim_soft(limit, i),
11910 +                       (long)__rlim_hard(limit, i),
11911 +                       atomic_read(&__rlim_lhit(limit, i)));
11912 +       }
11913 +}
11914 +
11915 +#endif
11916 +
11917 +#endif /* _VX_LIMIT_DEF_H */
11918 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/limit.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/limit.h
11919 --- linux-2.6.37/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
11920 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/limit.h   2010-11-23 02:09:41.000000000 +0100
11921 @@ -0,0 +1,71 @@
11922 +#ifndef _VX_LIMIT_H
11923 +#define _VX_LIMIT_H
11924 +
11925 +#define VLIMIT_NSOCK   16
11926 +#define VLIMIT_OPENFD  17
11927 +#define VLIMIT_ANON    18
11928 +#define VLIMIT_SHMEM   19
11929 +#define VLIMIT_SEMARY  20
11930 +#define VLIMIT_NSEMS   21
11931 +#define VLIMIT_DENTRY  22
11932 +#define VLIMIT_MAPPED  23
11933 +
11934 +
11935 +#ifdef __KERNEL__
11936 +
11937 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11938 +
11939 +/*     keep in sync with CRLIM_INFINITY */
11940 +
11941 +#define        VLIM_INFINITY   (~0ULL)
11942 +
11943 +#include <asm/atomic.h>
11944 +#include <asm/resource.h>
11945 +
11946 +#ifndef RLIM_INFINITY
11947 +#warning RLIM_INFINITY is undefined
11948 +#endif
11949 +
11950 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11951 +
11952 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11953 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11954 +
11955 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11956 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11957 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11958 +
11959 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11960 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11961 +
11962 +typedef atomic_long_t rlim_atomic_t;
11963 +typedef unsigned long rlim_t;
11964 +
11965 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11966 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11967 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11968 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11969 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11970 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11971 +
11972 +
11973 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11974 +#define        VX_VLIM(r) ((long long)(long)(r))
11975 +#define        VX_RLIM(v) ((rlim_t)(v))
11976 +#else
11977 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11978 +               ? VLIM_INFINITY : (long long)(r))
11979 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11980 +               ? RLIM_INFINITY : (rlim_t)(v))
11981 +#endif
11982 +
11983 +struct sysinfo;
11984 +
11985 +void vx_vsi_meminfo(struct sysinfo *);
11986 +void vx_vsi_swapinfo(struct sysinfo *);
11987 +long vx_vsi_cached(struct sysinfo *);
11988 +
11989 +#define NUM_LIMITS     24
11990 +
11991 +#endif /* __KERNEL__ */
11992 +#endif /* _VX_LIMIT_H */
11993 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/limit_int.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/limit_int.h
11994 --- linux-2.6.37/include/linux/vserver/limit_int.h      1970-01-01 01:00:00.000000000 +0100
11995 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/limit_int.h       2010-11-23 02:09:41.000000000 +0100
11996 @@ -0,0 +1,198 @@
11997 +#ifndef _VX_LIMIT_INT_H
11998 +#define _VX_LIMIT_INT_H
11999 +
12000 +#include "context.h"
12001 +
12002 +#ifdef __KERNEL__
12003 +
12004 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12005 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12006 +
12007 +extern const char *vlimit_name[NUM_LIMITS];
12008 +
12009 +static inline void __vx_acc_cres(struct vx_info *vxi,
12010 +       int res, int dir, void *_data, char *_file, int _line)
12011 +{
12012 +       if (VXD_RCRES_COND(res))
12013 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12014 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12015 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12016 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12017 +       if (!vxi)
12018 +               return;
12019 +
12020 +       if (dir > 0)
12021 +               __rlim_inc(&vxi->limit, res);
12022 +       else
12023 +               __rlim_dec(&vxi->limit, res);
12024 +}
12025 +
12026 +static inline void __vx_add_cres(struct vx_info *vxi,
12027 +       int res, int amount, void *_data, char *_file, int _line)
12028 +{
12029 +       if (VXD_RCRES_COND(res))
12030 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12031 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12032 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12033 +                       amount, _data, _file, _line);
12034 +       if (amount == 0)
12035 +               return;
12036 +       if (!vxi)
12037 +               return;
12038 +       __rlim_add(&vxi->limit, res, amount);
12039 +}
12040 +
12041 +static inline
12042 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12043 +{
12044 +       int cond = (value > __rlim_rmax(limit, res));
12045 +
12046 +       if (cond)
12047 +               __rlim_rmax(limit, res) = value;
12048 +       return cond;
12049 +}
12050 +
12051 +static inline
12052 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12053 +{
12054 +       int cond = (value < __rlim_rmin(limit, res));
12055 +
12056 +       if (cond)
12057 +               __rlim_rmin(limit, res) = value;
12058 +       return cond;
12059 +}
12060 +
12061 +static inline
12062 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12063 +{
12064 +       if (!__vx_cres_adjust_max(limit, res, value))
12065 +               __vx_cres_adjust_min(limit, res, value);
12066 +}
12067 +
12068 +
12069 +/*     return values:
12070 +        +1 ... no limit hit
12071 +        -1 ... over soft limit
12072 +         0 ... over hard limit         */
12073 +
12074 +static inline int __vx_cres_avail(struct vx_info *vxi,
12075 +       int res, int num, char *_file, int _line)
12076 +{
12077 +       struct _vx_limit *limit;
12078 +       rlim_t value;
12079 +
12080 +       if (VXD_RLIMIT_COND(res))
12081 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12082 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12083 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12084 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12085 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12086 +                       num, _file, _line);
12087 +       if (!vxi)
12088 +               return 1;
12089 +
12090 +       limit = &vxi->limit;
12091 +       value = __rlim_get(limit, res);
12092 +
12093 +       if (!__vx_cres_adjust_max(limit, res, value))
12094 +               __vx_cres_adjust_min(limit, res, value);
12095 +
12096 +       if (num == 0)
12097 +               return 1;
12098 +
12099 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12100 +               return -1;
12101 +       if (value + num <= __rlim_soft(limit, res))
12102 +               return -1;
12103 +
12104 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12105 +               return 1;
12106 +       if (value + num <= __rlim_hard(limit, res))
12107 +               return 1;
12108 +
12109 +       __rlim_hit(limit, res);
12110 +       return 0;
12111 +}
12112 +
12113 +
12114 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12115 +
12116 +static inline
12117 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12118 +{
12119 +       rlim_t value, sum = 0;
12120 +       int res;
12121 +
12122 +       while ((res = *array++)) {
12123 +               value = __rlim_get(limit, res);
12124 +               __vx_cres_fixup(limit, res, value);
12125 +               sum += value;
12126 +       }
12127 +       return sum;
12128 +}
12129 +
12130 +static inline
12131 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12132 +{
12133 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12134 +       int res = *array;
12135 +
12136 +       if (value == __rlim_get(limit, res))
12137 +               return value;
12138 +
12139 +       __rlim_set(limit, res, value);
12140 +       /* now adjust min/max */
12141 +       if (!__vx_cres_adjust_max(limit, res, value))
12142 +               __vx_cres_adjust_min(limit, res, value);
12143 +
12144 +       return value;
12145 +}
12146 +
12147 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12148 +       const int *array, int num, char *_file, int _line)
12149 +{
12150 +       struct _vx_limit *limit;
12151 +       rlim_t value = 0;
12152 +       int res;
12153 +
12154 +       if (num == 0)
12155 +               return 1;
12156 +       if (!vxi)
12157 +               return 1;
12158 +
12159 +       limit = &vxi->limit;
12160 +       res = *array;
12161 +       value = __vx_cres_array_sum(limit, array + 1);
12162 +
12163 +       __rlim_set(limit, res, value);
12164 +       __vx_cres_fixup(limit, res, value);
12165 +
12166 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12167 +}
12168 +
12169 +
12170 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12171 +{
12172 +       rlim_t value;
12173 +       int res;
12174 +
12175 +       /* complex resources first */
12176 +       if ((id < 0) || (id == RLIMIT_RSS))
12177 +               __vx_cres_array_fixup(limit, VLA_RSS);
12178 +
12179 +       for (res = 0; res < NUM_LIMITS; res++) {
12180 +               if ((id > 0) && (res != id))
12181 +                       continue;
12182 +
12183 +               value = __rlim_get(limit, res);
12184 +               __vx_cres_fixup(limit, res, value);
12185 +
12186 +               /* not supposed to happen, maybe warn? */
12187 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12188 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12189 +       }
12190 +}
12191 +
12192 +
12193 +#endif /* __KERNEL__ */
12194 +#endif /* _VX_LIMIT_INT_H */
12195 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/monitor.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/monitor.h
12196 --- linux-2.6.37/include/linux/vserver/monitor.h        1970-01-01 01:00:00.000000000 +0100
12197 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/monitor.h 2010-11-23 02:09:41.000000000 +0100
12198 @@ -0,0 +1,96 @@
12199 +#ifndef _VX_MONITOR_H
12200 +#define _VX_MONITOR_H
12201 +
12202 +#include <linux/types.h>
12203 +
12204 +enum {
12205 +       VXM_UNUSED = 0,
12206 +
12207 +       VXM_SYNC = 0x10,
12208 +
12209 +       VXM_UPDATE = 0x20,
12210 +       VXM_UPDATE_1,
12211 +       VXM_UPDATE_2,
12212 +
12213 +       VXM_RQINFO_1 = 0x24,
12214 +       VXM_RQINFO_2,
12215 +
12216 +       VXM_ACTIVATE = 0x40,
12217 +       VXM_DEACTIVATE,
12218 +       VXM_IDLE,
12219 +
12220 +       VXM_HOLD = 0x44,
12221 +       VXM_UNHOLD,
12222 +
12223 +       VXM_MIGRATE = 0x48,
12224 +       VXM_RESCHED,
12225 +
12226 +       /* all other bits are flags */
12227 +       VXM_SCHED = 0x80,
12228 +};
12229 +
12230 +struct _vxm_update_1 {
12231 +       uint32_t tokens_max;
12232 +       uint32_t fill_rate;
12233 +       uint32_t interval;
12234 +};
12235 +
12236 +struct _vxm_update_2 {
12237 +       uint32_t tokens_min;
12238 +       uint32_t fill_rate;
12239 +       uint32_t interval;
12240 +};
12241 +
12242 +struct _vxm_rqinfo_1 {
12243 +       uint16_t running;
12244 +       uint16_t onhold;
12245 +       uint16_t iowait;
12246 +       uint16_t uintr;
12247 +       uint32_t idle_tokens;
12248 +};
12249 +
12250 +struct _vxm_rqinfo_2 {
12251 +       uint32_t norm_time;
12252 +       uint32_t idle_time;
12253 +       uint32_t idle_skip;
12254 +};
12255 +
12256 +struct _vxm_sched {
12257 +       uint32_t tokens;
12258 +       uint32_t norm_time;
12259 +       uint32_t idle_time;
12260 +};
12261 +
12262 +struct _vxm_task {
12263 +       uint16_t pid;
12264 +       uint16_t state;
12265 +};
12266 +
12267 +struct _vxm_event {
12268 +       uint32_t jif;
12269 +       union {
12270 +               uint32_t seq;
12271 +               uint32_t sec;
12272 +       };
12273 +       union {
12274 +               uint32_t tokens;
12275 +               uint32_t nsec;
12276 +               struct _vxm_task tsk;
12277 +       };
12278 +};
12279 +
12280 +struct _vx_mon_entry {
12281 +       uint16_t type;
12282 +       uint16_t xid;
12283 +       union {
12284 +               struct _vxm_event ev;
12285 +               struct _vxm_sched sd;
12286 +               struct _vxm_update_1 u1;
12287 +               struct _vxm_update_2 u2;
12288 +               struct _vxm_rqinfo_1 q1;
12289 +               struct _vxm_rqinfo_2 q2;
12290 +       };
12291 +};
12292 +
12293 +
12294 +#endif /* _VX_MONITOR_H */
12295 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/network_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/network_cmd.h
12296 --- linux-2.6.37/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
12297 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/network_cmd.h     2010-11-23 02:09:41.000000000 +0100
12298 @@ -0,0 +1,150 @@
12299 +#ifndef _VX_NETWORK_CMD_H
12300 +#define _VX_NETWORK_CMD_H
12301 +
12302 +
12303 +/* vinfo commands */
12304 +
12305 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12306 +
12307 +#ifdef __KERNEL__
12308 +extern int vc_task_nid(uint32_t);
12309 +
12310 +#endif /* __KERNEL__ */
12311 +
12312 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12313 +
12314 +struct vcmd_nx_info_v0 {
12315 +       uint32_t nid;
12316 +       /* more to come */
12317 +};
12318 +
12319 +#ifdef __KERNEL__
12320 +extern int vc_nx_info(struct nx_info *, void __user *);
12321 +
12322 +#endif /* __KERNEL__ */
12323 +
12324 +#include <linux/in.h>
12325 +#include <linux/in6.h>
12326 +
12327 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12328 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12329 +
12330 +struct  vcmd_net_create {
12331 +       uint64_t flagword;
12332 +};
12333 +
12334 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12335 +
12336 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12337 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12338 +
12339 +struct vcmd_net_addr_v0 {
12340 +       uint16_t type;
12341 +       uint16_t count;
12342 +       struct in_addr ip[4];
12343 +       struct in_addr mask[4];
12344 +};
12345 +
12346 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12347 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12348 +
12349 +struct vcmd_net_addr_ipv4_v1 {
12350 +       uint16_t type;
12351 +       uint16_t flags;
12352 +       struct in_addr ip;
12353 +       struct in_addr mask;
12354 +};
12355 +
12356 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12357 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12358 +
12359 +struct vcmd_net_addr_ipv6_v1 {
12360 +       uint16_t type;
12361 +       uint16_t flags;
12362 +       uint32_t prefix;
12363 +       struct in6_addr ip;
12364 +       struct in6_addr mask;
12365 +};
12366 +
12367 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12368 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12369 +
12370 +struct vcmd_match_ipv4_v0 {
12371 +       uint16_t type;
12372 +       uint16_t flags;
12373 +       uint16_t parent;
12374 +       uint16_t prefix;
12375 +       struct in_addr ip;
12376 +       struct in_addr ip2;
12377 +       struct in_addr mask;
12378 +};
12379 +
12380 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12381 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12382 +
12383 +struct vcmd_match_ipv6_v0 {
12384 +       uint16_t type;
12385 +       uint16_t flags;
12386 +       uint16_t parent;
12387 +       uint16_t prefix;
12388 +       struct in6_addr ip;
12389 +       struct in6_addr ip2;
12390 +       struct in6_addr mask;
12391 +};
12392 +
12393 +
12394 +#ifdef __KERNEL__
12395 +extern int vc_net_create(uint32_t, void __user *);
12396 +extern int vc_net_migrate(struct nx_info *, void __user *);
12397 +
12398 +extern int vc_net_add(struct nx_info *, void __user *);
12399 +extern int vc_net_remove(struct nx_info *, void __user *);
12400 +
12401 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12402 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12403 +
12404 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12405 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12406 +
12407 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12408 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12409 +
12410 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12411 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12412 +
12413 +#endif /* __KERNEL__ */
12414 +
12415 +
12416 +/* flag commands */
12417 +
12418 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12419 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12420 +
12421 +struct vcmd_net_flags_v0 {
12422 +       uint64_t flagword;
12423 +       uint64_t mask;
12424 +};
12425 +
12426 +#ifdef __KERNEL__
12427 +extern int vc_get_nflags(struct nx_info *, void __user *);
12428 +extern int vc_set_nflags(struct nx_info *, void __user *);
12429 +
12430 +#endif /* __KERNEL__ */
12431 +
12432 +
12433 +/* network caps commands */
12434 +
12435 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12436 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12437 +
12438 +struct vcmd_net_caps_v0 {
12439 +       uint64_t ncaps;
12440 +       uint64_t cmask;
12441 +};
12442 +
12443 +#ifdef __KERNEL__
12444 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12445 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12446 +
12447 +#endif /* __KERNEL__ */
12448 +#endif /* _VX_CONTEXT_CMD_H */
12449 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/network.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/network.h
12450 --- linux-2.6.37/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
12451 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/network.h 2010-11-23 02:09:41.000000000 +0100
12452 @@ -0,0 +1,146 @@
12453 +#ifndef _VX_NETWORK_H
12454 +#define _VX_NETWORK_H
12455 +
12456 +#include <linux/types.h>
12457 +
12458 +
12459 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12460 +
12461 +
12462 +/* network flags */
12463 +
12464 +#define NXF_INFO_PRIVATE       0x00000008
12465 +
12466 +#define NXF_SINGLE_IP          0x00000100
12467 +#define NXF_LBACK_REMAP                0x00000200
12468 +#define NXF_LBACK_ALLOW                0x00000400
12469 +
12470 +#define NXF_HIDE_NETIF         0x02000000
12471 +#define NXF_HIDE_LBACK         0x04000000
12472 +
12473 +#define NXF_STATE_SETUP                (1ULL << 32)
12474 +#define NXF_STATE_ADMIN                (1ULL << 34)
12475 +
12476 +#define NXF_SC_HELPER          (1ULL << 36)
12477 +#define NXF_PERSISTENT         (1ULL << 38)
12478 +
12479 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12480 +
12481 +
12482 +#define        NXF_INIT_SET            (__nxf_init_set())
12483 +
12484 +static inline uint64_t __nxf_init_set(void) {
12485 +       return    NXF_STATE_ADMIN
12486 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12487 +               | NXF_LBACK_REMAP
12488 +               | NXF_HIDE_LBACK
12489 +#endif
12490 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12491 +               | NXF_SINGLE_IP
12492 +#endif
12493 +               | NXF_HIDE_NETIF;
12494 +}
12495 +
12496 +
12497 +/* network caps */
12498 +
12499 +#define NXC_TUN_CREATE         0x00000001
12500 +
12501 +#define NXC_RAW_ICMP           0x00000100
12502 +
12503 +
12504 +/* address types */
12505 +
12506 +#define NXA_TYPE_IPV4          0x0001
12507 +#define NXA_TYPE_IPV6          0x0002
12508 +
12509 +#define NXA_TYPE_NONE          0x0000
12510 +#define NXA_TYPE_ANY           0x00FF
12511 +
12512 +#define NXA_TYPE_ADDR          0x0010
12513 +#define NXA_TYPE_MASK          0x0020
12514 +#define NXA_TYPE_RANGE         0x0040
12515 +
12516 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12517 +
12518 +#define NXA_MOD_BCAST          0x0100
12519 +#define NXA_MOD_LBACK          0x0200
12520 +
12521 +#define NXA_LOOPBACK           0x1000
12522 +
12523 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12524 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12525 +
12526 +#ifdef __KERNEL__
12527 +
12528 +#include <linux/list.h>
12529 +#include <linux/spinlock.h>
12530 +#include <linux/rcupdate.h>
12531 +#include <linux/in.h>
12532 +#include <linux/in6.h>
12533 +#include <asm/atomic.h>
12534 +
12535 +struct nx_addr_v4 {
12536 +       struct nx_addr_v4 *next;
12537 +       struct in_addr ip[2];
12538 +       struct in_addr mask;
12539 +       uint16_t type;
12540 +       uint16_t flags;
12541 +};
12542 +
12543 +struct nx_addr_v6 {
12544 +       struct nx_addr_v6 *next;
12545 +       struct in6_addr ip;
12546 +       struct in6_addr mask;
12547 +       uint32_t prefix;
12548 +       uint16_t type;
12549 +       uint16_t flags;
12550 +};
12551 +
12552 +struct nx_info {
12553 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12554 +       nid_t nx_id;                    /* vnet id */
12555 +       atomic_t nx_usecnt;             /* usage count */
12556 +       atomic_t nx_tasks;              /* tasks count */
12557 +       int nx_state;                   /* context state */
12558 +
12559 +       uint64_t nx_flags;              /* network flag word */
12560 +       uint64_t nx_ncaps;              /* network capabilities */
12561 +
12562 +       struct in_addr v4_lback;        /* Loopback address */
12563 +       struct in_addr v4_bcast;        /* Broadcast address */
12564 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12565 +#ifdef CONFIG_IPV6
12566 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12567 +#endif
12568 +       char nx_name[65];               /* network context name */
12569 +};
12570 +
12571 +
12572 +/* status flags */
12573 +
12574 +#define NXS_HASHED      0x0001
12575 +#define NXS_SHUTDOWN    0x0100
12576 +#define NXS_RELEASED    0x8000
12577 +
12578 +extern struct nx_info *lookup_nx_info(int);
12579 +
12580 +extern int get_nid_list(int, unsigned int *, int);
12581 +extern int nid_is_hashed(nid_t);
12582 +
12583 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12584 +
12585 +extern long vs_net_change(struct nx_info *, unsigned int);
12586 +
12587 +struct sock;
12588 +
12589 +
12590 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12591 +#ifdef  CONFIG_IPV6
12592 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12593 +#else
12594 +#define NX_IPV6(n)     (0)
12595 +#endif
12596 +
12597 +#endif /* __KERNEL__ */
12598 +#endif /* _VX_NETWORK_H */
12599 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/percpu.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/percpu.h
12600 --- linux-2.6.37/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
12601 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/percpu.h  2010-11-23 02:09:41.000000000 +0100
12602 @@ -0,0 +1,14 @@
12603 +#ifndef _VX_PERCPU_H
12604 +#define _VX_PERCPU_H
12605 +
12606 +#include "cvirt_def.h"
12607 +#include "sched_def.h"
12608 +
12609 +struct _vx_percpu {
12610 +       struct _vx_cvirt_pc cvirt;
12611 +       struct _vx_sched_pc sched;
12612 +};
12613 +
12614 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12615 +
12616 +#endif /* _VX_PERCPU_H */
12617 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/pid.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/pid.h
12618 --- linux-2.6.37/include/linux/vserver/pid.h    1970-01-01 01:00:00.000000000 +0100
12619 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/pid.h     2010-11-23 02:09:41.000000000 +0100
12620 @@ -0,0 +1,51 @@
12621 +#ifndef _VSERVER_PID_H
12622 +#define _VSERVER_PID_H
12623 +
12624 +/* pid faking stuff */
12625 +
12626 +#define vx_info_map_pid(v, p) \
12627 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12628 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12629 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12630 +#define vx_map_tgid(p) vx_map_pid(p)
12631 +
12632 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12633 +       const char *func, const char *file, int line)
12634 +{
12635 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12636 +               vxfprintk(VXD_CBIT(cvirt, 2),
12637 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12638 +                       vxi, (long long)vxi->vx_flags, pid,
12639 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12640 +                       func, file, line);
12641 +               if (pid == 0)
12642 +                       return 0;
12643 +               if (pid == vxi->vx_initpid)
12644 +                       return 1;
12645 +       }
12646 +       return pid;
12647 +}
12648 +
12649 +#define vx_info_rmap_pid(v, p) \
12650 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12651 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12652 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12653 +
12654 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12655 +       const char *func, const char *file, int line)
12656 +{
12657 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12658 +               vxfprintk(VXD_CBIT(cvirt, 2),
12659 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12660 +                       vxi, (long long)vxi->vx_flags, pid,
12661 +                       (pid == 1) ? vxi->vx_initpid : pid,
12662 +                       func, file, line);
12663 +               if ((pid == 1) && vxi->vx_initpid)
12664 +                       return vxi->vx_initpid;
12665 +               if (pid == vxi->vx_initpid)
12666 +                       return ~0U;
12667 +       }
12668 +       return pid;
12669 +}
12670 +
12671 +#endif
12672 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/sched_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/sched_cmd.h
12673 --- linux-2.6.37/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
12674 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/sched_cmd.h       2010-11-23 02:09:41.000000000 +0100
12675 @@ -0,0 +1,21 @@
12676 +#ifndef _VX_SCHED_CMD_H
12677 +#define _VX_SCHED_CMD_H
12678 +
12679 +
12680 +struct vcmd_prio_bias {
12681 +       int32_t cpu_id;
12682 +       int32_t prio_bias;
12683 +};
12684 +
12685 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
12686 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
12687 +
12688 +#ifdef __KERNEL__
12689 +
12690 +#include <linux/compiler.h>
12691 +
12692 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12693 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12694 +
12695 +#endif /* __KERNEL__ */
12696 +#endif /* _VX_SCHED_CMD_H */
12697 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/sched_def.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/sched_def.h
12698 --- linux-2.6.37/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
12699 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/sched_def.h       2010-11-23 02:09:41.000000000 +0100
12700 @@ -0,0 +1,38 @@
12701 +#ifndef _VX_SCHED_DEF_H
12702 +#define _VX_SCHED_DEF_H
12703 +
12704 +#include <linux/spinlock.h>
12705 +#include <linux/jiffies.h>
12706 +#include <linux/cpumask.h>
12707 +#include <asm/atomic.h>
12708 +#include <asm/param.h>
12709 +
12710 +
12711 +/* context sub struct */
12712 +
12713 +struct _vx_sched {
12714 +       int prio_bias;                  /* bias offset for priority */
12715 +
12716 +       cpumask_t update;               /* CPUs which should update */
12717 +};
12718 +
12719 +struct _vx_sched_pc {
12720 +       int prio_bias;                  /* bias offset for priority */
12721 +
12722 +       uint64_t user_ticks;            /* token tick events */
12723 +       uint64_t sys_ticks;             /* token tick events */
12724 +       uint64_t hold_ticks;            /* token ticks paused */
12725 +};
12726 +
12727 +
12728 +#ifdef CONFIG_VSERVER_DEBUG
12729 +
12730 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12731 +{
12732 +       printk("\t_vx_sched:\n");
12733 +       printk("\t priority = %4d\n", sched->prio_bias);
12734 +}
12735 +
12736 +#endif
12737 +
12738 +#endif /* _VX_SCHED_DEF_H */
12739 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/sched.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/sched.h
12740 --- linux-2.6.37/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
12741 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/sched.h   2010-11-23 02:09:41.000000000 +0100
12742 @@ -0,0 +1,23 @@
12743 +#ifndef _VX_SCHED_H
12744 +#define _VX_SCHED_H
12745 +
12746 +
12747 +#ifdef __KERNEL__
12748 +
12749 +struct timespec;
12750 +
12751 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12752 +
12753 +
12754 +struct vx_info;
12755 +
12756 +void vx_update_load(struct vx_info *);
12757 +
12758 +
12759 +void vx_update_sched_param(struct _vx_sched *sched,
12760 +       struct _vx_sched_pc *sched_pc);
12761 +
12762 +#endif /* __KERNEL__ */
12763 +#else  /* _VX_SCHED_H */
12764 +#warning duplicate inclusion
12765 +#endif /* _VX_SCHED_H */
12766 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/signal_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/signal_cmd.h
12767 --- linux-2.6.37/include/linux/vserver/signal_cmd.h     1970-01-01 01:00:00.000000000 +0100
12768 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/signal_cmd.h      2010-11-23 02:09:41.000000000 +0100
12769 @@ -0,0 +1,43 @@
12770 +#ifndef _VX_SIGNAL_CMD_H
12771 +#define _VX_SIGNAL_CMD_H
12772 +
12773 +
12774 +/*  signalling vserver commands */
12775 +
12776 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12777 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12778 +
12779 +struct vcmd_ctx_kill_v0 {
12780 +       int32_t pid;
12781 +       int32_t sig;
12782 +};
12783 +
12784 +struct vcmd_wait_exit_v0 {
12785 +       int32_t reboot_cmd;
12786 +       int32_t exit_code;
12787 +};
12788 +
12789 +#ifdef __KERNEL__
12790 +
12791 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12792 +extern int vc_wait_exit(struct vx_info *, void __user *);
12793 +
12794 +#endif /* __KERNEL__ */
12795 +
12796 +/*  process alteration commands */
12797 +
12798 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12799 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12800 +
12801 +struct vcmd_pflags_v0 {
12802 +       uint32_t flagword;
12803 +       uint32_t mask;
12804 +};
12805 +
12806 +#ifdef __KERNEL__
12807 +
12808 +extern int vc_get_pflags(uint32_t pid, void __user *);
12809 +extern int vc_set_pflags(uint32_t pid, void __user *);
12810 +
12811 +#endif /* __KERNEL__ */
12812 +#endif /* _VX_SIGNAL_CMD_H */
12813 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/signal.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/signal.h
12814 --- linux-2.6.37/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
12815 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/signal.h  2010-11-23 02:09:41.000000000 +0100
12816 @@ -0,0 +1,14 @@
12817 +#ifndef _VX_SIGNAL_H
12818 +#define _VX_SIGNAL_H
12819 +
12820 +
12821 +#ifdef __KERNEL__
12822 +
12823 +struct vx_info;
12824 +
12825 +int vx_info_kill(struct vx_info *, int, int);
12826 +
12827 +#endif /* __KERNEL__ */
12828 +#else  /* _VX_SIGNAL_H */
12829 +#warning duplicate inclusion
12830 +#endif /* _VX_SIGNAL_H */
12831 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/space_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/space_cmd.h
12832 --- linux-2.6.37/include/linux/vserver/space_cmd.h      1970-01-01 01:00:00.000000000 +0100
12833 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/space_cmd.h       2010-11-23 02:09:41.000000000 +0100
12834 @@ -0,0 +1,38 @@
12835 +#ifndef _VX_SPACE_CMD_H
12836 +#define _VX_SPACE_CMD_H
12837 +
12838 +
12839 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12840 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12841 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12842 +
12843 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12844 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12845 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12846 +
12847 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12848 +
12849 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12850 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12851 +
12852 +
12853 +struct vcmd_space_mask_v1 {
12854 +       uint64_t mask;
12855 +};
12856 +
12857 +struct vcmd_space_mask_v2 {
12858 +       uint64_t mask;
12859 +       uint32_t index;
12860 +};
12861 +
12862 +
12863 +#ifdef __KERNEL__
12864 +
12865 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12866 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12867 +extern int vc_enter_space(struct vx_info *, void __user *);
12868 +extern int vc_set_space(struct vx_info *, void __user *);
12869 +extern int vc_get_space_mask(void __user *, int);
12870 +
12871 +#endif /* __KERNEL__ */
12872 +#endif /* _VX_SPACE_CMD_H */
12873 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/space.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/space.h
12874 --- linux-2.6.37/include/linux/vserver/space.h  1970-01-01 01:00:00.000000000 +0100
12875 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/space.h   2010-11-23 02:09:41.000000000 +0100
12876 @@ -0,0 +1,12 @@
12877 +#ifndef _VX_SPACE_H
12878 +#define _VX_SPACE_H
12879 +
12880 +#include <linux/types.h>
12881 +
12882 +struct vx_info;
12883 +
12884 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12885 +
12886 +#else  /* _VX_SPACE_H */
12887 +#warning duplicate inclusion
12888 +#endif /* _VX_SPACE_H */
12889 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/switch.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/switch.h
12890 --- linux-2.6.37/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
12891 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/switch.h  2010-11-23 02:09:41.000000000 +0100
12892 @@ -0,0 +1,98 @@
12893 +#ifndef _VX_SWITCH_H
12894 +#define _VX_SWITCH_H
12895 +
12896 +#include <linux/types.h>
12897 +
12898 +
12899 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12900 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12901 +#define VC_VERSION(c)          ((c) & 0xFFF)
12902 +
12903 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12904 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12905 +
12906 +/*
12907 +
12908 +  Syscall Matrix V2.8
12909 +
12910 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12911 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12912 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12913 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12914 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12915 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12916 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12917 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12918 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12919 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12920 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12921 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12922 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12923 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12924 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12925 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12926 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12927 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12928 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12929 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12930 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12931 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12932 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12933 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12934 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12935 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12936 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12937 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12938 +
12939 +*/
12940 +
12941 +#define VC_CAT_VERSION         0
12942 +
12943 +#define VC_CAT_VSETUP          1
12944 +#define VC_CAT_VHOST           2
12945 +
12946 +#define VC_CAT_DEVICE          6
12947 +
12948 +#define VC_CAT_VPROC           9
12949 +#define VC_CAT_PROCALT         10
12950 +#define VC_CAT_PROCMIG         11
12951 +#define VC_CAT_PROCTRL         12
12952 +
12953 +#define VC_CAT_SCHED           14
12954 +#define VC_CAT_MEMCTRL         20
12955 +
12956 +#define VC_CAT_VNET            25
12957 +#define VC_CAT_NETALT          26
12958 +#define VC_CAT_NETMIG          27
12959 +#define VC_CAT_NETCTRL         28
12960 +
12961 +#define VC_CAT_TAGMIG          35
12962 +#define VC_CAT_DLIMIT          36
12963 +#define VC_CAT_INODE           38
12964 +
12965 +#define VC_CAT_VSTAT           40
12966 +#define VC_CAT_VINFO           46
12967 +#define VC_CAT_EVENT           48
12968 +
12969 +#define VC_CAT_FLAGS           52
12970 +#define VC_CAT_VSPACE          54
12971 +#define VC_CAT_DEBUG           56
12972 +#define VC_CAT_RLIMIT          60
12973 +
12974 +#define VC_CAT_SYSTEST         61
12975 +#define VC_CAT_COMPAT          63
12976 +
12977 +/*  query version */
12978 +
12979 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12980 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12981 +
12982 +
12983 +#ifdef __KERNEL__
12984 +
12985 +#include <linux/errno.h>
12986 +
12987 +#endif /* __KERNEL__ */
12988 +
12989 +#endif /* _VX_SWITCH_H */
12990 +
12991 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/tag_cmd.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/tag_cmd.h
12992 --- linux-2.6.37/include/linux/vserver/tag_cmd.h        1970-01-01 01:00:00.000000000 +0100
12993 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/tag_cmd.h 2010-11-23 02:09:41.000000000 +0100
12994 @@ -0,0 +1,22 @@
12995 +#ifndef _VX_TAG_CMD_H
12996 +#define _VX_TAG_CMD_H
12997 +
12998 +
12999 +/* vinfo commands */
13000 +
13001 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13002 +
13003 +#ifdef __KERNEL__
13004 +extern int vc_task_tag(uint32_t);
13005 +
13006 +#endif /* __KERNEL__ */
13007 +
13008 +/* context commands */
13009 +
13010 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13011 +
13012 +#ifdef __KERNEL__
13013 +extern int vc_tag_migrate(uint32_t);
13014 +
13015 +#endif /* __KERNEL__ */
13016 +#endif /* _VX_TAG_CMD_H */
13017 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/tag.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/tag.h
13018 --- linux-2.6.37/include/linux/vserver/tag.h    1970-01-01 01:00:00.000000000 +0100
13019 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vserver/tag.h     2010-11-23 02:09:41.000000000 +0100
13020 @@ -0,0 +1,143 @@
13021 +#ifndef _DX_TAG_H
13022 +#define _DX_TAG_H
13023 +
13024 +#include <linux/types.h>
13025 +
13026 +
13027 +#define DX_TAG(in)     (IS_TAGGED(in))
13028 +
13029 +
13030 +#ifdef CONFIG_TAG_NFSD
13031 +#define DX_TAG_NFSD    1
13032 +#else
13033 +#define DX_TAG_NFSD    0
13034 +#endif
13035 +
13036 +
13037 +#ifdef CONFIG_TAGGING_NONE
13038 +
13039 +#define MAX_UID                0xFFFFFFFF
13040 +#define MAX_GID                0xFFFFFFFF
13041 +
13042 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13043 +
13044 +#define TAGINO_UID(cond, uid, tag)     (uid)
13045 +#define TAGINO_GID(cond, gid, tag)     (gid)
13046 +
13047 +#endif
13048 +
13049 +
13050 +#ifdef CONFIG_TAGGING_GID16
13051 +
13052 +#define MAX_UID                0xFFFFFFFF
13053 +#define MAX_GID                0x0000FFFF
13054 +
13055 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13056 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13057 +
13058 +#define TAGINO_UID(cond, uid, tag)     (uid)
13059 +#define TAGINO_GID(cond, gid, tag)     \
13060 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13061 +
13062 +#endif
13063 +
13064 +
13065 +#ifdef CONFIG_TAGGING_ID24
13066 +
13067 +#define MAX_UID                0x00FFFFFF
13068 +#define MAX_GID                0x00FFFFFF
13069 +
13070 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13071 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13072 +
13073 +#define TAGINO_UID(cond, uid, tag)     \
13074 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13075 +#define TAGINO_GID(cond, gid, tag)     \
13076 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13077 +
13078 +#endif
13079 +
13080 +
13081 +#ifdef CONFIG_TAGGING_UID16
13082 +
13083 +#define MAX_UID                0x0000FFFF
13084 +#define MAX_GID                0xFFFFFFFF
13085 +
13086 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13087 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13088 +
13089 +#define TAGINO_UID(cond, uid, tag)     \
13090 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13091 +#define TAGINO_GID(cond, gid, tag)     (gid)
13092 +
13093 +#endif
13094 +
13095 +
13096 +#ifdef CONFIG_TAGGING_INTERN
13097 +
13098 +#define MAX_UID                0xFFFFFFFF
13099 +#define MAX_GID                0xFFFFFFFF
13100 +
13101 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13102 +       ((cond) ? (tag) : 0)
13103 +
13104 +#define TAGINO_UID(cond, uid, tag)     (uid)
13105 +#define TAGINO_GID(cond, gid, tag)     (gid)
13106 +
13107 +#endif
13108 +
13109 +
13110 +#ifndef CONFIG_TAGGING_NONE
13111 +#define dx_current_fstag(sb)   \
13112 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13113 +#else
13114 +#define dx_current_fstag(sb)   (0)
13115 +#endif
13116 +
13117 +#ifndef CONFIG_TAGGING_INTERN
13118 +#define TAGINO_TAG(cond, tag)  (0)
13119 +#else
13120 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13121 +#endif
13122 +
13123 +#define INOTAG_UID(cond, uid, gid)     \
13124 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13125 +#define INOTAG_GID(cond, uid, gid)     \
13126 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13127 +
13128 +
13129 +static inline uid_t dx_map_uid(uid_t uid)
13130 +{
13131 +       if ((uid > MAX_UID) && (uid != -1))
13132 +               uid = -2;
13133 +       return (uid & MAX_UID);
13134 +}
13135 +
13136 +static inline gid_t dx_map_gid(gid_t gid)
13137 +{
13138 +       if ((gid > MAX_GID) && (gid != -1))
13139 +               gid = -2;
13140 +       return (gid & MAX_GID);
13141 +}
13142 +
13143 +struct peer_tag {
13144 +       int32_t xid;
13145 +       int32_t nid;
13146 +};
13147 +
13148 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13149 +
13150 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13151 +                unsigned long *flags);
13152 +
13153 +#ifdef CONFIG_PROPAGATE
13154 +
13155 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13156 +
13157 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13158 +
13159 +#else
13160 +#define dx_propagate_tag(n, i) do { } while (0)
13161 +#endif
13162 +
13163 +#endif /* _DX_TAG_H */
13164 diff -NurpP --minimal linux-2.6.37/include/linux/vs_inet6.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_inet6.h
13165 --- linux-2.6.37/include/linux/vs_inet6.h       1970-01-01 01:00:00.000000000 +0100
13166 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_inet6.h        2010-11-23 02:09:41.000000000 +0100
13167 @@ -0,0 +1,246 @@
13168 +#ifndef _VS_INET6_H
13169 +#define _VS_INET6_H
13170 +
13171 +#include "vserver/base.h"
13172 +#include "vserver/network.h"
13173 +#include "vserver/debug.h"
13174 +
13175 +#include <net/ipv6.h>
13176 +
13177 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13178 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13179 +
13180 +
13181 +#ifdef CONFIG_IPV6
13182 +
13183 +static inline
13184 +int v6_addr_match(struct nx_addr_v6 *nxa,
13185 +       const struct in6_addr *addr, uint16_t mask)
13186 +{
13187 +       int ret = 0;
13188 +
13189 +       switch (nxa->type & mask) {
13190 +       case NXA_TYPE_MASK:
13191 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13192 +               break;
13193 +       case NXA_TYPE_ADDR:
13194 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13195 +               break;
13196 +       case NXA_TYPE_ANY:
13197 +               ret = 1;
13198 +               break;
13199 +       }
13200 +       vxdprintk(VXD_CBIT(net, 0),
13201 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13202 +               nxa, NXAV6(nxa), addr, mask, ret);
13203 +       return ret;
13204 +}
13205 +
13206 +static inline
13207 +int v6_addr_in_nx_info(struct nx_info *nxi,
13208 +       const struct in6_addr *addr, uint16_t mask)
13209 +{
13210 +       struct nx_addr_v6 *nxa;
13211 +       int ret = 1;
13212 +
13213 +       if (!nxi)
13214 +               goto out;
13215 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13216 +               if (v6_addr_match(nxa, addr, mask))
13217 +                       goto out;
13218 +       ret = 0;
13219 +out:
13220 +       vxdprintk(VXD_CBIT(net, 0),
13221 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13222 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13223 +       return ret;
13224 +}
13225 +
13226 +static inline
13227 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13228 +{
13229 +       /* FIXME: needs full range checks */
13230 +       return v6_addr_match(nxa, &addr->ip, mask);
13231 +}
13232 +
13233 +static inline
13234 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13235 +{
13236 +       struct nx_addr_v6 *ptr;
13237 +
13238 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13239 +               if (v6_nx_addr_match(ptr, nxa, mask))
13240 +                       return 1;
13241 +       return 0;
13242 +}
13243 +
13244 +
13245 +/*
13246 + *     Check if a given address matches for a socket
13247 + *
13248 + *     nxi:            the socket's nx_info if any
13249 + *     addr:           to be verified address
13250 + */
13251 +static inline
13252 +int v6_sock_addr_match (
13253 +       struct nx_info *nxi,
13254 +       struct inet_sock *inet,
13255 +       struct in6_addr *addr)
13256 +{
13257 +       struct sock *sk = &inet->sk;
13258 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13259 +
13260 +       if (!ipv6_addr_any(addr) &&
13261 +               ipv6_addr_equal(saddr, addr))
13262 +               return 1;
13263 +       if (ipv6_addr_any(saddr))
13264 +               return v6_addr_in_nx_info(nxi, addr, -1);
13265 +       return 0;
13266 +}
13267 +
13268 +/*
13269 + *     check if address is covered by socket
13270 + *
13271 + *     sk:     the socket to check against
13272 + *     addr:   the address in question (must be != 0)
13273 + */
13274 +
13275 +static inline
13276 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13277 +{
13278 +       struct nx_info *nxi = sk->sk_nx_info;
13279 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13280 +
13281 +       vxdprintk(VXD_CBIT(net, 5),
13282 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13283 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13284 +               (sk->sk_socket?sk->sk_socket->flags:0));
13285 +
13286 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13287 +               return v6_addr_match(nxa, saddr, -1);
13288 +       } else if (nxi) {               /* match against nx_info */
13289 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13290 +       } else {                        /* unrestricted any socket */
13291 +               return 1;
13292 +       }
13293 +}
13294 +
13295 +
13296 +/* inet related checks and helpers */
13297 +
13298 +
13299 +struct in_ifaddr;
13300 +struct net_device;
13301 +struct sock;
13302 +
13303 +
13304 +#include <linux/netdevice.h>
13305 +#include <linux/inetdevice.h>
13306 +#include <net/inet_timewait_sock.h>
13307 +
13308 +
13309 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13310 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13311 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13312 +
13313 +
13314 +
13315 +static inline
13316 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13317 +{
13318 +       if (!nxi)
13319 +               return 1;
13320 +       if (!ifa)
13321 +               return 0;
13322 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13323 +}
13324 +
13325 +static inline
13326 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13327 +{
13328 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13329 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13330 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13331 +
13332 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13333 +               return 1;
13334 +       if (v6_ifa_in_nx_info(ifa, nxi))
13335 +               return 1;
13336 +       return 0;
13337 +}
13338 +
13339 +
13340 +struct nx_v6_sock_addr {
13341 +       struct in6_addr saddr;  /* Address used for validation */
13342 +       struct in6_addr baddr;  /* Address used for socket bind */
13343 +};
13344 +
13345 +static inline
13346 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13347 +       struct nx_v6_sock_addr *nsa)
13348 +{
13349 +       // struct sock *sk = &inet->sk;
13350 +       // struct nx_info *nxi = sk->sk_nx_info;
13351 +       struct in6_addr saddr = addr->sin6_addr;
13352 +       struct in6_addr baddr = saddr;
13353 +
13354 +       nsa->saddr = saddr;
13355 +       nsa->baddr = baddr;
13356 +       return 0;
13357 +}
13358 +
13359 +static inline
13360 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13361 +{
13362 +       // struct sock *sk = &inet->sk;
13363 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13364 +
13365 +       // *saddr = nsa->baddr;
13366 +       // inet->inet_saddr = nsa->baddr;
13367 +}
13368 +
13369 +static inline
13370 +int nx_info_has_v6(struct nx_info *nxi)
13371 +{
13372 +       if (!nxi)
13373 +               return 1;
13374 +       if (NX_IPV6(nxi))
13375 +               return 1;
13376 +       return 0;
13377 +}
13378 +
13379 +#else /* CONFIG_IPV6 */
13380 +
13381 +static inline
13382 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13383 +{
13384 +       return 1;
13385 +}
13386 +
13387 +
13388 +static inline
13389 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13390 +{
13391 +       return 1;
13392 +}
13393 +
13394 +static inline
13395 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13396 +{
13397 +       return 1;
13398 +}
13399 +
13400 +static inline
13401 +int nx_info_has_v6(struct nx_info *nxi)
13402 +{
13403 +       return 0;
13404 +}
13405 +
13406 +#endif /* CONFIG_IPV6 */
13407 +
13408 +#define current_nx_info_has_v6() \
13409 +       nx_info_has_v6(current_nx_info())
13410 +
13411 +#else
13412 +#warning duplicate inclusion
13413 +#endif
13414 diff -NurpP --minimal linux-2.6.37/include/linux/vs_inet.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_inet.h
13415 --- linux-2.6.37/include/linux/vs_inet.h        1970-01-01 01:00:00.000000000 +0100
13416 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_inet.h 2010-11-23 02:09:41.000000000 +0100
13417 @@ -0,0 +1,351 @@
13418 +#ifndef _VS_INET_H
13419 +#define _VS_INET_H
13420 +
13421 +#include "vserver/base.h"
13422 +#include "vserver/network.h"
13423 +#include "vserver/debug.h"
13424 +
13425 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13426 +
13427 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13428 +                       NIPQUAD((a)->mask), (a)->type
13429 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13430 +
13431 +#define NIPQUAD(addr) \
13432 +       ((unsigned char *)&addr)[0], \
13433 +       ((unsigned char *)&addr)[1], \
13434 +       ((unsigned char *)&addr)[2], \
13435 +       ((unsigned char *)&addr)[3]
13436 +
13437 +#define NIPQUAD_FMT "%u.%u.%u.%u"
13438 +
13439 +
13440 +static inline
13441 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13442 +{
13443 +       __be32 ip = nxa->ip[0].s_addr;
13444 +       __be32 mask = nxa->mask.s_addr;
13445 +       __be32 bcast = ip | ~mask;
13446 +       int ret = 0;
13447 +
13448 +       switch (nxa->type & tmask) {
13449 +       case NXA_TYPE_MASK:
13450 +               ret = (ip == (addr & mask));
13451 +               break;
13452 +       case NXA_TYPE_ADDR:
13453 +               ret = 3;
13454 +               if (addr == ip)
13455 +                       break;
13456 +               /* fall through to broadcast */
13457 +       case NXA_MOD_BCAST:
13458 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13459 +               break;
13460 +       case NXA_TYPE_RANGE:
13461 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13462 +                       (nxa->ip[1].s_addr > addr));
13463 +               break;
13464 +       case NXA_TYPE_ANY:
13465 +               ret = 2;
13466 +               break;
13467 +       }
13468 +
13469 +       vxdprintk(VXD_CBIT(net, 0),
13470 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13471 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13472 +       return ret;
13473 +}
13474 +
13475 +static inline
13476 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13477 +{
13478 +       struct nx_addr_v4 *nxa;
13479 +       int ret = 1;
13480 +
13481 +       if (!nxi)
13482 +               goto out;
13483 +
13484 +       ret = 2;
13485 +       /* allow 127.0.0.1 when remapping lback */
13486 +       if ((tmask & NXA_LOOPBACK) &&
13487 +               (addr == IPI_LOOPBACK) &&
13488 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13489 +               goto out;
13490 +       ret = 3;
13491 +       /* check for lback address */
13492 +       if ((tmask & NXA_MOD_LBACK) &&
13493 +               (nxi->v4_lback.s_addr == addr))
13494 +               goto out;
13495 +       ret = 4;
13496 +       /* check for broadcast address */
13497 +       if ((tmask & NXA_MOD_BCAST) &&
13498 +               (nxi->v4_bcast.s_addr == addr))
13499 +               goto out;
13500 +       ret = 5;
13501 +       /* check for v4 addresses */
13502 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13503 +               if (v4_addr_match(nxa, addr, tmask))
13504 +                       goto out;
13505 +       ret = 0;
13506 +out:
13507 +       vxdprintk(VXD_CBIT(net, 0),
13508 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13509 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13510 +       return ret;
13511 +}
13512 +
13513 +static inline
13514 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13515 +{
13516 +       /* FIXME: needs full range checks */
13517 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13518 +}
13519 +
13520 +static inline
13521 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13522 +{
13523 +       struct nx_addr_v4 *ptr;
13524 +
13525 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13526 +               if (v4_nx_addr_match(ptr, nxa, mask))
13527 +                       return 1;
13528 +       return 0;
13529 +}
13530 +
13531 +#include <net/inet_sock.h>
13532 +
13533 +/*
13534 + *     Check if a given address matches for a socket
13535 + *
13536 + *     nxi:            the socket's nx_info if any
13537 + *     addr:           to be verified address
13538 + */
13539 +static inline
13540 +int v4_sock_addr_match (
13541 +       struct nx_info *nxi,
13542 +       struct inet_sock *inet,
13543 +       __be32 addr)
13544 +{
13545 +       __be32 saddr = inet->inet_rcv_saddr;
13546 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13547 +
13548 +       if (addr && (saddr == addr || bcast == addr))
13549 +               return 1;
13550 +       if (!saddr)
13551 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13552 +       return 0;
13553 +}
13554 +
13555 +
13556 +/* inet related checks and helpers */
13557 +
13558 +
13559 +struct in_ifaddr;
13560 +struct net_device;
13561 +struct sock;
13562 +
13563 +#ifdef CONFIG_INET
13564 +
13565 +#include <linux/netdevice.h>
13566 +#include <linux/inetdevice.h>
13567 +#include <net/inet_sock.h>
13568 +#include <net/inet_timewait_sock.h>
13569 +
13570 +
13571 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13572 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13573 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13574 +
13575 +
13576 +/*
13577 + *     check if address is covered by socket
13578 + *
13579 + *     sk:     the socket to check against
13580 + *     addr:   the address in question (must be != 0)
13581 + */
13582 +
13583 +static inline
13584 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13585 +{
13586 +       struct nx_info *nxi = sk->sk_nx_info;
13587 +       __be32 saddr = inet_rcv_saddr(sk);
13588 +
13589 +       vxdprintk(VXD_CBIT(net, 5),
13590 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13591 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13592 +               (sk->sk_socket?sk->sk_socket->flags:0));
13593 +
13594 +       if (saddr) {            /* direct address match */
13595 +               return v4_addr_match(nxa, saddr, -1);
13596 +       } else if (nxi) {       /* match against nx_info */
13597 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13598 +       } else {                /* unrestricted any socket */
13599 +               return 1;
13600 +       }
13601 +}
13602 +
13603 +
13604 +
13605 +static inline
13606 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13607 +{
13608 +       vxdprintk(VXD_CBIT(net, 1),
13609 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
13610 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13611 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13612 +
13613 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13614 +               return 1;
13615 +       if (dev_in_nx_info(dev, nxi))
13616 +               return 1;
13617 +       return 0;
13618 +}
13619 +
13620 +
13621 +static inline
13622 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13623 +{
13624 +       if (!nxi)
13625 +               return 1;
13626 +       if (!ifa)
13627 +               return 0;
13628 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13629 +}
13630 +
13631 +static inline
13632 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13633 +{
13634 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13635 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13636 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13637 +
13638 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13639 +               return 1;
13640 +       if (v4_ifa_in_nx_info(ifa, nxi))
13641 +               return 1;
13642 +       return 0;
13643 +}
13644 +
13645 +
13646 +struct nx_v4_sock_addr {
13647 +       __be32 saddr;   /* Address used for validation */
13648 +       __be32 baddr;   /* Address used for socket bind */
13649 +};
13650 +
13651 +static inline
13652 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13653 +       struct nx_v4_sock_addr *nsa)
13654 +{
13655 +       struct sock *sk = &inet->sk;
13656 +       struct nx_info *nxi = sk->sk_nx_info;
13657 +       __be32 saddr = addr->sin_addr.s_addr;
13658 +       __be32 baddr = saddr;
13659 +
13660 +       vxdprintk(VXD_CBIT(net, 3),
13661 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13662 +               sk, sk->sk_nx_info, sk->sk_socket,
13663 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13664 +               NIPQUAD(saddr));
13665 +
13666 +       if (nxi) {
13667 +               if (saddr == INADDR_ANY) {
13668 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13669 +                               baddr = nxi->v4.ip[0].s_addr;
13670 +               } else if (saddr == IPI_LOOPBACK) {
13671 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13672 +                               baddr = nxi->v4_lback.s_addr;
13673 +               } else {        /* normal address bind */
13674 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13675 +                               return -EADDRNOTAVAIL;
13676 +               }
13677 +       }
13678 +
13679 +       vxdprintk(VXD_CBIT(net, 3),
13680 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13681 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13682 +
13683 +       nsa->saddr = saddr;
13684 +       nsa->baddr = baddr;
13685 +       return 0;
13686 +}
13687 +
13688 +static inline
13689 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13690 +{
13691 +       inet->inet_saddr = nsa->baddr;
13692 +       inet->inet_rcv_saddr = nsa->baddr;
13693 +}
13694 +
13695 +
13696 +/*
13697 + *      helper to simplify inet_lookup_listener
13698 + *
13699 + *      nxi:   the socket's nx_info if any
13700 + *      addr:  to be verified address
13701 + *      saddr: socket address
13702 + */
13703 +static inline int v4_inet_addr_match (
13704 +       struct nx_info *nxi,
13705 +       __be32 addr,
13706 +       __be32 saddr)
13707 +{
13708 +       if (addr && (saddr == addr))
13709 +               return 1;
13710 +       if (!saddr)
13711 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13712 +       return 0;
13713 +}
13714 +
13715 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13716 +{
13717 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13718 +               (addr == nxi->v4_lback.s_addr))
13719 +               return IPI_LOOPBACK;
13720 +       return addr;
13721 +}
13722 +
13723 +static inline
13724 +int nx_info_has_v4(struct nx_info *nxi)
13725 +{
13726 +       if (!nxi)
13727 +               return 1;
13728 +       if (NX_IPV4(nxi))
13729 +               return 1;
13730 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13731 +               return 1;
13732 +       return 0;
13733 +}
13734 +
13735 +#else /* CONFIG_INET */
13736 +
13737 +static inline
13738 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13739 +{
13740 +       return 1;
13741 +}
13742 +
13743 +static inline
13744 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13745 +{
13746 +       return 1;
13747 +}
13748 +
13749 +static inline
13750 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13751 +{
13752 +       return 1;
13753 +}
13754 +
13755 +static inline
13756 +int nx_info_has_v4(struct nx_info *nxi)
13757 +{
13758 +       return 0;
13759 +}
13760 +
13761 +#endif /* CONFIG_INET */
13762 +
13763 +#define current_nx_info_has_v4() \
13764 +       nx_info_has_v4(current_nx_info())
13765 +
13766 +#else
13767 +// #warning duplicate inclusion
13768 +#endif
13769 diff -NurpP --minimal linux-2.6.37/include/linux/vs_limit.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_limit.h
13770 --- linux-2.6.37/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
13771 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_limit.h        2010-11-23 02:09:41.000000000 +0100
13772 @@ -0,0 +1,140 @@
13773 +#ifndef _VS_LIMIT_H
13774 +#define _VS_LIMIT_H
13775 +
13776 +#include "vserver/limit.h"
13777 +#include "vserver/base.h"
13778 +#include "vserver/context.h"
13779 +#include "vserver/debug.h"
13780 +#include "vserver/context.h"
13781 +#include "vserver/limit_int.h"
13782 +
13783 +
13784 +#define vx_acc_cres(v, d, p, r) \
13785 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13786 +
13787 +#define vx_acc_cres_cond(x, d, p, r) \
13788 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13789 +       r, d, p, __FILE__, __LINE__)
13790 +
13791 +
13792 +#define vx_add_cres(v, a, p, r) \
13793 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13794 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13795 +
13796 +#define vx_add_cres_cond(x, a, p, r) \
13797 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13798 +       r, a, p, __FILE__, __LINE__)
13799 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13800 +
13801 +
13802 +/* process and file limits */
13803 +
13804 +#define vx_nproc_inc(p) \
13805 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13806 +
13807 +#define vx_nproc_dec(p) \
13808 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13809 +
13810 +#define vx_files_inc(f) \
13811 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13812 +
13813 +#define vx_files_dec(f) \
13814 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13815 +
13816 +#define vx_locks_inc(l) \
13817 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13818 +
13819 +#define vx_locks_dec(l) \
13820 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13821 +
13822 +#define vx_openfd_inc(f) \
13823 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13824 +
13825 +#define vx_openfd_dec(f) \
13826 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
13827 +
13828 +
13829 +#define vx_cres_avail(v, n, r) \
13830 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13831 +
13832 +
13833 +#define vx_nproc_avail(n) \
13834 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
13835 +
13836 +#define vx_files_avail(n) \
13837 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
13838 +
13839 +#define vx_locks_avail(n) \
13840 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
13841 +
13842 +#define vx_openfd_avail(n) \
13843 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
13844 +
13845 +
13846 +/* dentry limits */
13847 +
13848 +#define vx_dentry_inc(d) do {                                          \
13849 +       if (atomic_read(&d->d_count) == 1)                              \
13850 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
13851 +       } while (0)
13852 +
13853 +#define vx_dentry_dec(d) do {                                          \
13854 +       if (atomic_read(&d->d_count) == 0)                              \
13855 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
13856 +       } while (0)
13857 +
13858 +#define vx_dentry_avail(n) \
13859 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
13860 +
13861 +
13862 +/* socket limits */
13863 +
13864 +#define vx_sock_inc(s) \
13865 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13866 +
13867 +#define vx_sock_dec(s) \
13868 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13869 +
13870 +#define vx_sock_avail(n) \
13871 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
13872 +
13873 +
13874 +/* ipc resource limits */
13875 +
13876 +#define vx_ipcmsg_add(v, u, a) \
13877 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13878 +
13879 +#define vx_ipcmsg_sub(v, u, a) \
13880 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13881 +
13882 +#define vx_ipcmsg_avail(v, a) \
13883 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13884 +
13885 +
13886 +#define vx_ipcshm_add(v, k, a) \
13887 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13888 +
13889 +#define vx_ipcshm_sub(v, k, a) \
13890 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13891 +
13892 +#define vx_ipcshm_avail(v, a) \
13893 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13894 +
13895 +
13896 +#define vx_semary_inc(a) \
13897 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
13898 +
13899 +#define vx_semary_dec(a) \
13900 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
13901 +
13902 +
13903 +#define vx_nsems_add(a,n) \
13904 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
13905 +
13906 +#define vx_nsems_sub(a,n) \
13907 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
13908 +
13909 +
13910 +#else
13911 +#warning duplicate inclusion
13912 +#endif
13913 diff -NurpP --minimal linux-2.6.37/include/linux/vs_memory.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_memory.h
13914 --- linux-2.6.37/include/linux/vs_memory.h      1970-01-01 01:00:00.000000000 +0100
13915 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_memory.h       2010-11-23 02:09:41.000000000 +0100
13916 @@ -0,0 +1,58 @@
13917 +#ifndef _VS_MEMORY_H
13918 +#define _VS_MEMORY_H
13919 +
13920 +#include "vserver/limit.h"
13921 +#include "vserver/base.h"
13922 +#include "vserver/context.h"
13923 +#include "vserver/debug.h"
13924 +#include "vserver/context.h"
13925 +#include "vserver/limit_int.h"
13926 +
13927 +enum {
13928 +       VXPT_UNKNOWN = 0,
13929 +       VXPT_ANON,
13930 +       VXPT_NONE,
13931 +       VXPT_FILE,
13932 +       VXPT_SWAP,
13933 +       VXPT_WRITE
13934 +};
13935 +
13936 +#if 0
13937 +#define        vx_page_fault(mm, vma, type, ret)
13938 +#else
13939 +
13940 +static inline
13941 +void __vx_page_fault(struct mm_struct *mm,
13942 +       struct vm_area_struct *vma, int type, int ret)
13943 +{
13944 +       struct vx_info *vxi = mm->mm_vx_info;
13945 +       int what;
13946 +/*
13947 +       static char *page_type[6] =
13948 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
13949 +       static char *page_what[4] =
13950 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
13951 +*/
13952 +
13953 +       if (!vxi)
13954 +               return;
13955 +
13956 +       what = (ret & 0x3);
13957 +
13958 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
13959 +               type, what, ret, page_type[type], page_what[what]);
13960 +*/
13961 +       if (ret & VM_FAULT_WRITE)
13962 +               what |= 0x4;
13963 +       atomic_inc(&vxi->cacct.page[type][what]);
13964 +}
13965 +
13966 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
13967 +#endif
13968 +
13969 +
13970 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
13971 +
13972 +#else
13973 +#warning duplicate inclusion
13974 +#endif
13975 diff -NurpP --minimal linux-2.6.37/include/linux/vs_network.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_network.h
13976 --- linux-2.6.37/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
13977 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_network.h      2010-11-23 02:09:41.000000000 +0100
13978 @@ -0,0 +1,169 @@
13979 +#ifndef _NX_VS_NETWORK_H
13980 +#define _NX_VS_NETWORK_H
13981 +
13982 +#include "vserver/context.h"
13983 +#include "vserver/network.h"
13984 +#include "vserver/base.h"
13985 +#include "vserver/check.h"
13986 +#include "vserver/debug.h"
13987 +
13988 +#include <linux/sched.h>
13989 +
13990 +
13991 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
13992 +
13993 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
13994 +       const char *_file, int _line)
13995 +{
13996 +       if (!nxi)
13997 +               return NULL;
13998 +
13999 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14000 +               nxi, nxi ? nxi->nx_id : 0,
14001 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14002 +               _file, _line);
14003 +
14004 +       atomic_inc(&nxi->nx_usecnt);
14005 +       return nxi;
14006 +}
14007 +
14008 +
14009 +extern void free_nx_info(struct nx_info *);
14010 +
14011 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14012 +
14013 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14014 +{
14015 +       if (!nxi)
14016 +               return;
14017 +
14018 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14019 +               nxi, nxi ? nxi->nx_id : 0,
14020 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14021 +               _file, _line);
14022 +
14023 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14024 +               free_nx_info(nxi);
14025 +}
14026 +
14027 +
14028 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14029 +
14030 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14031 +               const char *_file, int _line)
14032 +{
14033 +       if (nxi) {
14034 +               vxlprintk(VXD_CBIT(nid, 3),
14035 +                       "init_nx_info(%p[#%d.%d])",
14036 +                       nxi, nxi ? nxi->nx_id : 0,
14037 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14038 +                       _file, _line);
14039 +
14040 +               atomic_inc(&nxi->nx_usecnt);
14041 +       }
14042 +       *nxp = nxi;
14043 +}
14044 +
14045 +
14046 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14047 +
14048 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14049 +       const char *_file, int _line)
14050 +{
14051 +       struct nx_info *nxo;
14052 +
14053 +       if (!nxi)
14054 +               return;
14055 +
14056 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14057 +               nxi, nxi ? nxi->nx_id : 0,
14058 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14059 +               _file, _line);
14060 +
14061 +       atomic_inc(&nxi->nx_usecnt);
14062 +       nxo = xchg(nxp, nxi);
14063 +       BUG_ON(nxo);
14064 +}
14065 +
14066 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14067 +
14068 +static inline void __clr_nx_info(struct nx_info **nxp,
14069 +       const char *_file, int _line)
14070 +{
14071 +       struct nx_info *nxo;
14072 +
14073 +       nxo = xchg(nxp, NULL);
14074 +       if (!nxo)
14075 +               return;
14076 +
14077 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14078 +               nxo, nxo ? nxo->nx_id : 0,
14079 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14080 +               _file, _line);
14081 +
14082 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14083 +               free_nx_info(nxo);
14084 +}
14085 +
14086 +
14087 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14088 +
14089 +static inline void __claim_nx_info(struct nx_info *nxi,
14090 +       struct task_struct *task, const char *_file, int _line)
14091 +{
14092 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14093 +               nxi, nxi ? nxi->nx_id : 0,
14094 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14095 +               nxi?atomic_read(&nxi->nx_tasks):0,
14096 +               task, _file, _line);
14097 +
14098 +       atomic_inc(&nxi->nx_tasks);
14099 +}
14100 +
14101 +
14102 +extern void unhash_nx_info(struct nx_info *);
14103 +
14104 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14105 +
14106 +static inline void __release_nx_info(struct nx_info *nxi,
14107 +       struct task_struct *task, const char *_file, int _line)
14108 +{
14109 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14110 +               nxi, nxi ? nxi->nx_id : 0,
14111 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14112 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14113 +               task, _file, _line);
14114 +
14115 +       might_sleep();
14116 +
14117 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14118 +               unhash_nx_info(nxi);
14119 +}
14120 +
14121 +
14122 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14123 +
14124 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14125 +       const char *_file, int _line)
14126 +{
14127 +       struct nx_info *nxi;
14128 +
14129 +       task_lock(p);
14130 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14131 +               p, _file, _line);
14132 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14133 +       task_unlock(p);
14134 +       return nxi;
14135 +}
14136 +
14137 +
14138 +static inline void exit_nx_info(struct task_struct *p)
14139 +{
14140 +       if (p->nx_info)
14141 +               release_nx_info(p->nx_info, p);
14142 +}
14143 +
14144 +
14145 +#else
14146 +#warning duplicate inclusion
14147 +#endif
14148 diff -NurpP --minimal linux-2.6.37/include/linux/vs_pid.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_pid.h
14149 --- linux-2.6.37/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
14150 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_pid.h  2010-11-23 02:09:41.000000000 +0100
14151 @@ -0,0 +1,95 @@
14152 +#ifndef _VS_PID_H
14153 +#define _VS_PID_H
14154 +
14155 +#include "vserver/base.h"
14156 +#include "vserver/check.h"
14157 +#include "vserver/context.h"
14158 +#include "vserver/debug.h"
14159 +#include "vserver/pid.h"
14160 +#include <linux/pid_namespace.h>
14161 +
14162 +
14163 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14164 +
14165 +static inline
14166 +int vx_proc_task_visible(struct task_struct *task)
14167 +{
14168 +       if ((task->pid == 1) &&
14169 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14170 +               /* show a blend through init */
14171 +               goto visible;
14172 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14173 +               goto visible;
14174 +       return 0;
14175 +visible:
14176 +       return 1;
14177 +}
14178 +
14179 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14180 +
14181 +#if 0
14182 +
14183 +static inline
14184 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14185 +{
14186 +       struct task_struct *task = find_task_by_real_pid(pid);
14187 +
14188 +       if (task && !vx_proc_task_visible(task)) {
14189 +               vxdprintk(VXD_CBIT(misc, 6),
14190 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14191 +                       task, task->xid, task->pid,
14192 +                       current, current->xid, current->pid);
14193 +               task = NULL;
14194 +       }
14195 +       return task;
14196 +}
14197 +
14198 +#endif
14199 +
14200 +static inline
14201 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14202 +{
14203 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14204 +
14205 +       if (task && !vx_proc_task_visible(task)) {
14206 +               vxdprintk(VXD_CBIT(misc, 6),
14207 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14208 +                       task, task->xid, task->pid,
14209 +                       current, current->xid, current->pid);
14210 +               put_task_struct(task);
14211 +               task = NULL;
14212 +       }
14213 +       return task;
14214 +}
14215 +
14216 +#if 0
14217 +
14218 +static inline
14219 +struct task_struct *vx_child_reaper(struct task_struct *p)
14220 +{
14221 +       struct vx_info *vxi = p->vx_info;
14222 +       struct task_struct *reaper = child_reaper(p);
14223 +
14224 +       if (!vxi)
14225 +               goto out;
14226 +
14227 +       BUG_ON(!p->vx_info->vx_reaper);
14228 +
14229 +       /* child reaper for the guest reaper */
14230 +       if (vxi->vx_reaper == p)
14231 +               goto out;
14232 +
14233 +       reaper = vxi->vx_reaper;
14234 +out:
14235 +       vxdprintk(VXD_CBIT(xid, 7),
14236 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14237 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14238 +       return reaper;
14239 +}
14240 +
14241 +#endif
14242 +
14243 +
14244 +#else
14245 +#warning duplicate inclusion
14246 +#endif
14247 diff -NurpP --minimal linux-2.6.37/include/linux/vs_sched.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_sched.h
14248 --- linux-2.6.37/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
14249 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_sched.h        2010-11-23 02:09:41.000000000 +0100
14250 @@ -0,0 +1,40 @@
14251 +#ifndef _VS_SCHED_H
14252 +#define _VS_SCHED_H
14253 +
14254 +#include "vserver/base.h"
14255 +#include "vserver/context.h"
14256 +#include "vserver/sched.h"
14257 +
14258 +
14259 +#define MAX_PRIO_BIAS           20
14260 +#define MIN_PRIO_BIAS          -20
14261 +
14262 +static inline
14263 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14264 +{
14265 +       struct vx_info *vxi = p->vx_info;
14266 +
14267 +       if (vxi)
14268 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14269 +       return prio;
14270 +}
14271 +
14272 +static inline void vx_account_user(struct vx_info *vxi,
14273 +       cputime_t cputime, int nice)
14274 +{
14275 +       if (!vxi)
14276 +               return;
14277 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14278 +}
14279 +
14280 +static inline void vx_account_system(struct vx_info *vxi,
14281 +       cputime_t cputime, int idle)
14282 +{
14283 +       if (!vxi)
14284 +               return;
14285 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14286 +}
14287 +
14288 +#else
14289 +#warning duplicate inclusion
14290 +#endif
14291 diff -NurpP --minimal linux-2.6.37/include/linux/vs_socket.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_socket.h
14292 --- linux-2.6.37/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
14293 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_socket.h       2010-11-23 02:09:41.000000000 +0100
14294 @@ -0,0 +1,67 @@
14295 +#ifndef _VS_SOCKET_H
14296 +#define _VS_SOCKET_H
14297 +
14298 +#include "vserver/debug.h"
14299 +#include "vserver/base.h"
14300 +#include "vserver/cacct.h"
14301 +#include "vserver/context.h"
14302 +#include "vserver/tag.h"
14303 +
14304 +
14305 +/* socket accounting */
14306 +
14307 +#include <linux/socket.h>
14308 +
14309 +static inline int vx_sock_type(int family)
14310 +{
14311 +       switch (family) {
14312 +       case PF_UNSPEC:
14313 +               return VXA_SOCK_UNSPEC;
14314 +       case PF_UNIX:
14315 +               return VXA_SOCK_UNIX;
14316 +       case PF_INET:
14317 +               return VXA_SOCK_INET;
14318 +       case PF_INET6:
14319 +               return VXA_SOCK_INET6;
14320 +       case PF_PACKET:
14321 +               return VXA_SOCK_PACKET;
14322 +       default:
14323 +               return VXA_SOCK_OTHER;
14324 +       }
14325 +}
14326 +
14327 +#define vx_acc_sock(v, f, p, s) \
14328 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14329 +
14330 +static inline void __vx_acc_sock(struct vx_info *vxi,
14331 +       int family, int pos, int size, char *file, int line)
14332 +{
14333 +       if (vxi) {
14334 +               int type = vx_sock_type(family);
14335 +
14336 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14337 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14338 +       }
14339 +}
14340 +
14341 +#define vx_sock_recv(sk, s) \
14342 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14343 +#define vx_sock_send(sk, s) \
14344 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14345 +#define vx_sock_fail(sk, s) \
14346 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14347 +
14348 +
14349 +#define sock_vx_init(s) do {           \
14350 +       (s)->sk_xid = 0;                \
14351 +       (s)->sk_vx_info = NULL;         \
14352 +       } while (0)
14353 +
14354 +#define sock_nx_init(s) do {           \
14355 +       (s)->sk_nid = 0;                \
14356 +       (s)->sk_nx_info = NULL;         \
14357 +       } while (0)
14358 +
14359 +#else
14360 +#warning duplicate inclusion
14361 +#endif
14362 diff -NurpP --minimal linux-2.6.37/include/linux/vs_tag.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_tag.h
14363 --- linux-2.6.37/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
14364 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_tag.h  2010-11-23 02:09:41.000000000 +0100
14365 @@ -0,0 +1,47 @@
14366 +#ifndef _VS_TAG_H
14367 +#define _VS_TAG_H
14368 +
14369 +#include <linux/vserver/tag.h>
14370 +
14371 +/* check conditions */
14372 +
14373 +#define DX_ADMIN       0x0001
14374 +#define DX_WATCH       0x0002
14375 +#define DX_HOSTID      0x0008
14376 +
14377 +#define DX_IDENT       0x0010
14378 +
14379 +#define DX_ARG_MASK    0x0010
14380 +
14381 +
14382 +#define dx_task_tag(t) ((t)->tag)
14383 +
14384 +#define dx_current_tag() dx_task_tag(current)
14385 +
14386 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14387 +
14388 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14389 +
14390 +
14391 +/*
14392 + * check current context for ADMIN/WATCH and
14393 + * optionally against supplied argument
14394 + */
14395 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14396 +{
14397 +       if (mode & DX_ARG_MASK) {
14398 +               if ((mode & DX_IDENT) && (id == cid))
14399 +                       return 1;
14400 +       }
14401 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14402 +               ((mode & DX_WATCH) && (cid == 1)) ||
14403 +               ((mode & DX_HOSTID) && (id == 0)));
14404 +}
14405 +
14406 +struct inode;
14407 +int dx_permission(const struct inode *inode, int mask);
14408 +
14409 +
14410 +#else
14411 +#warning duplicate inclusion
14412 +#endif
14413 diff -NurpP --minimal linux-2.6.37/include/linux/vs_time.h linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_time.h
14414 --- linux-2.6.37/include/linux/vs_time.h        1970-01-01 01:00:00.000000000 +0100
14415 +++ linux-2.6.37-vs2.3.0.37-rc3/include/linux/vs_time.h 2010-11-23 02:09:41.000000000 +0100
14416 @@ -0,0 +1,19 @@
14417 +#ifndef _VS_TIME_H
14418 +#define _VS_TIME_H
14419 +
14420 +
14421 +/* time faking stuff */
14422 +
14423 +#ifdef CONFIG_VSERVER_VTIME
14424 +
14425 +extern void vx_adjust_timespec(struct timespec *ts);
14426 +extern int vx_settimeofday(struct timespec *ts);
14427 +
14428 +#else
14429 +#define        vx_adjust_timespec(t)   do { } while (0)
14430 +#define        vx_settimeofday(t)      do_settimeofday(t)
14431 +#endif
14432 +
14433 +#else
14434 +#warning duplicate inclusion
14435 +#endif
14436 diff -NurpP --minimal linux-2.6.37/include/net/addrconf.h linux-2.6.37-vs2.3.0.37-rc3/include/net/addrconf.h
14437 --- linux-2.6.37/include/net/addrconf.h 2011-01-05 21:50:35.000000000 +0100
14438 +++ linux-2.6.37-vs2.3.0.37-rc3/include/net/addrconf.h  2010-11-23 02:09:41.000000000 +0100
14439 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14440                                                struct net_device *dev,
14441                                                const struct in6_addr *daddr,
14442                                                unsigned int srcprefs,
14443 -                                              struct in6_addr *saddr);
14444 +                                              struct in6_addr *saddr,
14445 +                                              struct nx_info *nxi);
14446  extern int                     ipv6_get_lladdr(struct net_device *dev,
14447                                                 struct in6_addr *addr,
14448                                                 unsigned char banned_flags);
14449 diff -NurpP --minimal linux-2.6.37/include/net/af_unix.h linux-2.6.37-vs2.3.0.37-rc3/include/net/af_unix.h
14450 --- linux-2.6.37/include/net/af_unix.h  2011-01-05 21:50:35.000000000 +0100
14451 +++ linux-2.6.37-vs2.3.0.37-rc3/include/net/af_unix.h   2011-01-05 22:30:40.000000000 +0100
14452 @@ -4,6 +4,7 @@
14453  #include <linux/socket.h>
14454  #include <linux/un.h>
14455  #include <linux/mutex.h>
14456 +#include <linux/vs_base.h>
14457  #include <net/sock.h>
14458  
14459  extern void unix_inflight(struct file *fp);
14460 diff -NurpP --minimal linux-2.6.37/include/net/inet_timewait_sock.h linux-2.6.37-vs2.3.0.37-rc3/include/net/inet_timewait_sock.h
14461 --- linux-2.6.37/include/net/inet_timewait_sock.h       2010-08-02 16:52:56.000000000 +0200
14462 +++ linux-2.6.37-vs2.3.0.37-rc3/include/net/inet_timewait_sock.h        2010-11-23 02:09:41.000000000 +0100
14463 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14464  #define tw_hash                        __tw_common.skc_hash
14465  #define tw_prot                        __tw_common.skc_prot
14466  #define tw_net                 __tw_common.skc_net
14467 +#define tw_xid                 __tw_common.skc_xid
14468 +#define tw_vx_info             __tw_common.skc_vx_info
14469 +#define tw_nid                 __tw_common.skc_nid
14470 +#define tw_nx_info             __tw_common.skc_nx_info
14471         int                     tw_timeout;
14472         volatile unsigned char  tw_substate;
14473         /* 3 bits hole, try to pack */
14474 diff -NurpP --minimal linux-2.6.37/include/net/route.h linux-2.6.37-vs2.3.0.37-rc3/include/net/route.h
14475 --- linux-2.6.37/include/net/route.h    2010-10-21 13:07:56.000000000 +0200
14476 +++ linux-2.6.37-vs2.3.0.37-rc3/include/net/route.h     2010-11-23 02:09:41.000000000 +0100
14477 @@ -145,6 +145,9 @@ static inline void ip_rt_put(struct rtab
14478                 dst_release(&rt->dst);
14479  }
14480  
14481 +#include <linux/vs_base.h>
14482 +#include <linux/vs_inet.h>
14483 +
14484  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14485  
14486  extern const __u8 ip_tos2prio[16];
14487 @@ -154,6 +157,9 @@ static inline char rt_tos2priority(u8 to
14488         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14489  }
14490  
14491 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14492 +       struct rtable **, struct flowi *);
14493 +
14494  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14495                                    __be32 src, u32 tos, int oif, u8 protocol,
14496                                    __be16 sport, __be16 dport, struct sock *sk,
14497 @@ -171,11 +177,24 @@ static inline int ip_route_connect(struc
14498  
14499         int err;
14500         struct net *net = sock_net(sk);
14501 +       struct nx_info *nx_info = current_nx_info();
14502  
14503         if (inet_sk(sk)->transparent)
14504                 fl.flags |= FLOWI_FLAG_ANYSRC;
14505  
14506 -       if (!dst || !src) {
14507 +       if (sk)
14508 +               nx_info = sk->sk_nx_info;
14509 +
14510 +       vxdprintk(VXD_CBIT(net, 4),
14511 +               "ip_route_connect(%p) %p,%p;%lx",
14512 +               sk, nx_info, sk->sk_socket,
14513 +               (sk->sk_socket?sk->sk_socket->flags:0));
14514 +
14515 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14516 +       if (err)
14517 +               return err;
14518 +
14519 +       if (!fl.fl4_dst || !fl.fl4_src) {
14520                 err = __ip_route_output_key(net, rp, &fl);
14521                 if (err)
14522                         return err;
14523 diff -NurpP --minimal linux-2.6.37/include/net/sock.h linux-2.6.37-vs2.3.0.37-rc3/include/net/sock.h
14524 --- linux-2.6.37/include/net/sock.h     2011-01-05 21:50:36.000000000 +0100
14525 +++ linux-2.6.37-vs2.3.0.37-rc3/include/net/sock.h      2011-01-05 22:30:42.000000000 +0100
14526 @@ -150,6 +150,10 @@ struct sock_common {
14527  #ifdef CONFIG_NET_NS
14528         struct net              *skc_net;
14529  #endif
14530 +       xid_t                   skc_xid;
14531 +       struct vx_info          *skc_vx_info;
14532 +       nid_t                   skc_nid;
14533 +       struct nx_info          *skc_nx_info;
14534  };
14535  
14536  /**
14537 @@ -241,6 +245,10 @@ struct sock {
14538  #define sk_bind_node           __sk_common.skc_bind_node
14539  #define sk_prot                        __sk_common.skc_prot
14540  #define sk_net                 __sk_common.skc_net
14541 +#define sk_xid                 __sk_common.skc_xid
14542 +#define sk_vx_info             __sk_common.skc_vx_info
14543 +#define sk_nid                 __sk_common.skc_nid
14544 +#define sk_nx_info             __sk_common.skc_nx_info
14545         kmemcheck_bitfield_begin(flags);
14546         unsigned int            sk_shutdown  : 2,
14547                                 sk_no_check  : 2,
14548 diff -NurpP --minimal linux-2.6.37/init/Kconfig linux-2.6.37-vs2.3.0.37-rc3/init/Kconfig
14549 --- linux-2.6.37/init/Kconfig   2011-01-05 21:50:37.000000000 +0100
14550 +++ linux-2.6.37-vs2.3.0.37-rc3/init/Kconfig    2011-01-05 22:30:42.000000000 +0100
14551 @@ -503,6 +503,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14552  menuconfig CGROUPS
14553         boolean "Control Group support"
14554         depends on EVENTFD
14555 +       default y
14556         help
14557           This option adds support for grouping sets of processes together, for
14558           use with process control subsystems such as Cpusets, CFS, memory
14559 @@ -528,6 +529,7 @@ config CGROUP_DEBUG
14560  
14561  config CGROUP_NS
14562         bool "Namespace cgroup subsystem"
14563 +       default n
14564         help
14565           Provides a simple namespace cgroup subsystem to
14566           provide hierarchical naming of sets of namespaces,
14567 diff -NurpP --minimal linux-2.6.37/init/main.c linux-2.6.37-vs2.3.0.37-rc3/init/main.c
14568 --- linux-2.6.37/init/main.c    2011-01-05 21:50:37.000000000 +0100
14569 +++ linux-2.6.37-vs2.3.0.37-rc3/init/main.c     2010-11-23 02:09:41.000000000 +0100
14570 @@ -67,6 +67,7 @@
14571  #include <linux/sfi.h>
14572  #include <linux/shmem_fs.h>
14573  #include <linux/slab.h>
14574 +#include <linux/vserver/percpu.h>
14575  
14576  #include <asm/io.h>
14577  #include <asm/bugs.h>
14578 diff -NurpP --minimal linux-2.6.37/ipc/mqueue.c linux-2.6.37-vs2.3.0.37-rc3/ipc/mqueue.c
14579 --- linux-2.6.37/ipc/mqueue.c   2011-01-05 21:50:37.000000000 +0100
14580 +++ linux-2.6.37-vs2.3.0.37-rc3/ipc/mqueue.c    2010-11-23 02:09:41.000000000 +0100
14581 @@ -33,6 +33,8 @@
14582  #include <linux/pid.h>
14583  #include <linux/ipc_namespace.h>
14584  #include <linux/slab.h>
14585 +#include <linux/vs_context.h>
14586 +#include <linux/vs_limit.h>
14587  
14588  #include <net/sock.h>
14589  #include "util.h"
14590 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14591         struct sigevent notify;
14592         struct pid* notify_owner;
14593         struct user_struct *user;       /* user who created, for accounting */
14594 +       struct vx_info *vxi;
14595         struct sock *notify_sock;
14596         struct sk_buff *notify_cookie;
14597  
14598 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
14599                 if (S_ISREG(mode)) {
14600                         struct mqueue_inode_info *info;
14601                         struct task_struct *p = current;
14602 +                       struct vx_info *vxi = p->vx_info;
14603                         unsigned long mq_bytes, mq_msg_tblsz;
14604  
14605                         inode->i_fop = &mqueue_file_operations;
14606 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14607                         info->notify_owner = NULL;
14608                         info->qsize = 0;
14609                         info->user = NULL;      /* set when all is ok */
14610 +                       info->vxi = NULL;
14611                         memset(&info->attr, 0, sizeof(info->attr));
14612                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14613                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14614 @@ -157,16 +162,19 @@ static struct inode *mqueue_get_inode(st
14615                         spin_lock(&mq_lock);
14616                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14617                             u->mq_bytes + mq_bytes >
14618 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
14619 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
14620 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14621                                 spin_unlock(&mq_lock);
14622                                 /* mqueue_evict_inode() releases info->messages */
14623                                 goto out_inode;
14624                         }
14625                         u->mq_bytes += mq_bytes;
14626 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14627                         spin_unlock(&mq_lock);
14628  
14629                         /* all is ok */
14630                         info->user = get_uid(u);
14631 +                       info->vxi = get_vx_info(vxi);
14632                 } else if (S_ISDIR(mode)) {
14633                         inc_nlink(inode);
14634                         /* Some things misbehave if size == 0 on a directory */
14635 @@ -268,8 +276,11 @@ static void mqueue_evict_inode(struct in
14636             + info->attr.mq_msgsize);
14637         user = info->user;
14638         if (user) {
14639 +               struct vx_info *vxi = info->vxi;
14640 +
14641                 spin_lock(&mq_lock);
14642                 user->mq_bytes -= mq_bytes;
14643 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14644                 /*
14645                  * get_ns_from_inode() ensures that the
14646                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14647 @@ -279,6 +290,7 @@ static void mqueue_evict_inode(struct in
14648                 if (ipc_ns)
14649                         ipc_ns->mq_queues_count--;
14650                 spin_unlock(&mq_lock);
14651 +               put_vx_info(vxi);
14652                 free_uid(user);
14653         }
14654         if (ipc_ns)
14655 diff -NurpP --minimal linux-2.6.37/ipc/msg.c linux-2.6.37-vs2.3.0.37-rc3/ipc/msg.c
14656 --- linux-2.6.37/ipc/msg.c      2010-08-02 16:52:57.000000000 +0200
14657 +++ linux-2.6.37-vs2.3.0.37-rc3/ipc/msg.c       2010-11-23 02:09:41.000000000 +0100
14658 @@ -37,6 +37,7 @@
14659  #include <linux/rwsem.h>
14660  #include <linux/nsproxy.h>
14661  #include <linux/ipc_namespace.h>
14662 +#include <linux/vs_base.h>
14663  
14664  #include <asm/current.h>
14665  #include <asm/uaccess.h>
14666 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14667  
14668         msq->q_perm.mode = msgflg & S_IRWXUGO;
14669         msq->q_perm.key = key;
14670 +       msq->q_perm.xid = vx_current_xid();
14671  
14672         msq->q_perm.security = NULL;
14673         retval = security_msg_queue_alloc(msq);
14674 diff -NurpP --minimal linux-2.6.37/ipc/namespace.c linux-2.6.37-vs2.3.0.37-rc3/ipc/namespace.c
14675 --- linux-2.6.37/ipc/namespace.c        2009-09-10 15:26:27.000000000 +0200
14676 +++ linux-2.6.37-vs2.3.0.37-rc3/ipc/namespace.c 2010-11-23 02:09:41.000000000 +0100
14677 @@ -11,6 +11,8 @@
14678  #include <linux/slab.h>
14679  #include <linux/fs.h>
14680  #include <linux/mount.h>
14681 +#include <linux/vs_base.h>
14682 +#include <linux/vserver/global.h>
14683  
14684  #include "util.h"
14685  
14686 diff -NurpP --minimal linux-2.6.37/ipc/sem.c linux-2.6.37-vs2.3.0.37-rc3/ipc/sem.c
14687 --- linux-2.6.37/ipc/sem.c      2010-10-21 13:07:56.000000000 +0200
14688 +++ linux-2.6.37-vs2.3.0.37-rc3/ipc/sem.c       2010-11-23 02:09:41.000000000 +0100
14689 @@ -86,6 +86,8 @@
14690  #include <linux/rwsem.h>
14691  #include <linux/nsproxy.h>
14692  #include <linux/ipc_namespace.h>
14693 +#include <linux/vs_base.h>
14694 +#include <linux/vs_limit.h>
14695  
14696  #include <asm/uaccess.h>
14697  #include "util.h"
14698 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14699  
14700         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14701         sma->sem_perm.key = key;
14702 +       sma->sem_perm.xid = vx_current_xid();
14703  
14704         sma->sem_perm.security = NULL;
14705         retval = security_sem_alloc(sma);
14706 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14707                 return id;
14708         }
14709         ns->used_sems += nsems;
14710 +       /* FIXME: obsoleted? */
14711 +       vx_semary_inc(sma);
14712 +       vx_nsems_add(sma, nsems);
14713  
14714         sma->sem_base = (struct sem *) &sma[1];
14715  
14716 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
14717  
14718         wake_up_sem_queue_do(&tasks);
14719         ns->used_sems -= sma->sem_nsems;
14720 +       /* FIXME: obsoleted? */
14721 +       vx_nsems_sub(sma, sma->sem_nsems);
14722 +       vx_semary_dec(sma);
14723         security_sem_free(sma);
14724         ipc_rcu_putref(sma);
14725  }
14726 diff -NurpP --minimal linux-2.6.37/ipc/shm.c linux-2.6.37-vs2.3.0.37-rc3/ipc/shm.c
14727 --- linux-2.6.37/ipc/shm.c      2011-01-05 21:50:37.000000000 +0100
14728 +++ linux-2.6.37-vs2.3.0.37-rc3/ipc/shm.c       2010-11-23 02:09:41.000000000 +0100
14729 @@ -39,6 +39,8 @@
14730  #include <linux/nsproxy.h>
14731  #include <linux/mount.h>
14732  #include <linux/ipc_namespace.h>
14733 +#include <linux/vs_context.h>
14734 +#include <linux/vs_limit.h>
14735  
14736  #include <asm/uaccess.h>
14737  
14738 @@ -173,7 +175,12 @@ static void shm_open(struct vm_area_stru
14739   */
14740  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14741  {
14742 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14743 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14744 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14745 +
14746 +       vx_ipcshm_sub(vxi, shp, numpages);
14747 +       ns->shm_tot -= numpages;
14748 +
14749         shm_rmid(ns, shp);
14750         shm_unlock(shp);
14751         if (!is_file_hugepages(shp->shm_file))
14752 @@ -183,6 +190,7 @@ static void shm_destroy(struct ipc_names
14753                                                 shp->mlock_user);
14754         fput (shp->shm_file);
14755         security_shm_free(shp);
14756 +       put_vx_info(vxi);
14757         ipc_rcu_putref(shp);
14758  }
14759  
14760 @@ -355,11 +363,15 @@ static int newseg(struct ipc_namespace *
14761         if (ns->shm_tot + numpages > ns->shm_ctlall)
14762                 return -ENOSPC;
14763  
14764 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14765 +               return -ENOSPC;
14766 +
14767         shp = ipc_rcu_alloc(sizeof(*shp));
14768         if (!shp)
14769                 return -ENOMEM;
14770  
14771         shp->shm_perm.key = key;
14772 +       shp->shm_perm.xid = vx_current_xid();
14773         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14774         shp->mlock_user = NULL;
14775  
14776 @@ -413,6 +425,7 @@ static int newseg(struct ipc_namespace *
14777         ns->shm_tot += numpages;
14778         error = shp->shm_perm.id;
14779         shm_unlock(shp);
14780 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14781         return error;
14782  
14783  no_id:
14784 diff -NurpP --minimal linux-2.6.37/kernel/capability.c linux-2.6.37-vs2.3.0.37-rc3/kernel/capability.c
14785 --- linux-2.6.37/kernel/capability.c    2010-08-02 16:52:57.000000000 +0200
14786 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/capability.c     2010-11-23 02:09:41.000000000 +0100
14787 @@ -14,6 +14,7 @@
14788  #include <linux/security.h>
14789  #include <linux/syscalls.h>
14790  #include <linux/pid_namespace.h>
14791 +#include <linux/vs_context.h>
14792  #include <asm/uaccess.h>
14793  
14794  /*
14795 @@ -119,6 +120,7 @@ static int cap_validate_magic(cap_user_h
14796         return 0;
14797  }
14798  
14799 +
14800  /*
14801   * The only thing that can change the capabilities of the current
14802   * process is the current process. As such, we can't be in this code
14803 @@ -289,6 +291,8 @@ error:
14804         return ret;
14805  }
14806  
14807 +#include <linux/vserver/base.h>
14808 +
14809  /**
14810   * capable - Determine if the current task has a superior capability in effect
14811   * @cap: The capability to be tested for
14812 @@ -301,6 +305,9 @@ error:
14813   */
14814  int capable(int cap)
14815  {
14816 +       /* here for now so we don't require task locking */
14817 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
14818 +               return 0;
14819         if (unlikely(!cap_valid(cap))) {
14820                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
14821                 BUG();
14822 diff -NurpP --minimal linux-2.6.37/kernel/compat.c linux-2.6.37-vs2.3.0.37-rc3/kernel/compat.c
14823 --- linux-2.6.37/kernel/compat.c        2010-10-21 13:07:56.000000000 +0200
14824 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/compat.c 2010-11-23 02:09:41.000000000 +0100
14825 @@ -914,7 +914,7 @@ asmlinkage long compat_sys_stime(compat_
14826         if (err)
14827                 return err;
14828  
14829 -       do_settimeofday(&tv);
14830 +       vx_settimeofday(&tv);
14831         return 0;
14832  }
14833  
14834 diff -NurpP --minimal linux-2.6.37/kernel/cred.c linux-2.6.37-vs2.3.0.37-rc3/kernel/cred.c
14835 --- linux-2.6.37/kernel/cred.c  2011-01-05 21:50:37.000000000 +0100
14836 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/cred.c   2011-01-31 21:05:40.000000000 +0100
14837 @@ -60,31 +60,6 @@ struct cred init_cred = {
14838  #endif
14839  };
14840  
14841 -static inline void set_cred_subscribers(struct cred *cred, int n)
14842 -{
14843 -#ifdef CONFIG_DEBUG_CREDENTIALS
14844 -       atomic_set(&cred->subscribers, n);
14845 -#endif
14846 -}
14847 -
14848 -static inline int read_cred_subscribers(const struct cred *cred)
14849 -{
14850 -#ifdef CONFIG_DEBUG_CREDENTIALS
14851 -       return atomic_read(&cred->subscribers);
14852 -#else
14853 -       return 0;
14854 -#endif
14855 -}
14856 -
14857 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14858 -{
14859 -#ifdef CONFIG_DEBUG_CREDENTIALS
14860 -       struct cred *cred = (struct cred *) _cred;
14861 -
14862 -       atomic_add(n, &cred->subscribers);
14863 -#endif
14864 -}
14865 -
14866  /*
14867   * Dispose of the shared task group credentials
14868   */
14869 @@ -280,21 +255,16 @@ error:
14870   *
14871   * Call commit_creds() or abort_creds() to clean up.
14872   */
14873 -struct cred *prepare_creds(void)
14874 +struct cred *__prepare_creds(const struct cred *old)
14875  {
14876 -       struct task_struct *task = current;
14877 -       const struct cred *old;
14878         struct cred *new;
14879  
14880 -       validate_process_creds();
14881 -
14882         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14883         if (!new)
14884                 return NULL;
14885  
14886         kdebug("prepare_creds() alloc %p", new);
14887  
14888 -       old = task->cred;
14889         memcpy(new, old, sizeof(struct cred));
14890  
14891         atomic_set(&new->usage, 1);
14892 @@ -321,6 +291,13 @@ error:
14893         abort_creds(new);
14894         return NULL;
14895  }
14896 +
14897 +struct cred *prepare_creds(void)
14898 +{
14899 +       validate_process_creds();
14900 +
14901 +       return __prepare_creds(current->cred);
14902 +}
14903  EXPORT_SYMBOL(prepare_creds);
14904  
14905  /*
14906 diff -NurpP --minimal linux-2.6.37/kernel/exit.c linux-2.6.37-vs2.3.0.37-rc3/kernel/exit.c
14907 --- linux-2.6.37/kernel/exit.c  2011-01-05 21:50:37.000000000 +0100
14908 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/exit.c   2011-01-05 22:30:42.000000000 +0100
14909 @@ -48,6 +48,10 @@
14910  #include <linux/fs_struct.h>
14911  #include <linux/init_task.h>
14912  #include <linux/perf_event.h>
14913 +#include <linux/vs_limit.h>
14914 +#include <linux/vs_context.h>
14915 +#include <linux/vs_network.h>
14916 +#include <linux/vs_pid.h>
14917  #include <trace/events/sched.h>
14918  #include <linux/hw_breakpoint.h>
14919  #include <linux/oom.h>
14920 @@ -494,9 +498,11 @@ static void close_files(struct files_str
14921                                         filp_close(file, files);
14922                                         cond_resched();
14923                                 }
14924 +                               vx_openfd_dec(i);
14925                         }
14926                         i++;
14927                         set >>= 1;
14928 +                       cond_resched();
14929                 }
14930         }
14931  }
14932 @@ -1043,11 +1049,16 @@ NORET_TYPE void do_exit(long code)
14933  
14934         validate_creds_for_do_exit(tsk);
14935  
14936 +       /* needs to stay after exit_notify() */
14937 +       exit_vx_info(tsk, code);
14938 +       exit_nx_info(tsk);
14939 +
14940         preempt_disable();
14941         exit_rcu();
14942         /* causes final put_task_struct in finish_task_switch(). */
14943         tsk->state = TASK_DEAD;
14944         schedule();
14945 +       printk("bad task: %p [%lx]\n", current, current->state);
14946         BUG();
14947         /* Avoid "noreturn function does return".  */
14948         for (;;)
14949 diff -NurpP --minimal linux-2.6.37/kernel/fork.c linux-2.6.37-vs2.3.0.37-rc3/kernel/fork.c
14950 --- linux-2.6.37/kernel/fork.c  2011-01-05 21:50:37.000000000 +0100
14951 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/fork.c   2011-01-05 22:30:42.000000000 +0100
14952 @@ -66,6 +66,10 @@
14953  #include <linux/posix-timers.h>
14954  #include <linux/user-return-notifier.h>
14955  #include <linux/oom.h>
14956 +#include <linux/vs_context.h>
14957 +#include <linux/vs_network.h>
14958 +#include <linux/vs_limit.h>
14959 +#include <linux/vs_memory.h>
14960  
14961  #include <asm/pgtable.h>
14962  #include <asm/pgalloc.h>
14963 @@ -161,6 +165,8 @@ void free_task(struct task_struct *tsk)
14964         account_kernel_stack(tsk->stack, -1);
14965         free_thread_info(tsk->stack);
14966         rt_mutex_debug_task_free(tsk);
14967 +       clr_vx_info(&tsk->vx_info);
14968 +       clr_nx_info(&tsk->nx_info);
14969         ftrace_graph_exit_task(tsk);
14970         free_task_struct(tsk);
14971  }
14972 @@ -495,6 +501,7 @@ static struct mm_struct * mm_init(struct
14973         if (likely(!mm_alloc_pgd(mm))) {
14974                 mm->def_flags = 0;
14975                 mmu_notifier_mm_init(mm);
14976 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14977                 return mm;
14978         }
14979  
14980 @@ -528,6 +535,7 @@ void __mmdrop(struct mm_struct *mm)
14981         mm_free_pgd(mm);
14982         destroy_context(mm);
14983         mmu_notifier_mm_destroy(mm);
14984 +       clr_vx_info(&mm->mm_vx_info);
14985         free_mm(mm);
14986  }
14987  EXPORT_SYMBOL_GPL(__mmdrop);
14988 @@ -663,6 +671,7 @@ struct mm_struct *dup_mm(struct task_str
14989                 goto fail_nomem;
14990  
14991         memcpy(mm, oldmm, sizeof(*mm));
14992 +       mm->mm_vx_info = NULL;
14993  
14994         /* Initializing for Swap token stuff */
14995         mm->token_priority = 0;
14996 @@ -701,6 +710,7 @@ fail_nocontext:
14997          * If init_new_context() failed, we cannot use mmput() to free the mm
14998          * because it calls destroy_context()
14999          */
15000 +       clr_vx_info(&mm->mm_vx_info);
15001         mm_free_pgd(mm);
15002         free_mm(mm);
15003         return NULL;
15004 @@ -980,6 +990,8 @@ static struct task_struct *copy_process(
15005         int retval;
15006         struct task_struct *p;
15007         int cgroup_callbacks_done = 0;
15008 +       struct vx_info *vxi;
15009 +       struct nx_info *nxi;
15010  
15011         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15012                 return ERR_PTR(-EINVAL);
15013 @@ -1026,7 +1038,12 @@ static struct task_struct *copy_process(
15014         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15015         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15016  #endif
15017 +       init_vx_info(&p->vx_info, current_vx_info());
15018 +       init_nx_info(&p->nx_info, current_nx_info());
15019 +
15020         retval = -EAGAIN;
15021 +       if (!vx_nproc_avail(1))
15022 +               goto bad_fork_free;
15023         if (atomic_read(&p->real_cred->user->processes) >=
15024                         task_rlimit(p, RLIMIT_NPROC)) {
15025                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15026 @@ -1291,6 +1308,18 @@ static struct task_struct *copy_process(
15027  
15028         total_forks++;
15029         spin_unlock(&current->sighand->siglock);
15030 +
15031 +       /* p is copy of current */
15032 +       vxi = p->vx_info;
15033 +       if (vxi) {
15034 +               claim_vx_info(vxi, p);
15035 +               atomic_inc(&vxi->cvirt.nr_threads);
15036 +               atomic_inc(&vxi->cvirt.total_forks);
15037 +               vx_nproc_inc(p);
15038 +       }
15039 +       nxi = p->nx_info;
15040 +       if (nxi)
15041 +               claim_nx_info(nxi, p);
15042         write_unlock_irq(&tasklist_lock);
15043         proc_fork_connector(p);
15044         cgroup_post_fork(p);
15045 diff -NurpP --minimal linux-2.6.37/kernel/kthread.c linux-2.6.37-vs2.3.0.37-rc3/kernel/kthread.c
15046 --- linux-2.6.37/kernel/kthread.c       2011-01-05 21:50:38.000000000 +0100
15047 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/kthread.c        2011-01-05 22:30:42.000000000 +0100
15048 @@ -16,6 +16,7 @@
15049  #include <linux/mutex.h>
15050  #include <linux/slab.h>
15051  #include <linux/freezer.h>
15052 +#include <linux/vs_pid.h>
15053  #include <trace/events/sched.h>
15054  
15055  static DEFINE_SPINLOCK(kthread_create_lock);
15056 diff -NurpP --minimal linux-2.6.37/kernel/Makefile linux-2.6.37-vs2.3.0.37-rc3/kernel/Makefile
15057 --- linux-2.6.37/kernel/Makefile        2011-01-05 21:50:37.000000000 +0100
15058 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/Makefile 2010-11-23 02:09:41.000000000 +0100
15059 @@ -25,6 +25,7 @@ CFLAGS_REMOVE_perf_event.o = -pg
15060  CFLAGS_REMOVE_irq_work.o = -pg
15061  endif
15062  
15063 +obj-y += vserver/
15064  obj-$(CONFIG_FREEZER) += freezer.o
15065  obj-$(CONFIG_PROFILING) += profile.o
15066  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15067 diff -NurpP --minimal linux-2.6.37/kernel/nsproxy.c linux-2.6.37-vs2.3.0.37-rc3/kernel/nsproxy.c
15068 --- linux-2.6.37/kernel/nsproxy.c       2010-07-07 18:31:57.000000000 +0200
15069 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/nsproxy.c        2010-11-23 02:09:41.000000000 +0100
15070 @@ -20,6 +20,8 @@
15071  #include <linux/mnt_namespace.h>
15072  #include <linux/utsname.h>
15073  #include <linux/pid_namespace.h>
15074 +#include <linux/vserver/global.h>
15075 +#include <linux/vserver/debug.h>
15076  #include <net/net_namespace.h>
15077  #include <linux/ipc_namespace.h>
15078  
15079 @@ -43,8 +45,11 @@ static inline struct nsproxy *create_nsp
15080         struct nsproxy *nsproxy;
15081  
15082         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15083 -       if (nsproxy)
15084 +       if (nsproxy) {
15085                 atomic_set(&nsproxy->count, 1);
15086 +               atomic_inc(&vs_global_nsproxy);
15087 +       }
15088 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15089         return nsproxy;
15090  }
15091  
15092 @@ -53,41 +58,52 @@ static inline struct nsproxy *create_nsp
15093   * Return the newly created nsproxy.  Do not attach this to the task,
15094   * leave it to the caller to do proper locking and attach it to task.
15095   */
15096 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15097 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15098 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15099 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15100  {
15101         struct nsproxy *new_nsp;
15102         int err;
15103  
15104 +       vxdprintk(VXD_CBIT(space, 4),
15105 +               "unshare_namespaces(0x%08lx,%p,%p)",
15106 +               flags, orig, new_fs);
15107 +
15108         new_nsp = create_nsproxy();
15109         if (!new_nsp)
15110                 return ERR_PTR(-ENOMEM);
15111  
15112 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15113 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15114         if (IS_ERR(new_nsp->mnt_ns)) {
15115                 err = PTR_ERR(new_nsp->mnt_ns);
15116                 goto out_ns;
15117         }
15118  
15119 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15120 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15121         if (IS_ERR(new_nsp->uts_ns)) {
15122                 err = PTR_ERR(new_nsp->uts_ns);
15123                 goto out_uts;
15124         }
15125  
15126 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15127 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15128         if (IS_ERR(new_nsp->ipc_ns)) {
15129                 err = PTR_ERR(new_nsp->ipc_ns);
15130                 goto out_ipc;
15131         }
15132  
15133 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15134 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15135         if (IS_ERR(new_nsp->pid_ns)) {
15136                 err = PTR_ERR(new_nsp->pid_ns);
15137                 goto out_pid;
15138         }
15139  
15140 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15141 +       /* disabled now?
15142 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15143 +       if (IS_ERR(new_nsp->user_ns)) {
15144 +               err = PTR_ERR(new_nsp->user_ns);
15145 +               goto out_user;
15146 +       } */
15147 +
15148 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15149         if (IS_ERR(new_nsp->net_ns)) {
15150                 err = PTR_ERR(new_nsp->net_ns);
15151                 goto out_net;
15152 @@ -112,6 +128,38 @@ out_ns:
15153         return ERR_PTR(err);
15154  }
15155  
15156 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15157 +                       struct fs_struct *new_fs)
15158 +{
15159 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15160 +}
15161 +
15162 +/*
15163 + * copies the nsproxy, setting refcount to 1, and grabbing a
15164 + * reference to all contained namespaces.
15165 + */
15166 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15167 +{
15168 +       struct nsproxy *ns = create_nsproxy();
15169 +
15170 +       if (ns) {
15171 +               memcpy(ns, orig, sizeof(struct nsproxy));
15172 +               atomic_set(&ns->count, 1);
15173 +
15174 +               if (ns->mnt_ns)
15175 +                       get_mnt_ns(ns->mnt_ns);
15176 +               if (ns->uts_ns)
15177 +                       get_uts_ns(ns->uts_ns);
15178 +               if (ns->ipc_ns)
15179 +                       get_ipc_ns(ns->ipc_ns);
15180 +               if (ns->pid_ns)
15181 +                       get_pid_ns(ns->pid_ns);
15182 +               if (ns->net_ns)
15183 +                       get_net(ns->net_ns);
15184 +       }
15185 +       return ns;
15186 +}
15187 +
15188  /*
15189   * called from clone.  This now handles copy for nsproxy and all
15190   * namespaces therein.
15191 @@ -119,9 +167,12 @@ out_ns:
15192  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15193  {
15194         struct nsproxy *old_ns = tsk->nsproxy;
15195 -       struct nsproxy *new_ns;
15196 +       struct nsproxy *new_ns = NULL;
15197         int err = 0;
15198  
15199 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15200 +               flags, tsk, old_ns);
15201 +
15202         if (!old_ns)
15203                 return 0;
15204  
15205 @@ -131,7 +182,7 @@ int copy_namespaces(unsigned long flags,
15206                                 CLONE_NEWPID | CLONE_NEWNET)))
15207                 return 0;
15208  
15209 -       if (!capable(CAP_SYS_ADMIN)) {
15210 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15211                 err = -EPERM;
15212                 goto out;
15213         }
15214 @@ -158,6 +209,9 @@ int copy_namespaces(unsigned long flags,
15215  
15216  out:
15217         put_nsproxy(old_ns);
15218 +       vxdprintk(VXD_CBIT(space, 3),
15219 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15220 +               flags, tsk, old_ns, err, new_ns);
15221         return err;
15222  }
15223  
15224 @@ -171,7 +225,9 @@ void free_nsproxy(struct nsproxy *ns)
15225                 put_ipc_ns(ns->ipc_ns);
15226         if (ns->pid_ns)
15227                 put_pid_ns(ns->pid_ns);
15228 -       put_net(ns->net_ns);
15229 +       if (ns->net_ns)
15230 +               put_net(ns->net_ns);
15231 +       atomic_dec(&vs_global_nsproxy);
15232         kmem_cache_free(nsproxy_cachep, ns);
15233  }
15234  
15235 @@ -184,11 +240,15 @@ int unshare_nsproxy_namespaces(unsigned 
15236  {
15237         int err = 0;
15238  
15239 +       vxdprintk(VXD_CBIT(space, 4),
15240 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15241 +               unshare_flags, current->nsproxy);
15242 +
15243         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15244                                CLONE_NEWNET)))
15245                 return 0;
15246  
15247 -       if (!capable(CAP_SYS_ADMIN))
15248 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15249                 return -EPERM;
15250  
15251         *new_nsp = create_new_namespaces(unshare_flags, current,
15252 diff -NurpP --minimal linux-2.6.37/kernel/pid.c linux-2.6.37-vs2.3.0.37-rc3/kernel/pid.c
15253 --- linux-2.6.37/kernel/pid.c   2011-01-05 21:50:38.000000000 +0100
15254 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/pid.c    2010-11-23 02:37:26.000000000 +0100
15255 @@ -36,6 +36,7 @@
15256  #include <linux/pid_namespace.h>
15257  #include <linux/init_task.h>
15258  #include <linux/syscalls.h>
15259 +#include <linux/vs_pid.h>
15260  
15261  #define pid_hashfn(nr, ns)     \
15262         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15263 @@ -339,7 +340,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15264  
15265  struct pid *find_vpid(int nr)
15266  {
15267 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15268 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15269  }
15270  EXPORT_SYMBOL_GPL(find_vpid);
15271  
15272 @@ -399,6 +400,9 @@ void transfer_pid(struct task_struct *ol
15273  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15274  {
15275         struct task_struct *result = NULL;
15276 +
15277 +       if (type == PIDTYPE_REALPID)
15278 +               type = PIDTYPE_PID;
15279         if (pid) {
15280                 struct hlist_node *first;
15281                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
15282 @@ -417,7 +421,7 @@ EXPORT_SYMBOL(pid_task);
15283  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15284  {
15285         rcu_lockdep_assert(rcu_read_lock_held());
15286 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15287 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15288  }
15289  
15290  struct task_struct *find_task_by_vpid(pid_t vnr)
15291 @@ -459,7 +463,7 @@ struct pid *find_get_pid(pid_t nr)
15292  }
15293  EXPORT_SYMBOL_GPL(find_get_pid);
15294  
15295 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15296 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15297  {
15298         struct upid *upid;
15299         pid_t nr = 0;
15300 @@ -472,6 +476,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15301         return nr;
15302  }
15303  
15304 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15305 +{
15306 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15307 +}
15308 +
15309  pid_t pid_vnr(struct pid *pid)
15310  {
15311         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15312 diff -NurpP --minimal linux-2.6.37/kernel/pid_namespace.c linux-2.6.37-vs2.3.0.37-rc3/kernel/pid_namespace.c
15313 --- linux-2.6.37/kernel/pid_namespace.c 2010-07-07 18:31:57.000000000 +0200
15314 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/pid_namespace.c  2010-11-23 02:09:41.000000000 +0100
15315 @@ -14,6 +14,7 @@
15316  #include <linux/err.h>
15317  #include <linux/acct.h>
15318  #include <linux/slab.h>
15319 +#include <linux/vserver/global.h>
15320  
15321  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15322  
15323 @@ -87,6 +88,7 @@ static struct pid_namespace *create_pid_
15324                 goto out_free_map;
15325  
15326         kref_init(&ns->kref);
15327 +       atomic_inc(&vs_global_pid_ns);
15328         ns->level = level;
15329         ns->parent = get_pid_ns(parent_pid_ns);
15330  
15331 @@ -112,6 +114,7 @@ static void destroy_pid_namespace(struct
15332  
15333         for (i = 0; i < PIDMAP_ENTRIES; i++)
15334                 kfree(ns->pidmap[i].page);
15335 +       atomic_dec(&vs_global_pid_ns);
15336         kmem_cache_free(pid_ns_cachep, ns);
15337  }
15338  
15339 diff -NurpP --minimal linux-2.6.37/kernel/posix-timers.c linux-2.6.37-vs2.3.0.37-rc3/kernel/posix-timers.c
15340 --- linux-2.6.37/kernel/posix-timers.c  2010-10-21 13:07:57.000000000 +0200
15341 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/posix-timers.c   2010-11-23 02:09:41.000000000 +0100
15342 @@ -46,6 +46,7 @@
15343  #include <linux/wait.h>
15344  #include <linux/workqueue.h>
15345  #include <linux/module.h>
15346 +#include <linux/vs_context.h>
15347  
15348  /*
15349   * Management arrays for POSIX timers.  Timers are kept in slab memory
15350 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15351  {
15352         struct task_struct *task;
15353         int shared, ret = -1;
15354 +
15355         /*
15356          * FIXME: if ->sigq is queued we can race with
15357          * dequeue_signal()->do_schedule_next_timer().
15358 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15359         rcu_read_lock();
15360         task = pid_task(timr->it_pid, PIDTYPE_PID);
15361         if (task) {
15362 +               struct vx_info_save vxis;
15363 +               struct vx_info *vxi;
15364 +
15365 +               vxi = get_vx_info(task->vx_info);
15366 +               enter_vx_info(vxi, &vxis);
15367                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15368                 ret = send_sigqueue(timr->sigq, task, shared);
15369 +               leave_vx_info(&vxis);
15370 +               put_vx_info(vxi);
15371         }
15372         rcu_read_unlock();
15373 +
15374         /* If we failed to send the signal the timer stops. */
15375         return ret > 0;
15376  }
15377 diff -NurpP --minimal linux-2.6.37/kernel/printk.c linux-2.6.37-vs2.3.0.37-rc3/kernel/printk.c
15378 --- linux-2.6.37/kernel/printk.c        2011-01-05 21:50:38.000000000 +0100
15379 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/printk.c 2011-01-05 22:30:42.000000000 +0100
15380 @@ -39,6 +39,7 @@
15381  #include <linux/syslog.h>
15382  #include <linux/cpu.h>
15383  #include <linux/notifier.h>
15384 +#include <linux/vs_cvirt.h>
15385  
15386  #include <asm/uaccess.h>
15387  
15388 @@ -272,18 +273,19 @@ int do_syslog(int type, char __user *buf
15389         unsigned i, j, limit, count;
15390         int do_clear = 0;
15391         char c;
15392 -       int error = 0;
15393 +       int error;
15394  
15395         /*
15396          * If this is from /proc/kmsg we only do the capabilities checks
15397          * at open time.
15398          */
15399         if (type == SYSLOG_ACTION_OPEN || !from_file) {
15400 -               if (dmesg_restrict && !capable(CAP_SYS_ADMIN))
15401 +               if (dmesg_restrict &&
15402 +                   !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
15403                         return -EPERM;
15404                 if ((type != SYSLOG_ACTION_READ_ALL &&
15405                      type != SYSLOG_ACTION_SIZE_BUFFER) &&
15406 -                   !capable(CAP_SYS_ADMIN))
15407 +                   !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
15408                         return -EPERM;
15409         }
15410  
15411 @@ -291,12 +293,9 @@ int do_syslog(int type, char __user *buf
15412         if (error)
15413                 return error;
15414  
15415 -       switch (type) {
15416 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15417 -               break;
15418 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15419 -               break;
15420 -       case SYSLOG_ACTION_READ:        /* Read from log */
15421 +       if ((type == SYSLOG_ACTION_READ) ||
15422 +           (type == SYSLOG_ACTION_READ_ALL) ||
15423 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15424                 error = -EINVAL;
15425                 if (!buf || len < 0)
15426                         goto out;
15427 @@ -307,6 +306,16 @@ int do_syslog(int type, char __user *buf
15428                         error = -EFAULT;
15429                         goto out;
15430                 }
15431 +       }
15432 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15433 +               return vx_do_syslog(type, buf, len);
15434 +
15435 +       switch (type) {
15436 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15437 +               break;
15438 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15439 +               break;
15440 +       case SYSLOG_ACTION_READ:        /* Read from log */
15441                 error = wait_event_interruptible(log_wait,
15442                                                         (log_start - log_end));
15443                 if (error)
15444 @@ -333,16 +342,6 @@ int do_syslog(int type, char __user *buf
15445                 /* FALL THRU */
15446         /* Read last kernel messages */
15447         case SYSLOG_ACTION_READ_ALL:
15448 -               error = -EINVAL;
15449 -               if (!buf || len < 0)
15450 -                       goto out;
15451 -               error = 0;
15452 -               if (!len)
15453 -                       goto out;
15454 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15455 -                       error = -EFAULT;
15456 -                       goto out;
15457 -               }
15458                 count = len;
15459                 if (count > log_buf_len)
15460                         count = log_buf_len;
15461 diff -NurpP --minimal linux-2.6.37/kernel/ptrace.c linux-2.6.37-vs2.3.0.37-rc3/kernel/ptrace.c
15462 --- linux-2.6.37/kernel/ptrace.c        2011-01-05 21:50:38.000000000 +0100
15463 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/ptrace.c 2010-11-23 02:09:41.000000000 +0100
15464 @@ -22,6 +22,7 @@
15465  #include <linux/syscalls.h>
15466  #include <linux/uaccess.h>
15467  #include <linux/regset.h>
15468 +#include <linux/vs_context.h>
15469  
15470  
15471  /*
15472 @@ -150,6 +151,11 @@ int __ptrace_may_access(struct task_stru
15473                 dumpable = get_dumpable(task->mm);
15474         if (!dumpable && !capable(CAP_SYS_PTRACE))
15475                 return -EPERM;
15476 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15477 +               return -EPERM;
15478 +       if (!vx_check(task->xid, VS_IDENT) &&
15479 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15480 +               return -EACCES;
15481  
15482         return security_ptrace_access_check(task, mode);
15483  }
15484 @@ -713,6 +719,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15485                 goto out;
15486         }
15487  
15488 +       ret = -EPERM;
15489 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15490 +               goto out_put_task_struct;
15491 +
15492         if (request == PTRACE_ATTACH) {
15493                 ret = ptrace_attach(child);
15494                 /*
15495 diff -NurpP --minimal linux-2.6.37/kernel/sched.c linux-2.6.37-vs2.3.0.37-rc3/kernel/sched.c
15496 --- linux-2.6.37/kernel/sched.c 2011-01-05 21:50:38.000000000 +0100
15497 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/sched.c  2011-01-05 22:30:42.000000000 +0100
15498 @@ -72,6 +72,8 @@
15499  #include <linux/ctype.h>
15500  #include <linux/ftrace.h>
15501  #include <linux/slab.h>
15502 +#include <linux/vs_sched.h>
15503 +#include <linux/vs_cvirt.h>
15504  
15505  #include <asm/tlb.h>
15506  #include <asm/irq_regs.h>
15507 @@ -3361,9 +3363,17 @@ static void calc_global_nohz(unsigned lo
15508   */
15509  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15510  {
15511 -       loads[0] = (avenrun[0] + offset) << shift;
15512 -       loads[1] = (avenrun[1] + offset) << shift;
15513 -       loads[2] = (avenrun[2] + offset) << shift;
15514 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15515 +               struct vx_info *vxi = current_vx_info();
15516 +
15517 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15518 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15519 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15520 +       } else {
15521 +               loads[0] = (avenrun[0] + offset) << shift;
15522 +               loads[1] = (avenrun[1] + offset) << shift;
15523 +               loads[2] = (avenrun[2] + offset) << shift;
15524 +       }
15525  }
15526  
15527  /*
15528 @@ -3651,16 +3661,19 @@ void account_user_time(struct task_struc
15529                        cputime_t cputime_scaled)
15530  {
15531         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15532 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15533         cputime64_t tmp;
15534 +       int nice = (TASK_NICE(p) > 0);
15535  
15536         /* Add user time to process. */
15537         p->utime = cputime_add(p->utime, cputime);
15538         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15539 +       vx_account_user(vxi, cputime, nice);
15540         account_group_user_time(p, cputime);
15541  
15542         /* Add user time to cpustat. */
15543         tmp = cputime_to_cputime64(cputime);
15544 -       if (TASK_NICE(p) > 0)
15545 +       if (nice)
15546                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15547         else
15548                 cpustat->user = cputime64_add(cpustat->user, tmp);
15549 @@ -3711,6 +3724,7 @@ void account_system_time(struct task_str
15550                          cputime_t cputime, cputime_t cputime_scaled)
15551  {
15552         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15553 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15554         cputime64_t tmp;
15555  
15556         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15557 @@ -3721,6 +3735,7 @@ void account_system_time(struct task_str
15558         /* Add system time to process. */
15559         p->stime = cputime_add(p->stime, cputime);
15560         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15561 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15562         account_group_system_time(p, cputime);
15563  
15564         /* Add system time to cpustat. */
15565 @@ -4804,7 +4819,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15566                 nice = 19;
15567  
15568         if (increment < 0 && !can_nice(current, nice))
15569 -               return -EPERM;
15570 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15571  
15572         retval = security_task_setnice(current, nice);
15573         if (retval)
15574 diff -NurpP --minimal linux-2.6.37/kernel/sched_fair.c linux-2.6.37-vs2.3.0.37-rc3/kernel/sched_fair.c
15575 --- linux-2.6.37/kernel/sched_fair.c    2011-01-05 21:50:38.000000000 +0100
15576 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/sched_fair.c     2011-01-05 22:30:42.000000000 +0100
15577 @@ -782,6 +782,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15578         check_spread(cfs_rq, se);
15579         if (se != cfs_rq->curr)
15580                 __enqueue_entity(cfs_rq, se);
15581 +
15582 +       if (entity_is_task(se))
15583 +               vx_activate_task(task_of(se));
15584  }
15585  
15586  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
15587 @@ -825,6 +828,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15588  
15589         if (se != cfs_rq->curr)
15590                 __dequeue_entity(cfs_rq, se);
15591 +       if (entity_is_task(se))
15592 +               vx_deactivate_task(task_of(se));
15593         account_entity_dequeue(cfs_rq, se);
15594         update_min_vruntime(cfs_rq);
15595  
15596 diff -NurpP --minimal linux-2.6.37/kernel/signal.c linux-2.6.37-vs2.3.0.37-rc3/kernel/signal.c
15597 --- linux-2.6.37/kernel/signal.c        2011-01-05 21:50:38.000000000 +0100
15598 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/signal.c 2010-11-23 02:09:41.000000000 +0100
15599 @@ -28,6 +28,8 @@
15600  #include <linux/freezer.h>
15601  #include <linux/pid_namespace.h>
15602  #include <linux/nsproxy.h>
15603 +#include <linux/vs_context.h>
15604 +#include <linux/vs_pid.h>
15605  #define CREATE_TRACE_POINTS
15606  #include <trace/events/signal.h>
15607  
15608 @@ -646,9 +648,18 @@ static int check_kill_permission(int sig
15609         struct pid *sid;
15610         int error;
15611  
15612 +       vxdprintk(VXD_CBIT(misc, 7),
15613 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15614 +               sig, info, t, vx_task_xid(t), t->pid);
15615 +
15616         if (!valid_signal(sig))
15617                 return -EINVAL;
15618  
15619 +/*     FIXME: needed? if so, why?
15620 +       if ((info != SEND_SIG_NOINFO) &&
15621 +               (is_si_special(info) || !si_fromuser(info)))
15622 +               goto skip;      */
15623 +
15624         if (!si_fromuser(info))
15625                 return 0;
15626  
15627 @@ -678,6 +689,20 @@ static int check_kill_permission(int sig
15628                 }
15629         }
15630  
15631 +       error = -EPERM;
15632 +       if (t->pid == 1 && current->xid)
15633 +               return error;
15634 +
15635 +       error = -ESRCH;
15636 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15637 +                 loops, maybe ENOENT or EACCES? */
15638 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15639 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15640 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15641 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15642 +               return error;
15643 +       }
15644 +/* skip: */
15645         return security_task_kill(t, info, sig, 0);
15646  }
15647  
15648 @@ -1171,7 +1196,7 @@ int kill_pid_info(int sig, struct siginf
15649         rcu_read_lock();
15650  retry:
15651         p = pid_task(pid, PIDTYPE_PID);
15652 -       if (p) {
15653 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15654                 error = group_send_sig_info(sig, info, p);
15655                 if (unlikely(error == -ESRCH))
15656                         /*
15657 @@ -1211,7 +1236,7 @@ int kill_pid_info_as_uid(int sig, struct
15658  
15659         rcu_read_lock();
15660         p = pid_task(pid, PIDTYPE_PID);
15661 -       if (!p) {
15662 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15663                 ret = -ESRCH;
15664                 goto out_unlock;
15665         }
15666 @@ -1266,8 +1291,10 @@ static int kill_something_info(int sig, 
15667                 struct task_struct * p;
15668  
15669                 for_each_process(p) {
15670 -                       if (task_pid_vnr(p) > 1 &&
15671 -                                       !same_thread_group(p, current)) {
15672 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15673 +                               task_pid_vnr(p) > 1 &&
15674 +                               !same_thread_group(p, current) &&
15675 +                               !vx_current_initpid(p->pid)) {
15676                                 int err = group_send_sig_info(sig, info, p);
15677                                 ++count;
15678                                 if (err != -EPERM)
15679 @@ -1936,6 +1963,11 @@ relock:
15680                                 !sig_kernel_only(signr))
15681                         continue;
15682  
15683 +               /* virtual init is protected against user signals */
15684 +               if ((info->si_code == SI_USER) &&
15685 +                       vx_current_initpid(current->pid))
15686 +                       continue;
15687 +
15688                 if (sig_kernel_stop(signr)) {
15689                         /*
15690                          * The default action is to stop all threads in
15691 diff -NurpP --minimal linux-2.6.37/kernel/softirq.c linux-2.6.37-vs2.3.0.37-rc3/kernel/softirq.c
15692 --- linux-2.6.37/kernel/softirq.c       2011-01-05 21:50:38.000000000 +0100
15693 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/softirq.c        2010-11-23 02:09:41.000000000 +0100
15694 @@ -24,6 +24,7 @@
15695  #include <linux/ftrace.h>
15696  #include <linux/smp.h>
15697  #include <linux/tick.h>
15698 +#include <linux/vs_context.h>
15699  
15700  #define CREATE_TRACE_POINTS
15701  #include <trace/events/irq.h>
15702 diff -NurpP --minimal linux-2.6.37/kernel/sys.c linux-2.6.37-vs2.3.0.37-rc3/kernel/sys.c
15703 --- linux-2.6.37/kernel/sys.c   2010-10-21 13:07:57.000000000 +0200
15704 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/sys.c    2010-11-23 02:09:41.000000000 +0100
15705 @@ -42,6 +42,7 @@
15706  #include <linux/syscalls.h>
15707  #include <linux/kprobes.h>
15708  #include <linux/user_namespace.h>
15709 +#include <linux/vs_pid.h>
15710  
15711  #include <asm/uaccess.h>
15712  #include <asm/io.h>
15713 @@ -131,7 +132,10 @@ static int set_one_prio(struct task_stru
15714                 goto out;
15715         }
15716         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15717 -               error = -EACCES;
15718 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15719 +                       error = 0;
15720 +               else
15721 +                       error = -EACCES;
15722                 goto out;
15723         }
15724         no_nice = security_task_setnice(p, niceval);
15725 @@ -181,6 +185,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15726                         else
15727                                 pgrp = task_pgrp(current);
15728                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15729 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15730 +                                       continue;
15731                                 error = set_one_prio(p, niceval, error);
15732                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15733                         break;
15734 @@ -244,6 +250,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15735                         else
15736                                 pgrp = task_pgrp(current);
15737                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15738 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15739 +                                       continue;
15740                                 niceval = 20 - task_nice(p);
15741                                 if (niceval > retval)
15742                                         retval = niceval;
15743 @@ -357,6 +365,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15744  
15745  static DEFINE_MUTEX(reboot_mutex);
15746  
15747 +long vs_reboot(unsigned int, void __user *);
15748 +
15749  /*
15750   * Reboot system call: for obvious reasons only root may call it,
15751   * and even root needs to set up some magic numbers in the registers
15752 @@ -389,6 +399,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15753         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15754                 cmd = LINUX_REBOOT_CMD_HALT;
15755  
15756 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15757 +               return vs_reboot(cmd, arg);
15758 +
15759         mutex_lock(&reboot_mutex);
15760         switch (cmd) {
15761         case LINUX_REBOOT_CMD_RESTART:
15762 @@ -1169,7 +1182,7 @@ SYSCALL_DEFINE2(sethostname, char __user
15763         int errno;
15764         char tmp[__NEW_UTS_LEN];
15765  
15766 -       if (!capable(CAP_SYS_ADMIN))
15767 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15768                 return -EPERM;
15769         if (len < 0 || len > __NEW_UTS_LEN)
15770                 return -EINVAL;
15771 @@ -1218,7 +1231,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
15772         int errno;
15773         char tmp[__NEW_UTS_LEN];
15774  
15775 -       if (!capable(CAP_SYS_ADMIN))
15776 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15777                 return -EPERM;
15778         if (len < 0 || len > __NEW_UTS_LEN)
15779                 return -EINVAL;
15780 @@ -1334,7 +1347,7 @@ int do_prlimit(struct task_struct *tsk, 
15781         task_lock(tsk->group_leader);
15782         if (new_rlim) {
15783                 if (new_rlim->rlim_max > rlim->rlim_max &&
15784 -                               !capable(CAP_SYS_RESOURCE))
15785 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15786                         retval = -EPERM;
15787                 if (!retval)
15788                         retval = security_task_setrlimit(tsk->group_leader,
15789 @@ -1383,7 +1396,7 @@ static int check_prlimit_permission(stru
15790              cred->gid != tcred->egid ||
15791              cred->gid != tcred->sgid ||
15792              cred->gid != tcred->gid) &&
15793 -            !capable(CAP_SYS_RESOURCE)) {
15794 +            !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT)) {
15795                 return -EPERM;
15796         }
15797  
15798 diff -NurpP --minimal linux-2.6.37/kernel/sysctl_binary.c linux-2.6.37-vs2.3.0.37-rc3/kernel/sysctl_binary.c
15799 --- linux-2.6.37/kernel/sysctl_binary.c 2010-08-02 16:52:57.000000000 +0200
15800 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/sysctl_binary.c  2010-11-23 02:09:41.000000000 +0100
15801 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15802  
15803         { CTL_INT,      KERN_PANIC,                     "panic" },
15804         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15805 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15806  
15807         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15808         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15809 diff -NurpP --minimal linux-2.6.37/kernel/sysctl.c linux-2.6.37-vs2.3.0.37-rc3/kernel/sysctl.c
15810 --- linux-2.6.37/kernel/sysctl.c        2011-01-05 21:50:39.000000000 +0100
15811 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/sysctl.c 2010-11-23 02:09:41.000000000 +0100
15812 @@ -73,6 +73,7 @@
15813  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15814  #include <linux/lockdep.h>
15815  #endif
15816 +extern char vshelper_path[];
15817  #ifdef CONFIG_CHR_DEV_SG
15818  #include <scsi/sg.h>
15819  #endif
15820 @@ -571,6 +572,13 @@ static struct ctl_table kern_table[] = {
15821                 .proc_handler   = proc_dostring,
15822         },
15823  #endif
15824 +       {
15825 +               .procname       = "vshelper",
15826 +               .data           = &vshelper_path,
15827 +               .maxlen         = 256,
15828 +               .mode           = 0644,
15829 +               .proc_handler   = &proc_dostring,
15830 +       },
15831  #ifdef CONFIG_CHR_DEV_SG
15832         {
15833                 .procname       = "sg-big-buff",
15834 diff -NurpP --minimal linux-2.6.37/kernel/time/timekeeping.c linux-2.6.37-vs2.3.0.37-rc3/kernel/time/timekeeping.c
15835 --- linux-2.6.37/kernel/time/timekeeping.c      2010-10-21 13:07:57.000000000 +0200
15836 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/time/timekeeping.c       2010-11-23 02:09:41.000000000 +0100
15837 @@ -229,6 +229,7 @@ void getnstimeofday(struct timespec *ts)
15838         } while (read_seqretry(&xtime_lock, seq));
15839  
15840         timespec_add_ns(ts, nsecs);
15841 +       vx_adjust_timespec(ts);
15842  }
15843  
15844  EXPORT_SYMBOL(getnstimeofday);
15845 diff -NurpP --minimal linux-2.6.37/kernel/time.c linux-2.6.37-vs2.3.0.37-rc3/kernel/time.c
15846 --- linux-2.6.37/kernel/time.c  2010-10-21 13:07:57.000000000 +0200
15847 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/time.c   2010-11-23 02:09:41.000000000 +0100
15848 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15849         if (err)
15850                 return err;
15851  
15852 -       do_settimeofday(&tv);
15853 +       vx_settimeofday(&tv);
15854         return 0;
15855  }
15856  
15857 @@ -177,7 +177,7 @@ int do_sys_settimeofday(struct timespec 
15858                 /* SMP safe, again the code in arch/foo/time.c should
15859                  * globally block out interrupts when it runs.
15860                  */
15861 -               return do_settimeofday(tv);
15862 +               return vx_settimeofday(tv);
15863         }
15864         return 0;
15865  }
15866 diff -NurpP --minimal linux-2.6.37/kernel/timer.c linux-2.6.37-vs2.3.0.37-rc3/kernel/timer.c
15867 --- linux-2.6.37/kernel/timer.c 2011-01-05 21:50:39.000000000 +0100
15868 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/timer.c  2011-01-05 22:30:42.000000000 +0100
15869 @@ -40,6 +40,10 @@
15870  #include <linux/irq_work.h>
15871  #include <linux/sched.h>
15872  #include <linux/slab.h>
15873 +#include <linux/vs_base.h>
15874 +#include <linux/vs_cvirt.h>
15875 +#include <linux/vs_pid.h>
15876 +#include <linux/vserver/sched.h>
15877  
15878  #include <asm/uaccess.h>
15879  #include <asm/unistd.h>
15880 @@ -1341,12 +1345,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15881  
15882  #endif
15883  
15884 -#ifndef __alpha__
15885 -
15886 -/*
15887 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15888 - * should be moved into arch/i386 instead?
15889 - */
15890  
15891  /**
15892   * sys_getpid - return the thread group id of the current process
15893 @@ -1375,10 +1373,23 @@ SYSCALL_DEFINE0(getppid)
15894         rcu_read_lock();
15895         pid = task_tgid_vnr(current->real_parent);
15896         rcu_read_unlock();
15897 +       return vx_map_pid(pid);
15898 +}
15899  
15900 -       return pid;
15901 +#ifdef __alpha__
15902 +
15903 +/*
15904 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15905 + */
15906 +
15907 +asmlinkage long do_getxpid(long *ppid)
15908 +{
15909 +       *ppid = sys_getppid();
15910 +       return sys_getpid();
15911  }
15912  
15913 +#else /* _alpha_ */
15914 +
15915  SYSCALL_DEFINE0(getuid)
15916  {
15917         /* Only we change this so SMP safe */
15918 diff -NurpP --minimal linux-2.6.37/kernel/user_namespace.c linux-2.6.37-vs2.3.0.37-rc3/kernel/user_namespace.c
15919 --- linux-2.6.37/kernel/user_namespace.c        2010-10-21 13:07:57.000000000 +0200
15920 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/user_namespace.c 2010-11-23 02:09:41.000000000 +0100
15921 @@ -11,6 +11,7 @@
15922  #include <linux/user_namespace.h>
15923  #include <linux/highuid.h>
15924  #include <linux/cred.h>
15925 +#include <linux/vserver/global.h>
15926  
15927  /*
15928   * Create a new user namespace, deriving the creator from the user in the
15929 @@ -31,6 +32,7 @@ int create_user_ns(struct cred *new)
15930                 return -ENOMEM;
15931  
15932         kref_init(&ns->kref);
15933 +       atomic_inc(&vs_global_user_ns);
15934  
15935         for (n = 0; n < UIDHASH_SZ; ++n)
15936                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15937 @@ -79,6 +81,8 @@ void free_user_ns(struct kref *kref)
15938         struct user_namespace *ns =
15939                 container_of(kref, struct user_namespace, kref);
15940  
15941 +       /* FIXME: maybe move into destroyer? */
15942 +       atomic_dec(&vs_global_user_ns);
15943         INIT_WORK(&ns->destroyer, free_user_ns_work);
15944         schedule_work(&ns->destroyer);
15945  }
15946 diff -NurpP --minimal linux-2.6.37/kernel/utsname.c linux-2.6.37-vs2.3.0.37-rc3/kernel/utsname.c
15947 --- linux-2.6.37/kernel/utsname.c       2009-09-10 15:26:28.000000000 +0200
15948 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/utsname.c        2010-11-23 02:09:41.000000000 +0100
15949 @@ -14,14 +14,17 @@
15950  #include <linux/utsname.h>
15951  #include <linux/err.h>
15952  #include <linux/slab.h>
15953 +#include <linux/vserver/global.h>
15954  
15955  static struct uts_namespace *create_uts_ns(void)
15956  {
15957         struct uts_namespace *uts_ns;
15958  
15959         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15960 -       if (uts_ns)
15961 +       if (uts_ns) {
15962                 kref_init(&uts_ns->kref);
15963 +               atomic_inc(&vs_global_uts_ns);
15964 +       }
15965         return uts_ns;
15966  }
15967  
15968 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
15969         struct uts_namespace *ns;
15970  
15971         ns = container_of(kref, struct uts_namespace, kref);
15972 +       atomic_dec(&vs_global_uts_ns);
15973         kfree(ns);
15974  }
15975 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cacct.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cacct.c
15976 --- linux-2.6.37/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
15977 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cacct.c  2010-11-23 02:09:41.000000000 +0100
15978 @@ -0,0 +1,42 @@
15979 +/*
15980 + *  linux/kernel/vserver/cacct.c
15981 + *
15982 + *  Virtual Server: Context Accounting
15983 + *
15984 + *  Copyright (C) 2006-2007 Herbert Pötzl
15985 + *
15986 + *  V0.01  added accounting stats
15987 + *
15988 + */
15989 +
15990 +#include <linux/types.h>
15991 +#include <linux/vs_context.h>
15992 +#include <linux/vserver/cacct_cmd.h>
15993 +#include <linux/vserver/cacct_int.h>
15994 +
15995 +#include <asm/errno.h>
15996 +#include <asm/uaccess.h>
15997 +
15998 +
15999 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16000 +{
16001 +       struct vcmd_sock_stat_v0 vc_data;
16002 +       int j, field;
16003 +
16004 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16005 +               return -EFAULT;
16006 +
16007 +       field = vc_data.field;
16008 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16009 +               return -EINVAL;
16010 +
16011 +       for (j = 0; j < 3; j++) {
16012 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16013 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16014 +       }
16015 +
16016 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16017 +               return -EFAULT;
16018 +       return 0;
16019 +}
16020 +
16021 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cacct_init.h linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cacct_init.h
16022 --- linux-2.6.37/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
16023 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cacct_init.h     2010-11-23 02:09:41.000000000 +0100
16024 @@ -0,0 +1,25 @@
16025 +
16026 +
16027 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16028 +{
16029 +       int i, j;
16030 +
16031 +
16032 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16033 +               for (j = 0; j < 3; j++) {
16034 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16035 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16036 +               }
16037 +       }
16038 +       for (i = 0; i < 8; i++)
16039 +               atomic_set(&cacct->slab[i], 0);
16040 +       for (i = 0; i < 5; i++)
16041 +               for (j = 0; j < 4; j++)
16042 +                       atomic_set(&cacct->page[i][j], 0);
16043 +}
16044 +
16045 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16046 +{
16047 +       return;
16048 +}
16049 +
16050 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cacct_proc.h linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cacct_proc.h
16051 --- linux-2.6.37/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
16052 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cacct_proc.h     2010-11-23 02:09:41.000000000 +0100
16053 @@ -0,0 +1,53 @@
16054 +#ifndef _VX_CACCT_PROC_H
16055 +#define _VX_CACCT_PROC_H
16056 +
16057 +#include <linux/vserver/cacct_int.h>
16058 +
16059 +
16060 +#define VX_SOCKA_TOP   \
16061 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16062 +
16063 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16064 +{
16065 +       int i, j, length = 0;
16066 +       static char *type[VXA_SOCK_SIZE] = {
16067 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16068 +       };
16069 +
16070 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16071 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16072 +               length += sprintf(buffer + length, "%s:", type[i]);
16073 +               for (j = 0; j < 3; j++) {
16074 +                       length += sprintf(buffer + length,
16075 +                               "\t%10lu/%-10lu",
16076 +                               vx_sock_count(cacct, i, j),
16077 +                               vx_sock_total(cacct, i, j));
16078 +               }
16079 +               buffer[length++] = '\n';
16080 +       }
16081 +
16082 +       length += sprintf(buffer + length, "\n");
16083 +       length += sprintf(buffer + length,
16084 +               "slab:\t %8u %8u %8u %8u\n",
16085 +               atomic_read(&cacct->slab[1]),
16086 +               atomic_read(&cacct->slab[4]),
16087 +               atomic_read(&cacct->slab[0]),
16088 +               atomic_read(&cacct->slab[2]));
16089 +
16090 +       length += sprintf(buffer + length, "\n");
16091 +       for (i = 0; i < 5; i++) {
16092 +               length += sprintf(buffer + length,
16093 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16094 +                       atomic_read(&cacct->page[i][0]),
16095 +                       atomic_read(&cacct->page[i][1]),
16096 +                       atomic_read(&cacct->page[i][2]),
16097 +                       atomic_read(&cacct->page[i][3]),
16098 +                       atomic_read(&cacct->page[i][4]),
16099 +                       atomic_read(&cacct->page[i][5]),
16100 +                       atomic_read(&cacct->page[i][6]),
16101 +                       atomic_read(&cacct->page[i][7]));
16102 +       }
16103 +       return length;
16104 +}
16105 +
16106 +#endif /* _VX_CACCT_PROC_H */
16107 diff -NurpP --minimal linux-2.6.37/kernel/vserver/context.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/context.c
16108 --- linux-2.6.37/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
16109 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/context.c        2011-01-31 21:05:40.000000000 +0100
16110 @@ -0,0 +1,1086 @@
16111 +/*
16112 + *  linux/kernel/vserver/context.c
16113 + *
16114 + *  Virtual Server: Context Support
16115 + *
16116 + *  Copyright (C) 2003-2010  Herbert Pötzl
16117 + *
16118 + *  V0.01  context helper
16119 + *  V0.02  vx_ctx_kill syscall command
16120 + *  V0.03  replaced context_info calls
16121 + *  V0.04  redesign of struct (de)alloc
16122 + *  V0.05  rlimit basic implementation
16123 + *  V0.06  task_xid and info commands
16124 + *  V0.07  context flags and caps
16125 + *  V0.08  switch to RCU based hash
16126 + *  V0.09  revert to non RCU for now
16127 + *  V0.10  and back to working RCU hash
16128 + *  V0.11  and back to locking again
16129 + *  V0.12  referenced context store
16130 + *  V0.13  separate per cpu data
16131 + *  V0.14  changed vcmds to vxi arg
16132 + *  V0.15  added context stat
16133 + *  V0.16  have __create claim() the vxi
16134 + *  V0.17  removed older and legacy stuff
16135 + *  V0.18  added user credentials
16136 + *
16137 + */
16138 +
16139 +#include <linux/slab.h>
16140 +#include <linux/types.h>
16141 +#include <linux/security.h>
16142 +#include <linux/pid_namespace.h>
16143 +
16144 +#include <linux/vserver/context.h>
16145 +#include <linux/vserver/network.h>
16146 +#include <linux/vserver/debug.h>
16147 +#include <linux/vserver/limit.h>
16148 +#include <linux/vserver/limit_int.h>
16149 +#include <linux/vserver/space.h>
16150 +#include <linux/init_task.h>
16151 +#include <linux/fs_struct.h>
16152 +#include <linux/cred.h>
16153 +
16154 +#include <linux/vs_context.h>
16155 +#include <linux/vs_limit.h>
16156 +#include <linux/vs_pid.h>
16157 +#include <linux/vserver/context_cmd.h>
16158 +
16159 +#include "cvirt_init.h"
16160 +#include "cacct_init.h"
16161 +#include "limit_init.h"
16162 +#include "sched_init.h"
16163 +
16164 +
16165 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16166 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16167 +
16168 +
16169 +/*     now inactive context structures */
16170 +
16171 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16172 +
16173 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
16174 +
16175 +
16176 +/*     __alloc_vx_info()
16177 +
16178 +       * allocate an initialized vx_info struct
16179 +       * doesn't make it visible (hash)                        */
16180 +
16181 +static struct vx_info *__alloc_vx_info(xid_t xid)
16182 +{
16183 +       struct vx_info *new = NULL;
16184 +       int cpu, index;
16185 +
16186 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16187 +
16188 +       /* would this benefit from a slab cache? */
16189 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16190 +       if (!new)
16191 +               return 0;
16192 +
16193 +       memset(new, 0, sizeof(struct vx_info));
16194 +#ifdef CONFIG_SMP
16195 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16196 +       if (!new->ptr_pc)
16197 +               goto error;
16198 +#endif
16199 +       new->vx_id = xid;
16200 +       INIT_HLIST_NODE(&new->vx_hlist);
16201 +       atomic_set(&new->vx_usecnt, 0);
16202 +       atomic_set(&new->vx_tasks, 0);
16203 +       new->vx_parent = NULL;
16204 +       new->vx_state = 0;
16205 +       init_waitqueue_head(&new->vx_wait);
16206 +
16207 +       /* prepare reaper */
16208 +       get_task_struct(init_pid_ns.child_reaper);
16209 +       new->vx_reaper = init_pid_ns.child_reaper;
16210 +       new->vx_badness_bias = 0;
16211 +
16212 +       /* rest of init goes here */
16213 +       vx_info_init_limit(&new->limit);
16214 +       vx_info_init_sched(&new->sched);
16215 +       vx_info_init_cvirt(&new->cvirt);
16216 +       vx_info_init_cacct(&new->cacct);
16217 +
16218 +       /* per cpu data structures */
16219 +       for_each_possible_cpu(cpu) {
16220 +               vx_info_init_sched_pc(
16221 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16222 +               vx_info_init_cvirt_pc(
16223 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16224 +       }
16225 +
16226 +       new->vx_flags = VXF_INIT_SET;
16227 +       cap_set_init_eff(new->vx_bcaps);
16228 +       new->vx_ccaps = 0;
16229 +       new->vx_umask = 0;
16230 +
16231 +       new->reboot_cmd = 0;
16232 +       new->exit_code = 0;
16233 +
16234 +       // preconfig spaces
16235 +       for (index = 0; index < VX_SPACES; index++) {
16236 +               struct _vx_space *space = &new->space[index];
16237 +
16238 +               // filesystem
16239 +               spin_lock(&init_fs.lock);
16240 +               init_fs.users++;
16241 +               spin_unlock(&init_fs.lock);
16242 +               space->vx_fs = &init_fs;
16243 +
16244 +               /* FIXME: do we want defaults? */
16245 +               // space->vx_real_cred = 0;
16246 +               // space->vx_cred = 0;
16247 +       }
16248 +
16249 +
16250 +       vxdprintk(VXD_CBIT(xid, 0),
16251 +               "alloc_vx_info(%d) = %p", xid, new);
16252 +       vxh_alloc_vx_info(new);
16253 +       atomic_inc(&vx_global_ctotal);
16254 +       return new;
16255 +#ifdef CONFIG_SMP
16256 +error:
16257 +       kfree(new);
16258 +       return 0;
16259 +#endif
16260 +}
16261 +
16262 +/*     __dealloc_vx_info()
16263 +
16264 +       * final disposal of vx_info                             */
16265 +
16266 +static void __dealloc_vx_info(struct vx_info *vxi)
16267 +{
16268 +#ifdef CONFIG_VSERVER_WARN
16269 +       struct vx_info_save vxis;
16270 +       int cpu;
16271 +#endif
16272 +       vxdprintk(VXD_CBIT(xid, 0),
16273 +               "dealloc_vx_info(%p)", vxi);
16274 +       vxh_dealloc_vx_info(vxi);
16275 +
16276 +#ifdef CONFIG_VSERVER_WARN
16277 +       enter_vx_info(vxi, &vxis);
16278 +       vx_info_exit_limit(&vxi->limit);
16279 +       vx_info_exit_sched(&vxi->sched);
16280 +       vx_info_exit_cvirt(&vxi->cvirt);
16281 +       vx_info_exit_cacct(&vxi->cacct);
16282 +
16283 +       for_each_possible_cpu(cpu) {
16284 +               vx_info_exit_sched_pc(
16285 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16286 +               vx_info_exit_cvirt_pc(
16287 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16288 +       }
16289 +       leave_vx_info(&vxis);
16290 +#endif
16291 +
16292 +       vxi->vx_id = -1;
16293 +       vxi->vx_state |= VXS_RELEASED;
16294 +
16295 +#ifdef CONFIG_SMP
16296 +       free_percpu(vxi->ptr_pc);
16297 +#endif
16298 +       kfree(vxi);
16299 +       atomic_dec(&vx_global_ctotal);
16300 +}
16301 +
16302 +static void __shutdown_vx_info(struct vx_info *vxi)
16303 +{
16304 +       struct nsproxy *nsproxy;
16305 +       struct fs_struct *fs;
16306 +       struct cred *cred;
16307 +       int index, kill;
16308 +
16309 +       might_sleep();
16310 +
16311 +       vxi->vx_state |= VXS_SHUTDOWN;
16312 +       vs_state_change(vxi, VSC_SHUTDOWN);
16313 +
16314 +       for (index = 0; index < VX_SPACES; index++) {
16315 +               struct _vx_space *space = &vxi->space[index];
16316 +
16317 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16318 +               if (nsproxy)
16319 +                       put_nsproxy(nsproxy);
16320 +
16321 +               fs = xchg(&space->vx_fs, NULL);
16322 +               spin_lock(&fs->lock);
16323 +               kill = !--fs->users;
16324 +               spin_unlock(&fs->lock);
16325 +               if (kill)
16326 +                       free_fs_struct(fs);
16327 +#if 0
16328 +               cred = xchg(&space->vx_real_cred, NULL);
16329 +               if (cred) {
16330 +                       alter_cred_subscribers(cred, -1);
16331 +                       put_cred(cred);
16332 +               }
16333 +
16334 +#endif
16335 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16336 +               if (cred)
16337 +                       abort_creds(cred);
16338 +       }
16339 +}
16340 +
16341 +/* exported stuff */
16342 +
16343 +void free_vx_info(struct vx_info *vxi)
16344 +{
16345 +       unsigned long flags;
16346 +       unsigned index;
16347 +
16348 +       /* check for reference counts first */
16349 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16350 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16351 +
16352 +       /* context must not be hashed */
16353 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16354 +
16355 +       /* context shutdown is mandatory */
16356 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16357 +
16358 +       /* spaces check */
16359 +       for (index = 0; index < VX_SPACES; index++) {
16360 +               struct _vx_space *space = &vxi->space[index];
16361 +
16362 +               BUG_ON(space->vx_nsproxy);
16363 +               BUG_ON(space->vx_fs);
16364 +               // BUG_ON(space->vx_real_cred);
16365 +               // BUG_ON(space->vx_cred);
16366 +       }
16367 +
16368 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16369 +       hlist_del(&vxi->vx_hlist);
16370 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16371 +
16372 +       __dealloc_vx_info(vxi);
16373 +}
16374 +
16375 +
16376 +/*     hash table for vx_info hash */
16377 +
16378 +#define VX_HASH_SIZE   13
16379 +
16380 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16381 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16382 +
16383 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
16384 +
16385 +
16386 +static inline unsigned int __hashval(xid_t xid)
16387 +{
16388 +       return (xid % VX_HASH_SIZE);
16389 +}
16390 +
16391 +
16392 +
16393 +/*     __hash_vx_info()
16394 +
16395 +       * add the vxi to the global hash table
16396 +       * requires the hash_lock to be held                     */
16397 +
16398 +static inline void __hash_vx_info(struct vx_info *vxi)
16399 +{
16400 +       struct hlist_head *head;
16401 +
16402 +       vxd_assert_lock(&vx_info_hash_lock);
16403 +       vxdprintk(VXD_CBIT(xid, 4),
16404 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16405 +       vxh_hash_vx_info(vxi);
16406 +
16407 +       /* context must not be hashed */
16408 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16409 +
16410 +       vxi->vx_state |= VXS_HASHED;
16411 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16412 +       hlist_add_head(&vxi->vx_hlist, head);
16413 +       atomic_inc(&vx_global_cactive);
16414 +}
16415 +
16416 +/*     __unhash_vx_info()
16417 +
16418 +       * remove the vxi from the global hash table
16419 +       * requires the hash_lock to be held                     */
16420 +
16421 +static inline void __unhash_vx_info(struct vx_info *vxi)
16422 +{
16423 +       unsigned long flags;
16424 +
16425 +       vxd_assert_lock(&vx_info_hash_lock);
16426 +       vxdprintk(VXD_CBIT(xid, 4),
16427 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16428 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16429 +       vxh_unhash_vx_info(vxi);
16430 +
16431 +       /* context must be hashed */
16432 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16433 +       /* but without tasks */
16434 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16435 +
16436 +       vxi->vx_state &= ~VXS_HASHED;
16437 +       hlist_del_init(&vxi->vx_hlist);
16438 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16439 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16440 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16441 +       atomic_dec(&vx_global_cactive);
16442 +}
16443 +
16444 +
16445 +/*     __lookup_vx_info()
16446 +
16447 +       * requires the hash_lock to be held
16448 +       * doesn't increment the vx_refcnt                       */
16449 +
16450 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16451 +{
16452 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16453 +       struct hlist_node *pos;
16454 +       struct vx_info *vxi;
16455 +
16456 +       vxd_assert_lock(&vx_info_hash_lock);
16457 +       hlist_for_each(pos, head) {
16458 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16459 +
16460 +               if (vxi->vx_id == xid)
16461 +                       goto found;
16462 +       }
16463 +       vxi = NULL;
16464 +found:
16465 +       vxdprintk(VXD_CBIT(xid, 0),
16466 +               "__lookup_vx_info(#%u): %p[#%u]",
16467 +               xid, vxi, vxi ? vxi->vx_id : 0);
16468 +       vxh_lookup_vx_info(vxi, xid);
16469 +       return vxi;
16470 +}
16471 +
16472 +
16473 +/*     __create_vx_info()
16474 +
16475 +       * create the requested context
16476 +       * get(), claim() and hash it                            */
16477 +
16478 +static struct vx_info *__create_vx_info(int id)
16479 +{
16480 +       struct vx_info *new, *vxi = NULL;
16481 +
16482 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16483 +
16484 +       if (!(new = __alloc_vx_info(id)))
16485 +               return ERR_PTR(-ENOMEM);
16486 +
16487 +       /* required to make dynamic xids unique */
16488 +       spin_lock(&vx_info_hash_lock);
16489 +
16490 +       /* static context requested */
16491 +       if ((vxi = __lookup_vx_info(id))) {
16492 +               vxdprintk(VXD_CBIT(xid, 0),
16493 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16494 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16495 +                       vxi = ERR_PTR(-EBUSY);
16496 +               else
16497 +                       vxi = ERR_PTR(-EEXIST);
16498 +               goto out_unlock;
16499 +       }
16500 +       /* new context */
16501 +       vxdprintk(VXD_CBIT(xid, 0),
16502 +               "create_vx_info(%d) = %p (new)", id, new);
16503 +       claim_vx_info(new, NULL);
16504 +       __hash_vx_info(get_vx_info(new));
16505 +       vxi = new, new = NULL;
16506 +
16507 +out_unlock:
16508 +       spin_unlock(&vx_info_hash_lock);
16509 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16510 +       if (new)
16511 +               __dealloc_vx_info(new);
16512 +       return vxi;
16513 +}
16514 +
16515 +
16516 +/*     exported stuff                                          */
16517 +
16518 +
16519 +void unhash_vx_info(struct vx_info *vxi)
16520 +{
16521 +       __shutdown_vx_info(vxi);
16522 +       spin_lock(&vx_info_hash_lock);
16523 +       __unhash_vx_info(vxi);
16524 +       spin_unlock(&vx_info_hash_lock);
16525 +       __wakeup_vx_info(vxi);
16526 +}
16527 +
16528 +
16529 +/*     lookup_vx_info()
16530 +
16531 +       * search for a vx_info and get() it
16532 +       * negative id means current                             */
16533 +
16534 +struct vx_info *lookup_vx_info(int id)
16535 +{
16536 +       struct vx_info *vxi = NULL;
16537 +
16538 +       if (id < 0) {
16539 +               vxi = get_vx_info(current_vx_info());
16540 +       } else if (id > 1) {
16541 +               spin_lock(&vx_info_hash_lock);
16542 +               vxi = get_vx_info(__lookup_vx_info(id));
16543 +               spin_unlock(&vx_info_hash_lock);
16544 +       }
16545 +       return vxi;
16546 +}
16547 +
16548 +/*     xid_is_hashed()
16549 +
16550 +       * verify that xid is still hashed                       */
16551 +
16552 +int xid_is_hashed(xid_t xid)
16553 +{
16554 +       int hashed;
16555 +
16556 +       spin_lock(&vx_info_hash_lock);
16557 +       hashed = (__lookup_vx_info(xid) != NULL);
16558 +       spin_unlock(&vx_info_hash_lock);
16559 +       return hashed;
16560 +}
16561 +
16562 +#ifdef CONFIG_PROC_FS
16563 +
16564 +/*     get_xid_list()
16565 +
16566 +       * get a subset of hashed xids for proc
16567 +       * assumes size is at least one                          */
16568 +
16569 +int get_xid_list(int index, unsigned int *xids, int size)
16570 +{
16571 +       int hindex, nr_xids = 0;
16572 +
16573 +       /* only show current and children */
16574 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16575 +               if (index > 0)
16576 +                       return 0;
16577 +               xids[nr_xids] = vx_current_xid();
16578 +               return 1;
16579 +       }
16580 +
16581 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16582 +               struct hlist_head *head = &vx_info_hash[hindex];
16583 +               struct hlist_node *pos;
16584 +
16585 +               spin_lock(&vx_info_hash_lock);
16586 +               hlist_for_each(pos, head) {
16587 +                       struct vx_info *vxi;
16588 +
16589 +                       if (--index > 0)
16590 +                               continue;
16591 +
16592 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16593 +                       xids[nr_xids] = vxi->vx_id;
16594 +                       if (++nr_xids >= size) {
16595 +                               spin_unlock(&vx_info_hash_lock);
16596 +                               goto out;
16597 +                       }
16598 +               }
16599 +               /* keep the lock time short */
16600 +               spin_unlock(&vx_info_hash_lock);
16601 +       }
16602 +out:
16603 +       return nr_xids;
16604 +}
16605 +#endif
16606 +
16607 +#ifdef CONFIG_VSERVER_DEBUG
16608 +
16609 +void   dump_vx_info_inactive(int level)
16610 +{
16611 +       struct hlist_node *entry, *next;
16612 +
16613 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16614 +               struct vx_info *vxi =
16615 +                       list_entry(entry, struct vx_info, vx_hlist);
16616 +
16617 +               dump_vx_info(vxi, level);
16618 +       }
16619 +}
16620 +
16621 +#endif
16622 +
16623 +#if 0
16624 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16625 +{
16626 +       struct user_struct *new_user, *old_user;
16627 +
16628 +       if (!p || !vxi)
16629 +               BUG();
16630 +
16631 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16632 +               return -EACCES;
16633 +
16634 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16635 +       if (!new_user)
16636 +               return -ENOMEM;
16637 +
16638 +       old_user = p->user;
16639 +       if (new_user != old_user) {
16640 +               atomic_inc(&new_user->processes);
16641 +               atomic_dec(&old_user->processes);
16642 +               p->user = new_user;
16643 +       }
16644 +       free_uid(old_user);
16645 +       return 0;
16646 +}
16647 +#endif
16648 +
16649 +#if 0
16650 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16651 +{
16652 +       // p->cap_effective &= vxi->vx_cap_bset;
16653 +       p->cap_effective =
16654 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16655 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16656 +       p->cap_inheritable =
16657 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16658 +       // p->cap_permitted &= vxi->vx_cap_bset;
16659 +       p->cap_permitted =
16660 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16661 +}
16662 +#endif
16663 +
16664 +
16665 +#include <linux/file.h>
16666 +#include <linux/fdtable.h>
16667 +
16668 +static int vx_openfd_task(struct task_struct *tsk)
16669 +{
16670 +       struct files_struct *files = tsk->files;
16671 +       struct fdtable *fdt;
16672 +       const unsigned long *bptr;
16673 +       int count, total;
16674 +
16675 +       /* no rcu_read_lock() because of spin_lock() */
16676 +       spin_lock(&files->file_lock);
16677 +       fdt = files_fdtable(files);
16678 +       bptr = fdt->open_fds->fds_bits;
16679 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16680 +       for (total = 0; count > 0; count--) {
16681 +               if (*bptr)
16682 +                       total += hweight_long(*bptr);
16683 +               bptr++;
16684 +       }
16685 +       spin_unlock(&files->file_lock);
16686 +       return total;
16687 +}
16688 +
16689 +
16690 +/*     for *space compatibility */
16691 +
16692 +asmlinkage long sys_unshare(unsigned long);
16693 +
16694 +/*
16695 + *     migrate task to new context
16696 + *     gets vxi, puts old_vxi on change
16697 + *     optionally unshares namespaces (hack)
16698 + */
16699 +
16700 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16701 +{
16702 +       struct vx_info *old_vxi;
16703 +       int ret = 0;
16704 +
16705 +       if (!p || !vxi)
16706 +               BUG();
16707 +
16708 +       vxdprintk(VXD_CBIT(xid, 5),
16709 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16710 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16711 +
16712 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16713 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16714 +               return -EACCES;
16715 +
16716 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16717 +               return -EFAULT;
16718 +
16719 +       old_vxi = task_get_vx_info(p);
16720 +       if (old_vxi == vxi)
16721 +               goto out;
16722 +
16723 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16724 +       {
16725 +               int openfd;
16726 +
16727 +               task_lock(p);
16728 +               openfd = vx_openfd_task(p);
16729 +
16730 +               if (old_vxi) {
16731 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16732 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16733 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16734 +                       /* FIXME: what about the struct files here? */
16735 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16736 +                       /* account for the executable */
16737 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16738 +               }
16739 +               atomic_inc(&vxi->cvirt.nr_threads);
16740 +               atomic_inc(&vxi->cvirt.nr_running);
16741 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16742 +               /* FIXME: what about the struct files here? */
16743 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16744 +               /* account for the executable */
16745 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16746 +
16747 +               if (old_vxi) {
16748 +                       release_vx_info(old_vxi, p);
16749 +                       clr_vx_info(&p->vx_info);
16750 +               }
16751 +               claim_vx_info(vxi, p);
16752 +               set_vx_info(&p->vx_info, vxi);
16753 +               p->xid = vxi->vx_id;
16754 +
16755 +               vxdprintk(VXD_CBIT(xid, 5),
16756 +                       "moved task %p into vxi:%p[#%d]",
16757 +                       p, vxi, vxi->vx_id);
16758 +
16759 +               // vx_mask_cap_bset(vxi, p);
16760 +               task_unlock(p);
16761 +
16762 +               /* hack for *spaces to provide compatibility */
16763 +               if (unshare) {
16764 +                       struct nsproxy *old_nsp, *new_nsp;
16765 +
16766 +                       ret = unshare_nsproxy_namespaces(
16767 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16768 +                               &new_nsp, NULL);
16769 +                       if (ret)
16770 +                               goto out;
16771 +
16772 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16773 +                       vx_set_space(vxi,
16774 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16775 +                       put_nsproxy(old_nsp);
16776 +               }
16777 +       }
16778 +out:
16779 +       put_vx_info(old_vxi);
16780 +       return ret;
16781 +}
16782 +
16783 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16784 +{
16785 +       struct task_struct *old_reaper;
16786 +
16787 +       if (!vxi)
16788 +               return -EINVAL;
16789 +
16790 +       vxdprintk(VXD_CBIT(xid, 6),
16791 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16792 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16793 +
16794 +       old_reaper = vxi->vx_reaper;
16795 +       if (old_reaper == p)
16796 +               return 0;
16797 +
16798 +       /* set new child reaper */
16799 +       get_task_struct(p);
16800 +       vxi->vx_reaper = p;
16801 +       put_task_struct(old_reaper);
16802 +       return 0;
16803 +}
16804 +
16805 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16806 +{
16807 +       if (!vxi)
16808 +               return -EINVAL;
16809 +
16810 +       vxdprintk(VXD_CBIT(xid, 6),
16811 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16812 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16813 +
16814 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16815 +       // vxi->vx_initpid = p->tgid;
16816 +       vxi->vx_initpid = p->pid;
16817 +       return 0;
16818 +}
16819 +
16820 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16821 +{
16822 +       vxdprintk(VXD_CBIT(xid, 6),
16823 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16824 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16825 +
16826 +       vxi->exit_code = code;
16827 +       vxi->vx_initpid = 0;
16828 +}
16829 +
16830 +
16831 +void vx_set_persistent(struct vx_info *vxi)
16832 +{
16833 +       vxdprintk(VXD_CBIT(xid, 6),
16834 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16835 +
16836 +       get_vx_info(vxi);
16837 +       claim_vx_info(vxi, NULL);
16838 +}
16839 +
16840 +void vx_clear_persistent(struct vx_info *vxi)
16841 +{
16842 +       vxdprintk(VXD_CBIT(xid, 6),
16843 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16844 +
16845 +       release_vx_info(vxi, NULL);
16846 +       put_vx_info(vxi);
16847 +}
16848 +
16849 +void vx_update_persistent(struct vx_info *vxi)
16850 +{
16851 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16852 +               vx_set_persistent(vxi);
16853 +       else
16854 +               vx_clear_persistent(vxi);
16855 +}
16856 +
16857 +
16858 +/*     task must be current or locked          */
16859 +
16860 +void   exit_vx_info(struct task_struct *p, int code)
16861 +{
16862 +       struct vx_info *vxi = p->vx_info;
16863 +
16864 +       if (vxi) {
16865 +               atomic_dec(&vxi->cvirt.nr_threads);
16866 +               vx_nproc_dec(p);
16867 +
16868 +               vxi->exit_code = code;
16869 +               release_vx_info(vxi, p);
16870 +       }
16871 +}
16872 +
16873 +void   exit_vx_info_early(struct task_struct *p, int code)
16874 +{
16875 +       struct vx_info *vxi = p->vx_info;
16876 +
16877 +       if (vxi) {
16878 +               if (vxi->vx_initpid == p->pid)
16879 +                       vx_exit_init(vxi, p, code);
16880 +               if (vxi->vx_reaper == p)
16881 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16882 +       }
16883 +}
16884 +
16885 +
16886 +/* vserver syscall commands below here */
16887 +
16888 +/* taks xid and vx_info functions */
16889 +
16890 +#include <asm/uaccess.h>
16891 +
16892 +
16893 +int vc_task_xid(uint32_t id)
16894 +{
16895 +       xid_t xid;
16896 +
16897 +       if (id) {
16898 +               struct task_struct *tsk;
16899 +
16900 +               read_lock(&tasklist_lock);
16901 +               tsk = find_task_by_real_pid(id);
16902 +               xid = (tsk) ? tsk->xid : -ESRCH;
16903 +               read_unlock(&tasklist_lock);
16904 +       } else
16905 +               xid = vx_current_xid();
16906 +       return xid;
16907 +}
16908 +
16909 +
16910 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16911 +{
16912 +       struct vcmd_vx_info_v0 vc_data;
16913 +
16914 +       vc_data.xid = vxi->vx_id;
16915 +       vc_data.initpid = vxi->vx_initpid;
16916 +
16917 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16918 +               return -EFAULT;
16919 +       return 0;
16920 +}
16921 +
16922 +
16923 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16924 +{
16925 +       struct vcmd_ctx_stat_v0 vc_data;
16926 +
16927 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16928 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16929 +
16930 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16931 +               return -EFAULT;
16932 +       return 0;
16933 +}
16934 +
16935 +
16936 +/* context functions */
16937 +
16938 +int vc_ctx_create(uint32_t xid, void __user *data)
16939 +{
16940 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16941 +       struct vx_info *new_vxi;
16942 +       int ret;
16943 +
16944 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16945 +               return -EFAULT;
16946 +
16947 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16948 +               return -EINVAL;
16949 +
16950 +       new_vxi = __create_vx_info(xid);
16951 +       if (IS_ERR(new_vxi))
16952 +               return PTR_ERR(new_vxi);
16953 +
16954 +       /* initial flags */
16955 +       new_vxi->vx_flags = vc_data.flagword;
16956 +
16957 +       ret = -ENOEXEC;
16958 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16959 +               goto out;
16960 +
16961 +       ret = vx_migrate_task(current, new_vxi, (!data));
16962 +       if (ret)
16963 +               goto out;
16964 +
16965 +       /* return context id on success */
16966 +       ret = new_vxi->vx_id;
16967 +
16968 +       /* get a reference for persistent contexts */
16969 +       if ((vc_data.flagword & VXF_PERSISTENT))
16970 +               vx_set_persistent(new_vxi);
16971 +out:
16972 +       release_vx_info(new_vxi, NULL);
16973 +       put_vx_info(new_vxi);
16974 +       return ret;
16975 +}
16976 +
16977 +
16978 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16979 +{
16980 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16981 +       int ret;
16982 +
16983 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16984 +               return -EFAULT;
16985 +
16986 +       ret = vx_migrate_task(current, vxi, 0);
16987 +       if (ret)
16988 +               return ret;
16989 +       if (vc_data.flagword & VXM_SET_INIT)
16990 +               ret = vx_set_init(vxi, current);
16991 +       if (ret)
16992 +               return ret;
16993 +       if (vc_data.flagword & VXM_SET_REAPER)
16994 +               ret = vx_set_reaper(vxi, current);
16995 +       return ret;
16996 +}
16997 +
16998 +
16999 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17000 +{
17001 +       struct vcmd_ctx_flags_v0 vc_data;
17002 +
17003 +       vc_data.flagword = vxi->vx_flags;
17004 +
17005 +       /* special STATE flag handling */
17006 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17007 +
17008 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17009 +               return -EFAULT;
17010 +       return 0;
17011 +}
17012 +
17013 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17014 +{
17015 +       struct vcmd_ctx_flags_v0 vc_data;
17016 +       uint64_t mask, trigger;
17017 +
17018 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17019 +               return -EFAULT;
17020 +
17021 +       /* special STATE flag handling */
17022 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17023 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17024 +
17025 +       if (vxi == current_vx_info()) {
17026 +               /* if (trigger & VXF_STATE_SETUP)
17027 +                       vx_mask_cap_bset(vxi, current); */
17028 +               if (trigger & VXF_STATE_INIT) {
17029 +                       int ret;
17030 +
17031 +                       ret = vx_set_init(vxi, current);
17032 +                       if (ret)
17033 +                               return ret;
17034 +                       ret = vx_set_reaper(vxi, current);
17035 +                       if (ret)
17036 +                               return ret;
17037 +               }
17038 +       }
17039 +
17040 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17041 +               vc_data.flagword, mask);
17042 +       if (trigger & VXF_PERSISTENT)
17043 +               vx_update_persistent(vxi);
17044 +
17045 +       return 0;
17046 +}
17047 +
17048 +
17049 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17050 +{
17051 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17052 +
17053 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17054 +       return v;
17055 +}
17056 +
17057 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17058 +{
17059 +       kernel_cap_t c = __cap_empty_set;
17060 +
17061 +       c.cap[0] = v & 0xFFFFFFFF;
17062 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17063 +
17064 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17065 +       return c;
17066 +}
17067 +
17068 +
17069 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17070 +{
17071 +       if (bcaps)
17072 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17073 +       if (ccaps)
17074 +               *ccaps = vxi->vx_ccaps;
17075 +
17076 +       return 0;
17077 +}
17078 +
17079 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17080 +{
17081 +       struct vcmd_ctx_caps_v1 vc_data;
17082 +       int ret;
17083 +
17084 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17085 +       if (ret)
17086 +               return ret;
17087 +       vc_data.cmask = ~0ULL;
17088 +
17089 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17090 +               return -EFAULT;
17091 +       return 0;
17092 +}
17093 +
17094 +static int do_set_caps(struct vx_info *vxi,
17095 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17096 +{
17097 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17098 +
17099 +#if 0
17100 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17101 +               bcaps, bmask, ccaps, cmask);
17102 +#endif
17103 +       vxi->vx_bcaps = cap_t_from_caps(
17104 +               vs_mask_flags(bcold, bcaps, bmask));
17105 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17106 +
17107 +       return 0;
17108 +}
17109 +
17110 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17111 +{
17112 +       struct vcmd_ctx_caps_v1 vc_data;
17113 +
17114 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17115 +               return -EFAULT;
17116 +
17117 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17118 +}
17119 +
17120 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17121 +{
17122 +       struct vcmd_bcaps vc_data;
17123 +       int ret;
17124 +
17125 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17126 +       if (ret)
17127 +               return ret;
17128 +       vc_data.bmask = ~0ULL;
17129 +
17130 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17131 +               return -EFAULT;
17132 +       return 0;
17133 +}
17134 +
17135 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17136 +{
17137 +       struct vcmd_bcaps vc_data;
17138 +
17139 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17140 +               return -EFAULT;
17141 +
17142 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17143 +}
17144 +
17145 +
17146 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17147 +{
17148 +       struct vcmd_umask vc_data;
17149 +
17150 +       vc_data.umask = vxi->vx_umask;
17151 +       vc_data.mask = ~0ULL;
17152 +
17153 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17154 +               return -EFAULT;
17155 +       return 0;
17156 +}
17157 +
17158 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17159 +{
17160 +       struct vcmd_umask vc_data;
17161 +
17162 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17163 +               return -EFAULT;
17164 +
17165 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17166 +               vc_data.umask, vc_data.mask);
17167 +       return 0;
17168 +}
17169 +
17170 +
17171 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17172 +{
17173 +       struct vcmd_badness_v0 vc_data;
17174 +
17175 +       vc_data.bias = vxi->vx_badness_bias;
17176 +
17177 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17178 +               return -EFAULT;
17179 +       return 0;
17180 +}
17181 +
17182 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17183 +{
17184 +       struct vcmd_badness_v0 vc_data;
17185 +
17186 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17187 +               return -EFAULT;
17188 +
17189 +       vxi->vx_badness_bias = vc_data.bias;
17190 +       return 0;
17191 +}
17192 +
17193 +#include <linux/module.h>
17194 +
17195 +EXPORT_SYMBOL_GPL(free_vx_info);
17196 +
17197 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cvirt.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cvirt.c
17198 --- linux-2.6.37/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
17199 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cvirt.c  2011-01-08 03:33:34.000000000 +0100
17200 @@ -0,0 +1,303 @@
17201 +/*
17202 + *  linux/kernel/vserver/cvirt.c
17203 + *
17204 + *  Virtual Server: Context Virtualization
17205 + *
17206 + *  Copyright (C) 2004-2007  Herbert Pötzl
17207 + *
17208 + *  V0.01  broken out from limit.c
17209 + *  V0.02  added utsname stuff
17210 + *  V0.03  changed vcmds to vxi arg
17211 + *
17212 + */
17213 +
17214 +#include <linux/types.h>
17215 +#include <linux/utsname.h>
17216 +#include <linux/vs_cvirt.h>
17217 +#include <linux/vserver/switch.h>
17218 +#include <linux/vserver/cvirt_cmd.h>
17219 +
17220 +#include <asm/uaccess.h>
17221 +
17222 +
17223 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17224 +{
17225 +       struct vx_info *vxi = current_vx_info();
17226 +
17227 +       set_normalized_timespec(uptime,
17228 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17229 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17230 +       if (!idle)
17231 +               return;
17232 +       set_normalized_timespec(idle,
17233 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17234 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17235 +       return;
17236 +}
17237 +
17238 +uint64_t vx_idle_jiffies(void)
17239 +{
17240 +       return init_task.utime + init_task.stime;
17241 +}
17242 +
17243 +
17244 +
17245 +static inline uint32_t __update_loadavg(uint32_t load,
17246 +       int wsize, int delta, int n)
17247 +{
17248 +       unsigned long long calc, prev;
17249 +
17250 +       /* just set it to n */
17251 +       if (unlikely(delta >= wsize))
17252 +               return (n << FSHIFT);
17253 +
17254 +       calc = delta * n;
17255 +       calc <<= FSHIFT;
17256 +       prev = (wsize - delta);
17257 +       prev *= load;
17258 +       calc += prev;
17259 +       do_div(calc, wsize);
17260 +       return calc;
17261 +}
17262 +
17263 +
17264 +void vx_update_load(struct vx_info *vxi)
17265 +{
17266 +       uint32_t now, last, delta;
17267 +       unsigned int nr_running, nr_uninterruptible;
17268 +       unsigned int total;
17269 +       unsigned long flags;
17270 +
17271 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17272 +
17273 +       now = jiffies;
17274 +       last = vxi->cvirt.load_last;
17275 +       delta = now - last;
17276 +
17277 +       if (delta < 5*HZ)
17278 +               goto out;
17279 +
17280 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17281 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17282 +       total = nr_running + nr_uninterruptible;
17283 +
17284 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17285 +               60*HZ, delta, total);
17286 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17287 +               5*60*HZ, delta, total);
17288 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17289 +               15*60*HZ, delta, total);
17290 +
17291 +       vxi->cvirt.load_last = now;
17292 +out:
17293 +       atomic_inc(&vxi->cvirt.load_updates);
17294 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17295 +}
17296 +
17297 +
17298 +/*
17299 + * Commands to do_syslog:
17300 + *
17301 + *      0 -- Close the log.  Currently a NOP.
17302 + *      1 -- Open the log. Currently a NOP.
17303 + *      2 -- Read from the log.
17304 + *      3 -- Read all messages remaining in the ring buffer.
17305 + *      4 -- Read and clear all messages remaining in the ring buffer
17306 + *      5 -- Clear ring buffer.
17307 + *      6 -- Disable printk's to console
17308 + *      7 -- Enable printk's to console
17309 + *      8 -- Set level of messages printed to console
17310 + *      9 -- Return number of unread characters in the log buffer
17311 + *     10 -- Return size of the log buffer
17312 + */
17313 +int vx_do_syslog(int type, char __user *buf, int len)
17314 +{
17315 +       int error = 0;
17316 +       int do_clear = 0;
17317 +       struct vx_info *vxi = current_vx_info();
17318 +       struct _vx_syslog *log;
17319 +
17320 +       if (!vxi)
17321 +               return -EINVAL;
17322 +       log = &vxi->cvirt.syslog;
17323 +
17324 +       switch (type) {
17325 +       case 0:         /* Close log */
17326 +       case 1:         /* Open log */
17327 +               break;
17328 +       case 2:         /* Read from log */
17329 +               error = wait_event_interruptible(log->log_wait,
17330 +                       (log->log_start - log->log_end));
17331 +               if (error)
17332 +                       break;
17333 +               spin_lock_irq(&log->logbuf_lock);
17334 +               spin_unlock_irq(&log->logbuf_lock);
17335 +               break;
17336 +       case 4:         /* Read/clear last kernel messages */
17337 +               do_clear = 1;
17338 +               /* fall through */
17339 +       case 3:         /* Read last kernel messages */
17340 +               return 0;
17341 +
17342 +       case 5:         /* Clear ring buffer */
17343 +               return 0;
17344 +
17345 +       case 6:         /* Disable logging to console */
17346 +       case 7:         /* Enable logging to console */
17347 +       case 8:         /* Set level of messages printed to console */
17348 +               break;
17349 +
17350 +       case 9:         /* Number of chars in the log buffer */
17351 +               return 0;
17352 +       case 10:        /* Size of the log buffer */
17353 +               return 0;
17354 +       default:
17355 +               error = -EINVAL;
17356 +               break;
17357 +       }
17358 +       return error;
17359 +}
17360 +
17361 +
17362 +/* virtual host info names */
17363 +
17364 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17365 +{
17366 +       struct nsproxy *nsproxy;
17367 +       struct uts_namespace *uts;
17368 +
17369 +       if (id == VHIN_CONTEXT)
17370 +               return vxi->vx_name;
17371 +
17372 +       nsproxy = vxi->space[0].vx_nsproxy;
17373 +       if (!nsproxy)
17374 +               return NULL;
17375 +
17376 +       uts = nsproxy->uts_ns;
17377 +       if (!uts)
17378 +               return NULL;
17379 +
17380 +       switch (id) {
17381 +       case VHIN_SYSNAME:
17382 +               return uts->name.sysname;
17383 +       case VHIN_NODENAME:
17384 +               return uts->name.nodename;
17385 +       case VHIN_RELEASE:
17386 +               return uts->name.release;
17387 +       case VHIN_VERSION:
17388 +               return uts->name.version;
17389 +       case VHIN_MACHINE:
17390 +               return uts->name.machine;
17391 +       case VHIN_DOMAINNAME:
17392 +               return uts->name.domainname;
17393 +       default:
17394 +               return NULL;
17395 +       }
17396 +       return NULL;
17397 +}
17398 +
17399 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17400 +{
17401 +       struct vcmd_vhi_name_v0 vc_data;
17402 +       char *name;
17403 +
17404 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17405 +               return -EFAULT;
17406 +
17407 +       name = vx_vhi_name(vxi, vc_data.field);
17408 +       if (!name)
17409 +               return -EINVAL;
17410 +
17411 +       memcpy(name, vc_data.name, 65);
17412 +       return 0;
17413 +}
17414 +
17415 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17416 +{
17417 +       struct vcmd_vhi_name_v0 vc_data;
17418 +       char *name;
17419 +
17420 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17421 +               return -EFAULT;
17422 +
17423 +       name = vx_vhi_name(vxi, vc_data.field);
17424 +       if (!name)
17425 +               return -EINVAL;
17426 +
17427 +       memcpy(vc_data.name, name, 65);
17428 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17429 +               return -EFAULT;
17430 +       return 0;
17431 +}
17432 +
17433 +
17434 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17435 +{
17436 +       struct vcmd_virt_stat_v0 vc_data;
17437 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17438 +       struct timespec uptime;
17439 +
17440 +       do_posix_clock_monotonic_gettime(&uptime);
17441 +       set_normalized_timespec(&uptime,
17442 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17443 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17444 +
17445 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17446 +       vc_data.uptime = timespec_to_ns(&uptime);
17447 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17448 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17449 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17450 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17451 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17452 +       vc_data.load[0] = cvirt->load[0];
17453 +       vc_data.load[1] = cvirt->load[1];
17454 +       vc_data.load[2] = cvirt->load[2];
17455 +
17456 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17457 +               return -EFAULT;
17458 +       return 0;
17459 +}
17460 +
17461 +
17462 +#ifdef CONFIG_VSERVER_VTIME
17463 +
17464 +/* virtualized time base */
17465 +
17466 +void vx_adjust_timespec(struct timespec *ts)
17467 +{
17468 +       struct vx_info *vxi;
17469 +
17470 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17471 +               return;
17472 +
17473 +       vxi = current_vx_info();
17474 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17475 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17476 +
17477 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17478 +               ts->tv_sec++;
17479 +               ts->tv_nsec -= NSEC_PER_SEC;
17480 +       } else if (ts->tv_nsec < 0) {
17481 +               ts->tv_sec--;
17482 +               ts->tv_nsec += NSEC_PER_SEC;
17483 +       }
17484 +}
17485 +
17486 +int vx_settimeofday(struct timespec *ts)
17487 +{
17488 +       struct timespec ats, delta;
17489 +       struct vx_info *vxi;
17490 +
17491 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17492 +               return do_settimeofday(ts);
17493 +
17494 +       getnstimeofday(&ats);
17495 +       delta = timespec_sub(*ts, ats);
17496 +
17497 +       vxi = current_vx_info();
17498 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17499 +       return 0;
17500 +}
17501 +
17502 +#endif
17503 +
17504 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cvirt_init.h linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cvirt_init.h
17505 --- linux-2.6.37/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
17506 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cvirt_init.h     2010-11-23 02:09:41.000000000 +0100
17507 @@ -0,0 +1,69 @@
17508 +
17509 +
17510 +extern uint64_t vx_idle_jiffies(void);
17511 +
17512 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17513 +{
17514 +       uint64_t idle_jiffies = vx_idle_jiffies();
17515 +       uint64_t nsuptime;
17516 +
17517 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17518 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17519 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17520 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17521 +       cvirt->bias_ts.tv_sec = 0;
17522 +       cvirt->bias_ts.tv_nsec = 0;
17523 +
17524 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17525 +       atomic_set(&cvirt->nr_threads, 0);
17526 +       atomic_set(&cvirt->nr_running, 0);
17527 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17528 +       atomic_set(&cvirt->nr_onhold, 0);
17529 +
17530 +       spin_lock_init(&cvirt->load_lock);
17531 +       cvirt->load_last = jiffies;
17532 +       atomic_set(&cvirt->load_updates, 0);
17533 +       cvirt->load[0] = 0;
17534 +       cvirt->load[1] = 0;
17535 +       cvirt->load[2] = 0;
17536 +       atomic_set(&cvirt->total_forks, 0);
17537 +
17538 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17539 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17540 +       cvirt->syslog.log_start = 0;
17541 +       cvirt->syslog.log_end = 0;
17542 +       cvirt->syslog.con_start = 0;
17543 +       cvirt->syslog.logged_chars = 0;
17544 +}
17545 +
17546 +static inline
17547 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17548 +{
17549 +       // cvirt_pc->cpustat = { 0 };
17550 +}
17551 +
17552 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17553 +{
17554 +       int value;
17555 +
17556 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17557 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17558 +               cvirt, value);
17559 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17560 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17561 +               cvirt, value);
17562 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17563 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17564 +               cvirt, value);
17565 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17566 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17567 +               cvirt, value);
17568 +       return;
17569 +}
17570 +
17571 +static inline
17572 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17573 +{
17574 +       return;
17575 +}
17576 +
17577 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cvirt_proc.h linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cvirt_proc.h
17578 --- linux-2.6.37/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
17579 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/cvirt_proc.h     2010-11-23 02:09:41.000000000 +0100
17580 @@ -0,0 +1,135 @@
17581 +#ifndef _VX_CVIRT_PROC_H
17582 +#define _VX_CVIRT_PROC_H
17583 +
17584 +#include <linux/nsproxy.h>
17585 +#include <linux/mnt_namespace.h>
17586 +#include <linux/ipc_namespace.h>
17587 +#include <linux/utsname.h>
17588 +#include <linux/ipc.h>
17589 +
17590 +
17591 +static inline
17592 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17593 +{
17594 +       struct mnt_namespace *ns;
17595 +       struct uts_namespace *uts;
17596 +       struct ipc_namespace *ipc;
17597 +       struct path path;
17598 +       char *pstr, *root;
17599 +       int length = 0;
17600 +
17601 +       if (!nsproxy)
17602 +               goto out;
17603 +
17604 +       length += sprintf(buffer + length,
17605 +               "NSProxy:\t%p [%p,%p,%p]\n",
17606 +               nsproxy, nsproxy->mnt_ns,
17607 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17608 +
17609 +       ns = nsproxy->mnt_ns;
17610 +       if (!ns)
17611 +               goto skip_ns;
17612 +
17613 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17614 +       if (!pstr)
17615 +               goto skip_ns;
17616 +
17617 +       path.mnt = ns->root;
17618 +       path.dentry = ns->root->mnt_root;
17619 +       root = d_path(&path, pstr, PATH_MAX - 2);
17620 +       length += sprintf(buffer + length,
17621 +               "Namespace:\t%p [#%u]\n"
17622 +               "RootPath:\t%s\n",
17623 +               ns, atomic_read(&ns->count),
17624 +               root);
17625 +       kfree(pstr);
17626 +skip_ns:
17627 +
17628 +       uts = nsproxy->uts_ns;
17629 +       if (!uts)
17630 +               goto skip_uts;
17631 +
17632 +       length += sprintf(buffer + length,
17633 +               "SysName:\t%.*s\n"
17634 +               "NodeName:\t%.*s\n"
17635 +               "Release:\t%.*s\n"
17636 +               "Version:\t%.*s\n"
17637 +               "Machine:\t%.*s\n"
17638 +               "DomainName:\t%.*s\n",
17639 +               __NEW_UTS_LEN, uts->name.sysname,
17640 +               __NEW_UTS_LEN, uts->name.nodename,
17641 +               __NEW_UTS_LEN, uts->name.release,
17642 +               __NEW_UTS_LEN, uts->name.version,
17643 +               __NEW_UTS_LEN, uts->name.machine,
17644 +               __NEW_UTS_LEN, uts->name.domainname);
17645 +skip_uts:
17646 +
17647 +       ipc = nsproxy->ipc_ns;
17648 +       if (!ipc)
17649 +               goto skip_ipc;
17650 +
17651 +       length += sprintf(buffer + length,
17652 +               "SEMS:\t\t%d %d %d %d  %d\n"
17653 +               "MSG:\t\t%d %d %d\n"
17654 +               "SHM:\t\t%lu %lu  %d %d\n",
17655 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17656 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17657 +               ipc->used_sems,
17658 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17659 +               (unsigned long)ipc->shm_ctlmax,
17660 +               (unsigned long)ipc->shm_ctlall,
17661 +               ipc->shm_ctlmni, ipc->shm_tot);
17662 +skip_ipc:
17663 +out:
17664 +       return length;
17665 +}
17666 +
17667 +
17668 +#include <linux/sched.h>
17669 +
17670 +#define LOAD_INT(x) ((x) >> FSHIFT)
17671 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17672 +
17673 +static inline
17674 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17675 +{
17676 +       int length = 0;
17677 +       int a, b, c;
17678 +
17679 +       length += sprintf(buffer + length,
17680 +               "BiasUptime:\t%lu.%02lu\n",
17681 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17682 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17683 +
17684 +       a = cvirt->load[0] + (FIXED_1 / 200);
17685 +       b = cvirt->load[1] + (FIXED_1 / 200);
17686 +       c = cvirt->load[2] + (FIXED_1 / 200);
17687 +       length += sprintf(buffer + length,
17688 +               "nr_threads:\t%d\n"
17689 +               "nr_running:\t%d\n"
17690 +               "nr_unintr:\t%d\n"
17691 +               "nr_onhold:\t%d\n"
17692 +               "load_updates:\t%d\n"
17693 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17694 +               "total_forks:\t%d\n",
17695 +               atomic_read(&cvirt->nr_threads),
17696 +               atomic_read(&cvirt->nr_running),
17697 +               atomic_read(&cvirt->nr_uninterruptible),
17698 +               atomic_read(&cvirt->nr_onhold),
17699 +               atomic_read(&cvirt->load_updates),
17700 +               LOAD_INT(a), LOAD_FRAC(a),
17701 +               LOAD_INT(b), LOAD_FRAC(b),
17702 +               LOAD_INT(c), LOAD_FRAC(c),
17703 +               atomic_read(&cvirt->total_forks));
17704 +       return length;
17705 +}
17706 +
17707 +static inline
17708 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17709 +       char *buffer, int cpu)
17710 +{
17711 +       int length = 0;
17712 +       return length;
17713 +}
17714 +
17715 +#endif /* _VX_CVIRT_PROC_H */
17716 diff -NurpP --minimal linux-2.6.37/kernel/vserver/debug.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/debug.c
17717 --- linux-2.6.37/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
17718 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/debug.c  2010-11-23 02:09:41.000000000 +0100
17719 @@ -0,0 +1,32 @@
17720 +/*
17721 + *  kernel/vserver/debug.c
17722 + *
17723 + *  Copyright (C) 2005-2007 Herbert Pötzl
17724 + *
17725 + *  V0.01  vx_info dump support
17726 + *
17727 + */
17728 +
17729 +#include <linux/module.h>
17730 +
17731 +#include <linux/vserver/context.h>
17732 +
17733 +
17734 +void   dump_vx_info(struct vx_info *vxi, int level)
17735 +{
17736 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17737 +               atomic_read(&vxi->vx_usecnt),
17738 +               atomic_read(&vxi->vx_tasks),
17739 +               vxi->vx_state);
17740 +       if (level > 0) {
17741 +               __dump_vx_limit(&vxi->limit);
17742 +               __dump_vx_sched(&vxi->sched);
17743 +               __dump_vx_cvirt(&vxi->cvirt);
17744 +               __dump_vx_cacct(&vxi->cacct);
17745 +       }
17746 +       printk("---\n");
17747 +}
17748 +
17749 +
17750 +EXPORT_SYMBOL_GPL(dump_vx_info);
17751 +
17752 diff -NurpP --minimal linux-2.6.37/kernel/vserver/device.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/device.c
17753 --- linux-2.6.37/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
17754 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/device.c 2010-11-23 02:09:41.000000000 +0100
17755 @@ -0,0 +1,443 @@
17756 +/*
17757 + *  linux/kernel/vserver/device.c
17758 + *
17759 + *  Linux-VServer: Device Support
17760 + *
17761 + *  Copyright (C) 2006  Herbert Pötzl
17762 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17763 + *
17764 + *  V0.01  device mapping basics
17765 + *  V0.02  added defaults
17766 + *
17767 + */
17768 +
17769 +#include <linux/slab.h>
17770 +#include <linux/rcupdate.h>
17771 +#include <linux/fs.h>
17772 +#include <linux/namei.h>
17773 +#include <linux/hash.h>
17774 +
17775 +#include <asm/errno.h>
17776 +#include <asm/uaccess.h>
17777 +#include <linux/vserver/base.h>
17778 +#include <linux/vserver/debug.h>
17779 +#include <linux/vserver/context.h>
17780 +#include <linux/vserver/device.h>
17781 +#include <linux/vserver/device_cmd.h>
17782 +
17783 +
17784 +#define DMAP_HASH_BITS 4
17785 +
17786 +
17787 +struct vs_mapping {
17788 +       union {
17789 +               struct hlist_node hlist;
17790 +               struct list_head list;
17791 +       } u;
17792 +#define dm_hlist       u.hlist
17793 +#define dm_list                u.list
17794 +       xid_t xid;
17795 +       dev_t device;
17796 +       struct vx_dmap_target target;
17797 +};
17798 +
17799 +
17800 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17801 +
17802 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
17803 +
17804 +static struct vx_dmap_target dmap_defaults[2] = {
17805 +       { .flags = DATTR_OPEN },
17806 +       { .flags = DATTR_OPEN },
17807 +};
17808 +
17809 +
17810 +struct kmem_cache *dmap_cachep __read_mostly;
17811 +
17812 +int __init dmap_cache_init(void)
17813 +{
17814 +       dmap_cachep = kmem_cache_create("dmap_cache",
17815 +               sizeof(struct vs_mapping), 0,
17816 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17817 +       return 0;
17818 +}
17819 +
17820 +__initcall(dmap_cache_init);
17821 +
17822 +
17823 +static inline unsigned int __hashval(dev_t dev, int bits)
17824 +{
17825 +       return hash_long((unsigned long)dev, bits);
17826 +}
17827 +
17828 +
17829 +/*     __hash_mapping()
17830 + *     add the mapping to the hash table
17831 + */
17832 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17833 +{
17834 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17835 +       struct hlist_head *head, *hash = dmap_main_hash;
17836 +       int device = vdm->device;
17837 +
17838 +       spin_lock(hash_lock);
17839 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17840 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17841 +
17842 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17843 +       hlist_add_head(&vdm->dm_hlist, head);
17844 +       spin_unlock(hash_lock);
17845 +}
17846 +
17847 +
17848 +static inline int __mode_to_default(umode_t mode)
17849 +{
17850 +       switch (mode) {
17851 +       case S_IFBLK:
17852 +               return 0;
17853 +       case S_IFCHR:
17854 +               return 1;
17855 +       default:
17856 +               BUG();
17857 +       }
17858 +}
17859 +
17860 +
17861 +/*     __set_default()
17862 + *     set a default
17863 + */
17864 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17865 +       struct vx_dmap_target *vdmt)
17866 +{
17867 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17868 +       spin_lock(hash_lock);
17869 +
17870 +       if (vxi)
17871 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17872 +       else
17873 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17874 +
17875 +
17876 +       spin_unlock(hash_lock);
17877 +
17878 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17879 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17880 +}
17881 +
17882 +
17883 +/*     __remove_default()
17884 + *     remove a default
17885 + */
17886 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17887 +{
17888 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17889 +       spin_lock(hash_lock);
17890 +
17891 +       if (vxi)
17892 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17893 +       else    /* remove == reset */
17894 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17895 +
17896 +       spin_unlock(hash_lock);
17897 +       return 0;
17898 +}
17899 +
17900 +
17901 +/*     __find_mapping()
17902 + *     find a mapping in the hash table
17903 + *
17904 + *     caller must hold hash_lock
17905 + */
17906 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17907 +       struct vs_mapping **local, struct vs_mapping **global)
17908 +{
17909 +       struct hlist_head *hash = dmap_main_hash;
17910 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17911 +       struct hlist_node *pos;
17912 +       struct vs_mapping *vdm;
17913 +
17914 +       *local = NULL;
17915 +       if (global)
17916 +               *global = NULL;
17917 +
17918 +       hlist_for_each(pos, head) {
17919 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17920 +
17921 +               if ((vdm->device == device) &&
17922 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17923 +                       if (vdm->xid == xid) {
17924 +                               *local = vdm;
17925 +                               return 1;
17926 +                       } else if (global && vdm->xid == 0)
17927 +                               *global = vdm;
17928 +               }
17929 +       }
17930 +
17931 +       if (global && *global)
17932 +               return 0;
17933 +       else
17934 +               return -ENOENT;
17935 +}
17936 +
17937 +
17938 +/*     __lookup_mapping()
17939 + *     find a mapping and store the result in target and flags
17940 + */
17941 +static inline int __lookup_mapping(struct vx_info *vxi,
17942 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17943 +{
17944 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17945 +       struct vs_mapping *vdm, *global;
17946 +       struct vx_dmap_target *vdmt;
17947 +       int ret = 0;
17948 +       xid_t xid = vxi->vx_id;
17949 +       int index;
17950 +
17951 +       spin_lock(hash_lock);
17952 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17953 +               ret = 1;
17954 +               vdmt = &vdm->target;
17955 +               goto found;
17956 +       }
17957 +
17958 +       index = __mode_to_default(mode);
17959 +       if (vxi && vxi->dmap.targets[index].flags) {
17960 +               ret = 2;
17961 +               vdmt = &vxi->dmap.targets[index];
17962 +       } else if (global) {
17963 +               ret = 3;
17964 +               vdmt = &global->target;
17965 +               goto found;
17966 +       } else {
17967 +               ret = 4;
17968 +               vdmt = &dmap_defaults[index];
17969 +       }
17970 +
17971 +found:
17972 +       if (target && (vdmt->flags & DATTR_REMAP))
17973 +               *target = vdmt->target;
17974 +       else if (target)
17975 +               *target = device;
17976 +       if (flags)
17977 +               *flags = vdmt->flags;
17978 +
17979 +       spin_unlock(hash_lock);
17980 +
17981 +       return ret;
17982 +}
17983 +
17984 +
17985 +/*     __remove_mapping()
17986 + *     remove a mapping from the hash table
17987 + */
17988 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17989 +       umode_t mode)
17990 +{
17991 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17992 +       struct vs_mapping *vdm = NULL;
17993 +       int ret = 0;
17994 +
17995 +       spin_lock(hash_lock);
17996 +
17997 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17998 +               NULL);
17999 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18000 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18001 +       if (ret < 0)
18002 +               goto out;
18003 +       hlist_del(&vdm->dm_hlist);
18004 +
18005 +out:
18006 +       spin_unlock(hash_lock);
18007 +       if (vdm)
18008 +               kmem_cache_free(dmap_cachep, vdm);
18009 +       return ret;
18010 +}
18011 +
18012 +
18013 +
18014 +int vs_map_device(struct vx_info *vxi,
18015 +       dev_t device, dev_t *target, umode_t mode)
18016 +{
18017 +       int ret, flags = DATTR_MASK;
18018 +
18019 +       if (!vxi) {
18020 +               if (target)
18021 +                       *target = device;
18022 +               goto out;
18023 +       }
18024 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18025 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18026 +               device, target ? *target : 0, flags, mode, ret);
18027 +out:
18028 +       return (flags & DATTR_MASK);
18029 +}
18030 +
18031 +
18032 +
18033 +static int do_set_mapping(struct vx_info *vxi,
18034 +       dev_t device, dev_t target, int flags, umode_t mode)
18035 +{
18036 +       if (device) {
18037 +               struct vs_mapping *new;
18038 +
18039 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18040 +               if (!new)
18041 +                       return -ENOMEM;
18042 +
18043 +               INIT_HLIST_NODE(&new->dm_hlist);
18044 +               new->device = device;
18045 +               new->target.target = target;
18046 +               new->target.flags = flags | mode;
18047 +               new->xid = (vxi ? vxi->vx_id : 0);
18048 +
18049 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18050 +               __hash_mapping(vxi, new);
18051 +       } else {
18052 +               struct vx_dmap_target new = {
18053 +                       .target = target,
18054 +                       .flags = flags | mode,
18055 +               };
18056 +               __set_default(vxi, mode, &new);
18057 +       }
18058 +       return 0;
18059 +}
18060 +
18061 +
18062 +static int do_unset_mapping(struct vx_info *vxi,
18063 +       dev_t device, dev_t target, int flags, umode_t mode)
18064 +{
18065 +       int ret = -EINVAL;
18066 +
18067 +       if (device) {
18068 +               ret = __remove_mapping(vxi, device, mode);
18069 +               if (ret < 0)
18070 +                       goto out;
18071 +       } else {
18072 +               ret = __remove_default(vxi, mode);
18073 +               if (ret < 0)
18074 +                       goto out;
18075 +       }
18076 +
18077 +out:
18078 +       return ret;
18079 +}
18080 +
18081 +
18082 +static inline int __user_device(const char __user *name, dev_t *dev,
18083 +       umode_t *mode)
18084 +{
18085 +       struct nameidata nd;
18086 +       int ret;
18087 +
18088 +       if (!name) {
18089 +               *dev = 0;
18090 +               return 0;
18091 +       }
18092 +       ret = user_lpath(name, &nd.path);
18093 +       if (ret)
18094 +               return ret;
18095 +       if (nd.path.dentry->d_inode) {
18096 +               *dev = nd.path.dentry->d_inode->i_rdev;
18097 +               *mode = nd.path.dentry->d_inode->i_mode;
18098 +       }
18099 +       path_put(&nd.path);
18100 +       return 0;
18101 +}
18102 +
18103 +static inline int __mapping_mode(dev_t device, dev_t target,
18104 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18105 +{
18106 +       if (device)
18107 +               *mode = device_mode & S_IFMT;
18108 +       else if (target)
18109 +               *mode = target_mode & S_IFMT;
18110 +       else
18111 +               return -EINVAL;
18112 +
18113 +       /* if both given, device and target mode have to match */
18114 +       if (device && target &&
18115 +               ((device_mode ^ target_mode) & S_IFMT))
18116 +               return -EINVAL;
18117 +       return 0;
18118 +}
18119 +
18120 +
18121 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18122 +       const char __user *target_path, int flags, int set)
18123 +{
18124 +       dev_t device = ~0, target = ~0;
18125 +       umode_t device_mode = 0, target_mode = 0, mode;
18126 +       int ret;
18127 +
18128 +       ret = __user_device(device_path, &device, &device_mode);
18129 +       if (ret)
18130 +               return ret;
18131 +       ret = __user_device(target_path, &target, &target_mode);
18132 +       if (ret)
18133 +               return ret;
18134 +
18135 +       ret = __mapping_mode(device, target,
18136 +               device_mode, target_mode, &mode);
18137 +       if (ret)
18138 +               return ret;
18139 +
18140 +       if (set)
18141 +               return do_set_mapping(vxi, device, target,
18142 +                       flags, mode);
18143 +       else
18144 +               return do_unset_mapping(vxi, device, target,
18145 +                       flags, mode);
18146 +}
18147 +
18148 +
18149 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18150 +{
18151 +       struct vcmd_set_mapping_v0 vc_data;
18152 +
18153 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18154 +               return -EFAULT;
18155 +
18156 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18157 +               vc_data.flags, 1);
18158 +}
18159 +
18160 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18161 +{
18162 +       struct vcmd_set_mapping_v0 vc_data;
18163 +
18164 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18165 +               return -EFAULT;
18166 +
18167 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18168 +               vc_data.flags, 0);
18169 +}
18170 +
18171 +
18172 +#ifdef CONFIG_COMPAT
18173 +
18174 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18175 +{
18176 +       struct vcmd_set_mapping_v0_x32 vc_data;
18177 +
18178 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18179 +               return -EFAULT;
18180 +
18181 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18182 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18183 +}
18184 +
18185 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18186 +{
18187 +       struct vcmd_set_mapping_v0_x32 vc_data;
18188 +
18189 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18190 +               return -EFAULT;
18191 +
18192 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18193 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18194 +}
18195 +
18196 +#endif /* CONFIG_COMPAT */
18197 +
18198 +
18199 diff -NurpP --minimal linux-2.6.37/kernel/vserver/dlimit.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/dlimit.c
18200 --- linux-2.6.37/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
18201 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/dlimit.c 2011-01-05 23:26:15.000000000 +0100
18202 @@ -0,0 +1,531 @@
18203 +/*
18204 + *  linux/kernel/vserver/dlimit.c
18205 + *
18206 + *  Virtual Server: Context Disk Limits
18207 + *
18208 + *  Copyright (C) 2004-2009  Herbert Pötzl
18209 + *
18210 + *  V0.01  initial version
18211 + *  V0.02  compat32 splitup
18212 + *  V0.03  extended interface
18213 + *
18214 + */
18215 +
18216 +#include <linux/statfs.h>
18217 +#include <linux/sched.h>
18218 +#include <linux/namei.h>
18219 +#include <linux/vs_tag.h>
18220 +#include <linux/vs_dlimit.h>
18221 +#include <linux/vserver/dlimit_cmd.h>
18222 +#include <linux/slab.h>
18223 +// #include <linux/gfp.h>
18224 +
18225 +#include <asm/uaccess.h>
18226 +
18227 +/*     __alloc_dl_info()
18228 +
18229 +       * allocate an initialized dl_info struct
18230 +       * doesn't make it visible (hash)                        */
18231 +
18232 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18233 +{
18234 +       struct dl_info *new = NULL;
18235 +
18236 +       vxdprintk(VXD_CBIT(dlim, 5),
18237 +               "alloc_dl_info(%p,%d)*", sb, tag);
18238 +
18239 +       /* would this benefit from a slab cache? */
18240 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18241 +       if (!new)
18242 +               return 0;
18243 +
18244 +       memset(new, 0, sizeof(struct dl_info));
18245 +       new->dl_tag = tag;
18246 +       new->dl_sb = sb;
18247 +       // INIT_RCU_HEAD(&new->dl_rcu);
18248 +       INIT_HLIST_NODE(&new->dl_hlist);
18249 +       spin_lock_init(&new->dl_lock);
18250 +       atomic_set(&new->dl_refcnt, 0);
18251 +       atomic_set(&new->dl_usecnt, 0);
18252 +
18253 +       /* rest of init goes here */
18254 +
18255 +       vxdprintk(VXD_CBIT(dlim, 4),
18256 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18257 +       return new;
18258 +}
18259 +
18260 +/*     __dealloc_dl_info()
18261 +
18262 +       * final disposal of dl_info                             */
18263 +
18264 +static void __dealloc_dl_info(struct dl_info *dli)
18265 +{
18266 +       vxdprintk(VXD_CBIT(dlim, 4),
18267 +               "dealloc_dl_info(%p)", dli);
18268 +
18269 +       dli->dl_hlist.next = LIST_POISON1;
18270 +       dli->dl_tag = -1;
18271 +       dli->dl_sb = 0;
18272 +
18273 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18274 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18275 +
18276 +       kfree(dli);
18277 +}
18278 +
18279 +
18280 +/*     hash table for dl_info hash */
18281 +
18282 +#define DL_HASH_SIZE   13
18283 +
18284 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18285 +
18286 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
18287 +
18288 +
18289 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18290 +{
18291 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18292 +}
18293 +
18294 +
18295 +
18296 +/*     __hash_dl_info()
18297 +
18298 +       * add the dli to the global hash table
18299 +       * requires the hash_lock to be held                     */
18300 +
18301 +static inline void __hash_dl_info(struct dl_info *dli)
18302 +{
18303 +       struct hlist_head *head;
18304 +
18305 +       vxdprintk(VXD_CBIT(dlim, 6),
18306 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18307 +       get_dl_info(dli);
18308 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18309 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18310 +}
18311 +
18312 +/*     __unhash_dl_info()
18313 +
18314 +       * remove the dli from the global hash table
18315 +       * requires the hash_lock to be held                     */
18316 +
18317 +static inline void __unhash_dl_info(struct dl_info *dli)
18318 +{
18319 +       vxdprintk(VXD_CBIT(dlim, 6),
18320 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18321 +       hlist_del_rcu(&dli->dl_hlist);
18322 +       put_dl_info(dli);
18323 +}
18324 +
18325 +
18326 +/*     __lookup_dl_info()
18327 +
18328 +       * requires the rcu_read_lock()
18329 +       * doesn't increment the dl_refcnt                       */
18330 +
18331 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18332 +{
18333 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18334 +       struct hlist_node *pos;
18335 +       struct dl_info *dli;
18336 +
18337 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18338 +
18339 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18340 +                       return dli;
18341 +               }
18342 +       }
18343 +       return NULL;
18344 +}
18345 +
18346 +
18347 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18348 +{
18349 +       struct dl_info *dli;
18350 +
18351 +       rcu_read_lock();
18352 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18353 +       vxdprintk(VXD_CBIT(dlim, 7),
18354 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18355 +       rcu_read_unlock();
18356 +       return dli;
18357 +}
18358 +
18359 +void rcu_free_dl_info(struct rcu_head *head)
18360 +{
18361 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18362 +       int usecnt, refcnt;
18363 +
18364 +       BUG_ON(!dli || !head);
18365 +
18366 +       usecnt = atomic_read(&dli->dl_usecnt);
18367 +       BUG_ON(usecnt < 0);
18368 +
18369 +       refcnt = atomic_read(&dli->dl_refcnt);
18370 +       BUG_ON(refcnt < 0);
18371 +
18372 +       vxdprintk(VXD_CBIT(dlim, 3),
18373 +               "rcu_free_dl_info(%p)", dli);
18374 +       if (!usecnt)
18375 +               __dealloc_dl_info(dli);
18376 +       else
18377 +               printk("!!! rcu didn't free\n");
18378 +}
18379 +
18380 +
18381 +
18382 +
18383 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18384 +       uint32_t flags, int add)
18385 +{
18386 +       struct path path;
18387 +       int ret;
18388 +
18389 +       ret = user_lpath(name, &path);
18390 +       if (!ret) {
18391 +               struct super_block *sb;
18392 +               struct dl_info *dli;
18393 +
18394 +               ret = -EINVAL;
18395 +               if (!path.dentry->d_inode)
18396 +                       goto out_release;
18397 +               if (!(sb = path.dentry->d_inode->i_sb))
18398 +                       goto out_release;
18399 +
18400 +               if (add) {
18401 +                       dli = __alloc_dl_info(sb, id);
18402 +                       spin_lock(&dl_info_hash_lock);
18403 +
18404 +                       ret = -EEXIST;
18405 +                       if (__lookup_dl_info(sb, id))
18406 +                               goto out_unlock;
18407 +                       __hash_dl_info(dli);
18408 +                       dli = NULL;
18409 +               } else {
18410 +                       spin_lock(&dl_info_hash_lock);
18411 +                       dli = __lookup_dl_info(sb, id);
18412 +
18413 +                       ret = -ESRCH;
18414 +                       if (!dli)
18415 +                               goto out_unlock;
18416 +                       __unhash_dl_info(dli);
18417 +               }
18418 +               ret = 0;
18419 +       out_unlock:
18420 +               spin_unlock(&dl_info_hash_lock);
18421 +               if (add && dli)
18422 +                       __dealloc_dl_info(dli);
18423 +       out_release:
18424 +               path_put(&path);
18425 +       }
18426 +       return ret;
18427 +}
18428 +
18429 +int vc_add_dlimit(uint32_t id, void __user *data)
18430 +{
18431 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18432 +
18433 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18434 +               return -EFAULT;
18435 +
18436 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18437 +}
18438 +
18439 +int vc_rem_dlimit(uint32_t id, void __user *data)
18440 +{
18441 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18442 +
18443 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18444 +               return -EFAULT;
18445 +
18446 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18447 +}
18448 +
18449 +#ifdef CONFIG_COMPAT
18450 +
18451 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18452 +{
18453 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18454 +
18455 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18456 +               return -EFAULT;
18457 +
18458 +       return do_addrem_dlimit(id,
18459 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18460 +}
18461 +
18462 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18463 +{
18464 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18465 +
18466 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18467 +               return -EFAULT;
18468 +
18469 +       return do_addrem_dlimit(id,
18470 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18471 +}
18472 +
18473 +#endif /* CONFIG_COMPAT */
18474 +
18475 +
18476 +static inline
18477 +int do_set_dlimit(uint32_t id, const char __user *name,
18478 +       uint32_t space_used, uint32_t space_total,
18479 +       uint32_t inodes_used, uint32_t inodes_total,
18480 +       uint32_t reserved, uint32_t flags)
18481 +{
18482 +       struct path path;
18483 +       int ret;
18484 +
18485 +       ret = user_lpath(name, &path);
18486 +       if (!ret) {
18487 +               struct super_block *sb;
18488 +               struct dl_info *dli;
18489 +
18490 +               ret = -EINVAL;
18491 +               if (!path.dentry->d_inode)
18492 +                       goto out_release;
18493 +               if (!(sb = path.dentry->d_inode->i_sb))
18494 +                       goto out_release;
18495 +
18496 +               /* sanity checks */
18497 +               if ((reserved != CDLIM_KEEP &&
18498 +                       reserved > 100) ||
18499 +                       (inodes_used != CDLIM_KEEP &&
18500 +                       inodes_used > inodes_total) ||
18501 +                       (space_used != CDLIM_KEEP &&
18502 +                       space_used > space_total))
18503 +                       goto out_release;
18504 +
18505 +               ret = -ESRCH;
18506 +               dli = locate_dl_info(sb, id);
18507 +               if (!dli)
18508 +                       goto out_release;
18509 +
18510 +               spin_lock(&dli->dl_lock);
18511 +
18512 +               if (inodes_used != CDLIM_KEEP)
18513 +                       dli->dl_inodes_used = inodes_used;
18514 +               if (inodes_total != CDLIM_KEEP)
18515 +                       dli->dl_inodes_total = inodes_total;
18516 +               if (space_used != CDLIM_KEEP)
18517 +                       dli->dl_space_used = dlimit_space_32to64(
18518 +                               space_used, flags, DLIMS_USED);
18519 +
18520 +               if (space_total == CDLIM_INFINITY)
18521 +                       dli->dl_space_total = DLIM_INFINITY;
18522 +               else if (space_total != CDLIM_KEEP)
18523 +                       dli->dl_space_total = dlimit_space_32to64(
18524 +                               space_total, flags, DLIMS_TOTAL);
18525 +
18526 +               if (reserved != CDLIM_KEEP)
18527 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18528 +
18529 +               spin_unlock(&dli->dl_lock);
18530 +
18531 +               put_dl_info(dli);
18532 +               ret = 0;
18533 +
18534 +       out_release:
18535 +               path_put(&path);
18536 +       }
18537 +       return ret;
18538 +}
18539 +
18540 +int vc_set_dlimit(uint32_t id, void __user *data)
18541 +{
18542 +       struct vcmd_ctx_dlimit_v0 vc_data;
18543 +
18544 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18545 +               return -EFAULT;
18546 +
18547 +       return do_set_dlimit(id, vc_data.name,
18548 +               vc_data.space_used, vc_data.space_total,
18549 +               vc_data.inodes_used, vc_data.inodes_total,
18550 +               vc_data.reserved, vc_data.flags);
18551 +}
18552 +
18553 +#ifdef CONFIG_COMPAT
18554 +
18555 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18556 +{
18557 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18558 +
18559 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18560 +               return -EFAULT;
18561 +
18562 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18563 +               vc_data.space_used, vc_data.space_total,
18564 +               vc_data.inodes_used, vc_data.inodes_total,
18565 +               vc_data.reserved, vc_data.flags);
18566 +}
18567 +
18568 +#endif /* CONFIG_COMPAT */
18569 +
18570 +
18571 +static inline
18572 +int do_get_dlimit(uint32_t id, const char __user *name,
18573 +       uint32_t *space_used, uint32_t *space_total,
18574 +       uint32_t *inodes_used, uint32_t *inodes_total,
18575 +       uint32_t *reserved, uint32_t *flags)
18576 +{
18577 +       struct path path;
18578 +       int ret;
18579 +
18580 +       ret = user_lpath(name, &path);
18581 +       if (!ret) {
18582 +               struct super_block *sb;
18583 +               struct dl_info *dli;
18584 +
18585 +               ret = -EINVAL;
18586 +               if (!path.dentry->d_inode)
18587 +                       goto out_release;
18588 +               if (!(sb = path.dentry->d_inode->i_sb))
18589 +                       goto out_release;
18590 +
18591 +               ret = -ESRCH;
18592 +               dli = locate_dl_info(sb, id);
18593 +               if (!dli)
18594 +                       goto out_release;
18595 +
18596 +               spin_lock(&dli->dl_lock);
18597 +               *inodes_used = dli->dl_inodes_used;
18598 +               *inodes_total = dli->dl_inodes_total;
18599 +
18600 +               *space_used = dlimit_space_64to32(
18601 +                       dli->dl_space_used, flags, DLIMS_USED);
18602 +
18603 +               if (dli->dl_space_total == DLIM_INFINITY)
18604 +                       *space_total = CDLIM_INFINITY;
18605 +               else
18606 +                       *space_total = dlimit_space_64to32(
18607 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18608 +
18609 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18610 +               spin_unlock(&dli->dl_lock);
18611 +
18612 +               put_dl_info(dli);
18613 +               ret = -EFAULT;
18614 +
18615 +               ret = 0;
18616 +       out_release:
18617 +               path_put(&path);
18618 +       }
18619 +       return ret;
18620 +}
18621 +
18622 +
18623 +int vc_get_dlimit(uint32_t id, void __user *data)
18624 +{
18625 +       struct vcmd_ctx_dlimit_v0 vc_data;
18626 +       int ret;
18627 +
18628 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18629 +               return -EFAULT;
18630 +
18631 +       ret = do_get_dlimit(id, vc_data.name,
18632 +               &vc_data.space_used, &vc_data.space_total,
18633 +               &vc_data.inodes_used, &vc_data.inodes_total,
18634 +               &vc_data.reserved, &vc_data.flags);
18635 +       if (ret)
18636 +               return ret;
18637 +
18638 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18639 +               return -EFAULT;
18640 +       return 0;
18641 +}
18642 +
18643 +#ifdef CONFIG_COMPAT
18644 +
18645 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18646 +{
18647 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18648 +       int ret;
18649 +
18650 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18651 +               return -EFAULT;
18652 +
18653 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18654 +               &vc_data.space_used, &vc_data.space_total,
18655 +               &vc_data.inodes_used, &vc_data.inodes_total,
18656 +               &vc_data.reserved, &vc_data.flags);
18657 +       if (ret)
18658 +               return ret;
18659 +
18660 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18661 +               return -EFAULT;
18662 +       return 0;
18663 +}
18664 +
18665 +#endif /* CONFIG_COMPAT */
18666 +
18667 +
18668 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18669 +{
18670 +       struct dl_info *dli;
18671 +       __u64 blimit, bfree, bavail;
18672 +       __u32 ifree;
18673 +
18674 +       dli = locate_dl_info(sb, dx_current_tag());
18675 +       if (!dli)
18676 +               return;
18677 +
18678 +       spin_lock(&dli->dl_lock);
18679 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18680 +               goto no_ilim;
18681 +
18682 +       /* reduce max inodes available to limit */
18683 +       if (buf->f_files > dli->dl_inodes_total)
18684 +               buf->f_files = dli->dl_inodes_total;
18685 +
18686 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18687 +       /* reduce free inodes to min */
18688 +       if (ifree < buf->f_ffree)
18689 +               buf->f_ffree = ifree;
18690 +
18691 +no_ilim:
18692 +       if (dli->dl_space_total == DLIM_INFINITY)
18693 +               goto no_blim;
18694 +
18695 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18696 +
18697 +       if (dli->dl_space_total < dli->dl_space_used)
18698 +               bfree = 0;
18699 +       else
18700 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18701 +                       >> sb->s_blocksize_bits;
18702 +
18703 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18704 +       if (bavail < dli->dl_space_used)
18705 +               bavail = 0;
18706 +       else
18707 +               bavail = (bavail - dli->dl_space_used)
18708 +                       >> sb->s_blocksize_bits;
18709 +
18710 +       /* reduce max space available to limit */
18711 +       if (buf->f_blocks > blimit)
18712 +               buf->f_blocks = blimit;
18713 +
18714 +       /* reduce free space to min */
18715 +       if (bfree < buf->f_bfree)
18716 +               buf->f_bfree = bfree;
18717 +
18718 +       /* reduce avail space to min */
18719 +       if (bavail < buf->f_bavail)
18720 +               buf->f_bavail = bavail;
18721 +
18722 +no_blim:
18723 +       spin_unlock(&dli->dl_lock);
18724 +       put_dl_info(dli);
18725 +
18726 +       return;
18727 +}
18728 +
18729 +#include <linux/module.h>
18730 +
18731 +EXPORT_SYMBOL_GPL(locate_dl_info);
18732 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18733 +
18734 diff -NurpP --minimal linux-2.6.37/kernel/vserver/helper.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/helper.c
18735 --- linux-2.6.37/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
18736 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/helper.c 2010-11-23 02:09:41.000000000 +0100
18737 @@ -0,0 +1,223 @@
18738 +/*
18739 + *  linux/kernel/vserver/helper.c
18740 + *
18741 + *  Virtual Context Support
18742 + *
18743 + *  Copyright (C) 2004-2007  Herbert Pötzl
18744 + *
18745 + *  V0.01  basic helper
18746 + *
18747 + */
18748 +
18749 +#include <linux/kmod.h>
18750 +#include <linux/reboot.h>
18751 +#include <linux/vs_context.h>
18752 +#include <linux/vs_network.h>
18753 +#include <linux/vserver/signal.h>
18754 +
18755 +
18756 +char vshelper_path[255] = "/sbin/vshelper";
18757 +
18758 +
18759 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18760 +{
18761 +       int ret;
18762 +
18763 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18764 +               printk( KERN_WARNING
18765 +                       "%s: (%s %s) returned %s with %d\n",
18766 +                       name, argv[1], argv[2],
18767 +                       sync ? "sync" : "async", ret);
18768 +       }
18769 +       vxdprintk(VXD_CBIT(switch, 4),
18770 +               "%s: (%s %s) returned %s with %d",
18771 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18772 +       return ret;
18773 +}
18774 +
18775 +/*
18776 + *      vshelper path is set via /proc/sys
18777 + *      invoked by vserver sys_reboot(), with
18778 + *      the following arguments
18779 + *
18780 + *      argv [0] = vshelper_path;
18781 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18782 + *      argv [2] = context identifier
18783 + *
18784 + *      envp [*] = type-specific parameters
18785 + */
18786 +
18787 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18788 +{
18789 +       char id_buf[8], cmd_buf[16];
18790 +       char uid_buf[16], pid_buf[16];
18791 +       int ret;
18792 +
18793 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18794 +       char *envp[] = {"HOME=/", "TERM=linux",
18795 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18796 +                       uid_buf, pid_buf, cmd_buf, 0};
18797 +
18798 +       if (vx_info_state(vxi, VXS_HELPER))
18799 +               return -EAGAIN;
18800 +       vxi->vx_state |= VXS_HELPER;
18801 +
18802 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18803 +
18804 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18805 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18806 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18807 +
18808 +       switch (cmd) {
18809 +       case LINUX_REBOOT_CMD_RESTART:
18810 +               argv[1] = "restart";
18811 +               break;
18812 +
18813 +       case LINUX_REBOOT_CMD_HALT:
18814 +               argv[1] = "halt";
18815 +               break;
18816 +
18817 +       case LINUX_REBOOT_CMD_POWER_OFF:
18818 +               argv[1] = "poweroff";
18819 +               break;
18820 +
18821 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18822 +               argv[1] = "swsusp";
18823 +               break;
18824 +
18825 +       case LINUX_REBOOT_CMD_OOM:
18826 +               argv[1] = "oom";
18827 +               break;
18828 +
18829 +       default:
18830 +               vxi->vx_state &= ~VXS_HELPER;
18831 +               return 0;
18832 +       }
18833 +
18834 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18835 +       vxi->vx_state &= ~VXS_HELPER;
18836 +       __wakeup_vx_info(vxi);
18837 +       return (ret) ? -EPERM : 0;
18838 +}
18839 +
18840 +
18841 +long vs_reboot(unsigned int cmd, void __user *arg)
18842 +{
18843 +       struct vx_info *vxi = current_vx_info();
18844 +       long ret = 0;
18845 +
18846 +       vxdprintk(VXD_CBIT(misc, 5),
18847 +               "vs_reboot(%p[#%d],%u)",
18848 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18849 +
18850 +       ret = vs_reboot_helper(vxi, cmd, arg);
18851 +       if (ret)
18852 +               return ret;
18853 +
18854 +       vxi->reboot_cmd = cmd;
18855 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18856 +               switch (cmd) {
18857 +               case LINUX_REBOOT_CMD_RESTART:
18858 +               case LINUX_REBOOT_CMD_HALT:
18859 +               case LINUX_REBOOT_CMD_POWER_OFF:
18860 +                       vx_info_kill(vxi, 0, SIGKILL);
18861 +                       vx_info_kill(vxi, 1, SIGKILL);
18862 +               default:
18863 +                       break;
18864 +               }
18865 +       }
18866 +       return 0;
18867 +}
18868 +
18869 +long vs_oom_action(unsigned int cmd)
18870 +{
18871 +       struct vx_info *vxi = current_vx_info();
18872 +       long ret = 0;
18873 +
18874 +       vxdprintk(VXD_CBIT(misc, 5),
18875 +               "vs_oom_action(%p[#%d],%u)",
18876 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18877 +
18878 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18879 +       if (ret)
18880 +               return ret;
18881 +
18882 +       vxi->reboot_cmd = cmd;
18883 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18884 +               vx_info_kill(vxi, 0, SIGKILL);
18885 +               vx_info_kill(vxi, 1, SIGKILL);
18886 +       }
18887 +       return 0;
18888 +}
18889 +
18890 +/*
18891 + *      argv [0] = vshelper_path;
18892 + *      argv [1] = action: "startup", "shutdown"
18893 + *      argv [2] = context identifier
18894 + *
18895 + *      envp [*] = type-specific parameters
18896 + */
18897 +
18898 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18899 +{
18900 +       char id_buf[8], cmd_buf[16];
18901 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18902 +       char *envp[] = {"HOME=/", "TERM=linux",
18903 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18904 +
18905 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18906 +               return 0;
18907 +
18908 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18909 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18910 +
18911 +       switch (cmd) {
18912 +       case VSC_STARTUP:
18913 +               argv[1] = "startup";
18914 +               break;
18915 +       case VSC_SHUTDOWN:
18916 +               argv[1] = "shutdown";
18917 +               break;
18918 +       default:
18919 +               return 0;
18920 +       }
18921 +
18922 +       return do_vshelper(vshelper_path, argv, envp, 1);
18923 +}
18924 +
18925 +
18926 +/*
18927 + *      argv [0] = vshelper_path;
18928 + *      argv [1] = action: "netup", "netdown"
18929 + *      argv [2] = context identifier
18930 + *
18931 + *      envp [*] = type-specific parameters
18932 + */
18933 +
18934 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18935 +{
18936 +       char id_buf[8], cmd_buf[16];
18937 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18938 +       char *envp[] = {"HOME=/", "TERM=linux",
18939 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18940 +
18941 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18942 +               return 0;
18943 +
18944 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18945 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18946 +
18947 +       switch (cmd) {
18948 +       case VSC_NETUP:
18949 +               argv[1] = "netup";
18950 +               break;
18951 +       case VSC_NETDOWN:
18952 +               argv[1] = "netdown";
18953 +               break;
18954 +       default:
18955 +               return 0;
18956 +       }
18957 +
18958 +       return do_vshelper(vshelper_path, argv, envp, 1);
18959 +}
18960 +
18961 diff -NurpP --minimal linux-2.6.37/kernel/vserver/history.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/history.c
18962 --- linux-2.6.37/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
18963 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/history.c        2010-11-23 02:09:41.000000000 +0100
18964 @@ -0,0 +1,258 @@
18965 +/*
18966 + *  kernel/vserver/history.c
18967 + *
18968 + *  Virtual Context History Backtrace
18969 + *
18970 + *  Copyright (C) 2004-2007  Herbert Pötzl
18971 + *
18972 + *  V0.01  basic structure
18973 + *  V0.02  hash/unhash and trace
18974 + *  V0.03  preemption fixes
18975 + *
18976 + */
18977 +
18978 +#include <linux/module.h>
18979 +#include <asm/uaccess.h>
18980 +
18981 +#include <linux/vserver/context.h>
18982 +#include <linux/vserver/debug.h>
18983 +#include <linux/vserver/debug_cmd.h>
18984 +#include <linux/vserver/history.h>
18985 +
18986 +
18987 +#ifdef CONFIG_VSERVER_HISTORY
18988 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18989 +#else
18990 +#define VXH_SIZE       64
18991 +#endif
18992 +
18993 +struct _vx_history {
18994 +       unsigned int counter;
18995 +
18996 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18997 +};
18998 +
18999 +
19000 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19001 +
19002 +unsigned volatile int vxh_active = 1;
19003 +
19004 +static atomic_t sequence = ATOMIC_INIT(0);
19005 +
19006 +
19007 +/*     vxh_advance()
19008 +
19009 +       * requires disabled preemption                          */
19010 +
19011 +struct _vx_hist_entry *vxh_advance(void *loc)
19012 +{
19013 +       unsigned int cpu = smp_processor_id();
19014 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19015 +       struct _vx_hist_entry *entry;
19016 +       unsigned int index;
19017 +
19018 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19019 +       entry = &hist->entry[index];
19020 +
19021 +       entry->seq = atomic_inc_return(&sequence);
19022 +       entry->loc = loc;
19023 +       return entry;
19024 +}
19025 +
19026 +EXPORT_SYMBOL_GPL(vxh_advance);
19027 +
19028 +
19029 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19030 +
19031 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19032 +
19033 +
19034 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19035 +
19036 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19037 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19038 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19039 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19040 +
19041 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19042 +{
19043 +       switch (e->type) {
19044 +       case VXH_THROW_OOPS:
19045 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19046 +               break;
19047 +
19048 +       case VXH_GET_VX_INFO:
19049 +       case VXH_PUT_VX_INFO:
19050 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19051 +                       VXH_LOC_ARGS(e),
19052 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19053 +                       VXH_VXI_ARGS(e));
19054 +               break;
19055 +
19056 +       case VXH_INIT_VX_INFO:
19057 +       case VXH_SET_VX_INFO:
19058 +       case VXH_CLR_VX_INFO:
19059 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19060 +                       VXH_LOC_ARGS(e),
19061 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19062 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19063 +                       VXH_VXI_ARGS(e), e->sc.data);
19064 +               break;
19065 +
19066 +       case VXH_CLAIM_VX_INFO:
19067 +       case VXH_RELEASE_VX_INFO:
19068 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19069 +                       VXH_LOC_ARGS(e),
19070 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19071 +                       VXH_VXI_ARGS(e), e->sc.data);
19072 +               break;
19073 +
19074 +       case VXH_ALLOC_VX_INFO:
19075 +       case VXH_DEALLOC_VX_INFO:
19076 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19077 +                       VXH_LOC_ARGS(e),
19078 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19079 +                       VXH_VXI_ARGS(e));
19080 +               break;
19081 +
19082 +       case VXH_HASH_VX_INFO:
19083 +       case VXH_UNHASH_VX_INFO:
19084 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19085 +                       VXH_LOC_ARGS(e),
19086 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19087 +                       VXH_VXI_ARGS(e));
19088 +               break;
19089 +
19090 +       case VXH_LOC_VX_INFO:
19091 +       case VXH_LOOKUP_VX_INFO:
19092 +       case VXH_CREATE_VX_INFO:
19093 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19094 +                       VXH_LOC_ARGS(e),
19095 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19096 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19097 +                       e->ll.arg, VXH_VXI_ARGS(e));
19098 +               break;
19099 +       }
19100 +}
19101 +
19102 +static void __vxh_dump_history(void)
19103 +{
19104 +       unsigned int i, cpu;
19105 +
19106 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19107 +               atomic_read(&sequence), NR_CPUS);
19108 +
19109 +       for (i = 0; i < VXH_SIZE; i++) {
19110 +               for_each_online_cpu(cpu) {
19111 +                       struct _vx_history *hist =
19112 +                               &per_cpu(vx_history_buffer, cpu);
19113 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19114 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19115 +
19116 +                       vxh_dump_entry(entry, cpu);
19117 +               }
19118 +       }
19119 +}
19120 +
19121 +void   vxh_dump_history(void)
19122 +{
19123 +       vxh_active = 0;
19124 +#ifdef CONFIG_SMP
19125 +       local_irq_enable();
19126 +       smp_send_stop();
19127 +       local_irq_disable();
19128 +#endif
19129 +       __vxh_dump_history();
19130 +}
19131 +
19132 +
19133 +/* vserver syscall commands below here */
19134 +
19135 +
19136 +int vc_dump_history(uint32_t id)
19137 +{
19138 +       vxh_active = 0;
19139 +       __vxh_dump_history();
19140 +       vxh_active = 1;
19141 +
19142 +       return 0;
19143 +}
19144 +
19145 +
19146 +int do_read_history(struct __user _vx_hist_entry *data,
19147 +       int cpu, uint32_t *index, uint32_t *count)
19148 +{
19149 +       int pos, ret = 0;
19150 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19151 +       int end = hist->counter;
19152 +       int start = end - VXH_SIZE + 2;
19153 +       int idx = *index;
19154 +
19155 +       /* special case: get current pos */
19156 +       if (!*count) {
19157 +               *index = end;
19158 +               return 0;
19159 +       }
19160 +
19161 +       /* have we lost some data? */
19162 +       if (idx < start)
19163 +               idx = start;
19164 +
19165 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19166 +               struct _vx_hist_entry *entry =
19167 +                       &hist->entry[idx % VXH_SIZE];
19168 +
19169 +               /* send entry to userspace */
19170 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19171 +               if (ret)
19172 +                       break;
19173 +       }
19174 +       /* save new index and count */
19175 +       *index = idx;
19176 +       *count = pos;
19177 +       return ret ? ret : (*index < end);
19178 +}
19179 +
19180 +int vc_read_history(uint32_t id, void __user *data)
19181 +{
19182 +       struct vcmd_read_history_v0 vc_data;
19183 +       int ret;
19184 +
19185 +       if (id >= NR_CPUS)
19186 +               return -EINVAL;
19187 +
19188 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19189 +               return -EFAULT;
19190 +
19191 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19192 +               id, &vc_data.index, &vc_data.count);
19193 +
19194 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19195 +               return -EFAULT;
19196 +       return ret;
19197 +}
19198 +
19199 +#ifdef CONFIG_COMPAT
19200 +
19201 +int vc_read_history_x32(uint32_t id, void __user *data)
19202 +{
19203 +       struct vcmd_read_history_v0_x32 vc_data;
19204 +       int ret;
19205 +
19206 +       if (id >= NR_CPUS)
19207 +               return -EINVAL;
19208 +
19209 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19210 +               return -EFAULT;
19211 +
19212 +       ret = do_read_history((struct __user _vx_hist_entry *)
19213 +               compat_ptr(vc_data.data_ptr),
19214 +               id, &vc_data.index, &vc_data.count);
19215 +
19216 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19217 +               return -EFAULT;
19218 +       return ret;
19219 +}
19220 +
19221 +#endif /* CONFIG_COMPAT */
19222 +
19223 diff -NurpP --minimal linux-2.6.37/kernel/vserver/inet.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/inet.c
19224 --- linux-2.6.37/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
19225 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/inet.c   2010-11-23 02:09:41.000000000 +0100
19226 @@ -0,0 +1,224 @@
19227 +
19228 +#include <linux/in.h>
19229 +#include <linux/inetdevice.h>
19230 +#include <linux/vs_inet.h>
19231 +#include <linux/vs_inet6.h>
19232 +#include <linux/vserver/debug.h>
19233 +#include <net/route.h>
19234 +#include <net/addrconf.h>
19235 +
19236 +
19237 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19238 +{
19239 +       int ret = 0;
19240 +
19241 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19242 +               ret = 1;
19243 +       else {
19244 +               struct nx_addr_v4 *ptr;
19245 +
19246 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19247 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19248 +                               ret = 1;
19249 +                               break;
19250 +                       }
19251 +               }
19252 +       }
19253 +
19254 +       vxdprintk(VXD_CBIT(net, 2),
19255 +               "nx_v4_addr_conflict(%p,%p): %d",
19256 +               nxi1, nxi2, ret);
19257 +
19258 +       return ret;
19259 +}
19260 +
19261 +
19262 +#ifdef CONFIG_IPV6
19263 +
19264 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19265 +{
19266 +       int ret = 0;
19267 +
19268 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19269 +               ret = 1;
19270 +       else {
19271 +               struct nx_addr_v6 *ptr;
19272 +
19273 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19274 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19275 +                               ret = 1;
19276 +                               break;
19277 +                       }
19278 +               }
19279 +       }
19280 +
19281 +       vxdprintk(VXD_CBIT(net, 2),
19282 +               "nx_v6_addr_conflict(%p,%p): %d",
19283 +               nxi1, nxi2, ret);
19284 +
19285 +       return ret;
19286 +}
19287 +
19288 +#endif
19289 +
19290 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19291 +{
19292 +       struct in_device *in_dev;
19293 +       struct in_ifaddr **ifap;
19294 +       struct in_ifaddr *ifa;
19295 +       int ret = 0;
19296 +
19297 +       if (!dev)
19298 +               goto out;
19299 +       in_dev = in_dev_get(dev);
19300 +       if (!in_dev)
19301 +               goto out;
19302 +
19303 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19304 +               ifap = &ifa->ifa_next) {
19305 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19306 +                       ret = 1;
19307 +                       break;
19308 +               }
19309 +       }
19310 +       in_dev_put(in_dev);
19311 +out:
19312 +       return ret;
19313 +}
19314 +
19315 +
19316 +#ifdef CONFIG_IPV6
19317 +
19318 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19319 +{
19320 +       struct inet6_dev *in_dev;
19321 +       struct inet6_ifaddr *ifa;
19322 +       int ret = 0;
19323 +
19324 +       if (!dev)
19325 +               goto out;
19326 +       in_dev = in6_dev_get(dev);
19327 +       if (!in_dev)
19328 +               goto out;
19329 +
19330 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19331 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19332 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19333 +                       ret = 1;
19334 +                       break;
19335 +               }
19336 +       }
19337 +       in6_dev_put(in_dev);
19338 +out:
19339 +       return ret;
19340 +}
19341 +
19342 +#endif
19343 +
19344 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19345 +{
19346 +       int ret = 1;
19347 +
19348 +       if (!nxi)
19349 +               goto out;
19350 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19351 +               goto out;
19352 +#ifdef CONFIG_IPV6
19353 +       ret = 2;
19354 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19355 +               goto out;
19356 +#endif
19357 +       ret = 0;
19358 +out:
19359 +       vxdprintk(VXD_CBIT(net, 3),
19360 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19361 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19362 +       return ret;
19363 +}
19364 +
19365 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
19366 +       struct rtable **rp, struct flowi *fl)
19367 +{
19368 +       if (!nxi)
19369 +               return 0;
19370 +
19371 +       /* FIXME: handle lback only case */
19372 +       if (!NX_IPV4(nxi))
19373 +               return -EPERM;
19374 +
19375 +       vxdprintk(VXD_CBIT(net, 4),
19376 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19377 +               nxi, nxi ? nxi->nx_id : 0,
19378 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
19379 +
19380 +       /* single IP is unconditional */
19381 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19382 +               (fl->fl4_src == INADDR_ANY))
19383 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
19384 +
19385 +       if (fl->fl4_src == INADDR_ANY) {
19386 +               struct nx_addr_v4 *ptr;
19387 +               __be32 found = 0;
19388 +               int err;
19389 +
19390 +               err = __ip_route_output_key(net, rp, fl);
19391 +               if (!err) {
19392 +                       found = (*rp)->rt_src;
19393 +                       ip_rt_put(*rp);
19394 +                       vxdprintk(VXD_CBIT(net, 4),
19395 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19396 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
19397 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19398 +                               goto found;
19399 +               }
19400 +
19401 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19402 +                       __be32 primary = ptr->ip[0].s_addr;
19403 +                       __be32 mask = ptr->mask.s_addr;
19404 +                       __be32 neta = primary & mask;
19405 +
19406 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19407 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19408 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19409 +                               NIPQUAD(mask), NIPQUAD(neta));
19410 +                       if ((found & mask) != neta)
19411 +                               continue;
19412 +
19413 +                       fl->fl4_src = primary;
19414 +                       err = __ip_route_output_key(net, rp, fl);
19415 +                       vxdprintk(VXD_CBIT(net, 4),
19416 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19417 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
19418 +                       if (!err) {
19419 +                               found = (*rp)->rt_src;
19420 +                               ip_rt_put(*rp);
19421 +                               if (found == primary)
19422 +                                       goto found;
19423 +                       }
19424 +               }
19425 +               /* still no source ip? */
19426 +               found = ipv4_is_loopback(fl->fl4_dst)
19427 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19428 +       found:
19429 +               /* assign src ip to flow */
19430 +               fl->fl4_src = found;
19431 +
19432 +       } else {
19433 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
19434 +                       return -EPERM;
19435 +       }
19436 +
19437 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19438 +               if (ipv4_is_loopback(fl->fl4_dst))
19439 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
19440 +               if (ipv4_is_loopback(fl->fl4_src))
19441 +                       fl->fl4_src = nxi->v4_lback.s_addr;
19442 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
19443 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19444 +               return -EPERM;
19445 +
19446 +       return 0;
19447 +}
19448 +
19449 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19450 +
19451 diff -NurpP --minimal linux-2.6.37/kernel/vserver/init.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/init.c
19452 --- linux-2.6.37/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
19453 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/init.c   2010-11-23 02:09:41.000000000 +0100
19454 @@ -0,0 +1,45 @@
19455 +/*
19456 + *  linux/kernel/init.c
19457 + *
19458 + *  Virtual Server Init
19459 + *
19460 + *  Copyright (C) 2004-2007  Herbert Pötzl
19461 + *
19462 + *  V0.01  basic structure
19463 + *
19464 + */
19465 +
19466 +#include <linux/init.h>
19467 +
19468 +int    vserver_register_sysctl(void);
19469 +void   vserver_unregister_sysctl(void);
19470 +
19471 +
19472 +static int __init init_vserver(void)
19473 +{
19474 +       int ret = 0;
19475 +
19476 +#ifdef CONFIG_VSERVER_DEBUG
19477 +       vserver_register_sysctl();
19478 +#endif
19479 +       return ret;
19480 +}
19481 +
19482 +
19483 +static void __exit exit_vserver(void)
19484 +{
19485 +
19486 +#ifdef CONFIG_VSERVER_DEBUG
19487 +       vserver_unregister_sysctl();
19488 +#endif
19489 +       return;
19490 +}
19491 +
19492 +/* FIXME: GFP_ZONETYPES gone
19493 +long vx_slab[GFP_ZONETYPES]; */
19494 +long vx_area;
19495 +
19496 +
19497 +module_init(init_vserver);
19498 +module_exit(exit_vserver);
19499 +
19500 diff -NurpP --minimal linux-2.6.37/kernel/vserver/inode.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/inode.c
19501 --- linux-2.6.37/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
19502 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/inode.c  2010-11-23 02:09:41.000000000 +0100
19503 @@ -0,0 +1,435 @@
19504 +/*
19505 + *  linux/kernel/vserver/inode.c
19506 + *
19507 + *  Virtual Server: File System Support
19508 + *
19509 + *  Copyright (C) 2004-2007  Herbert Pötzl
19510 + *
19511 + *  V0.01  separated from vcontext V0.05
19512 + *  V0.02  moved to tag (instead of xid)
19513 + *
19514 + */
19515 +
19516 +#include <linux/tty.h>
19517 +#include <linux/proc_fs.h>
19518 +#include <linux/devpts_fs.h>
19519 +#include <linux/fs.h>
19520 +#include <linux/file.h>
19521 +#include <linux/mount.h>
19522 +#include <linux/parser.h>
19523 +#include <linux/namei.h>
19524 +#include <linux/vserver/inode.h>
19525 +#include <linux/vserver/inode_cmd.h>
19526 +#include <linux/vs_base.h>
19527 +#include <linux/vs_tag.h>
19528 +
19529 +#include <asm/uaccess.h>
19530 +
19531 +
19532 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19533 +{
19534 +       struct proc_dir_entry *entry;
19535 +
19536 +       if (!in || !in->i_sb)
19537 +               return -ESRCH;
19538 +
19539 +       *flags = IATTR_TAG
19540 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19541 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19542 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19543 +               | (IS_COW(in) ? IATTR_COW : 0);
19544 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19545 +
19546 +       if (S_ISDIR(in->i_mode))
19547 +               *mask |= IATTR_BARRIER;
19548 +
19549 +       if (IS_TAGGED(in)) {
19550 +               *tag = in->i_tag;
19551 +               *mask |= IATTR_TAG;
19552 +       }
19553 +
19554 +       switch (in->i_sb->s_magic) {
19555 +       case PROC_SUPER_MAGIC:
19556 +               entry = PROC_I(in)->pde;
19557 +
19558 +               /* check for specific inodes? */
19559 +               if (entry)
19560 +                       *mask |= IATTR_FLAGS;
19561 +               if (entry)
19562 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19563 +               else
19564 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19565 +               break;
19566 +
19567 +       case DEVPTS_SUPER_MAGIC:
19568 +               *tag = in->i_tag;
19569 +               *mask |= IATTR_TAG;
19570 +               break;
19571 +
19572 +       default:
19573 +               break;
19574 +       }
19575 +       return 0;
19576 +}
19577 +
19578 +int vc_get_iattr(void __user *data)
19579 +{
19580 +       struct path path;
19581 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19582 +       int ret;
19583 +
19584 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19585 +               return -EFAULT;
19586 +
19587 +       ret = user_lpath(vc_data.name, &path);
19588 +       if (!ret) {
19589 +               ret = __vc_get_iattr(path.dentry->d_inode,
19590 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19591 +               path_put(&path);
19592 +       }
19593 +       if (ret)
19594 +               return ret;
19595 +
19596 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19597 +               ret = -EFAULT;
19598 +       return ret;
19599 +}
19600 +
19601 +#ifdef CONFIG_COMPAT
19602 +
19603 +int vc_get_iattr_x32(void __user *data)
19604 +{
19605 +       struct path path;
19606 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19607 +       int ret;
19608 +
19609 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19610 +               return -EFAULT;
19611 +
19612 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19613 +       if (!ret) {
19614 +               ret = __vc_get_iattr(path.dentry->d_inode,
19615 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19616 +               path_put(&path);
19617 +       }
19618 +       if (ret)
19619 +               return ret;
19620 +
19621 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19622 +               ret = -EFAULT;
19623 +       return ret;
19624 +}
19625 +
19626 +#endif /* CONFIG_COMPAT */
19627 +
19628 +
19629 +int vc_fget_iattr(uint32_t fd, void __user *data)
19630 +{
19631 +       struct file *filp;
19632 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19633 +       int ret;
19634 +
19635 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19636 +               return -EFAULT;
19637 +
19638 +       filp = fget(fd);
19639 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19640 +               return -EBADF;
19641 +
19642 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19643 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19644 +
19645 +       fput(filp);
19646 +
19647 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19648 +               ret = -EFAULT;
19649 +       return ret;
19650 +}
19651 +
19652 +
19653 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19654 +{
19655 +       struct inode *in = de->d_inode;
19656 +       int error = 0, is_proc = 0, has_tag = 0;
19657 +       struct iattr attr = { 0 };
19658 +
19659 +       if (!in || !in->i_sb)
19660 +               return -ESRCH;
19661 +
19662 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19663 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19664 +               return -EINVAL;
19665 +
19666 +       has_tag = IS_TAGGED(in) ||
19667 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19668 +       if ((*mask & IATTR_TAG) && !has_tag)
19669 +               return -EINVAL;
19670 +
19671 +       mutex_lock(&in->i_mutex);
19672 +       if (*mask & IATTR_TAG) {
19673 +               attr.ia_tag = *tag;
19674 +               attr.ia_valid |= ATTR_TAG;
19675 +       }
19676 +
19677 +       if (*mask & IATTR_FLAGS) {
19678 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19679 +               unsigned int iflags = PROC_I(in)->vx_flags;
19680 +
19681 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19682 +                       | (*flags & IATTR_FLAGS);
19683 +               PROC_I(in)->vx_flags = iflags;
19684 +               if (entry)
19685 +                       entry->vx_flags = iflags;
19686 +       }
19687 +
19688 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19689 +               IATTR_BARRIER | IATTR_COW)) {
19690 +               int iflags = in->i_flags;
19691 +               int vflags = in->i_vflags;
19692 +
19693 +               if (*mask & IATTR_IMMUTABLE) {
19694 +                       if (*flags & IATTR_IMMUTABLE)
19695 +                               iflags |= S_IMMUTABLE;
19696 +                       else
19697 +                               iflags &= ~S_IMMUTABLE;
19698 +               }
19699 +               if (*mask & IATTR_IXUNLINK) {
19700 +                       if (*flags & IATTR_IXUNLINK)
19701 +                               iflags |= S_IXUNLINK;
19702 +                       else
19703 +                               iflags &= ~S_IXUNLINK;
19704 +               }
19705 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19706 +                       if (*flags & IATTR_BARRIER)
19707 +                               vflags |= V_BARRIER;
19708 +                       else
19709 +                               vflags &= ~V_BARRIER;
19710 +               }
19711 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19712 +                       if (*flags & IATTR_COW)
19713 +                               vflags |= V_COW;
19714 +                       else
19715 +                               vflags &= ~V_COW;
19716 +               }
19717 +               if (in->i_op && in->i_op->sync_flags) {
19718 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19719 +                       if (error)
19720 +                               goto out;
19721 +               }
19722 +       }
19723 +
19724 +       if (attr.ia_valid) {
19725 +               if (in->i_op && in->i_op->setattr)
19726 +                       error = in->i_op->setattr(de, &attr);
19727 +               else {
19728 +                       error = inode_change_ok(in, &attr);
19729 +                       if (!error) {
19730 +                               setattr_copy(in, &attr);
19731 +                               mark_inode_dirty(in);
19732 +                       }
19733 +               }
19734 +       }
19735 +
19736 +out:
19737 +       mutex_unlock(&in->i_mutex);
19738 +       return error;
19739 +}
19740 +
19741 +int vc_set_iattr(void __user *data)
19742 +{
19743 +       struct path path;
19744 +       struct vcmd_ctx_iattr_v1 vc_data;
19745 +       int ret;
19746 +
19747 +       if (!capable(CAP_LINUX_IMMUTABLE))
19748 +               return -EPERM;
19749 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19750 +               return -EFAULT;
19751 +
19752 +       ret = user_lpath(vc_data.name, &path);
19753 +       if (!ret) {
19754 +               ret = __vc_set_iattr(path.dentry,
19755 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19756 +               path_put(&path);
19757 +       }
19758 +
19759 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19760 +               ret = -EFAULT;
19761 +       return ret;
19762 +}
19763 +
19764 +#ifdef CONFIG_COMPAT
19765 +
19766 +int vc_set_iattr_x32(void __user *data)
19767 +{
19768 +       struct path path;
19769 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19770 +       int ret;
19771 +
19772 +       if (!capable(CAP_LINUX_IMMUTABLE))
19773 +               return -EPERM;
19774 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19775 +               return -EFAULT;
19776 +
19777 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19778 +       if (!ret) {
19779 +               ret = __vc_set_iattr(path.dentry,
19780 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19781 +               path_put(&path);
19782 +       }
19783 +
19784 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19785 +               ret = -EFAULT;
19786 +       return ret;
19787 +}
19788 +
19789 +#endif /* CONFIG_COMPAT */
19790 +
19791 +int vc_fset_iattr(uint32_t fd, void __user *data)
19792 +{
19793 +       struct file *filp;
19794 +       struct vcmd_ctx_fiattr_v0 vc_data;
19795 +       int ret;
19796 +
19797 +       if (!capable(CAP_LINUX_IMMUTABLE))
19798 +               return -EPERM;
19799 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19800 +               return -EFAULT;
19801 +
19802 +       filp = fget(fd);
19803 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19804 +               return -EBADF;
19805 +
19806 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19807 +               &vc_data.flags, &vc_data.mask);
19808 +
19809 +       fput(filp);
19810 +
19811 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19812 +               return -EFAULT;
19813 +       return ret;
19814 +}
19815 +
19816 +
19817 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19818 +
19819 +static match_table_t tokens = {
19820 +       {Opt_notagcheck, "notagcheck"},
19821 +#ifdef CONFIG_PROPAGATE
19822 +       {Opt_notag, "notag"},
19823 +       {Opt_tag, "tag"},
19824 +       {Opt_tagid, "tagid=%u"},
19825 +#endif
19826 +       {Opt_err, NULL}
19827 +};
19828 +
19829 +
19830 +static void __dx_parse_remove(char *string, char *opt)
19831 +{
19832 +       char *p = strstr(string, opt);
19833 +       char *q = p;
19834 +
19835 +       if (p) {
19836 +               while (*q != '\0' && *q != ',')
19837 +                       q++;
19838 +               while (*q)
19839 +                       *p++ = *q++;
19840 +               while (*p)
19841 +                       *p++ = '\0';
19842 +       }
19843 +}
19844 +
19845 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19846 +                unsigned long *flags)
19847 +{
19848 +       int set = 0;
19849 +       substring_t args[MAX_OPT_ARGS];
19850 +       int token, option = 0;
19851 +       char *s, *p, *opts;
19852 +
19853 +       if (!string)
19854 +               return 0;
19855 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19856 +       if (!s)
19857 +               return 0;
19858 +
19859 +       opts = s;
19860 +       while ((p = strsep(&opts, ",")) != NULL) {
19861 +               token = match_token(p, tokens, args);
19862 +
19863 +               vxdprintk(VXD_CBIT(tag, 7),
19864 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19865 +                       p, token, option);
19866 +
19867 +               switch (token) {
19868 +#ifdef CONFIG_PROPAGATE
19869 +               case Opt_tag:
19870 +                       if (tag)
19871 +                               *tag = 0;
19872 +                       if (remove)
19873 +                               __dx_parse_remove(s, "tag");
19874 +                       *mnt_flags |= MNT_TAGID;
19875 +                       set |= MNT_TAGID;
19876 +                       break;
19877 +               case Opt_notag:
19878 +                       if (remove)
19879 +                               __dx_parse_remove(s, "notag");
19880 +                       *mnt_flags |= MNT_NOTAG;
19881 +                       set |= MNT_NOTAG;
19882 +                       break;
19883 +               case Opt_tagid:
19884 +                       if (tag && !match_int(args, &option))
19885 +                               *tag = option;
19886 +                       if (remove)
19887 +                               __dx_parse_remove(s, "tagid");
19888 +                       *mnt_flags |= MNT_TAGID;
19889 +                       set |= MNT_TAGID;
19890 +                       break;
19891 +#endif
19892 +               case Opt_notagcheck:
19893 +                       if (remove)
19894 +                               __dx_parse_remove(s, "notagcheck");
19895 +                       *flags |= MS_NOTAGCHECK;
19896 +                       set |= MS_NOTAGCHECK;
19897 +                       break;
19898 +               }
19899 +       }
19900 +       if (set)
19901 +               strcpy(string, s);
19902 +       kfree(s);
19903 +       return set;
19904 +}
19905 +
19906 +#ifdef CONFIG_PROPAGATE
19907 +
19908 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19909 +{
19910 +       tag_t new_tag = 0;
19911 +       struct vfsmount *mnt;
19912 +       int propagate;
19913 +
19914 +       if (!nd)
19915 +               return;
19916 +       mnt = nd->path.mnt;
19917 +       if (!mnt)
19918 +               return;
19919 +
19920 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19921 +       if (propagate)
19922 +               new_tag = mnt->mnt_tag;
19923 +
19924 +       vxdprintk(VXD_CBIT(tag, 7),
19925 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19926 +               inode, inode->i_ino, inode->i_tag,
19927 +               new_tag, (propagate) ? 1 : 0);
19928 +
19929 +       if (propagate)
19930 +               inode->i_tag = new_tag;
19931 +}
19932 +
19933 +#include <linux/module.h>
19934 +
19935 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19936 +
19937 +#endif /* CONFIG_PROPAGATE */
19938 +
19939 diff -NurpP --minimal linux-2.6.37/kernel/vserver/Kconfig linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/Kconfig
19940 --- linux-2.6.37/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
19941 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/Kconfig  2010-11-23 02:09:41.000000000 +0100
19942 @@ -0,0 +1,265 @@
19943 +#
19944 +# Linux VServer configuration
19945 +#
19946 +
19947 +menu "Linux VServer"
19948 +
19949 +config VSERVER_AUTO_LBACK
19950 +       bool    "Automatically Assign Loopback IP"
19951 +       default y
19952 +       help
19953 +         Automatically assign a guest specific loopback
19954 +         IP and add it to the kernel network stack on
19955 +         startup.
19956 +
19957 +config VSERVER_AUTO_SINGLE
19958 +       bool    "Automatic Single IP Special Casing"
19959 +       depends on EXPERIMENTAL
19960 +       default y
19961 +       help
19962 +         This allows network contexts with a single IP to
19963 +         automatically remap 0.0.0.0 bindings to that IP,
19964 +         avoiding further network checks and improving
19965 +         performance.
19966 +
19967 +         (note: such guests do not allow to change the ip
19968 +          on the fly and do not show loopback addresses)
19969 +
19970 +config VSERVER_COWBL
19971 +       bool    "Enable COW Immutable Link Breaking"
19972 +       default y
19973 +       help
19974 +         This enables the COW (Copy-On-Write) link break code.
19975 +         It allows you to treat unified files like normal files
19976 +         when writing to them (which will implicitely break the
19977 +         link and create a copy of the unified file)
19978 +
19979 +config VSERVER_VTIME
19980 +       bool    "Enable Virtualized Guest Time"
19981 +       depends on EXPERIMENTAL
19982 +       default n
19983 +       help
19984 +         This enables per guest time offsets to allow for
19985 +         adjusting the system clock individually per guest.
19986 +         this adds some overhead to the time functions and
19987 +         therefore should not be enabled without good reason.
19988 +
19989 +config VSERVER_DEVICE
19990 +       bool    "Enable Guest Device Mapping"
19991 +       depends on EXPERIMENTAL
19992 +       default n
19993 +       help
19994 +         This enables generic device remapping.
19995 +
19996 +config VSERVER_PROC_SECURE
19997 +       bool    "Enable Proc Security"
19998 +       depends on PROC_FS
19999 +       default y
20000 +       help
20001 +         This configures ProcFS security to initially hide
20002 +         non-process entries for all contexts except the main and
20003 +         spectator context (i.e. for all guests), which is a secure
20004 +         default.
20005 +
20006 +         (note: on 1.2x the entries were visible by default)
20007 +
20008 +config VSERVER_HARDCPU
20009 +       bool    "Enable Hard CPU Limits"
20010 +       default y
20011 +       help
20012 +         Activate the Hard CPU Limits
20013 +
20014 +         This will compile in code that allows the Token Bucket
20015 +         Scheduler to put processes on hold when a context's
20016 +         tokens are depleted (provided that its per-context
20017 +         sched_hard flag is set).
20018 +
20019 +         Processes belonging to that context will not be able
20020 +         to consume CPU resources again until a per-context
20021 +         configured minimum of tokens has been reached.
20022 +
20023 +config VSERVER_IDLETIME
20024 +       bool    "Avoid idle CPUs by skipping Time"
20025 +       depends on VSERVER_HARDCPU
20026 +       default y
20027 +       help
20028 +         This option allows the scheduler to artificially
20029 +         advance time (per cpu) when otherwise the idle
20030 +         task would be scheduled, thus keeping the cpu
20031 +         busy and sharing the available resources among
20032 +         certain contexts.
20033 +
20034 +config VSERVER_IDLELIMIT
20035 +       bool    "Limit the IDLE task"
20036 +       depends on VSERVER_HARDCPU
20037 +       default n
20038 +       help
20039 +         Limit the idle slices, so the the next context
20040 +         will be scheduled as soon as possible.
20041 +
20042 +         This might improve interactivity and latency, but
20043 +         will also marginally increase scheduling overhead.
20044 +
20045 +choice
20046 +       prompt  "Persistent Inode Tagging"
20047 +       default TAGGING_ID24
20048 +       help
20049 +         This adds persistent context information to filesystems
20050 +         mounted with the tagxid option. Tagging is a requirement
20051 +         for per-context disk limits and per-context quota.
20052 +
20053 +
20054 +config TAGGING_NONE
20055 +       bool    "Disabled"
20056 +       help
20057 +         do not store per-context information in inodes.
20058 +
20059 +config TAGGING_UID16
20060 +       bool    "UID16/GID32"
20061 +       help
20062 +         reduces UID to 16 bit, but leaves GID at 32 bit.
20063 +
20064 +config TAGGING_GID16
20065 +       bool    "UID32/GID16"
20066 +       help
20067 +         reduces GID to 16 bit, but leaves UID at 32 bit.
20068 +
20069 +config TAGGING_ID24
20070 +       bool    "UID24/GID24"
20071 +       help
20072 +         uses the upper 8bit from UID and GID for XID tagging
20073 +         which leaves 24bit for UID/GID each, which should be
20074 +         more than sufficient for normal use.
20075 +
20076 +config TAGGING_INTERN
20077 +       bool    "UID32/GID32"
20078 +       help
20079 +         this uses otherwise reserved inode fields in the on
20080 +         disk representation, which limits the use to a few
20081 +         filesystems (currently ext2 and ext3)
20082 +
20083 +endchoice
20084 +
20085 +config TAG_NFSD
20086 +       bool    "Tag NFSD User Auth and Files"
20087 +       default n
20088 +       help
20089 +         Enable this if you do want the in-kernel NFS
20090 +         Server to use the tagging specified above.
20091 +         (will require patched clients too)
20092 +
20093 +config VSERVER_PRIVACY
20094 +       bool    "Honor Privacy Aspects of Guests"
20095 +       default n
20096 +       help
20097 +         When enabled, most context checks will disallow
20098 +         access to structures assigned to a specific context,
20099 +         like ptys or loop devices.
20100 +
20101 +config VSERVER_CONTEXTS
20102 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
20103 +       range 1 65533
20104 +       default "768"   if 64BIT
20105 +       default "256"
20106 +       help
20107 +         This setting will optimize certain data structures
20108 +         and memory allocations according to the expected
20109 +         maximum.
20110 +
20111 +         note: this is not a strict upper limit.
20112 +
20113 +config VSERVER_WARN
20114 +       bool    "VServer Warnings"
20115 +       default y
20116 +       help
20117 +         This enables various runtime warnings, which will
20118 +         notify about potential manipulation attempts or
20119 +         resource shortage. It is generally considered to
20120 +         be a good idea to have that enabled.
20121 +
20122 +config VSERVER_WARN_DEVPTS
20123 +       bool    "VServer DevPTS Warnings"
20124 +       depends on VSERVER_WARN
20125 +       default y
20126 +       help
20127 +         This enables DevPTS related warnings, issued when a
20128 +         process inside a context tries to lookup or access
20129 +         a dynamic pts from the host or a different context.
20130 +
20131 +config VSERVER_DEBUG
20132 +       bool    "VServer Debugging Code"
20133 +       default n
20134 +       help
20135 +         Set this to yes if you want to be able to activate
20136 +         debugging output at runtime. It adds a very small
20137 +         overhead to all vserver related functions and
20138 +         increases the kernel size by about 20k.
20139 +
20140 +config VSERVER_HISTORY
20141 +       bool    "VServer History Tracing"
20142 +       depends on VSERVER_DEBUG
20143 +       default n
20144 +       help
20145 +         Set this to yes if you want to record the history of
20146 +         linux-vserver activities, so they can be replayed in
20147 +         the event of a kernel panic or oops.
20148 +
20149 +config VSERVER_HISTORY_SIZE
20150 +       int     "Per-CPU History Size (32-65536)"
20151 +       depends on VSERVER_HISTORY
20152 +       range 32 65536
20153 +       default 64
20154 +       help
20155 +         This allows you to specify the number of entries in
20156 +         the per-CPU history buffer.
20157 +
20158 +config VSERVER_LEGACY_MEM
20159 +       bool    "Legacy Memory Limits"
20160 +       default n
20161 +       help
20162 +         This provides fake memory limits to keep
20163 +         older tools happy in the face of memory
20164 +         cgroups
20165 +
20166 +choice
20167 +       prompt  "Quotes used in debug and warn messages"
20168 +       default QUOTES_ISO8859
20169 +
20170 +config QUOTES_ISO8859
20171 +       bool    "Extended ASCII (ISO 8859) angle quotes"
20172 +       help
20173 +         This uses the extended ASCII characters \xbb
20174 +         and \xab for quoting file and process names.
20175 +
20176 +config QUOTES_UTF8
20177 +       bool    "UTF-8 angle quotes"
20178 +       help
20179 +         This uses the the UTF-8 sequences for angle
20180 +         quotes to quote file and process names.
20181 +
20182 +config QUOTES_ASCII
20183 +       bool    "ASCII single quotes"
20184 +       help
20185 +         This uses the ASCII single quote character
20186 +         (\x27) to quote file and process names.
20187 +
20188 +endchoice
20189 +
20190 +endmenu
20191 +
20192 +
20193 +config VSERVER
20194 +       bool
20195 +       default y
20196 +       select NAMESPACES
20197 +       select UTS_NS
20198 +       select IPC_NS
20199 +       select USER_NS
20200 +       select SYSVIPC
20201 +
20202 +config VSERVER_SECURITY
20203 +       bool
20204 +       depends on SECURITY
20205 +       default y
20206 +       select SECURITY_CAPABILITIES
20207 +
20208 diff -NurpP --minimal linux-2.6.37/kernel/vserver/limit.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/limit.c
20209 --- linux-2.6.37/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
20210 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/limit.c  2010-11-23 02:09:41.000000000 +0100
20211 @@ -0,0 +1,354 @@
20212 +/*
20213 + *  linux/kernel/vserver/limit.c
20214 + *
20215 + *  Virtual Server: Context Limits
20216 + *
20217 + *  Copyright (C) 2004-2010  Herbert Pötzl
20218 + *
20219 + *  V0.01  broken out from vcontext V0.05
20220 + *  V0.02  changed vcmds to vxi arg
20221 + *  V0.03  added memory cgroup support
20222 + *
20223 + */
20224 +
20225 +#include <linux/sched.h>
20226 +#include <linux/module.h>
20227 +#include <linux/memcontrol.h>
20228 +#include <linux/res_counter.h>
20229 +#include <linux/vs_limit.h>
20230 +#include <linux/vserver/limit.h>
20231 +#include <linux/vserver/limit_cmd.h>
20232 +
20233 +#include <asm/uaccess.h>
20234 +
20235 +
20236 +const char *vlimit_name[NUM_LIMITS] = {
20237 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20238 +       [RLIMIT_RSS]            = "RSS",
20239 +       [RLIMIT_AS]             = "VM",
20240 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20241 +       [RLIMIT_CPU]            = "CPU",
20242 +       [RLIMIT_NPROC]          = "NPROC",
20243 +       [RLIMIT_NOFILE]         = "NOFILE",
20244 +       [RLIMIT_LOCKS]          = "LOCKS",
20245 +       [RLIMIT_SIGPENDING]     = "SIGP",
20246 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20247 +
20248 +       [VLIMIT_NSOCK]          = "NSOCK",
20249 +       [VLIMIT_OPENFD]         = "OPENFD",
20250 +       [VLIMIT_SHMEM]          = "SHMEM",
20251 +       [VLIMIT_DENTRY]         = "DENTRY",
20252 +};
20253 +
20254 +EXPORT_SYMBOL_GPL(vlimit_name);
20255 +
20256 +#define MASK_ENTRY(x)  (1 << (x))
20257 +
20258 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20259 +               /* minimum */
20260 +       0
20261 +       ,       /* softlimit */
20262 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20263 +       MASK_ENTRY( RLIMIT_RSS          ) |
20264 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20265 +       0
20266 +       ,       /* maximum */
20267 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20268 +       MASK_ENTRY( RLIMIT_RSS          ) |
20269 +       MASK_ENTRY( RLIMIT_AS           ) |
20270 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20271 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20272 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20273 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20274 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20275 +
20276 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20277 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20278 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20279 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20280 +       0
20281 +};
20282 +               /* accounting only */
20283 +uint32_t account_mask =
20284 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20285 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20286 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20287 +       0;
20288 +
20289 +
20290 +static int is_valid_vlimit(int id)
20291 +{
20292 +       uint32_t mask = vlimit_mask.minimum |
20293 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20294 +       return mask & (1 << id);
20295 +}
20296 +
20297 +static int is_accounted_vlimit(int id)
20298 +{
20299 +       if (is_valid_vlimit(id))
20300 +               return 1;
20301 +       return account_mask & (1 << id);
20302 +}
20303 +
20304 +
20305 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20306 +{
20307 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20308 +       return VX_VLIM(limit);
20309 +}
20310 +
20311 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20312 +{
20313 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20314 +       return VX_VLIM(limit);
20315 +}
20316 +
20317 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20318 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20319 +{
20320 +       if (!is_valid_vlimit(id))
20321 +               return -EINVAL;
20322 +
20323 +       if (minimum)
20324 +               *minimum = CRLIM_UNSET;
20325 +       if (softlimit)
20326 +               *softlimit = vc_get_soft(vxi, id);
20327 +       if (maximum)
20328 +               *maximum = vc_get_hard(vxi, id);
20329 +       return 0;
20330 +}
20331 +
20332 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20333 +{
20334 +       struct vcmd_ctx_rlimit_v0 vc_data;
20335 +       int ret;
20336 +
20337 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20338 +               return -EFAULT;
20339 +
20340 +       ret = do_get_rlimit(vxi, vc_data.id,
20341 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20342 +       if (ret)
20343 +               return ret;
20344 +
20345 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20346 +               return -EFAULT;
20347 +       return 0;
20348 +}
20349 +
20350 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20351 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20352 +{
20353 +       if (!is_valid_vlimit(id))
20354 +               return -EINVAL;
20355 +
20356 +       if (maximum != CRLIM_KEEP)
20357 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20358 +       if (softlimit != CRLIM_KEEP)
20359 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20360 +
20361 +       /* clamp soft limit */
20362 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20363 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20364 +
20365 +       return 0;
20366 +}
20367 +
20368 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20369 +{
20370 +       struct vcmd_ctx_rlimit_v0 vc_data;
20371 +
20372 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20373 +               return -EFAULT;
20374 +
20375 +       return do_set_rlimit(vxi, vc_data.id,
20376 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20377 +}
20378 +
20379 +#ifdef CONFIG_IA32_EMULATION
20380 +
20381 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20382 +{
20383 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20384 +
20385 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20386 +               return -EFAULT;
20387 +
20388 +       return do_set_rlimit(vxi, vc_data.id,
20389 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20390 +}
20391 +
20392 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20393 +{
20394 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20395 +       int ret;
20396 +
20397 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20398 +               return -EFAULT;
20399 +
20400 +       ret = do_get_rlimit(vxi, vc_data.id,
20401 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20402 +       if (ret)
20403 +               return ret;
20404 +
20405 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20406 +               return -EFAULT;
20407 +       return 0;
20408 +}
20409 +
20410 +#endif /* CONFIG_IA32_EMULATION */
20411 +
20412 +
20413 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20414 +{
20415 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20416 +               return -EFAULT;
20417 +       return 0;
20418 +}
20419 +
20420 +
20421 +static inline void vx_reset_hits(struct _vx_limit *limit)
20422 +{
20423 +       int lim;
20424 +
20425 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20426 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20427 +       }
20428 +}
20429 +
20430 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20431 +{
20432 +       vx_reset_hits(&vxi->limit);
20433 +       return 0;
20434 +}
20435 +
20436 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20437 +{
20438 +       rlim_t value;
20439 +       int lim;
20440 +
20441 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20442 +               value = __rlim_get(limit, lim);
20443 +               __rlim_rmax(limit, lim) = value;
20444 +               __rlim_rmin(limit, lim) = value;
20445 +       }
20446 +}
20447 +
20448 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20449 +{
20450 +       vx_reset_minmax(&vxi->limit);
20451 +       return 0;
20452 +}
20453 +
20454 +
20455 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20456 +{
20457 +       struct vcmd_rlimit_stat_v0 vc_data;
20458 +       struct _vx_limit *limit = &vxi->limit;
20459 +       int id;
20460 +
20461 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20462 +               return -EFAULT;
20463 +
20464 +       id = vc_data.id;
20465 +       if (!is_accounted_vlimit(id))
20466 +               return -EINVAL;
20467 +
20468 +       vx_limit_fixup(limit, id);
20469 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20470 +       vc_data.value = __rlim_get(limit, id);
20471 +       vc_data.minimum = __rlim_rmin(limit, id);
20472 +       vc_data.maximum = __rlim_rmax(limit, id);
20473 +
20474 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20475 +               return -EFAULT;
20476 +       return 0;
20477 +}
20478 +
20479 +
20480 +void vx_vsi_meminfo(struct sysinfo *val)
20481 +{
20482 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20483 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20484 +       u64 res_limit, res_usage;
20485 +
20486 +       if (!mcg)
20487 +               return;
20488 +
20489 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20490 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20491 +
20492 +       if (res_limit != RESOURCE_MAX)
20493 +               val->totalram = (res_limit >> PAGE_SHIFT);
20494 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20495 +       val->bufferram = 0;
20496 +       val->totalhigh = 0;
20497 +       val->freehigh = 0;
20498 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20499 +       return;
20500 +}
20501 +
20502 +void vx_vsi_swapinfo(struct sysinfo *val)
20503 +{
20504 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20505 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20506 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20507 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20508 +       s64 swap_limit, swap_usage;
20509 +
20510 +       if (!mcg)
20511 +               return;
20512 +
20513 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20514 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20515 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20516 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20517 +
20518 +       if (res_limit == RESOURCE_MAX)
20519 +               return;
20520 +
20521 +       swap_limit = memsw_limit - res_limit;
20522 +       if (memsw_limit != RESOURCE_MAX)
20523 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20524 +
20525 +       swap_usage = memsw_usage - res_usage;
20526 +       val->freeswap = (swap_usage < swap_limit) ?
20527 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20528 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20529 +       val->totalswap = 0;
20530 +       val->freeswap = 0;
20531 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20532 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20533 +       return;
20534 +}
20535 +
20536 +long vx_vsi_cached(struct sysinfo *val)
20537 +{
20538 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20539 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20540 +
20541 +       return mem_cgroup_stat_read_cache(mcg);
20542 +#else
20543 +       return 0;
20544 +#endif
20545 +}
20546 +
20547 +
20548 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20549 +{
20550 +       struct vx_info *vxi = mm->mm_vx_info;
20551 +       unsigned long points;
20552 +       rlim_t v, w;
20553 +
20554 +       if (!vxi)
20555 +               return 0;
20556 +
20557 +       points = vxi->vx_badness_bias;
20558 +
20559 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20560 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20561 +       points += (v > w) ? (v - w) : 0;
20562 +
20563 +       return points;
20564 +}
20565 +
20566 diff -NurpP --minimal linux-2.6.37/kernel/vserver/limit_init.h linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/limit_init.h
20567 --- linux-2.6.37/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
20568 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/limit_init.h     2010-11-23 02:09:41.000000000 +0100
20569 @@ -0,0 +1,31 @@
20570 +
20571 +
20572 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20573 +{
20574 +       int lim;
20575 +
20576 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20577 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20578 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20579 +               __rlim_set(limit, lim, 0);
20580 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20581 +               __rlim_rmin(limit, lim) = 0;
20582 +               __rlim_rmax(limit, lim) = 0;
20583 +       }
20584 +}
20585 +
20586 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20587 +{
20588 +       rlim_t value;
20589 +       int lim;
20590 +
20591 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20592 +               if ((1 << lim) & VLIM_NOCHECK)
20593 +                       continue;
20594 +               value = __rlim_get(limit, lim);
20595 +               vxwprintk_xid(value,
20596 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20597 +                       limit, vlimit_name[lim], lim, (long)value);
20598 +       }
20599 +}
20600 +
20601 diff -NurpP --minimal linux-2.6.37/kernel/vserver/limit_proc.h linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/limit_proc.h
20602 --- linux-2.6.37/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
20603 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/limit_proc.h     2010-11-23 02:09:41.000000000 +0100
20604 @@ -0,0 +1,57 @@
20605 +#ifndef _VX_LIMIT_PROC_H
20606 +#define _VX_LIMIT_PROC_H
20607 +
20608 +#include <linux/vserver/limit_int.h>
20609 +
20610 +
20611 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20612 +#define VX_LIMIT_TOP   \
20613 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20614 +
20615 +#define VX_LIMIT_ARG(r)                                \
20616 +       (unsigned long)__rlim_get(limit, r),    \
20617 +       (unsigned long)__rlim_rmin(limit, r),   \
20618 +       (unsigned long)__rlim_rmax(limit, r),   \
20619 +       VX_VLIM(__rlim_soft(limit, r)),         \
20620 +       VX_VLIM(__rlim_hard(limit, r)),         \
20621 +       atomic_read(&__rlim_lhit(limit, r))
20622 +
20623 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20624 +{
20625 +       vx_limit_fixup(limit, -1);
20626 +       return sprintf(buffer, VX_LIMIT_TOP
20627 +               "PROC"  VX_LIMIT_FMT
20628 +               "VM"    VX_LIMIT_FMT
20629 +               "VML"   VX_LIMIT_FMT
20630 +               "RSS"   VX_LIMIT_FMT
20631 +               "ANON"  VX_LIMIT_FMT
20632 +               "RMAP"  VX_LIMIT_FMT
20633 +               "FILES" VX_LIMIT_FMT
20634 +               "OFD"   VX_LIMIT_FMT
20635 +               "LOCKS" VX_LIMIT_FMT
20636 +               "SOCK"  VX_LIMIT_FMT
20637 +               "MSGQ"  VX_LIMIT_FMT
20638 +               "SHM"   VX_LIMIT_FMT
20639 +               "SEMA"  VX_LIMIT_FMT
20640 +               "SEMS"  VX_LIMIT_FMT
20641 +               "DENT"  VX_LIMIT_FMT,
20642 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20643 +               VX_LIMIT_ARG(RLIMIT_AS),
20644 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20645 +               VX_LIMIT_ARG(RLIMIT_RSS),
20646 +               VX_LIMIT_ARG(VLIMIT_ANON),
20647 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20648 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20649 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20650 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20651 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20652 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20653 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20654 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20655 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20656 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20657 +}
20658 +
20659 +#endif /* _VX_LIMIT_PROC_H */
20660 +
20661 +
20662 diff -NurpP --minimal linux-2.6.37/kernel/vserver/Makefile linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/Makefile
20663 --- linux-2.6.37/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
20664 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/Makefile 2010-11-23 02:09:41.000000000 +0100
20665 @@ -0,0 +1,18 @@
20666 +#
20667 +# Makefile for the Linux vserver routines.
20668 +#
20669 +
20670 +
20671 +obj-y          += vserver.o
20672 +
20673 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
20674 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
20675 +                  dlimit.o tag.o
20676 +
20677 +vserver-$(CONFIG_INET) += inet.o
20678 +vserver-$(CONFIG_PROC_FS) += proc.o
20679 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
20680 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
20681 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
20682 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
20683 +
20684 diff -NurpP --minimal linux-2.6.37/kernel/vserver/network.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/network.c
20685 --- linux-2.6.37/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
20686 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/network.c        2010-11-23 02:09:41.000000000 +0100
20687 @@ -0,0 +1,864 @@
20688 +/*
20689 + *  linux/kernel/vserver/network.c
20690 + *
20691 + *  Virtual Server: Network Support
20692 + *
20693 + *  Copyright (C) 2003-2007  Herbert Pötzl
20694 + *
20695 + *  V0.01  broken out from vcontext V0.05
20696 + *  V0.02  cleaned up implementation
20697 + *  V0.03  added equiv nx commands
20698 + *  V0.04  switch to RCU based hash
20699 + *  V0.05  and back to locking again
20700 + *  V0.06  changed vcmds to nxi arg
20701 + *  V0.07  have __create claim() the nxi
20702 + *
20703 + */
20704 +
20705 +#include <linux/err.h>
20706 +#include <linux/slab.h>
20707 +#include <linux/rcupdate.h>
20708 +
20709 +#include <linux/vs_network.h>
20710 +#include <linux/vs_pid.h>
20711 +#include <linux/vserver/network_cmd.h>
20712 +
20713 +
20714 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20715 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20716 +
20717 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20718 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20719 +
20720 +
20721 +static int __init init_network(void)
20722 +{
20723 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20724 +               sizeof(struct nx_addr_v4), 0,
20725 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20726 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20727 +               sizeof(struct nx_addr_v6), 0,
20728 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20729 +       return 0;
20730 +}
20731 +
20732 +
20733 +/*     __alloc_nx_addr_v4()                                    */
20734 +
20735 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20736 +{
20737 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20738 +               nx_addr_v4_cachep, GFP_KERNEL);
20739 +
20740 +       if (!IS_ERR(nxa))
20741 +               memset(nxa, 0, sizeof(*nxa));
20742 +       return nxa;
20743 +}
20744 +
20745 +/*     __dealloc_nx_addr_v4()                                  */
20746 +
20747 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20748 +{
20749 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20750 +}
20751 +
20752 +/*     __dealloc_nx_addr_v4_all()                              */
20753 +
20754 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20755 +{
20756 +       while (nxa) {
20757 +               struct nx_addr_v4 *next = nxa->next;
20758 +
20759 +               __dealloc_nx_addr_v4(nxa);
20760 +               nxa = next;
20761 +       }
20762 +}
20763 +
20764 +
20765 +#ifdef CONFIG_IPV6
20766 +
20767 +/*     __alloc_nx_addr_v6()                                    */
20768 +
20769 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20770 +{
20771 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20772 +               nx_addr_v6_cachep, GFP_KERNEL);
20773 +
20774 +       if (!IS_ERR(nxa))
20775 +               memset(nxa, 0, sizeof(*nxa));
20776 +       return nxa;
20777 +}
20778 +
20779 +/*     __dealloc_nx_addr_v6()                                  */
20780 +
20781 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20782 +{
20783 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20784 +}
20785 +
20786 +/*     __dealloc_nx_addr_v6_all()                              */
20787 +
20788 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20789 +{
20790 +       while (nxa) {
20791 +               struct nx_addr_v6 *next = nxa->next;
20792 +
20793 +               __dealloc_nx_addr_v6(nxa);
20794 +               nxa = next;
20795 +       }
20796 +}
20797 +
20798 +#endif /* CONFIG_IPV6 */
20799 +
20800 +/*     __alloc_nx_info()
20801 +
20802 +       * allocate an initialized nx_info struct
20803 +       * doesn't make it visible (hash)                        */
20804 +
20805 +static struct nx_info *__alloc_nx_info(nid_t nid)
20806 +{
20807 +       struct nx_info *new = NULL;
20808 +
20809 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20810 +
20811 +       /* would this benefit from a slab cache? */
20812 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20813 +       if (!new)
20814 +               return 0;
20815 +
20816 +       memset(new, 0, sizeof(struct nx_info));
20817 +       new->nx_id = nid;
20818 +       INIT_HLIST_NODE(&new->nx_hlist);
20819 +       atomic_set(&new->nx_usecnt, 0);
20820 +       atomic_set(&new->nx_tasks, 0);
20821 +       new->nx_state = 0;
20822 +
20823 +       new->nx_flags = NXF_INIT_SET;
20824 +
20825 +       /* rest of init goes here */
20826 +
20827 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20828 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20829 +
20830 +       vxdprintk(VXD_CBIT(nid, 0),
20831 +               "alloc_nx_info(%d) = %p", nid, new);
20832 +       atomic_inc(&nx_global_ctotal);
20833 +       return new;
20834 +}
20835 +
20836 +/*     __dealloc_nx_info()
20837 +
20838 +       * final disposal of nx_info                             */
20839 +
20840 +static void __dealloc_nx_info(struct nx_info *nxi)
20841 +{
20842 +       vxdprintk(VXD_CBIT(nid, 0),
20843 +               "dealloc_nx_info(%p)", nxi);
20844 +
20845 +       nxi->nx_hlist.next = LIST_POISON1;
20846 +       nxi->nx_id = -1;
20847 +
20848 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20849 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20850 +
20851 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20852 +
20853 +       nxi->nx_state |= NXS_RELEASED;
20854 +       kfree(nxi);
20855 +       atomic_dec(&nx_global_ctotal);
20856 +}
20857 +
20858 +static void __shutdown_nx_info(struct nx_info *nxi)
20859 +{
20860 +       nxi->nx_state |= NXS_SHUTDOWN;
20861 +       vs_net_change(nxi, VSC_NETDOWN);
20862 +}
20863 +
20864 +/*     exported stuff                                          */
20865 +
20866 +void free_nx_info(struct nx_info *nxi)
20867 +{
20868 +       /* context shutdown is mandatory */
20869 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20870 +
20871 +       /* context must not be hashed */
20872 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20873 +
20874 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20875 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20876 +
20877 +       __dealloc_nx_info(nxi);
20878 +}
20879 +
20880 +
20881 +void __nx_set_lback(struct nx_info *nxi)
20882 +{
20883 +       int nid = nxi->nx_id;
20884 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20885 +
20886 +       nxi->v4_lback.s_addr = lback;
20887 +}
20888 +
20889 +extern int __nx_inet_add_lback(__be32 addr);
20890 +extern int __nx_inet_del_lback(__be32 addr);
20891 +
20892 +
20893 +/*     hash table for nx_info hash */
20894 +
20895 +#define NX_HASH_SIZE   13
20896 +
20897 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20898 +
20899 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
20900 +
20901 +
20902 +static inline unsigned int __hashval(nid_t nid)
20903 +{
20904 +       return (nid % NX_HASH_SIZE);
20905 +}
20906 +
20907 +
20908 +
20909 +/*     __hash_nx_info()
20910 +
20911 +       * add the nxi to the global hash table
20912 +       * requires the hash_lock to be held                     */
20913 +
20914 +static inline void __hash_nx_info(struct nx_info *nxi)
20915 +{
20916 +       struct hlist_head *head;
20917 +
20918 +       vxd_assert_lock(&nx_info_hash_lock);
20919 +       vxdprintk(VXD_CBIT(nid, 4),
20920 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20921 +
20922 +       /* context must not be hashed */
20923 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20924 +
20925 +       nxi->nx_state |= NXS_HASHED;
20926 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20927 +       hlist_add_head(&nxi->nx_hlist, head);
20928 +       atomic_inc(&nx_global_cactive);
20929 +}
20930 +
20931 +/*     __unhash_nx_info()
20932 +
20933 +       * remove the nxi from the global hash table
20934 +       * requires the hash_lock to be held                     */
20935 +
20936 +static inline void __unhash_nx_info(struct nx_info *nxi)
20937 +{
20938 +       vxd_assert_lock(&nx_info_hash_lock);
20939 +       vxdprintk(VXD_CBIT(nid, 4),
20940 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20941 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20942 +
20943 +       /* context must be hashed */
20944 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20945 +       /* but without tasks */
20946 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20947 +
20948 +       nxi->nx_state &= ~NXS_HASHED;
20949 +       hlist_del(&nxi->nx_hlist);
20950 +       atomic_dec(&nx_global_cactive);
20951 +}
20952 +
20953 +
20954 +/*     __lookup_nx_info()
20955 +
20956 +       * requires the hash_lock to be held
20957 +       * doesn't increment the nx_refcnt                       */
20958 +
20959 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20960 +{
20961 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20962 +       struct hlist_node *pos;
20963 +       struct nx_info *nxi;
20964 +
20965 +       vxd_assert_lock(&nx_info_hash_lock);
20966 +       hlist_for_each(pos, head) {
20967 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20968 +
20969 +               if (nxi->nx_id == nid)
20970 +                       goto found;
20971 +       }
20972 +       nxi = NULL;
20973 +found:
20974 +       vxdprintk(VXD_CBIT(nid, 0),
20975 +               "__lookup_nx_info(#%u): %p[#%u]",
20976 +               nid, nxi, nxi ? nxi->nx_id : 0);
20977 +       return nxi;
20978 +}
20979 +
20980 +
20981 +/*     __create_nx_info()
20982 +
20983 +       * create the requested context
20984 +       * get(), claim() and hash it                            */
20985 +
20986 +static struct nx_info *__create_nx_info(int id)
20987 +{
20988 +       struct nx_info *new, *nxi = NULL;
20989 +
20990 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20991 +
20992 +       if (!(new = __alloc_nx_info(id)))
20993 +               return ERR_PTR(-ENOMEM);
20994 +
20995 +       /* required to make dynamic xids unique */
20996 +       spin_lock(&nx_info_hash_lock);
20997 +
20998 +       /* static context requested */
20999 +       if ((nxi = __lookup_nx_info(id))) {
21000 +               vxdprintk(VXD_CBIT(nid, 0),
21001 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21002 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21003 +                       nxi = ERR_PTR(-EBUSY);
21004 +               else
21005 +                       nxi = ERR_PTR(-EEXIST);
21006 +               goto out_unlock;
21007 +       }
21008 +       /* new context */
21009 +       vxdprintk(VXD_CBIT(nid, 0),
21010 +               "create_nx_info(%d) = %p (new)", id, new);
21011 +       claim_nx_info(new, NULL);
21012 +       __nx_set_lback(new);
21013 +       __hash_nx_info(get_nx_info(new));
21014 +       nxi = new, new = NULL;
21015 +
21016 +out_unlock:
21017 +       spin_unlock(&nx_info_hash_lock);
21018 +       if (new)
21019 +               __dealloc_nx_info(new);
21020 +       return nxi;
21021 +}
21022 +
21023 +
21024 +
21025 +/*     exported stuff                                          */
21026 +
21027 +
21028 +void unhash_nx_info(struct nx_info *nxi)
21029 +{
21030 +       __shutdown_nx_info(nxi);
21031 +       spin_lock(&nx_info_hash_lock);
21032 +       __unhash_nx_info(nxi);
21033 +       spin_unlock(&nx_info_hash_lock);
21034 +}
21035 +
21036 +/*     lookup_nx_info()
21037 +
21038 +       * search for a nx_info and get() it
21039 +       * negative id means current                             */
21040 +
21041 +struct nx_info *lookup_nx_info(int id)
21042 +{
21043 +       struct nx_info *nxi = NULL;
21044 +
21045 +       if (id < 0) {
21046 +               nxi = get_nx_info(current_nx_info());
21047 +       } else if (id > 1) {
21048 +               spin_lock(&nx_info_hash_lock);
21049 +               nxi = get_nx_info(__lookup_nx_info(id));
21050 +               spin_unlock(&nx_info_hash_lock);
21051 +       }
21052 +       return nxi;
21053 +}
21054 +
21055 +/*     nid_is_hashed()
21056 +
21057 +       * verify that nid is still hashed                       */
21058 +
21059 +int nid_is_hashed(nid_t nid)
21060 +{
21061 +       int hashed;
21062 +
21063 +       spin_lock(&nx_info_hash_lock);
21064 +       hashed = (__lookup_nx_info(nid) != NULL);
21065 +       spin_unlock(&nx_info_hash_lock);
21066 +       return hashed;
21067 +}
21068 +
21069 +
21070 +#ifdef CONFIG_PROC_FS
21071 +
21072 +/*     get_nid_list()
21073 +
21074 +       * get a subset of hashed nids for proc
21075 +       * assumes size is at least one                          */
21076 +
21077 +int get_nid_list(int index, unsigned int *nids, int size)
21078 +{
21079 +       int hindex, nr_nids = 0;
21080 +
21081 +       /* only show current and children */
21082 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
21083 +               if (index > 0)
21084 +                       return 0;
21085 +               nids[nr_nids] = nx_current_nid();
21086 +               return 1;
21087 +       }
21088 +
21089 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
21090 +               struct hlist_head *head = &nx_info_hash[hindex];
21091 +               struct hlist_node *pos;
21092 +
21093 +               spin_lock(&nx_info_hash_lock);
21094 +               hlist_for_each(pos, head) {
21095 +                       struct nx_info *nxi;
21096 +
21097 +                       if (--index > 0)
21098 +                               continue;
21099 +
21100 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21101 +                       nids[nr_nids] = nxi->nx_id;
21102 +                       if (++nr_nids >= size) {
21103 +                               spin_unlock(&nx_info_hash_lock);
21104 +                               goto out;
21105 +                       }
21106 +               }
21107 +               /* keep the lock time short */
21108 +               spin_unlock(&nx_info_hash_lock);
21109 +       }
21110 +out:
21111 +       return nr_nids;
21112 +}
21113 +#endif
21114 +
21115 +
21116 +/*
21117 + *     migrate task to new network
21118 + *     gets nxi, puts old_nxi on change
21119 + */
21120 +
21121 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
21122 +{
21123 +       struct nx_info *old_nxi;
21124 +       int ret = 0;
21125 +
21126 +       if (!p || !nxi)
21127 +               BUG();
21128 +
21129 +       vxdprintk(VXD_CBIT(nid, 5),
21130 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21131 +               p, nxi, nxi->nx_id,
21132 +               atomic_read(&nxi->nx_usecnt),
21133 +               atomic_read(&nxi->nx_tasks));
21134 +
21135 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21136 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21137 +               return -EACCES;
21138 +
21139 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21140 +               return -EFAULT;
21141 +
21142 +       /* maybe disallow this completely? */
21143 +       old_nxi = task_get_nx_info(p);
21144 +       if (old_nxi == nxi)
21145 +               goto out;
21146 +
21147 +       task_lock(p);
21148 +       if (old_nxi)
21149 +               clr_nx_info(&p->nx_info);
21150 +       claim_nx_info(nxi, p);
21151 +       set_nx_info(&p->nx_info, nxi);
21152 +       p->nid = nxi->nx_id;
21153 +       task_unlock(p);
21154 +
21155 +       vxdprintk(VXD_CBIT(nid, 5),
21156 +               "moved task %p into nxi:%p[#%d]",
21157 +               p, nxi, nxi->nx_id);
21158 +
21159 +       if (old_nxi)
21160 +               release_nx_info(old_nxi, p);
21161 +       ret = 0;
21162 +out:
21163 +       put_nx_info(old_nxi);
21164 +       return ret;
21165 +}
21166 +
21167 +
21168 +void nx_set_persistent(struct nx_info *nxi)
21169 +{
21170 +       vxdprintk(VXD_CBIT(nid, 6),
21171 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21172 +
21173 +       get_nx_info(nxi);
21174 +       claim_nx_info(nxi, NULL);
21175 +}
21176 +
21177 +void nx_clear_persistent(struct nx_info *nxi)
21178 +{
21179 +       vxdprintk(VXD_CBIT(nid, 6),
21180 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21181 +
21182 +       release_nx_info(nxi, NULL);
21183 +       put_nx_info(nxi);
21184 +}
21185 +
21186 +void nx_update_persistent(struct nx_info *nxi)
21187 +{
21188 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21189 +               nx_set_persistent(nxi);
21190 +       else
21191 +               nx_clear_persistent(nxi);
21192 +}
21193 +
21194 +/* vserver syscall commands below here */
21195 +
21196 +/* taks nid and nx_info functions */
21197 +
21198 +#include <asm/uaccess.h>
21199 +
21200 +
21201 +int vc_task_nid(uint32_t id)
21202 +{
21203 +       nid_t nid;
21204 +
21205 +       if (id) {
21206 +               struct task_struct *tsk;
21207 +
21208 +               read_lock(&tasklist_lock);
21209 +               tsk = find_task_by_real_pid(id);
21210 +               nid = (tsk) ? tsk->nid : -ESRCH;
21211 +               read_unlock(&tasklist_lock);
21212 +       } else
21213 +               nid = nx_current_nid();
21214 +       return nid;
21215 +}
21216 +
21217 +
21218 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21219 +{
21220 +       struct vcmd_nx_info_v0 vc_data;
21221 +
21222 +       vc_data.nid = nxi->nx_id;
21223 +
21224 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21225 +               return -EFAULT;
21226 +       return 0;
21227 +}
21228 +
21229 +
21230 +/* network functions */
21231 +
21232 +int vc_net_create(uint32_t nid, void __user *data)
21233 +{
21234 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21235 +       struct nx_info *new_nxi;
21236 +       int ret;
21237 +
21238 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21239 +               return -EFAULT;
21240 +
21241 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21242 +               return -EINVAL;
21243 +
21244 +       new_nxi = __create_nx_info(nid);
21245 +       if (IS_ERR(new_nxi))
21246 +               return PTR_ERR(new_nxi);
21247 +
21248 +       /* initial flags */
21249 +       new_nxi->nx_flags = vc_data.flagword;
21250 +
21251 +       ret = -ENOEXEC;
21252 +       if (vs_net_change(new_nxi, VSC_NETUP))
21253 +               goto out;
21254 +
21255 +       ret = nx_migrate_task(current, new_nxi);
21256 +       if (ret)
21257 +               goto out;
21258 +
21259 +       /* return context id on success */
21260 +       ret = new_nxi->nx_id;
21261 +
21262 +       /* get a reference for persistent contexts */
21263 +       if ((vc_data.flagword & NXF_PERSISTENT))
21264 +               nx_set_persistent(new_nxi);
21265 +out:
21266 +       release_nx_info(new_nxi, NULL);
21267 +       put_nx_info(new_nxi);
21268 +       return ret;
21269 +}
21270 +
21271 +
21272 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21273 +{
21274 +       return nx_migrate_task(current, nxi);
21275 +}
21276 +
21277 +
21278 +
21279 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21280 +       uint16_t type, uint16_t flags)
21281 +{
21282 +       struct nx_addr_v4 *nxa = &nxi->v4;
21283 +
21284 +       if (NX_IPV4(nxi)) {
21285 +               /* locate last entry */
21286 +               for (; nxa->next; nxa = nxa->next);
21287 +               nxa->next = __alloc_nx_addr_v4();
21288 +               nxa = nxa->next;
21289 +
21290 +               if (IS_ERR(nxa))
21291 +                       return PTR_ERR(nxa);
21292 +       }
21293 +
21294 +       if (nxi->v4.next)
21295 +               /* remove single ip for ip list */
21296 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21297 +
21298 +       nxa->ip[0].s_addr = ip;
21299 +       nxa->ip[1].s_addr = ip2;
21300 +       nxa->mask.s_addr = mask;
21301 +       nxa->type = type;
21302 +       nxa->flags = flags;
21303 +       return 0;
21304 +}
21305 +
21306 +
21307 +int vc_net_add(struct nx_info *nxi, void __user *data)
21308 +{
21309 +       struct vcmd_net_addr_v0 vc_data;
21310 +       int index, ret = 0;
21311 +
21312 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21313 +               return -EFAULT;
21314 +
21315 +       switch (vc_data.type) {
21316 +       case NXA_TYPE_IPV4:
21317 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21318 +                       return -EINVAL;
21319 +
21320 +               index = 0;
21321 +               while (index < vc_data.count) {
21322 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21323 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21324 +                       if (ret)
21325 +                               return ret;
21326 +                       index++;
21327 +               }
21328 +               ret = index;
21329 +               break;
21330 +
21331 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21332 +               nxi->v4_bcast = vc_data.ip[0];
21333 +               ret = 1;
21334 +               break;
21335 +
21336 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21337 +               nxi->v4_lback = vc_data.ip[0];
21338 +               ret = 1;
21339 +               break;
21340 +
21341 +       default:
21342 +               ret = -EINVAL;
21343 +               break;
21344 +       }
21345 +       return ret;
21346 +}
21347 +
21348 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21349 +{
21350 +       struct vcmd_net_addr_v0 vc_data;
21351 +
21352 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21353 +               return -EFAULT;
21354 +
21355 +       switch (vc_data.type) {
21356 +       case NXA_TYPE_ANY:
21357 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21358 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21359 +               break;
21360 +
21361 +       default:
21362 +               return -EINVAL;
21363 +       }
21364 +       return 0;
21365 +}
21366 +
21367 +
21368 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21369 +{
21370 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21371 +
21372 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21373 +               return -EFAULT;
21374 +
21375 +       switch (vc_data.type) {
21376 +       case NXA_TYPE_ADDR:
21377 +       case NXA_TYPE_RANGE:
21378 +       case NXA_TYPE_MASK:
21379 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21380 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21381 +
21382 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21383 +               nxi->v4_bcast = vc_data.ip;
21384 +               break;
21385 +
21386 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21387 +               nxi->v4_lback = vc_data.ip;
21388 +               break;
21389 +
21390 +       default:
21391 +               return -EINVAL;
21392 +       }
21393 +       return 0;
21394 +}
21395 +
21396 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
21397 +{
21398 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21399 +
21400 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21401 +               return -EFAULT;
21402 +
21403 +       switch (vc_data.type) {
21404 +/*     case NXA_TYPE_ADDR:
21405 +               break;          */
21406 +
21407 +       case NXA_TYPE_ANY:
21408 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21409 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21410 +               break;
21411 +
21412 +       default:
21413 +               return -EINVAL;
21414 +       }
21415 +       return 0;
21416 +}
21417 +
21418 +
21419 +#ifdef CONFIG_IPV6
21420 +
21421 +int do_add_v6_addr(struct nx_info *nxi,
21422 +       struct in6_addr *ip, struct in6_addr *mask,
21423 +       uint32_t prefix, uint16_t type, uint16_t flags)
21424 +{
21425 +       struct nx_addr_v6 *nxa = &nxi->v6;
21426 +
21427 +       if (NX_IPV6(nxi)) {
21428 +               /* locate last entry */
21429 +               for (; nxa->next; nxa = nxa->next);
21430 +               nxa->next = __alloc_nx_addr_v6();
21431 +               nxa = nxa->next;
21432 +
21433 +               if (IS_ERR(nxa))
21434 +                       return PTR_ERR(nxa);
21435 +       }
21436 +
21437 +       nxa->ip = *ip;
21438 +       nxa->mask = *mask;
21439 +       nxa->prefix = prefix;
21440 +       nxa->type = type;
21441 +       nxa->flags = flags;
21442 +       return 0;
21443 +}
21444 +
21445 +
21446 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21447 +{
21448 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21449 +
21450 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21451 +               return -EFAULT;
21452 +
21453 +       switch (vc_data.type) {
21454 +       case NXA_TYPE_ADDR:
21455 +       case NXA_TYPE_MASK:
21456 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21457 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21458 +       default:
21459 +               return -EINVAL;
21460 +       }
21461 +       return 0;
21462 +}
21463 +
21464 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21465 +{
21466 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21467 +
21468 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21469 +               return -EFAULT;
21470 +
21471 +       switch (vc_data.type) {
21472 +       case NXA_TYPE_ANY:
21473 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21474 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21475 +               break;
21476 +
21477 +       default:
21478 +               return -EINVAL;
21479 +       }
21480 +       return 0;
21481 +}
21482 +
21483 +#endif /* CONFIG_IPV6 */
21484 +
21485 +
21486 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21487 +{
21488 +       struct vcmd_net_flags_v0 vc_data;
21489 +
21490 +       vc_data.flagword = nxi->nx_flags;
21491 +
21492 +       /* special STATE flag handling */
21493 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21494 +
21495 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21496 +               return -EFAULT;
21497 +       return 0;
21498 +}
21499 +
21500 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21501 +{
21502 +       struct vcmd_net_flags_v0 vc_data;
21503 +       uint64_t mask, trigger;
21504 +
21505 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21506 +               return -EFAULT;
21507 +
21508 +       /* special STATE flag handling */
21509 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21510 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21511 +
21512 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21513 +               vc_data.flagword, mask);
21514 +       if (trigger & NXF_PERSISTENT)
21515 +               nx_update_persistent(nxi);
21516 +
21517 +       return 0;
21518 +}
21519 +
21520 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21521 +{
21522 +       struct vcmd_net_caps_v0 vc_data;
21523 +
21524 +       vc_data.ncaps = nxi->nx_ncaps;
21525 +       vc_data.cmask = ~0ULL;
21526 +
21527 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21528 +               return -EFAULT;
21529 +       return 0;
21530 +}
21531 +
21532 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21533 +{
21534 +       struct vcmd_net_caps_v0 vc_data;
21535 +
21536 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21537 +               return -EFAULT;
21538 +
21539 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21540 +               vc_data.ncaps, vc_data.cmask);
21541 +       return 0;
21542 +}
21543 +
21544 +
21545 +#include <linux/module.h>
21546 +
21547 +module_init(init_network);
21548 +
21549 +EXPORT_SYMBOL_GPL(free_nx_info);
21550 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21551 +
21552 diff -NurpP --minimal linux-2.6.37/kernel/vserver/proc.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/proc.c
21553 --- linux-2.6.37/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
21554 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/proc.c   2011-01-08 03:33:34.000000000 +0100
21555 @@ -0,0 +1,1098 @@
21556 +/*
21557 + *  linux/kernel/vserver/proc.c
21558 + *
21559 + *  Virtual Context Support
21560 + *
21561 + *  Copyright (C) 2003-2007  Herbert Pötzl
21562 + *
21563 + *  V0.01  basic structure
21564 + *  V0.02  adaptation vs1.3.0
21565 + *  V0.03  proc permissions
21566 + *  V0.04  locking/generic
21567 + *  V0.05  next generation procfs
21568 + *  V0.06  inode validation
21569 + *  V0.07  generic rewrite vid
21570 + *  V0.08  remove inode type
21571 + *
21572 + */
21573 +
21574 +#include <linux/proc_fs.h>
21575 +#include <linux/fs_struct.h>
21576 +#include <linux/mount.h>
21577 +#include <asm/unistd.h>
21578 +
21579 +#include <linux/vs_context.h>
21580 +#include <linux/vs_network.h>
21581 +#include <linux/vs_cvirt.h>
21582 +
21583 +#include <linux/in.h>
21584 +#include <linux/inetdevice.h>
21585 +#include <linux/vs_inet.h>
21586 +#include <linux/vs_inet6.h>
21587 +
21588 +#include <linux/vserver/global.h>
21589 +
21590 +#include "cvirt_proc.h"
21591 +#include "cacct_proc.h"
21592 +#include "limit_proc.h"
21593 +#include "sched_proc.h"
21594 +#include "vci_config.h"
21595 +
21596 +
21597 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21598 +{
21599 +       unsigned __capi;
21600 +
21601 +       CAP_FOR_EACH_U32(__capi) {
21602 +               buffer += sprintf(buffer, "%08x",
21603 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21604 +       }
21605 +       return buffer;
21606 +}
21607 +
21608 +
21609 +static struct proc_dir_entry *proc_virtual;
21610 +
21611 +static struct proc_dir_entry *proc_virtnet;
21612 +
21613 +
21614 +/* first the actual feeds */
21615 +
21616 +
21617 +static int proc_vci(char *buffer)
21618 +{
21619 +       return sprintf(buffer,
21620 +               "VCIVersion:\t%04x:%04x\n"
21621 +               "VCISyscall:\t%d\n"
21622 +               "VCIKernel:\t%08x\n",
21623 +               VCI_VERSION >> 16,
21624 +               VCI_VERSION & 0xFFFF,
21625 +               __NR_vserver,
21626 +               vci_kernel_config());
21627 +}
21628 +
21629 +static int proc_virtual_info(char *buffer)
21630 +{
21631 +       return proc_vci(buffer);
21632 +}
21633 +
21634 +static int proc_virtual_status(char *buffer)
21635 +{
21636 +       return sprintf(buffer,
21637 +               "#CTotal:\t%d\n"
21638 +               "#CActive:\t%d\n"
21639 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21640 +               "#InitTask:\t%d\t%d %d\n",
21641 +               atomic_read(&vx_global_ctotal),
21642 +               atomic_read(&vx_global_cactive),
21643 +               atomic_read(&vs_global_nsproxy),
21644 +               atomic_read(&vs_global_fs),
21645 +               atomic_read(&vs_global_mnt_ns),
21646 +               atomic_read(&vs_global_uts_ns),
21647 +               atomic_read(&nr_ipc_ns),
21648 +               atomic_read(&vs_global_user_ns),
21649 +               atomic_read(&vs_global_pid_ns),
21650 +               atomic_read(&init_task.usage),
21651 +               atomic_read(&init_task.nsproxy->count),
21652 +               init_task.fs->users);
21653 +}
21654 +
21655 +
21656 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21657 +{
21658 +       int length;
21659 +
21660 +       length = sprintf(buffer,
21661 +               "ID:\t%d\n"
21662 +               "Info:\t%p\n"
21663 +               "Init:\t%d\n"
21664 +               "OOM:\t%lld\n",
21665 +               vxi->vx_id,
21666 +               vxi,
21667 +               vxi->vx_initpid,
21668 +               vxi->vx_badness_bias);
21669 +       return length;
21670 +}
21671 +
21672 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21673 +{
21674 +       char *orig = buffer;
21675 +
21676 +       buffer += sprintf(buffer,
21677 +               "UseCnt:\t%d\n"
21678 +               "Tasks:\t%d\n"
21679 +               "Flags:\t%016llx\n",
21680 +               atomic_read(&vxi->vx_usecnt),
21681 +               atomic_read(&vxi->vx_tasks),
21682 +               (unsigned long long)vxi->vx_flags);
21683 +
21684 +       buffer += sprintf(buffer, "BCaps:\t");
21685 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21686 +       buffer += sprintf(buffer, "\n");
21687 +
21688 +       buffer += sprintf(buffer,
21689 +               "CCaps:\t%016llx\n"
21690 +               "Spaces:\t%08lx %08lx\n",
21691 +               (unsigned long long)vxi->vx_ccaps,
21692 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21693 +       return buffer - orig;
21694 +}
21695 +
21696 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21697 +{
21698 +       return vx_info_proc_limit(&vxi->limit, buffer);
21699 +}
21700 +
21701 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21702 +{
21703 +       int cpu, length;
21704 +
21705 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21706 +       for_each_online_cpu(cpu) {
21707 +               length += vx_info_proc_sched_pc(
21708 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21709 +                       buffer + length, cpu);
21710 +       }
21711 +       return length;
21712 +}
21713 +
21714 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21715 +{
21716 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21717 +}
21718 +
21719 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21720 +{
21721 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21722 +}
21723 +
21724 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21725 +{
21726 +       int cpu, length;
21727 +
21728 +       vx_update_load(vxi);
21729 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21730 +       for_each_online_cpu(cpu) {
21731 +               length += vx_info_proc_cvirt_pc(
21732 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21733 +                       buffer + length, cpu);
21734 +       }
21735 +       return length;
21736 +}
21737 +
21738 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21739 +{
21740 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21741 +}
21742 +
21743 +
21744 +static int proc_virtnet_info(char *buffer)
21745 +{
21746 +       return proc_vci(buffer);
21747 +}
21748 +
21749 +static int proc_virtnet_status(char *buffer)
21750 +{
21751 +       return sprintf(buffer,
21752 +               "#CTotal:\t%d\n"
21753 +               "#CActive:\t%d\n",
21754 +               atomic_read(&nx_global_ctotal),
21755 +               atomic_read(&nx_global_cactive));
21756 +}
21757 +
21758 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21759 +{
21760 +       struct nx_addr_v4 *v4a;
21761 +#ifdef CONFIG_IPV6
21762 +       struct nx_addr_v6 *v6a;
21763 +#endif
21764 +       int length, i;
21765 +
21766 +       length = sprintf(buffer,
21767 +               "ID:\t%d\n"
21768 +               "Info:\t%p\n"
21769 +               "Bcast:\t" NIPQUAD_FMT "\n"
21770 +               "Lback:\t" NIPQUAD_FMT "\n",
21771 +               nxi->nx_id,
21772 +               nxi,
21773 +               NIPQUAD(nxi->v4_bcast.s_addr),
21774 +               NIPQUAD(nxi->v4_lback.s_addr));
21775 +
21776 +       if (!NX_IPV4(nxi))
21777 +               goto skip_v4;
21778 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21779 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21780 +                       i, NXAV4(v4a));
21781 +skip_v4:
21782 +#ifdef CONFIG_IPV6
21783 +       if (!NX_IPV6(nxi))
21784 +               goto skip_v6;
21785 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21786 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21787 +                       i, NXAV6(v6a));
21788 +skip_v6:
21789 +#endif
21790 +       return length;
21791 +}
21792 +
21793 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21794 +{
21795 +       int length;
21796 +
21797 +       length = sprintf(buffer,
21798 +               "UseCnt:\t%d\n"
21799 +               "Tasks:\t%d\n"
21800 +               "Flags:\t%016llx\n"
21801 +               "NCaps:\t%016llx\n",
21802 +               atomic_read(&nxi->nx_usecnt),
21803 +               atomic_read(&nxi->nx_tasks),
21804 +               (unsigned long long)nxi->nx_flags,
21805 +               (unsigned long long)nxi->nx_ncaps);
21806 +       return length;
21807 +}
21808 +
21809 +
21810 +
21811 +/* here the inode helpers */
21812 +
21813 +struct vs_entry {
21814 +       int len;
21815 +       char *name;
21816 +       mode_t mode;
21817 +       struct inode_operations *iop;
21818 +       struct file_operations *fop;
21819 +       union proc_op op;
21820 +};
21821 +
21822 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21823 +{
21824 +       struct inode *inode = new_inode(sb);
21825 +
21826 +       if (!inode)
21827 +               goto out;
21828 +
21829 +       inode->i_mode = p->mode;
21830 +       if (p->iop)
21831 +               inode->i_op = p->iop;
21832 +       if (p->fop)
21833 +               inode->i_fop = p->fop;
21834 +
21835 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21836 +       inode->i_flags |= S_IMMUTABLE;
21837 +
21838 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21839 +
21840 +       inode->i_uid = 0;
21841 +       inode->i_gid = 0;
21842 +       inode->i_tag = 0;
21843 +out:
21844 +       return inode;
21845 +}
21846 +
21847 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21848 +       struct dentry *dentry, int id, void *ptr)
21849 +{
21850 +       struct vs_entry *p = ptr;
21851 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21852 +       struct dentry *error = ERR_PTR(-EINVAL);
21853 +
21854 +       if (!inode)
21855 +               goto out;
21856 +
21857 +       PROC_I(inode)->op = p->op;
21858 +       PROC_I(inode)->fd = id;
21859 +       d_add(dentry, inode);
21860 +       error = NULL;
21861 +out:
21862 +       return error;
21863 +}
21864 +
21865 +/* Lookups */
21866 +
21867 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21868 +
21869 +/*
21870 + * Fill a directory entry.
21871 + *
21872 + * If possible create the dcache entry and derive our inode number and
21873 + * file type from dcache entry.
21874 + *
21875 + * Since all of the proc inode numbers are dynamically generated, the inode
21876 + * numbers do not exist until the inode is cache.  This means creating the
21877 + * the dcache entry in readdir is necessary to keep the inode numbers
21878 + * reported by readdir in sync with the inode numbers reported
21879 + * by stat.
21880 + */
21881 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21882 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21883 +{
21884 +       struct dentry *child, *dir = filp->f_dentry;
21885 +       struct inode *inode;
21886 +       struct qstr qname;
21887 +       ino_t ino = 0;
21888 +       unsigned type = DT_UNKNOWN;
21889 +
21890 +       qname.name = name;
21891 +       qname.len  = len;
21892 +       qname.hash = full_name_hash(name, len);
21893 +
21894 +       child = d_lookup(dir, &qname);
21895 +       if (!child) {
21896 +               struct dentry *new;
21897 +               new = d_alloc(dir, &qname);
21898 +               if (new) {
21899 +                       child = instantiate(dir->d_inode, new, id, ptr);
21900 +                       if (child)
21901 +                               dput(new);
21902 +                       else
21903 +                               child = new;
21904 +               }
21905 +       }
21906 +       if (!child || IS_ERR(child) || !child->d_inode)
21907 +               goto end_instantiate;
21908 +       inode = child->d_inode;
21909 +       if (inode) {
21910 +               ino = inode->i_ino;
21911 +               type = inode->i_mode >> 12;
21912 +       }
21913 +       dput(child);
21914 +end_instantiate:
21915 +       if (!ino)
21916 +               ino = find_inode_number(dir, &qname);
21917 +       if (!ino)
21918 +               ino = 1;
21919 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21920 +}
21921 +
21922 +
21923 +
21924 +/* get and revalidate vx_info/xid */
21925 +
21926 +static inline
21927 +struct vx_info *get_proc_vx_info(struct inode *inode)
21928 +{
21929 +       return lookup_vx_info(PROC_I(inode)->fd);
21930 +}
21931 +
21932 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21933 +{
21934 +       struct inode *inode = dentry->d_inode;
21935 +       xid_t xid = PROC_I(inode)->fd;
21936 +
21937 +       if (!xid || xid_is_hashed(xid))
21938 +               return 1;
21939 +       d_drop(dentry);
21940 +       return 0;
21941 +}
21942 +
21943 +
21944 +/* get and revalidate nx_info/nid */
21945 +
21946 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21947 +{
21948 +       struct inode *inode = dentry->d_inode;
21949 +       nid_t nid = PROC_I(inode)->fd;
21950 +
21951 +       if (!nid || nid_is_hashed(nid))
21952 +               return 1;
21953 +       d_drop(dentry);
21954 +       return 0;
21955 +}
21956 +
21957 +
21958 +
21959 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21960 +
21961 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21962 +                         size_t count, loff_t *ppos)
21963 +{
21964 +       struct inode *inode = file->f_dentry->d_inode;
21965 +       unsigned long page;
21966 +       ssize_t length = 0;
21967 +
21968 +       if (count > PROC_BLOCK_SIZE)
21969 +               count = PROC_BLOCK_SIZE;
21970 +
21971 +       /* fade that out as soon as stable */
21972 +       WARN_ON(PROC_I(inode)->fd);
21973 +
21974 +       if (!(page = __get_free_page(GFP_KERNEL)))
21975 +               return -ENOMEM;
21976 +
21977 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21978 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21979 +
21980 +       if (length >= 0)
21981 +               length = simple_read_from_buffer(buf, count, ppos,
21982 +                       (char *)page, length);
21983 +
21984 +       free_page(page);
21985 +       return length;
21986 +}
21987 +
21988 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21989 +                         size_t count, loff_t *ppos)
21990 +{
21991 +       struct inode *inode = file->f_dentry->d_inode;
21992 +       struct vx_info *vxi = NULL;
21993 +       xid_t xid = PROC_I(inode)->fd;
21994 +       unsigned long page;
21995 +       ssize_t length = 0;
21996 +
21997 +       if (count > PROC_BLOCK_SIZE)
21998 +               count = PROC_BLOCK_SIZE;
21999 +
22000 +       /* fade that out as soon as stable */
22001 +       WARN_ON(!xid);
22002 +       vxi = lookup_vx_info(xid);
22003 +       if (!vxi)
22004 +               goto out;
22005 +
22006 +       length = -ENOMEM;
22007 +       if (!(page = __get_free_page(GFP_KERNEL)))
22008 +               goto out_put;
22009 +
22010 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22011 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22012 +
22013 +       if (length >= 0)
22014 +               length = simple_read_from_buffer(buf, count, ppos,
22015 +                       (char *)page, length);
22016 +
22017 +       free_page(page);
22018 +out_put:
22019 +       put_vx_info(vxi);
22020 +out:
22021 +       return length;
22022 +}
22023 +
22024 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22025 +                         size_t count, loff_t *ppos)
22026 +{
22027 +       struct inode *inode = file->f_dentry->d_inode;
22028 +       struct nx_info *nxi = NULL;
22029 +       nid_t nid = PROC_I(inode)->fd;
22030 +       unsigned long page;
22031 +       ssize_t length = 0;
22032 +
22033 +       if (count > PROC_BLOCK_SIZE)
22034 +               count = PROC_BLOCK_SIZE;
22035 +
22036 +       /* fade that out as soon as stable */
22037 +       WARN_ON(!nid);
22038 +       nxi = lookup_nx_info(nid);
22039 +       if (!nxi)
22040 +               goto out;
22041 +
22042 +       length = -ENOMEM;
22043 +       if (!(page = __get_free_page(GFP_KERNEL)))
22044 +               goto out_put;
22045 +
22046 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22047 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22048 +
22049 +       if (length >= 0)
22050 +               length = simple_read_from_buffer(buf, count, ppos,
22051 +                       (char *)page, length);
22052 +
22053 +       free_page(page);
22054 +out_put:
22055 +       put_nx_info(nxi);
22056 +out:
22057 +       return length;
22058 +}
22059 +
22060 +
22061 +
22062 +/* here comes the lower level */
22063 +
22064 +
22065 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22066 +       .len  = sizeof(NAME) - 1,       \
22067 +       .name = (NAME),                 \
22068 +       .mode = MODE,                   \
22069 +       .iop  = IOP,                    \
22070 +       .fop  = FOP,                    \
22071 +       .op   = OP,                     \
22072 +}
22073 +
22074 +
22075 +#define DIR(NAME, MODE, OTYPE)                         \
22076 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22077 +               &proc_ ## OTYPE ## _inode_operations,   \
22078 +               &proc_ ## OTYPE ## _file_operations, { } )
22079 +
22080 +#define INF(NAME, MODE, OTYPE)                         \
22081 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22082 +               &proc_vs_info_file_operations,          \
22083 +               { .proc_vs_read = &proc_##OTYPE } )
22084 +
22085 +#define VINF(NAME, MODE, OTYPE)                                \
22086 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22087 +               &proc_vx_info_file_operations,          \
22088 +               { .proc_vxi_read = &proc_##OTYPE } )
22089 +
22090 +#define NINF(NAME, MODE, OTYPE)                                \
22091 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22092 +               &proc_nx_info_file_operations,          \
22093 +               { .proc_nxi_read = &proc_##OTYPE } )
22094 +
22095 +
22096 +static struct file_operations proc_vs_info_file_operations = {
22097 +       .read =         proc_vs_info_read,
22098 +};
22099 +
22100 +static struct file_operations proc_vx_info_file_operations = {
22101 +       .read =         proc_vx_info_read,
22102 +};
22103 +
22104 +static struct dentry_operations proc_xid_dentry_operations = {
22105 +       .d_revalidate = proc_xid_revalidate,
22106 +};
22107 +
22108 +static struct vs_entry vx_base_stuff[] = {
22109 +       VINF("info",    S_IRUGO, vxi_info),
22110 +       VINF("status",  S_IRUGO, vxi_status),
22111 +       VINF("limit",   S_IRUGO, vxi_limit),
22112 +       VINF("sched",   S_IRUGO, vxi_sched),
22113 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
22114 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
22115 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22116 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22117 +       {}
22118 +};
22119 +
22120 +
22121 +
22122 +
22123 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22124 +       struct dentry *dentry, int id, void *ptr)
22125 +{
22126 +       dentry->d_op = &proc_xid_dentry_operations;
22127 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22128 +}
22129 +
22130 +static struct dentry *proc_xid_lookup(struct inode *dir,
22131 +       struct dentry *dentry, struct nameidata *nd)
22132 +{
22133 +       struct vs_entry *p = vx_base_stuff;
22134 +       struct dentry *error = ERR_PTR(-ENOENT);
22135 +
22136 +       for (; p->name; p++) {
22137 +               if (p->len != dentry->d_name.len)
22138 +                       continue;
22139 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22140 +                       break;
22141 +       }
22142 +       if (!p->name)
22143 +               goto out;
22144 +
22145 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22146 +out:
22147 +       return error;
22148 +}
22149 +
22150 +static int proc_xid_readdir(struct file *filp,
22151 +       void *dirent, filldir_t filldir)
22152 +{
22153 +       struct dentry *dentry = filp->f_dentry;
22154 +       struct inode *inode = dentry->d_inode;
22155 +       struct vs_entry *p = vx_base_stuff;
22156 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22157 +       int pos, index;
22158 +       u64 ino;
22159 +
22160 +       pos = filp->f_pos;
22161 +       switch (pos) {
22162 +       case 0:
22163 +               ino = inode->i_ino;
22164 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22165 +                       goto out;
22166 +               pos++;
22167 +               /* fall through */
22168 +       case 1:
22169 +               ino = parent_ino(dentry);
22170 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22171 +                       goto out;
22172 +               pos++;
22173 +               /* fall through */
22174 +       default:
22175 +               index = pos - 2;
22176 +               if (index >= size)
22177 +                       goto out;
22178 +               for (p += index; p->name; p++) {
22179 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22180 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22181 +                               goto out;
22182 +                       pos++;
22183 +               }
22184 +       }
22185 +out:
22186 +       filp->f_pos = pos;
22187 +       return 1;
22188 +}
22189 +
22190 +
22191 +
22192 +static struct file_operations proc_nx_info_file_operations = {
22193 +       .read =         proc_nx_info_read,
22194 +};
22195 +
22196 +static struct dentry_operations proc_nid_dentry_operations = {
22197 +       .d_revalidate = proc_nid_revalidate,
22198 +};
22199 +
22200 +static struct vs_entry nx_base_stuff[] = {
22201 +       NINF("info",    S_IRUGO, nxi_info),
22202 +       NINF("status",  S_IRUGO, nxi_status),
22203 +       {}
22204 +};
22205 +
22206 +
22207 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22208 +       struct dentry *dentry, int id, void *ptr)
22209 +{
22210 +       dentry->d_op = &proc_nid_dentry_operations;
22211 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22212 +}
22213 +
22214 +static struct dentry *proc_nid_lookup(struct inode *dir,
22215 +       struct dentry *dentry, struct nameidata *nd)
22216 +{
22217 +       struct vs_entry *p = nx_base_stuff;
22218 +       struct dentry *error = ERR_PTR(-ENOENT);
22219 +
22220 +       for (; p->name; p++) {
22221 +               if (p->len != dentry->d_name.len)
22222 +                       continue;
22223 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22224 +                       break;
22225 +       }
22226 +       if (!p->name)
22227 +               goto out;
22228 +
22229 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22230 +out:
22231 +       return error;
22232 +}
22233 +
22234 +static int proc_nid_readdir(struct file *filp,
22235 +       void *dirent, filldir_t filldir)
22236 +{
22237 +       struct dentry *dentry = filp->f_dentry;
22238 +       struct inode *inode = dentry->d_inode;
22239 +       struct vs_entry *p = nx_base_stuff;
22240 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22241 +       int pos, index;
22242 +       u64 ino;
22243 +
22244 +       pos = filp->f_pos;
22245 +       switch (pos) {
22246 +       case 0:
22247 +               ino = inode->i_ino;
22248 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22249 +                       goto out;
22250 +               pos++;
22251 +               /* fall through */
22252 +       case 1:
22253 +               ino = parent_ino(dentry);
22254 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22255 +                       goto out;
22256 +               pos++;
22257 +               /* fall through */
22258 +       default:
22259 +               index = pos - 2;
22260 +               if (index >= size)
22261 +                       goto out;
22262 +               for (p += index; p->name; p++) {
22263 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22264 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22265 +                               goto out;
22266 +                       pos++;
22267 +               }
22268 +       }
22269 +out:
22270 +       filp->f_pos = pos;
22271 +       return 1;
22272 +}
22273 +
22274 +
22275 +#define MAX_MULBY10    ((~0U - 9) / 10)
22276 +
22277 +static inline int atovid(const char *str, int len)
22278 +{
22279 +       int vid, c;
22280 +
22281 +       vid = 0;
22282 +       while (len-- > 0) {
22283 +               c = *str - '0';
22284 +               str++;
22285 +               if (c > 9)
22286 +                       return -1;
22287 +               if (vid >= MAX_MULBY10)
22288 +                       return -1;
22289 +               vid *= 10;
22290 +               vid += c;
22291 +               if (!vid)
22292 +                       return -1;
22293 +       }
22294 +       return vid;
22295 +}
22296 +
22297 +/* now the upper level (virtual) */
22298 +
22299 +
22300 +static struct file_operations proc_xid_file_operations = {
22301 +       .read =         generic_read_dir,
22302 +       .readdir =      proc_xid_readdir,
22303 +};
22304 +
22305 +static struct inode_operations proc_xid_inode_operations = {
22306 +       .lookup =       proc_xid_lookup,
22307 +};
22308 +
22309 +static struct vs_entry vx_virtual_stuff[] = {
22310 +       INF("info",     S_IRUGO, virtual_info),
22311 +       INF("status",   S_IRUGO, virtual_status),
22312 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22313 +};
22314 +
22315 +
22316 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22317 +       struct dentry *dentry, struct nameidata *nd)
22318 +{
22319 +       struct vs_entry *p = vx_virtual_stuff;
22320 +       struct dentry *error = ERR_PTR(-ENOENT);
22321 +       int id = 0;
22322 +
22323 +       for (; p->name; p++) {
22324 +               if (p->len != dentry->d_name.len)
22325 +                       continue;
22326 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22327 +                       break;
22328 +       }
22329 +       if (p->name)
22330 +               goto instantiate;
22331 +
22332 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22333 +       if ((id < 0) || !xid_is_hashed(id))
22334 +               goto out;
22335 +
22336 +instantiate:
22337 +       error = proc_xid_instantiate(dir, dentry, id, p);
22338 +out:
22339 +       return error;
22340 +}
22341 +
22342 +static struct file_operations proc_nid_file_operations = {
22343 +       .read =         generic_read_dir,
22344 +       .readdir =      proc_nid_readdir,
22345 +};
22346 +
22347 +static struct inode_operations proc_nid_inode_operations = {
22348 +       .lookup =       proc_nid_lookup,
22349 +};
22350 +
22351 +static struct vs_entry nx_virtnet_stuff[] = {
22352 +       INF("info",     S_IRUGO, virtnet_info),
22353 +       INF("status",   S_IRUGO, virtnet_status),
22354 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22355 +};
22356 +
22357 +
22358 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22359 +       struct dentry *dentry, struct nameidata *nd)
22360 +{
22361 +       struct vs_entry *p = nx_virtnet_stuff;
22362 +       struct dentry *error = ERR_PTR(-ENOENT);
22363 +       int id = 0;
22364 +
22365 +       for (; p->name; p++) {
22366 +               if (p->len != dentry->d_name.len)
22367 +                       continue;
22368 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22369 +                       break;
22370 +       }
22371 +       if (p->name)
22372 +               goto instantiate;
22373 +
22374 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22375 +       if ((id < 0) || !nid_is_hashed(id))
22376 +               goto out;
22377 +
22378 +instantiate:
22379 +       error = proc_nid_instantiate(dir, dentry, id, p);
22380 +out:
22381 +       return error;
22382 +}
22383 +
22384 +
22385 +#define PROC_MAXVIDS 32
22386 +
22387 +int proc_virtual_readdir(struct file *filp,
22388 +       void *dirent, filldir_t filldir)
22389 +{
22390 +       struct dentry *dentry = filp->f_dentry;
22391 +       struct inode *inode = dentry->d_inode;
22392 +       struct vs_entry *p = vx_virtual_stuff;
22393 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22394 +       int pos, index;
22395 +       unsigned int xid_array[PROC_MAXVIDS];
22396 +       char buf[PROC_NUMBUF];
22397 +       unsigned int nr_xids, i;
22398 +       u64 ino;
22399 +
22400 +       pos = filp->f_pos;
22401 +       switch (pos) {
22402 +       case 0:
22403 +               ino = inode->i_ino;
22404 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22405 +                       goto out;
22406 +               pos++;
22407 +               /* fall through */
22408 +       case 1:
22409 +               ino = parent_ino(dentry);
22410 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22411 +                       goto out;
22412 +               pos++;
22413 +               /* fall through */
22414 +       default:
22415 +               index = pos - 2;
22416 +               if (index >= size)
22417 +                       goto entries;
22418 +               for (p += index; p->name; p++) {
22419 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22420 +                               vs_proc_instantiate, 0, p))
22421 +                               goto out;
22422 +                       pos++;
22423 +               }
22424 +       entries:
22425 +               index = pos - size;
22426 +               p = &vx_virtual_stuff[size - 1];
22427 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22428 +               for (i = 0; i < nr_xids; i++) {
22429 +                       int n, xid = xid_array[i];
22430 +                       unsigned int j = PROC_NUMBUF;
22431 +
22432 +                       n = xid;
22433 +                       do
22434 +                               buf[--j] = '0' + (n % 10);
22435 +                       while (n /= 10);
22436 +
22437 +                       if (proc_fill_cache(filp, dirent, filldir,
22438 +                               buf + j, PROC_NUMBUF - j,
22439 +                               vs_proc_instantiate, xid, p))
22440 +                               goto out;
22441 +                       pos++;
22442 +               }
22443 +       }
22444 +out:
22445 +       filp->f_pos = pos;
22446 +       return 0;
22447 +}
22448 +
22449 +static int proc_virtual_getattr(struct vfsmount *mnt,
22450 +       struct dentry *dentry, struct kstat *stat)
22451 +{
22452 +       struct inode *inode = dentry->d_inode;
22453 +
22454 +       generic_fillattr(inode, stat);
22455 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22456 +       return 0;
22457 +}
22458 +
22459 +static struct file_operations proc_virtual_dir_operations = {
22460 +       .read =         generic_read_dir,
22461 +       .readdir =      proc_virtual_readdir,
22462 +};
22463 +
22464 +static struct inode_operations proc_virtual_dir_inode_operations = {
22465 +       .getattr =      proc_virtual_getattr,
22466 +       .lookup =       proc_virtual_lookup,
22467 +};
22468 +
22469 +
22470 +
22471 +
22472 +
22473 +int proc_virtnet_readdir(struct file *filp,
22474 +       void *dirent, filldir_t filldir)
22475 +{
22476 +       struct dentry *dentry = filp->f_dentry;
22477 +       struct inode *inode = dentry->d_inode;
22478 +       struct vs_entry *p = nx_virtnet_stuff;
22479 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22480 +       int pos, index;
22481 +       unsigned int nid_array[PROC_MAXVIDS];
22482 +       char buf[PROC_NUMBUF];
22483 +       unsigned int nr_nids, i;
22484 +       u64 ino;
22485 +
22486 +       pos = filp->f_pos;
22487 +       switch (pos) {
22488 +       case 0:
22489 +               ino = inode->i_ino;
22490 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22491 +                       goto out;
22492 +               pos++;
22493 +               /* fall through */
22494 +       case 1:
22495 +               ino = parent_ino(dentry);
22496 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22497 +                       goto out;
22498 +               pos++;
22499 +               /* fall through */
22500 +       default:
22501 +               index = pos - 2;
22502 +               if (index >= size)
22503 +                       goto entries;
22504 +               for (p += index; p->name; p++) {
22505 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22506 +                               vs_proc_instantiate, 0, p))
22507 +                               goto out;
22508 +                       pos++;
22509 +               }
22510 +       entries:
22511 +               index = pos - size;
22512 +               p = &nx_virtnet_stuff[size - 1];
22513 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22514 +               for (i = 0; i < nr_nids; i++) {
22515 +                       int n, nid = nid_array[i];
22516 +                       unsigned int j = PROC_NUMBUF;
22517 +
22518 +                       n = nid;
22519 +                       do
22520 +                               buf[--j] = '0' + (n % 10);
22521 +                       while (n /= 10);
22522 +
22523 +                       if (proc_fill_cache(filp, dirent, filldir,
22524 +                               buf + j, PROC_NUMBUF - j,
22525 +                               vs_proc_instantiate, nid, p))
22526 +                               goto out;
22527 +                       pos++;
22528 +               }
22529 +       }
22530 +out:
22531 +       filp->f_pos = pos;
22532 +       return 0;
22533 +}
22534 +
22535 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22536 +       struct dentry *dentry, struct kstat *stat)
22537 +{
22538 +       struct inode *inode = dentry->d_inode;
22539 +
22540 +       generic_fillattr(inode, stat);
22541 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22542 +       return 0;
22543 +}
22544 +
22545 +static struct file_operations proc_virtnet_dir_operations = {
22546 +       .read =         generic_read_dir,
22547 +       .readdir =      proc_virtnet_readdir,
22548 +};
22549 +
22550 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22551 +       .getattr =      proc_virtnet_getattr,
22552 +       .lookup =       proc_virtnet_lookup,
22553 +};
22554 +
22555 +
22556 +
22557 +void proc_vx_init(void)
22558 +{
22559 +       struct proc_dir_entry *ent;
22560 +
22561 +       ent = proc_mkdir("virtual", 0);
22562 +       if (ent) {
22563 +               ent->proc_fops = &proc_virtual_dir_operations;
22564 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22565 +       }
22566 +       proc_virtual = ent;
22567 +
22568 +       ent = proc_mkdir("virtnet", 0);
22569 +       if (ent) {
22570 +               ent->proc_fops = &proc_virtnet_dir_operations;
22571 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22572 +       }
22573 +       proc_virtnet = ent;
22574 +}
22575 +
22576 +
22577 +
22578 +
22579 +/* per pid info */
22580 +
22581 +
22582 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22583 +{
22584 +       struct vx_info *vxi;
22585 +       char *orig = buffer;
22586 +
22587 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22588 +
22589 +       vxi = task_get_vx_info(p);
22590 +       if (!vxi)
22591 +               goto out;
22592 +
22593 +       buffer += sprintf(buffer, "BCaps:\t");
22594 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22595 +       buffer += sprintf(buffer, "\n");
22596 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22597 +               (unsigned long long)vxi->vx_ccaps);
22598 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22599 +               (unsigned long long)vxi->vx_flags);
22600 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22601 +
22602 +       put_vx_info(vxi);
22603 +out:
22604 +       return buffer - orig;
22605 +}
22606 +
22607 +
22608 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22609 +{
22610 +       struct nx_info *nxi;
22611 +       struct nx_addr_v4 *v4a;
22612 +#ifdef CONFIG_IPV6
22613 +       struct nx_addr_v6 *v6a;
22614 +#endif
22615 +       char *orig = buffer;
22616 +       int i;
22617 +
22618 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22619 +
22620 +       nxi = task_get_nx_info(p);
22621 +       if (!nxi)
22622 +               goto out;
22623 +
22624 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22625 +               (unsigned long long)nxi->nx_ncaps);
22626 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22627 +               (unsigned long long)nxi->nx_flags);
22628 +
22629 +       buffer += sprintf(buffer,
22630 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22631 +               NIPQUAD(nxi->v4_bcast.s_addr));
22632 +       buffer += sprintf (buffer,
22633 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22634 +               NIPQUAD(nxi->v4_lback.s_addr));
22635 +       if (!NX_IPV4(nxi))
22636 +               goto skip_v4;
22637 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22638 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22639 +                       i, NXAV4(v4a));
22640 +skip_v4:
22641 +#ifdef CONFIG_IPV6
22642 +       if (!NX_IPV6(nxi))
22643 +               goto skip_v6;
22644 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22645 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22646 +                       i, NXAV6(v6a));
22647 +skip_v6:
22648 +#endif
22649 +       put_nx_info(nxi);
22650 +out:
22651 +       return buffer - orig;
22652 +}
22653 +
22654 diff -NurpP --minimal linux-2.6.37/kernel/vserver/sched.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/sched.c
22655 --- linux-2.6.37/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
22656 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/sched.c  2010-11-23 02:09:41.000000000 +0100
22657 @@ -0,0 +1,82 @@
22658 +/*
22659 + *  linux/kernel/vserver/sched.c
22660 + *
22661 + *  Virtual Server: Scheduler Support
22662 + *
22663 + *  Copyright (C) 2004-2010  Herbert Pötzl
22664 + *
22665 + *  V0.01  adapted Sam Vilains version to 2.6.3
22666 + *  V0.02  removed legacy interface
22667 + *  V0.03  changed vcmds to vxi arg
22668 + *  V0.04  removed older and legacy interfaces
22669 + *  V0.05  removed scheduler code/commands
22670 + *
22671 + */
22672 +
22673 +#include <linux/vs_context.h>
22674 +#include <linux/vs_sched.h>
22675 +#include <linux/vserver/sched_cmd.h>
22676 +
22677 +#include <asm/uaccess.h>
22678 +
22679 +
22680 +void vx_update_sched_param(struct _vx_sched *sched,
22681 +       struct _vx_sched_pc *sched_pc)
22682 +{
22683 +       sched_pc->prio_bias = sched->prio_bias;
22684 +}
22685 +
22686 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22687 +{
22688 +       int cpu;
22689 +
22690 +       if (data->prio_bias > MAX_PRIO_BIAS)
22691 +               data->prio_bias = MAX_PRIO_BIAS;
22692 +       if (data->prio_bias < MIN_PRIO_BIAS)
22693 +               data->prio_bias = MIN_PRIO_BIAS;
22694 +
22695 +       if (data->cpu_id != ~0) {
22696 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22697 +               cpus_and(vxi->sched.update, cpu_online_map,
22698 +                       vxi->sched.update);
22699 +       } else
22700 +               vxi->sched.update = cpu_online_map;
22701 +
22702 +       for_each_cpu_mask(cpu, vxi->sched.update)
22703 +               vx_update_sched_param(&vxi->sched,
22704 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22705 +       return 0;
22706 +}
22707 +
22708 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22709 +{
22710 +       struct vcmd_prio_bias vc_data;
22711 +
22712 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22713 +               return -EFAULT;
22714 +
22715 +       return do_set_prio_bias(vxi, &vc_data);
22716 +}
22717 +
22718 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22719 +{
22720 +       struct vcmd_prio_bias vc_data;
22721 +       struct _vx_sched_pc *pcd;
22722 +       int cpu;
22723 +
22724 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22725 +               return -EFAULT;
22726 +
22727 +       cpu = vc_data.cpu_id;
22728 +
22729 +       if (!cpu_possible(cpu))
22730 +               return -EINVAL;
22731 +
22732 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22733 +       vc_data.prio_bias = pcd->prio_bias;
22734 +
22735 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22736 +               return -EFAULT;
22737 +       return 0;
22738 +}
22739 +
22740 diff -NurpP --minimal linux-2.6.37/kernel/vserver/sched_init.h linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/sched_init.h
22741 --- linux-2.6.37/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
22742 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/sched_init.h     2010-11-23 02:09:41.000000000 +0100
22743 @@ -0,0 +1,27 @@
22744 +
22745 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22746 +{
22747 +       /* scheduling; hard code starting values as constants */
22748 +       sched->prio_bias = 0;
22749 +}
22750 +
22751 +static inline
22752 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22753 +{
22754 +       sched_pc->prio_bias = 0;
22755 +
22756 +       sched_pc->user_ticks = 0;
22757 +       sched_pc->sys_ticks = 0;
22758 +       sched_pc->hold_ticks = 0;
22759 +}
22760 +
22761 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22762 +{
22763 +       return;
22764 +}
22765 +
22766 +static inline
22767 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22768 +{
22769 +       return;
22770 +}
22771 diff -NurpP --minimal linux-2.6.37/kernel/vserver/sched_proc.h linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/sched_proc.h
22772 --- linux-2.6.37/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
22773 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/sched_proc.h     2010-11-23 02:09:41.000000000 +0100
22774 @@ -0,0 +1,32 @@
22775 +#ifndef _VX_SCHED_PROC_H
22776 +#define _VX_SCHED_PROC_H
22777 +
22778 +
22779 +static inline
22780 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22781 +{
22782 +       int length = 0;
22783 +
22784 +       length += sprintf(buffer,
22785 +               "PrioBias:\t%8d\n",
22786 +               sched->prio_bias);
22787 +       return length;
22788 +}
22789 +
22790 +static inline
22791 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22792 +       char *buffer, int cpu)
22793 +{
22794 +       int length = 0;
22795 +
22796 +       length += sprintf(buffer + length,
22797 +               "cpu %d: %lld %lld %lld", cpu,
22798 +               (unsigned long long)sched_pc->user_ticks,
22799 +               (unsigned long long)sched_pc->sys_ticks,
22800 +               (unsigned long long)sched_pc->hold_ticks);
22801 +       length += sprintf(buffer + length,
22802 +               " %d\n", sched_pc->prio_bias);
22803 +       return length;
22804 +}
22805 +
22806 +#endif /* _VX_SCHED_PROC_H */
22807 diff -NurpP --minimal linux-2.6.37/kernel/vserver/signal.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/signal.c
22808 --- linux-2.6.37/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
22809 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/signal.c 2010-11-23 02:09:41.000000000 +0100
22810 @@ -0,0 +1,132 @@
22811 +/*
22812 + *  linux/kernel/vserver/signal.c
22813 + *
22814 + *  Virtual Server: Signal Support
22815 + *
22816 + *  Copyright (C) 2003-2007  Herbert Pötzl
22817 + *
22818 + *  V0.01  broken out from vcontext V0.05
22819 + *  V0.02  changed vcmds to vxi arg
22820 + *  V0.03  adjusted siginfo for kill
22821 + *
22822 + */
22823 +
22824 +#include <asm/uaccess.h>
22825 +
22826 +#include <linux/vs_context.h>
22827 +#include <linux/vs_pid.h>
22828 +#include <linux/vserver/signal_cmd.h>
22829 +
22830 +
22831 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22832 +{
22833 +       int retval, count = 0;
22834 +       struct task_struct *p;
22835 +       struct siginfo *sip = SEND_SIG_PRIV;
22836 +
22837 +       retval = -ESRCH;
22838 +       vxdprintk(VXD_CBIT(misc, 4),
22839 +               "vx_info_kill(%p[#%d],%d,%d)*",
22840 +               vxi, vxi->vx_id, pid, sig);
22841 +       read_lock(&tasklist_lock);
22842 +       switch (pid) {
22843 +       case  0:
22844 +       case -1:
22845 +               for_each_process(p) {
22846 +                       int err = 0;
22847 +
22848 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22849 +                               (pid && vxi->vx_initpid == p->pid))
22850 +                               continue;
22851 +
22852 +                       err = group_send_sig_info(sig, sip, p);
22853 +                       ++count;
22854 +                       if (err != -EPERM)
22855 +                               retval = err;
22856 +               }
22857 +               break;
22858 +
22859 +       case 1:
22860 +               if (vxi->vx_initpid) {
22861 +                       pid = vxi->vx_initpid;
22862 +                       /* for now, only SIGINT to private init ... */
22863 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22864 +                               /* ... as long as there are tasks left */
22865 +                               (atomic_read(&vxi->vx_tasks) > 1))
22866 +                               sig = SIGINT;
22867 +               }
22868 +               /* fallthrough */
22869 +       default:
22870 +               p = find_task_by_real_pid(pid);
22871 +               if (p) {
22872 +                       if (vx_task_xid(p) == vxi->vx_id)
22873 +                               retval = group_send_sig_info(sig, sip, p);
22874 +               }
22875 +               break;
22876 +       }
22877 +       read_unlock(&tasklist_lock);
22878 +       vxdprintk(VXD_CBIT(misc, 4),
22879 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22880 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22881 +       return retval;
22882 +}
22883 +
22884 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22885 +{
22886 +       struct vcmd_ctx_kill_v0 vc_data;
22887 +
22888 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22889 +               return -EFAULT;
22890 +
22891 +       /* special check to allow guest shutdown */
22892 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22893 +               /* forbid killall pid=0 when init is present */
22894 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22895 +               (vc_data.pid > 1)))
22896 +               return -EACCES;
22897 +
22898 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22899 +}
22900 +
22901 +
22902 +static int __wait_exit(struct vx_info *vxi)
22903 +{
22904 +       DECLARE_WAITQUEUE(wait, current);
22905 +       int ret = 0;
22906 +
22907 +       add_wait_queue(&vxi->vx_wait, &wait);
22908 +       set_current_state(TASK_INTERRUPTIBLE);
22909 +
22910 +wait:
22911 +       if (vx_info_state(vxi,
22912 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22913 +               goto out;
22914 +       if (signal_pending(current)) {
22915 +               ret = -ERESTARTSYS;
22916 +               goto out;
22917 +       }
22918 +       schedule();
22919 +       goto wait;
22920 +
22921 +out:
22922 +       set_current_state(TASK_RUNNING);
22923 +       remove_wait_queue(&vxi->vx_wait, &wait);
22924 +       return ret;
22925 +}
22926 +
22927 +
22928 +
22929 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22930 +{
22931 +       struct vcmd_wait_exit_v0 vc_data;
22932 +       int ret;
22933 +
22934 +       ret = __wait_exit(vxi);
22935 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22936 +       vc_data.exit_code = vxi->exit_code;
22937 +
22938 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22939 +               ret = -EFAULT;
22940 +       return ret;
22941 +}
22942 +
22943 diff -NurpP --minimal linux-2.6.37/kernel/vserver/space.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/space.c
22944 --- linux-2.6.37/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
22945 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/space.c  2011-01-31 21:05:40.000000000 +0100
22946 @@ -0,0 +1,438 @@
22947 +/*
22948 + *  linux/kernel/vserver/space.c
22949 + *
22950 + *  Virtual Server: Context Space Support
22951 + *
22952 + *  Copyright (C) 2003-2010  Herbert Pötzl
22953 + *
22954 + *  V0.01  broken out from context.c 0.07
22955 + *  V0.02  added task locking for namespace
22956 + *  V0.03  broken out vx_enter_namespace
22957 + *  V0.04  added *space support and commands
22958 + *  V0.05  added credential support
22959 + *
22960 + */
22961 +
22962 +#include <linux/utsname.h>
22963 +#include <linux/nsproxy.h>
22964 +#include <linux/err.h>
22965 +#include <linux/fs_struct.h>
22966 +#include <linux/cred.h>
22967 +#include <asm/uaccess.h>
22968 +
22969 +#include <linux/vs_context.h>
22970 +#include <linux/vserver/space.h>
22971 +#include <linux/vserver/space_cmd.h>
22972 +
22973 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22974 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22975 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22976 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22977 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22978 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22979 +
22980 +
22981 +/* namespace functions */
22982 +
22983 +#include <linux/mnt_namespace.h>
22984 +#include <linux/user_namespace.h>
22985 +#include <linux/pid_namespace.h>
22986 +#include <linux/ipc_namespace.h>
22987 +#include <net/net_namespace.h>
22988 +
22989 +
22990 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22991 +       .mask = CLONE_FS |
22992 +               CLONE_NEWNS |
22993 +               CLONE_NEWUTS |
22994 +               CLONE_NEWIPC |
22995 +               CLONE_NEWUSER |
22996 +               0
22997 +};
22998 +
22999 +static const struct vcmd_space_mask_v1 space_mask = {
23000 +       .mask = CLONE_FS |
23001 +               CLONE_NEWNS |
23002 +               CLONE_NEWUTS |
23003 +               CLONE_NEWIPC |
23004 +               CLONE_NEWUSER |
23005 +#ifdef CONFIG_PID_NS
23006 +               CLONE_NEWPID |
23007 +#endif
23008 +#ifdef CONFIG_NET_NS
23009 +               CLONE_NEWNET |
23010 +#endif
23011 +               0
23012 +};
23013 +
23014 +static const struct vcmd_space_mask_v1 default_space_mask = {
23015 +       .mask = CLONE_FS |
23016 +               CLONE_NEWNS |
23017 +               CLONE_NEWUTS |
23018 +               CLONE_NEWIPC |
23019 +               CLONE_NEWUSER |
23020 +#ifdef CONFIG_PID_NS
23021 +//             CLONE_NEWPID |
23022 +#endif
23023 +               0
23024 +};
23025 +
23026 +/*
23027 + *     build a new nsproxy mix
23028 + *      assumes that both proxies are 'const'
23029 + *     does not touch nsproxy refcounts
23030 + *     will hold a reference on the result.
23031 + */
23032 +
23033 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
23034 +       struct nsproxy *new_nsproxy, unsigned long mask)
23035 +{
23036 +       struct mnt_namespace *old_ns;
23037 +       struct uts_namespace *old_uts;
23038 +       struct ipc_namespace *old_ipc;
23039 +#ifdef CONFIG_PID_NS
23040 +       struct pid_namespace *old_pid;
23041 +#endif
23042 +#ifdef CONFIG_NET_NS
23043 +       struct net *old_net;
23044 +#endif
23045 +       struct nsproxy *nsproxy;
23046 +
23047 +       nsproxy = copy_nsproxy(old_nsproxy);
23048 +       if (!nsproxy)
23049 +               goto out;
23050 +
23051 +       if (mask & CLONE_NEWNS) {
23052 +               old_ns = nsproxy->mnt_ns;
23053 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
23054 +               if (nsproxy->mnt_ns)
23055 +                       get_mnt_ns(nsproxy->mnt_ns);
23056 +       } else
23057 +               old_ns = NULL;
23058 +
23059 +       if (mask & CLONE_NEWUTS) {
23060 +               old_uts = nsproxy->uts_ns;
23061 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
23062 +               if (nsproxy->uts_ns)
23063 +                       get_uts_ns(nsproxy->uts_ns);
23064 +       } else
23065 +               old_uts = NULL;
23066 +
23067 +       if (mask & CLONE_NEWIPC) {
23068 +               old_ipc = nsproxy->ipc_ns;
23069 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
23070 +               if (nsproxy->ipc_ns)
23071 +                       get_ipc_ns(nsproxy->ipc_ns);
23072 +       } else
23073 +               old_ipc = NULL;
23074 +
23075 +#ifdef CONFIG_PID_NS
23076 +       if (mask & CLONE_NEWPID) {
23077 +               old_pid = nsproxy->pid_ns;
23078 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23079 +               if (nsproxy->pid_ns)
23080 +                       get_pid_ns(nsproxy->pid_ns);
23081 +       } else
23082 +               old_pid = NULL;
23083 +#endif
23084 +#ifdef CONFIG_NET_NS
23085 +       if (mask & CLONE_NEWNET) {
23086 +               old_net = nsproxy->net_ns;
23087 +               nsproxy->net_ns = new_nsproxy->net_ns;
23088 +               if (nsproxy->net_ns)
23089 +                       get_net(nsproxy->net_ns);
23090 +       } else
23091 +               old_net = NULL;
23092 +#endif
23093 +       if (old_ns)
23094 +               put_mnt_ns(old_ns);
23095 +       if (old_uts)
23096 +               put_uts_ns(old_uts);
23097 +       if (old_ipc)
23098 +               put_ipc_ns(old_ipc);
23099 +#ifdef CONFIG_PID_NS
23100 +       if (old_pid)
23101 +               put_pid_ns(old_pid);
23102 +#endif
23103 +#ifdef CONFIG_NET_NS
23104 +       if (old_net)
23105 +               put_net(old_net);
23106 +#endif
23107 +out:
23108 +       return nsproxy;
23109 +}
23110 +
23111 +
23112 +/*
23113 + *     merge two nsproxy structs into a new one.
23114 + *     will hold a reference on the result.
23115 + */
23116 +
23117 +static inline
23118 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
23119 +       struct nsproxy *proxy, unsigned long mask)
23120 +{
23121 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
23122 +
23123 +       if (!proxy)
23124 +               return NULL;
23125 +
23126 +       if (mask) {
23127 +               /* vs_mix_nsproxy returns with reference */
23128 +               return vs_mix_nsproxy(old ? old : &null_proxy,
23129 +                       proxy, mask);
23130 +       }
23131 +       get_nsproxy(proxy);
23132 +       return proxy;
23133 +}
23134 +
23135 +
23136 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23137 +{
23138 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
23139 +       struct fs_struct *fs_cur, *fs = NULL;
23140 +       struct _vx_space *space;
23141 +       int ret, kill = 0;
23142 +
23143 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
23144 +               vxi, vxi->vx_id, mask, index);
23145 +
23146 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
23147 +               return -EACCES;
23148 +
23149 +       if (index >= VX_SPACES)
23150 +               return -EINVAL;
23151 +
23152 +       space = &vxi->space[index];
23153 +
23154 +       if (!mask)
23155 +               mask = space->vx_nsmask;
23156 +
23157 +       if ((mask & space->vx_nsmask) != mask)
23158 +               return -EINVAL;
23159 +
23160 +       if (mask & CLONE_FS) {
23161 +               fs = copy_fs_struct(space->vx_fs);
23162 +               if (!fs)
23163 +                       return -ENOMEM;
23164 +       }
23165 +       proxy = space->vx_nsproxy;
23166 +
23167 +       vxdprintk(VXD_CBIT(space, 9),
23168 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23169 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23170 +
23171 +       task_lock(current);
23172 +       fs_cur = current->fs;
23173 +
23174 +       if (mask & CLONE_FS) {
23175 +               spin_lock(&fs_cur->lock);
23176 +               current->fs = fs;
23177 +               kill = !--fs_cur->users;
23178 +               spin_unlock(&fs_cur->lock);
23179 +       }
23180 +
23181 +       proxy_cur = current->nsproxy;
23182 +       get_nsproxy(proxy_cur);
23183 +       task_unlock(current);
23184 +
23185 +       if (kill)
23186 +               free_fs_struct(fs_cur);
23187 +
23188 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23189 +       if (IS_ERR(proxy_new)) {
23190 +               ret = PTR_ERR(proxy_new);
23191 +               goto out_put;
23192 +       }
23193 +
23194 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23195 +
23196 +       if (mask & CLONE_NEWUSER) {
23197 +               struct cred *cred;
23198 +
23199 +               vxdprintk(VXD_CBIT(space, 10),
23200 +#if 1
23201 +                       "vx_enter_space(%p[#%u])", vxi, vxi->vx_id);
23202 +#else
23203 +                       "vx_enter_space(%p[#%u],%p,%p) cred (%p,%p)",
23204 +                       vxi, vxi->vx_id,
23205 +                       space->vx_real_cred, space->vx_cred,
23206 +                       current->real_cred, current->cred);
23207 +               exit_creds(current);
23208 +               current->real_cred = get_cred(space->vx_real_cred);
23209 +               alter_cred_subscribers(current->real_cred, 1);
23210 +#endif
23211 +               cred = __prepare_creds(space->vx_cred);
23212 +               if (cred)
23213 +                       commit_creds(cred);
23214 +       }
23215 +
23216 +       ret = 0;
23217 +
23218 +       if (proxy_new)
23219 +               put_nsproxy(proxy_new);
23220 +out_put:
23221 +       if (proxy_cur)
23222 +               put_nsproxy(proxy_cur);
23223 +       return ret;
23224 +}
23225 +
23226 +
23227 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23228 +{
23229 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23230 +       struct fs_struct *fs_vxi, *fs;
23231 +       struct _vx_space *space;
23232 +       int ret, kill = 0;
23233 +
23234 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23235 +               vxi, vxi->vx_id, mask, index);
23236 +
23237 +       if ((mask & space_mask.mask) != mask)
23238 +               return -EINVAL;
23239 +
23240 +       if (index >= VX_SPACES)
23241 +               return -EINVAL;
23242 +
23243 +       space = &vxi->space[index];
23244 +
23245 +       proxy_vxi = space->vx_nsproxy;
23246 +       fs_vxi = space->vx_fs;
23247 +
23248 +       if (mask & CLONE_FS) {
23249 +               fs = copy_fs_struct(current->fs);
23250 +               if (!fs)
23251 +                       return -ENOMEM;
23252 +       }
23253 +
23254 +       task_lock(current);
23255 +
23256 +       if (mask & CLONE_FS) {
23257 +               spin_lock(&fs_vxi->lock);
23258 +               space->vx_fs = fs;
23259 +               kill = !--fs_vxi->users;
23260 +               spin_unlock(&fs_vxi->lock);
23261 +       }
23262 +
23263 +       proxy_cur = current->nsproxy;
23264 +       get_nsproxy(proxy_cur);
23265 +       task_unlock(current);
23266 +
23267 +       if (kill)
23268 +               free_fs_struct(fs_vxi);
23269 +
23270 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23271 +       if (IS_ERR(proxy_new)) {
23272 +               ret = PTR_ERR(proxy_new);
23273 +               goto out_put;
23274 +       }
23275 +
23276 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
23277 +       space->vx_nsmask |= mask;
23278 +
23279 +       if (mask & CLONE_NEWUSER) {
23280 +               struct cred *cred;
23281 +
23282 +               vxdprintk(VXD_CBIT(space, 10),
23283 +#if 1
23284 +                       "vx_set_space(%p[#%u])", vxi, vxi->vx_id);
23285 +#else
23286 +                       "vx_set_space(%p[#%u],%p,%p) cred (%p,%p)",
23287 +                       vxi, vxi->vx_id,
23288 +                       space->vx_real_cred, space->vx_cred,
23289 +                       current->real_cred, current->cred);
23290 +
23291 +               if (current->real_cred) {
23292 +                       cred = get_cred(current->real_cred);
23293 +                       alter_cred_subscribers(cred, 1);
23294 +               } else
23295 +                       cred = NULL;
23296 +               cred = xchg(&space->vx_real_cred, cred);
23297 +               if (cred) {
23298 +                       alter_cred_subscribers(cred, -1);
23299 +                       put_cred(cred);
23300 +               }
23301 +
23302 +#endif
23303 +               cred = prepare_creds();
23304 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
23305 +               if (cred)
23306 +                       abort_creds(cred);
23307 +       }
23308 +
23309 +       ret = 0;
23310 +
23311 +       if (proxy_new)
23312 +               put_nsproxy(proxy_new);
23313 +out_put:
23314 +       if (proxy_cur)
23315 +               put_nsproxy(proxy_cur);
23316 +       return ret;
23317 +}
23318 +
23319 +
23320 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23321 +{
23322 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23323 +
23324 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23325 +               return -EFAULT;
23326 +
23327 +       return vx_enter_space(vxi, vc_data.mask, 0);
23328 +}
23329 +
23330 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23331 +{
23332 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23333 +
23334 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23335 +               return -EFAULT;
23336 +
23337 +       if (vc_data.index >= VX_SPACES)
23338 +               return -EINVAL;
23339 +
23340 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23341 +}
23342 +
23343 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23344 +{
23345 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23346 +
23347 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23348 +               return -EFAULT;
23349 +
23350 +       return vx_set_space(vxi, vc_data.mask, 0);
23351 +}
23352 +
23353 +int vc_set_space(struct vx_info *vxi, void __user *data)
23354 +{
23355 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23356 +
23357 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23358 +               return -EFAULT;
23359 +
23360 +       if (vc_data.index >= VX_SPACES)
23361 +               return -EINVAL;
23362 +
23363 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23364 +}
23365 +
23366 +int vc_get_space_mask(void __user *data, int type)
23367 +{
23368 +       const struct vcmd_space_mask_v1 *mask;
23369 +
23370 +       if (type == 0)
23371 +               mask = &space_mask_v0;
23372 +       else if (type == 1)
23373 +               mask = &space_mask;
23374 +       else
23375 +               mask = &default_space_mask;
23376 +
23377 +       vxdprintk(VXD_CBIT(space, 10),
23378 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23379 +
23380 +       if (copy_to_user(data, mask, sizeof(*mask)))
23381 +               return -EFAULT;
23382 +       return 0;
23383 +}
23384 +
23385 diff -NurpP --minimal linux-2.6.37/kernel/vserver/switch.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/switch.c
23386 --- linux-2.6.37/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
23387 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/switch.c 2010-11-23 02:09:41.000000000 +0100
23388 @@ -0,0 +1,531 @@
23389 +/*
23390 + *  linux/kernel/vserver/switch.c
23391 + *
23392 + *  Virtual Server: Syscall Switch
23393 + *
23394 + *  Copyright (C) 2003-2007  Herbert Pötzl
23395 + *
23396 + *  V0.01  syscall switch
23397 + *  V0.02  added signal to context
23398 + *  V0.03  added rlimit functions
23399 + *  V0.04  added iattr, task/xid functions
23400 + *  V0.05  added debug/history stuff
23401 + *  V0.06  added compat32 layer
23402 + *  V0.07  vcmd args and perms
23403 + *  V0.08  added status commands
23404 + *  V0.09  added tag commands
23405 + *  V0.10  added oom bias
23406 + *  V0.11  added device commands
23407 + *
23408 + */
23409 +
23410 +#include <linux/vs_context.h>
23411 +#include <linux/vs_network.h>
23412 +#include <linux/vserver/switch.h>
23413 +
23414 +#include "vci_config.h"
23415 +
23416 +
23417 +static inline
23418 +int vc_get_version(uint32_t id)
23419 +{
23420 +       return VCI_VERSION;
23421 +}
23422 +
23423 +static inline
23424 +int vc_get_vci(uint32_t id)
23425 +{
23426 +       return vci_kernel_config();
23427 +}
23428 +
23429 +#include <linux/vserver/context_cmd.h>
23430 +#include <linux/vserver/cvirt_cmd.h>
23431 +#include <linux/vserver/cacct_cmd.h>
23432 +#include <linux/vserver/limit_cmd.h>
23433 +#include <linux/vserver/network_cmd.h>
23434 +#include <linux/vserver/sched_cmd.h>
23435 +#include <linux/vserver/debug_cmd.h>
23436 +#include <linux/vserver/inode_cmd.h>
23437 +#include <linux/vserver/dlimit_cmd.h>
23438 +#include <linux/vserver/signal_cmd.h>
23439 +#include <linux/vserver/space_cmd.h>
23440 +#include <linux/vserver/tag_cmd.h>
23441 +#include <linux/vserver/device_cmd.h>
23442 +
23443 +#include <linux/vserver/inode.h>
23444 +#include <linux/vserver/dlimit.h>
23445 +
23446 +
23447 +#ifdef CONFIG_COMPAT
23448 +#define __COMPAT(name, id, data, compat)       \
23449 +       (compat) ? name ## _x32(id, data) : name(id, data)
23450 +#define __COMPAT_NO_ID(name, data, compat)     \
23451 +       (compat) ? name ## _x32(data) : name(data)
23452 +#else
23453 +#define __COMPAT(name, id, data, compat)       \
23454 +       name(id, data)
23455 +#define __COMPAT_NO_ID(name, data, compat)     \
23456 +       name(data)
23457 +#endif
23458 +
23459 +
23460 +static inline
23461 +long do_vcmd(uint32_t cmd, uint32_t id,
23462 +       struct vx_info *vxi, struct nx_info *nxi,
23463 +       void __user *data, int compat)
23464 +{
23465 +       switch (cmd) {
23466 +
23467 +       case VCMD_get_version:
23468 +               return vc_get_version(id);
23469 +       case VCMD_get_vci:
23470 +               return vc_get_vci(id);
23471 +
23472 +       case VCMD_task_xid:
23473 +               return vc_task_xid(id);
23474 +       case VCMD_vx_info:
23475 +               return vc_vx_info(vxi, data);
23476 +
23477 +       case VCMD_task_nid:
23478 +               return vc_task_nid(id);
23479 +       case VCMD_nx_info:
23480 +               return vc_nx_info(nxi, data);
23481 +
23482 +       case VCMD_task_tag:
23483 +               return vc_task_tag(id);
23484 +
23485 +       case VCMD_set_space_v1:
23486 +               return vc_set_space_v1(vxi, data);
23487 +       /* this is version 2 */
23488 +       case VCMD_set_space:
23489 +               return vc_set_space(vxi, data);
23490 +
23491 +       case VCMD_get_space_mask_v0:
23492 +               return vc_get_space_mask(data, 0);
23493 +       /* this is version 1 */
23494 +       case VCMD_get_space_mask:
23495 +               return vc_get_space_mask(data, 1);
23496 +
23497 +       case VCMD_get_space_default:
23498 +               return vc_get_space_mask(data, -1);
23499 +
23500 +#ifdef CONFIG_IA32_EMULATION
23501 +       case VCMD_get_rlimit:
23502 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23503 +       case VCMD_set_rlimit:
23504 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23505 +#else
23506 +       case VCMD_get_rlimit:
23507 +               return vc_get_rlimit(vxi, data);
23508 +       case VCMD_set_rlimit:
23509 +               return vc_set_rlimit(vxi, data);
23510 +#endif
23511 +       case VCMD_get_rlimit_mask:
23512 +               return vc_get_rlimit_mask(id, data);
23513 +       case VCMD_reset_hits:
23514 +               return vc_reset_hits(vxi, data);
23515 +       case VCMD_reset_minmax:
23516 +               return vc_reset_minmax(vxi, data);
23517 +
23518 +       case VCMD_get_vhi_name:
23519 +               return vc_get_vhi_name(vxi, data);
23520 +       case VCMD_set_vhi_name:
23521 +               return vc_set_vhi_name(vxi, data);
23522 +
23523 +       case VCMD_ctx_stat:
23524 +               return vc_ctx_stat(vxi, data);
23525 +       case VCMD_virt_stat:
23526 +               return vc_virt_stat(vxi, data);
23527 +       case VCMD_sock_stat:
23528 +               return vc_sock_stat(vxi, data);
23529 +       case VCMD_rlimit_stat:
23530 +               return vc_rlimit_stat(vxi, data);
23531 +
23532 +       case VCMD_set_cflags:
23533 +               return vc_set_cflags(vxi, data);
23534 +       case VCMD_get_cflags:
23535 +               return vc_get_cflags(vxi, data);
23536 +
23537 +       /* this is version 1 */
23538 +       case VCMD_set_ccaps:
23539 +               return vc_set_ccaps(vxi, data);
23540 +       /* this is version 1 */
23541 +       case VCMD_get_ccaps:
23542 +               return vc_get_ccaps(vxi, data);
23543 +       case VCMD_set_bcaps:
23544 +               return vc_set_bcaps(vxi, data);
23545 +       case VCMD_get_bcaps:
23546 +               return vc_get_bcaps(vxi, data);
23547 +
23548 +       case VCMD_set_badness:
23549 +               return vc_set_badness(vxi, data);
23550 +       case VCMD_get_badness:
23551 +               return vc_get_badness(vxi, data);
23552 +
23553 +       case VCMD_set_nflags:
23554 +               return vc_set_nflags(nxi, data);
23555 +       case VCMD_get_nflags:
23556 +               return vc_get_nflags(nxi, data);
23557 +
23558 +       case VCMD_set_ncaps:
23559 +               return vc_set_ncaps(nxi, data);
23560 +       case VCMD_get_ncaps:
23561 +               return vc_get_ncaps(nxi, data);
23562 +
23563 +       case VCMD_set_prio_bias:
23564 +               return vc_set_prio_bias(vxi, data);
23565 +       case VCMD_get_prio_bias:
23566 +               return vc_get_prio_bias(vxi, data);
23567 +       case VCMD_add_dlimit:
23568 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23569 +       case VCMD_rem_dlimit:
23570 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23571 +       case VCMD_set_dlimit:
23572 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23573 +       case VCMD_get_dlimit:
23574 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23575 +
23576 +       case VCMD_ctx_kill:
23577 +               return vc_ctx_kill(vxi, data);
23578 +
23579 +       case VCMD_wait_exit:
23580 +               return vc_wait_exit(vxi, data);
23581 +
23582 +       case VCMD_get_iattr:
23583 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23584 +       case VCMD_set_iattr:
23585 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23586 +
23587 +       case VCMD_fget_iattr:
23588 +               return vc_fget_iattr(id, data);
23589 +       case VCMD_fset_iattr:
23590 +               return vc_fset_iattr(id, data);
23591 +
23592 +       case VCMD_enter_space_v0:
23593 +               return vc_enter_space_v1(vxi, NULL);
23594 +       case VCMD_enter_space_v1:
23595 +               return vc_enter_space_v1(vxi, data);
23596 +       /* this is version 2 */
23597 +       case VCMD_enter_space:
23598 +               return vc_enter_space(vxi, data);
23599 +
23600 +       case VCMD_ctx_create_v0:
23601 +               return vc_ctx_create(id, NULL);
23602 +       case VCMD_ctx_create:
23603 +               return vc_ctx_create(id, data);
23604 +       case VCMD_ctx_migrate_v0:
23605 +               return vc_ctx_migrate(vxi, NULL);
23606 +       case VCMD_ctx_migrate:
23607 +               return vc_ctx_migrate(vxi, data);
23608 +
23609 +       case VCMD_net_create_v0:
23610 +               return vc_net_create(id, NULL);
23611 +       case VCMD_net_create:
23612 +               return vc_net_create(id, data);
23613 +       case VCMD_net_migrate:
23614 +               return vc_net_migrate(nxi, data);
23615 +
23616 +       case VCMD_tag_migrate:
23617 +               return vc_tag_migrate(id);
23618 +
23619 +       case VCMD_net_add:
23620 +               return vc_net_add(nxi, data);
23621 +       case VCMD_net_remove:
23622 +               return vc_net_remove(nxi, data);
23623 +
23624 +       case VCMD_net_add_ipv4:
23625 +               return vc_net_add_ipv4(nxi, data);
23626 +       case VCMD_net_remove_ipv4:
23627 +               return vc_net_remove_ipv4(nxi, data);
23628 +#ifdef CONFIG_IPV6
23629 +       case VCMD_net_add_ipv6:
23630 +               return vc_net_add_ipv6(nxi, data);
23631 +       case VCMD_net_remove_ipv6:
23632 +               return vc_net_remove_ipv6(nxi, data);
23633 +#endif
23634 +/*     case VCMD_add_match_ipv4:
23635 +               return vc_add_match_ipv4(nxi, data);
23636 +       case VCMD_get_match_ipv4:
23637 +               return vc_get_match_ipv4(nxi, data);
23638 +#ifdef CONFIG_IPV6
23639 +       case VCMD_add_match_ipv6:
23640 +               return vc_add_match_ipv6(nxi, data);
23641 +       case VCMD_get_match_ipv6:
23642 +               return vc_get_match_ipv6(nxi, data);
23643 +#endif */
23644 +
23645 +#ifdef CONFIG_VSERVER_DEVICE
23646 +       case VCMD_set_mapping:
23647 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23648 +       case VCMD_unset_mapping:
23649 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23650 +#endif
23651 +#ifdef CONFIG_VSERVER_HISTORY
23652 +       case VCMD_dump_history:
23653 +               return vc_dump_history(id);
23654 +       case VCMD_read_history:
23655 +               return __COMPAT(vc_read_history, id, data, compat);
23656 +#endif
23657 +       default:
23658 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23659 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23660 +       }
23661 +       return -ENOSYS;
23662 +}
23663 +
23664 +
23665 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23666 +       case VCMD_ ## vcmd: perm = _perm;               \
23667 +               args = _args; flags = _flags; break
23668 +
23669 +
23670 +#define VCA_NONE       0x00
23671 +#define VCA_VXI                0x01
23672 +#define VCA_NXI                0x02
23673 +
23674 +#define VCF_NONE       0x00
23675 +#define VCF_INFO       0x01
23676 +#define VCF_ADMIN      0x02
23677 +#define VCF_ARES       0x06    /* includes admin */
23678 +#define VCF_SETUP      0x08
23679 +
23680 +#define VCF_ZIDOK      0x10    /* zero id okay */
23681 +
23682 +
23683 +static inline
23684 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23685 +{
23686 +       long ret;
23687 +       int permit = -1, state = 0;
23688 +       int perm = -1, args = 0, flags = 0;
23689 +       struct vx_info *vxi = NULL;
23690 +       struct nx_info *nxi = NULL;
23691 +
23692 +       switch (cmd) {
23693 +       /* unpriviledged commands */
23694 +       __VCMD(get_version,      0, VCA_NONE,   0);
23695 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23696 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23697 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23698 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23699 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23700 +
23701 +       /* info commands */
23702 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23703 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23704 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23705 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23706 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23707 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23708 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23709 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23710 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23711 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23712 +
23713 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23714 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23715 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23716 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23717 +
23718 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23719 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23720 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23721 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23722 +
23723 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23724 +
23725 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23726 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23727 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23728 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23729 +
23730 +       /* lower admin commands */
23731 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23732 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23733 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23734 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23735 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23736 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23737 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23738 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23739 +
23740 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23741 +       __VCMD(net_create,       5, VCA_NONE,   0);
23742 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23743 +
23744 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23745 +
23746 +       /* higher admin commands */
23747 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23748 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23749 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23750 +
23751 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23752 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23753 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23754 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23755 +
23756 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23757 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23758 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23759 +
23760 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23761 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23762 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23763 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23764 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23765 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23766 +#ifdef CONFIG_IPV6
23767 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23768 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23769 +#endif
23770 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23771 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23772 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23773 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23774 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23775 +
23776 +#ifdef CONFIG_VSERVER_DEVICE
23777 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23778 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23779 +#endif
23780 +       /* debug level admin commands */
23781 +#ifdef CONFIG_VSERVER_HISTORY
23782 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23783 +       __VCMD(read_history,     9, VCA_NONE,   0);
23784 +#endif
23785 +
23786 +       default:
23787 +               perm = -1;
23788 +       }
23789 +
23790 +       vxdprintk(VXD_CBIT(switch, 0),
23791 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23792 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23793 +               VC_VERSION(cmd), id, data, compat,
23794 +               perm, args, flags);
23795 +
23796 +       ret = -ENOSYS;
23797 +       if (perm < 0)
23798 +               goto out;
23799 +
23800 +       state = 1;
23801 +       if (!capable(CAP_CONTEXT))
23802 +               goto out;
23803 +
23804 +       state = 2;
23805 +       /* moved here from the individual commands */
23806 +       ret = -EPERM;
23807 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23808 +               goto out;
23809 +
23810 +       state = 3;
23811 +       /* vcmd involves resource management  */
23812 +       ret = -EPERM;
23813 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23814 +               goto out;
23815 +
23816 +       state = 4;
23817 +       /* various legacy exceptions */
23818 +       switch (cmd) {
23819 +       /* will go away when spectator is a cap */
23820 +       case VCMD_ctx_migrate_v0:
23821 +       case VCMD_ctx_migrate:
23822 +               if (id == 1) {
23823 +                       current->xid = 1;
23824 +                       ret = 1;
23825 +                       goto out;
23826 +               }
23827 +               break;
23828 +
23829 +       /* will go away when spectator is a cap */
23830 +       case VCMD_net_migrate:
23831 +               if (id == 1) {
23832 +                       current->nid = 1;
23833 +                       ret = 1;
23834 +                       goto out;
23835 +               }
23836 +               break;
23837 +       }
23838 +
23839 +       /* vcmds are fine by default */
23840 +       permit = 1;
23841 +
23842 +       /* admin type vcmds require admin ... */
23843 +       if (flags & VCF_ADMIN)
23844 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23845 +
23846 +       /* ... but setup type vcmds override that */
23847 +       if (!permit && (flags & VCF_SETUP))
23848 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23849 +
23850 +       state = 5;
23851 +       ret = -EPERM;
23852 +       if (!permit)
23853 +               goto out;
23854 +
23855 +       state = 6;
23856 +       if (!id && (flags & VCF_ZIDOK))
23857 +               goto skip_id;
23858 +
23859 +       ret = -ESRCH;
23860 +       if (args & VCA_VXI) {
23861 +               vxi = lookup_vx_info(id);
23862 +               if (!vxi)
23863 +                       goto out;
23864 +
23865 +               if ((flags & VCF_ADMIN) &&
23866 +                       /* special case kill for shutdown */
23867 +                       (cmd != VCMD_ctx_kill) &&
23868 +                       /* can context be administrated? */
23869 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23870 +                       ret = -EACCES;
23871 +                       goto out_vxi;
23872 +               }
23873 +       }
23874 +       state = 7;
23875 +       if (args & VCA_NXI) {
23876 +               nxi = lookup_nx_info(id);
23877 +               if (!nxi)
23878 +                       goto out_vxi;
23879 +
23880 +               if ((flags & VCF_ADMIN) &&
23881 +                       /* can context be administrated? */
23882 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23883 +                       ret = -EACCES;
23884 +                       goto out_nxi;
23885 +               }
23886 +       }
23887 +skip_id:
23888 +       state = 8;
23889 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23890 +
23891 +out_nxi:
23892 +       if ((args & VCA_NXI) && nxi)
23893 +               put_nx_info(nxi);
23894 +out_vxi:
23895 +       if ((args & VCA_VXI) && vxi)
23896 +               put_vx_info(vxi);
23897 +out:
23898 +       vxdprintk(VXD_CBIT(switch, 1),
23899 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23900 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23901 +               VC_VERSION(cmd), ret, ret, state, permit);
23902 +       return ret;
23903 +}
23904 +
23905 +asmlinkage long
23906 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23907 +{
23908 +       return do_vserver(cmd, id, data, 0);
23909 +}
23910 +
23911 +#ifdef CONFIG_COMPAT
23912 +
23913 +asmlinkage long
23914 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23915 +{
23916 +       return do_vserver(cmd, id, data, 1);
23917 +}
23918 +
23919 +#endif /* CONFIG_COMPAT */
23920 diff -NurpP --minimal linux-2.6.37/kernel/vserver/sysctl.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/sysctl.c
23921 --- linux-2.6.37/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
23922 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/sysctl.c 2010-11-23 02:09:41.000000000 +0100
23923 @@ -0,0 +1,241 @@
23924 +/*
23925 + *  kernel/vserver/sysctl.c
23926 + *
23927 + *  Virtual Context Support
23928 + *
23929 + *  Copyright (C) 2004-2007  Herbert Pötzl
23930 + *
23931 + *  V0.01  basic structure
23932 + *
23933 + */
23934 +
23935 +#include <linux/module.h>
23936 +#include <linux/ctype.h>
23937 +#include <linux/sysctl.h>
23938 +#include <linux/parser.h>
23939 +#include <asm/uaccess.h>
23940 +
23941 +enum {
23942 +       CTL_DEBUG_ERROR         = 0,
23943 +       CTL_DEBUG_SWITCH        = 1,
23944 +       CTL_DEBUG_XID,
23945 +       CTL_DEBUG_NID,
23946 +       CTL_DEBUG_TAG,
23947 +       CTL_DEBUG_NET,
23948 +       CTL_DEBUG_LIMIT,
23949 +       CTL_DEBUG_CRES,
23950 +       CTL_DEBUG_DLIM,
23951 +       CTL_DEBUG_QUOTA,
23952 +       CTL_DEBUG_CVIRT,
23953 +       CTL_DEBUG_SPACE,
23954 +       CTL_DEBUG_MISC,
23955 +};
23956 +
23957 +
23958 +unsigned int vx_debug_switch   = 0;
23959 +unsigned int vx_debug_xid      = 0;
23960 +unsigned int vx_debug_nid      = 0;
23961 +unsigned int vx_debug_tag      = 0;
23962 +unsigned int vx_debug_net      = 0;
23963 +unsigned int vx_debug_limit    = 0;
23964 +unsigned int vx_debug_cres     = 0;
23965 +unsigned int vx_debug_dlim     = 0;
23966 +unsigned int vx_debug_quota    = 0;
23967 +unsigned int vx_debug_cvirt    = 0;
23968 +unsigned int vx_debug_space    = 0;
23969 +unsigned int vx_debug_misc     = 0;
23970 +
23971 +
23972 +static struct ctl_table_header *vserver_table_header;
23973 +static ctl_table vserver_root_table[];
23974 +
23975 +
23976 +void vserver_register_sysctl(void)
23977 +{
23978 +       if (!vserver_table_header) {
23979 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23980 +       }
23981 +
23982 +}
23983 +
23984 +void vserver_unregister_sysctl(void)
23985 +{
23986 +       if (vserver_table_header) {
23987 +               unregister_sysctl_table(vserver_table_header);
23988 +               vserver_table_header = NULL;
23989 +       }
23990 +}
23991 +
23992 +
23993 +static int proc_dodebug(ctl_table *table, int write,
23994 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23995 +{
23996 +       char            tmpbuf[20], *p, c;
23997 +       unsigned int    value;
23998 +       size_t          left, len;
23999 +
24000 +       if ((*ppos && !write) || !*lenp) {
24001 +               *lenp = 0;
24002 +               return 0;
24003 +       }
24004 +
24005 +       left = *lenp;
24006 +
24007 +       if (write) {
24008 +               if (!access_ok(VERIFY_READ, buffer, left))
24009 +                       return -EFAULT;
24010 +               p = (char *)buffer;
24011 +               while (left && __get_user(c, p) >= 0 && isspace(c))
24012 +                       left--, p++;
24013 +               if (!left)
24014 +                       goto done;
24015 +
24016 +               if (left > sizeof(tmpbuf) - 1)
24017 +                       return -EINVAL;
24018 +               if (copy_from_user(tmpbuf, p, left))
24019 +                       return -EFAULT;
24020 +               tmpbuf[left] = '\0';
24021 +
24022 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
24023 +                       value = 10 * value + (*p - '0');
24024 +               if (*p && !isspace(*p))
24025 +                       return -EINVAL;
24026 +               while (left && isspace(*p))
24027 +                       left--, p++;
24028 +               *(unsigned int *)table->data = value;
24029 +       } else {
24030 +               if (!access_ok(VERIFY_WRITE, buffer, left))
24031 +                       return -EFAULT;
24032 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
24033 +               if (len > left)
24034 +                       len = left;
24035 +               if (__copy_to_user(buffer, tmpbuf, len))
24036 +                       return -EFAULT;
24037 +               if ((left -= len) > 0) {
24038 +                       if (put_user('\n', (char *)buffer + len))
24039 +                               return -EFAULT;
24040 +                       left--;
24041 +               }
24042 +       }
24043 +
24044 +done:
24045 +       *lenp -= left;
24046 +       *ppos += *lenp;
24047 +       return 0;
24048 +}
24049 +
24050 +static int zero;
24051 +
24052 +#define        CTL_ENTRY(ctl, name)                            \
24053 +       {                                               \
24054 +               .procname       = #name,                \
24055 +               .data           = &vx_ ## name,         \
24056 +               .maxlen         = sizeof(int),          \
24057 +               .mode           = 0644,                 \
24058 +               .proc_handler   = &proc_dodebug,        \
24059 +               .extra1         = &zero,                \
24060 +               .extra2         = &zero,                \
24061 +       }
24062 +
24063 +static ctl_table vserver_debug_table[] = {
24064 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
24065 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
24066 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
24067 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
24068 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
24069 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
24070 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
24071 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
24072 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
24073 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
24074 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
24075 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
24076 +       { 0 }
24077 +};
24078 +
24079 +static ctl_table vserver_root_table[] = {
24080 +       {
24081 +               .procname       = "vserver",
24082 +               .mode           = 0555,
24083 +               .child          = vserver_debug_table
24084 +       },
24085 +       { 0 }
24086 +};
24087 +
24088 +
24089 +static match_table_t tokens = {
24090 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24091 +       { CTL_DEBUG_XID,        "xid=%x"        },
24092 +       { CTL_DEBUG_NID,        "nid=%x"        },
24093 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24094 +       { CTL_DEBUG_NET,        "net=%x"        },
24095 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24096 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24097 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24098 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24099 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24100 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24101 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24102 +       { CTL_DEBUG_ERROR,      NULL            }
24103 +};
24104 +
24105 +#define        HANDLE_CASE(id, name, val)                              \
24106 +       case CTL_DEBUG_ ## id:                                  \
24107 +               vx_debug_ ## name = val;                        \
24108 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24109 +               break
24110 +
24111 +
24112 +static int __init vs_debug_setup(char *str)
24113 +{
24114 +       char *p;
24115 +       int token;
24116 +
24117 +       printk("vs_debug_setup(%s)\n", str);
24118 +       while ((p = strsep(&str, ",")) != NULL) {
24119 +               substring_t args[MAX_OPT_ARGS];
24120 +               unsigned int value;
24121 +
24122 +               if (!*p)
24123 +                       continue;
24124 +
24125 +               token = match_token(p, tokens, args);
24126 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24127 +
24128 +               switch (token) {
24129 +               HANDLE_CASE(SWITCH, switch, value);
24130 +               HANDLE_CASE(XID,    xid,    value);
24131 +               HANDLE_CASE(NID,    nid,    value);
24132 +               HANDLE_CASE(TAG,    tag,    value);
24133 +               HANDLE_CASE(NET,    net,    value);
24134 +               HANDLE_CASE(LIMIT,  limit,  value);
24135 +               HANDLE_CASE(CRES,   cres,   value);
24136 +               HANDLE_CASE(DLIM,   dlim,   value);
24137 +               HANDLE_CASE(QUOTA,  quota,  value);
24138 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24139 +               HANDLE_CASE(SPACE,  space,  value);
24140 +               HANDLE_CASE(MISC,   misc,   value);
24141 +               default:
24142 +                       return -EINVAL;
24143 +                       break;
24144 +               }
24145 +       }
24146 +       return 1;
24147 +}
24148 +
24149 +__setup("vsdebug=", vs_debug_setup);
24150 +
24151 +
24152 +
24153 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24154 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24155 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24156 +EXPORT_SYMBOL_GPL(vx_debug_net);
24157 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24158 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24159 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24160 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24161 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24162 +EXPORT_SYMBOL_GPL(vx_debug_space);
24163 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24164 +
24165 diff -NurpP --minimal linux-2.6.37/kernel/vserver/tag.c linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/tag.c
24166 --- linux-2.6.37/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
24167 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/tag.c    2010-11-23 02:09:41.000000000 +0100
24168 @@ -0,0 +1,63 @@
24169 +/*
24170 + *  linux/kernel/vserver/tag.c
24171 + *
24172 + *  Virtual Server: Shallow Tag Space
24173 + *
24174 + *  Copyright (C) 2007  Herbert Pötzl
24175 + *
24176 + *  V0.01  basic implementation
24177 + *
24178 + */
24179 +
24180 +#include <linux/sched.h>
24181 +#include <linux/vserver/debug.h>
24182 +#include <linux/vs_pid.h>
24183 +#include <linux/vs_tag.h>
24184 +
24185 +#include <linux/vserver/tag_cmd.h>
24186 +
24187 +
24188 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24189 +{
24190 +       if (!p)
24191 +               BUG();
24192 +
24193 +       vxdprintk(VXD_CBIT(tag, 5),
24194 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24195 +
24196 +       task_lock(p);
24197 +       p->tag = tag;
24198 +       task_unlock(p);
24199 +
24200 +       vxdprintk(VXD_CBIT(tag, 5),
24201 +               "moved task %p into [#%d]", p, tag);
24202 +       return 0;
24203 +}
24204 +
24205 +/* vserver syscall commands below here */
24206 +
24207 +/* taks xid and vx_info functions */
24208 +
24209 +
24210 +int vc_task_tag(uint32_t id)
24211 +{
24212 +       tag_t tag;
24213 +
24214 +       if (id) {
24215 +               struct task_struct *tsk;
24216 +               read_lock(&tasklist_lock);
24217 +               tsk = find_task_by_real_pid(id);
24218 +               tag = (tsk) ? tsk->tag : -ESRCH;
24219 +               read_unlock(&tasklist_lock);
24220 +       } else
24221 +               tag = dx_current_tag();
24222 +       return tag;
24223 +}
24224 +
24225 +
24226 +int vc_tag_migrate(uint32_t tag)
24227 +{
24228 +       return dx_migrate_task(current, tag & 0xFFFF);
24229 +}
24230 +
24231 +
24232 diff -NurpP --minimal linux-2.6.37/kernel/vserver/vci_config.h linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/vci_config.h
24233 --- linux-2.6.37/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
24234 +++ linux-2.6.37-vs2.3.0.37-rc3/kernel/vserver/vci_config.h     2010-11-23 02:09:41.000000000 +0100
24235 @@ -0,0 +1,82 @@
24236 +
24237 +/*  interface version */
24238 +
24239 +#define VCI_VERSION            0x00020307
24240 +
24241 +
24242 +enum {
24243 +       VCI_KCBIT_NO_DYNAMIC = 0,
24244 +
24245 +       VCI_KCBIT_PROC_SECURE = 4,
24246 +       VCI_KCBIT_HARDCPU = 5,
24247 +       VCI_KCBIT_IDLELIMIT = 6,
24248 +       VCI_KCBIT_IDLETIME = 7,
24249 +
24250 +       VCI_KCBIT_COWBL = 8,
24251 +       VCI_KCBIT_FULLCOWBL = 9,
24252 +       VCI_KCBIT_SPACES = 10,
24253 +       VCI_KCBIT_NETV2 = 11,
24254 +       VCI_KCBIT_MEMCG = 12,
24255 +
24256 +       VCI_KCBIT_DEBUG = 16,
24257 +       VCI_KCBIT_HISTORY = 20,
24258 +       VCI_KCBIT_TAGGED = 24,
24259 +       VCI_KCBIT_PPTAG = 28,
24260 +
24261 +       VCI_KCBIT_MORE = 31,
24262 +};
24263 +
24264 +
24265 +static inline uint32_t vci_kernel_config(void)
24266 +{
24267 +       return
24268 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24269 +
24270 +       /* configured features */
24271 +#ifdef CONFIG_VSERVER_PROC_SECURE
24272 +       (1 << VCI_KCBIT_PROC_SECURE) |
24273 +#endif
24274 +#ifdef CONFIG_VSERVER_IDLELIMIT
24275 +       (1 << VCI_KCBIT_IDLELIMIT) |
24276 +#endif
24277 +#ifdef CONFIG_VSERVER_IDLETIME
24278 +       (1 << VCI_KCBIT_IDLETIME) |
24279 +#endif
24280 +#ifdef CONFIG_VSERVER_COWBL
24281 +       (1 << VCI_KCBIT_COWBL) |
24282 +       (1 << VCI_KCBIT_FULLCOWBL) |
24283 +#endif
24284 +       (1 << VCI_KCBIT_SPACES) |
24285 +       (1 << VCI_KCBIT_NETV2) |
24286 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24287 +       (1 << VCI_KCBIT_MEMCG) |
24288 +#endif
24289 +
24290 +       /* debug options */
24291 +#ifdef CONFIG_VSERVER_DEBUG
24292 +       (1 << VCI_KCBIT_DEBUG) |
24293 +#endif
24294 +#ifdef CONFIG_VSERVER_HISTORY
24295 +       (1 << VCI_KCBIT_HISTORY) |
24296 +#endif
24297 +
24298 +       /* inode context tagging */
24299 +#if    defined(CONFIG_TAGGING_NONE)
24300 +       (0 << VCI_KCBIT_TAGGED) |
24301 +#elif  defined(CONFIG_TAGGING_UID16)
24302 +       (1 << VCI_KCBIT_TAGGED) |
24303 +#elif  defined(CONFIG_TAGGING_GID16)
24304 +       (2 << VCI_KCBIT_TAGGED) |
24305 +#elif  defined(CONFIG_TAGGING_ID24)
24306 +       (3 << VCI_KCBIT_TAGGED) |
24307 +#elif  defined(CONFIG_TAGGING_INTERN)
24308 +       (4 << VCI_KCBIT_TAGGED) |
24309 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24310 +       (5 << VCI_KCBIT_TAGGED) |
24311 +#else
24312 +       (7 << VCI_KCBIT_TAGGED) |
24313 +#endif
24314 +       (1 << VCI_KCBIT_PPTAG) |
24315 +       0;
24316 +}
24317 +
24318 diff -NurpP --minimal linux-2.6.37/mm/filemap_xip.c linux-2.6.37-vs2.3.0.37-rc3/mm/filemap_xip.c
24319 --- linux-2.6.37/mm/filemap_xip.c       2010-07-07 18:31:58.000000000 +0200
24320 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/filemap_xip.c        2010-11-23 02:09:41.000000000 +0100
24321 @@ -18,6 +18,7 @@
24322  #include <linux/seqlock.h>
24323  #include <linux/mutex.h>
24324  #include <linux/gfp.h>
24325 +#include <linux/vs_memory.h>
24326  #include <asm/tlbflush.h>
24327  #include <asm/io.h>
24328  
24329 diff -NurpP --minimal linux-2.6.37/mm/fremap.c linux-2.6.37-vs2.3.0.37-rc3/mm/fremap.c
24330 --- linux-2.6.37/mm/fremap.c    2010-10-21 13:07:57.000000000 +0200
24331 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/fremap.c     2010-11-23 02:09:41.000000000 +0100
24332 @@ -16,6 +16,7 @@
24333  #include <linux/module.h>
24334  #include <linux/syscalls.h>
24335  #include <linux/mmu_notifier.h>
24336 +#include <linux/vs_memory.h>
24337  
24338  #include <asm/mmu_context.h>
24339  #include <asm/cacheflush.h>
24340 diff -NurpP --minimal linux-2.6.37/mm/hugetlb.c linux-2.6.37-vs2.3.0.37-rc3/mm/hugetlb.c
24341 --- linux-2.6.37/mm/hugetlb.c   2011-01-05 21:50:39.000000000 +0100
24342 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/hugetlb.c    2011-01-05 22:30:43.000000000 +0100
24343 @@ -28,6 +28,7 @@
24344  
24345  #include <linux/hugetlb.h>
24346  #include <linux/node.h>
24347 +#include <linux/vs_memory.h>
24348  #include "internal.h"
24349  
24350  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24351 diff -NurpP --minimal linux-2.6.37/mm/memcontrol.c linux-2.6.37-vs2.3.0.37-rc3/mm/memcontrol.c
24352 --- linux-2.6.37/mm/memcontrol.c        2011-01-05 21:50:40.000000000 +0100
24353 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/memcontrol.c 2011-01-05 22:30:43.000000000 +0100
24354 @@ -681,6 +681,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24355                                 struct mem_cgroup, css);
24356  }
24357  
24358 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24359 +{
24360 +       return res_counter_read_u64(&mem->res, member);
24361 +}
24362 +
24363 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24364 +{
24365 +       return res_counter_read_u64(&mem->memsw, member);
24366 +}
24367 +
24368 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24369 +{
24370 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24371 +}
24372 +
24373 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24374 +{
24375 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24376 +}
24377 +
24378 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24379 +{
24380 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24381 +}
24382 +
24383  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24384  {
24385         struct mem_cgroup *mem = NULL;
24386 diff -NurpP --minimal linux-2.6.37/mm/memory.c linux-2.6.37-vs2.3.0.37-rc3/mm/memory.c
24387 --- linux-2.6.37/mm/memory.c    2011-01-05 21:50:40.000000000 +0100
24388 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/memory.c     2010-11-23 02:09:41.000000000 +0100
24389 @@ -3153,6 +3153,7 @@ static inline int handle_pte_fault(struc
24390  {
24391         pte_t entry;
24392         spinlock_t *ptl;
24393 +       int ret = 0, type = VXPT_UNKNOWN;
24394  
24395         entry = *pte;
24396         if (!pte_present(entry)) {
24397 @@ -3177,9 +3178,12 @@ static inline int handle_pte_fault(struc
24398         if (unlikely(!pte_same(*pte, entry)))
24399                 goto unlock;
24400         if (flags & FAULT_FLAG_WRITE) {
24401 -               if (!pte_write(entry))
24402 -                       return do_wp_page(mm, vma, address,
24403 +               if (!pte_write(entry)) {
24404 +                       ret = do_wp_page(mm, vma, address,
24405                                         pte, pmd, ptl, entry);
24406 +                       type = VXPT_WRITE;
24407 +                       goto out;
24408 +               }
24409                 entry = pte_mkdirty(entry);
24410         }
24411         entry = pte_mkyoung(entry);
24412 @@ -3197,7 +3201,10 @@ static inline int handle_pte_fault(struc
24413         }
24414  unlock:
24415         pte_unmap_unlock(pte, ptl);
24416 -       return 0;
24417 +       ret = 0;
24418 +out:
24419 +       vx_page_fault(mm, vma, type, ret);
24420 +       return ret;
24421  }
24422  
24423  /*
24424 diff -NurpP --minimal linux-2.6.37/mm/mremap.c linux-2.6.37-vs2.3.0.37-rc3/mm/mremap.c
24425 --- linux-2.6.37/mm/mremap.c    2011-01-05 21:50:40.000000000 +0100
24426 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/mremap.c     2010-11-23 02:09:41.000000000 +0100
24427 @@ -19,6 +19,7 @@
24428  #include <linux/security.h>
24429  #include <linux/syscalls.h>
24430  #include <linux/mmu_notifier.h>
24431 +#include <linux/vs_memory.h>
24432  
24433  #include <asm/uaccess.h>
24434  #include <asm/cacheflush.h>
24435 diff -NurpP --minimal linux-2.6.37/mm/oom_kill.c linux-2.6.37-vs2.3.0.37-rc3/mm/oom_kill.c
24436 --- linux-2.6.37/mm/oom_kill.c  2011-01-05 21:50:40.000000000 +0100
24437 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/oom_kill.c   2010-11-23 02:09:41.000000000 +0100
24438 @@ -31,6 +31,9 @@
24439  #include <linux/memcontrol.h>
24440  #include <linux/mempolicy.h>
24441  #include <linux/security.h>
24442 +#include <linux/reboot.h>
24443 +#include <linux/vs_memory.h>
24444 +#include <linux/vs_context.h>
24445  
24446  int sysctl_panic_on_oom;
24447  int sysctl_oom_kill_allocating_task;
24448 @@ -124,11 +127,18 @@ struct task_struct *find_lock_task_mm(st
24449  static bool oom_unkillable_task(struct task_struct *p,
24450                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24451  {
24452 -       if (is_global_init(p))
24453 +       unsigned xid = vx_current_xid();
24454 +
24455 +       /* skip the init task, global and per guest */
24456 +       if (task_is_init(p))
24457                 return true;
24458         if (p->flags & PF_KTHREAD)
24459                 return true;
24460  
24461 +       /* skip other guest and host processes if oom in guest */
24462 +       if (xid && vx_task_xid(p) != xid)
24463 +               return true;
24464 +
24465         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24466         if (mem && !task_in_mem_cgroup(p, mem))
24467                 return true;
24468 @@ -210,6 +220,18 @@ unsigned int oom_badness(struct task_str
24469         points += p->signal->oom_score_adj;
24470  
24471         /*
24472 +        * add points for context badness and
24473 +        * reduce badness for processes belonging to
24474 +        * a different context
24475 +        */
24476 +
24477 +       points += vx_badness(p, p->mm);
24478 +
24479 +       if ((vx_current_xid() > 1) &&
24480 +               vx_current_xid() != vx_task_xid(p))
24481 +               points /= 16;
24482 +
24483 +       /*
24484          * Never return 0 for an eligible task that may be killed since it's
24485          * possible that no single user task uses more than 0.1% of memory and
24486          * no single admin tasks uses more than 3.0%.
24487 @@ -414,8 +436,8 @@ static int oom_kill_task(struct task_str
24488         /* mm cannot be safely dereferenced after task_unlock(p) */
24489         mm = p->mm;
24490  
24491 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24492 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24493 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24494 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24495                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24496                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24497         task_unlock(p);
24498 @@ -477,8 +499,8 @@ static int oom_kill_process(struct task_
24499         }
24500  
24501         task_lock(p);
24502 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24503 -               message, task_pid_nr(p), p->comm, points);
24504 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24505 +               message, task_pid_nr(p), p->xid, p->comm, points);
24506         task_unlock(p);
24507  
24508         /*
24509 @@ -567,6 +589,8 @@ int unregister_oom_notifier(struct notif
24510  }
24511  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24512  
24513 +long vs_oom_action(unsigned int);
24514 +
24515  /*
24516   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24517   * if a parallel OOM killing is already taking place that includes a zone in
24518 @@ -726,7 +750,12 @@ retry:
24519         if (!p) {
24520                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24521                 read_unlock(&tasklist_lock);
24522 -               panic("Out of memory and no killable processes...\n");
24523 +
24524 +               /* avoid panic for guest OOM */
24525 +               if (current->xid)
24526 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24527 +               else
24528 +                       panic("Out of memory and no killable processes...\n");
24529         }
24530  
24531         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24532 diff -NurpP --minimal linux-2.6.37/mm/page_alloc.c linux-2.6.37-vs2.3.0.37-rc3/mm/page_alloc.c
24533 --- linux-2.6.37/mm/page_alloc.c        2011-01-05 21:50:40.000000000 +0100
24534 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/page_alloc.c 2011-01-05 22:30:43.000000000 +0100
24535 @@ -53,6 +53,8 @@
24536  #include <linux/compaction.h>
24537  #include <trace/events/kmem.h>
24538  #include <linux/ftrace_event.h>
24539 +#include <linux/vs_base.h>
24540 +#include <linux/vs_limit.h>
24541  
24542  #include <asm/tlbflush.h>
24543  #include <asm/div64.h>
24544 @@ -2335,6 +2337,9 @@ void si_meminfo(struct sysinfo *val)
24545         val->totalhigh = totalhigh_pages;
24546         val->freehigh = nr_free_highpages();
24547         val->mem_unit = PAGE_SIZE;
24548 +
24549 +       if (vx_flags(VXF_VIRT_MEM, 0))
24550 +               vx_vsi_meminfo(val);
24551  }
24552  
24553  EXPORT_SYMBOL(si_meminfo);
24554 @@ -2355,6 +2360,9 @@ void si_meminfo_node(struct sysinfo *val
24555         val->freehigh = 0;
24556  #endif
24557         val->mem_unit = PAGE_SIZE;
24558 +
24559 +       if (vx_flags(VXF_VIRT_MEM, 0))
24560 +               vx_vsi_meminfo(val);
24561  }
24562  #endif
24563  
24564 diff -NurpP --minimal linux-2.6.37/mm/rmap.c linux-2.6.37-vs2.3.0.37-rc3/mm/rmap.c
24565 --- linux-2.6.37/mm/rmap.c      2011-01-05 21:50:40.000000000 +0100
24566 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/rmap.c       2010-11-23 02:09:41.000000000 +0100
24567 @@ -57,6 +57,7 @@
24568  #include <linux/mmu_notifier.h>
24569  #include <linux/migrate.h>
24570  #include <linux/hugetlb.h>
24571 +#include <linux/vs_memory.h>
24572  
24573  #include <asm/tlbflush.h>
24574  
24575 diff -NurpP --minimal linux-2.6.37/mm/shmem.c linux-2.6.37-vs2.3.0.37-rc3/mm/shmem.c
24576 --- linux-2.6.37/mm/shmem.c     2011-01-05 21:50:40.000000000 +0100
24577 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/shmem.c      2010-11-23 02:09:41.000000000 +0100
24578 @@ -1816,7 +1816,7 @@ static int shmem_statfs(struct dentry *d
24579  {
24580         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24581  
24582 -       buf->f_type = TMPFS_MAGIC;
24583 +       buf->f_type = TMPFS_SUPER_MAGIC;
24584         buf->f_bsize = PAGE_CACHE_SIZE;
24585         buf->f_namelen = NAME_MAX;
24586         if (sbinfo->max_blocks) {
24587 @@ -2378,7 +2378,7 @@ int shmem_fill_super(struct super_block 
24588         sb->s_maxbytes = SHMEM_MAX_BYTES;
24589         sb->s_blocksize = PAGE_CACHE_SIZE;
24590         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24591 -       sb->s_magic = TMPFS_MAGIC;
24592 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24593         sb->s_op = &shmem_ops;
24594         sb->s_time_gran = 1;
24595  #ifdef CONFIG_TMPFS_POSIX_ACL
24596 diff -NurpP --minimal linux-2.6.37/mm/slab.c linux-2.6.37-vs2.3.0.37-rc3/mm/slab.c
24597 --- linux-2.6.37/mm/slab.c      2011-01-05 21:50:40.000000000 +0100
24598 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/slab.c       2010-11-23 02:09:41.000000000 +0100
24599 @@ -407,6 +407,8 @@ static void kmem_list3_init(struct kmem_
24600  #define STATS_INC_FREEMISS(x)  do { } while (0)
24601  #endif
24602  
24603 +#include "slab_vs.h"
24604 +
24605  #if DEBUG
24606  
24607  /*
24608 @@ -3346,6 +3348,7 @@ retry:
24609  
24610         obj = slab_get_obj(cachep, slabp, nodeid);
24611         check_slabp(cachep, slabp);
24612 +       vx_slab_alloc(cachep, flags);
24613         l3->free_objects--;
24614         /* move slabp to correct slabp list: */
24615         list_del(&slabp->list);
24616 @@ -3423,6 +3426,7 @@ __cache_alloc_node(struct kmem_cache *ca
24617         /* ___cache_alloc_node can fall back to other nodes */
24618         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24619    out:
24620 +       vx_slab_alloc(cachep, flags);
24621         local_irq_restore(save_flags);
24622         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24623         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24624 @@ -3609,6 +3613,7 @@ static inline void __cache_free(struct k
24625         check_irq_off();
24626         kmemleak_free_recursive(objp, cachep->flags);
24627         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
24628 +       vx_slab_free(cachep);
24629  
24630         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24631  
24632 diff -NurpP --minimal linux-2.6.37/mm/slab_vs.h linux-2.6.37-vs2.3.0.37-rc3/mm/slab_vs.h
24633 --- linux-2.6.37/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
24634 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/slab_vs.h    2010-11-23 02:09:41.000000000 +0100
24635 @@ -0,0 +1,29 @@
24636 +
24637 +#include <linux/vserver/context.h>
24638 +
24639 +#include <linux/vs_context.h>
24640 +
24641 +static inline
24642 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24643 +{
24644 +       int what = gfp_zone(cachep->gfpflags);
24645 +       struct vx_info *vxi = current_vx_info();
24646 +
24647 +       if (!vxi)
24648 +               return;
24649 +
24650 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24651 +}
24652 +
24653 +static inline
24654 +void vx_slab_free(struct kmem_cache *cachep)
24655 +{
24656 +       int what = gfp_zone(cachep->gfpflags);
24657 +       struct vx_info *vxi = current_vx_info();
24658 +
24659 +       if (!vxi)
24660 +               return;
24661 +
24662 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24663 +}
24664 +
24665 diff -NurpP --minimal linux-2.6.37/mm/swapfile.c linux-2.6.37-vs2.3.0.37-rc3/mm/swapfile.c
24666 --- linux-2.6.37/mm/swapfile.c  2011-01-05 21:50:40.000000000 +0100
24667 +++ linux-2.6.37-vs2.3.0.37-rc3/mm/swapfile.c   2010-11-23 02:09:41.000000000 +0100
24668 @@ -36,6 +36,8 @@
24669  #include <asm/tlbflush.h>
24670  #include <linux/swapops.h>
24671  #include <linux/page_cgroup.h>
24672 +#include <linux/vs_base.h>
24673 +#include <linux/vs_memory.h>
24674  
24675  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24676                                  unsigned char);
24677 @@ -1773,6 +1775,16 @@ static int swap_show(struct seq_file *sw
24678  
24679         if (si == SEQ_START_TOKEN) {
24680                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24681 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24682 +                       struct sysinfo si;
24683 +
24684 +                       vx_vsi_swapinfo(&si);
24685 +                       if (si.totalswap < (1 << 10))
24686 +                               return 0;
24687 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24688 +                               "hdv0", "partition", si.totalswap >> 10,
24689 +                               (si.totalswap - si.freeswap) >> 10, -1);
24690 +               }
24691                 return 0;
24692         }
24693  
24694 @@ -2178,6 +2190,8 @@ void si_swapinfo(struct sysinfo *val)
24695         val->freeswap = nr_swap_pages + nr_to_be_unused;
24696         val->totalswap = total_swap_pages + nr_to_be_unused;
24697         spin_unlock(&swap_lock);
24698 +       if (vx_flags(VXF_VIRT_MEM, 0))
24699 +               vx_vsi_swapinfo(val);
24700  }
24701  
24702  /*
24703 diff -NurpP --minimal linux-2.6.37/net/core/dev.c linux-2.6.37-vs2.3.0.37-rc3/net/core/dev.c
24704 --- linux-2.6.37/net/core/dev.c 2011-01-05 21:50:41.000000000 +0100
24705 +++ linux-2.6.37-vs2.3.0.37-rc3/net/core/dev.c  2010-11-23 02:09:41.000000000 +0100
24706 @@ -127,6 +127,7 @@
24707  #include <linux/in.h>
24708  #include <linux/jhash.h>
24709  #include <linux/random.h>
24710 +#include <linux/vs_inet.h>
24711  #include <trace/events/napi.h>
24712  #include <trace/events/net.h>
24713  #include <trace/events/skb.h>
24714 @@ -608,7 +609,8 @@ struct net_device *__dev_get_by_name(str
24715         struct hlist_head *head = dev_name_hash(net, name);
24716  
24717         hlist_for_each_entry(dev, p, head, name_hlist)
24718 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24719 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24720 +                   nx_dev_visible(current_nx_info(), dev))
24721                         return dev;
24722  
24723         return NULL;
24724 @@ -634,7 +636,8 @@ struct net_device *dev_get_by_name_rcu(s
24725         struct hlist_head *head = dev_name_hash(net, name);
24726  
24727         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24728 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24729 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24730 +                   nx_dev_visible(current_nx_info(), dev))
24731                         return dev;
24732  
24733         return NULL;
24734 @@ -685,7 +688,8 @@ struct net_device *__dev_get_by_index(st
24735         struct hlist_head *head = dev_index_hash(net, ifindex);
24736  
24737         hlist_for_each_entry(dev, p, head, index_hlist)
24738 -               if (dev->ifindex == ifindex)
24739 +               if ((dev->ifindex == ifindex) &&
24740 +                   nx_dev_visible(current_nx_info(), dev))
24741                         return dev;
24742  
24743         return NULL;
24744 @@ -710,7 +714,8 @@ struct net_device *dev_get_by_index_rcu(
24745         struct hlist_head *head = dev_index_hash(net, ifindex);
24746  
24747         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
24748 -               if (dev->ifindex == ifindex)
24749 +               if ((dev->ifindex == ifindex) &&
24750 +                   nx_dev_visible(current_nx_info(), dev))
24751                         return dev;
24752  
24753         return NULL;
24754 @@ -763,10 +768,12 @@ struct net_device *dev_getbyhwaddr(struc
24755  
24756         ASSERT_RTNL();
24757  
24758 -       for_each_netdev(net, dev)
24759 +       for_each_netdev(net, dev) {
24760                 if (dev->type == type &&
24761 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24762 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24763 +                   nx_dev_visible(current_nx_info(), dev))
24764                         return dev;
24765 +       }
24766  
24767         return NULL;
24768  }
24769 @@ -777,9 +784,11 @@ struct net_device *__dev_getfirstbyhwtyp
24770         struct net_device *dev;
24771  
24772         ASSERT_RTNL();
24773 -       for_each_netdev(net, dev)
24774 -               if (dev->type == type)
24775 +       for_each_netdev(net, dev) {
24776 +               if ((dev->type == type) &&
24777 +                   nx_dev_visible(current_nx_info(), dev))
24778                         return dev;
24779 +       }
24780  
24781         return NULL;
24782  }
24783 @@ -897,6 +906,8 @@ static int __dev_alloc_name(struct net *
24784                                 continue;
24785                         if (i < 0 || i >= max_netdevices)
24786                                 continue;
24787 +                       if (!nx_dev_visible(current_nx_info(), d))
24788 +                               continue;
24789  
24790                         /*  avoid cases where sscanf is not exact inverse of printf */
24791                         snprintf(buf, IFNAMSIZ, name, i);
24792 @@ -3746,6 +3757,8 @@ static int dev_ifconf(struct net *net, c
24793  
24794         total = 0;
24795         for_each_netdev(net, dev) {
24796 +               if (!nx_dev_visible(current_nx_info(), dev))
24797 +                       continue;
24798                 for (i = 0; i < NPROTO; i++) {
24799                         if (gifconf_list[i]) {
24800                                 int done;
24801 @@ -3817,6 +3830,10 @@ static void dev_seq_printf_stats(struct 
24802         struct rtnl_link_stats64 temp;
24803         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24804  
24805 +       /* device visible inside network context? */
24806 +       if (!nx_dev_visible(current_nx_info(), dev))
24807 +               return;
24808 +
24809         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24810                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24811                    dev->name, stats->rx_bytes, stats->rx_packets,
24812 diff -NurpP --minimal linux-2.6.37/net/core/rtnetlink.c linux-2.6.37-vs2.3.0.37-rc3/net/core/rtnetlink.c
24813 --- linux-2.6.37/net/core/rtnetlink.c   2011-01-05 21:50:41.000000000 +0100
24814 +++ linux-2.6.37-vs2.3.0.37-rc3/net/core/rtnetlink.c    2010-11-23 02:09:41.000000000 +0100
24815 @@ -891,6 +891,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24816                 hlist_for_each_entry(dev, node, head, index_hlist) {
24817                         if (idx < s_idx)
24818                                 goto cont;
24819 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24820 +                               continue;
24821                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24822                                              NETLINK_CB(cb->skb).pid,
24823                                              cb->nlh->nlmsg_seq, 0,
24824 @@ -1607,6 +1609,9 @@ void rtmsg_ifinfo(int type, struct net_d
24825         struct sk_buff *skb;
24826         int err = -ENOBUFS;
24827  
24828 +       if (!nx_dev_visible(current_nx_info(), dev))
24829 +               return;
24830 +
24831         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
24832         if (skb == NULL)
24833                 goto errout;
24834 diff -NurpP --minimal linux-2.6.37/net/core/sock.c linux-2.6.37-vs2.3.0.37-rc3/net/core/sock.c
24835 --- linux-2.6.37/net/core/sock.c        2011-01-05 21:50:41.000000000 +0100
24836 +++ linux-2.6.37-vs2.3.0.37-rc3/net/core/sock.c 2011-01-05 22:30:43.000000000 +0100
24837 @@ -127,6 +127,10 @@
24838  #include <net/cls_cgroup.h>
24839  
24840  #include <linux/filter.h>
24841 +#include <linux/vs_socket.h>
24842 +#include <linux/vs_limit.h>
24843 +#include <linux/vs_context.h>
24844 +#include <linux/vs_network.h>
24845  
24846  #ifdef CONFIG_INET
24847  #include <net/tcp.h>
24848 @@ -1069,6 +1073,8 @@ static struct sock *sk_prot_alloc(struct
24849                         goto out_free_sec;
24850                 sk_tx_queue_clear(sk);
24851         }
24852 +               sock_vx_init(sk);
24853 +               sock_nx_init(sk);
24854  
24855         return sk;
24856  
24857 @@ -1168,6 +1174,11 @@ static void __sk_free(struct sock *sk)
24858                 put_cred(sk->sk_peer_cred);
24859         put_pid(sk->sk_peer_pid);
24860         put_net(sock_net(sk));
24861 +       vx_sock_dec(sk);
24862 +       clr_vx_info(&sk->sk_vx_info);
24863 +       sk->sk_xid = -1;
24864 +       clr_nx_info(&sk->sk_nx_info);
24865 +       sk->sk_nid = -1;
24866         sk_prot_free(sk->sk_prot_creator, sk);
24867  }
24868  
24869 @@ -1215,6 +1226,8 @@ struct sock *sk_clone(const struct sock 
24870  
24871                 /* SANITY */
24872                 get_net(sock_net(newsk));
24873 +               sock_vx_init(newsk);
24874 +               sock_nx_init(newsk);
24875                 sk_node_init(&newsk->sk_node);
24876                 sock_lock_init(newsk);
24877                 bh_lock_sock(newsk);
24878 @@ -1270,6 +1283,12 @@ struct sock *sk_clone(const struct sock 
24879                 smp_wmb();
24880                 atomic_set(&newsk->sk_refcnt, 2);
24881  
24882 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24883 +               newsk->sk_xid = sk->sk_xid;
24884 +               vx_sock_inc(newsk);
24885 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24886 +               newsk->sk_nid = sk->sk_nid;
24887 +
24888                 /*
24889                  * Increment the counter in the same struct proto as the master
24890                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24891 @@ -2016,6 +2035,12 @@ void sock_init_data(struct socket *sock,
24892  
24893         sk->sk_stamp = ktime_set(-1L, 0);
24894  
24895 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24896 +       sk->sk_xid = vx_current_xid();
24897 +       vx_sock_inc(sk);
24898 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24899 +       sk->sk_nid = nx_current_nid();
24900 +
24901         /*
24902          * Before updating sk_refcnt, we must commit prior changes to memory
24903          * (Documentation/RCU/rculist_nulls.txt for details)
24904 diff -NurpP --minimal linux-2.6.37/net/ipv4/af_inet.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/af_inet.c
24905 --- linux-2.6.37/net/ipv4/af_inet.c     2011-01-05 21:50:41.000000000 +0100
24906 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/af_inet.c      2010-11-23 02:09:41.000000000 +0100
24907 @@ -116,6 +116,7 @@
24908  #ifdef CONFIG_IP_MROUTE
24909  #include <linux/mroute.h>
24910  #endif
24911 +#include <linux/vs_limit.h>
24912  
24913  
24914  /* The inetsw table contains everything that inet_create needs to
24915 @@ -325,9 +326,13 @@ lookup_protocol:
24916         }
24917  
24918         err = -EPERM;
24919 +       if ((protocol == IPPROTO_ICMP) &&
24920 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24921 +               goto override;
24922 +
24923         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24924                 goto out_rcu_unlock;
24925 -
24926 +override:
24927         err = -EAFNOSUPPORT;
24928         if (!inet_netns_ok(net, protocol))
24929                 goto out_rcu_unlock;
24930 @@ -451,6 +456,7 @@ int inet_bind(struct socket *sock, struc
24931         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24932         struct sock *sk = sock->sk;
24933         struct inet_sock *inet = inet_sk(sk);
24934 +       struct nx_v4_sock_addr nsa;
24935         unsigned short snum;
24936         int chk_addr_ret;
24937         int err;
24938 @@ -464,7 +470,11 @@ int inet_bind(struct socket *sock, struc
24939         if (addr_len < sizeof(struct sockaddr_in))
24940                 goto out;
24941  
24942 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24943 +       err = v4_map_sock_addr(inet, addr, &nsa);
24944 +       if (err)
24945 +               goto out;
24946 +
24947 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24948  
24949         /* Not specified by any standard per-se, however it breaks too
24950          * many applications when removed.  It is unfortunate since
24951 @@ -476,7 +486,7 @@ int inet_bind(struct socket *sock, struc
24952         err = -EADDRNOTAVAIL;
24953         if (!sysctl_ip_nonlocal_bind &&
24954             !(inet->freebind || inet->transparent) &&
24955 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24956 +           nsa.saddr != htonl(INADDR_ANY) &&
24957             chk_addr_ret != RTN_LOCAL &&
24958             chk_addr_ret != RTN_MULTICAST &&
24959             chk_addr_ret != RTN_BROADCAST)
24960 @@ -501,7 +511,7 @@ int inet_bind(struct socket *sock, struc
24961         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24962                 goto out_release_sock;
24963  
24964 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24965 +       v4_set_sock_addr(inet, &nsa);
24966         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24967                 inet->inet_saddr = 0;  /* Use device */
24968  
24969 @@ -703,11 +713,13 @@ int inet_getname(struct socket *sock, st
24970                      peer == 1))
24971                         return -ENOTCONN;
24972                 sin->sin_port = inet->inet_dport;
24973 -               sin->sin_addr.s_addr = inet->inet_daddr;
24974 +               sin->sin_addr.s_addr =
24975 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24976         } else {
24977                 __be32 addr = inet->inet_rcv_saddr;
24978                 if (!addr)
24979                         addr = inet->inet_saddr;
24980 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24981                 sin->sin_port = inet->inet_sport;
24982                 sin->sin_addr.s_addr = addr;
24983         }
24984 diff -NurpP --minimal linux-2.6.37/net/ipv4/devinet.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/devinet.c
24985 --- linux-2.6.37/net/ipv4/devinet.c     2011-01-05 21:50:41.000000000 +0100
24986 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/devinet.c      2010-11-23 02:09:41.000000000 +0100
24987 @@ -420,6 +420,7 @@ struct in_device *inetdev_by_index(struc
24988  }
24989  EXPORT_SYMBOL(inetdev_by_index);
24990  
24991 +
24992  /* Called only from RTNL semaphored context. No locks. */
24993  
24994  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24995 @@ -660,6 +661,8 @@ int devinet_ioctl(struct net *net, unsig
24996  
24997         in_dev = __in_dev_get_rtnl(dev);
24998         if (in_dev) {
24999 +               struct nx_info *nxi = current_nx_info();
25000 +
25001                 if (tryaddrmatch) {
25002                         /* Matthias Andree */
25003                         /* compare label and address (4.4BSD style) */
25004 @@ -668,6 +671,8 @@ int devinet_ioctl(struct net *net, unsig
25005                            This is checked above. */
25006                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25007                              ifap = &ifa->ifa_next) {
25008 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25009 +                                       continue;
25010                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
25011                                     sin_orig.sin_addr.s_addr ==
25012                                                         ifa->ifa_address) {
25013 @@ -680,9 +685,12 @@ int devinet_ioctl(struct net *net, unsig
25014                    comparing just the label */
25015                 if (!ifa) {
25016                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25017 -                            ifap = &ifa->ifa_next)
25018 +                            ifap = &ifa->ifa_next) {
25019 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25020 +                                       continue;
25021                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
25022                                         break;
25023 +                       }
25024                 }
25025         }
25026  
25027 @@ -834,6 +842,8 @@ static int inet_gifconf(struct net_devic
25028                 goto out;
25029  
25030         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
25031 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
25032 +                       continue;
25033                 if (!buf) {
25034                         done += sizeof(ifr);
25035                         continue;
25036 @@ -1183,6 +1193,7 @@ static int inet_dump_ifaddr(struct sk_bu
25037         struct net_device *dev;
25038         struct in_device *in_dev;
25039         struct in_ifaddr *ifa;
25040 +       struct sock *sk = skb->sk;
25041         struct hlist_head *head;
25042         struct hlist_node *node;
25043  
25044 @@ -1205,6 +1216,8 @@ static int inet_dump_ifaddr(struct sk_bu
25045  
25046                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
25047                              ifa = ifa->ifa_next, ip_idx++) {
25048 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
25049 +                               continue;
25050                                 if (ip_idx < s_ip_idx)
25051                                         continue;
25052                                 if (inet_fill_ifaddr(skb, ifa,
25053 diff -NurpP --minimal linux-2.6.37/net/ipv4/fib_hash.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/fib_hash.c
25054 --- linux-2.6.37/net/ipv4/fib_hash.c    2011-01-05 21:50:41.000000000 +0100
25055 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/fib_hash.c     2010-11-23 02:09:41.000000000 +0100
25056 @@ -1080,7 +1080,7 @@ static int fib_seq_show(struct seq_file 
25057         prefix  = f->fn_key;
25058         mask    = FZ_MASK(iter->zone);
25059         flags   = fib_flag_trans(fa->fa_type, mask, fi);
25060 -       if (fi)
25061 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
25062                 seq_printf(seq,
25063                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
25064                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
25065 diff -NurpP --minimal linux-2.6.37/net/ipv4/inet_connection_sock.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/inet_connection_sock.c
25066 --- linux-2.6.37/net/ipv4/inet_connection_sock.c        2010-10-21 13:07:58.000000000 +0200
25067 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/inet_connection_sock.c 2010-11-23 02:09:41.000000000 +0100
25068 @@ -52,10 +52,40 @@ void inet_get_local_port_range(int *low,
25069  }
25070  EXPORT_SYMBOL(inet_get_local_port_range);
25071  
25072 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25073 +{
25074 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
25075 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
25076 +
25077 +       if (inet_v6_ipv6only(sk2))
25078 +               return 0;
25079 +
25080 +       if (sk1_rcv_saddr &&
25081 +           sk2_rcv_saddr &&
25082 +           sk1_rcv_saddr == sk2_rcv_saddr)
25083 +               return 1;
25084 +
25085 +       if (sk1_rcv_saddr &&
25086 +           !sk2_rcv_saddr &&
25087 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
25088 +               return 1;
25089 +
25090 +       if (sk2_rcv_saddr &&
25091 +           !sk1_rcv_saddr &&
25092 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
25093 +               return 1;
25094 +
25095 +       if (!sk1_rcv_saddr &&
25096 +           !sk2_rcv_saddr &&
25097 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
25098 +               return 1;
25099 +
25100 +       return 0;
25101 +}
25102 +
25103  int inet_csk_bind_conflict(const struct sock *sk,
25104                            const struct inet_bind_bucket *tb)
25105  {
25106 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
25107         struct sock *sk2;
25108         struct hlist_node *node;
25109         int reuse = sk->sk_reuse;
25110 @@ -75,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25111                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25112                         if (!reuse || !sk2->sk_reuse ||
25113                             sk2->sk_state == TCP_LISTEN) {
25114 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
25115 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
25116 -                                   sk2_rcv_saddr == sk_rcv_saddr)
25117 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25118                                         break;
25119                         }
25120                 }
25121 diff -NurpP --minimal linux-2.6.37/net/ipv4/inet_diag.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/inet_diag.c
25122 --- linux-2.6.37/net/ipv4/inet_diag.c   2011-01-05 21:50:42.000000000 +0100
25123 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/inet_diag.c    2010-11-23 02:09:41.000000000 +0100
25124 @@ -33,6 +33,8 @@
25125  #include <linux/stddef.h>
25126  
25127  #include <linux/inet_diag.h>
25128 +#include <linux/vs_network.h>
25129 +#include <linux/vs_inet.h>
25130  
25131  static const struct inet_diag_handler **inet_diag_table;
25132  
25133 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25134  
25135         r->id.idiag_sport = inet->inet_sport;
25136         r->id.idiag_dport = inet->inet_dport;
25137 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25138 -       r->id.idiag_dst[0] = inet->inet_daddr;
25139 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25140 +               inet->inet_rcv_saddr);
25141 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25142 +               inet->inet_daddr);
25143  
25144  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25145         if (r->idiag_family == AF_INET6) {
25146 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25147         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25148         r->id.idiag_sport     = tw->tw_sport;
25149         r->id.idiag_dport     = tw->tw_dport;
25150 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25151 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25152 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25153 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25154         r->idiag_state        = tw->tw_substate;
25155         r->idiag_timer        = 3;
25156         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25157 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25158         err = -EINVAL;
25159  
25160         if (req->idiag_family == AF_INET) {
25161 +               /* TODO: lback */
25162                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25163                                  req->id.idiag_dport, req->id.idiag_src[0],
25164                                  req->id.idiag_sport, req->id.idiag_if);
25165 @@ -507,6 +512,7 @@ static int inet_csk_diag_dump(struct soc
25166                 } else
25167  #endif
25168                 {
25169 +                       /* TODO: lback */
25170                         entry.saddr = &inet->inet_rcv_saddr;
25171                         entry.daddr = &inet->inet_daddr;
25172                 }
25173 @@ -545,6 +551,7 @@ static int inet_twsk_diag_dump(struct in
25174                 } else
25175  #endif
25176                 {
25177 +                       /* TODO: lback */
25178                         entry.saddr = &tw->tw_rcv_saddr;
25179                         entry.daddr = &tw->tw_daddr;
25180                 }
25181 @@ -591,8 +598,8 @@ static int inet_diag_fill_req(struct sk_
25182  
25183         r->id.idiag_sport = inet->inet_sport;
25184         r->id.idiag_dport = ireq->rmt_port;
25185 -       r->id.idiag_src[0] = ireq->loc_addr;
25186 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25187 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25188 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25189         r->idiag_expires = jiffies_to_msecs(tmo);
25190         r->idiag_rqueue = 0;
25191         r->idiag_wqueue = 0;
25192 @@ -663,6 +670,7 @@ static int inet_diag_dump_reqs(struct sk
25193                                 continue;
25194  
25195                         if (bc) {
25196 +                               /* TODO: lback */
25197                                 entry.saddr =
25198  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25199                                         (entry.family == AF_INET6) ?
25200 @@ -733,6 +741,8 @@ static int inet_diag_dump(struct sk_buff
25201                         sk_nulls_for_each(sk, node, &ilb->head) {
25202                                 struct inet_sock *inet = inet_sk(sk);
25203  
25204 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25205 +                                       continue;
25206                                 if (num < s_num) {
25207                                         num++;
25208                                         continue;
25209 @@ -799,6 +809,8 @@ skip_listen_ht:
25210                 sk_nulls_for_each(sk, node, &head->chain) {
25211                         struct inet_sock *inet = inet_sk(sk);
25212  
25213 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25214 +                               continue;
25215                         if (num < s_num)
25216                                 goto next_normal;
25217                         if (!(r->idiag_states & (1 << sk->sk_state)))
25218 @@ -823,6 +835,8 @@ next_normal:
25219                         inet_twsk_for_each(tw, node,
25220                                     &head->twchain) {
25221  
25222 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25223 +                                       continue;
25224                                 if (num < s_num)
25225                                         goto next_dying;
25226                                 if (r->id.idiag_sport != tw->tw_sport &&
25227 diff -NurpP --minimal linux-2.6.37/net/ipv4/inet_hashtables.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/inet_hashtables.c
25228 --- linux-2.6.37/net/ipv4/inet_hashtables.c     2011-01-05 21:50:42.000000000 +0100
25229 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/inet_hashtables.c      2011-01-05 22:30:43.000000000 +0100
25230 @@ -21,6 +21,7 @@
25231  
25232  #include <net/inet_connection_sock.h>
25233  #include <net/inet_hashtables.h>
25234 +#include <net/route.h>
25235  #include <net/ip.h>
25236  
25237  /*
25238 @@ -155,6 +156,11 @@ static inline int compute_score(struct s
25239                         if (rcv_saddr != daddr)
25240                                 return -1;
25241                         score += 2;
25242 +               } else {
25243 +                       /* block non nx_info ips */
25244 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25245 +                               daddr, NXA_MASK_BIND))
25246 +                               return -1;
25247                 }
25248                 if (sk->sk_bound_dev_if) {
25249                         if (sk->sk_bound_dev_if != dif)
25250 @@ -172,7 +178,6 @@ static inline int compute_score(struct s
25251   * wildcarded during the search since they can never be otherwise.
25252   */
25253  
25254 -
25255  struct sock *__inet_lookup_listener(struct net *net,
25256                                     struct inet_hashinfo *hashinfo,
25257                                     const __be32 daddr, const unsigned short hnum,
25258 @@ -195,6 +200,7 @@ begin:
25259                         hiscore = score;
25260                 }
25261         }
25262 +
25263         /*
25264          * if the nulls value we got at the end of this lookup is
25265          * not the expected one, we must restart lookup.
25266 diff -NurpP --minimal linux-2.6.37/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/netfilter/nf_nat_helper.c
25267 --- linux-2.6.37/net/ipv4/netfilter/nf_nat_helper.c     2011-01-05 21:50:42.000000000 +0100
25268 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/netfilter/nf_nat_helper.c      2010-11-23 02:09:41.000000000 +0100
25269 @@ -20,6 +20,7 @@
25270  #include <net/route.h>
25271  
25272  #include <linux/netfilter_ipv4.h>
25273 +#include <net/route.h>
25274  #include <net/netfilter/nf_conntrack.h>
25275  #include <net/netfilter/nf_conntrack_helper.h>
25276  #include <net/netfilter/nf_conntrack_ecache.h>
25277 diff -NurpP --minimal linux-2.6.37/net/ipv4/netfilter.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/netfilter.c
25278 --- linux-2.6.37/net/ipv4/netfilter.c   2010-10-21 13:07:58.000000000 +0200
25279 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/netfilter.c    2010-11-23 02:09:41.000000000 +0100
25280 @@ -5,7 +5,7 @@
25281  #include <linux/ip.h>
25282  #include <linux/skbuff.h>
25283  #include <linux/gfp.h>
25284 -#include <net/route.h>
25285 +// #include <net/route.h>
25286  #include <net/xfrm.h>
25287  #include <net/ip.h>
25288  #include <net/netfilter/nf_queue.h>
25289 diff -NurpP --minimal linux-2.6.37/net/ipv4/raw.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/raw.c
25290 --- linux-2.6.37/net/ipv4/raw.c 2011-01-05 21:50:42.000000000 +0100
25291 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/raw.c  2010-11-23 02:09:41.000000000 +0100
25292 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
25293  
25294                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25295                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25296 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25297 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25298                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25299                         goto found; /* gotcha */
25300         }
25301 @@ -383,6 +383,12 @@ static int raw_send_hdrinc(struct sock *
25302                 icmp_out_count(net, ((struct icmphdr *)
25303                         skb_transport_header(skb))->type);
25304  
25305 +       err = -EPERM;
25306 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25307 +               sk->sk_nx_info &&
25308 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25309 +               goto error_free;
25310 +
25311         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25312                       rt->dst.dev, dst_output);
25313         if (err > 0)
25314 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
25315                 }
25316  
25317                 security_sk_classify_flow(sk, &fl);
25318 +               if (sk->sk_nx_info) {
25319 +                       err = ip_v4_find_src(sock_net(sk),
25320 +                               sk->sk_nx_info, &rt, &fl);
25321 +
25322 +                       if (err)
25323 +                               goto done;
25324 +               }
25325                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
25326         }
25327         if (err)
25328 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
25329  {
25330         struct inet_sock *inet = inet_sk(sk);
25331         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25332 +       struct nx_v4_sock_addr nsa = { 0 };
25333         int ret = -EINVAL;
25334         int chk_addr_ret;
25335  
25336         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25337                 goto out;
25338 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25339 +       v4_map_sock_addr(inet, addr, &nsa);
25340 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25341         ret = -EADDRNOTAVAIL;
25342 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25343 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25344             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25345                 goto out;
25346 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25347 +       v4_set_sock_addr(inet, &nsa);
25348         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25349                 inet->inet_saddr = 0;  /* Use device */
25350         sk_dst_reset(sk);
25351 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
25352         /* Copy the address. */
25353         if (sin) {
25354                 sin->sin_family = AF_INET;
25355 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25356 +               sin->sin_addr.s_addr =
25357 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25358                 sin->sin_port = 0;
25359                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25360         }
25361 @@ -875,7 +891,8 @@ static struct sock *raw_get_first(struct
25362                 struct hlist_node *node;
25363  
25364                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25365 -                       if (sock_net(sk) == seq_file_net(seq))
25366 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25367 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25368                                 goto found;
25369         }
25370         sk = NULL;
25371 @@ -891,7 +908,8 @@ static struct sock *raw_get_next(struct 
25372                 sk = sk_next(sk);
25373  try_again:
25374                 ;
25375 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25376 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25377 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25378  
25379         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25380                 sk = sk_head(&state->h->ht[state->bucket]);
25381 @@ -950,7 +968,10 @@ static void raw_sock_seq_show(struct seq
25382  
25383         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
25384                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
25385 -               i, src, srcp, dest, destp, sp->sk_state,
25386 +               i,
25387 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25388 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25389 +               sp->sk_state,
25390                 sk_wmem_alloc_get(sp),
25391                 sk_rmem_alloc_get(sp),
25392                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25393 diff -NurpP --minimal linux-2.6.37/net/ipv4/tcp.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/tcp.c
25394 --- linux-2.6.37/net/ipv4/tcp.c 2011-01-05 21:50:42.000000000 +0100
25395 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/tcp.c  2011-01-05 22:30:43.000000000 +0100
25396 @@ -266,6 +266,7 @@
25397  #include <linux/crypto.h>
25398  #include <linux/time.h>
25399  #include <linux/slab.h>
25400 +#include <linux/in.h>
25401  
25402  #include <net/icmp.h>
25403  #include <net/tcp.h>
25404 diff -NurpP --minimal linux-2.6.37/net/ipv4/tcp_ipv4.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/tcp_ipv4.c
25405 --- linux-2.6.37/net/ipv4/tcp_ipv4.c    2011-01-05 21:50:42.000000000 +0100
25406 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/tcp_ipv4.c     2011-01-05 22:33:32.000000000 +0100
25407 @@ -2018,6 +2018,12 @@ static void *listening_get_next(struct s
25408                 req = req->dl_next;
25409                 while (1) {
25410                         while (req) {
25411 +                               vxdprintk(VXD_CBIT(net, 6),
25412 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25413 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25414 +                               if (req->sk &&
25415 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25416 +                                       continue;
25417                                 if (req->rsk_ops->family == st->family) {
25418                                         cur = req;
25419                                         goto out;
25420 @@ -2043,6 +2049,10 @@ get_req:
25421         }
25422  get_sk:
25423         sk_nulls_for_each_from(sk, node) {
25424 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25425 +                       sk, sk->sk_nid, nx_current_nid());
25426 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25427 +                       continue;
25428                 if (!net_eq(sock_net(sk), net))
25429                         continue;
25430                 if (sk->sk_family == st->family) {
25431 @@ -2119,6 +2129,11 @@ static void *established_get_first(struc
25432  
25433                 spin_lock_bh(lock);
25434                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25435 +                       vxdprintk(VXD_CBIT(net, 6),
25436 +                               "sk,egf: %p [#%d] (from %d)",
25437 +                               sk, sk->sk_nid, nx_current_nid());
25438 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25439 +                               continue;
25440                         if (sk->sk_family != st->family ||
25441                             !net_eq(sock_net(sk), net)) {
25442                                 continue;
25443 @@ -2129,6 +2144,11 @@ static void *established_get_first(struc
25444                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25445                 inet_twsk_for_each(tw, node,
25446                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25447 +                       vxdprintk(VXD_CBIT(net, 6),
25448 +                               "tw: %p [#%d] (from %d)",
25449 +                               tw, tw->tw_nid, nx_current_nid());
25450 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25451 +                               continue;
25452                         if (tw->tw_family != st->family ||
25453                             !net_eq(twsk_net(tw), net)) {
25454                                 continue;
25455 @@ -2158,7 +2178,9 @@ static void *established_get_next(struct
25456                 tw = cur;
25457                 tw = tw_next(tw);
25458  get_tw:
25459 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25460 +               while (tw && (tw->tw_family != st->family ||
25461 +                       !net_eq(twsk_net(tw), net) ||
25462 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25463                         tw = tw_next(tw);
25464                 }
25465                 if (tw) {
25466 @@ -2182,6 +2204,11 @@ get_tw:
25467                 sk = sk_nulls_next(sk);
25468  
25469         sk_nulls_for_each_from(sk, node) {
25470 +               vxdprintk(VXD_CBIT(net, 6),
25471 +                       "sk,egn: %p [#%d] (from %d)",
25472 +                       sk, sk->sk_nid, nx_current_nid());
25473 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25474 +                       continue;
25475                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25476                         goto found;
25477         }
25478 @@ -2391,9 +2418,9 @@ static void get_openreq4(struct sock *sk
25479         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25480                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
25481                 i,
25482 -               ireq->loc_addr,
25483 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25484                 ntohs(inet_sk(sk)->inet_sport),
25485 -               ireq->rmt_addr,
25486 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25487                 ntohs(ireq->rmt_port),
25488                 TCP_SYN_RECV,
25489                 0, 0, /* could print option size, but that is af dependent. */
25490 @@ -2445,7 +2472,10 @@ static void get_tcp4_sock(struct sock *s
25491  
25492         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
25493                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
25494 -               i, src, srcp, dest, destp, sk->sk_state,
25495 +               i,
25496 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25497 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25498 +               sk->sk_state,
25499                 tp->write_seq - tp->snd_una,
25500                 rx_queue,
25501                 timer_active,
25502 @@ -2480,7 +2510,10 @@ static void get_timewait4_sock(struct in
25503  
25504         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25505                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
25506 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
25507 +               i,
25508 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25509 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25510 +               tw->tw_substate, 0, 0,
25511                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
25512                 atomic_read(&tw->tw_refcnt), tw, len);
25513  }
25514 diff -NurpP --minimal linux-2.6.37/net/ipv4/tcp_minisocks.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/tcp_minisocks.c
25515 --- linux-2.6.37/net/ipv4/tcp_minisocks.c       2011-01-05 21:50:42.000000000 +0100
25516 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/tcp_minisocks.c        2011-01-05 22:30:43.000000000 +0100
25517 @@ -23,6 +23,9 @@
25518  #include <linux/slab.h>
25519  #include <linux/sysctl.h>
25520  #include <linux/workqueue.h>
25521 +#include <linux/vs_limit.h>
25522 +#include <linux/vs_socket.h>
25523 +#include <linux/vs_context.h>
25524  #include <net/tcp.h>
25525  #include <net/inet_common.h>
25526  #include <net/xfrm.h>
25527 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int 
25528                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25529                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25530  
25531 +               tw->tw_xid              = sk->sk_xid;
25532 +               tw->tw_vx_info          = NULL;
25533 +               tw->tw_nid              = sk->sk_nid;
25534 +               tw->tw_nx_info          = NULL;
25535 +
25536  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25537                 if (tw->tw_family == PF_INET6) {
25538                         struct ipv6_pinfo *np = inet6_sk(sk);
25539 diff -NurpP --minimal linux-2.6.37/net/ipv4/udp.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/udp.c
25540 --- linux-2.6.37/net/ipv4/udp.c 2011-01-05 21:50:42.000000000 +0100
25541 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv4/udp.c  2011-01-05 22:30:43.000000000 +0100
25542 @@ -296,14 +296,7 @@ fail:
25543  }
25544  EXPORT_SYMBOL(udp_lib_get_port);
25545  
25546 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25547 -{
25548 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25549 -
25550 -       return  (!ipv6_only_sock(sk2)  &&
25551 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25552 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25553 -}
25554 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25555  
25556  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25557                                        unsigned int port)
25558 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
25559                         if (inet->inet_rcv_saddr != daddr)
25560                                 return -1;
25561                         score += 2;
25562 +               } else {
25563 +                       /* block non nx_info ips */
25564 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25565 +                               daddr, NXA_MASK_BIND))
25566 +                               return -1;
25567                 }
25568                 if (inet->inet_daddr) {
25569                         if (inet->inet_daddr != saddr)
25570 @@ -441,6 +439,7 @@ exact_match:
25571         return result;
25572  }
25573  
25574 +
25575  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25576   * harder than this. -DaveM
25577   */
25578 @@ -486,6 +485,11 @@ begin:
25579         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25580                 score = compute_score(sk, net, saddr, hnum, sport,
25581                                       daddr, dport, dif);
25582 +               /* FIXME: disabled?
25583 +               if (score == 9) {
25584 +                       result = sk;
25585 +                       break;
25586 +               } else */
25587                 if (score > badness) {
25588                         result = sk;
25589                         badness = score;
25590 @@ -499,6 +503,7 @@ begin:
25591         if (get_nulls_value(node) != slot)
25592                 goto begin;
25593  
25594 +
25595         if (result) {
25596                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
25597                         result = NULL;
25598 @@ -508,6 +513,7 @@ begin:
25599                         goto begin;
25600                 }
25601         }
25602 +
25603         rcu_read_unlock();
25604         return result;
25605  }
25606 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
25607                     udp_sk(s)->udp_port_hash != hnum ||
25608                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25609                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25610 -                   (inet->inet_rcv_saddr &&
25611 -                    inet->inet_rcv_saddr != loc_addr) ||
25612 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25613                     ipv6_only_sock(s) ||
25614                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25615                         continue;
25616 @@ -900,8 +905,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
25617                                                { .sport = inet->inet_sport,
25618                                                  .dport = dport } } };
25619                 struct net *net = sock_net(sk);
25620 +               struct nx_info *nxi = sk->sk_nx_info;
25621  
25622                 security_sk_classify_flow(sk, &fl);
25623 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
25624 +               if (err)
25625 +                       goto out;
25626 +
25627                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
25628                 if (err) {
25629                         if (err == -ENETUNREACH)
25630 @@ -1183,7 +1193,8 @@ try_again:
25631         if (sin) {
25632                 sin->sin_family = AF_INET;
25633                 sin->sin_port = udp_hdr(skb)->source;
25634 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25635 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25636 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25637                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25638         }
25639         if (inet->cmsg_flags)
25640 @@ -1924,6 +1935,8 @@ static struct sock *udp_get_first(struct
25641                 sk_nulls_for_each(sk, node, &hslot->head) {
25642                         if (!net_eq(sock_net(sk), net))
25643                                 continue;
25644 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25645 +                               continue;
25646                         if (sk->sk_family == state->family)
25647                                 goto found;
25648                 }
25649 @@ -1941,7 +1954,9 @@ static struct sock *udp_get_next(struct 
25650  
25651         do {
25652                 sk = sk_nulls_next(sk);
25653 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25654 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25655 +               sk->sk_family != state->family ||
25656 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25657  
25658         if (!sk) {
25659                 if (state->bucket <= state->udp_table->mask)
25660 @@ -2048,7 +2063,10 @@ static void udp4_format_sock(struct sock
25661  
25662         seq_printf(f, "%5d: %08X:%04X %08X:%04X"
25663                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
25664 -               bucket, src, srcp, dest, destp, sp->sk_state,
25665 +               bucket,
25666 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25667 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25668 +               sp->sk_state,
25669                 sk_wmem_alloc_get(sp),
25670                 sk_rmem_alloc_get(sp),
25671                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25672 diff -NurpP --minimal linux-2.6.37/net/ipv6/addrconf.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/addrconf.c
25673 --- linux-2.6.37/net/ipv6/addrconf.c    2011-01-05 21:50:42.000000000 +0100
25674 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/addrconf.c     2011-01-05 22:30:43.000000000 +0100
25675 @@ -87,6 +87,8 @@
25676  
25677  #include <linux/proc_fs.h>
25678  #include <linux/seq_file.h>
25679 +#include <linux/vs_network.h>
25680 +#include <linux/vs_inet6.h>
25681  
25682  /* Set to 3 to get tracing... */
25683  #define ACONF_DEBUG 2
25684 @@ -1124,7 +1126,7 @@ out:
25685  
25686  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25687                        const struct in6_addr *daddr, unsigned int prefs,
25688 -                      struct in6_addr *saddr)
25689 +                      struct in6_addr *saddr, struct nx_info *nxi)
25690  {
25691         struct ipv6_saddr_score scores[2],
25692                                 *score = &scores[0], *hiscore = &scores[1];
25693 @@ -1196,6 +1198,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25694                                                dev->name);
25695                                 continue;
25696                         }
25697 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25698 +                               continue;
25699  
25700                         score->rule = -1;
25701                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25702 @@ -3079,7 +3083,10 @@ static void if6_seq_stop(struct seq_file
25703  static int if6_seq_show(struct seq_file *seq, void *v)
25704  {
25705         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25706 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25707 +
25708 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25709 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25710 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25711                    &ifp->addr,
25712                    ifp->idev->dev->ifindex,
25713                    ifp->prefix_len,
25714 @@ -3585,6 +3592,11 @@ static int in6_dump_addrs(struct inet6_d
25715         struct ifacaddr6 *ifaca;
25716         int err = 1;
25717         int ip_idx = *p_ip_idx;
25718 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25719 +
25720 +       /* disable ipv6 on non v6 guests */
25721 +       if (nxi && !nx_info_has_v6(nxi))
25722 +               return skb->len;
25723  
25724         read_lock_bh(&idev->lock);
25725         switch (type) {
25726 @@ -3595,6 +3607,8 @@ static int in6_dump_addrs(struct inet6_d
25727                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25728                         if (++ip_idx < s_ip_idx)
25729                                 continue;
25730 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25731 +                                       continue;
25732                         err = inet6_fill_ifaddr(skb, ifa,
25733                                                 NETLINK_CB(cb->skb).pid,
25734                                                 cb->nlh->nlmsg_seq,
25735 @@ -3611,6 +3625,8 @@ static int in6_dump_addrs(struct inet6_d
25736                      ifmca = ifmca->next, ip_idx++) {
25737                         if (ip_idx < s_ip_idx)
25738                                 continue;
25739 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25740 +                                       continue;
25741                         err = inet6_fill_ifmcaddr(skb, ifmca,
25742                                                   NETLINK_CB(cb->skb).pid,
25743                                                   cb->nlh->nlmsg_seq,
25744 @@ -3626,6 +3642,8 @@ static int in6_dump_addrs(struct inet6_d
25745                      ifaca = ifaca->aca_next, ip_idx++) {
25746                         if (ip_idx < s_ip_idx)
25747                                 continue;
25748 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25749 +                                       continue;
25750                         err = inet6_fill_ifacaddr(skb, ifaca,
25751                                                   NETLINK_CB(cb->skb).pid,
25752                                                   cb->nlh->nlmsg_seq,
25753 @@ -3975,6 +3993,11 @@ static int inet6_dump_ifinfo(struct sk_b
25754         struct inet6_dev *idev;
25755         struct hlist_head *head;
25756         struct hlist_node *node;
25757 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25758 +
25759 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25760 +       if (skb->sk && skb->sk->sk_vx_info)
25761 +               return skb->len; */
25762  
25763         s_h = cb->args[0];
25764         s_idx = cb->args[1];
25765 @@ -3986,6 +4009,8 @@ static int inet6_dump_ifinfo(struct sk_b
25766                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25767                         if (idx < s_idx)
25768                                 goto cont;
25769 +                       if (!v6_dev_in_nx_info(dev, nxi))
25770 +                               goto cont;
25771                         idev = __in6_dev_get(dev);
25772                         if (!idev)
25773                                 goto cont;
25774 diff -NurpP --minimal linux-2.6.37/net/ipv6/af_inet6.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/af_inet6.c
25775 --- linux-2.6.37/net/ipv6/af_inet6.c    2011-01-05 21:50:42.000000000 +0100
25776 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/af_inet6.c     2010-11-23 02:09:41.000000000 +0100
25777 @@ -42,6 +42,8 @@
25778  #include <linux/netdevice.h>
25779  #include <linux/icmpv6.h>
25780  #include <linux/netfilter_ipv6.h>
25781 +#include <linux/vs_inet.h>
25782 +#include <linux/vs_inet6.h>
25783  
25784  #include <net/ip.h>
25785  #include <net/ipv6.h>
25786 @@ -160,9 +162,12 @@ lookup_protocol:
25787         }
25788  
25789         err = -EPERM;
25790 +       if ((protocol == IPPROTO_ICMPV6) &&
25791 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25792 +               goto override;
25793         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25794                 goto out_rcu_unlock;
25795 -
25796 +override:
25797         sock->ops = answer->ops;
25798         answer_prot = answer->prot;
25799         answer_no_check = answer->no_check;
25800 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25801         struct inet_sock *inet = inet_sk(sk);
25802         struct ipv6_pinfo *np = inet6_sk(sk);
25803         struct net *net = sock_net(sk);
25804 +       struct nx_v6_sock_addr nsa;
25805         __be32 v4addr = 0;
25806         unsigned short snum;
25807         int addr_type = 0;
25808 @@ -272,6 +278,11 @@ int inet6_bind(struct socket *sock, stru
25809  
25810         if (addr_len < SIN6_LEN_RFC2133)
25811                 return -EINVAL;
25812 +
25813 +       err = v6_map_sock_addr(inet, addr, &nsa);
25814 +       if (err)
25815 +               return err;
25816 +
25817         addr_type = ipv6_addr_type(&addr->sin6_addr);
25818         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25819                 return -EINVAL;
25820 @@ -303,6 +314,7 @@ int inet6_bind(struct socket *sock, stru
25821                 /* Reproduce AF_INET checks to make the bindings consitant */
25822                 v4addr = addr->sin6_addr.s6_addr32[3];
25823                 chk_addr_ret = inet_addr_type(net, v4addr);
25824 +
25825                 if (!sysctl_ip_nonlocal_bind &&
25826                     !(inet->freebind || inet->transparent) &&
25827                     v4addr != htonl(INADDR_ANY) &&
25828 @@ -312,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
25829                         err = -EADDRNOTAVAIL;
25830                         goto out;
25831                 }
25832 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25833 +                       err = -EADDRNOTAVAIL;
25834 +                       goto out;
25835 +               }
25836         } else {
25837                 if (addr_type != IPV6_ADDR_ANY) {
25838                         struct net_device *dev = NULL;
25839 @@ -338,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
25840                                 }
25841                         }
25842  
25843 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25844 +                               err = -EADDRNOTAVAIL;
25845 +                               goto out;
25846 +                       }
25847 +
25848                         /* ipv4 addr of the socket is invalid.  Only the
25849                          * unspecified and mapped address have a v4 equivalent.
25850                          */
25851 @@ -354,6 +375,9 @@ int inet6_bind(struct socket *sock, stru
25852                 }
25853         }
25854  
25855 +       /* what's that for? */
25856 +       v6_set_sock_addr(inet, &nsa);
25857 +
25858         inet->inet_rcv_saddr = v4addr;
25859         inet->inet_saddr = v4addr;
25860  
25861 @@ -455,9 +479,11 @@ int inet6_getname(struct socket *sock, s
25862                         return -ENOTCONN;
25863                 sin->sin6_port = inet->inet_dport;
25864                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25865 +               /* FIXME: remap lback? */
25866                 if (np->sndflow)
25867                         sin->sin6_flowinfo = np->flow_label;
25868         } else {
25869 +               /* FIXME: remap lback? */
25870                 if (ipv6_addr_any(&np->rcv_saddr))
25871                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25872                 else
25873 diff -NurpP --minimal linux-2.6.37/net/ipv6/fib6_rules.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/fib6_rules.c
25874 --- linux-2.6.37/net/ipv6/fib6_rules.c  2011-01-05 21:50:42.000000000 +0100
25875 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/fib6_rules.c   2010-11-23 02:09:41.000000000 +0100
25876 @@ -88,7 +88,7 @@ static int fib6_rule_action(struct fib_r
25877                                                ip6_dst_idev(&rt->dst)->dev,
25878                                                &flp->fl6_dst,
25879                                                rt6_flags2srcprefs(flags),
25880 -                                              &saddr))
25881 +                                              &saddr, NULL))
25882                                 goto again;
25883                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25884                                                r->src.plen))
25885 diff -NurpP --minimal linux-2.6.37/net/ipv6/inet6_hashtables.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/inet6_hashtables.c
25886 --- linux-2.6.37/net/ipv6/inet6_hashtables.c    2010-02-25 11:52:10.000000000 +0100
25887 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/inet6_hashtables.c     2010-11-23 02:09:41.000000000 +0100
25888 @@ -16,6 +16,7 @@
25889  
25890  #include <linux/module.h>
25891  #include <linux/random.h>
25892 +#include <linux/vs_inet6.h>
25893  
25894  #include <net/inet_connection_sock.h>
25895  #include <net/inet_hashtables.h>
25896 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
25897         unsigned int slot = hash & hashinfo->ehash_mask;
25898         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25899  
25900 -
25901         rcu_read_lock();
25902  begin:
25903         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25904 @@ -94,7 +94,7 @@ begin:
25905                                 sock_put(sk);
25906                                 goto begin;
25907                         }
25908 -               goto out;
25909 +                       goto out;
25910                 }
25911         }
25912         if (get_nulls_value(node) != slot)
25913 @@ -140,6 +140,9 @@ static int inline compute_score(struct s
25914                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25915                                 return -1;
25916                         score++;
25917 +               } else {
25918 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25919 +                               return -1;
25920                 }
25921                 if (sk->sk_bound_dev_if) {
25922                         if (sk->sk_bound_dev_if != dif)
25923 diff -NurpP --minimal linux-2.6.37/net/ipv6/ip6_output.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/ip6_output.c
25924 --- linux-2.6.37/net/ipv6/ip6_output.c  2011-01-05 21:50:42.000000000 +0100
25925 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/ip6_output.c   2011-01-05 22:30:43.000000000 +0100
25926 @@ -930,7 +930,7 @@ static int ip6_dst_lookup_tail(struct so
25927                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
25928                                          &fl->fl6_dst,
25929                                          sk ? inet6_sk(sk)->srcprefs : 0,
25930 -                                        &fl->fl6_src);
25931 +                                        &fl->fl6_src, sk->sk_nx_info);
25932                 if (err)
25933                         goto out_err_release;
25934         }
25935 diff -NurpP --minimal linux-2.6.37/net/ipv6/Kconfig linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/Kconfig
25936 --- linux-2.6.37/net/ipv6/Kconfig       2010-08-02 16:52:59.000000000 +0200
25937 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/Kconfig        2010-11-23 02:09:41.000000000 +0100
25938 @@ -4,8 +4,8 @@
25939  
25940  #   IPv6 as module will cause a CRASH if you try to unload it
25941  menuconfig IPV6
25942 -       tristate "The IPv6 protocol"
25943 -       default m
25944 +       bool "The IPv6 protocol"
25945 +       default n
25946         ---help---
25947           This is complemental support for the IP version 6.
25948           You will still be able to do traditional IPv4 networking as well.
25949 diff -NurpP --minimal linux-2.6.37/net/ipv6/ndisc.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/ndisc.c
25950 --- linux-2.6.37/net/ipv6/ndisc.c       2011-01-05 21:50:42.000000000 +0100
25951 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/ndisc.c        2010-11-23 02:09:41.000000000 +0100
25952 @@ -595,7 +595,7 @@ static void ndisc_send_na(struct net_dev
25953         } else {
25954                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25955                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25956 -                                      &tmpaddr))
25957 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
25958                         return;
25959                 src_addr = &tmpaddr;
25960         }
25961 diff -NurpP --minimal linux-2.6.37/net/ipv6/raw.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/raw.c
25962 --- linux-2.6.37/net/ipv6/raw.c 2011-01-05 21:50:42.000000000 +0100
25963 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/raw.c  2010-11-23 02:09:41.000000000 +0100
25964 @@ -30,6 +30,7 @@
25965  #include <linux/icmpv6.h>
25966  #include <linux/netfilter.h>
25967  #include <linux/netfilter_ipv6.h>
25968 +#include <linux/vs_inet6.h>
25969  #include <linux/skbuff.h>
25970  #include <asm/uaccess.h>
25971  #include <asm/ioctls.h>
25972 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25973                                 goto out_unlock;
25974                 }
25975  
25976 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25977 +                       err = -EADDRNOTAVAIL;
25978 +                       if (dev)
25979 +                               dev_put(dev);
25980 +                       goto out;
25981 +               }
25982 +
25983                 /* ipv4 addr of the socket is invalid.  Only the
25984                  * unspecified and mapped address have a v4 equivalent.
25985                  */
25986 diff -NurpP --minimal linux-2.6.37/net/ipv6/route.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/route.c
25987 --- linux-2.6.37/net/ipv6/route.c       2011-01-05 21:50:42.000000000 +0100
25988 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/route.c        2011-01-05 22:30:43.000000000 +0100
25989 @@ -2290,7 +2290,8 @@ static int rt6_fill_node(struct net *net
25990                 struct inet6_dev *idev = ip6_dst_idev(&rt->dst);
25991                 struct in6_addr saddr_buf;
25992                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25993 -                                      dst, 0, &saddr_buf) == 0)
25994 +                       dst, 0, &saddr_buf,
25995 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25996                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25997         }
25998  
25999 diff -NurpP --minimal linux-2.6.37/net/ipv6/tcp_ipv6.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/tcp_ipv6.c
26000 --- linux-2.6.37/net/ipv6/tcp_ipv6.c    2011-01-05 21:50:42.000000000 +0100
26001 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/tcp_ipv6.c     2010-11-23 02:09:41.000000000 +0100
26002 @@ -69,6 +69,7 @@
26003  
26004  #include <linux/crypto.h>
26005  #include <linux/scatterlist.h>
26006 +#include <linux/vs_inet6.h>
26007  
26008  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
26009  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
26010 @@ -160,8 +161,15 @@ static int tcp_v6_connect(struct sock *s
26011          *      connect() to INADDR_ANY means loopback (BSD'ism).
26012          */
26013  
26014 -       if(ipv6_addr_any(&usin->sin6_addr))
26015 -               usin->sin6_addr.s6_addr[15] = 0x1;
26016 +       if(ipv6_addr_any(&usin->sin6_addr)) {
26017 +               struct nx_info *nxi =  sk->sk_nx_info;
26018 +
26019 +               if (nxi && nx_info_has_v6(nxi))
26020 +                       /* FIXME: remap lback? */
26021 +                       usin->sin6_addr = nxi->v6.ip;
26022 +               else
26023 +                       usin->sin6_addr.s6_addr[15] = 0x1;
26024 +       }
26025  
26026         addr_type = ipv6_addr_type(&usin->sin6_addr);
26027  
26028 diff -NurpP --minimal linux-2.6.37/net/ipv6/udp.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/udp.c
26029 --- linux-2.6.37/net/ipv6/udp.c 2011-01-05 21:50:42.000000000 +0100
26030 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/udp.c  2011-01-05 22:30:43.000000000 +0100
26031 @@ -48,13 +48,14 @@
26032  
26033  #include <linux/proc_fs.h>
26034  #include <linux/seq_file.h>
26035 +#include <linux/vs_inet6.h>
26036  #include "udp_impl.h"
26037  
26038  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
26039  {
26040         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
26041         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
26042 -       __be32 sk1_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
26043 +       __be32 sk_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
26044         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26045         int sk_ipv6only = ipv6_only_sock(sk);
26046         int sk2_ipv6only = inet_v6_ipv6only(sk2);
26047 @@ -62,24 +63,49 @@ int ipv6_rcv_saddr_equal(const struct so
26048         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
26049  
26050         /* if both are mapped, treat as IPv4 */
26051 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
26052 -               return (!sk2_ipv6only &&
26053 -                       (!sk1_rcv_saddr || !sk2_rcv_saddr ||
26054 -                         sk1_rcv_saddr == sk2_rcv_saddr));
26055 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
26056 +               if (!sk2_ipv6only &&
26057 +                       (!sk_rcv_saddr || !sk2_rcv_saddr ||
26058 +                         sk_rcv_saddr == sk2_rcv_saddr))
26059 +                       goto vs_v4;
26060 +               else
26061 +                       return 0;
26062 +       }
26063  
26064         if (addr_type2 == IPV6_ADDR_ANY &&
26065             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26066 -               return 1;
26067 +               goto vs;
26068  
26069         if (addr_type == IPV6_ADDR_ANY &&
26070             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26071 -               return 1;
26072 +               goto vs;
26073  
26074         if (sk2_rcv_saddr6 &&
26075             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26076 -               return 1;
26077 +               goto vs;
26078  
26079         return 0;
26080 +
26081 +vs_v4:
26082 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
26083 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26084 +       if (!sk2_rcv_saddr)
26085 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
26086 +       if (!sk_rcv_saddr)
26087 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
26088 +       return 1;
26089 +vs:
26090 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
26091 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26092 +       else if (addr_type2 == IPV6_ADDR_ANY)
26093 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
26094 +       else if (addr_type == IPV6_ADDR_ANY) {
26095 +               if (addr_type2 == IPV6_ADDR_MAPPED)
26096 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26097 +               else
26098 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
26099 +       }
26100 +       return 1;
26101  }
26102  
26103  static unsigned int udp6_portaddr_hash(struct net *net,
26104 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
26105                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26106                                 return -1;
26107                         score++;
26108 +               } else {
26109 +                       /* block non nx_info ips */
26110 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26111 +                               return -1;
26112                 }
26113                 if (!ipv6_addr_any(&np->daddr)) {
26114                         if (!ipv6_addr_equal(&np->daddr, saddr))
26115 diff -NurpP --minimal linux-2.6.37/net/ipv6/xfrm6_policy.c linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/xfrm6_policy.c
26116 --- linux-2.6.37/net/ipv6/xfrm6_policy.c        2011-01-05 21:50:42.000000000 +0100
26117 +++ linux-2.6.37-vs2.3.0.37-rc3/net/ipv6/xfrm6_policy.c 2010-11-23 02:09:41.000000000 +0100
26118 @@ -62,7 +62,7 @@ static int xfrm6_get_saddr(struct net *n
26119         dev = ip6_dst_idev(dst)->dev;
26120         ipv6_dev_get_saddr(dev_net(dev), dev,
26121                            (struct in6_addr *)&daddr->a6, 0,
26122 -                          (struct in6_addr *)&saddr->a6);
26123 +                          (struct in6_addr *)&saddr->a6, NULL);
26124         dst_release(dst);
26125         return 0;
26126  }
26127 diff -NurpP --minimal linux-2.6.37/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.37-vs2.3.0.37-rc3/net/netfilter/ipvs/ip_vs_xmit.c
26128 --- linux-2.6.37/net/netfilter/ipvs/ip_vs_xmit.c        2011-01-05 21:50:43.000000000 +0100
26129 +++ linux-2.6.37-vs2.3.0.37-rc3/net/netfilter/ipvs/ip_vs_xmit.c 2011-01-06 00:35:16.000000000 +0100
26130 @@ -231,7 +231,7 @@ __ip_vs_route_output_v6(struct net *net,
26131                 return dst;
26132         if (ipv6_addr_any(&fl.fl6_src) &&
26133             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
26134 -                              &fl.fl6_dst, 0, &fl.fl6_src) < 0)
26135 +                              &fl.fl6_dst, 0, &fl.fl6_src, NULL) < 0)
26136                 goto out_err;
26137         if (do_xfrm && xfrm_lookup(net, &dst, &fl, NULL, 0) < 0)
26138                 goto out_err;
26139 diff -NurpP --minimal linux-2.6.37/net/netlink/af_netlink.c linux-2.6.37-vs2.3.0.37-rc3/net/netlink/af_netlink.c
26140 --- linux-2.6.37/net/netlink/af_netlink.c       2011-01-05 21:50:43.000000000 +0100
26141 +++ linux-2.6.37-vs2.3.0.37-rc3/net/netlink/af_netlink.c        2010-11-23 02:09:41.000000000 +0100
26142 @@ -55,6 +55,9 @@
26143  #include <linux/types.h>
26144  #include <linux/audit.h>
26145  #include <linux/mutex.h>
26146 +#include <linux/vs_context.h>
26147 +#include <linux/vs_network.h>
26148 +#include <linux/vs_limit.h>
26149  
26150  #include <net/net_namespace.h>
26151  #include <net/sock.h>
26152 @@ -1912,6 +1915,8 @@ static struct sock *netlink_seq_socket_i
26153                         sk_for_each(s, node, &hash->table[j]) {
26154                                 if (sock_net(s) != seq_file_net(seq))
26155                                         continue;
26156 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26157 +                                       continue;
26158                                 if (off == pos) {
26159                                         iter->link = i;
26160                                         iter->hash_idx = j;
26161 @@ -1946,7 +1951,8 @@ static void *netlink_seq_next(struct seq
26162         s = v;
26163         do {
26164                 s = sk_next(s);
26165 -       } while (s && sock_net(s) != seq_file_net(seq));
26166 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26167 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26168         if (s)
26169                 return s;
26170  
26171 @@ -1958,7 +1964,8 @@ static void *netlink_seq_next(struct seq
26172  
26173                 for (; j <= hash->mask; j++) {
26174                         s = sk_head(&hash->table[j]);
26175 -                       while (s && sock_net(s) != seq_file_net(seq))
26176 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26177 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26178                                 s = sk_next(s);
26179                         if (s) {
26180                                 iter->link = i;
26181 diff -NurpP --minimal linux-2.6.37/net/sctp/ipv6.c linux-2.6.37-vs2.3.0.37-rc3/net/sctp/ipv6.c
26182 --- linux-2.6.37/net/sctp/ipv6.c        2011-01-05 21:50:45.000000000 +0100
26183 +++ linux-2.6.37-vs2.3.0.37-rc3/net/sctp/ipv6.c 2010-11-23 02:09:41.000000000 +0100
26184 @@ -306,7 +306,8 @@ static void sctp_v6_get_saddr(struct sct
26185                                    dst ? ip6_dst_idev(dst)->dev : NULL,
26186                                    &daddr->v6.sin6_addr,
26187                                    inet6_sk(&sk->inet.sk)->srcprefs,
26188 -                                  &saddr->v6.sin6_addr);
26189 +                                  &saddr->v6.sin6_addr,
26190 +                                  asoc->base.sk->sk_nx_info);
26191                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
26192                                   &saddr->v6.sin6_addr);
26193                 return;
26194 diff -NurpP --minimal linux-2.6.37/net/socket.c linux-2.6.37-vs2.3.0.37-rc3/net/socket.c
26195 --- linux-2.6.37/net/socket.c   2011-01-05 21:50:45.000000000 +0100
26196 +++ linux-2.6.37-vs2.3.0.37-rc3/net/socket.c    2011-01-05 22:30:44.000000000 +0100
26197 @@ -98,6 +98,10 @@
26198  
26199  #include <net/sock.h>
26200  #include <linux/netfilter.h>
26201 +#include <linux/vs_base.h>
26202 +#include <linux/vs_socket.h>
26203 +#include <linux/vs_inet.h>
26204 +#include <linux/vs_inet6.h>
26205  
26206  #include <linux/if_tun.h>
26207  #include <linux/ipv6_route.h>
26208 @@ -550,7 +554,7 @@ static inline int __sock_sendmsg(struct 
26209                                  struct msghdr *msg, size_t size)
26210  {
26211         struct sock_iocb *si = kiocb_to_siocb(iocb);
26212 -       int err;
26213 +       int err, len;
26214  
26215         sock_update_classid(sock->sk);
26216  
26217 @@ -563,7 +567,22 @@ static inline int __sock_sendmsg(struct 
26218         if (err)
26219                 return err;
26220  
26221 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26222 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26223 +       if (sock->sk) {
26224 +               if (len == size)
26225 +                       vx_sock_send(sock->sk, size);
26226 +               else
26227 +                       vx_sock_fail(sock->sk, size);
26228 +       }
26229 +       vxdprintk(VXD_CBIT(net, 7),
26230 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26231 +               sock, sock->sk,
26232 +               (sock->sk)?sock->sk->sk_nx_info:0,
26233 +               (sock->sk)?sock->sk->sk_vx_info:0,
26234 +               (sock->sk)?sock->sk->sk_xid:0,
26235 +               (sock->sk)?sock->sk->sk_nid:0,
26236 +               (unsigned int)size, len);
26237 +       return len;
26238  }
26239  
26240  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
26241 @@ -681,6 +700,7 @@ static inline int __sock_recvmsg_nosec(s
26242                                        struct msghdr *msg, size_t size, int flags)
26243  {
26244         struct sock_iocb *si = kiocb_to_siocb(iocb);
26245 +       int len;
26246  
26247         sock_update_classid(sock->sk);
26248  
26249 @@ -690,7 +710,18 @@ static inline int __sock_recvmsg_nosec(s
26250         si->size = size;
26251         si->flags = flags;
26252  
26253 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26254 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26255 +       if ((len >= 0) && sock->sk)
26256 +               vx_sock_recv(sock->sk, len);
26257 +       vxdprintk(VXD_CBIT(net, 7),
26258 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26259 +               sock, sock->sk,
26260 +               (sock->sk)?sock->sk->sk_nx_info:0,
26261 +               (sock->sk)?sock->sk->sk_vx_info:0,
26262 +               (sock->sk)?sock->sk->sk_xid:0,
26263 +               (sock->sk)?sock->sk->sk_nid:0,
26264 +               (unsigned int)size, len);
26265 +       return len;
26266  }
26267  
26268  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26269 @@ -1174,6 +1205,13 @@ int __sock_create(struct net *net, int f
26270         if (type < 0 || type >= SOCK_MAX)
26271                 return -EINVAL;
26272  
26273 +       if (!nx_check(0, VS_ADMIN)) {
26274 +               if (family == PF_INET && !current_nx_info_has_v4())
26275 +                       return -EAFNOSUPPORT;
26276 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26277 +                       return -EAFNOSUPPORT;
26278 +       }
26279 +
26280         /* Compatibility.
26281  
26282            This uglymoron is moved from INET layer to here to avoid
26283 @@ -1309,6 +1347,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26284         if (retval < 0)
26285                 goto out;
26286  
26287 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26288         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26289         if (retval < 0)
26290                 goto out_release;
26291 @@ -1350,10 +1389,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26292         err = sock_create(family, type, protocol, &sock1);
26293         if (err < 0)
26294                 goto out;
26295 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26296  
26297         err = sock_create(family, type, protocol, &sock2);
26298         if (err < 0)
26299                 goto out_release_1;
26300 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26301  
26302         err = sock1->ops->socketpair(sock1, sock2);
26303         if (err < 0)
26304 diff -NurpP --minimal linux-2.6.37/net/sunrpc/auth.c linux-2.6.37-vs2.3.0.37-rc3/net/sunrpc/auth.c
26305 --- linux-2.6.37/net/sunrpc/auth.c      2011-01-05 21:50:45.000000000 +0100
26306 +++ linux-2.6.37-vs2.3.0.37-rc3/net/sunrpc/auth.c       2010-11-23 02:09:41.000000000 +0100
26307 @@ -14,6 +14,7 @@
26308  #include <linux/hash.h>
26309  #include <linux/sunrpc/clnt.h>
26310  #include <linux/spinlock.h>
26311 +#include <linux/vs_tag.h>
26312  
26313  #ifdef RPC_DEBUG
26314  # define RPCDBG_FACILITY       RPCDBG_AUTH
26315 @@ -425,6 +426,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26316         memset(&acred, 0, sizeof(acred));
26317         acred.uid = cred->fsuid;
26318         acred.gid = cred->fsgid;
26319 +       acred.tag = dx_current_tag();
26320         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26321  
26322         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26323 @@ -465,6 +467,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26324         struct auth_cred acred = {
26325                 .uid = 0,
26326                 .gid = 0,
26327 +               .tag = dx_current_tag(),
26328         };
26329  
26330         dprintk("RPC: %5u looking up %s cred\n",
26331 diff -NurpP --minimal linux-2.6.37/net/sunrpc/auth_unix.c linux-2.6.37-vs2.3.0.37-rc3/net/sunrpc/auth_unix.c
26332 --- linux-2.6.37/net/sunrpc/auth_unix.c 2010-10-21 13:08:01.000000000 +0200
26333 +++ linux-2.6.37-vs2.3.0.37-rc3/net/sunrpc/auth_unix.c  2010-11-23 02:09:41.000000000 +0100
26334 @@ -12,12 +12,14 @@
26335  #include <linux/module.h>
26336  #include <linux/sunrpc/clnt.h>
26337  #include <linux/sunrpc/auth.h>
26338 +#include <linux/vs_tag.h>
26339  
26340  #define NFS_NGROUPS    16
26341  
26342  struct unx_cred {
26343         struct rpc_cred         uc_base;
26344         gid_t                   uc_gid;
26345 +       tag_t                   uc_tag;
26346         gid_t                   uc_gids[NFS_NGROUPS];
26347  };
26348  #define uc_uid                 uc_base.cr_uid
26349 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26350                 groups = NFS_NGROUPS;
26351  
26352         cred->uc_gid = acred->gid;
26353 +       cred->uc_tag = acred->tag;
26354         for (i = 0; i < groups; i++)
26355                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26356         if (i < NFS_NGROUPS)
26357 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26358         unsigned int i;
26359  
26360  
26361 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26362 +       if (cred->uc_uid != acred->uid ||
26363 +               cred->uc_gid != acred->gid ||
26364 +               cred->uc_tag != acred->tag)
26365                 return 0;
26366  
26367         if (acred->group_info != NULL)
26368 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
26369         struct rpc_clnt *clnt = task->tk_client;
26370         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26371         __be32          *base, *hold;
26372 -       int             i;
26373 +       int             i, tag;
26374  
26375         *p++ = htonl(RPC_AUTH_UNIX);
26376         base = p++;
26377 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
26378          * Copy the UTS nodename captured when the client was created.
26379          */
26380         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26381 +       tag = task->tk_client->cl_tag;
26382  
26383 -       *p++ = htonl((u32) cred->uc_uid);
26384 -       *p++ = htonl((u32) cred->uc_gid);
26385 +       *p++ = htonl((u32) TAGINO_UID(tag,
26386 +               cred->uc_uid, cred->uc_tag));
26387 +       *p++ = htonl((u32) TAGINO_GID(tag,
26388 +               cred->uc_gid, cred->uc_tag));
26389         hold = p++;
26390         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26391                 *p++ = htonl((u32) cred->uc_gids[i]);
26392 diff -NurpP --minimal linux-2.6.37/net/sunrpc/clnt.c linux-2.6.37-vs2.3.0.37-rc3/net/sunrpc/clnt.c
26393 --- linux-2.6.37/net/sunrpc/clnt.c      2011-01-05 21:50:45.000000000 +0100
26394 +++ linux-2.6.37-vs2.3.0.37-rc3/net/sunrpc/clnt.c       2011-01-05 22:30:44.000000000 +0100
26395 @@ -33,6 +33,7 @@
26396  #include <linux/utsname.h>
26397  #include <linux/workqueue.h>
26398  #include <linux/in6.h>
26399 +#include <linux/vs_cvirt.h>
26400  
26401  #include <linux/sunrpc/clnt.h>
26402  #include <linux/sunrpc/rpc_pipe_fs.h>
26403 @@ -359,6 +360,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26404         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26405                 clnt->cl_chatty = 1;
26406  
26407 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26408 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26409 +               clnt->cl_tag = 1; */
26410         return clnt;
26411  }
26412  EXPORT_SYMBOL_GPL(rpc_create);
26413 diff -NurpP --minimal linux-2.6.37/net/unix/af_unix.c linux-2.6.37-vs2.3.0.37-rc3/net/unix/af_unix.c
26414 --- linux-2.6.37/net/unix/af_unix.c     2011-01-05 21:50:46.000000000 +0100
26415 +++ linux-2.6.37-vs2.3.0.37-rc3/net/unix/af_unix.c      2011-01-05 22:30:44.000000000 +0100
26416 @@ -114,6 +114,8 @@
26417  #include <linux/mount.h>
26418  #include <net/checksum.h>
26419  #include <linux/security.h>
26420 +#include <linux/vs_context.h>
26421 +#include <linux/vs_limit.h>
26422  
26423  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26424  static DEFINE_SPINLOCK(unix_table_lock);
26425 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26426                 if (!net_eq(sock_net(s), net))
26427                         continue;
26428  
26429 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26430 +                       continue;
26431                 if (u->addr->len == len &&
26432                     !memcmp(u->addr->name, sunname, len))
26433                         goto found;
26434 @@ -2179,6 +2183,8 @@ static struct sock *unix_seq_idx(struct 
26435         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26436                 if (sock_net(s) != seq_file_net(seq))
26437                         continue;
26438 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26439 +                       continue;
26440                 if (off == pos)
26441                         return s;
26442                 ++off;
26443 @@ -2203,7 +2209,8 @@ static void *unix_seq_next(struct seq_fi
26444                 sk = first_unix_socket(&iter->i);
26445         else
26446                 sk = next_unix_socket(&iter->i, sk);
26447 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26448 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26449 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26450                 sk = next_unix_socket(&iter->i, sk);
26451         return sk;
26452  }
26453 diff -NurpP --minimal linux-2.6.37/scripts/checksyscalls.sh linux-2.6.37-vs2.3.0.37-rc3/scripts/checksyscalls.sh
26454 --- linux-2.6.37/scripts/checksyscalls.sh       2010-10-21 13:08:01.000000000 +0200
26455 +++ linux-2.6.37-vs2.3.0.37-rc3/scripts/checksyscalls.sh        2010-11-23 02:09:41.000000000 +0100
26456 @@ -193,7 +193,6 @@ cat << EOF
26457  #define __IGNORE_afs_syscall
26458  #define __IGNORE_getpmsg
26459  #define __IGNORE_putpmsg
26460 -#define __IGNORE_vserver
26461  EOF
26462  }
26463  
26464 diff -NurpP --minimal linux-2.6.37/security/commoncap.c linux-2.6.37-vs2.3.0.37-rc3/security/commoncap.c
26465 --- linux-2.6.37/security/commoncap.c   2011-01-05 21:50:47.000000000 +0100
26466 +++ linux-2.6.37-vs2.3.0.37-rc3/security/commoncap.c    2010-11-23 02:21:20.000000000 +0100
26467 @@ -27,6 +27,7 @@
26468  #include <linux/sched.h>
26469  #include <linux/prctl.h>
26470  #include <linux/securebits.h>
26471 +// #include <linux/vs_context.h>
26472  
26473  /*
26474   * If a non-root user executes a setuid-root binary in
26475 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
26476  
26477  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
26478  {
26479 -       NETLINK_CB(skb).eff_cap = current_cap();
26480 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
26481         return 0;
26482  }
26483  
26484 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
26485                 return -EPERM;
26486         return 0;
26487  }
26488 +
26489  EXPORT_SYMBOL(cap_netlink_recv);
26490  
26491  /**
26492 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
26493  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
26494                 int audit)
26495  {
26496 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26497 +       struct vx_info *vxi = tsk->vx_info;
26498 +
26499 +#if 0
26500 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
26501 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
26502 +               cap_raised(tsk->cap_effective, cap),
26503 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
26504 +#endif
26505 +
26506 +       /* special case SETUP */
26507 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26508 +               /* FIXME: maybe use cred instead? */
26509 +               cap_raised(tsk->cred->cap_effective, cap))
26510 +               return 0;
26511 +
26512 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26513  }
26514  
26515  /**
26516 @@ -570,7 +587,7 @@ int cap_inode_setxattr(struct dentry *de
26517  
26518         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26519                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26520 -           !capable(CAP_SYS_ADMIN))
26521 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26522                 return -EPERM;
26523         return 0;
26524  }
26525 @@ -596,7 +613,7 @@ int cap_inode_removexattr(struct dentry 
26526  
26527         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26528                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26529 -           !capable(CAP_SYS_ADMIN))
26530 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26531                 return -EPERM;
26532         return 0;
26533  }
26534 @@ -929,3 +946,4 @@ int cap_file_mmap(struct file *file, uns
26535         }
26536         return ret;
26537  }
26538 +
26539 diff -NurpP --minimal linux-2.6.37/security/selinux/hooks.c linux-2.6.37-vs2.3.0.37-rc3/security/selinux/hooks.c
26540 --- linux-2.6.37/security/selinux/hooks.c       2011-01-05 21:50:47.000000000 +0100
26541 +++ linux-2.6.37-vs2.3.0.37-rc3/security/selinux/hooks.c        2010-11-23 02:09:41.000000000 +0100
26542 @@ -64,7 +64,6 @@
26543  #include <linux/dccp.h>
26544  #include <linux/quota.h>
26545  #include <linux/un.h>          /* for Unix socket types */
26546 -#include <net/af_unix.h>       /* for Unix socket types */
26547  #include <linux/parser.h>
26548  #include <linux/nfs_mount.h>
26549  #include <net/ipv6.h>
This page took 3.997529 seconds and 4 git commands to generate.