]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
089af0b93274b2685c80bc98cd983cddbf61d9fc
[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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/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-rc2/include/linux/cred.h    2011-01-08 03:33:34.000000000 +0100
8517 @@ -208,6 +208,31 @@ static inline void validate_process_cred
8518  }
8519  #endif
8520  
8521 +static inline void set_cred_subscribers(struct cred *cred, int n)
8522 +{
8523 +#ifdef CONFIG_DEBUG_CREDENTIALS
8524 +       atomic_set(&cred->subscribers, n);
8525 +#endif
8526 +}
8527 +
8528 +static inline int read_cred_subscribers(const struct cred *cred)
8529 +{
8530 +#ifdef CONFIG_DEBUG_CREDENTIALS
8531 +       return atomic_read(&cred->subscribers);
8532 +#else
8533 +       return 0;
8534 +#endif
8535 +}
8536 +
8537 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8538 +{
8539 +#ifdef CONFIG_DEBUG_CREDENTIALS
8540 +       struct cred *cred = (struct cred *) _cred;
8541 +
8542 +       atomic_add(n, &cred->subscribers);
8543 +#endif
8544 +}
8545 +
8546  /**
8547   * get_new_cred - Get a reference on a new set of credentials
8548   * @cred: The new credentials to reference
8549 diff -NurpP --minimal linux-2.6.37/include/linux/devpts_fs.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/devpts_fs.h
8550 --- linux-2.6.37/include/linux/devpts_fs.h      2008-12-25 00:26:37.000000000 +0100
8551 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/devpts_fs.h       2010-11-23 02:09:41.000000000 +0100
8552 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8553  
8554  #endif
8555  
8556 -
8557  #endif /* _LINUX_DEVPTS_FS_H */
8558 diff -NurpP --minimal linux-2.6.37/include/linux/ext2_fs.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/ext2_fs.h
8559 --- linux-2.6.37/include/linux/ext2_fs.h        2010-02-25 11:52:07.000000000 +0100
8560 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/ext2_fs.h 2010-11-23 02:09:41.000000000 +0100
8561 @@ -189,8 +189,12 @@ struct ext2_group_desc
8562  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8563  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8564  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8565 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8566  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8567  
8568 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8569 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8570 +
8571  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8572  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8573  
8574 @@ -274,7 +278,8 @@ struct ext2_inode {
8575                         __u16   i_pad1;
8576                         __le16  l_i_uid_high;   /* these 2 fields    */
8577                         __le16  l_i_gid_high;   /* were reserved2[0] */
8578 -                       __u32   l_i_reserved2;
8579 +                       __le16  l_i_tag;        /* Context Tag */
8580 +                       __u16   l_i_reserved2;
8581                 } linux2;
8582                 struct {
8583                         __u8    h_i_frag;       /* Fragment number */
8584 @@ -303,6 +308,7 @@ struct ext2_inode {
8585  #define i_gid_low      i_gid
8586  #define i_uid_high     osd2.linux2.l_i_uid_high
8587  #define i_gid_high     osd2.linux2.l_i_gid_high
8588 +#define i_raw_tag      osd2.linux2.l_i_tag
8589  #define i_reserved2    osd2.linux2.l_i_reserved2
8590  #endif
8591  
8592 @@ -347,6 +353,7 @@ struct ext2_inode {
8593  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8594  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8595  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8596 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8597  
8598  
8599  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8600 diff -NurpP --minimal linux-2.6.37/include/linux/ext3_fs.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/ext3_fs.h
8601 --- linux-2.6.37/include/linux/ext3_fs.h        2010-10-21 13:07:53.000000000 +0200
8602 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/ext3_fs.h 2010-11-23 02:09:41.000000000 +0100
8603 @@ -173,10 +173,14 @@ struct ext3_group_desc
8604  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8605  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8606  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8607 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8608  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8609  
8610 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8611 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8612 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8613 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8614 +
8615 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8616 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8617  
8618  /* Flags that should be inherited by new inodes from their parent. */
8619  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8620 @@ -312,7 +316,8 @@ struct ext3_inode {
8621                         __u16   i_pad1;
8622                         __le16  l_i_uid_high;   /* these 2 fields    */
8623                         __le16  l_i_gid_high;   /* were reserved2[0] */
8624 -                       __u32   l_i_reserved2;
8625 +                       __le16  l_i_tag;        /* Context Tag */
8626 +                       __u16   l_i_reserved2;
8627                 } linux2;
8628                 struct {
8629                         __u8    h_i_frag;       /* Fragment number */
8630 @@ -343,6 +348,7 @@ struct ext3_inode {
8631  #define i_gid_low      i_gid
8632  #define i_uid_high     osd2.linux2.l_i_uid_high
8633  #define i_gid_high     osd2.linux2.l_i_gid_high
8634 +#define i_raw_tag      osd2.linux2.l_i_tag
8635  #define i_reserved2    osd2.linux2.l_i_reserved2
8636  
8637  #elif defined(__GNU__)
8638 @@ -405,6 +411,7 @@ struct ext3_inode {
8639  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8640  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8641                                                   * error in ordered mode */
8642 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8643  
8644  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8645  #ifndef _LINUX_EXT2_FS_H
8646 @@ -908,6 +915,7 @@ extern void ext3_get_inode_flags(struct 
8647  extern void ext3_set_aops(struct inode *inode);
8648  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8649                        u64 start, u64 len);
8650 +extern int ext3_sync_flags(struct inode *, int, int);
8651  
8652  /* ioctl.c */
8653  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8654 diff -NurpP --minimal linux-2.6.37/include/linux/fs.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/fs.h
8655 --- linux-2.6.37/include/linux/fs.h     2011-01-05 21:50:30.000000000 +0100
8656 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/fs.h      2011-01-05 22:30:40.000000000 +0100
8657 @@ -214,6 +214,9 @@ struct inodes_stat_t {
8658  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8659  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8660  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8661 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8662 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8663 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8664  #define MS_BORN                (1<<29)
8665  #define MS_ACTIVE      (1<<30)
8666  #define MS_NOUSER      (1<<31)
8667 @@ -242,6 +245,14 @@ struct inodes_stat_t {
8668  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8669  #define S_PRIVATE      512     /* Inode is fs-internal */
8670  #define S_IMA          1024    /* Inode has an associated IMA struct */
8671 +#define S_IXUNLINK     2048    /* Immutable Invert on unlink */
8672 +
8673 +/* Linux-VServer related Inode flags */
8674 +
8675 +#define V_VALID                1
8676 +#define V_XATTR                2
8677 +#define V_BARRIER      4       /* Barrier for chroot() */
8678 +#define V_COW          8       /* Copy on Write */
8679  
8680  /*
8681   * Note that nosuid etc flags are inode-specific: setting some file-system
8682 @@ -264,12 +275,15 @@ struct inodes_stat_t {
8683  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8684                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8685  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8686 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8687 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8688 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8689 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8690 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8691  
8692  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8693  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8694  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8695 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8696 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8697  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8698  
8699  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8700 @@ -278,6 +292,16 @@ struct inodes_stat_t {
8701  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8702  #define IS_IMA(inode)          ((inode)->i_flags & S_IMA)
8703  
8704 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8705 +
8706 +#ifdef CONFIG_VSERVER_COWBL
8707 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8708 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8709 +#else
8710 +#  define IS_COW(inode)                (0)
8711 +#  define IS_COW_LINK(inode)   (0)
8712 +#endif
8713 +
8714  /* the read-only stuff doesn't really belong here, but any other place is
8715     probably as bad and I don't want to create yet another include file. */
8716  
8717 @@ -362,11 +386,14 @@ struct inodes_stat_t {
8718  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8719  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8720  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8721 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8722  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8723  
8724 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8725 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8726 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8727 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8728  
8729 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8730 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8731  
8732  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8733  #define SYNC_FILE_RANGE_WRITE          2
8734 @@ -446,6 +473,7 @@ typedef void (dio_iodone_t)(struct kiocb
8735  #define ATTR_KILL_PRIV (1 << 14)
8736  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8737  #define ATTR_TIMES_SET (1 << 16)
8738 +#define ATTR_TAG       (1 << 17)
8739  
8740  /*
8741   * This is the Inode Attributes structure, used for notify_change().  It
8742 @@ -461,6 +489,7 @@ struct iattr {
8743         umode_t         ia_mode;
8744         uid_t           ia_uid;
8745         gid_t           ia_gid;
8746 +       tag_t           ia_tag;
8747         loff_t          ia_size;
8748         struct timespec ia_atime;
8749         struct timespec ia_mtime;
8750 @@ -474,6 +503,9 @@ struct iattr {
8751         struct file     *ia_file;
8752  };
8753  
8754 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8755 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8756 +
8757  /*
8758   * Includes for diskquotas.
8759   */
8760 @@ -743,7 +775,9 @@ struct inode {
8761         unsigned int            i_nlink;
8762         uid_t                   i_uid;
8763         gid_t                   i_gid;
8764 +       tag_t                   i_tag;
8765         dev_t                   i_rdev;
8766 +       dev_t                   i_mdev;
8767         unsigned int            i_blkbits;
8768         u64                     i_version;
8769         loff_t                  i_size;
8770 @@ -785,7 +819,8 @@ struct inode {
8771         unsigned long           i_state;
8772         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8773  
8774 -       unsigned int            i_flags;
8775 +       unsigned short          i_flags;
8776 +       unsigned short          i_vflags;
8777  
8778  #ifdef CONFIG_IMA
8779         /* protected by i_lock */
8780 @@ -882,12 +917,12 @@ static inline void i_size_write(struct i
8781  
8782  static inline unsigned iminor(const struct inode *inode)
8783  {
8784 -       return MINOR(inode->i_rdev);
8785 +       return MINOR(inode->i_mdev);
8786  }
8787  
8788  static inline unsigned imajor(const struct inode *inode)
8789  {
8790 -       return MAJOR(inode->i_rdev);
8791 +       return MAJOR(inode->i_mdev);
8792  }
8793  
8794  extern struct block_device *I_BDEV(struct inode *inode);
8795 @@ -949,6 +984,7 @@ struct file {
8796         loff_t                  f_pos;
8797         struct fown_struct      f_owner;
8798         const struct cred       *f_cred;
8799 +       xid_t                   f_xid;
8800         struct file_ra_state    f_ra;
8801  
8802         u64                     f_version;
8803 @@ -1087,6 +1123,7 @@ struct file_lock {
8804         struct file *fl_file;
8805         loff_t fl_start;
8806         loff_t fl_end;
8807 +       xid_t fl_xid;
8808  
8809         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8810         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8811 @@ -1568,6 +1605,7 @@ struct inode_operations {
8812         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8813         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8814         int (*removexattr) (struct dentry *, const char *);
8815 +       int (*sync_flags) (struct inode *, int, int);
8816         void (*truncate_range)(struct inode *, loff_t, loff_t);
8817         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8818                           loff_t len);
8819 @@ -1588,6 +1626,7 @@ extern ssize_t vfs_readv(struct file *, 
8820                 unsigned long, loff_t *);
8821  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8822                 unsigned long, loff_t *);
8823 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8824  
8825  struct super_operations {
8826         struct inode *(*alloc_inode)(struct super_block *sb);
8827 @@ -2389,6 +2428,7 @@ extern int dcache_dir_open(struct inode 
8828  extern int dcache_dir_close(struct inode *, struct file *);
8829  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8830  extern int dcache_readdir(struct file *, void *, filldir_t);
8831 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8832  extern int simple_setattr(struct dentry *, struct iattr *);
8833  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8834  extern int simple_statfs(struct dentry *, struct kstatfs *);
8835 diff -NurpP --minimal linux-2.6.37/include/linux/gfs2_ondisk.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/gfs2_ondisk.h
8836 --- linux-2.6.37/include/linux/gfs2_ondisk.h    2010-07-07 18:31:55.000000000 +0200
8837 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/gfs2_ondisk.h     2010-11-23 02:09:41.000000000 +0100
8838 @@ -211,6 +211,9 @@ enum {
8839         gfs2fl_NoAtime          = 7,
8840         gfs2fl_Sync             = 8,
8841         gfs2fl_System           = 9,
8842 +       gfs2fl_IXUnlink         = 16,
8843 +       gfs2fl_Barrier          = 17,
8844 +       gfs2fl_Cow              = 18,
8845         gfs2fl_TruncInProg      = 29,
8846         gfs2fl_InheritDirectio  = 30,
8847         gfs2fl_InheritJdata     = 31,
8848 @@ -227,6 +230,9 @@ enum {
8849  #define GFS2_DIF_NOATIME               0x00000080
8850  #define GFS2_DIF_SYNC                  0x00000100
8851  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8852 +#define GFS2_DIF_IXUNLINK              0x00010000
8853 +#define GFS2_DIF_BARRIER               0x00020000
8854 +#define GFS2_DIF_COW                   0x00040000
8855  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8856  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8857  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8858 diff -NurpP --minimal linux-2.6.37/include/linux/if_tun.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/if_tun.h
8859 --- linux-2.6.37/include/linux/if_tun.h 2010-08-02 16:52:54.000000000 +0200
8860 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/if_tun.h  2010-11-23 02:09:41.000000000 +0100
8861 @@ -53,6 +53,7 @@
8862  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8863  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8864  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8865 +#define TUNSETNID     _IOW('T', 217, int)
8866  
8867  /* TUNSETIFF ifr flags */
8868  #define IFF_TUN                0x0001
8869 diff -NurpP --minimal linux-2.6.37/include/linux/init_task.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/init_task.h
8870 --- linux-2.6.37/include/linux/init_task.h      2011-01-05 21:50:30.000000000 +0100
8871 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/init_task.h       2010-11-23 02:09:41.000000000 +0100
8872 @@ -178,6 +178,10 @@ extern struct cred init_cred;
8873         INIT_FTRACE_GRAPH                                               \
8874         INIT_TRACE_RECURSION                                            \
8875         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8876 +       .xid            = 0,                                            \
8877 +       .vx_info        = NULL,                                         \
8878 +       .nid            = 0,                                            \
8879 +       .nx_info        = NULL,                                         \
8880  }
8881  
8882  
8883 diff -NurpP --minimal linux-2.6.37/include/linux/ipc.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/ipc.h
8884 --- linux-2.6.37/include/linux/ipc.h    2009-12-03 20:02:55.000000000 +0100
8885 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/ipc.h     2010-11-23 02:09:41.000000000 +0100
8886 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8887         key_t           key;
8888         uid_t           uid;
8889         gid_t           gid;
8890 +       xid_t           xid;
8891         uid_t           cuid;
8892         gid_t           cgid;
8893         mode_t          mode; 
8894 diff -NurpP --minimal linux-2.6.37/include/linux/Kbuild linux-2.6.37-vs2.3.0.37-rc2/include/linux/Kbuild
8895 --- linux-2.6.37/include/linux/Kbuild   2011-01-05 21:50:28.000000000 +0100
8896 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/Kbuild    2010-11-23 02:09:41.000000000 +0100
8897 @@ -15,6 +15,7 @@ header-y += netfilter_bridge/
8898  header-y += netfilter_ipv4/
8899  header-y += netfilter_ipv6/
8900  header-y += usb/
8901 +header-y += vserver/
8902  header-y += wimax/
8903  
8904  objhdr-y += version.h
8905 diff -NurpP --minimal linux-2.6.37/include/linux/loop.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/loop.h
8906 --- linux-2.6.37/include/linux/loop.h   2009-09-10 15:26:25.000000000 +0200
8907 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/loop.h    2010-11-23 02:09:41.000000000 +0100
8908 @@ -45,6 +45,7 @@ struct loop_device {
8909         struct loop_func_table *lo_encryption;
8910         __u32           lo_init[2];
8911         uid_t           lo_key_owner;   /* Who set the key */
8912 +       xid_t           lo_xid;
8913         int             (*ioctl)(struct loop_device *, int cmd, 
8914                                  unsigned long arg); 
8915  
8916 diff -NurpP --minimal linux-2.6.37/include/linux/magic.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/magic.h
8917 --- linux-2.6.37/include/linux/magic.h  2011-01-05 21:50:30.000000000 +0100
8918 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/magic.h   2010-11-23 02:09:41.000000000 +0100
8919 @@ -3,7 +3,7 @@
8920  
8921  #define ADFS_SUPER_MAGIC       0xadf5
8922  #define AFFS_SUPER_MAGIC       0xadff
8923 -#define AFS_SUPER_MAGIC                0x5346414F
8924 +#define AFS_SUPER_MAGIC                0x5346414F
8925  #define AUTOFS_SUPER_MAGIC     0x0187
8926  #define CODA_SUPER_MAGIC       0x73757245
8927  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8928 @@ -38,6 +38,7 @@
8929  #define NFS_SUPER_MAGIC                0x6969
8930  #define OPENPROM_SUPER_MAGIC   0x9fa1
8931  #define PROC_SUPER_MAGIC       0x9fa0
8932 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8933  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8934  
8935  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8936 diff -NurpP --minimal linux-2.6.37/include/linux/major.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/major.h
8937 --- linux-2.6.37/include/linux/major.h  2009-09-10 15:26:25.000000000 +0200
8938 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/major.h   2010-11-23 02:09:41.000000000 +0100
8939 @@ -15,6 +15,7 @@
8940  #define HD_MAJOR               IDE0_MAJOR
8941  #define PTY_SLAVE_MAJOR                3
8942  #define TTY_MAJOR              4
8943 +#define VROOT_MAJOR            4
8944  #define TTYAUX_MAJOR           5
8945  #define LP_MAJOR               6
8946  #define VCS_MAJOR              7
8947 diff -NurpP --minimal linux-2.6.37/include/linux/memcontrol.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/memcontrol.h
8948 --- linux-2.6.37/include/linux/memcontrol.h     2010-10-21 13:07:53.000000000 +0200
8949 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/memcontrol.h      2010-11-23 02:09:41.000000000 +0100
8950 @@ -77,6 +77,13 @@ int task_in_mem_cgroup(struct task_struc
8951  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
8952  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8953  
8954 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8955 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8956 +
8957 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8958 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8959 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8960 +
8961  static inline
8962  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8963  {
8964 diff -NurpP --minimal linux-2.6.37/include/linux/mm_types.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/mm_types.h
8965 --- linux-2.6.37/include/linux/mm_types.h       2011-01-05 21:50:31.000000000 +0100
8966 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/mm_types.h        2010-11-23 02:09:41.000000000 +0100
8967 @@ -269,6 +269,7 @@ struct mm_struct {
8968  
8969         /* Architecture-specific MM context */
8970         mm_context_t context;
8971 +       struct vx_info *mm_vx_info;
8972  
8973         /* Swap token stuff */
8974         /*
8975 diff -NurpP --minimal linux-2.6.37/include/linux/mount.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/mount.h
8976 --- linux-2.6.37/include/linux/mount.h  2010-10-21 13:07:53.000000000 +0200
8977 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/mount.h   2010-11-23 02:09:41.000000000 +0100
8978 @@ -46,6 +46,9 @@ struct mnt_namespace;
8979  
8980  #define MNT_INTERNAL   0x4000
8981  
8982 +#define MNT_TAGID      0x10000
8983 +#define MNT_NOTAG      0x20000
8984 +
8985  struct vfsmount {
8986         struct list_head mnt_hash;
8987         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8988 @@ -84,6 +87,7 @@ struct vfsmount {
8989  #else
8990         int mnt_writers;
8991  #endif
8992 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8993  };
8994  
8995  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
8996 diff -NurpP --minimal linux-2.6.37/include/linux/net.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/net.h
8997 --- linux-2.6.37/include/linux/net.h    2011-01-05 21:50:31.000000000 +0100
8998 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/net.h     2010-11-23 02:09:41.000000000 +0100
8999 @@ -71,6 +71,7 @@ struct net;
9000  #define SOCK_NOSPACE           2
9001  #define SOCK_PASSCRED          3
9002  #define SOCK_PASSSEC           4
9003 +#define SOCK_USER_SOCKET       5
9004  
9005  #ifndef ARCH_HAS_SOCKET_TYPES
9006  /**
9007 diff -NurpP --minimal linux-2.6.37/include/linux/nfs_mount.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/nfs_mount.h
9008 --- linux-2.6.37/include/linux/nfs_mount.h      2011-01-05 21:50:31.000000000 +0100
9009 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/nfs_mount.h       2010-11-23 02:09:41.000000000 +0100
9010 @@ -63,7 +63,8 @@ struct nfs_mount_data {
9011  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9012  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9013  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9014 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9015 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9016 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9017  
9018  /* The following are for internal use only */
9019  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9020 diff -NurpP --minimal linux-2.6.37/include/linux/nsproxy.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/nsproxy.h
9021 --- linux-2.6.37/include/linux/nsproxy.h        2009-06-11 17:13:17.000000000 +0200
9022 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/nsproxy.h 2010-11-23 02:09:41.000000000 +0100
9023 @@ -3,6 +3,7 @@
9024  
9025  #include <linux/spinlock.h>
9026  #include <linux/sched.h>
9027 +#include <linux/vserver/debug.h>
9028  
9029  struct mnt_namespace;
9030  struct uts_namespace;
9031 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9032  }
9033  
9034  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9035 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9036  void exit_task_namespaces(struct task_struct *tsk);
9037  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9038  void free_nsproxy(struct nsproxy *ns);
9039  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9040         struct fs_struct *);
9041  
9042 -static inline void put_nsproxy(struct nsproxy *ns)
9043 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9044 +
9045 +static inline void __get_nsproxy(struct nsproxy *ns,
9046 +       const char *_file, int _line)
9047  {
9048 -       if (atomic_dec_and_test(&ns->count)) {
9049 -               free_nsproxy(ns);
9050 -       }
9051 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9052 +               ns, atomic_read(&ns->count), _file, _line);
9053 +       atomic_inc(&ns->count);
9054  }
9055  
9056 -static inline void get_nsproxy(struct nsproxy *ns)
9057 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9058 +
9059 +static inline void __put_nsproxy(struct nsproxy *ns,
9060 +       const char *_file, int _line)
9061  {
9062 -       atomic_inc(&ns->count);
9063 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9064 +               ns, atomic_read(&ns->count), _file, _line);
9065 +       if (atomic_dec_and_test(&ns->count)) {
9066 +               free_nsproxy(ns);
9067 +       }
9068  }
9069  
9070  #ifdef CONFIG_CGROUP_NS
9071 diff -NurpP --minimal linux-2.6.37/include/linux/pid.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/pid.h
9072 --- linux-2.6.37/include/linux/pid.h    2009-03-24 14:22:43.000000000 +0100
9073 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/pid.h     2010-11-23 02:09:41.000000000 +0100
9074 @@ -8,7 +8,8 @@ enum pid_type
9075         PIDTYPE_PID,
9076         PIDTYPE_PGID,
9077         PIDTYPE_SID,
9078 -       PIDTYPE_MAX
9079 +       PIDTYPE_MAX,
9080 +       PIDTYPE_REALPID
9081  };
9082  
9083  /*
9084 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9085  }
9086  
9087  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9088 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9089  pid_t pid_vnr(struct pid *pid);
9090  
9091  #define do_each_pid_task(pid, type, task)                              \
9092 diff -NurpP --minimal linux-2.6.37/include/linux/proc_fs.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/proc_fs.h
9093 --- linux-2.6.37/include/linux/proc_fs.h        2009-12-03 20:02:56.000000000 +0100
9094 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/proc_fs.h 2010-11-23 02:09:41.000000000 +0100
9095 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9096         nlink_t nlink;
9097         uid_t uid;
9098         gid_t gid;
9099 +       int vx_flags;
9100         loff_t size;
9101         const struct inode_operations *proc_iops;
9102         /*
9103 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9104  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9105  #endif
9106  
9107 +struct vx_info;
9108 +struct nx_info;
9109 +
9110  union proc_op {
9111         int (*proc_get_link)(struct inode *, struct path *);
9112         int (*proc_read)(struct task_struct *task, char *page);
9113         int (*proc_show)(struct seq_file *m,
9114                 struct pid_namespace *ns, struct pid *pid,
9115                 struct task_struct *task);
9116 +       int (*proc_vs_read)(char *page);
9117 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9118 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9119  };
9120  
9121  struct ctl_table_header;
9122 @@ -263,6 +270,7 @@ struct ctl_table;
9123  
9124  struct proc_inode {
9125         struct pid *pid;
9126 +       int vx_flags;
9127         int fd;
9128         union proc_op op;
9129         struct proc_dir_entry *pde;
9130 diff -NurpP --minimal linux-2.6.37/include/linux/quotaops.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/quotaops.h
9131 --- linux-2.6.37/include/linux/quotaops.h       2010-10-21 13:07:54.000000000 +0200
9132 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/quotaops.h        2010-11-23 02:09:41.000000000 +0100
9133 @@ -8,6 +8,7 @@
9134  #define _LINUX_QUOTAOPS_
9135  
9136  #include <linux/fs.h>
9137 +#include <linux/vs_dlimit.h>
9138  
9139  #define DQUOT_SPACE_WARN       0x1
9140  #define DQUOT_SPACE_RESERVE    0x2
9141 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
9142  
9143  static inline int dquot_alloc_inode(const struct inode *inode)
9144  {
9145 -       return 0;
9146 +       return dl_alloc_inode(inode);
9147  }
9148  
9149  static inline void dquot_free_inode(const struct inode *inode)
9150  {
9151 +       dl_free_inode(inode);
9152  }
9153  
9154  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
9155 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct 
9156  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
9157                 int flags)
9158  {
9159 +       int ret = 0;
9160 +
9161 +       if ((ret = dl_alloc_space(inode, number)))
9162 +               return ret;
9163         if (!(flags & DQUOT_SPACE_RESERVE))
9164                 inode_add_bytes(inode, number);
9165         return 0;
9166 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
9167  {
9168         if (!(flags & DQUOT_SPACE_RESERVE))
9169                 inode_sub_bytes(inode, number);
9170 +       dl_free_space(inode, number);
9171  }
9172  
9173  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
9174 diff -NurpP --minimal linux-2.6.37/include/linux/reboot.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/reboot.h
9175 --- linux-2.6.37/include/linux/reboot.h 2010-07-07 18:31:56.000000000 +0200
9176 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/reboot.h  2010-11-23 02:09:41.000000000 +0100
9177 @@ -33,6 +33,7 @@
9178  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9179  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9180  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9181 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9182  
9183  
9184  #ifdef __KERNEL__
9185 diff -NurpP --minimal linux-2.6.37/include/linux/reiserfs_fs.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/reiserfs_fs.h
9186 --- linux-2.6.37/include/linux/reiserfs_fs.h    2011-01-05 21:50:32.000000000 +0100
9187 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/reiserfs_fs.h     2010-11-23 02:09:41.000000000 +0100
9188 @@ -976,6 +976,11 @@ struct stat_data_v1 {
9189  #define REISERFS_COMPR_FL     FS_COMPR_FL
9190  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9191  
9192 +/* unfortunately reiserfs sdattr is only 16 bit */
9193 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9194 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9195 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9196 +
9197  /* persistent flags that file inherits from the parent directory */
9198  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9199                                 REISERFS_SYNC_FL |      \
9200 @@ -985,6 +990,9 @@ struct stat_data_v1 {
9201                                 REISERFS_COMPR_FL |     \
9202                                 REISERFS_NOTAIL_FL )
9203  
9204 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9205 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9206 +
9207  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9208     address blocks) */
9209  struct stat_data {
9210 @@ -2070,6 +2078,7 @@ static inline void reiserfs_update_sd(st
9211  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9212  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9213  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9214 +int reiserfs_sync_flags(struct inode *inode, int, int);
9215  
9216  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
9217  
9218 diff -NurpP --minimal linux-2.6.37/include/linux/reiserfs_fs_sb.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/reiserfs_fs_sb.h
9219 --- linux-2.6.37/include/linux/reiserfs_fs_sb.h 2010-02-25 11:52:07.000000000 +0100
9220 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/reiserfs_fs_sb.h  2010-11-23 02:09:41.000000000 +0100
9221 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9222         REISERFS_EXPOSE_PRIVROOT,
9223         REISERFS_BARRIER_NONE,
9224         REISERFS_BARRIER_FLUSH,
9225 +       REISERFS_TAGGED,
9226  
9227         /* Actions on error */
9228         REISERFS_ERROR_PANIC,
9229 diff -NurpP --minimal linux-2.6.37/include/linux/sched.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/sched.h
9230 --- linux-2.6.37/include/linux/sched.h  2011-01-05 21:50:32.000000000 +0100
9231 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/sched.h   2011-01-05 22:30:40.000000000 +0100
9232 @@ -1357,6 +1357,14 @@ struct task_struct {
9233  #endif
9234         seccomp_t seccomp;
9235  
9236 +/* vserver context data */
9237 +       struct vx_info *vx_info;
9238 +       struct nx_info *nx_info;
9239 +
9240 +       xid_t xid;
9241 +       nid_t nid;
9242 +       tag_t tag;
9243 +
9244  /* Thread group tracking */
9245         u32 parent_exec_id;
9246         u32 self_exec_id;
9247 @@ -1591,6 +1599,11 @@ struct pid_namespace;
9248  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9249                         struct pid_namespace *ns);
9250  
9251 +#include <linux/vserver/base.h>
9252 +#include <linux/vserver/context.h>
9253 +#include <linux/vserver/debug.h>
9254 +#include <linux/vserver/pid.h>
9255 +
9256  static inline pid_t task_pid_nr(struct task_struct *tsk)
9257  {
9258         return tsk->pid;
9259 @@ -1604,7 +1617,8 @@ static inline pid_t task_pid_nr_ns(struc
9260  
9261  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9262  {
9263 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9264 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9265 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9266  }
9267  
9268  
9269 @@ -1617,7 +1631,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9270  
9271  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9272  {
9273 -       return pid_vnr(task_tgid(tsk));
9274 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9275  }
9276  
9277  
9278 diff -NurpP --minimal linux-2.6.37/include/linux/shmem_fs.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/shmem_fs.h
9279 --- linux-2.6.37/include/linux/shmem_fs.h       2010-10-21 13:07:55.000000000 +0200
9280 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/shmem_fs.h        2010-11-23 02:09:41.000000000 +0100
9281 @@ -9,6 +9,9 @@
9282  
9283  #define SHMEM_NR_DIRECT 16
9284  
9285 +#define TMPFS_SUPER_MAGIC      0x01021994
9286 +
9287 +
9288  struct shmem_inode_info {
9289         spinlock_t              lock;
9290         unsigned long           flags;
9291 diff -NurpP --minimal linux-2.6.37/include/linux/stat.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/stat.h
9292 --- linux-2.6.37/include/linux/stat.h   2008-12-25 00:26:37.000000000 +0100
9293 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/stat.h    2010-11-23 02:09:41.000000000 +0100
9294 @@ -66,6 +66,7 @@ struct kstat {
9295         unsigned int    nlink;
9296         uid_t           uid;
9297         gid_t           gid;
9298 +       tag_t           tag;
9299         dev_t           rdev;
9300         loff_t          size;
9301         struct timespec  atime;
9302 diff -NurpP --minimal linux-2.6.37/include/linux/sunrpc/auth.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/sunrpc/auth.h
9303 --- linux-2.6.37/include/linux/sunrpc/auth.h    2011-01-05 21:50:33.000000000 +0100
9304 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/sunrpc/auth.h     2010-11-23 02:09:41.000000000 +0100
9305 @@ -25,6 +25,7 @@
9306  struct auth_cred {
9307         uid_t   uid;
9308         gid_t   gid;
9309 +       tag_t   tag;
9310         struct group_info *group_info;
9311         unsigned char machine_cred : 1;
9312  };
9313 diff -NurpP --minimal linux-2.6.37/include/linux/sunrpc/clnt.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/sunrpc/clnt.h
9314 --- linux-2.6.37/include/linux/sunrpc/clnt.h    2011-01-05 21:50:33.000000000 +0100
9315 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/sunrpc/clnt.h     2010-11-23 02:09:41.000000000 +0100
9316 @@ -49,7 +49,8 @@ struct rpc_clnt {
9317         unsigned int            cl_softrtry : 1,/* soft timeouts */
9318                                 cl_discrtry : 1,/* disconnect before retry */
9319                                 cl_autobind : 1,/* use getport() */
9320 -                               cl_chatty   : 1;/* be verbose */
9321 +                               cl_chatty   : 1,/* be verbose */
9322 +                               cl_tag      : 1;/* context tagging */
9323  
9324         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9325         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9326 diff -NurpP --minimal linux-2.6.37/include/linux/syscalls.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/syscalls.h
9327 --- linux-2.6.37/include/linux/syscalls.h       2011-01-05 21:50:34.000000000 +0100
9328 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/syscalls.h        2010-11-23 02:09:41.000000000 +0100
9329 @@ -478,6 +478,8 @@ asmlinkage long sys_symlink(const char _
9330  asmlinkage long sys_unlink(const char __user *pathname);
9331  asmlinkage long sys_rename(const char __user *oldname,
9332                                 const char __user *newname);
9333 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9334 +                               umode_t mode);
9335  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9336  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9337  
9338 diff -NurpP --minimal linux-2.6.37/include/linux/sysctl.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/sysctl.h
9339 --- linux-2.6.37/include/linux/sysctl.h 2010-08-02 16:52:56.000000000 +0200
9340 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/sysctl.h  2010-11-23 02:09:41.000000000 +0100
9341 @@ -60,6 +60,7 @@ enum
9342         CTL_ABI=9,              /* Binary emulation */
9343         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9344         CTL_ARLAN=254,          /* arlan wireless driver */
9345 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9346         CTL_S390DBF=5677,       /* s390 debug */
9347         CTL_SUNRPC=7249,        /* sunrpc debug */
9348         CTL_PM=9899,            /* frv power management */
9349 @@ -94,6 +95,7 @@ enum
9350  
9351         KERN_PANIC=15,          /* int: panic timeout */
9352         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9353 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9354  
9355         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9356         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9357 diff -NurpP --minimal linux-2.6.37/include/linux/sysfs.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/sysfs.h
9358 --- linux-2.6.37/include/linux/sysfs.h  2011-01-05 21:50:34.000000000 +0100
9359 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/sysfs.h   2010-11-23 02:09:41.000000000 +0100
9360 @@ -19,6 +19,8 @@
9361  #include <linux/kobject_ns.h>
9362  #include <asm/atomic.h>
9363  
9364 +#define SYSFS_SUPER_MAGIC      0x62656572
9365 +
9366  struct kobject;
9367  struct module;
9368  enum kobj_ns_type;
9369 diff -NurpP --minimal linux-2.6.37/include/linux/time.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/time.h
9370 --- linux-2.6.37/include/linux/time.h   2010-10-21 13:07:55.000000000 +0200
9371 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/time.h    2010-11-23 02:09:41.000000000 +0100
9372 @@ -252,6 +252,9 @@ static __always_inline void timespec_add
9373         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9374         a->tv_nsec = ns;
9375  }
9376 +
9377 +#include <linux/vs_time.h>
9378 +
9379  #endif /* __KERNEL__ */
9380  
9381  #define NFDBITS                        __NFDBITS
9382 diff -NurpP --minimal linux-2.6.37/include/linux/types.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/types.h
9383 --- linux-2.6.37/include/linux/types.h  2011-01-05 21:50:34.000000000 +0100
9384 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/types.h   2010-11-23 02:09:41.000000000 +0100
9385 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
9386  typedef __kernel_gid32_t       gid_t;
9387  typedef __kernel_uid16_t        uid16_t;
9388  typedef __kernel_gid16_t        gid16_t;
9389 +typedef unsigned int           xid_t;
9390 +typedef unsigned int           nid_t;
9391 +typedef unsigned int           tag_t;
9392  
9393  typedef unsigned long          uintptr_t;
9394  
9395 diff -NurpP --minimal linux-2.6.37/include/linux/vroot.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vroot.h
9396 --- linux-2.6.37/include/linux/vroot.h  1970-01-01 01:00:00.000000000 +0100
9397 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vroot.h   2010-11-23 02:09:41.000000000 +0100
9398 @@ -0,0 +1,51 @@
9399 +
9400 +/*
9401 + * include/linux/vroot.h
9402 + *
9403 + * written by Herbert Pötzl, 9/11/2002
9404 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9405 + *
9406 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9407 + * Redistribution of this file is permitted under the
9408 + * GNU General Public License.
9409 + */
9410 +
9411 +#ifndef _LINUX_VROOT_H
9412 +#define _LINUX_VROOT_H
9413 +
9414 +
9415 +#ifdef __KERNEL__
9416 +
9417 +/* Possible states of device */
9418 +enum {
9419 +       Vr_unbound,
9420 +       Vr_bound,
9421 +};
9422 +
9423 +struct vroot_device {
9424 +       int             vr_number;
9425 +       int             vr_refcnt;
9426 +
9427 +       struct semaphore        vr_ctl_mutex;
9428 +       struct block_device    *vr_device;
9429 +       int                     vr_state;
9430 +};
9431 +
9432 +
9433 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9434 +
9435 +extern int register_vroot_grb(vroot_grb_func *);
9436 +extern int unregister_vroot_grb(vroot_grb_func *);
9437 +
9438 +#endif /* __KERNEL__ */
9439 +
9440 +#define MAX_VROOT_DEFAULT      8
9441 +
9442 +/*
9443 + * IOCTL commands --- we will commandeer 0x56 ('V')
9444 + */
9445 +
9446 +#define VROOT_SET_DEV          0x5600
9447 +#define VROOT_CLR_DEV          0x5601
9448 +
9449 +#endif /* _LINUX_VROOT_H */
9450 diff -NurpP --minimal linux-2.6.37/include/linux/vs_base.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_base.h
9451 --- linux-2.6.37/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
9452 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_base.h 2010-11-23 02:09:41.000000000 +0100
9453 @@ -0,0 +1,10 @@
9454 +#ifndef _VS_BASE_H
9455 +#define _VS_BASE_H
9456 +
9457 +#include "vserver/base.h"
9458 +#include "vserver/check.h"
9459 +#include "vserver/debug.h"
9460 +
9461 +#else
9462 +#warning duplicate inclusion
9463 +#endif
9464 diff -NurpP --minimal linux-2.6.37/include/linux/vs_context.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_context.h
9465 --- linux-2.6.37/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
9466 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_context.h      2010-11-23 02:09:41.000000000 +0100
9467 @@ -0,0 +1,242 @@
9468 +#ifndef _VS_CONTEXT_H
9469 +#define _VS_CONTEXT_H
9470 +
9471 +#include "vserver/base.h"
9472 +#include "vserver/check.h"
9473 +#include "vserver/context.h"
9474 +#include "vserver/history.h"
9475 +#include "vserver/debug.h"
9476 +
9477 +#include <linux/sched.h>
9478 +
9479 +
9480 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9481 +
9482 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9483 +       const char *_file, int _line, void *_here)
9484 +{
9485 +       if (!vxi)
9486 +               return NULL;
9487 +
9488 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9489 +               vxi, vxi ? vxi->vx_id : 0,
9490 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9491 +               _file, _line);
9492 +       __vxh_get_vx_info(vxi, _here);
9493 +
9494 +       atomic_inc(&vxi->vx_usecnt);
9495 +       return vxi;
9496 +}
9497 +
9498 +
9499 +extern void free_vx_info(struct vx_info *);
9500 +
9501 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9502 +
9503 +static inline void __put_vx_info(struct vx_info *vxi,
9504 +       const char *_file, int _line, void *_here)
9505 +{
9506 +       if (!vxi)
9507 +               return;
9508 +
9509 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9510 +               vxi, vxi ? vxi->vx_id : 0,
9511 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9512 +               _file, _line);
9513 +       __vxh_put_vx_info(vxi, _here);
9514 +
9515 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9516 +               free_vx_info(vxi);
9517 +}
9518 +
9519 +
9520 +#define init_vx_info(p, i) \
9521 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9522 +
9523 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9524 +       const char *_file, int _line, void *_here)
9525 +{
9526 +       if (vxi) {
9527 +               vxlprintk(VXD_CBIT(xid, 3),
9528 +                       "init_vx_info(%p[#%d.%d])",
9529 +                       vxi, vxi ? vxi->vx_id : 0,
9530 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9531 +                       _file, _line);
9532 +               __vxh_init_vx_info(vxi, vxp, _here);
9533 +
9534 +               atomic_inc(&vxi->vx_usecnt);
9535 +       }
9536 +       *vxp = vxi;
9537 +}
9538 +
9539 +
9540 +#define set_vx_info(p, i) \
9541 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9542 +
9543 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9544 +       const char *_file, int _line, void *_here)
9545 +{
9546 +       struct vx_info *vxo;
9547 +
9548 +       if (!vxi)
9549 +               return;
9550 +
9551 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9552 +               vxi, vxi ? vxi->vx_id : 0,
9553 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9554 +               _file, _line);
9555 +       __vxh_set_vx_info(vxi, vxp, _here);
9556 +
9557 +       atomic_inc(&vxi->vx_usecnt);
9558 +       vxo = xchg(vxp, vxi);
9559 +       BUG_ON(vxo);
9560 +}
9561 +
9562 +
9563 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9564 +
9565 +static inline void __clr_vx_info(struct vx_info **vxp,
9566 +       const char *_file, int _line, void *_here)
9567 +{
9568 +       struct vx_info *vxo;
9569 +
9570 +       vxo = xchg(vxp, NULL);
9571 +       if (!vxo)
9572 +               return;
9573 +
9574 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9575 +               vxo, vxo ? vxo->vx_id : 0,
9576 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9577 +               _file, _line);
9578 +       __vxh_clr_vx_info(vxo, vxp, _here);
9579 +
9580 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9581 +               free_vx_info(vxo);
9582 +}
9583 +
9584 +
9585 +#define claim_vx_info(v, p) \
9586 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9587 +
9588 +static inline void __claim_vx_info(struct vx_info *vxi,
9589 +       struct task_struct *task,
9590 +       const char *_file, int _line, void *_here)
9591 +{
9592 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9593 +               vxi, vxi ? vxi->vx_id : 0,
9594 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9595 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9596 +               task, _file, _line);
9597 +       __vxh_claim_vx_info(vxi, task, _here);
9598 +
9599 +       atomic_inc(&vxi->vx_tasks);
9600 +}
9601 +
9602 +
9603 +extern void unhash_vx_info(struct vx_info *);
9604 +
9605 +#define release_vx_info(v, p) \
9606 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9607 +
9608 +static inline void __release_vx_info(struct vx_info *vxi,
9609 +       struct task_struct *task,
9610 +       const char *_file, int _line, void *_here)
9611 +{
9612 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9613 +               vxi, vxi ? vxi->vx_id : 0,
9614 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9615 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9616 +               task, _file, _line);
9617 +       __vxh_release_vx_info(vxi, task, _here);
9618 +
9619 +       might_sleep();
9620 +
9621 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9622 +               unhash_vx_info(vxi);
9623 +}
9624 +
9625 +
9626 +#define task_get_vx_info(p) \
9627 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9628 +
9629 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9630 +       const char *_file, int _line, void *_here)
9631 +{
9632 +       struct vx_info *vxi;
9633 +
9634 +       task_lock(p);
9635 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9636 +               p, _file, _line);
9637 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9638 +       task_unlock(p);
9639 +       return vxi;
9640 +}
9641 +
9642 +
9643 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9644 +{
9645 +       if (waitqueue_active(&vxi->vx_wait))
9646 +               wake_up_interruptible(&vxi->vx_wait);
9647 +}
9648 +
9649 +
9650 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9651 +
9652 +static inline void __enter_vx_info(struct vx_info *vxi,
9653 +       struct vx_info_save *vxis, const char *_file, int _line)
9654 +{
9655 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9656 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9657 +               current->xid, current->vx_info, _file, _line);
9658 +       vxis->vxi = xchg(&current->vx_info, vxi);
9659 +       vxis->xid = current->xid;
9660 +       current->xid = vxi ? vxi->vx_id : 0;
9661 +}
9662 +
9663 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9664 +
9665 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9666 +       const char *_file, int _line)
9667 +{
9668 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9669 +               vxis, vxis->xid, vxis->vxi, current,
9670 +               current->xid, current->vx_info, _file, _line);
9671 +       (void)xchg(&current->vx_info, vxis->vxi);
9672 +       current->xid = vxis->xid;
9673 +}
9674 +
9675 +
9676 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9677 +{
9678 +       vxis->vxi = xchg(&current->vx_info, NULL);
9679 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9680 +}
9681 +
9682 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9683 +{
9684 +       (void)xchg(&current->xid, vxis->xid);
9685 +       (void)xchg(&current->vx_info, vxis->vxi);
9686 +}
9687 +
9688 +#define task_is_init(p) \
9689 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9690 +
9691 +static inline int __task_is_init(struct task_struct *p,
9692 +       const char *_file, int _line, void *_here)
9693 +{
9694 +       int is_init = is_global_init(p);
9695 +
9696 +       task_lock(p);
9697 +       if (p->vx_info)
9698 +               is_init = p->vx_info->vx_initpid == p->pid;
9699 +       task_unlock(p);
9700 +       return is_init;
9701 +}
9702 +
9703 +extern void exit_vx_info(struct task_struct *, int);
9704 +extern void exit_vx_info_early(struct task_struct *, int);
9705 +
9706 +
9707 +#else
9708 +#warning duplicate inclusion
9709 +#endif
9710 diff -NurpP --minimal linux-2.6.37/include/linux/vs_cowbl.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_cowbl.h
9711 --- linux-2.6.37/include/linux/vs_cowbl.h       1970-01-01 01:00:00.000000000 +0100
9712 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_cowbl.h        2010-11-23 02:09:41.000000000 +0100
9713 @@ -0,0 +1,48 @@
9714 +#ifndef _VS_COWBL_H
9715 +#define _VS_COWBL_H
9716 +
9717 +#include <linux/fs.h>
9718 +#include <linux/dcache.h>
9719 +#include <linux/namei.h>
9720 +#include <linux/slab.h>
9721 +
9722 +extern struct dentry *cow_break_link(const char *pathname);
9723 +
9724 +static inline int cow_check_and_break(struct path *path)
9725 +{
9726 +       struct inode *inode = path->dentry->d_inode;
9727 +       int error = 0;
9728 +
9729 +       /* do we need this check? */
9730 +       if (IS_RDONLY(inode))
9731 +               return -EROFS;
9732 +
9733 +       if (IS_COW(inode)) {
9734 +               if (IS_COW_LINK(inode)) {
9735 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9736 +                       char *pp, *buf;
9737 +
9738 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9739 +                       if (!buf) {
9740 +                               return -ENOMEM;
9741 +                       }
9742 +                       pp = d_path(path, buf, PATH_MAX);
9743 +                       new_dentry = cow_break_link(pp);
9744 +                       kfree(buf);
9745 +                       if (!IS_ERR(new_dentry)) {
9746 +                               path->dentry = new_dentry;
9747 +                               dput(old_dentry);
9748 +                       } else
9749 +                               error = PTR_ERR(new_dentry);
9750 +               } else {
9751 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9752 +                       inode->i_ctime = CURRENT_TIME;
9753 +                       mark_inode_dirty(inode);
9754 +               }
9755 +       }
9756 +       return error;
9757 +}
9758 +
9759 +#else
9760 +#warning duplicate inclusion
9761 +#endif
9762 diff -NurpP --minimal linux-2.6.37/include/linux/vs_cvirt.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_cvirt.h
9763 --- linux-2.6.37/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
9764 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_cvirt.h        2010-11-23 02:09:41.000000000 +0100
9765 @@ -0,0 +1,50 @@
9766 +#ifndef _VS_CVIRT_H
9767 +#define _VS_CVIRT_H
9768 +
9769 +#include "vserver/cvirt.h"
9770 +#include "vserver/context.h"
9771 +#include "vserver/base.h"
9772 +#include "vserver/check.h"
9773 +#include "vserver/debug.h"
9774 +
9775 +
9776 +static inline void vx_activate_task(struct task_struct *p)
9777 +{
9778 +       struct vx_info *vxi;
9779 +
9780 +       if ((vxi = p->vx_info)) {
9781 +               vx_update_load(vxi);
9782 +               atomic_inc(&vxi->cvirt.nr_running);
9783 +       }
9784 +}
9785 +
9786 +static inline void vx_deactivate_task(struct task_struct *p)
9787 +{
9788 +       struct vx_info *vxi;
9789 +
9790 +       if ((vxi = p->vx_info)) {
9791 +               vx_update_load(vxi);
9792 +               atomic_dec(&vxi->cvirt.nr_running);
9793 +       }
9794 +}
9795 +
9796 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9797 +{
9798 +       struct vx_info *vxi;
9799 +
9800 +       if ((vxi = p->vx_info))
9801 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9802 +}
9803 +
9804 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9805 +{
9806 +       struct vx_info *vxi;
9807 +
9808 +       if ((vxi = p->vx_info))
9809 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9810 +}
9811 +
9812 +
9813 +#else
9814 +#warning duplicate inclusion
9815 +#endif
9816 diff -NurpP --minimal linux-2.6.37/include/linux/vs_device.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_device.h
9817 --- linux-2.6.37/include/linux/vs_device.h      1970-01-01 01:00:00.000000000 +0100
9818 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_device.h       2010-11-23 02:09:41.000000000 +0100
9819 @@ -0,0 +1,45 @@
9820 +#ifndef _VS_DEVICE_H
9821 +#define _VS_DEVICE_H
9822 +
9823 +#include "vserver/base.h"
9824 +#include "vserver/device.h"
9825 +#include "vserver/debug.h"
9826 +
9827 +
9828 +#ifdef CONFIG_VSERVER_DEVICE
9829 +
9830 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9831 +
9832 +#define vs_device_perm(v, d, m, p) \
9833 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9834 +
9835 +#else
9836 +
9837 +static inline
9838 +int vs_map_device(struct vx_info *vxi,
9839 +       dev_t device, dev_t *target, umode_t mode)
9840 +{
9841 +       if (target)
9842 +               *target = device;
9843 +       return ~0;
9844 +}
9845 +
9846 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9847 +
9848 +#endif
9849 +
9850 +
9851 +#define vs_map_chrdev(d, t, p) \
9852 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9853 +#define vs_map_blkdev(d, t, p) \
9854 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9855 +
9856 +#define vs_chrdev_perm(d, p) \
9857 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9858 +#define vs_blkdev_perm(d, p) \
9859 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9860 +
9861 +
9862 +#else
9863 +#warning duplicate inclusion
9864 +#endif
9865 diff -NurpP --minimal linux-2.6.37/include/linux/vs_dlimit.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_dlimit.h
9866 --- linux-2.6.37/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
9867 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_dlimit.h       2010-11-23 02:09:41.000000000 +0100
9868 @@ -0,0 +1,215 @@
9869 +#ifndef _VS_DLIMIT_H
9870 +#define _VS_DLIMIT_H
9871 +
9872 +#include <linux/fs.h>
9873 +
9874 +#include "vserver/dlimit.h"
9875 +#include "vserver/base.h"
9876 +#include "vserver/debug.h"
9877 +
9878 +
9879 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9880 +
9881 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9882 +       const char *_file, int _line)
9883 +{
9884 +       if (!dli)
9885 +               return NULL;
9886 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9887 +               dli, dli ? dli->dl_tag : 0,
9888 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9889 +               _file, _line);
9890 +       atomic_inc(&dli->dl_usecnt);
9891 +       return dli;
9892 +}
9893 +
9894 +
9895 +#define free_dl_info(i) \
9896 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9897 +
9898 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9899 +
9900 +static inline void __put_dl_info(struct dl_info *dli,
9901 +       const char *_file, int _line)
9902 +{
9903 +       if (!dli)
9904 +               return;
9905 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9906 +               dli, dli ? dli->dl_tag : 0,
9907 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9908 +               _file, _line);
9909 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9910 +               free_dl_info(dli);
9911 +}
9912 +
9913 +
9914 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9915 +
9916 +static inline int __dl_alloc_space(struct super_block *sb,
9917 +       tag_t tag, dlsize_t nr, const char *file, int line)
9918 +{
9919 +       struct dl_info *dli = NULL;
9920 +       int ret = 0;
9921 +
9922 +       if (nr == 0)
9923 +               goto out;
9924 +       dli = locate_dl_info(sb, tag);
9925 +       if (!dli)
9926 +               goto out;
9927 +
9928 +       spin_lock(&dli->dl_lock);
9929 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9930 +       if (!ret)
9931 +               dli->dl_space_used += nr;
9932 +       spin_unlock(&dli->dl_lock);
9933 +       put_dl_info(dli);
9934 +out:
9935 +       vxlprintk(VXD_CBIT(dlim, 1),
9936 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9937 +               sb, tag, __dlimit_char(dli), (long long)nr,
9938 +               ret, file, line);
9939 +       return ret ? -ENOSPC : 0;
9940 +}
9941 +
9942 +static inline void __dl_free_space(struct super_block *sb,
9943 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9944 +{
9945 +       struct dl_info *dli = NULL;
9946 +
9947 +       if (nr == 0)
9948 +               goto out;
9949 +       dli = locate_dl_info(sb, tag);
9950 +       if (!dli)
9951 +               goto out;
9952 +
9953 +       spin_lock(&dli->dl_lock);
9954 +       if (dli->dl_space_used > nr)
9955 +               dli->dl_space_used -= nr;
9956 +       else
9957 +               dli->dl_space_used = 0;
9958 +       spin_unlock(&dli->dl_lock);
9959 +       put_dl_info(dli);
9960 +out:
9961 +       vxlprintk(VXD_CBIT(dlim, 1),
9962 +               "FREE  (%p,#%d)%c %lld bytes",
9963 +               sb, tag, __dlimit_char(dli), (long long)nr,
9964 +               _file, _line);
9965 +}
9966 +
9967 +static inline int __dl_alloc_inode(struct super_block *sb,
9968 +       tag_t tag, const char *_file, int _line)
9969 +{
9970 +       struct dl_info *dli;
9971 +       int ret = 0;
9972 +
9973 +       dli = locate_dl_info(sb, tag);
9974 +       if (!dli)
9975 +               goto out;
9976 +
9977 +       spin_lock(&dli->dl_lock);
9978 +       dli->dl_inodes_used++;
9979 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9980 +       spin_unlock(&dli->dl_lock);
9981 +       put_dl_info(dli);
9982 +out:
9983 +       vxlprintk(VXD_CBIT(dlim, 0),
9984 +               "ALLOC (%p,#%d)%c inode (%d)",
9985 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9986 +       return ret ? -ENOSPC : 0;
9987 +}
9988 +
9989 +static inline void __dl_free_inode(struct super_block *sb,
9990 +       tag_t tag, const char *_file, int _line)
9991 +{
9992 +       struct dl_info *dli;
9993 +
9994 +       dli = locate_dl_info(sb, tag);
9995 +       if (!dli)
9996 +               goto out;
9997 +
9998 +       spin_lock(&dli->dl_lock);
9999 +       if (dli->dl_inodes_used > 1)
10000 +               dli->dl_inodes_used--;
10001 +       else
10002 +               dli->dl_inodes_used = 0;
10003 +       spin_unlock(&dli->dl_lock);
10004 +       put_dl_info(dli);
10005 +out:
10006 +       vxlprintk(VXD_CBIT(dlim, 0),
10007 +               "FREE  (%p,#%d)%c inode",
10008 +               sb, tag, __dlimit_char(dli), _file, _line);
10009 +}
10010 +
10011 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10012 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10013 +       const char *_file, int _line)
10014 +{
10015 +       struct dl_info *dli;
10016 +       uint64_t broot, bfree;
10017 +
10018 +       dli = locate_dl_info(sb, tag);
10019 +       if (!dli)
10020 +               return;
10021 +
10022 +       spin_lock(&dli->dl_lock);
10023 +       broot = (dli->dl_space_total -
10024 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10025 +               >> sb->s_blocksize_bits;
10026 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10027 +                       >> sb->s_blocksize_bits;
10028 +       spin_unlock(&dli->dl_lock);
10029 +
10030 +       vxlprintk(VXD_CBIT(dlim, 2),
10031 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10032 +               (long long)bfree, (long long)broot,
10033 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10034 +               _file, _line);
10035 +       if (free_blocks) {
10036 +               if (*free_blocks > bfree)
10037 +                       *free_blocks = bfree;
10038 +       }
10039 +       if (root_blocks) {
10040 +               if (*root_blocks > broot)
10041 +                       *root_blocks = broot;
10042 +       }
10043 +       put_dl_info(dli);
10044 +}
10045 +
10046 +#define dl_prealloc_space(in, bytes) \
10047 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10048 +               __FILE__, __LINE__ )
10049 +
10050 +#define dl_alloc_space(in, bytes) \
10051 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10052 +               __FILE__, __LINE__ )
10053 +
10054 +#define dl_reserve_space(in, bytes) \
10055 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10056 +               __FILE__, __LINE__ )
10057 +
10058 +#define dl_claim_space(in, bytes) (0)
10059 +
10060 +#define dl_release_space(in, bytes) \
10061 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10062 +               __FILE__, __LINE__ )
10063 +
10064 +#define dl_free_space(in, bytes) \
10065 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10066 +               __FILE__, __LINE__ )
10067 +
10068 +
10069 +
10070 +#define dl_alloc_inode(in) \
10071 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10072 +
10073 +#define dl_free_inode(in) \
10074 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10075 +
10076 +
10077 +#define dl_adjust_block(sb, tag, fb, rb) \
10078 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10079 +
10080 +
10081 +#else
10082 +#warning duplicate inclusion
10083 +#endif
10084 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/base.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/base.h
10085 --- linux-2.6.37/include/linux/vserver/base.h   1970-01-01 01:00:00.000000000 +0100
10086 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/base.h    2010-11-23 02:09:41.000000000 +0100
10087 @@ -0,0 +1,170 @@
10088 +#ifndef _VX_BASE_H
10089 +#define _VX_BASE_H
10090 +
10091 +
10092 +/* context state changes */
10093 +
10094 +enum {
10095 +       VSC_STARTUP = 1,
10096 +       VSC_SHUTDOWN,
10097 +
10098 +       VSC_NETUP,
10099 +       VSC_NETDOWN,
10100 +};
10101 +
10102 +
10103 +
10104 +#define vx_task_xid(t) ((t)->xid)
10105 +
10106 +#define vx_current_xid() vx_task_xid(current)
10107 +
10108 +#define current_vx_info() (current->vx_info)
10109 +
10110 +
10111 +#define nx_task_nid(t) ((t)->nid)
10112 +
10113 +#define nx_current_nid() nx_task_nid(current)
10114 +
10115 +#define current_nx_info() (current->nx_info)
10116 +
10117 +
10118 +/* generic flag merging */
10119 +
10120 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10121 +
10122 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10123 +
10124 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10125 +
10126 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10127 +
10128 +
10129 +/* context flags */
10130 +
10131 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10132 +
10133 +#define vx_current_flags()     __vx_flags(current_vx_info())
10134 +
10135 +#define vx_info_flags(v, m, f) \
10136 +       vs_check_flags(__vx_flags(v), m, f)
10137 +
10138 +#define task_vx_flags(t, m, f) \
10139 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10140 +
10141 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10142 +
10143 +
10144 +/* context caps */
10145 +
10146 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10147 +
10148 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10149 +
10150 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10151 +
10152 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10153 +
10154 +
10155 +
10156 +/* network flags */
10157 +
10158 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10159 +
10160 +#define nx_current_flags()     __nx_flags(current_nx_info())
10161 +
10162 +#define nx_info_flags(n, m, f) \
10163 +       vs_check_flags(__nx_flags(n), m, f)
10164 +
10165 +#define task_nx_flags(t, m, f) \
10166 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10167 +
10168 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10169 +
10170 +
10171 +/* network caps */
10172 +
10173 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10174 +
10175 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10176 +
10177 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10178 +
10179 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10180 +
10181 +
10182 +/* context mask capabilities */
10183 +
10184 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10185 +
10186 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10187 +
10188 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10189 +
10190 +
10191 +/* context bcap mask */
10192 +
10193 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10194 +
10195 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10196 +
10197 +
10198 +/* mask given bcaps */
10199 +
10200 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10201 +
10202 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10203 +
10204 +
10205 +/* masked cap_bset */
10206 +
10207 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10208 +
10209 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10210 +
10211 +#if 0
10212 +#define vx_info_mbcap(v, b) \
10213 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10214 +       vx_info_bcaps(v, b) : (b))
10215 +
10216 +#define task_vx_mbcap(t, b) \
10217 +       vx_info_mbcap((t)->vx_info, (t)->b)
10218 +
10219 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10220 +#endif
10221 +
10222 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10223 +
10224 +#define vx_capable(b, c) (capable(b) || \
10225 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10226 +
10227 +#define nx_capable(b, c) (capable(b) || \
10228 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10229 +
10230 +#define vx_task_initpid(t, n) \
10231 +       ((t)->vx_info && \
10232 +       ((t)->vx_info->vx_initpid == (n)))
10233 +
10234 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10235 +
10236 +
10237 +/* context unshare mask */
10238 +
10239 +#define __vx_umask(v)          ((v)->vx_umask)
10240 +
10241 +#define vx_current_umask()     __vx_umask(current_vx_info())
10242 +
10243 +#define vx_can_unshare(b, f) (capable(b) || \
10244 +       (cap_raised(current_cap(), b) && \
10245 +       !((f) & ~vx_current_umask())))
10246 +
10247 +
10248 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10249 +
10250 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10251 +
10252 +
10253 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10254 +
10255 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10256 +
10257 +#endif
10258 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cacct_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cacct_cmd.h
10259 --- linux-2.6.37/include/linux/vserver/cacct_cmd.h      1970-01-01 01:00:00.000000000 +0100
10260 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cacct_cmd.h       2010-11-23 02:09:41.000000000 +0100
10261 @@ -0,0 +1,23 @@
10262 +#ifndef _VX_CACCT_CMD_H
10263 +#define _VX_CACCT_CMD_H
10264 +
10265 +
10266 +/* virtual host info name commands */
10267 +
10268 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10269 +
10270 +struct vcmd_sock_stat_v0 {
10271 +       uint32_t field;
10272 +       uint32_t count[3];
10273 +       uint64_t total[3];
10274 +};
10275 +
10276 +
10277 +#ifdef __KERNEL__
10278 +
10279 +#include <linux/compiler.h>
10280 +
10281 +extern int vc_sock_stat(struct vx_info *, void __user *);
10282 +
10283 +#endif /* __KERNEL__ */
10284 +#endif /* _VX_CACCT_CMD_H */
10285 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cacct_def.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cacct_def.h
10286 --- linux-2.6.37/include/linux/vserver/cacct_def.h      1970-01-01 01:00:00.000000000 +0100
10287 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cacct_def.h       2010-11-23 02:09:41.000000000 +0100
10288 @@ -0,0 +1,43 @@
10289 +#ifndef _VX_CACCT_DEF_H
10290 +#define _VX_CACCT_DEF_H
10291 +
10292 +#include <asm/atomic.h>
10293 +#include <linux/vserver/cacct.h>
10294 +
10295 +
10296 +struct _vx_sock_acc {
10297 +       atomic_long_t count;
10298 +       atomic_long_t total;
10299 +};
10300 +
10301 +/* context sub struct */
10302 +
10303 +struct _vx_cacct {
10304 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10305 +       atomic_t slab[8];
10306 +       atomic_t page[6][8];
10307 +};
10308 +
10309 +#ifdef CONFIG_VSERVER_DEBUG
10310 +
10311 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10312 +{
10313 +       int i, j;
10314 +
10315 +       printk("\t_vx_cacct:");
10316 +       for (i = 0; i < 6; i++) {
10317 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10318 +
10319 +               printk("\t [%d] =", i);
10320 +               for (j = 0; j < 3; j++) {
10321 +                       printk(" [%d] = %8lu, %8lu", j,
10322 +                               atomic_long_read(&ptr[j].count),
10323 +                               atomic_long_read(&ptr[j].total));
10324 +               }
10325 +               printk("\n");
10326 +       }
10327 +}
10328 +
10329 +#endif
10330 +
10331 +#endif /* _VX_CACCT_DEF_H */
10332 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cacct.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cacct.h
10333 --- linux-2.6.37/include/linux/vserver/cacct.h  1970-01-01 01:00:00.000000000 +0100
10334 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cacct.h   2010-11-23 02:09:41.000000000 +0100
10335 @@ -0,0 +1,15 @@
10336 +#ifndef _VX_CACCT_H
10337 +#define _VX_CACCT_H
10338 +
10339 +
10340 +enum sock_acc_field {
10341 +       VXA_SOCK_UNSPEC = 0,
10342 +       VXA_SOCK_UNIX,
10343 +       VXA_SOCK_INET,
10344 +       VXA_SOCK_INET6,
10345 +       VXA_SOCK_PACKET,
10346 +       VXA_SOCK_OTHER,
10347 +       VXA_SOCK_SIZE   /* array size */
10348 +};
10349 +
10350 +#endif /* _VX_CACCT_H */
10351 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cacct_int.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cacct_int.h
10352 --- linux-2.6.37/include/linux/vserver/cacct_int.h      1970-01-01 01:00:00.000000000 +0100
10353 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cacct_int.h       2010-11-23 02:09:41.000000000 +0100
10354 @@ -0,0 +1,21 @@
10355 +#ifndef _VX_CACCT_INT_H
10356 +#define _VX_CACCT_INT_H
10357 +
10358 +
10359 +#ifdef __KERNEL__
10360 +
10361 +static inline
10362 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10363 +{
10364 +       return atomic_long_read(&cacct->sock[type][pos].count);
10365 +}
10366 +
10367 +
10368 +static inline
10369 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10370 +{
10371 +       return atomic_long_read(&cacct->sock[type][pos].total);
10372 +}
10373 +
10374 +#endif /* __KERNEL__ */
10375 +#endif /* _VX_CACCT_INT_H */
10376 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/check.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/check.h
10377 --- linux-2.6.37/include/linux/vserver/check.h  1970-01-01 01:00:00.000000000 +0100
10378 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/check.h   2010-11-23 02:09:41.000000000 +0100
10379 @@ -0,0 +1,89 @@
10380 +#ifndef _VS_CHECK_H
10381 +#define _VS_CHECK_H
10382 +
10383 +
10384 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10385 +
10386 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10387 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10388 +#else
10389 +#define MIN_D_CONTEXT  65536
10390 +#endif
10391 +
10392 +/* check conditions */
10393 +
10394 +#define VS_ADMIN       0x0001
10395 +#define VS_WATCH       0x0002
10396 +#define VS_HIDE                0x0004
10397 +#define VS_HOSTID      0x0008
10398 +
10399 +#define VS_IDENT       0x0010
10400 +#define VS_EQUIV       0x0020
10401 +#define VS_PARENT      0x0040
10402 +#define VS_CHILD       0x0080
10403 +
10404 +#define VS_ARG_MASK    0x00F0
10405 +
10406 +#define VS_DYNAMIC     0x0100
10407 +#define VS_STATIC      0x0200
10408 +
10409 +#define VS_ATR_MASK    0x0F00
10410 +
10411 +#ifdef CONFIG_VSERVER_PRIVACY
10412 +#define VS_ADMIN_P     (0)
10413 +#define VS_WATCH_P     (0)
10414 +#else
10415 +#define VS_ADMIN_P     VS_ADMIN
10416 +#define VS_WATCH_P     VS_WATCH
10417 +#endif
10418 +
10419 +#define VS_HARDIRQ     0x1000
10420 +#define VS_SOFTIRQ     0x2000
10421 +#define VS_IRQ         0x4000
10422 +
10423 +#define VS_IRQ_MASK    0xF000
10424 +
10425 +#include <linux/hardirq.h>
10426 +
10427 +/*
10428 + * check current context for ADMIN/WATCH and
10429 + * optionally against supplied argument
10430 + */
10431 +static inline int __vs_check(int cid, int id, unsigned int mode)
10432 +{
10433 +       if (mode & VS_ARG_MASK) {
10434 +               if ((mode & VS_IDENT) && (id == cid))
10435 +                       return 1;
10436 +       }
10437 +       if (mode & VS_ATR_MASK) {
10438 +               if ((mode & VS_DYNAMIC) &&
10439 +                       (id >= MIN_D_CONTEXT) &&
10440 +                       (id <= MAX_S_CONTEXT))
10441 +                       return 1;
10442 +               if ((mode & VS_STATIC) &&
10443 +                       (id > 1) && (id < MIN_D_CONTEXT))
10444 +                       return 1;
10445 +       }
10446 +       if (mode & VS_IRQ_MASK) {
10447 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10448 +                       return 1;
10449 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10450 +                       return 1;
10451 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10452 +                       return 1;
10453 +       }
10454 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10455 +               ((mode & VS_WATCH) && (cid == 1)) ||
10456 +               ((mode & VS_HOSTID) && (id == 0)));
10457 +}
10458 +
10459 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10460 +
10461 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10462 +
10463 +
10464 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10465 +
10466 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10467 +
10468 +#endif
10469 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/context_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/context_cmd.h
10470 --- linux-2.6.37/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
10471 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/context_cmd.h     2010-11-23 02:09:41.000000000 +0100
10472 @@ -0,0 +1,145 @@
10473 +#ifndef _VX_CONTEXT_CMD_H
10474 +#define _VX_CONTEXT_CMD_H
10475 +
10476 +
10477 +/* vinfo commands */
10478 +
10479 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10480 +
10481 +#ifdef __KERNEL__
10482 +extern int vc_task_xid(uint32_t);
10483 +
10484 +#endif /* __KERNEL__ */
10485 +
10486 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10487 +
10488 +struct vcmd_vx_info_v0 {
10489 +       uint32_t xid;
10490 +       uint32_t initpid;
10491 +       /* more to come */
10492 +};
10493 +
10494 +#ifdef __KERNEL__
10495 +extern int vc_vx_info(struct vx_info *, void __user *);
10496 +
10497 +#endif /* __KERNEL__ */
10498 +
10499 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10500 +
10501 +struct vcmd_ctx_stat_v0 {
10502 +       uint32_t usecnt;
10503 +       uint32_t tasks;
10504 +       /* more to come */
10505 +};
10506 +
10507 +#ifdef __KERNEL__
10508 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10509 +
10510 +#endif /* __KERNEL__ */
10511 +
10512 +/* context commands */
10513 +
10514 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10515 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10516 +
10517 +struct vcmd_ctx_create {
10518 +       uint64_t flagword;
10519 +};
10520 +
10521 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10522 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10523 +
10524 +struct vcmd_ctx_migrate {
10525 +       uint64_t flagword;
10526 +};
10527 +
10528 +#ifdef __KERNEL__
10529 +extern int vc_ctx_create(uint32_t, void __user *);
10530 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10531 +
10532 +#endif /* __KERNEL__ */
10533 +
10534 +
10535 +/* flag commands */
10536 +
10537 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10538 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10539 +
10540 +struct vcmd_ctx_flags_v0 {
10541 +       uint64_t flagword;
10542 +       uint64_t mask;
10543 +};
10544 +
10545 +#ifdef __KERNEL__
10546 +extern int vc_get_cflags(struct vx_info *, void __user *);
10547 +extern int vc_set_cflags(struct vx_info *, void __user *);
10548 +
10549 +#endif /* __KERNEL__ */
10550 +
10551 +
10552 +/* context caps commands */
10553 +
10554 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10555 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10556 +
10557 +struct vcmd_ctx_caps_v1 {
10558 +       uint64_t ccaps;
10559 +       uint64_t cmask;
10560 +};
10561 +
10562 +#ifdef __KERNEL__
10563 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10564 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10565 +
10566 +#endif /* __KERNEL__ */
10567 +
10568 +
10569 +/* bcaps commands */
10570 +
10571 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10572 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10573 +
10574 +struct vcmd_bcaps {
10575 +       uint64_t bcaps;
10576 +       uint64_t bmask;
10577 +};
10578 +
10579 +#ifdef __KERNEL__
10580 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10581 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10582 +
10583 +#endif /* __KERNEL__ */
10584 +
10585 +
10586 +/* umask commands */
10587 +
10588 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10589 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10590 +
10591 +struct vcmd_umask {
10592 +       uint64_t umask;
10593 +       uint64_t mask;
10594 +};
10595 +
10596 +#ifdef __KERNEL__
10597 +extern int vc_get_umask(struct vx_info *, void __user *);
10598 +extern int vc_set_umask(struct vx_info *, void __user *);
10599 +
10600 +#endif /* __KERNEL__ */
10601 +
10602 +
10603 +/* OOM badness */
10604 +
10605 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10606 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10607 +
10608 +struct vcmd_badness_v0 {
10609 +       int64_t bias;
10610 +};
10611 +
10612 +#ifdef __KERNEL__
10613 +extern int vc_get_badness(struct vx_info *, void __user *);
10614 +extern int vc_set_badness(struct vx_info *, void __user *);
10615 +
10616 +#endif /* __KERNEL__ */
10617 +#endif /* _VX_CONTEXT_CMD_H */
10618 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/context.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/context.h
10619 --- linux-2.6.37/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
10620 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/context.h 2011-01-08 03:34:09.000000000 +0100
10621 @@ -0,0 +1,190 @@
10622 +#ifndef _VX_CONTEXT_H
10623 +#define _VX_CONTEXT_H
10624 +
10625 +#include <linux/types.h>
10626 +#include <linux/capability.h>
10627 +
10628 +
10629 +/* context flags */
10630 +
10631 +#define VXF_INFO_SCHED         0x00000002
10632 +#define VXF_INFO_NPROC         0x00000004
10633 +#define VXF_INFO_PRIVATE       0x00000008
10634 +
10635 +#define VXF_INFO_INIT          0x00000010
10636 +#define VXF_INFO_HIDE          0x00000020
10637 +#define VXF_INFO_ULIMIT                0x00000040
10638 +#define VXF_INFO_NSPACE                0x00000080
10639 +
10640 +#define VXF_SCHED_HARD         0x00000100
10641 +#define VXF_SCHED_PRIO         0x00000200
10642 +#define VXF_SCHED_PAUSE                0x00000400
10643 +
10644 +#define VXF_VIRT_MEM           0x00010000
10645 +#define VXF_VIRT_UPTIME                0x00020000
10646 +#define VXF_VIRT_CPU           0x00040000
10647 +#define VXF_VIRT_LOAD          0x00080000
10648 +#define VXF_VIRT_TIME          0x00100000
10649 +
10650 +#define VXF_HIDE_MOUNT         0x01000000
10651 +/* was VXF_HIDE_NETIF          0x02000000 */
10652 +#define VXF_HIDE_VINFO         0x04000000
10653 +
10654 +#define VXF_STATE_SETUP                (1ULL << 32)
10655 +#define VXF_STATE_INIT         (1ULL << 33)
10656 +#define VXF_STATE_ADMIN                (1ULL << 34)
10657 +
10658 +#define VXF_SC_HELPER          (1ULL << 36)
10659 +#define VXF_REBOOT_KILL                (1ULL << 37)
10660 +#define VXF_PERSISTENT         (1ULL << 38)
10661 +
10662 +#define VXF_FORK_RSS           (1ULL << 48)
10663 +#define VXF_PROLIFIC           (1ULL << 49)
10664 +
10665 +#define VXF_IGNEG_NICE         (1ULL << 52)
10666 +
10667 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10668 +
10669 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10670 +
10671 +
10672 +/* context migration */
10673 +
10674 +#define VXM_SET_INIT           0x00000001
10675 +#define VXM_SET_REAPER         0x00000002
10676 +
10677 +/* context caps */
10678 +
10679 +#define VXC_CAP_MASK           0x00000000
10680 +
10681 +#define VXC_SET_UTSNAME                0x00000001
10682 +#define VXC_SET_RLIMIT         0x00000002
10683 +#define VXC_FS_SECURITY                0x00000004
10684 +#define VXC_FS_TRUSTED         0x00000008
10685 +#define VXC_TIOCSTI            0x00000010
10686 +
10687 +/* was VXC_RAW_ICMP            0x00000100 */
10688 +#define VXC_SYSLOG             0x00001000
10689 +#define VXC_OOM_ADJUST         0x00002000
10690 +#define VXC_AUDIT_CONTROL      0x00004000
10691 +
10692 +#define VXC_SECURE_MOUNT       0x00010000
10693 +#define VXC_SECURE_REMOUNT     0x00020000
10694 +#define VXC_BINARY_MOUNT       0x00040000
10695 +
10696 +#define VXC_QUOTA_CTL          0x00100000
10697 +#define VXC_ADMIN_MAPPER       0x00200000
10698 +#define VXC_ADMIN_CLOOP                0x00400000
10699 +
10700 +#define VXC_KTHREAD            0x01000000
10701 +#define VXC_NAMESPACE          0x02000000
10702 +
10703 +
10704 +#ifdef __KERNEL__
10705 +
10706 +#include <linux/list.h>
10707 +#include <linux/spinlock.h>
10708 +#include <linux/rcupdate.h>
10709 +
10710 +#include "limit_def.h"
10711 +#include "sched_def.h"
10712 +#include "cvirt_def.h"
10713 +#include "cacct_def.h"
10714 +#include "device_def.h"
10715 +
10716 +#define VX_SPACES      2
10717 +
10718 +struct _vx_info_pc {
10719 +       struct _vx_sched_pc sched_pc;
10720 +       struct _vx_cvirt_pc cvirt_pc;
10721 +};
10722 +
10723 +struct _vx_space {
10724 +       unsigned long vx_nsmask;                /* assignment mask */
10725 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10726 +       struct fs_struct *vx_fs;                /* private namespace fs */
10727 +//     const struct cred *vx_real_cred;        /* real task credentials */
10728 +//     const struct cred *vx_cred;             /* task credentials */
10729 +};
10730 +
10731 +struct vx_info {
10732 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10733 +       xid_t vx_id;                            /* context id */
10734 +       atomic_t vx_usecnt;                     /* usage count */
10735 +       atomic_t vx_tasks;                      /* tasks count */
10736 +       struct vx_info *vx_parent;              /* parent context */
10737 +       int vx_state;                           /* context state */
10738 +
10739 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10740 +
10741 +       uint64_t vx_flags;                      /* context flags */
10742 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10743 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10744 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10745 +
10746 +       struct task_struct *vx_reaper;          /* guest reaper process */
10747 +       pid_t vx_initpid;                       /* PID of guest init */
10748 +       int64_t vx_badness_bias;                /* OOM points bias */
10749 +
10750 +       struct _vx_limit limit;                 /* vserver limits */
10751 +       struct _vx_sched sched;                 /* vserver scheduler */
10752 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10753 +       struct _vx_cacct cacct;                 /* context accounting */
10754 +
10755 +       struct _vx_device dmap;                 /* default device map targets */
10756 +
10757 +#ifndef CONFIG_SMP
10758 +       struct _vx_info_pc info_pc;             /* per cpu data */
10759 +#else
10760 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10761 +#endif
10762 +
10763 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10764 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10765 +       int exit_code;                          /* last process exit code */
10766 +
10767 +       char vx_name[65];                       /* vserver name */
10768 +};
10769 +
10770 +#ifndef CONFIG_SMP
10771 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10772 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10773 +#else
10774 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10775 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10776 +#endif
10777 +
10778 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10779 +
10780 +
10781 +struct vx_info_save {
10782 +       struct vx_info *vxi;
10783 +       xid_t xid;
10784 +};
10785 +
10786 +
10787 +/* status flags */
10788 +
10789 +#define VXS_HASHED     0x0001
10790 +#define VXS_PAUSED     0x0010
10791 +#define VXS_SHUTDOWN   0x0100
10792 +#define VXS_HELPER     0x1000
10793 +#define VXS_RELEASED   0x8000
10794 +
10795 +
10796 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10797 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10798 +
10799 +extern struct vx_info *lookup_vx_info(int);
10800 +extern struct vx_info *lookup_or_create_vx_info(int);
10801 +
10802 +extern int get_xid_list(int, unsigned int *, int);
10803 +extern int xid_is_hashed(xid_t);
10804 +
10805 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10806 +
10807 +extern long vs_state_change(struct vx_info *, unsigned int);
10808 +
10809 +
10810 +#endif /* __KERNEL__ */
10811 +#endif /* _VX_CONTEXT_H */
10812 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cvirt_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cvirt_cmd.h
10813 --- linux-2.6.37/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
10814 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cvirt_cmd.h       2010-11-23 02:09:41.000000000 +0100
10815 @@ -0,0 +1,53 @@
10816 +#ifndef _VX_CVIRT_CMD_H
10817 +#define _VX_CVIRT_CMD_H
10818 +
10819 +
10820 +/* virtual host info name commands */
10821 +
10822 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10823 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10824 +
10825 +struct vcmd_vhi_name_v0 {
10826 +       uint32_t field;
10827 +       char name[65];
10828 +};
10829 +
10830 +
10831 +enum vhi_name_field {
10832 +       VHIN_CONTEXT = 0,
10833 +       VHIN_SYSNAME,
10834 +       VHIN_NODENAME,
10835 +       VHIN_RELEASE,
10836 +       VHIN_VERSION,
10837 +       VHIN_MACHINE,
10838 +       VHIN_DOMAINNAME,
10839 +};
10840 +
10841 +
10842 +#ifdef __KERNEL__
10843 +
10844 +#include <linux/compiler.h>
10845 +
10846 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10847 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10848 +
10849 +#endif /* __KERNEL__ */
10850 +
10851 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10852 +
10853 +struct vcmd_virt_stat_v0 {
10854 +       uint64_t offset;
10855 +       uint64_t uptime;
10856 +       uint32_t nr_threads;
10857 +       uint32_t nr_running;
10858 +       uint32_t nr_uninterruptible;
10859 +       uint32_t nr_onhold;
10860 +       uint32_t nr_forks;
10861 +       uint32_t load[3];
10862 +};
10863 +
10864 +#ifdef __KERNEL__
10865 +extern int vc_virt_stat(struct vx_info *, void __user *);
10866 +
10867 +#endif /* __KERNEL__ */
10868 +#endif /* _VX_CVIRT_CMD_H */
10869 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cvirt_def.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cvirt_def.h
10870 --- linux-2.6.37/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
10871 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cvirt_def.h       2010-11-23 02:09:41.000000000 +0100
10872 @@ -0,0 +1,80 @@
10873 +#ifndef _VX_CVIRT_DEF_H
10874 +#define _VX_CVIRT_DEF_H
10875 +
10876 +#include <linux/jiffies.h>
10877 +#include <linux/spinlock.h>
10878 +#include <linux/wait.h>
10879 +#include <linux/time.h>
10880 +#include <asm/atomic.h>
10881 +
10882 +
10883 +struct _vx_usage_stat {
10884 +       uint64_t user;
10885 +       uint64_t nice;
10886 +       uint64_t system;
10887 +       uint64_t softirq;
10888 +       uint64_t irq;
10889 +       uint64_t idle;
10890 +       uint64_t iowait;
10891 +};
10892 +
10893 +struct _vx_syslog {
10894 +       wait_queue_head_t log_wait;
10895 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10896 +
10897 +       unsigned long log_start;        /* next char to be read by syslog() */
10898 +       unsigned long con_start;        /* next char to be sent to consoles */
10899 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10900 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10901 +
10902 +       char log_buf[1024];
10903 +};
10904 +
10905 +
10906 +/* context sub struct */
10907 +
10908 +struct _vx_cvirt {
10909 +       atomic_t nr_threads;            /* number of current threads */
10910 +       atomic_t nr_running;            /* number of running threads */
10911 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10912 +
10913 +       atomic_t nr_onhold;             /* processes on hold */
10914 +       uint32_t onhold_last;           /* jiffies when put on hold */
10915 +
10916 +       struct timespec bias_ts;        /* time offset to the host */
10917 +       struct timespec bias_idle;
10918 +       struct timespec bias_uptime;    /* context creation point */
10919 +       uint64_t bias_clock;            /* offset in clock_t */
10920 +
10921 +       spinlock_t load_lock;           /* lock for the load averages */
10922 +       atomic_t load_updates;          /* nr of load updates done so far */
10923 +       uint32_t load_last;             /* last time load was calculated */
10924 +       uint32_t load[3];               /* load averages 1,5,15 */
10925 +
10926 +       atomic_t total_forks;           /* number of forks so far */
10927 +
10928 +       struct _vx_syslog syslog;
10929 +};
10930 +
10931 +struct _vx_cvirt_pc {
10932 +       struct _vx_usage_stat cpustat;
10933 +};
10934 +
10935 +
10936 +#ifdef CONFIG_VSERVER_DEBUG
10937 +
10938 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10939 +{
10940 +       printk("\t_vx_cvirt:\n");
10941 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10942 +               atomic_read(&cvirt->nr_threads),
10943 +               atomic_read(&cvirt->nr_running),
10944 +               atomic_read(&cvirt->nr_uninterruptible),
10945 +               atomic_read(&cvirt->nr_onhold));
10946 +       /* add rest here */
10947 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10948 +}
10949 +
10950 +#endif
10951 +
10952 +#endif /* _VX_CVIRT_DEF_H */
10953 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/cvirt.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cvirt.h
10954 --- linux-2.6.37/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
10955 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/cvirt.h   2010-11-23 02:09:41.000000000 +0100
10956 @@ -0,0 +1,20 @@
10957 +#ifndef _VX_CVIRT_H
10958 +#define _VX_CVIRT_H
10959 +
10960 +
10961 +#ifdef __KERNEL__
10962 +
10963 +struct timespec;
10964 +
10965 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10966 +
10967 +
10968 +struct vx_info;
10969 +
10970 +void vx_update_load(struct vx_info *);
10971 +
10972 +
10973 +int vx_do_syslog(int, char __user *, int);
10974 +
10975 +#endif /* __KERNEL__ */
10976 +#endif /* _VX_CVIRT_H */
10977 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/debug_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/debug_cmd.h
10978 --- linux-2.6.37/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
10979 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/debug_cmd.h       2010-11-23 02:09:41.000000000 +0100
10980 @@ -0,0 +1,58 @@
10981 +#ifndef _VX_DEBUG_CMD_H
10982 +#define _VX_DEBUG_CMD_H
10983 +
10984 +
10985 +/* debug commands */
10986 +
10987 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
10988 +
10989 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
10990 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
10991 +
10992 +struct  vcmd_read_history_v0 {
10993 +       uint32_t index;
10994 +       uint32_t count;
10995 +       char __user *data;
10996 +};
10997 +
10998 +struct  vcmd_read_monitor_v0 {
10999 +       uint32_t index;
11000 +       uint32_t count;
11001 +       char __user *data;
11002 +};
11003 +
11004 +
11005 +#ifdef __KERNEL__
11006 +
11007 +#ifdef CONFIG_COMPAT
11008 +
11009 +#include <asm/compat.h>
11010 +
11011 +struct vcmd_read_history_v0_x32 {
11012 +       uint32_t index;
11013 +       uint32_t count;
11014 +       compat_uptr_t data_ptr;
11015 +};
11016 +
11017 +struct vcmd_read_monitor_v0_x32 {
11018 +       uint32_t index;
11019 +       uint32_t count;
11020 +       compat_uptr_t data_ptr;
11021 +};
11022 +
11023 +#endif  /* CONFIG_COMPAT */
11024 +
11025 +extern int vc_dump_history(uint32_t);
11026 +
11027 +extern int vc_read_history(uint32_t, void __user *);
11028 +extern int vc_read_monitor(uint32_t, void __user *);
11029 +
11030 +#ifdef CONFIG_COMPAT
11031 +
11032 +extern int vc_read_history_x32(uint32_t, void __user *);
11033 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11034 +
11035 +#endif  /* CONFIG_COMPAT */
11036 +
11037 +#endif /* __KERNEL__ */
11038 +#endif /* _VX_DEBUG_CMD_H */
11039 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/debug.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/debug.h
11040 --- linux-2.6.37/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
11041 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/debug.h   2010-11-23 02:09:41.000000000 +0100
11042 @@ -0,0 +1,140 @@
11043 +#ifndef _VX_DEBUG_H
11044 +#define _VX_DEBUG_H
11045 +
11046 +
11047 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11048 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11049 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11050 +
11051 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11052 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11053 +#define VXF_DEV                "%p[%lu,%d:%d]"
11054 +
11055 +#if    defined(CONFIG_QUOTES_UTF8)
11056 +#define        VS_Q_LQM        "\xc2\xbb"
11057 +#define        VS_Q_RQM        "\xc2\xab"
11058 +#elif  defined(CONFIG_QUOTES_ASCII)
11059 +#define        VS_Q_LQM        "\x27"
11060 +#define        VS_Q_RQM        "\x27"
11061 +#else
11062 +#define        VS_Q_LQM        "\xbb"
11063 +#define        VS_Q_RQM        "\xab"
11064 +#endif
11065 +
11066 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11067 +
11068 +
11069 +#define vxd_path(p)                                            \
11070 +       ({ static char _buffer[PATH_MAX];                       \
11071 +          d_path(p, _buffer, sizeof(_buffer)); })
11072 +
11073 +#define vxd_cond_path(n)                                       \
11074 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11075 +
11076 +
11077 +#ifdef CONFIG_VSERVER_DEBUG
11078 +
11079 +extern unsigned int vx_debug_switch;
11080 +extern unsigned int vx_debug_xid;
11081 +extern unsigned int vx_debug_nid;
11082 +extern unsigned int vx_debug_tag;
11083 +extern unsigned int vx_debug_net;
11084 +extern unsigned int vx_debug_limit;
11085 +extern unsigned int vx_debug_cres;
11086 +extern unsigned int vx_debug_dlim;
11087 +extern unsigned int vx_debug_quota;
11088 +extern unsigned int vx_debug_cvirt;
11089 +extern unsigned int vx_debug_space;
11090 +extern unsigned int vx_debug_misc;
11091 +
11092 +
11093 +#define VX_LOGLEVEL    "vxD: "
11094 +#define VX_PROC_FMT    "%p: "
11095 +#define VX_PROCESS     current
11096 +
11097 +#define vxdprintk(c, f, x...)                                  \
11098 +       do {                                                    \
11099 +               if (c)                                          \
11100 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11101 +                               VX_PROCESS , ##x);              \
11102 +       } while (0)
11103 +
11104 +#define vxlprintk(c, f, x...)                                  \
11105 +       do {                                                    \
11106 +               if (c)                                          \
11107 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11108 +       } while (0)
11109 +
11110 +#define vxfprintk(c, f, x...)                                  \
11111 +       do {                                                    \
11112 +               if (c)                                          \
11113 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11114 +       } while (0)
11115 +
11116 +
11117 +struct vx_info;
11118 +
11119 +void dump_vx_info(struct vx_info *, int);
11120 +void dump_vx_info_inactive(int);
11121 +
11122 +#else  /* CONFIG_VSERVER_DEBUG */
11123 +
11124 +#define vx_debug_switch 0
11125 +#define vx_debug_xid   0
11126 +#define vx_debug_nid   0
11127 +#define vx_debug_tag   0
11128 +#define vx_debug_net   0
11129 +#define vx_debug_limit 0
11130 +#define vx_debug_cres  0
11131 +#define vx_debug_dlim  0
11132 +#define vx_debug_cvirt 0
11133 +
11134 +#define vxdprintk(x...) do { } while (0)
11135 +#define vxlprintk(x...) do { } while (0)
11136 +#define vxfprintk(x...) do { } while (0)
11137 +
11138 +#endif /* CONFIG_VSERVER_DEBUG */
11139 +
11140 +
11141 +#ifdef CONFIG_VSERVER_WARN
11142 +
11143 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11144 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11145 +#define VX_WARN_XID    "[xid #%u] "
11146 +#define VX_WARN_NID    "[nid #%u] "
11147 +#define VX_WARN_TAG    "[tag #%u] "
11148 +
11149 +#define vxwprintk(c, f, x...)                                  \
11150 +       do {                                                    \
11151 +               if (c)                                          \
11152 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11153 +       } while (0)
11154 +
11155 +#else  /* CONFIG_VSERVER_WARN */
11156 +
11157 +#define vxwprintk(x...) do { } while (0)
11158 +
11159 +#endif /* CONFIG_VSERVER_WARN */
11160 +
11161 +#define vxwprintk_task(c, f, x...)                             \
11162 +       vxwprintk(c, VX_WARN_TASK f,                            \
11163 +               current->comm, current->pid,                    \
11164 +               current->xid, current->nid, current->tag, ##x)
11165 +#define vxwprintk_xid(c, f, x...)                              \
11166 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11167 +#define vxwprintk_nid(c, f, x...)                              \
11168 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11169 +#define vxwprintk_tag(c, f, x...)                              \
11170 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11171 +
11172 +#ifdef CONFIG_VSERVER_DEBUG
11173 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11174 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11175 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11176 +#else
11177 +#define vxd_assert_lock(l)     do { } while (0)
11178 +#define vxd_assert(c, f, x...) do { } while (0)
11179 +#endif
11180 +
11181 +
11182 +#endif /* _VX_DEBUG_H */
11183 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/device_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/device_cmd.h
11184 --- linux-2.6.37/include/linux/vserver/device_cmd.h     1970-01-01 01:00:00.000000000 +0100
11185 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/device_cmd.h      2010-11-23 02:09:41.000000000 +0100
11186 @@ -0,0 +1,44 @@
11187 +#ifndef _VX_DEVICE_CMD_H
11188 +#define _VX_DEVICE_CMD_H
11189 +
11190 +
11191 +/*  device vserver commands */
11192 +
11193 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11194 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11195 +
11196 +struct vcmd_set_mapping_v0 {
11197 +       const char __user *device;
11198 +       const char __user *target;
11199 +       uint32_t flags;
11200 +};
11201 +
11202 +
11203 +#ifdef __KERNEL__
11204 +
11205 +#ifdef CONFIG_COMPAT
11206 +
11207 +#include <asm/compat.h>
11208 +
11209 +struct vcmd_set_mapping_v0_x32 {
11210 +       compat_uptr_t device_ptr;
11211 +       compat_uptr_t target_ptr;
11212 +       uint32_t flags;
11213 +};
11214 +
11215 +#endif /* CONFIG_COMPAT */
11216 +
11217 +#include <linux/compiler.h>
11218 +
11219 +extern int vc_set_mapping(struct vx_info *, void __user *);
11220 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11221 +
11222 +#ifdef CONFIG_COMPAT
11223 +
11224 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11225 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11226 +
11227 +#endif /* CONFIG_COMPAT */
11228 +
11229 +#endif /* __KERNEL__ */
11230 +#endif /* _VX_DEVICE_CMD_H */
11231 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/device_def.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/device_def.h
11232 --- linux-2.6.37/include/linux/vserver/device_def.h     1970-01-01 01:00:00.000000000 +0100
11233 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/device_def.h      2010-11-23 02:09:41.000000000 +0100
11234 @@ -0,0 +1,17 @@
11235 +#ifndef _VX_DEVICE_DEF_H
11236 +#define _VX_DEVICE_DEF_H
11237 +
11238 +#include <linux/types.h>
11239 +
11240 +struct vx_dmap_target {
11241 +       dev_t target;
11242 +       uint32_t flags;
11243 +};
11244 +
11245 +struct _vx_device {
11246 +#ifdef CONFIG_VSERVER_DEVICE
11247 +       struct vx_dmap_target targets[2];
11248 +#endif
11249 +};
11250 +
11251 +#endif /* _VX_DEVICE_DEF_H */
11252 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/device.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/device.h
11253 --- linux-2.6.37/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
11254 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/device.h  2010-11-23 02:09:41.000000000 +0100
11255 @@ -0,0 +1,15 @@
11256 +#ifndef _VX_DEVICE_H
11257 +#define _VX_DEVICE_H
11258 +
11259 +
11260 +#define DATTR_CREATE   0x00000001
11261 +#define DATTR_OPEN     0x00000002
11262 +
11263 +#define DATTR_REMAP    0x00000010
11264 +
11265 +#define DATTR_MASK     0x00000013
11266 +
11267 +
11268 +#else  /* _VX_DEVICE_H */
11269 +#warning duplicate inclusion
11270 +#endif /* _VX_DEVICE_H */
11271 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/dlimit_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/dlimit_cmd.h
11272 --- linux-2.6.37/include/linux/vserver/dlimit_cmd.h     1970-01-01 01:00:00.000000000 +0100
11273 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/dlimit_cmd.h      2010-11-23 02:09:41.000000000 +0100
11274 @@ -0,0 +1,109 @@
11275 +#ifndef _VX_DLIMIT_CMD_H
11276 +#define _VX_DLIMIT_CMD_H
11277 +
11278 +
11279 +/*  dlimit vserver commands */
11280 +
11281 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11282 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11283 +
11284 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11285 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11286 +
11287 +struct vcmd_ctx_dlimit_base_v0 {
11288 +       const char __user *name;
11289 +       uint32_t flags;
11290 +};
11291 +
11292 +struct vcmd_ctx_dlimit_v0 {
11293 +       const char __user *name;
11294 +       uint32_t space_used;                    /* used space in kbytes */
11295 +       uint32_t space_total;                   /* maximum space in kbytes */
11296 +       uint32_t inodes_used;                   /* used inodes */
11297 +       uint32_t inodes_total;                  /* maximum inodes */
11298 +       uint32_t reserved;                      /* reserved for root in % */
11299 +       uint32_t flags;
11300 +};
11301 +
11302 +#define CDLIM_UNSET            ((uint32_t)0UL)
11303 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11304 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11305 +
11306 +#define DLIME_UNIT     0
11307 +#define DLIME_KILO     1
11308 +#define DLIME_MEGA     2
11309 +#define DLIME_GIGA     3
11310 +
11311 +#define DLIMF_SHIFT    0x10
11312 +
11313 +#define DLIMS_USED     0
11314 +#define DLIMS_TOTAL    2
11315 +
11316 +static inline
11317 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11318 +{
11319 +       int exp = (flags & DLIMF_SHIFT) ?
11320 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11321 +       return ((uint64_t)val) << (10 * exp);
11322 +}
11323 +
11324 +static inline
11325 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11326 +{
11327 +       int exp = 0;
11328 +
11329 +       if (*flags & DLIMF_SHIFT) {
11330 +               while (val > (1LL << 32) && (exp < 3)) {
11331 +                       val >>= 10;
11332 +                       exp++;
11333 +               }
11334 +               *flags &= ~(DLIME_GIGA << shift);
11335 +               *flags |= exp << shift;
11336 +       } else
11337 +               val >>= 10;
11338 +       return val;
11339 +}
11340 +
11341 +#ifdef __KERNEL__
11342 +
11343 +#ifdef CONFIG_COMPAT
11344 +
11345 +#include <asm/compat.h>
11346 +
11347 +struct vcmd_ctx_dlimit_base_v0_x32 {
11348 +       compat_uptr_t name_ptr;
11349 +       uint32_t flags;
11350 +};
11351 +
11352 +struct vcmd_ctx_dlimit_v0_x32 {
11353 +       compat_uptr_t name_ptr;
11354 +       uint32_t space_used;                    /* used space in kbytes */
11355 +       uint32_t space_total;                   /* maximum space in kbytes */
11356 +       uint32_t inodes_used;                   /* used inodes */
11357 +       uint32_t inodes_total;                  /* maximum inodes */
11358 +       uint32_t reserved;                      /* reserved for root in % */
11359 +       uint32_t flags;
11360 +};
11361 +
11362 +#endif /* CONFIG_COMPAT */
11363 +
11364 +#include <linux/compiler.h>
11365 +
11366 +extern int vc_add_dlimit(uint32_t, void __user *);
11367 +extern int vc_rem_dlimit(uint32_t, void __user *);
11368 +
11369 +extern int vc_set_dlimit(uint32_t, void __user *);
11370 +extern int vc_get_dlimit(uint32_t, void __user *);
11371 +
11372 +#ifdef CONFIG_COMPAT
11373 +
11374 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11375 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11376 +
11377 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11378 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11379 +
11380 +#endif /* CONFIG_COMPAT */
11381 +
11382 +#endif /* __KERNEL__ */
11383 +#endif /* _VX_DLIMIT_CMD_H */
11384 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/dlimit.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/dlimit.h
11385 --- linux-2.6.37/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
11386 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/dlimit.h  2010-11-23 02:09:41.000000000 +0100
11387 @@ -0,0 +1,54 @@
11388 +#ifndef _VX_DLIMIT_H
11389 +#define _VX_DLIMIT_H
11390 +
11391 +#include "switch.h"
11392 +
11393 +
11394 +#ifdef __KERNEL__
11395 +
11396 +/*      keep in sync with CDLIM_INFINITY       */
11397 +
11398 +#define DLIM_INFINITY          (~0ULL)
11399 +
11400 +#include <linux/spinlock.h>
11401 +#include <linux/rcupdate.h>
11402 +
11403 +struct super_block;
11404 +
11405 +struct dl_info {
11406 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11407 +       struct rcu_head dl_rcu;                 /* the rcu head */
11408 +       tag_t dl_tag;                           /* context tag */
11409 +       atomic_t dl_usecnt;                     /* usage count */
11410 +       atomic_t dl_refcnt;                     /* reference count */
11411 +
11412 +       struct super_block *dl_sb;              /* associated superblock */
11413 +
11414 +       spinlock_t dl_lock;                     /* protect the values */
11415 +
11416 +       unsigned long long dl_space_used;       /* used space in bytes */
11417 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11418 +       unsigned long dl_inodes_used;           /* used inodes */
11419 +       unsigned long dl_inodes_total;          /* maximum inodes */
11420 +
11421 +       unsigned int dl_nrlmult;                /* non root limit mult */
11422 +};
11423 +
11424 +struct rcu_head;
11425 +
11426 +extern void rcu_free_dl_info(struct rcu_head *);
11427 +extern void unhash_dl_info(struct dl_info *);
11428 +
11429 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11430 +
11431 +
11432 +struct kstatfs;
11433 +
11434 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11435 +
11436 +typedef uint64_t dlsize_t;
11437 +
11438 +#endif /* __KERNEL__ */
11439 +#else  /* _VX_DLIMIT_H */
11440 +#warning duplicate inclusion
11441 +#endif /* _VX_DLIMIT_H */
11442 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/global.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/global.h
11443 --- linux-2.6.37/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
11444 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/global.h  2010-11-23 02:09:41.000000000 +0100
11445 @@ -0,0 +1,19 @@
11446 +#ifndef _VX_GLOBAL_H
11447 +#define _VX_GLOBAL_H
11448 +
11449 +
11450 +extern atomic_t vx_global_ctotal;
11451 +extern atomic_t vx_global_cactive;
11452 +
11453 +extern atomic_t nx_global_ctotal;
11454 +extern atomic_t nx_global_cactive;
11455 +
11456 +extern atomic_t vs_global_nsproxy;
11457 +extern atomic_t vs_global_fs;
11458 +extern atomic_t vs_global_mnt_ns;
11459 +extern atomic_t vs_global_uts_ns;
11460 +extern atomic_t vs_global_user_ns;
11461 +extern atomic_t vs_global_pid_ns;
11462 +
11463 +
11464 +#endif /* _VX_GLOBAL_H */
11465 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/history.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/history.h
11466 --- linux-2.6.37/include/linux/vserver/history.h        1970-01-01 01:00:00.000000000 +0100
11467 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/history.h 2010-11-23 02:09:41.000000000 +0100
11468 @@ -0,0 +1,197 @@
11469 +#ifndef _VX_HISTORY_H
11470 +#define _VX_HISTORY_H
11471 +
11472 +
11473 +enum {
11474 +       VXH_UNUSED = 0,
11475 +       VXH_THROW_OOPS = 1,
11476 +
11477 +       VXH_GET_VX_INFO,
11478 +       VXH_PUT_VX_INFO,
11479 +       VXH_INIT_VX_INFO,
11480 +       VXH_SET_VX_INFO,
11481 +       VXH_CLR_VX_INFO,
11482 +       VXH_CLAIM_VX_INFO,
11483 +       VXH_RELEASE_VX_INFO,
11484 +       VXH_ALLOC_VX_INFO,
11485 +       VXH_DEALLOC_VX_INFO,
11486 +       VXH_HASH_VX_INFO,
11487 +       VXH_UNHASH_VX_INFO,
11488 +       VXH_LOC_VX_INFO,
11489 +       VXH_LOOKUP_VX_INFO,
11490 +       VXH_CREATE_VX_INFO,
11491 +};
11492 +
11493 +struct _vxhe_vxi {
11494 +       struct vx_info *ptr;
11495 +       unsigned xid;
11496 +       unsigned usecnt;
11497 +       unsigned tasks;
11498 +};
11499 +
11500 +struct _vxhe_set_clr {
11501 +       void *data;
11502 +};
11503 +
11504 +struct _vxhe_loc_lookup {
11505 +       unsigned arg;
11506 +};
11507 +
11508 +struct _vx_hist_entry {
11509 +       void *loc;
11510 +       unsigned short seq;
11511 +       unsigned short type;
11512 +       struct _vxhe_vxi vxi;
11513 +       union {
11514 +               struct _vxhe_set_clr sc;
11515 +               struct _vxhe_loc_lookup ll;
11516 +       };
11517 +};
11518 +
11519 +#ifdef CONFIG_VSERVER_HISTORY
11520 +
11521 +extern unsigned volatile int vxh_active;
11522 +
11523 +struct _vx_hist_entry *vxh_advance(void *loc);
11524 +
11525 +
11526 +static inline
11527 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11528 +{
11529 +       entry->vxi.ptr = vxi;
11530 +       if (vxi) {
11531 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11532 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11533 +               entry->vxi.xid = vxi->vx_id;
11534 +       }
11535 +}
11536 +
11537 +
11538 +#define        __HERE__ current_text_addr()
11539 +
11540 +#define __VXH_BODY(__type, __data, __here)     \
11541 +       struct _vx_hist_entry *entry;           \
11542 +                                               \
11543 +       preempt_disable();                      \
11544 +       entry = vxh_advance(__here);            \
11545 +       __data;                                 \
11546 +       entry->type = __type;                   \
11547 +       preempt_enable();
11548 +
11549 +
11550 +       /* pass vxi only */
11551 +
11552 +#define __VXH_SMPL                             \
11553 +       __vxh_copy_vxi(entry, vxi)
11554 +
11555 +static inline
11556 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11557 +{
11558 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11559 +}
11560 +
11561 +       /* pass vxi and data (void *) */
11562 +
11563 +#define __VXH_DATA                             \
11564 +       __vxh_copy_vxi(entry, vxi);             \
11565 +       entry->sc.data = data
11566 +
11567 +static inline
11568 +void   __vxh_data(struct vx_info *vxi, void *data,
11569 +                       int __type, void *__here)
11570 +{
11571 +       __VXH_BODY(__type, __VXH_DATA, __here)
11572 +}
11573 +
11574 +       /* pass vxi and arg (long) */
11575 +
11576 +#define __VXH_LONG                             \
11577 +       __vxh_copy_vxi(entry, vxi);             \
11578 +       entry->ll.arg = arg
11579 +
11580 +static inline
11581 +void   __vxh_long(struct vx_info *vxi, long arg,
11582 +                       int __type, void *__here)
11583 +{
11584 +       __VXH_BODY(__type, __VXH_LONG, __here)
11585 +}
11586 +
11587 +
11588 +static inline
11589 +void   __vxh_throw_oops(void *__here)
11590 +{
11591 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11592 +       /* prevent further acquisition */
11593 +       vxh_active = 0;
11594 +}
11595 +
11596 +
11597 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11598 +
11599 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11600 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11601 +
11602 +#define __vxh_init_vx_info(v, d, h) \
11603 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11604 +#define __vxh_set_vx_info(v, d, h) \
11605 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11606 +#define __vxh_clr_vx_info(v, d, h) \
11607 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11608 +
11609 +#define __vxh_claim_vx_info(v, d, h) \
11610 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11611 +#define __vxh_release_vx_info(v, d, h) \
11612 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11613 +
11614 +#define vxh_alloc_vx_info(v) \
11615 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11616 +#define vxh_dealloc_vx_info(v) \
11617 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11618 +
11619 +#define vxh_hash_vx_info(v) \
11620 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11621 +#define vxh_unhash_vx_info(v) \
11622 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11623 +
11624 +#define vxh_loc_vx_info(v, l) \
11625 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11626 +#define vxh_lookup_vx_info(v, l) \
11627 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11628 +#define vxh_create_vx_info(v, l) \
11629 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11630 +
11631 +extern void vxh_dump_history(void);
11632 +
11633 +
11634 +#else  /* CONFIG_VSERVER_HISTORY */
11635 +
11636 +#define        __HERE__        0
11637 +
11638 +#define vxh_throw_oops()               do { } while (0)
11639 +
11640 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11641 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11642 +
11643 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11644 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11645 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11646 +
11647 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11648 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11649 +
11650 +#define vxh_alloc_vx_info(v)           do { } while (0)
11651 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11652 +
11653 +#define vxh_hash_vx_info(v)            do { } while (0)
11654 +#define vxh_unhash_vx_info(v)          do { } while (0)
11655 +
11656 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11657 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11658 +#define vxh_create_vx_info(v, l)       do { } while (0)
11659 +
11660 +#define vxh_dump_history()             do { } while (0)
11661 +
11662 +
11663 +#endif /* CONFIG_VSERVER_HISTORY */
11664 +
11665 +#endif /* _VX_HISTORY_H */
11666 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/inode_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/inode_cmd.h
11667 --- linux-2.6.37/include/linux/vserver/inode_cmd.h      1970-01-01 01:00:00.000000000 +0100
11668 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/inode_cmd.h       2010-11-23 02:09:41.000000000 +0100
11669 @@ -0,0 +1,59 @@
11670 +#ifndef _VX_INODE_CMD_H
11671 +#define _VX_INODE_CMD_H
11672 +
11673 +
11674 +/*  inode vserver commands */
11675 +
11676 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11677 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11678 +
11679 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11680 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11681 +
11682 +struct vcmd_ctx_iattr_v1 {
11683 +       const char __user *name;
11684 +       uint32_t tag;
11685 +       uint32_t flags;
11686 +       uint32_t mask;
11687 +};
11688 +
11689 +struct vcmd_ctx_fiattr_v0 {
11690 +       uint32_t tag;
11691 +       uint32_t flags;
11692 +       uint32_t mask;
11693 +};
11694 +
11695 +
11696 +#ifdef __KERNEL__
11697 +
11698 +
11699 +#ifdef CONFIG_COMPAT
11700 +
11701 +#include <asm/compat.h>
11702 +
11703 +struct vcmd_ctx_iattr_v1_x32 {
11704 +       compat_uptr_t name_ptr;
11705 +       uint32_t tag;
11706 +       uint32_t flags;
11707 +       uint32_t mask;
11708 +};
11709 +
11710 +#endif /* CONFIG_COMPAT */
11711 +
11712 +#include <linux/compiler.h>
11713 +
11714 +extern int vc_get_iattr(void __user *);
11715 +extern int vc_set_iattr(void __user *);
11716 +
11717 +extern int vc_fget_iattr(uint32_t, void __user *);
11718 +extern int vc_fset_iattr(uint32_t, void __user *);
11719 +
11720 +#ifdef CONFIG_COMPAT
11721 +
11722 +extern int vc_get_iattr_x32(void __user *);
11723 +extern int vc_set_iattr_x32(void __user *);
11724 +
11725 +#endif /* CONFIG_COMPAT */
11726 +
11727 +#endif /* __KERNEL__ */
11728 +#endif /* _VX_INODE_CMD_H */
11729 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/inode.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/inode.h
11730 --- linux-2.6.37/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
11731 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/inode.h   2010-11-23 02:09:41.000000000 +0100
11732 @@ -0,0 +1,39 @@
11733 +#ifndef _VX_INODE_H
11734 +#define _VX_INODE_H
11735 +
11736 +
11737 +#define IATTR_TAG      0x01000000
11738 +
11739 +#define IATTR_ADMIN    0x00000001
11740 +#define IATTR_WATCH    0x00000002
11741 +#define IATTR_HIDE     0x00000004
11742 +#define IATTR_FLAGS    0x00000007
11743 +
11744 +#define IATTR_BARRIER  0x00010000
11745 +#define IATTR_IXUNLINK 0x00020000
11746 +#define IATTR_IMMUTABLE 0x00040000
11747 +#define IATTR_COW      0x00080000
11748 +
11749 +#ifdef __KERNEL__
11750 +
11751 +
11752 +#ifdef CONFIG_VSERVER_PROC_SECURE
11753 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11754 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11755 +#else
11756 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11757 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11758 +#endif
11759 +
11760 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11761 +
11762 +#endif /* __KERNEL__ */
11763 +
11764 +/* inode ioctls */
11765 +
11766 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11767 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11768 +
11769 +#else  /* _VX_INODE_H */
11770 +#warning duplicate inclusion
11771 +#endif /* _VX_INODE_H */
11772 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/Kbuild linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/Kbuild
11773 --- linux-2.6.37/include/linux/vserver/Kbuild   1970-01-01 01:00:00.000000000 +0100
11774 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/Kbuild    2010-11-23 02:09:41.000000000 +0100
11775 @@ -0,0 +1,8 @@
11776 +
11777 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11778 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11779 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11780 +       debug_cmd.h device_cmd.h
11781 +
11782 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11783 +
11784 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/limit_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/limit_cmd.h
11785 --- linux-2.6.37/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
11786 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/limit_cmd.h       2010-11-23 02:09:41.000000000 +0100
11787 @@ -0,0 +1,71 @@
11788 +#ifndef _VX_LIMIT_CMD_H
11789 +#define _VX_LIMIT_CMD_H
11790 +
11791 +
11792 +/*  rlimit vserver commands */
11793 +
11794 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11795 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11796 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11797 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11798 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11799 +
11800 +struct vcmd_ctx_rlimit_v0 {
11801 +       uint32_t id;
11802 +       uint64_t minimum;
11803 +       uint64_t softlimit;
11804 +       uint64_t maximum;
11805 +};
11806 +
11807 +struct vcmd_ctx_rlimit_mask_v0 {
11808 +       uint32_t minimum;
11809 +       uint32_t softlimit;
11810 +       uint32_t maximum;
11811 +};
11812 +
11813 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11814 +
11815 +struct vcmd_rlimit_stat_v0 {
11816 +       uint32_t id;
11817 +       uint32_t hits;
11818 +       uint64_t value;
11819 +       uint64_t minimum;
11820 +       uint64_t maximum;
11821 +};
11822 +
11823 +#define CRLIM_UNSET            (0ULL)
11824 +#define CRLIM_INFINITY         (~0ULL)
11825 +#define CRLIM_KEEP             (~1ULL)
11826 +
11827 +#ifdef __KERNEL__
11828 +
11829 +#ifdef CONFIG_IA32_EMULATION
11830 +
11831 +struct vcmd_ctx_rlimit_v0_x32 {
11832 +       uint32_t id;
11833 +       uint64_t minimum;
11834 +       uint64_t softlimit;
11835 +       uint64_t maximum;
11836 +} __attribute__ ((packed));
11837 +
11838 +#endif /* CONFIG_IA32_EMULATION */
11839 +
11840 +#include <linux/compiler.h>
11841 +
11842 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11843 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11844 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11845 +extern int vc_reset_hits(struct vx_info *, void __user *);
11846 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11847 +
11848 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11849 +
11850 +#ifdef CONFIG_IA32_EMULATION
11851 +
11852 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11853 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11854 +
11855 +#endif /* CONFIG_IA32_EMULATION */
11856 +
11857 +#endif /* __KERNEL__ */
11858 +#endif /* _VX_LIMIT_CMD_H */
11859 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/limit_def.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/limit_def.h
11860 --- linux-2.6.37/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
11861 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/limit_def.h       2010-11-23 02:09:41.000000000 +0100
11862 @@ -0,0 +1,47 @@
11863 +#ifndef _VX_LIMIT_DEF_H
11864 +#define _VX_LIMIT_DEF_H
11865 +
11866 +#include <asm/atomic.h>
11867 +#include <asm/resource.h>
11868 +
11869 +#include "limit.h"
11870 +
11871 +
11872 +struct _vx_res_limit {
11873 +       rlim_t soft;            /* Context soft limit */
11874 +       rlim_t hard;            /* Context hard limit */
11875 +
11876 +       rlim_atomic_t rcur;     /* Current value */
11877 +       rlim_t rmin;            /* Context minimum */
11878 +       rlim_t rmax;            /* Context maximum */
11879 +
11880 +       atomic_t lhit;          /* Limit hits */
11881 +};
11882 +
11883 +/* context sub struct */
11884 +
11885 +struct _vx_limit {
11886 +       struct _vx_res_limit res[NUM_LIMITS];
11887 +};
11888 +
11889 +#ifdef CONFIG_VSERVER_DEBUG
11890 +
11891 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11892 +{
11893 +       int i;
11894 +
11895 +       printk("\t_vx_limit:");
11896 +       for (i = 0; i < NUM_LIMITS; i++) {
11897 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11898 +                       i, (unsigned long)__rlim_get(limit, i),
11899 +                       (unsigned long)__rlim_rmin(limit, i),
11900 +                       (unsigned long)__rlim_rmax(limit, i),
11901 +                       (long)__rlim_soft(limit, i),
11902 +                       (long)__rlim_hard(limit, i),
11903 +                       atomic_read(&__rlim_lhit(limit, i)));
11904 +       }
11905 +}
11906 +
11907 +#endif
11908 +
11909 +#endif /* _VX_LIMIT_DEF_H */
11910 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/limit.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/limit.h
11911 --- linux-2.6.37/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
11912 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/limit.h   2010-11-23 02:09:41.000000000 +0100
11913 @@ -0,0 +1,71 @@
11914 +#ifndef _VX_LIMIT_H
11915 +#define _VX_LIMIT_H
11916 +
11917 +#define VLIMIT_NSOCK   16
11918 +#define VLIMIT_OPENFD  17
11919 +#define VLIMIT_ANON    18
11920 +#define VLIMIT_SHMEM   19
11921 +#define VLIMIT_SEMARY  20
11922 +#define VLIMIT_NSEMS   21
11923 +#define VLIMIT_DENTRY  22
11924 +#define VLIMIT_MAPPED  23
11925 +
11926 +
11927 +#ifdef __KERNEL__
11928 +
11929 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11930 +
11931 +/*     keep in sync with CRLIM_INFINITY */
11932 +
11933 +#define        VLIM_INFINITY   (~0ULL)
11934 +
11935 +#include <asm/atomic.h>
11936 +#include <asm/resource.h>
11937 +
11938 +#ifndef RLIM_INFINITY
11939 +#warning RLIM_INFINITY is undefined
11940 +#endif
11941 +
11942 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11943 +
11944 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11945 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11946 +
11947 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11948 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11949 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11950 +
11951 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11952 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11953 +
11954 +typedef atomic_long_t rlim_atomic_t;
11955 +typedef unsigned long rlim_t;
11956 +
11957 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11958 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11959 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11960 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11961 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11962 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11963 +
11964 +
11965 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11966 +#define        VX_VLIM(r) ((long long)(long)(r))
11967 +#define        VX_RLIM(v) ((rlim_t)(v))
11968 +#else
11969 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11970 +               ? VLIM_INFINITY : (long long)(r))
11971 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11972 +               ? RLIM_INFINITY : (rlim_t)(v))
11973 +#endif
11974 +
11975 +struct sysinfo;
11976 +
11977 +void vx_vsi_meminfo(struct sysinfo *);
11978 +void vx_vsi_swapinfo(struct sysinfo *);
11979 +long vx_vsi_cached(struct sysinfo *);
11980 +
11981 +#define NUM_LIMITS     24
11982 +
11983 +#endif /* __KERNEL__ */
11984 +#endif /* _VX_LIMIT_H */
11985 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/limit_int.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/limit_int.h
11986 --- linux-2.6.37/include/linux/vserver/limit_int.h      1970-01-01 01:00:00.000000000 +0100
11987 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/limit_int.h       2010-11-23 02:09:41.000000000 +0100
11988 @@ -0,0 +1,198 @@
11989 +#ifndef _VX_LIMIT_INT_H
11990 +#define _VX_LIMIT_INT_H
11991 +
11992 +#include "context.h"
11993 +
11994 +#ifdef __KERNEL__
11995 +
11996 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11997 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11998 +
11999 +extern const char *vlimit_name[NUM_LIMITS];
12000 +
12001 +static inline void __vx_acc_cres(struct vx_info *vxi,
12002 +       int res, int dir, void *_data, char *_file, int _line)
12003 +{
12004 +       if (VXD_RCRES_COND(res))
12005 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12006 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12007 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12008 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12009 +       if (!vxi)
12010 +               return;
12011 +
12012 +       if (dir > 0)
12013 +               __rlim_inc(&vxi->limit, res);
12014 +       else
12015 +               __rlim_dec(&vxi->limit, res);
12016 +}
12017 +
12018 +static inline void __vx_add_cres(struct vx_info *vxi,
12019 +       int res, int amount, void *_data, char *_file, int _line)
12020 +{
12021 +       if (VXD_RCRES_COND(res))
12022 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12023 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12024 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12025 +                       amount, _data, _file, _line);
12026 +       if (amount == 0)
12027 +               return;
12028 +       if (!vxi)
12029 +               return;
12030 +       __rlim_add(&vxi->limit, res, amount);
12031 +}
12032 +
12033 +static inline
12034 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12035 +{
12036 +       int cond = (value > __rlim_rmax(limit, res));
12037 +
12038 +       if (cond)
12039 +               __rlim_rmax(limit, res) = value;
12040 +       return cond;
12041 +}
12042 +
12043 +static inline
12044 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12045 +{
12046 +       int cond = (value < __rlim_rmin(limit, res));
12047 +
12048 +       if (cond)
12049 +               __rlim_rmin(limit, res) = value;
12050 +       return cond;
12051 +}
12052 +
12053 +static inline
12054 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12055 +{
12056 +       if (!__vx_cres_adjust_max(limit, res, value))
12057 +               __vx_cres_adjust_min(limit, res, value);
12058 +}
12059 +
12060 +
12061 +/*     return values:
12062 +        +1 ... no limit hit
12063 +        -1 ... over soft limit
12064 +         0 ... over hard limit         */
12065 +
12066 +static inline int __vx_cres_avail(struct vx_info *vxi,
12067 +       int res, int num, char *_file, int _line)
12068 +{
12069 +       struct _vx_limit *limit;
12070 +       rlim_t value;
12071 +
12072 +       if (VXD_RLIMIT_COND(res))
12073 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12074 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12075 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12076 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12077 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12078 +                       num, _file, _line);
12079 +       if (!vxi)
12080 +               return 1;
12081 +
12082 +       limit = &vxi->limit;
12083 +       value = __rlim_get(limit, res);
12084 +
12085 +       if (!__vx_cres_adjust_max(limit, res, value))
12086 +               __vx_cres_adjust_min(limit, res, value);
12087 +
12088 +       if (num == 0)
12089 +               return 1;
12090 +
12091 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12092 +               return -1;
12093 +       if (value + num <= __rlim_soft(limit, res))
12094 +               return -1;
12095 +
12096 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12097 +               return 1;
12098 +       if (value + num <= __rlim_hard(limit, res))
12099 +               return 1;
12100 +
12101 +       __rlim_hit(limit, res);
12102 +       return 0;
12103 +}
12104 +
12105 +
12106 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12107 +
12108 +static inline
12109 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12110 +{
12111 +       rlim_t value, sum = 0;
12112 +       int res;
12113 +
12114 +       while ((res = *array++)) {
12115 +               value = __rlim_get(limit, res);
12116 +               __vx_cres_fixup(limit, res, value);
12117 +               sum += value;
12118 +       }
12119 +       return sum;
12120 +}
12121 +
12122 +static inline
12123 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12124 +{
12125 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12126 +       int res = *array;
12127 +
12128 +       if (value == __rlim_get(limit, res))
12129 +               return value;
12130 +
12131 +       __rlim_set(limit, res, value);
12132 +       /* now adjust min/max */
12133 +       if (!__vx_cres_adjust_max(limit, res, value))
12134 +               __vx_cres_adjust_min(limit, res, value);
12135 +
12136 +       return value;
12137 +}
12138 +
12139 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12140 +       const int *array, int num, char *_file, int _line)
12141 +{
12142 +       struct _vx_limit *limit;
12143 +       rlim_t value = 0;
12144 +       int res;
12145 +
12146 +       if (num == 0)
12147 +               return 1;
12148 +       if (!vxi)
12149 +               return 1;
12150 +
12151 +       limit = &vxi->limit;
12152 +       res = *array;
12153 +       value = __vx_cres_array_sum(limit, array + 1);
12154 +
12155 +       __rlim_set(limit, res, value);
12156 +       __vx_cres_fixup(limit, res, value);
12157 +
12158 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12159 +}
12160 +
12161 +
12162 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12163 +{
12164 +       rlim_t value;
12165 +       int res;
12166 +
12167 +       /* complex resources first */
12168 +       if ((id < 0) || (id == RLIMIT_RSS))
12169 +               __vx_cres_array_fixup(limit, VLA_RSS);
12170 +
12171 +       for (res = 0; res < NUM_LIMITS; res++) {
12172 +               if ((id > 0) && (res != id))
12173 +                       continue;
12174 +
12175 +               value = __rlim_get(limit, res);
12176 +               __vx_cres_fixup(limit, res, value);
12177 +
12178 +               /* not supposed to happen, maybe warn? */
12179 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12180 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12181 +       }
12182 +}
12183 +
12184 +
12185 +#endif /* __KERNEL__ */
12186 +#endif /* _VX_LIMIT_INT_H */
12187 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/monitor.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/monitor.h
12188 --- linux-2.6.37/include/linux/vserver/monitor.h        1970-01-01 01:00:00.000000000 +0100
12189 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/monitor.h 2010-11-23 02:09:41.000000000 +0100
12190 @@ -0,0 +1,96 @@
12191 +#ifndef _VX_MONITOR_H
12192 +#define _VX_MONITOR_H
12193 +
12194 +#include <linux/types.h>
12195 +
12196 +enum {
12197 +       VXM_UNUSED = 0,
12198 +
12199 +       VXM_SYNC = 0x10,
12200 +
12201 +       VXM_UPDATE = 0x20,
12202 +       VXM_UPDATE_1,
12203 +       VXM_UPDATE_2,
12204 +
12205 +       VXM_RQINFO_1 = 0x24,
12206 +       VXM_RQINFO_2,
12207 +
12208 +       VXM_ACTIVATE = 0x40,
12209 +       VXM_DEACTIVATE,
12210 +       VXM_IDLE,
12211 +
12212 +       VXM_HOLD = 0x44,
12213 +       VXM_UNHOLD,
12214 +
12215 +       VXM_MIGRATE = 0x48,
12216 +       VXM_RESCHED,
12217 +
12218 +       /* all other bits are flags */
12219 +       VXM_SCHED = 0x80,
12220 +};
12221 +
12222 +struct _vxm_update_1 {
12223 +       uint32_t tokens_max;
12224 +       uint32_t fill_rate;
12225 +       uint32_t interval;
12226 +};
12227 +
12228 +struct _vxm_update_2 {
12229 +       uint32_t tokens_min;
12230 +       uint32_t fill_rate;
12231 +       uint32_t interval;
12232 +};
12233 +
12234 +struct _vxm_rqinfo_1 {
12235 +       uint16_t running;
12236 +       uint16_t onhold;
12237 +       uint16_t iowait;
12238 +       uint16_t uintr;
12239 +       uint32_t idle_tokens;
12240 +};
12241 +
12242 +struct _vxm_rqinfo_2 {
12243 +       uint32_t norm_time;
12244 +       uint32_t idle_time;
12245 +       uint32_t idle_skip;
12246 +};
12247 +
12248 +struct _vxm_sched {
12249 +       uint32_t tokens;
12250 +       uint32_t norm_time;
12251 +       uint32_t idle_time;
12252 +};
12253 +
12254 +struct _vxm_task {
12255 +       uint16_t pid;
12256 +       uint16_t state;
12257 +};
12258 +
12259 +struct _vxm_event {
12260 +       uint32_t jif;
12261 +       union {
12262 +               uint32_t seq;
12263 +               uint32_t sec;
12264 +       };
12265 +       union {
12266 +               uint32_t tokens;
12267 +               uint32_t nsec;
12268 +               struct _vxm_task tsk;
12269 +       };
12270 +};
12271 +
12272 +struct _vx_mon_entry {
12273 +       uint16_t type;
12274 +       uint16_t xid;
12275 +       union {
12276 +               struct _vxm_event ev;
12277 +               struct _vxm_sched sd;
12278 +               struct _vxm_update_1 u1;
12279 +               struct _vxm_update_2 u2;
12280 +               struct _vxm_rqinfo_1 q1;
12281 +               struct _vxm_rqinfo_2 q2;
12282 +       };
12283 +};
12284 +
12285 +
12286 +#endif /* _VX_MONITOR_H */
12287 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/network_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/network_cmd.h
12288 --- linux-2.6.37/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
12289 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/network_cmd.h     2010-11-23 02:09:41.000000000 +0100
12290 @@ -0,0 +1,150 @@
12291 +#ifndef _VX_NETWORK_CMD_H
12292 +#define _VX_NETWORK_CMD_H
12293 +
12294 +
12295 +/* vinfo commands */
12296 +
12297 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12298 +
12299 +#ifdef __KERNEL__
12300 +extern int vc_task_nid(uint32_t);
12301 +
12302 +#endif /* __KERNEL__ */
12303 +
12304 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12305 +
12306 +struct vcmd_nx_info_v0 {
12307 +       uint32_t nid;
12308 +       /* more to come */
12309 +};
12310 +
12311 +#ifdef __KERNEL__
12312 +extern int vc_nx_info(struct nx_info *, void __user *);
12313 +
12314 +#endif /* __KERNEL__ */
12315 +
12316 +#include <linux/in.h>
12317 +#include <linux/in6.h>
12318 +
12319 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12320 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12321 +
12322 +struct  vcmd_net_create {
12323 +       uint64_t flagword;
12324 +};
12325 +
12326 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12327 +
12328 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12329 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12330 +
12331 +struct vcmd_net_addr_v0 {
12332 +       uint16_t type;
12333 +       uint16_t count;
12334 +       struct in_addr ip[4];
12335 +       struct in_addr mask[4];
12336 +};
12337 +
12338 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12339 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12340 +
12341 +struct vcmd_net_addr_ipv4_v1 {
12342 +       uint16_t type;
12343 +       uint16_t flags;
12344 +       struct in_addr ip;
12345 +       struct in_addr mask;
12346 +};
12347 +
12348 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12349 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12350 +
12351 +struct vcmd_net_addr_ipv6_v1 {
12352 +       uint16_t type;
12353 +       uint16_t flags;
12354 +       uint32_t prefix;
12355 +       struct in6_addr ip;
12356 +       struct in6_addr mask;
12357 +};
12358 +
12359 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12360 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12361 +
12362 +struct vcmd_match_ipv4_v0 {
12363 +       uint16_t type;
12364 +       uint16_t flags;
12365 +       uint16_t parent;
12366 +       uint16_t prefix;
12367 +       struct in_addr ip;
12368 +       struct in_addr ip2;
12369 +       struct in_addr mask;
12370 +};
12371 +
12372 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12373 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12374 +
12375 +struct vcmd_match_ipv6_v0 {
12376 +       uint16_t type;
12377 +       uint16_t flags;
12378 +       uint16_t parent;
12379 +       uint16_t prefix;
12380 +       struct in6_addr ip;
12381 +       struct in6_addr ip2;
12382 +       struct in6_addr mask;
12383 +};
12384 +
12385 +
12386 +#ifdef __KERNEL__
12387 +extern int vc_net_create(uint32_t, void __user *);
12388 +extern int vc_net_migrate(struct nx_info *, void __user *);
12389 +
12390 +extern int vc_net_add(struct nx_info *, void __user *);
12391 +extern int vc_net_remove(struct nx_info *, void __user *);
12392 +
12393 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12394 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12395 +
12396 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12397 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12398 +
12399 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12400 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12401 +
12402 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12403 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12404 +
12405 +#endif /* __KERNEL__ */
12406 +
12407 +
12408 +/* flag commands */
12409 +
12410 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12411 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12412 +
12413 +struct vcmd_net_flags_v0 {
12414 +       uint64_t flagword;
12415 +       uint64_t mask;
12416 +};
12417 +
12418 +#ifdef __KERNEL__
12419 +extern int vc_get_nflags(struct nx_info *, void __user *);
12420 +extern int vc_set_nflags(struct nx_info *, void __user *);
12421 +
12422 +#endif /* __KERNEL__ */
12423 +
12424 +
12425 +/* network caps commands */
12426 +
12427 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12428 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12429 +
12430 +struct vcmd_net_caps_v0 {
12431 +       uint64_t ncaps;
12432 +       uint64_t cmask;
12433 +};
12434 +
12435 +#ifdef __KERNEL__
12436 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12437 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12438 +
12439 +#endif /* __KERNEL__ */
12440 +#endif /* _VX_CONTEXT_CMD_H */
12441 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/network.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/network.h
12442 --- linux-2.6.37/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
12443 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/network.h 2010-11-23 02:09:41.000000000 +0100
12444 @@ -0,0 +1,146 @@
12445 +#ifndef _VX_NETWORK_H
12446 +#define _VX_NETWORK_H
12447 +
12448 +#include <linux/types.h>
12449 +
12450 +
12451 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12452 +
12453 +
12454 +/* network flags */
12455 +
12456 +#define NXF_INFO_PRIVATE       0x00000008
12457 +
12458 +#define NXF_SINGLE_IP          0x00000100
12459 +#define NXF_LBACK_REMAP                0x00000200
12460 +#define NXF_LBACK_ALLOW                0x00000400
12461 +
12462 +#define NXF_HIDE_NETIF         0x02000000
12463 +#define NXF_HIDE_LBACK         0x04000000
12464 +
12465 +#define NXF_STATE_SETUP                (1ULL << 32)
12466 +#define NXF_STATE_ADMIN                (1ULL << 34)
12467 +
12468 +#define NXF_SC_HELPER          (1ULL << 36)
12469 +#define NXF_PERSISTENT         (1ULL << 38)
12470 +
12471 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12472 +
12473 +
12474 +#define        NXF_INIT_SET            (__nxf_init_set())
12475 +
12476 +static inline uint64_t __nxf_init_set(void) {
12477 +       return    NXF_STATE_ADMIN
12478 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12479 +               | NXF_LBACK_REMAP
12480 +               | NXF_HIDE_LBACK
12481 +#endif
12482 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12483 +               | NXF_SINGLE_IP
12484 +#endif
12485 +               | NXF_HIDE_NETIF;
12486 +}
12487 +
12488 +
12489 +/* network caps */
12490 +
12491 +#define NXC_TUN_CREATE         0x00000001
12492 +
12493 +#define NXC_RAW_ICMP           0x00000100
12494 +
12495 +
12496 +/* address types */
12497 +
12498 +#define NXA_TYPE_IPV4          0x0001
12499 +#define NXA_TYPE_IPV6          0x0002
12500 +
12501 +#define NXA_TYPE_NONE          0x0000
12502 +#define NXA_TYPE_ANY           0x00FF
12503 +
12504 +#define NXA_TYPE_ADDR          0x0010
12505 +#define NXA_TYPE_MASK          0x0020
12506 +#define NXA_TYPE_RANGE         0x0040
12507 +
12508 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12509 +
12510 +#define NXA_MOD_BCAST          0x0100
12511 +#define NXA_MOD_LBACK          0x0200
12512 +
12513 +#define NXA_LOOPBACK           0x1000
12514 +
12515 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12516 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12517 +
12518 +#ifdef __KERNEL__
12519 +
12520 +#include <linux/list.h>
12521 +#include <linux/spinlock.h>
12522 +#include <linux/rcupdate.h>
12523 +#include <linux/in.h>
12524 +#include <linux/in6.h>
12525 +#include <asm/atomic.h>
12526 +
12527 +struct nx_addr_v4 {
12528 +       struct nx_addr_v4 *next;
12529 +       struct in_addr ip[2];
12530 +       struct in_addr mask;
12531 +       uint16_t type;
12532 +       uint16_t flags;
12533 +};
12534 +
12535 +struct nx_addr_v6 {
12536 +       struct nx_addr_v6 *next;
12537 +       struct in6_addr ip;
12538 +       struct in6_addr mask;
12539 +       uint32_t prefix;
12540 +       uint16_t type;
12541 +       uint16_t flags;
12542 +};
12543 +
12544 +struct nx_info {
12545 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12546 +       nid_t nx_id;                    /* vnet id */
12547 +       atomic_t nx_usecnt;             /* usage count */
12548 +       atomic_t nx_tasks;              /* tasks count */
12549 +       int nx_state;                   /* context state */
12550 +
12551 +       uint64_t nx_flags;              /* network flag word */
12552 +       uint64_t nx_ncaps;              /* network capabilities */
12553 +
12554 +       struct in_addr v4_lback;        /* Loopback address */
12555 +       struct in_addr v4_bcast;        /* Broadcast address */
12556 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12557 +#ifdef CONFIG_IPV6
12558 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12559 +#endif
12560 +       char nx_name[65];               /* network context name */
12561 +};
12562 +
12563 +
12564 +/* status flags */
12565 +
12566 +#define NXS_HASHED      0x0001
12567 +#define NXS_SHUTDOWN    0x0100
12568 +#define NXS_RELEASED    0x8000
12569 +
12570 +extern struct nx_info *lookup_nx_info(int);
12571 +
12572 +extern int get_nid_list(int, unsigned int *, int);
12573 +extern int nid_is_hashed(nid_t);
12574 +
12575 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12576 +
12577 +extern long vs_net_change(struct nx_info *, unsigned int);
12578 +
12579 +struct sock;
12580 +
12581 +
12582 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12583 +#ifdef  CONFIG_IPV6
12584 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12585 +#else
12586 +#define NX_IPV6(n)     (0)
12587 +#endif
12588 +
12589 +#endif /* __KERNEL__ */
12590 +#endif /* _VX_NETWORK_H */
12591 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/percpu.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/percpu.h
12592 --- linux-2.6.37/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
12593 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/percpu.h  2010-11-23 02:09:41.000000000 +0100
12594 @@ -0,0 +1,14 @@
12595 +#ifndef _VX_PERCPU_H
12596 +#define _VX_PERCPU_H
12597 +
12598 +#include "cvirt_def.h"
12599 +#include "sched_def.h"
12600 +
12601 +struct _vx_percpu {
12602 +       struct _vx_cvirt_pc cvirt;
12603 +       struct _vx_sched_pc sched;
12604 +};
12605 +
12606 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12607 +
12608 +#endif /* _VX_PERCPU_H */
12609 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/pid.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/pid.h
12610 --- linux-2.6.37/include/linux/vserver/pid.h    1970-01-01 01:00:00.000000000 +0100
12611 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/pid.h     2010-11-23 02:09:41.000000000 +0100
12612 @@ -0,0 +1,51 @@
12613 +#ifndef _VSERVER_PID_H
12614 +#define _VSERVER_PID_H
12615 +
12616 +/* pid faking stuff */
12617 +
12618 +#define vx_info_map_pid(v, p) \
12619 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12620 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12621 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12622 +#define vx_map_tgid(p) vx_map_pid(p)
12623 +
12624 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12625 +       const char *func, const char *file, int line)
12626 +{
12627 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12628 +               vxfprintk(VXD_CBIT(cvirt, 2),
12629 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12630 +                       vxi, (long long)vxi->vx_flags, pid,
12631 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12632 +                       func, file, line);
12633 +               if (pid == 0)
12634 +                       return 0;
12635 +               if (pid == vxi->vx_initpid)
12636 +                       return 1;
12637 +       }
12638 +       return pid;
12639 +}
12640 +
12641 +#define vx_info_rmap_pid(v, p) \
12642 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12643 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12644 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12645 +
12646 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12647 +       const char *func, const char *file, int line)
12648 +{
12649 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12650 +               vxfprintk(VXD_CBIT(cvirt, 2),
12651 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12652 +                       vxi, (long long)vxi->vx_flags, pid,
12653 +                       (pid == 1) ? vxi->vx_initpid : pid,
12654 +                       func, file, line);
12655 +               if ((pid == 1) && vxi->vx_initpid)
12656 +                       return vxi->vx_initpid;
12657 +               if (pid == vxi->vx_initpid)
12658 +                       return ~0U;
12659 +       }
12660 +       return pid;
12661 +}
12662 +
12663 +#endif
12664 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/sched_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/sched_cmd.h
12665 --- linux-2.6.37/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
12666 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/sched_cmd.h       2010-11-23 02:09:41.000000000 +0100
12667 @@ -0,0 +1,21 @@
12668 +#ifndef _VX_SCHED_CMD_H
12669 +#define _VX_SCHED_CMD_H
12670 +
12671 +
12672 +struct vcmd_prio_bias {
12673 +       int32_t cpu_id;
12674 +       int32_t prio_bias;
12675 +};
12676 +
12677 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
12678 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
12679 +
12680 +#ifdef __KERNEL__
12681 +
12682 +#include <linux/compiler.h>
12683 +
12684 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12685 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12686 +
12687 +#endif /* __KERNEL__ */
12688 +#endif /* _VX_SCHED_CMD_H */
12689 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/sched_def.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/sched_def.h
12690 --- linux-2.6.37/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
12691 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/sched_def.h       2010-11-23 02:09:41.000000000 +0100
12692 @@ -0,0 +1,38 @@
12693 +#ifndef _VX_SCHED_DEF_H
12694 +#define _VX_SCHED_DEF_H
12695 +
12696 +#include <linux/spinlock.h>
12697 +#include <linux/jiffies.h>
12698 +#include <linux/cpumask.h>
12699 +#include <asm/atomic.h>
12700 +#include <asm/param.h>
12701 +
12702 +
12703 +/* context sub struct */
12704 +
12705 +struct _vx_sched {
12706 +       int prio_bias;                  /* bias offset for priority */
12707 +
12708 +       cpumask_t update;               /* CPUs which should update */
12709 +};
12710 +
12711 +struct _vx_sched_pc {
12712 +       int prio_bias;                  /* bias offset for priority */
12713 +
12714 +       uint64_t user_ticks;            /* token tick events */
12715 +       uint64_t sys_ticks;             /* token tick events */
12716 +       uint64_t hold_ticks;            /* token ticks paused */
12717 +};
12718 +
12719 +
12720 +#ifdef CONFIG_VSERVER_DEBUG
12721 +
12722 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12723 +{
12724 +       printk("\t_vx_sched:\n");
12725 +       printk("\t priority = %4d\n", sched->prio_bias);
12726 +}
12727 +
12728 +#endif
12729 +
12730 +#endif /* _VX_SCHED_DEF_H */
12731 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/sched.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/sched.h
12732 --- linux-2.6.37/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
12733 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/sched.h   2010-11-23 02:09:41.000000000 +0100
12734 @@ -0,0 +1,23 @@
12735 +#ifndef _VX_SCHED_H
12736 +#define _VX_SCHED_H
12737 +
12738 +
12739 +#ifdef __KERNEL__
12740 +
12741 +struct timespec;
12742 +
12743 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12744 +
12745 +
12746 +struct vx_info;
12747 +
12748 +void vx_update_load(struct vx_info *);
12749 +
12750 +
12751 +void vx_update_sched_param(struct _vx_sched *sched,
12752 +       struct _vx_sched_pc *sched_pc);
12753 +
12754 +#endif /* __KERNEL__ */
12755 +#else  /* _VX_SCHED_H */
12756 +#warning duplicate inclusion
12757 +#endif /* _VX_SCHED_H */
12758 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/signal_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/signal_cmd.h
12759 --- linux-2.6.37/include/linux/vserver/signal_cmd.h     1970-01-01 01:00:00.000000000 +0100
12760 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/signal_cmd.h      2010-11-23 02:09:41.000000000 +0100
12761 @@ -0,0 +1,43 @@
12762 +#ifndef _VX_SIGNAL_CMD_H
12763 +#define _VX_SIGNAL_CMD_H
12764 +
12765 +
12766 +/*  signalling vserver commands */
12767 +
12768 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12769 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12770 +
12771 +struct vcmd_ctx_kill_v0 {
12772 +       int32_t pid;
12773 +       int32_t sig;
12774 +};
12775 +
12776 +struct vcmd_wait_exit_v0 {
12777 +       int32_t reboot_cmd;
12778 +       int32_t exit_code;
12779 +};
12780 +
12781 +#ifdef __KERNEL__
12782 +
12783 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12784 +extern int vc_wait_exit(struct vx_info *, void __user *);
12785 +
12786 +#endif /* __KERNEL__ */
12787 +
12788 +/*  process alteration commands */
12789 +
12790 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12791 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12792 +
12793 +struct vcmd_pflags_v0 {
12794 +       uint32_t flagword;
12795 +       uint32_t mask;
12796 +};
12797 +
12798 +#ifdef __KERNEL__
12799 +
12800 +extern int vc_get_pflags(uint32_t pid, void __user *);
12801 +extern int vc_set_pflags(uint32_t pid, void __user *);
12802 +
12803 +#endif /* __KERNEL__ */
12804 +#endif /* _VX_SIGNAL_CMD_H */
12805 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/signal.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/signal.h
12806 --- linux-2.6.37/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
12807 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/signal.h  2010-11-23 02:09:41.000000000 +0100
12808 @@ -0,0 +1,14 @@
12809 +#ifndef _VX_SIGNAL_H
12810 +#define _VX_SIGNAL_H
12811 +
12812 +
12813 +#ifdef __KERNEL__
12814 +
12815 +struct vx_info;
12816 +
12817 +int vx_info_kill(struct vx_info *, int, int);
12818 +
12819 +#endif /* __KERNEL__ */
12820 +#else  /* _VX_SIGNAL_H */
12821 +#warning duplicate inclusion
12822 +#endif /* _VX_SIGNAL_H */
12823 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/space_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/space_cmd.h
12824 --- linux-2.6.37/include/linux/vserver/space_cmd.h      1970-01-01 01:00:00.000000000 +0100
12825 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/space_cmd.h       2010-11-23 02:09:41.000000000 +0100
12826 @@ -0,0 +1,38 @@
12827 +#ifndef _VX_SPACE_CMD_H
12828 +#define _VX_SPACE_CMD_H
12829 +
12830 +
12831 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12832 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12833 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12834 +
12835 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12836 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12837 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12838 +
12839 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12840 +
12841 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12842 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12843 +
12844 +
12845 +struct vcmd_space_mask_v1 {
12846 +       uint64_t mask;
12847 +};
12848 +
12849 +struct vcmd_space_mask_v2 {
12850 +       uint64_t mask;
12851 +       uint32_t index;
12852 +};
12853 +
12854 +
12855 +#ifdef __KERNEL__
12856 +
12857 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12858 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12859 +extern int vc_enter_space(struct vx_info *, void __user *);
12860 +extern int vc_set_space(struct vx_info *, void __user *);
12861 +extern int vc_get_space_mask(void __user *, int);
12862 +
12863 +#endif /* __KERNEL__ */
12864 +#endif /* _VX_SPACE_CMD_H */
12865 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/space.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/space.h
12866 --- linux-2.6.37/include/linux/vserver/space.h  1970-01-01 01:00:00.000000000 +0100
12867 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/space.h   2010-11-23 02:09:41.000000000 +0100
12868 @@ -0,0 +1,12 @@
12869 +#ifndef _VX_SPACE_H
12870 +#define _VX_SPACE_H
12871 +
12872 +#include <linux/types.h>
12873 +
12874 +struct vx_info;
12875 +
12876 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12877 +
12878 +#else  /* _VX_SPACE_H */
12879 +#warning duplicate inclusion
12880 +#endif /* _VX_SPACE_H */
12881 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/switch.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/switch.h
12882 --- linux-2.6.37/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
12883 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/switch.h  2010-11-23 02:09:41.000000000 +0100
12884 @@ -0,0 +1,98 @@
12885 +#ifndef _VX_SWITCH_H
12886 +#define _VX_SWITCH_H
12887 +
12888 +#include <linux/types.h>
12889 +
12890 +
12891 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12892 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12893 +#define VC_VERSION(c)          ((c) & 0xFFF)
12894 +
12895 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12896 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12897 +
12898 +/*
12899 +
12900 +  Syscall Matrix V2.8
12901 +
12902 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12903 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12904 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12905 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12906 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12907 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12908 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12909 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12910 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12911 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12912 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12913 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12914 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12915 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12916 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12917 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12918 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12919 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12920 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12921 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12922 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12923 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12924 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12925 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12926 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12927 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12928 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12929 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12930 +
12931 +*/
12932 +
12933 +#define VC_CAT_VERSION         0
12934 +
12935 +#define VC_CAT_VSETUP          1
12936 +#define VC_CAT_VHOST           2
12937 +
12938 +#define VC_CAT_DEVICE          6
12939 +
12940 +#define VC_CAT_VPROC           9
12941 +#define VC_CAT_PROCALT         10
12942 +#define VC_CAT_PROCMIG         11
12943 +#define VC_CAT_PROCTRL         12
12944 +
12945 +#define VC_CAT_SCHED           14
12946 +#define VC_CAT_MEMCTRL         20
12947 +
12948 +#define VC_CAT_VNET            25
12949 +#define VC_CAT_NETALT          26
12950 +#define VC_CAT_NETMIG          27
12951 +#define VC_CAT_NETCTRL         28
12952 +
12953 +#define VC_CAT_TAGMIG          35
12954 +#define VC_CAT_DLIMIT          36
12955 +#define VC_CAT_INODE           38
12956 +
12957 +#define VC_CAT_VSTAT           40
12958 +#define VC_CAT_VINFO           46
12959 +#define VC_CAT_EVENT           48
12960 +
12961 +#define VC_CAT_FLAGS           52
12962 +#define VC_CAT_VSPACE          54
12963 +#define VC_CAT_DEBUG           56
12964 +#define VC_CAT_RLIMIT          60
12965 +
12966 +#define VC_CAT_SYSTEST         61
12967 +#define VC_CAT_COMPAT          63
12968 +
12969 +/*  query version */
12970 +
12971 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12972 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12973 +
12974 +
12975 +#ifdef __KERNEL__
12976 +
12977 +#include <linux/errno.h>
12978 +
12979 +#endif /* __KERNEL__ */
12980 +
12981 +#endif /* _VX_SWITCH_H */
12982 +
12983 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/tag_cmd.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/tag_cmd.h
12984 --- linux-2.6.37/include/linux/vserver/tag_cmd.h        1970-01-01 01:00:00.000000000 +0100
12985 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/tag_cmd.h 2010-11-23 02:09:41.000000000 +0100
12986 @@ -0,0 +1,22 @@
12987 +#ifndef _VX_TAG_CMD_H
12988 +#define _VX_TAG_CMD_H
12989 +
12990 +
12991 +/* vinfo commands */
12992 +
12993 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
12994 +
12995 +#ifdef __KERNEL__
12996 +extern int vc_task_tag(uint32_t);
12997 +
12998 +#endif /* __KERNEL__ */
12999 +
13000 +/* context commands */
13001 +
13002 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13003 +
13004 +#ifdef __KERNEL__
13005 +extern int vc_tag_migrate(uint32_t);
13006 +
13007 +#endif /* __KERNEL__ */
13008 +#endif /* _VX_TAG_CMD_H */
13009 diff -NurpP --minimal linux-2.6.37/include/linux/vserver/tag.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/tag.h
13010 --- linux-2.6.37/include/linux/vserver/tag.h    1970-01-01 01:00:00.000000000 +0100
13011 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vserver/tag.h     2010-11-23 02:09:41.000000000 +0100
13012 @@ -0,0 +1,143 @@
13013 +#ifndef _DX_TAG_H
13014 +#define _DX_TAG_H
13015 +
13016 +#include <linux/types.h>
13017 +
13018 +
13019 +#define DX_TAG(in)     (IS_TAGGED(in))
13020 +
13021 +
13022 +#ifdef CONFIG_TAG_NFSD
13023 +#define DX_TAG_NFSD    1
13024 +#else
13025 +#define DX_TAG_NFSD    0
13026 +#endif
13027 +
13028 +
13029 +#ifdef CONFIG_TAGGING_NONE
13030 +
13031 +#define MAX_UID                0xFFFFFFFF
13032 +#define MAX_GID                0xFFFFFFFF
13033 +
13034 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13035 +
13036 +#define TAGINO_UID(cond, uid, tag)     (uid)
13037 +#define TAGINO_GID(cond, gid, tag)     (gid)
13038 +
13039 +#endif
13040 +
13041 +
13042 +#ifdef CONFIG_TAGGING_GID16
13043 +
13044 +#define MAX_UID                0xFFFFFFFF
13045 +#define MAX_GID                0x0000FFFF
13046 +
13047 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13048 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13049 +
13050 +#define TAGINO_UID(cond, uid, tag)     (uid)
13051 +#define TAGINO_GID(cond, gid, tag)     \
13052 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13053 +
13054 +#endif
13055 +
13056 +
13057 +#ifdef CONFIG_TAGGING_ID24
13058 +
13059 +#define MAX_UID                0x00FFFFFF
13060 +#define MAX_GID                0x00FFFFFF
13061 +
13062 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13063 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13064 +
13065 +#define TAGINO_UID(cond, uid, tag)     \
13066 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13067 +#define TAGINO_GID(cond, gid, tag)     \
13068 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13069 +
13070 +#endif
13071 +
13072 +
13073 +#ifdef CONFIG_TAGGING_UID16
13074 +
13075 +#define MAX_UID                0x0000FFFF
13076 +#define MAX_GID                0xFFFFFFFF
13077 +
13078 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13079 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13080 +
13081 +#define TAGINO_UID(cond, uid, tag)     \
13082 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13083 +#define TAGINO_GID(cond, gid, tag)     (gid)
13084 +
13085 +#endif
13086 +
13087 +
13088 +#ifdef CONFIG_TAGGING_INTERN
13089 +
13090 +#define MAX_UID                0xFFFFFFFF
13091 +#define MAX_GID                0xFFFFFFFF
13092 +
13093 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13094 +       ((cond) ? (tag) : 0)
13095 +
13096 +#define TAGINO_UID(cond, uid, tag)     (uid)
13097 +#define TAGINO_GID(cond, gid, tag)     (gid)
13098 +
13099 +#endif
13100 +
13101 +
13102 +#ifndef CONFIG_TAGGING_NONE
13103 +#define dx_current_fstag(sb)   \
13104 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13105 +#else
13106 +#define dx_current_fstag(sb)   (0)
13107 +#endif
13108 +
13109 +#ifndef CONFIG_TAGGING_INTERN
13110 +#define TAGINO_TAG(cond, tag)  (0)
13111 +#else
13112 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13113 +#endif
13114 +
13115 +#define INOTAG_UID(cond, uid, gid)     \
13116 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13117 +#define INOTAG_GID(cond, uid, gid)     \
13118 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13119 +
13120 +
13121 +static inline uid_t dx_map_uid(uid_t uid)
13122 +{
13123 +       if ((uid > MAX_UID) && (uid != -1))
13124 +               uid = -2;
13125 +       return (uid & MAX_UID);
13126 +}
13127 +
13128 +static inline gid_t dx_map_gid(gid_t gid)
13129 +{
13130 +       if ((gid > MAX_GID) && (gid != -1))
13131 +               gid = -2;
13132 +       return (gid & MAX_GID);
13133 +}
13134 +
13135 +struct peer_tag {
13136 +       int32_t xid;
13137 +       int32_t nid;
13138 +};
13139 +
13140 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13141 +
13142 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13143 +                unsigned long *flags);
13144 +
13145 +#ifdef CONFIG_PROPAGATE
13146 +
13147 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13148 +
13149 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13150 +
13151 +#else
13152 +#define dx_propagate_tag(n, i) do { } while (0)
13153 +#endif
13154 +
13155 +#endif /* _DX_TAG_H */
13156 diff -NurpP --minimal linux-2.6.37/include/linux/vs_inet6.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_inet6.h
13157 --- linux-2.6.37/include/linux/vs_inet6.h       1970-01-01 01:00:00.000000000 +0100
13158 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_inet6.h        2010-11-23 02:09:41.000000000 +0100
13159 @@ -0,0 +1,246 @@
13160 +#ifndef _VS_INET6_H
13161 +#define _VS_INET6_H
13162 +
13163 +#include "vserver/base.h"
13164 +#include "vserver/network.h"
13165 +#include "vserver/debug.h"
13166 +
13167 +#include <net/ipv6.h>
13168 +
13169 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13170 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13171 +
13172 +
13173 +#ifdef CONFIG_IPV6
13174 +
13175 +static inline
13176 +int v6_addr_match(struct nx_addr_v6 *nxa,
13177 +       const struct in6_addr *addr, uint16_t mask)
13178 +{
13179 +       int ret = 0;
13180 +
13181 +       switch (nxa->type & mask) {
13182 +       case NXA_TYPE_MASK:
13183 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13184 +               break;
13185 +       case NXA_TYPE_ADDR:
13186 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13187 +               break;
13188 +       case NXA_TYPE_ANY:
13189 +               ret = 1;
13190 +               break;
13191 +       }
13192 +       vxdprintk(VXD_CBIT(net, 0),
13193 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13194 +               nxa, NXAV6(nxa), addr, mask, ret);
13195 +       return ret;
13196 +}
13197 +
13198 +static inline
13199 +int v6_addr_in_nx_info(struct nx_info *nxi,
13200 +       const struct in6_addr *addr, uint16_t mask)
13201 +{
13202 +       struct nx_addr_v6 *nxa;
13203 +       int ret = 1;
13204 +
13205 +       if (!nxi)
13206 +               goto out;
13207 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13208 +               if (v6_addr_match(nxa, addr, mask))
13209 +                       goto out;
13210 +       ret = 0;
13211 +out:
13212 +       vxdprintk(VXD_CBIT(net, 0),
13213 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13214 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13215 +       return ret;
13216 +}
13217 +
13218 +static inline
13219 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13220 +{
13221 +       /* FIXME: needs full range checks */
13222 +       return v6_addr_match(nxa, &addr->ip, mask);
13223 +}
13224 +
13225 +static inline
13226 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13227 +{
13228 +       struct nx_addr_v6 *ptr;
13229 +
13230 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13231 +               if (v6_nx_addr_match(ptr, nxa, mask))
13232 +                       return 1;
13233 +       return 0;
13234 +}
13235 +
13236 +
13237 +/*
13238 + *     Check if a given address matches for a socket
13239 + *
13240 + *     nxi:            the socket's nx_info if any
13241 + *     addr:           to be verified address
13242 + */
13243 +static inline
13244 +int v6_sock_addr_match (
13245 +       struct nx_info *nxi,
13246 +       struct inet_sock *inet,
13247 +       struct in6_addr *addr)
13248 +{
13249 +       struct sock *sk = &inet->sk;
13250 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13251 +
13252 +       if (!ipv6_addr_any(addr) &&
13253 +               ipv6_addr_equal(saddr, addr))
13254 +               return 1;
13255 +       if (ipv6_addr_any(saddr))
13256 +               return v6_addr_in_nx_info(nxi, addr, -1);
13257 +       return 0;
13258 +}
13259 +
13260 +/*
13261 + *     check if address is covered by socket
13262 + *
13263 + *     sk:     the socket to check against
13264 + *     addr:   the address in question (must be != 0)
13265 + */
13266 +
13267 +static inline
13268 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13269 +{
13270 +       struct nx_info *nxi = sk->sk_nx_info;
13271 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13272 +
13273 +       vxdprintk(VXD_CBIT(net, 5),
13274 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13275 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13276 +               (sk->sk_socket?sk->sk_socket->flags:0));
13277 +
13278 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13279 +               return v6_addr_match(nxa, saddr, -1);
13280 +       } else if (nxi) {               /* match against nx_info */
13281 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13282 +       } else {                        /* unrestricted any socket */
13283 +               return 1;
13284 +       }
13285 +}
13286 +
13287 +
13288 +/* inet related checks and helpers */
13289 +
13290 +
13291 +struct in_ifaddr;
13292 +struct net_device;
13293 +struct sock;
13294 +
13295 +
13296 +#include <linux/netdevice.h>
13297 +#include <linux/inetdevice.h>
13298 +#include <net/inet_timewait_sock.h>
13299 +
13300 +
13301 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13302 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13303 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13304 +
13305 +
13306 +
13307 +static inline
13308 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13309 +{
13310 +       if (!nxi)
13311 +               return 1;
13312 +       if (!ifa)
13313 +               return 0;
13314 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13315 +}
13316 +
13317 +static inline
13318 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13319 +{
13320 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13321 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13322 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13323 +
13324 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13325 +               return 1;
13326 +       if (v6_ifa_in_nx_info(ifa, nxi))
13327 +               return 1;
13328 +       return 0;
13329 +}
13330 +
13331 +
13332 +struct nx_v6_sock_addr {
13333 +       struct in6_addr saddr;  /* Address used for validation */
13334 +       struct in6_addr baddr;  /* Address used for socket bind */
13335 +};
13336 +
13337 +static inline
13338 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13339 +       struct nx_v6_sock_addr *nsa)
13340 +{
13341 +       // struct sock *sk = &inet->sk;
13342 +       // struct nx_info *nxi = sk->sk_nx_info;
13343 +       struct in6_addr saddr = addr->sin6_addr;
13344 +       struct in6_addr baddr = saddr;
13345 +
13346 +       nsa->saddr = saddr;
13347 +       nsa->baddr = baddr;
13348 +       return 0;
13349 +}
13350 +
13351 +static inline
13352 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13353 +{
13354 +       // struct sock *sk = &inet->sk;
13355 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13356 +
13357 +       // *saddr = nsa->baddr;
13358 +       // inet->inet_saddr = nsa->baddr;
13359 +}
13360 +
13361 +static inline
13362 +int nx_info_has_v6(struct nx_info *nxi)
13363 +{
13364 +       if (!nxi)
13365 +               return 1;
13366 +       if (NX_IPV6(nxi))
13367 +               return 1;
13368 +       return 0;
13369 +}
13370 +
13371 +#else /* CONFIG_IPV6 */
13372 +
13373 +static inline
13374 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13375 +{
13376 +       return 1;
13377 +}
13378 +
13379 +
13380 +static inline
13381 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13382 +{
13383 +       return 1;
13384 +}
13385 +
13386 +static inline
13387 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13388 +{
13389 +       return 1;
13390 +}
13391 +
13392 +static inline
13393 +int nx_info_has_v6(struct nx_info *nxi)
13394 +{
13395 +       return 0;
13396 +}
13397 +
13398 +#endif /* CONFIG_IPV6 */
13399 +
13400 +#define current_nx_info_has_v6() \
13401 +       nx_info_has_v6(current_nx_info())
13402 +
13403 +#else
13404 +#warning duplicate inclusion
13405 +#endif
13406 diff -NurpP --minimal linux-2.6.37/include/linux/vs_inet.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_inet.h
13407 --- linux-2.6.37/include/linux/vs_inet.h        1970-01-01 01:00:00.000000000 +0100
13408 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_inet.h 2010-11-23 02:09:41.000000000 +0100
13409 @@ -0,0 +1,351 @@
13410 +#ifndef _VS_INET_H
13411 +#define _VS_INET_H
13412 +
13413 +#include "vserver/base.h"
13414 +#include "vserver/network.h"
13415 +#include "vserver/debug.h"
13416 +
13417 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13418 +
13419 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13420 +                       NIPQUAD((a)->mask), (a)->type
13421 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13422 +
13423 +#define NIPQUAD(addr) \
13424 +       ((unsigned char *)&addr)[0], \
13425 +       ((unsigned char *)&addr)[1], \
13426 +       ((unsigned char *)&addr)[2], \
13427 +       ((unsigned char *)&addr)[3]
13428 +
13429 +#define NIPQUAD_FMT "%u.%u.%u.%u"
13430 +
13431 +
13432 +static inline
13433 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13434 +{
13435 +       __be32 ip = nxa->ip[0].s_addr;
13436 +       __be32 mask = nxa->mask.s_addr;
13437 +       __be32 bcast = ip | ~mask;
13438 +       int ret = 0;
13439 +
13440 +       switch (nxa->type & tmask) {
13441 +       case NXA_TYPE_MASK:
13442 +               ret = (ip == (addr & mask));
13443 +               break;
13444 +       case NXA_TYPE_ADDR:
13445 +               ret = 3;
13446 +               if (addr == ip)
13447 +                       break;
13448 +               /* fall through to broadcast */
13449 +       case NXA_MOD_BCAST:
13450 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13451 +               break;
13452 +       case NXA_TYPE_RANGE:
13453 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13454 +                       (nxa->ip[1].s_addr > addr));
13455 +               break;
13456 +       case NXA_TYPE_ANY:
13457 +               ret = 2;
13458 +               break;
13459 +       }
13460 +
13461 +       vxdprintk(VXD_CBIT(net, 0),
13462 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13463 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13464 +       return ret;
13465 +}
13466 +
13467 +static inline
13468 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13469 +{
13470 +       struct nx_addr_v4 *nxa;
13471 +       int ret = 1;
13472 +
13473 +       if (!nxi)
13474 +               goto out;
13475 +
13476 +       ret = 2;
13477 +       /* allow 127.0.0.1 when remapping lback */
13478 +       if ((tmask & NXA_LOOPBACK) &&
13479 +               (addr == IPI_LOOPBACK) &&
13480 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13481 +               goto out;
13482 +       ret = 3;
13483 +       /* check for lback address */
13484 +       if ((tmask & NXA_MOD_LBACK) &&
13485 +               (nxi->v4_lback.s_addr == addr))
13486 +               goto out;
13487 +       ret = 4;
13488 +       /* check for broadcast address */
13489 +       if ((tmask & NXA_MOD_BCAST) &&
13490 +               (nxi->v4_bcast.s_addr == addr))
13491 +               goto out;
13492 +       ret = 5;
13493 +       /* check for v4 addresses */
13494 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13495 +               if (v4_addr_match(nxa, addr, tmask))
13496 +                       goto out;
13497 +       ret = 0;
13498 +out:
13499 +       vxdprintk(VXD_CBIT(net, 0),
13500 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13501 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13502 +       return ret;
13503 +}
13504 +
13505 +static inline
13506 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13507 +{
13508 +       /* FIXME: needs full range checks */
13509 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13510 +}
13511 +
13512 +static inline
13513 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13514 +{
13515 +       struct nx_addr_v4 *ptr;
13516 +
13517 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13518 +               if (v4_nx_addr_match(ptr, nxa, mask))
13519 +                       return 1;
13520 +       return 0;
13521 +}
13522 +
13523 +#include <net/inet_sock.h>
13524 +
13525 +/*
13526 + *     Check if a given address matches for a socket
13527 + *
13528 + *     nxi:            the socket's nx_info if any
13529 + *     addr:           to be verified address
13530 + */
13531 +static inline
13532 +int v4_sock_addr_match (
13533 +       struct nx_info *nxi,
13534 +       struct inet_sock *inet,
13535 +       __be32 addr)
13536 +{
13537 +       __be32 saddr = inet->inet_rcv_saddr;
13538 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13539 +
13540 +       if (addr && (saddr == addr || bcast == addr))
13541 +               return 1;
13542 +       if (!saddr)
13543 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13544 +       return 0;
13545 +}
13546 +
13547 +
13548 +/* inet related checks and helpers */
13549 +
13550 +
13551 +struct in_ifaddr;
13552 +struct net_device;
13553 +struct sock;
13554 +
13555 +#ifdef CONFIG_INET
13556 +
13557 +#include <linux/netdevice.h>
13558 +#include <linux/inetdevice.h>
13559 +#include <net/inet_sock.h>
13560 +#include <net/inet_timewait_sock.h>
13561 +
13562 +
13563 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13564 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13565 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13566 +
13567 +
13568 +/*
13569 + *     check if address is covered by socket
13570 + *
13571 + *     sk:     the socket to check against
13572 + *     addr:   the address in question (must be != 0)
13573 + */
13574 +
13575 +static inline
13576 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13577 +{
13578 +       struct nx_info *nxi = sk->sk_nx_info;
13579 +       __be32 saddr = inet_rcv_saddr(sk);
13580 +
13581 +       vxdprintk(VXD_CBIT(net, 5),
13582 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13583 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13584 +               (sk->sk_socket?sk->sk_socket->flags:0));
13585 +
13586 +       if (saddr) {            /* direct address match */
13587 +               return v4_addr_match(nxa, saddr, -1);
13588 +       } else if (nxi) {       /* match against nx_info */
13589 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13590 +       } else {                /* unrestricted any socket */
13591 +               return 1;
13592 +       }
13593 +}
13594 +
13595 +
13596 +
13597 +static inline
13598 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13599 +{
13600 +       vxdprintk(VXD_CBIT(net, 1),
13601 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
13602 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13603 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13604 +
13605 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13606 +               return 1;
13607 +       if (dev_in_nx_info(dev, nxi))
13608 +               return 1;
13609 +       return 0;
13610 +}
13611 +
13612 +
13613 +static inline
13614 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13615 +{
13616 +       if (!nxi)
13617 +               return 1;
13618 +       if (!ifa)
13619 +               return 0;
13620 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13621 +}
13622 +
13623 +static inline
13624 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13625 +{
13626 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13627 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13628 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13629 +
13630 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13631 +               return 1;
13632 +       if (v4_ifa_in_nx_info(ifa, nxi))
13633 +               return 1;
13634 +       return 0;
13635 +}
13636 +
13637 +
13638 +struct nx_v4_sock_addr {
13639 +       __be32 saddr;   /* Address used for validation */
13640 +       __be32 baddr;   /* Address used for socket bind */
13641 +};
13642 +
13643 +static inline
13644 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13645 +       struct nx_v4_sock_addr *nsa)
13646 +{
13647 +       struct sock *sk = &inet->sk;
13648 +       struct nx_info *nxi = sk->sk_nx_info;
13649 +       __be32 saddr = addr->sin_addr.s_addr;
13650 +       __be32 baddr = saddr;
13651 +
13652 +       vxdprintk(VXD_CBIT(net, 3),
13653 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13654 +               sk, sk->sk_nx_info, sk->sk_socket,
13655 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13656 +               NIPQUAD(saddr));
13657 +
13658 +       if (nxi) {
13659 +               if (saddr == INADDR_ANY) {
13660 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13661 +                               baddr = nxi->v4.ip[0].s_addr;
13662 +               } else if (saddr == IPI_LOOPBACK) {
13663 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13664 +                               baddr = nxi->v4_lback.s_addr;
13665 +               } else {        /* normal address bind */
13666 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13667 +                               return -EADDRNOTAVAIL;
13668 +               }
13669 +       }
13670 +
13671 +       vxdprintk(VXD_CBIT(net, 3),
13672 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13673 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13674 +
13675 +       nsa->saddr = saddr;
13676 +       nsa->baddr = baddr;
13677 +       return 0;
13678 +}
13679 +
13680 +static inline
13681 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13682 +{
13683 +       inet->inet_saddr = nsa->baddr;
13684 +       inet->inet_rcv_saddr = nsa->baddr;
13685 +}
13686 +
13687 +
13688 +/*
13689 + *      helper to simplify inet_lookup_listener
13690 + *
13691 + *      nxi:   the socket's nx_info if any
13692 + *      addr:  to be verified address
13693 + *      saddr: socket address
13694 + */
13695 +static inline int v4_inet_addr_match (
13696 +       struct nx_info *nxi,
13697 +       __be32 addr,
13698 +       __be32 saddr)
13699 +{
13700 +       if (addr && (saddr == addr))
13701 +               return 1;
13702 +       if (!saddr)
13703 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13704 +       return 0;
13705 +}
13706 +
13707 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13708 +{
13709 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13710 +               (addr == nxi->v4_lback.s_addr))
13711 +               return IPI_LOOPBACK;
13712 +       return addr;
13713 +}
13714 +
13715 +static inline
13716 +int nx_info_has_v4(struct nx_info *nxi)
13717 +{
13718 +       if (!nxi)
13719 +               return 1;
13720 +       if (NX_IPV4(nxi))
13721 +               return 1;
13722 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13723 +               return 1;
13724 +       return 0;
13725 +}
13726 +
13727 +#else /* CONFIG_INET */
13728 +
13729 +static inline
13730 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13731 +{
13732 +       return 1;
13733 +}
13734 +
13735 +static inline
13736 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13737 +{
13738 +       return 1;
13739 +}
13740 +
13741 +static inline
13742 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13743 +{
13744 +       return 1;
13745 +}
13746 +
13747 +static inline
13748 +int nx_info_has_v4(struct nx_info *nxi)
13749 +{
13750 +       return 0;
13751 +}
13752 +
13753 +#endif /* CONFIG_INET */
13754 +
13755 +#define current_nx_info_has_v4() \
13756 +       nx_info_has_v4(current_nx_info())
13757 +
13758 +#else
13759 +// #warning duplicate inclusion
13760 +#endif
13761 diff -NurpP --minimal linux-2.6.37/include/linux/vs_limit.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_limit.h
13762 --- linux-2.6.37/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
13763 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_limit.h        2010-11-23 02:09:41.000000000 +0100
13764 @@ -0,0 +1,140 @@
13765 +#ifndef _VS_LIMIT_H
13766 +#define _VS_LIMIT_H
13767 +
13768 +#include "vserver/limit.h"
13769 +#include "vserver/base.h"
13770 +#include "vserver/context.h"
13771 +#include "vserver/debug.h"
13772 +#include "vserver/context.h"
13773 +#include "vserver/limit_int.h"
13774 +
13775 +
13776 +#define vx_acc_cres(v, d, p, r) \
13777 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13778 +
13779 +#define vx_acc_cres_cond(x, d, p, r) \
13780 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13781 +       r, d, p, __FILE__, __LINE__)
13782 +
13783 +
13784 +#define vx_add_cres(v, a, p, r) \
13785 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13786 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13787 +
13788 +#define vx_add_cres_cond(x, a, p, r) \
13789 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13790 +       r, a, p, __FILE__, __LINE__)
13791 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13792 +
13793 +
13794 +/* process and file limits */
13795 +
13796 +#define vx_nproc_inc(p) \
13797 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13798 +
13799 +#define vx_nproc_dec(p) \
13800 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13801 +
13802 +#define vx_files_inc(f) \
13803 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13804 +
13805 +#define vx_files_dec(f) \
13806 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13807 +
13808 +#define vx_locks_inc(l) \
13809 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13810 +
13811 +#define vx_locks_dec(l) \
13812 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13813 +
13814 +#define vx_openfd_inc(f) \
13815 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13816 +
13817 +#define vx_openfd_dec(f) \
13818 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
13819 +
13820 +
13821 +#define vx_cres_avail(v, n, r) \
13822 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13823 +
13824 +
13825 +#define vx_nproc_avail(n) \
13826 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
13827 +
13828 +#define vx_files_avail(n) \
13829 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
13830 +
13831 +#define vx_locks_avail(n) \
13832 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
13833 +
13834 +#define vx_openfd_avail(n) \
13835 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
13836 +
13837 +
13838 +/* dentry limits */
13839 +
13840 +#define vx_dentry_inc(d) do {                                          \
13841 +       if (atomic_read(&d->d_count) == 1)                              \
13842 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
13843 +       } while (0)
13844 +
13845 +#define vx_dentry_dec(d) do {                                          \
13846 +       if (atomic_read(&d->d_count) == 0)                              \
13847 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
13848 +       } while (0)
13849 +
13850 +#define vx_dentry_avail(n) \
13851 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
13852 +
13853 +
13854 +/* socket limits */
13855 +
13856 +#define vx_sock_inc(s) \
13857 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13858 +
13859 +#define vx_sock_dec(s) \
13860 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13861 +
13862 +#define vx_sock_avail(n) \
13863 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
13864 +
13865 +
13866 +/* ipc resource limits */
13867 +
13868 +#define vx_ipcmsg_add(v, u, a) \
13869 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13870 +
13871 +#define vx_ipcmsg_sub(v, u, a) \
13872 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13873 +
13874 +#define vx_ipcmsg_avail(v, a) \
13875 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13876 +
13877 +
13878 +#define vx_ipcshm_add(v, k, a) \
13879 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13880 +
13881 +#define vx_ipcshm_sub(v, k, a) \
13882 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13883 +
13884 +#define vx_ipcshm_avail(v, a) \
13885 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13886 +
13887 +
13888 +#define vx_semary_inc(a) \
13889 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
13890 +
13891 +#define vx_semary_dec(a) \
13892 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
13893 +
13894 +
13895 +#define vx_nsems_add(a,n) \
13896 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
13897 +
13898 +#define vx_nsems_sub(a,n) \
13899 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
13900 +
13901 +
13902 +#else
13903 +#warning duplicate inclusion
13904 +#endif
13905 diff -NurpP --minimal linux-2.6.37/include/linux/vs_memory.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_memory.h
13906 --- linux-2.6.37/include/linux/vs_memory.h      1970-01-01 01:00:00.000000000 +0100
13907 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_memory.h       2010-11-23 02:09:41.000000000 +0100
13908 @@ -0,0 +1,58 @@
13909 +#ifndef _VS_MEMORY_H
13910 +#define _VS_MEMORY_H
13911 +
13912 +#include "vserver/limit.h"
13913 +#include "vserver/base.h"
13914 +#include "vserver/context.h"
13915 +#include "vserver/debug.h"
13916 +#include "vserver/context.h"
13917 +#include "vserver/limit_int.h"
13918 +
13919 +enum {
13920 +       VXPT_UNKNOWN = 0,
13921 +       VXPT_ANON,
13922 +       VXPT_NONE,
13923 +       VXPT_FILE,
13924 +       VXPT_SWAP,
13925 +       VXPT_WRITE
13926 +};
13927 +
13928 +#if 0
13929 +#define        vx_page_fault(mm, vma, type, ret)
13930 +#else
13931 +
13932 +static inline
13933 +void __vx_page_fault(struct mm_struct *mm,
13934 +       struct vm_area_struct *vma, int type, int ret)
13935 +{
13936 +       struct vx_info *vxi = mm->mm_vx_info;
13937 +       int what;
13938 +/*
13939 +       static char *page_type[6] =
13940 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
13941 +       static char *page_what[4] =
13942 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
13943 +*/
13944 +
13945 +       if (!vxi)
13946 +               return;
13947 +
13948 +       what = (ret & 0x3);
13949 +
13950 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
13951 +               type, what, ret, page_type[type], page_what[what]);
13952 +*/
13953 +       if (ret & VM_FAULT_WRITE)
13954 +               what |= 0x4;
13955 +       atomic_inc(&vxi->cacct.page[type][what]);
13956 +}
13957 +
13958 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
13959 +#endif
13960 +
13961 +
13962 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
13963 +
13964 +#else
13965 +#warning duplicate inclusion
13966 +#endif
13967 diff -NurpP --minimal linux-2.6.37/include/linux/vs_network.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_network.h
13968 --- linux-2.6.37/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
13969 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_network.h      2010-11-23 02:09:41.000000000 +0100
13970 @@ -0,0 +1,169 @@
13971 +#ifndef _NX_VS_NETWORK_H
13972 +#define _NX_VS_NETWORK_H
13973 +
13974 +#include "vserver/context.h"
13975 +#include "vserver/network.h"
13976 +#include "vserver/base.h"
13977 +#include "vserver/check.h"
13978 +#include "vserver/debug.h"
13979 +
13980 +#include <linux/sched.h>
13981 +
13982 +
13983 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
13984 +
13985 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
13986 +       const char *_file, int _line)
13987 +{
13988 +       if (!nxi)
13989 +               return NULL;
13990 +
13991 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
13992 +               nxi, nxi ? nxi->nx_id : 0,
13993 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13994 +               _file, _line);
13995 +
13996 +       atomic_inc(&nxi->nx_usecnt);
13997 +       return nxi;
13998 +}
13999 +
14000 +
14001 +extern void free_nx_info(struct nx_info *);
14002 +
14003 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14004 +
14005 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14006 +{
14007 +       if (!nxi)
14008 +               return;
14009 +
14010 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14011 +               nxi, nxi ? nxi->nx_id : 0,
14012 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14013 +               _file, _line);
14014 +
14015 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14016 +               free_nx_info(nxi);
14017 +}
14018 +
14019 +
14020 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14021 +
14022 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14023 +               const char *_file, int _line)
14024 +{
14025 +       if (nxi) {
14026 +               vxlprintk(VXD_CBIT(nid, 3),
14027 +                       "init_nx_info(%p[#%d.%d])",
14028 +                       nxi, nxi ? nxi->nx_id : 0,
14029 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14030 +                       _file, _line);
14031 +
14032 +               atomic_inc(&nxi->nx_usecnt);
14033 +       }
14034 +       *nxp = nxi;
14035 +}
14036 +
14037 +
14038 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14039 +
14040 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14041 +       const char *_file, int _line)
14042 +{
14043 +       struct nx_info *nxo;
14044 +
14045 +       if (!nxi)
14046 +               return;
14047 +
14048 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14049 +               nxi, nxi ? nxi->nx_id : 0,
14050 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14051 +               _file, _line);
14052 +
14053 +       atomic_inc(&nxi->nx_usecnt);
14054 +       nxo = xchg(nxp, nxi);
14055 +       BUG_ON(nxo);
14056 +}
14057 +
14058 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14059 +
14060 +static inline void __clr_nx_info(struct nx_info **nxp,
14061 +       const char *_file, int _line)
14062 +{
14063 +       struct nx_info *nxo;
14064 +
14065 +       nxo = xchg(nxp, NULL);
14066 +       if (!nxo)
14067 +               return;
14068 +
14069 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14070 +               nxo, nxo ? nxo->nx_id : 0,
14071 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14072 +               _file, _line);
14073 +
14074 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14075 +               free_nx_info(nxo);
14076 +}
14077 +
14078 +
14079 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14080 +
14081 +static inline void __claim_nx_info(struct nx_info *nxi,
14082 +       struct task_struct *task, const char *_file, int _line)
14083 +{
14084 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14085 +               nxi, nxi ? nxi->nx_id : 0,
14086 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14087 +               nxi?atomic_read(&nxi->nx_tasks):0,
14088 +               task, _file, _line);
14089 +
14090 +       atomic_inc(&nxi->nx_tasks);
14091 +}
14092 +
14093 +
14094 +extern void unhash_nx_info(struct nx_info *);
14095 +
14096 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14097 +
14098 +static inline void __release_nx_info(struct nx_info *nxi,
14099 +       struct task_struct *task, const char *_file, int _line)
14100 +{
14101 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14102 +               nxi, nxi ? nxi->nx_id : 0,
14103 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14104 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14105 +               task, _file, _line);
14106 +
14107 +       might_sleep();
14108 +
14109 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14110 +               unhash_nx_info(nxi);
14111 +}
14112 +
14113 +
14114 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14115 +
14116 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14117 +       const char *_file, int _line)
14118 +{
14119 +       struct nx_info *nxi;
14120 +
14121 +       task_lock(p);
14122 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14123 +               p, _file, _line);
14124 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14125 +       task_unlock(p);
14126 +       return nxi;
14127 +}
14128 +
14129 +
14130 +static inline void exit_nx_info(struct task_struct *p)
14131 +{
14132 +       if (p->nx_info)
14133 +               release_nx_info(p->nx_info, p);
14134 +}
14135 +
14136 +
14137 +#else
14138 +#warning duplicate inclusion
14139 +#endif
14140 diff -NurpP --minimal linux-2.6.37/include/linux/vs_pid.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_pid.h
14141 --- linux-2.6.37/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
14142 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_pid.h  2010-11-23 02:09:41.000000000 +0100
14143 @@ -0,0 +1,95 @@
14144 +#ifndef _VS_PID_H
14145 +#define _VS_PID_H
14146 +
14147 +#include "vserver/base.h"
14148 +#include "vserver/check.h"
14149 +#include "vserver/context.h"
14150 +#include "vserver/debug.h"
14151 +#include "vserver/pid.h"
14152 +#include <linux/pid_namespace.h>
14153 +
14154 +
14155 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14156 +
14157 +static inline
14158 +int vx_proc_task_visible(struct task_struct *task)
14159 +{
14160 +       if ((task->pid == 1) &&
14161 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14162 +               /* show a blend through init */
14163 +               goto visible;
14164 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14165 +               goto visible;
14166 +       return 0;
14167 +visible:
14168 +       return 1;
14169 +}
14170 +
14171 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14172 +
14173 +#if 0
14174 +
14175 +static inline
14176 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14177 +{
14178 +       struct task_struct *task = find_task_by_real_pid(pid);
14179 +
14180 +       if (task && !vx_proc_task_visible(task)) {
14181 +               vxdprintk(VXD_CBIT(misc, 6),
14182 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14183 +                       task, task->xid, task->pid,
14184 +                       current, current->xid, current->pid);
14185 +               task = NULL;
14186 +       }
14187 +       return task;
14188 +}
14189 +
14190 +#endif
14191 +
14192 +static inline
14193 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14194 +{
14195 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14196 +
14197 +       if (task && !vx_proc_task_visible(task)) {
14198 +               vxdprintk(VXD_CBIT(misc, 6),
14199 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14200 +                       task, task->xid, task->pid,
14201 +                       current, current->xid, current->pid);
14202 +               put_task_struct(task);
14203 +               task = NULL;
14204 +       }
14205 +       return task;
14206 +}
14207 +
14208 +#if 0
14209 +
14210 +static inline
14211 +struct task_struct *vx_child_reaper(struct task_struct *p)
14212 +{
14213 +       struct vx_info *vxi = p->vx_info;
14214 +       struct task_struct *reaper = child_reaper(p);
14215 +
14216 +       if (!vxi)
14217 +               goto out;
14218 +
14219 +       BUG_ON(!p->vx_info->vx_reaper);
14220 +
14221 +       /* child reaper for the guest reaper */
14222 +       if (vxi->vx_reaper == p)
14223 +               goto out;
14224 +
14225 +       reaper = vxi->vx_reaper;
14226 +out:
14227 +       vxdprintk(VXD_CBIT(xid, 7),
14228 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14229 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14230 +       return reaper;
14231 +}
14232 +
14233 +#endif
14234 +
14235 +
14236 +#else
14237 +#warning duplicate inclusion
14238 +#endif
14239 diff -NurpP --minimal linux-2.6.37/include/linux/vs_sched.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_sched.h
14240 --- linux-2.6.37/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
14241 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_sched.h        2010-11-23 02:09:41.000000000 +0100
14242 @@ -0,0 +1,40 @@
14243 +#ifndef _VS_SCHED_H
14244 +#define _VS_SCHED_H
14245 +
14246 +#include "vserver/base.h"
14247 +#include "vserver/context.h"
14248 +#include "vserver/sched.h"
14249 +
14250 +
14251 +#define MAX_PRIO_BIAS           20
14252 +#define MIN_PRIO_BIAS          -20
14253 +
14254 +static inline
14255 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14256 +{
14257 +       struct vx_info *vxi = p->vx_info;
14258 +
14259 +       if (vxi)
14260 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14261 +       return prio;
14262 +}
14263 +
14264 +static inline void vx_account_user(struct vx_info *vxi,
14265 +       cputime_t cputime, int nice)
14266 +{
14267 +       if (!vxi)
14268 +               return;
14269 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14270 +}
14271 +
14272 +static inline void vx_account_system(struct vx_info *vxi,
14273 +       cputime_t cputime, int idle)
14274 +{
14275 +       if (!vxi)
14276 +               return;
14277 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14278 +}
14279 +
14280 +#else
14281 +#warning duplicate inclusion
14282 +#endif
14283 diff -NurpP --minimal linux-2.6.37/include/linux/vs_socket.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_socket.h
14284 --- linux-2.6.37/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
14285 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_socket.h       2010-11-23 02:09:41.000000000 +0100
14286 @@ -0,0 +1,67 @@
14287 +#ifndef _VS_SOCKET_H
14288 +#define _VS_SOCKET_H
14289 +
14290 +#include "vserver/debug.h"
14291 +#include "vserver/base.h"
14292 +#include "vserver/cacct.h"
14293 +#include "vserver/context.h"
14294 +#include "vserver/tag.h"
14295 +
14296 +
14297 +/* socket accounting */
14298 +
14299 +#include <linux/socket.h>
14300 +
14301 +static inline int vx_sock_type(int family)
14302 +{
14303 +       switch (family) {
14304 +       case PF_UNSPEC:
14305 +               return VXA_SOCK_UNSPEC;
14306 +       case PF_UNIX:
14307 +               return VXA_SOCK_UNIX;
14308 +       case PF_INET:
14309 +               return VXA_SOCK_INET;
14310 +       case PF_INET6:
14311 +               return VXA_SOCK_INET6;
14312 +       case PF_PACKET:
14313 +               return VXA_SOCK_PACKET;
14314 +       default:
14315 +               return VXA_SOCK_OTHER;
14316 +       }
14317 +}
14318 +
14319 +#define vx_acc_sock(v, f, p, s) \
14320 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14321 +
14322 +static inline void __vx_acc_sock(struct vx_info *vxi,
14323 +       int family, int pos, int size, char *file, int line)
14324 +{
14325 +       if (vxi) {
14326 +               int type = vx_sock_type(family);
14327 +
14328 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14329 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14330 +       }
14331 +}
14332 +
14333 +#define vx_sock_recv(sk, s) \
14334 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14335 +#define vx_sock_send(sk, s) \
14336 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14337 +#define vx_sock_fail(sk, s) \
14338 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14339 +
14340 +
14341 +#define sock_vx_init(s) do {           \
14342 +       (s)->sk_xid = 0;                \
14343 +       (s)->sk_vx_info = NULL;         \
14344 +       } while (0)
14345 +
14346 +#define sock_nx_init(s) do {           \
14347 +       (s)->sk_nid = 0;                \
14348 +       (s)->sk_nx_info = NULL;         \
14349 +       } while (0)
14350 +
14351 +#else
14352 +#warning duplicate inclusion
14353 +#endif
14354 diff -NurpP --minimal linux-2.6.37/include/linux/vs_tag.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_tag.h
14355 --- linux-2.6.37/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
14356 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_tag.h  2010-11-23 02:09:41.000000000 +0100
14357 @@ -0,0 +1,47 @@
14358 +#ifndef _VS_TAG_H
14359 +#define _VS_TAG_H
14360 +
14361 +#include <linux/vserver/tag.h>
14362 +
14363 +/* check conditions */
14364 +
14365 +#define DX_ADMIN       0x0001
14366 +#define DX_WATCH       0x0002
14367 +#define DX_HOSTID      0x0008
14368 +
14369 +#define DX_IDENT       0x0010
14370 +
14371 +#define DX_ARG_MASK    0x0010
14372 +
14373 +
14374 +#define dx_task_tag(t) ((t)->tag)
14375 +
14376 +#define dx_current_tag() dx_task_tag(current)
14377 +
14378 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14379 +
14380 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14381 +
14382 +
14383 +/*
14384 + * check current context for ADMIN/WATCH and
14385 + * optionally against supplied argument
14386 + */
14387 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14388 +{
14389 +       if (mode & DX_ARG_MASK) {
14390 +               if ((mode & DX_IDENT) && (id == cid))
14391 +                       return 1;
14392 +       }
14393 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14394 +               ((mode & DX_WATCH) && (cid == 1)) ||
14395 +               ((mode & DX_HOSTID) && (id == 0)));
14396 +}
14397 +
14398 +struct inode;
14399 +int dx_permission(const struct inode *inode, int mask);
14400 +
14401 +
14402 +#else
14403 +#warning duplicate inclusion
14404 +#endif
14405 diff -NurpP --minimal linux-2.6.37/include/linux/vs_time.h linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_time.h
14406 --- linux-2.6.37/include/linux/vs_time.h        1970-01-01 01:00:00.000000000 +0100
14407 +++ linux-2.6.37-vs2.3.0.37-rc2/include/linux/vs_time.h 2010-11-23 02:09:41.000000000 +0100
14408 @@ -0,0 +1,19 @@
14409 +#ifndef _VS_TIME_H
14410 +#define _VS_TIME_H
14411 +
14412 +
14413 +/* time faking stuff */
14414 +
14415 +#ifdef CONFIG_VSERVER_VTIME
14416 +
14417 +extern void vx_adjust_timespec(struct timespec *ts);
14418 +extern int vx_settimeofday(struct timespec *ts);
14419 +
14420 +#else
14421 +#define        vx_adjust_timespec(t)   do { } while (0)
14422 +#define        vx_settimeofday(t)      do_settimeofday(t)
14423 +#endif
14424 +
14425 +#else
14426 +#warning duplicate inclusion
14427 +#endif
14428 diff -NurpP --minimal linux-2.6.37/include/net/addrconf.h linux-2.6.37-vs2.3.0.37-rc2/include/net/addrconf.h
14429 --- linux-2.6.37/include/net/addrconf.h 2011-01-05 21:50:35.000000000 +0100
14430 +++ linux-2.6.37-vs2.3.0.37-rc2/include/net/addrconf.h  2010-11-23 02:09:41.000000000 +0100
14431 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14432                                                struct net_device *dev,
14433                                                const struct in6_addr *daddr,
14434                                                unsigned int srcprefs,
14435 -                                              struct in6_addr *saddr);
14436 +                                              struct in6_addr *saddr,
14437 +                                              struct nx_info *nxi);
14438  extern int                     ipv6_get_lladdr(struct net_device *dev,
14439                                                 struct in6_addr *addr,
14440                                                 unsigned char banned_flags);
14441 diff -NurpP --minimal linux-2.6.37/include/net/af_unix.h linux-2.6.37-vs2.3.0.37-rc2/include/net/af_unix.h
14442 --- linux-2.6.37/include/net/af_unix.h  2011-01-05 21:50:35.000000000 +0100
14443 +++ linux-2.6.37-vs2.3.0.37-rc2/include/net/af_unix.h   2011-01-05 22:30:40.000000000 +0100
14444 @@ -4,6 +4,7 @@
14445  #include <linux/socket.h>
14446  #include <linux/un.h>
14447  #include <linux/mutex.h>
14448 +#include <linux/vs_base.h>
14449  #include <net/sock.h>
14450  
14451  extern void unix_inflight(struct file *fp);
14452 diff -NurpP --minimal linux-2.6.37/include/net/inet_timewait_sock.h linux-2.6.37-vs2.3.0.37-rc2/include/net/inet_timewait_sock.h
14453 --- linux-2.6.37/include/net/inet_timewait_sock.h       2010-08-02 16:52:56.000000000 +0200
14454 +++ linux-2.6.37-vs2.3.0.37-rc2/include/net/inet_timewait_sock.h        2010-11-23 02:09:41.000000000 +0100
14455 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14456  #define tw_hash                        __tw_common.skc_hash
14457  #define tw_prot                        __tw_common.skc_prot
14458  #define tw_net                 __tw_common.skc_net
14459 +#define tw_xid                 __tw_common.skc_xid
14460 +#define tw_vx_info             __tw_common.skc_vx_info
14461 +#define tw_nid                 __tw_common.skc_nid
14462 +#define tw_nx_info             __tw_common.skc_nx_info
14463         int                     tw_timeout;
14464         volatile unsigned char  tw_substate;
14465         /* 3 bits hole, try to pack */
14466 diff -NurpP --minimal linux-2.6.37/include/net/route.h linux-2.6.37-vs2.3.0.37-rc2/include/net/route.h
14467 --- linux-2.6.37/include/net/route.h    2010-10-21 13:07:56.000000000 +0200
14468 +++ linux-2.6.37-vs2.3.0.37-rc2/include/net/route.h     2010-11-23 02:09:41.000000000 +0100
14469 @@ -145,6 +145,9 @@ static inline void ip_rt_put(struct rtab
14470                 dst_release(&rt->dst);
14471  }
14472  
14473 +#include <linux/vs_base.h>
14474 +#include <linux/vs_inet.h>
14475 +
14476  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14477  
14478  extern const __u8 ip_tos2prio[16];
14479 @@ -154,6 +157,9 @@ static inline char rt_tos2priority(u8 to
14480         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14481  }
14482  
14483 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14484 +       struct rtable **, struct flowi *);
14485 +
14486  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14487                                    __be32 src, u32 tos, int oif, u8 protocol,
14488                                    __be16 sport, __be16 dport, struct sock *sk,
14489 @@ -171,11 +177,24 @@ static inline int ip_route_connect(struc
14490  
14491         int err;
14492         struct net *net = sock_net(sk);
14493 +       struct nx_info *nx_info = current_nx_info();
14494  
14495         if (inet_sk(sk)->transparent)
14496                 fl.flags |= FLOWI_FLAG_ANYSRC;
14497  
14498 -       if (!dst || !src) {
14499 +       if (sk)
14500 +               nx_info = sk->sk_nx_info;
14501 +
14502 +       vxdprintk(VXD_CBIT(net, 4),
14503 +               "ip_route_connect(%p) %p,%p;%lx",
14504 +               sk, nx_info, sk->sk_socket,
14505 +               (sk->sk_socket?sk->sk_socket->flags:0));
14506 +
14507 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14508 +       if (err)
14509 +               return err;
14510 +
14511 +       if (!fl.fl4_dst || !fl.fl4_src) {
14512                 err = __ip_route_output_key(net, rp, &fl);
14513                 if (err)
14514                         return err;
14515 diff -NurpP --minimal linux-2.6.37/include/net/sock.h linux-2.6.37-vs2.3.0.37-rc2/include/net/sock.h
14516 --- linux-2.6.37/include/net/sock.h     2011-01-05 21:50:36.000000000 +0100
14517 +++ linux-2.6.37-vs2.3.0.37-rc2/include/net/sock.h      2011-01-05 22:30:42.000000000 +0100
14518 @@ -150,6 +150,10 @@ struct sock_common {
14519  #ifdef CONFIG_NET_NS
14520         struct net              *skc_net;
14521  #endif
14522 +       xid_t                   skc_xid;
14523 +       struct vx_info          *skc_vx_info;
14524 +       nid_t                   skc_nid;
14525 +       struct nx_info          *skc_nx_info;
14526  };
14527  
14528  /**
14529 @@ -241,6 +245,10 @@ struct sock {
14530  #define sk_bind_node           __sk_common.skc_bind_node
14531  #define sk_prot                        __sk_common.skc_prot
14532  #define sk_net                 __sk_common.skc_net
14533 +#define sk_xid                 __sk_common.skc_xid
14534 +#define sk_vx_info             __sk_common.skc_vx_info
14535 +#define sk_nid                 __sk_common.skc_nid
14536 +#define sk_nx_info             __sk_common.skc_nx_info
14537         kmemcheck_bitfield_begin(flags);
14538         unsigned int            sk_shutdown  : 2,
14539                                 sk_no_check  : 2,
14540 diff -NurpP --minimal linux-2.6.37/init/Kconfig linux-2.6.37-vs2.3.0.37-rc2/init/Kconfig
14541 --- linux-2.6.37/init/Kconfig   2011-01-05 21:50:37.000000000 +0100
14542 +++ linux-2.6.37-vs2.3.0.37-rc2/init/Kconfig    2011-01-05 22:30:42.000000000 +0100
14543 @@ -503,6 +503,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14544  menuconfig CGROUPS
14545         boolean "Control Group support"
14546         depends on EVENTFD
14547 +       default y
14548         help
14549           This option adds support for grouping sets of processes together, for
14550           use with process control subsystems such as Cpusets, CFS, memory
14551 @@ -528,6 +529,7 @@ config CGROUP_DEBUG
14552  
14553  config CGROUP_NS
14554         bool "Namespace cgroup subsystem"
14555 +       default n
14556         help
14557           Provides a simple namespace cgroup subsystem to
14558           provide hierarchical naming of sets of namespaces,
14559 diff -NurpP --minimal linux-2.6.37/init/main.c linux-2.6.37-vs2.3.0.37-rc2/init/main.c
14560 --- linux-2.6.37/init/main.c    2011-01-05 21:50:37.000000000 +0100
14561 +++ linux-2.6.37-vs2.3.0.37-rc2/init/main.c     2010-11-23 02:09:41.000000000 +0100
14562 @@ -67,6 +67,7 @@
14563  #include <linux/sfi.h>
14564  #include <linux/shmem_fs.h>
14565  #include <linux/slab.h>
14566 +#include <linux/vserver/percpu.h>
14567  
14568  #include <asm/io.h>
14569  #include <asm/bugs.h>
14570 diff -NurpP --minimal linux-2.6.37/ipc/mqueue.c linux-2.6.37-vs2.3.0.37-rc2/ipc/mqueue.c
14571 --- linux-2.6.37/ipc/mqueue.c   2011-01-05 21:50:37.000000000 +0100
14572 +++ linux-2.6.37-vs2.3.0.37-rc2/ipc/mqueue.c    2010-11-23 02:09:41.000000000 +0100
14573 @@ -33,6 +33,8 @@
14574  #include <linux/pid.h>
14575  #include <linux/ipc_namespace.h>
14576  #include <linux/slab.h>
14577 +#include <linux/vs_context.h>
14578 +#include <linux/vs_limit.h>
14579  
14580  #include <net/sock.h>
14581  #include "util.h"
14582 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14583         struct sigevent notify;
14584         struct pid* notify_owner;
14585         struct user_struct *user;       /* user who created, for accounting */
14586 +       struct vx_info *vxi;
14587         struct sock *notify_sock;
14588         struct sk_buff *notify_cookie;
14589  
14590 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
14591                 if (S_ISREG(mode)) {
14592                         struct mqueue_inode_info *info;
14593                         struct task_struct *p = current;
14594 +                       struct vx_info *vxi = p->vx_info;
14595                         unsigned long mq_bytes, mq_msg_tblsz;
14596  
14597                         inode->i_fop = &mqueue_file_operations;
14598 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14599                         info->notify_owner = NULL;
14600                         info->qsize = 0;
14601                         info->user = NULL;      /* set when all is ok */
14602 +                       info->vxi = NULL;
14603                         memset(&info->attr, 0, sizeof(info->attr));
14604                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14605                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14606 @@ -157,16 +162,19 @@ static struct inode *mqueue_get_inode(st
14607                         spin_lock(&mq_lock);
14608                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14609                             u->mq_bytes + mq_bytes >
14610 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
14611 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
14612 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14613                                 spin_unlock(&mq_lock);
14614                                 /* mqueue_evict_inode() releases info->messages */
14615                                 goto out_inode;
14616                         }
14617                         u->mq_bytes += mq_bytes;
14618 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14619                         spin_unlock(&mq_lock);
14620  
14621                         /* all is ok */
14622                         info->user = get_uid(u);
14623 +                       info->vxi = get_vx_info(vxi);
14624                 } else if (S_ISDIR(mode)) {
14625                         inc_nlink(inode);
14626                         /* Some things misbehave if size == 0 on a directory */
14627 @@ -268,8 +276,11 @@ static void mqueue_evict_inode(struct in
14628             + info->attr.mq_msgsize);
14629         user = info->user;
14630         if (user) {
14631 +               struct vx_info *vxi = info->vxi;
14632 +
14633                 spin_lock(&mq_lock);
14634                 user->mq_bytes -= mq_bytes;
14635 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14636                 /*
14637                  * get_ns_from_inode() ensures that the
14638                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14639 @@ -279,6 +290,7 @@ static void mqueue_evict_inode(struct in
14640                 if (ipc_ns)
14641                         ipc_ns->mq_queues_count--;
14642                 spin_unlock(&mq_lock);
14643 +               put_vx_info(vxi);
14644                 free_uid(user);
14645         }
14646         if (ipc_ns)
14647 diff -NurpP --minimal linux-2.6.37/ipc/msg.c linux-2.6.37-vs2.3.0.37-rc2/ipc/msg.c
14648 --- linux-2.6.37/ipc/msg.c      2010-08-02 16:52:57.000000000 +0200
14649 +++ linux-2.6.37-vs2.3.0.37-rc2/ipc/msg.c       2010-11-23 02:09:41.000000000 +0100
14650 @@ -37,6 +37,7 @@
14651  #include <linux/rwsem.h>
14652  #include <linux/nsproxy.h>
14653  #include <linux/ipc_namespace.h>
14654 +#include <linux/vs_base.h>
14655  
14656  #include <asm/current.h>
14657  #include <asm/uaccess.h>
14658 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14659  
14660         msq->q_perm.mode = msgflg & S_IRWXUGO;
14661         msq->q_perm.key = key;
14662 +       msq->q_perm.xid = vx_current_xid();
14663  
14664         msq->q_perm.security = NULL;
14665         retval = security_msg_queue_alloc(msq);
14666 diff -NurpP --minimal linux-2.6.37/ipc/namespace.c linux-2.6.37-vs2.3.0.37-rc2/ipc/namespace.c
14667 --- linux-2.6.37/ipc/namespace.c        2009-09-10 15:26:27.000000000 +0200
14668 +++ linux-2.6.37-vs2.3.0.37-rc2/ipc/namespace.c 2010-11-23 02:09:41.000000000 +0100
14669 @@ -11,6 +11,8 @@
14670  #include <linux/slab.h>
14671  #include <linux/fs.h>
14672  #include <linux/mount.h>
14673 +#include <linux/vs_base.h>
14674 +#include <linux/vserver/global.h>
14675  
14676  #include "util.h"
14677  
14678 diff -NurpP --minimal linux-2.6.37/ipc/sem.c linux-2.6.37-vs2.3.0.37-rc2/ipc/sem.c
14679 --- linux-2.6.37/ipc/sem.c      2010-10-21 13:07:56.000000000 +0200
14680 +++ linux-2.6.37-vs2.3.0.37-rc2/ipc/sem.c       2010-11-23 02:09:41.000000000 +0100
14681 @@ -86,6 +86,8 @@
14682  #include <linux/rwsem.h>
14683  #include <linux/nsproxy.h>
14684  #include <linux/ipc_namespace.h>
14685 +#include <linux/vs_base.h>
14686 +#include <linux/vs_limit.h>
14687  
14688  #include <asm/uaccess.h>
14689  #include "util.h"
14690 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14691  
14692         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14693         sma->sem_perm.key = key;
14694 +       sma->sem_perm.xid = vx_current_xid();
14695  
14696         sma->sem_perm.security = NULL;
14697         retval = security_sem_alloc(sma);
14698 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14699                 return id;
14700         }
14701         ns->used_sems += nsems;
14702 +       /* FIXME: obsoleted? */
14703 +       vx_semary_inc(sma);
14704 +       vx_nsems_add(sma, nsems);
14705  
14706         sma->sem_base = (struct sem *) &sma[1];
14707  
14708 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
14709  
14710         wake_up_sem_queue_do(&tasks);
14711         ns->used_sems -= sma->sem_nsems;
14712 +       /* FIXME: obsoleted? */
14713 +       vx_nsems_sub(sma, sma->sem_nsems);
14714 +       vx_semary_dec(sma);
14715         security_sem_free(sma);
14716         ipc_rcu_putref(sma);
14717  }
14718 diff -NurpP --minimal linux-2.6.37/ipc/shm.c linux-2.6.37-vs2.3.0.37-rc2/ipc/shm.c
14719 --- linux-2.6.37/ipc/shm.c      2011-01-05 21:50:37.000000000 +0100
14720 +++ linux-2.6.37-vs2.3.0.37-rc2/ipc/shm.c       2010-11-23 02:09:41.000000000 +0100
14721 @@ -39,6 +39,8 @@
14722  #include <linux/nsproxy.h>
14723  #include <linux/mount.h>
14724  #include <linux/ipc_namespace.h>
14725 +#include <linux/vs_context.h>
14726 +#include <linux/vs_limit.h>
14727  
14728  #include <asm/uaccess.h>
14729  
14730 @@ -173,7 +175,12 @@ static void shm_open(struct vm_area_stru
14731   */
14732  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14733  {
14734 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14735 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14736 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14737 +
14738 +       vx_ipcshm_sub(vxi, shp, numpages);
14739 +       ns->shm_tot -= numpages;
14740 +
14741         shm_rmid(ns, shp);
14742         shm_unlock(shp);
14743         if (!is_file_hugepages(shp->shm_file))
14744 @@ -183,6 +190,7 @@ static void shm_destroy(struct ipc_names
14745                                                 shp->mlock_user);
14746         fput (shp->shm_file);
14747         security_shm_free(shp);
14748 +       put_vx_info(vxi);
14749         ipc_rcu_putref(shp);
14750  }
14751  
14752 @@ -355,11 +363,15 @@ static int newseg(struct ipc_namespace *
14753         if (ns->shm_tot + numpages > ns->shm_ctlall)
14754                 return -ENOSPC;
14755  
14756 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14757 +               return -ENOSPC;
14758 +
14759         shp = ipc_rcu_alloc(sizeof(*shp));
14760         if (!shp)
14761                 return -ENOMEM;
14762  
14763         shp->shm_perm.key = key;
14764 +       shp->shm_perm.xid = vx_current_xid();
14765         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14766         shp->mlock_user = NULL;
14767  
14768 @@ -413,6 +425,7 @@ static int newseg(struct ipc_namespace *
14769         ns->shm_tot += numpages;
14770         error = shp->shm_perm.id;
14771         shm_unlock(shp);
14772 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14773         return error;
14774  
14775  no_id:
14776 diff -NurpP --minimal linux-2.6.37/kernel/capability.c linux-2.6.37-vs2.3.0.37-rc2/kernel/capability.c
14777 --- linux-2.6.37/kernel/capability.c    2010-08-02 16:52:57.000000000 +0200
14778 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/capability.c     2010-11-23 02:09:41.000000000 +0100
14779 @@ -14,6 +14,7 @@
14780  #include <linux/security.h>
14781  #include <linux/syscalls.h>
14782  #include <linux/pid_namespace.h>
14783 +#include <linux/vs_context.h>
14784  #include <asm/uaccess.h>
14785  
14786  /*
14787 @@ -119,6 +120,7 @@ static int cap_validate_magic(cap_user_h
14788         return 0;
14789  }
14790  
14791 +
14792  /*
14793   * The only thing that can change the capabilities of the current
14794   * process is the current process. As such, we can't be in this code
14795 @@ -289,6 +291,8 @@ error:
14796         return ret;
14797  }
14798  
14799 +#include <linux/vserver/base.h>
14800 +
14801  /**
14802   * capable - Determine if the current task has a superior capability in effect
14803   * @cap: The capability to be tested for
14804 @@ -301,6 +305,9 @@ error:
14805   */
14806  int capable(int cap)
14807  {
14808 +       /* here for now so we don't require task locking */
14809 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
14810 +               return 0;
14811         if (unlikely(!cap_valid(cap))) {
14812                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
14813                 BUG();
14814 diff -NurpP --minimal linux-2.6.37/kernel/compat.c linux-2.6.37-vs2.3.0.37-rc2/kernel/compat.c
14815 --- linux-2.6.37/kernel/compat.c        2010-10-21 13:07:56.000000000 +0200
14816 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/compat.c 2010-11-23 02:09:41.000000000 +0100
14817 @@ -914,7 +914,7 @@ asmlinkage long compat_sys_stime(compat_
14818         if (err)
14819                 return err;
14820  
14821 -       do_settimeofday(&tv);
14822 +       vx_settimeofday(&tv);
14823         return 0;
14824  }
14825  
14826 diff -NurpP --minimal linux-2.6.37/kernel/cred.c linux-2.6.37-vs2.3.0.37-rc2/kernel/cred.c
14827 --- linux-2.6.37/kernel/cred.c  2011-01-05 21:50:37.000000000 +0100
14828 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/cred.c   2011-01-08 03:33:34.000000000 +0100
14829 @@ -60,31 +60,6 @@ struct cred init_cred = {
14830  #endif
14831  };
14832  
14833 -static inline void set_cred_subscribers(struct cred *cred, int n)
14834 -{
14835 -#ifdef CONFIG_DEBUG_CREDENTIALS
14836 -       atomic_set(&cred->subscribers, n);
14837 -#endif
14838 -}
14839 -
14840 -static inline int read_cred_subscribers(const struct cred *cred)
14841 -{
14842 -#ifdef CONFIG_DEBUG_CREDENTIALS
14843 -       return atomic_read(&cred->subscribers);
14844 -#else
14845 -       return 0;
14846 -#endif
14847 -}
14848 -
14849 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14850 -{
14851 -#ifdef CONFIG_DEBUG_CREDENTIALS
14852 -       struct cred *cred = (struct cred *) _cred;
14853 -
14854 -       atomic_add(n, &cred->subscribers);
14855 -#endif
14856 -}
14857 -
14858  /*
14859   * Dispose of the shared task group credentials
14860   */
14861 diff -NurpP --minimal linux-2.6.37/kernel/exit.c linux-2.6.37-vs2.3.0.37-rc2/kernel/exit.c
14862 --- linux-2.6.37/kernel/exit.c  2011-01-05 21:50:37.000000000 +0100
14863 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/exit.c   2011-01-05 22:30:42.000000000 +0100
14864 @@ -48,6 +48,10 @@
14865  #include <linux/fs_struct.h>
14866  #include <linux/init_task.h>
14867  #include <linux/perf_event.h>
14868 +#include <linux/vs_limit.h>
14869 +#include <linux/vs_context.h>
14870 +#include <linux/vs_network.h>
14871 +#include <linux/vs_pid.h>
14872  #include <trace/events/sched.h>
14873  #include <linux/hw_breakpoint.h>
14874  #include <linux/oom.h>
14875 @@ -494,9 +498,11 @@ static void close_files(struct files_str
14876                                         filp_close(file, files);
14877                                         cond_resched();
14878                                 }
14879 +                               vx_openfd_dec(i);
14880                         }
14881                         i++;
14882                         set >>= 1;
14883 +                       cond_resched();
14884                 }
14885         }
14886  }
14887 @@ -1043,11 +1049,16 @@ NORET_TYPE void do_exit(long code)
14888  
14889         validate_creds_for_do_exit(tsk);
14890  
14891 +       /* needs to stay after exit_notify() */
14892 +       exit_vx_info(tsk, code);
14893 +       exit_nx_info(tsk);
14894 +
14895         preempt_disable();
14896         exit_rcu();
14897         /* causes final put_task_struct in finish_task_switch(). */
14898         tsk->state = TASK_DEAD;
14899         schedule();
14900 +       printk("bad task: %p [%lx]\n", current, current->state);
14901         BUG();
14902         /* Avoid "noreturn function does return".  */
14903         for (;;)
14904 diff -NurpP --minimal linux-2.6.37/kernel/fork.c linux-2.6.37-vs2.3.0.37-rc2/kernel/fork.c
14905 --- linux-2.6.37/kernel/fork.c  2011-01-05 21:50:37.000000000 +0100
14906 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/fork.c   2011-01-05 22:30:42.000000000 +0100
14907 @@ -66,6 +66,10 @@
14908  #include <linux/posix-timers.h>
14909  #include <linux/user-return-notifier.h>
14910  #include <linux/oom.h>
14911 +#include <linux/vs_context.h>
14912 +#include <linux/vs_network.h>
14913 +#include <linux/vs_limit.h>
14914 +#include <linux/vs_memory.h>
14915  
14916  #include <asm/pgtable.h>
14917  #include <asm/pgalloc.h>
14918 @@ -161,6 +165,8 @@ void free_task(struct task_struct *tsk)
14919         account_kernel_stack(tsk->stack, -1);
14920         free_thread_info(tsk->stack);
14921         rt_mutex_debug_task_free(tsk);
14922 +       clr_vx_info(&tsk->vx_info);
14923 +       clr_nx_info(&tsk->nx_info);
14924         ftrace_graph_exit_task(tsk);
14925         free_task_struct(tsk);
14926  }
14927 @@ -495,6 +501,7 @@ static struct mm_struct * mm_init(struct
14928         if (likely(!mm_alloc_pgd(mm))) {
14929                 mm->def_flags = 0;
14930                 mmu_notifier_mm_init(mm);
14931 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14932                 return mm;
14933         }
14934  
14935 @@ -528,6 +535,7 @@ void __mmdrop(struct mm_struct *mm)
14936         mm_free_pgd(mm);
14937         destroy_context(mm);
14938         mmu_notifier_mm_destroy(mm);
14939 +       clr_vx_info(&mm->mm_vx_info);
14940         free_mm(mm);
14941  }
14942  EXPORT_SYMBOL_GPL(__mmdrop);
14943 @@ -663,6 +671,7 @@ struct mm_struct *dup_mm(struct task_str
14944                 goto fail_nomem;
14945  
14946         memcpy(mm, oldmm, sizeof(*mm));
14947 +       mm->mm_vx_info = NULL;
14948  
14949         /* Initializing for Swap token stuff */
14950         mm->token_priority = 0;
14951 @@ -701,6 +710,7 @@ fail_nocontext:
14952          * If init_new_context() failed, we cannot use mmput() to free the mm
14953          * because it calls destroy_context()
14954          */
14955 +       clr_vx_info(&mm->mm_vx_info);
14956         mm_free_pgd(mm);
14957         free_mm(mm);
14958         return NULL;
14959 @@ -980,6 +990,8 @@ static struct task_struct *copy_process(
14960         int retval;
14961         struct task_struct *p;
14962         int cgroup_callbacks_done = 0;
14963 +       struct vx_info *vxi;
14964 +       struct nx_info *nxi;
14965  
14966         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14967                 return ERR_PTR(-EINVAL);
14968 @@ -1026,7 +1038,12 @@ static struct task_struct *copy_process(
14969         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14970         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14971  #endif
14972 +       init_vx_info(&p->vx_info, current_vx_info());
14973 +       init_nx_info(&p->nx_info, current_nx_info());
14974 +
14975         retval = -EAGAIN;
14976 +       if (!vx_nproc_avail(1))
14977 +               goto bad_fork_free;
14978         if (atomic_read(&p->real_cred->user->processes) >=
14979                         task_rlimit(p, RLIMIT_NPROC)) {
14980                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14981 @@ -1291,6 +1308,18 @@ static struct task_struct *copy_process(
14982  
14983         total_forks++;
14984         spin_unlock(&current->sighand->siglock);
14985 +
14986 +       /* p is copy of current */
14987 +       vxi = p->vx_info;
14988 +       if (vxi) {
14989 +               claim_vx_info(vxi, p);
14990 +               atomic_inc(&vxi->cvirt.nr_threads);
14991 +               atomic_inc(&vxi->cvirt.total_forks);
14992 +               vx_nproc_inc(p);
14993 +       }
14994 +       nxi = p->nx_info;
14995 +       if (nxi)
14996 +               claim_nx_info(nxi, p);
14997         write_unlock_irq(&tasklist_lock);
14998         proc_fork_connector(p);
14999         cgroup_post_fork(p);
15000 diff -NurpP --minimal linux-2.6.37/kernel/kthread.c linux-2.6.37-vs2.3.0.37-rc2/kernel/kthread.c
15001 --- linux-2.6.37/kernel/kthread.c       2011-01-05 21:50:38.000000000 +0100
15002 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/kthread.c        2011-01-05 22:30:42.000000000 +0100
15003 @@ -16,6 +16,7 @@
15004  #include <linux/mutex.h>
15005  #include <linux/slab.h>
15006  #include <linux/freezer.h>
15007 +#include <linux/vs_pid.h>
15008  #include <trace/events/sched.h>
15009  
15010  static DEFINE_SPINLOCK(kthread_create_lock);
15011 diff -NurpP --minimal linux-2.6.37/kernel/Makefile linux-2.6.37-vs2.3.0.37-rc2/kernel/Makefile
15012 --- linux-2.6.37/kernel/Makefile        2011-01-05 21:50:37.000000000 +0100
15013 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/Makefile 2010-11-23 02:09:41.000000000 +0100
15014 @@ -25,6 +25,7 @@ CFLAGS_REMOVE_perf_event.o = -pg
15015  CFLAGS_REMOVE_irq_work.o = -pg
15016  endif
15017  
15018 +obj-y += vserver/
15019  obj-$(CONFIG_FREEZER) += freezer.o
15020  obj-$(CONFIG_PROFILING) += profile.o
15021  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15022 diff -NurpP --minimal linux-2.6.37/kernel/nsproxy.c linux-2.6.37-vs2.3.0.37-rc2/kernel/nsproxy.c
15023 --- linux-2.6.37/kernel/nsproxy.c       2010-07-07 18:31:57.000000000 +0200
15024 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/nsproxy.c        2010-11-23 02:09:41.000000000 +0100
15025 @@ -20,6 +20,8 @@
15026  #include <linux/mnt_namespace.h>
15027  #include <linux/utsname.h>
15028  #include <linux/pid_namespace.h>
15029 +#include <linux/vserver/global.h>
15030 +#include <linux/vserver/debug.h>
15031  #include <net/net_namespace.h>
15032  #include <linux/ipc_namespace.h>
15033  
15034 @@ -43,8 +45,11 @@ static inline struct nsproxy *create_nsp
15035         struct nsproxy *nsproxy;
15036  
15037         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15038 -       if (nsproxy)
15039 +       if (nsproxy) {
15040                 atomic_set(&nsproxy->count, 1);
15041 +               atomic_inc(&vs_global_nsproxy);
15042 +       }
15043 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15044         return nsproxy;
15045  }
15046  
15047 @@ -53,41 +58,52 @@ static inline struct nsproxy *create_nsp
15048   * Return the newly created nsproxy.  Do not attach this to the task,
15049   * leave it to the caller to do proper locking and attach it to task.
15050   */
15051 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15052 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15053 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15054 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15055  {
15056         struct nsproxy *new_nsp;
15057         int err;
15058  
15059 +       vxdprintk(VXD_CBIT(space, 4),
15060 +               "unshare_namespaces(0x%08lx,%p,%p)",
15061 +               flags, orig, new_fs);
15062 +
15063         new_nsp = create_nsproxy();
15064         if (!new_nsp)
15065                 return ERR_PTR(-ENOMEM);
15066  
15067 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15068 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15069         if (IS_ERR(new_nsp->mnt_ns)) {
15070                 err = PTR_ERR(new_nsp->mnt_ns);
15071                 goto out_ns;
15072         }
15073  
15074 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15075 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15076         if (IS_ERR(new_nsp->uts_ns)) {
15077                 err = PTR_ERR(new_nsp->uts_ns);
15078                 goto out_uts;
15079         }
15080  
15081 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15082 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15083         if (IS_ERR(new_nsp->ipc_ns)) {
15084                 err = PTR_ERR(new_nsp->ipc_ns);
15085                 goto out_ipc;
15086         }
15087  
15088 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15089 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15090         if (IS_ERR(new_nsp->pid_ns)) {
15091                 err = PTR_ERR(new_nsp->pid_ns);
15092                 goto out_pid;
15093         }
15094  
15095 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15096 +       /* disabled now?
15097 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15098 +       if (IS_ERR(new_nsp->user_ns)) {
15099 +               err = PTR_ERR(new_nsp->user_ns);
15100 +               goto out_user;
15101 +       } */
15102 +
15103 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15104         if (IS_ERR(new_nsp->net_ns)) {
15105                 err = PTR_ERR(new_nsp->net_ns);
15106                 goto out_net;
15107 @@ -112,6 +128,38 @@ out_ns:
15108         return ERR_PTR(err);
15109  }
15110  
15111 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15112 +                       struct fs_struct *new_fs)
15113 +{
15114 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15115 +}
15116 +
15117 +/*
15118 + * copies the nsproxy, setting refcount to 1, and grabbing a
15119 + * reference to all contained namespaces.
15120 + */
15121 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15122 +{
15123 +       struct nsproxy *ns = create_nsproxy();
15124 +
15125 +       if (ns) {
15126 +               memcpy(ns, orig, sizeof(struct nsproxy));
15127 +               atomic_set(&ns->count, 1);
15128 +
15129 +               if (ns->mnt_ns)
15130 +                       get_mnt_ns(ns->mnt_ns);
15131 +               if (ns->uts_ns)
15132 +                       get_uts_ns(ns->uts_ns);
15133 +               if (ns->ipc_ns)
15134 +                       get_ipc_ns(ns->ipc_ns);
15135 +               if (ns->pid_ns)
15136 +                       get_pid_ns(ns->pid_ns);
15137 +               if (ns->net_ns)
15138 +                       get_net(ns->net_ns);
15139 +       }
15140 +       return ns;
15141 +}
15142 +
15143  /*
15144   * called from clone.  This now handles copy for nsproxy and all
15145   * namespaces therein.
15146 @@ -119,9 +167,12 @@ out_ns:
15147  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15148  {
15149         struct nsproxy *old_ns = tsk->nsproxy;
15150 -       struct nsproxy *new_ns;
15151 +       struct nsproxy *new_ns = NULL;
15152         int err = 0;
15153  
15154 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15155 +               flags, tsk, old_ns);
15156 +
15157         if (!old_ns)
15158                 return 0;
15159  
15160 @@ -131,7 +182,7 @@ int copy_namespaces(unsigned long flags,
15161                                 CLONE_NEWPID | CLONE_NEWNET)))
15162                 return 0;
15163  
15164 -       if (!capable(CAP_SYS_ADMIN)) {
15165 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15166                 err = -EPERM;
15167                 goto out;
15168         }
15169 @@ -158,6 +209,9 @@ int copy_namespaces(unsigned long flags,
15170  
15171  out:
15172         put_nsproxy(old_ns);
15173 +       vxdprintk(VXD_CBIT(space, 3),
15174 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15175 +               flags, tsk, old_ns, err, new_ns);
15176         return err;
15177  }
15178  
15179 @@ -171,7 +225,9 @@ void free_nsproxy(struct nsproxy *ns)
15180                 put_ipc_ns(ns->ipc_ns);
15181         if (ns->pid_ns)
15182                 put_pid_ns(ns->pid_ns);
15183 -       put_net(ns->net_ns);
15184 +       if (ns->net_ns)
15185 +               put_net(ns->net_ns);
15186 +       atomic_dec(&vs_global_nsproxy);
15187         kmem_cache_free(nsproxy_cachep, ns);
15188  }
15189  
15190 @@ -184,11 +240,15 @@ int unshare_nsproxy_namespaces(unsigned 
15191  {
15192         int err = 0;
15193  
15194 +       vxdprintk(VXD_CBIT(space, 4),
15195 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15196 +               unshare_flags, current->nsproxy);
15197 +
15198         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15199                                CLONE_NEWNET)))
15200                 return 0;
15201  
15202 -       if (!capable(CAP_SYS_ADMIN))
15203 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15204                 return -EPERM;
15205  
15206         *new_nsp = create_new_namespaces(unshare_flags, current,
15207 diff -NurpP --minimal linux-2.6.37/kernel/pid.c linux-2.6.37-vs2.3.0.37-rc2/kernel/pid.c
15208 --- linux-2.6.37/kernel/pid.c   2011-01-05 21:50:38.000000000 +0100
15209 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/pid.c    2010-11-23 02:37:26.000000000 +0100
15210 @@ -36,6 +36,7 @@
15211  #include <linux/pid_namespace.h>
15212  #include <linux/init_task.h>
15213  #include <linux/syscalls.h>
15214 +#include <linux/vs_pid.h>
15215  
15216  #define pid_hashfn(nr, ns)     \
15217         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15218 @@ -339,7 +340,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15219  
15220  struct pid *find_vpid(int nr)
15221  {
15222 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15223 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15224  }
15225  EXPORT_SYMBOL_GPL(find_vpid);
15226  
15227 @@ -399,6 +400,9 @@ void transfer_pid(struct task_struct *ol
15228  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15229  {
15230         struct task_struct *result = NULL;
15231 +
15232 +       if (type == PIDTYPE_REALPID)
15233 +               type = PIDTYPE_PID;
15234         if (pid) {
15235                 struct hlist_node *first;
15236                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
15237 @@ -417,7 +421,7 @@ EXPORT_SYMBOL(pid_task);
15238  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15239  {
15240         rcu_lockdep_assert(rcu_read_lock_held());
15241 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15242 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15243  }
15244  
15245  struct task_struct *find_task_by_vpid(pid_t vnr)
15246 @@ -459,7 +463,7 @@ struct pid *find_get_pid(pid_t nr)
15247  }
15248  EXPORT_SYMBOL_GPL(find_get_pid);
15249  
15250 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15251 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15252  {
15253         struct upid *upid;
15254         pid_t nr = 0;
15255 @@ -472,6 +476,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15256         return nr;
15257  }
15258  
15259 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15260 +{
15261 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15262 +}
15263 +
15264  pid_t pid_vnr(struct pid *pid)
15265  {
15266         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15267 diff -NurpP --minimal linux-2.6.37/kernel/pid_namespace.c linux-2.6.37-vs2.3.0.37-rc2/kernel/pid_namespace.c
15268 --- linux-2.6.37/kernel/pid_namespace.c 2010-07-07 18:31:57.000000000 +0200
15269 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/pid_namespace.c  2010-11-23 02:09:41.000000000 +0100
15270 @@ -14,6 +14,7 @@
15271  #include <linux/err.h>
15272  #include <linux/acct.h>
15273  #include <linux/slab.h>
15274 +#include <linux/vserver/global.h>
15275  
15276  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15277  
15278 @@ -87,6 +88,7 @@ static struct pid_namespace *create_pid_
15279                 goto out_free_map;
15280  
15281         kref_init(&ns->kref);
15282 +       atomic_inc(&vs_global_pid_ns);
15283         ns->level = level;
15284         ns->parent = get_pid_ns(parent_pid_ns);
15285  
15286 @@ -112,6 +114,7 @@ static void destroy_pid_namespace(struct
15287  
15288         for (i = 0; i < PIDMAP_ENTRIES; i++)
15289                 kfree(ns->pidmap[i].page);
15290 +       atomic_dec(&vs_global_pid_ns);
15291         kmem_cache_free(pid_ns_cachep, ns);
15292  }
15293  
15294 diff -NurpP --minimal linux-2.6.37/kernel/posix-timers.c linux-2.6.37-vs2.3.0.37-rc2/kernel/posix-timers.c
15295 --- linux-2.6.37/kernel/posix-timers.c  2010-10-21 13:07:57.000000000 +0200
15296 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/posix-timers.c   2010-11-23 02:09:41.000000000 +0100
15297 @@ -46,6 +46,7 @@
15298  #include <linux/wait.h>
15299  #include <linux/workqueue.h>
15300  #include <linux/module.h>
15301 +#include <linux/vs_context.h>
15302  
15303  /*
15304   * Management arrays for POSIX timers.  Timers are kept in slab memory
15305 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15306  {
15307         struct task_struct *task;
15308         int shared, ret = -1;
15309 +
15310         /*
15311          * FIXME: if ->sigq is queued we can race with
15312          * dequeue_signal()->do_schedule_next_timer().
15313 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15314         rcu_read_lock();
15315         task = pid_task(timr->it_pid, PIDTYPE_PID);
15316         if (task) {
15317 +               struct vx_info_save vxis;
15318 +               struct vx_info *vxi;
15319 +
15320 +               vxi = get_vx_info(task->vx_info);
15321 +               enter_vx_info(vxi, &vxis);
15322                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15323                 ret = send_sigqueue(timr->sigq, task, shared);
15324 +               leave_vx_info(&vxis);
15325 +               put_vx_info(vxi);
15326         }
15327         rcu_read_unlock();
15328 +
15329         /* If we failed to send the signal the timer stops. */
15330         return ret > 0;
15331  }
15332 diff -NurpP --minimal linux-2.6.37/kernel/printk.c linux-2.6.37-vs2.3.0.37-rc2/kernel/printk.c
15333 --- linux-2.6.37/kernel/printk.c        2011-01-05 21:50:38.000000000 +0100
15334 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/printk.c 2011-01-05 22:30:42.000000000 +0100
15335 @@ -39,6 +39,7 @@
15336  #include <linux/syslog.h>
15337  #include <linux/cpu.h>
15338  #include <linux/notifier.h>
15339 +#include <linux/vs_cvirt.h>
15340  
15341  #include <asm/uaccess.h>
15342  
15343 @@ -272,18 +273,19 @@ int do_syslog(int type, char __user *buf
15344         unsigned i, j, limit, count;
15345         int do_clear = 0;
15346         char c;
15347 -       int error = 0;
15348 +       int error;
15349  
15350         /*
15351          * If this is from /proc/kmsg we only do the capabilities checks
15352          * at open time.
15353          */
15354         if (type == SYSLOG_ACTION_OPEN || !from_file) {
15355 -               if (dmesg_restrict && !capable(CAP_SYS_ADMIN))
15356 +               if (dmesg_restrict &&
15357 +                   !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
15358                         return -EPERM;
15359                 if ((type != SYSLOG_ACTION_READ_ALL &&
15360                      type != SYSLOG_ACTION_SIZE_BUFFER) &&
15361 -                   !capable(CAP_SYS_ADMIN))
15362 +                   !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
15363                         return -EPERM;
15364         }
15365  
15366 @@ -291,12 +293,9 @@ int do_syslog(int type, char __user *buf
15367         if (error)
15368                 return error;
15369  
15370 -       switch (type) {
15371 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15372 -               break;
15373 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15374 -               break;
15375 -       case SYSLOG_ACTION_READ:        /* Read from log */
15376 +       if ((type == SYSLOG_ACTION_READ) ||
15377 +           (type == SYSLOG_ACTION_READ_ALL) ||
15378 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15379                 error = -EINVAL;
15380                 if (!buf || len < 0)
15381                         goto out;
15382 @@ -307,6 +306,16 @@ int do_syslog(int type, char __user *buf
15383                         error = -EFAULT;
15384                         goto out;
15385                 }
15386 +       }
15387 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15388 +               return vx_do_syslog(type, buf, len);
15389 +
15390 +       switch (type) {
15391 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15392 +               break;
15393 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15394 +               break;
15395 +       case SYSLOG_ACTION_READ:        /* Read from log */
15396                 error = wait_event_interruptible(log_wait,
15397                                                         (log_start - log_end));
15398                 if (error)
15399 @@ -333,16 +342,6 @@ int do_syslog(int type, char __user *buf
15400                 /* FALL THRU */
15401         /* Read last kernel messages */
15402         case SYSLOG_ACTION_READ_ALL:
15403 -               error = -EINVAL;
15404 -               if (!buf || len < 0)
15405 -                       goto out;
15406 -               error = 0;
15407 -               if (!len)
15408 -                       goto out;
15409 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15410 -                       error = -EFAULT;
15411 -                       goto out;
15412 -               }
15413                 count = len;
15414                 if (count > log_buf_len)
15415                         count = log_buf_len;
15416 diff -NurpP --minimal linux-2.6.37/kernel/ptrace.c linux-2.6.37-vs2.3.0.37-rc2/kernel/ptrace.c
15417 --- linux-2.6.37/kernel/ptrace.c        2011-01-05 21:50:38.000000000 +0100
15418 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/ptrace.c 2010-11-23 02:09:41.000000000 +0100
15419 @@ -22,6 +22,7 @@
15420  #include <linux/syscalls.h>
15421  #include <linux/uaccess.h>
15422  #include <linux/regset.h>
15423 +#include <linux/vs_context.h>
15424  
15425  
15426  /*
15427 @@ -150,6 +151,11 @@ int __ptrace_may_access(struct task_stru
15428                 dumpable = get_dumpable(task->mm);
15429         if (!dumpable && !capable(CAP_SYS_PTRACE))
15430                 return -EPERM;
15431 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15432 +               return -EPERM;
15433 +       if (!vx_check(task->xid, VS_IDENT) &&
15434 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15435 +               return -EACCES;
15436  
15437         return security_ptrace_access_check(task, mode);
15438  }
15439 @@ -713,6 +719,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15440                 goto out;
15441         }
15442  
15443 +       ret = -EPERM;
15444 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15445 +               goto out_put_task_struct;
15446 +
15447         if (request == PTRACE_ATTACH) {
15448                 ret = ptrace_attach(child);
15449                 /*
15450 diff -NurpP --minimal linux-2.6.37/kernel/sched.c linux-2.6.37-vs2.3.0.37-rc2/kernel/sched.c
15451 --- linux-2.6.37/kernel/sched.c 2011-01-05 21:50:38.000000000 +0100
15452 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/sched.c  2011-01-05 22:30:42.000000000 +0100
15453 @@ -72,6 +72,8 @@
15454  #include <linux/ctype.h>
15455  #include <linux/ftrace.h>
15456  #include <linux/slab.h>
15457 +#include <linux/vs_sched.h>
15458 +#include <linux/vs_cvirt.h>
15459  
15460  #include <asm/tlb.h>
15461  #include <asm/irq_regs.h>
15462 @@ -3361,9 +3363,17 @@ static void calc_global_nohz(unsigned lo
15463   */
15464  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15465  {
15466 -       loads[0] = (avenrun[0] + offset) << shift;
15467 -       loads[1] = (avenrun[1] + offset) << shift;
15468 -       loads[2] = (avenrun[2] + offset) << shift;
15469 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15470 +               struct vx_info *vxi = current_vx_info();
15471 +
15472 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15473 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15474 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15475 +       } else {
15476 +               loads[0] = (avenrun[0] + offset) << shift;
15477 +               loads[1] = (avenrun[1] + offset) << shift;
15478 +               loads[2] = (avenrun[2] + offset) << shift;
15479 +       }
15480  }
15481  
15482  /*
15483 @@ -3651,16 +3661,19 @@ void account_user_time(struct task_struc
15484                        cputime_t cputime_scaled)
15485  {
15486         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15487 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15488         cputime64_t tmp;
15489 +       int nice = (TASK_NICE(p) > 0);
15490  
15491         /* Add user time to process. */
15492         p->utime = cputime_add(p->utime, cputime);
15493         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15494 +       vx_account_user(vxi, cputime, nice);
15495         account_group_user_time(p, cputime);
15496  
15497         /* Add user time to cpustat. */
15498         tmp = cputime_to_cputime64(cputime);
15499 -       if (TASK_NICE(p) > 0)
15500 +       if (nice)
15501                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15502         else
15503                 cpustat->user = cputime64_add(cpustat->user, tmp);
15504 @@ -3711,6 +3724,7 @@ void account_system_time(struct task_str
15505                          cputime_t cputime, cputime_t cputime_scaled)
15506  {
15507         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15508 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15509         cputime64_t tmp;
15510  
15511         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15512 @@ -3721,6 +3735,7 @@ void account_system_time(struct task_str
15513         /* Add system time to process. */
15514         p->stime = cputime_add(p->stime, cputime);
15515         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15516 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15517         account_group_system_time(p, cputime);
15518  
15519         /* Add system time to cpustat. */
15520 @@ -4804,7 +4819,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15521                 nice = 19;
15522  
15523         if (increment < 0 && !can_nice(current, nice))
15524 -               return -EPERM;
15525 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15526  
15527         retval = security_task_setnice(current, nice);
15528         if (retval)
15529 diff -NurpP --minimal linux-2.6.37/kernel/sched_fair.c linux-2.6.37-vs2.3.0.37-rc2/kernel/sched_fair.c
15530 --- linux-2.6.37/kernel/sched_fair.c    2011-01-05 21:50:38.000000000 +0100
15531 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/sched_fair.c     2011-01-05 22:30:42.000000000 +0100
15532 @@ -782,6 +782,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15533         check_spread(cfs_rq, se);
15534         if (se != cfs_rq->curr)
15535                 __enqueue_entity(cfs_rq, se);
15536 +
15537 +       if (entity_is_task(se))
15538 +               vx_activate_task(task_of(se));
15539  }
15540  
15541  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
15542 @@ -825,6 +828,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15543  
15544         if (se != cfs_rq->curr)
15545                 __dequeue_entity(cfs_rq, se);
15546 +       if (entity_is_task(se))
15547 +               vx_deactivate_task(task_of(se));
15548         account_entity_dequeue(cfs_rq, se);
15549         update_min_vruntime(cfs_rq);
15550  
15551 diff -NurpP --minimal linux-2.6.37/kernel/signal.c linux-2.6.37-vs2.3.0.37-rc2/kernel/signal.c
15552 --- linux-2.6.37/kernel/signal.c        2011-01-05 21:50:38.000000000 +0100
15553 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/signal.c 2010-11-23 02:09:41.000000000 +0100
15554 @@ -28,6 +28,8 @@
15555  #include <linux/freezer.h>
15556  #include <linux/pid_namespace.h>
15557  #include <linux/nsproxy.h>
15558 +#include <linux/vs_context.h>
15559 +#include <linux/vs_pid.h>
15560  #define CREATE_TRACE_POINTS
15561  #include <trace/events/signal.h>
15562  
15563 @@ -646,9 +648,18 @@ static int check_kill_permission(int sig
15564         struct pid *sid;
15565         int error;
15566  
15567 +       vxdprintk(VXD_CBIT(misc, 7),
15568 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15569 +               sig, info, t, vx_task_xid(t), t->pid);
15570 +
15571         if (!valid_signal(sig))
15572                 return -EINVAL;
15573  
15574 +/*     FIXME: needed? if so, why?
15575 +       if ((info != SEND_SIG_NOINFO) &&
15576 +               (is_si_special(info) || !si_fromuser(info)))
15577 +               goto skip;      */
15578 +
15579         if (!si_fromuser(info))
15580                 return 0;
15581  
15582 @@ -678,6 +689,20 @@ static int check_kill_permission(int sig
15583                 }
15584         }
15585  
15586 +       error = -EPERM;
15587 +       if (t->pid == 1 && current->xid)
15588 +               return error;
15589 +
15590 +       error = -ESRCH;
15591 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15592 +                 loops, maybe ENOENT or EACCES? */
15593 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15594 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15595 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15596 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15597 +               return error;
15598 +       }
15599 +/* skip: */
15600         return security_task_kill(t, info, sig, 0);
15601  }
15602  
15603 @@ -1171,7 +1196,7 @@ int kill_pid_info(int sig, struct siginf
15604         rcu_read_lock();
15605  retry:
15606         p = pid_task(pid, PIDTYPE_PID);
15607 -       if (p) {
15608 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15609                 error = group_send_sig_info(sig, info, p);
15610                 if (unlikely(error == -ESRCH))
15611                         /*
15612 @@ -1211,7 +1236,7 @@ int kill_pid_info_as_uid(int sig, struct
15613  
15614         rcu_read_lock();
15615         p = pid_task(pid, PIDTYPE_PID);
15616 -       if (!p) {
15617 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15618                 ret = -ESRCH;
15619                 goto out_unlock;
15620         }
15621 @@ -1266,8 +1291,10 @@ static int kill_something_info(int sig, 
15622                 struct task_struct * p;
15623  
15624                 for_each_process(p) {
15625 -                       if (task_pid_vnr(p) > 1 &&
15626 -                                       !same_thread_group(p, current)) {
15627 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15628 +                               task_pid_vnr(p) > 1 &&
15629 +                               !same_thread_group(p, current) &&
15630 +                               !vx_current_initpid(p->pid)) {
15631                                 int err = group_send_sig_info(sig, info, p);
15632                                 ++count;
15633                                 if (err != -EPERM)
15634 @@ -1936,6 +1963,11 @@ relock:
15635                                 !sig_kernel_only(signr))
15636                         continue;
15637  
15638 +               /* virtual init is protected against user signals */
15639 +               if ((info->si_code == SI_USER) &&
15640 +                       vx_current_initpid(current->pid))
15641 +                       continue;
15642 +
15643                 if (sig_kernel_stop(signr)) {
15644                         /*
15645                          * The default action is to stop all threads in
15646 diff -NurpP --minimal linux-2.6.37/kernel/softirq.c linux-2.6.37-vs2.3.0.37-rc2/kernel/softirq.c
15647 --- linux-2.6.37/kernel/softirq.c       2011-01-05 21:50:38.000000000 +0100
15648 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/softirq.c        2010-11-23 02:09:41.000000000 +0100
15649 @@ -24,6 +24,7 @@
15650  #include <linux/ftrace.h>
15651  #include <linux/smp.h>
15652  #include <linux/tick.h>
15653 +#include <linux/vs_context.h>
15654  
15655  #define CREATE_TRACE_POINTS
15656  #include <trace/events/irq.h>
15657 diff -NurpP --minimal linux-2.6.37/kernel/sys.c linux-2.6.37-vs2.3.0.37-rc2/kernel/sys.c
15658 --- linux-2.6.37/kernel/sys.c   2010-10-21 13:07:57.000000000 +0200
15659 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/sys.c    2010-11-23 02:09:41.000000000 +0100
15660 @@ -42,6 +42,7 @@
15661  #include <linux/syscalls.h>
15662  #include <linux/kprobes.h>
15663  #include <linux/user_namespace.h>
15664 +#include <linux/vs_pid.h>
15665  
15666  #include <asm/uaccess.h>
15667  #include <asm/io.h>
15668 @@ -131,7 +132,10 @@ static int set_one_prio(struct task_stru
15669                 goto out;
15670         }
15671         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15672 -               error = -EACCES;
15673 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15674 +                       error = 0;
15675 +               else
15676 +                       error = -EACCES;
15677                 goto out;
15678         }
15679         no_nice = security_task_setnice(p, niceval);
15680 @@ -181,6 +185,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15681                         else
15682                                 pgrp = task_pgrp(current);
15683                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15684 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15685 +                                       continue;
15686                                 error = set_one_prio(p, niceval, error);
15687                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15688                         break;
15689 @@ -244,6 +250,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15690                         else
15691                                 pgrp = task_pgrp(current);
15692                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15693 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15694 +                                       continue;
15695                                 niceval = 20 - task_nice(p);
15696                                 if (niceval > retval)
15697                                         retval = niceval;
15698 @@ -357,6 +365,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15699  
15700  static DEFINE_MUTEX(reboot_mutex);
15701  
15702 +long vs_reboot(unsigned int, void __user *);
15703 +
15704  /*
15705   * Reboot system call: for obvious reasons only root may call it,
15706   * and even root needs to set up some magic numbers in the registers
15707 @@ -389,6 +399,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15708         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15709                 cmd = LINUX_REBOOT_CMD_HALT;
15710  
15711 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15712 +               return vs_reboot(cmd, arg);
15713 +
15714         mutex_lock(&reboot_mutex);
15715         switch (cmd) {
15716         case LINUX_REBOOT_CMD_RESTART:
15717 @@ -1169,7 +1182,7 @@ SYSCALL_DEFINE2(sethostname, char __user
15718         int errno;
15719         char tmp[__NEW_UTS_LEN];
15720  
15721 -       if (!capable(CAP_SYS_ADMIN))
15722 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15723                 return -EPERM;
15724         if (len < 0 || len > __NEW_UTS_LEN)
15725                 return -EINVAL;
15726 @@ -1218,7 +1231,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
15727         int errno;
15728         char tmp[__NEW_UTS_LEN];
15729  
15730 -       if (!capable(CAP_SYS_ADMIN))
15731 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15732                 return -EPERM;
15733         if (len < 0 || len > __NEW_UTS_LEN)
15734                 return -EINVAL;
15735 @@ -1334,7 +1347,7 @@ int do_prlimit(struct task_struct *tsk, 
15736         task_lock(tsk->group_leader);
15737         if (new_rlim) {
15738                 if (new_rlim->rlim_max > rlim->rlim_max &&
15739 -                               !capable(CAP_SYS_RESOURCE))
15740 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15741                         retval = -EPERM;
15742                 if (!retval)
15743                         retval = security_task_setrlimit(tsk->group_leader,
15744 @@ -1383,7 +1396,7 @@ static int check_prlimit_permission(stru
15745              cred->gid != tcred->egid ||
15746              cred->gid != tcred->sgid ||
15747              cred->gid != tcred->gid) &&
15748 -            !capable(CAP_SYS_RESOURCE)) {
15749 +            !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT)) {
15750                 return -EPERM;
15751         }
15752  
15753 diff -NurpP --minimal linux-2.6.37/kernel/sysctl_binary.c linux-2.6.37-vs2.3.0.37-rc2/kernel/sysctl_binary.c
15754 --- linux-2.6.37/kernel/sysctl_binary.c 2010-08-02 16:52:57.000000000 +0200
15755 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/sysctl_binary.c  2010-11-23 02:09:41.000000000 +0100
15756 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15757  
15758         { CTL_INT,      KERN_PANIC,                     "panic" },
15759         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15760 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15761  
15762         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15763         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15764 diff -NurpP --minimal linux-2.6.37/kernel/sysctl.c linux-2.6.37-vs2.3.0.37-rc2/kernel/sysctl.c
15765 --- linux-2.6.37/kernel/sysctl.c        2011-01-05 21:50:39.000000000 +0100
15766 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/sysctl.c 2010-11-23 02:09:41.000000000 +0100
15767 @@ -73,6 +73,7 @@
15768  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15769  #include <linux/lockdep.h>
15770  #endif
15771 +extern char vshelper_path[];
15772  #ifdef CONFIG_CHR_DEV_SG
15773  #include <scsi/sg.h>
15774  #endif
15775 @@ -571,6 +572,13 @@ static struct ctl_table kern_table[] = {
15776                 .proc_handler   = proc_dostring,
15777         },
15778  #endif
15779 +       {
15780 +               .procname       = "vshelper",
15781 +               .data           = &vshelper_path,
15782 +               .maxlen         = 256,
15783 +               .mode           = 0644,
15784 +               .proc_handler   = &proc_dostring,
15785 +       },
15786  #ifdef CONFIG_CHR_DEV_SG
15787         {
15788                 .procname       = "sg-big-buff",
15789 diff -NurpP --minimal linux-2.6.37/kernel/time/timekeeping.c linux-2.6.37-vs2.3.0.37-rc2/kernel/time/timekeeping.c
15790 --- linux-2.6.37/kernel/time/timekeeping.c      2010-10-21 13:07:57.000000000 +0200
15791 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/time/timekeeping.c       2010-11-23 02:09:41.000000000 +0100
15792 @@ -229,6 +229,7 @@ void getnstimeofday(struct timespec *ts)
15793         } while (read_seqretry(&xtime_lock, seq));
15794  
15795         timespec_add_ns(ts, nsecs);
15796 +       vx_adjust_timespec(ts);
15797  }
15798  
15799  EXPORT_SYMBOL(getnstimeofday);
15800 diff -NurpP --minimal linux-2.6.37/kernel/time.c linux-2.6.37-vs2.3.0.37-rc2/kernel/time.c
15801 --- linux-2.6.37/kernel/time.c  2010-10-21 13:07:57.000000000 +0200
15802 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/time.c   2010-11-23 02:09:41.000000000 +0100
15803 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15804         if (err)
15805                 return err;
15806  
15807 -       do_settimeofday(&tv);
15808 +       vx_settimeofday(&tv);
15809         return 0;
15810  }
15811  
15812 @@ -177,7 +177,7 @@ int do_sys_settimeofday(struct timespec 
15813                 /* SMP safe, again the code in arch/foo/time.c should
15814                  * globally block out interrupts when it runs.
15815                  */
15816 -               return do_settimeofday(tv);
15817 +               return vx_settimeofday(tv);
15818         }
15819         return 0;
15820  }
15821 diff -NurpP --minimal linux-2.6.37/kernel/timer.c linux-2.6.37-vs2.3.0.37-rc2/kernel/timer.c
15822 --- linux-2.6.37/kernel/timer.c 2011-01-05 21:50:39.000000000 +0100
15823 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/timer.c  2011-01-05 22:30:42.000000000 +0100
15824 @@ -40,6 +40,10 @@
15825  #include <linux/irq_work.h>
15826  #include <linux/sched.h>
15827  #include <linux/slab.h>
15828 +#include <linux/vs_base.h>
15829 +#include <linux/vs_cvirt.h>
15830 +#include <linux/vs_pid.h>
15831 +#include <linux/vserver/sched.h>
15832  
15833  #include <asm/uaccess.h>
15834  #include <asm/unistd.h>
15835 @@ -1341,12 +1345,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15836  
15837  #endif
15838  
15839 -#ifndef __alpha__
15840 -
15841 -/*
15842 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15843 - * should be moved into arch/i386 instead?
15844 - */
15845  
15846  /**
15847   * sys_getpid - return the thread group id of the current process
15848 @@ -1375,10 +1373,23 @@ SYSCALL_DEFINE0(getppid)
15849         rcu_read_lock();
15850         pid = task_tgid_vnr(current->real_parent);
15851         rcu_read_unlock();
15852 +       return vx_map_pid(pid);
15853 +}
15854  
15855 -       return pid;
15856 +#ifdef __alpha__
15857 +
15858 +/*
15859 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15860 + */
15861 +
15862 +asmlinkage long do_getxpid(long *ppid)
15863 +{
15864 +       *ppid = sys_getppid();
15865 +       return sys_getpid();
15866  }
15867  
15868 +#else /* _alpha_ */
15869 +
15870  SYSCALL_DEFINE0(getuid)
15871  {
15872         /* Only we change this so SMP safe */
15873 diff -NurpP --minimal linux-2.6.37/kernel/user_namespace.c linux-2.6.37-vs2.3.0.37-rc2/kernel/user_namespace.c
15874 --- linux-2.6.37/kernel/user_namespace.c        2010-10-21 13:07:57.000000000 +0200
15875 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/user_namespace.c 2010-11-23 02:09:41.000000000 +0100
15876 @@ -11,6 +11,7 @@
15877  #include <linux/user_namespace.h>
15878  #include <linux/highuid.h>
15879  #include <linux/cred.h>
15880 +#include <linux/vserver/global.h>
15881  
15882  /*
15883   * Create a new user namespace, deriving the creator from the user in the
15884 @@ -31,6 +32,7 @@ int create_user_ns(struct cred *new)
15885                 return -ENOMEM;
15886  
15887         kref_init(&ns->kref);
15888 +       atomic_inc(&vs_global_user_ns);
15889  
15890         for (n = 0; n < UIDHASH_SZ; ++n)
15891                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15892 @@ -79,6 +81,8 @@ void free_user_ns(struct kref *kref)
15893         struct user_namespace *ns =
15894                 container_of(kref, struct user_namespace, kref);
15895  
15896 +       /* FIXME: maybe move into destroyer? */
15897 +       atomic_dec(&vs_global_user_ns);
15898         INIT_WORK(&ns->destroyer, free_user_ns_work);
15899         schedule_work(&ns->destroyer);
15900  }
15901 diff -NurpP --minimal linux-2.6.37/kernel/utsname.c linux-2.6.37-vs2.3.0.37-rc2/kernel/utsname.c
15902 --- linux-2.6.37/kernel/utsname.c       2009-09-10 15:26:28.000000000 +0200
15903 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/utsname.c        2010-11-23 02:09:41.000000000 +0100
15904 @@ -14,14 +14,17 @@
15905  #include <linux/utsname.h>
15906  #include <linux/err.h>
15907  #include <linux/slab.h>
15908 +#include <linux/vserver/global.h>
15909  
15910  static struct uts_namespace *create_uts_ns(void)
15911  {
15912         struct uts_namespace *uts_ns;
15913  
15914         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15915 -       if (uts_ns)
15916 +       if (uts_ns) {
15917                 kref_init(&uts_ns->kref);
15918 +               atomic_inc(&vs_global_uts_ns);
15919 +       }
15920         return uts_ns;
15921  }
15922  
15923 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
15924         struct uts_namespace *ns;
15925  
15926         ns = container_of(kref, struct uts_namespace, kref);
15927 +       atomic_dec(&vs_global_uts_ns);
15928         kfree(ns);
15929  }
15930 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cacct.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cacct.c
15931 --- linux-2.6.37/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
15932 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cacct.c  2010-11-23 02:09:41.000000000 +0100
15933 @@ -0,0 +1,42 @@
15934 +/*
15935 + *  linux/kernel/vserver/cacct.c
15936 + *
15937 + *  Virtual Server: Context Accounting
15938 + *
15939 + *  Copyright (C) 2006-2007 Herbert Pötzl
15940 + *
15941 + *  V0.01  added accounting stats
15942 + *
15943 + */
15944 +
15945 +#include <linux/types.h>
15946 +#include <linux/vs_context.h>
15947 +#include <linux/vserver/cacct_cmd.h>
15948 +#include <linux/vserver/cacct_int.h>
15949 +
15950 +#include <asm/errno.h>
15951 +#include <asm/uaccess.h>
15952 +
15953 +
15954 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15955 +{
15956 +       struct vcmd_sock_stat_v0 vc_data;
15957 +       int j, field;
15958 +
15959 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15960 +               return -EFAULT;
15961 +
15962 +       field = vc_data.field;
15963 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15964 +               return -EINVAL;
15965 +
15966 +       for (j = 0; j < 3; j++) {
15967 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15968 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15969 +       }
15970 +
15971 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15972 +               return -EFAULT;
15973 +       return 0;
15974 +}
15975 +
15976 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cacct_init.h linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cacct_init.h
15977 --- linux-2.6.37/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
15978 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cacct_init.h     2010-11-23 02:09:41.000000000 +0100
15979 @@ -0,0 +1,25 @@
15980 +
15981 +
15982 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15983 +{
15984 +       int i, j;
15985 +
15986 +
15987 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15988 +               for (j = 0; j < 3; j++) {
15989 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15990 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15991 +               }
15992 +       }
15993 +       for (i = 0; i < 8; i++)
15994 +               atomic_set(&cacct->slab[i], 0);
15995 +       for (i = 0; i < 5; i++)
15996 +               for (j = 0; j < 4; j++)
15997 +                       atomic_set(&cacct->page[i][j], 0);
15998 +}
15999 +
16000 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16001 +{
16002 +       return;
16003 +}
16004 +
16005 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cacct_proc.h linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cacct_proc.h
16006 --- linux-2.6.37/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
16007 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cacct_proc.h     2010-11-23 02:09:41.000000000 +0100
16008 @@ -0,0 +1,53 @@
16009 +#ifndef _VX_CACCT_PROC_H
16010 +#define _VX_CACCT_PROC_H
16011 +
16012 +#include <linux/vserver/cacct_int.h>
16013 +
16014 +
16015 +#define VX_SOCKA_TOP   \
16016 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16017 +
16018 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16019 +{
16020 +       int i, j, length = 0;
16021 +       static char *type[VXA_SOCK_SIZE] = {
16022 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16023 +       };
16024 +
16025 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16026 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16027 +               length += sprintf(buffer + length, "%s:", type[i]);
16028 +               for (j = 0; j < 3; j++) {
16029 +                       length += sprintf(buffer + length,
16030 +                               "\t%10lu/%-10lu",
16031 +                               vx_sock_count(cacct, i, j),
16032 +                               vx_sock_total(cacct, i, j));
16033 +               }
16034 +               buffer[length++] = '\n';
16035 +       }
16036 +
16037 +       length += sprintf(buffer + length, "\n");
16038 +       length += sprintf(buffer + length,
16039 +               "slab:\t %8u %8u %8u %8u\n",
16040 +               atomic_read(&cacct->slab[1]),
16041 +               atomic_read(&cacct->slab[4]),
16042 +               atomic_read(&cacct->slab[0]),
16043 +               atomic_read(&cacct->slab[2]));
16044 +
16045 +       length += sprintf(buffer + length, "\n");
16046 +       for (i = 0; i < 5; i++) {
16047 +               length += sprintf(buffer + length,
16048 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16049 +                       atomic_read(&cacct->page[i][0]),
16050 +                       atomic_read(&cacct->page[i][1]),
16051 +                       atomic_read(&cacct->page[i][2]),
16052 +                       atomic_read(&cacct->page[i][3]),
16053 +                       atomic_read(&cacct->page[i][4]),
16054 +                       atomic_read(&cacct->page[i][5]),
16055 +                       atomic_read(&cacct->page[i][6]),
16056 +                       atomic_read(&cacct->page[i][7]));
16057 +       }
16058 +       return length;
16059 +}
16060 +
16061 +#endif /* _VX_CACCT_PROC_H */
16062 diff -NurpP --minimal linux-2.6.37/kernel/vserver/context.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/context.c
16063 --- linux-2.6.37/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
16064 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/context.c        2011-01-08 03:38:49.000000000 +0100
16065 @@ -0,0 +1,1088 @@
16066 +/*
16067 + *  linux/kernel/vserver/context.c
16068 + *
16069 + *  Virtual Server: Context Support
16070 + *
16071 + *  Copyright (C) 2003-2010  Herbert Pötzl
16072 + *
16073 + *  V0.01  context helper
16074 + *  V0.02  vx_ctx_kill syscall command
16075 + *  V0.03  replaced context_info calls
16076 + *  V0.04  redesign of struct (de)alloc
16077 + *  V0.05  rlimit basic implementation
16078 + *  V0.06  task_xid and info commands
16079 + *  V0.07  context flags and caps
16080 + *  V0.08  switch to RCU based hash
16081 + *  V0.09  revert to non RCU for now
16082 + *  V0.10  and back to working RCU hash
16083 + *  V0.11  and back to locking again
16084 + *  V0.12  referenced context store
16085 + *  V0.13  separate per cpu data
16086 + *  V0.14  changed vcmds to vxi arg
16087 + *  V0.15  added context stat
16088 + *  V0.16  have __create claim() the vxi
16089 + *  V0.17  removed older and legacy stuff
16090 + *  V0.18  added user credentials
16091 + *
16092 + */
16093 +
16094 +#include <linux/slab.h>
16095 +#include <linux/types.h>
16096 +#include <linux/security.h>
16097 +#include <linux/pid_namespace.h>
16098 +
16099 +#include <linux/vserver/context.h>
16100 +#include <linux/vserver/network.h>
16101 +#include <linux/vserver/debug.h>
16102 +#include <linux/vserver/limit.h>
16103 +#include <linux/vserver/limit_int.h>
16104 +#include <linux/vserver/space.h>
16105 +#include <linux/init_task.h>
16106 +#include <linux/fs_struct.h>
16107 +#include <linux/cred.h>
16108 +
16109 +#include <linux/vs_context.h>
16110 +#include <linux/vs_limit.h>
16111 +#include <linux/vs_pid.h>
16112 +#include <linux/vserver/context_cmd.h>
16113 +
16114 +#include "cvirt_init.h"
16115 +#include "cacct_init.h"
16116 +#include "limit_init.h"
16117 +#include "sched_init.h"
16118 +
16119 +
16120 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16121 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16122 +
16123 +
16124 +/*     now inactive context structures */
16125 +
16126 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16127 +
16128 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
16129 +
16130 +
16131 +/*     __alloc_vx_info()
16132 +
16133 +       * allocate an initialized vx_info struct
16134 +       * doesn't make it visible (hash)                        */
16135 +
16136 +static struct vx_info *__alloc_vx_info(xid_t xid)
16137 +{
16138 +       struct vx_info *new = NULL;
16139 +       int cpu, index;
16140 +
16141 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16142 +
16143 +       /* would this benefit from a slab cache? */
16144 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16145 +       if (!new)
16146 +               return 0;
16147 +
16148 +       memset(new, 0, sizeof(struct vx_info));
16149 +#ifdef CONFIG_SMP
16150 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16151 +       if (!new->ptr_pc)
16152 +               goto error;
16153 +#endif
16154 +       new->vx_id = xid;
16155 +       INIT_HLIST_NODE(&new->vx_hlist);
16156 +       atomic_set(&new->vx_usecnt, 0);
16157 +       atomic_set(&new->vx_tasks, 0);
16158 +       new->vx_parent = NULL;
16159 +       new->vx_state = 0;
16160 +       init_waitqueue_head(&new->vx_wait);
16161 +
16162 +       /* prepare reaper */
16163 +       get_task_struct(init_pid_ns.child_reaper);
16164 +       new->vx_reaper = init_pid_ns.child_reaper;
16165 +       new->vx_badness_bias = 0;
16166 +
16167 +       /* rest of init goes here */
16168 +       vx_info_init_limit(&new->limit);
16169 +       vx_info_init_sched(&new->sched);
16170 +       vx_info_init_cvirt(&new->cvirt);
16171 +       vx_info_init_cacct(&new->cacct);
16172 +
16173 +       /* per cpu data structures */
16174 +       for_each_possible_cpu(cpu) {
16175 +               vx_info_init_sched_pc(
16176 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16177 +               vx_info_init_cvirt_pc(
16178 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16179 +       }
16180 +
16181 +       new->vx_flags = VXF_INIT_SET;
16182 +       cap_set_init_eff(new->vx_bcaps);
16183 +       new->vx_ccaps = 0;
16184 +       new->vx_umask = 0;
16185 +
16186 +       new->reboot_cmd = 0;
16187 +       new->exit_code = 0;
16188 +
16189 +       // preconfig spaces
16190 +       for (index = 0; index < VX_SPACES; index++) {
16191 +               struct _vx_space *space = &new->space[index];
16192 +
16193 +               // filesystem
16194 +               spin_lock(&init_fs.lock);
16195 +               init_fs.users++;
16196 +               spin_unlock(&init_fs.lock);
16197 +               space->vx_fs = &init_fs;
16198 +
16199 +               /* FIXME: do we want defaults? */
16200 +               // space->vx_real_cred = 0;
16201 +               // space->vx_cred = 0;
16202 +       }
16203 +
16204 +
16205 +       vxdprintk(VXD_CBIT(xid, 0),
16206 +               "alloc_vx_info(%d) = %p", xid, new);
16207 +       vxh_alloc_vx_info(new);
16208 +       atomic_inc(&vx_global_ctotal);
16209 +       return new;
16210 +#ifdef CONFIG_SMP
16211 +error:
16212 +       kfree(new);
16213 +       return 0;
16214 +#endif
16215 +}
16216 +
16217 +/*     __dealloc_vx_info()
16218 +
16219 +       * final disposal of vx_info                             */
16220 +
16221 +static void __dealloc_vx_info(struct vx_info *vxi)
16222 +{
16223 +#ifdef CONFIG_VSERVER_WARN
16224 +       struct vx_info_save vxis;
16225 +       int cpu;
16226 +#endif
16227 +       vxdprintk(VXD_CBIT(xid, 0),
16228 +               "dealloc_vx_info(%p)", vxi);
16229 +       vxh_dealloc_vx_info(vxi);
16230 +
16231 +#ifdef CONFIG_VSERVER_WARN
16232 +       enter_vx_info(vxi, &vxis);
16233 +       vx_info_exit_limit(&vxi->limit);
16234 +       vx_info_exit_sched(&vxi->sched);
16235 +       vx_info_exit_cvirt(&vxi->cvirt);
16236 +       vx_info_exit_cacct(&vxi->cacct);
16237 +
16238 +       for_each_possible_cpu(cpu) {
16239 +               vx_info_exit_sched_pc(
16240 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16241 +               vx_info_exit_cvirt_pc(
16242 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16243 +       }
16244 +       leave_vx_info(&vxis);
16245 +#endif
16246 +
16247 +       vxi->vx_id = -1;
16248 +       vxi->vx_state |= VXS_RELEASED;
16249 +
16250 +#ifdef CONFIG_SMP
16251 +       free_percpu(vxi->ptr_pc);
16252 +#endif
16253 +       kfree(vxi);
16254 +       atomic_dec(&vx_global_ctotal);
16255 +}
16256 +
16257 +static void __shutdown_vx_info(struct vx_info *vxi)
16258 +{
16259 +       struct nsproxy *nsproxy;
16260 +       struct fs_struct *fs;
16261 +       const struct cred *cred;
16262 +       int index, kill;
16263 +
16264 +       might_sleep();
16265 +
16266 +       vxi->vx_state |= VXS_SHUTDOWN;
16267 +       vs_state_change(vxi, VSC_SHUTDOWN);
16268 +
16269 +       for (index = 0; index < VX_SPACES; index++) {
16270 +               struct _vx_space *space = &vxi->space[index];
16271 +
16272 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16273 +               if (nsproxy)
16274 +                       put_nsproxy(nsproxy);
16275 +
16276 +               fs = xchg(&space->vx_fs, NULL);
16277 +               spin_lock(&fs->lock);
16278 +               kill = !--fs->users;
16279 +               spin_unlock(&fs->lock);
16280 +               if (kill)
16281 +                       free_fs_struct(fs);
16282 +#if 0
16283 +               cred = xchg(&space->vx_real_cred, NULL);
16284 +               if (cred) {
16285 +                       alter_cred_subscribers(cred, -1);
16286 +                       put_cred(cred);
16287 +               }
16288 +
16289 +               cred = xchg(&space->vx_cred, NULL);
16290 +               if (cred) {
16291 +                       alter_cred_subscribers(cred, -1);
16292 +                       put_cred(cred);
16293 +               }
16294 +#endif
16295 +       }
16296 +}
16297 +
16298 +/* exported stuff */
16299 +
16300 +void free_vx_info(struct vx_info *vxi)
16301 +{
16302 +       unsigned long flags;
16303 +       unsigned index;
16304 +
16305 +       /* check for reference counts first */
16306 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16307 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16308 +
16309 +       /* context must not be hashed */
16310 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16311 +
16312 +       /* context shutdown is mandatory */
16313 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16314 +
16315 +       /* spaces check */
16316 +       for (index = 0; index < VX_SPACES; index++) {
16317 +               struct _vx_space *space = &vxi->space[index];
16318 +
16319 +               BUG_ON(space->vx_nsproxy);
16320 +               BUG_ON(space->vx_fs);
16321 +               // BUG_ON(space->vx_real_cred);
16322 +               // BUG_ON(space->vx_cred);
16323 +       }
16324 +
16325 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16326 +       hlist_del(&vxi->vx_hlist);
16327 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16328 +
16329 +       __dealloc_vx_info(vxi);
16330 +}
16331 +
16332 +
16333 +/*     hash table for vx_info hash */
16334 +
16335 +#define VX_HASH_SIZE   13
16336 +
16337 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16338 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16339 +
16340 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
16341 +
16342 +
16343 +static inline unsigned int __hashval(xid_t xid)
16344 +{
16345 +       return (xid % VX_HASH_SIZE);
16346 +}
16347 +
16348 +
16349 +
16350 +/*     __hash_vx_info()
16351 +
16352 +       * add the vxi to the global hash table
16353 +       * requires the hash_lock to be held                     */
16354 +
16355 +static inline void __hash_vx_info(struct vx_info *vxi)
16356 +{
16357 +       struct hlist_head *head;
16358 +
16359 +       vxd_assert_lock(&vx_info_hash_lock);
16360 +       vxdprintk(VXD_CBIT(xid, 4),
16361 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16362 +       vxh_hash_vx_info(vxi);
16363 +
16364 +       /* context must not be hashed */
16365 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16366 +
16367 +       vxi->vx_state |= VXS_HASHED;
16368 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16369 +       hlist_add_head(&vxi->vx_hlist, head);
16370 +       atomic_inc(&vx_global_cactive);
16371 +}
16372 +
16373 +/*     __unhash_vx_info()
16374 +
16375 +       * remove the vxi from the global hash table
16376 +       * requires the hash_lock to be held                     */
16377 +
16378 +static inline void __unhash_vx_info(struct vx_info *vxi)
16379 +{
16380 +       unsigned long flags;
16381 +
16382 +       vxd_assert_lock(&vx_info_hash_lock);
16383 +       vxdprintk(VXD_CBIT(xid, 4),
16384 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16385 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16386 +       vxh_unhash_vx_info(vxi);
16387 +
16388 +       /* context must be hashed */
16389 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16390 +       /* but without tasks */
16391 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16392 +
16393 +       vxi->vx_state &= ~VXS_HASHED;
16394 +       hlist_del_init(&vxi->vx_hlist);
16395 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16396 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16397 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16398 +       atomic_dec(&vx_global_cactive);
16399 +}
16400 +
16401 +
16402 +/*     __lookup_vx_info()
16403 +
16404 +       * requires the hash_lock to be held
16405 +       * doesn't increment the vx_refcnt                       */
16406 +
16407 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16408 +{
16409 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16410 +       struct hlist_node *pos;
16411 +       struct vx_info *vxi;
16412 +
16413 +       vxd_assert_lock(&vx_info_hash_lock);
16414 +       hlist_for_each(pos, head) {
16415 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16416 +
16417 +               if (vxi->vx_id == xid)
16418 +                       goto found;
16419 +       }
16420 +       vxi = NULL;
16421 +found:
16422 +       vxdprintk(VXD_CBIT(xid, 0),
16423 +               "__lookup_vx_info(#%u): %p[#%u]",
16424 +               xid, vxi, vxi ? vxi->vx_id : 0);
16425 +       vxh_lookup_vx_info(vxi, xid);
16426 +       return vxi;
16427 +}
16428 +
16429 +
16430 +/*     __create_vx_info()
16431 +
16432 +       * create the requested context
16433 +       * get(), claim() and hash it                            */
16434 +
16435 +static struct vx_info *__create_vx_info(int id)
16436 +{
16437 +       struct vx_info *new, *vxi = NULL;
16438 +
16439 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16440 +
16441 +       if (!(new = __alloc_vx_info(id)))
16442 +               return ERR_PTR(-ENOMEM);
16443 +
16444 +       /* required to make dynamic xids unique */
16445 +       spin_lock(&vx_info_hash_lock);
16446 +
16447 +       /* static context requested */
16448 +       if ((vxi = __lookup_vx_info(id))) {
16449 +               vxdprintk(VXD_CBIT(xid, 0),
16450 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16451 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16452 +                       vxi = ERR_PTR(-EBUSY);
16453 +               else
16454 +                       vxi = ERR_PTR(-EEXIST);
16455 +               goto out_unlock;
16456 +       }
16457 +       /* new context */
16458 +       vxdprintk(VXD_CBIT(xid, 0),
16459 +               "create_vx_info(%d) = %p (new)", id, new);
16460 +       claim_vx_info(new, NULL);
16461 +       __hash_vx_info(get_vx_info(new));
16462 +       vxi = new, new = NULL;
16463 +
16464 +out_unlock:
16465 +       spin_unlock(&vx_info_hash_lock);
16466 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16467 +       if (new)
16468 +               __dealloc_vx_info(new);
16469 +       return vxi;
16470 +}
16471 +
16472 +
16473 +/*     exported stuff                                          */
16474 +
16475 +
16476 +void unhash_vx_info(struct vx_info *vxi)
16477 +{
16478 +       __shutdown_vx_info(vxi);
16479 +       spin_lock(&vx_info_hash_lock);
16480 +       __unhash_vx_info(vxi);
16481 +       spin_unlock(&vx_info_hash_lock);
16482 +       __wakeup_vx_info(vxi);
16483 +}
16484 +
16485 +
16486 +/*     lookup_vx_info()
16487 +
16488 +       * search for a vx_info and get() it
16489 +       * negative id means current                             */
16490 +
16491 +struct vx_info *lookup_vx_info(int id)
16492 +{
16493 +       struct vx_info *vxi = NULL;
16494 +
16495 +       if (id < 0) {
16496 +               vxi = get_vx_info(current_vx_info());
16497 +       } else if (id > 1) {
16498 +               spin_lock(&vx_info_hash_lock);
16499 +               vxi = get_vx_info(__lookup_vx_info(id));
16500 +               spin_unlock(&vx_info_hash_lock);
16501 +       }
16502 +       return vxi;
16503 +}
16504 +
16505 +/*     xid_is_hashed()
16506 +
16507 +       * verify that xid is still hashed                       */
16508 +
16509 +int xid_is_hashed(xid_t xid)
16510 +{
16511 +       int hashed;
16512 +
16513 +       spin_lock(&vx_info_hash_lock);
16514 +       hashed = (__lookup_vx_info(xid) != NULL);
16515 +       spin_unlock(&vx_info_hash_lock);
16516 +       return hashed;
16517 +}
16518 +
16519 +#ifdef CONFIG_PROC_FS
16520 +
16521 +/*     get_xid_list()
16522 +
16523 +       * get a subset of hashed xids for proc
16524 +       * assumes size is at least one                          */
16525 +
16526 +int get_xid_list(int index, unsigned int *xids, int size)
16527 +{
16528 +       int hindex, nr_xids = 0;
16529 +
16530 +       /* only show current and children */
16531 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16532 +               if (index > 0)
16533 +                       return 0;
16534 +               xids[nr_xids] = vx_current_xid();
16535 +               return 1;
16536 +       }
16537 +
16538 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16539 +               struct hlist_head *head = &vx_info_hash[hindex];
16540 +               struct hlist_node *pos;
16541 +
16542 +               spin_lock(&vx_info_hash_lock);
16543 +               hlist_for_each(pos, head) {
16544 +                       struct vx_info *vxi;
16545 +
16546 +                       if (--index > 0)
16547 +                               continue;
16548 +
16549 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16550 +                       xids[nr_xids] = vxi->vx_id;
16551 +                       if (++nr_xids >= size) {
16552 +                               spin_unlock(&vx_info_hash_lock);
16553 +                               goto out;
16554 +                       }
16555 +               }
16556 +               /* keep the lock time short */
16557 +               spin_unlock(&vx_info_hash_lock);
16558 +       }
16559 +out:
16560 +       return nr_xids;
16561 +}
16562 +#endif
16563 +
16564 +#ifdef CONFIG_VSERVER_DEBUG
16565 +
16566 +void   dump_vx_info_inactive(int level)
16567 +{
16568 +       struct hlist_node *entry, *next;
16569 +
16570 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16571 +               struct vx_info *vxi =
16572 +                       list_entry(entry, struct vx_info, vx_hlist);
16573 +
16574 +               dump_vx_info(vxi, level);
16575 +       }
16576 +}
16577 +
16578 +#endif
16579 +
16580 +#if 0
16581 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16582 +{
16583 +       struct user_struct *new_user, *old_user;
16584 +
16585 +       if (!p || !vxi)
16586 +               BUG();
16587 +
16588 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16589 +               return -EACCES;
16590 +
16591 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16592 +       if (!new_user)
16593 +               return -ENOMEM;
16594 +
16595 +       old_user = p->user;
16596 +       if (new_user != old_user) {
16597 +               atomic_inc(&new_user->processes);
16598 +               atomic_dec(&old_user->processes);
16599 +               p->user = new_user;
16600 +       }
16601 +       free_uid(old_user);
16602 +       return 0;
16603 +}
16604 +#endif
16605 +
16606 +#if 0
16607 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16608 +{
16609 +       // p->cap_effective &= vxi->vx_cap_bset;
16610 +       p->cap_effective =
16611 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16612 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16613 +       p->cap_inheritable =
16614 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16615 +       // p->cap_permitted &= vxi->vx_cap_bset;
16616 +       p->cap_permitted =
16617 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16618 +}
16619 +#endif
16620 +
16621 +
16622 +#include <linux/file.h>
16623 +#include <linux/fdtable.h>
16624 +
16625 +static int vx_openfd_task(struct task_struct *tsk)
16626 +{
16627 +       struct files_struct *files = tsk->files;
16628 +       struct fdtable *fdt;
16629 +       const unsigned long *bptr;
16630 +       int count, total;
16631 +
16632 +       /* no rcu_read_lock() because of spin_lock() */
16633 +       spin_lock(&files->file_lock);
16634 +       fdt = files_fdtable(files);
16635 +       bptr = fdt->open_fds->fds_bits;
16636 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16637 +       for (total = 0; count > 0; count--) {
16638 +               if (*bptr)
16639 +                       total += hweight_long(*bptr);
16640 +               bptr++;
16641 +       }
16642 +       spin_unlock(&files->file_lock);
16643 +       return total;
16644 +}
16645 +
16646 +
16647 +/*     for *space compatibility */
16648 +
16649 +asmlinkage long sys_unshare(unsigned long);
16650 +
16651 +/*
16652 + *     migrate task to new context
16653 + *     gets vxi, puts old_vxi on change
16654 + *     optionally unshares namespaces (hack)
16655 + */
16656 +
16657 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16658 +{
16659 +       struct vx_info *old_vxi;
16660 +       int ret = 0;
16661 +
16662 +       if (!p || !vxi)
16663 +               BUG();
16664 +
16665 +       vxdprintk(VXD_CBIT(xid, 5),
16666 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16667 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16668 +
16669 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16670 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16671 +               return -EACCES;
16672 +
16673 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16674 +               return -EFAULT;
16675 +
16676 +       old_vxi = task_get_vx_info(p);
16677 +       if (old_vxi == vxi)
16678 +               goto out;
16679 +
16680 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16681 +       {
16682 +               int openfd;
16683 +
16684 +               task_lock(p);
16685 +               openfd = vx_openfd_task(p);
16686 +
16687 +               if (old_vxi) {
16688 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16689 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16690 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16691 +                       /* FIXME: what about the struct files here? */
16692 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16693 +                       /* account for the executable */
16694 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16695 +               }
16696 +               atomic_inc(&vxi->cvirt.nr_threads);
16697 +               atomic_inc(&vxi->cvirt.nr_running);
16698 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16699 +               /* FIXME: what about the struct files here? */
16700 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16701 +               /* account for the executable */
16702 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16703 +
16704 +               if (old_vxi) {
16705 +                       release_vx_info(old_vxi, p);
16706 +                       clr_vx_info(&p->vx_info);
16707 +               }
16708 +               claim_vx_info(vxi, p);
16709 +               set_vx_info(&p->vx_info, vxi);
16710 +               p->xid = vxi->vx_id;
16711 +
16712 +               vxdprintk(VXD_CBIT(xid, 5),
16713 +                       "moved task %p into vxi:%p[#%d]",
16714 +                       p, vxi, vxi->vx_id);
16715 +
16716 +               // vx_mask_cap_bset(vxi, p);
16717 +               task_unlock(p);
16718 +
16719 +               /* hack for *spaces to provide compatibility */
16720 +               if (unshare) {
16721 +                       struct nsproxy *old_nsp, *new_nsp;
16722 +
16723 +                       ret = unshare_nsproxy_namespaces(
16724 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16725 +                               &new_nsp, NULL);
16726 +                       if (ret)
16727 +                               goto out;
16728 +
16729 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16730 +                       vx_set_space(vxi,
16731 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16732 +                       put_nsproxy(old_nsp);
16733 +               }
16734 +       }
16735 +out:
16736 +       put_vx_info(old_vxi);
16737 +       return ret;
16738 +}
16739 +
16740 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16741 +{
16742 +       struct task_struct *old_reaper;
16743 +
16744 +       if (!vxi)
16745 +               return -EINVAL;
16746 +
16747 +       vxdprintk(VXD_CBIT(xid, 6),
16748 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16749 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16750 +
16751 +       old_reaper = vxi->vx_reaper;
16752 +       if (old_reaper == p)
16753 +               return 0;
16754 +
16755 +       /* set new child reaper */
16756 +       get_task_struct(p);
16757 +       vxi->vx_reaper = p;
16758 +       put_task_struct(old_reaper);
16759 +       return 0;
16760 +}
16761 +
16762 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16763 +{
16764 +       if (!vxi)
16765 +               return -EINVAL;
16766 +
16767 +       vxdprintk(VXD_CBIT(xid, 6),
16768 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16769 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16770 +
16771 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16772 +       // vxi->vx_initpid = p->tgid;
16773 +       vxi->vx_initpid = p->pid;
16774 +       return 0;
16775 +}
16776 +
16777 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16778 +{
16779 +       vxdprintk(VXD_CBIT(xid, 6),
16780 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16781 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16782 +
16783 +       vxi->exit_code = code;
16784 +       vxi->vx_initpid = 0;
16785 +}
16786 +
16787 +
16788 +void vx_set_persistent(struct vx_info *vxi)
16789 +{
16790 +       vxdprintk(VXD_CBIT(xid, 6),
16791 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16792 +
16793 +       get_vx_info(vxi);
16794 +       claim_vx_info(vxi, NULL);
16795 +}
16796 +
16797 +void vx_clear_persistent(struct vx_info *vxi)
16798 +{
16799 +       vxdprintk(VXD_CBIT(xid, 6),
16800 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16801 +
16802 +       release_vx_info(vxi, NULL);
16803 +       put_vx_info(vxi);
16804 +}
16805 +
16806 +void vx_update_persistent(struct vx_info *vxi)
16807 +{
16808 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16809 +               vx_set_persistent(vxi);
16810 +       else
16811 +               vx_clear_persistent(vxi);
16812 +}
16813 +
16814 +
16815 +/*     task must be current or locked          */
16816 +
16817 +void   exit_vx_info(struct task_struct *p, int code)
16818 +{
16819 +       struct vx_info *vxi = p->vx_info;
16820 +
16821 +       if (vxi) {
16822 +               atomic_dec(&vxi->cvirt.nr_threads);
16823 +               vx_nproc_dec(p);
16824 +
16825 +               vxi->exit_code = code;
16826 +               release_vx_info(vxi, p);
16827 +       }
16828 +}
16829 +
16830 +void   exit_vx_info_early(struct task_struct *p, int code)
16831 +{
16832 +       struct vx_info *vxi = p->vx_info;
16833 +
16834 +       if (vxi) {
16835 +               if (vxi->vx_initpid == p->pid)
16836 +                       vx_exit_init(vxi, p, code);
16837 +               if (vxi->vx_reaper == p)
16838 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16839 +       }
16840 +}
16841 +
16842 +
16843 +/* vserver syscall commands below here */
16844 +
16845 +/* taks xid and vx_info functions */
16846 +
16847 +#include <asm/uaccess.h>
16848 +
16849 +
16850 +int vc_task_xid(uint32_t id)
16851 +{
16852 +       xid_t xid;
16853 +
16854 +       if (id) {
16855 +               struct task_struct *tsk;
16856 +
16857 +               read_lock(&tasklist_lock);
16858 +               tsk = find_task_by_real_pid(id);
16859 +               xid = (tsk) ? tsk->xid : -ESRCH;
16860 +               read_unlock(&tasklist_lock);
16861 +       } else
16862 +               xid = vx_current_xid();
16863 +       return xid;
16864 +}
16865 +
16866 +
16867 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16868 +{
16869 +       struct vcmd_vx_info_v0 vc_data;
16870 +
16871 +       vc_data.xid = vxi->vx_id;
16872 +       vc_data.initpid = vxi->vx_initpid;
16873 +
16874 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16875 +               return -EFAULT;
16876 +       return 0;
16877 +}
16878 +
16879 +
16880 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16881 +{
16882 +       struct vcmd_ctx_stat_v0 vc_data;
16883 +
16884 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16885 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16886 +
16887 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16888 +               return -EFAULT;
16889 +       return 0;
16890 +}
16891 +
16892 +
16893 +/* context functions */
16894 +
16895 +int vc_ctx_create(uint32_t xid, void __user *data)
16896 +{
16897 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16898 +       struct vx_info *new_vxi;
16899 +       int ret;
16900 +
16901 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16902 +               return -EFAULT;
16903 +
16904 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16905 +               return -EINVAL;
16906 +
16907 +       new_vxi = __create_vx_info(xid);
16908 +       if (IS_ERR(new_vxi))
16909 +               return PTR_ERR(new_vxi);
16910 +
16911 +       /* initial flags */
16912 +       new_vxi->vx_flags = vc_data.flagword;
16913 +
16914 +       ret = -ENOEXEC;
16915 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16916 +               goto out;
16917 +
16918 +       ret = vx_migrate_task(current, new_vxi, (!data));
16919 +       if (ret)
16920 +               goto out;
16921 +
16922 +       /* return context id on success */
16923 +       ret = new_vxi->vx_id;
16924 +
16925 +       /* get a reference for persistent contexts */
16926 +       if ((vc_data.flagword & VXF_PERSISTENT))
16927 +               vx_set_persistent(new_vxi);
16928 +out:
16929 +       release_vx_info(new_vxi, NULL);
16930 +       put_vx_info(new_vxi);
16931 +       return ret;
16932 +}
16933 +
16934 +
16935 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16936 +{
16937 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16938 +       int ret;
16939 +
16940 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16941 +               return -EFAULT;
16942 +
16943 +       ret = vx_migrate_task(current, vxi, 0);
16944 +       if (ret)
16945 +               return ret;
16946 +       if (vc_data.flagword & VXM_SET_INIT)
16947 +               ret = vx_set_init(vxi, current);
16948 +       if (ret)
16949 +               return ret;
16950 +       if (vc_data.flagword & VXM_SET_REAPER)
16951 +               ret = vx_set_reaper(vxi, current);
16952 +       return ret;
16953 +}
16954 +
16955 +
16956 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16957 +{
16958 +       struct vcmd_ctx_flags_v0 vc_data;
16959 +
16960 +       vc_data.flagword = vxi->vx_flags;
16961 +
16962 +       /* special STATE flag handling */
16963 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16964 +
16965 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16966 +               return -EFAULT;
16967 +       return 0;
16968 +}
16969 +
16970 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16971 +{
16972 +       struct vcmd_ctx_flags_v0 vc_data;
16973 +       uint64_t mask, trigger;
16974 +
16975 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16976 +               return -EFAULT;
16977 +
16978 +       /* special STATE flag handling */
16979 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16980 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16981 +
16982 +       if (vxi == current_vx_info()) {
16983 +               /* if (trigger & VXF_STATE_SETUP)
16984 +                       vx_mask_cap_bset(vxi, current); */
16985 +               if (trigger & VXF_STATE_INIT) {
16986 +                       int ret;
16987 +
16988 +                       ret = vx_set_init(vxi, current);
16989 +                       if (ret)
16990 +                               return ret;
16991 +                       ret = vx_set_reaper(vxi, current);
16992 +                       if (ret)
16993 +                               return ret;
16994 +               }
16995 +       }
16996 +
16997 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16998 +               vc_data.flagword, mask);
16999 +       if (trigger & VXF_PERSISTENT)
17000 +               vx_update_persistent(vxi);
17001 +
17002 +       return 0;
17003 +}
17004 +
17005 +
17006 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17007 +{
17008 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17009 +
17010 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17011 +       return v;
17012 +}
17013 +
17014 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17015 +{
17016 +       kernel_cap_t c = __cap_empty_set;
17017 +
17018 +       c.cap[0] = v & 0xFFFFFFFF;
17019 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17020 +
17021 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17022 +       return c;
17023 +}
17024 +
17025 +
17026 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17027 +{
17028 +       if (bcaps)
17029 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17030 +       if (ccaps)
17031 +               *ccaps = vxi->vx_ccaps;
17032 +
17033 +       return 0;
17034 +}
17035 +
17036 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17037 +{
17038 +       struct vcmd_ctx_caps_v1 vc_data;
17039 +       int ret;
17040 +
17041 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17042 +       if (ret)
17043 +               return ret;
17044 +       vc_data.cmask = ~0ULL;
17045 +
17046 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17047 +               return -EFAULT;
17048 +       return 0;
17049 +}
17050 +
17051 +static int do_set_caps(struct vx_info *vxi,
17052 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17053 +{
17054 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17055 +
17056 +#if 0
17057 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17058 +               bcaps, bmask, ccaps, cmask);
17059 +#endif
17060 +       vxi->vx_bcaps = cap_t_from_caps(
17061 +               vs_mask_flags(bcold, bcaps, bmask));
17062 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17063 +
17064 +       return 0;
17065 +}
17066 +
17067 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17068 +{
17069 +       struct vcmd_ctx_caps_v1 vc_data;
17070 +
17071 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17072 +               return -EFAULT;
17073 +
17074 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17075 +}
17076 +
17077 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17078 +{
17079 +       struct vcmd_bcaps vc_data;
17080 +       int ret;
17081 +
17082 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17083 +       if (ret)
17084 +               return ret;
17085 +       vc_data.bmask = ~0ULL;
17086 +
17087 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17088 +               return -EFAULT;
17089 +       return 0;
17090 +}
17091 +
17092 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17093 +{
17094 +       struct vcmd_bcaps vc_data;
17095 +
17096 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17097 +               return -EFAULT;
17098 +
17099 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17100 +}
17101 +
17102 +
17103 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17104 +{
17105 +       struct vcmd_umask vc_data;
17106 +
17107 +       vc_data.umask = vxi->vx_umask;
17108 +       vc_data.mask = ~0ULL;
17109 +
17110 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17111 +               return -EFAULT;
17112 +       return 0;
17113 +}
17114 +
17115 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17116 +{
17117 +       struct vcmd_umask vc_data;
17118 +
17119 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17120 +               return -EFAULT;
17121 +
17122 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17123 +               vc_data.umask, vc_data.mask);
17124 +       return 0;
17125 +}
17126 +
17127 +
17128 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17129 +{
17130 +       struct vcmd_badness_v0 vc_data;
17131 +
17132 +       vc_data.bias = vxi->vx_badness_bias;
17133 +
17134 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17135 +               return -EFAULT;
17136 +       return 0;
17137 +}
17138 +
17139 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17140 +{
17141 +       struct vcmd_badness_v0 vc_data;
17142 +
17143 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17144 +               return -EFAULT;
17145 +
17146 +       vxi->vx_badness_bias = vc_data.bias;
17147 +       return 0;
17148 +}
17149 +
17150 +#include <linux/module.h>
17151 +
17152 +EXPORT_SYMBOL_GPL(free_vx_info);
17153 +
17154 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cvirt.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cvirt.c
17155 --- linux-2.6.37/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
17156 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cvirt.c  2011-01-08 03:33:34.000000000 +0100
17157 @@ -0,0 +1,303 @@
17158 +/*
17159 + *  linux/kernel/vserver/cvirt.c
17160 + *
17161 + *  Virtual Server: Context Virtualization
17162 + *
17163 + *  Copyright (C) 2004-2007  Herbert Pötzl
17164 + *
17165 + *  V0.01  broken out from limit.c
17166 + *  V0.02  added utsname stuff
17167 + *  V0.03  changed vcmds to vxi arg
17168 + *
17169 + */
17170 +
17171 +#include <linux/types.h>
17172 +#include <linux/utsname.h>
17173 +#include <linux/vs_cvirt.h>
17174 +#include <linux/vserver/switch.h>
17175 +#include <linux/vserver/cvirt_cmd.h>
17176 +
17177 +#include <asm/uaccess.h>
17178 +
17179 +
17180 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17181 +{
17182 +       struct vx_info *vxi = current_vx_info();
17183 +
17184 +       set_normalized_timespec(uptime,
17185 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17186 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17187 +       if (!idle)
17188 +               return;
17189 +       set_normalized_timespec(idle,
17190 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17191 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17192 +       return;
17193 +}
17194 +
17195 +uint64_t vx_idle_jiffies(void)
17196 +{
17197 +       return init_task.utime + init_task.stime;
17198 +}
17199 +
17200 +
17201 +
17202 +static inline uint32_t __update_loadavg(uint32_t load,
17203 +       int wsize, int delta, int n)
17204 +{
17205 +       unsigned long long calc, prev;
17206 +
17207 +       /* just set it to n */
17208 +       if (unlikely(delta >= wsize))
17209 +               return (n << FSHIFT);
17210 +
17211 +       calc = delta * n;
17212 +       calc <<= FSHIFT;
17213 +       prev = (wsize - delta);
17214 +       prev *= load;
17215 +       calc += prev;
17216 +       do_div(calc, wsize);
17217 +       return calc;
17218 +}
17219 +
17220 +
17221 +void vx_update_load(struct vx_info *vxi)
17222 +{
17223 +       uint32_t now, last, delta;
17224 +       unsigned int nr_running, nr_uninterruptible;
17225 +       unsigned int total;
17226 +       unsigned long flags;
17227 +
17228 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17229 +
17230 +       now = jiffies;
17231 +       last = vxi->cvirt.load_last;
17232 +       delta = now - last;
17233 +
17234 +       if (delta < 5*HZ)
17235 +               goto out;
17236 +
17237 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17238 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17239 +       total = nr_running + nr_uninterruptible;
17240 +
17241 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17242 +               60*HZ, delta, total);
17243 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17244 +               5*60*HZ, delta, total);
17245 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17246 +               15*60*HZ, delta, total);
17247 +
17248 +       vxi->cvirt.load_last = now;
17249 +out:
17250 +       atomic_inc(&vxi->cvirt.load_updates);
17251 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17252 +}
17253 +
17254 +
17255 +/*
17256 + * Commands to do_syslog:
17257 + *
17258 + *      0 -- Close the log.  Currently a NOP.
17259 + *      1 -- Open the log. Currently a NOP.
17260 + *      2 -- Read from the log.
17261 + *      3 -- Read all messages remaining in the ring buffer.
17262 + *      4 -- Read and clear all messages remaining in the ring buffer
17263 + *      5 -- Clear ring buffer.
17264 + *      6 -- Disable printk's to console
17265 + *      7 -- Enable printk's to console
17266 + *      8 -- Set level of messages printed to console
17267 + *      9 -- Return number of unread characters in the log buffer
17268 + *     10 -- Return size of the log buffer
17269 + */
17270 +int vx_do_syslog(int type, char __user *buf, int len)
17271 +{
17272 +       int error = 0;
17273 +       int do_clear = 0;
17274 +       struct vx_info *vxi = current_vx_info();
17275 +       struct _vx_syslog *log;
17276 +
17277 +       if (!vxi)
17278 +               return -EINVAL;
17279 +       log = &vxi->cvirt.syslog;
17280 +
17281 +       switch (type) {
17282 +       case 0:         /* Close log */
17283 +       case 1:         /* Open log */
17284 +               break;
17285 +       case 2:         /* Read from log */
17286 +               error = wait_event_interruptible(log->log_wait,
17287 +                       (log->log_start - log->log_end));
17288 +               if (error)
17289 +                       break;
17290 +               spin_lock_irq(&log->logbuf_lock);
17291 +               spin_unlock_irq(&log->logbuf_lock);
17292 +               break;
17293 +       case 4:         /* Read/clear last kernel messages */
17294 +               do_clear = 1;
17295 +               /* fall through */
17296 +       case 3:         /* Read last kernel messages */
17297 +               return 0;
17298 +
17299 +       case 5:         /* Clear ring buffer */
17300 +               return 0;
17301 +
17302 +       case 6:         /* Disable logging to console */
17303 +       case 7:         /* Enable logging to console */
17304 +       case 8:         /* Set level of messages printed to console */
17305 +               break;
17306 +
17307 +       case 9:         /* Number of chars in the log buffer */
17308 +               return 0;
17309 +       case 10:        /* Size of the log buffer */
17310 +               return 0;
17311 +       default:
17312 +               error = -EINVAL;
17313 +               break;
17314 +       }
17315 +       return error;
17316 +}
17317 +
17318 +
17319 +/* virtual host info names */
17320 +
17321 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17322 +{
17323 +       struct nsproxy *nsproxy;
17324 +       struct uts_namespace *uts;
17325 +
17326 +       if (id == VHIN_CONTEXT)
17327 +               return vxi->vx_name;
17328 +
17329 +       nsproxy = vxi->space[0].vx_nsproxy;
17330 +       if (!nsproxy)
17331 +               return NULL;
17332 +
17333 +       uts = nsproxy->uts_ns;
17334 +       if (!uts)
17335 +               return NULL;
17336 +
17337 +       switch (id) {
17338 +       case VHIN_SYSNAME:
17339 +               return uts->name.sysname;
17340 +       case VHIN_NODENAME:
17341 +               return uts->name.nodename;
17342 +       case VHIN_RELEASE:
17343 +               return uts->name.release;
17344 +       case VHIN_VERSION:
17345 +               return uts->name.version;
17346 +       case VHIN_MACHINE:
17347 +               return uts->name.machine;
17348 +       case VHIN_DOMAINNAME:
17349 +               return uts->name.domainname;
17350 +       default:
17351 +               return NULL;
17352 +       }
17353 +       return NULL;
17354 +}
17355 +
17356 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17357 +{
17358 +       struct vcmd_vhi_name_v0 vc_data;
17359 +       char *name;
17360 +
17361 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17362 +               return -EFAULT;
17363 +
17364 +       name = vx_vhi_name(vxi, vc_data.field);
17365 +       if (!name)
17366 +               return -EINVAL;
17367 +
17368 +       memcpy(name, vc_data.name, 65);
17369 +       return 0;
17370 +}
17371 +
17372 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17373 +{
17374 +       struct vcmd_vhi_name_v0 vc_data;
17375 +       char *name;
17376 +
17377 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17378 +               return -EFAULT;
17379 +
17380 +       name = vx_vhi_name(vxi, vc_data.field);
17381 +       if (!name)
17382 +               return -EINVAL;
17383 +
17384 +       memcpy(vc_data.name, name, 65);
17385 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17386 +               return -EFAULT;
17387 +       return 0;
17388 +}
17389 +
17390 +
17391 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17392 +{
17393 +       struct vcmd_virt_stat_v0 vc_data;
17394 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17395 +       struct timespec uptime;
17396 +
17397 +       do_posix_clock_monotonic_gettime(&uptime);
17398 +       set_normalized_timespec(&uptime,
17399 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17400 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17401 +
17402 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17403 +       vc_data.uptime = timespec_to_ns(&uptime);
17404 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17405 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17406 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17407 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17408 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17409 +       vc_data.load[0] = cvirt->load[0];
17410 +       vc_data.load[1] = cvirt->load[1];
17411 +       vc_data.load[2] = cvirt->load[2];
17412 +
17413 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17414 +               return -EFAULT;
17415 +       return 0;
17416 +}
17417 +
17418 +
17419 +#ifdef CONFIG_VSERVER_VTIME
17420 +
17421 +/* virtualized time base */
17422 +
17423 +void vx_adjust_timespec(struct timespec *ts)
17424 +{
17425 +       struct vx_info *vxi;
17426 +
17427 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17428 +               return;
17429 +
17430 +       vxi = current_vx_info();
17431 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17432 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17433 +
17434 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17435 +               ts->tv_sec++;
17436 +               ts->tv_nsec -= NSEC_PER_SEC;
17437 +       } else if (ts->tv_nsec < 0) {
17438 +               ts->tv_sec--;
17439 +               ts->tv_nsec += NSEC_PER_SEC;
17440 +       }
17441 +}
17442 +
17443 +int vx_settimeofday(struct timespec *ts)
17444 +{
17445 +       struct timespec ats, delta;
17446 +       struct vx_info *vxi;
17447 +
17448 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17449 +               return do_settimeofday(ts);
17450 +
17451 +       getnstimeofday(&ats);
17452 +       delta = timespec_sub(*ts, ats);
17453 +
17454 +       vxi = current_vx_info();
17455 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17456 +       return 0;
17457 +}
17458 +
17459 +#endif
17460 +
17461 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cvirt_init.h linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cvirt_init.h
17462 --- linux-2.6.37/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
17463 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cvirt_init.h     2010-11-23 02:09:41.000000000 +0100
17464 @@ -0,0 +1,69 @@
17465 +
17466 +
17467 +extern uint64_t vx_idle_jiffies(void);
17468 +
17469 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17470 +{
17471 +       uint64_t idle_jiffies = vx_idle_jiffies();
17472 +       uint64_t nsuptime;
17473 +
17474 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17475 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17476 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17477 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17478 +       cvirt->bias_ts.tv_sec = 0;
17479 +       cvirt->bias_ts.tv_nsec = 0;
17480 +
17481 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17482 +       atomic_set(&cvirt->nr_threads, 0);
17483 +       atomic_set(&cvirt->nr_running, 0);
17484 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17485 +       atomic_set(&cvirt->nr_onhold, 0);
17486 +
17487 +       spin_lock_init(&cvirt->load_lock);
17488 +       cvirt->load_last = jiffies;
17489 +       atomic_set(&cvirt->load_updates, 0);
17490 +       cvirt->load[0] = 0;
17491 +       cvirt->load[1] = 0;
17492 +       cvirt->load[2] = 0;
17493 +       atomic_set(&cvirt->total_forks, 0);
17494 +
17495 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17496 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17497 +       cvirt->syslog.log_start = 0;
17498 +       cvirt->syslog.log_end = 0;
17499 +       cvirt->syslog.con_start = 0;
17500 +       cvirt->syslog.logged_chars = 0;
17501 +}
17502 +
17503 +static inline
17504 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17505 +{
17506 +       // cvirt_pc->cpustat = { 0 };
17507 +}
17508 +
17509 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17510 +{
17511 +       int value;
17512 +
17513 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17514 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17515 +               cvirt, value);
17516 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17517 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17518 +               cvirt, value);
17519 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17520 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17521 +               cvirt, value);
17522 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17523 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17524 +               cvirt, value);
17525 +       return;
17526 +}
17527 +
17528 +static inline
17529 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17530 +{
17531 +       return;
17532 +}
17533 +
17534 diff -NurpP --minimal linux-2.6.37/kernel/vserver/cvirt_proc.h linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cvirt_proc.h
17535 --- linux-2.6.37/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
17536 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/cvirt_proc.h     2010-11-23 02:09:41.000000000 +0100
17537 @@ -0,0 +1,135 @@
17538 +#ifndef _VX_CVIRT_PROC_H
17539 +#define _VX_CVIRT_PROC_H
17540 +
17541 +#include <linux/nsproxy.h>
17542 +#include <linux/mnt_namespace.h>
17543 +#include <linux/ipc_namespace.h>
17544 +#include <linux/utsname.h>
17545 +#include <linux/ipc.h>
17546 +
17547 +
17548 +static inline
17549 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17550 +{
17551 +       struct mnt_namespace *ns;
17552 +       struct uts_namespace *uts;
17553 +       struct ipc_namespace *ipc;
17554 +       struct path path;
17555 +       char *pstr, *root;
17556 +       int length = 0;
17557 +
17558 +       if (!nsproxy)
17559 +               goto out;
17560 +
17561 +       length += sprintf(buffer + length,
17562 +               "NSProxy:\t%p [%p,%p,%p]\n",
17563 +               nsproxy, nsproxy->mnt_ns,
17564 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17565 +
17566 +       ns = nsproxy->mnt_ns;
17567 +       if (!ns)
17568 +               goto skip_ns;
17569 +
17570 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17571 +       if (!pstr)
17572 +               goto skip_ns;
17573 +
17574 +       path.mnt = ns->root;
17575 +       path.dentry = ns->root->mnt_root;
17576 +       root = d_path(&path, pstr, PATH_MAX - 2);
17577 +       length += sprintf(buffer + length,
17578 +               "Namespace:\t%p [#%u]\n"
17579 +               "RootPath:\t%s\n",
17580 +               ns, atomic_read(&ns->count),
17581 +               root);
17582 +       kfree(pstr);
17583 +skip_ns:
17584 +
17585 +       uts = nsproxy->uts_ns;
17586 +       if (!uts)
17587 +               goto skip_uts;
17588 +
17589 +       length += sprintf(buffer + length,
17590 +               "SysName:\t%.*s\n"
17591 +               "NodeName:\t%.*s\n"
17592 +               "Release:\t%.*s\n"
17593 +               "Version:\t%.*s\n"
17594 +               "Machine:\t%.*s\n"
17595 +               "DomainName:\t%.*s\n",
17596 +               __NEW_UTS_LEN, uts->name.sysname,
17597 +               __NEW_UTS_LEN, uts->name.nodename,
17598 +               __NEW_UTS_LEN, uts->name.release,
17599 +               __NEW_UTS_LEN, uts->name.version,
17600 +               __NEW_UTS_LEN, uts->name.machine,
17601 +               __NEW_UTS_LEN, uts->name.domainname);
17602 +skip_uts:
17603 +
17604 +       ipc = nsproxy->ipc_ns;
17605 +       if (!ipc)
17606 +               goto skip_ipc;
17607 +
17608 +       length += sprintf(buffer + length,
17609 +               "SEMS:\t\t%d %d %d %d  %d\n"
17610 +               "MSG:\t\t%d %d %d\n"
17611 +               "SHM:\t\t%lu %lu  %d %d\n",
17612 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17613 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17614 +               ipc->used_sems,
17615 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17616 +               (unsigned long)ipc->shm_ctlmax,
17617 +               (unsigned long)ipc->shm_ctlall,
17618 +               ipc->shm_ctlmni, ipc->shm_tot);
17619 +skip_ipc:
17620 +out:
17621 +       return length;
17622 +}
17623 +
17624 +
17625 +#include <linux/sched.h>
17626 +
17627 +#define LOAD_INT(x) ((x) >> FSHIFT)
17628 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17629 +
17630 +static inline
17631 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17632 +{
17633 +       int length = 0;
17634 +       int a, b, c;
17635 +
17636 +       length += sprintf(buffer + length,
17637 +               "BiasUptime:\t%lu.%02lu\n",
17638 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17639 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17640 +
17641 +       a = cvirt->load[0] + (FIXED_1 / 200);
17642 +       b = cvirt->load[1] + (FIXED_1 / 200);
17643 +       c = cvirt->load[2] + (FIXED_1 / 200);
17644 +       length += sprintf(buffer + length,
17645 +               "nr_threads:\t%d\n"
17646 +               "nr_running:\t%d\n"
17647 +               "nr_unintr:\t%d\n"
17648 +               "nr_onhold:\t%d\n"
17649 +               "load_updates:\t%d\n"
17650 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17651 +               "total_forks:\t%d\n",
17652 +               atomic_read(&cvirt->nr_threads),
17653 +               atomic_read(&cvirt->nr_running),
17654 +               atomic_read(&cvirt->nr_uninterruptible),
17655 +               atomic_read(&cvirt->nr_onhold),
17656 +               atomic_read(&cvirt->load_updates),
17657 +               LOAD_INT(a), LOAD_FRAC(a),
17658 +               LOAD_INT(b), LOAD_FRAC(b),
17659 +               LOAD_INT(c), LOAD_FRAC(c),
17660 +               atomic_read(&cvirt->total_forks));
17661 +       return length;
17662 +}
17663 +
17664 +static inline
17665 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17666 +       char *buffer, int cpu)
17667 +{
17668 +       int length = 0;
17669 +       return length;
17670 +}
17671 +
17672 +#endif /* _VX_CVIRT_PROC_H */
17673 diff -NurpP --minimal linux-2.6.37/kernel/vserver/debug.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/debug.c
17674 --- linux-2.6.37/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
17675 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/debug.c  2010-11-23 02:09:41.000000000 +0100
17676 @@ -0,0 +1,32 @@
17677 +/*
17678 + *  kernel/vserver/debug.c
17679 + *
17680 + *  Copyright (C) 2005-2007 Herbert Pötzl
17681 + *
17682 + *  V0.01  vx_info dump support
17683 + *
17684 + */
17685 +
17686 +#include <linux/module.h>
17687 +
17688 +#include <linux/vserver/context.h>
17689 +
17690 +
17691 +void   dump_vx_info(struct vx_info *vxi, int level)
17692 +{
17693 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17694 +               atomic_read(&vxi->vx_usecnt),
17695 +               atomic_read(&vxi->vx_tasks),
17696 +               vxi->vx_state);
17697 +       if (level > 0) {
17698 +               __dump_vx_limit(&vxi->limit);
17699 +               __dump_vx_sched(&vxi->sched);
17700 +               __dump_vx_cvirt(&vxi->cvirt);
17701 +               __dump_vx_cacct(&vxi->cacct);
17702 +       }
17703 +       printk("---\n");
17704 +}
17705 +
17706 +
17707 +EXPORT_SYMBOL_GPL(dump_vx_info);
17708 +
17709 diff -NurpP --minimal linux-2.6.37/kernel/vserver/device.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/device.c
17710 --- linux-2.6.37/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
17711 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/device.c 2010-11-23 02:09:41.000000000 +0100
17712 @@ -0,0 +1,443 @@
17713 +/*
17714 + *  linux/kernel/vserver/device.c
17715 + *
17716 + *  Linux-VServer: Device Support
17717 + *
17718 + *  Copyright (C) 2006  Herbert Pötzl
17719 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17720 + *
17721 + *  V0.01  device mapping basics
17722 + *  V0.02  added defaults
17723 + *
17724 + */
17725 +
17726 +#include <linux/slab.h>
17727 +#include <linux/rcupdate.h>
17728 +#include <linux/fs.h>
17729 +#include <linux/namei.h>
17730 +#include <linux/hash.h>
17731 +
17732 +#include <asm/errno.h>
17733 +#include <asm/uaccess.h>
17734 +#include <linux/vserver/base.h>
17735 +#include <linux/vserver/debug.h>
17736 +#include <linux/vserver/context.h>
17737 +#include <linux/vserver/device.h>
17738 +#include <linux/vserver/device_cmd.h>
17739 +
17740 +
17741 +#define DMAP_HASH_BITS 4
17742 +
17743 +
17744 +struct vs_mapping {
17745 +       union {
17746 +               struct hlist_node hlist;
17747 +               struct list_head list;
17748 +       } u;
17749 +#define dm_hlist       u.hlist
17750 +#define dm_list                u.list
17751 +       xid_t xid;
17752 +       dev_t device;
17753 +       struct vx_dmap_target target;
17754 +};
17755 +
17756 +
17757 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17758 +
17759 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
17760 +
17761 +static struct vx_dmap_target dmap_defaults[2] = {
17762 +       { .flags = DATTR_OPEN },
17763 +       { .flags = DATTR_OPEN },
17764 +};
17765 +
17766 +
17767 +struct kmem_cache *dmap_cachep __read_mostly;
17768 +
17769 +int __init dmap_cache_init(void)
17770 +{
17771 +       dmap_cachep = kmem_cache_create("dmap_cache",
17772 +               sizeof(struct vs_mapping), 0,
17773 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17774 +       return 0;
17775 +}
17776 +
17777 +__initcall(dmap_cache_init);
17778 +
17779 +
17780 +static inline unsigned int __hashval(dev_t dev, int bits)
17781 +{
17782 +       return hash_long((unsigned long)dev, bits);
17783 +}
17784 +
17785 +
17786 +/*     __hash_mapping()
17787 + *     add the mapping to the hash table
17788 + */
17789 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17790 +{
17791 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17792 +       struct hlist_head *head, *hash = dmap_main_hash;
17793 +       int device = vdm->device;
17794 +
17795 +       spin_lock(hash_lock);
17796 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17797 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17798 +
17799 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17800 +       hlist_add_head(&vdm->dm_hlist, head);
17801 +       spin_unlock(hash_lock);
17802 +}
17803 +
17804 +
17805 +static inline int __mode_to_default(umode_t mode)
17806 +{
17807 +       switch (mode) {
17808 +       case S_IFBLK:
17809 +               return 0;
17810 +       case S_IFCHR:
17811 +               return 1;
17812 +       default:
17813 +               BUG();
17814 +       }
17815 +}
17816 +
17817 +
17818 +/*     __set_default()
17819 + *     set a default
17820 + */
17821 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17822 +       struct vx_dmap_target *vdmt)
17823 +{
17824 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17825 +       spin_lock(hash_lock);
17826 +
17827 +       if (vxi)
17828 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17829 +       else
17830 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17831 +
17832 +
17833 +       spin_unlock(hash_lock);
17834 +
17835 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17836 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17837 +}
17838 +
17839 +
17840 +/*     __remove_default()
17841 + *     remove a default
17842 + */
17843 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17844 +{
17845 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17846 +       spin_lock(hash_lock);
17847 +
17848 +       if (vxi)
17849 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17850 +       else    /* remove == reset */
17851 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17852 +
17853 +       spin_unlock(hash_lock);
17854 +       return 0;
17855 +}
17856 +
17857 +
17858 +/*     __find_mapping()
17859 + *     find a mapping in the hash table
17860 + *
17861 + *     caller must hold hash_lock
17862 + */
17863 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17864 +       struct vs_mapping **local, struct vs_mapping **global)
17865 +{
17866 +       struct hlist_head *hash = dmap_main_hash;
17867 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17868 +       struct hlist_node *pos;
17869 +       struct vs_mapping *vdm;
17870 +
17871 +       *local = NULL;
17872 +       if (global)
17873 +               *global = NULL;
17874 +
17875 +       hlist_for_each(pos, head) {
17876 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17877 +
17878 +               if ((vdm->device == device) &&
17879 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17880 +                       if (vdm->xid == xid) {
17881 +                               *local = vdm;
17882 +                               return 1;
17883 +                       } else if (global && vdm->xid == 0)
17884 +                               *global = vdm;
17885 +               }
17886 +       }
17887 +
17888 +       if (global && *global)
17889 +               return 0;
17890 +       else
17891 +               return -ENOENT;
17892 +}
17893 +
17894 +
17895 +/*     __lookup_mapping()
17896 + *     find a mapping and store the result in target and flags
17897 + */
17898 +static inline int __lookup_mapping(struct vx_info *vxi,
17899 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17900 +{
17901 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17902 +       struct vs_mapping *vdm, *global;
17903 +       struct vx_dmap_target *vdmt;
17904 +       int ret = 0;
17905 +       xid_t xid = vxi->vx_id;
17906 +       int index;
17907 +
17908 +       spin_lock(hash_lock);
17909 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17910 +               ret = 1;
17911 +               vdmt = &vdm->target;
17912 +               goto found;
17913 +       }
17914 +
17915 +       index = __mode_to_default(mode);
17916 +       if (vxi && vxi->dmap.targets[index].flags) {
17917 +               ret = 2;
17918 +               vdmt = &vxi->dmap.targets[index];
17919 +       } else if (global) {
17920 +               ret = 3;
17921 +               vdmt = &global->target;
17922 +               goto found;
17923 +       } else {
17924 +               ret = 4;
17925 +               vdmt = &dmap_defaults[index];
17926 +       }
17927 +
17928 +found:
17929 +       if (target && (vdmt->flags & DATTR_REMAP))
17930 +               *target = vdmt->target;
17931 +       else if (target)
17932 +               *target = device;
17933 +       if (flags)
17934 +               *flags = vdmt->flags;
17935 +
17936 +       spin_unlock(hash_lock);
17937 +
17938 +       return ret;
17939 +}
17940 +
17941 +
17942 +/*     __remove_mapping()
17943 + *     remove a mapping from the hash table
17944 + */
17945 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17946 +       umode_t mode)
17947 +{
17948 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17949 +       struct vs_mapping *vdm = NULL;
17950 +       int ret = 0;
17951 +
17952 +       spin_lock(hash_lock);
17953 +
17954 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17955 +               NULL);
17956 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17957 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17958 +       if (ret < 0)
17959 +               goto out;
17960 +       hlist_del(&vdm->dm_hlist);
17961 +
17962 +out:
17963 +       spin_unlock(hash_lock);
17964 +       if (vdm)
17965 +               kmem_cache_free(dmap_cachep, vdm);
17966 +       return ret;
17967 +}
17968 +
17969 +
17970 +
17971 +int vs_map_device(struct vx_info *vxi,
17972 +       dev_t device, dev_t *target, umode_t mode)
17973 +{
17974 +       int ret, flags = DATTR_MASK;
17975 +
17976 +       if (!vxi) {
17977 +               if (target)
17978 +                       *target = device;
17979 +               goto out;
17980 +       }
17981 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17982 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17983 +               device, target ? *target : 0, flags, mode, ret);
17984 +out:
17985 +       return (flags & DATTR_MASK);
17986 +}
17987 +
17988 +
17989 +
17990 +static int do_set_mapping(struct vx_info *vxi,
17991 +       dev_t device, dev_t target, int flags, umode_t mode)
17992 +{
17993 +       if (device) {
17994 +               struct vs_mapping *new;
17995 +
17996 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17997 +               if (!new)
17998 +                       return -ENOMEM;
17999 +
18000 +               INIT_HLIST_NODE(&new->dm_hlist);
18001 +               new->device = device;
18002 +               new->target.target = target;
18003 +               new->target.flags = flags | mode;
18004 +               new->xid = (vxi ? vxi->vx_id : 0);
18005 +
18006 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18007 +               __hash_mapping(vxi, new);
18008 +       } else {
18009 +               struct vx_dmap_target new = {
18010 +                       .target = target,
18011 +                       .flags = flags | mode,
18012 +               };
18013 +               __set_default(vxi, mode, &new);
18014 +       }
18015 +       return 0;
18016 +}
18017 +
18018 +
18019 +static int do_unset_mapping(struct vx_info *vxi,
18020 +       dev_t device, dev_t target, int flags, umode_t mode)
18021 +{
18022 +       int ret = -EINVAL;
18023 +
18024 +       if (device) {
18025 +               ret = __remove_mapping(vxi, device, mode);
18026 +               if (ret < 0)
18027 +                       goto out;
18028 +       } else {
18029 +               ret = __remove_default(vxi, mode);
18030 +               if (ret < 0)
18031 +                       goto out;
18032 +       }
18033 +
18034 +out:
18035 +       return ret;
18036 +}
18037 +
18038 +
18039 +static inline int __user_device(const char __user *name, dev_t *dev,
18040 +       umode_t *mode)
18041 +{
18042 +       struct nameidata nd;
18043 +       int ret;
18044 +
18045 +       if (!name) {
18046 +               *dev = 0;
18047 +               return 0;
18048 +       }
18049 +       ret = user_lpath(name, &nd.path);
18050 +       if (ret)
18051 +               return ret;
18052 +       if (nd.path.dentry->d_inode) {
18053 +               *dev = nd.path.dentry->d_inode->i_rdev;
18054 +               *mode = nd.path.dentry->d_inode->i_mode;
18055 +       }
18056 +       path_put(&nd.path);
18057 +       return 0;
18058 +}
18059 +
18060 +static inline int __mapping_mode(dev_t device, dev_t target,
18061 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18062 +{
18063 +       if (device)
18064 +               *mode = device_mode & S_IFMT;
18065 +       else if (target)
18066 +               *mode = target_mode & S_IFMT;
18067 +       else
18068 +               return -EINVAL;
18069 +
18070 +       /* if both given, device and target mode have to match */
18071 +       if (device && target &&
18072 +               ((device_mode ^ target_mode) & S_IFMT))
18073 +               return -EINVAL;
18074 +       return 0;
18075 +}
18076 +
18077 +
18078 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18079 +       const char __user *target_path, int flags, int set)
18080 +{
18081 +       dev_t device = ~0, target = ~0;
18082 +       umode_t device_mode = 0, target_mode = 0, mode;
18083 +       int ret;
18084 +
18085 +       ret = __user_device(device_path, &device, &device_mode);
18086 +       if (ret)
18087 +               return ret;
18088 +       ret = __user_device(target_path, &target, &target_mode);
18089 +       if (ret)
18090 +               return ret;
18091 +
18092 +       ret = __mapping_mode(device, target,
18093 +               device_mode, target_mode, &mode);
18094 +       if (ret)
18095 +               return ret;
18096 +
18097 +       if (set)
18098 +               return do_set_mapping(vxi, device, target,
18099 +                       flags, mode);
18100 +       else
18101 +               return do_unset_mapping(vxi, device, target,
18102 +                       flags, mode);
18103 +}
18104 +
18105 +
18106 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18107 +{
18108 +       struct vcmd_set_mapping_v0 vc_data;
18109 +
18110 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18111 +               return -EFAULT;
18112 +
18113 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18114 +               vc_data.flags, 1);
18115 +}
18116 +
18117 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18118 +{
18119 +       struct vcmd_set_mapping_v0 vc_data;
18120 +
18121 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18122 +               return -EFAULT;
18123 +
18124 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18125 +               vc_data.flags, 0);
18126 +}
18127 +
18128 +
18129 +#ifdef CONFIG_COMPAT
18130 +
18131 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18132 +{
18133 +       struct vcmd_set_mapping_v0_x32 vc_data;
18134 +
18135 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18136 +               return -EFAULT;
18137 +
18138 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18139 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18140 +}
18141 +
18142 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18143 +{
18144 +       struct vcmd_set_mapping_v0_x32 vc_data;
18145 +
18146 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18147 +               return -EFAULT;
18148 +
18149 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18150 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18151 +}
18152 +
18153 +#endif /* CONFIG_COMPAT */
18154 +
18155 +
18156 diff -NurpP --minimal linux-2.6.37/kernel/vserver/dlimit.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/dlimit.c
18157 --- linux-2.6.37/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
18158 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/dlimit.c 2011-01-05 23:26:15.000000000 +0100
18159 @@ -0,0 +1,531 @@
18160 +/*
18161 + *  linux/kernel/vserver/dlimit.c
18162 + *
18163 + *  Virtual Server: Context Disk Limits
18164 + *
18165 + *  Copyright (C) 2004-2009  Herbert Pötzl
18166 + *
18167 + *  V0.01  initial version
18168 + *  V0.02  compat32 splitup
18169 + *  V0.03  extended interface
18170 + *
18171 + */
18172 +
18173 +#include <linux/statfs.h>
18174 +#include <linux/sched.h>
18175 +#include <linux/namei.h>
18176 +#include <linux/vs_tag.h>
18177 +#include <linux/vs_dlimit.h>
18178 +#include <linux/vserver/dlimit_cmd.h>
18179 +#include <linux/slab.h>
18180 +// #include <linux/gfp.h>
18181 +
18182 +#include <asm/uaccess.h>
18183 +
18184 +/*     __alloc_dl_info()
18185 +
18186 +       * allocate an initialized dl_info struct
18187 +       * doesn't make it visible (hash)                        */
18188 +
18189 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18190 +{
18191 +       struct dl_info *new = NULL;
18192 +
18193 +       vxdprintk(VXD_CBIT(dlim, 5),
18194 +               "alloc_dl_info(%p,%d)*", sb, tag);
18195 +
18196 +       /* would this benefit from a slab cache? */
18197 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18198 +       if (!new)
18199 +               return 0;
18200 +
18201 +       memset(new, 0, sizeof(struct dl_info));
18202 +       new->dl_tag = tag;
18203 +       new->dl_sb = sb;
18204 +       // INIT_RCU_HEAD(&new->dl_rcu);
18205 +       INIT_HLIST_NODE(&new->dl_hlist);
18206 +       spin_lock_init(&new->dl_lock);
18207 +       atomic_set(&new->dl_refcnt, 0);
18208 +       atomic_set(&new->dl_usecnt, 0);
18209 +
18210 +       /* rest of init goes here */
18211 +
18212 +       vxdprintk(VXD_CBIT(dlim, 4),
18213 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18214 +       return new;
18215 +}
18216 +
18217 +/*     __dealloc_dl_info()
18218 +
18219 +       * final disposal of dl_info                             */
18220 +
18221 +static void __dealloc_dl_info(struct dl_info *dli)
18222 +{
18223 +       vxdprintk(VXD_CBIT(dlim, 4),
18224 +               "dealloc_dl_info(%p)", dli);
18225 +
18226 +       dli->dl_hlist.next = LIST_POISON1;
18227 +       dli->dl_tag = -1;
18228 +       dli->dl_sb = 0;
18229 +
18230 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18231 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18232 +
18233 +       kfree(dli);
18234 +}
18235 +
18236 +
18237 +/*     hash table for dl_info hash */
18238 +
18239 +#define DL_HASH_SIZE   13
18240 +
18241 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18242 +
18243 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
18244 +
18245 +
18246 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18247 +{
18248 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18249 +}
18250 +
18251 +
18252 +
18253 +/*     __hash_dl_info()
18254 +
18255 +       * add the dli to the global hash table
18256 +       * requires the hash_lock to be held                     */
18257 +
18258 +static inline void __hash_dl_info(struct dl_info *dli)
18259 +{
18260 +       struct hlist_head *head;
18261 +
18262 +       vxdprintk(VXD_CBIT(dlim, 6),
18263 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18264 +       get_dl_info(dli);
18265 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18266 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18267 +}
18268 +
18269 +/*     __unhash_dl_info()
18270 +
18271 +       * remove the dli from the global hash table
18272 +       * requires the hash_lock to be held                     */
18273 +
18274 +static inline void __unhash_dl_info(struct dl_info *dli)
18275 +{
18276 +       vxdprintk(VXD_CBIT(dlim, 6),
18277 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18278 +       hlist_del_rcu(&dli->dl_hlist);
18279 +       put_dl_info(dli);
18280 +}
18281 +
18282 +
18283 +/*     __lookup_dl_info()
18284 +
18285 +       * requires the rcu_read_lock()
18286 +       * doesn't increment the dl_refcnt                       */
18287 +
18288 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18289 +{
18290 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18291 +       struct hlist_node *pos;
18292 +       struct dl_info *dli;
18293 +
18294 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18295 +
18296 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18297 +                       return dli;
18298 +               }
18299 +       }
18300 +       return NULL;
18301 +}
18302 +
18303 +
18304 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18305 +{
18306 +       struct dl_info *dli;
18307 +
18308 +       rcu_read_lock();
18309 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18310 +       vxdprintk(VXD_CBIT(dlim, 7),
18311 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18312 +       rcu_read_unlock();
18313 +       return dli;
18314 +}
18315 +
18316 +void rcu_free_dl_info(struct rcu_head *head)
18317 +{
18318 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18319 +       int usecnt, refcnt;
18320 +
18321 +       BUG_ON(!dli || !head);
18322 +
18323 +       usecnt = atomic_read(&dli->dl_usecnt);
18324 +       BUG_ON(usecnt < 0);
18325 +
18326 +       refcnt = atomic_read(&dli->dl_refcnt);
18327 +       BUG_ON(refcnt < 0);
18328 +
18329 +       vxdprintk(VXD_CBIT(dlim, 3),
18330 +               "rcu_free_dl_info(%p)", dli);
18331 +       if (!usecnt)
18332 +               __dealloc_dl_info(dli);
18333 +       else
18334 +               printk("!!! rcu didn't free\n");
18335 +}
18336 +
18337 +
18338 +
18339 +
18340 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18341 +       uint32_t flags, int add)
18342 +{
18343 +       struct path path;
18344 +       int ret;
18345 +
18346 +       ret = user_lpath(name, &path);
18347 +       if (!ret) {
18348 +               struct super_block *sb;
18349 +               struct dl_info *dli;
18350 +
18351 +               ret = -EINVAL;
18352 +               if (!path.dentry->d_inode)
18353 +                       goto out_release;
18354 +               if (!(sb = path.dentry->d_inode->i_sb))
18355 +                       goto out_release;
18356 +
18357 +               if (add) {
18358 +                       dli = __alloc_dl_info(sb, id);
18359 +                       spin_lock(&dl_info_hash_lock);
18360 +
18361 +                       ret = -EEXIST;
18362 +                       if (__lookup_dl_info(sb, id))
18363 +                               goto out_unlock;
18364 +                       __hash_dl_info(dli);
18365 +                       dli = NULL;
18366 +               } else {
18367 +                       spin_lock(&dl_info_hash_lock);
18368 +                       dli = __lookup_dl_info(sb, id);
18369 +
18370 +                       ret = -ESRCH;
18371 +                       if (!dli)
18372 +                               goto out_unlock;
18373 +                       __unhash_dl_info(dli);
18374 +               }
18375 +               ret = 0;
18376 +       out_unlock:
18377 +               spin_unlock(&dl_info_hash_lock);
18378 +               if (add && dli)
18379 +                       __dealloc_dl_info(dli);
18380 +       out_release:
18381 +               path_put(&path);
18382 +       }
18383 +       return ret;
18384 +}
18385 +
18386 +int vc_add_dlimit(uint32_t id, void __user *data)
18387 +{
18388 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18389 +
18390 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18391 +               return -EFAULT;
18392 +
18393 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18394 +}
18395 +
18396 +int vc_rem_dlimit(uint32_t id, void __user *data)
18397 +{
18398 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18399 +
18400 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18401 +               return -EFAULT;
18402 +
18403 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18404 +}
18405 +
18406 +#ifdef CONFIG_COMPAT
18407 +
18408 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18409 +{
18410 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18411 +
18412 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18413 +               return -EFAULT;
18414 +
18415 +       return do_addrem_dlimit(id,
18416 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18417 +}
18418 +
18419 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18420 +{
18421 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18422 +
18423 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18424 +               return -EFAULT;
18425 +
18426 +       return do_addrem_dlimit(id,
18427 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18428 +}
18429 +
18430 +#endif /* CONFIG_COMPAT */
18431 +
18432 +
18433 +static inline
18434 +int do_set_dlimit(uint32_t id, const char __user *name,
18435 +       uint32_t space_used, uint32_t space_total,
18436 +       uint32_t inodes_used, uint32_t inodes_total,
18437 +       uint32_t reserved, uint32_t flags)
18438 +{
18439 +       struct path path;
18440 +       int ret;
18441 +
18442 +       ret = user_lpath(name, &path);
18443 +       if (!ret) {
18444 +               struct super_block *sb;
18445 +               struct dl_info *dli;
18446 +
18447 +               ret = -EINVAL;
18448 +               if (!path.dentry->d_inode)
18449 +                       goto out_release;
18450 +               if (!(sb = path.dentry->d_inode->i_sb))
18451 +                       goto out_release;
18452 +
18453 +               /* sanity checks */
18454 +               if ((reserved != CDLIM_KEEP &&
18455 +                       reserved > 100) ||
18456 +                       (inodes_used != CDLIM_KEEP &&
18457 +                       inodes_used > inodes_total) ||
18458 +                       (space_used != CDLIM_KEEP &&
18459 +                       space_used > space_total))
18460 +                       goto out_release;
18461 +
18462 +               ret = -ESRCH;
18463 +               dli = locate_dl_info(sb, id);
18464 +               if (!dli)
18465 +                       goto out_release;
18466 +
18467 +               spin_lock(&dli->dl_lock);
18468 +
18469 +               if (inodes_used != CDLIM_KEEP)
18470 +                       dli->dl_inodes_used = inodes_used;
18471 +               if (inodes_total != CDLIM_KEEP)
18472 +                       dli->dl_inodes_total = inodes_total;
18473 +               if (space_used != CDLIM_KEEP)
18474 +                       dli->dl_space_used = dlimit_space_32to64(
18475 +                               space_used, flags, DLIMS_USED);
18476 +
18477 +               if (space_total == CDLIM_INFINITY)
18478 +                       dli->dl_space_total = DLIM_INFINITY;
18479 +               else if (space_total != CDLIM_KEEP)
18480 +                       dli->dl_space_total = dlimit_space_32to64(
18481 +                               space_total, flags, DLIMS_TOTAL);
18482 +
18483 +               if (reserved != CDLIM_KEEP)
18484 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18485 +
18486 +               spin_unlock(&dli->dl_lock);
18487 +
18488 +               put_dl_info(dli);
18489 +               ret = 0;
18490 +
18491 +       out_release:
18492 +               path_put(&path);
18493 +       }
18494 +       return ret;
18495 +}
18496 +
18497 +int vc_set_dlimit(uint32_t id, void __user *data)
18498 +{
18499 +       struct vcmd_ctx_dlimit_v0 vc_data;
18500 +
18501 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18502 +               return -EFAULT;
18503 +
18504 +       return do_set_dlimit(id, vc_data.name,
18505 +               vc_data.space_used, vc_data.space_total,
18506 +               vc_data.inodes_used, vc_data.inodes_total,
18507 +               vc_data.reserved, vc_data.flags);
18508 +}
18509 +
18510 +#ifdef CONFIG_COMPAT
18511 +
18512 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18513 +{
18514 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18515 +
18516 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18517 +               return -EFAULT;
18518 +
18519 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18520 +               vc_data.space_used, vc_data.space_total,
18521 +               vc_data.inodes_used, vc_data.inodes_total,
18522 +               vc_data.reserved, vc_data.flags);
18523 +}
18524 +
18525 +#endif /* CONFIG_COMPAT */
18526 +
18527 +
18528 +static inline
18529 +int do_get_dlimit(uint32_t id, const char __user *name,
18530 +       uint32_t *space_used, uint32_t *space_total,
18531 +       uint32_t *inodes_used, uint32_t *inodes_total,
18532 +       uint32_t *reserved, uint32_t *flags)
18533 +{
18534 +       struct path path;
18535 +       int ret;
18536 +
18537 +       ret = user_lpath(name, &path);
18538 +       if (!ret) {
18539 +               struct super_block *sb;
18540 +               struct dl_info *dli;
18541 +
18542 +               ret = -EINVAL;
18543 +               if (!path.dentry->d_inode)
18544 +                       goto out_release;
18545 +               if (!(sb = path.dentry->d_inode->i_sb))
18546 +                       goto out_release;
18547 +
18548 +               ret = -ESRCH;
18549 +               dli = locate_dl_info(sb, id);
18550 +               if (!dli)
18551 +                       goto out_release;
18552 +
18553 +               spin_lock(&dli->dl_lock);
18554 +               *inodes_used = dli->dl_inodes_used;
18555 +               *inodes_total = dli->dl_inodes_total;
18556 +
18557 +               *space_used = dlimit_space_64to32(
18558 +                       dli->dl_space_used, flags, DLIMS_USED);
18559 +
18560 +               if (dli->dl_space_total == DLIM_INFINITY)
18561 +                       *space_total = CDLIM_INFINITY;
18562 +               else
18563 +                       *space_total = dlimit_space_64to32(
18564 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18565 +
18566 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18567 +               spin_unlock(&dli->dl_lock);
18568 +
18569 +               put_dl_info(dli);
18570 +               ret = -EFAULT;
18571 +
18572 +               ret = 0;
18573 +       out_release:
18574 +               path_put(&path);
18575 +       }
18576 +       return ret;
18577 +}
18578 +
18579 +
18580 +int vc_get_dlimit(uint32_t id, void __user *data)
18581 +{
18582 +       struct vcmd_ctx_dlimit_v0 vc_data;
18583 +       int ret;
18584 +
18585 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18586 +               return -EFAULT;
18587 +
18588 +       ret = do_get_dlimit(id, vc_data.name,
18589 +               &vc_data.space_used, &vc_data.space_total,
18590 +               &vc_data.inodes_used, &vc_data.inodes_total,
18591 +               &vc_data.reserved, &vc_data.flags);
18592 +       if (ret)
18593 +               return ret;
18594 +
18595 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18596 +               return -EFAULT;
18597 +       return 0;
18598 +}
18599 +
18600 +#ifdef CONFIG_COMPAT
18601 +
18602 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18603 +{
18604 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18605 +       int ret;
18606 +
18607 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18608 +               return -EFAULT;
18609 +
18610 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18611 +               &vc_data.space_used, &vc_data.space_total,
18612 +               &vc_data.inodes_used, &vc_data.inodes_total,
18613 +               &vc_data.reserved, &vc_data.flags);
18614 +       if (ret)
18615 +               return ret;
18616 +
18617 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18618 +               return -EFAULT;
18619 +       return 0;
18620 +}
18621 +
18622 +#endif /* CONFIG_COMPAT */
18623 +
18624 +
18625 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18626 +{
18627 +       struct dl_info *dli;
18628 +       __u64 blimit, bfree, bavail;
18629 +       __u32 ifree;
18630 +
18631 +       dli = locate_dl_info(sb, dx_current_tag());
18632 +       if (!dli)
18633 +               return;
18634 +
18635 +       spin_lock(&dli->dl_lock);
18636 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18637 +               goto no_ilim;
18638 +
18639 +       /* reduce max inodes available to limit */
18640 +       if (buf->f_files > dli->dl_inodes_total)
18641 +               buf->f_files = dli->dl_inodes_total;
18642 +
18643 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18644 +       /* reduce free inodes to min */
18645 +       if (ifree < buf->f_ffree)
18646 +               buf->f_ffree = ifree;
18647 +
18648 +no_ilim:
18649 +       if (dli->dl_space_total == DLIM_INFINITY)
18650 +               goto no_blim;
18651 +
18652 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18653 +
18654 +       if (dli->dl_space_total < dli->dl_space_used)
18655 +               bfree = 0;
18656 +       else
18657 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18658 +                       >> sb->s_blocksize_bits;
18659 +
18660 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18661 +       if (bavail < dli->dl_space_used)
18662 +               bavail = 0;
18663 +       else
18664 +               bavail = (bavail - dli->dl_space_used)
18665 +                       >> sb->s_blocksize_bits;
18666 +
18667 +       /* reduce max space available to limit */
18668 +       if (buf->f_blocks > blimit)
18669 +               buf->f_blocks = blimit;
18670 +
18671 +       /* reduce free space to min */
18672 +       if (bfree < buf->f_bfree)
18673 +               buf->f_bfree = bfree;
18674 +
18675 +       /* reduce avail space to min */
18676 +       if (bavail < buf->f_bavail)
18677 +               buf->f_bavail = bavail;
18678 +
18679 +no_blim:
18680 +       spin_unlock(&dli->dl_lock);
18681 +       put_dl_info(dli);
18682 +
18683 +       return;
18684 +}
18685 +
18686 +#include <linux/module.h>
18687 +
18688 +EXPORT_SYMBOL_GPL(locate_dl_info);
18689 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18690 +
18691 diff -NurpP --minimal linux-2.6.37/kernel/vserver/helper.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/helper.c
18692 --- linux-2.6.37/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
18693 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/helper.c 2010-11-23 02:09:41.000000000 +0100
18694 @@ -0,0 +1,223 @@
18695 +/*
18696 + *  linux/kernel/vserver/helper.c
18697 + *
18698 + *  Virtual Context Support
18699 + *
18700 + *  Copyright (C) 2004-2007  Herbert Pötzl
18701 + *
18702 + *  V0.01  basic helper
18703 + *
18704 + */
18705 +
18706 +#include <linux/kmod.h>
18707 +#include <linux/reboot.h>
18708 +#include <linux/vs_context.h>
18709 +#include <linux/vs_network.h>
18710 +#include <linux/vserver/signal.h>
18711 +
18712 +
18713 +char vshelper_path[255] = "/sbin/vshelper";
18714 +
18715 +
18716 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18717 +{
18718 +       int ret;
18719 +
18720 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18721 +               printk( KERN_WARNING
18722 +                       "%s: (%s %s) returned %s with %d\n",
18723 +                       name, argv[1], argv[2],
18724 +                       sync ? "sync" : "async", ret);
18725 +       }
18726 +       vxdprintk(VXD_CBIT(switch, 4),
18727 +               "%s: (%s %s) returned %s with %d",
18728 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18729 +       return ret;
18730 +}
18731 +
18732 +/*
18733 + *      vshelper path is set via /proc/sys
18734 + *      invoked by vserver sys_reboot(), with
18735 + *      the following arguments
18736 + *
18737 + *      argv [0] = vshelper_path;
18738 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18739 + *      argv [2] = context identifier
18740 + *
18741 + *      envp [*] = type-specific parameters
18742 + */
18743 +
18744 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18745 +{
18746 +       char id_buf[8], cmd_buf[16];
18747 +       char uid_buf[16], pid_buf[16];
18748 +       int ret;
18749 +
18750 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18751 +       char *envp[] = {"HOME=/", "TERM=linux",
18752 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18753 +                       uid_buf, pid_buf, cmd_buf, 0};
18754 +
18755 +       if (vx_info_state(vxi, VXS_HELPER))
18756 +               return -EAGAIN;
18757 +       vxi->vx_state |= VXS_HELPER;
18758 +
18759 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18760 +
18761 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18762 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18763 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18764 +
18765 +       switch (cmd) {
18766 +       case LINUX_REBOOT_CMD_RESTART:
18767 +               argv[1] = "restart";
18768 +               break;
18769 +
18770 +       case LINUX_REBOOT_CMD_HALT:
18771 +               argv[1] = "halt";
18772 +               break;
18773 +
18774 +       case LINUX_REBOOT_CMD_POWER_OFF:
18775 +               argv[1] = "poweroff";
18776 +               break;
18777 +
18778 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18779 +               argv[1] = "swsusp";
18780 +               break;
18781 +
18782 +       case LINUX_REBOOT_CMD_OOM:
18783 +               argv[1] = "oom";
18784 +               break;
18785 +
18786 +       default:
18787 +               vxi->vx_state &= ~VXS_HELPER;
18788 +               return 0;
18789 +       }
18790 +
18791 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18792 +       vxi->vx_state &= ~VXS_HELPER;
18793 +       __wakeup_vx_info(vxi);
18794 +       return (ret) ? -EPERM : 0;
18795 +}
18796 +
18797 +
18798 +long vs_reboot(unsigned int cmd, void __user *arg)
18799 +{
18800 +       struct vx_info *vxi = current_vx_info();
18801 +       long ret = 0;
18802 +
18803 +       vxdprintk(VXD_CBIT(misc, 5),
18804 +               "vs_reboot(%p[#%d],%u)",
18805 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18806 +
18807 +       ret = vs_reboot_helper(vxi, cmd, arg);
18808 +       if (ret)
18809 +               return ret;
18810 +
18811 +       vxi->reboot_cmd = cmd;
18812 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18813 +               switch (cmd) {
18814 +               case LINUX_REBOOT_CMD_RESTART:
18815 +               case LINUX_REBOOT_CMD_HALT:
18816 +               case LINUX_REBOOT_CMD_POWER_OFF:
18817 +                       vx_info_kill(vxi, 0, SIGKILL);
18818 +                       vx_info_kill(vxi, 1, SIGKILL);
18819 +               default:
18820 +                       break;
18821 +               }
18822 +       }
18823 +       return 0;
18824 +}
18825 +
18826 +long vs_oom_action(unsigned int cmd)
18827 +{
18828 +       struct vx_info *vxi = current_vx_info();
18829 +       long ret = 0;
18830 +
18831 +       vxdprintk(VXD_CBIT(misc, 5),
18832 +               "vs_oom_action(%p[#%d],%u)",
18833 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18834 +
18835 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18836 +       if (ret)
18837 +               return ret;
18838 +
18839 +       vxi->reboot_cmd = cmd;
18840 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18841 +               vx_info_kill(vxi, 0, SIGKILL);
18842 +               vx_info_kill(vxi, 1, SIGKILL);
18843 +       }
18844 +       return 0;
18845 +}
18846 +
18847 +/*
18848 + *      argv [0] = vshelper_path;
18849 + *      argv [1] = action: "startup", "shutdown"
18850 + *      argv [2] = context identifier
18851 + *
18852 + *      envp [*] = type-specific parameters
18853 + */
18854 +
18855 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18856 +{
18857 +       char id_buf[8], cmd_buf[16];
18858 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18859 +       char *envp[] = {"HOME=/", "TERM=linux",
18860 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18861 +
18862 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18863 +               return 0;
18864 +
18865 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18866 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18867 +
18868 +       switch (cmd) {
18869 +       case VSC_STARTUP:
18870 +               argv[1] = "startup";
18871 +               break;
18872 +       case VSC_SHUTDOWN:
18873 +               argv[1] = "shutdown";
18874 +               break;
18875 +       default:
18876 +               return 0;
18877 +       }
18878 +
18879 +       return do_vshelper(vshelper_path, argv, envp, 1);
18880 +}
18881 +
18882 +
18883 +/*
18884 + *      argv [0] = vshelper_path;
18885 + *      argv [1] = action: "netup", "netdown"
18886 + *      argv [2] = context identifier
18887 + *
18888 + *      envp [*] = type-specific parameters
18889 + */
18890 +
18891 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18892 +{
18893 +       char id_buf[8], cmd_buf[16];
18894 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18895 +       char *envp[] = {"HOME=/", "TERM=linux",
18896 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18897 +
18898 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18899 +               return 0;
18900 +
18901 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18902 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18903 +
18904 +       switch (cmd) {
18905 +       case VSC_NETUP:
18906 +               argv[1] = "netup";
18907 +               break;
18908 +       case VSC_NETDOWN:
18909 +               argv[1] = "netdown";
18910 +               break;
18911 +       default:
18912 +               return 0;
18913 +       }
18914 +
18915 +       return do_vshelper(vshelper_path, argv, envp, 1);
18916 +}
18917 +
18918 diff -NurpP --minimal linux-2.6.37/kernel/vserver/history.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/history.c
18919 --- linux-2.6.37/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
18920 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/history.c        2010-11-23 02:09:41.000000000 +0100
18921 @@ -0,0 +1,258 @@
18922 +/*
18923 + *  kernel/vserver/history.c
18924 + *
18925 + *  Virtual Context History Backtrace
18926 + *
18927 + *  Copyright (C) 2004-2007  Herbert Pötzl
18928 + *
18929 + *  V0.01  basic structure
18930 + *  V0.02  hash/unhash and trace
18931 + *  V0.03  preemption fixes
18932 + *
18933 + */
18934 +
18935 +#include <linux/module.h>
18936 +#include <asm/uaccess.h>
18937 +
18938 +#include <linux/vserver/context.h>
18939 +#include <linux/vserver/debug.h>
18940 +#include <linux/vserver/debug_cmd.h>
18941 +#include <linux/vserver/history.h>
18942 +
18943 +
18944 +#ifdef CONFIG_VSERVER_HISTORY
18945 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18946 +#else
18947 +#define VXH_SIZE       64
18948 +#endif
18949 +
18950 +struct _vx_history {
18951 +       unsigned int counter;
18952 +
18953 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18954 +};
18955 +
18956 +
18957 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18958 +
18959 +unsigned volatile int vxh_active = 1;
18960 +
18961 +static atomic_t sequence = ATOMIC_INIT(0);
18962 +
18963 +
18964 +/*     vxh_advance()
18965 +
18966 +       * requires disabled preemption                          */
18967 +
18968 +struct _vx_hist_entry *vxh_advance(void *loc)
18969 +{
18970 +       unsigned int cpu = smp_processor_id();
18971 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18972 +       struct _vx_hist_entry *entry;
18973 +       unsigned int index;
18974 +
18975 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18976 +       entry = &hist->entry[index];
18977 +
18978 +       entry->seq = atomic_inc_return(&sequence);
18979 +       entry->loc = loc;
18980 +       return entry;
18981 +}
18982 +
18983 +EXPORT_SYMBOL_GPL(vxh_advance);
18984 +
18985 +
18986 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18987 +
18988 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18989 +
18990 +
18991 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18992 +
18993 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18994 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18995 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18996 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18997 +
18998 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18999 +{
19000 +       switch (e->type) {
19001 +       case VXH_THROW_OOPS:
19002 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19003 +               break;
19004 +
19005 +       case VXH_GET_VX_INFO:
19006 +       case VXH_PUT_VX_INFO:
19007 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19008 +                       VXH_LOC_ARGS(e),
19009 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19010 +                       VXH_VXI_ARGS(e));
19011 +               break;
19012 +
19013 +       case VXH_INIT_VX_INFO:
19014 +       case VXH_SET_VX_INFO:
19015 +       case VXH_CLR_VX_INFO:
19016 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19017 +                       VXH_LOC_ARGS(e),
19018 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19019 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19020 +                       VXH_VXI_ARGS(e), e->sc.data);
19021 +               break;
19022 +
19023 +       case VXH_CLAIM_VX_INFO:
19024 +       case VXH_RELEASE_VX_INFO:
19025 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19026 +                       VXH_LOC_ARGS(e),
19027 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19028 +                       VXH_VXI_ARGS(e), e->sc.data);
19029 +               break;
19030 +
19031 +       case VXH_ALLOC_VX_INFO:
19032 +       case VXH_DEALLOC_VX_INFO:
19033 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19034 +                       VXH_LOC_ARGS(e),
19035 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19036 +                       VXH_VXI_ARGS(e));
19037 +               break;
19038 +
19039 +       case VXH_HASH_VX_INFO:
19040 +       case VXH_UNHASH_VX_INFO:
19041 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19042 +                       VXH_LOC_ARGS(e),
19043 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19044 +                       VXH_VXI_ARGS(e));
19045 +               break;
19046 +
19047 +       case VXH_LOC_VX_INFO:
19048 +       case VXH_LOOKUP_VX_INFO:
19049 +       case VXH_CREATE_VX_INFO:
19050 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19051 +                       VXH_LOC_ARGS(e),
19052 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19053 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19054 +                       e->ll.arg, VXH_VXI_ARGS(e));
19055 +               break;
19056 +       }
19057 +}
19058 +
19059 +static void __vxh_dump_history(void)
19060 +{
19061 +       unsigned int i, cpu;
19062 +
19063 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19064 +               atomic_read(&sequence), NR_CPUS);
19065 +
19066 +       for (i = 0; i < VXH_SIZE; i++) {
19067 +               for_each_online_cpu(cpu) {
19068 +                       struct _vx_history *hist =
19069 +                               &per_cpu(vx_history_buffer, cpu);
19070 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19071 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19072 +
19073 +                       vxh_dump_entry(entry, cpu);
19074 +               }
19075 +       }
19076 +}
19077 +
19078 +void   vxh_dump_history(void)
19079 +{
19080 +       vxh_active = 0;
19081 +#ifdef CONFIG_SMP
19082 +       local_irq_enable();
19083 +       smp_send_stop();
19084 +       local_irq_disable();
19085 +#endif
19086 +       __vxh_dump_history();
19087 +}
19088 +
19089 +
19090 +/* vserver syscall commands below here */
19091 +
19092 +
19093 +int vc_dump_history(uint32_t id)
19094 +{
19095 +       vxh_active = 0;
19096 +       __vxh_dump_history();
19097 +       vxh_active = 1;
19098 +
19099 +       return 0;
19100 +}
19101 +
19102 +
19103 +int do_read_history(struct __user _vx_hist_entry *data,
19104 +       int cpu, uint32_t *index, uint32_t *count)
19105 +{
19106 +       int pos, ret = 0;
19107 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19108 +       int end = hist->counter;
19109 +       int start = end - VXH_SIZE + 2;
19110 +       int idx = *index;
19111 +
19112 +       /* special case: get current pos */
19113 +       if (!*count) {
19114 +               *index = end;
19115 +               return 0;
19116 +       }
19117 +
19118 +       /* have we lost some data? */
19119 +       if (idx < start)
19120 +               idx = start;
19121 +
19122 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19123 +               struct _vx_hist_entry *entry =
19124 +                       &hist->entry[idx % VXH_SIZE];
19125 +
19126 +               /* send entry to userspace */
19127 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19128 +               if (ret)
19129 +                       break;
19130 +       }
19131 +       /* save new index and count */
19132 +       *index = idx;
19133 +       *count = pos;
19134 +       return ret ? ret : (*index < end);
19135 +}
19136 +
19137 +int vc_read_history(uint32_t id, void __user *data)
19138 +{
19139 +       struct vcmd_read_history_v0 vc_data;
19140 +       int ret;
19141 +
19142 +       if (id >= NR_CPUS)
19143 +               return -EINVAL;
19144 +
19145 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19146 +               return -EFAULT;
19147 +
19148 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19149 +               id, &vc_data.index, &vc_data.count);
19150 +
19151 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19152 +               return -EFAULT;
19153 +       return ret;
19154 +}
19155 +
19156 +#ifdef CONFIG_COMPAT
19157 +
19158 +int vc_read_history_x32(uint32_t id, void __user *data)
19159 +{
19160 +       struct vcmd_read_history_v0_x32 vc_data;
19161 +       int ret;
19162 +
19163 +       if (id >= NR_CPUS)
19164 +               return -EINVAL;
19165 +
19166 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19167 +               return -EFAULT;
19168 +
19169 +       ret = do_read_history((struct __user _vx_hist_entry *)
19170 +               compat_ptr(vc_data.data_ptr),
19171 +               id, &vc_data.index, &vc_data.count);
19172 +
19173 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19174 +               return -EFAULT;
19175 +       return ret;
19176 +}
19177 +
19178 +#endif /* CONFIG_COMPAT */
19179 +
19180 diff -NurpP --minimal linux-2.6.37/kernel/vserver/inet.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/inet.c
19181 --- linux-2.6.37/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
19182 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/inet.c   2010-11-23 02:09:41.000000000 +0100
19183 @@ -0,0 +1,224 @@
19184 +
19185 +#include <linux/in.h>
19186 +#include <linux/inetdevice.h>
19187 +#include <linux/vs_inet.h>
19188 +#include <linux/vs_inet6.h>
19189 +#include <linux/vserver/debug.h>
19190 +#include <net/route.h>
19191 +#include <net/addrconf.h>
19192 +
19193 +
19194 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19195 +{
19196 +       int ret = 0;
19197 +
19198 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19199 +               ret = 1;
19200 +       else {
19201 +               struct nx_addr_v4 *ptr;
19202 +
19203 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19204 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19205 +                               ret = 1;
19206 +                               break;
19207 +                       }
19208 +               }
19209 +       }
19210 +
19211 +       vxdprintk(VXD_CBIT(net, 2),
19212 +               "nx_v4_addr_conflict(%p,%p): %d",
19213 +               nxi1, nxi2, ret);
19214 +
19215 +       return ret;
19216 +}
19217 +
19218 +
19219 +#ifdef CONFIG_IPV6
19220 +
19221 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19222 +{
19223 +       int ret = 0;
19224 +
19225 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19226 +               ret = 1;
19227 +       else {
19228 +               struct nx_addr_v6 *ptr;
19229 +
19230 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19231 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19232 +                               ret = 1;
19233 +                               break;
19234 +                       }
19235 +               }
19236 +       }
19237 +
19238 +       vxdprintk(VXD_CBIT(net, 2),
19239 +               "nx_v6_addr_conflict(%p,%p): %d",
19240 +               nxi1, nxi2, ret);
19241 +
19242 +       return ret;
19243 +}
19244 +
19245 +#endif
19246 +
19247 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19248 +{
19249 +       struct in_device *in_dev;
19250 +       struct in_ifaddr **ifap;
19251 +       struct in_ifaddr *ifa;
19252 +       int ret = 0;
19253 +
19254 +       if (!dev)
19255 +               goto out;
19256 +       in_dev = in_dev_get(dev);
19257 +       if (!in_dev)
19258 +               goto out;
19259 +
19260 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19261 +               ifap = &ifa->ifa_next) {
19262 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19263 +                       ret = 1;
19264 +                       break;
19265 +               }
19266 +       }
19267 +       in_dev_put(in_dev);
19268 +out:
19269 +       return ret;
19270 +}
19271 +
19272 +
19273 +#ifdef CONFIG_IPV6
19274 +
19275 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19276 +{
19277 +       struct inet6_dev *in_dev;
19278 +       struct inet6_ifaddr *ifa;
19279 +       int ret = 0;
19280 +
19281 +       if (!dev)
19282 +               goto out;
19283 +       in_dev = in6_dev_get(dev);
19284 +       if (!in_dev)
19285 +               goto out;
19286 +
19287 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19288 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19289 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19290 +                       ret = 1;
19291 +                       break;
19292 +               }
19293 +       }
19294 +       in6_dev_put(in_dev);
19295 +out:
19296 +       return ret;
19297 +}
19298 +
19299 +#endif
19300 +
19301 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19302 +{
19303 +       int ret = 1;
19304 +
19305 +       if (!nxi)
19306 +               goto out;
19307 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19308 +               goto out;
19309 +#ifdef CONFIG_IPV6
19310 +       ret = 2;
19311 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19312 +               goto out;
19313 +#endif
19314 +       ret = 0;
19315 +out:
19316 +       vxdprintk(VXD_CBIT(net, 3),
19317 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19318 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19319 +       return ret;
19320 +}
19321 +
19322 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
19323 +       struct rtable **rp, struct flowi *fl)
19324 +{
19325 +       if (!nxi)
19326 +               return 0;
19327 +
19328 +       /* FIXME: handle lback only case */
19329 +       if (!NX_IPV4(nxi))
19330 +               return -EPERM;
19331 +
19332 +       vxdprintk(VXD_CBIT(net, 4),
19333 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19334 +               nxi, nxi ? nxi->nx_id : 0,
19335 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
19336 +
19337 +       /* single IP is unconditional */
19338 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19339 +               (fl->fl4_src == INADDR_ANY))
19340 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
19341 +
19342 +       if (fl->fl4_src == INADDR_ANY) {
19343 +               struct nx_addr_v4 *ptr;
19344 +               __be32 found = 0;
19345 +               int err;
19346 +
19347 +               err = __ip_route_output_key(net, rp, fl);
19348 +               if (!err) {
19349 +                       found = (*rp)->rt_src;
19350 +                       ip_rt_put(*rp);
19351 +                       vxdprintk(VXD_CBIT(net, 4),
19352 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19353 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
19354 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19355 +                               goto found;
19356 +               }
19357 +
19358 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19359 +                       __be32 primary = ptr->ip[0].s_addr;
19360 +                       __be32 mask = ptr->mask.s_addr;
19361 +                       __be32 neta = primary & mask;
19362 +
19363 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19364 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19365 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19366 +                               NIPQUAD(mask), NIPQUAD(neta));
19367 +                       if ((found & mask) != neta)
19368 +                               continue;
19369 +
19370 +                       fl->fl4_src = primary;
19371 +                       err = __ip_route_output_key(net, rp, fl);
19372 +                       vxdprintk(VXD_CBIT(net, 4),
19373 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19374 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
19375 +                       if (!err) {
19376 +                               found = (*rp)->rt_src;
19377 +                               ip_rt_put(*rp);
19378 +                               if (found == primary)
19379 +                                       goto found;
19380 +                       }
19381 +               }
19382 +               /* still no source ip? */
19383 +               found = ipv4_is_loopback(fl->fl4_dst)
19384 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19385 +       found:
19386 +               /* assign src ip to flow */
19387 +               fl->fl4_src = found;
19388 +
19389 +       } else {
19390 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
19391 +                       return -EPERM;
19392 +       }
19393 +
19394 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19395 +               if (ipv4_is_loopback(fl->fl4_dst))
19396 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
19397 +               if (ipv4_is_loopback(fl->fl4_src))
19398 +                       fl->fl4_src = nxi->v4_lback.s_addr;
19399 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
19400 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19401 +               return -EPERM;
19402 +
19403 +       return 0;
19404 +}
19405 +
19406 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19407 +
19408 diff -NurpP --minimal linux-2.6.37/kernel/vserver/init.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/init.c
19409 --- linux-2.6.37/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
19410 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/init.c   2010-11-23 02:09:41.000000000 +0100
19411 @@ -0,0 +1,45 @@
19412 +/*
19413 + *  linux/kernel/init.c
19414 + *
19415 + *  Virtual Server Init
19416 + *
19417 + *  Copyright (C) 2004-2007  Herbert Pötzl
19418 + *
19419 + *  V0.01  basic structure
19420 + *
19421 + */
19422 +
19423 +#include <linux/init.h>
19424 +
19425 +int    vserver_register_sysctl(void);
19426 +void   vserver_unregister_sysctl(void);
19427 +
19428 +
19429 +static int __init init_vserver(void)
19430 +{
19431 +       int ret = 0;
19432 +
19433 +#ifdef CONFIG_VSERVER_DEBUG
19434 +       vserver_register_sysctl();
19435 +#endif
19436 +       return ret;
19437 +}
19438 +
19439 +
19440 +static void __exit exit_vserver(void)
19441 +{
19442 +
19443 +#ifdef CONFIG_VSERVER_DEBUG
19444 +       vserver_unregister_sysctl();
19445 +#endif
19446 +       return;
19447 +}
19448 +
19449 +/* FIXME: GFP_ZONETYPES gone
19450 +long vx_slab[GFP_ZONETYPES]; */
19451 +long vx_area;
19452 +
19453 +
19454 +module_init(init_vserver);
19455 +module_exit(exit_vserver);
19456 +
19457 diff -NurpP --minimal linux-2.6.37/kernel/vserver/inode.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/inode.c
19458 --- linux-2.6.37/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
19459 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/inode.c  2010-11-23 02:09:41.000000000 +0100
19460 @@ -0,0 +1,435 @@
19461 +/*
19462 + *  linux/kernel/vserver/inode.c
19463 + *
19464 + *  Virtual Server: File System Support
19465 + *
19466 + *  Copyright (C) 2004-2007  Herbert Pötzl
19467 + *
19468 + *  V0.01  separated from vcontext V0.05
19469 + *  V0.02  moved to tag (instead of xid)
19470 + *
19471 + */
19472 +
19473 +#include <linux/tty.h>
19474 +#include <linux/proc_fs.h>
19475 +#include <linux/devpts_fs.h>
19476 +#include <linux/fs.h>
19477 +#include <linux/file.h>
19478 +#include <linux/mount.h>
19479 +#include <linux/parser.h>
19480 +#include <linux/namei.h>
19481 +#include <linux/vserver/inode.h>
19482 +#include <linux/vserver/inode_cmd.h>
19483 +#include <linux/vs_base.h>
19484 +#include <linux/vs_tag.h>
19485 +
19486 +#include <asm/uaccess.h>
19487 +
19488 +
19489 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19490 +{
19491 +       struct proc_dir_entry *entry;
19492 +
19493 +       if (!in || !in->i_sb)
19494 +               return -ESRCH;
19495 +
19496 +       *flags = IATTR_TAG
19497 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19498 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19499 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19500 +               | (IS_COW(in) ? IATTR_COW : 0);
19501 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19502 +
19503 +       if (S_ISDIR(in->i_mode))
19504 +               *mask |= IATTR_BARRIER;
19505 +
19506 +       if (IS_TAGGED(in)) {
19507 +               *tag = in->i_tag;
19508 +               *mask |= IATTR_TAG;
19509 +       }
19510 +
19511 +       switch (in->i_sb->s_magic) {
19512 +       case PROC_SUPER_MAGIC:
19513 +               entry = PROC_I(in)->pde;
19514 +
19515 +               /* check for specific inodes? */
19516 +               if (entry)
19517 +                       *mask |= IATTR_FLAGS;
19518 +               if (entry)
19519 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19520 +               else
19521 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19522 +               break;
19523 +
19524 +       case DEVPTS_SUPER_MAGIC:
19525 +               *tag = in->i_tag;
19526 +               *mask |= IATTR_TAG;
19527 +               break;
19528 +
19529 +       default:
19530 +               break;
19531 +       }
19532 +       return 0;
19533 +}
19534 +
19535 +int vc_get_iattr(void __user *data)
19536 +{
19537 +       struct path path;
19538 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19539 +       int ret;
19540 +
19541 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19542 +               return -EFAULT;
19543 +
19544 +       ret = user_lpath(vc_data.name, &path);
19545 +       if (!ret) {
19546 +               ret = __vc_get_iattr(path.dentry->d_inode,
19547 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19548 +               path_put(&path);
19549 +       }
19550 +       if (ret)
19551 +               return ret;
19552 +
19553 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19554 +               ret = -EFAULT;
19555 +       return ret;
19556 +}
19557 +
19558 +#ifdef CONFIG_COMPAT
19559 +
19560 +int vc_get_iattr_x32(void __user *data)
19561 +{
19562 +       struct path path;
19563 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19564 +       int ret;
19565 +
19566 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19567 +               return -EFAULT;
19568 +
19569 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19570 +       if (!ret) {
19571 +               ret = __vc_get_iattr(path.dentry->d_inode,
19572 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19573 +               path_put(&path);
19574 +       }
19575 +       if (ret)
19576 +               return ret;
19577 +
19578 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19579 +               ret = -EFAULT;
19580 +       return ret;
19581 +}
19582 +
19583 +#endif /* CONFIG_COMPAT */
19584 +
19585 +
19586 +int vc_fget_iattr(uint32_t fd, void __user *data)
19587 +{
19588 +       struct file *filp;
19589 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19590 +       int ret;
19591 +
19592 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19593 +               return -EFAULT;
19594 +
19595 +       filp = fget(fd);
19596 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19597 +               return -EBADF;
19598 +
19599 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19600 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19601 +
19602 +       fput(filp);
19603 +
19604 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19605 +               ret = -EFAULT;
19606 +       return ret;
19607 +}
19608 +
19609 +
19610 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19611 +{
19612 +       struct inode *in = de->d_inode;
19613 +       int error = 0, is_proc = 0, has_tag = 0;
19614 +       struct iattr attr = { 0 };
19615 +
19616 +       if (!in || !in->i_sb)
19617 +               return -ESRCH;
19618 +
19619 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19620 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19621 +               return -EINVAL;
19622 +
19623 +       has_tag = IS_TAGGED(in) ||
19624 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19625 +       if ((*mask & IATTR_TAG) && !has_tag)
19626 +               return -EINVAL;
19627 +
19628 +       mutex_lock(&in->i_mutex);
19629 +       if (*mask & IATTR_TAG) {
19630 +               attr.ia_tag = *tag;
19631 +               attr.ia_valid |= ATTR_TAG;
19632 +       }
19633 +
19634 +       if (*mask & IATTR_FLAGS) {
19635 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19636 +               unsigned int iflags = PROC_I(in)->vx_flags;
19637 +
19638 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19639 +                       | (*flags & IATTR_FLAGS);
19640 +               PROC_I(in)->vx_flags = iflags;
19641 +               if (entry)
19642 +                       entry->vx_flags = iflags;
19643 +       }
19644 +
19645 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19646 +               IATTR_BARRIER | IATTR_COW)) {
19647 +               int iflags = in->i_flags;
19648 +               int vflags = in->i_vflags;
19649 +
19650 +               if (*mask & IATTR_IMMUTABLE) {
19651 +                       if (*flags & IATTR_IMMUTABLE)
19652 +                               iflags |= S_IMMUTABLE;
19653 +                       else
19654 +                               iflags &= ~S_IMMUTABLE;
19655 +               }
19656 +               if (*mask & IATTR_IXUNLINK) {
19657 +                       if (*flags & IATTR_IXUNLINK)
19658 +                               iflags |= S_IXUNLINK;
19659 +                       else
19660 +                               iflags &= ~S_IXUNLINK;
19661 +               }
19662 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19663 +                       if (*flags & IATTR_BARRIER)
19664 +                               vflags |= V_BARRIER;
19665 +                       else
19666 +                               vflags &= ~V_BARRIER;
19667 +               }
19668 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19669 +                       if (*flags & IATTR_COW)
19670 +                               vflags |= V_COW;
19671 +                       else
19672 +                               vflags &= ~V_COW;
19673 +               }
19674 +               if (in->i_op && in->i_op->sync_flags) {
19675 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19676 +                       if (error)
19677 +                               goto out;
19678 +               }
19679 +       }
19680 +
19681 +       if (attr.ia_valid) {
19682 +               if (in->i_op && in->i_op->setattr)
19683 +                       error = in->i_op->setattr(de, &attr);
19684 +               else {
19685 +                       error = inode_change_ok(in, &attr);
19686 +                       if (!error) {
19687 +                               setattr_copy(in, &attr);
19688 +                               mark_inode_dirty(in);
19689 +                       }
19690 +               }
19691 +       }
19692 +
19693 +out:
19694 +       mutex_unlock(&in->i_mutex);
19695 +       return error;
19696 +}
19697 +
19698 +int vc_set_iattr(void __user *data)
19699 +{
19700 +       struct path path;
19701 +       struct vcmd_ctx_iattr_v1 vc_data;
19702 +       int ret;
19703 +
19704 +       if (!capable(CAP_LINUX_IMMUTABLE))
19705 +               return -EPERM;
19706 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19707 +               return -EFAULT;
19708 +
19709 +       ret = user_lpath(vc_data.name, &path);
19710 +       if (!ret) {
19711 +               ret = __vc_set_iattr(path.dentry,
19712 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19713 +               path_put(&path);
19714 +       }
19715 +
19716 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19717 +               ret = -EFAULT;
19718 +       return ret;
19719 +}
19720 +
19721 +#ifdef CONFIG_COMPAT
19722 +
19723 +int vc_set_iattr_x32(void __user *data)
19724 +{
19725 +       struct path path;
19726 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19727 +       int ret;
19728 +
19729 +       if (!capable(CAP_LINUX_IMMUTABLE))
19730 +               return -EPERM;
19731 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19732 +               return -EFAULT;
19733 +
19734 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19735 +       if (!ret) {
19736 +               ret = __vc_set_iattr(path.dentry,
19737 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19738 +               path_put(&path);
19739 +       }
19740 +
19741 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19742 +               ret = -EFAULT;
19743 +       return ret;
19744 +}
19745 +
19746 +#endif /* CONFIG_COMPAT */
19747 +
19748 +int vc_fset_iattr(uint32_t fd, void __user *data)
19749 +{
19750 +       struct file *filp;
19751 +       struct vcmd_ctx_fiattr_v0 vc_data;
19752 +       int ret;
19753 +
19754 +       if (!capable(CAP_LINUX_IMMUTABLE))
19755 +               return -EPERM;
19756 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19757 +               return -EFAULT;
19758 +
19759 +       filp = fget(fd);
19760 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19761 +               return -EBADF;
19762 +
19763 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19764 +               &vc_data.flags, &vc_data.mask);
19765 +
19766 +       fput(filp);
19767 +
19768 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19769 +               return -EFAULT;
19770 +       return ret;
19771 +}
19772 +
19773 +
19774 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19775 +
19776 +static match_table_t tokens = {
19777 +       {Opt_notagcheck, "notagcheck"},
19778 +#ifdef CONFIG_PROPAGATE
19779 +       {Opt_notag, "notag"},
19780 +       {Opt_tag, "tag"},
19781 +       {Opt_tagid, "tagid=%u"},
19782 +#endif
19783 +       {Opt_err, NULL}
19784 +};
19785 +
19786 +
19787 +static void __dx_parse_remove(char *string, char *opt)
19788 +{
19789 +       char *p = strstr(string, opt);
19790 +       char *q = p;
19791 +
19792 +       if (p) {
19793 +               while (*q != '\0' && *q != ',')
19794 +                       q++;
19795 +               while (*q)
19796 +                       *p++ = *q++;
19797 +               while (*p)
19798 +                       *p++ = '\0';
19799 +       }
19800 +}
19801 +
19802 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19803 +                unsigned long *flags)
19804 +{
19805 +       int set = 0;
19806 +       substring_t args[MAX_OPT_ARGS];
19807 +       int token, option = 0;
19808 +       char *s, *p, *opts;
19809 +
19810 +       if (!string)
19811 +               return 0;
19812 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19813 +       if (!s)
19814 +               return 0;
19815 +
19816 +       opts = s;
19817 +       while ((p = strsep(&opts, ",")) != NULL) {
19818 +               token = match_token(p, tokens, args);
19819 +
19820 +               vxdprintk(VXD_CBIT(tag, 7),
19821 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19822 +                       p, token, option);
19823 +
19824 +               switch (token) {
19825 +#ifdef CONFIG_PROPAGATE
19826 +               case Opt_tag:
19827 +                       if (tag)
19828 +                               *tag = 0;
19829 +                       if (remove)
19830 +                               __dx_parse_remove(s, "tag");
19831 +                       *mnt_flags |= MNT_TAGID;
19832 +                       set |= MNT_TAGID;
19833 +                       break;
19834 +               case Opt_notag:
19835 +                       if (remove)
19836 +                               __dx_parse_remove(s, "notag");
19837 +                       *mnt_flags |= MNT_NOTAG;
19838 +                       set |= MNT_NOTAG;
19839 +                       break;
19840 +               case Opt_tagid:
19841 +                       if (tag && !match_int(args, &option))
19842 +                               *tag = option;
19843 +                       if (remove)
19844 +                               __dx_parse_remove(s, "tagid");
19845 +                       *mnt_flags |= MNT_TAGID;
19846 +                       set |= MNT_TAGID;
19847 +                       break;
19848 +#endif
19849 +               case Opt_notagcheck:
19850 +                       if (remove)
19851 +                               __dx_parse_remove(s, "notagcheck");
19852 +                       *flags |= MS_NOTAGCHECK;
19853 +                       set |= MS_NOTAGCHECK;
19854 +                       break;
19855 +               }
19856 +       }
19857 +       if (set)
19858 +               strcpy(string, s);
19859 +       kfree(s);
19860 +       return set;
19861 +}
19862 +
19863 +#ifdef CONFIG_PROPAGATE
19864 +
19865 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19866 +{
19867 +       tag_t new_tag = 0;
19868 +       struct vfsmount *mnt;
19869 +       int propagate;
19870 +
19871 +       if (!nd)
19872 +               return;
19873 +       mnt = nd->path.mnt;
19874 +       if (!mnt)
19875 +               return;
19876 +
19877 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19878 +       if (propagate)
19879 +               new_tag = mnt->mnt_tag;
19880 +
19881 +       vxdprintk(VXD_CBIT(tag, 7),
19882 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19883 +               inode, inode->i_ino, inode->i_tag,
19884 +               new_tag, (propagate) ? 1 : 0);
19885 +
19886 +       if (propagate)
19887 +               inode->i_tag = new_tag;
19888 +}
19889 +
19890 +#include <linux/module.h>
19891 +
19892 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19893 +
19894 +#endif /* CONFIG_PROPAGATE */
19895 +
19896 diff -NurpP --minimal linux-2.6.37/kernel/vserver/Kconfig linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/Kconfig
19897 --- linux-2.6.37/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
19898 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/Kconfig  2010-11-23 02:09:41.000000000 +0100
19899 @@ -0,0 +1,265 @@
19900 +#
19901 +# Linux VServer configuration
19902 +#
19903 +
19904 +menu "Linux VServer"
19905 +
19906 +config VSERVER_AUTO_LBACK
19907 +       bool    "Automatically Assign Loopback IP"
19908 +       default y
19909 +       help
19910 +         Automatically assign a guest specific loopback
19911 +         IP and add it to the kernel network stack on
19912 +         startup.
19913 +
19914 +config VSERVER_AUTO_SINGLE
19915 +       bool    "Automatic Single IP Special Casing"
19916 +       depends on EXPERIMENTAL
19917 +       default y
19918 +       help
19919 +         This allows network contexts with a single IP to
19920 +         automatically remap 0.0.0.0 bindings to that IP,
19921 +         avoiding further network checks and improving
19922 +         performance.
19923 +
19924 +         (note: such guests do not allow to change the ip
19925 +          on the fly and do not show loopback addresses)
19926 +
19927 +config VSERVER_COWBL
19928 +       bool    "Enable COW Immutable Link Breaking"
19929 +       default y
19930 +       help
19931 +         This enables the COW (Copy-On-Write) link break code.
19932 +         It allows you to treat unified files like normal files
19933 +         when writing to them (which will implicitely break the
19934 +         link and create a copy of the unified file)
19935 +
19936 +config VSERVER_VTIME
19937 +       bool    "Enable Virtualized Guest Time"
19938 +       depends on EXPERIMENTAL
19939 +       default n
19940 +       help
19941 +         This enables per guest time offsets to allow for
19942 +         adjusting the system clock individually per guest.
19943 +         this adds some overhead to the time functions and
19944 +         therefore should not be enabled without good reason.
19945 +
19946 +config VSERVER_DEVICE
19947 +       bool    "Enable Guest Device Mapping"
19948 +       depends on EXPERIMENTAL
19949 +       default n
19950 +       help
19951 +         This enables generic device remapping.
19952 +
19953 +config VSERVER_PROC_SECURE
19954 +       bool    "Enable Proc Security"
19955 +       depends on PROC_FS
19956 +       default y
19957 +       help
19958 +         This configures ProcFS security to initially hide
19959 +         non-process entries for all contexts except the main and
19960 +         spectator context (i.e. for all guests), which is a secure
19961 +         default.
19962 +
19963 +         (note: on 1.2x the entries were visible by default)
19964 +
19965 +config VSERVER_HARDCPU
19966 +       bool    "Enable Hard CPU Limits"
19967 +       default y
19968 +       help
19969 +         Activate the Hard CPU Limits
19970 +
19971 +         This will compile in code that allows the Token Bucket
19972 +         Scheduler to put processes on hold when a context's
19973 +         tokens are depleted (provided that its per-context
19974 +         sched_hard flag is set).
19975 +
19976 +         Processes belonging to that context will not be able
19977 +         to consume CPU resources again until a per-context
19978 +         configured minimum of tokens has been reached.
19979 +
19980 +config VSERVER_IDLETIME
19981 +       bool    "Avoid idle CPUs by skipping Time"
19982 +       depends on VSERVER_HARDCPU
19983 +       default y
19984 +       help
19985 +         This option allows the scheduler to artificially
19986 +         advance time (per cpu) when otherwise the idle
19987 +         task would be scheduled, thus keeping the cpu
19988 +         busy and sharing the available resources among
19989 +         certain contexts.
19990 +
19991 +config VSERVER_IDLELIMIT
19992 +       bool    "Limit the IDLE task"
19993 +       depends on VSERVER_HARDCPU
19994 +       default n
19995 +       help
19996 +         Limit the idle slices, so the the next context
19997 +         will be scheduled as soon as possible.
19998 +
19999 +         This might improve interactivity and latency, but
20000 +         will also marginally increase scheduling overhead.
20001 +
20002 +choice
20003 +       prompt  "Persistent Inode Tagging"
20004 +       default TAGGING_ID24
20005 +       help
20006 +         This adds persistent context information to filesystems
20007 +         mounted with the tagxid option. Tagging is a requirement
20008 +         for per-context disk limits and per-context quota.
20009 +
20010 +
20011 +config TAGGING_NONE
20012 +       bool    "Disabled"
20013 +       help
20014 +         do not store per-context information in inodes.
20015 +
20016 +config TAGGING_UID16
20017 +       bool    "UID16/GID32"
20018 +       help
20019 +         reduces UID to 16 bit, but leaves GID at 32 bit.
20020 +
20021 +config TAGGING_GID16
20022 +       bool    "UID32/GID16"
20023 +       help
20024 +         reduces GID to 16 bit, but leaves UID at 32 bit.
20025 +
20026 +config TAGGING_ID24
20027 +       bool    "UID24/GID24"
20028 +       help
20029 +         uses the upper 8bit from UID and GID for XID tagging
20030 +         which leaves 24bit for UID/GID each, which should be
20031 +         more than sufficient for normal use.
20032 +
20033 +config TAGGING_INTERN
20034 +       bool    "UID32/GID32"
20035 +       help
20036 +         this uses otherwise reserved inode fields in the on
20037 +         disk representation, which limits the use to a few
20038 +         filesystems (currently ext2 and ext3)
20039 +
20040 +endchoice
20041 +
20042 +config TAG_NFSD
20043 +       bool    "Tag NFSD User Auth and Files"
20044 +       default n
20045 +       help
20046 +         Enable this if you do want the in-kernel NFS
20047 +         Server to use the tagging specified above.
20048 +         (will require patched clients too)
20049 +
20050 +config VSERVER_PRIVACY
20051 +       bool    "Honor Privacy Aspects of Guests"
20052 +       default n
20053 +       help
20054 +         When enabled, most context checks will disallow
20055 +         access to structures assigned to a specific context,
20056 +         like ptys or loop devices.
20057 +
20058 +config VSERVER_CONTEXTS
20059 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
20060 +       range 1 65533
20061 +       default "768"   if 64BIT
20062 +       default "256"
20063 +       help
20064 +         This setting will optimize certain data structures
20065 +         and memory allocations according to the expected
20066 +         maximum.
20067 +
20068 +         note: this is not a strict upper limit.
20069 +
20070 +config VSERVER_WARN
20071 +       bool    "VServer Warnings"
20072 +       default y
20073 +       help
20074 +         This enables various runtime warnings, which will
20075 +         notify about potential manipulation attempts or
20076 +         resource shortage. It is generally considered to
20077 +         be a good idea to have that enabled.
20078 +
20079 +config VSERVER_WARN_DEVPTS
20080 +       bool    "VServer DevPTS Warnings"
20081 +       depends on VSERVER_WARN
20082 +       default y
20083 +       help
20084 +         This enables DevPTS related warnings, issued when a
20085 +         process inside a context tries to lookup or access
20086 +         a dynamic pts from the host or a different context.
20087 +
20088 +config VSERVER_DEBUG
20089 +       bool    "VServer Debugging Code"
20090 +       default n
20091 +       help
20092 +         Set this to yes if you want to be able to activate
20093 +         debugging output at runtime. It adds a very small
20094 +         overhead to all vserver related functions and
20095 +         increases the kernel size by about 20k.
20096 +
20097 +config VSERVER_HISTORY
20098 +       bool    "VServer History Tracing"
20099 +       depends on VSERVER_DEBUG
20100 +       default n
20101 +       help
20102 +         Set this to yes if you want to record the history of
20103 +         linux-vserver activities, so they can be replayed in
20104 +         the event of a kernel panic or oops.
20105 +
20106 +config VSERVER_HISTORY_SIZE
20107 +       int     "Per-CPU History Size (32-65536)"
20108 +       depends on VSERVER_HISTORY
20109 +       range 32 65536
20110 +       default 64
20111 +       help
20112 +         This allows you to specify the number of entries in
20113 +         the per-CPU history buffer.
20114 +
20115 +config VSERVER_LEGACY_MEM
20116 +       bool    "Legacy Memory Limits"
20117 +       default n
20118 +       help
20119 +         This provides fake memory limits to keep
20120 +         older tools happy in the face of memory
20121 +         cgroups
20122 +
20123 +choice
20124 +       prompt  "Quotes used in debug and warn messages"
20125 +       default QUOTES_ISO8859
20126 +
20127 +config QUOTES_ISO8859
20128 +       bool    "Extended ASCII (ISO 8859) angle quotes"
20129 +       help
20130 +         This uses the extended ASCII characters \xbb
20131 +         and \xab for quoting file and process names.
20132 +
20133 +config QUOTES_UTF8
20134 +       bool    "UTF-8 angle quotes"
20135 +       help
20136 +         This uses the the UTF-8 sequences for angle
20137 +         quotes to quote file and process names.
20138 +
20139 +config QUOTES_ASCII
20140 +       bool    "ASCII single quotes"
20141 +       help
20142 +         This uses the ASCII single quote character
20143 +         (\x27) to quote file and process names.
20144 +
20145 +endchoice
20146 +
20147 +endmenu
20148 +
20149 +
20150 +config VSERVER
20151 +       bool
20152 +       default y
20153 +       select NAMESPACES
20154 +       select UTS_NS
20155 +       select IPC_NS
20156 +       select USER_NS
20157 +       select SYSVIPC
20158 +
20159 +config VSERVER_SECURITY
20160 +       bool
20161 +       depends on SECURITY
20162 +       default y
20163 +       select SECURITY_CAPABILITIES
20164 +
20165 diff -NurpP --minimal linux-2.6.37/kernel/vserver/limit.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/limit.c
20166 --- linux-2.6.37/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
20167 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/limit.c  2010-11-23 02:09:41.000000000 +0100
20168 @@ -0,0 +1,354 @@
20169 +/*
20170 + *  linux/kernel/vserver/limit.c
20171 + *
20172 + *  Virtual Server: Context Limits
20173 + *
20174 + *  Copyright (C) 2004-2010  Herbert Pötzl
20175 + *
20176 + *  V0.01  broken out from vcontext V0.05
20177 + *  V0.02  changed vcmds to vxi arg
20178 + *  V0.03  added memory cgroup support
20179 + *
20180 + */
20181 +
20182 +#include <linux/sched.h>
20183 +#include <linux/module.h>
20184 +#include <linux/memcontrol.h>
20185 +#include <linux/res_counter.h>
20186 +#include <linux/vs_limit.h>
20187 +#include <linux/vserver/limit.h>
20188 +#include <linux/vserver/limit_cmd.h>
20189 +
20190 +#include <asm/uaccess.h>
20191 +
20192 +
20193 +const char *vlimit_name[NUM_LIMITS] = {
20194 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20195 +       [RLIMIT_RSS]            = "RSS",
20196 +       [RLIMIT_AS]             = "VM",
20197 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20198 +       [RLIMIT_CPU]            = "CPU",
20199 +       [RLIMIT_NPROC]          = "NPROC",
20200 +       [RLIMIT_NOFILE]         = "NOFILE",
20201 +       [RLIMIT_LOCKS]          = "LOCKS",
20202 +       [RLIMIT_SIGPENDING]     = "SIGP",
20203 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20204 +
20205 +       [VLIMIT_NSOCK]          = "NSOCK",
20206 +       [VLIMIT_OPENFD]         = "OPENFD",
20207 +       [VLIMIT_SHMEM]          = "SHMEM",
20208 +       [VLIMIT_DENTRY]         = "DENTRY",
20209 +};
20210 +
20211 +EXPORT_SYMBOL_GPL(vlimit_name);
20212 +
20213 +#define MASK_ENTRY(x)  (1 << (x))
20214 +
20215 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20216 +               /* minimum */
20217 +       0
20218 +       ,       /* softlimit */
20219 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20220 +       MASK_ENTRY( RLIMIT_RSS          ) |
20221 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20222 +       0
20223 +       ,       /* maximum */
20224 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20225 +       MASK_ENTRY( RLIMIT_RSS          ) |
20226 +       MASK_ENTRY( RLIMIT_AS           ) |
20227 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20228 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20229 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20230 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20231 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20232 +
20233 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20234 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20235 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20236 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20237 +       0
20238 +};
20239 +               /* accounting only */
20240 +uint32_t account_mask =
20241 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20242 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20243 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20244 +       0;
20245 +
20246 +
20247 +static int is_valid_vlimit(int id)
20248 +{
20249 +       uint32_t mask = vlimit_mask.minimum |
20250 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20251 +       return mask & (1 << id);
20252 +}
20253 +
20254 +static int is_accounted_vlimit(int id)
20255 +{
20256 +       if (is_valid_vlimit(id))
20257 +               return 1;
20258 +       return account_mask & (1 << id);
20259 +}
20260 +
20261 +
20262 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20263 +{
20264 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20265 +       return VX_VLIM(limit);
20266 +}
20267 +
20268 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20269 +{
20270 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20271 +       return VX_VLIM(limit);
20272 +}
20273 +
20274 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20275 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20276 +{
20277 +       if (!is_valid_vlimit(id))
20278 +               return -EINVAL;
20279 +
20280 +       if (minimum)
20281 +               *minimum = CRLIM_UNSET;
20282 +       if (softlimit)
20283 +               *softlimit = vc_get_soft(vxi, id);
20284 +       if (maximum)
20285 +               *maximum = vc_get_hard(vxi, id);
20286 +       return 0;
20287 +}
20288 +
20289 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20290 +{
20291 +       struct vcmd_ctx_rlimit_v0 vc_data;
20292 +       int ret;
20293 +
20294 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20295 +               return -EFAULT;
20296 +
20297 +       ret = do_get_rlimit(vxi, vc_data.id,
20298 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20299 +       if (ret)
20300 +               return ret;
20301 +
20302 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20303 +               return -EFAULT;
20304 +       return 0;
20305 +}
20306 +
20307 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20308 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20309 +{
20310 +       if (!is_valid_vlimit(id))
20311 +               return -EINVAL;
20312 +
20313 +       if (maximum != CRLIM_KEEP)
20314 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20315 +       if (softlimit != CRLIM_KEEP)
20316 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20317 +
20318 +       /* clamp soft limit */
20319 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20320 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20321 +
20322 +       return 0;
20323 +}
20324 +
20325 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20326 +{
20327 +       struct vcmd_ctx_rlimit_v0 vc_data;
20328 +
20329 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20330 +               return -EFAULT;
20331 +
20332 +       return do_set_rlimit(vxi, vc_data.id,
20333 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20334 +}
20335 +
20336 +#ifdef CONFIG_IA32_EMULATION
20337 +
20338 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20339 +{
20340 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20341 +
20342 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20343 +               return -EFAULT;
20344 +
20345 +       return do_set_rlimit(vxi, vc_data.id,
20346 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20347 +}
20348 +
20349 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20350 +{
20351 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20352 +       int ret;
20353 +
20354 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20355 +               return -EFAULT;
20356 +
20357 +       ret = do_get_rlimit(vxi, vc_data.id,
20358 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20359 +       if (ret)
20360 +               return ret;
20361 +
20362 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20363 +               return -EFAULT;
20364 +       return 0;
20365 +}
20366 +
20367 +#endif /* CONFIG_IA32_EMULATION */
20368 +
20369 +
20370 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20371 +{
20372 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20373 +               return -EFAULT;
20374 +       return 0;
20375 +}
20376 +
20377 +
20378 +static inline void vx_reset_hits(struct _vx_limit *limit)
20379 +{
20380 +       int lim;
20381 +
20382 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20383 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20384 +       }
20385 +}
20386 +
20387 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20388 +{
20389 +       vx_reset_hits(&vxi->limit);
20390 +       return 0;
20391 +}
20392 +
20393 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20394 +{
20395 +       rlim_t value;
20396 +       int lim;
20397 +
20398 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20399 +               value = __rlim_get(limit, lim);
20400 +               __rlim_rmax(limit, lim) = value;
20401 +               __rlim_rmin(limit, lim) = value;
20402 +       }
20403 +}
20404 +
20405 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20406 +{
20407 +       vx_reset_minmax(&vxi->limit);
20408 +       return 0;
20409 +}
20410 +
20411 +
20412 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20413 +{
20414 +       struct vcmd_rlimit_stat_v0 vc_data;
20415 +       struct _vx_limit *limit = &vxi->limit;
20416 +       int id;
20417 +
20418 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20419 +               return -EFAULT;
20420 +
20421 +       id = vc_data.id;
20422 +       if (!is_accounted_vlimit(id))
20423 +               return -EINVAL;
20424 +
20425 +       vx_limit_fixup(limit, id);
20426 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20427 +       vc_data.value = __rlim_get(limit, id);
20428 +       vc_data.minimum = __rlim_rmin(limit, id);
20429 +       vc_data.maximum = __rlim_rmax(limit, id);
20430 +
20431 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20432 +               return -EFAULT;
20433 +       return 0;
20434 +}
20435 +
20436 +
20437 +void vx_vsi_meminfo(struct sysinfo *val)
20438 +{
20439 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20440 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20441 +       u64 res_limit, res_usage;
20442 +
20443 +       if (!mcg)
20444 +               return;
20445 +
20446 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20447 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20448 +
20449 +       if (res_limit != RESOURCE_MAX)
20450 +               val->totalram = (res_limit >> PAGE_SHIFT);
20451 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20452 +       val->bufferram = 0;
20453 +       val->totalhigh = 0;
20454 +       val->freehigh = 0;
20455 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20456 +       return;
20457 +}
20458 +
20459 +void vx_vsi_swapinfo(struct sysinfo *val)
20460 +{
20461 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20462 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20463 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20464 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20465 +       s64 swap_limit, swap_usage;
20466 +
20467 +       if (!mcg)
20468 +               return;
20469 +
20470 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20471 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20472 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20473 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20474 +
20475 +       if (res_limit == RESOURCE_MAX)
20476 +               return;
20477 +
20478 +       swap_limit = memsw_limit - res_limit;
20479 +       if (memsw_limit != RESOURCE_MAX)
20480 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20481 +
20482 +       swap_usage = memsw_usage - res_usage;
20483 +       val->freeswap = (swap_usage < swap_limit) ?
20484 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20485 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20486 +       val->totalswap = 0;
20487 +       val->freeswap = 0;
20488 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20489 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20490 +       return;
20491 +}
20492 +
20493 +long vx_vsi_cached(struct sysinfo *val)
20494 +{
20495 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20496 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20497 +
20498 +       return mem_cgroup_stat_read_cache(mcg);
20499 +#else
20500 +       return 0;
20501 +#endif
20502 +}
20503 +
20504 +
20505 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20506 +{
20507 +       struct vx_info *vxi = mm->mm_vx_info;
20508 +       unsigned long points;
20509 +       rlim_t v, w;
20510 +
20511 +       if (!vxi)
20512 +               return 0;
20513 +
20514 +       points = vxi->vx_badness_bias;
20515 +
20516 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20517 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20518 +       points += (v > w) ? (v - w) : 0;
20519 +
20520 +       return points;
20521 +}
20522 +
20523 diff -NurpP --minimal linux-2.6.37/kernel/vserver/limit_init.h linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/limit_init.h
20524 --- linux-2.6.37/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
20525 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/limit_init.h     2010-11-23 02:09:41.000000000 +0100
20526 @@ -0,0 +1,31 @@
20527 +
20528 +
20529 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20530 +{
20531 +       int lim;
20532 +
20533 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20534 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20535 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20536 +               __rlim_set(limit, lim, 0);
20537 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20538 +               __rlim_rmin(limit, lim) = 0;
20539 +               __rlim_rmax(limit, lim) = 0;
20540 +       }
20541 +}
20542 +
20543 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20544 +{
20545 +       rlim_t value;
20546 +       int lim;
20547 +
20548 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20549 +               if ((1 << lim) & VLIM_NOCHECK)
20550 +                       continue;
20551 +               value = __rlim_get(limit, lim);
20552 +               vxwprintk_xid(value,
20553 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20554 +                       limit, vlimit_name[lim], lim, (long)value);
20555 +       }
20556 +}
20557 +
20558 diff -NurpP --minimal linux-2.6.37/kernel/vserver/limit_proc.h linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/limit_proc.h
20559 --- linux-2.6.37/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
20560 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/limit_proc.h     2010-11-23 02:09:41.000000000 +0100
20561 @@ -0,0 +1,57 @@
20562 +#ifndef _VX_LIMIT_PROC_H
20563 +#define _VX_LIMIT_PROC_H
20564 +
20565 +#include <linux/vserver/limit_int.h>
20566 +
20567 +
20568 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20569 +#define VX_LIMIT_TOP   \
20570 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20571 +
20572 +#define VX_LIMIT_ARG(r)                                \
20573 +       (unsigned long)__rlim_get(limit, r),    \
20574 +       (unsigned long)__rlim_rmin(limit, r),   \
20575 +       (unsigned long)__rlim_rmax(limit, r),   \
20576 +       VX_VLIM(__rlim_soft(limit, r)),         \
20577 +       VX_VLIM(__rlim_hard(limit, r)),         \
20578 +       atomic_read(&__rlim_lhit(limit, r))
20579 +
20580 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20581 +{
20582 +       vx_limit_fixup(limit, -1);
20583 +       return sprintf(buffer, VX_LIMIT_TOP
20584 +               "PROC"  VX_LIMIT_FMT
20585 +               "VM"    VX_LIMIT_FMT
20586 +               "VML"   VX_LIMIT_FMT
20587 +               "RSS"   VX_LIMIT_FMT
20588 +               "ANON"  VX_LIMIT_FMT
20589 +               "RMAP"  VX_LIMIT_FMT
20590 +               "FILES" VX_LIMIT_FMT
20591 +               "OFD"   VX_LIMIT_FMT
20592 +               "LOCKS" VX_LIMIT_FMT
20593 +               "SOCK"  VX_LIMIT_FMT
20594 +               "MSGQ"  VX_LIMIT_FMT
20595 +               "SHM"   VX_LIMIT_FMT
20596 +               "SEMA"  VX_LIMIT_FMT
20597 +               "SEMS"  VX_LIMIT_FMT
20598 +               "DENT"  VX_LIMIT_FMT,
20599 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20600 +               VX_LIMIT_ARG(RLIMIT_AS),
20601 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20602 +               VX_LIMIT_ARG(RLIMIT_RSS),
20603 +               VX_LIMIT_ARG(VLIMIT_ANON),
20604 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20605 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20606 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20607 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20608 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20609 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20610 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20611 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20612 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20613 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20614 +}
20615 +
20616 +#endif /* _VX_LIMIT_PROC_H */
20617 +
20618 +
20619 diff -NurpP --minimal linux-2.6.37/kernel/vserver/Makefile linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/Makefile
20620 --- linux-2.6.37/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
20621 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/Makefile 2010-11-23 02:09:41.000000000 +0100
20622 @@ -0,0 +1,18 @@
20623 +#
20624 +# Makefile for the Linux vserver routines.
20625 +#
20626 +
20627 +
20628 +obj-y          += vserver.o
20629 +
20630 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
20631 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
20632 +                  dlimit.o tag.o
20633 +
20634 +vserver-$(CONFIG_INET) += inet.o
20635 +vserver-$(CONFIG_PROC_FS) += proc.o
20636 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
20637 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
20638 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
20639 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
20640 +
20641 diff -NurpP --minimal linux-2.6.37/kernel/vserver/network.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/network.c
20642 --- linux-2.6.37/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
20643 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/network.c        2010-11-23 02:09:41.000000000 +0100
20644 @@ -0,0 +1,864 @@
20645 +/*
20646 + *  linux/kernel/vserver/network.c
20647 + *
20648 + *  Virtual Server: Network Support
20649 + *
20650 + *  Copyright (C) 2003-2007  Herbert Pötzl
20651 + *
20652 + *  V0.01  broken out from vcontext V0.05
20653 + *  V0.02  cleaned up implementation
20654 + *  V0.03  added equiv nx commands
20655 + *  V0.04  switch to RCU based hash
20656 + *  V0.05  and back to locking again
20657 + *  V0.06  changed vcmds to nxi arg
20658 + *  V0.07  have __create claim() the nxi
20659 + *
20660 + */
20661 +
20662 +#include <linux/err.h>
20663 +#include <linux/slab.h>
20664 +#include <linux/rcupdate.h>
20665 +
20666 +#include <linux/vs_network.h>
20667 +#include <linux/vs_pid.h>
20668 +#include <linux/vserver/network_cmd.h>
20669 +
20670 +
20671 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20672 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20673 +
20674 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20675 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20676 +
20677 +
20678 +static int __init init_network(void)
20679 +{
20680 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20681 +               sizeof(struct nx_addr_v4), 0,
20682 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20683 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20684 +               sizeof(struct nx_addr_v6), 0,
20685 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20686 +       return 0;
20687 +}
20688 +
20689 +
20690 +/*     __alloc_nx_addr_v4()                                    */
20691 +
20692 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20693 +{
20694 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20695 +               nx_addr_v4_cachep, GFP_KERNEL);
20696 +
20697 +       if (!IS_ERR(nxa))
20698 +               memset(nxa, 0, sizeof(*nxa));
20699 +       return nxa;
20700 +}
20701 +
20702 +/*     __dealloc_nx_addr_v4()                                  */
20703 +
20704 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20705 +{
20706 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20707 +}
20708 +
20709 +/*     __dealloc_nx_addr_v4_all()                              */
20710 +
20711 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20712 +{
20713 +       while (nxa) {
20714 +               struct nx_addr_v4 *next = nxa->next;
20715 +
20716 +               __dealloc_nx_addr_v4(nxa);
20717 +               nxa = next;
20718 +       }
20719 +}
20720 +
20721 +
20722 +#ifdef CONFIG_IPV6
20723 +
20724 +/*     __alloc_nx_addr_v6()                                    */
20725 +
20726 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20727 +{
20728 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20729 +               nx_addr_v6_cachep, GFP_KERNEL);
20730 +
20731 +       if (!IS_ERR(nxa))
20732 +               memset(nxa, 0, sizeof(*nxa));
20733 +       return nxa;
20734 +}
20735 +
20736 +/*     __dealloc_nx_addr_v6()                                  */
20737 +
20738 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20739 +{
20740 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20741 +}
20742 +
20743 +/*     __dealloc_nx_addr_v6_all()                              */
20744 +
20745 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20746 +{
20747 +       while (nxa) {
20748 +               struct nx_addr_v6 *next = nxa->next;
20749 +
20750 +               __dealloc_nx_addr_v6(nxa);
20751 +               nxa = next;
20752 +       }
20753 +}
20754 +
20755 +#endif /* CONFIG_IPV6 */
20756 +
20757 +/*     __alloc_nx_info()
20758 +
20759 +       * allocate an initialized nx_info struct
20760 +       * doesn't make it visible (hash)                        */
20761 +
20762 +static struct nx_info *__alloc_nx_info(nid_t nid)
20763 +{
20764 +       struct nx_info *new = NULL;
20765 +
20766 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20767 +
20768 +       /* would this benefit from a slab cache? */
20769 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20770 +       if (!new)
20771 +               return 0;
20772 +
20773 +       memset(new, 0, sizeof(struct nx_info));
20774 +       new->nx_id = nid;
20775 +       INIT_HLIST_NODE(&new->nx_hlist);
20776 +       atomic_set(&new->nx_usecnt, 0);
20777 +       atomic_set(&new->nx_tasks, 0);
20778 +       new->nx_state = 0;
20779 +
20780 +       new->nx_flags = NXF_INIT_SET;
20781 +
20782 +       /* rest of init goes here */
20783 +
20784 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20785 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20786 +
20787 +       vxdprintk(VXD_CBIT(nid, 0),
20788 +               "alloc_nx_info(%d) = %p", nid, new);
20789 +       atomic_inc(&nx_global_ctotal);
20790 +       return new;
20791 +}
20792 +
20793 +/*     __dealloc_nx_info()
20794 +
20795 +       * final disposal of nx_info                             */
20796 +
20797 +static void __dealloc_nx_info(struct nx_info *nxi)
20798 +{
20799 +       vxdprintk(VXD_CBIT(nid, 0),
20800 +               "dealloc_nx_info(%p)", nxi);
20801 +
20802 +       nxi->nx_hlist.next = LIST_POISON1;
20803 +       nxi->nx_id = -1;
20804 +
20805 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20806 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20807 +
20808 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20809 +
20810 +       nxi->nx_state |= NXS_RELEASED;
20811 +       kfree(nxi);
20812 +       atomic_dec(&nx_global_ctotal);
20813 +}
20814 +
20815 +static void __shutdown_nx_info(struct nx_info *nxi)
20816 +{
20817 +       nxi->nx_state |= NXS_SHUTDOWN;
20818 +       vs_net_change(nxi, VSC_NETDOWN);
20819 +}
20820 +
20821 +/*     exported stuff                                          */
20822 +
20823 +void free_nx_info(struct nx_info *nxi)
20824 +{
20825 +       /* context shutdown is mandatory */
20826 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20827 +
20828 +       /* context must not be hashed */
20829 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20830 +
20831 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20832 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20833 +
20834 +       __dealloc_nx_info(nxi);
20835 +}
20836 +
20837 +
20838 +void __nx_set_lback(struct nx_info *nxi)
20839 +{
20840 +       int nid = nxi->nx_id;
20841 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20842 +
20843 +       nxi->v4_lback.s_addr = lback;
20844 +}
20845 +
20846 +extern int __nx_inet_add_lback(__be32 addr);
20847 +extern int __nx_inet_del_lback(__be32 addr);
20848 +
20849 +
20850 +/*     hash table for nx_info hash */
20851 +
20852 +#define NX_HASH_SIZE   13
20853 +
20854 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20855 +
20856 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
20857 +
20858 +
20859 +static inline unsigned int __hashval(nid_t nid)
20860 +{
20861 +       return (nid % NX_HASH_SIZE);
20862 +}
20863 +
20864 +
20865 +
20866 +/*     __hash_nx_info()
20867 +
20868 +       * add the nxi to the global hash table
20869 +       * requires the hash_lock to be held                     */
20870 +
20871 +static inline void __hash_nx_info(struct nx_info *nxi)
20872 +{
20873 +       struct hlist_head *head;
20874 +
20875 +       vxd_assert_lock(&nx_info_hash_lock);
20876 +       vxdprintk(VXD_CBIT(nid, 4),
20877 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20878 +
20879 +       /* context must not be hashed */
20880 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20881 +
20882 +       nxi->nx_state |= NXS_HASHED;
20883 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20884 +       hlist_add_head(&nxi->nx_hlist, head);
20885 +       atomic_inc(&nx_global_cactive);
20886 +}
20887 +
20888 +/*     __unhash_nx_info()
20889 +
20890 +       * remove the nxi from the global hash table
20891 +       * requires the hash_lock to be held                     */
20892 +
20893 +static inline void __unhash_nx_info(struct nx_info *nxi)
20894 +{
20895 +       vxd_assert_lock(&nx_info_hash_lock);
20896 +       vxdprintk(VXD_CBIT(nid, 4),
20897 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20898 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20899 +
20900 +       /* context must be hashed */
20901 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20902 +       /* but without tasks */
20903 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20904 +
20905 +       nxi->nx_state &= ~NXS_HASHED;
20906 +       hlist_del(&nxi->nx_hlist);
20907 +       atomic_dec(&nx_global_cactive);
20908 +}
20909 +
20910 +
20911 +/*     __lookup_nx_info()
20912 +
20913 +       * requires the hash_lock to be held
20914 +       * doesn't increment the nx_refcnt                       */
20915 +
20916 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20917 +{
20918 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20919 +       struct hlist_node *pos;
20920 +       struct nx_info *nxi;
20921 +
20922 +       vxd_assert_lock(&nx_info_hash_lock);
20923 +       hlist_for_each(pos, head) {
20924 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20925 +
20926 +               if (nxi->nx_id == nid)
20927 +                       goto found;
20928 +       }
20929 +       nxi = NULL;
20930 +found:
20931 +       vxdprintk(VXD_CBIT(nid, 0),
20932 +               "__lookup_nx_info(#%u): %p[#%u]",
20933 +               nid, nxi, nxi ? nxi->nx_id : 0);
20934 +       return nxi;
20935 +}
20936 +
20937 +
20938 +/*     __create_nx_info()
20939 +
20940 +       * create the requested context
20941 +       * get(), claim() and hash it                            */
20942 +
20943 +static struct nx_info *__create_nx_info(int id)
20944 +{
20945 +       struct nx_info *new, *nxi = NULL;
20946 +
20947 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20948 +
20949 +       if (!(new = __alloc_nx_info(id)))
20950 +               return ERR_PTR(-ENOMEM);
20951 +
20952 +       /* required to make dynamic xids unique */
20953 +       spin_lock(&nx_info_hash_lock);
20954 +
20955 +       /* static context requested */
20956 +       if ((nxi = __lookup_nx_info(id))) {
20957 +               vxdprintk(VXD_CBIT(nid, 0),
20958 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20959 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20960 +                       nxi = ERR_PTR(-EBUSY);
20961 +               else
20962 +                       nxi = ERR_PTR(-EEXIST);
20963 +               goto out_unlock;
20964 +       }
20965 +       /* new context */
20966 +       vxdprintk(VXD_CBIT(nid, 0),
20967 +               "create_nx_info(%d) = %p (new)", id, new);
20968 +       claim_nx_info(new, NULL);
20969 +       __nx_set_lback(new);
20970 +       __hash_nx_info(get_nx_info(new));
20971 +       nxi = new, new = NULL;
20972 +
20973 +out_unlock:
20974 +       spin_unlock(&nx_info_hash_lock);
20975 +       if (new)
20976 +               __dealloc_nx_info(new);
20977 +       return nxi;
20978 +}
20979 +
20980 +
20981 +
20982 +/*     exported stuff                                          */
20983 +
20984 +
20985 +void unhash_nx_info(struct nx_info *nxi)
20986 +{
20987 +       __shutdown_nx_info(nxi);
20988 +       spin_lock(&nx_info_hash_lock);
20989 +       __unhash_nx_info(nxi);
20990 +       spin_unlock(&nx_info_hash_lock);
20991 +}
20992 +
20993 +/*     lookup_nx_info()
20994 +
20995 +       * search for a nx_info and get() it
20996 +       * negative id means current                             */
20997 +
20998 +struct nx_info *lookup_nx_info(int id)
20999 +{
21000 +       struct nx_info *nxi = NULL;
21001 +
21002 +       if (id < 0) {
21003 +               nxi = get_nx_info(current_nx_info());
21004 +       } else if (id > 1) {
21005 +               spin_lock(&nx_info_hash_lock);
21006 +               nxi = get_nx_info(__lookup_nx_info(id));
21007 +               spin_unlock(&nx_info_hash_lock);
21008 +       }
21009 +       return nxi;
21010 +}
21011 +
21012 +/*     nid_is_hashed()
21013 +
21014 +       * verify that nid is still hashed                       */
21015 +
21016 +int nid_is_hashed(nid_t nid)
21017 +{
21018 +       int hashed;
21019 +
21020 +       spin_lock(&nx_info_hash_lock);
21021 +       hashed = (__lookup_nx_info(nid) != NULL);
21022 +       spin_unlock(&nx_info_hash_lock);
21023 +       return hashed;
21024 +}
21025 +
21026 +
21027 +#ifdef CONFIG_PROC_FS
21028 +
21029 +/*     get_nid_list()
21030 +
21031 +       * get a subset of hashed nids for proc
21032 +       * assumes size is at least one                          */
21033 +
21034 +int get_nid_list(int index, unsigned int *nids, int size)
21035 +{
21036 +       int hindex, nr_nids = 0;
21037 +
21038 +       /* only show current and children */
21039 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
21040 +               if (index > 0)
21041 +                       return 0;
21042 +               nids[nr_nids] = nx_current_nid();
21043 +               return 1;
21044 +       }
21045 +
21046 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
21047 +               struct hlist_head *head = &nx_info_hash[hindex];
21048 +               struct hlist_node *pos;
21049 +
21050 +               spin_lock(&nx_info_hash_lock);
21051 +               hlist_for_each(pos, head) {
21052 +                       struct nx_info *nxi;
21053 +
21054 +                       if (--index > 0)
21055 +                               continue;
21056 +
21057 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21058 +                       nids[nr_nids] = nxi->nx_id;
21059 +                       if (++nr_nids >= size) {
21060 +                               spin_unlock(&nx_info_hash_lock);
21061 +                               goto out;
21062 +                       }
21063 +               }
21064 +               /* keep the lock time short */
21065 +               spin_unlock(&nx_info_hash_lock);
21066 +       }
21067 +out:
21068 +       return nr_nids;
21069 +}
21070 +#endif
21071 +
21072 +
21073 +/*
21074 + *     migrate task to new network
21075 + *     gets nxi, puts old_nxi on change
21076 + */
21077 +
21078 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
21079 +{
21080 +       struct nx_info *old_nxi;
21081 +       int ret = 0;
21082 +
21083 +       if (!p || !nxi)
21084 +               BUG();
21085 +
21086 +       vxdprintk(VXD_CBIT(nid, 5),
21087 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21088 +               p, nxi, nxi->nx_id,
21089 +               atomic_read(&nxi->nx_usecnt),
21090 +               atomic_read(&nxi->nx_tasks));
21091 +
21092 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21093 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21094 +               return -EACCES;
21095 +
21096 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21097 +               return -EFAULT;
21098 +
21099 +       /* maybe disallow this completely? */
21100 +       old_nxi = task_get_nx_info(p);
21101 +       if (old_nxi == nxi)
21102 +               goto out;
21103 +
21104 +       task_lock(p);
21105 +       if (old_nxi)
21106 +               clr_nx_info(&p->nx_info);
21107 +       claim_nx_info(nxi, p);
21108 +       set_nx_info(&p->nx_info, nxi);
21109 +       p->nid = nxi->nx_id;
21110 +       task_unlock(p);
21111 +
21112 +       vxdprintk(VXD_CBIT(nid, 5),
21113 +               "moved task %p into nxi:%p[#%d]",
21114 +               p, nxi, nxi->nx_id);
21115 +
21116 +       if (old_nxi)
21117 +               release_nx_info(old_nxi, p);
21118 +       ret = 0;
21119 +out:
21120 +       put_nx_info(old_nxi);
21121 +       return ret;
21122 +}
21123 +
21124 +
21125 +void nx_set_persistent(struct nx_info *nxi)
21126 +{
21127 +       vxdprintk(VXD_CBIT(nid, 6),
21128 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21129 +
21130 +       get_nx_info(nxi);
21131 +       claim_nx_info(nxi, NULL);
21132 +}
21133 +
21134 +void nx_clear_persistent(struct nx_info *nxi)
21135 +{
21136 +       vxdprintk(VXD_CBIT(nid, 6),
21137 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21138 +
21139 +       release_nx_info(nxi, NULL);
21140 +       put_nx_info(nxi);
21141 +}
21142 +
21143 +void nx_update_persistent(struct nx_info *nxi)
21144 +{
21145 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21146 +               nx_set_persistent(nxi);
21147 +       else
21148 +               nx_clear_persistent(nxi);
21149 +}
21150 +
21151 +/* vserver syscall commands below here */
21152 +
21153 +/* taks nid and nx_info functions */
21154 +
21155 +#include <asm/uaccess.h>
21156 +
21157 +
21158 +int vc_task_nid(uint32_t id)
21159 +{
21160 +       nid_t nid;
21161 +
21162 +       if (id) {
21163 +               struct task_struct *tsk;
21164 +
21165 +               read_lock(&tasklist_lock);
21166 +               tsk = find_task_by_real_pid(id);
21167 +               nid = (tsk) ? tsk->nid : -ESRCH;
21168 +               read_unlock(&tasklist_lock);
21169 +       } else
21170 +               nid = nx_current_nid();
21171 +       return nid;
21172 +}
21173 +
21174 +
21175 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21176 +{
21177 +       struct vcmd_nx_info_v0 vc_data;
21178 +
21179 +       vc_data.nid = nxi->nx_id;
21180 +
21181 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21182 +               return -EFAULT;
21183 +       return 0;
21184 +}
21185 +
21186 +
21187 +/* network functions */
21188 +
21189 +int vc_net_create(uint32_t nid, void __user *data)
21190 +{
21191 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21192 +       struct nx_info *new_nxi;
21193 +       int ret;
21194 +
21195 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21196 +               return -EFAULT;
21197 +
21198 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21199 +               return -EINVAL;
21200 +
21201 +       new_nxi = __create_nx_info(nid);
21202 +       if (IS_ERR(new_nxi))
21203 +               return PTR_ERR(new_nxi);
21204 +
21205 +       /* initial flags */
21206 +       new_nxi->nx_flags = vc_data.flagword;
21207 +
21208 +       ret = -ENOEXEC;
21209 +       if (vs_net_change(new_nxi, VSC_NETUP))
21210 +               goto out;
21211 +
21212 +       ret = nx_migrate_task(current, new_nxi);
21213 +       if (ret)
21214 +               goto out;
21215 +
21216 +       /* return context id on success */
21217 +       ret = new_nxi->nx_id;
21218 +
21219 +       /* get a reference for persistent contexts */
21220 +       if ((vc_data.flagword & NXF_PERSISTENT))
21221 +               nx_set_persistent(new_nxi);
21222 +out:
21223 +       release_nx_info(new_nxi, NULL);
21224 +       put_nx_info(new_nxi);
21225 +       return ret;
21226 +}
21227 +
21228 +
21229 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21230 +{
21231 +       return nx_migrate_task(current, nxi);
21232 +}
21233 +
21234 +
21235 +
21236 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21237 +       uint16_t type, uint16_t flags)
21238 +{
21239 +       struct nx_addr_v4 *nxa = &nxi->v4;
21240 +
21241 +       if (NX_IPV4(nxi)) {
21242 +               /* locate last entry */
21243 +               for (; nxa->next; nxa = nxa->next);
21244 +               nxa->next = __alloc_nx_addr_v4();
21245 +               nxa = nxa->next;
21246 +
21247 +               if (IS_ERR(nxa))
21248 +                       return PTR_ERR(nxa);
21249 +       }
21250 +
21251 +       if (nxi->v4.next)
21252 +               /* remove single ip for ip list */
21253 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21254 +
21255 +       nxa->ip[0].s_addr = ip;
21256 +       nxa->ip[1].s_addr = ip2;
21257 +       nxa->mask.s_addr = mask;
21258 +       nxa->type = type;
21259 +       nxa->flags = flags;
21260 +       return 0;
21261 +}
21262 +
21263 +
21264 +int vc_net_add(struct nx_info *nxi, void __user *data)
21265 +{
21266 +       struct vcmd_net_addr_v0 vc_data;
21267 +       int index, ret = 0;
21268 +
21269 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21270 +               return -EFAULT;
21271 +
21272 +       switch (vc_data.type) {
21273 +       case NXA_TYPE_IPV4:
21274 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21275 +                       return -EINVAL;
21276 +
21277 +               index = 0;
21278 +               while (index < vc_data.count) {
21279 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21280 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21281 +                       if (ret)
21282 +                               return ret;
21283 +                       index++;
21284 +               }
21285 +               ret = index;
21286 +               break;
21287 +
21288 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21289 +               nxi->v4_bcast = vc_data.ip[0];
21290 +               ret = 1;
21291 +               break;
21292 +
21293 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21294 +               nxi->v4_lback = vc_data.ip[0];
21295 +               ret = 1;
21296 +               break;
21297 +
21298 +       default:
21299 +               ret = -EINVAL;
21300 +               break;
21301 +       }
21302 +       return ret;
21303 +}
21304 +
21305 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21306 +{
21307 +       struct vcmd_net_addr_v0 vc_data;
21308 +
21309 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21310 +               return -EFAULT;
21311 +
21312 +       switch (vc_data.type) {
21313 +       case NXA_TYPE_ANY:
21314 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21315 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21316 +               break;
21317 +
21318 +       default:
21319 +               return -EINVAL;
21320 +       }
21321 +       return 0;
21322 +}
21323 +
21324 +
21325 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21326 +{
21327 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21328 +
21329 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21330 +               return -EFAULT;
21331 +
21332 +       switch (vc_data.type) {
21333 +       case NXA_TYPE_ADDR:
21334 +       case NXA_TYPE_RANGE:
21335 +       case NXA_TYPE_MASK:
21336 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21337 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21338 +
21339 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21340 +               nxi->v4_bcast = vc_data.ip;
21341 +               break;
21342 +
21343 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21344 +               nxi->v4_lback = vc_data.ip;
21345 +               break;
21346 +
21347 +       default:
21348 +               return -EINVAL;
21349 +       }
21350 +       return 0;
21351 +}
21352 +
21353 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
21354 +{
21355 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21356 +
21357 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21358 +               return -EFAULT;
21359 +
21360 +       switch (vc_data.type) {
21361 +/*     case NXA_TYPE_ADDR:
21362 +               break;          */
21363 +
21364 +       case NXA_TYPE_ANY:
21365 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21366 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21367 +               break;
21368 +
21369 +       default:
21370 +               return -EINVAL;
21371 +       }
21372 +       return 0;
21373 +}
21374 +
21375 +
21376 +#ifdef CONFIG_IPV6
21377 +
21378 +int do_add_v6_addr(struct nx_info *nxi,
21379 +       struct in6_addr *ip, struct in6_addr *mask,
21380 +       uint32_t prefix, uint16_t type, uint16_t flags)
21381 +{
21382 +       struct nx_addr_v6 *nxa = &nxi->v6;
21383 +
21384 +       if (NX_IPV6(nxi)) {
21385 +               /* locate last entry */
21386 +               for (; nxa->next; nxa = nxa->next);
21387 +               nxa->next = __alloc_nx_addr_v6();
21388 +               nxa = nxa->next;
21389 +
21390 +               if (IS_ERR(nxa))
21391 +                       return PTR_ERR(nxa);
21392 +       }
21393 +
21394 +       nxa->ip = *ip;
21395 +       nxa->mask = *mask;
21396 +       nxa->prefix = prefix;
21397 +       nxa->type = type;
21398 +       nxa->flags = flags;
21399 +       return 0;
21400 +}
21401 +
21402 +
21403 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21404 +{
21405 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21406 +
21407 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21408 +               return -EFAULT;
21409 +
21410 +       switch (vc_data.type) {
21411 +       case NXA_TYPE_ADDR:
21412 +       case NXA_TYPE_MASK:
21413 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21414 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21415 +       default:
21416 +               return -EINVAL;
21417 +       }
21418 +       return 0;
21419 +}
21420 +
21421 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21422 +{
21423 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21424 +
21425 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21426 +               return -EFAULT;
21427 +
21428 +       switch (vc_data.type) {
21429 +       case NXA_TYPE_ANY:
21430 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21431 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21432 +               break;
21433 +
21434 +       default:
21435 +               return -EINVAL;
21436 +       }
21437 +       return 0;
21438 +}
21439 +
21440 +#endif /* CONFIG_IPV6 */
21441 +
21442 +
21443 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21444 +{
21445 +       struct vcmd_net_flags_v0 vc_data;
21446 +
21447 +       vc_data.flagword = nxi->nx_flags;
21448 +
21449 +       /* special STATE flag handling */
21450 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21451 +
21452 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21453 +               return -EFAULT;
21454 +       return 0;
21455 +}
21456 +
21457 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21458 +{
21459 +       struct vcmd_net_flags_v0 vc_data;
21460 +       uint64_t mask, trigger;
21461 +
21462 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21463 +               return -EFAULT;
21464 +
21465 +       /* special STATE flag handling */
21466 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21467 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21468 +
21469 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21470 +               vc_data.flagword, mask);
21471 +       if (trigger & NXF_PERSISTENT)
21472 +               nx_update_persistent(nxi);
21473 +
21474 +       return 0;
21475 +}
21476 +
21477 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21478 +{
21479 +       struct vcmd_net_caps_v0 vc_data;
21480 +
21481 +       vc_data.ncaps = nxi->nx_ncaps;
21482 +       vc_data.cmask = ~0ULL;
21483 +
21484 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21485 +               return -EFAULT;
21486 +       return 0;
21487 +}
21488 +
21489 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21490 +{
21491 +       struct vcmd_net_caps_v0 vc_data;
21492 +
21493 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21494 +               return -EFAULT;
21495 +
21496 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21497 +               vc_data.ncaps, vc_data.cmask);
21498 +       return 0;
21499 +}
21500 +
21501 +
21502 +#include <linux/module.h>
21503 +
21504 +module_init(init_network);
21505 +
21506 +EXPORT_SYMBOL_GPL(free_nx_info);
21507 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21508 +
21509 diff -NurpP --minimal linux-2.6.37/kernel/vserver/proc.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/proc.c
21510 --- linux-2.6.37/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
21511 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/proc.c   2011-01-08 03:33:34.000000000 +0100
21512 @@ -0,0 +1,1098 @@
21513 +/*
21514 + *  linux/kernel/vserver/proc.c
21515 + *
21516 + *  Virtual Context Support
21517 + *
21518 + *  Copyright (C) 2003-2007  Herbert Pötzl
21519 + *
21520 + *  V0.01  basic structure
21521 + *  V0.02  adaptation vs1.3.0
21522 + *  V0.03  proc permissions
21523 + *  V0.04  locking/generic
21524 + *  V0.05  next generation procfs
21525 + *  V0.06  inode validation
21526 + *  V0.07  generic rewrite vid
21527 + *  V0.08  remove inode type
21528 + *
21529 + */
21530 +
21531 +#include <linux/proc_fs.h>
21532 +#include <linux/fs_struct.h>
21533 +#include <linux/mount.h>
21534 +#include <asm/unistd.h>
21535 +
21536 +#include <linux/vs_context.h>
21537 +#include <linux/vs_network.h>
21538 +#include <linux/vs_cvirt.h>
21539 +
21540 +#include <linux/in.h>
21541 +#include <linux/inetdevice.h>
21542 +#include <linux/vs_inet.h>
21543 +#include <linux/vs_inet6.h>
21544 +
21545 +#include <linux/vserver/global.h>
21546 +
21547 +#include "cvirt_proc.h"
21548 +#include "cacct_proc.h"
21549 +#include "limit_proc.h"
21550 +#include "sched_proc.h"
21551 +#include "vci_config.h"
21552 +
21553 +
21554 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21555 +{
21556 +       unsigned __capi;
21557 +
21558 +       CAP_FOR_EACH_U32(__capi) {
21559 +               buffer += sprintf(buffer, "%08x",
21560 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21561 +       }
21562 +       return buffer;
21563 +}
21564 +
21565 +
21566 +static struct proc_dir_entry *proc_virtual;
21567 +
21568 +static struct proc_dir_entry *proc_virtnet;
21569 +
21570 +
21571 +/* first the actual feeds */
21572 +
21573 +
21574 +static int proc_vci(char *buffer)
21575 +{
21576 +       return sprintf(buffer,
21577 +               "VCIVersion:\t%04x:%04x\n"
21578 +               "VCISyscall:\t%d\n"
21579 +               "VCIKernel:\t%08x\n",
21580 +               VCI_VERSION >> 16,
21581 +               VCI_VERSION & 0xFFFF,
21582 +               __NR_vserver,
21583 +               vci_kernel_config());
21584 +}
21585 +
21586 +static int proc_virtual_info(char *buffer)
21587 +{
21588 +       return proc_vci(buffer);
21589 +}
21590 +
21591 +static int proc_virtual_status(char *buffer)
21592 +{
21593 +       return sprintf(buffer,
21594 +               "#CTotal:\t%d\n"
21595 +               "#CActive:\t%d\n"
21596 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21597 +               "#InitTask:\t%d\t%d %d\n",
21598 +               atomic_read(&vx_global_ctotal),
21599 +               atomic_read(&vx_global_cactive),
21600 +               atomic_read(&vs_global_nsproxy),
21601 +               atomic_read(&vs_global_fs),
21602 +               atomic_read(&vs_global_mnt_ns),
21603 +               atomic_read(&vs_global_uts_ns),
21604 +               atomic_read(&nr_ipc_ns),
21605 +               atomic_read(&vs_global_user_ns),
21606 +               atomic_read(&vs_global_pid_ns),
21607 +               atomic_read(&init_task.usage),
21608 +               atomic_read(&init_task.nsproxy->count),
21609 +               init_task.fs->users);
21610 +}
21611 +
21612 +
21613 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21614 +{
21615 +       int length;
21616 +
21617 +       length = sprintf(buffer,
21618 +               "ID:\t%d\n"
21619 +               "Info:\t%p\n"
21620 +               "Init:\t%d\n"
21621 +               "OOM:\t%lld\n",
21622 +               vxi->vx_id,
21623 +               vxi,
21624 +               vxi->vx_initpid,
21625 +               vxi->vx_badness_bias);
21626 +       return length;
21627 +}
21628 +
21629 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21630 +{
21631 +       char *orig = buffer;
21632 +
21633 +       buffer += sprintf(buffer,
21634 +               "UseCnt:\t%d\n"
21635 +               "Tasks:\t%d\n"
21636 +               "Flags:\t%016llx\n",
21637 +               atomic_read(&vxi->vx_usecnt),
21638 +               atomic_read(&vxi->vx_tasks),
21639 +               (unsigned long long)vxi->vx_flags);
21640 +
21641 +       buffer += sprintf(buffer, "BCaps:\t");
21642 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21643 +       buffer += sprintf(buffer, "\n");
21644 +
21645 +       buffer += sprintf(buffer,
21646 +               "CCaps:\t%016llx\n"
21647 +               "Spaces:\t%08lx %08lx\n",
21648 +               (unsigned long long)vxi->vx_ccaps,
21649 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21650 +       return buffer - orig;
21651 +}
21652 +
21653 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21654 +{
21655 +       return vx_info_proc_limit(&vxi->limit, buffer);
21656 +}
21657 +
21658 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21659 +{
21660 +       int cpu, length;
21661 +
21662 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21663 +       for_each_online_cpu(cpu) {
21664 +               length += vx_info_proc_sched_pc(
21665 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21666 +                       buffer + length, cpu);
21667 +       }
21668 +       return length;
21669 +}
21670 +
21671 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21672 +{
21673 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21674 +}
21675 +
21676 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21677 +{
21678 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21679 +}
21680 +
21681 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21682 +{
21683 +       int cpu, length;
21684 +
21685 +       vx_update_load(vxi);
21686 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21687 +       for_each_online_cpu(cpu) {
21688 +               length += vx_info_proc_cvirt_pc(
21689 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21690 +                       buffer + length, cpu);
21691 +       }
21692 +       return length;
21693 +}
21694 +
21695 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21696 +{
21697 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21698 +}
21699 +
21700 +
21701 +static int proc_virtnet_info(char *buffer)
21702 +{
21703 +       return proc_vci(buffer);
21704 +}
21705 +
21706 +static int proc_virtnet_status(char *buffer)
21707 +{
21708 +       return sprintf(buffer,
21709 +               "#CTotal:\t%d\n"
21710 +               "#CActive:\t%d\n",
21711 +               atomic_read(&nx_global_ctotal),
21712 +               atomic_read(&nx_global_cactive));
21713 +}
21714 +
21715 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21716 +{
21717 +       struct nx_addr_v4 *v4a;
21718 +#ifdef CONFIG_IPV6
21719 +       struct nx_addr_v6 *v6a;
21720 +#endif
21721 +       int length, i;
21722 +
21723 +       length = sprintf(buffer,
21724 +               "ID:\t%d\n"
21725 +               "Info:\t%p\n"
21726 +               "Bcast:\t" NIPQUAD_FMT "\n"
21727 +               "Lback:\t" NIPQUAD_FMT "\n",
21728 +               nxi->nx_id,
21729 +               nxi,
21730 +               NIPQUAD(nxi->v4_bcast.s_addr),
21731 +               NIPQUAD(nxi->v4_lback.s_addr));
21732 +
21733 +       if (!NX_IPV4(nxi))
21734 +               goto skip_v4;
21735 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21736 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21737 +                       i, NXAV4(v4a));
21738 +skip_v4:
21739 +#ifdef CONFIG_IPV6
21740 +       if (!NX_IPV6(nxi))
21741 +               goto skip_v6;
21742 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21743 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21744 +                       i, NXAV6(v6a));
21745 +skip_v6:
21746 +#endif
21747 +       return length;
21748 +}
21749 +
21750 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21751 +{
21752 +       int length;
21753 +
21754 +       length = sprintf(buffer,
21755 +               "UseCnt:\t%d\n"
21756 +               "Tasks:\t%d\n"
21757 +               "Flags:\t%016llx\n"
21758 +               "NCaps:\t%016llx\n",
21759 +               atomic_read(&nxi->nx_usecnt),
21760 +               atomic_read(&nxi->nx_tasks),
21761 +               (unsigned long long)nxi->nx_flags,
21762 +               (unsigned long long)nxi->nx_ncaps);
21763 +       return length;
21764 +}
21765 +
21766 +
21767 +
21768 +/* here the inode helpers */
21769 +
21770 +struct vs_entry {
21771 +       int len;
21772 +       char *name;
21773 +       mode_t mode;
21774 +       struct inode_operations *iop;
21775 +       struct file_operations *fop;
21776 +       union proc_op op;
21777 +};
21778 +
21779 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21780 +{
21781 +       struct inode *inode = new_inode(sb);
21782 +
21783 +       if (!inode)
21784 +               goto out;
21785 +
21786 +       inode->i_mode = p->mode;
21787 +       if (p->iop)
21788 +               inode->i_op = p->iop;
21789 +       if (p->fop)
21790 +               inode->i_fop = p->fop;
21791 +
21792 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21793 +       inode->i_flags |= S_IMMUTABLE;
21794 +
21795 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21796 +
21797 +       inode->i_uid = 0;
21798 +       inode->i_gid = 0;
21799 +       inode->i_tag = 0;
21800 +out:
21801 +       return inode;
21802 +}
21803 +
21804 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21805 +       struct dentry *dentry, int id, void *ptr)
21806 +{
21807 +       struct vs_entry *p = ptr;
21808 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21809 +       struct dentry *error = ERR_PTR(-EINVAL);
21810 +
21811 +       if (!inode)
21812 +               goto out;
21813 +
21814 +       PROC_I(inode)->op = p->op;
21815 +       PROC_I(inode)->fd = id;
21816 +       d_add(dentry, inode);
21817 +       error = NULL;
21818 +out:
21819 +       return error;
21820 +}
21821 +
21822 +/* Lookups */
21823 +
21824 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21825 +
21826 +/*
21827 + * Fill a directory entry.
21828 + *
21829 + * If possible create the dcache entry and derive our inode number and
21830 + * file type from dcache entry.
21831 + *
21832 + * Since all of the proc inode numbers are dynamically generated, the inode
21833 + * numbers do not exist until the inode is cache.  This means creating the
21834 + * the dcache entry in readdir is necessary to keep the inode numbers
21835 + * reported by readdir in sync with the inode numbers reported
21836 + * by stat.
21837 + */
21838 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21839 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21840 +{
21841 +       struct dentry *child, *dir = filp->f_dentry;
21842 +       struct inode *inode;
21843 +       struct qstr qname;
21844 +       ino_t ino = 0;
21845 +       unsigned type = DT_UNKNOWN;
21846 +
21847 +       qname.name = name;
21848 +       qname.len  = len;
21849 +       qname.hash = full_name_hash(name, len);
21850 +
21851 +       child = d_lookup(dir, &qname);
21852 +       if (!child) {
21853 +               struct dentry *new;
21854 +               new = d_alloc(dir, &qname);
21855 +               if (new) {
21856 +                       child = instantiate(dir->d_inode, new, id, ptr);
21857 +                       if (child)
21858 +                               dput(new);
21859 +                       else
21860 +                               child = new;
21861 +               }
21862 +       }
21863 +       if (!child || IS_ERR(child) || !child->d_inode)
21864 +               goto end_instantiate;
21865 +       inode = child->d_inode;
21866 +       if (inode) {
21867 +               ino = inode->i_ino;
21868 +               type = inode->i_mode >> 12;
21869 +       }
21870 +       dput(child);
21871 +end_instantiate:
21872 +       if (!ino)
21873 +               ino = find_inode_number(dir, &qname);
21874 +       if (!ino)
21875 +               ino = 1;
21876 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21877 +}
21878 +
21879 +
21880 +
21881 +/* get and revalidate vx_info/xid */
21882 +
21883 +static inline
21884 +struct vx_info *get_proc_vx_info(struct inode *inode)
21885 +{
21886 +       return lookup_vx_info(PROC_I(inode)->fd);
21887 +}
21888 +
21889 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21890 +{
21891 +       struct inode *inode = dentry->d_inode;
21892 +       xid_t xid = PROC_I(inode)->fd;
21893 +
21894 +       if (!xid || xid_is_hashed(xid))
21895 +               return 1;
21896 +       d_drop(dentry);
21897 +       return 0;
21898 +}
21899 +
21900 +
21901 +/* get and revalidate nx_info/nid */
21902 +
21903 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21904 +{
21905 +       struct inode *inode = dentry->d_inode;
21906 +       nid_t nid = PROC_I(inode)->fd;
21907 +
21908 +       if (!nid || nid_is_hashed(nid))
21909 +               return 1;
21910 +       d_drop(dentry);
21911 +       return 0;
21912 +}
21913 +
21914 +
21915 +
21916 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21917 +
21918 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21919 +                         size_t count, loff_t *ppos)
21920 +{
21921 +       struct inode *inode = file->f_dentry->d_inode;
21922 +       unsigned long page;
21923 +       ssize_t length = 0;
21924 +
21925 +       if (count > PROC_BLOCK_SIZE)
21926 +               count = PROC_BLOCK_SIZE;
21927 +
21928 +       /* fade that out as soon as stable */
21929 +       WARN_ON(PROC_I(inode)->fd);
21930 +
21931 +       if (!(page = __get_free_page(GFP_KERNEL)))
21932 +               return -ENOMEM;
21933 +
21934 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21935 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21936 +
21937 +       if (length >= 0)
21938 +               length = simple_read_from_buffer(buf, count, ppos,
21939 +                       (char *)page, length);
21940 +
21941 +       free_page(page);
21942 +       return length;
21943 +}
21944 +
21945 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21946 +                         size_t count, loff_t *ppos)
21947 +{
21948 +       struct inode *inode = file->f_dentry->d_inode;
21949 +       struct vx_info *vxi = NULL;
21950 +       xid_t xid = PROC_I(inode)->fd;
21951 +       unsigned long page;
21952 +       ssize_t length = 0;
21953 +
21954 +       if (count > PROC_BLOCK_SIZE)
21955 +               count = PROC_BLOCK_SIZE;
21956 +
21957 +       /* fade that out as soon as stable */
21958 +       WARN_ON(!xid);
21959 +       vxi = lookup_vx_info(xid);
21960 +       if (!vxi)
21961 +               goto out;
21962 +
21963 +       length = -ENOMEM;
21964 +       if (!(page = __get_free_page(GFP_KERNEL)))
21965 +               goto out_put;
21966 +
21967 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21968 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21969 +
21970 +       if (length >= 0)
21971 +               length = simple_read_from_buffer(buf, count, ppos,
21972 +                       (char *)page, length);
21973 +
21974 +       free_page(page);
21975 +out_put:
21976 +       put_vx_info(vxi);
21977 +out:
21978 +       return length;
21979 +}
21980 +
21981 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21982 +                         size_t count, loff_t *ppos)
21983 +{
21984 +       struct inode *inode = file->f_dentry->d_inode;
21985 +       struct nx_info *nxi = NULL;
21986 +       nid_t nid = PROC_I(inode)->fd;
21987 +       unsigned long page;
21988 +       ssize_t length = 0;
21989 +
21990 +       if (count > PROC_BLOCK_SIZE)
21991 +               count = PROC_BLOCK_SIZE;
21992 +
21993 +       /* fade that out as soon as stable */
21994 +       WARN_ON(!nid);
21995 +       nxi = lookup_nx_info(nid);
21996 +       if (!nxi)
21997 +               goto out;
21998 +
21999 +       length = -ENOMEM;
22000 +       if (!(page = __get_free_page(GFP_KERNEL)))
22001 +               goto out_put;
22002 +
22003 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22004 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22005 +
22006 +       if (length >= 0)
22007 +               length = simple_read_from_buffer(buf, count, ppos,
22008 +                       (char *)page, length);
22009 +
22010 +       free_page(page);
22011 +out_put:
22012 +       put_nx_info(nxi);
22013 +out:
22014 +       return length;
22015 +}
22016 +
22017 +
22018 +
22019 +/* here comes the lower level */
22020 +
22021 +
22022 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22023 +       .len  = sizeof(NAME) - 1,       \
22024 +       .name = (NAME),                 \
22025 +       .mode = MODE,                   \
22026 +       .iop  = IOP,                    \
22027 +       .fop  = FOP,                    \
22028 +       .op   = OP,                     \
22029 +}
22030 +
22031 +
22032 +#define DIR(NAME, MODE, OTYPE)                         \
22033 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22034 +               &proc_ ## OTYPE ## _inode_operations,   \
22035 +               &proc_ ## OTYPE ## _file_operations, { } )
22036 +
22037 +#define INF(NAME, MODE, OTYPE)                         \
22038 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22039 +               &proc_vs_info_file_operations,          \
22040 +               { .proc_vs_read = &proc_##OTYPE } )
22041 +
22042 +#define VINF(NAME, MODE, OTYPE)                                \
22043 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22044 +               &proc_vx_info_file_operations,          \
22045 +               { .proc_vxi_read = &proc_##OTYPE } )
22046 +
22047 +#define NINF(NAME, MODE, OTYPE)                                \
22048 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22049 +               &proc_nx_info_file_operations,          \
22050 +               { .proc_nxi_read = &proc_##OTYPE } )
22051 +
22052 +
22053 +static struct file_operations proc_vs_info_file_operations = {
22054 +       .read =         proc_vs_info_read,
22055 +};
22056 +
22057 +static struct file_operations proc_vx_info_file_operations = {
22058 +       .read =         proc_vx_info_read,
22059 +};
22060 +
22061 +static struct dentry_operations proc_xid_dentry_operations = {
22062 +       .d_revalidate = proc_xid_revalidate,
22063 +};
22064 +
22065 +static struct vs_entry vx_base_stuff[] = {
22066 +       VINF("info",    S_IRUGO, vxi_info),
22067 +       VINF("status",  S_IRUGO, vxi_status),
22068 +       VINF("limit",   S_IRUGO, vxi_limit),
22069 +       VINF("sched",   S_IRUGO, vxi_sched),
22070 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
22071 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
22072 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22073 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22074 +       {}
22075 +};
22076 +
22077 +
22078 +
22079 +
22080 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22081 +       struct dentry *dentry, int id, void *ptr)
22082 +{
22083 +       dentry->d_op = &proc_xid_dentry_operations;
22084 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22085 +}
22086 +
22087 +static struct dentry *proc_xid_lookup(struct inode *dir,
22088 +       struct dentry *dentry, struct nameidata *nd)
22089 +{
22090 +       struct vs_entry *p = vx_base_stuff;
22091 +       struct dentry *error = ERR_PTR(-ENOENT);
22092 +
22093 +       for (; p->name; p++) {
22094 +               if (p->len != dentry->d_name.len)
22095 +                       continue;
22096 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22097 +                       break;
22098 +       }
22099 +       if (!p->name)
22100 +               goto out;
22101 +
22102 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22103 +out:
22104 +       return error;
22105 +}
22106 +
22107 +static int proc_xid_readdir(struct file *filp,
22108 +       void *dirent, filldir_t filldir)
22109 +{
22110 +       struct dentry *dentry = filp->f_dentry;
22111 +       struct inode *inode = dentry->d_inode;
22112 +       struct vs_entry *p = vx_base_stuff;
22113 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22114 +       int pos, index;
22115 +       u64 ino;
22116 +
22117 +       pos = filp->f_pos;
22118 +       switch (pos) {
22119 +       case 0:
22120 +               ino = inode->i_ino;
22121 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22122 +                       goto out;
22123 +               pos++;
22124 +               /* fall through */
22125 +       case 1:
22126 +               ino = parent_ino(dentry);
22127 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22128 +                       goto out;
22129 +               pos++;
22130 +               /* fall through */
22131 +       default:
22132 +               index = pos - 2;
22133 +               if (index >= size)
22134 +                       goto out;
22135 +               for (p += index; p->name; p++) {
22136 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22137 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22138 +                               goto out;
22139 +                       pos++;
22140 +               }
22141 +       }
22142 +out:
22143 +       filp->f_pos = pos;
22144 +       return 1;
22145 +}
22146 +
22147 +
22148 +
22149 +static struct file_operations proc_nx_info_file_operations = {
22150 +       .read =         proc_nx_info_read,
22151 +};
22152 +
22153 +static struct dentry_operations proc_nid_dentry_operations = {
22154 +       .d_revalidate = proc_nid_revalidate,
22155 +};
22156 +
22157 +static struct vs_entry nx_base_stuff[] = {
22158 +       NINF("info",    S_IRUGO, nxi_info),
22159 +       NINF("status",  S_IRUGO, nxi_status),
22160 +       {}
22161 +};
22162 +
22163 +
22164 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22165 +       struct dentry *dentry, int id, void *ptr)
22166 +{
22167 +       dentry->d_op = &proc_nid_dentry_operations;
22168 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22169 +}
22170 +
22171 +static struct dentry *proc_nid_lookup(struct inode *dir,
22172 +       struct dentry *dentry, struct nameidata *nd)
22173 +{
22174 +       struct vs_entry *p = nx_base_stuff;
22175 +       struct dentry *error = ERR_PTR(-ENOENT);
22176 +
22177 +       for (; p->name; p++) {
22178 +               if (p->len != dentry->d_name.len)
22179 +                       continue;
22180 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22181 +                       break;
22182 +       }
22183 +       if (!p->name)
22184 +               goto out;
22185 +
22186 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22187 +out:
22188 +       return error;
22189 +}
22190 +
22191 +static int proc_nid_readdir(struct file *filp,
22192 +       void *dirent, filldir_t filldir)
22193 +{
22194 +       struct dentry *dentry = filp->f_dentry;
22195 +       struct inode *inode = dentry->d_inode;
22196 +       struct vs_entry *p = nx_base_stuff;
22197 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22198 +       int pos, index;
22199 +       u64 ino;
22200 +
22201 +       pos = filp->f_pos;
22202 +       switch (pos) {
22203 +       case 0:
22204 +               ino = inode->i_ino;
22205 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22206 +                       goto out;
22207 +               pos++;
22208 +               /* fall through */
22209 +       case 1:
22210 +               ino = parent_ino(dentry);
22211 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22212 +                       goto out;
22213 +               pos++;
22214 +               /* fall through */
22215 +       default:
22216 +               index = pos - 2;
22217 +               if (index >= size)
22218 +                       goto out;
22219 +               for (p += index; p->name; p++) {
22220 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22221 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22222 +                               goto out;
22223 +                       pos++;
22224 +               }
22225 +       }
22226 +out:
22227 +       filp->f_pos = pos;
22228 +       return 1;
22229 +}
22230 +
22231 +
22232 +#define MAX_MULBY10    ((~0U - 9) / 10)
22233 +
22234 +static inline int atovid(const char *str, int len)
22235 +{
22236 +       int vid, c;
22237 +
22238 +       vid = 0;
22239 +       while (len-- > 0) {
22240 +               c = *str - '0';
22241 +               str++;
22242 +               if (c > 9)
22243 +                       return -1;
22244 +               if (vid >= MAX_MULBY10)
22245 +                       return -1;
22246 +               vid *= 10;
22247 +               vid += c;
22248 +               if (!vid)
22249 +                       return -1;
22250 +       }
22251 +       return vid;
22252 +}
22253 +
22254 +/* now the upper level (virtual) */
22255 +
22256 +
22257 +static struct file_operations proc_xid_file_operations = {
22258 +       .read =         generic_read_dir,
22259 +       .readdir =      proc_xid_readdir,
22260 +};
22261 +
22262 +static struct inode_operations proc_xid_inode_operations = {
22263 +       .lookup =       proc_xid_lookup,
22264 +};
22265 +
22266 +static struct vs_entry vx_virtual_stuff[] = {
22267 +       INF("info",     S_IRUGO, virtual_info),
22268 +       INF("status",   S_IRUGO, virtual_status),
22269 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22270 +};
22271 +
22272 +
22273 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22274 +       struct dentry *dentry, struct nameidata *nd)
22275 +{
22276 +       struct vs_entry *p = vx_virtual_stuff;
22277 +       struct dentry *error = ERR_PTR(-ENOENT);
22278 +       int id = 0;
22279 +
22280 +       for (; p->name; p++) {
22281 +               if (p->len != dentry->d_name.len)
22282 +                       continue;
22283 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22284 +                       break;
22285 +       }
22286 +       if (p->name)
22287 +               goto instantiate;
22288 +
22289 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22290 +       if ((id < 0) || !xid_is_hashed(id))
22291 +               goto out;
22292 +
22293 +instantiate:
22294 +       error = proc_xid_instantiate(dir, dentry, id, p);
22295 +out:
22296 +       return error;
22297 +}
22298 +
22299 +static struct file_operations proc_nid_file_operations = {
22300 +       .read =         generic_read_dir,
22301 +       .readdir =      proc_nid_readdir,
22302 +};
22303 +
22304 +static struct inode_operations proc_nid_inode_operations = {
22305 +       .lookup =       proc_nid_lookup,
22306 +};
22307 +
22308 +static struct vs_entry nx_virtnet_stuff[] = {
22309 +       INF("info",     S_IRUGO, virtnet_info),
22310 +       INF("status",   S_IRUGO, virtnet_status),
22311 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22312 +};
22313 +
22314 +
22315 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22316 +       struct dentry *dentry, struct nameidata *nd)
22317 +{
22318 +       struct vs_entry *p = nx_virtnet_stuff;
22319 +       struct dentry *error = ERR_PTR(-ENOENT);
22320 +       int id = 0;
22321 +
22322 +       for (; p->name; p++) {
22323 +               if (p->len != dentry->d_name.len)
22324 +                       continue;
22325 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22326 +                       break;
22327 +       }
22328 +       if (p->name)
22329 +               goto instantiate;
22330 +
22331 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22332 +       if ((id < 0) || !nid_is_hashed(id))
22333 +               goto out;
22334 +
22335 +instantiate:
22336 +       error = proc_nid_instantiate(dir, dentry, id, p);
22337 +out:
22338 +       return error;
22339 +}
22340 +
22341 +
22342 +#define PROC_MAXVIDS 32
22343 +
22344 +int proc_virtual_readdir(struct file *filp,
22345 +       void *dirent, filldir_t filldir)
22346 +{
22347 +       struct dentry *dentry = filp->f_dentry;
22348 +       struct inode *inode = dentry->d_inode;
22349 +       struct vs_entry *p = vx_virtual_stuff;
22350 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22351 +       int pos, index;
22352 +       unsigned int xid_array[PROC_MAXVIDS];
22353 +       char buf[PROC_NUMBUF];
22354 +       unsigned int nr_xids, i;
22355 +       u64 ino;
22356 +
22357 +       pos = filp->f_pos;
22358 +       switch (pos) {
22359 +       case 0:
22360 +               ino = inode->i_ino;
22361 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22362 +                       goto out;
22363 +               pos++;
22364 +               /* fall through */
22365 +       case 1:
22366 +               ino = parent_ino(dentry);
22367 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22368 +                       goto out;
22369 +               pos++;
22370 +               /* fall through */
22371 +       default:
22372 +               index = pos - 2;
22373 +               if (index >= size)
22374 +                       goto entries;
22375 +               for (p += index; p->name; p++) {
22376 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22377 +                               vs_proc_instantiate, 0, p))
22378 +                               goto out;
22379 +                       pos++;
22380 +               }
22381 +       entries:
22382 +               index = pos - size;
22383 +               p = &vx_virtual_stuff[size - 1];
22384 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22385 +               for (i = 0; i < nr_xids; i++) {
22386 +                       int n, xid = xid_array[i];
22387 +                       unsigned int j = PROC_NUMBUF;
22388 +
22389 +                       n = xid;
22390 +                       do
22391 +                               buf[--j] = '0' + (n % 10);
22392 +                       while (n /= 10);
22393 +
22394 +                       if (proc_fill_cache(filp, dirent, filldir,
22395 +                               buf + j, PROC_NUMBUF - j,
22396 +                               vs_proc_instantiate, xid, p))
22397 +                               goto out;
22398 +                       pos++;
22399 +               }
22400 +       }
22401 +out:
22402 +       filp->f_pos = pos;
22403 +       return 0;
22404 +}
22405 +
22406 +static int proc_virtual_getattr(struct vfsmount *mnt,
22407 +       struct dentry *dentry, struct kstat *stat)
22408 +{
22409 +       struct inode *inode = dentry->d_inode;
22410 +
22411 +       generic_fillattr(inode, stat);
22412 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22413 +       return 0;
22414 +}
22415 +
22416 +static struct file_operations proc_virtual_dir_operations = {
22417 +       .read =         generic_read_dir,
22418 +       .readdir =      proc_virtual_readdir,
22419 +};
22420 +
22421 +static struct inode_operations proc_virtual_dir_inode_operations = {
22422 +       .getattr =      proc_virtual_getattr,
22423 +       .lookup =       proc_virtual_lookup,
22424 +};
22425 +
22426 +
22427 +
22428 +
22429 +
22430 +int proc_virtnet_readdir(struct file *filp,
22431 +       void *dirent, filldir_t filldir)
22432 +{
22433 +       struct dentry *dentry = filp->f_dentry;
22434 +       struct inode *inode = dentry->d_inode;
22435 +       struct vs_entry *p = nx_virtnet_stuff;
22436 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22437 +       int pos, index;
22438 +       unsigned int nid_array[PROC_MAXVIDS];
22439 +       char buf[PROC_NUMBUF];
22440 +       unsigned int nr_nids, i;
22441 +       u64 ino;
22442 +
22443 +       pos = filp->f_pos;
22444 +       switch (pos) {
22445 +       case 0:
22446 +               ino = inode->i_ino;
22447 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22448 +                       goto out;
22449 +               pos++;
22450 +               /* fall through */
22451 +       case 1:
22452 +               ino = parent_ino(dentry);
22453 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22454 +                       goto out;
22455 +               pos++;
22456 +               /* fall through */
22457 +       default:
22458 +               index = pos - 2;
22459 +               if (index >= size)
22460 +                       goto entries;
22461 +               for (p += index; p->name; p++) {
22462 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22463 +                               vs_proc_instantiate, 0, p))
22464 +                               goto out;
22465 +                       pos++;
22466 +               }
22467 +       entries:
22468 +               index = pos - size;
22469 +               p = &nx_virtnet_stuff[size - 1];
22470 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22471 +               for (i = 0; i < nr_nids; i++) {
22472 +                       int n, nid = nid_array[i];
22473 +                       unsigned int j = PROC_NUMBUF;
22474 +
22475 +                       n = nid;
22476 +                       do
22477 +                               buf[--j] = '0' + (n % 10);
22478 +                       while (n /= 10);
22479 +
22480 +                       if (proc_fill_cache(filp, dirent, filldir,
22481 +                               buf + j, PROC_NUMBUF - j,
22482 +                               vs_proc_instantiate, nid, p))
22483 +                               goto out;
22484 +                       pos++;
22485 +               }
22486 +       }
22487 +out:
22488 +       filp->f_pos = pos;
22489 +       return 0;
22490 +}
22491 +
22492 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22493 +       struct dentry *dentry, struct kstat *stat)
22494 +{
22495 +       struct inode *inode = dentry->d_inode;
22496 +
22497 +       generic_fillattr(inode, stat);
22498 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22499 +       return 0;
22500 +}
22501 +
22502 +static struct file_operations proc_virtnet_dir_operations = {
22503 +       .read =         generic_read_dir,
22504 +       .readdir =      proc_virtnet_readdir,
22505 +};
22506 +
22507 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22508 +       .getattr =      proc_virtnet_getattr,
22509 +       .lookup =       proc_virtnet_lookup,
22510 +};
22511 +
22512 +
22513 +
22514 +void proc_vx_init(void)
22515 +{
22516 +       struct proc_dir_entry *ent;
22517 +
22518 +       ent = proc_mkdir("virtual", 0);
22519 +       if (ent) {
22520 +               ent->proc_fops = &proc_virtual_dir_operations;
22521 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22522 +       }
22523 +       proc_virtual = ent;
22524 +
22525 +       ent = proc_mkdir("virtnet", 0);
22526 +       if (ent) {
22527 +               ent->proc_fops = &proc_virtnet_dir_operations;
22528 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22529 +       }
22530 +       proc_virtnet = ent;
22531 +}
22532 +
22533 +
22534 +
22535 +
22536 +/* per pid info */
22537 +
22538 +
22539 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22540 +{
22541 +       struct vx_info *vxi;
22542 +       char *orig = buffer;
22543 +
22544 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22545 +
22546 +       vxi = task_get_vx_info(p);
22547 +       if (!vxi)
22548 +               goto out;
22549 +
22550 +       buffer += sprintf(buffer, "BCaps:\t");
22551 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22552 +       buffer += sprintf(buffer, "\n");
22553 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22554 +               (unsigned long long)vxi->vx_ccaps);
22555 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22556 +               (unsigned long long)vxi->vx_flags);
22557 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22558 +
22559 +       put_vx_info(vxi);
22560 +out:
22561 +       return buffer - orig;
22562 +}
22563 +
22564 +
22565 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22566 +{
22567 +       struct nx_info *nxi;
22568 +       struct nx_addr_v4 *v4a;
22569 +#ifdef CONFIG_IPV6
22570 +       struct nx_addr_v6 *v6a;
22571 +#endif
22572 +       char *orig = buffer;
22573 +       int i;
22574 +
22575 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22576 +
22577 +       nxi = task_get_nx_info(p);
22578 +       if (!nxi)
22579 +               goto out;
22580 +
22581 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22582 +               (unsigned long long)nxi->nx_ncaps);
22583 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22584 +               (unsigned long long)nxi->nx_flags);
22585 +
22586 +       buffer += sprintf(buffer,
22587 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22588 +               NIPQUAD(nxi->v4_bcast.s_addr));
22589 +       buffer += sprintf (buffer,
22590 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22591 +               NIPQUAD(nxi->v4_lback.s_addr));
22592 +       if (!NX_IPV4(nxi))
22593 +               goto skip_v4;
22594 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22595 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22596 +                       i, NXAV4(v4a));
22597 +skip_v4:
22598 +#ifdef CONFIG_IPV6
22599 +       if (!NX_IPV6(nxi))
22600 +               goto skip_v6;
22601 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22602 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22603 +                       i, NXAV6(v6a));
22604 +skip_v6:
22605 +#endif
22606 +       put_nx_info(nxi);
22607 +out:
22608 +       return buffer - orig;
22609 +}
22610 +
22611 diff -NurpP --minimal linux-2.6.37/kernel/vserver/sched.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/sched.c
22612 --- linux-2.6.37/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
22613 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/sched.c  2010-11-23 02:09:41.000000000 +0100
22614 @@ -0,0 +1,82 @@
22615 +/*
22616 + *  linux/kernel/vserver/sched.c
22617 + *
22618 + *  Virtual Server: Scheduler Support
22619 + *
22620 + *  Copyright (C) 2004-2010  Herbert Pötzl
22621 + *
22622 + *  V0.01  adapted Sam Vilains version to 2.6.3
22623 + *  V0.02  removed legacy interface
22624 + *  V0.03  changed vcmds to vxi arg
22625 + *  V0.04  removed older and legacy interfaces
22626 + *  V0.05  removed scheduler code/commands
22627 + *
22628 + */
22629 +
22630 +#include <linux/vs_context.h>
22631 +#include <linux/vs_sched.h>
22632 +#include <linux/vserver/sched_cmd.h>
22633 +
22634 +#include <asm/uaccess.h>
22635 +
22636 +
22637 +void vx_update_sched_param(struct _vx_sched *sched,
22638 +       struct _vx_sched_pc *sched_pc)
22639 +{
22640 +       sched_pc->prio_bias = sched->prio_bias;
22641 +}
22642 +
22643 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22644 +{
22645 +       int cpu;
22646 +
22647 +       if (data->prio_bias > MAX_PRIO_BIAS)
22648 +               data->prio_bias = MAX_PRIO_BIAS;
22649 +       if (data->prio_bias < MIN_PRIO_BIAS)
22650 +               data->prio_bias = MIN_PRIO_BIAS;
22651 +
22652 +       if (data->cpu_id != ~0) {
22653 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22654 +               cpus_and(vxi->sched.update, cpu_online_map,
22655 +                       vxi->sched.update);
22656 +       } else
22657 +               vxi->sched.update = cpu_online_map;
22658 +
22659 +       for_each_cpu_mask(cpu, vxi->sched.update)
22660 +               vx_update_sched_param(&vxi->sched,
22661 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22662 +       return 0;
22663 +}
22664 +
22665 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22666 +{
22667 +       struct vcmd_prio_bias vc_data;
22668 +
22669 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22670 +               return -EFAULT;
22671 +
22672 +       return do_set_prio_bias(vxi, &vc_data);
22673 +}
22674 +
22675 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22676 +{
22677 +       struct vcmd_prio_bias vc_data;
22678 +       struct _vx_sched_pc *pcd;
22679 +       int cpu;
22680 +
22681 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22682 +               return -EFAULT;
22683 +
22684 +       cpu = vc_data.cpu_id;
22685 +
22686 +       if (!cpu_possible(cpu))
22687 +               return -EINVAL;
22688 +
22689 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22690 +       vc_data.prio_bias = pcd->prio_bias;
22691 +
22692 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22693 +               return -EFAULT;
22694 +       return 0;
22695 +}
22696 +
22697 diff -NurpP --minimal linux-2.6.37/kernel/vserver/sched_init.h linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/sched_init.h
22698 --- linux-2.6.37/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
22699 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/sched_init.h     2010-11-23 02:09:41.000000000 +0100
22700 @@ -0,0 +1,27 @@
22701 +
22702 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22703 +{
22704 +       /* scheduling; hard code starting values as constants */
22705 +       sched->prio_bias = 0;
22706 +}
22707 +
22708 +static inline
22709 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22710 +{
22711 +       sched_pc->prio_bias = 0;
22712 +
22713 +       sched_pc->user_ticks = 0;
22714 +       sched_pc->sys_ticks = 0;
22715 +       sched_pc->hold_ticks = 0;
22716 +}
22717 +
22718 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22719 +{
22720 +       return;
22721 +}
22722 +
22723 +static inline
22724 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22725 +{
22726 +       return;
22727 +}
22728 diff -NurpP --minimal linux-2.6.37/kernel/vserver/sched_proc.h linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/sched_proc.h
22729 --- linux-2.6.37/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
22730 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/sched_proc.h     2010-11-23 02:09:41.000000000 +0100
22731 @@ -0,0 +1,32 @@
22732 +#ifndef _VX_SCHED_PROC_H
22733 +#define _VX_SCHED_PROC_H
22734 +
22735 +
22736 +static inline
22737 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22738 +{
22739 +       int length = 0;
22740 +
22741 +       length += sprintf(buffer,
22742 +               "PrioBias:\t%8d\n",
22743 +               sched->prio_bias);
22744 +       return length;
22745 +}
22746 +
22747 +static inline
22748 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22749 +       char *buffer, int cpu)
22750 +{
22751 +       int length = 0;
22752 +
22753 +       length += sprintf(buffer + length,
22754 +               "cpu %d: %lld %lld %lld", cpu,
22755 +               (unsigned long long)sched_pc->user_ticks,
22756 +               (unsigned long long)sched_pc->sys_ticks,
22757 +               (unsigned long long)sched_pc->hold_ticks);
22758 +       length += sprintf(buffer + length,
22759 +               " %d\n", sched_pc->prio_bias);
22760 +       return length;
22761 +}
22762 +
22763 +#endif /* _VX_SCHED_PROC_H */
22764 diff -NurpP --minimal linux-2.6.37/kernel/vserver/signal.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/signal.c
22765 --- linux-2.6.37/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
22766 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/signal.c 2010-11-23 02:09:41.000000000 +0100
22767 @@ -0,0 +1,132 @@
22768 +/*
22769 + *  linux/kernel/vserver/signal.c
22770 + *
22771 + *  Virtual Server: Signal Support
22772 + *
22773 + *  Copyright (C) 2003-2007  Herbert Pötzl
22774 + *
22775 + *  V0.01  broken out from vcontext V0.05
22776 + *  V0.02  changed vcmds to vxi arg
22777 + *  V0.03  adjusted siginfo for kill
22778 + *
22779 + */
22780 +
22781 +#include <asm/uaccess.h>
22782 +
22783 +#include <linux/vs_context.h>
22784 +#include <linux/vs_pid.h>
22785 +#include <linux/vserver/signal_cmd.h>
22786 +
22787 +
22788 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22789 +{
22790 +       int retval, count = 0;
22791 +       struct task_struct *p;
22792 +       struct siginfo *sip = SEND_SIG_PRIV;
22793 +
22794 +       retval = -ESRCH;
22795 +       vxdprintk(VXD_CBIT(misc, 4),
22796 +               "vx_info_kill(%p[#%d],%d,%d)*",
22797 +               vxi, vxi->vx_id, pid, sig);
22798 +       read_lock(&tasklist_lock);
22799 +       switch (pid) {
22800 +       case  0:
22801 +       case -1:
22802 +               for_each_process(p) {
22803 +                       int err = 0;
22804 +
22805 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22806 +                               (pid && vxi->vx_initpid == p->pid))
22807 +                               continue;
22808 +
22809 +                       err = group_send_sig_info(sig, sip, p);
22810 +                       ++count;
22811 +                       if (err != -EPERM)
22812 +                               retval = err;
22813 +               }
22814 +               break;
22815 +
22816 +       case 1:
22817 +               if (vxi->vx_initpid) {
22818 +                       pid = vxi->vx_initpid;
22819 +                       /* for now, only SIGINT to private init ... */
22820 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22821 +                               /* ... as long as there are tasks left */
22822 +                               (atomic_read(&vxi->vx_tasks) > 1))
22823 +                               sig = SIGINT;
22824 +               }
22825 +               /* fallthrough */
22826 +       default:
22827 +               p = find_task_by_real_pid(pid);
22828 +               if (p) {
22829 +                       if (vx_task_xid(p) == vxi->vx_id)
22830 +                               retval = group_send_sig_info(sig, sip, p);
22831 +               }
22832 +               break;
22833 +       }
22834 +       read_unlock(&tasklist_lock);
22835 +       vxdprintk(VXD_CBIT(misc, 4),
22836 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22837 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22838 +       return retval;
22839 +}
22840 +
22841 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22842 +{
22843 +       struct vcmd_ctx_kill_v0 vc_data;
22844 +
22845 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22846 +               return -EFAULT;
22847 +
22848 +       /* special check to allow guest shutdown */
22849 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22850 +               /* forbid killall pid=0 when init is present */
22851 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22852 +               (vc_data.pid > 1)))
22853 +               return -EACCES;
22854 +
22855 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22856 +}
22857 +
22858 +
22859 +static int __wait_exit(struct vx_info *vxi)
22860 +{
22861 +       DECLARE_WAITQUEUE(wait, current);
22862 +       int ret = 0;
22863 +
22864 +       add_wait_queue(&vxi->vx_wait, &wait);
22865 +       set_current_state(TASK_INTERRUPTIBLE);
22866 +
22867 +wait:
22868 +       if (vx_info_state(vxi,
22869 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22870 +               goto out;
22871 +       if (signal_pending(current)) {
22872 +               ret = -ERESTARTSYS;
22873 +               goto out;
22874 +       }
22875 +       schedule();
22876 +       goto wait;
22877 +
22878 +out:
22879 +       set_current_state(TASK_RUNNING);
22880 +       remove_wait_queue(&vxi->vx_wait, &wait);
22881 +       return ret;
22882 +}
22883 +
22884 +
22885 +
22886 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22887 +{
22888 +       struct vcmd_wait_exit_v0 vc_data;
22889 +       int ret;
22890 +
22891 +       ret = __wait_exit(vxi);
22892 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22893 +       vc_data.exit_code = vxi->exit_code;
22894 +
22895 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22896 +               ret = -EFAULT;
22897 +       return ret;
22898 +}
22899 +
22900 diff -NurpP --minimal linux-2.6.37/kernel/vserver/space.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/space.c
22901 --- linux-2.6.37/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
22902 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/space.c  2011-01-08 04:03:49.000000000 +0100
22903 @@ -0,0 +1,441 @@
22904 +/*
22905 + *  linux/kernel/vserver/space.c
22906 + *
22907 + *  Virtual Server: Context Space Support
22908 + *
22909 + *  Copyright (C) 2003-2010  Herbert Pötzl
22910 + *
22911 + *  V0.01  broken out from context.c 0.07
22912 + *  V0.02  added task locking for namespace
22913 + *  V0.03  broken out vx_enter_namespace
22914 + *  V0.04  added *space support and commands
22915 + *  V0.05  added credential support
22916 + *
22917 + */
22918 +
22919 +#include <linux/utsname.h>
22920 +#include <linux/nsproxy.h>
22921 +#include <linux/err.h>
22922 +#include <linux/fs_struct.h>
22923 +#include <linux/cred.h>
22924 +#include <asm/uaccess.h>
22925 +
22926 +#include <linux/vs_context.h>
22927 +#include <linux/vserver/space.h>
22928 +#include <linux/vserver/space_cmd.h>
22929 +
22930 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22931 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22932 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22933 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22934 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22935 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22936 +
22937 +
22938 +/* namespace functions */
22939 +
22940 +#include <linux/mnt_namespace.h>
22941 +#include <linux/user_namespace.h>
22942 +#include <linux/pid_namespace.h>
22943 +#include <linux/ipc_namespace.h>
22944 +#include <net/net_namespace.h>
22945 +
22946 +
22947 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22948 +       .mask = CLONE_FS |
22949 +               CLONE_NEWNS |
22950 +               CLONE_NEWUTS |
22951 +               CLONE_NEWIPC |
22952 +               CLONE_NEWUSER |
22953 +               0
22954 +};
22955 +
22956 +static const struct vcmd_space_mask_v1 space_mask = {
22957 +       .mask = CLONE_FS |
22958 +               CLONE_NEWNS |
22959 +               CLONE_NEWUTS |
22960 +               CLONE_NEWIPC |
22961 +               CLONE_NEWUSER |
22962 +#ifdef CONFIG_PID_NS
22963 +               CLONE_NEWPID |
22964 +#endif
22965 +#ifdef CONFIG_NET_NS
22966 +               CLONE_NEWNET |
22967 +#endif
22968 +               0
22969 +};
22970 +
22971 +static const struct vcmd_space_mask_v1 default_space_mask = {
22972 +       .mask = CLONE_FS |
22973 +               CLONE_NEWNS |
22974 +               CLONE_NEWUTS |
22975 +               CLONE_NEWIPC |
22976 +               CLONE_NEWUSER |
22977 +#ifdef CONFIG_PID_NS
22978 +//             CLONE_NEWPID |
22979 +#endif
22980 +               0
22981 +};
22982 +
22983 +/*
22984 + *     build a new nsproxy mix
22985 + *      assumes that both proxies are 'const'
22986 + *     does not touch nsproxy refcounts
22987 + *     will hold a reference on the result.
22988 + */
22989 +
22990 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22991 +       struct nsproxy *new_nsproxy, unsigned long mask)
22992 +{
22993 +       struct mnt_namespace *old_ns;
22994 +       struct uts_namespace *old_uts;
22995 +       struct ipc_namespace *old_ipc;
22996 +#ifdef CONFIG_PID_NS
22997 +       struct pid_namespace *old_pid;
22998 +#endif
22999 +#ifdef CONFIG_NET_NS
23000 +       struct net *old_net;
23001 +#endif
23002 +       struct nsproxy *nsproxy;
23003 +
23004 +       nsproxy = copy_nsproxy(old_nsproxy);
23005 +       if (!nsproxy)
23006 +               goto out;
23007 +
23008 +       if (mask & CLONE_NEWNS) {
23009 +               old_ns = nsproxy->mnt_ns;
23010 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
23011 +               if (nsproxy->mnt_ns)
23012 +                       get_mnt_ns(nsproxy->mnt_ns);
23013 +       } else
23014 +               old_ns = NULL;
23015 +
23016 +       if (mask & CLONE_NEWUTS) {
23017 +               old_uts = nsproxy->uts_ns;
23018 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
23019 +               if (nsproxy->uts_ns)
23020 +                       get_uts_ns(nsproxy->uts_ns);
23021 +       } else
23022 +               old_uts = NULL;
23023 +
23024 +       if (mask & CLONE_NEWIPC) {
23025 +               old_ipc = nsproxy->ipc_ns;
23026 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
23027 +               if (nsproxy->ipc_ns)
23028 +                       get_ipc_ns(nsproxy->ipc_ns);
23029 +       } else
23030 +               old_ipc = NULL;
23031 +
23032 +#ifdef CONFIG_PID_NS
23033 +       if (mask & CLONE_NEWPID) {
23034 +               old_pid = nsproxy->pid_ns;
23035 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23036 +               if (nsproxy->pid_ns)
23037 +                       get_pid_ns(nsproxy->pid_ns);
23038 +       } else
23039 +               old_pid = NULL;
23040 +#endif
23041 +#ifdef CONFIG_NET_NS
23042 +       if (mask & CLONE_NEWNET) {
23043 +               old_net = nsproxy->net_ns;
23044 +               nsproxy->net_ns = new_nsproxy->net_ns;
23045 +               if (nsproxy->net_ns)
23046 +                       get_net(nsproxy->net_ns);
23047 +       } else
23048 +               old_net = NULL;
23049 +#endif
23050 +       if (old_ns)
23051 +               put_mnt_ns(old_ns);
23052 +       if (old_uts)
23053 +               put_uts_ns(old_uts);
23054 +       if (old_ipc)
23055 +               put_ipc_ns(old_ipc);
23056 +#ifdef CONFIG_PID_NS
23057 +       if (old_pid)
23058 +               put_pid_ns(old_pid);
23059 +#endif
23060 +#ifdef CONFIG_NET_NS
23061 +       if (old_net)
23062 +               put_net(old_net);
23063 +#endif
23064 +out:
23065 +       return nsproxy;
23066 +}
23067 +
23068 +
23069 +/*
23070 + *     merge two nsproxy structs into a new one.
23071 + *     will hold a reference on the result.
23072 + */
23073 +
23074 +static inline
23075 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
23076 +       struct nsproxy *proxy, unsigned long mask)
23077 +{
23078 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
23079 +
23080 +       if (!proxy)
23081 +               return NULL;
23082 +
23083 +       if (mask) {
23084 +               /* vs_mix_nsproxy returns with reference */
23085 +               return vs_mix_nsproxy(old ? old : &null_proxy,
23086 +                       proxy, mask);
23087 +       }
23088 +       get_nsproxy(proxy);
23089 +       return proxy;
23090 +}
23091 +
23092 +
23093 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23094 +{
23095 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
23096 +       struct fs_struct *fs_cur, *fs = NULL;
23097 +       struct _vx_space *space;
23098 +       int ret, kill = 0;
23099 +
23100 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
23101 +               vxi, vxi->vx_id, mask, index);
23102 +
23103 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
23104 +               return -EACCES;
23105 +
23106 +       if (index >= VX_SPACES)
23107 +               return -EINVAL;
23108 +
23109 +       space = &vxi->space[index];
23110 +
23111 +       if (!mask)
23112 +               mask = space->vx_nsmask;
23113 +
23114 +       if ((mask & space->vx_nsmask) != mask)
23115 +               return -EINVAL;
23116 +
23117 +       if (mask & CLONE_FS) {
23118 +               fs = copy_fs_struct(space->vx_fs);
23119 +               if (!fs)
23120 +                       return -ENOMEM;
23121 +       }
23122 +       proxy = space->vx_nsproxy;
23123 +
23124 +       vxdprintk(VXD_CBIT(space, 9),
23125 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23126 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23127 +
23128 +       task_lock(current);
23129 +       fs_cur = current->fs;
23130 +
23131 +       if (mask & CLONE_FS) {
23132 +               spin_lock(&fs_cur->lock);
23133 +               current->fs = fs;
23134 +               kill = !--fs_cur->users;
23135 +               spin_unlock(&fs_cur->lock);
23136 +       }
23137 +
23138 +       proxy_cur = current->nsproxy;
23139 +       get_nsproxy(proxy_cur);
23140 +       task_unlock(current);
23141 +
23142 +       if (kill)
23143 +               free_fs_struct(fs_cur);
23144 +
23145 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23146 +       if (IS_ERR(proxy_new)) {
23147 +               ret = PTR_ERR(proxy_new);
23148 +               goto out_put;
23149 +       }
23150 +
23151 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23152 +
23153 +       if (mask & CLONE_NEWUSER) {
23154 +               vxdprintk(VXD_CBIT(space, 10),
23155 +#if 1
23156 +                       "vx_enter_space(%p[#%u])", vxi, vxi->vx_id);
23157 +#else
23158 +                       "vx_enter_space(%p[#%u],%p,%p) cred (%p,%p)",
23159 +                       vxi, vxi->vx_id,
23160 +                       space->vx_real_cred, space->vx_cred,
23161 +                       current->real_cred, current->cred);
23162 +               exit_creds(current);
23163 +               current->real_cred = get_cred(space->vx_real_cred);
23164 +               alter_cred_subscribers(current->real_cred, 1);
23165 +               current->cred = get_cred(space->vx_cred);
23166 +               alter_cred_subscribers(current->cred, 1);
23167 +#endif
23168 +       }
23169 +
23170 +       ret = 0;
23171 +
23172 +       if (proxy_new)
23173 +               put_nsproxy(proxy_new);
23174 +out_put:
23175 +       if (proxy_cur)
23176 +               put_nsproxy(proxy_cur);
23177 +       return ret;
23178 +}
23179 +
23180 +
23181 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23182 +{
23183 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23184 +       struct fs_struct *fs_vxi, *fs;
23185 +       struct _vx_space *space;
23186 +       int ret, kill = 0;
23187 +
23188 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23189 +               vxi, vxi->vx_id, mask, index);
23190 +
23191 +       if ((mask & space_mask.mask) != mask)
23192 +               return -EINVAL;
23193 +
23194 +       if (index >= VX_SPACES)
23195 +               return -EINVAL;
23196 +
23197 +       space = &vxi->space[index];
23198 +
23199 +       proxy_vxi = space->vx_nsproxy;
23200 +       fs_vxi = space->vx_fs;
23201 +
23202 +       if (mask & CLONE_FS) {
23203 +               fs = copy_fs_struct(current->fs);
23204 +               if (!fs)
23205 +                       return -ENOMEM;
23206 +       }
23207 +
23208 +       task_lock(current);
23209 +
23210 +       if (mask & CLONE_FS) {
23211 +               spin_lock(&fs_vxi->lock);
23212 +               space->vx_fs = fs;
23213 +               kill = !--fs_vxi->users;
23214 +               spin_unlock(&fs_vxi->lock);
23215 +       }
23216 +
23217 +       proxy_cur = current->nsproxy;
23218 +       get_nsproxy(proxy_cur);
23219 +       task_unlock(current);
23220 +
23221 +       if (kill)
23222 +               free_fs_struct(fs_vxi);
23223 +
23224 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23225 +       if (IS_ERR(proxy_new)) {
23226 +               ret = PTR_ERR(proxy_new);
23227 +               goto out_put;
23228 +       }
23229 +
23230 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
23231 +       space->vx_nsmask |= mask;
23232 +
23233 +       if (mask & CLONE_NEWUSER) {
23234 +               // const struct cred *cred;
23235 +
23236 +               vxdprintk(VXD_CBIT(space, 10),
23237 +#if 1
23238 +                       "vx_set_space(%p[#%u])", vxi, vxi->vx_id);
23239 +#else
23240 +                       "vx_set_space(%p[#%u],%p,%p) cred (%p,%p)",
23241 +                       vxi, vxi->vx_id,
23242 +                       space->vx_real_cred, space->vx_cred,
23243 +                       current->real_cred, current->cred);
23244 +
23245 +               if (current->real_cred) {
23246 +                       cred = get_cred(current->real_cred);
23247 +                       alter_cred_subscribers(cred, 1);
23248 +               } else
23249 +                       cred = NULL;
23250 +               cred = xchg(&space->vx_real_cred, cred);
23251 +               if (cred) {
23252 +                       alter_cred_subscribers(cred, -1);
23253 +                       put_cred(cred);
23254 +               }
23255 +
23256 +               if (current->cred) {
23257 +                       cred = get_cred(current->cred);
23258 +                       alter_cred_subscribers(cred, 1);
23259 +               } else
23260 +                       cred = NULL;
23261 +               cred = xchg(&space->vx_cred, cred);
23262 +               if (cred) {
23263 +                       alter_cred_subscribers(cred, -1);
23264 +                       put_cred(cred);
23265 +               }
23266 +#endif
23267 +       }
23268 +
23269 +       ret = 0;
23270 +
23271 +       if (proxy_new)
23272 +               put_nsproxy(proxy_new);
23273 +out_put:
23274 +       if (proxy_cur)
23275 +               put_nsproxy(proxy_cur);
23276 +       return ret;
23277 +}
23278 +
23279 +
23280 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23281 +{
23282 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23283 +
23284 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23285 +               return -EFAULT;
23286 +
23287 +       return vx_enter_space(vxi, vc_data.mask, 0);
23288 +}
23289 +
23290 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23291 +{
23292 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23293 +
23294 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23295 +               return -EFAULT;
23296 +
23297 +       if (vc_data.index >= VX_SPACES)
23298 +               return -EINVAL;
23299 +
23300 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23301 +}
23302 +
23303 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23304 +{
23305 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23306 +
23307 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23308 +               return -EFAULT;
23309 +
23310 +       return vx_set_space(vxi, vc_data.mask, 0);
23311 +}
23312 +
23313 +int vc_set_space(struct vx_info *vxi, void __user *data)
23314 +{
23315 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23316 +
23317 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23318 +               return -EFAULT;
23319 +
23320 +       if (vc_data.index >= VX_SPACES)
23321 +               return -EINVAL;
23322 +
23323 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23324 +}
23325 +
23326 +int vc_get_space_mask(void __user *data, int type)
23327 +{
23328 +       const struct vcmd_space_mask_v1 *mask;
23329 +
23330 +       if (type == 0)
23331 +               mask = &space_mask_v0;
23332 +       else if (type == 1)
23333 +               mask = &space_mask;
23334 +       else
23335 +               mask = &default_space_mask;
23336 +
23337 +       vxdprintk(VXD_CBIT(space, 10),
23338 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23339 +
23340 +       if (copy_to_user(data, mask, sizeof(*mask)))
23341 +               return -EFAULT;
23342 +       return 0;
23343 +}
23344 +
23345 diff -NurpP --minimal linux-2.6.37/kernel/vserver/switch.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/switch.c
23346 --- linux-2.6.37/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
23347 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/switch.c 2010-11-23 02:09:41.000000000 +0100
23348 @@ -0,0 +1,531 @@
23349 +/*
23350 + *  linux/kernel/vserver/switch.c
23351 + *
23352 + *  Virtual Server: Syscall Switch
23353 + *
23354 + *  Copyright (C) 2003-2007  Herbert Pötzl
23355 + *
23356 + *  V0.01  syscall switch
23357 + *  V0.02  added signal to context
23358 + *  V0.03  added rlimit functions
23359 + *  V0.04  added iattr, task/xid functions
23360 + *  V0.05  added debug/history stuff
23361 + *  V0.06  added compat32 layer
23362 + *  V0.07  vcmd args and perms
23363 + *  V0.08  added status commands
23364 + *  V0.09  added tag commands
23365 + *  V0.10  added oom bias
23366 + *  V0.11  added device commands
23367 + *
23368 + */
23369 +
23370 +#include <linux/vs_context.h>
23371 +#include <linux/vs_network.h>
23372 +#include <linux/vserver/switch.h>
23373 +
23374 +#include "vci_config.h"
23375 +
23376 +
23377 +static inline
23378 +int vc_get_version(uint32_t id)
23379 +{
23380 +       return VCI_VERSION;
23381 +}
23382 +
23383 +static inline
23384 +int vc_get_vci(uint32_t id)
23385 +{
23386 +       return vci_kernel_config();
23387 +}
23388 +
23389 +#include <linux/vserver/context_cmd.h>
23390 +#include <linux/vserver/cvirt_cmd.h>
23391 +#include <linux/vserver/cacct_cmd.h>
23392 +#include <linux/vserver/limit_cmd.h>
23393 +#include <linux/vserver/network_cmd.h>
23394 +#include <linux/vserver/sched_cmd.h>
23395 +#include <linux/vserver/debug_cmd.h>
23396 +#include <linux/vserver/inode_cmd.h>
23397 +#include <linux/vserver/dlimit_cmd.h>
23398 +#include <linux/vserver/signal_cmd.h>
23399 +#include <linux/vserver/space_cmd.h>
23400 +#include <linux/vserver/tag_cmd.h>
23401 +#include <linux/vserver/device_cmd.h>
23402 +
23403 +#include <linux/vserver/inode.h>
23404 +#include <linux/vserver/dlimit.h>
23405 +
23406 +
23407 +#ifdef CONFIG_COMPAT
23408 +#define __COMPAT(name, id, data, compat)       \
23409 +       (compat) ? name ## _x32(id, data) : name(id, data)
23410 +#define __COMPAT_NO_ID(name, data, compat)     \
23411 +       (compat) ? name ## _x32(data) : name(data)
23412 +#else
23413 +#define __COMPAT(name, id, data, compat)       \
23414 +       name(id, data)
23415 +#define __COMPAT_NO_ID(name, data, compat)     \
23416 +       name(data)
23417 +#endif
23418 +
23419 +
23420 +static inline
23421 +long do_vcmd(uint32_t cmd, uint32_t id,
23422 +       struct vx_info *vxi, struct nx_info *nxi,
23423 +       void __user *data, int compat)
23424 +{
23425 +       switch (cmd) {
23426 +
23427 +       case VCMD_get_version:
23428 +               return vc_get_version(id);
23429 +       case VCMD_get_vci:
23430 +               return vc_get_vci(id);
23431 +
23432 +       case VCMD_task_xid:
23433 +               return vc_task_xid(id);
23434 +       case VCMD_vx_info:
23435 +               return vc_vx_info(vxi, data);
23436 +
23437 +       case VCMD_task_nid:
23438 +               return vc_task_nid(id);
23439 +       case VCMD_nx_info:
23440 +               return vc_nx_info(nxi, data);
23441 +
23442 +       case VCMD_task_tag:
23443 +               return vc_task_tag(id);
23444 +
23445 +       case VCMD_set_space_v1:
23446 +               return vc_set_space_v1(vxi, data);
23447 +       /* this is version 2 */
23448 +       case VCMD_set_space:
23449 +               return vc_set_space(vxi, data);
23450 +
23451 +       case VCMD_get_space_mask_v0:
23452 +               return vc_get_space_mask(data, 0);
23453 +       /* this is version 1 */
23454 +       case VCMD_get_space_mask:
23455 +               return vc_get_space_mask(data, 1);
23456 +
23457 +       case VCMD_get_space_default:
23458 +               return vc_get_space_mask(data, -1);
23459 +
23460 +#ifdef CONFIG_IA32_EMULATION
23461 +       case VCMD_get_rlimit:
23462 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23463 +       case VCMD_set_rlimit:
23464 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23465 +#else
23466 +       case VCMD_get_rlimit:
23467 +               return vc_get_rlimit(vxi, data);
23468 +       case VCMD_set_rlimit:
23469 +               return vc_set_rlimit(vxi, data);
23470 +#endif
23471 +       case VCMD_get_rlimit_mask:
23472 +               return vc_get_rlimit_mask(id, data);
23473 +       case VCMD_reset_hits:
23474 +               return vc_reset_hits(vxi, data);
23475 +       case VCMD_reset_minmax:
23476 +               return vc_reset_minmax(vxi, data);
23477 +
23478 +       case VCMD_get_vhi_name:
23479 +               return vc_get_vhi_name(vxi, data);
23480 +       case VCMD_set_vhi_name:
23481 +               return vc_set_vhi_name(vxi, data);
23482 +
23483 +       case VCMD_ctx_stat:
23484 +               return vc_ctx_stat(vxi, data);
23485 +       case VCMD_virt_stat:
23486 +               return vc_virt_stat(vxi, data);
23487 +       case VCMD_sock_stat:
23488 +               return vc_sock_stat(vxi, data);
23489 +       case VCMD_rlimit_stat:
23490 +               return vc_rlimit_stat(vxi, data);
23491 +
23492 +       case VCMD_set_cflags:
23493 +               return vc_set_cflags(vxi, data);
23494 +       case VCMD_get_cflags:
23495 +               return vc_get_cflags(vxi, data);
23496 +
23497 +       /* this is version 1 */
23498 +       case VCMD_set_ccaps:
23499 +               return vc_set_ccaps(vxi, data);
23500 +       /* this is version 1 */
23501 +       case VCMD_get_ccaps:
23502 +               return vc_get_ccaps(vxi, data);
23503 +       case VCMD_set_bcaps:
23504 +               return vc_set_bcaps(vxi, data);
23505 +       case VCMD_get_bcaps:
23506 +               return vc_get_bcaps(vxi, data);
23507 +
23508 +       case VCMD_set_badness:
23509 +               return vc_set_badness(vxi, data);
23510 +       case VCMD_get_badness:
23511 +               return vc_get_badness(vxi, data);
23512 +
23513 +       case VCMD_set_nflags:
23514 +               return vc_set_nflags(nxi, data);
23515 +       case VCMD_get_nflags:
23516 +               return vc_get_nflags(nxi, data);
23517 +
23518 +       case VCMD_set_ncaps:
23519 +               return vc_set_ncaps(nxi, data);
23520 +       case VCMD_get_ncaps:
23521 +               return vc_get_ncaps(nxi, data);
23522 +
23523 +       case VCMD_set_prio_bias:
23524 +               return vc_set_prio_bias(vxi, data);
23525 +       case VCMD_get_prio_bias:
23526 +               return vc_get_prio_bias(vxi, data);
23527 +       case VCMD_add_dlimit:
23528 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23529 +       case VCMD_rem_dlimit:
23530 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23531 +       case VCMD_set_dlimit:
23532 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23533 +       case VCMD_get_dlimit:
23534 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23535 +
23536 +       case VCMD_ctx_kill:
23537 +               return vc_ctx_kill(vxi, data);
23538 +
23539 +       case VCMD_wait_exit:
23540 +               return vc_wait_exit(vxi, data);
23541 +
23542 +       case VCMD_get_iattr:
23543 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23544 +       case VCMD_set_iattr:
23545 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23546 +
23547 +       case VCMD_fget_iattr:
23548 +               return vc_fget_iattr(id, data);
23549 +       case VCMD_fset_iattr:
23550 +               return vc_fset_iattr(id, data);
23551 +
23552 +       case VCMD_enter_space_v0:
23553 +               return vc_enter_space_v1(vxi, NULL);
23554 +       case VCMD_enter_space_v1:
23555 +               return vc_enter_space_v1(vxi, data);
23556 +       /* this is version 2 */
23557 +       case VCMD_enter_space:
23558 +               return vc_enter_space(vxi, data);
23559 +
23560 +       case VCMD_ctx_create_v0:
23561 +               return vc_ctx_create(id, NULL);
23562 +       case VCMD_ctx_create:
23563 +               return vc_ctx_create(id, data);
23564 +       case VCMD_ctx_migrate_v0:
23565 +               return vc_ctx_migrate(vxi, NULL);
23566 +       case VCMD_ctx_migrate:
23567 +               return vc_ctx_migrate(vxi, data);
23568 +
23569 +       case VCMD_net_create_v0:
23570 +               return vc_net_create(id, NULL);
23571 +       case VCMD_net_create:
23572 +               return vc_net_create(id, data);
23573 +       case VCMD_net_migrate:
23574 +               return vc_net_migrate(nxi, data);
23575 +
23576 +       case VCMD_tag_migrate:
23577 +               return vc_tag_migrate(id);
23578 +
23579 +       case VCMD_net_add:
23580 +               return vc_net_add(nxi, data);
23581 +       case VCMD_net_remove:
23582 +               return vc_net_remove(nxi, data);
23583 +
23584 +       case VCMD_net_add_ipv4:
23585 +               return vc_net_add_ipv4(nxi, data);
23586 +       case VCMD_net_remove_ipv4:
23587 +               return vc_net_remove_ipv4(nxi, data);
23588 +#ifdef CONFIG_IPV6
23589 +       case VCMD_net_add_ipv6:
23590 +               return vc_net_add_ipv6(nxi, data);
23591 +       case VCMD_net_remove_ipv6:
23592 +               return vc_net_remove_ipv6(nxi, data);
23593 +#endif
23594 +/*     case VCMD_add_match_ipv4:
23595 +               return vc_add_match_ipv4(nxi, data);
23596 +       case VCMD_get_match_ipv4:
23597 +               return vc_get_match_ipv4(nxi, data);
23598 +#ifdef CONFIG_IPV6
23599 +       case VCMD_add_match_ipv6:
23600 +               return vc_add_match_ipv6(nxi, data);
23601 +       case VCMD_get_match_ipv6:
23602 +               return vc_get_match_ipv6(nxi, data);
23603 +#endif */
23604 +
23605 +#ifdef CONFIG_VSERVER_DEVICE
23606 +       case VCMD_set_mapping:
23607 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23608 +       case VCMD_unset_mapping:
23609 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23610 +#endif
23611 +#ifdef CONFIG_VSERVER_HISTORY
23612 +       case VCMD_dump_history:
23613 +               return vc_dump_history(id);
23614 +       case VCMD_read_history:
23615 +               return __COMPAT(vc_read_history, id, data, compat);
23616 +#endif
23617 +       default:
23618 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23619 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23620 +       }
23621 +       return -ENOSYS;
23622 +}
23623 +
23624 +
23625 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23626 +       case VCMD_ ## vcmd: perm = _perm;               \
23627 +               args = _args; flags = _flags; break
23628 +
23629 +
23630 +#define VCA_NONE       0x00
23631 +#define VCA_VXI                0x01
23632 +#define VCA_NXI                0x02
23633 +
23634 +#define VCF_NONE       0x00
23635 +#define VCF_INFO       0x01
23636 +#define VCF_ADMIN      0x02
23637 +#define VCF_ARES       0x06    /* includes admin */
23638 +#define VCF_SETUP      0x08
23639 +
23640 +#define VCF_ZIDOK      0x10    /* zero id okay */
23641 +
23642 +
23643 +static inline
23644 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23645 +{
23646 +       long ret;
23647 +       int permit = -1, state = 0;
23648 +       int perm = -1, args = 0, flags = 0;
23649 +       struct vx_info *vxi = NULL;
23650 +       struct nx_info *nxi = NULL;
23651 +
23652 +       switch (cmd) {
23653 +       /* unpriviledged commands */
23654 +       __VCMD(get_version,      0, VCA_NONE,   0);
23655 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23656 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23657 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23658 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23659 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23660 +
23661 +       /* info commands */
23662 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23663 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23664 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23665 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23666 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23667 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23668 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23669 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23670 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23671 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23672 +
23673 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23674 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23675 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23676 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23677 +
23678 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23679 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23680 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23681 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23682 +
23683 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23684 +
23685 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23686 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23687 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23688 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23689 +
23690 +       /* lower admin commands */
23691 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23692 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23693 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23694 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23695 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23696 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23697 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23698 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23699 +
23700 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23701 +       __VCMD(net_create,       5, VCA_NONE,   0);
23702 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23703 +
23704 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23705 +
23706 +       /* higher admin commands */
23707 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23708 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23709 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23710 +
23711 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23712 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23713 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23714 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23715 +
23716 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23717 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23718 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23719 +
23720 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23721 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23722 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23723 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23724 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23725 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23726 +#ifdef CONFIG_IPV6
23727 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23728 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23729 +#endif
23730 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23731 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23732 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23733 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23734 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23735 +
23736 +#ifdef CONFIG_VSERVER_DEVICE
23737 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23738 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23739 +#endif
23740 +       /* debug level admin commands */
23741 +#ifdef CONFIG_VSERVER_HISTORY
23742 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23743 +       __VCMD(read_history,     9, VCA_NONE,   0);
23744 +#endif
23745 +
23746 +       default:
23747 +               perm = -1;
23748 +       }
23749 +
23750 +       vxdprintk(VXD_CBIT(switch, 0),
23751 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23752 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23753 +               VC_VERSION(cmd), id, data, compat,
23754 +               perm, args, flags);
23755 +
23756 +       ret = -ENOSYS;
23757 +       if (perm < 0)
23758 +               goto out;
23759 +
23760 +       state = 1;
23761 +       if (!capable(CAP_CONTEXT))
23762 +               goto out;
23763 +
23764 +       state = 2;
23765 +       /* moved here from the individual commands */
23766 +       ret = -EPERM;
23767 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23768 +               goto out;
23769 +
23770 +       state = 3;
23771 +       /* vcmd involves resource management  */
23772 +       ret = -EPERM;
23773 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23774 +               goto out;
23775 +
23776 +       state = 4;
23777 +       /* various legacy exceptions */
23778 +       switch (cmd) {
23779 +       /* will go away when spectator is a cap */
23780 +       case VCMD_ctx_migrate_v0:
23781 +       case VCMD_ctx_migrate:
23782 +               if (id == 1) {
23783 +                       current->xid = 1;
23784 +                       ret = 1;
23785 +                       goto out;
23786 +               }
23787 +               break;
23788 +
23789 +       /* will go away when spectator is a cap */
23790 +       case VCMD_net_migrate:
23791 +               if (id == 1) {
23792 +                       current->nid = 1;
23793 +                       ret = 1;
23794 +                       goto out;
23795 +               }
23796 +               break;
23797 +       }
23798 +
23799 +       /* vcmds are fine by default */
23800 +       permit = 1;
23801 +
23802 +       /* admin type vcmds require admin ... */
23803 +       if (flags & VCF_ADMIN)
23804 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23805 +
23806 +       /* ... but setup type vcmds override that */
23807 +       if (!permit && (flags & VCF_SETUP))
23808 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23809 +
23810 +       state = 5;
23811 +       ret = -EPERM;
23812 +       if (!permit)
23813 +               goto out;
23814 +
23815 +       state = 6;
23816 +       if (!id && (flags & VCF_ZIDOK))
23817 +               goto skip_id;
23818 +
23819 +       ret = -ESRCH;
23820 +       if (args & VCA_VXI) {
23821 +               vxi = lookup_vx_info(id);
23822 +               if (!vxi)
23823 +                       goto out;
23824 +
23825 +               if ((flags & VCF_ADMIN) &&
23826 +                       /* special case kill for shutdown */
23827 +                       (cmd != VCMD_ctx_kill) &&
23828 +                       /* can context be administrated? */
23829 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23830 +                       ret = -EACCES;
23831 +                       goto out_vxi;
23832 +               }
23833 +       }
23834 +       state = 7;
23835 +       if (args & VCA_NXI) {
23836 +               nxi = lookup_nx_info(id);
23837 +               if (!nxi)
23838 +                       goto out_vxi;
23839 +
23840 +               if ((flags & VCF_ADMIN) &&
23841 +                       /* can context be administrated? */
23842 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23843 +                       ret = -EACCES;
23844 +                       goto out_nxi;
23845 +               }
23846 +       }
23847 +skip_id:
23848 +       state = 8;
23849 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23850 +
23851 +out_nxi:
23852 +       if ((args & VCA_NXI) && nxi)
23853 +               put_nx_info(nxi);
23854 +out_vxi:
23855 +       if ((args & VCA_VXI) && vxi)
23856 +               put_vx_info(vxi);
23857 +out:
23858 +       vxdprintk(VXD_CBIT(switch, 1),
23859 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23860 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23861 +               VC_VERSION(cmd), ret, ret, state, permit);
23862 +       return ret;
23863 +}
23864 +
23865 +asmlinkage long
23866 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23867 +{
23868 +       return do_vserver(cmd, id, data, 0);
23869 +}
23870 +
23871 +#ifdef CONFIG_COMPAT
23872 +
23873 +asmlinkage long
23874 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23875 +{
23876 +       return do_vserver(cmd, id, data, 1);
23877 +}
23878 +
23879 +#endif /* CONFIG_COMPAT */
23880 diff -NurpP --minimal linux-2.6.37/kernel/vserver/sysctl.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/sysctl.c
23881 --- linux-2.6.37/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
23882 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/sysctl.c 2010-11-23 02:09:41.000000000 +0100
23883 @@ -0,0 +1,241 @@
23884 +/*
23885 + *  kernel/vserver/sysctl.c
23886 + *
23887 + *  Virtual Context Support
23888 + *
23889 + *  Copyright (C) 2004-2007  Herbert Pötzl
23890 + *
23891 + *  V0.01  basic structure
23892 + *
23893 + */
23894 +
23895 +#include <linux/module.h>
23896 +#include <linux/ctype.h>
23897 +#include <linux/sysctl.h>
23898 +#include <linux/parser.h>
23899 +#include <asm/uaccess.h>
23900 +
23901 +enum {
23902 +       CTL_DEBUG_ERROR         = 0,
23903 +       CTL_DEBUG_SWITCH        = 1,
23904 +       CTL_DEBUG_XID,
23905 +       CTL_DEBUG_NID,
23906 +       CTL_DEBUG_TAG,
23907 +       CTL_DEBUG_NET,
23908 +       CTL_DEBUG_LIMIT,
23909 +       CTL_DEBUG_CRES,
23910 +       CTL_DEBUG_DLIM,
23911 +       CTL_DEBUG_QUOTA,
23912 +       CTL_DEBUG_CVIRT,
23913 +       CTL_DEBUG_SPACE,
23914 +       CTL_DEBUG_MISC,
23915 +};
23916 +
23917 +
23918 +unsigned int vx_debug_switch   = 0;
23919 +unsigned int vx_debug_xid      = 0;
23920 +unsigned int vx_debug_nid      = 0;
23921 +unsigned int vx_debug_tag      = 0;
23922 +unsigned int vx_debug_net      = 0;
23923 +unsigned int vx_debug_limit    = 0;
23924 +unsigned int vx_debug_cres     = 0;
23925 +unsigned int vx_debug_dlim     = 0;
23926 +unsigned int vx_debug_quota    = 0;
23927 +unsigned int vx_debug_cvirt    = 0;
23928 +unsigned int vx_debug_space    = 0;
23929 +unsigned int vx_debug_misc     = 0;
23930 +
23931 +
23932 +static struct ctl_table_header *vserver_table_header;
23933 +static ctl_table vserver_root_table[];
23934 +
23935 +
23936 +void vserver_register_sysctl(void)
23937 +{
23938 +       if (!vserver_table_header) {
23939 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23940 +       }
23941 +
23942 +}
23943 +
23944 +void vserver_unregister_sysctl(void)
23945 +{
23946 +       if (vserver_table_header) {
23947 +               unregister_sysctl_table(vserver_table_header);
23948 +               vserver_table_header = NULL;
23949 +       }
23950 +}
23951 +
23952 +
23953 +static int proc_dodebug(ctl_table *table, int write,
23954 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23955 +{
23956 +       char            tmpbuf[20], *p, c;
23957 +       unsigned int    value;
23958 +       size_t          left, len;
23959 +
23960 +       if ((*ppos && !write) || !*lenp) {
23961 +               *lenp = 0;
23962 +               return 0;
23963 +       }
23964 +
23965 +       left = *lenp;
23966 +
23967 +       if (write) {
23968 +               if (!access_ok(VERIFY_READ, buffer, left))
23969 +                       return -EFAULT;
23970 +               p = (char *)buffer;
23971 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23972 +                       left--, p++;
23973 +               if (!left)
23974 +                       goto done;
23975 +
23976 +               if (left > sizeof(tmpbuf) - 1)
23977 +                       return -EINVAL;
23978 +               if (copy_from_user(tmpbuf, p, left))
23979 +                       return -EFAULT;
23980 +               tmpbuf[left] = '\0';
23981 +
23982 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23983 +                       value = 10 * value + (*p - '0');
23984 +               if (*p && !isspace(*p))
23985 +                       return -EINVAL;
23986 +               while (left && isspace(*p))
23987 +                       left--, p++;
23988 +               *(unsigned int *)table->data = value;
23989 +       } else {
23990 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23991 +                       return -EFAULT;
23992 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23993 +               if (len > left)
23994 +                       len = left;
23995 +               if (__copy_to_user(buffer, tmpbuf, len))
23996 +                       return -EFAULT;
23997 +               if ((left -= len) > 0) {
23998 +                       if (put_user('\n', (char *)buffer + len))
23999 +                               return -EFAULT;
24000 +                       left--;
24001 +               }
24002 +       }
24003 +
24004 +done:
24005 +       *lenp -= left;
24006 +       *ppos += *lenp;
24007 +       return 0;
24008 +}
24009 +
24010 +static int zero;
24011 +
24012 +#define        CTL_ENTRY(ctl, name)                            \
24013 +       {                                               \
24014 +               .procname       = #name,                \
24015 +               .data           = &vx_ ## name,         \
24016 +               .maxlen         = sizeof(int),          \
24017 +               .mode           = 0644,                 \
24018 +               .proc_handler   = &proc_dodebug,        \
24019 +               .extra1         = &zero,                \
24020 +               .extra2         = &zero,                \
24021 +       }
24022 +
24023 +static ctl_table vserver_debug_table[] = {
24024 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
24025 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
24026 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
24027 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
24028 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
24029 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
24030 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
24031 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
24032 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
24033 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
24034 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
24035 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
24036 +       { 0 }
24037 +};
24038 +
24039 +static ctl_table vserver_root_table[] = {
24040 +       {
24041 +               .procname       = "vserver",
24042 +               .mode           = 0555,
24043 +               .child          = vserver_debug_table
24044 +       },
24045 +       { 0 }
24046 +};
24047 +
24048 +
24049 +static match_table_t tokens = {
24050 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24051 +       { CTL_DEBUG_XID,        "xid=%x"        },
24052 +       { CTL_DEBUG_NID,        "nid=%x"        },
24053 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24054 +       { CTL_DEBUG_NET,        "net=%x"        },
24055 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24056 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24057 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24058 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24059 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24060 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24061 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24062 +       { CTL_DEBUG_ERROR,      NULL            }
24063 +};
24064 +
24065 +#define        HANDLE_CASE(id, name, val)                              \
24066 +       case CTL_DEBUG_ ## id:                                  \
24067 +               vx_debug_ ## name = val;                        \
24068 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24069 +               break
24070 +
24071 +
24072 +static int __init vs_debug_setup(char *str)
24073 +{
24074 +       char *p;
24075 +       int token;
24076 +
24077 +       printk("vs_debug_setup(%s)\n", str);
24078 +       while ((p = strsep(&str, ",")) != NULL) {
24079 +               substring_t args[MAX_OPT_ARGS];
24080 +               unsigned int value;
24081 +
24082 +               if (!*p)
24083 +                       continue;
24084 +
24085 +               token = match_token(p, tokens, args);
24086 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24087 +
24088 +               switch (token) {
24089 +               HANDLE_CASE(SWITCH, switch, value);
24090 +               HANDLE_CASE(XID,    xid,    value);
24091 +               HANDLE_CASE(NID,    nid,    value);
24092 +               HANDLE_CASE(TAG,    tag,    value);
24093 +               HANDLE_CASE(NET,    net,    value);
24094 +               HANDLE_CASE(LIMIT,  limit,  value);
24095 +               HANDLE_CASE(CRES,   cres,   value);
24096 +               HANDLE_CASE(DLIM,   dlim,   value);
24097 +               HANDLE_CASE(QUOTA,  quota,  value);
24098 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24099 +               HANDLE_CASE(SPACE,  space,  value);
24100 +               HANDLE_CASE(MISC,   misc,   value);
24101 +               default:
24102 +                       return -EINVAL;
24103 +                       break;
24104 +               }
24105 +       }
24106 +       return 1;
24107 +}
24108 +
24109 +__setup("vsdebug=", vs_debug_setup);
24110 +
24111 +
24112 +
24113 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24114 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24115 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24116 +EXPORT_SYMBOL_GPL(vx_debug_net);
24117 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24118 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24119 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24120 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24121 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24122 +EXPORT_SYMBOL_GPL(vx_debug_space);
24123 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24124 +
24125 diff -NurpP --minimal linux-2.6.37/kernel/vserver/tag.c linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/tag.c
24126 --- linux-2.6.37/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
24127 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/tag.c    2010-11-23 02:09:41.000000000 +0100
24128 @@ -0,0 +1,63 @@
24129 +/*
24130 + *  linux/kernel/vserver/tag.c
24131 + *
24132 + *  Virtual Server: Shallow Tag Space
24133 + *
24134 + *  Copyright (C) 2007  Herbert Pötzl
24135 + *
24136 + *  V0.01  basic implementation
24137 + *
24138 + */
24139 +
24140 +#include <linux/sched.h>
24141 +#include <linux/vserver/debug.h>
24142 +#include <linux/vs_pid.h>
24143 +#include <linux/vs_tag.h>
24144 +
24145 +#include <linux/vserver/tag_cmd.h>
24146 +
24147 +
24148 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24149 +{
24150 +       if (!p)
24151 +               BUG();
24152 +
24153 +       vxdprintk(VXD_CBIT(tag, 5),
24154 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24155 +
24156 +       task_lock(p);
24157 +       p->tag = tag;
24158 +       task_unlock(p);
24159 +
24160 +       vxdprintk(VXD_CBIT(tag, 5),
24161 +               "moved task %p into [#%d]", p, tag);
24162 +       return 0;
24163 +}
24164 +
24165 +/* vserver syscall commands below here */
24166 +
24167 +/* taks xid and vx_info functions */
24168 +
24169 +
24170 +int vc_task_tag(uint32_t id)
24171 +{
24172 +       tag_t tag;
24173 +
24174 +       if (id) {
24175 +               struct task_struct *tsk;
24176 +               read_lock(&tasklist_lock);
24177 +               tsk = find_task_by_real_pid(id);
24178 +               tag = (tsk) ? tsk->tag : -ESRCH;
24179 +               read_unlock(&tasklist_lock);
24180 +       } else
24181 +               tag = dx_current_tag();
24182 +       return tag;
24183 +}
24184 +
24185 +
24186 +int vc_tag_migrate(uint32_t tag)
24187 +{
24188 +       return dx_migrate_task(current, tag & 0xFFFF);
24189 +}
24190 +
24191 +
24192 diff -NurpP --minimal linux-2.6.37/kernel/vserver/vci_config.h linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/vci_config.h
24193 --- linux-2.6.37/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
24194 +++ linux-2.6.37-vs2.3.0.37-rc2/kernel/vserver/vci_config.h     2010-11-23 02:09:41.000000000 +0100
24195 @@ -0,0 +1,82 @@
24196 +
24197 +/*  interface version */
24198 +
24199 +#define VCI_VERSION            0x00020307
24200 +
24201 +
24202 +enum {
24203 +       VCI_KCBIT_NO_DYNAMIC = 0,
24204 +
24205 +       VCI_KCBIT_PROC_SECURE = 4,
24206 +       VCI_KCBIT_HARDCPU = 5,
24207 +       VCI_KCBIT_IDLELIMIT = 6,
24208 +       VCI_KCBIT_IDLETIME = 7,
24209 +
24210 +       VCI_KCBIT_COWBL = 8,
24211 +       VCI_KCBIT_FULLCOWBL = 9,
24212 +       VCI_KCBIT_SPACES = 10,
24213 +       VCI_KCBIT_NETV2 = 11,
24214 +       VCI_KCBIT_MEMCG = 12,
24215 +
24216 +       VCI_KCBIT_DEBUG = 16,
24217 +       VCI_KCBIT_HISTORY = 20,
24218 +       VCI_KCBIT_TAGGED = 24,
24219 +       VCI_KCBIT_PPTAG = 28,
24220 +
24221 +       VCI_KCBIT_MORE = 31,
24222 +};
24223 +
24224 +
24225 +static inline uint32_t vci_kernel_config(void)
24226 +{
24227 +       return
24228 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24229 +
24230 +       /* configured features */
24231 +#ifdef CONFIG_VSERVER_PROC_SECURE
24232 +       (1 << VCI_KCBIT_PROC_SECURE) |
24233 +#endif
24234 +#ifdef CONFIG_VSERVER_IDLELIMIT
24235 +       (1 << VCI_KCBIT_IDLELIMIT) |
24236 +#endif
24237 +#ifdef CONFIG_VSERVER_IDLETIME
24238 +       (1 << VCI_KCBIT_IDLETIME) |
24239 +#endif
24240 +#ifdef CONFIG_VSERVER_COWBL
24241 +       (1 << VCI_KCBIT_COWBL) |
24242 +       (1 << VCI_KCBIT_FULLCOWBL) |
24243 +#endif
24244 +       (1 << VCI_KCBIT_SPACES) |
24245 +       (1 << VCI_KCBIT_NETV2) |
24246 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24247 +       (1 << VCI_KCBIT_MEMCG) |
24248 +#endif
24249 +
24250 +       /* debug options */
24251 +#ifdef CONFIG_VSERVER_DEBUG
24252 +       (1 << VCI_KCBIT_DEBUG) |
24253 +#endif
24254 +#ifdef CONFIG_VSERVER_HISTORY
24255 +       (1 << VCI_KCBIT_HISTORY) |
24256 +#endif
24257 +
24258 +       /* inode context tagging */
24259 +#if    defined(CONFIG_TAGGING_NONE)
24260 +       (0 << VCI_KCBIT_TAGGED) |
24261 +#elif  defined(CONFIG_TAGGING_UID16)
24262 +       (1 << VCI_KCBIT_TAGGED) |
24263 +#elif  defined(CONFIG_TAGGING_GID16)
24264 +       (2 << VCI_KCBIT_TAGGED) |
24265 +#elif  defined(CONFIG_TAGGING_ID24)
24266 +       (3 << VCI_KCBIT_TAGGED) |
24267 +#elif  defined(CONFIG_TAGGING_INTERN)
24268 +       (4 << VCI_KCBIT_TAGGED) |
24269 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24270 +       (5 << VCI_KCBIT_TAGGED) |
24271 +#else
24272 +       (7 << VCI_KCBIT_TAGGED) |
24273 +#endif
24274 +       (1 << VCI_KCBIT_PPTAG) |
24275 +       0;
24276 +}
24277 +
24278 diff -NurpP --minimal linux-2.6.37/mm/filemap_xip.c linux-2.6.37-vs2.3.0.37-rc2/mm/filemap_xip.c
24279 --- linux-2.6.37/mm/filemap_xip.c       2010-07-07 18:31:58.000000000 +0200
24280 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/filemap_xip.c        2010-11-23 02:09:41.000000000 +0100
24281 @@ -18,6 +18,7 @@
24282  #include <linux/seqlock.h>
24283  #include <linux/mutex.h>
24284  #include <linux/gfp.h>
24285 +#include <linux/vs_memory.h>
24286  #include <asm/tlbflush.h>
24287  #include <asm/io.h>
24288  
24289 diff -NurpP --minimal linux-2.6.37/mm/fremap.c linux-2.6.37-vs2.3.0.37-rc2/mm/fremap.c
24290 --- linux-2.6.37/mm/fremap.c    2010-10-21 13:07:57.000000000 +0200
24291 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/fremap.c     2010-11-23 02:09:41.000000000 +0100
24292 @@ -16,6 +16,7 @@
24293  #include <linux/module.h>
24294  #include <linux/syscalls.h>
24295  #include <linux/mmu_notifier.h>
24296 +#include <linux/vs_memory.h>
24297  
24298  #include <asm/mmu_context.h>
24299  #include <asm/cacheflush.h>
24300 diff -NurpP --minimal linux-2.6.37/mm/hugetlb.c linux-2.6.37-vs2.3.0.37-rc2/mm/hugetlb.c
24301 --- linux-2.6.37/mm/hugetlb.c   2011-01-05 21:50:39.000000000 +0100
24302 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/hugetlb.c    2011-01-05 22:30:43.000000000 +0100
24303 @@ -28,6 +28,7 @@
24304  
24305  #include <linux/hugetlb.h>
24306  #include <linux/node.h>
24307 +#include <linux/vs_memory.h>
24308  #include "internal.h"
24309  
24310  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24311 diff -NurpP --minimal linux-2.6.37/mm/memcontrol.c linux-2.6.37-vs2.3.0.37-rc2/mm/memcontrol.c
24312 --- linux-2.6.37/mm/memcontrol.c        2011-01-05 21:50:40.000000000 +0100
24313 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/memcontrol.c 2011-01-05 22:30:43.000000000 +0100
24314 @@ -681,6 +681,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24315                                 struct mem_cgroup, css);
24316  }
24317  
24318 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24319 +{
24320 +       return res_counter_read_u64(&mem->res, member);
24321 +}
24322 +
24323 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24324 +{
24325 +       return res_counter_read_u64(&mem->memsw, member);
24326 +}
24327 +
24328 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24329 +{
24330 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24331 +}
24332 +
24333 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24334 +{
24335 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24336 +}
24337 +
24338 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24339 +{
24340 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24341 +}
24342 +
24343  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24344  {
24345         struct mem_cgroup *mem = NULL;
24346 diff -NurpP --minimal linux-2.6.37/mm/memory.c linux-2.6.37-vs2.3.0.37-rc2/mm/memory.c
24347 --- linux-2.6.37/mm/memory.c    2011-01-05 21:50:40.000000000 +0100
24348 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/memory.c     2010-11-23 02:09:41.000000000 +0100
24349 @@ -3153,6 +3153,7 @@ static inline int handle_pte_fault(struc
24350  {
24351         pte_t entry;
24352         spinlock_t *ptl;
24353 +       int ret = 0, type = VXPT_UNKNOWN;
24354  
24355         entry = *pte;
24356         if (!pte_present(entry)) {
24357 @@ -3177,9 +3178,12 @@ static inline int handle_pte_fault(struc
24358         if (unlikely(!pte_same(*pte, entry)))
24359                 goto unlock;
24360         if (flags & FAULT_FLAG_WRITE) {
24361 -               if (!pte_write(entry))
24362 -                       return do_wp_page(mm, vma, address,
24363 +               if (!pte_write(entry)) {
24364 +                       ret = do_wp_page(mm, vma, address,
24365                                         pte, pmd, ptl, entry);
24366 +                       type = VXPT_WRITE;
24367 +                       goto out;
24368 +               }
24369                 entry = pte_mkdirty(entry);
24370         }
24371         entry = pte_mkyoung(entry);
24372 @@ -3197,7 +3201,10 @@ static inline int handle_pte_fault(struc
24373         }
24374  unlock:
24375         pte_unmap_unlock(pte, ptl);
24376 -       return 0;
24377 +       ret = 0;
24378 +out:
24379 +       vx_page_fault(mm, vma, type, ret);
24380 +       return ret;
24381  }
24382  
24383  /*
24384 diff -NurpP --minimal linux-2.6.37/mm/mremap.c linux-2.6.37-vs2.3.0.37-rc2/mm/mremap.c
24385 --- linux-2.6.37/mm/mremap.c    2011-01-05 21:50:40.000000000 +0100
24386 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/mremap.c     2010-11-23 02:09:41.000000000 +0100
24387 @@ -19,6 +19,7 @@
24388  #include <linux/security.h>
24389  #include <linux/syscalls.h>
24390  #include <linux/mmu_notifier.h>
24391 +#include <linux/vs_memory.h>
24392  
24393  #include <asm/uaccess.h>
24394  #include <asm/cacheflush.h>
24395 diff -NurpP --minimal linux-2.6.37/mm/oom_kill.c linux-2.6.37-vs2.3.0.37-rc2/mm/oom_kill.c
24396 --- linux-2.6.37/mm/oom_kill.c  2011-01-05 21:50:40.000000000 +0100
24397 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/oom_kill.c   2010-11-23 02:09:41.000000000 +0100
24398 @@ -31,6 +31,9 @@
24399  #include <linux/memcontrol.h>
24400  #include <linux/mempolicy.h>
24401  #include <linux/security.h>
24402 +#include <linux/reboot.h>
24403 +#include <linux/vs_memory.h>
24404 +#include <linux/vs_context.h>
24405  
24406  int sysctl_panic_on_oom;
24407  int sysctl_oom_kill_allocating_task;
24408 @@ -124,11 +127,18 @@ struct task_struct *find_lock_task_mm(st
24409  static bool oom_unkillable_task(struct task_struct *p,
24410                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24411  {
24412 -       if (is_global_init(p))
24413 +       unsigned xid = vx_current_xid();
24414 +
24415 +       /* skip the init task, global and per guest */
24416 +       if (task_is_init(p))
24417                 return true;
24418         if (p->flags & PF_KTHREAD)
24419                 return true;
24420  
24421 +       /* skip other guest and host processes if oom in guest */
24422 +       if (xid && vx_task_xid(p) != xid)
24423 +               return true;
24424 +
24425         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24426         if (mem && !task_in_mem_cgroup(p, mem))
24427                 return true;
24428 @@ -210,6 +220,18 @@ unsigned int oom_badness(struct task_str
24429         points += p->signal->oom_score_adj;
24430  
24431         /*
24432 +        * add points for context badness and
24433 +        * reduce badness for processes belonging to
24434 +        * a different context
24435 +        */
24436 +
24437 +       points += vx_badness(p, p->mm);
24438 +
24439 +       if ((vx_current_xid() > 1) &&
24440 +               vx_current_xid() != vx_task_xid(p))
24441 +               points /= 16;
24442 +
24443 +       /*
24444          * Never return 0 for an eligible task that may be killed since it's
24445          * possible that no single user task uses more than 0.1% of memory and
24446          * no single admin tasks uses more than 3.0%.
24447 @@ -414,8 +436,8 @@ static int oom_kill_task(struct task_str
24448         /* mm cannot be safely dereferenced after task_unlock(p) */
24449         mm = p->mm;
24450  
24451 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24452 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24453 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24454 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24455                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24456                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24457         task_unlock(p);
24458 @@ -477,8 +499,8 @@ static int oom_kill_process(struct task_
24459         }
24460  
24461         task_lock(p);
24462 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24463 -               message, task_pid_nr(p), p->comm, points);
24464 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24465 +               message, task_pid_nr(p), p->xid, p->comm, points);
24466         task_unlock(p);
24467  
24468         /*
24469 @@ -567,6 +589,8 @@ int unregister_oom_notifier(struct notif
24470  }
24471  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24472  
24473 +long vs_oom_action(unsigned int);
24474 +
24475  /*
24476   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24477   * if a parallel OOM killing is already taking place that includes a zone in
24478 @@ -726,7 +750,12 @@ retry:
24479         if (!p) {
24480                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24481                 read_unlock(&tasklist_lock);
24482 -               panic("Out of memory and no killable processes...\n");
24483 +
24484 +               /* avoid panic for guest OOM */
24485 +               if (current->xid)
24486 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24487 +               else
24488 +                       panic("Out of memory and no killable processes...\n");
24489         }
24490  
24491         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24492 diff -NurpP --minimal linux-2.6.37/mm/page_alloc.c linux-2.6.37-vs2.3.0.37-rc2/mm/page_alloc.c
24493 --- linux-2.6.37/mm/page_alloc.c        2011-01-05 21:50:40.000000000 +0100
24494 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/page_alloc.c 2011-01-05 22:30:43.000000000 +0100
24495 @@ -53,6 +53,8 @@
24496  #include <linux/compaction.h>
24497  #include <trace/events/kmem.h>
24498  #include <linux/ftrace_event.h>
24499 +#include <linux/vs_base.h>
24500 +#include <linux/vs_limit.h>
24501  
24502  #include <asm/tlbflush.h>
24503  #include <asm/div64.h>
24504 @@ -2335,6 +2337,9 @@ void si_meminfo(struct sysinfo *val)
24505         val->totalhigh = totalhigh_pages;
24506         val->freehigh = nr_free_highpages();
24507         val->mem_unit = PAGE_SIZE;
24508 +
24509 +       if (vx_flags(VXF_VIRT_MEM, 0))
24510 +               vx_vsi_meminfo(val);
24511  }
24512  
24513  EXPORT_SYMBOL(si_meminfo);
24514 @@ -2355,6 +2360,9 @@ void si_meminfo_node(struct sysinfo *val
24515         val->freehigh = 0;
24516  #endif
24517         val->mem_unit = PAGE_SIZE;
24518 +
24519 +       if (vx_flags(VXF_VIRT_MEM, 0))
24520 +               vx_vsi_meminfo(val);
24521  }
24522  #endif
24523  
24524 diff -NurpP --minimal linux-2.6.37/mm/rmap.c linux-2.6.37-vs2.3.0.37-rc2/mm/rmap.c
24525 --- linux-2.6.37/mm/rmap.c      2011-01-05 21:50:40.000000000 +0100
24526 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/rmap.c       2010-11-23 02:09:41.000000000 +0100
24527 @@ -57,6 +57,7 @@
24528  #include <linux/mmu_notifier.h>
24529  #include <linux/migrate.h>
24530  #include <linux/hugetlb.h>
24531 +#include <linux/vs_memory.h>
24532  
24533  #include <asm/tlbflush.h>
24534  
24535 diff -NurpP --minimal linux-2.6.37/mm/shmem.c linux-2.6.37-vs2.3.0.37-rc2/mm/shmem.c
24536 --- linux-2.6.37/mm/shmem.c     2011-01-05 21:50:40.000000000 +0100
24537 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/shmem.c      2010-11-23 02:09:41.000000000 +0100
24538 @@ -1816,7 +1816,7 @@ static int shmem_statfs(struct dentry *d
24539  {
24540         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24541  
24542 -       buf->f_type = TMPFS_MAGIC;
24543 +       buf->f_type = TMPFS_SUPER_MAGIC;
24544         buf->f_bsize = PAGE_CACHE_SIZE;
24545         buf->f_namelen = NAME_MAX;
24546         if (sbinfo->max_blocks) {
24547 @@ -2378,7 +2378,7 @@ int shmem_fill_super(struct super_block 
24548         sb->s_maxbytes = SHMEM_MAX_BYTES;
24549         sb->s_blocksize = PAGE_CACHE_SIZE;
24550         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24551 -       sb->s_magic = TMPFS_MAGIC;
24552 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24553         sb->s_op = &shmem_ops;
24554         sb->s_time_gran = 1;
24555  #ifdef CONFIG_TMPFS_POSIX_ACL
24556 diff -NurpP --minimal linux-2.6.37/mm/slab.c linux-2.6.37-vs2.3.0.37-rc2/mm/slab.c
24557 --- linux-2.6.37/mm/slab.c      2011-01-05 21:50:40.000000000 +0100
24558 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/slab.c       2010-11-23 02:09:41.000000000 +0100
24559 @@ -407,6 +407,8 @@ static void kmem_list3_init(struct kmem_
24560  #define STATS_INC_FREEMISS(x)  do { } while (0)
24561  #endif
24562  
24563 +#include "slab_vs.h"
24564 +
24565  #if DEBUG
24566  
24567  /*
24568 @@ -3346,6 +3348,7 @@ retry:
24569  
24570         obj = slab_get_obj(cachep, slabp, nodeid);
24571         check_slabp(cachep, slabp);
24572 +       vx_slab_alloc(cachep, flags);
24573         l3->free_objects--;
24574         /* move slabp to correct slabp list: */
24575         list_del(&slabp->list);
24576 @@ -3423,6 +3426,7 @@ __cache_alloc_node(struct kmem_cache *ca
24577         /* ___cache_alloc_node can fall back to other nodes */
24578         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24579    out:
24580 +       vx_slab_alloc(cachep, flags);
24581         local_irq_restore(save_flags);
24582         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24583         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24584 @@ -3609,6 +3613,7 @@ static inline void __cache_free(struct k
24585         check_irq_off();
24586         kmemleak_free_recursive(objp, cachep->flags);
24587         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
24588 +       vx_slab_free(cachep);
24589  
24590         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24591  
24592 diff -NurpP --minimal linux-2.6.37/mm/slab_vs.h linux-2.6.37-vs2.3.0.37-rc2/mm/slab_vs.h
24593 --- linux-2.6.37/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
24594 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/slab_vs.h    2010-11-23 02:09:41.000000000 +0100
24595 @@ -0,0 +1,29 @@
24596 +
24597 +#include <linux/vserver/context.h>
24598 +
24599 +#include <linux/vs_context.h>
24600 +
24601 +static inline
24602 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24603 +{
24604 +       int what = gfp_zone(cachep->gfpflags);
24605 +       struct vx_info *vxi = current_vx_info();
24606 +
24607 +       if (!vxi)
24608 +               return;
24609 +
24610 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24611 +}
24612 +
24613 +static inline
24614 +void vx_slab_free(struct kmem_cache *cachep)
24615 +{
24616 +       int what = gfp_zone(cachep->gfpflags);
24617 +       struct vx_info *vxi = current_vx_info();
24618 +
24619 +       if (!vxi)
24620 +               return;
24621 +
24622 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24623 +}
24624 +
24625 diff -NurpP --minimal linux-2.6.37/mm/swapfile.c linux-2.6.37-vs2.3.0.37-rc2/mm/swapfile.c
24626 --- linux-2.6.37/mm/swapfile.c  2011-01-05 21:50:40.000000000 +0100
24627 +++ linux-2.6.37-vs2.3.0.37-rc2/mm/swapfile.c   2010-11-23 02:09:41.000000000 +0100
24628 @@ -36,6 +36,8 @@
24629  #include <asm/tlbflush.h>
24630  #include <linux/swapops.h>
24631  #include <linux/page_cgroup.h>
24632 +#include <linux/vs_base.h>
24633 +#include <linux/vs_memory.h>
24634  
24635  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24636                                  unsigned char);
24637 @@ -1773,6 +1775,16 @@ static int swap_show(struct seq_file *sw
24638  
24639         if (si == SEQ_START_TOKEN) {
24640                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24641 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24642 +                       struct sysinfo si;
24643 +
24644 +                       vx_vsi_swapinfo(&si);
24645 +                       if (si.totalswap < (1 << 10))
24646 +                               return 0;
24647 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24648 +                               "hdv0", "partition", si.totalswap >> 10,
24649 +                               (si.totalswap - si.freeswap) >> 10, -1);
24650 +               }
24651                 return 0;
24652         }
24653  
24654 @@ -2178,6 +2190,8 @@ void si_swapinfo(struct sysinfo *val)
24655         val->freeswap = nr_swap_pages + nr_to_be_unused;
24656         val->totalswap = total_swap_pages + nr_to_be_unused;
24657         spin_unlock(&swap_lock);
24658 +       if (vx_flags(VXF_VIRT_MEM, 0))
24659 +               vx_vsi_swapinfo(val);
24660  }
24661  
24662  /*
24663 diff -NurpP --minimal linux-2.6.37/net/core/dev.c linux-2.6.37-vs2.3.0.37-rc2/net/core/dev.c
24664 --- linux-2.6.37/net/core/dev.c 2011-01-05 21:50:41.000000000 +0100
24665 +++ linux-2.6.37-vs2.3.0.37-rc2/net/core/dev.c  2010-11-23 02:09:41.000000000 +0100
24666 @@ -127,6 +127,7 @@
24667  #include <linux/in.h>
24668  #include <linux/jhash.h>
24669  #include <linux/random.h>
24670 +#include <linux/vs_inet.h>
24671  #include <trace/events/napi.h>
24672  #include <trace/events/net.h>
24673  #include <trace/events/skb.h>
24674 @@ -608,7 +609,8 @@ struct net_device *__dev_get_by_name(str
24675         struct hlist_head *head = dev_name_hash(net, name);
24676  
24677         hlist_for_each_entry(dev, p, head, name_hlist)
24678 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24679 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24680 +                   nx_dev_visible(current_nx_info(), dev))
24681                         return dev;
24682  
24683         return NULL;
24684 @@ -634,7 +636,8 @@ struct net_device *dev_get_by_name_rcu(s
24685         struct hlist_head *head = dev_name_hash(net, name);
24686  
24687         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24688 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24689 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24690 +                   nx_dev_visible(current_nx_info(), dev))
24691                         return dev;
24692  
24693         return NULL;
24694 @@ -685,7 +688,8 @@ struct net_device *__dev_get_by_index(st
24695         struct hlist_head *head = dev_index_hash(net, ifindex);
24696  
24697         hlist_for_each_entry(dev, p, head, index_hlist)
24698 -               if (dev->ifindex == ifindex)
24699 +               if ((dev->ifindex == ifindex) &&
24700 +                   nx_dev_visible(current_nx_info(), dev))
24701                         return dev;
24702  
24703         return NULL;
24704 @@ -710,7 +714,8 @@ struct net_device *dev_get_by_index_rcu(
24705         struct hlist_head *head = dev_index_hash(net, ifindex);
24706  
24707         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
24708 -               if (dev->ifindex == ifindex)
24709 +               if ((dev->ifindex == ifindex) &&
24710 +                   nx_dev_visible(current_nx_info(), dev))
24711                         return dev;
24712  
24713         return NULL;
24714 @@ -763,10 +768,12 @@ struct net_device *dev_getbyhwaddr(struc
24715  
24716         ASSERT_RTNL();
24717  
24718 -       for_each_netdev(net, dev)
24719 +       for_each_netdev(net, dev) {
24720                 if (dev->type == type &&
24721 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24722 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24723 +                   nx_dev_visible(current_nx_info(), dev))
24724                         return dev;
24725 +       }
24726  
24727         return NULL;
24728  }
24729 @@ -777,9 +784,11 @@ struct net_device *__dev_getfirstbyhwtyp
24730         struct net_device *dev;
24731  
24732         ASSERT_RTNL();
24733 -       for_each_netdev(net, dev)
24734 -               if (dev->type == type)
24735 +       for_each_netdev(net, dev) {
24736 +               if ((dev->type == type) &&
24737 +                   nx_dev_visible(current_nx_info(), dev))
24738                         return dev;
24739 +       }
24740  
24741         return NULL;
24742  }
24743 @@ -897,6 +906,8 @@ static int __dev_alloc_name(struct net *
24744                                 continue;
24745                         if (i < 0 || i >= max_netdevices)
24746                                 continue;
24747 +                       if (!nx_dev_visible(current_nx_info(), d))
24748 +                               continue;
24749  
24750                         /*  avoid cases where sscanf is not exact inverse of printf */
24751                         snprintf(buf, IFNAMSIZ, name, i);
24752 @@ -3746,6 +3757,8 @@ static int dev_ifconf(struct net *net, c
24753  
24754         total = 0;
24755         for_each_netdev(net, dev) {
24756 +               if (!nx_dev_visible(current_nx_info(), dev))
24757 +                       continue;
24758                 for (i = 0; i < NPROTO; i++) {
24759                         if (gifconf_list[i]) {
24760                                 int done;
24761 @@ -3817,6 +3830,10 @@ static void dev_seq_printf_stats(struct 
24762         struct rtnl_link_stats64 temp;
24763         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24764  
24765 +       /* device visible inside network context? */
24766 +       if (!nx_dev_visible(current_nx_info(), dev))
24767 +               return;
24768 +
24769         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24770                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24771                    dev->name, stats->rx_bytes, stats->rx_packets,
24772 diff -NurpP --minimal linux-2.6.37/net/core/rtnetlink.c linux-2.6.37-vs2.3.0.37-rc2/net/core/rtnetlink.c
24773 --- linux-2.6.37/net/core/rtnetlink.c   2011-01-05 21:50:41.000000000 +0100
24774 +++ linux-2.6.37-vs2.3.0.37-rc2/net/core/rtnetlink.c    2010-11-23 02:09:41.000000000 +0100
24775 @@ -891,6 +891,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24776                 hlist_for_each_entry(dev, node, head, index_hlist) {
24777                         if (idx < s_idx)
24778                                 goto cont;
24779 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24780 +                               continue;
24781                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24782                                              NETLINK_CB(cb->skb).pid,
24783                                              cb->nlh->nlmsg_seq, 0,
24784 @@ -1607,6 +1609,9 @@ void rtmsg_ifinfo(int type, struct net_d
24785         struct sk_buff *skb;
24786         int err = -ENOBUFS;
24787  
24788 +       if (!nx_dev_visible(current_nx_info(), dev))
24789 +               return;
24790 +
24791         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
24792         if (skb == NULL)
24793                 goto errout;
24794 diff -NurpP --minimal linux-2.6.37/net/core/sock.c linux-2.6.37-vs2.3.0.37-rc2/net/core/sock.c
24795 --- linux-2.6.37/net/core/sock.c        2011-01-05 21:50:41.000000000 +0100
24796 +++ linux-2.6.37-vs2.3.0.37-rc2/net/core/sock.c 2011-01-05 22:30:43.000000000 +0100
24797 @@ -127,6 +127,10 @@
24798  #include <net/cls_cgroup.h>
24799  
24800  #include <linux/filter.h>
24801 +#include <linux/vs_socket.h>
24802 +#include <linux/vs_limit.h>
24803 +#include <linux/vs_context.h>
24804 +#include <linux/vs_network.h>
24805  
24806  #ifdef CONFIG_INET
24807  #include <net/tcp.h>
24808 @@ -1069,6 +1073,8 @@ static struct sock *sk_prot_alloc(struct
24809                         goto out_free_sec;
24810                 sk_tx_queue_clear(sk);
24811         }
24812 +               sock_vx_init(sk);
24813 +               sock_nx_init(sk);
24814  
24815         return sk;
24816  
24817 @@ -1168,6 +1174,11 @@ static void __sk_free(struct sock *sk)
24818                 put_cred(sk->sk_peer_cred);
24819         put_pid(sk->sk_peer_pid);
24820         put_net(sock_net(sk));
24821 +       vx_sock_dec(sk);
24822 +       clr_vx_info(&sk->sk_vx_info);
24823 +       sk->sk_xid = -1;
24824 +       clr_nx_info(&sk->sk_nx_info);
24825 +       sk->sk_nid = -1;
24826         sk_prot_free(sk->sk_prot_creator, sk);
24827  }
24828  
24829 @@ -1215,6 +1226,8 @@ struct sock *sk_clone(const struct sock 
24830  
24831                 /* SANITY */
24832                 get_net(sock_net(newsk));
24833 +               sock_vx_init(newsk);
24834 +               sock_nx_init(newsk);
24835                 sk_node_init(&newsk->sk_node);
24836                 sock_lock_init(newsk);
24837                 bh_lock_sock(newsk);
24838 @@ -1270,6 +1283,12 @@ struct sock *sk_clone(const struct sock 
24839                 smp_wmb();
24840                 atomic_set(&newsk->sk_refcnt, 2);
24841  
24842 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24843 +               newsk->sk_xid = sk->sk_xid;
24844 +               vx_sock_inc(newsk);
24845 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24846 +               newsk->sk_nid = sk->sk_nid;
24847 +
24848                 /*
24849                  * Increment the counter in the same struct proto as the master
24850                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24851 @@ -2016,6 +2035,12 @@ void sock_init_data(struct socket *sock,
24852  
24853         sk->sk_stamp = ktime_set(-1L, 0);
24854  
24855 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24856 +       sk->sk_xid = vx_current_xid();
24857 +       vx_sock_inc(sk);
24858 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24859 +       sk->sk_nid = nx_current_nid();
24860 +
24861         /*
24862          * Before updating sk_refcnt, we must commit prior changes to memory
24863          * (Documentation/RCU/rculist_nulls.txt for details)
24864 diff -NurpP --minimal linux-2.6.37/net/ipv4/af_inet.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/af_inet.c
24865 --- linux-2.6.37/net/ipv4/af_inet.c     2011-01-05 21:50:41.000000000 +0100
24866 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/af_inet.c      2010-11-23 02:09:41.000000000 +0100
24867 @@ -116,6 +116,7 @@
24868  #ifdef CONFIG_IP_MROUTE
24869  #include <linux/mroute.h>
24870  #endif
24871 +#include <linux/vs_limit.h>
24872  
24873  
24874  /* The inetsw table contains everything that inet_create needs to
24875 @@ -325,9 +326,13 @@ lookup_protocol:
24876         }
24877  
24878         err = -EPERM;
24879 +       if ((protocol == IPPROTO_ICMP) &&
24880 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24881 +               goto override;
24882 +
24883         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24884                 goto out_rcu_unlock;
24885 -
24886 +override:
24887         err = -EAFNOSUPPORT;
24888         if (!inet_netns_ok(net, protocol))
24889                 goto out_rcu_unlock;
24890 @@ -451,6 +456,7 @@ int inet_bind(struct socket *sock, struc
24891         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24892         struct sock *sk = sock->sk;
24893         struct inet_sock *inet = inet_sk(sk);
24894 +       struct nx_v4_sock_addr nsa;
24895         unsigned short snum;
24896         int chk_addr_ret;
24897         int err;
24898 @@ -464,7 +470,11 @@ int inet_bind(struct socket *sock, struc
24899         if (addr_len < sizeof(struct sockaddr_in))
24900                 goto out;
24901  
24902 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24903 +       err = v4_map_sock_addr(inet, addr, &nsa);
24904 +       if (err)
24905 +               goto out;
24906 +
24907 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24908  
24909         /* Not specified by any standard per-se, however it breaks too
24910          * many applications when removed.  It is unfortunate since
24911 @@ -476,7 +486,7 @@ int inet_bind(struct socket *sock, struc
24912         err = -EADDRNOTAVAIL;
24913         if (!sysctl_ip_nonlocal_bind &&
24914             !(inet->freebind || inet->transparent) &&
24915 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24916 +           nsa.saddr != htonl(INADDR_ANY) &&
24917             chk_addr_ret != RTN_LOCAL &&
24918             chk_addr_ret != RTN_MULTICAST &&
24919             chk_addr_ret != RTN_BROADCAST)
24920 @@ -501,7 +511,7 @@ int inet_bind(struct socket *sock, struc
24921         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24922                 goto out_release_sock;
24923  
24924 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24925 +       v4_set_sock_addr(inet, &nsa);
24926         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24927                 inet->inet_saddr = 0;  /* Use device */
24928  
24929 @@ -703,11 +713,13 @@ int inet_getname(struct socket *sock, st
24930                      peer == 1))
24931                         return -ENOTCONN;
24932                 sin->sin_port = inet->inet_dport;
24933 -               sin->sin_addr.s_addr = inet->inet_daddr;
24934 +               sin->sin_addr.s_addr =
24935 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24936         } else {
24937                 __be32 addr = inet->inet_rcv_saddr;
24938                 if (!addr)
24939                         addr = inet->inet_saddr;
24940 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24941                 sin->sin_port = inet->inet_sport;
24942                 sin->sin_addr.s_addr = addr;
24943         }
24944 diff -NurpP --minimal linux-2.6.37/net/ipv4/devinet.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/devinet.c
24945 --- linux-2.6.37/net/ipv4/devinet.c     2011-01-05 21:50:41.000000000 +0100
24946 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/devinet.c      2010-11-23 02:09:41.000000000 +0100
24947 @@ -420,6 +420,7 @@ struct in_device *inetdev_by_index(struc
24948  }
24949  EXPORT_SYMBOL(inetdev_by_index);
24950  
24951 +
24952  /* Called only from RTNL semaphored context. No locks. */
24953  
24954  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24955 @@ -660,6 +661,8 @@ int devinet_ioctl(struct net *net, unsig
24956  
24957         in_dev = __in_dev_get_rtnl(dev);
24958         if (in_dev) {
24959 +               struct nx_info *nxi = current_nx_info();
24960 +
24961                 if (tryaddrmatch) {
24962                         /* Matthias Andree */
24963                         /* compare label and address (4.4BSD style) */
24964 @@ -668,6 +671,8 @@ int devinet_ioctl(struct net *net, unsig
24965                            This is checked above. */
24966                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24967                              ifap = &ifa->ifa_next) {
24968 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24969 +                                       continue;
24970                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24971                                     sin_orig.sin_addr.s_addr ==
24972                                                         ifa->ifa_address) {
24973 @@ -680,9 +685,12 @@ int devinet_ioctl(struct net *net, unsig
24974                    comparing just the label */
24975                 if (!ifa) {
24976                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24977 -                            ifap = &ifa->ifa_next)
24978 +                            ifap = &ifa->ifa_next) {
24979 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24980 +                                       continue;
24981                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24982                                         break;
24983 +                       }
24984                 }
24985         }
24986  
24987 @@ -834,6 +842,8 @@ static int inet_gifconf(struct net_devic
24988                 goto out;
24989  
24990         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24991 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24992 +                       continue;
24993                 if (!buf) {
24994                         done += sizeof(ifr);
24995                         continue;
24996 @@ -1183,6 +1193,7 @@ static int inet_dump_ifaddr(struct sk_bu
24997         struct net_device *dev;
24998         struct in_device *in_dev;
24999         struct in_ifaddr *ifa;
25000 +       struct sock *sk = skb->sk;
25001         struct hlist_head *head;
25002         struct hlist_node *node;
25003  
25004 @@ -1205,6 +1216,8 @@ static int inet_dump_ifaddr(struct sk_bu
25005  
25006                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
25007                              ifa = ifa->ifa_next, ip_idx++) {
25008 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
25009 +                               continue;
25010                                 if (ip_idx < s_ip_idx)
25011                                         continue;
25012                                 if (inet_fill_ifaddr(skb, ifa,
25013 diff -NurpP --minimal linux-2.6.37/net/ipv4/fib_hash.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/fib_hash.c
25014 --- linux-2.6.37/net/ipv4/fib_hash.c    2011-01-05 21:50:41.000000000 +0100
25015 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/fib_hash.c     2010-11-23 02:09:41.000000000 +0100
25016 @@ -1080,7 +1080,7 @@ static int fib_seq_show(struct seq_file 
25017         prefix  = f->fn_key;
25018         mask    = FZ_MASK(iter->zone);
25019         flags   = fib_flag_trans(fa->fa_type, mask, fi);
25020 -       if (fi)
25021 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
25022                 seq_printf(seq,
25023                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
25024                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
25025 diff -NurpP --minimal linux-2.6.37/net/ipv4/inet_connection_sock.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/inet_connection_sock.c
25026 --- linux-2.6.37/net/ipv4/inet_connection_sock.c        2010-10-21 13:07:58.000000000 +0200
25027 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/inet_connection_sock.c 2010-11-23 02:09:41.000000000 +0100
25028 @@ -52,10 +52,40 @@ void inet_get_local_port_range(int *low,
25029  }
25030  EXPORT_SYMBOL(inet_get_local_port_range);
25031  
25032 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25033 +{
25034 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
25035 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
25036 +
25037 +       if (inet_v6_ipv6only(sk2))
25038 +               return 0;
25039 +
25040 +       if (sk1_rcv_saddr &&
25041 +           sk2_rcv_saddr &&
25042 +           sk1_rcv_saddr == sk2_rcv_saddr)
25043 +               return 1;
25044 +
25045 +       if (sk1_rcv_saddr &&
25046 +           !sk2_rcv_saddr &&
25047 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
25048 +               return 1;
25049 +
25050 +       if (sk2_rcv_saddr &&
25051 +           !sk1_rcv_saddr &&
25052 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
25053 +               return 1;
25054 +
25055 +       if (!sk1_rcv_saddr &&
25056 +           !sk2_rcv_saddr &&
25057 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
25058 +               return 1;
25059 +
25060 +       return 0;
25061 +}
25062 +
25063  int inet_csk_bind_conflict(const struct sock *sk,
25064                            const struct inet_bind_bucket *tb)
25065  {
25066 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
25067         struct sock *sk2;
25068         struct hlist_node *node;
25069         int reuse = sk->sk_reuse;
25070 @@ -75,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25071                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25072                         if (!reuse || !sk2->sk_reuse ||
25073                             sk2->sk_state == TCP_LISTEN) {
25074 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
25075 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
25076 -                                   sk2_rcv_saddr == sk_rcv_saddr)
25077 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25078                                         break;
25079                         }
25080                 }
25081 diff -NurpP --minimal linux-2.6.37/net/ipv4/inet_diag.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/inet_diag.c
25082 --- linux-2.6.37/net/ipv4/inet_diag.c   2011-01-05 21:50:42.000000000 +0100
25083 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/inet_diag.c    2010-11-23 02:09:41.000000000 +0100
25084 @@ -33,6 +33,8 @@
25085  #include <linux/stddef.h>
25086  
25087  #include <linux/inet_diag.h>
25088 +#include <linux/vs_network.h>
25089 +#include <linux/vs_inet.h>
25090  
25091  static const struct inet_diag_handler **inet_diag_table;
25092  
25093 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25094  
25095         r->id.idiag_sport = inet->inet_sport;
25096         r->id.idiag_dport = inet->inet_dport;
25097 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25098 -       r->id.idiag_dst[0] = inet->inet_daddr;
25099 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25100 +               inet->inet_rcv_saddr);
25101 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25102 +               inet->inet_daddr);
25103  
25104  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25105         if (r->idiag_family == AF_INET6) {
25106 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25107         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25108         r->id.idiag_sport     = tw->tw_sport;
25109         r->id.idiag_dport     = tw->tw_dport;
25110 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25111 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25112 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25113 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25114         r->idiag_state        = tw->tw_substate;
25115         r->idiag_timer        = 3;
25116         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25117 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25118         err = -EINVAL;
25119  
25120         if (req->idiag_family == AF_INET) {
25121 +               /* TODO: lback */
25122                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25123                                  req->id.idiag_dport, req->id.idiag_src[0],
25124                                  req->id.idiag_sport, req->id.idiag_if);
25125 @@ -507,6 +512,7 @@ static int inet_csk_diag_dump(struct soc
25126                 } else
25127  #endif
25128                 {
25129 +                       /* TODO: lback */
25130                         entry.saddr = &inet->inet_rcv_saddr;
25131                         entry.daddr = &inet->inet_daddr;
25132                 }
25133 @@ -545,6 +551,7 @@ static int inet_twsk_diag_dump(struct in
25134                 } else
25135  #endif
25136                 {
25137 +                       /* TODO: lback */
25138                         entry.saddr = &tw->tw_rcv_saddr;
25139                         entry.daddr = &tw->tw_daddr;
25140                 }
25141 @@ -591,8 +598,8 @@ static int inet_diag_fill_req(struct sk_
25142  
25143         r->id.idiag_sport = inet->inet_sport;
25144         r->id.idiag_dport = ireq->rmt_port;
25145 -       r->id.idiag_src[0] = ireq->loc_addr;
25146 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25147 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25148 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25149         r->idiag_expires = jiffies_to_msecs(tmo);
25150         r->idiag_rqueue = 0;
25151         r->idiag_wqueue = 0;
25152 @@ -663,6 +670,7 @@ static int inet_diag_dump_reqs(struct sk
25153                                 continue;
25154  
25155                         if (bc) {
25156 +                               /* TODO: lback */
25157                                 entry.saddr =
25158  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25159                                         (entry.family == AF_INET6) ?
25160 @@ -733,6 +741,8 @@ static int inet_diag_dump(struct sk_buff
25161                         sk_nulls_for_each(sk, node, &ilb->head) {
25162                                 struct inet_sock *inet = inet_sk(sk);
25163  
25164 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25165 +                                       continue;
25166                                 if (num < s_num) {
25167                                         num++;
25168                                         continue;
25169 @@ -799,6 +809,8 @@ skip_listen_ht:
25170                 sk_nulls_for_each(sk, node, &head->chain) {
25171                         struct inet_sock *inet = inet_sk(sk);
25172  
25173 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25174 +                               continue;
25175                         if (num < s_num)
25176                                 goto next_normal;
25177                         if (!(r->idiag_states & (1 << sk->sk_state)))
25178 @@ -823,6 +835,8 @@ next_normal:
25179                         inet_twsk_for_each(tw, node,
25180                                     &head->twchain) {
25181  
25182 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25183 +                                       continue;
25184                                 if (num < s_num)
25185                                         goto next_dying;
25186                                 if (r->id.idiag_sport != tw->tw_sport &&
25187 diff -NurpP --minimal linux-2.6.37/net/ipv4/inet_hashtables.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/inet_hashtables.c
25188 --- linux-2.6.37/net/ipv4/inet_hashtables.c     2011-01-05 21:50:42.000000000 +0100
25189 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/inet_hashtables.c      2011-01-05 22:30:43.000000000 +0100
25190 @@ -21,6 +21,7 @@
25191  
25192  #include <net/inet_connection_sock.h>
25193  #include <net/inet_hashtables.h>
25194 +#include <net/route.h>
25195  #include <net/ip.h>
25196  
25197  /*
25198 @@ -155,6 +156,11 @@ static inline int compute_score(struct s
25199                         if (rcv_saddr != daddr)
25200                                 return -1;
25201                         score += 2;
25202 +               } else {
25203 +                       /* block non nx_info ips */
25204 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25205 +                               daddr, NXA_MASK_BIND))
25206 +                               return -1;
25207                 }
25208                 if (sk->sk_bound_dev_if) {
25209                         if (sk->sk_bound_dev_if != dif)
25210 @@ -172,7 +178,6 @@ static inline int compute_score(struct s
25211   * wildcarded during the search since they can never be otherwise.
25212   */
25213  
25214 -
25215  struct sock *__inet_lookup_listener(struct net *net,
25216                                     struct inet_hashinfo *hashinfo,
25217                                     const __be32 daddr, const unsigned short hnum,
25218 @@ -195,6 +200,7 @@ begin:
25219                         hiscore = score;
25220                 }
25221         }
25222 +
25223         /*
25224          * if the nulls value we got at the end of this lookup is
25225          * not the expected one, we must restart lookup.
25226 diff -NurpP --minimal linux-2.6.37/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/netfilter/nf_nat_helper.c
25227 --- linux-2.6.37/net/ipv4/netfilter/nf_nat_helper.c     2011-01-05 21:50:42.000000000 +0100
25228 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/netfilter/nf_nat_helper.c      2010-11-23 02:09:41.000000000 +0100
25229 @@ -20,6 +20,7 @@
25230  #include <net/route.h>
25231  
25232  #include <linux/netfilter_ipv4.h>
25233 +#include <net/route.h>
25234  #include <net/netfilter/nf_conntrack.h>
25235  #include <net/netfilter/nf_conntrack_helper.h>
25236  #include <net/netfilter/nf_conntrack_ecache.h>
25237 diff -NurpP --minimal linux-2.6.37/net/ipv4/netfilter.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/netfilter.c
25238 --- linux-2.6.37/net/ipv4/netfilter.c   2010-10-21 13:07:58.000000000 +0200
25239 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/netfilter.c    2010-11-23 02:09:41.000000000 +0100
25240 @@ -5,7 +5,7 @@
25241  #include <linux/ip.h>
25242  #include <linux/skbuff.h>
25243  #include <linux/gfp.h>
25244 -#include <net/route.h>
25245 +// #include <net/route.h>
25246  #include <net/xfrm.h>
25247  #include <net/ip.h>
25248  #include <net/netfilter/nf_queue.h>
25249 diff -NurpP --minimal linux-2.6.37/net/ipv4/raw.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/raw.c
25250 --- linux-2.6.37/net/ipv4/raw.c 2011-01-05 21:50:42.000000000 +0100
25251 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/raw.c  2010-11-23 02:09:41.000000000 +0100
25252 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
25253  
25254                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25255                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25256 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25257 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25258                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25259                         goto found; /* gotcha */
25260         }
25261 @@ -383,6 +383,12 @@ static int raw_send_hdrinc(struct sock *
25262                 icmp_out_count(net, ((struct icmphdr *)
25263                         skb_transport_header(skb))->type);
25264  
25265 +       err = -EPERM;
25266 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25267 +               sk->sk_nx_info &&
25268 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25269 +               goto error_free;
25270 +
25271         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25272                       rt->dst.dev, dst_output);
25273         if (err > 0)
25274 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
25275                 }
25276  
25277                 security_sk_classify_flow(sk, &fl);
25278 +               if (sk->sk_nx_info) {
25279 +                       err = ip_v4_find_src(sock_net(sk),
25280 +                               sk->sk_nx_info, &rt, &fl);
25281 +
25282 +                       if (err)
25283 +                               goto done;
25284 +               }
25285                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
25286         }
25287         if (err)
25288 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
25289  {
25290         struct inet_sock *inet = inet_sk(sk);
25291         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25292 +       struct nx_v4_sock_addr nsa = { 0 };
25293         int ret = -EINVAL;
25294         int chk_addr_ret;
25295  
25296         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25297                 goto out;
25298 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25299 +       v4_map_sock_addr(inet, addr, &nsa);
25300 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25301         ret = -EADDRNOTAVAIL;
25302 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25303 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25304             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25305                 goto out;
25306 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25307 +       v4_set_sock_addr(inet, &nsa);
25308         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25309                 inet->inet_saddr = 0;  /* Use device */
25310         sk_dst_reset(sk);
25311 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
25312         /* Copy the address. */
25313         if (sin) {
25314                 sin->sin_family = AF_INET;
25315 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25316 +               sin->sin_addr.s_addr =
25317 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25318                 sin->sin_port = 0;
25319                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25320         }
25321 @@ -875,7 +891,8 @@ static struct sock *raw_get_first(struct
25322                 struct hlist_node *node;
25323  
25324                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25325 -                       if (sock_net(sk) == seq_file_net(seq))
25326 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25327 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25328                                 goto found;
25329         }
25330         sk = NULL;
25331 @@ -891,7 +908,8 @@ static struct sock *raw_get_next(struct 
25332                 sk = sk_next(sk);
25333  try_again:
25334                 ;
25335 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25336 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25337 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25338  
25339         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25340                 sk = sk_head(&state->h->ht[state->bucket]);
25341 @@ -950,7 +968,10 @@ static void raw_sock_seq_show(struct seq
25342  
25343         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
25344                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
25345 -               i, src, srcp, dest, destp, sp->sk_state,
25346 +               i,
25347 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25348 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25349 +               sp->sk_state,
25350                 sk_wmem_alloc_get(sp),
25351                 sk_rmem_alloc_get(sp),
25352                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25353 diff -NurpP --minimal linux-2.6.37/net/ipv4/tcp.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/tcp.c
25354 --- linux-2.6.37/net/ipv4/tcp.c 2011-01-05 21:50:42.000000000 +0100
25355 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/tcp.c  2011-01-05 22:30:43.000000000 +0100
25356 @@ -266,6 +266,7 @@
25357  #include <linux/crypto.h>
25358  #include <linux/time.h>
25359  #include <linux/slab.h>
25360 +#include <linux/in.h>
25361  
25362  #include <net/icmp.h>
25363  #include <net/tcp.h>
25364 diff -NurpP --minimal linux-2.6.37/net/ipv4/tcp_ipv4.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/tcp_ipv4.c
25365 --- linux-2.6.37/net/ipv4/tcp_ipv4.c    2011-01-05 21:50:42.000000000 +0100
25366 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/tcp_ipv4.c     2011-01-05 22:33:32.000000000 +0100
25367 @@ -2018,6 +2018,12 @@ static void *listening_get_next(struct s
25368                 req = req->dl_next;
25369                 while (1) {
25370                         while (req) {
25371 +                               vxdprintk(VXD_CBIT(net, 6),
25372 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25373 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25374 +                               if (req->sk &&
25375 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25376 +                                       continue;
25377                                 if (req->rsk_ops->family == st->family) {
25378                                         cur = req;
25379                                         goto out;
25380 @@ -2043,6 +2049,10 @@ get_req:
25381         }
25382  get_sk:
25383         sk_nulls_for_each_from(sk, node) {
25384 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25385 +                       sk, sk->sk_nid, nx_current_nid());
25386 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25387 +                       continue;
25388                 if (!net_eq(sock_net(sk), net))
25389                         continue;
25390                 if (sk->sk_family == st->family) {
25391 @@ -2119,6 +2129,11 @@ static void *established_get_first(struc
25392  
25393                 spin_lock_bh(lock);
25394                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25395 +                       vxdprintk(VXD_CBIT(net, 6),
25396 +                               "sk,egf: %p [#%d] (from %d)",
25397 +                               sk, sk->sk_nid, nx_current_nid());
25398 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25399 +                               continue;
25400                         if (sk->sk_family != st->family ||
25401                             !net_eq(sock_net(sk), net)) {
25402                                 continue;
25403 @@ -2129,6 +2144,11 @@ static void *established_get_first(struc
25404                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25405                 inet_twsk_for_each(tw, node,
25406                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25407 +                       vxdprintk(VXD_CBIT(net, 6),
25408 +                               "tw: %p [#%d] (from %d)",
25409 +                               tw, tw->tw_nid, nx_current_nid());
25410 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25411 +                               continue;
25412                         if (tw->tw_family != st->family ||
25413                             !net_eq(twsk_net(tw), net)) {
25414                                 continue;
25415 @@ -2158,7 +2178,9 @@ static void *established_get_next(struct
25416                 tw = cur;
25417                 tw = tw_next(tw);
25418  get_tw:
25419 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25420 +               while (tw && (tw->tw_family != st->family ||
25421 +                       !net_eq(twsk_net(tw), net) ||
25422 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25423                         tw = tw_next(tw);
25424                 }
25425                 if (tw) {
25426 @@ -2182,6 +2204,11 @@ get_tw:
25427                 sk = sk_nulls_next(sk);
25428  
25429         sk_nulls_for_each_from(sk, node) {
25430 +               vxdprintk(VXD_CBIT(net, 6),
25431 +                       "sk,egn: %p [#%d] (from %d)",
25432 +                       sk, sk->sk_nid, nx_current_nid());
25433 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25434 +                       continue;
25435                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25436                         goto found;
25437         }
25438 @@ -2391,9 +2418,9 @@ static void get_openreq4(struct sock *sk
25439         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25440                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
25441                 i,
25442 -               ireq->loc_addr,
25443 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25444                 ntohs(inet_sk(sk)->inet_sport),
25445 -               ireq->rmt_addr,
25446 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25447                 ntohs(ireq->rmt_port),
25448                 TCP_SYN_RECV,
25449                 0, 0, /* could print option size, but that is af dependent. */
25450 @@ -2445,7 +2472,10 @@ static void get_tcp4_sock(struct sock *s
25451  
25452         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
25453                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
25454 -               i, src, srcp, dest, destp, sk->sk_state,
25455 +               i,
25456 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25457 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25458 +               sk->sk_state,
25459                 tp->write_seq - tp->snd_una,
25460                 rx_queue,
25461                 timer_active,
25462 @@ -2480,7 +2510,10 @@ static void get_timewait4_sock(struct in
25463  
25464         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25465                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
25466 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
25467 +               i,
25468 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25469 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25470 +               tw->tw_substate, 0, 0,
25471                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
25472                 atomic_read(&tw->tw_refcnt), tw, len);
25473  }
25474 diff -NurpP --minimal linux-2.6.37/net/ipv4/tcp_minisocks.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/tcp_minisocks.c
25475 --- linux-2.6.37/net/ipv4/tcp_minisocks.c       2011-01-05 21:50:42.000000000 +0100
25476 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/tcp_minisocks.c        2011-01-05 22:30:43.000000000 +0100
25477 @@ -23,6 +23,9 @@
25478  #include <linux/slab.h>
25479  #include <linux/sysctl.h>
25480  #include <linux/workqueue.h>
25481 +#include <linux/vs_limit.h>
25482 +#include <linux/vs_socket.h>
25483 +#include <linux/vs_context.h>
25484  #include <net/tcp.h>
25485  #include <net/inet_common.h>
25486  #include <net/xfrm.h>
25487 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int 
25488                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25489                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25490  
25491 +               tw->tw_xid              = sk->sk_xid;
25492 +               tw->tw_vx_info          = NULL;
25493 +               tw->tw_nid              = sk->sk_nid;
25494 +               tw->tw_nx_info          = NULL;
25495 +
25496  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25497                 if (tw->tw_family == PF_INET6) {
25498                         struct ipv6_pinfo *np = inet6_sk(sk);
25499 diff -NurpP --minimal linux-2.6.37/net/ipv4/udp.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/udp.c
25500 --- linux-2.6.37/net/ipv4/udp.c 2011-01-05 21:50:42.000000000 +0100
25501 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv4/udp.c  2011-01-05 22:30:43.000000000 +0100
25502 @@ -296,14 +296,7 @@ fail:
25503  }
25504  EXPORT_SYMBOL(udp_lib_get_port);
25505  
25506 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25507 -{
25508 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25509 -
25510 -       return  (!ipv6_only_sock(sk2)  &&
25511 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25512 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25513 -}
25514 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25515  
25516  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25517                                        unsigned int port)
25518 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
25519                         if (inet->inet_rcv_saddr != daddr)
25520                                 return -1;
25521                         score += 2;
25522 +               } else {
25523 +                       /* block non nx_info ips */
25524 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25525 +                               daddr, NXA_MASK_BIND))
25526 +                               return -1;
25527                 }
25528                 if (inet->inet_daddr) {
25529                         if (inet->inet_daddr != saddr)
25530 @@ -441,6 +439,7 @@ exact_match:
25531         return result;
25532  }
25533  
25534 +
25535  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25536   * harder than this. -DaveM
25537   */
25538 @@ -486,6 +485,11 @@ begin:
25539         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25540                 score = compute_score(sk, net, saddr, hnum, sport,
25541                                       daddr, dport, dif);
25542 +               /* FIXME: disabled?
25543 +               if (score == 9) {
25544 +                       result = sk;
25545 +                       break;
25546 +               } else */
25547                 if (score > badness) {
25548                         result = sk;
25549                         badness = score;
25550 @@ -499,6 +503,7 @@ begin:
25551         if (get_nulls_value(node) != slot)
25552                 goto begin;
25553  
25554 +
25555         if (result) {
25556                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
25557                         result = NULL;
25558 @@ -508,6 +513,7 @@ begin:
25559                         goto begin;
25560                 }
25561         }
25562 +
25563         rcu_read_unlock();
25564         return result;
25565  }
25566 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
25567                     udp_sk(s)->udp_port_hash != hnum ||
25568                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25569                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25570 -                   (inet->inet_rcv_saddr &&
25571 -                    inet->inet_rcv_saddr != loc_addr) ||
25572 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25573                     ipv6_only_sock(s) ||
25574                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25575                         continue;
25576 @@ -900,8 +905,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
25577                                                { .sport = inet->inet_sport,
25578                                                  .dport = dport } } };
25579                 struct net *net = sock_net(sk);
25580 +               struct nx_info *nxi = sk->sk_nx_info;
25581  
25582                 security_sk_classify_flow(sk, &fl);
25583 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
25584 +               if (err)
25585 +                       goto out;
25586 +
25587                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
25588                 if (err) {
25589                         if (err == -ENETUNREACH)
25590 @@ -1183,7 +1193,8 @@ try_again:
25591         if (sin) {
25592                 sin->sin_family = AF_INET;
25593                 sin->sin_port = udp_hdr(skb)->source;
25594 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25595 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25596 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25597                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25598         }
25599         if (inet->cmsg_flags)
25600 @@ -1924,6 +1935,8 @@ static struct sock *udp_get_first(struct
25601                 sk_nulls_for_each(sk, node, &hslot->head) {
25602                         if (!net_eq(sock_net(sk), net))
25603                                 continue;
25604 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25605 +                               continue;
25606                         if (sk->sk_family == state->family)
25607                                 goto found;
25608                 }
25609 @@ -1941,7 +1954,9 @@ static struct sock *udp_get_next(struct 
25610  
25611         do {
25612                 sk = sk_nulls_next(sk);
25613 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25614 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25615 +               sk->sk_family != state->family ||
25616 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25617  
25618         if (!sk) {
25619                 if (state->bucket <= state->udp_table->mask)
25620 @@ -2048,7 +2063,10 @@ static void udp4_format_sock(struct sock
25621  
25622         seq_printf(f, "%5d: %08X:%04X %08X:%04X"
25623                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
25624 -               bucket, src, srcp, dest, destp, sp->sk_state,
25625 +               bucket,
25626 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25627 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25628 +               sp->sk_state,
25629                 sk_wmem_alloc_get(sp),
25630                 sk_rmem_alloc_get(sp),
25631                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25632 diff -NurpP --minimal linux-2.6.37/net/ipv6/addrconf.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/addrconf.c
25633 --- linux-2.6.37/net/ipv6/addrconf.c    2011-01-05 21:50:42.000000000 +0100
25634 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/addrconf.c     2011-01-05 22:30:43.000000000 +0100
25635 @@ -87,6 +87,8 @@
25636  
25637  #include <linux/proc_fs.h>
25638  #include <linux/seq_file.h>
25639 +#include <linux/vs_network.h>
25640 +#include <linux/vs_inet6.h>
25641  
25642  /* Set to 3 to get tracing... */
25643  #define ACONF_DEBUG 2
25644 @@ -1124,7 +1126,7 @@ out:
25645  
25646  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25647                        const struct in6_addr *daddr, unsigned int prefs,
25648 -                      struct in6_addr *saddr)
25649 +                      struct in6_addr *saddr, struct nx_info *nxi)
25650  {
25651         struct ipv6_saddr_score scores[2],
25652                                 *score = &scores[0], *hiscore = &scores[1];
25653 @@ -1196,6 +1198,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25654                                                dev->name);
25655                                 continue;
25656                         }
25657 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25658 +                               continue;
25659  
25660                         score->rule = -1;
25661                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25662 @@ -3079,7 +3083,10 @@ static void if6_seq_stop(struct seq_file
25663  static int if6_seq_show(struct seq_file *seq, void *v)
25664  {
25665         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25666 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25667 +
25668 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25669 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25670 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25671                    &ifp->addr,
25672                    ifp->idev->dev->ifindex,
25673                    ifp->prefix_len,
25674 @@ -3585,6 +3592,11 @@ static int in6_dump_addrs(struct inet6_d
25675         struct ifacaddr6 *ifaca;
25676         int err = 1;
25677         int ip_idx = *p_ip_idx;
25678 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25679 +
25680 +       /* disable ipv6 on non v6 guests */
25681 +       if (nxi && !nx_info_has_v6(nxi))
25682 +               return skb->len;
25683  
25684         read_lock_bh(&idev->lock);
25685         switch (type) {
25686 @@ -3595,6 +3607,8 @@ static int in6_dump_addrs(struct inet6_d
25687                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25688                         if (++ip_idx < s_ip_idx)
25689                                 continue;
25690 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25691 +                                       continue;
25692                         err = inet6_fill_ifaddr(skb, ifa,
25693                                                 NETLINK_CB(cb->skb).pid,
25694                                                 cb->nlh->nlmsg_seq,
25695 @@ -3611,6 +3625,8 @@ static int in6_dump_addrs(struct inet6_d
25696                      ifmca = ifmca->next, ip_idx++) {
25697                         if (ip_idx < s_ip_idx)
25698                                 continue;
25699 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25700 +                                       continue;
25701                         err = inet6_fill_ifmcaddr(skb, ifmca,
25702                                                   NETLINK_CB(cb->skb).pid,
25703                                                   cb->nlh->nlmsg_seq,
25704 @@ -3626,6 +3642,8 @@ static int in6_dump_addrs(struct inet6_d
25705                      ifaca = ifaca->aca_next, ip_idx++) {
25706                         if (ip_idx < s_ip_idx)
25707                                 continue;
25708 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25709 +                                       continue;
25710                         err = inet6_fill_ifacaddr(skb, ifaca,
25711                                                   NETLINK_CB(cb->skb).pid,
25712                                                   cb->nlh->nlmsg_seq,
25713 @@ -3975,6 +3993,11 @@ static int inet6_dump_ifinfo(struct sk_b
25714         struct inet6_dev *idev;
25715         struct hlist_head *head;
25716         struct hlist_node *node;
25717 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25718 +
25719 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25720 +       if (skb->sk && skb->sk->sk_vx_info)
25721 +               return skb->len; */
25722  
25723         s_h = cb->args[0];
25724         s_idx = cb->args[1];
25725 @@ -3986,6 +4009,8 @@ static int inet6_dump_ifinfo(struct sk_b
25726                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25727                         if (idx < s_idx)
25728                                 goto cont;
25729 +                       if (!v6_dev_in_nx_info(dev, nxi))
25730 +                               goto cont;
25731                         idev = __in6_dev_get(dev);
25732                         if (!idev)
25733                                 goto cont;
25734 diff -NurpP --minimal linux-2.6.37/net/ipv6/af_inet6.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/af_inet6.c
25735 --- linux-2.6.37/net/ipv6/af_inet6.c    2011-01-05 21:50:42.000000000 +0100
25736 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/af_inet6.c     2010-11-23 02:09:41.000000000 +0100
25737 @@ -42,6 +42,8 @@
25738  #include <linux/netdevice.h>
25739  #include <linux/icmpv6.h>
25740  #include <linux/netfilter_ipv6.h>
25741 +#include <linux/vs_inet.h>
25742 +#include <linux/vs_inet6.h>
25743  
25744  #include <net/ip.h>
25745  #include <net/ipv6.h>
25746 @@ -160,9 +162,12 @@ lookup_protocol:
25747         }
25748  
25749         err = -EPERM;
25750 +       if ((protocol == IPPROTO_ICMPV6) &&
25751 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25752 +               goto override;
25753         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25754                 goto out_rcu_unlock;
25755 -
25756 +override:
25757         sock->ops = answer->ops;
25758         answer_prot = answer->prot;
25759         answer_no_check = answer->no_check;
25760 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25761         struct inet_sock *inet = inet_sk(sk);
25762         struct ipv6_pinfo *np = inet6_sk(sk);
25763         struct net *net = sock_net(sk);
25764 +       struct nx_v6_sock_addr nsa;
25765         __be32 v4addr = 0;
25766         unsigned short snum;
25767         int addr_type = 0;
25768 @@ -272,6 +278,11 @@ int inet6_bind(struct socket *sock, stru
25769  
25770         if (addr_len < SIN6_LEN_RFC2133)
25771                 return -EINVAL;
25772 +
25773 +       err = v6_map_sock_addr(inet, addr, &nsa);
25774 +       if (err)
25775 +               return err;
25776 +
25777         addr_type = ipv6_addr_type(&addr->sin6_addr);
25778         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25779                 return -EINVAL;
25780 @@ -303,6 +314,7 @@ int inet6_bind(struct socket *sock, stru
25781                 /* Reproduce AF_INET checks to make the bindings consitant */
25782                 v4addr = addr->sin6_addr.s6_addr32[3];
25783                 chk_addr_ret = inet_addr_type(net, v4addr);
25784 +
25785                 if (!sysctl_ip_nonlocal_bind &&
25786                     !(inet->freebind || inet->transparent) &&
25787                     v4addr != htonl(INADDR_ANY) &&
25788 @@ -312,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
25789                         err = -EADDRNOTAVAIL;
25790                         goto out;
25791                 }
25792 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25793 +                       err = -EADDRNOTAVAIL;
25794 +                       goto out;
25795 +               }
25796         } else {
25797                 if (addr_type != IPV6_ADDR_ANY) {
25798                         struct net_device *dev = NULL;
25799 @@ -338,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
25800                                 }
25801                         }
25802  
25803 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25804 +                               err = -EADDRNOTAVAIL;
25805 +                               goto out;
25806 +                       }
25807 +
25808                         /* ipv4 addr of the socket is invalid.  Only the
25809                          * unspecified and mapped address have a v4 equivalent.
25810                          */
25811 @@ -354,6 +375,9 @@ int inet6_bind(struct socket *sock, stru
25812                 }
25813         }
25814  
25815 +       /* what's that for? */
25816 +       v6_set_sock_addr(inet, &nsa);
25817 +
25818         inet->inet_rcv_saddr = v4addr;
25819         inet->inet_saddr = v4addr;
25820  
25821 @@ -455,9 +479,11 @@ int inet6_getname(struct socket *sock, s
25822                         return -ENOTCONN;
25823                 sin->sin6_port = inet->inet_dport;
25824                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25825 +               /* FIXME: remap lback? */
25826                 if (np->sndflow)
25827                         sin->sin6_flowinfo = np->flow_label;
25828         } else {
25829 +               /* FIXME: remap lback? */
25830                 if (ipv6_addr_any(&np->rcv_saddr))
25831                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25832                 else
25833 diff -NurpP --minimal linux-2.6.37/net/ipv6/fib6_rules.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/fib6_rules.c
25834 --- linux-2.6.37/net/ipv6/fib6_rules.c  2011-01-05 21:50:42.000000000 +0100
25835 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/fib6_rules.c   2010-11-23 02:09:41.000000000 +0100
25836 @@ -88,7 +88,7 @@ static int fib6_rule_action(struct fib_r
25837                                                ip6_dst_idev(&rt->dst)->dev,
25838                                                &flp->fl6_dst,
25839                                                rt6_flags2srcprefs(flags),
25840 -                                              &saddr))
25841 +                                              &saddr, NULL))
25842                                 goto again;
25843                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25844                                                r->src.plen))
25845 diff -NurpP --minimal linux-2.6.37/net/ipv6/inet6_hashtables.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/inet6_hashtables.c
25846 --- linux-2.6.37/net/ipv6/inet6_hashtables.c    2010-02-25 11:52:10.000000000 +0100
25847 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/inet6_hashtables.c     2010-11-23 02:09:41.000000000 +0100
25848 @@ -16,6 +16,7 @@
25849  
25850  #include <linux/module.h>
25851  #include <linux/random.h>
25852 +#include <linux/vs_inet6.h>
25853  
25854  #include <net/inet_connection_sock.h>
25855  #include <net/inet_hashtables.h>
25856 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
25857         unsigned int slot = hash & hashinfo->ehash_mask;
25858         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25859  
25860 -
25861         rcu_read_lock();
25862  begin:
25863         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25864 @@ -94,7 +94,7 @@ begin:
25865                                 sock_put(sk);
25866                                 goto begin;
25867                         }
25868 -               goto out;
25869 +                       goto out;
25870                 }
25871         }
25872         if (get_nulls_value(node) != slot)
25873 @@ -140,6 +140,9 @@ static int inline compute_score(struct s
25874                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25875                                 return -1;
25876                         score++;
25877 +               } else {
25878 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25879 +                               return -1;
25880                 }
25881                 if (sk->sk_bound_dev_if) {
25882                         if (sk->sk_bound_dev_if != dif)
25883 diff -NurpP --minimal linux-2.6.37/net/ipv6/ip6_output.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/ip6_output.c
25884 --- linux-2.6.37/net/ipv6/ip6_output.c  2011-01-05 21:50:42.000000000 +0100
25885 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/ip6_output.c   2011-01-05 22:30:43.000000000 +0100
25886 @@ -930,7 +930,7 @@ static int ip6_dst_lookup_tail(struct so
25887                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
25888                                          &fl->fl6_dst,
25889                                          sk ? inet6_sk(sk)->srcprefs : 0,
25890 -                                        &fl->fl6_src);
25891 +                                        &fl->fl6_src, sk->sk_nx_info);
25892                 if (err)
25893                         goto out_err_release;
25894         }
25895 diff -NurpP --minimal linux-2.6.37/net/ipv6/Kconfig linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/Kconfig
25896 --- linux-2.6.37/net/ipv6/Kconfig       2010-08-02 16:52:59.000000000 +0200
25897 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/Kconfig        2010-11-23 02:09:41.000000000 +0100
25898 @@ -4,8 +4,8 @@
25899  
25900  #   IPv6 as module will cause a CRASH if you try to unload it
25901  menuconfig IPV6
25902 -       tristate "The IPv6 protocol"
25903 -       default m
25904 +       bool "The IPv6 protocol"
25905 +       default n
25906         ---help---
25907           This is complemental support for the IP version 6.
25908           You will still be able to do traditional IPv4 networking as well.
25909 diff -NurpP --minimal linux-2.6.37/net/ipv6/ndisc.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/ndisc.c
25910 --- linux-2.6.37/net/ipv6/ndisc.c       2011-01-05 21:50:42.000000000 +0100
25911 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/ndisc.c        2010-11-23 02:09:41.000000000 +0100
25912 @@ -595,7 +595,7 @@ static void ndisc_send_na(struct net_dev
25913         } else {
25914                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25915                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25916 -                                      &tmpaddr))
25917 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
25918                         return;
25919                 src_addr = &tmpaddr;
25920         }
25921 diff -NurpP --minimal linux-2.6.37/net/ipv6/raw.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/raw.c
25922 --- linux-2.6.37/net/ipv6/raw.c 2011-01-05 21:50:42.000000000 +0100
25923 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/raw.c  2010-11-23 02:09:41.000000000 +0100
25924 @@ -30,6 +30,7 @@
25925  #include <linux/icmpv6.h>
25926  #include <linux/netfilter.h>
25927  #include <linux/netfilter_ipv6.h>
25928 +#include <linux/vs_inet6.h>
25929  #include <linux/skbuff.h>
25930  #include <asm/uaccess.h>
25931  #include <asm/ioctls.h>
25932 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25933                                 goto out_unlock;
25934                 }
25935  
25936 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25937 +                       err = -EADDRNOTAVAIL;
25938 +                       if (dev)
25939 +                               dev_put(dev);
25940 +                       goto out;
25941 +               }
25942 +
25943                 /* ipv4 addr of the socket is invalid.  Only the
25944                  * unspecified and mapped address have a v4 equivalent.
25945                  */
25946 diff -NurpP --minimal linux-2.6.37/net/ipv6/route.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/route.c
25947 --- linux-2.6.37/net/ipv6/route.c       2011-01-05 21:50:42.000000000 +0100
25948 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/route.c        2011-01-05 22:30:43.000000000 +0100
25949 @@ -2290,7 +2290,8 @@ static int rt6_fill_node(struct net *net
25950                 struct inet6_dev *idev = ip6_dst_idev(&rt->dst);
25951                 struct in6_addr saddr_buf;
25952                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25953 -                                      dst, 0, &saddr_buf) == 0)
25954 +                       dst, 0, &saddr_buf,
25955 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25956                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25957         }
25958  
25959 diff -NurpP --minimal linux-2.6.37/net/ipv6/tcp_ipv6.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/tcp_ipv6.c
25960 --- linux-2.6.37/net/ipv6/tcp_ipv6.c    2011-01-05 21:50:42.000000000 +0100
25961 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/tcp_ipv6.c     2010-11-23 02:09:41.000000000 +0100
25962 @@ -69,6 +69,7 @@
25963  
25964  #include <linux/crypto.h>
25965  #include <linux/scatterlist.h>
25966 +#include <linux/vs_inet6.h>
25967  
25968  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25969  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25970 @@ -160,8 +161,15 @@ static int tcp_v6_connect(struct sock *s
25971          *      connect() to INADDR_ANY means loopback (BSD'ism).
25972          */
25973  
25974 -       if(ipv6_addr_any(&usin->sin6_addr))
25975 -               usin->sin6_addr.s6_addr[15] = 0x1;
25976 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25977 +               struct nx_info *nxi =  sk->sk_nx_info;
25978 +
25979 +               if (nxi && nx_info_has_v6(nxi))
25980 +                       /* FIXME: remap lback? */
25981 +                       usin->sin6_addr = nxi->v6.ip;
25982 +               else
25983 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25984 +       }
25985  
25986         addr_type = ipv6_addr_type(&usin->sin6_addr);
25987  
25988 diff -NurpP --minimal linux-2.6.37/net/ipv6/udp.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/udp.c
25989 --- linux-2.6.37/net/ipv6/udp.c 2011-01-05 21:50:42.000000000 +0100
25990 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/udp.c  2011-01-05 22:30:43.000000000 +0100
25991 @@ -48,13 +48,14 @@
25992  
25993  #include <linux/proc_fs.h>
25994  #include <linux/seq_file.h>
25995 +#include <linux/vs_inet6.h>
25996  #include "udp_impl.h"
25997  
25998  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25999  {
26000         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
26001         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
26002 -       __be32 sk1_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
26003 +       __be32 sk_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
26004         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26005         int sk_ipv6only = ipv6_only_sock(sk);
26006         int sk2_ipv6only = inet_v6_ipv6only(sk2);
26007 @@ -62,24 +63,49 @@ int ipv6_rcv_saddr_equal(const struct so
26008         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
26009  
26010         /* if both are mapped, treat as IPv4 */
26011 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
26012 -               return (!sk2_ipv6only &&
26013 -                       (!sk1_rcv_saddr || !sk2_rcv_saddr ||
26014 -                         sk1_rcv_saddr == sk2_rcv_saddr));
26015 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
26016 +               if (!sk2_ipv6only &&
26017 +                       (!sk_rcv_saddr || !sk2_rcv_saddr ||
26018 +                         sk_rcv_saddr == sk2_rcv_saddr))
26019 +                       goto vs_v4;
26020 +               else
26021 +                       return 0;
26022 +       }
26023  
26024         if (addr_type2 == IPV6_ADDR_ANY &&
26025             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26026 -               return 1;
26027 +               goto vs;
26028  
26029         if (addr_type == IPV6_ADDR_ANY &&
26030             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26031 -               return 1;
26032 +               goto vs;
26033  
26034         if (sk2_rcv_saddr6 &&
26035             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26036 -               return 1;
26037 +               goto vs;
26038  
26039         return 0;
26040 +
26041 +vs_v4:
26042 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
26043 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26044 +       if (!sk2_rcv_saddr)
26045 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
26046 +       if (!sk_rcv_saddr)
26047 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
26048 +       return 1;
26049 +vs:
26050 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
26051 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26052 +       else if (addr_type2 == IPV6_ADDR_ANY)
26053 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
26054 +       else if (addr_type == IPV6_ADDR_ANY) {
26055 +               if (addr_type2 == IPV6_ADDR_MAPPED)
26056 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26057 +               else
26058 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
26059 +       }
26060 +       return 1;
26061  }
26062  
26063  static unsigned int udp6_portaddr_hash(struct net *net,
26064 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
26065                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26066                                 return -1;
26067                         score++;
26068 +               } else {
26069 +                       /* block non nx_info ips */
26070 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26071 +                               return -1;
26072                 }
26073                 if (!ipv6_addr_any(&np->daddr)) {
26074                         if (!ipv6_addr_equal(&np->daddr, saddr))
26075 diff -NurpP --minimal linux-2.6.37/net/ipv6/xfrm6_policy.c linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/xfrm6_policy.c
26076 --- linux-2.6.37/net/ipv6/xfrm6_policy.c        2011-01-05 21:50:42.000000000 +0100
26077 +++ linux-2.6.37-vs2.3.0.37-rc2/net/ipv6/xfrm6_policy.c 2010-11-23 02:09:41.000000000 +0100
26078 @@ -62,7 +62,7 @@ static int xfrm6_get_saddr(struct net *n
26079         dev = ip6_dst_idev(dst)->dev;
26080         ipv6_dev_get_saddr(dev_net(dev), dev,
26081                            (struct in6_addr *)&daddr->a6, 0,
26082 -                          (struct in6_addr *)&saddr->a6);
26083 +                          (struct in6_addr *)&saddr->a6, NULL);
26084         dst_release(dst);
26085         return 0;
26086  }
26087 diff -NurpP --minimal linux-2.6.37/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.37-vs2.3.0.37-rc2/net/netfilter/ipvs/ip_vs_xmit.c
26088 --- linux-2.6.37/net/netfilter/ipvs/ip_vs_xmit.c        2011-01-05 21:50:43.000000000 +0100
26089 +++ linux-2.6.37-vs2.3.0.37-rc2/net/netfilter/ipvs/ip_vs_xmit.c 2011-01-06 00:35:16.000000000 +0100
26090 @@ -231,7 +231,7 @@ __ip_vs_route_output_v6(struct net *net,
26091                 return dst;
26092         if (ipv6_addr_any(&fl.fl6_src) &&
26093             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
26094 -                              &fl.fl6_dst, 0, &fl.fl6_src) < 0)
26095 +                              &fl.fl6_dst, 0, &fl.fl6_src, NULL) < 0)
26096                 goto out_err;
26097         if (do_xfrm && xfrm_lookup(net, &dst, &fl, NULL, 0) < 0)
26098                 goto out_err;
26099 diff -NurpP --minimal linux-2.6.37/net/netlink/af_netlink.c linux-2.6.37-vs2.3.0.37-rc2/net/netlink/af_netlink.c
26100 --- linux-2.6.37/net/netlink/af_netlink.c       2011-01-05 21:50:43.000000000 +0100
26101 +++ linux-2.6.37-vs2.3.0.37-rc2/net/netlink/af_netlink.c        2010-11-23 02:09:41.000000000 +0100
26102 @@ -55,6 +55,9 @@
26103  #include <linux/types.h>
26104  #include <linux/audit.h>
26105  #include <linux/mutex.h>
26106 +#include <linux/vs_context.h>
26107 +#include <linux/vs_network.h>
26108 +#include <linux/vs_limit.h>
26109  
26110  #include <net/net_namespace.h>
26111  #include <net/sock.h>
26112 @@ -1912,6 +1915,8 @@ static struct sock *netlink_seq_socket_i
26113                         sk_for_each(s, node, &hash->table[j]) {
26114                                 if (sock_net(s) != seq_file_net(seq))
26115                                         continue;
26116 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26117 +                                       continue;
26118                                 if (off == pos) {
26119                                         iter->link = i;
26120                                         iter->hash_idx = j;
26121 @@ -1946,7 +1951,8 @@ static void *netlink_seq_next(struct seq
26122         s = v;
26123         do {
26124                 s = sk_next(s);
26125 -       } while (s && sock_net(s) != seq_file_net(seq));
26126 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26127 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26128         if (s)
26129                 return s;
26130  
26131 @@ -1958,7 +1964,8 @@ static void *netlink_seq_next(struct seq
26132  
26133                 for (; j <= hash->mask; j++) {
26134                         s = sk_head(&hash->table[j]);
26135 -                       while (s && sock_net(s) != seq_file_net(seq))
26136 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26137 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26138                                 s = sk_next(s);
26139                         if (s) {
26140                                 iter->link = i;
26141 diff -NurpP --minimal linux-2.6.37/net/sctp/ipv6.c linux-2.6.37-vs2.3.0.37-rc2/net/sctp/ipv6.c
26142 --- linux-2.6.37/net/sctp/ipv6.c        2011-01-05 21:50:45.000000000 +0100
26143 +++ linux-2.6.37-vs2.3.0.37-rc2/net/sctp/ipv6.c 2010-11-23 02:09:41.000000000 +0100
26144 @@ -306,7 +306,8 @@ static void sctp_v6_get_saddr(struct sct
26145                                    dst ? ip6_dst_idev(dst)->dev : NULL,
26146                                    &daddr->v6.sin6_addr,
26147                                    inet6_sk(&sk->inet.sk)->srcprefs,
26148 -                                  &saddr->v6.sin6_addr);
26149 +                                  &saddr->v6.sin6_addr,
26150 +                                  asoc->base.sk->sk_nx_info);
26151                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
26152                                   &saddr->v6.sin6_addr);
26153                 return;
26154 diff -NurpP --minimal linux-2.6.37/net/socket.c linux-2.6.37-vs2.3.0.37-rc2/net/socket.c
26155 --- linux-2.6.37/net/socket.c   2011-01-05 21:50:45.000000000 +0100
26156 +++ linux-2.6.37-vs2.3.0.37-rc2/net/socket.c    2011-01-05 22:30:44.000000000 +0100
26157 @@ -98,6 +98,10 @@
26158  
26159  #include <net/sock.h>
26160  #include <linux/netfilter.h>
26161 +#include <linux/vs_base.h>
26162 +#include <linux/vs_socket.h>
26163 +#include <linux/vs_inet.h>
26164 +#include <linux/vs_inet6.h>
26165  
26166  #include <linux/if_tun.h>
26167  #include <linux/ipv6_route.h>
26168 @@ -550,7 +554,7 @@ static inline int __sock_sendmsg(struct 
26169                                  struct msghdr *msg, size_t size)
26170  {
26171         struct sock_iocb *si = kiocb_to_siocb(iocb);
26172 -       int err;
26173 +       int err, len;
26174  
26175         sock_update_classid(sock->sk);
26176  
26177 @@ -563,7 +567,22 @@ static inline int __sock_sendmsg(struct 
26178         if (err)
26179                 return err;
26180  
26181 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26182 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26183 +       if (sock->sk) {
26184 +               if (len == size)
26185 +                       vx_sock_send(sock->sk, size);
26186 +               else
26187 +                       vx_sock_fail(sock->sk, size);
26188 +       }
26189 +       vxdprintk(VXD_CBIT(net, 7),
26190 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26191 +               sock, sock->sk,
26192 +               (sock->sk)?sock->sk->sk_nx_info:0,
26193 +               (sock->sk)?sock->sk->sk_vx_info:0,
26194 +               (sock->sk)?sock->sk->sk_xid:0,
26195 +               (sock->sk)?sock->sk->sk_nid:0,
26196 +               (unsigned int)size, len);
26197 +       return len;
26198  }
26199  
26200  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
26201 @@ -681,6 +700,7 @@ static inline int __sock_recvmsg_nosec(s
26202                                        struct msghdr *msg, size_t size, int flags)
26203  {
26204         struct sock_iocb *si = kiocb_to_siocb(iocb);
26205 +       int len;
26206  
26207         sock_update_classid(sock->sk);
26208  
26209 @@ -690,7 +710,18 @@ static inline int __sock_recvmsg_nosec(s
26210         si->size = size;
26211         si->flags = flags;
26212  
26213 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26214 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26215 +       if ((len >= 0) && sock->sk)
26216 +               vx_sock_recv(sock->sk, len);
26217 +       vxdprintk(VXD_CBIT(net, 7),
26218 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26219 +               sock, sock->sk,
26220 +               (sock->sk)?sock->sk->sk_nx_info:0,
26221 +               (sock->sk)?sock->sk->sk_vx_info:0,
26222 +               (sock->sk)?sock->sk->sk_xid:0,
26223 +               (sock->sk)?sock->sk->sk_nid:0,
26224 +               (unsigned int)size, len);
26225 +       return len;
26226  }
26227  
26228  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26229 @@ -1174,6 +1205,13 @@ int __sock_create(struct net *net, int f
26230         if (type < 0 || type >= SOCK_MAX)
26231                 return -EINVAL;
26232  
26233 +       if (!nx_check(0, VS_ADMIN)) {
26234 +               if (family == PF_INET && !current_nx_info_has_v4())
26235 +                       return -EAFNOSUPPORT;
26236 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26237 +                       return -EAFNOSUPPORT;
26238 +       }
26239 +
26240         /* Compatibility.
26241  
26242            This uglymoron is moved from INET layer to here to avoid
26243 @@ -1309,6 +1347,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26244         if (retval < 0)
26245                 goto out;
26246  
26247 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26248         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26249         if (retval < 0)
26250                 goto out_release;
26251 @@ -1350,10 +1389,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26252         err = sock_create(family, type, protocol, &sock1);
26253         if (err < 0)
26254                 goto out;
26255 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26256  
26257         err = sock_create(family, type, protocol, &sock2);
26258         if (err < 0)
26259                 goto out_release_1;
26260 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26261  
26262         err = sock1->ops->socketpair(sock1, sock2);
26263         if (err < 0)
26264 diff -NurpP --minimal linux-2.6.37/net/sunrpc/auth.c linux-2.6.37-vs2.3.0.37-rc2/net/sunrpc/auth.c
26265 --- linux-2.6.37/net/sunrpc/auth.c      2011-01-05 21:50:45.000000000 +0100
26266 +++ linux-2.6.37-vs2.3.0.37-rc2/net/sunrpc/auth.c       2010-11-23 02:09:41.000000000 +0100
26267 @@ -14,6 +14,7 @@
26268  #include <linux/hash.h>
26269  #include <linux/sunrpc/clnt.h>
26270  #include <linux/spinlock.h>
26271 +#include <linux/vs_tag.h>
26272  
26273  #ifdef RPC_DEBUG
26274  # define RPCDBG_FACILITY       RPCDBG_AUTH
26275 @@ -425,6 +426,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26276         memset(&acred, 0, sizeof(acred));
26277         acred.uid = cred->fsuid;
26278         acred.gid = cred->fsgid;
26279 +       acred.tag = dx_current_tag();
26280         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26281  
26282         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26283 @@ -465,6 +467,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26284         struct auth_cred acred = {
26285                 .uid = 0,
26286                 .gid = 0,
26287 +               .tag = dx_current_tag(),
26288         };
26289  
26290         dprintk("RPC: %5u looking up %s cred\n",
26291 diff -NurpP --minimal linux-2.6.37/net/sunrpc/auth_unix.c linux-2.6.37-vs2.3.0.37-rc2/net/sunrpc/auth_unix.c
26292 --- linux-2.6.37/net/sunrpc/auth_unix.c 2010-10-21 13:08:01.000000000 +0200
26293 +++ linux-2.6.37-vs2.3.0.37-rc2/net/sunrpc/auth_unix.c  2010-11-23 02:09:41.000000000 +0100
26294 @@ -12,12 +12,14 @@
26295  #include <linux/module.h>
26296  #include <linux/sunrpc/clnt.h>
26297  #include <linux/sunrpc/auth.h>
26298 +#include <linux/vs_tag.h>
26299  
26300  #define NFS_NGROUPS    16
26301  
26302  struct unx_cred {
26303         struct rpc_cred         uc_base;
26304         gid_t                   uc_gid;
26305 +       tag_t                   uc_tag;
26306         gid_t                   uc_gids[NFS_NGROUPS];
26307  };
26308  #define uc_uid                 uc_base.cr_uid
26309 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26310                 groups = NFS_NGROUPS;
26311  
26312         cred->uc_gid = acred->gid;
26313 +       cred->uc_tag = acred->tag;
26314         for (i = 0; i < groups; i++)
26315                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26316         if (i < NFS_NGROUPS)
26317 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26318         unsigned int i;
26319  
26320  
26321 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26322 +       if (cred->uc_uid != acred->uid ||
26323 +               cred->uc_gid != acred->gid ||
26324 +               cred->uc_tag != acred->tag)
26325                 return 0;
26326  
26327         if (acred->group_info != NULL)
26328 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
26329         struct rpc_clnt *clnt = task->tk_client;
26330         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26331         __be32          *base, *hold;
26332 -       int             i;
26333 +       int             i, tag;
26334  
26335         *p++ = htonl(RPC_AUTH_UNIX);
26336         base = p++;
26337 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
26338          * Copy the UTS nodename captured when the client was created.
26339          */
26340         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26341 +       tag = task->tk_client->cl_tag;
26342  
26343 -       *p++ = htonl((u32) cred->uc_uid);
26344 -       *p++ = htonl((u32) cred->uc_gid);
26345 +       *p++ = htonl((u32) TAGINO_UID(tag,
26346 +               cred->uc_uid, cred->uc_tag));
26347 +       *p++ = htonl((u32) TAGINO_GID(tag,
26348 +               cred->uc_gid, cred->uc_tag));
26349         hold = p++;
26350         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26351                 *p++ = htonl((u32) cred->uc_gids[i]);
26352 diff -NurpP --minimal linux-2.6.37/net/sunrpc/clnt.c linux-2.6.37-vs2.3.0.37-rc2/net/sunrpc/clnt.c
26353 --- linux-2.6.37/net/sunrpc/clnt.c      2011-01-05 21:50:45.000000000 +0100
26354 +++ linux-2.6.37-vs2.3.0.37-rc2/net/sunrpc/clnt.c       2011-01-05 22:30:44.000000000 +0100
26355 @@ -33,6 +33,7 @@
26356  #include <linux/utsname.h>
26357  #include <linux/workqueue.h>
26358  #include <linux/in6.h>
26359 +#include <linux/vs_cvirt.h>
26360  
26361  #include <linux/sunrpc/clnt.h>
26362  #include <linux/sunrpc/rpc_pipe_fs.h>
26363 @@ -359,6 +360,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26364         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26365                 clnt->cl_chatty = 1;
26366  
26367 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26368 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26369 +               clnt->cl_tag = 1; */
26370         return clnt;
26371  }
26372  EXPORT_SYMBOL_GPL(rpc_create);
26373 diff -NurpP --minimal linux-2.6.37/net/unix/af_unix.c linux-2.6.37-vs2.3.0.37-rc2/net/unix/af_unix.c
26374 --- linux-2.6.37/net/unix/af_unix.c     2011-01-05 21:50:46.000000000 +0100
26375 +++ linux-2.6.37-vs2.3.0.37-rc2/net/unix/af_unix.c      2011-01-05 22:30:44.000000000 +0100
26376 @@ -114,6 +114,8 @@
26377  #include <linux/mount.h>
26378  #include <net/checksum.h>
26379  #include <linux/security.h>
26380 +#include <linux/vs_context.h>
26381 +#include <linux/vs_limit.h>
26382  
26383  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26384  static DEFINE_SPINLOCK(unix_table_lock);
26385 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26386                 if (!net_eq(sock_net(s), net))
26387                         continue;
26388  
26389 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26390 +                       continue;
26391                 if (u->addr->len == len &&
26392                     !memcmp(u->addr->name, sunname, len))
26393                         goto found;
26394 @@ -2179,6 +2183,8 @@ static struct sock *unix_seq_idx(struct 
26395         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26396                 if (sock_net(s) != seq_file_net(seq))
26397                         continue;
26398 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26399 +                       continue;
26400                 if (off == pos)
26401                         return s;
26402                 ++off;
26403 @@ -2203,7 +2209,8 @@ static void *unix_seq_next(struct seq_fi
26404                 sk = first_unix_socket(&iter->i);
26405         else
26406                 sk = next_unix_socket(&iter->i, sk);
26407 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26408 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26409 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26410                 sk = next_unix_socket(&iter->i, sk);
26411         return sk;
26412  }
26413 diff -NurpP --minimal linux-2.6.37/scripts/checksyscalls.sh linux-2.6.37-vs2.3.0.37-rc2/scripts/checksyscalls.sh
26414 --- linux-2.6.37/scripts/checksyscalls.sh       2010-10-21 13:08:01.000000000 +0200
26415 +++ linux-2.6.37-vs2.3.0.37-rc2/scripts/checksyscalls.sh        2010-11-23 02:09:41.000000000 +0100
26416 @@ -193,7 +193,6 @@ cat << EOF
26417  #define __IGNORE_afs_syscall
26418  #define __IGNORE_getpmsg
26419  #define __IGNORE_putpmsg
26420 -#define __IGNORE_vserver
26421  EOF
26422  }
26423  
26424 diff -NurpP --minimal linux-2.6.37/security/commoncap.c linux-2.6.37-vs2.3.0.37-rc2/security/commoncap.c
26425 --- linux-2.6.37/security/commoncap.c   2011-01-05 21:50:47.000000000 +0100
26426 +++ linux-2.6.37-vs2.3.0.37-rc2/security/commoncap.c    2010-11-23 02:21:20.000000000 +0100
26427 @@ -27,6 +27,7 @@
26428  #include <linux/sched.h>
26429  #include <linux/prctl.h>
26430  #include <linux/securebits.h>
26431 +// #include <linux/vs_context.h>
26432  
26433  /*
26434   * If a non-root user executes a setuid-root binary in
26435 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
26436  
26437  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
26438  {
26439 -       NETLINK_CB(skb).eff_cap = current_cap();
26440 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
26441         return 0;
26442  }
26443  
26444 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
26445                 return -EPERM;
26446         return 0;
26447  }
26448 +
26449  EXPORT_SYMBOL(cap_netlink_recv);
26450  
26451  /**
26452 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
26453  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
26454                 int audit)
26455  {
26456 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26457 +       struct vx_info *vxi = tsk->vx_info;
26458 +
26459 +#if 0
26460 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
26461 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
26462 +               cap_raised(tsk->cap_effective, cap),
26463 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
26464 +#endif
26465 +
26466 +       /* special case SETUP */
26467 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26468 +               /* FIXME: maybe use cred instead? */
26469 +               cap_raised(tsk->cred->cap_effective, cap))
26470 +               return 0;
26471 +
26472 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26473  }
26474  
26475  /**
26476 @@ -570,7 +587,7 @@ int cap_inode_setxattr(struct dentry *de
26477  
26478         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26479                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26480 -           !capable(CAP_SYS_ADMIN))
26481 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26482                 return -EPERM;
26483         return 0;
26484  }
26485 @@ -596,7 +613,7 @@ int cap_inode_removexattr(struct dentry 
26486  
26487         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26488                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26489 -           !capable(CAP_SYS_ADMIN))
26490 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26491                 return -EPERM;
26492         return 0;
26493  }
26494 @@ -929,3 +946,4 @@ int cap_file_mmap(struct file *file, uns
26495         }
26496         return ret;
26497  }
26498 +
26499 diff -NurpP --minimal linux-2.6.37/security/selinux/hooks.c linux-2.6.37-vs2.3.0.37-rc2/security/selinux/hooks.c
26500 --- linux-2.6.37/security/selinux/hooks.c       2011-01-05 21:50:47.000000000 +0100
26501 +++ linux-2.6.37-vs2.3.0.37-rc2/security/selinux/hooks.c        2010-11-23 02:09:41.000000000 +0100
26502 @@ -64,7 +64,6 @@
26503  #include <linux/dccp.h>
26504  #include <linux/quota.h>
26505  #include <linux/un.h>          /* for Unix socket types */
26506 -#include <net/af_unix.h>       /* for Unix socket types */
26507  #include <linux/parser.h>
26508  #include <linux/nfs_mount.h>
26509  #include <net/ipv6.h>
This page took 2.202626 seconds and 2 git commands to generate.