]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- revert last commit, moved fix to kernel-vserver-fixes.patch
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.35.4/arch/alpha/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/Kconfig
2 --- linux-2.6.35.4/arch/alpha/Kconfig   2010-08-02 16:51:53.000000000 +0200
3 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/Kconfig     2010-08-02 17:05:05.000000000 +0200
4 @@ -681,6 +681,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.35.4/arch/alpha/kernel/entry.S linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/kernel/entry.S
14 --- linux-2.6.35.4/arch/alpha/kernel/entry.S    2009-06-11 17:11:46.000000000 +0200
15 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/kernel/entry.S      2010-08-02 17:05:05.000000000 +0200
16 @@ -874,24 +874,15 @@ sys_getxgid:
17         .globl  sys_getxpid
18         .ent    sys_getxpid
19  sys_getxpid:
20 +       lda     $sp, -16($sp)
21 +       stq     $26, 0($sp)
22         .prologue 0
23 -       ldq     $2, TI_TASK($8)
24  
25 -       /* See linux/kernel/timer.c sys_getppid for discussion
26 -          about this loop.  */
27 -       ldq     $3, TASK_GROUP_LEADER($2)
28 -       ldq     $4, TASK_REAL_PARENT($3)
29 -       ldl     $0, TASK_TGID($2)
30 -1:     ldl     $1, TASK_TGID($4)
31 -#ifdef CONFIG_SMP
32 -       mov     $4, $5
33 -       mb
34 -       ldq     $3, TASK_GROUP_LEADER($2)
35 -       ldq     $4, TASK_REAL_PARENT($3)
36 -       cmpeq   $4, $5, $5
37 -       beq     $5, 1b
38 -#endif
39 -       stq     $1, 80($sp)
40 +       lda     $16, 96($sp)
41 +       jsr     $26, do_getxpid
42 +       ldq     $26, 0($sp)
43 +
44 +       lda     $sp, 16($sp)
45         ret
46  .end sys_getxpid
47  
48 diff -NurpP --minimal linux-2.6.35.4/arch/alpha/kernel/osf_sys.c linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.35.4/arch/alpha/kernel/osf_sys.c  2010-07-07 18:30:51.000000000 +0200
50 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/kernel/osf_sys.c    2010-08-02 17:05:05.000000000 +0200
51 @@ -866,7 +866,7 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct
52  {
53         if (tv) {
54                 struct timeval ktv;
55 -               do_gettimeofday(&ktv);
56 +               vx_gettimeofday(&ktv);
57                 if (put_tv32(tv, &ktv))
58                         return -EFAULT;
59         }
60 diff -NurpP --minimal linux-2.6.35.4/arch/alpha/kernel/ptrace.c linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.35.4/arch/alpha/kernel/ptrace.c   2010-07-07 18:30:51.000000000 +0200
62 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/kernel/ptrace.c     2010-08-02 17:05:05.000000000 +0200
63 @@ -13,6 +13,7 @@
64  #include <linux/user.h>
65  #include <linux/security.h>
66  #include <linux/signal.h>
67 +#include <linux/vs_base.h>
68  
69  #include <asm/uaccess.h>
70  #include <asm/pgtable.h>
71 diff -NurpP --minimal linux-2.6.35.4/arch/alpha/kernel/systbls.S linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/kernel/systbls.S
72 --- linux-2.6.35.4/arch/alpha/kernel/systbls.S  2010-02-25 11:51:19.000000000 +0100
73 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/kernel/systbls.S    2010-08-02 17:05:05.000000000 +0200
74 @@ -446,7 +446,7 @@ sys_call_table:
75         .quad sys_stat64                        /* 425 */
76         .quad sys_lstat64
77         .quad sys_fstat64
78 -       .quad sys_ni_syscall                    /* sys_vserver */
79 +       .quad sys_vserver                       /* sys_vserver */
80         .quad sys_ni_syscall                    /* sys_mbind */
81         .quad sys_ni_syscall                    /* sys_get_mempolicy */
82         .quad sys_ni_syscall                    /* sys_set_mempolicy */
83 diff -NurpP --minimal linux-2.6.35.4/arch/alpha/kernel/traps.c linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/kernel/traps.c
84 --- linux-2.6.35.4/arch/alpha/kernel/traps.c    2010-07-07 18:30:51.000000000 +0200
85 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/alpha/kernel/traps.c      2010-08-02 17:05:05.000000000 +0200
86 @@ -184,7 +184,8 @@ die_if_kernel(char * str, struct pt_regs
87  #ifdef CONFIG_SMP
88         printk("CPU %d ", hard_smp_processor_id());
89  #endif
90 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
91 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
92 +               task_pid_nr(current), current->xid, str, err);
93         dik_show_regs(regs, r9_15);
94         add_taint(TAINT_DIE);
95         dik_show_trace((unsigned long *)(regs+1));
96 diff -NurpP --minimal linux-2.6.35.4/arch/arm/include/asm/tlb.h linux-2.6.35.4-vs2.3.0.36.32/arch/arm/include/asm/tlb.h
97 --- linux-2.6.35.4/arch/arm/include/asm/tlb.h   2009-09-10 15:25:15.000000000 +0200
98 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/arm/include/asm/tlb.h     2010-08-02 17:05:05.000000000 +0200
99 @@ -27,6 +27,7 @@
100  
101  #else /* !CONFIG_MMU */
102  
103 +#include <linux/vs_memory.h>
104  #include <asm/pgalloc.h>
105  
106  /*
107 diff -NurpP --minimal linux-2.6.35.4/arch/arm/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/arm/Kconfig
108 --- linux-2.6.35.4/arch/arm/Kconfig     2010-09-05 01:41:56.000000000 +0200
109 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/arm/Kconfig       2010-08-14 18:19:32.000000000 +0200
110 @@ -1685,6 +1685,8 @@ source "fs/Kconfig"
111  
112  source "arch/arm/Kconfig.debug"
113  
114 +source "kernel/vserver/Kconfig"
115 +
116  source "security/Kconfig"
117  
118  source "crypto/Kconfig"
119 diff -NurpP --minimal linux-2.6.35.4/arch/arm/kernel/calls.S linux-2.6.35.4-vs2.3.0.36.32/arch/arm/kernel/calls.S
120 --- linux-2.6.35.4/arch/arm/kernel/calls.S      2010-07-07 18:30:52.000000000 +0200
121 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/arm/kernel/calls.S        2010-08-02 17:05:05.000000000 +0200
122 @@ -322,7 +322,7 @@
123  /* 310 */      CALL(sys_request_key)
124                 CALL(sys_keyctl)
125                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
126 -/* vserver */  CALL(sys_ni_syscall)
127 +               CALL(sys_vserver)
128                 CALL(sys_ioprio_set)
129  /* 315 */      CALL(sys_ioprio_get)
130                 CALL(sys_inotify_init)
131 diff -NurpP --minimal linux-2.6.35.4/arch/arm/kernel/process.c linux-2.6.35.4-vs2.3.0.36.32/arch/arm/kernel/process.c
132 --- linux-2.6.35.4/arch/arm/kernel/process.c    2010-08-02 16:51:55.000000000 +0200
133 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/arm/kernel/process.c      2010-08-02 17:05:05.000000000 +0200
134 @@ -269,7 +269,8 @@ void __show_regs(struct pt_regs *regs)
135  void show_regs(struct pt_regs * regs)
136  {
137         printk("\n");
138 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
139 +       printk("Pid: %d[#%u], comm: %20s\n",
140 +               task_pid_nr(current), current->xid, current->comm);
141         __show_regs(regs);
142         __backtrace();
143  }
144 diff -NurpP --minimal linux-2.6.35.4/arch/arm/kernel/traps.c linux-2.6.35.4-vs2.3.0.36.32/arch/arm/kernel/traps.c
145 --- linux-2.6.35.4/arch/arm/kernel/traps.c      2010-07-07 18:30:52.000000000 +0200
146 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/arm/kernel/traps.c        2010-08-02 17:05:05.000000000 +0200
147 @@ -243,8 +243,8 @@ static int __die(const char *str, int er
148  
149         print_modules();
150         __show_regs(regs);
151 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
152 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
153 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
154 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
155  
156         if (!user_mode(regs) || in_interrupt()) {
157                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
158 diff -NurpP --minimal linux-2.6.35.4/arch/avr32/mm/fault.c linux-2.6.35.4-vs2.3.0.36.32/arch/avr32/mm/fault.c
159 --- linux-2.6.35.4/arch/avr32/mm/fault.c        2009-09-10 15:25:20.000000000 +0200
160 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/avr32/mm/fault.c  2010-08-02 17:05:05.000000000 +0200
161 @@ -216,7 +216,8 @@ out_of_memory:
162                 down_read(&mm->mmap_sem);
163                 goto survive;
164         }
165 -       printk("VM: Killing process %s\n", tsk->comm);
166 +       printk("VM: Killing process %s(%d:#%u)\n",
167 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
168         if (user_mode(regs))
169                 do_group_exit(SIGKILL);
170         goto no_context;
171 diff -NurpP --minimal linux-2.6.35.4/arch/cris/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/cris/Kconfig
172 --- linux-2.6.35.4/arch/cris/Kconfig    2010-08-02 16:52:03.000000000 +0200
173 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/cris/Kconfig      2010-08-02 17:05:05.000000000 +0200
174 @@ -694,6 +694,8 @@ source "drivers/staging/Kconfig"
175  
176  source "arch/cris/Kconfig.debug"
177  
178 +source "kernel/vserver/Kconfig"
179 +
180  source "security/Kconfig"
181  
182  source "crypto/Kconfig"
183 diff -NurpP --minimal linux-2.6.35.4/arch/cris/mm/fault.c linux-2.6.35.4-vs2.3.0.36.32/arch/cris/mm/fault.c
184 --- linux-2.6.35.4/arch/cris/mm/fault.c 2010-02-25 11:51:26.000000000 +0100
185 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/cris/mm/fault.c   2010-08-02 17:05:05.000000000 +0200
186 @@ -245,7 +245,8 @@ do_page_fault(unsigned long address, str
187  
188   out_of_memory:
189         up_read(&mm->mmap_sem);
190 -       printk("VM: killing process %s\n", tsk->comm);
191 +       printk("VM: killing process %s(%d:#%u)\n",
192 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
193         if (user_mode(regs))
194                 do_exit(SIGKILL);
195         goto no_context;
196 diff -NurpP --minimal linux-2.6.35.4/arch/frv/kernel/kernel_thread.S linux-2.6.35.4-vs2.3.0.36.32/arch/frv/kernel/kernel_thread.S
197 --- linux-2.6.35.4/arch/frv/kernel/kernel_thread.S      2008-12-25 00:26:37.000000000 +0100
198 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/frv/kernel/kernel_thread.S        2010-08-02 17:05:05.000000000 +0200
199 @@ -37,7 +37,7 @@ kernel_thread:
200  
201         # start by forking the current process, but with shared VM
202         setlos.p        #__NR_clone,gr7         ; syscall number
203 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
204 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
205         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
206         setlo           #0xe4e4,gr9
207         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
208 diff -NurpP --minimal linux-2.6.35.4/arch/h8300/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/h8300/Kconfig
209 --- linux-2.6.35.4/arch/h8300/Kconfig   2010-02-25 11:51:26.000000000 +0100
210 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/h8300/Kconfig     2010-08-02 17:05:05.000000000 +0200
211 @@ -230,6 +230,8 @@ source "fs/Kconfig"
212  
213  source "arch/h8300/Kconfig.debug"
214  
215 +source "kernel/vserver/Kconfig"
216 +
217  source "security/Kconfig"
218  
219  source "crypto/Kconfig"
220 diff -NurpP --minimal linux-2.6.35.4/arch/ia64/include/asm/tlb.h linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/include/asm/tlb.h
221 --- linux-2.6.35.4/arch/ia64/include/asm/tlb.h  2010-02-25 11:51:26.000000000 +0100
222 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/include/asm/tlb.h    2010-08-02 17:05:05.000000000 +0200
223 @@ -40,6 +40,7 @@
224  #include <linux/mm.h>
225  #include <linux/pagemap.h>
226  #include <linux/swap.h>
227 +#include <linux/vs_memory.h>
228  
229  #include <asm/pgalloc.h>
230  #include <asm/processor.h>
231 diff -NurpP --minimal linux-2.6.35.4/arch/ia64/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/Kconfig
232 --- linux-2.6.35.4/arch/ia64/Kconfig    2010-08-02 16:52:03.000000000 +0200
233 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/Kconfig      2010-08-02 17:05:05.000000000 +0200
234 @@ -676,6 +676,8 @@ source "fs/Kconfig"
235  
236  source "arch/ia64/Kconfig.debug"
237  
238 +source "kernel/vserver/Kconfig"
239 +
240  source "security/Kconfig"
241  
242  source "crypto/Kconfig"
243 diff -NurpP --minimal linux-2.6.35.4/arch/ia64/kernel/entry.S linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/kernel/entry.S
244 --- linux-2.6.35.4/arch/ia64/kernel/entry.S     2010-07-07 18:31:01.000000000 +0200
245 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/kernel/entry.S       2010-08-02 17:05:05.000000000 +0200
246 @@ -1714,7 +1714,7 @@ sys_call_table:
247         data8 sys_mq_notify
248         data8 sys_mq_getsetattr
249         data8 sys_kexec_load
250 -       data8 sys_ni_syscall                    // reserved for vserver
251 +       data8 sys_vserver
252         data8 sys_waitid                        // 1270
253         data8 sys_add_key
254         data8 sys_request_key
255 diff -NurpP --minimal linux-2.6.35.4/arch/ia64/kernel/perfmon.c linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/kernel/perfmon.c
256 --- linux-2.6.35.4/arch/ia64/kernel/perfmon.c   2010-07-07 18:31:01.000000000 +0200
257 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/kernel/perfmon.c     2010-08-02 17:05:05.000000000 +0200
258 @@ -42,6 +42,7 @@
259  #include <linux/completion.h>
260  #include <linux/tracehook.h>
261  #include <linux/slab.h>
262 +#include <linux/vs_memory.h>
263  
264  #include <asm/errno.h>
265  #include <asm/intrinsics.h>
266 diff -NurpP --minimal linux-2.6.35.4/arch/ia64/kernel/process.c linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/kernel/process.c
267 --- linux-2.6.35.4/arch/ia64/kernel/process.c   2010-07-07 18:31:01.000000000 +0200
268 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/kernel/process.c     2010-08-02 17:05:05.000000000 +0200
269 @@ -113,8 +113,8 @@ show_regs (struct pt_regs *regs)
270         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
271  
272         print_modules();
273 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
274 -                       smp_processor_id(), current->comm);
275 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
276 +                       current->xid, smp_processor_id(), current->comm);
277         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
278                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
279                init_utsname()->release);
280 diff -NurpP --minimal linux-2.6.35.4/arch/ia64/kernel/ptrace.c linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/kernel/ptrace.c
281 --- linux-2.6.35.4/arch/ia64/kernel/ptrace.c    2010-08-02 16:52:04.000000000 +0200
282 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/kernel/ptrace.c      2010-08-02 17:05:05.000000000 +0200
283 @@ -21,6 +21,7 @@
284  #include <linux/regset.h>
285  #include <linux/elf.h>
286  #include <linux/tracehook.h>
287 +#include <linux/vs_base.h>
288  
289  #include <asm/pgtable.h>
290  #include <asm/processor.h>
291 diff -NurpP --minimal linux-2.6.35.4/arch/ia64/kernel/traps.c linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/kernel/traps.c
292 --- linux-2.6.35.4/arch/ia64/kernel/traps.c     2010-07-07 18:31:01.000000000 +0200
293 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/kernel/traps.c       2010-08-02 17:05:05.000000000 +0200
294 @@ -59,8 +59,9 @@ die (const char *str, struct pt_regs *re
295         put_cpu();
296  
297         if (++die.lock_owner_depth < 3) {
298 -               printk("%s[%d]: %s %ld [%d]\n",
299 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
300 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
301 +                       current->comm, task_pid_nr(current), current->xid,
302 +                       str, err, ++die_counter);
303                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
304                     != NOTIFY_STOP)
305                         show_regs(regs);
306 @@ -323,8 +324,9 @@ handle_fpu_swa (int fp_fault, struct pt_
307                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
308                                 last.time = current_jiffies + 5 * HZ;
309                                 printk(KERN_WARNING
310 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
311 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
312 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
313 +                                       current->comm, task_pid_nr(current), current->xid,
314 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
315                         }
316                 }
317         }
318 diff -NurpP --minimal linux-2.6.35.4/arch/ia64/mm/fault.c linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/mm/fault.c
319 --- linux-2.6.35.4/arch/ia64/mm/fault.c 2010-08-02 16:52:04.000000000 +0200
320 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/ia64/mm/fault.c   2010-08-02 17:05:05.000000000 +0200
321 @@ -10,6 +10,7 @@
322  #include <linux/interrupt.h>
323  #include <linux/kprobes.h>
324  #include <linux/kdebug.h>
325 +#include <linux/vs_memory.h>
326  
327  #include <asm/pgtable.h>
328  #include <asm/processor.h>
329 diff -NurpP --minimal linux-2.6.35.4/arch/m32r/kernel/traps.c linux-2.6.35.4-vs2.3.0.36.32/arch/m32r/kernel/traps.c
330 --- linux-2.6.35.4/arch/m32r/kernel/traps.c     2009-12-03 20:01:57.000000000 +0100
331 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/m32r/kernel/traps.c       2010-08-02 17:05:05.000000000 +0200
332 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
333         } else {
334                 printk("SPI: %08lx\n", sp);
335         }
336 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
337 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
338 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
339 +               current->comm, task_pid_nr(current), current->xid,
340 +               0xffff & i, 4096+(unsigned long)current);
341  
342         /*
343          * When in-kernel, we also print out the stack and code at the
344 diff -NurpP --minimal linux-2.6.35.4/arch/m68k/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/m68k/Kconfig
345 --- linux-2.6.35.4/arch/m68k/Kconfig    2010-08-02 16:52:04.000000000 +0200
346 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/m68k/Kconfig      2010-08-02 17:05:05.000000000 +0200
347 @@ -619,6 +619,8 @@ source "fs/Kconfig"
348  
349  source "arch/m68k/Kconfig.debug"
350  
351 +source "kernel/vserver/Kconfig"
352 +
353  source "security/Kconfig"
354  
355  source "crypto/Kconfig"
356 diff -NurpP --minimal linux-2.6.35.4/arch/m68k/kernel/ptrace.c linux-2.6.35.4-vs2.3.0.36.32/arch/m68k/kernel/ptrace.c
357 --- linux-2.6.35.4/arch/m68k/kernel/ptrace.c    2010-07-07 18:31:02.000000000 +0200
358 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/m68k/kernel/ptrace.c      2010-08-02 17:05:05.000000000 +0200
359 @@ -18,6 +18,7 @@
360  #include <linux/ptrace.h>
361  #include <linux/user.h>
362  #include <linux/signal.h>
363 +#include <linux/vs_base.h>
364  
365  #include <asm/uaccess.h>
366  #include <asm/page.h>
367 @@ -254,6 +255,8 @@ long arch_ptrace(struct task_struct *chi
368                 ret = ptrace_request(child, request, addr, data);
369                 break;
370         }
371 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
372 +               goto out_tsk;
373  
374         return ret;
375  out_eio:
376 diff -NurpP --minimal linux-2.6.35.4/arch/m68k/kernel/traps.c linux-2.6.35.4-vs2.3.0.36.32/arch/m68k/kernel/traps.c
377 --- linux-2.6.35.4/arch/m68k/kernel/traps.c     2010-08-02 16:52:04.000000000 +0200
378 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/m68k/kernel/traps.c       2010-08-02 17:05:05.000000000 +0200
379 @@ -906,8 +906,8 @@ void show_registers(struct pt_regs *regs
380         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
381                regs->d4, regs->d5, regs->a0, regs->a1);
382  
383 -       printk("Process %s (pid: %d, task=%p)\n",
384 -               current->comm, task_pid_nr(current), current);
385 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
386 +               current->comm, task_pid_nr(current), current->xid, current);
387         addr = (unsigned long)&fp->un;
388         printk("Frame format=%X ", regs->format);
389         switch (regs->format) {
390 diff -NurpP --minimal linux-2.6.35.4/arch/m68knommu/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/m68knommu/Kconfig
391 --- linux-2.6.35.4/arch/m68knommu/Kconfig       2010-08-02 16:52:04.000000000 +0200
392 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/m68knommu/Kconfig 2010-08-02 17:05:05.000000000 +0200
393 @@ -734,6 +734,8 @@ source "fs/Kconfig"
394  
395  source "arch/m68knommu/Kconfig.debug"
396  
397 +source "kernel/vserver/Kconfig"
398 +
399  source "security/Kconfig"
400  
401  source "crypto/Kconfig"
402 diff -NurpP --minimal linux-2.6.35.4/arch/m68knommu/kernel/traps.c linux-2.6.35.4-vs2.3.0.36.32/arch/m68knommu/kernel/traps.c
403 --- linux-2.6.35.4/arch/m68knommu/kernel/traps.c        2009-09-10 15:25:23.000000000 +0200
404 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/m68knommu/kernel/traps.c  2010-08-02 17:05:05.000000000 +0200
405 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
406         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
407                fp->d4, fp->d5, fp->a0, fp->a1);
408  
409 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
410 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
411 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
412 +               current->comm, task_pid_nr(current), current->xid,
413 +               PAGE_SIZE+(unsigned long)current);
414         show_stack(NULL, (unsigned long *)(fp + 1));
415         add_taint(TAINT_DIE);
416         do_exit(SIGSEGV);
417 diff -NurpP --minimal linux-2.6.35.4/arch/mips/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/mips/Kconfig
418 --- linux-2.6.35.4/arch/mips/Kconfig    2010-08-02 16:52:05.000000000 +0200
419 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/mips/Kconfig      2010-08-02 17:05:05.000000000 +0200
420 @@ -2253,6 +2253,8 @@ source "fs/Kconfig"
421  
422  source "arch/mips/Kconfig.debug"
423  
424 +source "kernel/vserver/Kconfig"
425 +
426  source "security/Kconfig"
427  
428  source "crypto/Kconfig"
429 diff -NurpP --minimal linux-2.6.35.4/arch/mips/kernel/ptrace.c linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/ptrace.c
430 --- linux-2.6.35.4/arch/mips/kernel/ptrace.c    2010-07-07 18:31:04.000000000 +0200
431 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/ptrace.c      2010-08-02 17:05:05.000000000 +0200
432 @@ -25,6 +25,7 @@
433  #include <linux/security.h>
434  #include <linux/audit.h>
435  #include <linux/seccomp.h>
436 +#include <linux/vs_base.h>
437  
438  #include <asm/byteorder.h>
439  #include <asm/cpu.h>
440 @@ -259,6 +260,9 @@ long arch_ptrace(struct task_struct *chi
441  {
442         int ret;
443  
444 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
445 +               goto out;
446 +
447         switch (request) {
448         /* when I and D space are separate, these will need to be fixed. */
449         case PTRACE_PEEKTEXT: /* read word at location addr. */
450 diff -NurpP --minimal linux-2.6.35.4/arch/mips/kernel/scall32-o32.S linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/scall32-o32.S
451 --- linux-2.6.35.4/arch/mips/kernel/scall32-o32.S       2010-02-25 11:51:28.000000000 +0100
452 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/scall32-o32.S 2010-08-02 17:05:05.000000000 +0200
453 @@ -525,7 +525,7 @@ einval:     li      v0, -ENOSYS
454         sys     sys_mq_timedreceive     5
455         sys     sys_mq_notify           2       /* 4275 */
456         sys     sys_mq_getsetattr       3
457 -       sys     sys_ni_syscall          0       /* sys_vserver */
458 +       sys     sys_vserver             3
459         sys     sys_waitid              5
460         sys     sys_ni_syscall          0       /* available, was setaltroot */
461         sys     sys_add_key             5       /* 4280 */
462 diff -NurpP --minimal linux-2.6.35.4/arch/mips/kernel/scall64-64.S linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/scall64-64.S
463 --- linux-2.6.35.4/arch/mips/kernel/scall64-64.S        2010-02-25 11:51:28.000000000 +0100
464 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/scall64-64.S  2010-08-02 17:05:05.000000000 +0200
465 @@ -362,7 +362,7 @@ sys_call_table:
466         PTR     sys_mq_timedreceive
467         PTR     sys_mq_notify
468         PTR     sys_mq_getsetattr               /* 5235 */
469 -       PTR     sys_ni_syscall                  /* sys_vserver */
470 +       PTR     sys_vserver
471         PTR     sys_waitid
472         PTR     sys_ni_syscall                  /* available, was setaltroot */
473         PTR     sys_add_key
474 diff -NurpP --minimal linux-2.6.35.4/arch/mips/kernel/scall64-n32.S linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/scall64-n32.S
475 --- linux-2.6.35.4/arch/mips/kernel/scall64-n32.S       2010-08-02 16:52:05.000000000 +0200
476 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/scall64-n32.S 2010-08-02 17:05:05.000000000 +0200
477 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
478         PTR     compat_sys_mq_timedreceive
479         PTR     compat_sys_mq_notify
480         PTR     compat_sys_mq_getsetattr
481 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
482 +       PTR     sys32_vserver                   /* 6240 */
483         PTR     compat_sys_waitid
484         PTR     sys_ni_syscall                  /* available, was setaltroot */
485         PTR     sys_add_key
486 diff -NurpP --minimal linux-2.6.35.4/arch/mips/kernel/scall64-o32.S linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/scall64-o32.S
487 --- linux-2.6.35.4/arch/mips/kernel/scall64-o32.S       2010-07-07 18:31:04.000000000 +0200
488 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/scall64-o32.S 2010-08-02 17:05:05.000000000 +0200
489 @@ -480,7 +480,7 @@ sys_call_table:
490         PTR     compat_sys_mq_timedreceive
491         PTR     compat_sys_mq_notify            /* 4275 */
492         PTR     compat_sys_mq_getsetattr
493 -       PTR     sys_ni_syscall                  /* sys_vserver */
494 +       PTR     sys32_vserver
495         PTR     sys_32_waitid
496         PTR     sys_ni_syscall                  /* available, was setaltroot */
497         PTR     sys_add_key                     /* 4280 */
498 diff -NurpP --minimal linux-2.6.35.4/arch/mips/kernel/traps.c linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/traps.c
499 --- linux-2.6.35.4/arch/mips/kernel/traps.c     2010-08-02 16:52:05.000000000 +0200
500 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/mips/kernel/traps.c       2010-08-02 17:05:05.000000000 +0200
501 @@ -340,9 +340,10 @@ void show_registers(const struct pt_regs
502  
503         __show_regs(regs);
504         print_modules();
505 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
506 -              current->comm, current->pid, current_thread_info(), current,
507 -             field, current_thread_info()->tp_value);
508 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
509 +               current->comm, task_pid_nr(current), current->xid,
510 +               current_thread_info(), current,
511 +               field, current_thread_info()->tp_value);
512         if (cpu_has_userlocal) {
513                 unsigned long tls;
514  
515 diff -NurpP --minimal linux-2.6.35.4/arch/parisc/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/parisc/Kconfig
516 --- linux-2.6.35.4/arch/parisc/Kconfig  2010-08-02 16:52:06.000000000 +0200
517 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/parisc/Kconfig    2010-08-02 17:05:05.000000000 +0200
518 @@ -299,6 +299,8 @@ source "fs/Kconfig"
519  
520  source "arch/parisc/Kconfig.debug"
521  
522 +source "kernel/vserver/Kconfig"
523 +
524  source "security/Kconfig"
525  
526  source "crypto/Kconfig"
527 diff -NurpP --minimal linux-2.6.35.4/arch/parisc/kernel/syscall_table.S linux-2.6.35.4-vs2.3.0.36.32/arch/parisc/kernel/syscall_table.S
528 --- linux-2.6.35.4/arch/parisc/kernel/syscall_table.S   2010-07-07 18:31:04.000000000 +0200
529 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/parisc/kernel/syscall_table.S     2010-08-02 17:05:05.000000000 +0200
530 @@ -361,7 +361,7 @@
531         ENTRY_COMP(mbind)               /* 260 */
532         ENTRY_COMP(get_mempolicy)
533         ENTRY_COMP(set_mempolicy)
534 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
535 +       ENTRY_DIFF(vserver)
536         ENTRY_SAME(add_key)
537         ENTRY_SAME(request_key)         /* 265 */
538         ENTRY_SAME(keyctl)
539 diff -NurpP --minimal linux-2.6.35.4/arch/parisc/kernel/traps.c linux-2.6.35.4-vs2.3.0.36.32/arch/parisc/kernel/traps.c
540 --- linux-2.6.35.4/arch/parisc/kernel/traps.c   2009-09-10 15:25:40.000000000 +0200
541 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/parisc/kernel/traps.c     2010-08-02 17:05:05.000000000 +0200
542 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
543                 if (err == 0)
544                         return; /* STFU */
545  
546 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
547 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
548 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
549 +                       current->comm, task_pid_nr(current), current->xid,
550 +                       str, err, regs->iaoq[0]);
551  #ifdef PRINT_USER_FAULTS
552                 /* XXX for debugging only */
553                 show_regs(regs);
554 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
555                 pdc_console_restart();
556         
557         if (err)
558 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
559 -                       current->comm, task_pid_nr(current), str, err);
560 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
561 +                       current->comm, task_pid_nr(current), current->xid, str, err);
562  
563         /* Wot's wrong wif bein' racy? */
564         if (current->thread.flags & PARISC_KERNEL_DEATH) {
565 diff -NurpP --minimal linux-2.6.35.4/arch/parisc/mm/fault.c linux-2.6.35.4-vs2.3.0.36.32/arch/parisc/mm/fault.c
566 --- linux-2.6.35.4/arch/parisc/mm/fault.c       2010-08-02 16:52:06.000000000 +0200
567 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/parisc/mm/fault.c 2010-08-02 17:05:05.000000000 +0200
568 @@ -237,8 +237,9 @@ bad_area:
569  
570  #ifdef PRINT_USER_FAULTS
571                 printk(KERN_DEBUG "\n");
572 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
573 -                   task_pid_nr(tsk), tsk->comm, code, address);
574 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
575 +                   "command='%s' type=%lu address=0x%08lx\n",
576 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
577                 if (vma) {
578                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
579                                         vma->vm_start, vma->vm_end);
580 diff -NurpP --minimal linux-2.6.35.4/arch/powerpc/include/asm/unistd.h linux-2.6.35.4-vs2.3.0.36.32/arch/powerpc/include/asm/unistd.h
581 --- linux-2.6.35.4/arch/powerpc/include/asm/unistd.h    2010-07-07 18:31:05.000000000 +0200
582 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/powerpc/include/asm/unistd.h      2010-08-02 17:05:05.000000000 +0200
583 @@ -275,7 +275,7 @@
584  #endif
585  #define __NR_rtas              255
586  #define __NR_sys_debug_setcontext 256
587 -/* Number 257 is reserved for vserver */
588 +#define __NR_vserver           257
589  #define __NR_migrate_pages     258
590  #define __NR_mbind             259
591  #define __NR_get_mempolicy     260
592 diff -NurpP --minimal linux-2.6.35.4/arch/powerpc/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/powerpc/Kconfig
593 --- linux-2.6.35.4/arch/powerpc/Kconfig 2010-08-02 16:52:06.000000000 +0200
594 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/powerpc/Kconfig   2010-08-02 17:05:05.000000000 +0200
595 @@ -990,6 +990,8 @@ source "lib/Kconfig"
596  
597  source "arch/powerpc/Kconfig.debug"
598  
599 +source "kernel/vserver/Kconfig"
600 +
601  source "security/Kconfig"
602  
603  config KEYS_COMPAT
604 diff -NurpP --minimal linux-2.6.35.4/arch/powerpc/kernel/process.c linux-2.6.35.4-vs2.3.0.36.32/arch/powerpc/kernel/process.c
605 --- linux-2.6.35.4/arch/powerpc/kernel/process.c        2010-08-02 16:52:07.000000000 +0200
606 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/powerpc/kernel/process.c  2010-08-02 17:05:05.000000000 +0200
607 @@ -605,8 +605,9 @@ void show_regs(struct pt_regs * regs)
608  #else
609                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
610  #endif
611 -       printk("TASK = %p[%d] '%s' THREAD: %p",
612 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
613 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
614 +              current, task_pid_nr(current), current->xid,
615 +              current->comm, task_thread_info(current));
616  
617  #ifdef CONFIG_SMP
618         printk(" CPU: %d", raw_smp_processor_id());
619 diff -NurpP --minimal linux-2.6.35.4/arch/powerpc/kernel/traps.c linux-2.6.35.4-vs2.3.0.36.32/arch/powerpc/kernel/traps.c
620 --- linux-2.6.35.4/arch/powerpc/kernel/traps.c  2010-08-02 16:52:07.000000000 +0200
621 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/powerpc/kernel/traps.c    2010-08-02 17:05:05.000000000 +0200
622 @@ -1053,8 +1053,9 @@ void nonrecoverable_exception(struct pt_
623  
624  void trace_syscall(struct pt_regs *regs)
625  {
626 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
627 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
628 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
629 +              current, task_pid_nr(current), current->xid,
630 +              regs->nip, regs->link, regs->gpr[0],
631                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
632  }
633  
634 diff -NurpP --minimal linux-2.6.35.4/arch/powerpc/kernel/vdso.c linux-2.6.35.4-vs2.3.0.36.32/arch/powerpc/kernel/vdso.c
635 --- linux-2.6.35.4/arch/powerpc/kernel/vdso.c   2010-08-02 16:52:07.000000000 +0200
636 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/powerpc/kernel/vdso.c     2010-08-02 17:43:41.000000000 +0200
637 @@ -23,6 +23,7 @@
638  #include <linux/security.h>
639  #include <linux/bootmem.h>
640  #include <linux/memblock.h>
641 +#include <linux/vs_memory.h>
642  
643  #include <asm/pgtable.h>
644  #include <asm/system.h>
645 diff -NurpP --minimal linux-2.6.35.4/arch/s390/include/asm/tlb.h linux-2.6.35.4-vs2.3.0.36.32/arch/s390/include/asm/tlb.h
646 --- linux-2.6.35.4/arch/s390/include/asm/tlb.h  2009-09-10 15:25:43.000000000 +0200
647 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/s390/include/asm/tlb.h    2010-08-02 17:05:05.000000000 +0200
648 @@ -23,6 +23,8 @@
649  
650  #include <linux/mm.h>
651  #include <linux/swap.h>
652 +#include <linux/vs_memory.h>
653 +
654  #include <asm/processor.h>
655  #include <asm/pgalloc.h>
656  #include <asm/smp.h>
657 diff -NurpP --minimal linux-2.6.35.4/arch/s390/include/asm/unistd.h linux-2.6.35.4-vs2.3.0.36.32/arch/s390/include/asm/unistd.h
658 --- linux-2.6.35.4/arch/s390/include/asm/unistd.h       2010-07-07 18:31:06.000000000 +0200
659 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/s390/include/asm/unistd.h 2010-08-02 17:05:05.000000000 +0200
660 @@ -202,7 +202,7 @@
661  #define __NR_clock_gettime     (__NR_timer_create+6)
662  #define __NR_clock_getres      (__NR_timer_create+7)
663  #define __NR_clock_nanosleep   (__NR_timer_create+8)
664 -/* Number 263 is reserved for vserver */
665 +#define __NR_vserver           263
666  #define __NR_statfs64          265
667  #define __NR_fstatfs64         266
668  #define __NR_remap_file_pages  267
669 diff -NurpP --minimal linux-2.6.35.4/arch/s390/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/s390/Kconfig
670 --- linux-2.6.35.4/arch/s390/Kconfig    2010-08-02 16:52:08.000000000 +0200
671 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/s390/Kconfig      2010-08-02 17:05:05.000000000 +0200
672 @@ -623,6 +623,8 @@ source "fs/Kconfig"
673  
674  source "arch/s390/Kconfig.debug"
675  
676 +source "kernel/vserver/Kconfig"
677 +
678  source "security/Kconfig"
679  
680  source "crypto/Kconfig"
681 diff -NurpP --minimal linux-2.6.35.4/arch/s390/kernel/ptrace.c linux-2.6.35.4-vs2.3.0.36.32/arch/s390/kernel/ptrace.c
682 --- linux-2.6.35.4/arch/s390/kernel/ptrace.c    2010-08-02 16:52:09.000000000 +0200
683 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/s390/kernel/ptrace.c      2010-08-02 17:05:05.000000000 +0200
684 @@ -36,6 +36,7 @@
685  #include <linux/regset.h>
686  #include <linux/tracehook.h>
687  #include <linux/seccomp.h>
688 +#include <linux/vs_base.h>
689  #include <trace/syscall.h>
690  #include <asm/compat.h>
691  #include <asm/segment.h>
692 diff -NurpP --minimal linux-2.6.35.4/arch/s390/kernel/syscalls.S linux-2.6.35.4-vs2.3.0.36.32/arch/s390/kernel/syscalls.S
693 --- linux-2.6.35.4/arch/s390/kernel/syscalls.S  2010-07-07 18:31:07.000000000 +0200
694 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/s390/kernel/syscalls.S    2010-08-02 17:05:05.000000000 +0200
695 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
696  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
697  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
698  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
699 -NI_SYSCALL                                                     /* reserved for vserver */
700 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
701  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
702  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
703  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
704 diff -NurpP --minimal linux-2.6.35.4/arch/sh/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/sh/Kconfig
705 --- linux-2.6.35.4/arch/sh/Kconfig      2010-08-02 16:52:09.000000000 +0200
706 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/sh/Kconfig        2010-08-02 17:05:05.000000000 +0200
707 @@ -881,6 +881,8 @@ source "fs/Kconfig"
708  
709  source "arch/sh/Kconfig.debug"
710  
711 +source "kernel/vserver/Kconfig"
712 +
713  source "security/Kconfig"
714  
715  source "crypto/Kconfig"
716 diff -NurpP --minimal linux-2.6.35.4/arch/sh/kernel/irq.c linux-2.6.35.4-vs2.3.0.36.32/arch/sh/kernel/irq.c
717 --- linux-2.6.35.4/arch/sh/kernel/irq.c 2010-08-02 16:52:10.000000000 +0200
718 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/sh/kernel/irq.c   2010-08-02 17:41:50.000000000 +0200
719 @@ -13,6 +13,7 @@
720  #include <linux/seq_file.h>
721  #include <linux/ftrace.h>
722  #include <linux/delay.h>
723 +// #include <linux/vs_context.h>
724  #include <asm/processor.h>
725  #include <asm/machvec.h>
726  #include <asm/uaccess.h>
727 diff -NurpP --minimal linux-2.6.35.4/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.35.4-vs2.3.0.36.32/arch/sh/kernel/vsyscall/vsyscall.c
728 --- linux-2.6.35.4/arch/sh/kernel/vsyscall/vsyscall.c   2010-07-07 18:31:10.000000000 +0200
729 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/sh/kernel/vsyscall/vsyscall.c     2010-08-02 17:05:05.000000000 +0200
730 @@ -18,6 +18,7 @@
731  #include <linux/elf.h>
732  #include <linux/sched.h>
733  #include <linux/err.h>
734 +#include <linux/vs_memory.h>
735  
736  /*
737   * Should the kernel map a VDSO page into processes and pass its
738 diff -NurpP --minimal linux-2.6.35.4/arch/sparc/include/asm/tlb_64.h linux-2.6.35.4-vs2.3.0.36.32/arch/sparc/include/asm/tlb_64.h
739 --- linux-2.6.35.4/arch/sparc/include/asm/tlb_64.h      2009-09-10 15:25:45.000000000 +0200
740 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/sparc/include/asm/tlb_64.h        2010-08-02 17:05:05.000000000 +0200
741 @@ -3,6 +3,7 @@
742  
743  #include <linux/swap.h>
744  #include <linux/pagemap.h>
745 +#include <linux/vs_memory.h>
746  #include <asm/pgalloc.h>
747  #include <asm/tlbflush.h>
748  #include <asm/mmu_context.h>
749 diff -NurpP --minimal linux-2.6.35.4/arch/sparc/include/asm/unistd.h linux-2.6.35.4-vs2.3.0.36.32/arch/sparc/include/asm/unistd.h
750 --- linux-2.6.35.4/arch/sparc/include/asm/unistd.h      2010-07-07 18:31:10.000000000 +0200
751 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/sparc/include/asm/unistd.h        2010-08-02 17:05:05.000000000 +0200
752 @@ -335,7 +335,7 @@
753  #define __NR_timer_getoverrun  264
754  #define __NR_timer_delete      265
755  #define __NR_timer_create      266
756 -/* #define __NR_vserver                267 Reserved for VSERVER */
757 +#define __NR_vserver           267
758  #define __NR_io_setup          268
759  #define __NR_io_destroy                269
760  #define __NR_io_submit         270
761 diff -NurpP --minimal linux-2.6.35.4/arch/sparc/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/sparc/Kconfig
762 --- linux-2.6.35.4/arch/sparc/Kconfig   2010-08-02 16:52:10.000000000 +0200
763 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/sparc/Kconfig     2010-08-02 17:05:05.000000000 +0200
764 @@ -570,6 +570,8 @@ source "fs/Kconfig"
765  
766  source "arch/sparc/Kconfig.debug"
767  
768 +source "kernel/vserver/Kconfig"
769 +
770  source "security/Kconfig"
771  
772  source "crypto/Kconfig"
773 diff -NurpP --minimal linux-2.6.35.4/arch/sparc/kernel/systbls_32.S linux-2.6.35.4-vs2.3.0.36.32/arch/sparc/kernel/systbls_32.S
774 --- linux-2.6.35.4/arch/sparc/kernel/systbls_32.S       2010-02-25 11:51:34.000000000 +0100
775 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/sparc/kernel/systbls_32.S 2010-08-02 17:05:05.000000000 +0200
776 @@ -70,7 +70,7 @@ sys_call_table:
777  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
778  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
779  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
780 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
781 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
782  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
783  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
784  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
785 diff -NurpP --minimal linux-2.6.35.4/arch/sparc/kernel/systbls_64.S linux-2.6.35.4-vs2.3.0.36.32/arch/sparc/kernel/systbls_64.S
786 --- linux-2.6.35.4/arch/sparc/kernel/systbls_64.S       2010-07-07 18:31:10.000000000 +0200
787 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/sparc/kernel/systbls_64.S 2010-08-02 17:05:05.000000000 +0200
788 @@ -71,7 +71,7 @@ sys_call_table32:
789  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
790         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
791  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
792 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
793 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
794  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
795         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
796  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
797 @@ -146,7 +146,7 @@ sys_call_table:
798  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
799         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
800  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
801 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
802 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
803  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
804         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
805  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
806 diff -NurpP --minimal linux-2.6.35.4/arch/um/include/asm/tlb.h linux-2.6.35.4-vs2.3.0.36.32/arch/um/include/asm/tlb.h
807 --- linux-2.6.35.4/arch/um/include/asm/tlb.h    2009-09-10 15:25:46.000000000 +0200
808 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/um/include/asm/tlb.h      2010-08-02 17:05:05.000000000 +0200
809 @@ -3,6 +3,7 @@
810  
811  #include <linux/pagemap.h>
812  #include <linux/swap.h>
813 +#include <linux/vs_memory.h>
814  #include <asm/percpu.h>
815  #include <asm/pgalloc.h>
816  #include <asm/tlbflush.h>
817 diff -NurpP --minimal linux-2.6.35.4/arch/um/include/shared/kern_constants.h linux-2.6.35.4-vs2.3.0.36.32/arch/um/include/shared/kern_constants.h
818 --- linux-2.6.35.4/arch/um/include/shared/kern_constants.h      1970-01-01 01:00:00.000000000 +0100
819 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/um/include/shared/kern_constants.h        2010-08-02 17:05:05.000000000 +0200
820 @@ -0,0 +1 @@
821 +#include "../../../../include/generated/asm-offsets.h"
822 diff -NurpP --minimal linux-2.6.35.4/arch/um/include/shared/user_constants.h linux-2.6.35.4-vs2.3.0.36.32/arch/um/include/shared/user_constants.h
823 --- linux-2.6.35.4/arch/um/include/shared/user_constants.h      1970-01-01 01:00:00.000000000 +0100
824 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/um/include/shared/user_constants.h        2010-08-02 17:05:05.000000000 +0200
825 @@ -0,0 +1,40 @@
826 +/*
827 + * DO NOT MODIFY.
828 + *
829 + * This file was generated by arch/um/Makefile
830 + *
831 + */
832 +
833 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
834 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
835 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
836 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
837 +#define HOST_RBX 5 /* RBX      # */
838 +#define HOST_RCX 11 /* RCX     # */
839 +#define HOST_RDI 14 /* RDI     # */
840 +#define HOST_RSI 13 /* RSI     # */
841 +#define HOST_RDX 12 /* RDX     # */
842 +#define HOST_RBP 4 /* RBP      # */
843 +#define HOST_RAX 10 /* RAX     # */
844 +#define HOST_R8 9 /* R8        # */
845 +#define HOST_R9 8 /* R9        # */
846 +#define HOST_R10 7 /* R10      # */
847 +#define HOST_R11 6 /* R11      # */
848 +#define HOST_R12 3 /* R12      # */
849 +#define HOST_R13 2 /* R13      # */
850 +#define HOST_R14 1 /* R14      # */
851 +#define HOST_R15 0 /* R15      # */
852 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
853 +#define HOST_CS 17 /* CS       # */
854 +#define HOST_SS 20 /* SS       # */
855 +#define HOST_EFLAGS 18 /* EFLAGS       # */
856 +#define HOST_IP 16 /* RIP      # */
857 +#define HOST_SP 19 /* RSP      # */
858 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
859 +#define UM_POLLIN 1 /* POLLIN  # */
860 +#define UM_POLLPRI 2 /* POLLPRI        # */
861 +#define UM_POLLOUT 4 /* POLLOUT        # */
862 +#define UM_PROT_READ 1 /* PROT_READ    # */
863 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
864 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
865 +
866 diff -NurpP --minimal linux-2.6.35.4/arch/um/Kconfig.rest linux-2.6.35.4-vs2.3.0.36.32/arch/um/Kconfig.rest
867 --- linux-2.6.35.4/arch/um/Kconfig.rest 2009-06-11 17:12:19.000000000 +0200
868 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/um/Kconfig.rest   2010-08-02 17:05:05.000000000 +0200
869 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
870  
871  source "fs/Kconfig"
872  
873 +source "kernel/vserver/Kconfig"
874 +
875  source "security/Kconfig"
876  
877  source "crypto/Kconfig"
878 diff -NurpP --minimal linux-2.6.35.4/arch/x86/ia32/ia32entry.S linux-2.6.35.4-vs2.3.0.36.32/arch/x86/ia32/ia32entry.S
879 --- linux-2.6.35.4/arch/x86/ia32/ia32entry.S    2010-07-07 18:31:11.000000000 +0200
880 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/x86/ia32/ia32entry.S      2010-08-02 17:05:05.000000000 +0200
881 @@ -777,7 +777,7 @@ ia32_sys_call_table:
882         .quad sys_tgkill                /* 270 */
883         .quad compat_sys_utimes
884         .quad sys32_fadvise64_64
885 -       .quad quiet_ni_syscall  /* sys_vserver */
886 +       .quad sys32_vserver
887         .quad sys_mbind
888         .quad compat_sys_get_mempolicy  /* 275 */
889         .quad sys_set_mempolicy
890 diff -NurpP --minimal linux-2.6.35.4/arch/x86/include/asm/unistd_64.h linux-2.6.35.4-vs2.3.0.36.32/arch/x86/include/asm/unistd_64.h
891 --- linux-2.6.35.4/arch/x86/include/asm/unistd_64.h     2010-07-07 18:31:11.000000000 +0200
892 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/x86/include/asm/unistd_64.h       2010-08-02 17:05:05.000000000 +0200
893 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
894  #define __NR_utimes                            235
895  __SYSCALL(__NR_utimes, sys_utimes)
896  #define __NR_vserver                           236
897 -__SYSCALL(__NR_vserver, sys_ni_syscall)
898 +__SYSCALL(__NR_vserver, sys_vserver)
899  #define __NR_mbind                             237
900  __SYSCALL(__NR_mbind, sys_mbind)
901  #define __NR_set_mempolicy                     238
902 diff -NurpP --minimal linux-2.6.35.4/arch/x86/Kconfig linux-2.6.35.4-vs2.3.0.36.32/arch/x86/Kconfig
903 --- linux-2.6.35.4/arch/x86/Kconfig     2010-09-05 01:41:56.000000000 +0200
904 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/x86/Kconfig       2010-09-06 02:59:52.000000000 +0200
905 @@ -2128,6 +2128,8 @@ source "fs/Kconfig"
906  
907  source "arch/x86/Kconfig.debug"
908  
909 +source "kernel/vserver/Kconfig"
910 +
911  source "security/Kconfig"
912  
913  source "crypto/Kconfig"
914 diff -NurpP --minimal linux-2.6.35.4/arch/x86/kernel/syscall_table_32.S linux-2.6.35.4-vs2.3.0.36.32/arch/x86/kernel/syscall_table_32.S
915 --- linux-2.6.35.4/arch/x86/kernel/syscall_table_32.S   2010-07-07 18:31:12.000000000 +0200
916 +++ linux-2.6.35.4-vs2.3.0.36.32/arch/x86/kernel/syscall_table_32.S     2010-08-02 17:05:05.000000000 +0200
917 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
918         .long sys_tgkill        /* 270 */
919         .long sys_utimes
920         .long sys_fadvise64_64
921 -       .long sys_ni_syscall    /* sys_vserver */
922 +       .long sys_vserver
923         .long sys_mbind
924         .long sys_get_mempolicy
925         .long sys_set_mempolicy
926 diff -NurpP --minimal linux-2.6.35.4/Documentation/vserver/debug.txt linux-2.6.35.4-vs2.3.0.36.32/Documentation/vserver/debug.txt
927 --- linux-2.6.35.4/Documentation/vserver/debug.txt      1970-01-01 01:00:00.000000000 +0100
928 +++ linux-2.6.35.4-vs2.3.0.36.32/Documentation/vserver/debug.txt        2010-08-02 17:05:05.000000000 +0200
929 @@ -0,0 +1,154 @@
930 +
931 +debug_cvirt:
932 +
933 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
934 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
935 +
936 +debug_dlim:
937 +
938 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
939 +       "FREE  (%p,#%d)%c inode"
940 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
941 +       "FREE  (%p,#%d)%c %lld bytes"
942 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
943 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
944 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
945 +       "rcu_free_dl_info(%p)"
946 + 4  10 "alloc_dl_info(%p,%d) = %p"
947 +       "dealloc_dl_info(%p)"
948 +       "get_dl_info(%p[#%d.%d])"
949 +       "put_dl_info(%p[#%d.%d])"
950 + 5  20 "alloc_dl_info(%p,%d)*"
951 + 6  40 "__hash_dl_info: %p[#%d]"
952 +       "__unhash_dl_info: %p[#%d]"
953 + 7  80 "locate_dl_info(%p,#%d) = %p"
954 +
955 +debug_misc:
956 +
957 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
958 +       "new_dqhash: %p [#0x%08x]"
959 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
960 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
961 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
962 +       "vroot_get_real_bdev not set"
963 + 1   2 "cow_break_link(»%s«)"
964 +       "temp copy Â»%s«"
965 + 2   4 "dentry_open(new): %p"
966 +       "dentry_open(old): %p"
967 +       "lookup_create(new): %p"
968 +       "old path Â»%s«"
969 +       "path_lookup(old): %d"
970 +       "vfs_create(new): %d"
971 +       "vfs_rename: %d"
972 +       "vfs_sendfile: %d"
973 + 3   8 "fput(new_file=%p[#%d])"
974 +       "fput(old_file=%p[#%d])"
975 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
976 +       "vx_info_kill(%p[#%d],%d,%d)*"
977 + 5  20 "vs_reboot(%p[#%d],%d)"
978 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
979 +
980 +debug_net:
981 +
982 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
983 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
984 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
985 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
986 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
987 + 6  40 "sk,egf: %p [#%d] (from %d)"
988 +       "sk,egn: %p [#%d] (from %d)"
989 +       "sk,req: %p [#%d] (from %d)"
990 +       "sk: %p [#%d] (from %d)"
991 +       "tw: %p [#%d] (from %d)"
992 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
993 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
994 +
995 +debug_nid:
996 +
997 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
998 +       "alloc_nx_info(%d) = %p"
999 +       "create_nx_info(%d) (dynamic rejected)"
1000 +       "create_nx_info(%d) = %p (already there)"
1001 +       "create_nx_info(%d) = %p (new)"
1002 +       "dealloc_nx_info(%p)"
1003 + 1   2 "alloc_nx_info(%d)*"
1004 +       "create_nx_info(%d)*"
1005 + 2   4 "get_nx_info(%p[#%d.%d])"
1006 +       "put_nx_info(%p[#%d.%d])"
1007 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
1008 +       "clr_nx_info(%p[#%d.%d])"
1009 +       "init_nx_info(%p[#%d.%d])"
1010 +       "release_nx_info(%p[#%d.%d.%d]) %p"
1011 +       "set_nx_info(%p[#%d.%d])"
1012 + 4  10 "__hash_nx_info: %p[#%d]"
1013 +       "__nx_dynamic_id: [#%d]"
1014 +       "__unhash_nx_info: %p[#%d.%d.%d]"
1015 + 5  20 "moved task %p into nxi:%p[#%d]"
1016 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
1017 +       "task_get_nx_info(%p)"
1018 + 6  40 "nx_clear_persistent(%p[#%d])"
1019 +
1020 +debug_quota:
1021 +
1022 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
1023 + 1   2 "quota_sync_dqh(%p,%d)"
1024 +       "sync_dquots(%p,%d)"
1025 +       "sync_dquots_dqh(%p,%d)"
1026 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
1027 +
1028 +debug_switch:
1029 +
1030 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
1031 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
1032 + 4  10 "%s: (%s %s) returned %s with %d"
1033 +
1034 +debug_tag:
1035 +
1036 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
1037 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1038 +
1039 +debug_xid:
1040 +
1041 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1042 +       "alloc_vx_info(%d) = %p"
1043 +       "alloc_vx_info(%d)*"
1044 +       "create_vx_info(%d) (dynamic rejected)"
1045 +       "create_vx_info(%d) = %p (already there)"
1046 +       "create_vx_info(%d) = %p (new)"
1047 +       "dealloc_vx_info(%p)"
1048 +       "loc_vx_info(%d) = %p (found)"
1049 +       "loc_vx_info(%d) = %p (new)"
1050 +       "loc_vx_info(%d) = %p (not available)"
1051 + 1   2 "create_vx_info(%d)*"
1052 +       "loc_vx_info(%d)*"
1053 + 2   4 "get_vx_info(%p[#%d.%d])"
1054 +       "put_vx_info(%p[#%d.%d])"
1055 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1056 +       "clr_vx_info(%p[#%d.%d])"
1057 +       "init_vx_info(%p[#%d.%d])"
1058 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1059 +       "set_vx_info(%p[#%d.%d])"
1060 + 4  10 "__hash_vx_info: %p[#%d]"
1061 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1062 +       "__vx_dynamic_id: [#%d]"
1063 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1064 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1065 +       "moved task %p into vxi:%p[#%d]"
1066 +       "task_get_vx_info(%p)"
1067 +       "vx_migrate_task(%p,%p[#%d.%d])"
1068 + 6  40 "vx_clear_persistent(%p[#%d])"
1069 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1070 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1071 +       "vx_set_persistent(%p[#%d])"
1072 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1073 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1074 +
1075 +
1076 +debug_limit:
1077 +
1078 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1079 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1080 +
1081 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1082 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1083 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1084 diff -NurpP --minimal linux-2.6.35.4/drivers/block/Kconfig linux-2.6.35.4-vs2.3.0.36.32/drivers/block/Kconfig
1085 --- linux-2.6.35.4/drivers/block/Kconfig        2010-08-02 16:52:14.000000000 +0200
1086 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/block/Kconfig  2010-08-02 17:05:05.000000000 +0200
1087 @@ -273,6 +273,13 @@ config BLK_DEV_CRYPTOLOOP
1088  
1089  source "drivers/block/drbd/Kconfig"
1090  
1091 +config BLK_DEV_VROOT
1092 +       tristate "Virtual Root device support"
1093 +       depends on QUOTACTL
1094 +       ---help---
1095 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1096 +         partition within a virtual server without compromising security.
1097 +
1098  config BLK_DEV_NBD
1099         tristate "Network block device support"
1100         depends on NET
1101 diff -NurpP --minimal linux-2.6.35.4/drivers/block/loop.c linux-2.6.35.4-vs2.3.0.36.32/drivers/block/loop.c
1102 --- linux-2.6.35.4/drivers/block/loop.c 2010-08-02 16:52:14.000000000 +0200
1103 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/block/loop.c   2010-08-02 17:05:05.000000000 +0200
1104 @@ -73,6 +73,7 @@
1105  #include <linux/highmem.h>
1106  #include <linux/kthread.h>
1107  #include <linux/splice.h>
1108 +#include <linux/vs_context.h>
1109  
1110  #include <asm/uaccess.h>
1111  
1112 @@ -813,6 +814,7 @@ static int loop_set_fd(struct loop_devic
1113         lo->lo_blocksize = lo_blocksize;
1114         lo->lo_device = bdev;
1115         lo->lo_flags = lo_flags;
1116 +       lo->lo_xid = vx_current_xid();
1117         lo->lo_backing_file = file;
1118         lo->transfer = transfer_none;
1119         lo->ioctl = NULL;
1120 @@ -941,6 +943,7 @@ static int loop_clr_fd(struct loop_devic
1121         lo->lo_encrypt_key_size = 0;
1122         lo->lo_flags = 0;
1123         lo->lo_thread = NULL;
1124 +       lo->lo_xid = 0;
1125         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1126         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1127         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1128 @@ -978,7 +981,7 @@ loop_set_status(struct loop_device *lo, 
1129  
1130         if (lo->lo_encrypt_key_size &&
1131             lo->lo_key_owner != uid &&
1132 -           !capable(CAP_SYS_ADMIN))
1133 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1134                 return -EPERM;
1135         if (lo->lo_state != Lo_bound)
1136                 return -ENXIO;
1137 @@ -1062,7 +1065,8 @@ loop_get_status(struct loop_device *lo, 
1138         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1139         info->lo_encrypt_type =
1140                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1141 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1142 +       if (lo->lo_encrypt_key_size &&
1143 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1144                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1145                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1146                        lo->lo_encrypt_key_size);
1147 @@ -1408,6 +1412,9 @@ static int lo_open(struct block_device *
1148  {
1149         struct loop_device *lo = bdev->bd_disk->private_data;
1150  
1151 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1152 +               return -EACCES;
1153 +
1154         mutex_lock(&lo->lo_ctl_mutex);
1155         lo->lo_refcnt++;
1156         mutex_unlock(&lo->lo_ctl_mutex);
1157 diff -NurpP --minimal linux-2.6.35.4/drivers/block/Makefile linux-2.6.35.4-vs2.3.0.36.32/drivers/block/Makefile
1158 --- linux-2.6.35.4/drivers/block/Makefile       2010-02-25 11:51:36.000000000 +0100
1159 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/block/Makefile 2010-08-02 17:05:05.000000000 +0200
1160 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1161  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1162  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1163  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1164 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1165  
1166  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1167  obj-$(CONFIG_BLK_DEV_DRBD)     += drbd/
1168 diff -NurpP --minimal linux-2.6.35.4/drivers/block/vroot.c linux-2.6.35.4-vs2.3.0.36.32/drivers/block/vroot.c
1169 --- linux-2.6.35.4/drivers/block/vroot.c        1970-01-01 01:00:00.000000000 +0100
1170 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/block/vroot.c  2010-08-02 17:05:05.000000000 +0200
1171 @@ -0,0 +1,282 @@
1172 +/*
1173 + *  linux/drivers/block/vroot.c
1174 + *
1175 + *  written by Herbert Pötzl, 9/11/2002
1176 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1177 + *
1178 + *  based on the loop.c code by Theodore Ts'o.
1179 + *
1180 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1181 + * Redistribution of this file is permitted under the
1182 + * GNU General Public License.
1183 + *
1184 + */
1185 +
1186 +#include <linux/module.h>
1187 +#include <linux/moduleparam.h>
1188 +#include <linux/file.h>
1189 +#include <linux/major.h>
1190 +#include <linux/blkdev.h>
1191 +#include <linux/slab.h>
1192 +
1193 +#include <linux/vroot.h>
1194 +#include <linux/vs_context.h>
1195 +
1196 +
1197 +static int max_vroot = 8;
1198 +
1199 +static struct vroot_device *vroot_dev;
1200 +static struct gendisk **disks;
1201 +
1202 +
1203 +static int vroot_set_dev(
1204 +       struct vroot_device *vr,
1205 +       struct block_device *bdev,
1206 +       unsigned int arg)
1207 +{
1208 +       struct block_device *real_bdev;
1209 +       struct file *file;
1210 +       struct inode *inode;
1211 +       int error;
1212 +
1213 +       error = -EBUSY;
1214 +       if (vr->vr_state != Vr_unbound)
1215 +               goto out;
1216 +
1217 +       error = -EBADF;
1218 +       file = fget(arg);
1219 +       if (!file)
1220 +               goto out;
1221 +
1222 +       error = -EINVAL;
1223 +       inode = file->f_dentry->d_inode;
1224 +
1225 +
1226 +       if (S_ISBLK(inode->i_mode)) {
1227 +               real_bdev = inode->i_bdev;
1228 +               vr->vr_device = real_bdev;
1229 +               __iget(real_bdev->bd_inode);
1230 +       } else
1231 +               goto out_fput;
1232 +
1233 +       vxdprintk(VXD_CBIT(misc, 0),
1234 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1235 +               vr->vr_number, VXD_DEV(real_bdev));
1236 +
1237 +       vr->vr_state = Vr_bound;
1238 +       error = 0;
1239 +
1240 + out_fput:
1241 +       fput(file);
1242 + out:
1243 +       return error;
1244 +}
1245 +
1246 +static int vroot_clr_dev(
1247 +       struct vroot_device *vr,
1248 +       struct block_device *bdev)
1249 +{
1250 +       struct block_device *real_bdev;
1251 +
1252 +       if (vr->vr_state != Vr_bound)
1253 +               return -ENXIO;
1254 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1255 +               return -EBUSY;
1256 +
1257 +       real_bdev = vr->vr_device;
1258 +
1259 +       vxdprintk(VXD_CBIT(misc, 0),
1260 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1261 +               vr->vr_number, VXD_DEV(real_bdev));
1262 +
1263 +       bdput(real_bdev);
1264 +       vr->vr_state = Vr_unbound;
1265 +       vr->vr_device = NULL;
1266 +       return 0;
1267 +}
1268 +
1269 +
1270 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1271 +       unsigned int cmd, unsigned long arg)
1272 +{
1273 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1274 +       int err;
1275 +
1276 +       down(&vr->vr_ctl_mutex);
1277 +       switch (cmd) {
1278 +       case VROOT_SET_DEV:
1279 +               err = vroot_set_dev(vr, bdev, arg);
1280 +               break;
1281 +       case VROOT_CLR_DEV:
1282 +               err = vroot_clr_dev(vr, bdev);
1283 +               break;
1284 +       default:
1285 +               err = -EINVAL;
1286 +               break;
1287 +       }
1288 +       up(&vr->vr_ctl_mutex);
1289 +       return err;
1290 +}
1291 +
1292 +static int vr_open(struct block_device *bdev, fmode_t mode)
1293 +{
1294 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1295 +
1296 +       down(&vr->vr_ctl_mutex);
1297 +       vr->vr_refcnt++;
1298 +       up(&vr->vr_ctl_mutex);
1299 +       return 0;
1300 +}
1301 +
1302 +static int vr_release(struct gendisk *disk, fmode_t mode)
1303 +{
1304 +       struct vroot_device *vr = disk->private_data;
1305 +
1306 +       down(&vr->vr_ctl_mutex);
1307 +       --vr->vr_refcnt;
1308 +       up(&vr->vr_ctl_mutex);
1309 +       return 0;
1310 +}
1311 +
1312 +static struct block_device_operations vr_fops = {
1313 +       .owner =        THIS_MODULE,
1314 +       .open =         vr_open,
1315 +       .release =      vr_release,
1316 +       .ioctl =        vr_ioctl,
1317 +};
1318 +
1319 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1320 +{
1321 +       struct inode *inode = bdev->bd_inode;
1322 +       struct vroot_device *vr;
1323 +       struct block_device *real_bdev;
1324 +       int minor = iminor(inode);
1325 +
1326 +       vr = &vroot_dev[minor];
1327 +       real_bdev = vr->vr_device;
1328 +
1329 +       vxdprintk(VXD_CBIT(misc, 0),
1330 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1331 +               vr->vr_number, VXD_DEV(real_bdev));
1332 +
1333 +       if (vr->vr_state != Vr_bound)
1334 +               return ERR_PTR(-ENXIO);
1335 +
1336 +       __iget(real_bdev->bd_inode);
1337 +       return real_bdev;
1338 +}
1339 +
1340 +/*
1341 + * And now the modules code and kernel interface.
1342 + */
1343 +
1344 +module_param(max_vroot, int, 0);
1345 +
1346 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1347 +MODULE_LICENSE("GPL");
1348 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1349 +
1350 +MODULE_AUTHOR ("Herbert Pötzl");
1351 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1352 +
1353 +
1354 +int __init vroot_init(void)
1355 +{
1356 +       int err, i;
1357 +
1358 +       if (max_vroot < 1 || max_vroot > 256) {
1359 +               max_vroot = MAX_VROOT_DEFAULT;
1360 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1361 +                       "(must be between 1 and 256), "
1362 +                       "using default (%d)\n", max_vroot);
1363 +       }
1364 +
1365 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1366 +               return -EIO;
1367 +
1368 +       err = -ENOMEM;
1369 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1370 +       if (!vroot_dev)
1371 +               goto out_mem1;
1372 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1373 +
1374 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1375 +       if (!disks)
1376 +               goto out_mem2;
1377 +
1378 +       for (i = 0; i < max_vroot; i++) {
1379 +               disks[i] = alloc_disk(1);
1380 +               if (!disks[i])
1381 +                       goto out_mem3;
1382 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1383 +               if (!disks[i]->queue)
1384 +                       goto out_mem3;
1385 +       }
1386 +
1387 +       for (i = 0; i < max_vroot; i++) {
1388 +               struct vroot_device *vr = &vroot_dev[i];
1389 +               struct gendisk *disk = disks[i];
1390 +
1391 +               memset(vr, 0, sizeof(*vr));
1392 +               init_MUTEX(&vr->vr_ctl_mutex);
1393 +               vr->vr_number = i;
1394 +               disk->major = VROOT_MAJOR;
1395 +               disk->first_minor = i;
1396 +               disk->fops = &vr_fops;
1397 +               sprintf(disk->disk_name, "vroot%d", i);
1398 +               disk->private_data = vr;
1399 +       }
1400 +
1401 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1402 +       if (err)
1403 +               goto out_mem3;
1404 +
1405 +       for (i = 0; i < max_vroot; i++)
1406 +               add_disk(disks[i]);
1407 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1408 +       return 0;
1409 +
1410 +out_mem3:
1411 +       while (i--)
1412 +               put_disk(disks[i]);
1413 +       kfree(disks);
1414 +out_mem2:
1415 +       kfree(vroot_dev);
1416 +out_mem1:
1417 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1418 +       printk(KERN_ERR "vroot: ran out of memory\n");
1419 +       return err;
1420 +}
1421 +
1422 +void vroot_exit(void)
1423 +{
1424 +       int i;
1425 +
1426 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1427 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1428 +
1429 +       for (i = 0; i < max_vroot; i++) {
1430 +               del_gendisk(disks[i]);
1431 +               put_disk(disks[i]);
1432 +       }
1433 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1434 +
1435 +       kfree(disks);
1436 +       kfree(vroot_dev);
1437 +}
1438 +
1439 +module_init(vroot_init);
1440 +module_exit(vroot_exit);
1441 +
1442 +#ifndef MODULE
1443 +
1444 +static int __init max_vroot_setup(char *str)
1445 +{
1446 +       max_vroot = simple_strtol(str, NULL, 0);
1447 +       return 1;
1448 +}
1449 +
1450 +__setup("max_vroot=", max_vroot_setup);
1451 +
1452 +#endif
1453 +
1454 diff -NurpP --minimal linux-2.6.35.4/drivers/char/sysrq.c linux-2.6.35.4-vs2.3.0.36.32/drivers/char/sysrq.c
1455 --- linux-2.6.35.4/drivers/char/sysrq.c 2010-08-02 16:52:15.000000000 +0200
1456 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/char/sysrq.c   2010-08-02 17:39:50.000000000 +0200
1457 @@ -42,6 +42,7 @@
1458  #include <linux/oom.h>
1459  #include <linux/slab.h>
1460  #include <linux/input.h>
1461 +#include <linux/vserver/debug.h>
1462  
1463  #include <asm/ptrace.h>
1464  #include <asm/irq_regs.h>
1465 @@ -396,6 +397,21 @@ static struct sysrq_key_op sysrq_unrt_op
1466         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1467  };
1468  
1469 +
1470 +#ifdef CONFIG_VSERVER_DEBUG
1471 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1472 +{
1473 +       dump_vx_info_inactive((key == 'x')?0:1);
1474 +}
1475 +
1476 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1477 +       .handler        = sysrq_handle_vxinfo,
1478 +       .help_msg       = "conteXt",
1479 +       .action_msg     = "Show Context Info",
1480 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1481 +};
1482 +#endif
1483 +
1484  /* Key Operations table and lock */
1485  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1486  
1487 @@ -450,7 +466,11 @@ static struct sysrq_key_op *sysrq_key_ta
1488         NULL,                           /* v */
1489         &sysrq_showstate_blocked_op,    /* w */
1490         /* x: May be registered on ppc/powerpc for xmon */
1491 +#ifdef CONFIG_VSERVER_DEBUG
1492 +       &sysrq_showvxinfo_op,           /* x */
1493 +#else
1494         NULL,                           /* x */
1495 +#endif
1496         /* y: May be registered on sparc64 for global register dump */
1497         NULL,                           /* y */
1498         &sysrq_ftrace_dump_op,          /* z */
1499 @@ -465,6 +485,8 @@ static int sysrq_key_table_key2index(int
1500                 retval = key - '0';
1501         else if ((key >= 'a') && (key <= 'z'))
1502                 retval = key + 10 - 'a';
1503 +       else if ((key >= 'A') && (key <= 'Z'))
1504 +               retval = key + 10 - 'A';
1505         else
1506                 retval = -1;
1507         return retval;
1508 diff -NurpP --minimal linux-2.6.35.4/drivers/char/tty_io.c linux-2.6.35.4-vs2.3.0.36.32/drivers/char/tty_io.c
1509 --- linux-2.6.35.4/drivers/char/tty_io.c        2010-09-05 01:41:56.000000000 +0200
1510 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/char/tty_io.c  2010-09-06 02:59:52.000000000 +0200
1511 @@ -106,6 +106,7 @@
1512  
1513  #include <linux/kmod.h>
1514  #include <linux/nsproxy.h>
1515 +#include <linux/vs_pid.h>
1516  
1517  #undef TTY_DEBUG_HANGUP
1518  
1519 @@ -1992,7 +1993,8 @@ static int tiocsti(struct tty_struct *tt
1520         char ch, mbz = 0;
1521         struct tty_ldisc *ld;
1522  
1523 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1524 +       if (((current->signal->tty != tty) &&
1525 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1526                 return -EPERM;
1527         if (get_user(ch, p))
1528                 return -EFAULT;
1529 @@ -2280,6 +2282,7 @@ static int tiocspgrp(struct tty_struct *
1530                 return -ENOTTY;
1531         if (get_user(pgrp_nr, p))
1532                 return -EFAULT;
1533 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1534         if (pgrp_nr < 0)
1535                 return -EINVAL;
1536         rcu_read_lock();
1537 diff -NurpP --minimal linux-2.6.35.4/drivers/gpu/drm/radeon/r100_reg_safe.h linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/r100_reg_safe.h
1538 --- linux-2.6.35.4/drivers/gpu/drm/radeon/r100_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1539 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/r100_reg_safe.h 2010-08-02 17:05:05.000000000 +0200
1540 @@ -0,0 +1,28 @@
1541 +static const unsigned r100_reg_safe_bm[102] = {
1542 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1543 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1544 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1545 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1546 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1547 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1548 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1549 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1550 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1551 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1552 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1553 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1554 +       0xFFFFFFCF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1555 +       0xFFFFFF9F, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1556 +       0x38E7FE1F, 0xFFC3FF8E, 0x7FF8FFFF, 0xFFFF803C,
1557 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1558 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFFFF, 0xFFFFFFFF,
1559 +       0x00000000, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF,
1560 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1561 +       0xFFFFFFFF, 0xFFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1562 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1563 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1564 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1565 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1566 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1567 +       0xFFFFFFFF, 0xFFFFFFEF,
1568 +};
1569 diff -NurpP --minimal linux-2.6.35.4/drivers/gpu/drm/radeon/r200_reg_safe.h linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/r200_reg_safe.h
1570 --- linux-2.6.35.4/drivers/gpu/drm/radeon/r200_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1571 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/r200_reg_safe.h 2010-08-02 17:05:05.000000000 +0200
1572 @@ -0,0 +1,28 @@
1573 +static const unsigned r200_reg_safe_bm[102] = {
1574 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1575 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1576 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
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 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1585 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1586 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1587 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1588 +       0xFFE7FE1F, 0xF003FFFF, 0x7EFFFFFF, 0xFFFF803C,
1589 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1590 +       0xFFFFFFFF, 0xFFFFEFCE, 0xFFFEFFFF, 0xFFFFFFFE,
1591 +       0x020E0FF0, 0xFFCC83FD, 0xFFFFFFFF, 0xFFFFFFFF,
1592 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1593 +       0xFFFBFFFF, 0xEFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1594 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1595 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1596 +       0xDFDFDFDF, 0x3FFDDFDF, 0xFFFFFFFF, 0xFFFFFF7F,
1597 +       0xFFFFFFFF, 0x00FFFFFF, 0x00000000, 0x00000000,
1598 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1599 +       0xFFFFFE3F, 0xFFFFFFEF,
1600 +};
1601 diff -NurpP --minimal linux-2.6.35.4/drivers/gpu/drm/radeon/r300_reg_safe.h linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/r300_reg_safe.h
1602 --- linux-2.6.35.4/drivers/gpu/drm/radeon/r300_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1603 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/r300_reg_safe.h 2010-08-02 17:05:05.000000000 +0200
1604 @@ -0,0 +1,42 @@
1605 +static const unsigned r300_reg_safe_bm[159] = {
1606 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1607 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1608 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
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 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1617 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1618 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1619 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1620 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1621 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1622 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1623 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1624 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1625 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1626 +       0xFFFFFFFF, 0xFFFFFFFF, 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 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1633 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1634 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1635 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1636 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1637 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1638 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1639 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1640 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1641 +       0x00000000, 0x0000C100, 0x00000000, 0x00000000,
1642 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1643 +       0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0xFF80FFFF,
1644 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1645 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1646 +};
1647 diff -NurpP --minimal linux-2.6.35.4/drivers/gpu/drm/radeon/r420_reg_safe.h linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/r420_reg_safe.h
1648 --- linux-2.6.35.4/drivers/gpu/drm/radeon/r420_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1649 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/r420_reg_safe.h 2010-08-02 17:05:05.000000000 +0200
1650 @@ -0,0 +1,42 @@
1651 +static const unsigned r420_reg_safe_bm[159] = {
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 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1663 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1664 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1665 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1666 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1667 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1668 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1669 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
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 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1679 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1680 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1681 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1682 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1683 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1684 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1685 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1686 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1687 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1688 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1689 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1690 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1691 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1692 +};
1693 diff -NurpP --minimal linux-2.6.35.4/drivers/gpu/drm/radeon/rn50_reg_safe.h linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/rn50_reg_safe.h
1694 --- linux-2.6.35.4/drivers/gpu/drm/radeon/rn50_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1695 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/rn50_reg_safe.h 2010-08-02 17:05:05.000000000 +0200
1696 @@ -0,0 +1,28 @@
1697 +static const unsigned rn50_reg_safe_bm[102] = {
1698 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1699 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1700 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1701 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1702 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1703 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1704 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1705 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1706 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1707 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1708 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1709 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
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,
1724 +};
1725 diff -NurpP --minimal linux-2.6.35.4/drivers/gpu/drm/radeon/rs600_reg_safe.h linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/rs600_reg_safe.h
1726 --- linux-2.6.35.4/drivers/gpu/drm/radeon/rs600_reg_safe.h      1970-01-01 01:00:00.000000000 +0100
1727 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/rs600_reg_safe.h        2010-08-02 17:05:05.000000000 +0200
1728 @@ -0,0 +1,57 @@
1729 +static const unsigned rs600_reg_safe_bm[219] = {
1730 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1731 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1732 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1733 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1734 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1735 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1736 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1737 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1738 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1739 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1740 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1741 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1742 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1743 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1744 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1745 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1746 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1747 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1748 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1749 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1750 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1751 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1752 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1753 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1754 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1755 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1756 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1757 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1758 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1759 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1760 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1761 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1762 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1763 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1764 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1765 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1766 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1767 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1768 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1769 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19, 0xFFFFFFFF,
1770 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1771 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1772 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1773 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1774 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1775 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1776 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1777 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1778 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1779 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1780 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1781 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1782 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1783 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1784 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1785 +};
1786 diff -NurpP --minimal linux-2.6.35.4/drivers/gpu/drm/radeon/rv515_reg_safe.h linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/rv515_reg_safe.h
1787 --- linux-2.6.35.4/drivers/gpu/drm/radeon/rv515_reg_safe.h      1970-01-01 01:00:00.000000000 +0100
1788 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/gpu/drm/radeon/rv515_reg_safe.h        2010-08-02 17:05:05.000000000 +0200
1789 @@ -0,0 +1,57 @@
1790 +static const unsigned rv515_reg_safe_bm[219] = {
1791 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1792 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1793 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1794 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1795 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1796 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1797 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1798 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1799 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1800 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1801 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1802 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1803 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1804 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1805 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1806 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1807 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1808 +       0xF0000038, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1809 +       0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF,
1810 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1811 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1812 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1813 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1814 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1815 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1816 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1817 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1818 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1819 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1820 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1821 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1822 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1823 +       0x1FFFF878, 0xFFFFE000, 0xFFFFFE1E, 0xFFFFFFFF,
1824 +       0x388F8F50, 0xFFF88082, 0xFF0000FC, 0xFAE009FF,
1825 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1826 +       0xFFFF8CFC, 0xFFFFC1FF, 0xFFFFFFFF, 0xFFFFFFFF,
1827 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1828 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF80FFFF,
1829 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1830 +       0x0003FC01, 0x3FFFFCF8, 0xFF800B19, 0xFFDFFFFF,
1831 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1832 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1833 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1834 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1835 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1836 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1837 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1838 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1839 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1840 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1841 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1842 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1843 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1844 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1845 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1846 +};
1847 diff -NurpP --minimal linux-2.6.35.4/drivers/infiniband/core/addr.c linux-2.6.35.4-vs2.3.0.36.32/drivers/infiniband/core/addr.c
1848 --- linux-2.6.35.4/drivers/infiniband/core/addr.c       2010-07-07 18:31:18.000000000 +0200
1849 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/infiniband/core/addr.c 2010-08-02 17:05:05.000000000 +0200
1850 @@ -252,7 +252,7 @@ static int addr6_resolve(struct sockaddr
1851  
1852         if (ipv6_addr_any(&fl.fl6_src)) {
1853                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1854 -                                        &fl.fl6_dst, 0, &fl.fl6_src);
1855 +                                        &fl.fl6_dst, 0, &fl.fl6_src, NULL);
1856                 if (ret)
1857                         goto put;
1858  
1859 diff -NurpP --minimal linux-2.6.35.4/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.35.4-vs2.3.0.36.32/drivers/infiniband/hw/ipath/ipath_user_pages.c
1860 --- linux-2.6.35.4/drivers/infiniband/hw/ipath/ipath_user_pages.c       2010-07-07 18:31:19.000000000 +0200
1861 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/infiniband/hw/ipath/ipath_user_pages.c 2010-08-02 17:05:05.000000000 +0200
1862 @@ -35,6 +35,7 @@
1863  #include <linux/device.h>
1864  #include <linux/slab.h>
1865  #include <linux/sched.h>
1866 +#include <linux/vs_memory.h>
1867  
1868  #include "ipath_kernel.h"
1869  
1870 diff -NurpP --minimal linux-2.6.35.4/drivers/md/dm.c linux-2.6.35.4-vs2.3.0.36.32/drivers/md/dm.c
1871 --- linux-2.6.35.4/drivers/md/dm.c      2010-09-05 01:41:56.000000000 +0200
1872 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/md/dm.c        2010-09-06 03:00:12.000000000 +0200
1873 @@ -20,6 +20,7 @@
1874  #include <linux/idr.h>
1875  #include <linux/hdreg.h>
1876  #include <linux/delay.h>
1877 +#include <linux/vs_base.h>
1878  
1879  #include <trace/events/block.h>
1880  
1881 @@ -120,6 +121,7 @@ struct mapped_device {
1882         rwlock_t map_lock;
1883         atomic_t holders;
1884         atomic_t open_count;
1885 +       xid_t xid;
1886  
1887         unsigned long flags;
1888  
1889 @@ -338,6 +340,7 @@ int dm_deleting_md(struct mapped_device 
1890  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1891  {
1892         struct mapped_device *md;
1893 +       int ret = -ENXIO;
1894  
1895         spin_lock(&_minor_lock);
1896  
1897 @@ -346,18 +349,19 @@ static int dm_blk_open(struct block_devi
1898                 goto out;
1899  
1900         if (test_bit(DMF_FREEING, &md->flags) ||
1901 -           dm_deleting_md(md)) {
1902 -               md = NULL;
1903 +           dm_deleting_md(md))
1904 +               goto out;
1905 +
1906 +       ret = -EACCES;
1907 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1908                 goto out;
1909 -       }
1910  
1911         dm_get(md);
1912         atomic_inc(&md->open_count);
1913 -
1914 +       ret = 0;
1915  out:
1916         spin_unlock(&_minor_lock);
1917 -
1918 -       return md ? 0 : -ENXIO;
1919 +       return ret;
1920  }
1921  
1922  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1923 @@ -575,6 +579,14 @@ int dm_set_geometry(struct mapped_device
1924         return 0;
1925  }
1926  
1927 +/*
1928 + * Get the xid associated with a dm device
1929 + */
1930 +xid_t dm_get_xid(struct mapped_device *md)
1931 +{
1932 +       return md->xid;
1933 +}
1934 +
1935  /*-----------------------------------------------------------------
1936   * CRUD START:
1937   *   A more elegant soln is in the works that uses the queue
1938 @@ -1887,6 +1899,7 @@ static struct mapped_device *alloc_dev(i
1939         INIT_LIST_HEAD(&md->uevent_list);
1940         spin_lock_init(&md->uevent_lock);
1941  
1942 +       md->xid = vx_current_xid();
1943         md->queue = blk_init_queue(dm_request_fn, NULL);
1944         if (!md->queue)
1945                 goto bad_queue;
1946 diff -NurpP --minimal linux-2.6.35.4/drivers/md/dm.h linux-2.6.35.4-vs2.3.0.36.32/drivers/md/dm.h
1947 --- linux-2.6.35.4/drivers/md/dm.h      2010-09-05 01:41:56.000000000 +0200
1948 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/md/dm.h        2010-09-06 02:59:52.000000000 +0200
1949 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1950  struct dm_table;
1951  struct dm_md_mempools;
1952  
1953 +xid_t dm_get_xid(struct mapped_device *md);
1954 +
1955  /*-----------------------------------------------------------------
1956   * Internal table functions.
1957   *---------------------------------------------------------------*/
1958 diff -NurpP --minimal linux-2.6.35.4/drivers/md/dm-ioctl.c linux-2.6.35.4-vs2.3.0.36.32/drivers/md/dm-ioctl.c
1959 --- linux-2.6.35.4/drivers/md/dm-ioctl.c        2010-09-05 01:41:56.000000000 +0200
1960 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/md/dm-ioctl.c  2010-09-06 02:59:52.000000000 +0200
1961 @@ -16,6 +16,7 @@
1962  #include <linux/dm-ioctl.h>
1963  #include <linux/hdreg.h>
1964  #include <linux/compat.h>
1965 +#include <linux/vs_context.h>
1966  
1967  #include <asm/uaccess.h>
1968  
1969 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1970         unsigned int h = hash_str(str);
1971  
1972         list_for_each_entry (hc, _name_buckets + h, name_list)
1973 -               if (!strcmp(hc->name, str)) {
1974 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1975 +                       !strcmp(hc->name, str)) {
1976                         dm_get(hc->md);
1977                         return hc;
1978                 }
1979 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1980         unsigned int h = hash_str(str);
1981  
1982         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1983 -               if (!strcmp(hc->uuid, str)) {
1984 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1985 +                       !strcmp(hc->uuid, str)) {
1986                         dm_get(hc->md);
1987                         return hc;
1988                 }
1989 @@ -375,6 +378,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1990  
1991  static int remove_all(struct dm_ioctl *param, size_t param_size)
1992  {
1993 +       if (!vx_check(0, VS_ADMIN))
1994 +               return -EPERM;
1995 +
1996         dm_hash_remove_all(1);
1997         param->data_size = 0;
1998         return 0;
1999 @@ -422,6 +428,8 @@ static int list_devices(struct dm_ioctl 
2000          */
2001         for (i = 0; i < NUM_BUCKETS; i++) {
2002                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2003 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2004 +                               continue;
2005                         needed += sizeof(struct dm_name_list);
2006                         needed += strlen(hc->name) + 1;
2007                         needed += ALIGN_MASK;
2008 @@ -445,6 +453,8 @@ static int list_devices(struct dm_ioctl 
2009          */
2010         for (i = 0; i < NUM_BUCKETS; i++) {
2011                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2012 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2013 +                               continue;
2014                         if (old_nl)
2015                                 old_nl->next = (uint32_t) ((void *) nl -
2016                                                            (void *) old_nl);
2017 @@ -680,10 +690,11 @@ static struct hash_cell *__find_device_h
2018         if (!md)
2019                 goto out;
2020  
2021 -       mdptr = dm_get_mdptr(md);
2022 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
2023 +               mdptr = dm_get_mdptr(md);
2024 +
2025         if (!mdptr)
2026                 dm_put(md);
2027 -
2028  out:
2029         return mdptr;
2030  }
2031 @@ -1526,8 +1537,8 @@ static int ctl_ioctl(uint command, struc
2032         ioctl_fn fn = NULL;
2033         size_t param_size;
2034  
2035 -       /* only root can play with this */
2036 -       if (!capable(CAP_SYS_ADMIN))
2037 +       /* only root and certain contexts can play with this */
2038 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
2039                 return -EACCES;
2040  
2041         if (_IOC_TYPE(command) != DM_IOCTL)
2042 diff -NurpP --minimal linux-2.6.35.4/drivers/net/tun.c linux-2.6.35.4-vs2.3.0.36.32/drivers/net/tun.c
2043 --- linux-2.6.35.4/drivers/net/tun.c    2010-08-02 16:52:27.000000000 +0200
2044 +++ linux-2.6.35.4-vs2.3.0.36.32/drivers/net/tun.c      2010-08-02 17:05:05.000000000 +0200
2045 @@ -62,6 +62,7 @@
2046  #include <linux/nsproxy.h>
2047  #include <linux/virtio_net.h>
2048  #include <linux/rcupdate.h>
2049 +#include <linux/vs_network.h>
2050  #include <net/net_namespace.h>
2051  #include <net/netns/generic.h>
2052  #include <net/rtnetlink.h>
2053 @@ -103,6 +104,7 @@ struct tun_struct {
2054         unsigned int            flags;
2055         uid_t                   owner;
2056         gid_t                   group;
2057 +       nid_t                   nid;
2058  
2059         struct net_device       *dev;
2060         struct fasync_struct    *fasync;
2061 @@ -851,6 +853,7 @@ static void tun_setup(struct net_device 
2062  
2063         tun->owner = -1;
2064         tun->group = -1;
2065 +       tun->nid = current->nid;
2066  
2067         dev->ethtool_ops = &tun_ethtool_ops;
2068         dev->destructor = tun_free_netdev;
2069 @@ -1001,7 +1004,7 @@ static int tun_set_iff(struct net *net, 
2070  
2071                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
2072                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
2073 -                   !capable(CAP_NET_ADMIN))
2074 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
2075                         return -EPERM;
2076                 err = security_tun_dev_attach(tun->socket.sk);
2077                 if (err < 0)
2078 @@ -1015,7 +1018,7 @@ static int tun_set_iff(struct net *net, 
2079                 char *name;
2080                 unsigned long flags = 0;
2081  
2082 -               if (!capable(CAP_NET_ADMIN))
2083 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
2084                         return -EPERM;
2085                 err = security_tun_dev_create();
2086                 if (err < 0)
2087 @@ -1085,6 +1088,9 @@ static int tun_set_iff(struct net *net, 
2088  
2089                 sk->sk_destruct = tun_sock_destruct;
2090  
2091 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
2092 +                       return -EPERM;
2093 +
2094                 err = tun_attach(tun, file);
2095                 if (err < 0)
2096                         goto failed;
2097 @@ -1276,6 +1282,16 @@ static long __tun_chr_ioctl(struct file 
2098                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
2099                 break;
2100  
2101 +       case TUNSETNID:
2102 +               if (!capable(CAP_CONTEXT))
2103 +                       return -EPERM;
2104 +
2105 +               /* Set nid owner of the device */
2106 +               tun->nid = (nid_t) arg;
2107 +
2108 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
2109 +               break;
2110 +
2111         case TUNSETLINK:
2112                 /* Only allow setting the type when the interface is down */
2113                 if (tun->dev->flags & IFF_UP) {
2114 diff -NurpP --minimal linux-2.6.35.4/fs/attr.c linux-2.6.35.4-vs2.3.0.36.32/fs/attr.c
2115 --- linux-2.6.35.4/fs/attr.c    2010-08-02 16:52:47.000000000 +0200
2116 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/attr.c      2010-08-02 21:00:32.000000000 +0200
2117 @@ -13,6 +13,9 @@
2118  #include <linux/fsnotify.h>
2119  #include <linux/fcntl.h>
2120  #include <linux/security.h>
2121 +#include <linux/proc_fs.h>
2122 +#include <linux/devpts_fs.h>
2123 +#include <linux/vs_tag.h>
2124  
2125  /* Taken over from the old code... */
2126  
2127 @@ -54,6 +57,10 @@ int inode_change_ok(const struct inode *
2128                 if (!is_owner_or_cap(inode))
2129                         goto error;
2130         }
2131 +
2132 +       if (dx_permission(inode, MAY_WRITE))
2133 +               goto error;
2134 +
2135  fine:
2136         retval = 0;
2137  error:
2138 @@ -127,6 +134,8 @@ void generic_setattr(struct inode *inode
2139                 inode->i_uid = attr->ia_uid;
2140         if (ia_valid & ATTR_GID)
2141                 inode->i_gid = attr->ia_gid;
2142 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2143 +               inode->i_tag = attr->ia_tag;
2144         if (ia_valid & ATTR_ATIME)
2145                 inode->i_atime = timespec_trunc(attr->ia_atime,
2146                                                 inode->i_sb->s_time_gran);
2147 @@ -179,7 +188,8 @@ int notify_change(struct dentry * dentry
2148         struct timespec now;
2149         unsigned int ia_valid = attr->ia_valid;
2150  
2151 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
2152 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
2153 +               ATTR_TAG | ATTR_TIMES_SET)) {
2154                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2155                         return -EPERM;
2156         }
2157 diff -NurpP --minimal linux-2.6.35.4/fs/binfmt_aout.c linux-2.6.35.4-vs2.3.0.36.32/fs/binfmt_aout.c
2158 --- linux-2.6.35.4/fs/binfmt_aout.c     2010-07-07 18:31:50.000000000 +0200
2159 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/binfmt_aout.c       2010-08-02 17:05:05.000000000 +0200
2160 @@ -25,6 +25,7 @@
2161  #include <linux/init.h>
2162  #include <linux/coredump.h>
2163  #include <linux/slab.h>
2164 +#include <linux/vs_memory.h>
2165  
2166  #include <asm/system.h>
2167  #include <asm/uaccess.h>
2168 diff -NurpP --minimal linux-2.6.35.4/fs/binfmt_elf.c linux-2.6.35.4-vs2.3.0.36.32/fs/binfmt_elf.c
2169 --- linux-2.6.35.4/fs/binfmt_elf.c      2010-07-07 18:31:50.000000000 +0200
2170 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/binfmt_elf.c        2010-08-02 17:05:05.000000000 +0200
2171 @@ -32,6 +32,7 @@
2172  #include <linux/elf.h>
2173  #include <linux/utsname.h>
2174  #include <linux/coredump.h>
2175 +#include <linux/vs_memory.h>
2176  #include <asm/uaccess.h>
2177  #include <asm/param.h>
2178  #include <asm/page.h>
2179 diff -NurpP --minimal linux-2.6.35.4/fs/binfmt_flat.c linux-2.6.35.4-vs2.3.0.36.32/fs/binfmt_flat.c
2180 --- linux-2.6.35.4/fs/binfmt_flat.c     2010-08-02 16:52:47.000000000 +0200
2181 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/binfmt_flat.c       2010-08-02 17:05:05.000000000 +0200
2182 @@ -35,6 +35,7 @@
2183  #include <linux/init.h>
2184  #include <linux/flat.h>
2185  #include <linux/syscalls.h>
2186 +#include <linux/vs_memory.h>
2187  
2188  #include <asm/byteorder.h>
2189  #include <asm/system.h>
2190 diff -NurpP --minimal linux-2.6.35.4/fs/binfmt_som.c linux-2.6.35.4-vs2.3.0.36.32/fs/binfmt_som.c
2191 --- linux-2.6.35.4/fs/binfmt_som.c      2010-02-25 11:52:04.000000000 +0100
2192 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/binfmt_som.c        2010-08-02 17:05:05.000000000 +0200
2193 @@ -28,6 +28,7 @@
2194  #include <linux/shm.h>
2195  #include <linux/personality.h>
2196  #include <linux/init.h>
2197 +#include <linux/vs_memory.h>
2198  
2199  #include <asm/uaccess.h>
2200  #include <asm/pgtable.h>
2201 diff -NurpP --minimal linux-2.6.35.4/fs/block_dev.c linux-2.6.35.4-vs2.3.0.36.32/fs/block_dev.c
2202 --- linux-2.6.35.4/fs/block_dev.c       2010-09-05 01:41:57.000000000 +0200
2203 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/block_dev.c 2010-08-14 18:19:32.000000000 +0200
2204 @@ -26,6 +26,7 @@
2205  #include <linux/namei.h>
2206  #include <linux/log2.h>
2207  #include <linux/kmemleak.h>
2208 +#include <linux/vs_device.h>
2209  #include <asm/uaccess.h>
2210  #include "internal.h"
2211  
2212 @@ -529,6 +530,7 @@ struct block_device *bdget(dev_t dev)
2213                 bdev->bd_invalidated = 0;
2214                 inode->i_mode = S_IFBLK;
2215                 inode->i_rdev = dev;
2216 +               inode->i_mdev = dev;
2217                 inode->i_bdev = bdev;
2218                 inode->i_data.a_ops = &def_blk_aops;
2219                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2220 @@ -575,6 +577,11 @@ EXPORT_SYMBOL(bdput);
2221  static struct block_device *bd_acquire(struct inode *inode)
2222  {
2223         struct block_device *bdev;
2224 +       dev_t mdev;
2225 +
2226 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2227 +               return NULL;
2228 +       inode->i_mdev = mdev;
2229  
2230         spin_lock(&bdev_lock);
2231         bdev = inode->i_bdev;
2232 @@ -585,7 +592,7 @@ static struct block_device *bd_acquire(s
2233         }
2234         spin_unlock(&bdev_lock);
2235  
2236 -       bdev = bdget(inode->i_rdev);
2237 +       bdev = bdget(mdev);
2238         if (bdev) {
2239                 spin_lock(&bdev_lock);
2240                 if (!inode->i_bdev) {
2241 diff -NurpP --minimal linux-2.6.35.4/fs/btrfs/ctree.h linux-2.6.35.4-vs2.3.0.36.32/fs/btrfs/ctree.h
2242 --- linux-2.6.35.4/fs/btrfs/ctree.h     2010-08-02 16:52:47.000000000 +0200
2243 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/btrfs/ctree.h       2010-08-02 17:05:05.000000000 +0200
2244 @@ -551,11 +551,14 @@ struct btrfs_inode_item {
2245         /* modification sequence number for NFS */
2246         __le64 sequence;
2247  
2248 +       __le16 tag;
2249         /*
2250          * a little future expansion, for more than this we can
2251          * just grow the inode item and version it
2252          */
2253 -       __le64 reserved[4];
2254 +       __le16 reserved16;
2255 +       __le32 reserved32;
2256 +       __le64 reserved[3];
2257         struct btrfs_timespec atime;
2258         struct btrfs_timespec ctime;
2259         struct btrfs_timespec mtime;
2260 @@ -1193,6 +1196,8 @@ struct btrfs_root {
2261  #define BTRFS_MOUNT_DISCARD            (1 << 10)
2262  #define BTRFS_MOUNT_FORCE_COMPRESS      (1 << 11)
2263  
2264 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2265 +
2266  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2267  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2268  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2269 @@ -1413,6 +1418,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2270  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2271  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2272  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2273 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2274  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2275  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2276  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2277 @@ -1474,6 +1480,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
2278  
2279  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
2280  
2281 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2282 +#define BTRFS_INODE_BARRIER            (1 << 25)
2283 +#define BTRFS_INODE_COW                        (1 << 26)
2284 +
2285  
2286  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
2287  
2288 @@ -2432,6 +2442,7 @@ extern const struct dentry_operations bt
2289  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2290  void btrfs_update_iflags(struct inode *inode);
2291  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2292 +int btrfs_sync_flags(struct inode *inode, int, int);
2293  
2294  /* file.c */
2295  int btrfs_sync_file(struct file *file, int datasync);
2296 diff -NurpP --minimal linux-2.6.35.4/fs/btrfs/disk-io.c linux-2.6.35.4-vs2.3.0.36.32/fs/btrfs/disk-io.c
2297 --- linux-2.6.35.4/fs/btrfs/disk-io.c   2010-08-02 16:52:47.000000000 +0200
2298 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/btrfs/disk-io.c     2010-08-02 17:05:05.000000000 +0200
2299 @@ -1707,6 +1707,9 @@ struct btrfs_root *open_ctree(struct sup
2300                 goto fail_iput;
2301         }
2302  
2303 +       if (btrfs_test_opt(tree_root, TAGGED))
2304 +               sb->s_flags |= MS_TAGGED;
2305 +
2306         features = btrfs_super_incompat_flags(disk_super) &
2307                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2308         if (features) {
2309 diff -NurpP --minimal linux-2.6.35.4/fs/btrfs/inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/btrfs/inode.c
2310 --- linux-2.6.35.4/fs/btrfs/inode.c     2010-08-02 16:52:47.000000000 +0200
2311 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/btrfs/inode.c       2010-08-02 17:05:05.000000000 +0200
2312 @@ -37,6 +37,8 @@
2313  #include <linux/posix_acl.h>
2314  #include <linux/falloc.h>
2315  #include <linux/slab.h>
2316 +#include <linux/vs_tag.h>
2317 +
2318  #include "compat.h"
2319  #include "ctree.h"
2320  #include "disk-io.h"
2321 @@ -2415,6 +2417,8 @@ static void btrfs_read_locked_inode(stru
2322         int maybe_acls;
2323         u64 alloc_group_block;
2324         u32 rdev;
2325 +       uid_t uid;
2326 +       gid_t gid;
2327         int ret;
2328  
2329         path = btrfs_alloc_path();
2330 @@ -2431,8 +2435,13 @@ static void btrfs_read_locked_inode(stru
2331  
2332         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2333         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2334 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2335 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2336 +
2337 +       uid = btrfs_inode_uid(leaf, inode_item);
2338 +       gid = btrfs_inode_gid(leaf, inode_item);
2339 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2340 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2341 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2342 +               btrfs_inode_tag(leaf, inode_item));
2343         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2344  
2345         tspec = btrfs_inode_atime(inode_item);
2346 @@ -2514,8 +2523,15 @@ static void fill_inode_item(struct btrfs
2347                             struct btrfs_inode_item *item,
2348                             struct inode *inode)
2349  {
2350 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2351 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2352 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2353 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2354 +
2355 +       btrfs_set_inode_uid(leaf, item, uid);
2356 +       btrfs_set_inode_gid(leaf, item, gid);
2357 +#ifdef CONFIG_TAGGING_INTERN
2358 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2359 +#endif
2360 +
2361         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2362         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2363         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2364 @@ -6940,6 +6956,7 @@ static const struct inode_operations btr
2365         .listxattr      = btrfs_listxattr,
2366         .removexattr    = btrfs_removexattr,
2367         .permission     = btrfs_permission,
2368 +       .sync_flags     = btrfs_sync_flags,
2369  };
2370  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2371         .lookup         = btrfs_lookup,
2372 @@ -7015,6 +7032,7 @@ static const struct inode_operations btr
2373         .permission     = btrfs_permission,
2374         .fallocate      = btrfs_fallocate,
2375         .fiemap         = btrfs_fiemap,
2376 +       .sync_flags     = btrfs_sync_flags,
2377  };
2378  static const struct inode_operations btrfs_special_inode_operations = {
2379         .getattr        = btrfs_getattr,
2380 diff -NurpP --minimal linux-2.6.35.4/fs/btrfs/ioctl.c linux-2.6.35.4-vs2.3.0.36.32/fs/btrfs/ioctl.c
2381 --- linux-2.6.35.4/fs/btrfs/ioctl.c     2010-08-02 16:52:47.000000000 +0200
2382 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/btrfs/ioctl.c       2010-08-02 17:05:05.000000000 +0200
2383 @@ -68,10 +68,13 @@ static unsigned int btrfs_flags_to_ioctl
2384  {
2385         unsigned int iflags = 0;
2386  
2387 -       if (flags & BTRFS_INODE_SYNC)
2388 -               iflags |= FS_SYNC_FL;
2389         if (flags & BTRFS_INODE_IMMUTABLE)
2390                 iflags |= FS_IMMUTABLE_FL;
2391 +       if (flags & BTRFS_INODE_IXUNLINK)
2392 +               iflags |= FS_IXUNLINK_FL;
2393 +
2394 +       if (flags & BTRFS_INODE_SYNC)
2395 +               iflags |= FS_SYNC_FL;
2396         if (flags & BTRFS_INODE_APPEND)
2397                 iflags |= FS_APPEND_FL;
2398         if (flags & BTRFS_INODE_NODUMP)
2399 @@ -81,28 +84,78 @@ static unsigned int btrfs_flags_to_ioctl
2400         if (flags & BTRFS_INODE_DIRSYNC)
2401                 iflags |= FS_DIRSYNC_FL;
2402  
2403 +       if (flags & BTRFS_INODE_BARRIER)
2404 +               iflags |= FS_BARRIER_FL;
2405 +       if (flags & BTRFS_INODE_COW)
2406 +               iflags |= FS_COW_FL;
2407         return iflags;
2408  }
2409  
2410  /*
2411 - * Update inode->i_flags based on the btrfs internal flags.
2412 + * Update inode->i_(v)flags based on the btrfs internal flags.
2413   */
2414  void btrfs_update_iflags(struct inode *inode)
2415  {
2416         struct btrfs_inode *ip = BTRFS_I(inode);
2417  
2418 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2419 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2420 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2421  
2422 -       if (ip->flags & BTRFS_INODE_SYNC)
2423 -               inode->i_flags |= S_SYNC;
2424         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2425                 inode->i_flags |= S_IMMUTABLE;
2426 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2427 +               inode->i_flags |= S_IXUNLINK;
2428 +
2429 +       if (ip->flags & BTRFS_INODE_SYNC)
2430 +               inode->i_flags |= S_SYNC;
2431         if (ip->flags & BTRFS_INODE_APPEND)
2432                 inode->i_flags |= S_APPEND;
2433         if (ip->flags & BTRFS_INODE_NOATIME)
2434                 inode->i_flags |= S_NOATIME;
2435         if (ip->flags & BTRFS_INODE_DIRSYNC)
2436                 inode->i_flags |= S_DIRSYNC;
2437 +
2438 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2439 +
2440 +       if (ip->flags & BTRFS_INODE_BARRIER)
2441 +               inode->i_vflags |= V_BARRIER;
2442 +       if (ip->flags & BTRFS_INODE_COW)
2443 +               inode->i_vflags |= V_COW;
2444 +}
2445 +
2446 +/*
2447 + * Update btrfs internal flags from inode->i_(v)flags.
2448 + */
2449 +void btrfs_update_flags(struct inode *inode)
2450 +{
2451 +       struct btrfs_inode *ip = BTRFS_I(inode);
2452 +
2453 +       unsigned int flags = inode->i_flags;
2454 +       unsigned int vflags = inode->i_vflags;
2455 +
2456 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2457 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2458 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2459 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2460 +
2461 +       if (flags & S_IMMUTABLE)
2462 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2463 +       if (flags & S_IXUNLINK)
2464 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2465 +
2466 +       if (flags & S_SYNC)
2467 +               ip->flags |= BTRFS_INODE_SYNC;
2468 +       if (flags & S_APPEND)
2469 +               ip->flags |= BTRFS_INODE_APPEND;
2470 +       if (flags & S_NOATIME)
2471 +               ip->flags |= BTRFS_INODE_NOATIME;
2472 +       if (flags & S_DIRSYNC)
2473 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2474 +
2475 +       if (vflags & V_BARRIER)
2476 +               ip->flags |= BTRFS_INODE_BARRIER;
2477 +       if (vflags & V_COW)
2478 +               ip->flags |= BTRFS_INODE_COW;
2479  }
2480  
2481  /*
2482 @@ -120,7 +173,7 @@ void btrfs_inherit_iflags(struct inode *
2483         flags = BTRFS_I(dir)->flags;
2484  
2485         if (S_ISREG(inode->i_mode))
2486 -               flags &= ~BTRFS_INODE_DIRSYNC;
2487 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2488         else if (!S_ISDIR(inode->i_mode))
2489                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2490  
2491 @@ -128,6 +181,30 @@ void btrfs_inherit_iflags(struct inode *
2492         btrfs_update_iflags(inode);
2493  }
2494  
2495 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2496 +{
2497 +       struct btrfs_inode *ip = BTRFS_I(inode);
2498 +       struct btrfs_root *root = ip->root;
2499 +       struct btrfs_trans_handle *trans;
2500 +       int ret;
2501 +
2502 +       trans = btrfs_join_transaction(root, 1);
2503 +       BUG_ON(!trans);
2504 +
2505 +       inode->i_flags = flags;
2506 +       inode->i_vflags = vflags;
2507 +       btrfs_update_flags(inode);
2508 +
2509 +       ret = btrfs_update_inode(trans, root, inode);
2510 +       BUG_ON(ret);
2511 +
2512 +       btrfs_update_iflags(inode);
2513 +       inode->i_ctime = CURRENT_TIME;
2514 +       btrfs_end_transaction(trans, root);
2515 +
2516 +       return 0;
2517 +}
2518 +
2519  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2520  {
2521         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2522 @@ -150,6 +227,7 @@ static int btrfs_ioctl_setflags(struct f
2523         if (copy_from_user(&flags, arg, sizeof(flags)))
2524                 return -EFAULT;
2525  
2526 +       /* maybe add FS_IXUNLINK_FL ? */
2527         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2528                       FS_NOATIME_FL | FS_NODUMP_FL | \
2529                       FS_SYNC_FL | FS_DIRSYNC_FL))
2530 @@ -162,7 +240,8 @@ static int btrfs_ioctl_setflags(struct f
2531  
2532         flags = btrfs_mask_flags(inode->i_mode, flags);
2533         oldflags = btrfs_flags_to_ioctl(ip->flags);
2534 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2535 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2536 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2537                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2538                         ret = -EPERM;
2539                         goto out_unlock;
2540 @@ -173,14 +252,19 @@ static int btrfs_ioctl_setflags(struct f
2541         if (ret)
2542                 goto out_unlock;
2543  
2544 -       if (flags & FS_SYNC_FL)
2545 -               ip->flags |= BTRFS_INODE_SYNC;
2546 -       else
2547 -               ip->flags &= ~BTRFS_INODE_SYNC;
2548         if (flags & FS_IMMUTABLE_FL)
2549                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2550         else
2551                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2552 +       if (flags & FS_IXUNLINK_FL)
2553 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2554 +       else
2555 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2556 +
2557 +       if (flags & FS_SYNC_FL)
2558 +               ip->flags |= BTRFS_INODE_SYNC;
2559 +       else
2560 +               ip->flags &= ~BTRFS_INODE_SYNC;
2561         if (flags & FS_APPEND_FL)
2562                 ip->flags |= BTRFS_INODE_APPEND;
2563         else
2564 diff -NurpP --minimal linux-2.6.35.4/fs/btrfs/super.c linux-2.6.35.4-vs2.3.0.36.32/fs/btrfs/super.c
2565 --- linux-2.6.35.4/fs/btrfs/super.c     2010-08-02 16:52:47.000000000 +0200
2566 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/btrfs/super.c       2010-08-02 17:05:05.000000000 +0200
2567 @@ -68,7 +68,7 @@ enum {
2568         Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd,
2569         Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
2570         Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
2571 -       Opt_discard, Opt_err,
2572 +       Opt_tag, Opt_notag, Opt_tagid, Opt_discard, Opt_err,
2573  };
2574  
2575  static match_table_t tokens = {
2576 @@ -92,6 +92,9 @@ static match_table_t tokens = {
2577         {Opt_flushoncommit, "flushoncommit"},
2578         {Opt_ratio, "metadata_ratio=%d"},
2579         {Opt_discard, "discard"},
2580 +       {Opt_tag, "tag"},
2581 +       {Opt_notag, "notag"},
2582 +       {Opt_tagid, "tagid=%u"},
2583         {Opt_err, NULL},
2584  };
2585  
2586 @@ -235,6 +238,22 @@ int btrfs_parse_options(struct btrfs_roo
2587                 case Opt_discard:
2588                         btrfs_set_opt(info->mount_opt, DISCARD);
2589                         break;
2590 +#ifndef CONFIG_TAGGING_NONE
2591 +               case Opt_tag:
2592 +                       printk(KERN_INFO "btrfs: use tagging\n");
2593 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2594 +                       break;
2595 +               case Opt_notag:
2596 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2597 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2598 +                       break;
2599 +#endif
2600 +#ifdef CONFIG_PROPAGATE
2601 +               case Opt_tagid:
2602 +                       /* use args[0] */
2603 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2604 +                       break;
2605 +#endif
2606                 case Opt_err:
2607                         printk(KERN_INFO "btrfs: unrecognized mount option "
2608                                "'%s'\n", p);
2609 @@ -681,6 +700,12 @@ static int btrfs_remount(struct super_bl
2610         if (ret)
2611                 return -EINVAL;
2612  
2613 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2614 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2615 +                       sb->s_id);
2616 +               return -EINVAL;
2617 +       }
2618 +
2619         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2620                 return 0;
2621  
2622 diff -NurpP --minimal linux-2.6.35.4/fs/char_dev.c linux-2.6.35.4-vs2.3.0.36.32/fs/char_dev.c
2623 --- linux-2.6.35.4/fs/char_dev.c        2010-09-05 01:41:57.000000000 +0200
2624 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/char_dev.c  2010-09-06 03:00:30.000000000 +0200
2625 @@ -21,6 +21,8 @@
2626  #include <linux/mutex.h>
2627  #include <linux/backing-dev.h>
2628  #include <linux/tty.h>
2629 +#include <linux/vs_context.h>
2630 +#include <linux/vs_device.h>
2631  
2632  #include "internal.h"
2633  
2634 @@ -369,14 +371,21 @@ static int chrdev_open(struct inode *ino
2635         struct cdev *p;
2636         struct cdev *new = NULL;
2637         int ret = 0;
2638 +       dev_t mdev;
2639 +
2640 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2641 +               return -EPERM;
2642 +       inode->i_mdev = mdev;
2643  
2644         spin_lock(&cdev_lock);
2645         p = inode->i_cdev;
2646         if (!p) {
2647                 struct kobject *kobj;
2648                 int idx;
2649 +
2650                 spin_unlock(&cdev_lock);
2651 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2652 +
2653 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2654                 if (!kobj)
2655                         return -ENXIO;
2656                 new = container_of(kobj, struct cdev, kobj);
2657 diff -NurpP --minimal linux-2.6.35.4/fs/dcache.c linux-2.6.35.4-vs2.3.0.36.32/fs/dcache.c
2658 --- linux-2.6.35.4/fs/dcache.c  2010-08-02 16:52:48.000000000 +0200
2659 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/dcache.c    2010-08-02 17:05:05.000000000 +0200
2660 @@ -33,6 +33,7 @@
2661  #include <linux/bootmem.h>
2662  #include <linux/fs_struct.h>
2663  #include <linux/hardirq.h>
2664 +#include <linux/vs_limit.h>
2665  #include "internal.h"
2666  
2667  int sysctl_vfs_cache_pressure __read_mostly = 100;
2668 @@ -230,6 +231,8 @@ repeat:
2669                 return;
2670         }
2671  
2672 +       vx_dentry_dec(dentry);
2673 +
2674         /*
2675          * AV: ->d_delete() is _NOT_ allowed to block now.
2676          */
2677 @@ -323,6 +326,7 @@ static inline struct dentry * __dget_loc
2678  {
2679         atomic_inc(&dentry->d_count);
2680         dentry_lru_del_init(dentry);
2681 +       vx_dentry_inc(dentry);
2682         return dentry;
2683  }
2684  
2685 @@ -926,6 +930,9 @@ struct dentry *d_alloc(struct dentry * p
2686         struct dentry *dentry;
2687         char *dname;
2688  
2689 +       if (!vx_dentry_avail(1))
2690 +               return NULL;
2691 +
2692         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2693         if (!dentry)
2694                 return NULL;
2695 @@ -971,6 +978,7 @@ struct dentry *d_alloc(struct dentry * p
2696         if (parent)
2697                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2698         dentry_stat.nr_dentry++;
2699 +       vx_dentry_inc(dentry);
2700         spin_unlock(&dcache_lock);
2701  
2702         return dentry;
2703 @@ -1420,6 +1428,7 @@ struct dentry * __d_lookup(struct dentry
2704                 }
2705  
2706                 atomic_inc(&dentry->d_count);
2707 +               vx_dentry_inc(dentry);
2708                 found = dentry;
2709                 spin_unlock(&dentry->d_lock);
2710                 break;
2711 diff -NurpP --minimal linux-2.6.35.4/fs/devpts/inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/devpts/inode.c
2712 --- linux-2.6.35.4/fs/devpts/inode.c    2010-08-02 16:52:48.000000000 +0200
2713 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/devpts/inode.c      2010-08-02 17:05:05.000000000 +0200
2714 @@ -25,6 +25,7 @@
2715  #include <linux/parser.h>
2716  #include <linux/fsnotify.h>
2717  #include <linux/seq_file.h>
2718 +#include <linux/vs_base.h>
2719  
2720  #define DEVPTS_DEFAULT_MODE 0600
2721  /*
2722 @@ -36,6 +37,20 @@
2723  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2724  #define PTMX_MINOR     2
2725  
2726 +static int devpts_permission(struct inode *inode, int mask)
2727 +{
2728 +       int ret = -EACCES;
2729 +
2730 +       /* devpts is xid tagged */
2731 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2732 +               ret = generic_permission(inode, mask, NULL);
2733 +       return ret;
2734 +}
2735 +
2736 +static struct inode_operations devpts_file_inode_operations = {
2737 +       .permission     = devpts_permission,
2738 +};
2739 +
2740  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2741  static DEFINE_MUTEX(allocated_ptys_lock);
2742  
2743 @@ -263,6 +278,25 @@ static int devpts_show_options(struct se
2744         return 0;
2745  }
2746  
2747 +static int devpts_filter(struct dentry *de)
2748 +{
2749 +       /* devpts is xid tagged */
2750 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2751 +}
2752 +
2753 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2754 +{
2755 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2756 +}
2757 +
2758 +static struct file_operations devpts_dir_operations = {
2759 +       .open           = dcache_dir_open,
2760 +       .release        = dcache_dir_close,
2761 +       .llseek         = dcache_dir_lseek,
2762 +       .read           = generic_read_dir,
2763 +       .readdir        = devpts_readdir,
2764 +};
2765 +
2766  static const struct super_operations devpts_sops = {
2767         .statfs         = simple_statfs,
2768         .remount_fs     = devpts_remount,
2769 @@ -302,12 +336,15 @@ devpts_fill_super(struct super_block *s,
2770         inode = new_inode(s);
2771         if (!inode)
2772                 goto free_fsi;
2773 +
2774         inode->i_ino = 1;
2775         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2776         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2777         inode->i_op = &simple_dir_inode_operations;
2778 -       inode->i_fop = &simple_dir_operations;
2779 +       inode->i_fop = &devpts_dir_operations;
2780         inode->i_nlink = 2;
2781 +       /* devpts is xid tagged */
2782 +       inode->i_tag = (tag_t)vx_current_xid();
2783  
2784         s->s_root = d_alloc_root(inode);
2785         if (s->s_root)
2786 @@ -495,6 +532,9 @@ int devpts_pty_new(struct inode *ptmx_in
2787         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2788         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2789         init_special_inode(inode, S_IFCHR|opts->mode, device);
2790 +       /* devpts is xid tagged */
2791 +       inode->i_tag = (tag_t)vx_current_xid();
2792 +       inode->i_op = &devpts_file_inode_operations;
2793         inode->i_private = tty;
2794         tty->driver_data = inode;
2795  
2796 diff -NurpP --minimal linux-2.6.35.4/fs/exec.c linux-2.6.35.4-vs2.3.0.36.32/fs/exec.c
2797 --- linux-2.6.35.4/fs/exec.c    2010-08-02 16:52:48.000000000 +0200
2798 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/exec.c      2010-08-02 17:05:05.000000000 +0200
2799 @@ -1506,7 +1506,7 @@ static int format_corename(char *corenam
2800                         /* UNIX time of coredump */
2801                         case 't': {
2802                                 struct timeval tv;
2803 -                               do_gettimeofday(&tv);
2804 +                               vx_gettimeofday(&tv);
2805                                 rc = snprintf(out_ptr, out_end - out_ptr,
2806                                               "%lu", tv.tv_sec);
2807                                 if (rc > out_end - out_ptr)
2808 diff -NurpP --minimal linux-2.6.35.4/fs/ext2/balloc.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/balloc.c
2809 --- linux-2.6.35.4/fs/ext2/balloc.c     2010-08-02 16:52:48.000000000 +0200
2810 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/balloc.c       2010-08-02 17:05:05.000000000 +0200
2811 @@ -702,7 +702,6 @@ ext2_try_to_allocate(struct super_block 
2812                         start = 0;
2813                 end = EXT2_BLOCKS_PER_GROUP(sb);
2814         }
2815 -
2816         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2817  
2818  repeat:
2819 diff -NurpP --minimal linux-2.6.35.4/fs/ext2/ext2.h linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/ext2.h
2820 --- linux-2.6.35.4/fs/ext2/ext2.h       2010-08-02 16:52:48.000000000 +0200
2821 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/ext2.h 2010-08-02 17:05:05.000000000 +0200
2822 @@ -130,6 +130,7 @@ extern int ext2_fiemap(struct inode *ino
2823  int __ext2_write_begin(struct file *file, struct address_space *mapping,
2824                 loff_t pos, unsigned len, unsigned flags,
2825                 struct page **pagep, void **fsdata);
2826 +extern int ext2_sync_flags(struct inode *, int, int);
2827  
2828  /* ioctl.c */
2829  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2830 diff -NurpP --minimal linux-2.6.35.4/fs/ext2/file.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/file.c
2831 --- linux-2.6.35.4/fs/ext2/file.c       2010-08-02 16:52:48.000000000 +0200
2832 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/file.c 2010-08-02 17:05:05.000000000 +0200
2833 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2834         .setattr        = ext2_setattr,
2835         .check_acl      = ext2_check_acl,
2836         .fiemap         = ext2_fiemap,
2837 +       .sync_flags     = ext2_sync_flags,
2838  };
2839 diff -NurpP --minimal linux-2.6.35.4/fs/ext2/ialloc.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/ialloc.c
2840 --- linux-2.6.35.4/fs/ext2/ialloc.c     2010-08-02 16:52:48.000000000 +0200
2841 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/ialloc.c       2010-08-02 18:15:12.000000000 +0200
2842 @@ -17,6 +17,7 @@
2843  #include <linux/backing-dev.h>
2844  #include <linux/buffer_head.h>
2845  #include <linux/random.h>
2846 +#include <linux/vs_tag.h>
2847  #include "ext2.h"
2848  #include "xattr.h"
2849  #include "acl.h"
2850 @@ -553,6 +554,7 @@ got:
2851                 inode->i_mode = mode;
2852                 inode->i_uid = current_fsuid();
2853                 inode->i_gid = dir->i_gid;
2854 +               inode->i_tag = dx_current_fstag(sb);
2855         } else
2856                 inode_init_owner(inode, dir, mode);
2857  
2858 diff -NurpP --minimal linux-2.6.35.4/fs/ext2/inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/inode.c
2859 --- linux-2.6.35.4/fs/ext2/inode.c      2010-08-02 16:52:48.000000000 +0200
2860 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/inode.c        2010-08-02 17:05:05.000000000 +0200
2861 @@ -32,6 +32,7 @@
2862  #include <linux/mpage.h>
2863  #include <linux/fiemap.h>
2864  #include <linux/namei.h>
2865 +#include <linux/vs_tag.h>
2866  #include "ext2.h"
2867  #include "acl.h"
2868  #include "xip.h"
2869 @@ -1164,7 +1165,7 @@ static void ext2_truncate_blocks(struct 
2870                 return;
2871         if (ext2_inode_is_fast_symlink(inode))
2872                 return;
2873 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2874 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2875                 return;
2876         __ext2_truncate_blocks(inode, offset);
2877  }
2878 @@ -1261,36 +1262,61 @@ void ext2_set_inode_flags(struct inode *
2879  {
2880         unsigned int flags = EXT2_I(inode)->i_flags;
2881  
2882 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2883 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2884 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2885 +
2886 +
2887 +       if (flags & EXT2_IMMUTABLE_FL)
2888 +               inode->i_flags |= S_IMMUTABLE;
2889 +       if (flags & EXT2_IXUNLINK_FL)
2890 +               inode->i_flags |= S_IXUNLINK;
2891 +
2892         if (flags & EXT2_SYNC_FL)
2893                 inode->i_flags |= S_SYNC;
2894         if (flags & EXT2_APPEND_FL)
2895                 inode->i_flags |= S_APPEND;
2896 -       if (flags & EXT2_IMMUTABLE_FL)
2897 -               inode->i_flags |= S_IMMUTABLE;
2898         if (flags & EXT2_NOATIME_FL)
2899                 inode->i_flags |= S_NOATIME;
2900         if (flags & EXT2_DIRSYNC_FL)
2901                 inode->i_flags |= S_DIRSYNC;
2902 +
2903 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2904 +
2905 +       if (flags & EXT2_BARRIER_FL)
2906 +               inode->i_vflags |= V_BARRIER;
2907 +       if (flags & EXT2_COW_FL)
2908 +               inode->i_vflags |= V_COW;
2909  }
2910  
2911  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2912  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2913  {
2914         unsigned int flags = ei->vfs_inode.i_flags;
2915 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2916 +
2917 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2918 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2919 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2920 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2921 +
2922 +       if (flags & S_IMMUTABLE)
2923 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2924 +       if (flags & S_IXUNLINK)
2925 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2926  
2927 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2928 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2929         if (flags & S_SYNC)
2930                 ei->i_flags |= EXT2_SYNC_FL;
2931         if (flags & S_APPEND)
2932                 ei->i_flags |= EXT2_APPEND_FL;
2933 -       if (flags & S_IMMUTABLE)
2934 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2935         if (flags & S_NOATIME)
2936                 ei->i_flags |= EXT2_NOATIME_FL;
2937         if (flags & S_DIRSYNC)
2938                 ei->i_flags |= EXT2_DIRSYNC_FL;
2939 +
2940 +       if (vflags & V_BARRIER)
2941 +               ei->i_flags |= EXT2_BARRIER_FL;
2942 +       if (vflags & V_COW)
2943 +               ei->i_flags |= EXT2_COW_FL;
2944  }
2945  
2946  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2947 @@ -1300,6 +1326,8 @@ struct inode *ext2_iget (struct super_bl
2948         struct ext2_inode *raw_inode;
2949         struct inode *inode;
2950         long ret = -EIO;
2951 +       uid_t uid;
2952 +       gid_t gid;
2953         int n;
2954  
2955         inode = iget_locked(sb, ino);
2956 @@ -1318,12 +1346,17 @@ struct inode *ext2_iget (struct super_bl
2957         }
2958  
2959         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2960 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2961 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2962 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2963 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2964         if (!(test_opt (inode->i_sb, NO_UID32))) {
2965 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2966 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2967 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2968 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2969         }
2970 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2971 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2972 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2973 +               le16_to_cpu(raw_inode->i_raw_tag));
2974 +
2975         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2976         inode->i_size = le32_to_cpu(raw_inode->i_size);
2977         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2978 @@ -1421,8 +1454,8 @@ static int __ext2_write_inode(struct ino
2979         struct ext2_inode_info *ei = EXT2_I(inode);
2980         struct super_block *sb = inode->i_sb;
2981         ino_t ino = inode->i_ino;
2982 -       uid_t uid = inode->i_uid;
2983 -       gid_t gid = inode->i_gid;
2984 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2985 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2986         struct buffer_head * bh;
2987         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2988         int n;
2989 @@ -1458,6 +1491,9 @@ static int __ext2_write_inode(struct ino
2990                 raw_inode->i_uid_high = 0;
2991                 raw_inode->i_gid_high = 0;
2992         }
2993 +#ifdef CONFIG_TAGGING_INTERN
2994 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2995 +#endif
2996         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2997         raw_inode->i_size = cpu_to_le32(inode->i_size);
2998         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2999 @@ -1547,7 +1583,8 @@ int ext2_setattr(struct dentry *dentry, 
3000         if (is_quota_modification(inode, iattr))
3001                 dquot_initialize(inode);
3002         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3003 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3004 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3005 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3006                 error = dquot_transfer(inode, iattr);
3007                 if (error)
3008                         return error;
3009 diff -NurpP --minimal linux-2.6.35.4/fs/ext2/ioctl.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/ioctl.c
3010 --- linux-2.6.35.4/fs/ext2/ioctl.c      2009-09-10 15:26:21.000000000 +0200
3011 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/ioctl.c        2010-08-02 17:05:05.000000000 +0200
3012 @@ -17,6 +17,16 @@
3013  #include <asm/uaccess.h>
3014  
3015  
3016 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
3017 +{
3018 +       inode->i_flags = flags;
3019 +       inode->i_vflags = vflags;
3020 +       ext2_get_inode_flags(EXT2_I(inode));
3021 +       inode->i_ctime = CURRENT_TIME_SEC;
3022 +       mark_inode_dirty(inode);
3023 +       return 0;
3024 +}
3025 +
3026  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3027  {
3028         struct inode *inode = filp->f_dentry->d_inode;
3029 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
3030  
3031                 flags = ext2_mask_flags(inode->i_mode, flags);
3032  
3033 +               if (IS_BARRIER(inode)) {
3034 +                       vxwprintk_task(1, "messing with the barrier.");
3035 +                       return -EACCES;
3036 +               }
3037 +
3038                 mutex_lock(&inode->i_mutex);
3039                 /* Is it quota file? Do not allow user to mess with it */
3040                 if (IS_NOQUOTA(inode)) {
3041 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
3042                  *
3043                  * This test looks nicer. Thanks to Pauline Middelink
3044                  */
3045 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
3046 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
3047 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
3048 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
3049                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3050                                 mutex_unlock(&inode->i_mutex);
3051                                 ret = -EPERM;
3052 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
3053                         }
3054                 }
3055  
3056 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
3057 +               flags &= EXT2_FL_USER_MODIFIABLE;
3058                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
3059                 ei->i_flags = flags;
3060                 mutex_unlock(&inode->i_mutex);
3061 diff -NurpP --minimal linux-2.6.35.4/fs/ext2/namei.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/namei.c
3062 --- linux-2.6.35.4/fs/ext2/namei.c      2010-07-07 18:31:51.000000000 +0200
3063 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/namei.c        2010-08-02 17:05:05.000000000 +0200
3064 @@ -32,6 +32,7 @@
3065  
3066  #include <linux/pagemap.h>
3067  #include <linux/quotaops.h>
3068 +#include <linux/vs_tag.h>
3069  #include "ext2.h"
3070  #include "xattr.h"
3071  #include "acl.h"
3072 @@ -75,6 +76,7 @@ static struct dentry *ext2_lookup(struct
3073                                 return ERR_PTR(-EIO);
3074                         } else {
3075                                 return ERR_CAST(inode);
3076 +               dx_propagate_tag(nd, inode);
3077                         }
3078                 }
3079         }
3080 @@ -418,6 +420,7 @@ const struct inode_operations ext2_dir_i
3081  #endif
3082         .setattr        = ext2_setattr,
3083         .check_acl      = ext2_check_acl,
3084 +       .sync_flags     = ext2_sync_flags,
3085  };
3086  
3087  const struct inode_operations ext2_special_inode_operations = {
3088 diff -NurpP --minimal linux-2.6.35.4/fs/ext2/super.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/super.c
3089 --- linux-2.6.35.4/fs/ext2/super.c      2010-08-02 16:52:48.000000000 +0200
3090 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext2/super.c        2010-08-02 17:05:05.000000000 +0200
3091 @@ -390,7 +390,8 @@ enum {
3092         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3093         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3094         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3095 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3096 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3097 +       Opt_tag, Opt_notag, Opt_tagid
3098  };
3099  
3100  static const match_table_t tokens = {
3101 @@ -418,6 +419,9 @@ static const match_table_t tokens = {
3102         {Opt_acl, "acl"},
3103         {Opt_noacl, "noacl"},
3104         {Opt_xip, "xip"},
3105 +       {Opt_tag, "tag"},
3106 +       {Opt_notag, "notag"},
3107 +       {Opt_tagid, "tagid=%u"},
3108         {Opt_grpquota, "grpquota"},
3109         {Opt_ignore, "noquota"},
3110         {Opt_quota, "quota"},
3111 @@ -488,6 +492,20 @@ static int parse_options(char *options, 
3112                 case Opt_nouid32:
3113                         set_opt (sbi->s_mount_opt, NO_UID32);
3114                         break;
3115 +#ifndef CONFIG_TAGGING_NONE
3116 +               case Opt_tag:
3117 +                       set_opt (sbi->s_mount_opt, TAGGED);
3118 +                       break;
3119 +               case Opt_notag:
3120 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3121 +                       break;
3122 +#endif
3123 +#ifdef CONFIG_PROPAGATE
3124 +               case Opt_tagid:
3125 +                       /* use args[0] */
3126 +                       set_opt (sbi->s_mount_opt, TAGGED);
3127 +                       break;
3128 +#endif
3129                 case Opt_nocheck:
3130                         clear_opt (sbi->s_mount_opt, CHECK);
3131                         break;
3132 @@ -845,6 +863,8 @@ static int ext2_fill_super(struct super_
3133         if (!parse_options((char *) data, sb))
3134                 goto failed_mount;
3135  
3136 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3137 +               sb->s_flags |= MS_TAGGED;
3138         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3139                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3140                  MS_POSIXACL : 0);
3141 @@ -1217,6 +1237,14 @@ static int ext2_remount (struct super_bl
3142                 goto restore_opts;
3143         }
3144  
3145 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3146 +               !(sb->s_flags & MS_TAGGED)) {
3147 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3148 +                      sb->s_id);
3149 +               err = -EINVAL;
3150 +               goto restore_opts;
3151 +       }
3152 +
3153         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3154                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3155  
3156 diff -NurpP --minimal linux-2.6.35.4/fs/ext3/file.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/file.c
3157 --- linux-2.6.35.4/fs/ext3/file.c       2010-07-07 18:31:51.000000000 +0200
3158 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/file.c 2010-08-02 17:05:05.000000000 +0200
3159 @@ -81,5 +81,6 @@ const struct inode_operations ext3_file_
3160  #endif
3161         .check_acl      = ext3_check_acl,
3162         .fiemap         = ext3_fiemap,
3163 +       .sync_flags     = ext3_sync_flags,
3164  };
3165  
3166 diff -NurpP --minimal linux-2.6.35.4/fs/ext3/ialloc.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/ialloc.c
3167 --- linux-2.6.35.4/fs/ext3/ialloc.c     2010-08-02 16:52:48.000000000 +0200
3168 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/ialloc.c       2010-08-02 18:14:48.000000000 +0200
3169 @@ -23,6 +23,7 @@
3170  #include <linux/buffer_head.h>
3171  #include <linux/random.h>
3172  #include <linux/bitops.h>
3173 +#include <linux/vs_tag.h>
3174  
3175  #include <asm/byteorder.h>
3176  
3177 @@ -543,6 +544,7 @@ got:
3178                 inode->i_mode = mode;
3179                 inode->i_uid = current_fsuid();
3180                 inode->i_gid = dir->i_gid;
3181 +               inode->i_tag = dx_current_fstag(sb);
3182         } else
3183                 inode_init_owner(inode, dir, mode);
3184  
3185 diff -NurpP --minimal linux-2.6.35.4/fs/ext3/inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/inode.c
3186 --- linux-2.6.35.4/fs/ext3/inode.c      2010-08-02 16:52:48.000000000 +0200
3187 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/inode.c        2010-08-02 17:05:05.000000000 +0200
3188 @@ -38,6 +38,7 @@
3189  #include <linux/bio.h>
3190  #include <linux/fiemap.h>
3191  #include <linux/namei.h>
3192 +#include <linux/vs_tag.h>
3193  #include "xattr.h"
3194  #include "acl.h"
3195  
3196 @@ -2354,7 +2355,7 @@ static void ext3_free_branches(handle_t 
3197  
3198  int ext3_can_truncate(struct inode *inode)
3199  {
3200 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3201 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3202                 return 0;
3203         if (S_ISREG(inode->i_mode))
3204                 return 1;
3205 @@ -2739,36 +2740,60 @@ void ext3_set_inode_flags(struct inode *
3206  {
3207         unsigned int flags = EXT3_I(inode)->i_flags;
3208  
3209 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3210 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3211 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3212 +
3213 +       if (flags & EXT3_IMMUTABLE_FL)
3214 +               inode->i_flags |= S_IMMUTABLE;
3215 +       if (flags & EXT3_IXUNLINK_FL)
3216 +               inode->i_flags |= S_IXUNLINK;
3217 +
3218         if (flags & EXT3_SYNC_FL)
3219                 inode->i_flags |= S_SYNC;
3220         if (flags & EXT3_APPEND_FL)
3221                 inode->i_flags |= S_APPEND;
3222 -       if (flags & EXT3_IMMUTABLE_FL)
3223 -               inode->i_flags |= S_IMMUTABLE;
3224         if (flags & EXT3_NOATIME_FL)
3225                 inode->i_flags |= S_NOATIME;
3226         if (flags & EXT3_DIRSYNC_FL)
3227                 inode->i_flags |= S_DIRSYNC;
3228 +
3229 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3230 +
3231 +       if (flags & EXT3_BARRIER_FL)
3232 +               inode->i_vflags |= V_BARRIER;
3233 +       if (flags & EXT3_COW_FL)
3234 +               inode->i_vflags |= V_COW;
3235  }
3236  
3237  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3238  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3239  {
3240         unsigned int flags = ei->vfs_inode.i_flags;
3241 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3242 +
3243 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3244 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3245 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3246 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3247 +
3248 +       if (flags & S_IMMUTABLE)
3249 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3250 +       if (flags & S_IXUNLINK)
3251 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3252  
3253 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3254 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3255         if (flags & S_SYNC)
3256                 ei->i_flags |= EXT3_SYNC_FL;
3257         if (flags & S_APPEND)
3258                 ei->i_flags |= EXT3_APPEND_FL;
3259 -       if (flags & S_IMMUTABLE)
3260 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3261         if (flags & S_NOATIME)
3262                 ei->i_flags |= EXT3_NOATIME_FL;
3263         if (flags & S_DIRSYNC)
3264                 ei->i_flags |= EXT3_DIRSYNC_FL;
3265 +
3266 +       if (vflags & V_BARRIER)
3267 +               ei->i_flags |= EXT3_BARRIER_FL;
3268 +       if (vflags & V_COW)
3269 +               ei->i_flags |= EXT3_COW_FL;
3270  }
3271  
3272  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3273 @@ -2782,6 +2807,8 @@ struct inode *ext3_iget(struct super_blo
3274         transaction_t *transaction;
3275         long ret;
3276         int block;
3277 +       uid_t uid;
3278 +       gid_t gid;
3279  
3280         inode = iget_locked(sb, ino);
3281         if (!inode)
3282 @@ -2798,12 +2825,17 @@ struct inode *ext3_iget(struct super_blo
3283         bh = iloc.bh;
3284         raw_inode = ext3_raw_inode(&iloc);
3285         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3286 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3287 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3288 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3289 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3290         if(!(test_opt (inode->i_sb, NO_UID32))) {
3291 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3292 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3293 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3294 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3295         }
3296 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3297 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3298 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3299 +               le16_to_cpu(raw_inode->i_raw_tag));
3300 +
3301         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3302         inode->i_size = le32_to_cpu(raw_inode->i_size);
3303         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3304 @@ -2958,6 +2990,8 @@ static int ext3_do_update_inode(handle_t
3305         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3306         struct ext3_inode_info *ei = EXT3_I(inode);
3307         struct buffer_head *bh = iloc->bh;
3308 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3309 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3310         int err = 0, rc, block;
3311  
3312  again:
3313 @@ -2972,29 +3006,32 @@ again:
3314         ext3_get_inode_flags(ei);
3315         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3316         if(!(test_opt(inode->i_sb, NO_UID32))) {
3317 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3318 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3319 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3320 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3321  /*
3322   * Fix up interoperability with old kernels. Otherwise, old inodes get
3323   * re-used with the upper 16 bits of the uid/gid intact
3324   */
3325                 if(!ei->i_dtime) {
3326                         raw_inode->i_uid_high =
3327 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3328 +                               cpu_to_le16(high_16_bits(uid));
3329                         raw_inode->i_gid_high =
3330 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3331 +                               cpu_to_le16(high_16_bits(gid));
3332                 } else {
3333                         raw_inode->i_uid_high = 0;
3334                         raw_inode->i_gid_high = 0;
3335                 }
3336         } else {
3337                 raw_inode->i_uid_low =
3338 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3339 +                       cpu_to_le16(fs_high2lowuid(uid));
3340                 raw_inode->i_gid_low =
3341 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3342 +                       cpu_to_le16(fs_high2lowgid(gid));
3343                 raw_inode->i_uid_high = 0;
3344                 raw_inode->i_gid_high = 0;
3345         }
3346 +#ifdef CONFIG_TAGGING_INTERN
3347 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3348 +#endif
3349         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3350         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3351         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3352 @@ -3154,7 +3191,8 @@ int ext3_setattr(struct dentry *dentry, 
3353         if (is_quota_modification(inode, attr))
3354                 dquot_initialize(inode);
3355         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3356 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3357 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3358 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3359                 handle_t *handle;
3360  
3361                 /* (user+group)*(old+new) structure, inode write (sb,
3362 @@ -3176,6 +3214,8 @@ int ext3_setattr(struct dentry *dentry, 
3363                         inode->i_uid = attr->ia_uid;
3364                 if (attr->ia_valid & ATTR_GID)
3365                         inode->i_gid = attr->ia_gid;
3366 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3367 +                       inode->i_tag = attr->ia_tag;
3368                 error = ext3_mark_inode_dirty(handle, inode);
3369                 ext3_journal_stop(handle);
3370         }
3371 diff -NurpP --minimal linux-2.6.35.4/fs/ext3/ioctl.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/ioctl.c
3372 --- linux-2.6.35.4/fs/ext3/ioctl.c      2009-06-11 17:13:03.000000000 +0200
3373 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/ioctl.c        2010-08-02 17:05:05.000000000 +0200
3374 @@ -8,6 +8,7 @@
3375   */
3376  
3377  #include <linux/fs.h>
3378 +#include <linux/mount.h>
3379  #include <linux/jbd.h>
3380  #include <linux/capability.h>
3381  #include <linux/ext3_fs.h>
3382 @@ -17,6 +18,34 @@
3383  #include <linux/compat.h>
3384  #include <asm/uaccess.h>
3385  
3386 +
3387 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3388 +{
3389 +       handle_t *handle = NULL;
3390 +       struct ext3_iloc iloc;
3391 +       int err;
3392 +
3393 +       handle = ext3_journal_start(inode, 1);
3394 +       if (IS_ERR(handle))
3395 +               return PTR_ERR(handle);
3396 +
3397 +       if (IS_SYNC(inode))
3398 +               handle->h_sync = 1;
3399 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3400 +       if (err)
3401 +               goto flags_err;
3402 +
3403 +       inode->i_flags = flags;
3404 +       inode->i_vflags = vflags;
3405 +       ext3_get_inode_flags(EXT3_I(inode));
3406 +       inode->i_ctime = CURRENT_TIME_SEC;
3407 +
3408 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3409 +flags_err:
3410 +       ext3_journal_stop(handle);
3411 +       return err;
3412 +}
3413 +
3414  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3415  {
3416         struct inode *inode = filp->f_dentry->d_inode;
3417 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3418  
3419                 flags = ext3_mask_flags(inode->i_mode, flags);
3420  
3421 +               if (IS_BARRIER(inode)) {
3422 +                       vxwprintk_task(1, "messing with the barrier.");
3423 +                       return -EACCES;
3424 +               }
3425 +
3426                 mutex_lock(&inode->i_mutex);
3427  
3428                 /* Is it quota file? Do not allow user to mess with it */
3429 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3430                  *
3431                  * This test looks nicer. Thanks to Pauline Middelink
3432                  */
3433 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3434 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3435 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3436 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3437                         if (!capable(CAP_LINUX_IMMUTABLE))
3438                                 goto flags_out;
3439                 }
3440 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3441                 if (err)
3442                         goto flags_err;
3443  
3444 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3445 +               flags &= EXT3_FL_USER_MODIFIABLE;
3446                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3447                 ei->i_flags = flags;
3448  
3449 diff -NurpP --minimal linux-2.6.35.4/fs/ext3/namei.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/namei.c
3450 --- linux-2.6.35.4/fs/ext3/namei.c      2010-07-07 18:31:51.000000000 +0200
3451 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/namei.c        2010-08-02 17:05:05.000000000 +0200
3452 @@ -36,6 +36,7 @@
3453  #include <linux/quotaops.h>
3454  #include <linux/buffer_head.h>
3455  #include <linux/bio.h>
3456 +#include <linux/vs_tag.h>
3457  
3458  #include "namei.h"
3459  #include "xattr.h"
3460 @@ -912,6 +913,7 @@ restart:
3461                                 if (bh)
3462                                         ll_rw_block(READ_META, 1, &bh);
3463                         }
3464 +               dx_propagate_tag(nd, inode);
3465                 }
3466                 if ((bh = bh_use[ra_ptr++]) == NULL)
3467                         goto next;
3468 @@ -2466,6 +2468,7 @@ const struct inode_operations ext3_dir_i
3469         .removexattr    = generic_removexattr,
3470  #endif
3471         .check_acl      = ext3_check_acl,
3472 +       .sync_flags     = ext3_sync_flags,
3473  };
3474  
3475  const struct inode_operations ext3_special_inode_operations = {
3476 diff -NurpP --minimal linux-2.6.35.4/fs/ext3/super.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/super.c
3477 --- linux-2.6.35.4/fs/ext3/super.c      2010-08-02 16:52:48.000000000 +0200
3478 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext3/super.c        2010-08-02 18:14:19.000000000 +0200
3479 @@ -817,7 +817,8 @@ enum {
3480         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3481         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3482         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
3483 -       Opt_resize, Opt_usrquota, Opt_grpquota
3484 +       Opt_resize, Opt_usrquota, Opt_grpquota,
3485 +       Opt_tag, Opt_notag, Opt_tagid
3486  };
3487  
3488  static const match_table_t tokens = {
3489 @@ -874,6 +875,9 @@ static const match_table_t tokens = {
3490         {Opt_barrier, "barrier"},
3491         {Opt_nobarrier, "nobarrier"},
3492         {Opt_resize, "resize"},
3493 +       {Opt_tag, "tag"},
3494 +       {Opt_notag, "notag"},
3495 +       {Opt_tagid, "tagid=%u"},
3496         {Opt_err, NULL},
3497  };
3498  
3499 @@ -1026,6 +1030,20 @@ static int parse_options (char *options,
3500                 case Opt_nouid32:
3501                         set_opt (sbi->s_mount_opt, NO_UID32);
3502                         break;
3503 +#ifndef CONFIG_TAGGING_NONE
3504 +               case Opt_tag:
3505 +                       set_opt (sbi->s_mount_opt, TAGGED);
3506 +                       break;
3507 +               case Opt_notag:
3508 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3509 +                       break;
3510 +#endif
3511 +#ifdef CONFIG_PROPAGATE
3512 +               case Opt_tagid:
3513 +                       /* use args[0] */
3514 +                       set_opt (sbi->s_mount_opt, TAGGED);
3515 +                       break;
3516 +#endif
3517                 case Opt_nocheck:
3518                         clear_opt (sbi->s_mount_opt, CHECK);
3519                         break;
3520 @@ -1712,6 +1730,9 @@ static int ext3_fill_super (struct super
3521                             NULL, 0))
3522                 goto failed_mount;
3523  
3524 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3525 +               sb->s_flags |= MS_TAGGED;
3526 +
3527         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3528                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3529  
3530 @@ -2585,6 +2606,14 @@ static int ext3_remount (struct super_bl
3531         if (test_opt(sb, ABORT))
3532                 ext3_abort(sb, __func__, "Abort forced by user");
3533  
3534 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3535 +               !(sb->s_flags & MS_TAGGED)) {
3536 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3537 +                       sb->s_id);
3538 +               err = -EINVAL;
3539 +               goto restore_opts;
3540 +       }
3541 +
3542         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3543                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3544  
3545 diff -NurpP --minimal linux-2.6.35.4/fs/ext4/ext4.h linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/ext4.h
3546 --- linux-2.6.35.4/fs/ext4/ext4.h       2010-08-02 16:52:48.000000000 +0200
3547 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/ext4.h 2010-08-02 17:05:05.000000000 +0200
3548 @@ -318,8 +318,12 @@ struct flex_groups {
3549  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3550  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3551  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3552 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3553  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3554  
3555 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3556 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3557 +
3558  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3559  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3560  
3561 @@ -588,7 +592,8 @@ struct ext4_inode {
3562                         __le16  l_i_file_acl_high;
3563                         __le16  l_i_uid_high;   /* these 2 fields */
3564                         __le16  l_i_gid_high;   /* were reserved2[0] */
3565 -                       __u32   l_i_reserved2;
3566 +                       __le16  l_i_tag;        /* Context Tag */
3567 +                       __u16   l_i_reserved2;
3568                 } linux2;
3569                 struct {
3570                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3571 @@ -702,6 +707,7 @@ do {                                                                               \
3572  #define i_gid_low      i_gid
3573  #define i_uid_high     osd2.linux2.l_i_uid_high
3574  #define i_gid_high     osd2.linux2.l_i_gid_high
3575 +#define i_raw_tag      osd2.linux2.l_i_tag
3576  #define i_reserved2    osd2.linux2.l_i_reserved2
3577  
3578  #elif defined(__GNU__)
3579 @@ -881,6 +887,7 @@ struct ext4_inode_info {
3580  #define EXT4_MOUNT_JOURNAL_CHECKSUM    0x800000 /* Journal checksums */
3581  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
3582  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3583 +#define EXT4_MOUNT_TAGGED              0x4000000 /* Enable Context Tags */
3584  #define EXT4_MOUNT_DELALLOC            0x8000000 /* Delalloc support */
3585  #define EXT4_MOUNT_DATA_ERR_ABORT      0x10000000 /* Abort on file data write */
3586  #define EXT4_MOUNT_BLOCK_VALIDITY      0x20000000 /* Block validity checking */
3587 @@ -1910,6 +1917,7 @@ extern int ext4_get_blocks(handle_t *han
3588                            struct buffer_head *bh, int flags);
3589  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3590                         __u64 start, __u64 len);
3591 +extern int ext4_sync_flags(struct inode *, int, int);
3592  /* move_extent.c */
3593  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3594                              __u64 start_orig, __u64 start_donor,
3595 diff -NurpP --minimal linux-2.6.35.4/fs/ext4/file.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/file.c
3596 --- linux-2.6.35.4/fs/ext4/file.c       2010-08-02 16:52:48.000000000 +0200
3597 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/file.c 2010-08-02 17:05:05.000000000 +0200
3598 @@ -160,5 +160,6 @@ const struct inode_operations ext4_file_
3599         .check_acl      = ext4_check_acl,
3600         .fallocate      = ext4_fallocate,
3601         .fiemap         = ext4_fiemap,
3602 +       .sync_flags     = ext4_sync_flags,
3603  };
3604  
3605 diff -NurpP --minimal linux-2.6.35.4/fs/ext4/ialloc.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/ialloc.c
3606 --- linux-2.6.35.4/fs/ext4/ialloc.c     2010-08-02 16:52:48.000000000 +0200
3607 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/ialloc.c       2010-08-02 18:12:48.000000000 +0200
3608 @@ -22,6 +22,7 @@
3609  #include <linux/random.h>
3610  #include <linux/bitops.h>
3611  #include <linux/blkdev.h>
3612 +#include <linux/vs_tag.h>
3613  #include <asm/byteorder.h>
3614  
3615  #include "ext4.h"
3616 @@ -976,6 +977,7 @@ got:
3617                 inode->i_mode = mode;
3618                 inode->i_uid = current_fsuid();
3619                 inode->i_gid = dir->i_gid;
3620 +               inode->i_tag = dx_current_fstag(sb);
3621         } else
3622                 inode_init_owner(inode, dir, mode);
3623  
3624 diff -NurpP --minimal linux-2.6.35.4/fs/ext4/inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/inode.c
3625 --- linux-2.6.35.4/fs/ext4/inode.c      2010-08-02 16:52:48.000000000 +0200
3626 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/inode.c        2010-08-02 18:11:10.000000000 +0200
3627 @@ -40,6 +40,7 @@
3628  #include <linux/workqueue.h>
3629  #include <linux/kernel.h>
3630  #include <linux/slab.h>
3631 +#include <linux/vs_tag.h>
3632  
3633  #include "ext4_jbd2.h"
3634  #include "xattr.h"
3635 @@ -4575,7 +4576,7 @@ static void ext4_free_branches(handle_t 
3636  
3637  int ext4_can_truncate(struct inode *inode)
3638  {
3639 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3640 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3641                 return 0;
3642         if (S_ISREG(inode->i_mode))
3643                 return 1;
3644 @@ -4926,41 +4927,64 @@ void ext4_set_inode_flags(struct inode *
3645  {
3646         unsigned int flags = EXT4_I(inode)->i_flags;
3647  
3648 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3649 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3650 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3651 +
3652 +       if (flags & EXT4_IMMUTABLE_FL)
3653 +               inode->i_flags |= S_IMMUTABLE;
3654 +       if (flags & EXT4_IXUNLINK_FL)
3655 +               inode->i_flags |= S_IXUNLINK;
3656 +
3657         if (flags & EXT4_SYNC_FL)
3658                 inode->i_flags |= S_SYNC;
3659         if (flags & EXT4_APPEND_FL)
3660                 inode->i_flags |= S_APPEND;
3661 -       if (flags & EXT4_IMMUTABLE_FL)
3662 -               inode->i_flags |= S_IMMUTABLE;
3663         if (flags & EXT4_NOATIME_FL)
3664                 inode->i_flags |= S_NOATIME;
3665         if (flags & EXT4_DIRSYNC_FL)
3666                 inode->i_flags |= S_DIRSYNC;
3667 +
3668 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3669 +
3670 +       if (flags & EXT4_BARRIER_FL)
3671 +               inode->i_vflags |= V_BARRIER;
3672 +       if (flags & EXT4_COW_FL)
3673 +               inode->i_vflags |= V_COW;
3674  }
3675  
3676  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3677  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3678  {
3679 -       unsigned int vfs_fl;
3680 +       unsigned int vfs_fl, vfs_vf;
3681         unsigned long old_fl, new_fl;
3682  
3683         do {
3684                 vfs_fl = ei->vfs_inode.i_flags;
3685 +               vfs_vf = ei->vfs_inode.i_vflags;
3686                 old_fl = ei->i_flags;
3687                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3688                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3689 -                               EXT4_DIRSYNC_FL);
3690 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3691 +                               EXT4_COW_FL);
3692 +
3693 +               if (vfs_fl & S_IMMUTABLE)
3694 +                       new_fl |= EXT4_IMMUTABLE_FL;
3695 +               if (vfs_fl & S_IXUNLINK)
3696 +                       new_fl |= EXT4_IXUNLINK_FL;
3697 +
3698                 if (vfs_fl & S_SYNC)
3699                         new_fl |= EXT4_SYNC_FL;
3700                 if (vfs_fl & S_APPEND)
3701                         new_fl |= EXT4_APPEND_FL;
3702 -               if (vfs_fl & S_IMMUTABLE)
3703 -                       new_fl |= EXT4_IMMUTABLE_FL;
3704                 if (vfs_fl & S_NOATIME)
3705                         new_fl |= EXT4_NOATIME_FL;
3706                 if (vfs_fl & S_DIRSYNC)
3707                         new_fl |= EXT4_DIRSYNC_FL;
3708 +
3709 +               if (vfs_vf & V_BARRIER)
3710 +                       new_fl |= EXT4_BARRIER_FL;
3711 +               if (vfs_vf & V_COW)
3712 +                       new_fl |= EXT4_COW_FL;
3713         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3714  }
3715  
3716 @@ -4996,6 +5020,8 @@ struct inode *ext4_iget(struct super_blo
3717         journal_t *journal = EXT4_SB(sb)->s_journal;
3718         long ret;
3719         int block;
3720 +       uid_t uid;
3721 +       gid_t gid;
3722  
3723         inode = iget_locked(sb, ino);
3724         if (!inode)
3725 @@ -5011,12 +5037,16 @@ struct inode *ext4_iget(struct super_blo
3726                 goto bad_inode;
3727         raw_inode = ext4_raw_inode(&iloc);
3728         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3729 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3730 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3731 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3732 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3733         if (!(test_opt(inode->i_sb, NO_UID32))) {
3734 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3735 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3736 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3737 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3738         }
3739 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3740 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3741 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3742 +               le16_to_cpu(raw_inode->i_raw_tag));
3743         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3744  
3745         ei->i_state_flags = 0;
3746 @@ -5235,6 +5265,8 @@ static int ext4_do_update_inode(handle_t
3747         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3748         struct ext4_inode_info *ei = EXT4_I(inode);
3749         struct buffer_head *bh = iloc->bh;
3750 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3751 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3752         int err = 0, rc, block;
3753  
3754         /* For fields not not tracking in the in-memory inode,
3755 @@ -5245,29 +5277,32 @@ static int ext4_do_update_inode(handle_t
3756         ext4_get_inode_flags(ei);
3757         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3758         if (!(test_opt(inode->i_sb, NO_UID32))) {
3759 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3760 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3761 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3762 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3763  /*
3764   * Fix up interoperability with old kernels. Otherwise, old inodes get
3765   * re-used with the upper 16 bits of the uid/gid intact
3766   */
3767                 if (!ei->i_dtime) {
3768                         raw_inode->i_uid_high =
3769 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3770 +                               cpu_to_le16(high_16_bits(uid));
3771                         raw_inode->i_gid_high =
3772 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3773 +                               cpu_to_le16(high_16_bits(gid));
3774                 } else {
3775                         raw_inode->i_uid_high = 0;
3776                         raw_inode->i_gid_high = 0;
3777                 }
3778         } else {
3779                 raw_inode->i_uid_low =
3780 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3781 +                       cpu_to_le16(fs_high2lowuid(uid));
3782                 raw_inode->i_gid_low =
3783 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3784 +                       cpu_to_le16(fs_high2lowgid(gid));
3785                 raw_inode->i_uid_high = 0;
3786                 raw_inode->i_gid_high = 0;
3787         }
3788 +#ifdef CONFIG_TAGGING_INTERN
3789 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3790 +#endif
3791         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3792  
3793         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3794 @@ -5453,7 +5488,8 @@ int ext4_setattr(struct dentry *dentry, 
3795         if (is_quota_modification(inode, attr))
3796                 dquot_initialize(inode);
3797         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3798 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3799 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3800 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3801                 handle_t *handle;
3802  
3803                 /* (user+group)*(old+new) structure, inode write (sb,
3804 @@ -5475,6 +5511,8 @@ int ext4_setattr(struct dentry *dentry, 
3805                         inode->i_uid = attr->ia_uid;
3806                 if (attr->ia_valid & ATTR_GID)
3807                         inode->i_gid = attr->ia_gid;
3808 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3809 +                       inode->i_tag = attr->ia_tag;
3810                 error = ext4_mark_inode_dirty(handle, inode);
3811                 ext4_journal_stop(handle);
3812         }
3813 diff -NurpP --minimal linux-2.6.35.4/fs/ext4/ioctl.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/ioctl.c
3814 --- linux-2.6.35.4/fs/ext4/ioctl.c      2010-08-02 16:52:48.000000000 +0200
3815 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/ioctl.c        2010-08-02 17:05:05.000000000 +0200
3816 @@ -14,10 +14,39 @@
3817  #include <linux/compat.h>
3818  #include <linux/mount.h>
3819  #include <linux/file.h>
3820 +#include <linux/vs_tag.h>
3821  #include <asm/uaccess.h>
3822  #include "ext4_jbd2.h"
3823  #include "ext4.h"
3824  
3825 +
3826 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3827 +{
3828 +       handle_t *handle = NULL;
3829 +       struct ext4_iloc iloc;
3830 +       int err;
3831 +
3832 +       handle = ext4_journal_start(inode, 1);
3833 +       if (IS_ERR(handle))
3834 +               return PTR_ERR(handle);
3835 +
3836 +       if (IS_SYNC(inode))
3837 +               ext4_handle_sync(handle);
3838 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3839 +       if (err)
3840 +               goto flags_err;
3841 +
3842 +       inode->i_flags = flags;
3843 +       inode->i_vflags = vflags;
3844 +       ext4_get_inode_flags(EXT4_I(inode));
3845 +       inode->i_ctime = ext4_current_time(inode);
3846 +
3847 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3848 +flags_err:
3849 +       ext4_journal_stop(handle);
3850 +       return err;
3851 +}
3852 +
3853  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3854  {
3855         struct inode *inode = filp->f_dentry->d_inode;
3856 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3857  
3858                 flags = ext4_mask_flags(inode->i_mode, flags);
3859  
3860 +               if (IS_BARRIER(inode)) {
3861 +                       vxwprintk_task(1, "messing with the barrier.");
3862 +                       return -EACCES;
3863 +               }
3864 +
3865                 err = -EPERM;
3866                 mutex_lock(&inode->i_mutex);
3867                 /* Is it quota file? Do not allow user to mess with it */
3868 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3869                  *
3870                  * This test looks nicer. Thanks to Pauline Middelink
3871                  */
3872 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3873 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3874 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3875 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3876                         if (!capable(CAP_LINUX_IMMUTABLE))
3877                                 goto flags_out;
3878                 }
3879 diff -NurpP --minimal linux-2.6.35.4/fs/ext4/namei.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/namei.c
3880 --- linux-2.6.35.4/fs/ext4/namei.c      2010-08-02 16:52:48.000000000 +0200
3881 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/namei.c        2010-08-02 17:05:05.000000000 +0200
3882 @@ -34,6 +34,7 @@
3883  #include <linux/quotaops.h>
3884  #include <linux/buffer_head.h>
3885  #include <linux/bio.h>
3886 +#include <linux/vs_tag.h>
3887  #include "ext4.h"
3888  #include "ext4_jbd2.h"
3889  
3890 @@ -937,6 +938,7 @@ restart:
3891                                 if (bh)
3892                                         ll_rw_block(READ_META, 1, &bh);
3893                         }
3894 +               dx_propagate_tag(nd, inode);
3895                 }
3896                 if ((bh = bh_use[ra_ptr++]) == NULL)
3897                         goto next;
3898 @@ -2550,6 +2552,7 @@ const struct inode_operations ext4_dir_i
3899  #endif
3900         .check_acl      = ext4_check_acl,
3901         .fiemap         = ext4_fiemap,
3902 +       .sync_flags     = ext4_sync_flags,
3903  };
3904  
3905  const struct inode_operations ext4_special_inode_operations = {
3906 diff -NurpP --minimal linux-2.6.35.4/fs/ext4/super.c linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/super.c
3907 --- linux-2.6.35.4/fs/ext4/super.c      2010-09-05 01:41:57.000000000 +0200
3908 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ext4/super.c        2010-08-14 18:19:32.000000000 +0200
3909 @@ -1161,6 +1161,7 @@ enum {
3910         Opt_inode_readahead_blks, Opt_journal_ioprio,
3911         Opt_dioread_nolock, Opt_dioread_lock,
3912         Opt_discard, Opt_nodiscard,
3913 +       Opt_tag, Opt_notag, Opt_tagid
3914  };
3915  
3916  static const match_table_t tokens = {
3917 @@ -1231,6 +1232,9 @@ static const match_table_t tokens = {
3918         {Opt_dioread_lock, "dioread_lock"},
3919         {Opt_discard, "discard"},
3920         {Opt_nodiscard, "nodiscard"},
3921 +       {Opt_tag, "tag"},
3922 +       {Opt_notag, "notag"},
3923 +       {Opt_tagid, "tagid=%u"},
3924         {Opt_err, NULL},
3925  };
3926  
3927 @@ -1399,6 +1403,20 @@ static int parse_options(char *options, 
3928                 case Opt_nouid32:
3929                         set_opt(sbi->s_mount_opt, NO_UID32);
3930                         break;
3931 +#ifndef CONFIG_TAGGING_NONE
3932 +               case Opt_tag:
3933 +                       set_opt (sbi->s_mount_opt, TAGGED);
3934 +                       break;
3935 +               case Opt_notag:
3936 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3937 +                       break;
3938 +#endif
3939 +#ifdef CONFIG_PROPAGATE
3940 +               case Opt_tagid:
3941 +                       /* use args[0] */
3942 +                       set_opt (sbi->s_mount_opt, TAGGED);
3943 +                       break;
3944 +#endif
3945                 case Opt_debug:
3946                         set_opt(sbi->s_mount_opt, DEBUG);
3947                         break;
3948 @@ -2566,6 +2584,9 @@ static int ext4_fill_super(struct super_
3949                            &journal_ioprio, NULL, 0))
3950                 goto failed_mount;
3951  
3952 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3953 +               sb->s_flags |= MS_TAGGED;
3954 +
3955         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3956                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3957  
3958 @@ -3618,6 +3639,14 @@ static int ext4_remount(struct super_blo
3959         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3960                 ext4_abort(sb, __func__, "Abort forced by user");
3961  
3962 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3963 +               !(sb->s_flags & MS_TAGGED)) {
3964 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3965 +                       sb->s_id);
3966 +               err = -EINVAL;
3967 +               goto restore_opts;
3968 +       }
3969 +
3970         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3971                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3972  
3973 diff -NurpP --minimal linux-2.6.35.4/fs/fcntl.c linux-2.6.35.4-vs2.3.0.36.32/fs/fcntl.c
3974 --- linux-2.6.35.4/fs/fcntl.c   2010-08-02 16:52:49.000000000 +0200
3975 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/fcntl.c     2010-08-02 17:05:06.000000000 +0200
3976 @@ -20,6 +20,7 @@
3977  #include <linux/signal.h>
3978  #include <linux/rcupdate.h>
3979  #include <linux/pid_namespace.h>
3980 +#include <linux/vs_limit.h>
3981  
3982  #include <asm/poll.h>
3983  #include <asm/siginfo.h>
3984 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3985  
3986         if (tofree)
3987                 filp_close(tofree, files);
3988 +       else
3989 +               vx_openfd_inc(newfd);   /* fd was unused */
3990  
3991         return newfd;
3992  
3993 @@ -434,6 +437,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3994         filp = fget(fd);
3995         if (!filp)
3996                 goto out;
3997 +       if (!vx_files_avail(1))
3998 +               goto out;
3999  
4000         err = security_file_fcntl(filp, cmd, arg);
4001         if (err) {
4002 diff -NurpP --minimal linux-2.6.35.4/fs/file.c linux-2.6.35.4-vs2.3.0.36.32/fs/file.c
4003 --- linux-2.6.35.4/fs/file.c    2010-07-07 18:31:51.000000000 +0200
4004 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/file.c      2010-08-02 17:05:06.000000000 +0200
4005 @@ -20,6 +20,7 @@
4006  #include <linux/spinlock.h>
4007  #include <linux/rcupdate.h>
4008  #include <linux/workqueue.h>
4009 +#include <linux/vs_limit.h>
4010  
4011  struct fdtable_defer {
4012         spinlock_t lock;
4013 @@ -368,6 +369,8 @@ struct files_struct *dup_fd(struct files
4014                 struct file *f = *old_fds++;
4015                 if (f) {
4016                         get_file(f);
4017 +                       /* TODO: sum it first for check and performance */
4018 +                       vx_openfd_inc(open_files - i);
4019                 } else {
4020                         /*
4021                          * The fd may be claimed in the fd bitmap but not yet
4022 @@ -476,6 +479,7 @@ repeat:
4023         else
4024                 FD_CLR(fd, fdt->close_on_exec);
4025         error = fd;
4026 +       vx_openfd_inc(fd);
4027  #if 1
4028         /* Sanity check */
4029         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
4030 diff -NurpP --minimal linux-2.6.35.4/fs/file_table.c linux-2.6.35.4-vs2.3.0.36.32/fs/file_table.c
4031 --- linux-2.6.35.4/fs/file_table.c      2010-08-02 16:52:49.000000000 +0200
4032 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/file_table.c        2010-08-02 17:05:06.000000000 +0200
4033 @@ -22,6 +22,8 @@
4034  #include <linux/sysctl.h>
4035  #include <linux/percpu_counter.h>
4036  #include <linux/ima.h>
4037 +#include <linux/vs_limit.h>
4038 +#include <linux/vs_context.h>
4039  
4040  #include <asm/atomic.h>
4041  
4042 @@ -133,6 +135,8 @@ struct file *get_empty_filp(void)
4043         spin_lock_init(&f->f_lock);
4044         eventpoll_init_file(f);
4045         /* f->f_version: 0 */
4046 +       f->f_xid = vx_current_xid();
4047 +       vx_files_inc(f);
4048         return f;
4049  
4050  over:
4051 @@ -249,6 +253,8 @@ static void __fput(struct file *file)
4052                 cdev_put(inode->i_cdev);
4053         fops_put(file->f_op);
4054         put_pid(file->f_owner.pid);
4055 +       vx_files_dec(file);
4056 +       file->f_xid = 0;
4057         file_kill(file);
4058         if (file->f_mode & FMODE_WRITE)
4059                 drop_file_write_access(file);
4060 @@ -324,6 +330,8 @@ void put_filp(struct file *file)
4061  {
4062         if (atomic_long_dec_and_test(&file->f_count)) {
4063                 security_file_free(file);
4064 +               vx_files_dec(file);
4065 +               file->f_xid = 0;
4066                 file_kill(file);
4067                 file_free(file);
4068         }
4069 diff -NurpP --minimal linux-2.6.35.4/fs/fs_struct.c linux-2.6.35.4-vs2.3.0.36.32/fs/fs_struct.c
4070 --- linux-2.6.35.4/fs/fs_struct.c       2009-06-11 17:13:04.000000000 +0200
4071 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/fs_struct.c 2010-08-02 17:05:06.000000000 +0200
4072 @@ -4,6 +4,7 @@
4073  #include <linux/path.h>
4074  #include <linux/slab.h>
4075  #include <linux/fs_struct.h>
4076 +#include <linux/vserver/global.h>
4077  
4078  /*
4079   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
4080 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
4081  {
4082         path_put(&fs->root);
4083         path_put(&fs->pwd);
4084 +       atomic_dec(&vs_global_fs);
4085         kmem_cache_free(fs_cachep, fs);
4086  }
4087  
4088 @@ -112,6 +114,7 @@ struct fs_struct *copy_fs_struct(struct 
4089                 fs->pwd = old->pwd;
4090                 path_get(&old->pwd);
4091                 read_unlock(&old->lock);
4092 +               atomic_inc(&vs_global_fs);
4093         }
4094         return fs;
4095  }
4096 diff -NurpP --minimal linux-2.6.35.4/fs/gfs2/file.c linux-2.6.35.4-vs2.3.0.36.32/fs/gfs2/file.c
4097 --- linux-2.6.35.4/fs/gfs2/file.c       2010-08-02 16:52:49.000000000 +0200
4098 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/gfs2/file.c 2010-08-02 17:05:06.000000000 +0200
4099 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
4100         [7] = GFS2_DIF_NOATIME,
4101         [12] = GFS2_DIF_EXHASH,
4102         [14] = GFS2_DIF_INHERIT_JDATA,
4103 +       [27] = GFS2_DIF_IXUNLINK,
4104 +       [26] = GFS2_DIF_BARRIER,
4105 +       [29] = GFS2_DIF_COW,
4106  };
4107  
4108  static const u32 gfs2_to_fsflags[32] = {
4109 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
4110         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4111         [gfs2fl_ExHash] = FS_INDEX_FL,
4112         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4113 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4114 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4115 +       [gfs2fl_Cow] = FS_COW_FL,
4116  };
4117  
4118  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4119 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
4120  {
4121         struct gfs2_inode *ip = GFS2_I(inode);
4122         unsigned int flags = inode->i_flags;
4123 +       unsigned int vflags = inode->i_vflags;
4124 +
4125 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4126 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4127  
4128 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4129         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4130                 flags |= S_IMMUTABLE;
4131 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4132 +               flags |= S_IXUNLINK;
4133 +
4134         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4135                 flags |= S_APPEND;
4136         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4137 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
4138         if (ip->i_diskflags & GFS2_DIF_SYNC)
4139                 flags |= S_SYNC;
4140         inode->i_flags = flags;
4141 +
4142 +       vflags &= ~(V_BARRIER | V_COW);
4143 +
4144 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4145 +               vflags |= V_BARRIER;
4146 +       if (ip->i_diskflags & GFS2_DIF_COW)
4147 +               vflags |= V_COW;
4148 +       inode->i_vflags = vflags;
4149 +}
4150 +
4151 +void gfs2_get_inode_flags(struct inode *inode)
4152 +{
4153 +       struct gfs2_inode *ip = GFS2_I(inode);
4154 +       unsigned int flags = inode->i_flags;
4155 +       unsigned int vflags = inode->i_vflags;
4156 +
4157 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4158 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4159 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4160 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4161 +
4162 +       if (flags & S_IMMUTABLE)
4163 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4164 +       if (flags & S_IXUNLINK)
4165 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4166 +
4167 +       if (flags & S_APPEND)
4168 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4169 +       if (flags & S_NOATIME)
4170 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4171 +       if (flags & S_SYNC)
4172 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4173 +
4174 +       if (vflags & V_BARRIER)
4175 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4176 +       if (vflags & V_COW)
4177 +               ip->i_diskflags |= GFS2_DIF_COW;
4178  }
4179  
4180  /* Flags that can be set by user space */
4181 @@ -293,6 +342,37 @@ static int gfs2_set_flags(struct file *f
4182         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4183  }
4184  
4185 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4186 +{
4187 +       struct gfs2_inode *ip = GFS2_I(inode);
4188 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4189 +       struct buffer_head *bh;
4190 +       struct gfs2_holder gh;
4191 +       int error;
4192 +
4193 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4194 +       if (error)
4195 +               return error;
4196 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4197 +       if (error)
4198 +               goto out;
4199 +       error = gfs2_meta_inode_buffer(ip, &bh);
4200 +       if (error)
4201 +               goto out_trans_end;
4202 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4203 +       inode->i_flags = flags;
4204 +       inode->i_vflags = vflags;
4205 +       gfs2_get_inode_flags(inode);
4206 +       gfs2_dinode_out(ip, bh->b_data);
4207 +       brelse(bh);
4208 +       gfs2_set_aops(inode);
4209 +out_trans_end:
4210 +       gfs2_trans_end(sdp);
4211 +out:
4212 +       gfs2_glock_dq_uninit(&gh);
4213 +       return error;
4214 +}
4215 +
4216  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4217  {
4218         switch(cmd) {
4219 diff -NurpP --minimal linux-2.6.35.4/fs/gfs2/inode.h linux-2.6.35.4-vs2.3.0.36.32/fs/gfs2/inode.h
4220 --- linux-2.6.35.4/fs/gfs2/inode.h      2010-08-02 16:52:49.000000000 +0200
4221 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/gfs2/inode.h        2010-08-02 17:05:06.000000000 +0200
4222 @@ -109,6 +109,7 @@ extern const struct file_operations gfs2
4223  extern const struct file_operations gfs2_dir_fops_nolock;
4224  
4225  extern void gfs2_set_inode_flags(struct inode *inode);
4226 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4227   
4228  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4229  extern const struct file_operations gfs2_file_fops;
4230 diff -NurpP --minimal linux-2.6.35.4/fs/gfs2/ops_inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/gfs2/ops_inode.c
4231 --- linux-2.6.35.4/fs/gfs2/ops_inode.c  2010-08-02 16:52:49.000000000 +0200
4232 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/gfs2/ops_inode.c    2010-08-02 17:05:06.000000000 +0200
4233 @@ -1346,6 +1346,7 @@ const struct inode_operations gfs2_file_
4234         .listxattr = gfs2_listxattr,
4235         .removexattr = gfs2_removexattr,
4236         .fiemap = gfs2_fiemap,
4237 +       .sync_flags = gfs2_sync_flags,
4238  };
4239  
4240  const struct inode_operations gfs2_dir_iops = {
4241 @@ -1366,6 +1367,7 @@ const struct inode_operations gfs2_dir_i
4242         .listxattr = gfs2_listxattr,
4243         .removexattr = gfs2_removexattr,
4244         .fiemap = gfs2_fiemap,
4245 +       .sync_flags = gfs2_sync_flags,
4246  };
4247  
4248  const struct inode_operations gfs2_symlink_iops = {
4249 diff -NurpP --minimal linux-2.6.35.4/fs/hfsplus/ioctl.c linux-2.6.35.4-vs2.3.0.36.32/fs/hfsplus/ioctl.c
4250 --- linux-2.6.35.4/fs/hfsplus/ioctl.c   2010-08-02 16:52:49.000000000 +0200
4251 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/hfsplus/ioctl.c     2010-08-02 17:48:55.000000000 +0200
4252 @@ -18,6 +18,7 @@
4253  #include <linux/sched.h>
4254  #include <linux/xattr.h>
4255  #include <linux/smp_lock.h>
4256 +// #include <linux/mount.h>
4257  #include <asm/uaccess.h>
4258  #include "hfsplus_fs.h"
4259  
4260 diff -NurpP --minimal linux-2.6.35.4/fs/inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/inode.c
4261 --- linux-2.6.35.4/fs/inode.c   2010-08-02 16:52:49.000000000 +0200
4262 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/inode.c     2010-08-02 19:08:57.000000000 +0200
4263 @@ -25,6 +25,7 @@
4264  #include <linux/mount.h>
4265  #include <linux/async.h>
4266  #include <linux/posix_acl.h>
4267 +#include <linux/vs_tag.h>
4268  
4269  /*
4270   * This is needed for the following functions:
4271 @@ -131,6 +132,9 @@ int inode_init_always(struct super_block
4272         struct address_space *const mapping = &inode->i_data;
4273  
4274         inode->i_sb = sb;
4275 +
4276 +       /* essential because of inode slab reuse */
4277 +       inode->i_tag = 0;
4278         inode->i_blkbits = sb->s_blocksize_bits;
4279         inode->i_flags = 0;
4280         atomic_set(&inode->i_count, 1);
4281 @@ -151,6 +155,7 @@ int inode_init_always(struct super_block
4282         inode->i_bdev = NULL;
4283         inode->i_cdev = NULL;
4284         inode->i_rdev = 0;
4285 +       inode->i_mdev = 0;
4286         inode->dirtied_when = 0;
4287  
4288         if (security_inode_alloc(inode))
4289 @@ -294,6 +299,8 @@ void __iget(struct inode *inode)
4290         inodes_stat.nr_unused--;
4291  }
4292  
4293 +EXPORT_SYMBOL_GPL(__iget);
4294 +
4295  /**
4296   * clear_inode - clear an inode
4297   * @inode: inode to clear
4298 @@ -1593,9 +1600,11 @@ void init_special_inode(struct inode *in
4299         if (S_ISCHR(mode)) {
4300                 inode->i_fop = &def_chr_fops;
4301                 inode->i_rdev = rdev;
4302 +               inode->i_mdev = rdev;
4303         } else if (S_ISBLK(mode)) {
4304                 inode->i_fop = &def_blk_fops;
4305                 inode->i_rdev = rdev;
4306 +               inode->i_mdev = rdev;
4307         } else if (S_ISFIFO(mode))
4308                 inode->i_fop = &def_fifo_fops;
4309         else if (S_ISSOCK(mode))
4310 @@ -1624,5 +1633,6 @@ void inode_init_owner(struct inode *inod
4311         } else
4312                 inode->i_gid = current_fsgid();
4313         inode->i_mode = mode;
4314 +       inode->i_tag = dx_current_fstag(inode->i_sb);
4315  }
4316  EXPORT_SYMBOL(inode_init_owner);
4317 diff -NurpP --minimal linux-2.6.35.4/fs/ioctl.c linux-2.6.35.4-vs2.3.0.36.32/fs/ioctl.c
4318 --- linux-2.6.35.4/fs/ioctl.c   2010-08-02 16:52:49.000000000 +0200
4319 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ioctl.c     2010-08-02 17:05:06.000000000 +0200
4320 @@ -16,6 +16,9 @@
4321  #include <linux/writeback.h>
4322  #include <linux/buffer_head.h>
4323  #include <linux/falloc.h>
4324 +#include <linux/proc_fs.h>
4325 +#include <linux/vserver/inode.h>
4326 +#include <linux/vs_tag.h>
4327  
4328  #include <asm/ioctls.h>
4329  
4330 diff -NurpP --minimal linux-2.6.35.4/fs/ioprio.c linux-2.6.35.4-vs2.3.0.36.32/fs/ioprio.c
4331 --- linux-2.6.35.4/fs/ioprio.c  2010-07-07 18:31:52.000000000 +0200
4332 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ioprio.c    2010-08-02 17:05:06.000000000 +0200
4333 @@ -27,6 +27,7 @@
4334  #include <linux/syscalls.h>
4335  #include <linux/security.h>
4336  #include <linux/pid_namespace.h>
4337 +#include <linux/vs_base.h>
4338  
4339  int set_task_ioprio(struct task_struct *task, int ioprio)
4340  {
4341 @@ -124,6 +125,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4342                         else
4343                                 pgrp = find_vpid(who);
4344                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4345 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4346 +                                       continue;
4347                                 ret = set_task_ioprio(p, ioprio);
4348                                 if (ret)
4349                                         break;
4350 @@ -213,6 +216,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4351                         else
4352                                 pgrp = find_vpid(who);
4353                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4354 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4355 +                                       continue;
4356                                 tmpio = get_task_ioprio(p);
4357                                 if (tmpio < 0)
4358                                         continue;
4359 diff -NurpP --minimal linux-2.6.35.4/fs/jfs/file.c linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/file.c
4360 --- linux-2.6.35.4/fs/jfs/file.c        2010-08-02 16:52:49.000000000 +0200
4361 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/file.c  2010-08-02 17:05:06.000000000 +0200
4362 @@ -101,7 +101,8 @@ int jfs_setattr(struct dentry *dentry, s
4363         if (is_quota_modification(inode, iattr))
4364                 dquot_initialize(inode);
4365         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4366 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4367 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4368 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4369                 rc = dquot_transfer(inode, iattr);
4370                 if (rc)
4371                         return rc;
4372 @@ -125,6 +126,7 @@ const struct inode_operations jfs_file_i
4373  #ifdef CONFIG_JFS_POSIX_ACL
4374         .check_acl      = jfs_check_acl,
4375  #endif
4376 +       .sync_flags     = jfs_sync_flags,
4377  };
4378  
4379  const struct file_operations jfs_file_operations = {
4380 diff -NurpP --minimal linux-2.6.35.4/fs/jfs/ioctl.c linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/ioctl.c
4381 --- linux-2.6.35.4/fs/jfs/ioctl.c       2008-12-25 00:26:37.000000000 +0100
4382 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/ioctl.c 2010-08-02 17:05:06.000000000 +0200
4383 @@ -11,6 +11,7 @@
4384  #include <linux/mount.h>
4385  #include <linux/time.h>
4386  #include <linux/sched.h>
4387 +#include <linux/mount.h>
4388  #include <asm/current.h>
4389  #include <asm/uaccess.h>
4390  
4391 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4392  }
4393  
4394  
4395 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4396 +{
4397 +       inode->i_flags = flags;
4398 +       inode->i_vflags = vflags;
4399 +       jfs_get_inode_flags(JFS_IP(inode));
4400 +       inode->i_ctime = CURRENT_TIME_SEC;
4401 +       mark_inode_dirty(inode);
4402 +       return 0;
4403 +}
4404 +
4405  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4406  {
4407         struct inode *inode = filp->f_dentry->d_inode;
4408 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4409                 if (!S_ISDIR(inode->i_mode))
4410                         flags &= ~JFS_DIRSYNC_FL;
4411  
4412 +               if (IS_BARRIER(inode)) {
4413 +                       vxwprintk_task(1, "messing with the barrier.");
4414 +                       return -EACCES;
4415 +               }
4416 +
4417                 /* Is it quota file? Do not allow user to mess with it */
4418                 if (IS_NOQUOTA(inode)) {
4419                         err = -EPERM;
4420 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4421                  * the relevant capability.
4422                  */
4423                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4424 -                       ((flags ^ oldflags) &
4425 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4426 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4427 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4428                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4429                                 mutex_unlock(&inode->i_mutex);
4430                                 err = -EPERM;
4431 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4432                         }
4433                 }
4434  
4435 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4436 +               flags &= JFS_FL_USER_MODIFIABLE;
4437                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4438                 jfs_inode->mode2 = flags;
4439  
4440 diff -NurpP --minimal linux-2.6.35.4/fs/jfs/jfs_dinode.h linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/jfs_dinode.h
4441 --- linux-2.6.35.4/fs/jfs/jfs_dinode.h  2008-12-25 00:26:37.000000000 +0100
4442 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/jfs_dinode.h    2010-08-02 17:05:06.000000000 +0200
4443 @@ -161,9 +161,13 @@ struct dinode {
4444  
4445  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4446  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4447 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4448  
4449 -#define JFS_FL_USER_VISIBLE    0x03F80000
4450 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4451 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4452 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4453 +
4454 +#define JFS_FL_USER_VISIBLE    0x07F80000
4455 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4456  #define JFS_FL_INHERIT         0x03C80000
4457  
4458  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4459 diff -NurpP --minimal linux-2.6.35.4/fs/jfs/jfs_filsys.h linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/jfs_filsys.h
4460 --- linux-2.6.35.4/fs/jfs/jfs_filsys.h  2008-12-25 00:26:37.000000000 +0100
4461 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/jfs_filsys.h    2010-08-02 17:05:06.000000000 +0200
4462 @@ -263,6 +263,7 @@
4463  #define JFS_NAME_MAX   255
4464  #define JFS_PATH_MAX   BPSIZE
4465  
4466 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4467  
4468  /*
4469   *     file system state (superblock state)
4470 diff -NurpP --minimal linux-2.6.35.4/fs/jfs/jfs_imap.c linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/jfs_imap.c
4471 --- linux-2.6.35.4/fs/jfs/jfs_imap.c    2010-07-07 18:31:52.000000000 +0200
4472 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/jfs_imap.c      2010-08-02 17:05:06.000000000 +0200
4473 @@ -46,6 +46,7 @@
4474  #include <linux/pagemap.h>
4475  #include <linux/quotaops.h>
4476  #include <linux/slab.h>
4477 +#include <linux/vs_tag.h>
4478  
4479  #include "jfs_incore.h"
4480  #include "jfs_inode.h"
4481 @@ -3060,6 +3061,8 @@ static int copy_from_dinode(struct dinod
4482  {
4483         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4484         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4485 +       uid_t uid;
4486 +       gid_t gid;
4487  
4488         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4489         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4490 @@ -3080,14 +3083,18 @@ static int copy_from_dinode(struct dinod
4491         }
4492         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4493  
4494 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4495 +       uid = le32_to_cpu(dip->di_uid);
4496 +       gid = le32_to_cpu(dip->di_gid);
4497 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4498 +
4499 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4500         if (sbi->uid == -1)
4501                 ip->i_uid = jfs_ip->saved_uid;
4502         else {
4503                 ip->i_uid = sbi->uid;
4504         }
4505  
4506 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4507 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4508         if (sbi->gid == -1)
4509                 ip->i_gid = jfs_ip->saved_gid;
4510         else {
4511 @@ -3152,14 +3159,12 @@ static void copy_to_dinode(struct dinode
4512         dip->di_size = cpu_to_le64(ip->i_size);
4513         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4514         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4515 -       if (sbi->uid == -1)
4516 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4517 -       else
4518 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4519 -       if (sbi->gid == -1)
4520 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4521 -       else
4522 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4523 +
4524 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4525 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4526 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4527 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4528 +
4529         jfs_get_inode_flags(jfs_ip);
4530         /*
4531          * mode2 is only needed for storing the higher order bits.
4532 diff -NurpP --minimal linux-2.6.35.4/fs/jfs/jfs_inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/jfs_inode.c
4533 --- linux-2.6.35.4/fs/jfs/jfs_inode.c   2010-08-02 16:52:49.000000000 +0200
4534 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/jfs_inode.c     2010-08-02 17:05:06.000000000 +0200
4535 @@ -18,6 +18,7 @@
4536  
4537  #include <linux/fs.h>
4538  #include <linux/quotaops.h>
4539 +#include <linux/vs_tag.h>
4540  #include "jfs_incore.h"
4541  #include "jfs_inode.h"
4542  #include "jfs_filsys.h"
4543 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4544  {
4545         unsigned int flags = JFS_IP(inode)->mode2;
4546  
4547 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4548 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4549 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4550 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4551  
4552         if (flags & JFS_IMMUTABLE_FL)
4553                 inode->i_flags |= S_IMMUTABLE;
4554 +       if (flags & JFS_IXUNLINK_FL)
4555 +               inode->i_flags |= S_IXUNLINK;
4556 +
4557 +       if (flags & JFS_SYNC_FL)
4558 +               inode->i_flags |= S_SYNC;
4559         if (flags & JFS_APPEND_FL)
4560                 inode->i_flags |= S_APPEND;
4561         if (flags & JFS_NOATIME_FL)
4562                 inode->i_flags |= S_NOATIME;
4563         if (flags & JFS_DIRSYNC_FL)
4564                 inode->i_flags |= S_DIRSYNC;
4565 -       if (flags & JFS_SYNC_FL)
4566 -               inode->i_flags |= S_SYNC;
4567 +
4568 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4569 +
4570 +       if (flags & JFS_BARRIER_FL)
4571 +               inode->i_vflags |= V_BARRIER;
4572 +       if (flags & JFS_COW_FL)
4573 +               inode->i_vflags |= V_COW;
4574  }
4575  
4576  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4577  {
4578         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4579 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4580 +
4581 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4582 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4583 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4584 +                          JFS_BARRIER_FL | JFS_COW_FL);
4585  
4586 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4587 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4588         if (flags & S_IMMUTABLE)
4589                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4590 +       if (flags & S_IXUNLINK)
4591 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4592 +
4593         if (flags & S_APPEND)
4594                 jfs_ip->mode2 |= JFS_APPEND_FL;
4595         if (flags & S_NOATIME)
4596 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4597                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4598         if (flags & S_SYNC)
4599                 jfs_ip->mode2 |= JFS_SYNC_FL;
4600 +
4601 +       if (vflags & V_BARRIER)
4602 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4603 +       if (vflags & V_COW)
4604 +               jfs_ip->mode2 |= JFS_COW_FL;
4605  }
4606  
4607  /*
4608 diff -NurpP --minimal linux-2.6.35.4/fs/jfs/jfs_inode.h linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/jfs_inode.h
4609 --- linux-2.6.35.4/fs/jfs/jfs_inode.h   2010-08-02 16:52:49.000000000 +0200
4610 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/jfs_inode.h     2010-08-02 17:05:06.000000000 +0200
4611 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4612  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4613         int fh_len, int fh_type);
4614  extern void jfs_set_inode_flags(struct inode *);
4615 +extern int jfs_sync_flags(struct inode *, int, int);
4616  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4617  extern int jfs_setattr(struct dentry *, struct iattr *);
4618  
4619 diff -NurpP --minimal linux-2.6.35.4/fs/jfs/namei.c linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/namei.c
4620 --- linux-2.6.35.4/fs/jfs/namei.c       2010-07-07 18:31:52.000000000 +0200
4621 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/namei.c 2010-08-02 17:05:06.000000000 +0200
4622 @@ -21,6 +21,7 @@
4623  #include <linux/ctype.h>
4624  #include <linux/quotaops.h>
4625  #include <linux/exportfs.h>
4626 +#include <linux/vs_tag.h>
4627  #include "jfs_incore.h"
4628  #include "jfs_superblock.h"
4629  #include "jfs_inode.h"
4630 @@ -1491,6 +1492,7 @@ static struct dentry *jfs_lookup(struct 
4631                 return ERR_CAST(ip);
4632         }
4633  
4634 +       dx_propagate_tag(nd, ip);
4635         dentry = d_splice_alias(ip, dentry);
4636  
4637         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4638 @@ -1560,6 +1562,7 @@ const struct inode_operations jfs_dir_in
4639  #ifdef CONFIG_JFS_POSIX_ACL
4640         .check_acl      = jfs_check_acl,
4641  #endif
4642 +       .sync_flags     = jfs_sync_flags,
4643  };
4644  
4645  const struct file_operations jfs_dir_operations = {
4646 diff -NurpP --minimal linux-2.6.35.4/fs/jfs/super.c linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/super.c
4647 --- linux-2.6.35.4/fs/jfs/super.c       2010-08-02 16:52:49.000000000 +0200
4648 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/jfs/super.c 2010-08-02 17:05:06.000000000 +0200
4649 @@ -200,7 +200,8 @@ static void jfs_put_super(struct super_b
4650  enum {
4651         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4652         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4653 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4654 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4655 +       Opt_tag, Opt_notag, Opt_tagid
4656  };
4657  
4658  static const match_table_t tokens = {
4659 @@ -210,6 +211,10 @@ static const match_table_t tokens = {
4660         {Opt_resize, "resize=%u"},
4661         {Opt_resize_nosize, "resize"},
4662         {Opt_errors, "errors=%s"},
4663 +       {Opt_tag, "tag"},
4664 +       {Opt_notag, "notag"},
4665 +       {Opt_tagid, "tagid=%u"},
4666 +       {Opt_tag, "tagxid"},
4667         {Opt_ignore, "noquota"},
4668         {Opt_ignore, "quota"},
4669         {Opt_usrquota, "usrquota"},
4670 @@ -344,6 +349,20 @@ static int parse_options(char *options, 
4671                         }
4672                         break;
4673                 }
4674 +#ifndef CONFIG_TAGGING_NONE
4675 +               case Opt_tag:
4676 +                       *flag |= JFS_TAGGED;
4677 +                       break;
4678 +               case Opt_notag:
4679 +                       *flag &= JFS_TAGGED;
4680 +                       break;
4681 +#endif
4682 +#ifdef CONFIG_PROPAGATE
4683 +               case Opt_tagid:
4684 +                       /* use args[0] */
4685 +                       *flag |= JFS_TAGGED;
4686 +                       break;
4687 +#endif
4688                 default:
4689                         printk("jfs: Unrecognized mount option \"%s\" "
4690                                         " or missing value\n", p);
4691 @@ -374,6 +393,12 @@ static int jfs_remount(struct super_bloc
4692         if (!parse_options(data, sb, &newLVSize, &flag)) {
4693                 return -EINVAL;
4694         }
4695 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4696 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4697 +                       sb->s_id);
4698 +               return -EINVAL;
4699 +       }
4700 +
4701         lock_kernel();
4702         if (newLVSize) {
4703                 if (sb->s_flags & MS_RDONLY) {
4704 @@ -465,6 +490,9 @@ static int jfs_fill_super(struct super_b
4705  #ifdef CONFIG_JFS_POSIX_ACL
4706         sb->s_flags |= MS_POSIXACL;
4707  #endif
4708 +       /* map mount option tagxid */
4709 +       if (sbi->flag & JFS_TAGGED)
4710 +               sb->s_flags |= MS_TAGGED;
4711  
4712         if (newLVSize) {
4713                 printk(KERN_ERR "resize option for remount only\n");
4714 diff -NurpP --minimal linux-2.6.35.4/fs/libfs.c linux-2.6.35.4-vs2.3.0.36.32/fs/libfs.c
4715 --- linux-2.6.35.4/fs/libfs.c   2010-08-02 16:52:49.000000000 +0200
4716 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/libfs.c     2010-08-02 17:05:06.000000000 +0200
4717 @@ -124,7 +124,8 @@ static inline unsigned char dt_type(stru
4718   * both impossible due to the lock on directory.
4719   */
4720  
4721 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4722 +static inline int do_dcache_readdir_filter(struct file *filp,
4723 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4724  {
4725         struct dentry *dentry = filp->f_path.dentry;
4726         struct dentry *cursor = filp->private_data;
4727 @@ -157,6 +158,8 @@ int dcache_readdir(struct file * filp, v
4728                                 next = list_entry(p, struct dentry, d_u.d_child);
4729                                 if (d_unhashed(next) || !next->d_inode)
4730                                         continue;
4731 +                               if (filter && !filter(next))
4732 +                                       continue;
4733  
4734                                 spin_unlock(&dcache_lock);
4735                                 if (filldir(dirent, next->d_name.name, 
4736 @@ -175,6 +178,18 @@ int dcache_readdir(struct file * filp, v
4737         return 0;
4738  }
4739  
4740 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4741 +{
4742 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4743 +}
4744 +
4745 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4746 +       int (*filter)(struct dentry *))
4747 +{
4748 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4749 +}
4750 +
4751 +
4752  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4753  {
4754         return -EISDIR;
4755 @@ -967,6 +982,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4756  EXPORT_SYMBOL(dcache_dir_lseek);
4757  EXPORT_SYMBOL(dcache_dir_open);
4758  EXPORT_SYMBOL(dcache_readdir);
4759 +EXPORT_SYMBOL(dcache_readdir_filter);
4760  EXPORT_SYMBOL(generic_read_dir);
4761  EXPORT_SYMBOL(get_sb_pseudo);
4762  EXPORT_SYMBOL(simple_write_begin);
4763 diff -NurpP --minimal linux-2.6.35.4/fs/locks.c linux-2.6.35.4-vs2.3.0.36.32/fs/locks.c
4764 --- linux-2.6.35.4/fs/locks.c   2010-07-07 18:31:52.000000000 +0200
4765 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/locks.c     2010-08-02 17:05:06.000000000 +0200
4766 @@ -127,6 +127,8 @@
4767  #include <linux/time.h>
4768  #include <linux/rcupdate.h>
4769  #include <linux/pid_namespace.h>
4770 +#include <linux/vs_base.h>
4771 +#include <linux/vs_limit.h>
4772  
4773  #include <asm/uaccess.h>
4774  
4775 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4776  /* Allocate an empty lock structure. */
4777  static struct file_lock *locks_alloc_lock(void)
4778  {
4779 +       if (!vx_locks_avail(1))
4780 +               return NULL;
4781         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4782  }
4783  
4784 @@ -174,6 +178,7 @@ static void locks_free_lock(struct file_
4785         BUG_ON(!list_empty(&fl->fl_block));
4786         BUG_ON(!list_empty(&fl->fl_link));
4787  
4788 +       vx_locks_dec(fl);
4789         locks_release_private(fl);
4790         kmem_cache_free(filelock_cache, fl);
4791  }
4792 @@ -194,6 +199,7 @@ void locks_init_lock(struct file_lock *f
4793         fl->fl_start = fl->fl_end = 0;
4794         fl->fl_ops = NULL;
4795         fl->fl_lmops = NULL;
4796 +       fl->fl_xid = -1;
4797  }
4798  
4799  EXPORT_SYMBOL(locks_init_lock);
4800 @@ -248,6 +254,7 @@ void locks_copy_lock(struct file_lock *n
4801         new->fl_file = fl->fl_file;
4802         new->fl_ops = fl->fl_ops;
4803         new->fl_lmops = fl->fl_lmops;
4804 +       new->fl_xid = fl->fl_xid;
4805  
4806         locks_copy_private(new, fl);
4807  }
4808 @@ -286,6 +293,11 @@ static int flock_make_lock(struct file *
4809         fl->fl_flags = FL_FLOCK;
4810         fl->fl_type = type;
4811         fl->fl_end = OFFSET_MAX;
4812 +
4813 +       vxd_assert(filp->f_xid == vx_current_xid(),
4814 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4815 +       fl->fl_xid = filp->f_xid;
4816 +       vx_locks_inc(fl);
4817         
4818         *lock = fl;
4819         return 0;
4820 @@ -451,6 +463,7 @@ static int lease_init(struct file *filp,
4821  
4822         fl->fl_owner = current->files;
4823         fl->fl_pid = current->tgid;
4824 +       fl->fl_xid = vx_current_xid();
4825  
4826         fl->fl_file = filp;
4827         fl->fl_flags = FL_LEASE;
4828 @@ -470,6 +483,11 @@ static struct file_lock *lease_alloc(str
4829         if (fl == NULL)
4830                 return ERR_PTR(error);
4831  
4832 +       fl->fl_xid = vx_current_xid();
4833 +       if (filp)
4834 +               vxd_assert(filp->f_xid == fl->fl_xid,
4835 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4836 +       vx_locks_inc(fl);
4837         error = lease_init(filp, type, fl);
4838         if (error) {
4839                 locks_free_lock(fl);
4840 @@ -770,6 +788,7 @@ static int flock_lock_file(struct file *
4841         if (found)
4842                 cond_resched();
4843  
4844 +       new_fl->fl_xid = -1;
4845  find_conflict:
4846         for_each_lock(inode, before) {
4847                 struct file_lock *fl = *before;
4848 @@ -790,6 +809,7 @@ find_conflict:
4849                 goto out;
4850         locks_copy_lock(new_fl, request);
4851         locks_insert_lock(before, new_fl);
4852 +       vx_locks_inc(new_fl);
4853         new_fl = NULL;
4854         error = 0;
4855  
4856 @@ -800,7 +820,8 @@ out:
4857         return error;
4858  }
4859  
4860 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4861 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4862 +       struct file_lock *conflock, xid_t xid)
4863  {
4864         struct file_lock *fl;
4865         struct file_lock *new_fl = NULL;
4866 @@ -810,6 +831,8 @@ static int __posix_lock_file(struct inod
4867         struct file_lock **before;
4868         int error, added = 0;
4869  
4870 +       vxd_assert(xid == vx_current_xid(),
4871 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4872         /*
4873          * We may need two file_lock structures for this operation,
4874          * so we get them in advance to avoid races.
4875 @@ -820,7 +843,11 @@ static int __posix_lock_file(struct inod
4876             (request->fl_type != F_UNLCK ||
4877              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4878                 new_fl = locks_alloc_lock();
4879 +               new_fl->fl_xid = xid;
4880 +               vx_locks_inc(new_fl);
4881                 new_fl2 = locks_alloc_lock();
4882 +               new_fl2->fl_xid = xid;
4883 +               vx_locks_inc(new_fl2);
4884         }
4885  
4886         lock_kernel();
4887 @@ -1019,7 +1046,8 @@ static int __posix_lock_file(struct inod
4888  int posix_lock_file(struct file *filp, struct file_lock *fl,
4889                         struct file_lock *conflock)
4890  {
4891 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4892 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4893 +               fl, conflock, filp->f_xid);
4894  }
4895  EXPORT_SYMBOL(posix_lock_file);
4896  
4897 @@ -1109,7 +1137,7 @@ int locks_mandatory_area(int read_write,
4898         fl.fl_end = offset + count - 1;
4899  
4900         for (;;) {
4901 -               error = __posix_lock_file(inode, &fl, NULL);
4902 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4903                 if (error != FILE_LOCK_DEFERRED)
4904                         break;
4905                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4906 @@ -1425,6 +1453,7 @@ int generic_setlease(struct file *filp, 
4907  
4908         locks_copy_lock(new_fl, lease);
4909         locks_insert_lock(before, new_fl);
4910 +       vx_locks_inc(new_fl);
4911  
4912         *flp = new_fl;
4913         return 0;
4914 @@ -1780,6 +1809,11 @@ int fcntl_setlk(unsigned int fd, struct 
4915         if (file_lock == NULL)
4916                 return -ENOLCK;
4917  
4918 +       vxd_assert(filp->f_xid == vx_current_xid(),
4919 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4920 +       file_lock->fl_xid = filp->f_xid;
4921 +       vx_locks_inc(file_lock);
4922 +
4923         /*
4924          * This might block, so we do it before checking the inode.
4925          */
4926 @@ -1898,6 +1932,11 @@ int fcntl_setlk64(unsigned int fd, struc
4927         if (file_lock == NULL)
4928                 return -ENOLCK;
4929  
4930 +       vxd_assert(filp->f_xid == vx_current_xid(),
4931 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4932 +       file_lock->fl_xid = filp->f_xid;
4933 +       vx_locks_inc(file_lock);
4934 +
4935         /*
4936          * This might block, so we do it before checking the inode.
4937          */
4938 @@ -2163,8 +2202,11 @@ static int locks_show(struct seq_file *f
4939  
4940         lock_get_status(f, fl, (long)f->private, "");
4941  
4942 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4943 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4944 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4945 +                       continue;
4946                 lock_get_status(f, bfl, (long)f->private, " ->");
4947 +       }
4948  
4949         f->private++;
4950         return 0;
4951 diff -NurpP --minimal linux-2.6.35.4/fs/namei.c linux-2.6.35.4-vs2.3.0.36.32/fs/namei.c
4952 --- linux-2.6.35.4/fs/namei.c   2010-08-02 16:52:50.000000000 +0200
4953 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/namei.c     2010-08-14 17:03:20.000000000 +0200
4954 @@ -32,6 +32,14 @@
4955  #include <linux/fcntl.h>
4956  #include <linux/device_cgroup.h>
4957  #include <linux/fs_struct.h>
4958 +#include <linux/proc_fs.h>
4959 +#include <linux/vserver/inode.h>
4960 +#include <linux/vs_base.h>
4961 +#include <linux/vs_tag.h>
4962 +#include <linux/vs_cowbl.h>
4963 +#include <linux/vs_device.h>
4964 +#include <linux/vs_context.h>
4965 +#include <linux/pid_namespace.h>
4966  #include <asm/uaccess.h>
4967  
4968  #include "internal.h"
4969 @@ -166,6 +174,77 @@ void putname(const char *name)
4970  EXPORT_SYMBOL(putname);
4971  #endif
4972  
4973 +static inline int dx_barrier(const struct inode *inode)
4974 +{
4975 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4976 +               vxwprintk_task(1, "did hit the barrier.");
4977 +               return 1;
4978 +       }
4979 +       return 0;
4980 +}
4981 +
4982 +static int __dx_permission(const struct inode *inode, int mask)
4983 +{
4984 +       if (dx_barrier(inode))
4985 +               return -EACCES;
4986 +
4987 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4988 +               /* devpts is xid tagged */
4989 +               if (S_ISDIR(inode->i_mode) ||
4990 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4991 +                       return 0;
4992 +       }
4993 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4994 +               struct proc_dir_entry *de = PDE(inode);
4995 +
4996 +               if (de && !vx_hide_check(0, de->vx_flags))
4997 +                       goto out;
4998 +
4999 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
5000 +                       struct pid *pid;
5001 +                       struct task_struct *tsk;
5002 +
5003 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
5004 +                           vx_flags(VXF_STATE_SETUP, 0))
5005 +                               return 0;
5006 +
5007 +                       pid = PROC_I(inode)->pid;
5008 +                       if (!pid)
5009 +                               goto out;
5010 +
5011 +                       tsk = pid_task(pid, PIDTYPE_PID);
5012 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
5013 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
5014 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
5015 +                               return 0;
5016 +               }
5017 +               else {
5018 +                       /* FIXME: Should we block some entries here? */
5019 +                       return 0;
5020 +               }
5021 +       }
5022 +       else {
5023 +               if (dx_notagcheck(inode->i_sb) ||
5024 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
5025 +                            DX_IDENT))
5026 +                       return 0;
5027 +       }
5028 +
5029 +out:
5030 +       return -EACCES;
5031 +}
5032 +
5033 +int dx_permission(const struct inode *inode, int mask)
5034 +{
5035 +       int ret = __dx_permission(inode, mask);
5036 +       if (unlikely(ret)) {
5037 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
5038 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
5039 +                       inode->i_ino);
5040 +       }
5041 +       return ret;
5042 +}
5043 +
5044  /*
5045   * This does basic POSIX ACL permission checking
5046   */
5047 @@ -266,10 +345,14 @@ int inode_permission(struct inode *inode
5048                 /*
5049                  * Nobody gets write access to an immutable file.
5050                  */
5051 -               if (IS_IMMUTABLE(inode))
5052 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5053                         return -EACCES;
5054         }
5055  
5056 +       retval = dx_permission(inode, mask);
5057 +       if (retval)
5058 +               return retval;
5059 +
5060         if (inode->i_op->permission)
5061                 retval = inode->i_op->permission(inode, mask);
5062         else
5063 @@ -464,6 +547,9 @@ static int exec_permission(struct inode 
5064  {
5065         int ret;
5066  
5067 +       if (dx_barrier(inode))
5068 +               return -EACCES;
5069 +
5070         if (inode->i_op->permission) {
5071                 ret = inode->i_op->permission(inode, MAY_EXEC);
5072                 if (!ret)
5073 @@ -677,7 +763,8 @@ static __always_inline void follow_dotdo
5074  
5075                 if (nd->path.dentry == nd->root.dentry &&
5076                     nd->path.mnt == nd->root.mnt) {
5077 -                       break;
5078 +                       /* for sane '/' avoid follow_mount() */
5079 +                       return;
5080                 }
5081                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5082                         /* rare case of legitimate dget_parent()... */
5083 @@ -701,7 +788,7 @@ static int do_lookup(struct nameidata *n
5084  {
5085         struct vfsmount *mnt = nd->path.mnt;
5086         struct dentry *dentry, *parent;
5087 -       struct inode *dir;
5088 +       struct inode *dir, *inode;
5089         /*
5090          * See if the low-level filesystem might want
5091          * to use its own hash..
5092 @@ -717,12 +804,26 @@ static int do_lookup(struct nameidata *n
5093                 goto need_lookup;
5094         if (dentry->d_op && dentry->d_op->d_revalidate)
5095                 goto need_revalidate;
5096 +
5097 +       inode = dentry->d_inode;
5098 +       if (!inode)
5099 +               goto done;
5100 +
5101 +       if (__dx_permission(inode, MAY_ACCESS))
5102 +               goto hidden;
5103  done:
5104         path->mnt = mnt;
5105         path->dentry = dentry;
5106         __follow_mount(path);
5107         return 0;
5108  
5109 +hidden:
5110 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s/%.*s«.",
5111 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5112 +               vxd_path(&nd->path), name->len, name->name);
5113 +       dput(dentry);
5114 +       return -ENOENT;
5115 +
5116  need_lookup:
5117         parent = nd->path.dentry;
5118         dir = parent->d_inode;
5119 @@ -1326,7 +1427,7 @@ static int may_delete(struct inode *dir,
5120         if (IS_APPEND(dir))
5121                 return -EPERM;
5122         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5123 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5124 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5125                 return -EPERM;
5126         if (isdir) {
5127                 if (!S_ISDIR(victim->d_inode->i_mode))
5128 @@ -1449,6 +1550,14 @@ int may_open(struct path *path, int acc_
5129                 break;
5130         }
5131  
5132 +#ifdef CONFIG_VSERVER_COWBL
5133 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5134 +               if (IS_COW_LINK(inode))
5135 +                       return -EMLINK;
5136 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5137 +               mark_inode_dirty(inode);
5138 +       }
5139 +#endif
5140         error = inode_permission(inode, acc_mode);
5141         if (error)
5142                 return error;
5143 @@ -1558,7 +1667,8 @@ static int open_will_truncate(int flag, 
5144  }
5145  
5146  static struct file *finish_open(struct nameidata *nd,
5147 -                               int open_flag, int acc_mode)
5148 +                               int open_flag, int acc_mode,
5149 +                               const char *pathname)
5150  {
5151         struct file *filp;
5152         int will_truncate;
5153 @@ -1571,6 +1681,23 @@ static struct file *finish_open(struct n
5154                         goto exit;
5155         }
5156         error = may_open(&nd->path, acc_mode, open_flag);
5157 +#ifdef CONFIG_VSERVER_COWBL
5158 +       if (error == -EMLINK) {
5159 +               struct dentry *dentry;
5160 +               dentry = cow_break_link(pathname);
5161 +               if (IS_ERR(dentry)) {
5162 +                       error = PTR_ERR(dentry);
5163 +                       goto exit_cow;
5164 +               }
5165 +               dput(dentry);
5166 +               if (will_truncate)
5167 +                       mnt_drop_write(nd->path.mnt);
5168 +               release_open_intent(nd);
5169 +               path_put(&nd->path);
5170 +               return ERR_PTR(-EMLINK);
5171 +       }
5172 +exit_cow:
5173 +#endif
5174         if (error) {
5175                 if (will_truncate)
5176                         mnt_drop_write(nd->path.mnt);
5177 @@ -1739,7 +1866,7 @@ static struct file *do_last(struct namei
5178         if (S_ISDIR(path->dentry->d_inode->i_mode))
5179                 goto exit;
5180  ok:
5181 -       filp = finish_open(nd, open_flag, acc_mode);
5182 +       filp = finish_open(nd, open_flag, acc_mode, pathname);
5183         return filp;
5184  
5185  exit_mutex_unlock:
5186 @@ -1768,7 +1895,11 @@ struct file *do_filp_open(int dfd, const
5187         int count = 0;
5188         int flag = open_to_namei_flags(open_flag);
5189         int force_reval = 0;
5190 -
5191 +#ifdef CONFIG_VSERVER_COWBL
5192 +       int rflag = flag;
5193 +       int rmode = mode;
5194 +restart:
5195 +#endif
5196         if (!(open_flag & O_CREAT))
5197                 mode = 0;
5198  
5199 @@ -1834,6 +1965,13 @@ reval:
5200         if (!(open_flag & O_NOFOLLOW))
5201                 nd.flags |= LOOKUP_FOLLOW;
5202         filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5203 +#ifdef CONFIG_VSERVER_COWBL
5204 +       if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5205 +               flag = rflag;
5206 +               mode = rmode;
5207 +               goto restart;
5208 +       }
5209 +#endif
5210         while (unlikely(!filp)) { /* trailing symlink */
5211                 struct path holder;
5212                 struct inode *inode = path.dentry->d_inode;
5213 @@ -1872,6 +2010,13 @@ reval:
5214                 holder = path;
5215                 nd.flags &= ~LOOKUP_PARENT;
5216                 filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5217 +#ifdef CONFIG_VSERVER_COWBL
5218 +               if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5219 +                       flag = rflag;
5220 +                       mode = rmode;
5221 +                       goto restart;
5222 +               }
5223 +#endif
5224                 if (inode->i_op->put_link)
5225                         inode->i_op->put_link(holder.dentry, &nd, cookie);
5226                 path_put(&holder);
5227 @@ -1972,9 +2117,17 @@ int vfs_mknod(struct inode *dir, struct 
5228         if (error)
5229                 return error;
5230  
5231 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5232 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5233 +               goto okay;
5234 +
5235 +       if (!capable(CAP_MKNOD))
5236                 return -EPERM;
5237  
5238 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5239 +               return -EPERM;
5240 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5241 +               return -EPERM;
5242 +okay:
5243         if (!dir->i_op->mknod)
5244                 return -EPERM;
5245  
5246 @@ -2439,7 +2592,7 @@ int vfs_link(struct dentry *old_dentry, 
5247         /*
5248          * A link to an append-only or immutable file cannot be created.
5249          */
5250 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5251 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5252                 return -EPERM;
5253         if (!dir->i_op->link)
5254                 return -EPERM;
5255 @@ -2811,6 +2964,219 @@ int vfs_follow_link(struct nameidata *nd
5256         return __vfs_follow_link(nd, link);
5257  }
5258  
5259 +
5260 +#ifdef CONFIG_VSERVER_COWBL
5261 +
5262 +#include <linux/file.h>
5263 +
5264 +static inline
5265 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5266 +{
5267 +       loff_t ppos = 0;
5268 +
5269 +       return do_splice_direct(in, &ppos, out, len, 0);
5270 +}
5271 +
5272 +struct dentry *cow_break_link(const char *pathname)
5273 +{
5274 +       int ret, mode, pathlen, redo = 0;
5275 +       struct nameidata old_nd, dir_nd;
5276 +       struct path old_path, new_path;
5277 +       struct dentry *dir, *res = NULL;
5278 +       struct file *old_file;
5279 +       struct file *new_file;
5280 +       char *to, *path, pad='\251';
5281 +       loff_t size;
5282 +
5283 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5284 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5285 +       ret = -ENOMEM;
5286 +       if (!path)
5287 +               goto out;
5288 +
5289 +       /* old_nd will have refs to dentry and mnt */
5290 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5291 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5292 +       if (ret < 0)
5293 +               goto out_free_path;
5294 +
5295 +       old_path = old_nd.path;
5296 +       mode = old_path.dentry->d_inode->i_mode;
5297 +
5298 +       to = d_path(&old_path, path, PATH_MAX-2);
5299 +       pathlen = strlen(to);
5300 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5301 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5302 +               old_path.dentry->d_name.len);
5303 +
5304 +       to[pathlen + 1] = 0;
5305 +retry:
5306 +       to[pathlen] = pad--;
5307 +       ret = -EMLINK;
5308 +       if (pad <= '\240')
5309 +               goto out_rel_old;
5310 +
5311 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5312 +       /* dir_nd will have refs to dentry and mnt */
5313 +       ret = path_lookup(to,
5314 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5315 +       vxdprintk(VXD_CBIT(misc, 2),
5316 +               "path_lookup(new): %d", ret);
5317 +       if (ret < 0)
5318 +               goto retry;
5319 +
5320 +       /* this puppy downs the inode mutex */
5321 +       new_path.dentry = lookup_create(&dir_nd, 0);
5322 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5323 +               vxdprintk(VXD_CBIT(misc, 2),
5324 +                       "lookup_create(new): %p", new_path.dentry);
5325 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5326 +               path_put(&dir_nd.path);
5327 +               goto retry;
5328 +       }
5329 +       vxdprintk(VXD_CBIT(misc, 2),
5330 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5331 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5332 +               new_path.dentry->d_name.len);
5333 +       dir = dir_nd.path.dentry;
5334 +
5335 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5336 +       vxdprintk(VXD_CBIT(misc, 2),
5337 +               "vfs_create(new): %d", ret);
5338 +       if (ret == -EEXIST) {
5339 +               mutex_unlock(&dir->d_inode->i_mutex);
5340 +               dput(new_path.dentry);
5341 +               path_put(&dir_nd.path);
5342 +               goto retry;
5343 +       }
5344 +       else if (ret < 0)
5345 +               goto out_unlock_new;
5346 +
5347 +       /* drop out early, ret passes ENOENT */
5348 +       ret = -ENOENT;
5349 +       if ((redo = d_unhashed(old_path.dentry)))
5350 +               goto out_unlock_new;
5351 +
5352 +       new_path.mnt = dir_nd.path.mnt;
5353 +       dget(old_path.dentry);
5354 +       mntget(old_path.mnt);
5355 +       /* this one cleans up the dentry/mnt in case of failure */
5356 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5357 +               O_RDONLY, current_cred());
5358 +       vxdprintk(VXD_CBIT(misc, 2),
5359 +               "dentry_open(old): %p", old_file);
5360 +       if (!old_file || IS_ERR(old_file)) {
5361 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5362 +               goto out_unlock_new;
5363 +       }
5364 +
5365 +       dget(new_path.dentry);
5366 +       mntget(new_path.mnt);
5367 +       /* this one cleans up the dentry/mnt in case of failure */
5368 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5369 +               O_WRONLY, current_cred());
5370 +       vxdprintk(VXD_CBIT(misc, 2),
5371 +               "dentry_open(new): %p", new_file);
5372 +
5373 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5374 +       if (!new_file || IS_ERR(new_file))
5375 +               goto out_fput_old;
5376 +
5377 +       size = i_size_read(old_file->f_dentry->d_inode);
5378 +       ret = do_cow_splice(old_file, new_file, size);
5379 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5380 +       if (ret < 0) {
5381 +               goto out_fput_both;
5382 +       } else if (ret < size) {
5383 +               ret = -ENOSPC;
5384 +               goto out_fput_both;
5385 +       } else {
5386 +               struct inode *old_inode = old_path.dentry->d_inode;
5387 +               struct inode *new_inode = new_path.dentry->d_inode;
5388 +               struct iattr attr = {
5389 +                       .ia_uid = old_inode->i_uid,
5390 +                       .ia_gid = old_inode->i_gid,
5391 +                       .ia_valid = ATTR_UID | ATTR_GID
5392 +                       };
5393 +
5394 +               ret = inode_setattr(new_inode, &attr);
5395 +               if (ret)
5396 +                       goto out_fput_both;
5397 +       }
5398 +
5399 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5400 +
5401 +       /* drop out late */
5402 +       ret = -ENOENT;
5403 +       if ((redo = d_unhashed(old_path.dentry)))
5404 +               goto out_unlock;
5405 +
5406 +       vxdprintk(VXD_CBIT(misc, 2),
5407 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5408 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5409 +               new_path.dentry->d_name.len,
5410 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5411 +               old_path.dentry->d_name.len);
5412 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5413 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5414 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5415 +       res = new_path.dentry;
5416 +
5417 +out_unlock:
5418 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5419 +
5420 +out_fput_both:
5421 +       vxdprintk(VXD_CBIT(misc, 3),
5422 +               "fput(new_file=%p[#%ld])", new_file,
5423 +               atomic_long_read(&new_file->f_count));
5424 +       fput(new_file);
5425 +
5426 +out_fput_old:
5427 +       vxdprintk(VXD_CBIT(misc, 3),
5428 +               "fput(old_file=%p[#%ld])", old_file,
5429 +               atomic_long_read(&old_file->f_count));
5430 +       fput(old_file);
5431 +
5432 +out_unlock_new:
5433 +       mutex_unlock(&dir->d_inode->i_mutex);
5434 +       if (!ret)
5435 +               goto out_redo;
5436 +
5437 +       /* error path cleanup */
5438 +       vfs_unlink(dir->d_inode, new_path.dentry);
5439 +       dput(new_path.dentry);
5440 +
5441 +out_redo:
5442 +       if (!redo)
5443 +               goto out_rel_both;
5444 +       /* lookup dentry once again */
5445 +       path_put(&old_nd.path);
5446 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5447 +       if (ret)
5448 +               goto out_rel_both;
5449 +
5450 +       new_path.dentry = old_nd.path.dentry;
5451 +       vxdprintk(VXD_CBIT(misc, 2),
5452 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5453 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5454 +               new_path.dentry->d_name.len);
5455 +       dget(new_path.dentry);
5456 +       res = new_path.dentry;
5457 +
5458 +out_rel_both:
5459 +       path_put(&dir_nd.path);
5460 +out_rel_old:
5461 +       path_put(&old_nd.path);
5462 +out_free_path:
5463 +       kfree(path);
5464 +out:
5465 +       if (ret)
5466 +               res = ERR_PTR(ret);
5467 +       return res;
5468 +}
5469 +
5470 +#endif
5471 +
5472  /* get the link contents into pagecache */
5473  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5474  {
5475 diff -NurpP --minimal linux-2.6.35.4/fs/namespace.c linux-2.6.35.4-vs2.3.0.36.32/fs/namespace.c
5476 --- linux-2.6.35.4/fs/namespace.c       2010-09-05 01:41:57.000000000 +0200
5477 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/namespace.c 2010-08-14 18:21:13.000000000 +0200
5478 @@ -29,6 +29,11 @@
5479  #include <linux/log2.h>
5480  #include <linux/idr.h>
5481  #include <linux/fs_struct.h>
5482 +#include <linux/vs_base.h>
5483 +#include <linux/vs_context.h>
5484 +#include <linux/vs_tag.h>
5485 +#include <linux/vserver/space.h>
5486 +#include <linux/vserver/global.h>
5487  #include <asm/uaccess.h>
5488  #include <asm/unistd.h>
5489  #include "pnode.h"
5490 @@ -567,6 +572,7 @@ static struct vfsmount *clone_mnt(struct
5491                 mnt->mnt_root = dget(root);
5492                 mnt->mnt_mountpoint = mnt->mnt_root;
5493                 mnt->mnt_parent = mnt;
5494 +               mnt->mnt_tag = old->mnt_tag;
5495  
5496                 if (flag & CL_SLAVE) {
5497                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5498 @@ -660,6 +666,31 @@ static inline void mangle(struct seq_fil
5499         seq_escape(m, s, " \t\n\\");
5500  }
5501  
5502 +static int mnt_is_reachable(struct vfsmount *mnt)
5503 +{
5504 +       struct path root;
5505 +       struct dentry *point;
5506 +       int ret;
5507 +
5508 +       if (mnt == mnt->mnt_ns->root)
5509 +               return 1;
5510 +
5511 +       spin_lock(&vfsmount_lock);
5512 +       root = current->fs->root;
5513 +       point = root.dentry;
5514 +
5515 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5516 +               point = mnt->mnt_mountpoint;
5517 +               mnt = mnt->mnt_parent;
5518 +       }
5519 +
5520 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5521 +
5522 +       spin_unlock(&vfsmount_lock);
5523 +
5524 +       return ret;
5525 +}
5526 +
5527  /*
5528   * Simple .show_options callback for filesystems which don't want to
5529   * implement more complex mount option showing.
5530 @@ -762,6 +793,8 @@ static int show_sb_opts(struct seq_file 
5531                 { MS_SYNCHRONOUS, ",sync" },
5532                 { MS_DIRSYNC, ",dirsync" },
5533                 { MS_MANDLOCK, ",mand" },
5534 +               { MS_TAGGED, ",tag" },
5535 +               { MS_NOTAGCHECK, ",notagcheck" },
5536                 { 0, NULL }
5537         };
5538         const struct proc_fs_info *fs_infop;
5539 @@ -809,10 +842,20 @@ static int show_vfsmnt(struct seq_file *
5540         int err = 0;
5541         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5542  
5543 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5544 -       seq_putc(m, ' ');
5545 -       seq_path(m, &mnt_path, " \t\n\\");
5546 -       seq_putc(m, ' ');
5547 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5548 +               return SEQ_SKIP;
5549 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5550 +               return SEQ_SKIP;
5551 +
5552 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5553 +               mnt == current->fs->root.mnt) {
5554 +               seq_puts(m, "/dev/root / ");
5555 +       } else {
5556 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5557 +               seq_putc(m, ' ');
5558 +               seq_path(m, &mnt_path, " \t\n\\");
5559 +               seq_putc(m, ' ');
5560 +       }
5561         show_type(m, mnt->mnt_sb);
5562         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5563         err = show_sb_opts(m, mnt->mnt_sb);
5564 @@ -842,6 +885,11 @@ static int show_mountinfo(struct seq_fil
5565         struct path root = p->root;
5566         int err = 0;
5567  
5568 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5569 +               return SEQ_SKIP;
5570 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5571 +               return SEQ_SKIP;
5572 +
5573         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5574                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5575         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5576 @@ -900,17 +948,27 @@ static int show_vfsstat(struct seq_file 
5577         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5578         int err = 0;
5579  
5580 -       /* device */
5581 -       if (mnt->mnt_devname) {
5582 -               seq_puts(m, "device ");
5583 -               mangle(m, mnt->mnt_devname);
5584 -       } else
5585 -               seq_puts(m, "no device");
5586 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5587 +               return SEQ_SKIP;
5588 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5589 +               return SEQ_SKIP;
5590  
5591 -       /* mount point */
5592 -       seq_puts(m, " mounted on ");
5593 -       seq_path(m, &mnt_path, " \t\n\\");
5594 -       seq_putc(m, ' ');
5595 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5596 +               mnt == current->fs->root.mnt) {
5597 +               seq_puts(m, "device /dev/root mounted on / ");
5598 +       } else {
5599 +               /* device */
5600 +               if (mnt->mnt_devname) {
5601 +                       seq_puts(m, "device ");
5602 +                       mangle(m, mnt->mnt_devname);
5603 +               } else
5604 +                       seq_puts(m, "no device");
5605 +
5606 +               /* mount point */
5607 +               seq_puts(m, " mounted on ");
5608 +               seq_path(m, &mnt_path, " \t\n\\");
5609 +               seq_putc(m, ' ');
5610 +       }
5611  
5612         /* file system type */
5613         seq_puts(m, "with fstype ");
5614 @@ -1151,7 +1209,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5615                 goto dput_and_out;
5616  
5617         retval = -EPERM;
5618 -       if (!capable(CAP_SYS_ADMIN))
5619 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5620                 goto dput_and_out;
5621  
5622         retval = do_umount(path.mnt, flags);
5623 @@ -1177,7 +1235,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5624  
5625  static int mount_is_safe(struct path *path)
5626  {
5627 -       if (capable(CAP_SYS_ADMIN))
5628 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5629                 return 0;
5630         return -EPERM;
5631  #ifdef notyet
5632 @@ -1449,7 +1507,7 @@ static int do_change_type(struct path *p
5633         int type = flag & ~MS_REC;
5634         int err = 0;
5635  
5636 -       if (!capable(CAP_SYS_ADMIN))
5637 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5638                 return -EPERM;
5639  
5640         if (path->dentry != path->mnt->mnt_root)
5641 @@ -1476,11 +1534,13 @@ static int do_change_type(struct path *p
5642   * do loopback mount.
5643   */
5644  static int do_loopback(struct path *path, char *old_name,
5645 -                               int recurse)
5646 +       tag_t tag, unsigned long flags, int mnt_flags)
5647  {
5648         struct path old_path;
5649         struct vfsmount *mnt = NULL;
5650         int err = mount_is_safe(path);
5651 +       int recurse = flags & MS_REC;
5652 +
5653         if (err)
5654                 return err;
5655         if (!old_name || !*old_name)
5656 @@ -1514,6 +1574,7 @@ static int do_loopback(struct path *path
5657                 spin_unlock(&vfsmount_lock);
5658                 release_mounts(&umount_list);
5659         }
5660 +       mnt->mnt_flags = mnt_flags;
5661  
5662  out:
5663         up_write(&namespace_sem);
5664 @@ -1544,12 +1605,12 @@ static int change_mount_flags(struct vfs
5665   * on it - tough luck.
5666   */
5667  static int do_remount(struct path *path, int flags, int mnt_flags,
5668 -                     void *data)
5669 +       void *data, xid_t xid)
5670  {
5671         int err;
5672         struct super_block *sb = path->mnt->mnt_sb;
5673  
5674 -       if (!capable(CAP_SYS_ADMIN))
5675 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5676                 return -EPERM;
5677  
5678         if (!check_mnt(path->mnt))
5679 @@ -1593,7 +1654,7 @@ static int do_move_mount(struct path *pa
5680         struct path old_path, parent_path;
5681         struct vfsmount *p;
5682         int err = 0;
5683 -       if (!capable(CAP_SYS_ADMIN))
5684 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5685                 return -EPERM;
5686         if (!old_name || !*old_name)
5687                 return -EINVAL;
5688 @@ -1675,7 +1736,7 @@ static int do_new_mount(struct path *pat
5689                 return -EINVAL;
5690  
5691         /* we need capabilities... */
5692 -       if (!capable(CAP_SYS_ADMIN))
5693 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5694                 return -EPERM;
5695  
5696         lock_kernel();
5697 @@ -1941,6 +2002,7 @@ long do_mount(char *dev_name, char *dir_
5698         struct path path;
5699         int retval = 0;
5700         int mnt_flags = 0;
5701 +       tag_t tag = 0;
5702  
5703         /* Discard magic */
5704         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5705 @@ -1968,6 +2030,12 @@ long do_mount(char *dev_name, char *dir_
5706         if (!(flags & MS_NOATIME))
5707                 mnt_flags |= MNT_RELATIME;
5708  
5709 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5710 +               /* FIXME: bind and re-mounts get the tag flag? */
5711 +               if (flags & (MS_BIND|MS_REMOUNT))
5712 +                       flags |= MS_TAGID;
5713 +       }
5714 +
5715         /* Separate the per-mountpoint flags */
5716         if (flags & MS_NOSUID)
5717                 mnt_flags |= MNT_NOSUID;
5718 @@ -1984,15 +2052,17 @@ long do_mount(char *dev_name, char *dir_
5719         if (flags & MS_RDONLY)
5720                 mnt_flags |= MNT_READONLY;
5721  
5722 +       if (!capable(CAP_SYS_ADMIN))
5723 +               mnt_flags |= MNT_NODEV;
5724         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5725                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5726                    MS_STRICTATIME);
5727  
5728         if (flags & MS_REMOUNT)
5729                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5730 -                                   data_page);
5731 +                                   data_page, tag);
5732         else if (flags & MS_BIND)
5733 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5734 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5735         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5736                 retval = do_change_type(&path, flags);
5737         else if (flags & MS_MOVE)
5738 @@ -2071,6 +2141,7 @@ static struct mnt_namespace *dup_mnt_ns(
5739                 q = next_mnt(q, new_ns->root);
5740         }
5741         up_write(&namespace_sem);
5742 +       atomic_inc(&vs_global_mnt_ns);
5743  
5744         if (rootmnt)
5745                 mntput(rootmnt);
5746 @@ -2215,9 +2286,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5747         down_write(&namespace_sem);
5748         mutex_lock(&old.dentry->d_inode->i_mutex);
5749         error = -EINVAL;
5750 -       if (IS_MNT_SHARED(old.mnt) ||
5751 +       if ((IS_MNT_SHARED(old.mnt) ||
5752                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5753 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5754 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5755 +               !vx_flags(VXF_STATE_SETUP, 0))
5756                 goto out2;
5757         if (!check_mnt(root.mnt))
5758                 goto out2;
5759 @@ -2348,6 +2420,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5760         spin_unlock(&vfsmount_lock);
5761         up_write(&namespace_sem);
5762         release_mounts(&umount_list);
5763 +       atomic_dec(&vs_global_mnt_ns);
5764         kfree(ns);
5765  }
5766  EXPORT_SYMBOL(put_mnt_ns);
5767 diff -NurpP --minimal linux-2.6.35.4/fs/nfs/client.c linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/client.c
5768 --- linux-2.6.35.4/fs/nfs/client.c      2010-08-02 16:52:50.000000000 +0200
5769 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/client.c        2010-08-02 17:05:06.000000000 +0200
5770 @@ -739,6 +739,9 @@ static int nfs_init_server_rpcclient(str
5771         if (server->flags & NFS_MOUNT_SOFT)
5772                 server->client->cl_softrtry = 1;
5773  
5774 +       server->client->cl_tag = 0;
5775 +       if (server->flags & NFS_MOUNT_TAGGED)
5776 +               server->client->cl_tag = 1;
5777         return 0;
5778  }
5779  
5780 @@ -910,6 +913,10 @@ static void nfs_server_set_fsinfo(struct
5781                 server->acdirmin = server->acdirmax = 0;
5782         }
5783  
5784 +       /* FIXME: needs fsinfo
5785 +       if (server->flags & NFS_MOUNT_TAGGED)
5786 +               sb->s_flags |= MS_TAGGED;       */
5787 +
5788         server->maxfilesize = fsinfo->maxfilesize;
5789  
5790         /* We're airborne Set socket buffersize */
5791 diff -NurpP --minimal linux-2.6.35.4/fs/nfs/dir.c linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/dir.c
5792 --- linux-2.6.35.4/fs/nfs/dir.c 2010-09-05 01:41:57.000000000 +0200
5793 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/dir.c   2010-09-06 02:59:52.000000000 +0200
5794 @@ -33,6 +33,7 @@
5795  #include <linux/namei.h>
5796  #include <linux/mount.h>
5797  #include <linux/sched.h>
5798 +#include <linux/vs_tag.h>
5799  
5800  #include "nfs4_fs.h"
5801  #include "delegation.h"
5802 @@ -979,6 +980,7 @@ static struct dentry *nfs_lookup(struct 
5803         if (IS_ERR(res))
5804                 goto out_unblock_sillyrename;
5805  
5806 +       dx_propagate_tag(nd, inode);
5807  no_entry:
5808         res = d_materialise_unique(dentry, inode);
5809         if (res != NULL) {
5810 diff -NurpP --minimal linux-2.6.35.4/fs/nfs/inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/inode.c
5811 --- linux-2.6.35.4/fs/nfs/inode.c       2010-08-02 16:52:50.000000000 +0200
5812 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/inode.c 2010-08-02 17:05:06.000000000 +0200
5813 @@ -37,6 +37,7 @@
5814  #include <linux/inet.h>
5815  #include <linux/nfs_xdr.h>
5816  #include <linux/slab.h>
5817 +#include <linux/vs_tag.h>
5818  
5819  #include <asm/system.h>
5820  #include <asm/uaccess.h>
5821 @@ -260,6 +261,8 @@ nfs_fhget(struct super_block *sb, struct
5822         if (inode->i_state & I_NEW) {
5823                 struct nfs_inode *nfsi = NFS_I(inode);
5824                 unsigned long now = jiffies;
5825 +               uid_t uid;
5826 +               gid_t gid;
5827  
5828                 /* We set i_ino for the few things that still rely on it,
5829                  * such as stat(2) */
5830 @@ -308,8 +311,8 @@ nfs_fhget(struct super_block *sb, struct
5831                 nfsi->change_attr = 0;
5832                 inode->i_size = 0;
5833                 inode->i_nlink = 0;
5834 -               inode->i_uid = -2;
5835 -               inode->i_gid = -2;
5836 +               uid = -2;
5837 +               gid = -2;
5838                 inode->i_blocks = 0;
5839                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5840  
5841 @@ -346,13 +349,13 @@ nfs_fhget(struct super_block *sb, struct
5842                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5843                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5844                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5845 -                       inode->i_uid = fattr->uid;
5846 +                       uid = fattr->uid;
5847                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5848                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5849                                 | NFS_INO_INVALID_ACCESS
5850                                 | NFS_INO_INVALID_ACL;
5851                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5852 -                       inode->i_gid = fattr->gid;
5853 +                       gid = fattr->gid;
5854                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5855                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5856                                 | NFS_INO_INVALID_ACCESS
5857 @@ -365,6 +368,11 @@ nfs_fhget(struct super_block *sb, struct
5858                          */
5859                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5860                 }
5861 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5862 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5863 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5864 +                               /* maybe fattr->xid someday */
5865 +
5866                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5867                 nfsi->attrtimeo_timestamp = now;
5868                 nfsi->access_cache = RB_ROOT;
5869 @@ -483,6 +491,8 @@ void nfs_setattr_update_inode(struct ino
5870                         inode->i_uid = attr->ia_uid;
5871                 if ((attr->ia_valid & ATTR_GID) != 0)
5872                         inode->i_gid = attr->ia_gid;
5873 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5874 +                       inode->i_tag = attr->ia_tag;
5875                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5876                 spin_unlock(&inode->i_lock);
5877         }
5878 @@ -856,6 +866,9 @@ static int nfs_check_inode_attributes(st
5879         struct nfs_inode *nfsi = NFS_I(inode);
5880         loff_t cur_size, new_isize;
5881         unsigned long invalid = 0;
5882 +       uid_t uid;
5883 +       gid_t gid;
5884 +       tag_t tag;
5885  
5886  
5887         /* Has the inode gone and changed behind our back? */
5888 @@ -879,13 +892,18 @@ static int nfs_check_inode_attributes(st
5889                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5890         }
5891  
5892 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5893 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5894 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5895 +
5896         /* Have any file permissions changed? */
5897         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5898                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5899 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5900 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5901                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5902 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5903 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5904                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5905 +               /* maybe check for tag too? */
5906  
5907         /* Has the link count changed? */
5908         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5909 @@ -1120,6 +1138,9 @@ static int nfs_update_inode(struct inode
5910         unsigned long invalid = 0;
5911         unsigned long now = jiffies;
5912         unsigned long save_cache_validity;
5913 +       uid_t uid;
5914 +       gid_t gid;
5915 +       tag_t tag;
5916  
5917         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5918                         __func__, inode->i_sb->s_id, inode->i_ino,
5919 @@ -1222,6 +1243,9 @@ static int nfs_update_inode(struct inode
5920                                 | NFS_INO_REVAL_PAGECACHE
5921                                 | NFS_INO_REVAL_FORCED);
5922  
5923 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5924 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5925 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5926  
5927         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5928                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5929 @@ -1243,9 +1267,9 @@ static int nfs_update_inode(struct inode
5930                                 | NFS_INO_REVAL_FORCED);
5931  
5932         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5933 -               if (inode->i_uid != fattr->uid) {
5934 +               if (uid != fattr->uid) {
5935                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5936 -                       inode->i_uid = fattr->uid;
5937 +                       uid = fattr->uid;
5938                 }
5939         } else if (server->caps & NFS_CAP_OWNER)
5940                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5941 @@ -1254,9 +1278,9 @@ static int nfs_update_inode(struct inode
5942                                 | NFS_INO_REVAL_FORCED);
5943  
5944         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5945 -               if (inode->i_gid != fattr->gid) {
5946 +               if (gid != fattr->gid) {
5947                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5948 -                       inode->i_gid = fattr->gid;
5949 +                       gid = fattr->gid;
5950                 }
5951         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5952                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5953 @@ -1264,6 +1288,10 @@ static int nfs_update_inode(struct inode
5954                                 | NFS_INO_INVALID_ACL
5955                                 | NFS_INO_REVAL_FORCED);
5956  
5957 +       inode->i_uid = uid;
5958 +       inode->i_gid = gid;
5959 +       inode->i_tag = tag;
5960 +
5961         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5962                 if (inode->i_nlink != fattr->nlink) {
5963                         invalid |= NFS_INO_INVALID_ATTR;
5964 diff -NurpP --minimal linux-2.6.35.4/fs/nfs/nfs3xdr.c linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/nfs3xdr.c
5965 --- linux-2.6.35.4/fs/nfs/nfs3xdr.c     2010-08-02 16:52:50.000000000 +0200
5966 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/nfs3xdr.c       2010-08-02 17:05:06.000000000 +0200
5967 @@ -20,6 +20,7 @@
5968  #include <linux/nfs3.h>
5969  #include <linux/nfs_fs.h>
5970  #include <linux/nfsacl.h>
5971 +#include <linux/vs_tag.h>
5972  #include "internal.h"
5973  
5974  #define NFSDBG_FACILITY                NFSDBG_XDR
5975 @@ -175,7 +176,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5976  }
5977  
5978  static inline __be32 *
5979 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5980 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5981  {
5982         if (attr->ia_valid & ATTR_MODE) {
5983                 *p++ = xdr_one;
5984 @@ -183,15 +184,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5985         } else {
5986                 *p++ = xdr_zero;
5987         }
5988 -       if (attr->ia_valid & ATTR_UID) {
5989 +       if (attr->ia_valid & ATTR_UID ||
5990 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5991                 *p++ = xdr_one;
5992 -               *p++ = htonl(attr->ia_uid);
5993 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5994         } else {
5995                 *p++ = xdr_zero;
5996         }
5997 -       if (attr->ia_valid & ATTR_GID) {
5998 +       if (attr->ia_valid & ATTR_GID ||
5999 +               (tag && (attr->ia_valid & ATTR_TAG))) {
6000                 *p++ = xdr_one;
6001 -               *p++ = htonl(attr->ia_gid);
6002 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
6003         } else {
6004                 *p++ = xdr_zero;
6005         }
6006 @@ -278,7 +281,8 @@ static int
6007  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
6008  {
6009         p = xdr_encode_fhandle(p, args->fh);
6010 -       p = xdr_encode_sattr(p, args->sattr);
6011 +       p = xdr_encode_sattr(p, args->sattr,
6012 +               req->rq_task->tk_client->cl_tag);
6013         *p++ = htonl(args->guard);
6014         if (args->guard)
6015                 p = xdr_encode_time3(p, &args->guardtime);
6016 @@ -383,7 +387,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
6017                 *p++ = args->verifier[0];
6018                 *p++ = args->verifier[1];
6019         } else
6020 -               p = xdr_encode_sattr(p, args->sattr);
6021 +               p = xdr_encode_sattr(p, args->sattr,
6022 +                       req->rq_task->tk_client->cl_tag);
6023  
6024         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6025         return 0;
6026 @@ -397,7 +402,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
6027  {
6028         p = xdr_encode_fhandle(p, args->fh);
6029         p = xdr_encode_array(p, args->name, args->len);
6030 -       p = xdr_encode_sattr(p, args->sattr);
6031 +       p = xdr_encode_sattr(p, args->sattr,
6032 +               req->rq_task->tk_client->cl_tag);
6033         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6034         return 0;
6035  }
6036 @@ -410,7 +416,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
6037  {
6038         p = xdr_encode_fhandle(p, args->fromfh);
6039         p = xdr_encode_array(p, args->fromname, args->fromlen);
6040 -       p = xdr_encode_sattr(p, args->sattr);
6041 +       p = xdr_encode_sattr(p, args->sattr,
6042 +               req->rq_task->tk_client->cl_tag);
6043         *p++ = htonl(args->pathlen);
6044         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6045  
6046 @@ -428,7 +435,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
6047         p = xdr_encode_fhandle(p, args->fh);
6048         p = xdr_encode_array(p, args->name, args->len);
6049         *p++ = htonl(args->type);
6050 -       p = xdr_encode_sattr(p, args->sattr);
6051 +       p = xdr_encode_sattr(p, args->sattr,
6052 +               req->rq_task->tk_client->cl_tag);
6053         if (args->type == NF3CHR || args->type == NF3BLK) {
6054                 *p++ = htonl(MAJOR(args->rdev));
6055                 *p++ = htonl(MINOR(args->rdev));
6056 diff -NurpP --minimal linux-2.6.35.4/fs/nfs/nfsroot.c linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/nfsroot.c
6057 --- linux-2.6.35.4/fs/nfs/nfsroot.c     2010-08-02 16:52:50.000000000 +0200
6058 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/nfsroot.c       2010-08-02 17:05:06.000000000 +0200
6059 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
6060  enum {
6061         /* Options that take integer arguments */
6062         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
6063 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
6064 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
6065         /* Options that take no arguments */
6066         Opt_soft, Opt_hard, Opt_intr,
6067         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
6068         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
6069 -       Opt_acl, Opt_noacl,
6070 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
6071         /* Error token */
6072         Opt_err
6073  };
6074 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
6075         {Opt_tcp, "tcp"},
6076         {Opt_acl, "acl"},
6077         {Opt_noacl, "noacl"},
6078 +       {Opt_tag, "tag"},
6079 +       {Opt_notag, "notag"},
6080 +       {Opt_tagid, "tagid=%u"},
6081         {Opt_err, NULL}
6082         
6083  };
6084 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
6085                         case Opt_noacl:
6086                                 nfs_data.flags |= NFS_MOUNT_NOACL;
6087                                 break;
6088 +#ifndef CONFIG_TAGGING_NONE
6089 +                       case Opt_tag:
6090 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6091 +                               break;
6092 +                       case Opt_notag:
6093 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
6094 +                               break;
6095 +#endif
6096 +#ifdef CONFIG_PROPAGATE
6097 +                       case Opt_tagid:
6098 +                               /* use args[0] */
6099 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6100 +                               break;
6101 +#endif
6102                         default:
6103                                 printk(KERN_WARNING "Root-NFS: unknown "
6104                                         "option: %s\n", p);
6105 diff -NurpP --minimal linux-2.6.35.4/fs/nfs/super.c linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/super.c
6106 --- linux-2.6.35.4/fs/nfs/super.c       2010-09-05 01:41:57.000000000 +0200
6107 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/nfs/super.c 2010-09-06 02:59:52.000000000 +0200
6108 @@ -54,6 +54,7 @@
6109  #include <linux/nfs_xdr.h>
6110  #include <linux/magic.h>
6111  #include <linux/parser.h>
6112 +#include <linux/vs_tag.h>
6113  
6114  #include <asm/system.h>
6115  #include <asm/uaccess.h>
6116 @@ -606,6 +607,7 @@ static void nfs_show_mount_options(struc
6117                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6118                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
6119                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
6120 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6121                 { 0, NULL, NULL }
6122         };
6123         const struct proc_nfs_info *nfs_infop;
6124 diff -NurpP --minimal linux-2.6.35.4/fs/nfsd/auth.c linux-2.6.35.4-vs2.3.0.36.32/fs/nfsd/auth.c
6125 --- linux-2.6.35.4/fs/nfsd/auth.c       2010-02-25 11:52:05.000000000 +0100
6126 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/nfsd/auth.c 2010-08-02 17:05:06.000000000 +0200
6127 @@ -1,6 +1,7 @@
6128  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
6129  
6130  #include <linux/sched.h>
6131 +#include <linux/vs_tag.h>
6132  #include "nfsd.h"
6133  #include "auth.h"
6134  
6135 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6136  
6137         new->fsuid = rqstp->rq_cred.cr_uid;
6138         new->fsgid = rqstp->rq_cred.cr_gid;
6139 +       /* FIXME: this desperately needs a tag :)
6140 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6141 +                       */
6142  
6143         rqgi = rqstp->rq_cred.cr_group_info;
6144  
6145 diff -NurpP --minimal linux-2.6.35.4/fs/nfsd/nfs3xdr.c linux-2.6.35.4-vs2.3.0.36.32/fs/nfsd/nfs3xdr.c
6146 --- linux-2.6.35.4/fs/nfsd/nfs3xdr.c    2010-02-25 11:52:05.000000000 +0100
6147 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/nfsd/nfs3xdr.c      2010-08-02 17:05:06.000000000 +0200
6148 @@ -7,6 +7,7 @@
6149   */
6150  
6151  #include <linux/namei.h>
6152 +#include <linux/vs_tag.h>
6153  #include "xdr3.h"
6154  #include "auth.h"
6155  
6156 @@ -95,6 +96,8 @@ static __be32 *
6157  decode_sattr3(__be32 *p, struct iattr *iap)
6158  {
6159         u32     tmp;
6160 +       uid_t   uid = 0;
6161 +       gid_t   gid = 0;
6162  
6163         iap->ia_valid = 0;
6164  
6165 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6166         }
6167         if (*p++) {
6168                 iap->ia_valid |= ATTR_UID;
6169 -               iap->ia_uid = ntohl(*p++);
6170 +               uid = ntohl(*p++);
6171         }
6172         if (*p++) {
6173                 iap->ia_valid |= ATTR_GID;
6174 -               iap->ia_gid = ntohl(*p++);
6175 +               gid = ntohl(*p++);
6176         }
6177 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6178 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6179 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6180         if (*p++) {
6181                 u64     newsize;
6182  
6183 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6184         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6185         *p++ = htonl((u32) stat->mode);
6186         *p++ = htonl((u32) stat->nlink);
6187 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6188 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6189 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6190 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6191 +               stat->uid, stat->tag)));
6192 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6193 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6194 +               stat->gid, stat->tag)));
6195         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6196                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6197         } else {
6198 diff -NurpP --minimal linux-2.6.35.4/fs/nfsd/nfs4xdr.c linux-2.6.35.4-vs2.3.0.36.32/fs/nfsd/nfs4xdr.c
6199 --- linux-2.6.35.4/fs/nfsd/nfs4xdr.c    2010-08-02 16:52:50.000000000 +0200
6200 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/nfsd/nfs4xdr.c      2010-08-02 17:05:06.000000000 +0200
6201 @@ -47,6 +47,7 @@
6202  #include <linux/nfsd_idmap.h>
6203  #include <linux/nfs4_acl.h>
6204  #include <linux/sunrpc/svcauth_gss.h>
6205 +#include <linux/vs_tag.h>
6206  
6207  #include "xdr4.h"
6208  #include "vfs.h"
6209 @@ -2053,14 +2054,18 @@ out_acl:
6210                 WRITE32(stat.nlink);
6211         }
6212         if (bmval1 & FATTR4_WORD1_OWNER) {
6213 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6214 +               status = nfsd4_encode_user(rqstp,
6215 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6216 +                       stat.uid, stat.tag), &p, &buflen);
6217                 if (status == nfserr_resource)
6218                         goto out_resource;
6219                 if (status)
6220                         goto out;
6221         }
6222         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6223 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6224 +               status = nfsd4_encode_group(rqstp,
6225 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6226 +                       stat.gid, stat.tag), &p, &buflen);
6227                 if (status == nfserr_resource)
6228                         goto out_resource;
6229                 if (status)
6230 diff -NurpP --minimal linux-2.6.35.4/fs/nfsd/nfsxdr.c linux-2.6.35.4-vs2.3.0.36.32/fs/nfsd/nfsxdr.c
6231 --- linux-2.6.35.4/fs/nfsd/nfsxdr.c     2010-02-25 11:52:05.000000000 +0100
6232 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/nfsd/nfsxdr.c       2010-08-02 17:05:06.000000000 +0200
6233 @@ -6,6 +6,7 @@
6234  
6235  #include "xdr.h"
6236  #include "auth.h"
6237 +#include <linux/vs_tag.h>
6238  
6239  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6240  
6241 @@ -88,6 +89,8 @@ static __be32 *
6242  decode_sattr(__be32 *p, struct iattr *iap)
6243  {
6244         u32     tmp, tmp1;
6245 +       uid_t   uid = 0;
6246 +       gid_t   gid = 0;
6247  
6248         iap->ia_valid = 0;
6249  
6250 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6251         }
6252         if ((tmp = ntohl(*p++)) != (u32)-1) {
6253                 iap->ia_valid |= ATTR_UID;
6254 -               iap->ia_uid = tmp;
6255 +               uid = tmp;
6256         }
6257         if ((tmp = ntohl(*p++)) != (u32)-1) {
6258                 iap->ia_valid |= ATTR_GID;
6259 -               iap->ia_gid = tmp;
6260 +               gid = tmp;
6261         }
6262 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6263 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6264 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6265         if ((tmp = ntohl(*p++)) != (u32)-1) {
6266                 iap->ia_valid |= ATTR_SIZE;
6267                 iap->ia_size = tmp;
6268 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6269         *p++ = htonl(nfs_ftypes[type >> 12]);
6270         *p++ = htonl((u32) stat->mode);
6271         *p++ = htonl((u32) stat->nlink);
6272 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6273 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6274 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6275 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6276 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6277 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6278  
6279         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6280                 *p++ = htonl(NFS_MAXPATHLEN);
6281 diff -NurpP --minimal linux-2.6.35.4/fs/ocfs2/dlmglue.c linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/dlmglue.c
6282 --- linux-2.6.35.4/fs/ocfs2/dlmglue.c   2010-08-02 16:52:51.000000000 +0200
6283 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/dlmglue.c     2010-08-02 17:05:06.000000000 +0200
6284 @@ -2114,6 +2114,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6285         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6286         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6287         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6288 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6289         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6290         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6291         lvb->lvb_iatime_packed  =
6292 @@ -2168,6 +2169,7 @@ static void ocfs2_refresh_inode_from_lvb
6293  
6294         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6295         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6296 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6297         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6298         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6299         ocfs2_unpack_timespec(&inode->i_atime,
6300 diff -NurpP --minimal linux-2.6.35.4/fs/ocfs2/dlmglue.h linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/dlmglue.h
6301 --- linux-2.6.35.4/fs/ocfs2/dlmglue.h   2009-12-03 20:02:53.000000000 +0100
6302 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/dlmglue.h     2010-08-02 17:05:06.000000000 +0200
6303 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6304         __be16       lvb_inlink;
6305         __be32       lvb_iattr;
6306         __be32       lvb_igeneration;
6307 -       __be32       lvb_reserved2;
6308 +       __be16       lvb_itag;
6309 +       __be16       lvb_reserved2;
6310  };
6311  
6312  #define OCFS2_QINFO_LVB_VERSION 1
6313 diff -NurpP --minimal linux-2.6.35.4/fs/ocfs2/file.c linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/file.c
6314 --- linux-2.6.35.4/fs/ocfs2/file.c      2010-08-02 16:52:51.000000000 +0200
6315 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/file.c        2010-08-02 17:05:06.000000000 +0200
6316 @@ -1129,13 +1129,15 @@ int ocfs2_setattr(struct dentry *dentry,
6317                 mlog(0, "uid change: %d\n", attr->ia_uid);
6318         if (attr->ia_valid & ATTR_GID)
6319                 mlog(0, "gid change: %d\n", attr->ia_gid);
6320 +       if (attr->ia_valid & ATTR_TAG)
6321 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6322         if (attr->ia_valid & ATTR_SIZE)
6323                 mlog(0, "size change...\n");
6324         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6325                 mlog(0, "time change...\n");
6326  
6327  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6328 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6329 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6330         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6331                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6332                 return 0;
6333 diff -NurpP --minimal linux-2.6.35.4/fs/ocfs2/inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/inode.c
6334 --- linux-2.6.35.4/fs/ocfs2/inode.c     2010-08-02 16:52:51.000000000 +0200
6335 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/inode.c       2010-08-02 17:05:06.000000000 +0200
6336 @@ -28,6 +28,7 @@
6337  #include <linux/highmem.h>
6338  #include <linux/pagemap.h>
6339  #include <linux/quotaops.h>
6340 +#include <linux/vs_tag.h>
6341  
6342  #include <asm/byteorder.h>
6343  
6344 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6345  {
6346         unsigned int flags = OCFS2_I(inode)->ip_attr;
6347  
6348 -       inode->i_flags &= ~(S_IMMUTABLE |
6349 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6350                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6351  
6352         if (flags & OCFS2_IMMUTABLE_FL)
6353                 inode->i_flags |= S_IMMUTABLE;
6354 +       if (flags & OCFS2_IXUNLINK_FL)
6355 +               inode->i_flags |= S_IXUNLINK;
6356  
6357         if (flags & OCFS2_SYNC_FL)
6358                 inode->i_flags |= S_SYNC;
6359 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
6360                 inode->i_flags |= S_NOATIME;
6361         if (flags & OCFS2_DIRSYNC_FL)
6362                 inode->i_flags |= S_DIRSYNC;
6363 +
6364 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6365 +
6366 +       if (flags & OCFS2_BARRIER_FL)
6367 +               inode->i_vflags |= V_BARRIER;
6368 +       if (flags & OCFS2_COW_FL)
6369 +               inode->i_vflags |= V_COW;
6370  }
6371  
6372  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6373  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6374  {
6375         unsigned int flags = oi->vfs_inode.i_flags;
6376 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6377 +
6378 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6379 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6380 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6381 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6382 +
6383 +       if (flags & S_IMMUTABLE)
6384 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6385 +       if (flags & S_IXUNLINK)
6386 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6387  
6388 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6389 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6390         if (flags & S_SYNC)
6391                 oi->ip_attr |= OCFS2_SYNC_FL;
6392         if (flags & S_APPEND)
6393                 oi->ip_attr |= OCFS2_APPEND_FL;
6394 -       if (flags & S_IMMUTABLE)
6395 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6396         if (flags & S_NOATIME)
6397                 oi->ip_attr |= OCFS2_NOATIME_FL;
6398         if (flags & S_DIRSYNC)
6399                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6400 +
6401 +       if (vflags & V_BARRIER)
6402 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6403 +       if (vflags & V_COW)
6404 +               oi->ip_attr |= OCFS2_COW_FL;
6405  }
6406  
6407  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6408 @@ -245,6 +267,8 @@ void ocfs2_populate_inode(struct inode *
6409         struct super_block *sb;
6410         struct ocfs2_super *osb;
6411         int use_plocks = 1;
6412 +       uid_t uid;
6413 +       gid_t gid;
6414  
6415         mlog_entry("(0x%p, size:%llu)\n", inode,
6416                    (unsigned long long)le64_to_cpu(fe->i_size));
6417 @@ -276,8 +300,12 @@ void ocfs2_populate_inode(struct inode *
6418         inode->i_generation = le32_to_cpu(fe->i_generation);
6419         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6420         inode->i_mode = le16_to_cpu(fe->i_mode);
6421 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6422 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6423 +       uid = le32_to_cpu(fe->i_uid);
6424 +       gid = le32_to_cpu(fe->i_gid);
6425 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6426 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6427 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6428 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6429  
6430         /* Fast symlinks will have i_size but no allocated clusters. */
6431         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6432 diff -NurpP --minimal linux-2.6.35.4/fs/ocfs2/inode.h linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/inode.h
6433 --- linux-2.6.35.4/fs/ocfs2/inode.h     2010-08-02 16:52:51.000000000 +0200
6434 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/inode.h       2010-08-02 17:05:06.000000000 +0200
6435 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
6436  
6437  void ocfs2_set_inode_flags(struct inode *inode);
6438  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6439 +int ocfs2_sync_flags(struct inode *inode, int, int);
6440  
6441  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6442  {
6443 diff -NurpP --minimal linux-2.6.35.4/fs/ocfs2/ioctl.c linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/ioctl.c
6444 --- linux-2.6.35.4/fs/ocfs2/ioctl.c     2010-02-25 11:52:06.000000000 +0100
6445 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/ioctl.c       2010-08-02 17:05:06.000000000 +0200
6446 @@ -43,7 +43,41 @@ static int ocfs2_get_inode_attr(struct i
6447         return status;
6448  }
6449  
6450 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6451 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6452 +{
6453 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6454 +       struct buffer_head *bh = NULL;
6455 +       handle_t *handle = NULL;
6456 +       int status;
6457 +
6458 +       status = ocfs2_inode_lock(inode, &bh, 1);
6459 +       if (status < 0) {
6460 +               mlog_errno(status);
6461 +               return status;
6462 +       }
6463 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6464 +       if (IS_ERR(handle)) {
6465 +               status = PTR_ERR(handle);
6466 +               mlog_errno(status);
6467 +               goto bail_unlock;
6468 +       }
6469 +
6470 +       inode->i_flags = flags;
6471 +       inode->i_vflags = vflags;
6472 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6473 +
6474 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6475 +       if (status < 0)
6476 +               mlog_errno(status);
6477 +
6478 +       ocfs2_commit_trans(osb, handle);
6479 +bail_unlock:
6480 +       ocfs2_inode_unlock(inode, 1);
6481 +       brelse(bh);
6482 +       return status;
6483 +}
6484 +
6485 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6486                                 unsigned mask)
6487  {
6488         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6489 @@ -68,6 +102,11 @@ static int ocfs2_set_inode_attr(struct i
6490         if (!S_ISDIR(inode->i_mode))
6491                 flags &= ~OCFS2_DIRSYNC_FL;
6492  
6493 +       if (IS_BARRIER(inode)) {
6494 +               vxwprintk_task(1, "messing with the barrier.");
6495 +               goto bail_unlock;
6496 +       }
6497 +
6498         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6499         if (IS_ERR(handle)) {
6500                 status = PTR_ERR(handle);
6501 @@ -109,6 +148,7 @@ bail:
6502         return status;
6503  }
6504  
6505 +
6506  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6507  {
6508         struct inode *inode = filp->f_path.dentry->d_inode;
6509 diff -NurpP --minimal linux-2.6.35.4/fs/ocfs2/namei.c linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/namei.c
6510 --- linux-2.6.35.4/fs/ocfs2/namei.c     2010-08-02 16:52:51.000000000 +0200
6511 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/namei.c       2010-08-02 17:05:06.000000000 +0200
6512 @@ -41,6 +41,7 @@
6513  #include <linux/slab.h>
6514  #include <linux/highmem.h>
6515  #include <linux/quotaops.h>
6516 +#include <linux/vs_tag.h>
6517  
6518  #define MLOG_MASK_PREFIX ML_NAMEI
6519  #include <cluster/masklog.h>
6520 @@ -487,6 +488,7 @@ static int ocfs2_mknod_locked(struct ocf
6521         u64 suballoc_loc, fe_blkno = 0;
6522         u16 suballoc_bit;
6523         u16 feat;
6524 +       tag_t tag;
6525  
6526         *new_fe_bh = NULL;
6527  
6528 @@ -532,8 +534,11 @@ static int ocfs2_mknod_locked(struct ocf
6529         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6530         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6531         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6532 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6533 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6534 +
6535 +       tag = dx_current_fstag(osb->sb);
6536 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6537 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6538 +       inode->i_tag = tag;
6539         fe->i_mode = cpu_to_le16(inode->i_mode);
6540         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6541                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6542 diff -NurpP --minimal linux-2.6.35.4/fs/ocfs2/ocfs2_fs.h linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/ocfs2_fs.h
6543 --- linux-2.6.35.4/fs/ocfs2/ocfs2_fs.h  2010-08-02 16:52:51.000000000 +0200
6544 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/ocfs2_fs.h    2010-08-02 17:05:06.000000000 +0200
6545 @@ -235,18 +235,23 @@
6546  #define OCFS2_HAS_REFCOUNT_FL   (0x0010)
6547  
6548  /* Inode attributes, keep in sync with EXT2 */
6549 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6550 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6551 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6552 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6553 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6554 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6555 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6556 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6557 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6558 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6559 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6560 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6561 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6562 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6563 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6564 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6565 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6566  
6567 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6568 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6569 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6570 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6571 +
6572 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6573 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6574 +
6575 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6576 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6577  
6578  /*
6579   * Extent record flags (e_node.leaf.flags)
6580 diff -NurpP --minimal linux-2.6.35.4/fs/ocfs2/ocfs2.h linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/ocfs2.h
6581 --- linux-2.6.35.4/fs/ocfs2/ocfs2.h     2010-08-02 16:52:51.000000000 +0200
6582 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/ocfs2.h       2010-08-02 17:05:06.000000000 +0200
6583 @@ -256,6 +256,7 @@ enum ocfs2_mount_options
6584                                                    control lists */
6585         OCFS2_MOUNT_USRQUOTA = 1 << 10, /* We support user quotas */
6586         OCFS2_MOUNT_GRPQUOTA = 1 << 11, /* We support group quotas */
6587 +       OCFS2_MOUNT_TAGGED = 1 << 12, /* use tagging */
6588  };
6589  
6590  #define OCFS2_OSB_SOFT_RO                      0x0001
6591 diff -NurpP --minimal linux-2.6.35.4/fs/ocfs2/super.c linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/super.c
6592 --- linux-2.6.35.4/fs/ocfs2/super.c     2010-08-02 16:52:51.000000000 +0200
6593 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/ocfs2/super.c       2010-08-02 18:00:11.000000000 +0200
6594 @@ -180,6 +180,7 @@ enum {
6595         Opt_grpquota,
6596         Opt_resv_level,
6597         Opt_dir_resv_level,
6598 +       Opt_tag, Opt_notag, Opt_tagid,
6599         Opt_err,
6600  };
6601  
6602 @@ -208,6 +209,9 @@ static const match_table_t tokens = {
6603         {Opt_grpquota, "grpquota"},
6604         {Opt_resv_level, "resv_level=%u"},
6605         {Opt_dir_resv_level, "dir_resv_level=%u"},
6606 +       {Opt_tag, "tag"},
6607 +       {Opt_notag, "notag"},
6608 +       {Opt_tagid, "tagid=%u"},
6609         {Opt_err, NULL}
6610  };
6611  
6612 @@ -618,6 +622,13 @@ static int ocfs2_remount(struct super_bl
6613                 goto out;
6614         }
6615  
6616 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6617 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6618 +               ret = -EINVAL;
6619 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6620 +               goto out;
6621 +       }
6622 +
6623         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6624             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6625                 ret = -EINVAL;
6626 @@ -1154,6 +1165,9 @@ static int ocfs2_fill_super(struct super
6627  
6628         ocfs2_complete_mount_recovery(osb);
6629  
6630 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6631 +               sb->s_flags |= MS_TAGGED;
6632 +
6633         if (ocfs2_mount_local(osb))
6634                 snprintf(nodestr, sizeof(nodestr), "local");
6635         else
6636 @@ -1469,6 +1483,20 @@ static int ocfs2_parse_options(struct su
6637                             option < OCFS2_MAX_RESV_LEVEL)
6638                                 mopt->dir_resv_level = option;
6639                         break;
6640 +#ifndef CONFIG_TAGGING_NONE
6641 +               case Opt_tag:
6642 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6643 +                       break;
6644 +               case Opt_notag:
6645 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6646 +                       break;
6647 +#endif
6648 +#ifdef CONFIG_PROPAGATE
6649 +               case Opt_tagid:
6650 +                       /* use args[0] */
6651 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6652 +                       break;
6653 +#endif
6654                 default:
6655                         mlog(ML_ERROR,
6656                              "Unrecognized mount option \"%s\" "
6657 diff -NurpP --minimal linux-2.6.35.4/fs/open.c linux-2.6.35.4-vs2.3.0.36.32/fs/open.c
6658 --- linux-2.6.35.4/fs/open.c    2010-08-02 16:52:51.000000000 +0200
6659 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/open.c      2010-08-02 21:36:22.000000000 +0200
6660 @@ -29,6 +29,11 @@
6661  #include <linux/falloc.h>
6662  #include <linux/fs_struct.h>
6663  #include <linux/ima.h>
6664 +#include <linux/vs_base.h>
6665 +#include <linux/vs_limit.h>
6666 +#include <linux/vs_tag.h>
6667 +#include <linux/vs_cowbl.h>
6668 +#include <linux/vserver/dlimit.h>
6669  
6670  #include "internal.h"
6671  
6672 @@ -481,6 +486,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6673         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6674         if (error)
6675                 goto out;
6676 +
6677 +#ifdef CONFIG_VSERVER_COWBL
6678 +       error = cow_check_and_break(&path);
6679 +       if (error)
6680 +               goto dput_and_out;
6681 +#endif
6682         inode = path.dentry->d_inode;
6683  
6684         error = mnt_want_write(path.mnt);
6685 @@ -518,11 +529,11 @@ static int chown_common(struct path *pat
6686         newattrs.ia_valid =  ATTR_CTIME;
6687         if (user != (uid_t) -1) {
6688                 newattrs.ia_valid |= ATTR_UID;
6689 -               newattrs.ia_uid = user;
6690 +               newattrs.ia_uid = dx_map_uid(user);
6691         }
6692         if (group != (gid_t) -1) {
6693                 newattrs.ia_valid |= ATTR_GID;
6694 -               newattrs.ia_gid = group;
6695 +               newattrs.ia_gid = dx_map_gid(group);
6696         }
6697         if (!S_ISDIR(inode->i_mode))
6698                 newattrs.ia_valid |=
6699 @@ -547,6 +558,10 @@ SYSCALL_DEFINE3(chown, const char __user
6700         error = mnt_want_write(path.mnt);
6701         if (error)
6702                 goto out_release;
6703 +#ifdef CONFIG_VSERVER_COWBL
6704 +       error = cow_check_and_break(&path);
6705 +       if (!error)
6706 +#endif
6707         error = chown_common(&path, user, group);
6708         mnt_drop_write(path.mnt);
6709  out_release:
6710 @@ -572,6 +587,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6711         error = mnt_want_write(path.mnt);
6712         if (error)
6713                 goto out_release;
6714 +#ifdef CONFIG_VSERVER_COWBL
6715 +       error = cow_check_and_break(&path);
6716 +       if (!error)
6717 +#endif
6718         error = chown_common(&path, user, group);
6719         mnt_drop_write(path.mnt);
6720  out_release:
6721 @@ -591,6 +610,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6722         error = mnt_want_write(path.mnt);
6723         if (error)
6724                 goto out_release;
6725 +#ifdef CONFIG_VSERVER_COWBL
6726 +       error = cow_check_and_break(&path);
6727 +       if (!error)
6728 +#endif
6729         error = chown_common(&path, user, group);
6730         mnt_drop_write(path.mnt);
6731  out_release:
6732 @@ -837,6 +860,7 @@ static void __put_unused_fd(struct files
6733         __FD_CLR(fd, fdt->open_fds);
6734         if (fd < files->next_fd)
6735                 files->next_fd = fd;
6736 +       vx_openfd_dec(fd);
6737  }
6738  
6739  void put_unused_fd(unsigned int fd)
6740 diff -NurpP --minimal linux-2.6.35.4/fs/proc/array.c linux-2.6.35.4-vs2.3.0.36.32/fs/proc/array.c
6741 --- linux-2.6.35.4/fs/proc/array.c      2010-08-02 16:52:51.000000000 +0200
6742 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/proc/array.c        2010-08-02 17:05:06.000000000 +0200
6743 @@ -81,6 +81,8 @@
6744  #include <linux/pid_namespace.h>
6745  #include <linux/ptrace.h>
6746  #include <linux/tracehook.h>
6747 +#include <linux/vs_context.h>
6748 +#include <linux/vs_network.h>
6749  
6750  #include <asm/pgtable.h>
6751  #include <asm/processor.h>
6752 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6753         rcu_read_lock();
6754         ppid = pid_alive(p) ?
6755                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6756 +       if (unlikely(vx_current_initpid(p->pid)))
6757 +               ppid = 0;
6758 +
6759         tpid = 0;
6760         if (pid_alive(p)) {
6761                 struct task_struct *tracer = tracehook_tracer_task(p);
6762 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6763  }
6764  
6765  static void render_cap_t(struct seq_file *m, const char *header,
6766 -                       kernel_cap_t *a)
6767 +                       struct vx_info *vxi, kernel_cap_t *a)
6768  {
6769         unsigned __capi;
6770  
6771 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6772         cap_bset        = cred->cap_bset;
6773         rcu_read_unlock();
6774  
6775 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6776 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6777 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6778 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6779 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6780 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6781 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6782 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6783 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6784  }
6785  
6786  static inline void task_context_switch_counts(struct seq_file *m,
6787 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6788         seq_printf(m, "\n");
6789  }
6790  
6791 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6792 +                       struct pid *pid, struct task_struct *task)
6793 +{
6794 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6795 +                       "Count:\t%u\n"
6796 +                       "uts:\t%p(%c)\n"
6797 +                       "ipc:\t%p(%c)\n"
6798 +                       "mnt:\t%p(%c)\n"
6799 +                       "pid:\t%p(%c)\n"
6800 +                       "net:\t%p(%c)\n",
6801 +                       task->nsproxy,
6802 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6803 +                       atomic_read(&task->nsproxy->count),
6804 +                       task->nsproxy->uts_ns,
6805 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6806 +                       task->nsproxy->ipc_ns,
6807 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6808 +                       task->nsproxy->mnt_ns,
6809 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6810 +                       task->nsproxy->pid_ns,
6811 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6812 +                       task->nsproxy->net_ns,
6813 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6814 +       return 0;
6815 +}
6816 +
6817 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6818 +{
6819 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6820 +               return;
6821 +
6822 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6823 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6824 +}
6825 +
6826 +
6827  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6828                         struct pid *pid, struct task_struct *task)
6829  {
6830 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6831         task_cap(m, task);
6832         task_cpus_allowed(m, task);
6833         cpuset_task_status_allowed(m, task);
6834 +       task_vs_id(m, task);
6835  #if defined(CONFIG_S390)
6836         task_show_regs(m, task);
6837  #endif
6838 @@ -465,6 +508,17 @@ static int do_task_stat(struct seq_file 
6839         /* convert nsec -> ticks */
6840         start_time = nsec_to_clock_t(start_time);
6841  
6842 +       /* fixup start time for virt uptime */
6843 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6844 +               unsigned long long bias =
6845 +                       current->vx_info->cvirt.bias_clock;
6846 +
6847 +               if (start_time > bias)
6848 +                       start_time -= bias;
6849 +               else
6850 +                       start_time = 0;
6851 +       }
6852 +
6853         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6854  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6855  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6856 diff -NurpP --minimal linux-2.6.35.4/fs/proc/base.c linux-2.6.35.4-vs2.3.0.36.32/fs/proc/base.c
6857 --- linux-2.6.35.4/fs/proc/base.c       2010-08-02 16:52:51.000000000 +0200
6858 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/proc/base.c 2010-08-02 17:05:06.000000000 +0200
6859 @@ -82,6 +82,8 @@
6860  #include <linux/pid_namespace.h>
6861  #include <linux/fs_struct.h>
6862  #include <linux/slab.h>
6863 +#include <linux/vs_context.h>
6864 +#include <linux/vs_network.h>
6865  #include "internal.h"
6866  
6867  /* NOTE:
6868 @@ -1033,12 +1035,17 @@ static ssize_t oom_adjust_write(struct f
6869                 return -ESRCH;
6870         }
6871  
6872 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6873 +       if (oom_adjust < task->signal->oom_adj &&
6874 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6875                 unlock_task_sighand(task, &flags);
6876                 put_task_struct(task);
6877                 return -EACCES;
6878         }
6879  
6880 +       /* prevent guest processes from circumventing the oom killer */
6881 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6882 +               oom_adjust = OOM_ADJUST_MIN;
6883 +
6884         task->signal->oom_adj = oom_adjust;
6885  
6886         unlock_task_sighand(task, &flags);
6887 @@ -1079,7 +1086,7 @@ static ssize_t proc_loginuid_write(struc
6888         ssize_t length;
6889         uid_t loginuid;
6890  
6891 -       if (!capable(CAP_AUDIT_CONTROL))
6892 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6893                 return -EPERM;
6894  
6895         rcu_read_lock();
6896 @@ -1517,6 +1524,8 @@ static struct inode *proc_pid_make_inode
6897                 inode->i_gid = cred->egid;
6898                 rcu_read_unlock();
6899         }
6900 +       /* procfs is xid tagged */
6901 +       inode->i_tag = (tag_t)vx_task_xid(task);
6902         security_task_to_inode(task, inode);
6903  
6904  out:
6905 @@ -2067,6 +2076,13 @@ static struct dentry *proc_pident_lookup
6906         if (!task)
6907                 goto out_no_task;
6908  
6909 +       /* TODO: maybe we can come up with a generic approach? */
6910 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6911 +               (dentry->d_name.len == 5) &&
6912 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6913 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6914 +               goto out;
6915 +
6916         /*
6917          * Yes, it does not scale. And it should not. Don't add
6918          * new entries into /proc/<tgid>/ without very good reasons.
6919 @@ -2474,7 +2490,7 @@ out_iput:
6920  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6921  {
6922         struct dentry *error;
6923 -       struct task_struct *task = get_proc_task(dir);
6924 +       struct task_struct *task = get_proc_task_real(dir);
6925         const struct pid_entry *p, *last;
6926  
6927         error = ERR_PTR(-ENOENT);
6928 @@ -2564,6 +2580,9 @@ static int proc_pid_personality(struct s
6929  static const struct file_operations proc_task_operations;
6930  static const struct inode_operations proc_task_inode_operations;
6931  
6932 +extern int proc_pid_vx_info(struct task_struct *, char *);
6933 +extern int proc_pid_nx_info(struct task_struct *, char *);
6934 +
6935  static const struct pid_entry tgid_base_stuff[] = {
6936         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6937         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6938 @@ -2623,6 +2642,8 @@ static const struct pid_entry tgid_base_
6939  #ifdef CONFIG_CGROUPS
6940         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6941  #endif
6942 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6943 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6944         INF("oom_score",  S_IRUGO, proc_oom_score),
6945         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6946  #ifdef CONFIG_AUDITSYSCALL
6947 @@ -2638,6 +2659,7 @@ static const struct pid_entry tgid_base_
6948  #ifdef CONFIG_TASK_IO_ACCOUNTING
6949         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6950  #endif
6951 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6952  };
6953  
6954  static int proc_tgid_base_readdir(struct file * filp,
6955 @@ -2829,7 +2851,7 @@ retry:
6956         iter.task = NULL;
6957         pid = find_ge_pid(iter.tgid, ns);
6958         if (pid) {
6959 -               iter.tgid = pid_nr_ns(pid, ns);
6960 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6961                 iter.task = pid_task(pid, PIDTYPE_PID);
6962                 /* What we to know is if the pid we have find is the
6963                  * pid of a thread_group_leader.  Testing for task
6964 @@ -2859,7 +2881,7 @@ static int proc_pid_fill_cache(struct fi
6965         struct tgid_iter iter)
6966  {
6967         char name[PROC_NUMBUF];
6968 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6969 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6970         return proc_fill_cache(filp, dirent, filldir, name, len,
6971                                 proc_pid_instantiate, iter.task, NULL);
6972  }
6973 @@ -2868,7 +2890,7 @@ static int proc_pid_fill_cache(struct fi
6974  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6975  {
6976         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6977 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6978 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6979         struct tgid_iter iter;
6980         struct pid_namespace *ns;
6981  
6982 @@ -2888,6 +2910,8 @@ int proc_pid_readdir(struct file * filp,
6983              iter.task;
6984              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6985                 filp->f_pos = iter.tgid + TGID_OFFSET;
6986 +               if (!vx_proc_task_visible(iter.task))
6987 +                       continue;
6988                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6989                         put_task_struct(iter.task);
6990                         goto out;
6991 @@ -3035,6 +3059,8 @@ static struct dentry *proc_task_lookup(s
6992         tid = name_to_int(dentry);
6993         if (tid == ~0U)
6994                 goto out;
6995 +       if (vx_current_initpid(tid))
6996 +               goto out;
6997  
6998         ns = dentry->d_sb->s_fs_info;
6999         rcu_read_lock();
7000 diff -NurpP --minimal linux-2.6.35.4/fs/proc/generic.c linux-2.6.35.4-vs2.3.0.36.32/fs/proc/generic.c
7001 --- linux-2.6.35.4/fs/proc/generic.c    2010-08-02 16:52:51.000000000 +0200
7002 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/proc/generic.c      2010-08-02 17:05:06.000000000 +0200
7003 @@ -21,6 +21,7 @@
7004  #include <linux/bitops.h>
7005  #include <linux/spinlock.h>
7006  #include <linux/completion.h>
7007 +#include <linux/vserver/inode.h>
7008  #include <asm/uaccess.h>
7009  
7010  #include "internal.h"
7011 @@ -418,6 +419,8 @@ struct dentry *proc_lookup_de(struct pro
7012         for (de = de->subdir; de ; de = de->next) {
7013                 if (de->namelen != dentry->d_name.len)
7014                         continue;
7015 +                       if (!vx_hide_check(0, de->vx_flags))
7016 +                               continue;
7017                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
7018                         unsigned int ino;
7019  
7020 @@ -426,6 +429,8 @@ struct dentry *proc_lookup_de(struct pro
7021                         spin_unlock(&proc_subdir_lock);
7022                         error = -EINVAL;
7023                         inode = proc_get_inode(dir->i_sb, ino, de);
7024 +                               /* generic proc entries belong to the host */
7025 +                               inode->i_tag = 0;
7026                         goto out_unlock;
7027                 }
7028         }
7029 @@ -503,6 +508,8 @@ int proc_readdir_de(struct proc_dir_entr
7030  
7031                                 /* filldir passes info to user space */
7032                                 pde_get(de);
7033 +                               if (!vx_hide_check(0, de->vx_flags))
7034 +                                       goto skip;
7035                                 spin_unlock(&proc_subdir_lock);
7036                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
7037                                             de->low_ino, de->mode >> 12) < 0) {
7038 @@ -510,6 +517,7 @@ int proc_readdir_de(struct proc_dir_entr
7039                                         goto out;
7040                                 }
7041                                 spin_lock(&proc_subdir_lock);
7042 +                       skip:
7043                                 filp->f_pos++;
7044                                 next = de->next;
7045                                 pde_put(de);
7046 @@ -624,6 +632,7 @@ static struct proc_dir_entry *__proc_cre
7047         ent->nlink = nlink;
7048         atomic_set(&ent->count, 1);
7049         ent->pde_users = 0;
7050 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7051         spin_lock_init(&ent->pde_unload_lock);
7052         ent->pde_unload_completion = NULL;
7053         INIT_LIST_HEAD(&ent->pde_openers);
7054 @@ -647,7 +656,8 @@ struct proc_dir_entry *proc_symlink(cons
7055                                 kfree(ent->data);
7056                                 kfree(ent);
7057                                 ent = NULL;
7058 -                       }
7059 +                       } else
7060 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7061                 } else {
7062                         kfree(ent);
7063                         ent = NULL;
7064 diff -NurpP --minimal linux-2.6.35.4/fs/proc/inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/proc/inode.c
7065 --- linux-2.6.35.4/fs/proc/inode.c      2010-08-02 16:52:51.000000000 +0200
7066 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/proc/inode.c        2010-08-02 17:05:06.000000000 +0200
7067 @@ -437,6 +437,8 @@ struct inode *proc_get_inode(struct supe
7068                         inode->i_uid = de->uid;
7069                         inode->i_gid = de->gid;
7070                 }
7071 +               if (de->vx_flags)
7072 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7073                 if (de->size)
7074                         inode->i_size = de->size;
7075                 if (de->nlink)
7076 diff -NurpP --minimal linux-2.6.35.4/fs/proc/internal.h linux-2.6.35.4-vs2.3.0.36.32/fs/proc/internal.h
7077 --- linux-2.6.35.4/fs/proc/internal.h   2010-02-25 11:52:06.000000000 +0100
7078 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/proc/internal.h     2010-08-02 17:05:06.000000000 +0200
7079 @@ -10,6 +10,7 @@
7080   */
7081  
7082  #include <linux/proc_fs.h>
7083 +#include <linux/vs_pid.h>
7084  
7085  extern struct proc_dir_entry proc_root;
7086  #ifdef CONFIG_PROC_SYSCTL
7087 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7088                                 struct pid *pid, struct task_struct *task);
7089  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7090                                 struct pid *pid, struct task_struct *task);
7091 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7092 +                               struct pid *pid, struct task_struct *task);
7093 +
7094  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7095  
7096  extern const struct file_operations proc_maps_operations;
7097 @@ -68,11 +72,16 @@ static inline struct pid *proc_pid(struc
7098         return PROC_I(inode)->pid;
7099  }
7100  
7101 -static inline struct task_struct *get_proc_task(struct inode *inode)
7102 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7103  {
7104         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7105  }
7106  
7107 +static inline struct task_struct *get_proc_task(struct inode *inode)
7108 +{
7109 +       return vx_get_proc_task(inode, proc_pid(inode));
7110 +}
7111 +
7112  static inline int proc_fd(struct inode *inode)
7113  {
7114         return PROC_I(inode)->fd;
7115 diff -NurpP --minimal linux-2.6.35.4/fs/proc/loadavg.c linux-2.6.35.4-vs2.3.0.36.32/fs/proc/loadavg.c
7116 --- linux-2.6.35.4/fs/proc/loadavg.c    2009-09-10 15:26:23.000000000 +0200
7117 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/proc/loadavg.c      2010-08-02 17:05:06.000000000 +0200
7118 @@ -12,15 +12,27 @@
7119  
7120  static int loadavg_proc_show(struct seq_file *m, void *v)
7121  {
7122 +       unsigned long running;
7123 +       unsigned int threads;
7124         unsigned long avnrun[3];
7125  
7126         get_avenrun(avnrun, FIXED_1/200, 0);
7127  
7128 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7129 +               struct vx_info *vxi = current_vx_info();
7130 +
7131 +               running = atomic_read(&vxi->cvirt.nr_running);
7132 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7133 +       } else {
7134 +               running = nr_running();
7135 +               threads = nr_threads;
7136 +       }
7137 +
7138         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7139                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7140                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7141                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7142 -               nr_running(), nr_threads,
7143 +               running, threads,
7144                 task_active_pid_ns(current)->last_pid);
7145         return 0;
7146  }
7147 diff -NurpP --minimal linux-2.6.35.4/fs/proc/meminfo.c linux-2.6.35.4-vs2.3.0.36.32/fs/proc/meminfo.c
7148 --- linux-2.6.35.4/fs/proc/meminfo.c    2009-12-03 20:02:53.000000000 +0100
7149 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/proc/meminfo.c      2010-08-02 17:05:06.000000000 +0200
7150 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7151         allowed = ((totalram_pages - hugetlb_total_pages())
7152                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7153  
7154 -       cached = global_page_state(NR_FILE_PAGES) -
7155 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7156 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7157                         total_swapcache_pages - i.bufferram;
7158         if (cached < 0)
7159                 cached = 0;
7160 diff -NurpP --minimal linux-2.6.35.4/fs/proc/root.c linux-2.6.35.4-vs2.3.0.36.32/fs/proc/root.c
7161 --- linux-2.6.35.4/fs/proc/root.c       2010-08-02 16:52:51.000000000 +0200
7162 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/proc/root.c 2010-08-02 17:05:06.000000000 +0200
7163 @@ -18,9 +18,14 @@
7164  #include <linux/bitops.h>
7165  #include <linux/mount.h>
7166  #include <linux/pid_namespace.h>
7167 +#include <linux/vserver/inode.h>
7168  
7169  #include "internal.h"
7170  
7171 +struct proc_dir_entry *proc_virtual;
7172 +
7173 +extern void proc_vx_init(void);
7174 +
7175  static int proc_test_super(struct super_block *sb, void *data)
7176  {
7177         return sb->s_fs_info == data;
7178 @@ -135,6 +140,7 @@ void __init proc_root_init(void)
7179  #endif
7180         proc_mkdir("bus", NULL);
7181         proc_sys_init();
7182 +       proc_vx_init();
7183  }
7184  
7185  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7186 @@ -202,6 +208,7 @@ struct proc_dir_entry proc_root = {
7187         .proc_iops      = &proc_root_inode_operations, 
7188         .proc_fops      = &proc_root_operations,
7189         .parent         = &proc_root,
7190 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7191  };
7192  
7193  int pid_ns_prepare_proc(struct pid_namespace *ns)
7194 diff -NurpP --minimal linux-2.6.35.4/fs/proc/uptime.c linux-2.6.35.4-vs2.3.0.36.32/fs/proc/uptime.c
7195 --- linux-2.6.35.4/fs/proc/uptime.c     2009-12-03 20:02:53.000000000 +0100
7196 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/proc/uptime.c       2010-08-02 17:05:06.000000000 +0200
7197 @@ -4,22 +4,22 @@
7198  #include <linux/sched.h>
7199  #include <linux/seq_file.h>
7200  #include <linux/time.h>
7201 -#include <linux/kernel_stat.h>
7202 +#include <linux/vserver/cvirt.h>
7203  #include <asm/cputime.h>
7204  
7205  static int uptime_proc_show(struct seq_file *m, void *v)
7206  {
7207         struct timespec uptime;
7208         struct timespec idle;
7209 -       int i;
7210 -       cputime_t idletime = cputime_zero;
7211 -
7212 -       for_each_possible_cpu(i)
7213 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7214 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7215  
7216         do_posix_clock_monotonic_gettime(&uptime);
7217         monotonic_to_bootbased(&uptime);
7218         cputime_to_timespec(idletime, &idle);
7219 +
7220 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7221 +               vx_vsi_uptime(&uptime, &idle);
7222 +
7223         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7224                         (unsigned long) uptime.tv_sec,
7225                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7226 diff -NurpP --minimal linux-2.6.35.4/fs/quota/dquot.c linux-2.6.35.4-vs2.3.0.36.32/fs/quota/dquot.c
7227 --- linux-2.6.35.4/fs/quota/dquot.c     2010-08-02 16:52:51.000000000 +0200
7228 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/quota/dquot.c       2010-08-02 22:36:48.000000000 +0200
7229 @@ -1503,6 +1503,9 @@ int __dquot_alloc_space(struct inode *in
7230         int reserve = flags & DQUOT_SPACE_RESERVE;
7231         int nofail = flags & DQUOT_SPACE_NOFAIL;
7232  
7233 +       if ((ret = dl_alloc_space(inode, number)))
7234 +               return ret;
7235 +
7236         /*
7237          * First test before acquiring mutex - solves deadlocks when we
7238          * re-enter the quota code and are already holding the mutex
7239 @@ -1557,6 +1560,9 @@ int dquot_alloc_inode(const struct inode
7240         int cnt, ret = 0;
7241         char warntype[MAXQUOTAS];
7242  
7243 +       if ((ret = dl_alloc_inode(inode)))
7244 +               return ret;
7245 +
7246         /* First test before acquiring mutex - solves deadlocks when we
7247           * re-enter the quota code and are already holding the mutex */
7248         if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode))
7249 @@ -1627,6 +1633,8 @@ void __dquot_free_space(struct inode *in
7250         char warntype[MAXQUOTAS];
7251         int reserve = flags & DQUOT_SPACE_RESERVE;
7252  
7253 +       dl_free_space(inode, number);
7254 +
7255         /* First test before acquiring mutex - solves deadlocks when we
7256           * re-enter the quota code and are already holding the mutex */
7257         if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode)) {
7258 @@ -1665,6 +1673,8 @@ void dquot_free_inode(const struct inode
7259         unsigned int cnt;
7260         char warntype[MAXQUOTAS];
7261  
7262 +       dl_free_inode(inode);
7263 +
7264         /* First test before acquiring mutex - solves deadlocks when we
7265           * re-enter the quota code and are already holding the mutex */
7266         if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode))
7267 diff -NurpP --minimal linux-2.6.35.4/fs/quota/quota.c linux-2.6.35.4-vs2.3.0.36.32/fs/quota/quota.c
7268 --- linux-2.6.35.4/fs/quota/quota.c     2010-08-02 16:52:51.000000000 +0200
7269 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/quota/quota.c       2010-08-02 17:05:06.000000000 +0200
7270 @@ -8,6 +8,7 @@
7271  #include <linux/fs.h>
7272  #include <linux/namei.h>
7273  #include <linux/slab.h>
7274 +#include <linux/vs_context.h>
7275  #include <asm/current.h>
7276  #include <asm/uaccess.h>
7277  #include <linux/kernel.h>
7278 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
7279                         break;
7280                 /*FALLTHROUGH*/
7281         default:
7282 -               if (!capable(CAP_SYS_ADMIN))
7283 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7284                         return -EPERM;
7285         }
7286  
7287 @@ -296,6 +297,46 @@ static int do_quotactl(struct super_bloc
7288         }
7289  }
7290  
7291 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7292 +
7293 +#include <linux/vroot.h>
7294 +#include <linux/major.h>
7295 +#include <linux/module.h>
7296 +#include <linux/kallsyms.h>
7297 +#include <linux/vserver/debug.h>
7298 +
7299 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7300 +
7301 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7302 +
7303 +int register_vroot_grb(vroot_grb_func *func) {
7304 +       int ret = -EBUSY;
7305 +
7306 +       spin_lock(&vroot_grb_lock);
7307 +       if (!vroot_get_real_bdev) {
7308 +               vroot_get_real_bdev = func;
7309 +               ret = 0;
7310 +       }
7311 +       spin_unlock(&vroot_grb_lock);
7312 +       return ret;
7313 +}
7314 +EXPORT_SYMBOL(register_vroot_grb);
7315 +
7316 +int unregister_vroot_grb(vroot_grb_func *func) {
7317 +       int ret = -EINVAL;
7318 +
7319 +       spin_lock(&vroot_grb_lock);
7320 +       if (vroot_get_real_bdev) {
7321 +               vroot_get_real_bdev = NULL;
7322 +               ret = 0;
7323 +       }
7324 +       spin_unlock(&vroot_grb_lock);
7325 +       return ret;
7326 +}
7327 +EXPORT_SYMBOL(unregister_vroot_grb);
7328 +
7329 +#endif
7330 +
7331  /*
7332   * look up a superblock on which quota ops will be performed
7333   * - use the name of a block device to find the superblock thereon
7334 @@ -313,6 +354,22 @@ static struct super_block *quotactl_bloc
7335         putname(tmp);
7336         if (IS_ERR(bdev))
7337                 return ERR_CAST(bdev);
7338 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7339 +       if (bdev && bdev->bd_inode &&
7340 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7341 +               struct block_device *bdnew = (void *)-EINVAL;
7342 +
7343 +               if (vroot_get_real_bdev)
7344 +                       bdnew = vroot_get_real_bdev(bdev);
7345 +               else
7346 +                       vxdprintk(VXD_CBIT(misc, 0),
7347 +                                       "vroot_get_real_bdev not set");
7348 +               bdput(bdev);
7349 +               if (IS_ERR(bdnew))
7350 +                       return ERR_PTR(PTR_ERR(bdnew));
7351 +               bdev = bdnew;
7352 +       }
7353 +#endif
7354         sb = get_super(bdev);
7355         bdput(bdev);
7356         if (!sb)
7357 diff -NurpP --minimal linux-2.6.35.4/fs/reiserfs/file.c linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/file.c
7358 --- linux-2.6.35.4/fs/reiserfs/file.c   2010-08-02 16:52:52.000000000 +0200
7359 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/file.c     2010-08-02 17:05:06.000000000 +0200
7360 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7361         .listxattr = reiserfs_listxattr,
7362         .removexattr = reiserfs_removexattr,
7363         .permission = reiserfs_permission,
7364 +       .sync_flags = reiserfs_sync_flags,
7365  };
7366 diff -NurpP --minimal linux-2.6.35.4/fs/reiserfs/inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/inode.c
7367 --- linux-2.6.35.4/fs/reiserfs/inode.c  2010-08-02 16:52:52.000000000 +0200
7368 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/inode.c    2010-08-02 17:05:06.000000000 +0200
7369 @@ -19,6 +19,7 @@
7370  #include <linux/writeback.h>
7371  #include <linux/quotaops.h>
7372  #include <linux/swap.h>
7373 +#include <linux/vs_tag.h>
7374  
7375  int reiserfs_commit_write(struct file *f, struct page *page,
7376                           unsigned from, unsigned to);
7377 @@ -1125,6 +1126,8 @@ static void init_inode(struct inode *ino
7378         struct buffer_head *bh;
7379         struct item_head *ih;
7380         __u32 rdev;
7381 +       uid_t uid;
7382 +       gid_t gid;
7383         //int version = ITEM_VERSION_1;
7384  
7385         bh = PATH_PLAST_BUFFER(path);
7386 @@ -1146,12 +1149,13 @@ static void init_inode(struct inode *ino
7387                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7388                 unsigned long blocks;
7389  
7390 +               uid = sd_v1_uid(sd);
7391 +               gid = sd_v1_gid(sd);
7392 +
7393                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7394                 set_inode_sd_version(inode, STAT_DATA_V1);
7395                 inode->i_mode = sd_v1_mode(sd);
7396                 inode->i_nlink = sd_v1_nlink(sd);
7397 -               inode->i_uid = sd_v1_uid(sd);
7398 -               inode->i_gid = sd_v1_gid(sd);
7399                 inode->i_size = sd_v1_size(sd);
7400                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7401                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7402 @@ -1193,11 +1197,12 @@ static void init_inode(struct inode *ino
7403                 // (directories and symlinks)
7404                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7405  
7406 +               uid    = sd_v2_uid(sd);
7407 +               gid    = sd_v2_gid(sd);
7408 +
7409                 inode->i_mode = sd_v2_mode(sd);
7410                 inode->i_nlink = sd_v2_nlink(sd);
7411 -               inode->i_uid = sd_v2_uid(sd);
7412                 inode->i_size = sd_v2_size(sd);
7413 -               inode->i_gid = sd_v2_gid(sd);
7414                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7415                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7416                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7417 @@ -1227,6 +1232,10 @@ static void init_inode(struct inode *ino
7418                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7419         }
7420  
7421 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7422 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7423 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7424 +
7425         pathrelse(path);
7426         if (S_ISREG(inode->i_mode)) {
7427                 inode->i_op = &reiserfs_file_inode_operations;
7428 @@ -1249,13 +1258,15 @@ static void init_inode(struct inode *ino
7429  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7430  {
7431         struct stat_data *sd_v2 = (struct stat_data *)sd;
7432 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7433 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7434         __u16 flags;
7435  
7436 +       set_sd_v2_uid(sd_v2, uid);
7437 +       set_sd_v2_gid(sd_v2, gid);
7438         set_sd_v2_mode(sd_v2, inode->i_mode);
7439         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7440 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7441         set_sd_v2_size(sd_v2, size);
7442 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7443         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7444         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7445         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7446 @@ -2856,14 +2867,19 @@ int reiserfs_commit_write(struct file *f
7447  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7448  {
7449         if (reiserfs_attrs(inode->i_sb)) {
7450 -               if (sd_attrs & REISERFS_SYNC_FL)
7451 -                       inode->i_flags |= S_SYNC;
7452 -               else
7453 -                       inode->i_flags &= ~S_SYNC;
7454                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7455                         inode->i_flags |= S_IMMUTABLE;
7456                 else
7457                         inode->i_flags &= ~S_IMMUTABLE;
7458 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7459 +                       inode->i_flags |= S_IXUNLINK;
7460 +               else
7461 +                       inode->i_flags &= ~S_IXUNLINK;
7462 +
7463 +               if (sd_attrs & REISERFS_SYNC_FL)
7464 +                       inode->i_flags |= S_SYNC;
7465 +               else
7466 +                       inode->i_flags &= ~S_SYNC;
7467                 if (sd_attrs & REISERFS_APPEND_FL)
7468                         inode->i_flags |= S_APPEND;
7469                 else
7470 @@ -2876,6 +2892,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7471                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7472                 else
7473                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7474 +
7475 +               if (sd_attrs & REISERFS_BARRIER_FL)
7476 +                       inode->i_vflags |= V_BARRIER;
7477 +               else
7478 +                       inode->i_vflags &= ~V_BARRIER;
7479 +               if (sd_attrs & REISERFS_COW_FL)
7480 +                       inode->i_vflags |= V_COW;
7481 +               else
7482 +                       inode->i_vflags &= ~V_COW;
7483         }
7484  }
7485  
7486 @@ -2886,6 +2911,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7487                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7488                 else
7489                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7490 +               if (inode->i_flags & S_IXUNLINK)
7491 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7492 +               else
7493 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7494 +
7495                 if (inode->i_flags & S_SYNC)
7496                         *sd_attrs |= REISERFS_SYNC_FL;
7497                 else
7498 @@ -2898,6 +2928,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7499                         *sd_attrs |= REISERFS_NOTAIL_FL;
7500                 else
7501                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7502 +
7503 +               if (inode->i_vflags & V_BARRIER)
7504 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7505 +               else
7506 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7507 +               if (inode->i_vflags & V_COW)
7508 +                       *sd_attrs |= REISERFS_COW_FL;
7509 +               else
7510 +                       *sd_attrs &= ~REISERFS_COW_FL;
7511         }
7512  }
7513  
7514 @@ -3122,9 +3161,11 @@ int reiserfs_setattr(struct dentry *dent
7515         }
7516  
7517         error = inode_change_ok(inode, attr);
7518 +
7519         if (!error) {
7520                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7521 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7522 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7523 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7524                         error = reiserfs_chown_xattrs(inode, attr);
7525  
7526                         if (!error) {
7527 @@ -3153,6 +3194,9 @@ int reiserfs_setattr(struct dentry *dent
7528                                         inode->i_uid = attr->ia_uid;
7529                                 if (attr->ia_valid & ATTR_GID)
7530                                         inode->i_gid = attr->ia_gid;
7531 +                               if ((attr->ia_valid & ATTR_TAG) &&
7532 +                                       IS_TAGGED(inode))
7533 +                                       inode->i_tag = attr->ia_tag;
7534                                 mark_inode_dirty(inode);
7535                                 error =
7536                                     journal_end(&th, inode->i_sb, jbegin_count);
7537 diff -NurpP --minimal linux-2.6.35.4/fs/reiserfs/ioctl.c linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/ioctl.c
7538 --- linux-2.6.35.4/fs/reiserfs/ioctl.c  2010-02-25 11:52:06.000000000 +0100
7539 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/ioctl.c    2010-08-02 17:05:06.000000000 +0200
7540 @@ -7,11 +7,27 @@
7541  #include <linux/mount.h>
7542  #include <linux/reiserfs_fs.h>
7543  #include <linux/time.h>
7544 +#include <linux/mount.h>
7545  #include <asm/uaccess.h>
7546  #include <linux/pagemap.h>
7547  #include <linux/smp_lock.h>
7548  #include <linux/compat.h>
7549  
7550 +
7551 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7552 +{
7553 +       __u16 sd_attrs = 0;
7554 +
7555 +       inode->i_flags = flags;
7556 +       inode->i_vflags = vflags;
7557 +
7558 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7559 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7560 +       inode->i_ctime = CURRENT_TIME_SEC;
7561 +       mark_inode_dirty(inode);
7562 +       return 0;
7563 +}
7564 +
7565  /*
7566   * reiserfs_ioctl - handler for ioctl for inode
7567   * supported commands:
7568 @@ -23,7 +39,7 @@
7569  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7570  {
7571         struct inode *inode = filp->f_path.dentry->d_inode;
7572 -       unsigned int flags;
7573 +       unsigned int flags, oldflags;
7574         int err = 0;
7575  
7576         reiserfs_write_lock(inode->i_sb);
7577 @@ -48,6 +64,7 @@ long reiserfs_ioctl(struct file *filp, u
7578  
7579                 flags = REISERFS_I(inode)->i_attrs;
7580                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7581 +               flags &= REISERFS_FL_USER_VISIBLE;
7582                 err = put_user(flags, (int __user *)arg);
7583                 break;
7584         case REISERFS_IOC_SETFLAGS:{
7585 @@ -68,6 +85,10 @@ long reiserfs_ioctl(struct file *filp, u
7586                                 err = -EFAULT;
7587                                 goto setflags_out;
7588                         }
7589 +                       if (IS_BARRIER(inode)) {
7590 +                               vxwprintk_task(1, "messing with the barrier.");
7591 +                               return -EACCES;
7592 +                       }
7593                         /*
7594                          * Is it quota file? Do not allow user to mess with it
7595                          */
7596 @@ -92,6 +113,10 @@ long reiserfs_ioctl(struct file *filp, u
7597                                         goto setflags_out;
7598                                 }
7599                         }
7600 +
7601 +                       oldflags = REISERFS_I(inode)->i_attrs;
7602 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7603 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7604                         sd_attrs_to_i_attrs(flags, inode);
7605                         REISERFS_I(inode)->i_attrs = flags;
7606                         inode->i_ctime = CURRENT_TIME_SEC;
7607 diff -NurpP --minimal linux-2.6.35.4/fs/reiserfs/namei.c linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/namei.c
7608 --- linux-2.6.35.4/fs/reiserfs/namei.c  2010-08-02 16:52:52.000000000 +0200
7609 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/namei.c    2010-08-02 17:05:06.000000000 +0200
7610 @@ -18,6 +18,7 @@
7611  #include <linux/reiserfs_acl.h>
7612  #include <linux/reiserfs_xattr.h>
7613  #include <linux/quotaops.h>
7614 +#include <linux/vs_tag.h>
7615  
7616  #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; }
7617  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7618 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7619         if (retval == IO_ERROR) {
7620                 return ERR_PTR(-EIO);
7621         }
7622 +               dx_propagate_tag(nd, inode);
7623  
7624         return d_splice_alias(inode, dentry);
7625  }
7626 @@ -1532,6 +1534,7 @@ const struct inode_operations reiserfs_d
7627         .listxattr = reiserfs_listxattr,
7628         .removexattr = reiserfs_removexattr,
7629         .permission = reiserfs_permission,
7630 +       .sync_flags = reiserfs_sync_flags,
7631  };
7632  
7633  /*
7634 diff -NurpP --minimal linux-2.6.35.4/fs/reiserfs/super.c linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/super.c
7635 --- linux-2.6.35.4/fs/reiserfs/super.c  2010-08-02 16:52:52.000000000 +0200
7636 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/super.c    2010-08-02 17:05:06.000000000 +0200
7637 @@ -897,6 +897,14 @@ static int reiserfs_parse_options(struct
7638                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7639                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7640  #endif
7641 +#ifndef CONFIG_TAGGING_NONE
7642 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7643 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7644 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7645 +#endif
7646 +#ifdef CONFIG_PROPAGATE
7647 +               {"tag",.arg_required = 'T',.values = NULL},
7648 +#endif
7649  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7650                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7651                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7652 @@ -1206,6 +1214,14 @@ static int reiserfs_remount(struct super
7653         handle_quota_files(s, qf_names, &qfmt);
7654  #endif
7655  
7656 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7657 +               !(s->s_flags & MS_TAGGED)) {
7658 +               reiserfs_warning(s, "super-vs01",
7659 +                       "reiserfs: tagging not permitted on remount.");
7660 +               err = -EINVAL;
7661 +               goto out_err;
7662 +       }
7663 +
7664         handle_attrs(s);
7665  
7666         /* Add options that are safe here */
7667 @@ -1688,6 +1704,10 @@ static int reiserfs_fill_super(struct su
7668                 goto error;
7669         }
7670  
7671 +       /* map mount option tagxid */
7672 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7673 +               s->s_flags |= MS_TAGGED;
7674 +
7675         rs = SB_DISK_SUPER_BLOCK(s);
7676         /* Let's do basic sanity check to verify that underlying device is not
7677            smaller than the filesystem. If the check fails then abort and scream,
7678 diff -NurpP --minimal linux-2.6.35.4/fs/reiserfs/xattr.c linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/xattr.c
7679 --- linux-2.6.35.4/fs/reiserfs/xattr.c  2010-08-02 16:52:52.000000000 +0200
7680 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/reiserfs/xattr.c    2010-08-02 17:05:06.000000000 +0200
7681 @@ -40,6 +40,7 @@
7682  #include <linux/errno.h>
7683  #include <linux/gfp.h>
7684  #include <linux/fs.h>
7685 +#include <linux/mount.h>
7686  #include <linux/file.h>
7687  #include <linux/pagemap.h>
7688  #include <linux/xattr.h>
7689 diff -NurpP --minimal linux-2.6.35.4/fs/stat.c linux-2.6.35.4-vs2.3.0.36.32/fs/stat.c
7690 --- linux-2.6.35.4/fs/stat.c    2010-02-25 11:52:06.000000000 +0100
7691 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/stat.c      2010-08-02 17:05:06.000000000 +0200
7692 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7693         stat->nlink = inode->i_nlink;
7694         stat->uid = inode->i_uid;
7695         stat->gid = inode->i_gid;
7696 +       stat->tag = inode->i_tag;
7697         stat->rdev = inode->i_rdev;
7698         stat->atime = inode->i_atime;
7699         stat->mtime = inode->i_mtime;
7700 diff -NurpP --minimal linux-2.6.35.4/fs/statfs.c linux-2.6.35.4-vs2.3.0.36.32/fs/statfs.c
7701 --- linux-2.6.35.4/fs/statfs.c  2010-08-02 16:52:52.000000000 +0200
7702 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/statfs.c    2010-08-02 19:10:27.000000000 +0200
7703 @@ -6,22 +6,28 @@
7704  #include <linux/statfs.h>
7705  #include <linux/security.h>
7706  #include <linux/uaccess.h>
7707 +#include <linux/vs_base.h>
7708 +#include <linux/vs_dlimit.h>
7709  
7710  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
7711  {
7712         int retval = -ENODEV;
7713  
7714         if (dentry) {
7715 +               struct super_block *sb = dentry->d_sb;
7716 +
7717                 retval = -ENOSYS;
7718 -               if (dentry->d_sb->s_op->statfs) {
7719 +               if (sb->s_op->statfs) {
7720                         memset(buf, 0, sizeof(*buf));
7721                         retval = security_sb_statfs(dentry);
7722                         if (retval)
7723                                 return retval;
7724 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
7725 +                       retval = sb->s_op->statfs(dentry, buf);
7726                         if (retval == 0 && buf->f_frsize == 0)
7727                                 buf->f_frsize = buf->f_bsize;
7728                 }
7729 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
7730 +                       vx_vsi_statfs(sb, buf);
7731         }
7732         return retval;
7733  }
7734 diff -NurpP --minimal linux-2.6.35.4/fs/super.c linux-2.6.35.4-vs2.3.0.36.32/fs/super.c
7735 --- linux-2.6.35.4/fs/super.c   2010-09-05 01:41:57.000000000 +0200
7736 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/super.c     2010-08-14 18:20:34.000000000 +0200
7737 @@ -30,6 +30,9 @@
7738  #include <linux/idr.h>
7739  #include <linux/mutex.h>
7740  #include <linux/backing-dev.h>
7741 +#include <linux/devpts_fs.h>
7742 +#include <linux/proc_fs.h>
7743 +#include <linux/vs_context.h>
7744  #include "internal.h"
7745  
7746  
7747 @@ -885,12 +888,18 @@ struct vfsmount *
7748  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7749  {
7750         struct vfsmount *mnt;
7751 +       struct super_block *sb;
7752         char *secdata = NULL;
7753         int error;
7754  
7755         if (!type)
7756                 return ERR_PTR(-ENODEV);
7757  
7758 +       error = -EPERM;
7759 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7760 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7761 +               goto out;
7762 +
7763         error = -ENOMEM;
7764         mnt = alloc_vfsmnt(name);
7765         if (!mnt)
7766 @@ -912,11 +921,19 @@ vfs_kern_mount(struct file_system_type *
7767         error = type->get_sb(type, flags, name, data, mnt);
7768         if (error < 0)
7769                 goto out_free_secdata;
7770 -       BUG_ON(!mnt->mnt_sb);
7771 -       WARN_ON(!mnt->mnt_sb->s_bdi);
7772 +
7773 +       sb = mnt->mnt_sb;
7774 +       BUG_ON(!sb);
7775 +       WARN_ON(!sb->s_bdi);
7776         mnt->mnt_sb->s_flags |= MS_BORN;
7777  
7778 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7779 +       error = -EPERM;
7780 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7781 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7782 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7783 +               goto out_sb;
7784 +
7785 +       error = security_sb_kern_mount(sb, flags, secdata);
7786         if (error)
7787                 goto out_sb;
7788  
7789 diff -NurpP --minimal linux-2.6.35.4/fs/sysfs/mount.c linux-2.6.35.4-vs2.3.0.36.32/fs/sysfs/mount.c
7790 --- linux-2.6.35.4/fs/sysfs/mount.c     2010-08-02 16:52:52.000000000 +0200
7791 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/sysfs/mount.c       2010-08-02 17:05:06.000000000 +0200
7792 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7793  
7794         sb->s_blocksize = PAGE_CACHE_SIZE;
7795         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7796 -       sb->s_magic = SYSFS_MAGIC;
7797 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7798         sb->s_op = &sysfs_ops;
7799         sb->s_time_gran = 1;
7800  
7801 diff -NurpP --minimal linux-2.6.35.4/fs/utimes.c linux-2.6.35.4-vs2.3.0.36.32/fs/utimes.c
7802 --- linux-2.6.35.4/fs/utimes.c  2009-03-24 14:22:37.000000000 +0100
7803 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/utimes.c    2010-08-02 22:52:28.000000000 +0200
7804 @@ -8,6 +8,8 @@
7805  #include <linux/stat.h>
7806  #include <linux/utime.h>
7807  #include <linux/syscalls.h>
7808 +#include <linux/mount.h>
7809 +#include <linux/vs_cowbl.h>
7810  #include <asm/uaccess.h>
7811  #include <asm/unistd.h>
7812  
7813 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7814  {
7815         int error;
7816         struct iattr newattrs;
7817 -       struct inode *inode = path->dentry->d_inode;
7818 +       struct inode *inode;
7819  
7820         error = mnt_want_write(path->mnt);
7821         if (error)
7822                 goto out;
7823  
7824 +       error = cow_check_and_break(path);
7825 +       if (error)
7826 +               goto mnt_drop_write_and_out;
7827 +
7828 +       inode = path->dentry->d_inode;
7829 +
7830         if (times && times[0].tv_nsec == UTIME_NOW &&
7831                      times[1].tv_nsec == UTIME_NOW)
7832                 times = NULL;
7833 diff -NurpP --minimal linux-2.6.35.4/fs/xattr.c linux-2.6.35.4-vs2.3.0.36.32/fs/xattr.c
7834 --- linux-2.6.35.4/fs/xattr.c   2010-08-02 16:52:52.000000000 +0200
7835 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xattr.c     2010-08-02 17:05:06.000000000 +0200
7836 @@ -18,6 +18,7 @@
7837  #include <linux/module.h>
7838  #include <linux/fsnotify.h>
7839  #include <linux/audit.h>
7840 +#include <linux/mount.h>
7841  #include <asm/uaccess.h>
7842  
7843  
7844 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7845          * The trusted.* namespace can only be accessed by a privileged user.
7846          */
7847         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
7848 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
7849 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
7850  
7851         /* In user.* namespace, only regular files and directories can have
7852          * extended attributes. For sticky directories, only the owner and
7853 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/linux-2.6/xfs_ioctl.c
7854 --- linux-2.6.35.4/fs/xfs/linux-2.6/xfs_ioctl.c 2010-08-02 16:52:52.000000000 +0200
7855 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/linux-2.6/xfs_ioctl.c   2010-08-02 17:05:06.000000000 +0200
7856 @@ -34,7 +34,6 @@
7857  #include "xfs_dir2_sf.h"
7858  #include "xfs_dinode.h"
7859  #include "xfs_inode.h"
7860 -#include "xfs_ioctl.h"
7861  #include "xfs_btree.h"
7862  #include "xfs_ialloc.h"
7863  #include "xfs_rtalloc.h"
7864 @@ -747,6 +746,10 @@ xfs_merge_ioc_xflags(
7865                 xflags |= XFS_XFLAG_IMMUTABLE;
7866         else
7867                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7868 +       if (flags & FS_IXUNLINK_FL)
7869 +               xflags |= XFS_XFLAG_IXUNLINK;
7870 +       else
7871 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7872         if (flags & FS_APPEND_FL)
7873                 xflags |= XFS_XFLAG_APPEND;
7874         else
7875 @@ -775,6 +778,8 @@ xfs_di2lxflags(
7876  
7877         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7878                 flags |= FS_IMMUTABLE_FL;
7879 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7880 +               flags |= FS_IXUNLINK_FL;
7881         if (di_flags & XFS_DIFLAG_APPEND)
7882                 flags |= FS_APPEND_FL;
7883         if (di_flags & XFS_DIFLAG_SYNC)
7884 @@ -833,6 +838,8 @@ xfs_set_diflags(
7885         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7886         if (xflags & XFS_XFLAG_IMMUTABLE)
7887                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7888 +       if (xflags & XFS_XFLAG_IXUNLINK)
7889 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7890         if (xflags & XFS_XFLAG_APPEND)
7891                 di_flags |= XFS_DIFLAG_APPEND;
7892         if (xflags & XFS_XFLAG_SYNC)
7893 @@ -875,6 +882,10 @@ xfs_diflags_to_linux(
7894                 inode->i_flags |= S_IMMUTABLE;
7895         else
7896                 inode->i_flags &= ~S_IMMUTABLE;
7897 +       if (xflags & XFS_XFLAG_IXUNLINK)
7898 +               inode->i_flags |= S_IXUNLINK;
7899 +       else
7900 +               inode->i_flags &= ~S_IXUNLINK;
7901         if (xflags & XFS_XFLAG_APPEND)
7902                 inode->i_flags |= S_APPEND;
7903         else
7904 @@ -1351,10 +1362,18 @@ xfs_file_ioctl(
7905         case XFS_IOC_FSGETXATTRA:
7906                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7907         case XFS_IOC_FSSETXATTR:
7908 +               if (IS_BARRIER(inode)) {
7909 +                       vxwprintk_task(1, "messing with the barrier.");
7910 +                       return -XFS_ERROR(EACCES);
7911 +               }
7912                 return xfs_ioc_fssetxattr(ip, filp, arg);
7913         case XFS_IOC_GETXFLAGS:
7914                 return xfs_ioc_getxflags(ip, arg);
7915         case XFS_IOC_SETXFLAGS:
7916 +               if (IS_BARRIER(inode)) {
7917 +                       vxwprintk_task(1, "messing with the barrier.");
7918 +                       return -XFS_ERROR(EACCES);
7919 +               }
7920                 return xfs_ioc_setxflags(ip, filp, arg);
7921  
7922         case XFS_IOC_FSSETDM: {
7923 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/linux-2.6/xfs_ioctl.h
7924 --- linux-2.6.35.4/fs/xfs/linux-2.6/xfs_ioctl.h 2010-07-07 18:31:54.000000000 +0200
7925 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/linux-2.6/xfs_ioctl.h   2010-08-02 17:05:06.000000000 +0200
7926 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7927         void __user             *uhandle,
7928         u32                     hlen);
7929  
7930 +extern int
7931 +xfs_sync_flags(
7932 +       struct inode            *inode,
7933 +       int                     flags,
7934 +       int                     vflags);
7935 +
7936  extern long
7937  xfs_file_ioctl(
7938         struct file             *filp,
7939 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/linux-2.6/xfs_iops.c
7940 --- linux-2.6.35.4/fs/xfs/linux-2.6/xfs_iops.c  2010-08-02 16:52:52.000000000 +0200
7941 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/linux-2.6/xfs_iops.c    2010-08-02 17:05:06.000000000 +0200
7942 @@ -36,6 +36,7 @@
7943  #include "xfs_attr_sf.h"
7944  #include "xfs_dinode.h"
7945  #include "xfs_inode.h"
7946 +#include "xfs_ioctl.h"
7947  #include "xfs_bmap.h"
7948  #include "xfs_btree.h"
7949  #include "xfs_ialloc.h"
7950 @@ -57,6 +58,7 @@
7951  #include <linux/falloc.h>
7952  #include <linux/fiemap.h>
7953  #include <linux/slab.h>
7954 +#include <linux/vs_tag.h>
7955  
7956  /*
7957   * Bring the timestamps in the XFS inode uptodate.
7958 @@ -507,6 +509,7 @@ xfs_vn_getattr(
7959         stat->nlink = ip->i_d.di_nlink;
7960         stat->uid = ip->i_d.di_uid;
7961         stat->gid = ip->i_d.di_gid;
7962 +       stat->tag = ip->i_d.di_tag;
7963         stat->ino = ip->i_ino;
7964         stat->atime = inode->i_atime;
7965         stat->mtime = inode->i_mtime;
7966 @@ -711,6 +714,7 @@ static const struct inode_operations xfs
7967         .listxattr              = xfs_vn_listxattr,
7968         .fallocate              = xfs_vn_fallocate,
7969         .fiemap                 = xfs_vn_fiemap,
7970 +       .sync_flags             = xfs_sync_flags,
7971  };
7972  
7973  static const struct inode_operations xfs_dir_inode_operations = {
7974 @@ -736,6 +740,7 @@ static const struct inode_operations xfs
7975         .getxattr               = generic_getxattr,
7976         .removexattr            = generic_removexattr,
7977         .listxattr              = xfs_vn_listxattr,
7978 +       .sync_flags             = xfs_sync_flags,
7979  };
7980  
7981  static const struct inode_operations xfs_dir_ci_inode_operations = {
7982 @@ -785,6 +790,10 @@ xfs_diflags_to_iflags(
7983                 inode->i_flags |= S_IMMUTABLE;
7984         else
7985                 inode->i_flags &= ~S_IMMUTABLE;
7986 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7987 +               inode->i_flags |= S_IXUNLINK;
7988 +       else
7989 +               inode->i_flags &= ~S_IXUNLINK;
7990         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7991                 inode->i_flags |= S_APPEND;
7992         else
7993 @@ -797,6 +806,15 @@ xfs_diflags_to_iflags(
7994                 inode->i_flags |= S_NOATIME;
7995         else
7996                 inode->i_flags &= ~S_NOATIME;
7997 +
7998 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7999 +               inode->i_vflags |= V_BARRIER;
8000 +       else
8001 +               inode->i_vflags &= ~V_BARRIER;
8002 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
8003 +               inode->i_vflags |= V_COW;
8004 +       else
8005 +               inode->i_vflags &= ~V_COW;
8006  }
8007  
8008  /*
8009 @@ -825,6 +843,7 @@ xfs_setup_inode(
8010         inode->i_nlink  = ip->i_d.di_nlink;
8011         inode->i_uid    = ip->i_d.di_uid;
8012         inode->i_gid    = ip->i_d.di_gid;
8013 +       inode->i_tag    = ip->i_d.di_tag;
8014  
8015         switch (inode->i_mode & S_IFMT) {
8016         case S_IFBLK:
8017 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/linux-2.6/xfs_linux.h
8018 --- linux-2.6.35.4/fs/xfs/linux-2.6/xfs_linux.h 2010-07-07 18:31:54.000000000 +0200
8019 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/linux-2.6/xfs_linux.h   2010-08-02 17:05:06.000000000 +0200
8020 @@ -117,6 +117,7 @@
8021  
8022  #define current_cpu()          (raw_smp_processor_id())
8023  #define current_pid()          (current->pid)
8024 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
8025  #define current_test_flags(f)  (current->flags & (f))
8026  #define current_set_flags_nested(sp, f)                \
8027                 (*(sp) = current->flags, current->flags |= (f))
8028 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/linux-2.6/xfs_super.c linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/linux-2.6/xfs_super.c
8029 --- linux-2.6.35.4/fs/xfs/linux-2.6/xfs_super.c 2010-08-02 16:52:52.000000000 +0200
8030 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/linux-2.6/xfs_super.c   2010-08-02 18:00:35.000000000 +0200
8031 @@ -121,6 +121,9 @@ mempool_t *xfs_ioend_pool;
8032  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
8033  #define MNTOPT_DELAYLOG   "delaylog"   /* Delayed loging enabled */
8034  #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
8035 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8036 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8037 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8038  
8039  /*
8040   * Table driven mount option parser.
8041 @@ -129,10 +132,14 @@ mempool_t *xfs_ioend_pool;
8042   * in the future, too.
8043   */
8044  enum {
8045 +       Opt_tag, Opt_notag,
8046         Opt_barrier, Opt_nobarrier, Opt_err
8047  };
8048  
8049  static const match_table_t tokens = {
8050 +       {Opt_tag, "tagxid"},
8051 +       {Opt_tag, "tag"},
8052 +       {Opt_notag, "notag"},
8053         {Opt_barrier, "barrier"},
8054         {Opt_nobarrier, "nobarrier"},
8055         {Opt_err, NULL}
8056 @@ -393,6 +400,19 @@ xfs_parseargs(
8057                 } else if (!strcmp(this_char, "irixsgid")) {
8058                         cmn_err(CE_WARN,
8059         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8060 +#ifndef CONFIG_TAGGING_NONE
8061 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8062 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8063 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8064 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
8065 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8066 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8067 +#endif
8068 +#ifdef CONFIG_PROPAGATE
8069 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8070 +                       /* use value */
8071 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8072 +#endif
8073                 } else {
8074                         cmn_err(CE_WARN,
8075                                 "XFS: unknown mount option [%s].", this_char);
8076 @@ -1376,6 +1396,16 @@ xfs_fs_remount(
8077                 case Opt_nobarrier:
8078                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8079                         break;
8080 +               case Opt_tag:
8081 +                       if (!(sb->s_flags & MS_TAGGED)) {
8082 +                               printk(KERN_INFO
8083 +                                       "XFS: %s: tagging not permitted on remount.\n",
8084 +                                       sb->s_id);
8085 +                               return -EINVAL;
8086 +                       }
8087 +                       break;
8088 +               case Opt_notag:
8089 +                       break;
8090                 default:
8091                         /*
8092                          * Logically we would return an error here to prevent
8093 @@ -1610,6 +1640,9 @@ xfs_fs_fill_super(
8094  
8095         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
8096  
8097 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8098 +               sb->s_flags |= MS_TAGGED;
8099 +
8100         sb->s_magic = XFS_SB_MAGIC;
8101         sb->s_blocksize = mp->m_sb.sb_blocksize;
8102         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
8103 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/xfs_dinode.h linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_dinode.h
8104 --- linux-2.6.35.4/fs/xfs/xfs_dinode.h  2009-06-11 17:13:09.000000000 +0200
8105 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_dinode.h    2010-08-02 17:05:06.000000000 +0200
8106 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
8107         __be32          di_gid;         /* owner's group id */
8108         __be32          di_nlink;       /* number of links to file */
8109         __be16          di_projid;      /* owner's project id */
8110 -       __u8            di_pad[8];      /* unused, zeroed space */
8111 +       __be16          di_tag;         /* context tagging */
8112 +       __be16          di_vflags;      /* vserver specific flags */
8113 +       __u8            di_pad[4];      /* unused, zeroed space */
8114         __be16          di_flushiter;   /* incremented on flush */
8115         xfs_timestamp_t di_atime;       /* time last accessed */
8116         xfs_timestamp_t di_mtime;       /* time last modified */
8117 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
8118  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8119  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8120  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8121 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8122 +
8123  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8124  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8125  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8126 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
8127  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8128  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8129  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8130 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8131  
8132  #ifdef CONFIG_XFS_RT
8133  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8134 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
8135          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8136          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8137          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8138 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8139 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8140 +        XFS_DIFLAG_IXUNLINK)
8141 +
8142 +#define XFS_DIVFLAG_BARRIER    0x01
8143 +#define XFS_DIVFLAG_COW                0x02
8144  
8145  #endif /* __XFS_DINODE_H__ */
8146 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/xfs_fs.h linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_fs.h
8147 --- linux-2.6.35.4/fs/xfs/xfs_fs.h      2010-07-07 18:31:54.000000000 +0200
8148 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_fs.h        2010-08-02 17:05:06.000000000 +0200
8149 @@ -67,6 +67,9 @@ struct fsxattr {
8150  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8151  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8152  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8153 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8154 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8155 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8156  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8157  
8158  /*
8159 @@ -293,7 +296,8 @@ typedef struct xfs_bstat {
8160         __u32           bs_gen;         /* generation count             */
8161         __u16           bs_projid;      /* project id                   */
8162         __u16           bs_forkoff;     /* inode fork offset in bytes   */
8163 -       unsigned char   bs_pad[12];     /* pad space, unused            */
8164 +       __u16           bs_tag;         /* context tagging              */
8165 +       unsigned char   bs_pad[10];     /* pad space, unused            */
8166         __u32           bs_dmevmask;    /* DMIG event mask              */
8167         __u16           bs_dmstate;     /* DMIG state info              */
8168         __u16           bs_aextents;    /* attribute number of extents  */
8169 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/xfs_ialloc.c linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_ialloc.c
8170 --- linux-2.6.35.4/fs/xfs/xfs_ialloc.c  2010-08-02 16:52:53.000000000 +0200
8171 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_ialloc.c    2010-08-02 17:05:06.000000000 +0200
8172 @@ -41,7 +41,6 @@
8173  #include "xfs_error.h"
8174  #include "xfs_bmap.h"
8175  
8176 -
8177  /*
8178   * Allocation group level functions.
8179   */
8180 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/xfs_inode.c linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_inode.c
8181 --- linux-2.6.35.4/fs/xfs/xfs_inode.c   2010-08-02 16:52:53.000000000 +0200
8182 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_inode.c     2010-08-02 17:05:06.000000000 +0200
8183 @@ -249,6 +249,7 @@ xfs_inotobp(
8184         return 0;
8185  }
8186  
8187 +#include <linux/vs_tag.h>
8188  
8189  /*
8190   * This routine is called to map an inode to the buffer containing
8191 @@ -654,15 +655,25 @@ xfs_iformat_btree(
8192  STATIC void
8193  xfs_dinode_from_disk(
8194         xfs_icdinode_t          *to,
8195 -       xfs_dinode_t            *from)
8196 +       xfs_dinode_t            *from,
8197 +       int tagged)
8198  {
8199 +       uint32_t uid, gid, tag;
8200 +
8201         to->di_magic = be16_to_cpu(from->di_magic);
8202         to->di_mode = be16_to_cpu(from->di_mode);
8203         to->di_version = from ->di_version;
8204         to->di_format = from->di_format;
8205         to->di_onlink = be16_to_cpu(from->di_onlink);
8206 -       to->di_uid = be32_to_cpu(from->di_uid);
8207 -       to->di_gid = be32_to_cpu(from->di_gid);
8208 +
8209 +       uid = be32_to_cpu(from->di_uid);
8210 +       gid = be32_to_cpu(from->di_gid);
8211 +       tag = be16_to_cpu(from->di_tag);
8212 +
8213 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8214 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8215 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8216 +
8217         to->di_nlink = be32_to_cpu(from->di_nlink);
8218         to->di_projid = be16_to_cpu(from->di_projid);
8219         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8220 @@ -683,21 +694,26 @@ xfs_dinode_from_disk(
8221         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8222         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8223         to->di_flags    = be16_to_cpu(from->di_flags);
8224 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8225         to->di_gen      = be32_to_cpu(from->di_gen);
8226  }
8227  
8228  void
8229  xfs_dinode_to_disk(
8230         xfs_dinode_t            *to,
8231 -       xfs_icdinode_t          *from)
8232 +       xfs_icdinode_t          *from,
8233 +       int tagged)
8234  {
8235         to->di_magic = cpu_to_be16(from->di_magic);
8236         to->di_mode = cpu_to_be16(from->di_mode);
8237         to->di_version = from ->di_version;
8238         to->di_format = from->di_format;
8239         to->di_onlink = cpu_to_be16(from->di_onlink);
8240 -       to->di_uid = cpu_to_be32(from->di_uid);
8241 -       to->di_gid = cpu_to_be32(from->di_gid);
8242 +
8243 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8244 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8245 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8246 +
8247         to->di_nlink = cpu_to_be32(from->di_nlink);
8248         to->di_projid = cpu_to_be16(from->di_projid);
8249         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8250 @@ -718,12 +734,14 @@ xfs_dinode_to_disk(
8251         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8252         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8253         to->di_flags = cpu_to_be16(from->di_flags);
8254 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8255         to->di_gen = cpu_to_be32(from->di_gen);
8256  }
8257  
8258  STATIC uint
8259  _xfs_dic2xflags(
8260 -       __uint16_t              di_flags)
8261 +       __uint16_t              di_flags,
8262 +       __uint16_t              di_vflags)
8263  {
8264         uint                    flags = 0;
8265  
8266 @@ -734,6 +752,8 @@ _xfs_dic2xflags(
8267                         flags |= XFS_XFLAG_PREALLOC;
8268                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8269                         flags |= XFS_XFLAG_IMMUTABLE;
8270 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8271 +                       flags |= XFS_XFLAG_IXUNLINK;
8272                 if (di_flags & XFS_DIFLAG_APPEND)
8273                         flags |= XFS_XFLAG_APPEND;
8274                 if (di_flags & XFS_DIFLAG_SYNC)
8275 @@ -758,6 +778,10 @@ _xfs_dic2xflags(
8276                         flags |= XFS_XFLAG_FILESTREAM;
8277         }
8278  
8279 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8280 +               flags |= FS_BARRIER_FL;
8281 +       if (di_vflags & XFS_DIVFLAG_COW)
8282 +               flags |= FS_COW_FL;
8283         return flags;
8284  }
8285  
8286 @@ -767,7 +791,7 @@ xfs_ip2xflags(
8287  {
8288         xfs_icdinode_t          *dic = &ip->i_d;
8289  
8290 -       return _xfs_dic2xflags(dic->di_flags) |
8291 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8292                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8293  }
8294  
8295 @@ -775,7 +799,8 @@ uint
8296  xfs_dic2xflags(
8297         xfs_dinode_t            *dip)
8298  {
8299 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8300 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8301 +                               be16_to_cpu(dip->di_vflags)) |
8302                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8303  }
8304  
8305 @@ -808,7 +833,6 @@ xfs_iread(
8306         if (error)
8307                 return error;
8308         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8309 -
8310         /*
8311          * If we got something that isn't an inode it means someone
8312          * (nfs or dmi) has a stale handle.
8313 @@ -833,7 +857,8 @@ xfs_iread(
8314          * Otherwise, just get the truly permanent information.
8315          */
8316         if (dip->di_mode) {
8317 -               xfs_dinode_from_disk(&ip->i_d, dip);
8318 +               xfs_dinode_from_disk(&ip->i_d, dip,
8319 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8320                 error = xfs_iformat(ip, dip);
8321                 if (error)  {
8322  #ifdef DEBUG
8323 @@ -1033,6 +1058,7 @@ xfs_ialloc(
8324         ASSERT(ip->i_d.di_nlink == nlink);
8325         ip->i_d.di_uid = current_fsuid();
8326         ip->i_d.di_gid = current_fsgid();
8327 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8328         ip->i_d.di_projid = prid;
8329         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8330  
8331 @@ -1093,6 +1119,7 @@ xfs_ialloc(
8332         ip->i_d.di_dmevmask = 0;
8333         ip->i_d.di_dmstate = 0;
8334         ip->i_d.di_flags = 0;
8335 +       ip->i_d.di_vflags = 0;
8336         flags = XFS_ILOG_CORE;
8337         switch (mode & S_IFMT) {
8338         case S_IFIFO:
8339 @@ -2116,6 +2143,7 @@ xfs_ifree(
8340         }
8341         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8342         ip->i_d.di_flags = 0;
8343 +       ip->i_d.di_vflags = 0;
8344         ip->i_d.di_dmevmask = 0;
8345         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8346         ip->i_df.if_ext_max =
8347 @@ -2985,7 +3013,8 @@ xfs_iflush_int(
8348          * because if the inode is dirty at all the core must
8349          * be.
8350          */
8351 -       xfs_dinode_to_disk(dip, &ip->i_d);
8352 +       xfs_dinode_to_disk(dip, &ip->i_d,
8353 +               mp->m_flags & XFS_MOUNT_TAGGED);
8354  
8355         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8356         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8357 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/xfs_inode.h linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_inode.h
8358 --- linux-2.6.35.4/fs/xfs/xfs_inode.h   2010-08-02 16:52:53.000000000 +0200
8359 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_inode.h     2010-08-02 17:05:06.000000000 +0200
8360 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8361         __uint32_t      di_gid;         /* owner's group id */
8362         __uint32_t      di_nlink;       /* number of links to file */
8363         __uint16_t      di_projid;      /* owner's project id */
8364 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8365 +       __uint16_t      di_tag;         /* context tagging */
8366 +       __uint16_t      di_vflags;      /* vserver specific flags */
8367 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8368         __uint16_t      di_flushiter;   /* incremented on flush */
8369         xfs_ictimestamp_t di_atime;     /* time last accessed */
8370         xfs_ictimestamp_t di_mtime;     /* time last modified */
8371 @@ -511,7 +513,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8372  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8373                           struct xfs_inode *, uint);
8374  void           xfs_dinode_to_disk(struct xfs_dinode *,
8375 -                                  struct xfs_icdinode *);
8376 +                                  struct xfs_icdinode *, int);
8377  void           xfs_idestroy_fork(struct xfs_inode *, int);
8378  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8379  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8380 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/xfs_itable.c linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_itable.c
8381 --- linux-2.6.35.4/fs/xfs/xfs_itable.c  2010-08-02 16:52:53.000000000 +0200
8382 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_itable.c    2010-08-02 17:05:06.000000000 +0200
8383 @@ -100,6 +100,7 @@ xfs_bulkstat_one_int(
8384         buf->bs_mode = dic->di_mode;
8385         buf->bs_uid = dic->di_uid;
8386         buf->bs_gid = dic->di_gid;
8387 +       buf->bs_tag = dic->di_tag;
8388         buf->bs_size = dic->di_size;
8389  
8390         /*
8391 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/xfs_log_recover.c linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_log_recover.c
8392 --- linux-2.6.35.4/fs/xfs/xfs_log_recover.c     2010-08-02 16:52:53.000000000 +0200
8393 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_log_recover.c       2010-08-02 17:05:06.000000000 +0200
8394 @@ -2461,7 +2461,8 @@ xlog_recover_do_inode_trans(
8395         }
8396  
8397         /* The core is in in-core format */
8398 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8399 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8400 +               mp->m_flags & XFS_MOUNT_TAGGED);
8401  
8402         /* the rest is in on-disk format */
8403         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8404 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/xfs_mount.h linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_mount.h
8405 --- linux-2.6.35.4/fs/xfs/xfs_mount.h   2010-08-02 16:52:53.000000000 +0200
8406 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_mount.h     2010-08-02 17:05:06.000000000 +0200
8407 @@ -302,6 +302,7 @@ typedef struct xfs_mount {
8408                                                    allocator */
8409  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8410  
8411 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8412  
8413  /*
8414   * Default minimum read and write sizes.
8415 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/xfs_vnodeops.c linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_vnodeops.c
8416 --- linux-2.6.35.4/fs/xfs/xfs_vnodeops.c        2010-08-02 16:52:53.000000000 +0200
8417 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_vnodeops.c  2010-08-02 17:05:06.000000000 +0200
8418 @@ -55,6 +55,80 @@
8419  #include "xfs_vnodeops.h"
8420  #include "xfs_trace.h"
8421  
8422 +
8423 +STATIC void
8424 +xfs_get_inode_flags(
8425 +       xfs_inode_t     *ip)
8426 +{
8427 +       struct inode    *inode = VFS_I(ip);
8428 +       unsigned int    flags = inode->i_flags;
8429 +       unsigned int    vflags = inode->i_vflags;
8430 +
8431 +       if (flags & S_IMMUTABLE)
8432 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8433 +       else
8434 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8435 +       if (flags & S_IXUNLINK)
8436 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8437 +       else
8438 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8439 +
8440 +       if (vflags & V_BARRIER)
8441 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8442 +       else
8443 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8444 +       if (vflags & V_COW)
8445 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8446 +       else
8447 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8448 +}
8449 +
8450 +int
8451 +xfs_sync_flags(
8452 +       struct inode            *inode,
8453 +       int                     flags,
8454 +       int                     vflags)
8455 +{
8456 +       struct xfs_inode        *ip = XFS_I(inode);
8457 +       struct xfs_mount        *mp = ip->i_mount;
8458 +       struct xfs_trans        *tp;
8459 +       unsigned int            lock_flags = 0;
8460 +       int                     code;
8461 +
8462 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8463 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8464 +       if (code)
8465 +               goto error_out;
8466 +
8467 +       lock_flags = XFS_ILOCK_EXCL;
8468 +       xfs_ilock(ip, lock_flags);
8469 +
8470 +       xfs_trans_ijoin(tp, ip, lock_flags);
8471 +       xfs_trans_ihold(tp, ip);
8472 +
8473 +       inode->i_flags = flags;
8474 +       inode->i_vflags = vflags;
8475 +       xfs_get_inode_flags(ip);
8476 +
8477 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8478 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8479 +
8480 +       XFS_STATS_INC(xs_ig_attrchg);
8481 +
8482 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8483 +               xfs_trans_set_sync(tp);
8484 +       code = xfs_trans_commit(tp, 0);
8485 +       xfs_iunlock(ip, lock_flags);
8486 +       return code;
8487 +
8488 +error_out:
8489 +       xfs_trans_cancel(tp, 0);
8490 +       if (lock_flags)
8491 +               xfs_iunlock(ip, lock_flags);
8492 +       return code;
8493 +}
8494 +
8495 +
8496  int
8497  xfs_setattr(
8498         struct xfs_inode        *ip,
8499 @@ -70,6 +144,7 @@ xfs_setattr(
8500         uint                    commit_flags=0;
8501         uid_t                   uid=0, iuid=0;
8502         gid_t                   gid=0, igid=0;
8503 +       tag_t                   tag=0, itag=0;
8504         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8505         int                     need_iolock = 1;
8506  
8507 @@ -162,7 +237,7 @@ xfs_setattr(
8508         /*
8509          * Change file ownership.  Must be the owner or privileged.
8510          */
8511 -       if (mask & (ATTR_UID|ATTR_GID)) {
8512 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8513                 /*
8514                  * These IDs could have changed since we last looked at them.
8515                  * But, we're assured that if the ownership did change
8516 @@ -171,8 +246,10 @@ xfs_setattr(
8517                  */
8518                 iuid = ip->i_d.di_uid;
8519                 igid = ip->i_d.di_gid;
8520 +               itag = ip->i_d.di_tag;
8521                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8522                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8523 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8524  
8525                 /*
8526                  * Do a quota reservation only if uid/gid is actually
8527 @@ -180,7 +257,8 @@ xfs_setattr(
8528                  */
8529                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8530                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8531 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8532 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8533 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8534                         ASSERT(tp);
8535                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8536                                                 capable(CAP_FOWNER) ?
8537 @@ -341,7 +419,7 @@ xfs_setattr(
8538         /*
8539          * Change file ownership.  Must be the owner or privileged.
8540          */
8541 -       if (mask & (ATTR_UID|ATTR_GID)) {
8542 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8543                 /*
8544                  * CAP_FSETID overrides the following restrictions:
8545                  *
8546 @@ -357,6 +435,10 @@ xfs_setattr(
8547                  * Change the ownerships and register quota modifications
8548                  * in the transaction.
8549                  */
8550 +               if (itag != tag) {
8551 +                       ip->i_d.di_tag = tag;
8552 +                       inode->i_tag = tag;
8553 +               }
8554                 if (iuid != uid) {
8555                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8556                                 ASSERT(mask & ATTR_UID);
8557 diff -NurpP --minimal linux-2.6.35.4/fs/xfs/xfs_vnodeops.h linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_vnodeops.h
8558 --- linux-2.6.35.4/fs/xfs/xfs_vnodeops.h        2010-07-07 18:31:54.000000000 +0200
8559 +++ linux-2.6.35.4-vs2.3.0.36.32/fs/xfs/xfs_vnodeops.h  2010-08-02 17:05:06.000000000 +0200
8560 @@ -14,6 +14,7 @@ struct xfs_inode;
8561  struct xfs_iomap;
8562  
8563  
8564 +int xfs_sync_xflags(struct xfs_inode *ip);
8565  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8566  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8567  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8568 diff -NurpP --minimal linux-2.6.35.4/include/asm-generic/tlb.h linux-2.6.35.4-vs2.3.0.36.32/include/asm-generic/tlb.h
8569 --- linux-2.6.35.4/include/asm-generic/tlb.h    2009-09-10 15:26:24.000000000 +0200
8570 +++ linux-2.6.35.4-vs2.3.0.36.32/include/asm-generic/tlb.h      2010-08-02 17:05:06.000000000 +0200
8571 @@ -14,6 +14,7 @@
8572  #define _ASM_GENERIC__TLB_H
8573  
8574  #include <linux/swap.h>
8575 +#include <linux/vs_memory.h>
8576  #include <asm/pgalloc.h>
8577  #include <asm/tlbflush.h>
8578  
8579 diff -NurpP --minimal linux-2.6.35.4/include/linux/capability.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/capability.h
8580 --- linux-2.6.35.4/include/linux/capability.h   2010-02-25 11:52:07.000000000 +0100
8581 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/capability.h     2010-08-02 17:05:06.000000000 +0200
8582 @@ -283,6 +283,7 @@ struct cpu_vfs_cap_data {
8583     arbitrary SCSI commands */
8584  /* Allow setting encryption key on loopback filesystem */
8585  /* Allow setting zone reclaim policy */
8586 +/* Allow the selection of a security context */
8587  
8588  #define CAP_SYS_ADMIN        21
8589  
8590 @@ -355,7 +356,13 @@ struct cpu_vfs_cap_data {
8591  
8592  #define CAP_MAC_ADMIN        33
8593  
8594 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8595 +/* Allow context manipulations */
8596 +/* Allow changing context info on files */
8597 +
8598 +#define CAP_CONTEXT         34
8599 +
8600 +
8601 +#define CAP_LAST_CAP         CAP_CONTEXT
8602  
8603  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8604  
8605 diff -NurpP --minimal linux-2.6.35.4/include/linux/devpts_fs.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/devpts_fs.h
8606 --- linux-2.6.35.4/include/linux/devpts_fs.h    2008-12-25 00:26:37.000000000 +0100
8607 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/devpts_fs.h      2010-08-02 17:05:06.000000000 +0200
8608 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8609  
8610  #endif
8611  
8612 -
8613  #endif /* _LINUX_DEVPTS_FS_H */
8614 diff -NurpP --minimal linux-2.6.35.4/include/linux/ext2_fs.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/ext2_fs.h
8615 --- linux-2.6.35.4/include/linux/ext2_fs.h      2010-02-25 11:52:07.000000000 +0100
8616 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/ext2_fs.h        2010-08-02 17:05:06.000000000 +0200
8617 @@ -189,8 +189,12 @@ struct ext2_group_desc
8618  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8619  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8620  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8621 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8622  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8623  
8624 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8625 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8626 +
8627  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8628  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8629  
8630 @@ -274,7 +278,8 @@ struct ext2_inode {
8631                         __u16   i_pad1;
8632                         __le16  l_i_uid_high;   /* these 2 fields    */
8633                         __le16  l_i_gid_high;   /* were reserved2[0] */
8634 -                       __u32   l_i_reserved2;
8635 +                       __le16  l_i_tag;        /* Context Tag */
8636 +                       __u16   l_i_reserved2;
8637                 } linux2;
8638                 struct {
8639                         __u8    h_i_frag;       /* Fragment number */
8640 @@ -303,6 +308,7 @@ struct ext2_inode {
8641  #define i_gid_low      i_gid
8642  #define i_uid_high     osd2.linux2.l_i_uid_high
8643  #define i_gid_high     osd2.linux2.l_i_gid_high
8644 +#define i_raw_tag      osd2.linux2.l_i_tag
8645  #define i_reserved2    osd2.linux2.l_i_reserved2
8646  #endif
8647  
8648 @@ -347,6 +353,7 @@ struct ext2_inode {
8649  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8650  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8651  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8652 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8653  
8654  
8655  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8656 diff -NurpP --minimal linux-2.6.35.4/include/linux/ext3_fs.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/ext3_fs.h
8657 --- linux-2.6.35.4/include/linux/ext3_fs.h      2010-08-02 16:52:54.000000000 +0200
8658 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/ext3_fs.h        2010-08-02 17:05:06.000000000 +0200
8659 @@ -173,10 +173,14 @@ struct ext3_group_desc
8660  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8661  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8662  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8663 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8664  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8665  
8666 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8667 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8668 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8669 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8670 +
8671 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8672 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8673  
8674  /* Flags that should be inherited by new inodes from their parent. */
8675  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8676 @@ -312,7 +316,8 @@ struct ext3_inode {
8677                         __u16   i_pad1;
8678                         __le16  l_i_uid_high;   /* these 2 fields    */
8679                         __le16  l_i_gid_high;   /* were reserved2[0] */
8680 -                       __u32   l_i_reserved2;
8681 +                       __le16  l_i_tag;        /* Context Tag */
8682 +                       __u16   l_i_reserved2;
8683                 } linux2;
8684                 struct {
8685                         __u8    h_i_frag;       /* Fragment number */
8686 @@ -343,6 +348,7 @@ struct ext3_inode {
8687  #define i_gid_low      i_gid
8688  #define i_uid_high     osd2.linux2.l_i_uid_high
8689  #define i_gid_high     osd2.linux2.l_i_gid_high
8690 +#define i_raw_tag      osd2.linux2.l_i_tag
8691  #define i_reserved2    osd2.linux2.l_i_reserved2
8692  
8693  #elif defined(__GNU__)
8694 @@ -406,6 +412,7 @@ struct ext3_inode {
8695  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8696  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8697                                                   * error in ordered mode */
8698 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8699  
8700  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8701  #ifndef _LINUX_EXT2_FS_H
8702 @@ -909,6 +916,7 @@ extern void ext3_get_inode_flags(struct 
8703  extern void ext3_set_aops(struct inode *inode);
8704  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8705                        u64 start, u64 len);
8706 +extern int ext3_sync_flags(struct inode *, int, int);
8707  
8708  /* ioctl.c */
8709  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8710 diff -NurpP --minimal linux-2.6.35.4/include/linux/fs.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/fs.h
8711 --- linux-2.6.35.4/include/linux/fs.h   2010-09-05 01:41:57.000000000 +0200
8712 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/fs.h     2010-08-14 18:21:44.000000000 +0200
8713 @@ -209,6 +209,9 @@ struct inodes_stat_t {
8714  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8715  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8716  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8717 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8718 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8719 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8720  #define MS_BORN                (1<<29)
8721  #define MS_ACTIVE      (1<<30)
8722  #define MS_NOUSER      (1<<31)
8723 @@ -236,6 +239,14 @@ struct inodes_stat_t {
8724  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8725  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8726  #define S_PRIVATE      512     /* Inode is fs-internal */
8727 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8728 +
8729 +/* Linux-VServer related Inode flags */
8730 +
8731 +#define V_VALID                1
8732 +#define V_XATTR                2
8733 +#define V_BARRIER      4       /* Barrier for chroot() */
8734 +#define V_COW          8       /* Copy on Write */
8735  
8736  /*
8737   * Note that nosuid etc flags are inode-specific: setting some file-system
8738 @@ -258,12 +269,15 @@ struct inodes_stat_t {
8739  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8740                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8741  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8742 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8743 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8744 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8745 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8746 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8747  
8748  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8749  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8750  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8751 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8752 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8753  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8754  
8755  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8756 @@ -271,6 +285,16 @@ struct inodes_stat_t {
8757  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8758  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8759  
8760 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8761 +
8762 +#ifdef CONFIG_VSERVER_COWBL
8763 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8764 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8765 +#else
8766 +#  define IS_COW(inode)                (0)
8767 +#  define IS_COW_LINK(inode)   (0)
8768 +#endif
8769 +
8770  /* the read-only stuff doesn't really belong here, but any other place is
8771     probably as bad and I don't want to create yet another include file. */
8772  
8773 @@ -353,11 +377,14 @@ struct inodes_stat_t {
8774  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8775  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8776  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8777 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8778  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8779  
8780 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8781 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8782 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8783 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8784  
8785 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8786 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8787  
8788  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8789  #define SYNC_FILE_RANGE_WRITE          2
8790 @@ -439,6 +466,7 @@ typedef void (dio_iodone_t)(struct kiocb
8791  #define ATTR_KILL_PRIV (1 << 14)
8792  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8793  #define ATTR_TIMES_SET (1 << 16)
8794 +#define ATTR_TAG       (1 << 17)
8795  
8796  /*
8797   * This is the Inode Attributes structure, used for notify_change().  It
8798 @@ -454,6 +482,7 @@ struct iattr {
8799         umode_t         ia_mode;
8800         uid_t           ia_uid;
8801         gid_t           ia_gid;
8802 +       tag_t           ia_tag;
8803         loff_t          ia_size;
8804         struct timespec ia_atime;
8805         struct timespec ia_mtime;
8806 @@ -467,6 +496,9 @@ struct iattr {
8807         struct file     *ia_file;
8808  };
8809  
8810 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8811 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8812 +
8813  /*
8814   * Includes for diskquotas.
8815   */
8816 @@ -733,7 +765,9 @@ struct inode {
8817         unsigned int            i_nlink;
8818         uid_t                   i_uid;
8819         gid_t                   i_gid;
8820 +       tag_t                   i_tag;
8821         dev_t                   i_rdev;
8822 +       dev_t                   i_mdev;
8823         unsigned int            i_blkbits;
8824         u64                     i_version;
8825         loff_t                  i_size;
8826 @@ -780,7 +814,8 @@ struct inode {
8827         unsigned long           i_state;
8828         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8829  
8830 -       unsigned int            i_flags;
8831 +       unsigned short          i_flags;
8832 +       unsigned short          i_vflags;
8833  
8834         atomic_t                i_writecount;
8835  #ifdef CONFIG_SECURITY
8836 @@ -868,12 +903,12 @@ static inline void i_size_write(struct i
8837  
8838  static inline unsigned iminor(const struct inode *inode)
8839  {
8840 -       return MINOR(inode->i_rdev);
8841 +       return MINOR(inode->i_mdev);
8842  }
8843  
8844  static inline unsigned imajor(const struct inode *inode)
8845  {
8846 -       return MAJOR(inode->i_rdev);
8847 +       return MAJOR(inode->i_mdev);
8848  }
8849  
8850  extern struct block_device *I_BDEV(struct inode *inode);
8851 @@ -932,6 +967,7 @@ struct file {
8852         loff_t                  f_pos;
8853         struct fown_struct      f_owner;
8854         const struct cred       *f_cred;
8855 +       xid_t                   f_xid;
8856         struct file_ra_state    f_ra;
8857  
8858         u64                     f_version;
8859 @@ -1074,6 +1110,7 @@ struct file_lock {
8860         struct file *fl_file;
8861         loff_t fl_start;
8862         loff_t fl_end;
8863 +       xid_t fl_xid;
8864  
8865         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8866         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8867 @@ -1535,6 +1572,7 @@ struct inode_operations {
8868         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8869         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8870         int (*removexattr) (struct dentry *, const char *);
8871 +       int (*sync_flags) (struct inode *, int, int);
8872         void (*truncate_range)(struct inode *, loff_t, loff_t);
8873         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8874                           loff_t len);
8875 @@ -1555,6 +1593,7 @@ extern ssize_t vfs_readv(struct file *, 
8876                 unsigned long, loff_t *);
8877  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8878                 unsigned long, loff_t *);
8879 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8880  
8881  struct super_operations {
8882         struct inode *(*alloc_inode)(struct super_block *sb);
8883 @@ -2378,6 +2417,7 @@ extern int dcache_dir_open(struct inode 
8884  extern int dcache_dir_close(struct inode *, struct file *);
8885  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8886  extern int dcache_readdir(struct file *, void *, filldir_t);
8887 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8888  extern int simple_setattr(struct dentry *, struct iattr *);
8889  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8890  extern int simple_statfs(struct dentry *, struct kstatfs *);
8891 diff -NurpP --minimal linux-2.6.35.4/include/linux/gfs2_ondisk.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/gfs2_ondisk.h
8892 --- linux-2.6.35.4/include/linux/gfs2_ondisk.h  2010-07-07 18:31:55.000000000 +0200
8893 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/gfs2_ondisk.h    2010-08-02 17:05:06.000000000 +0200
8894 @@ -211,6 +211,9 @@ enum {
8895         gfs2fl_NoAtime          = 7,
8896         gfs2fl_Sync             = 8,
8897         gfs2fl_System           = 9,
8898 +       gfs2fl_IXUnlink         = 16,
8899 +       gfs2fl_Barrier          = 17,
8900 +       gfs2fl_Cow              = 18,
8901         gfs2fl_TruncInProg      = 29,
8902         gfs2fl_InheritDirectio  = 30,
8903         gfs2fl_InheritJdata     = 31,
8904 @@ -227,6 +230,9 @@ enum {
8905  #define GFS2_DIF_NOATIME               0x00000080
8906  #define GFS2_DIF_SYNC                  0x00000100
8907  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8908 +#define GFS2_DIF_IXUNLINK              0x00010000
8909 +#define GFS2_DIF_BARRIER               0x00020000
8910 +#define GFS2_DIF_COW                   0x00040000
8911  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8912  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8913  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8914 diff -NurpP --minimal linux-2.6.35.4/include/linux/if_tun.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/if_tun.h
8915 --- linux-2.6.35.4/include/linux/if_tun.h       2010-08-02 16:52:54.000000000 +0200
8916 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/if_tun.h 2010-08-02 18:17:46.000000000 +0200
8917 @@ -53,6 +53,7 @@
8918  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8919  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8920  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8921 +#define TUNSETNID     _IOW('T', 217, int)
8922  
8923  /* TUNSETIFF ifr flags */
8924  #define IFF_TUN                0x0001
8925 diff -NurpP --minimal linux-2.6.35.4/include/linux/init_task.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/init_task.h
8926 --- linux-2.6.35.4/include/linux/init_task.h    2010-08-02 16:52:54.000000000 +0200
8927 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/init_task.h      2010-08-02 17:05:06.000000000 +0200
8928 @@ -172,6 +172,10 @@ extern struct cred init_cred;
8929         INIT_FTRACE_GRAPH                                               \
8930         INIT_TRACE_RECURSION                                            \
8931         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8932 +       .xid            = 0,                                            \
8933 +       .vx_info        = NULL,                                         \
8934 +       .nid            = 0,                                            \
8935 +       .nx_info        = NULL,                                         \
8936  }
8937  
8938  
8939 diff -NurpP --minimal linux-2.6.35.4/include/linux/ipc.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/ipc.h
8940 --- linux-2.6.35.4/include/linux/ipc.h  2009-12-03 20:02:55.000000000 +0100
8941 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/ipc.h    2010-08-02 17:05:06.000000000 +0200
8942 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8943         key_t           key;
8944         uid_t           uid;
8945         gid_t           gid;
8946 +       xid_t           xid;
8947         uid_t           cuid;
8948         gid_t           cgid;
8949         mode_t          mode; 
8950 diff -NurpP --minimal linux-2.6.35.4/include/linux/Kbuild linux-2.6.35.4-vs2.3.0.36.32/include/linux/Kbuild
8951 --- linux-2.6.35.4/include/linux/Kbuild 2010-09-05 01:41:57.000000000 +0200
8952 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/Kbuild   2010-08-14 18:19:32.000000000 +0200
8953 @@ -388,5 +388,8 @@ unifdef-y += xattr.h
8954  unifdef-y += xfrm.h
8955  
8956  objhdr-y += version.h
8957 +
8958 +header-y += vserver/
8959  header-y += wimax.h
8960  header-y += wimax/
8961 +
8962 diff -NurpP --minimal linux-2.6.35.4/include/linux/loop.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/loop.h
8963 --- linux-2.6.35.4/include/linux/loop.h 2009-09-10 15:26:25.000000000 +0200
8964 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/loop.h   2010-08-02 17:05:06.000000000 +0200
8965 @@ -45,6 +45,7 @@ struct loop_device {
8966         struct loop_func_table *lo_encryption;
8967         __u32           lo_init[2];
8968         uid_t           lo_key_owner;   /* Who set the key */
8969 +       xid_t           lo_xid;
8970         int             (*ioctl)(struct loop_device *, int cmd, 
8971                                  unsigned long arg); 
8972  
8973 diff -NurpP --minimal linux-2.6.35.4/include/linux/magic.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/magic.h
8974 --- linux-2.6.35.4/include/linux/magic.h        2010-07-07 18:31:55.000000000 +0200
8975 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/magic.h  2010-08-02 17:05:06.000000000 +0200
8976 @@ -3,7 +3,7 @@
8977  
8978  #define ADFS_SUPER_MAGIC       0xadf5
8979  #define AFFS_SUPER_MAGIC       0xadff
8980 -#define AFS_SUPER_MAGIC                0x5346414F
8981 +#define AFS_SUPER_MAGIC                0x5346414F
8982  #define AUTOFS_SUPER_MAGIC     0x0187
8983  #define CODA_SUPER_MAGIC       0x73757245
8984  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8985 @@ -38,6 +38,7 @@
8986  #define NFS_SUPER_MAGIC                0x6969
8987  #define OPENPROM_SUPER_MAGIC   0x9fa1
8988  #define PROC_SUPER_MAGIC       0x9fa0
8989 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8990  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8991  
8992  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8993 diff -NurpP --minimal linux-2.6.35.4/include/linux/major.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/major.h
8994 --- linux-2.6.35.4/include/linux/major.h        2009-09-10 15:26:25.000000000 +0200
8995 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/major.h  2010-08-02 17:05:06.000000000 +0200
8996 @@ -15,6 +15,7 @@
8997  #define HD_MAJOR               IDE0_MAJOR
8998  #define PTY_SLAVE_MAJOR                3
8999  #define TTY_MAJOR              4
9000 +#define VROOT_MAJOR            4
9001  #define TTYAUX_MAJOR           5
9002  #define LP_MAJOR               6
9003  #define VCS_MAJOR              7
9004 diff -NurpP --minimal linux-2.6.35.4/include/linux/memcontrol.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/memcontrol.h
9005 --- linux-2.6.35.4/include/linux/memcontrol.h   2010-08-02 16:52:54.000000000 +0200
9006 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/memcontrol.h     2010-08-02 17:05:06.000000000 +0200
9007 @@ -77,6 +77,13 @@ int task_in_mem_cgroup(struct task_struc
9008  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
9009  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
9010  
9011 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
9012 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
9013 +
9014 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
9015 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
9016 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
9017 +
9018  static inline
9019  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
9020  {
9021 diff -NurpP --minimal linux-2.6.35.4/include/linux/mm_types.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/mm_types.h
9022 --- linux-2.6.35.4/include/linux/mm_types.h     2010-09-05 01:41:57.000000000 +0200
9023 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/mm_types.h       2010-09-06 02:59:52.000000000 +0200
9024 @@ -269,6 +269,7 @@ struct mm_struct {
9025  
9026         /* Architecture-specific MM context */
9027         mm_context_t context;
9028 +       struct vx_info *mm_vx_info;
9029  
9030         /* Swap token stuff */
9031         /*
9032 diff -NurpP --minimal linux-2.6.35.4/include/linux/mount.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/mount.h
9033 --- linux-2.6.35.4/include/linux/mount.h        2010-07-07 18:31:56.000000000 +0200
9034 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/mount.h  2010-08-02 17:05:06.000000000 +0200
9035 @@ -47,6 +47,9 @@ struct mnt_namespace;
9036  
9037  #define MNT_INTERNAL   0x4000
9038  
9039 +#define MNT_TAGID      0x10000
9040 +#define MNT_NOTAG      0x20000
9041 +
9042  struct vfsmount {
9043         struct list_head mnt_hash;
9044         struct vfsmount *mnt_parent;    /* fs we are mounted on */
9045 @@ -81,6 +84,7 @@ struct vfsmount {
9046  #else
9047         int mnt_writers;
9048  #endif
9049 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9050  };
9051  
9052  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
9053 diff -NurpP --minimal linux-2.6.35.4/include/linux/net.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/net.h
9054 --- linux-2.6.35.4/include/linux/net.h  2010-08-02 16:52:55.000000000 +0200
9055 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/net.h    2010-08-02 17:05:06.000000000 +0200
9056 @@ -71,6 +71,7 @@ struct net;
9057  #define SOCK_NOSPACE           2
9058  #define SOCK_PASSCRED          3
9059  #define SOCK_PASSSEC           4
9060 +#define SOCK_USER_SOCKET       5
9061  
9062  #ifndef ARCH_HAS_SOCKET_TYPES
9063  /**
9064 diff -NurpP --minimal linux-2.6.35.4/include/linux/nfs_mount.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/nfs_mount.h
9065 --- linux-2.6.35.4/include/linux/nfs_mount.h    2009-03-24 14:22:43.000000000 +0100
9066 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/nfs_mount.h      2010-08-02 17:05:06.000000000 +0200
9067 @@ -63,7 +63,8 @@ struct nfs_mount_data {
9068  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9069  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9070  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9071 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9072 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9073 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9074  
9075  /* The following are for internal use only */
9076  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9077 diff -NurpP --minimal linux-2.6.35.4/include/linux/nsproxy.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/nsproxy.h
9078 --- linux-2.6.35.4/include/linux/nsproxy.h      2009-06-11 17:13:17.000000000 +0200
9079 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/nsproxy.h        2010-08-02 17:05:06.000000000 +0200
9080 @@ -3,6 +3,7 @@
9081  
9082  #include <linux/spinlock.h>
9083  #include <linux/sched.h>
9084 +#include <linux/vserver/debug.h>
9085  
9086  struct mnt_namespace;
9087  struct uts_namespace;
9088 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9089  }
9090  
9091  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9092 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9093  void exit_task_namespaces(struct task_struct *tsk);
9094  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9095  void free_nsproxy(struct nsproxy *ns);
9096  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9097         struct fs_struct *);
9098  
9099 -static inline void put_nsproxy(struct nsproxy *ns)
9100 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9101 +
9102 +static inline void __get_nsproxy(struct nsproxy *ns,
9103 +       const char *_file, int _line)
9104  {
9105 -       if (atomic_dec_and_test(&ns->count)) {
9106 -               free_nsproxy(ns);
9107 -       }
9108 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9109 +               ns, atomic_read(&ns->count), _file, _line);
9110 +       atomic_inc(&ns->count);
9111  }
9112  
9113 -static inline void get_nsproxy(struct nsproxy *ns)
9114 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9115 +
9116 +static inline void __put_nsproxy(struct nsproxy *ns,
9117 +       const char *_file, int _line)
9118  {
9119 -       atomic_inc(&ns->count);
9120 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9121 +               ns, atomic_read(&ns->count), _file, _line);
9122 +       if (atomic_dec_and_test(&ns->count)) {
9123 +               free_nsproxy(ns);
9124 +       }
9125  }
9126  
9127  #ifdef CONFIG_CGROUP_NS
9128 diff -NurpP --minimal linux-2.6.35.4/include/linux/pid.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/pid.h
9129 --- linux-2.6.35.4/include/linux/pid.h  2009-03-24 14:22:43.000000000 +0100
9130 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/pid.h    2010-08-02 17:05:06.000000000 +0200
9131 @@ -8,7 +8,8 @@ enum pid_type
9132         PIDTYPE_PID,
9133         PIDTYPE_PGID,
9134         PIDTYPE_SID,
9135 -       PIDTYPE_MAX
9136 +       PIDTYPE_MAX,
9137 +       PIDTYPE_REALPID
9138  };
9139  
9140  /*
9141 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9142  }
9143  
9144  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9145 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9146  pid_t pid_vnr(struct pid *pid);
9147  
9148  #define do_each_pid_task(pid, type, task)                              \
9149 diff -NurpP --minimal linux-2.6.35.4/include/linux/proc_fs.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/proc_fs.h
9150 --- linux-2.6.35.4/include/linux/proc_fs.h      2009-12-03 20:02:56.000000000 +0100
9151 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/proc_fs.h        2010-08-02 17:05:06.000000000 +0200
9152 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9153         nlink_t nlink;
9154         uid_t uid;
9155         gid_t gid;
9156 +       int vx_flags;
9157         loff_t size;
9158         const struct inode_operations *proc_iops;
9159         /*
9160 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9161  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9162  #endif
9163  
9164 +struct vx_info;
9165 +struct nx_info;
9166 +
9167  union proc_op {
9168         int (*proc_get_link)(struct inode *, struct path *);
9169         int (*proc_read)(struct task_struct *task, char *page);
9170         int (*proc_show)(struct seq_file *m,
9171                 struct pid_namespace *ns, struct pid *pid,
9172                 struct task_struct *task);
9173 +       int (*proc_vs_read)(char *page);
9174 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9175 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9176  };
9177  
9178  struct ctl_table_header;
9179 @@ -263,6 +270,7 @@ struct ctl_table;
9180  
9181  struct proc_inode {
9182         struct pid *pid;
9183 +       int vx_flags;
9184         int fd;
9185         union proc_op op;
9186         struct proc_dir_entry *pde;
9187 diff -NurpP --minimal linux-2.6.35.4/include/linux/quotaops.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/quotaops.h
9188 --- linux-2.6.35.4/include/linux/quotaops.h     2010-08-02 16:52:55.000000000 +0200
9189 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/quotaops.h       2010-08-02 22:35:47.000000000 +0200
9190 @@ -8,6 +8,7 @@
9191  #define _LINUX_QUOTAOPS_
9192  
9193  #include <linux/fs.h>
9194 +#include <linux/vs_dlimit.h>
9195  
9196  #define DQUOT_SPACE_WARN       0x1
9197  #define DQUOT_SPACE_RESERVE    0x2
9198 @@ -209,11 +210,12 @@ static inline void dquot_drop(struct ino
9199  
9200  static inline int dquot_alloc_inode(const struct inode *inode)
9201  {
9202 -       return 0;
9203 +       return dl_alloc_inode(inode);
9204  }
9205  
9206  static inline void dquot_free_inode(const struct inode *inode)
9207  {
9208 +       dl_free_inode(inode);
9209  }
9210  
9211  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
9212 @@ -224,6 +226,10 @@ static inline int dquot_transfer(struct 
9213  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
9214                 int flags)
9215  {
9216 +       int ret = 0;
9217 +
9218 +       if ((ret = dl_alloc_space(inode, number)))
9219 +               return ret;
9220         if (!(flags & DQUOT_SPACE_RESERVE))
9221                 inode_add_bytes(inode, number);
9222         return 0;
9223 @@ -234,6 +240,7 @@ static inline void __dquot_free_space(st
9224  {
9225         if (!(flags & DQUOT_SPACE_RESERVE))
9226                 inode_sub_bytes(inode, number);
9227 +       dl_free_space(inode, number);
9228  }
9229  
9230  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
9231 diff -NurpP --minimal linux-2.6.35.4/include/linux/reboot.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/reboot.h
9232 --- linux-2.6.35.4/include/linux/reboot.h       2010-07-07 18:31:56.000000000 +0200
9233 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/reboot.h 2010-08-02 17:05:06.000000000 +0200
9234 @@ -33,6 +33,7 @@
9235  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9236  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9237  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9238 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9239  
9240  
9241  #ifdef __KERNEL__
9242 diff -NurpP --minimal linux-2.6.35.4/include/linux/reiserfs_fs.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/reiserfs_fs.h
9243 --- linux-2.6.35.4/include/linux/reiserfs_fs.h  2010-07-07 18:31:56.000000000 +0200
9244 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/reiserfs_fs.h    2010-08-02 17:05:06.000000000 +0200
9245 @@ -977,6 +977,11 @@ struct stat_data_v1 {
9246  #define REISERFS_COMPR_FL     FS_COMPR_FL
9247  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9248  
9249 +/* unfortunately reiserfs sdattr is only 16 bit */
9250 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9251 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9252 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9253 +
9254  /* persistent flags that file inherits from the parent directory */
9255  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9256                                 REISERFS_SYNC_FL |      \
9257 @@ -986,6 +991,9 @@ struct stat_data_v1 {
9258                                 REISERFS_COMPR_FL |     \
9259                                 REISERFS_NOTAIL_FL )
9260  
9261 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9262 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9263 +
9264  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9265     address blocks) */
9266  struct stat_data {
9267 @@ -2071,6 +2079,7 @@ static inline void reiserfs_update_sd(st
9268  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9269  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9270  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9271 +int reiserfs_sync_flags(struct inode *inode, int, int);
9272  
9273  /* namei.c */
9274  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9275 diff -NurpP --minimal linux-2.6.35.4/include/linux/reiserfs_fs_sb.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/reiserfs_fs_sb.h
9276 --- linux-2.6.35.4/include/linux/reiserfs_fs_sb.h       2010-02-25 11:52:07.000000000 +0100
9277 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/reiserfs_fs_sb.h 2010-08-02 17:05:06.000000000 +0200
9278 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9279         REISERFS_EXPOSE_PRIVROOT,
9280         REISERFS_BARRIER_NONE,
9281         REISERFS_BARRIER_FLUSH,
9282 +       REISERFS_TAGGED,
9283  
9284         /* Actions on error */
9285         REISERFS_ERROR_PANIC,
9286 diff -NurpP --minimal linux-2.6.35.4/include/linux/sched.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/sched.h
9287 --- linux-2.6.35.4/include/linux/sched.h        2010-09-05 01:41:57.000000000 +0200
9288 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/sched.h  2010-08-14 18:19:32.000000000 +0200
9289 @@ -1343,6 +1343,14 @@ struct task_struct {
9290  #endif
9291         seccomp_t seccomp;
9292  
9293 +/* vserver context data */
9294 +       struct vx_info *vx_info;
9295 +       struct nx_info *nx_info;
9296 +
9297 +       xid_t xid;
9298 +       nid_t nid;
9299 +       tag_t tag;
9300 +
9301  /* Thread group tracking */
9302         u32 parent_exec_id;
9303         u32 self_exec_id;
9304 @@ -1577,6 +1585,11 @@ struct pid_namespace;
9305  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9306                         struct pid_namespace *ns);
9307  
9308 +#include <linux/vserver/base.h>
9309 +#include <linux/vserver/context.h>
9310 +#include <linux/vserver/debug.h>
9311 +#include <linux/vserver/pid.h>
9312 +
9313  static inline pid_t task_pid_nr(struct task_struct *tsk)
9314  {
9315         return tsk->pid;
9316 @@ -1590,7 +1603,8 @@ static inline pid_t task_pid_nr_ns(struc
9317  
9318  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9319  {
9320 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9321 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9322 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9323  }
9324  
9325  
9326 @@ -1603,7 +1617,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9327  
9328  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9329  {
9330 -       return pid_vnr(task_tgid(tsk));
9331 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9332  }
9333  
9334  
9335 diff -NurpP --minimal linux-2.6.35.4/include/linux/shmem_fs.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/shmem_fs.h
9336 --- linux-2.6.35.4/include/linux/shmem_fs.h     2010-02-25 11:52:08.000000000 +0100
9337 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/shmem_fs.h       2010-08-02 17:05:06.000000000 +0200
9338 @@ -8,6 +8,9 @@
9339  
9340  #define SHMEM_NR_DIRECT 16
9341  
9342 +#define TMPFS_SUPER_MAGIC      0x01021994
9343 +
9344 +
9345  struct shmem_inode_info {
9346         spinlock_t              lock;
9347         unsigned long           flags;
9348 diff -NurpP --minimal linux-2.6.35.4/include/linux/stat.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/stat.h
9349 --- linux-2.6.35.4/include/linux/stat.h 2008-12-25 00:26:37.000000000 +0100
9350 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/stat.h   2010-08-02 17:05:06.000000000 +0200
9351 @@ -66,6 +66,7 @@ struct kstat {
9352         unsigned int    nlink;
9353         uid_t           uid;
9354         gid_t           gid;
9355 +       tag_t           tag;
9356         dev_t           rdev;
9357         loff_t          size;
9358         struct timespec  atime;
9359 diff -NurpP --minimal linux-2.6.35.4/include/linux/sunrpc/auth.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/sunrpc/auth.h
9360 --- linux-2.6.35.4/include/linux/sunrpc/auth.h  2010-08-02 16:52:56.000000000 +0200
9361 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/sunrpc/auth.h    2010-08-02 17:05:06.000000000 +0200
9362 @@ -25,6 +25,7 @@
9363  struct auth_cred {
9364         uid_t   uid;
9365         gid_t   gid;
9366 +       tag_t   tag;
9367         struct group_info *group_info;
9368         unsigned char machine_cred : 1;
9369  };
9370 diff -NurpP --minimal linux-2.6.35.4/include/linux/sunrpc/clnt.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/sunrpc/clnt.h
9371 --- linux-2.6.35.4/include/linux/sunrpc/clnt.h  2009-12-03 20:02:56.000000000 +0100
9372 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/sunrpc/clnt.h    2010-08-02 17:05:06.000000000 +0200
9373 @@ -49,7 +49,8 @@ struct rpc_clnt {
9374         unsigned int            cl_softrtry : 1,/* soft timeouts */
9375                                 cl_discrtry : 1,/* disconnect before retry */
9376                                 cl_autobind : 1,/* use getport() */
9377 -                               cl_chatty   : 1;/* be verbose */
9378 +                               cl_chatty   : 1,/* be verbose */
9379 +                               cl_tag      : 1;/* context tagging */
9380  
9381         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9382         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9383 diff -NurpP --minimal linux-2.6.35.4/include/linux/syscalls.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/syscalls.h
9384 --- linux-2.6.35.4/include/linux/syscalls.h     2010-08-02 16:52:56.000000000 +0200
9385 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/syscalls.h       2010-08-02 17:05:06.000000000 +0200
9386 @@ -479,6 +479,8 @@ asmlinkage long sys_symlink(const char _
9387  asmlinkage long sys_unlink(const char __user *pathname);
9388  asmlinkage long sys_rename(const char __user *oldname,
9389                                 const char __user *newname);
9390 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9391 +                               umode_t mode);
9392  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9393  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9394  
9395 diff -NurpP --minimal linux-2.6.35.4/include/linux/sysctl.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/sysctl.h
9396 --- linux-2.6.35.4/include/linux/sysctl.h       2010-08-02 16:52:56.000000000 +0200
9397 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/sysctl.h 2010-08-02 17:05:06.000000000 +0200
9398 @@ -60,6 +60,7 @@ enum
9399         CTL_ABI=9,              /* Binary emulation */
9400         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9401         CTL_ARLAN=254,          /* arlan wireless driver */
9402 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9403         CTL_S390DBF=5677,       /* s390 debug */
9404         CTL_SUNRPC=7249,        /* sunrpc debug */
9405         CTL_PM=9899,            /* frv power management */
9406 @@ -94,6 +95,7 @@ enum
9407  
9408         KERN_PANIC=15,          /* int: panic timeout */
9409         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9410 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9411  
9412         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9413         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9414 diff -NurpP --minimal linux-2.6.35.4/include/linux/sysfs.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/sysfs.h
9415 --- linux-2.6.35.4/include/linux/sysfs.h        2010-08-02 16:52:56.000000000 +0200
9416 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/sysfs.h  2010-08-02 17:05:06.000000000 +0200
9417 @@ -18,6 +18,8 @@
9418  #include <linux/lockdep.h>
9419  #include <asm/atomic.h>
9420  
9421 +#define SYSFS_SUPER_MAGIC      0x62656572
9422 +
9423  struct kobject;
9424  struct module;
9425  enum kobj_ns_type;
9426 diff -NurpP --minimal linux-2.6.35.4/include/linux/time.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/time.h
9427 --- linux-2.6.35.4/include/linux/time.h 2010-08-02 16:52:56.000000000 +0200
9428 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/time.h   2010-08-02 17:05:06.000000000 +0200
9429 @@ -237,6 +237,9 @@ static __always_inline void timespec_add
9430         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9431         a->tv_nsec = ns;
9432  }
9433 +
9434 +#include <linux/vs_time.h>
9435 +
9436  #endif /* __KERNEL__ */
9437  
9438  #define NFDBITS                        __NFDBITS
9439 diff -NurpP --minimal linux-2.6.35.4/include/linux/types.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/types.h
9440 --- linux-2.6.35.4/include/linux/types.h        2010-08-02 16:52:56.000000000 +0200
9441 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/types.h  2010-08-02 17:05:06.000000000 +0200
9442 @@ -37,6 +37,9 @@ typedef __kernel_uid32_t      uid_t;
9443  typedef __kernel_gid32_t       gid_t;
9444  typedef __kernel_uid16_t        uid16_t;
9445  typedef __kernel_gid16_t        gid16_t;
9446 +typedef unsigned int           xid_t;
9447 +typedef unsigned int           nid_t;
9448 +typedef unsigned int           tag_t;
9449  
9450  typedef unsigned long          uintptr_t;
9451  
9452 diff -NurpP --minimal linux-2.6.35.4/include/linux/vroot.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vroot.h
9453 --- linux-2.6.35.4/include/linux/vroot.h        1970-01-01 01:00:00.000000000 +0100
9454 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vroot.h  2010-08-02 17:05:06.000000000 +0200
9455 @@ -0,0 +1,51 @@
9456 +
9457 +/*
9458 + * include/linux/vroot.h
9459 + *
9460 + * written by Herbert Pötzl, 9/11/2002
9461 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9462 + *
9463 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9464 + * Redistribution of this file is permitted under the
9465 + * GNU General Public License.
9466 + */
9467 +
9468 +#ifndef _LINUX_VROOT_H
9469 +#define _LINUX_VROOT_H
9470 +
9471 +
9472 +#ifdef __KERNEL__
9473 +
9474 +/* Possible states of device */
9475 +enum {
9476 +       Vr_unbound,
9477 +       Vr_bound,
9478 +};
9479 +
9480 +struct vroot_device {
9481 +       int             vr_number;
9482 +       int             vr_refcnt;
9483 +
9484 +       struct semaphore        vr_ctl_mutex;
9485 +       struct block_device    *vr_device;
9486 +       int                     vr_state;
9487 +};
9488 +
9489 +
9490 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9491 +
9492 +extern int register_vroot_grb(vroot_grb_func *);
9493 +extern int unregister_vroot_grb(vroot_grb_func *);
9494 +
9495 +#endif /* __KERNEL__ */
9496 +
9497 +#define MAX_VROOT_DEFAULT      8
9498 +
9499 +/*
9500 + * IOCTL commands --- we will commandeer 0x56 ('V')
9501 + */
9502 +
9503 +#define VROOT_SET_DEV          0x5600
9504 +#define VROOT_CLR_DEV          0x5601
9505 +
9506 +#endif /* _LINUX_VROOT_H */
9507 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_base.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_base.h
9508 --- linux-2.6.35.4/include/linux/vs_base.h      1970-01-01 01:00:00.000000000 +0100
9509 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_base.h        2010-08-02 17:05:06.000000000 +0200
9510 @@ -0,0 +1,10 @@
9511 +#ifndef _VS_BASE_H
9512 +#define _VS_BASE_H
9513 +
9514 +#include "vserver/base.h"
9515 +#include "vserver/check.h"
9516 +#include "vserver/debug.h"
9517 +
9518 +#else
9519 +#warning duplicate inclusion
9520 +#endif
9521 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_context.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_context.h
9522 --- linux-2.6.35.4/include/linux/vs_context.h   1970-01-01 01:00:00.000000000 +0100
9523 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_context.h     2010-08-02 17:05:06.000000000 +0200
9524 @@ -0,0 +1,242 @@
9525 +#ifndef _VS_CONTEXT_H
9526 +#define _VS_CONTEXT_H
9527 +
9528 +#include "vserver/base.h"
9529 +#include "vserver/check.h"
9530 +#include "vserver/context.h"
9531 +#include "vserver/history.h"
9532 +#include "vserver/debug.h"
9533 +
9534 +#include <linux/sched.h>
9535 +
9536 +
9537 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9538 +
9539 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9540 +       const char *_file, int _line, void *_here)
9541 +{
9542 +       if (!vxi)
9543 +               return NULL;
9544 +
9545 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9546 +               vxi, vxi ? vxi->vx_id : 0,
9547 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9548 +               _file, _line);
9549 +       __vxh_get_vx_info(vxi, _here);
9550 +
9551 +       atomic_inc(&vxi->vx_usecnt);
9552 +       return vxi;
9553 +}
9554 +
9555 +
9556 +extern void free_vx_info(struct vx_info *);
9557 +
9558 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9559 +
9560 +static inline void __put_vx_info(struct vx_info *vxi,
9561 +       const char *_file, int _line, void *_here)
9562 +{
9563 +       if (!vxi)
9564 +               return;
9565 +
9566 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9567 +               vxi, vxi ? vxi->vx_id : 0,
9568 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9569 +               _file, _line);
9570 +       __vxh_put_vx_info(vxi, _here);
9571 +
9572 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9573 +               free_vx_info(vxi);
9574 +}
9575 +
9576 +
9577 +#define init_vx_info(p, i) \
9578 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9579 +
9580 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9581 +       const char *_file, int _line, void *_here)
9582 +{
9583 +       if (vxi) {
9584 +               vxlprintk(VXD_CBIT(xid, 3),
9585 +                       "init_vx_info(%p[#%d.%d])",
9586 +                       vxi, vxi ? vxi->vx_id : 0,
9587 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9588 +                       _file, _line);
9589 +               __vxh_init_vx_info(vxi, vxp, _here);
9590 +
9591 +               atomic_inc(&vxi->vx_usecnt);
9592 +       }
9593 +       *vxp = vxi;
9594 +}
9595 +
9596 +
9597 +#define set_vx_info(p, i) \
9598 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9599 +
9600 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9601 +       const char *_file, int _line, void *_here)
9602 +{
9603 +       struct vx_info *vxo;
9604 +
9605 +       if (!vxi)
9606 +               return;
9607 +
9608 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9609 +               vxi, vxi ? vxi->vx_id : 0,
9610 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9611 +               _file, _line);
9612 +       __vxh_set_vx_info(vxi, vxp, _here);
9613 +
9614 +       atomic_inc(&vxi->vx_usecnt);
9615 +       vxo = xchg(vxp, vxi);
9616 +       BUG_ON(vxo);
9617 +}
9618 +
9619 +
9620 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9621 +
9622 +static inline void __clr_vx_info(struct vx_info **vxp,
9623 +       const char *_file, int _line, void *_here)
9624 +{
9625 +       struct vx_info *vxo;
9626 +
9627 +       vxo = xchg(vxp, NULL);
9628 +       if (!vxo)
9629 +               return;
9630 +
9631 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9632 +               vxo, vxo ? vxo->vx_id : 0,
9633 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9634 +               _file, _line);
9635 +       __vxh_clr_vx_info(vxo, vxp, _here);
9636 +
9637 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9638 +               free_vx_info(vxo);
9639 +}
9640 +
9641 +
9642 +#define claim_vx_info(v, p) \
9643 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9644 +
9645 +static inline void __claim_vx_info(struct vx_info *vxi,
9646 +       struct task_struct *task,
9647 +       const char *_file, int _line, void *_here)
9648 +{
9649 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9650 +               vxi, vxi ? vxi->vx_id : 0,
9651 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9652 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9653 +               task, _file, _line);
9654 +       __vxh_claim_vx_info(vxi, task, _here);
9655 +
9656 +       atomic_inc(&vxi->vx_tasks);
9657 +}
9658 +
9659 +
9660 +extern void unhash_vx_info(struct vx_info *);
9661 +
9662 +#define release_vx_info(v, p) \
9663 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9664 +
9665 +static inline void __release_vx_info(struct vx_info *vxi,
9666 +       struct task_struct *task,
9667 +       const char *_file, int _line, void *_here)
9668 +{
9669 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9670 +               vxi, vxi ? vxi->vx_id : 0,
9671 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9672 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9673 +               task, _file, _line);
9674 +       __vxh_release_vx_info(vxi, task, _here);
9675 +
9676 +       might_sleep();
9677 +
9678 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9679 +               unhash_vx_info(vxi);
9680 +}
9681 +
9682 +
9683 +#define task_get_vx_info(p) \
9684 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9685 +
9686 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9687 +       const char *_file, int _line, void *_here)
9688 +{
9689 +       struct vx_info *vxi;
9690 +
9691 +       task_lock(p);
9692 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9693 +               p, _file, _line);
9694 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9695 +       task_unlock(p);
9696 +       return vxi;
9697 +}
9698 +
9699 +
9700 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9701 +{
9702 +       if (waitqueue_active(&vxi->vx_wait))
9703 +               wake_up_interruptible(&vxi->vx_wait);
9704 +}
9705 +
9706 +
9707 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9708 +
9709 +static inline void __enter_vx_info(struct vx_info *vxi,
9710 +       struct vx_info_save *vxis, const char *_file, int _line)
9711 +{
9712 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9713 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9714 +               current->xid, current->vx_info, _file, _line);
9715 +       vxis->vxi = xchg(&current->vx_info, vxi);
9716 +       vxis->xid = current->xid;
9717 +       current->xid = vxi ? vxi->vx_id : 0;
9718 +}
9719 +
9720 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9721 +
9722 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9723 +       const char *_file, int _line)
9724 +{
9725 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9726 +               vxis, vxis->xid, vxis->vxi, current,
9727 +               current->xid, current->vx_info, _file, _line);
9728 +       (void)xchg(&current->vx_info, vxis->vxi);
9729 +       current->xid = vxis->xid;
9730 +}
9731 +
9732 +
9733 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9734 +{
9735 +       vxis->vxi = xchg(&current->vx_info, NULL);
9736 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9737 +}
9738 +
9739 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9740 +{
9741 +       (void)xchg(&current->xid, vxis->xid);
9742 +       (void)xchg(&current->vx_info, vxis->vxi);
9743 +}
9744 +
9745 +#define task_is_init(p) \
9746 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9747 +
9748 +static inline int __task_is_init(struct task_struct *p,
9749 +       const char *_file, int _line, void *_here)
9750 +{
9751 +       int is_init = is_global_init(p);
9752 +
9753 +       task_lock(p);
9754 +       if (p->vx_info)
9755 +               is_init = p->vx_info->vx_initpid == p->pid;
9756 +       task_unlock(p);
9757 +       return is_init;
9758 +}
9759 +
9760 +extern void exit_vx_info(struct task_struct *, int);
9761 +extern void exit_vx_info_early(struct task_struct *, int);
9762 +
9763 +
9764 +#else
9765 +#warning duplicate inclusion
9766 +#endif
9767 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_cowbl.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_cowbl.h
9768 --- linux-2.6.35.4/include/linux/vs_cowbl.h     1970-01-01 01:00:00.000000000 +0100
9769 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_cowbl.h       2010-08-02 21:01:17.000000000 +0200
9770 @@ -0,0 +1,48 @@
9771 +#ifndef _VS_COWBL_H
9772 +#define _VS_COWBL_H
9773 +
9774 +#include <linux/fs.h>
9775 +#include <linux/dcache.h>
9776 +#include <linux/namei.h>
9777 +#include <linux/slab.h>
9778 +
9779 +extern struct dentry *cow_break_link(const char *pathname);
9780 +
9781 +static inline int cow_check_and_break(struct path *path)
9782 +{
9783 +       struct inode *inode = path->dentry->d_inode;
9784 +       int error = 0;
9785 +
9786 +       /* do we need this check? */
9787 +       if (IS_RDONLY(inode))
9788 +               return -EROFS;
9789 +
9790 +       if (IS_COW(inode)) {
9791 +               if (IS_COW_LINK(inode)) {
9792 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9793 +                       char *pp, *buf;
9794 +
9795 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9796 +                       if (!buf) {
9797 +                               return -ENOMEM;
9798 +                       }
9799 +                       pp = d_path(path, buf, PATH_MAX);
9800 +                       new_dentry = cow_break_link(pp);
9801 +                       kfree(buf);
9802 +                       if (!IS_ERR(new_dentry)) {
9803 +                               path->dentry = new_dentry;
9804 +                               dput(old_dentry);
9805 +                       } else
9806 +                               error = PTR_ERR(new_dentry);
9807 +               } else {
9808 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9809 +                       inode->i_ctime = CURRENT_TIME;
9810 +                       mark_inode_dirty(inode);
9811 +               }
9812 +       }
9813 +       return error;
9814 +}
9815 +
9816 +#else
9817 +#warning duplicate inclusion
9818 +#endif
9819 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_cvirt.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_cvirt.h
9820 --- linux-2.6.35.4/include/linux/vs_cvirt.h     1970-01-01 01:00:00.000000000 +0100
9821 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_cvirt.h       2010-08-02 17:05:06.000000000 +0200
9822 @@ -0,0 +1,50 @@
9823 +#ifndef _VS_CVIRT_H
9824 +#define _VS_CVIRT_H
9825 +
9826 +#include "vserver/cvirt.h"
9827 +#include "vserver/context.h"
9828 +#include "vserver/base.h"
9829 +#include "vserver/check.h"
9830 +#include "vserver/debug.h"
9831 +
9832 +
9833 +static inline void vx_activate_task(struct task_struct *p)
9834 +{
9835 +       struct vx_info *vxi;
9836 +
9837 +       if ((vxi = p->vx_info)) {
9838 +               vx_update_load(vxi);
9839 +               atomic_inc(&vxi->cvirt.nr_running);
9840 +       }
9841 +}
9842 +
9843 +static inline void vx_deactivate_task(struct task_struct *p)
9844 +{
9845 +       struct vx_info *vxi;
9846 +
9847 +       if ((vxi = p->vx_info)) {
9848 +               vx_update_load(vxi);
9849 +               atomic_dec(&vxi->cvirt.nr_running);
9850 +       }
9851 +}
9852 +
9853 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9854 +{
9855 +       struct vx_info *vxi;
9856 +
9857 +       if ((vxi = p->vx_info))
9858 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9859 +}
9860 +
9861 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9862 +{
9863 +       struct vx_info *vxi;
9864 +
9865 +       if ((vxi = p->vx_info))
9866 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9867 +}
9868 +
9869 +
9870 +#else
9871 +#warning duplicate inclusion
9872 +#endif
9873 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_device.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_device.h
9874 --- linux-2.6.35.4/include/linux/vs_device.h    1970-01-01 01:00:00.000000000 +0100
9875 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_device.h      2010-08-02 17:05:06.000000000 +0200
9876 @@ -0,0 +1,45 @@
9877 +#ifndef _VS_DEVICE_H
9878 +#define _VS_DEVICE_H
9879 +
9880 +#include "vserver/base.h"
9881 +#include "vserver/device.h"
9882 +#include "vserver/debug.h"
9883 +
9884 +
9885 +#ifdef CONFIG_VSERVER_DEVICE
9886 +
9887 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9888 +
9889 +#define vs_device_perm(v, d, m, p) \
9890 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9891 +
9892 +#else
9893 +
9894 +static inline
9895 +int vs_map_device(struct vx_info *vxi,
9896 +       dev_t device, dev_t *target, umode_t mode)
9897 +{
9898 +       if (target)
9899 +               *target = device;
9900 +       return ~0;
9901 +}
9902 +
9903 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9904 +
9905 +#endif
9906 +
9907 +
9908 +#define vs_map_chrdev(d, t, p) \
9909 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9910 +#define vs_map_blkdev(d, t, p) \
9911 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9912 +
9913 +#define vs_chrdev_perm(d, p) \
9914 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9915 +#define vs_blkdev_perm(d, p) \
9916 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9917 +
9918 +
9919 +#else
9920 +#warning duplicate inclusion
9921 +#endif
9922 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_dlimit.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_dlimit.h
9923 --- linux-2.6.35.4/include/linux/vs_dlimit.h    1970-01-01 01:00:00.000000000 +0100
9924 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_dlimit.h      2010-08-02 22:21:17.000000000 +0200
9925 @@ -0,0 +1,215 @@
9926 +#ifndef _VS_DLIMIT_H
9927 +#define _VS_DLIMIT_H
9928 +
9929 +#include <linux/fs.h>
9930 +
9931 +#include "vserver/dlimit.h"
9932 +#include "vserver/base.h"
9933 +#include "vserver/debug.h"
9934 +
9935 +
9936 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9937 +
9938 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9939 +       const char *_file, int _line)
9940 +{
9941 +       if (!dli)
9942 +               return NULL;
9943 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9944 +               dli, dli ? dli->dl_tag : 0,
9945 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9946 +               _file, _line);
9947 +       atomic_inc(&dli->dl_usecnt);
9948 +       return dli;
9949 +}
9950 +
9951 +
9952 +#define free_dl_info(i) \
9953 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9954 +
9955 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9956 +
9957 +static inline void __put_dl_info(struct dl_info *dli,
9958 +       const char *_file, int _line)
9959 +{
9960 +       if (!dli)
9961 +               return;
9962 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9963 +               dli, dli ? dli->dl_tag : 0,
9964 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9965 +               _file, _line);
9966 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9967 +               free_dl_info(dli);
9968 +}
9969 +
9970 +
9971 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9972 +
9973 +static inline int __dl_alloc_space(struct super_block *sb,
9974 +       tag_t tag, dlsize_t nr, const char *file, int line)
9975 +{
9976 +       struct dl_info *dli = NULL;
9977 +       int ret = 0;
9978 +
9979 +       if (nr == 0)
9980 +               goto out;
9981 +       dli = locate_dl_info(sb, tag);
9982 +       if (!dli)
9983 +               goto out;
9984 +
9985 +       spin_lock(&dli->dl_lock);
9986 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9987 +       if (!ret)
9988 +               dli->dl_space_used += nr;
9989 +       spin_unlock(&dli->dl_lock);
9990 +       put_dl_info(dli);
9991 +out:
9992 +       vxlprintk(VXD_CBIT(dlim, 1),
9993 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9994 +               sb, tag, __dlimit_char(dli), (long long)nr,
9995 +               ret, file, line);
9996 +       return ret ? -ENOSPC : 0;
9997 +}
9998 +
9999 +static inline void __dl_free_space(struct super_block *sb,
10000 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10001 +{
10002 +       struct dl_info *dli = NULL;
10003 +
10004 +       if (nr == 0)
10005 +               goto out;
10006 +       dli = locate_dl_info(sb, tag);
10007 +       if (!dli)
10008 +               goto out;
10009 +
10010 +       spin_lock(&dli->dl_lock);
10011 +       if (dli->dl_space_used > nr)
10012 +               dli->dl_space_used -= nr;
10013 +       else
10014 +               dli->dl_space_used = 0;
10015 +       spin_unlock(&dli->dl_lock);
10016 +       put_dl_info(dli);
10017 +out:
10018 +       vxlprintk(VXD_CBIT(dlim, 1),
10019 +               "FREE  (%p,#%d)%c %lld bytes",
10020 +               sb, tag, __dlimit_char(dli), (long long)nr,
10021 +               _file, _line);
10022 +}
10023 +
10024 +static inline int __dl_alloc_inode(struct super_block *sb,
10025 +       tag_t tag, const char *_file, int _line)
10026 +{
10027 +       struct dl_info *dli;
10028 +       int ret = 0;
10029 +
10030 +       dli = locate_dl_info(sb, tag);
10031 +       if (!dli)
10032 +               goto out;
10033 +
10034 +       spin_lock(&dli->dl_lock);
10035 +       dli->dl_inodes_used++;
10036 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
10037 +       spin_unlock(&dli->dl_lock);
10038 +       put_dl_info(dli);
10039 +out:
10040 +       vxlprintk(VXD_CBIT(dlim, 0),
10041 +               "ALLOC (%p,#%d)%c inode (%d)",
10042 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10043 +       return ret ? -ENOSPC : 0;
10044 +}
10045 +
10046 +static inline void __dl_free_inode(struct super_block *sb,
10047 +       tag_t tag, const char *_file, int _line)
10048 +{
10049 +       struct dl_info *dli;
10050 +
10051 +       dli = locate_dl_info(sb, tag);
10052 +       if (!dli)
10053 +               goto out;
10054 +
10055 +       spin_lock(&dli->dl_lock);
10056 +       if (dli->dl_inodes_used > 1)
10057 +               dli->dl_inodes_used--;
10058 +       else
10059 +               dli->dl_inodes_used = 0;
10060 +       spin_unlock(&dli->dl_lock);
10061 +       put_dl_info(dli);
10062 +out:
10063 +       vxlprintk(VXD_CBIT(dlim, 0),
10064 +               "FREE  (%p,#%d)%c inode",
10065 +               sb, tag, __dlimit_char(dli), _file, _line);
10066 +}
10067 +
10068 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10069 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10070 +       const char *_file, int _line)
10071 +{
10072 +       struct dl_info *dli;
10073 +       uint64_t broot, bfree;
10074 +
10075 +       dli = locate_dl_info(sb, tag);
10076 +       if (!dli)
10077 +               return;
10078 +
10079 +       spin_lock(&dli->dl_lock);
10080 +       broot = (dli->dl_space_total -
10081 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10082 +               >> sb->s_blocksize_bits;
10083 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10084 +                       >> sb->s_blocksize_bits;
10085 +       spin_unlock(&dli->dl_lock);
10086 +
10087 +       vxlprintk(VXD_CBIT(dlim, 2),
10088 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10089 +               (long long)bfree, (long long)broot,
10090 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10091 +               _file, _line);
10092 +       if (free_blocks) {
10093 +               if (*free_blocks > bfree)
10094 +                       *free_blocks = bfree;
10095 +       }
10096 +       if (root_blocks) {
10097 +               if (*root_blocks > broot)
10098 +                       *root_blocks = broot;
10099 +       }
10100 +       put_dl_info(dli);
10101 +}
10102 +
10103 +#define dl_prealloc_space(in, bytes) \
10104 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10105 +               __FILE__, __LINE__ )
10106 +
10107 +#define dl_alloc_space(in, bytes) \
10108 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10109 +               __FILE__, __LINE__ )
10110 +
10111 +#define dl_reserve_space(in, bytes) \
10112 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10113 +               __FILE__, __LINE__ )
10114 +
10115 +#define dl_claim_space(in, bytes) (0)
10116 +
10117 +#define dl_release_space(in, bytes) \
10118 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10119 +               __FILE__, __LINE__ )
10120 +
10121 +#define dl_free_space(in, bytes) \
10122 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10123 +               __FILE__, __LINE__ )
10124 +
10125 +
10126 +
10127 +#define dl_alloc_inode(in) \
10128 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10129 +
10130 +#define dl_free_inode(in) \
10131 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10132 +
10133 +
10134 +#define dl_adjust_block(sb, tag, fb, rb) \
10135 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10136 +
10137 +
10138 +#else
10139 +#warning duplicate inclusion
10140 +#endif
10141 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/base.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/base.h
10142 --- linux-2.6.35.4/include/linux/vserver/base.h 1970-01-01 01:00:00.000000000 +0100
10143 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/base.h   2010-08-02 17:05:06.000000000 +0200
10144 @@ -0,0 +1,170 @@
10145 +#ifndef _VX_BASE_H
10146 +#define _VX_BASE_H
10147 +
10148 +
10149 +/* context state changes */
10150 +
10151 +enum {
10152 +       VSC_STARTUP = 1,
10153 +       VSC_SHUTDOWN,
10154 +
10155 +       VSC_NETUP,
10156 +       VSC_NETDOWN,
10157 +};
10158 +
10159 +
10160 +
10161 +#define vx_task_xid(t) ((t)->xid)
10162 +
10163 +#define vx_current_xid() vx_task_xid(current)
10164 +
10165 +#define current_vx_info() (current->vx_info)
10166 +
10167 +
10168 +#define nx_task_nid(t) ((t)->nid)
10169 +
10170 +#define nx_current_nid() nx_task_nid(current)
10171 +
10172 +#define current_nx_info() (current->nx_info)
10173 +
10174 +
10175 +/* generic flag merging */
10176 +
10177 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10178 +
10179 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10180 +
10181 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10182 +
10183 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10184 +
10185 +
10186 +/* context flags */
10187 +
10188 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10189 +
10190 +#define vx_current_flags()     __vx_flags(current_vx_info())
10191 +
10192 +#define vx_info_flags(v, m, f) \
10193 +       vs_check_flags(__vx_flags(v), m, f)
10194 +
10195 +#define task_vx_flags(t, m, f) \
10196 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10197 +
10198 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10199 +
10200 +
10201 +/* context caps */
10202 +
10203 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10204 +
10205 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10206 +
10207 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10208 +
10209 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10210 +
10211 +
10212 +
10213 +/* network flags */
10214 +
10215 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10216 +
10217 +#define nx_current_flags()     __nx_flags(current_nx_info())
10218 +
10219 +#define nx_info_flags(n, m, f) \
10220 +       vs_check_flags(__nx_flags(n), m, f)
10221 +
10222 +#define task_nx_flags(t, m, f) \
10223 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10224 +
10225 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10226 +
10227 +
10228 +/* network caps */
10229 +
10230 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10231 +
10232 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10233 +
10234 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10235 +
10236 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10237 +
10238 +
10239 +/* context mask capabilities */
10240 +
10241 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10242 +
10243 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10244 +
10245 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10246 +
10247 +
10248 +/* context bcap mask */
10249 +
10250 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10251 +
10252 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10253 +
10254 +
10255 +/* mask given bcaps */
10256 +
10257 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10258 +
10259 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10260 +
10261 +
10262 +/* masked cap_bset */
10263 +
10264 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10265 +
10266 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10267 +
10268 +#if 0
10269 +#define vx_info_mbcap(v, b) \
10270 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10271 +       vx_info_bcaps(v, b) : (b))
10272 +
10273 +#define task_vx_mbcap(t, b) \
10274 +       vx_info_mbcap((t)->vx_info, (t)->b)
10275 +
10276 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10277 +#endif
10278 +
10279 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10280 +
10281 +#define vx_capable(b, c) (capable(b) || \
10282 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10283 +
10284 +#define nx_capable(b, c) (capable(b) || \
10285 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10286 +
10287 +#define vx_task_initpid(t, n) \
10288 +       ((t)->vx_info && \
10289 +       ((t)->vx_info->vx_initpid == (n)))
10290 +
10291 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10292 +
10293 +
10294 +/* context unshare mask */
10295 +
10296 +#define __vx_umask(v)          ((v)->vx_umask)
10297 +
10298 +#define vx_current_umask()     __vx_umask(current_vx_info())
10299 +
10300 +#define vx_can_unshare(b, f) (capable(b) || \
10301 +       (cap_raised(current_cap(), b) && \
10302 +       !((f) & ~vx_current_umask())))
10303 +
10304 +
10305 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10306 +
10307 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10308 +
10309 +
10310 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10311 +
10312 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10313 +
10314 +#endif
10315 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/cacct_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cacct_cmd.h
10316 --- linux-2.6.35.4/include/linux/vserver/cacct_cmd.h    1970-01-01 01:00:00.000000000 +0100
10317 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cacct_cmd.h      2010-08-02 17:05:06.000000000 +0200
10318 @@ -0,0 +1,23 @@
10319 +#ifndef _VX_CACCT_CMD_H
10320 +#define _VX_CACCT_CMD_H
10321 +
10322 +
10323 +/* virtual host info name commands */
10324 +
10325 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10326 +
10327 +struct vcmd_sock_stat_v0 {
10328 +       uint32_t field;
10329 +       uint32_t count[3];
10330 +       uint64_t total[3];
10331 +};
10332 +
10333 +
10334 +#ifdef __KERNEL__
10335 +
10336 +#include <linux/compiler.h>
10337 +
10338 +extern int vc_sock_stat(struct vx_info *, void __user *);
10339 +
10340 +#endif /* __KERNEL__ */
10341 +#endif /* _VX_CACCT_CMD_H */
10342 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/cacct_def.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cacct_def.h
10343 --- linux-2.6.35.4/include/linux/vserver/cacct_def.h    1970-01-01 01:00:00.000000000 +0100
10344 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cacct_def.h      2010-08-02 17:05:06.000000000 +0200
10345 @@ -0,0 +1,43 @@
10346 +#ifndef _VX_CACCT_DEF_H
10347 +#define _VX_CACCT_DEF_H
10348 +
10349 +#include <asm/atomic.h>
10350 +#include <linux/vserver/cacct.h>
10351 +
10352 +
10353 +struct _vx_sock_acc {
10354 +       atomic_long_t count;
10355 +       atomic_long_t total;
10356 +};
10357 +
10358 +/* context sub struct */
10359 +
10360 +struct _vx_cacct {
10361 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10362 +       atomic_t slab[8];
10363 +       atomic_t page[6][8];
10364 +};
10365 +
10366 +#ifdef CONFIG_VSERVER_DEBUG
10367 +
10368 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10369 +{
10370 +       int i, j;
10371 +
10372 +       printk("\t_vx_cacct:");
10373 +       for (i = 0; i < 6; i++) {
10374 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10375 +
10376 +               printk("\t [%d] =", i);
10377 +               for (j = 0; j < 3; j++) {
10378 +                       printk(" [%d] = %8lu, %8lu", j,
10379 +                               atomic_long_read(&ptr[j].count),
10380 +                               atomic_long_read(&ptr[j].total));
10381 +               }
10382 +               printk("\n");
10383 +       }
10384 +}
10385 +
10386 +#endif
10387 +
10388 +#endif /* _VX_CACCT_DEF_H */
10389 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/cacct.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cacct.h
10390 --- linux-2.6.35.4/include/linux/vserver/cacct.h        1970-01-01 01:00:00.000000000 +0100
10391 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cacct.h  2010-08-02 17:05:06.000000000 +0200
10392 @@ -0,0 +1,15 @@
10393 +#ifndef _VX_CACCT_H
10394 +#define _VX_CACCT_H
10395 +
10396 +
10397 +enum sock_acc_field {
10398 +       VXA_SOCK_UNSPEC = 0,
10399 +       VXA_SOCK_UNIX,
10400 +       VXA_SOCK_INET,
10401 +       VXA_SOCK_INET6,
10402 +       VXA_SOCK_PACKET,
10403 +       VXA_SOCK_OTHER,
10404 +       VXA_SOCK_SIZE   /* array size */
10405 +};
10406 +
10407 +#endif /* _VX_CACCT_H */
10408 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/cacct_int.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cacct_int.h
10409 --- linux-2.6.35.4/include/linux/vserver/cacct_int.h    1970-01-01 01:00:00.000000000 +0100
10410 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cacct_int.h      2010-08-02 17:05:06.000000000 +0200
10411 @@ -0,0 +1,21 @@
10412 +#ifndef _VX_CACCT_INT_H
10413 +#define _VX_CACCT_INT_H
10414 +
10415 +
10416 +#ifdef __KERNEL__
10417 +
10418 +static inline
10419 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10420 +{
10421 +       return atomic_long_read(&cacct->sock[type][pos].count);
10422 +}
10423 +
10424 +
10425 +static inline
10426 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10427 +{
10428 +       return atomic_long_read(&cacct->sock[type][pos].total);
10429 +}
10430 +
10431 +#endif /* __KERNEL__ */
10432 +#endif /* _VX_CACCT_INT_H */
10433 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/check.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/check.h
10434 --- linux-2.6.35.4/include/linux/vserver/check.h        1970-01-01 01:00:00.000000000 +0100
10435 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/check.h  2010-08-02 17:05:06.000000000 +0200
10436 @@ -0,0 +1,89 @@
10437 +#ifndef _VS_CHECK_H
10438 +#define _VS_CHECK_H
10439 +
10440 +
10441 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10442 +
10443 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10444 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10445 +#else
10446 +#define MIN_D_CONTEXT  65536
10447 +#endif
10448 +
10449 +/* check conditions */
10450 +
10451 +#define VS_ADMIN       0x0001
10452 +#define VS_WATCH       0x0002
10453 +#define VS_HIDE                0x0004
10454 +#define VS_HOSTID      0x0008
10455 +
10456 +#define VS_IDENT       0x0010
10457 +#define VS_EQUIV       0x0020
10458 +#define VS_PARENT      0x0040
10459 +#define VS_CHILD       0x0080
10460 +
10461 +#define VS_ARG_MASK    0x00F0
10462 +
10463 +#define VS_DYNAMIC     0x0100
10464 +#define VS_STATIC      0x0200
10465 +
10466 +#define VS_ATR_MASK    0x0F00
10467 +
10468 +#ifdef CONFIG_VSERVER_PRIVACY
10469 +#define VS_ADMIN_P     (0)
10470 +#define VS_WATCH_P     (0)
10471 +#else
10472 +#define VS_ADMIN_P     VS_ADMIN
10473 +#define VS_WATCH_P     VS_WATCH
10474 +#endif
10475 +
10476 +#define VS_HARDIRQ     0x1000
10477 +#define VS_SOFTIRQ     0x2000
10478 +#define VS_IRQ         0x4000
10479 +
10480 +#define VS_IRQ_MASK    0xF000
10481 +
10482 +#include <linux/hardirq.h>
10483 +
10484 +/*
10485 + * check current context for ADMIN/WATCH and
10486 + * optionally against supplied argument
10487 + */
10488 +static inline int __vs_check(int cid, int id, unsigned int mode)
10489 +{
10490 +       if (mode & VS_ARG_MASK) {
10491 +               if ((mode & VS_IDENT) && (id == cid))
10492 +                       return 1;
10493 +       }
10494 +       if (mode & VS_ATR_MASK) {
10495 +               if ((mode & VS_DYNAMIC) &&
10496 +                       (id >= MIN_D_CONTEXT) &&
10497 +                       (id <= MAX_S_CONTEXT))
10498 +                       return 1;
10499 +               if ((mode & VS_STATIC) &&
10500 +                       (id > 1) && (id < MIN_D_CONTEXT))
10501 +                       return 1;
10502 +       }
10503 +       if (mode & VS_IRQ_MASK) {
10504 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10505 +                       return 1;
10506 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10507 +                       return 1;
10508 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10509 +                       return 1;
10510 +       }
10511 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10512 +               ((mode & VS_WATCH) && (cid == 1)) ||
10513 +               ((mode & VS_HOSTID) && (id == 0)));
10514 +}
10515 +
10516 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10517 +
10518 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10519 +
10520 +
10521 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10522 +
10523 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10524 +
10525 +#endif
10526 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/context_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/context_cmd.h
10527 --- linux-2.6.35.4/include/linux/vserver/context_cmd.h  1970-01-01 01:00:00.000000000 +0100
10528 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/context_cmd.h    2010-08-02 17:05:06.000000000 +0200
10529 @@ -0,0 +1,145 @@
10530 +#ifndef _VX_CONTEXT_CMD_H
10531 +#define _VX_CONTEXT_CMD_H
10532 +
10533 +
10534 +/* vinfo commands */
10535 +
10536 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10537 +
10538 +#ifdef __KERNEL__
10539 +extern int vc_task_xid(uint32_t);
10540 +
10541 +#endif /* __KERNEL__ */
10542 +
10543 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10544 +
10545 +struct vcmd_vx_info_v0 {
10546 +       uint32_t xid;
10547 +       uint32_t initpid;
10548 +       /* more to come */
10549 +};
10550 +
10551 +#ifdef __KERNEL__
10552 +extern int vc_vx_info(struct vx_info *, void __user *);
10553 +
10554 +#endif /* __KERNEL__ */
10555 +
10556 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10557 +
10558 +struct vcmd_ctx_stat_v0 {
10559 +       uint32_t usecnt;
10560 +       uint32_t tasks;
10561 +       /* more to come */
10562 +};
10563 +
10564 +#ifdef __KERNEL__
10565 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10566 +
10567 +#endif /* __KERNEL__ */
10568 +
10569 +/* context commands */
10570 +
10571 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10572 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10573 +
10574 +struct vcmd_ctx_create {
10575 +       uint64_t flagword;
10576 +};
10577 +
10578 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10579 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10580 +
10581 +struct vcmd_ctx_migrate {
10582 +       uint64_t flagword;
10583 +};
10584 +
10585 +#ifdef __KERNEL__
10586 +extern int vc_ctx_create(uint32_t, void __user *);
10587 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10588 +
10589 +#endif /* __KERNEL__ */
10590 +
10591 +
10592 +/* flag commands */
10593 +
10594 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10595 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10596 +
10597 +struct vcmd_ctx_flags_v0 {
10598 +       uint64_t flagword;
10599 +       uint64_t mask;
10600 +};
10601 +
10602 +#ifdef __KERNEL__
10603 +extern int vc_get_cflags(struct vx_info *, void __user *);
10604 +extern int vc_set_cflags(struct vx_info *, void __user *);
10605 +
10606 +#endif /* __KERNEL__ */
10607 +
10608 +
10609 +/* context caps commands */
10610 +
10611 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10612 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10613 +
10614 +struct vcmd_ctx_caps_v1 {
10615 +       uint64_t ccaps;
10616 +       uint64_t cmask;
10617 +};
10618 +
10619 +#ifdef __KERNEL__
10620 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10621 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10622 +
10623 +#endif /* __KERNEL__ */
10624 +
10625 +
10626 +/* bcaps commands */
10627 +
10628 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10629 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10630 +
10631 +struct vcmd_bcaps {
10632 +       uint64_t bcaps;
10633 +       uint64_t bmask;
10634 +};
10635 +
10636 +#ifdef __KERNEL__
10637 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10638 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10639 +
10640 +#endif /* __KERNEL__ */
10641 +
10642 +
10643 +/* umask commands */
10644 +
10645 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10646 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10647 +
10648 +struct vcmd_umask {
10649 +       uint64_t umask;
10650 +       uint64_t mask;
10651 +};
10652 +
10653 +#ifdef __KERNEL__
10654 +extern int vc_get_umask(struct vx_info *, void __user *);
10655 +extern int vc_set_umask(struct vx_info *, void __user *);
10656 +
10657 +#endif /* __KERNEL__ */
10658 +
10659 +
10660 +/* OOM badness */
10661 +
10662 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10663 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10664 +
10665 +struct vcmd_badness_v0 {
10666 +       int64_t bias;
10667 +};
10668 +
10669 +#ifdef __KERNEL__
10670 +extern int vc_get_badness(struct vx_info *, void __user *);
10671 +extern int vc_set_badness(struct vx_info *, void __user *);
10672 +
10673 +#endif /* __KERNEL__ */
10674 +#endif /* _VX_CONTEXT_CMD_H */
10675 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/context.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/context.h
10676 --- linux-2.6.35.4/include/linux/vserver/context.h      1970-01-01 01:00:00.000000000 +0100
10677 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/context.h        2010-08-02 17:05:06.000000000 +0200
10678 @@ -0,0 +1,184 @@
10679 +#ifndef _VX_CONTEXT_H
10680 +#define _VX_CONTEXT_H
10681 +
10682 +#include <linux/types.h>
10683 +#include <linux/capability.h>
10684 +
10685 +
10686 +/* context flags */
10687 +
10688 +#define VXF_INFO_SCHED         0x00000002
10689 +#define VXF_INFO_NPROC         0x00000004
10690 +#define VXF_INFO_PRIVATE       0x00000008
10691 +
10692 +#define VXF_INFO_INIT          0x00000010
10693 +#define VXF_INFO_HIDE          0x00000020
10694 +#define VXF_INFO_ULIMIT                0x00000040
10695 +#define VXF_INFO_NSPACE                0x00000080
10696 +
10697 +#define VXF_SCHED_HARD         0x00000100
10698 +#define VXF_SCHED_PRIO         0x00000200
10699 +#define VXF_SCHED_PAUSE                0x00000400
10700 +
10701 +#define VXF_VIRT_MEM           0x00010000
10702 +#define VXF_VIRT_UPTIME                0x00020000
10703 +#define VXF_VIRT_CPU           0x00040000
10704 +#define VXF_VIRT_LOAD          0x00080000
10705 +#define VXF_VIRT_TIME          0x00100000
10706 +
10707 +#define VXF_HIDE_MOUNT         0x01000000
10708 +/* was VXF_HIDE_NETIF          0x02000000 */
10709 +#define VXF_HIDE_VINFO         0x04000000
10710 +
10711 +#define VXF_STATE_SETUP                (1ULL << 32)
10712 +#define VXF_STATE_INIT         (1ULL << 33)
10713 +#define VXF_STATE_ADMIN                (1ULL << 34)
10714 +
10715 +#define VXF_SC_HELPER          (1ULL << 36)
10716 +#define VXF_REBOOT_KILL                (1ULL << 37)
10717 +#define VXF_PERSISTENT         (1ULL << 38)
10718 +
10719 +#define VXF_FORK_RSS           (1ULL << 48)
10720 +#define VXF_PROLIFIC           (1ULL << 49)
10721 +
10722 +#define VXF_IGNEG_NICE         (1ULL << 52)
10723 +
10724 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10725 +
10726 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10727 +
10728 +
10729 +/* context migration */
10730 +
10731 +#define VXM_SET_INIT           0x00000001
10732 +#define VXM_SET_REAPER         0x00000002
10733 +
10734 +/* context caps */
10735 +
10736 +#define VXC_CAP_MASK           0x00000000
10737 +
10738 +#define VXC_SET_UTSNAME                0x00000001
10739 +#define VXC_SET_RLIMIT         0x00000002
10740 +#define VXC_FS_SECURITY                0x00000004
10741 +#define VXC_FS_TRUSTED         0x00000008
10742 +#define VXC_TIOCSTI            0x00000010
10743 +
10744 +/* was VXC_RAW_ICMP            0x00000100 */
10745 +#define VXC_SYSLOG             0x00001000
10746 +#define VXC_OOM_ADJUST         0x00002000
10747 +#define VXC_AUDIT_CONTROL      0x00004000
10748 +
10749 +#define VXC_SECURE_MOUNT       0x00010000
10750 +#define VXC_SECURE_REMOUNT     0x00020000
10751 +#define VXC_BINARY_MOUNT       0x00040000
10752 +
10753 +#define VXC_QUOTA_CTL          0x00100000
10754 +#define VXC_ADMIN_MAPPER       0x00200000
10755 +#define VXC_ADMIN_CLOOP                0x00400000
10756 +
10757 +#define VXC_KTHREAD            0x01000000
10758 +#define VXC_NAMESPACE          0x02000000
10759 +
10760 +
10761 +#ifdef __KERNEL__
10762 +
10763 +#include <linux/list.h>
10764 +#include <linux/spinlock.h>
10765 +#include <linux/rcupdate.h>
10766 +
10767 +#include "limit_def.h"
10768 +#include "sched_def.h"
10769 +#include "cvirt_def.h"
10770 +#include "cacct_def.h"
10771 +#include "device_def.h"
10772 +
10773 +#define VX_SPACES      2
10774 +
10775 +struct _vx_info_pc {
10776 +       struct _vx_sched_pc sched_pc;
10777 +       struct _vx_cvirt_pc cvirt_pc;
10778 +};
10779 +
10780 +struct vx_info {
10781 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10782 +       xid_t vx_id;                            /* context id */
10783 +       atomic_t vx_usecnt;                     /* usage count */
10784 +       atomic_t vx_tasks;                      /* tasks count */
10785 +       struct vx_info *vx_parent;              /* parent context */
10786 +       int vx_state;                           /* context state */
10787 +
10788 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10789 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10790 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10791 +
10792 +       uint64_t vx_flags;                      /* context flags */
10793 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10794 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10795 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10796 +
10797 +       struct task_struct *vx_reaper;          /* guest reaper process */
10798 +       pid_t vx_initpid;                       /* PID of guest init */
10799 +       int64_t vx_badness_bias;                /* OOM points bias */
10800 +
10801 +       struct _vx_limit limit;                 /* vserver limits */
10802 +       struct _vx_sched sched;                 /* vserver scheduler */
10803 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10804 +       struct _vx_cacct cacct;                 /* context accounting */
10805 +
10806 +       struct _vx_device dmap;                 /* default device map targets */
10807 +
10808 +#ifndef CONFIG_SMP
10809 +       struct _vx_info_pc info_pc;             /* per cpu data */
10810 +#else
10811 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10812 +#endif
10813 +
10814 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10815 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10816 +       int exit_code;                          /* last process exit code */
10817 +
10818 +       char vx_name[65];                       /* vserver name */
10819 +};
10820 +
10821 +#ifndef CONFIG_SMP
10822 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10823 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10824 +#else
10825 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10826 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10827 +#endif
10828 +
10829 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10830 +
10831 +
10832 +struct vx_info_save {
10833 +       struct vx_info *vxi;
10834 +       xid_t xid;
10835 +};
10836 +
10837 +
10838 +/* status flags */
10839 +
10840 +#define VXS_HASHED     0x0001
10841 +#define VXS_PAUSED     0x0010
10842 +#define VXS_SHUTDOWN   0x0100
10843 +#define VXS_HELPER     0x1000
10844 +#define VXS_RELEASED   0x8000
10845 +
10846 +
10847 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10848 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10849 +
10850 +extern struct vx_info *lookup_vx_info(int);
10851 +extern struct vx_info *lookup_or_create_vx_info(int);
10852 +
10853 +extern int get_xid_list(int, unsigned int *, int);
10854 +extern int xid_is_hashed(xid_t);
10855 +
10856 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10857 +
10858 +extern long vs_state_change(struct vx_info *, unsigned int);
10859 +
10860 +
10861 +#endif /* __KERNEL__ */
10862 +#endif /* _VX_CONTEXT_H */
10863 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/cvirt_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cvirt_cmd.h
10864 --- linux-2.6.35.4/include/linux/vserver/cvirt_cmd.h    1970-01-01 01:00:00.000000000 +0100
10865 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cvirt_cmd.h      2010-08-02 17:05:06.000000000 +0200
10866 @@ -0,0 +1,53 @@
10867 +#ifndef _VX_CVIRT_CMD_H
10868 +#define _VX_CVIRT_CMD_H
10869 +
10870 +
10871 +/* virtual host info name commands */
10872 +
10873 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10874 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10875 +
10876 +struct vcmd_vhi_name_v0 {
10877 +       uint32_t field;
10878 +       char name[65];
10879 +};
10880 +
10881 +
10882 +enum vhi_name_field {
10883 +       VHIN_CONTEXT = 0,
10884 +       VHIN_SYSNAME,
10885 +       VHIN_NODENAME,
10886 +       VHIN_RELEASE,
10887 +       VHIN_VERSION,
10888 +       VHIN_MACHINE,
10889 +       VHIN_DOMAINNAME,
10890 +};
10891 +
10892 +
10893 +#ifdef __KERNEL__
10894 +
10895 +#include <linux/compiler.h>
10896 +
10897 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10898 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10899 +
10900 +#endif /* __KERNEL__ */
10901 +
10902 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10903 +
10904 +struct vcmd_virt_stat_v0 {
10905 +       uint64_t offset;
10906 +       uint64_t uptime;
10907 +       uint32_t nr_threads;
10908 +       uint32_t nr_running;
10909 +       uint32_t nr_uninterruptible;
10910 +       uint32_t nr_onhold;
10911 +       uint32_t nr_forks;
10912 +       uint32_t load[3];
10913 +};
10914 +
10915 +#ifdef __KERNEL__
10916 +extern int vc_virt_stat(struct vx_info *, void __user *);
10917 +
10918 +#endif /* __KERNEL__ */
10919 +#endif /* _VX_CVIRT_CMD_H */
10920 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/cvirt_def.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cvirt_def.h
10921 --- linux-2.6.35.4/include/linux/vserver/cvirt_def.h    1970-01-01 01:00:00.000000000 +0100
10922 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cvirt_def.h      2010-08-02 17:05:06.000000000 +0200
10923 @@ -0,0 +1,80 @@
10924 +#ifndef _VX_CVIRT_DEF_H
10925 +#define _VX_CVIRT_DEF_H
10926 +
10927 +#include <linux/jiffies.h>
10928 +#include <linux/spinlock.h>
10929 +#include <linux/wait.h>
10930 +#include <linux/time.h>
10931 +#include <asm/atomic.h>
10932 +
10933 +
10934 +struct _vx_usage_stat {
10935 +       uint64_t user;
10936 +       uint64_t nice;
10937 +       uint64_t system;
10938 +       uint64_t softirq;
10939 +       uint64_t irq;
10940 +       uint64_t idle;
10941 +       uint64_t iowait;
10942 +};
10943 +
10944 +struct _vx_syslog {
10945 +       wait_queue_head_t log_wait;
10946 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10947 +
10948 +       unsigned long log_start;        /* next char to be read by syslog() */
10949 +       unsigned long con_start;        /* next char to be sent to consoles */
10950 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10951 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10952 +
10953 +       char log_buf[1024];
10954 +};
10955 +
10956 +
10957 +/* context sub struct */
10958 +
10959 +struct _vx_cvirt {
10960 +       atomic_t nr_threads;            /* number of current threads */
10961 +       atomic_t nr_running;            /* number of running threads */
10962 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10963 +
10964 +       atomic_t nr_onhold;             /* processes on hold */
10965 +       uint32_t onhold_last;           /* jiffies when put on hold */
10966 +
10967 +       struct timeval bias_tv;         /* time offset to the host */
10968 +       struct timespec bias_idle;
10969 +       struct timespec bias_uptime;    /* context creation point */
10970 +       uint64_t bias_clock;            /* offset in clock_t */
10971 +
10972 +       spinlock_t load_lock;           /* lock for the load averages */
10973 +       atomic_t load_updates;          /* nr of load updates done so far */
10974 +       uint32_t load_last;             /* last time load was calculated */
10975 +       uint32_t load[3];               /* load averages 1,5,15 */
10976 +
10977 +       atomic_t total_forks;           /* number of forks so far */
10978 +
10979 +       struct _vx_syslog syslog;
10980 +};
10981 +
10982 +struct _vx_cvirt_pc {
10983 +       struct _vx_usage_stat cpustat;
10984 +};
10985 +
10986 +
10987 +#ifdef CONFIG_VSERVER_DEBUG
10988 +
10989 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10990 +{
10991 +       printk("\t_vx_cvirt:\n");
10992 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10993 +               atomic_read(&cvirt->nr_threads),
10994 +               atomic_read(&cvirt->nr_running),
10995 +               atomic_read(&cvirt->nr_uninterruptible),
10996 +               atomic_read(&cvirt->nr_onhold));
10997 +       /* add rest here */
10998 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10999 +}
11000 +
11001 +#endif
11002 +
11003 +#endif /* _VX_CVIRT_DEF_H */
11004 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/cvirt.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cvirt.h
11005 --- linux-2.6.35.4/include/linux/vserver/cvirt.h        1970-01-01 01:00:00.000000000 +0100
11006 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/cvirt.h  2010-08-02 17:05:06.000000000 +0200
11007 @@ -0,0 +1,20 @@
11008 +#ifndef _VX_CVIRT_H
11009 +#define _VX_CVIRT_H
11010 +
11011 +
11012 +#ifdef __KERNEL__
11013 +
11014 +struct timespec;
11015 +
11016 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11017 +
11018 +
11019 +struct vx_info;
11020 +
11021 +void vx_update_load(struct vx_info *);
11022 +
11023 +
11024 +int vx_do_syslog(int, char __user *, int);
11025 +
11026 +#endif /* __KERNEL__ */
11027 +#endif /* _VX_CVIRT_H */
11028 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/debug_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/debug_cmd.h
11029 --- linux-2.6.35.4/include/linux/vserver/debug_cmd.h    1970-01-01 01:00:00.000000000 +0100
11030 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/debug_cmd.h      2010-08-02 17:05:06.000000000 +0200
11031 @@ -0,0 +1,58 @@
11032 +#ifndef _VX_DEBUG_CMD_H
11033 +#define _VX_DEBUG_CMD_H
11034 +
11035 +
11036 +/* debug commands */
11037 +
11038 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11039 +
11040 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11041 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11042 +
11043 +struct  vcmd_read_history_v0 {
11044 +       uint32_t index;
11045 +       uint32_t count;
11046 +       char __user *data;
11047 +};
11048 +
11049 +struct  vcmd_read_monitor_v0 {
11050 +       uint32_t index;
11051 +       uint32_t count;
11052 +       char __user *data;
11053 +};
11054 +
11055 +
11056 +#ifdef __KERNEL__
11057 +
11058 +#ifdef CONFIG_COMPAT
11059 +
11060 +#include <asm/compat.h>
11061 +
11062 +struct vcmd_read_history_v0_x32 {
11063 +       uint32_t index;
11064 +       uint32_t count;
11065 +       compat_uptr_t data_ptr;
11066 +};
11067 +
11068 +struct vcmd_read_monitor_v0_x32 {
11069 +       uint32_t index;
11070 +       uint32_t count;
11071 +       compat_uptr_t data_ptr;
11072 +};
11073 +
11074 +#endif  /* CONFIG_COMPAT */
11075 +
11076 +extern int vc_dump_history(uint32_t);
11077 +
11078 +extern int vc_read_history(uint32_t, void __user *);
11079 +extern int vc_read_monitor(uint32_t, void __user *);
11080 +
11081 +#ifdef CONFIG_COMPAT
11082 +
11083 +extern int vc_read_history_x32(uint32_t, void __user *);
11084 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11085 +
11086 +#endif  /* CONFIG_COMPAT */
11087 +
11088 +#endif /* __KERNEL__ */
11089 +#endif /* _VX_DEBUG_CMD_H */
11090 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/debug.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/debug.h
11091 --- linux-2.6.35.4/include/linux/vserver/debug.h        1970-01-01 01:00:00.000000000 +0100
11092 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/debug.h  2010-08-02 17:05:06.000000000 +0200
11093 @@ -0,0 +1,127 @@
11094 +#ifndef _VX_DEBUG_H
11095 +#define _VX_DEBUG_H
11096 +
11097 +
11098 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11099 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11100 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11101 +
11102 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11103 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11104 +#define VXF_DEV                "%p[%lu,%d:%d]"
11105 +
11106 +
11107 +#define vxd_path(p)                                            \
11108 +       ({ static char _buffer[PATH_MAX];                       \
11109 +          d_path(p, _buffer, sizeof(_buffer)); })
11110 +
11111 +#define vxd_cond_path(n)                                       \
11112 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11113 +
11114 +
11115 +#ifdef CONFIG_VSERVER_DEBUG
11116 +
11117 +extern unsigned int vx_debug_switch;
11118 +extern unsigned int vx_debug_xid;
11119 +extern unsigned int vx_debug_nid;
11120 +extern unsigned int vx_debug_tag;
11121 +extern unsigned int vx_debug_net;
11122 +extern unsigned int vx_debug_limit;
11123 +extern unsigned int vx_debug_cres;
11124 +extern unsigned int vx_debug_dlim;
11125 +extern unsigned int vx_debug_quota;
11126 +extern unsigned int vx_debug_cvirt;
11127 +extern unsigned int vx_debug_space;
11128 +extern unsigned int vx_debug_misc;
11129 +
11130 +
11131 +#define VX_LOGLEVEL    "vxD: "
11132 +#define VX_PROC_FMT    "%p: "
11133 +#define VX_PROCESS     current
11134 +
11135 +#define vxdprintk(c, f, x...)                                  \
11136 +       do {                                                    \
11137 +               if (c)                                          \
11138 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11139 +                               VX_PROCESS , ##x);              \
11140 +       } while (0)
11141 +
11142 +#define vxlprintk(c, f, x...)                                  \
11143 +       do {                                                    \
11144 +               if (c)                                          \
11145 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11146 +       } while (0)
11147 +
11148 +#define vxfprintk(c, f, x...)                                  \
11149 +       do {                                                    \
11150 +               if (c)                                          \
11151 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11152 +       } while (0)
11153 +
11154 +
11155 +struct vx_info;
11156 +
11157 +void dump_vx_info(struct vx_info *, int);
11158 +void dump_vx_info_inactive(int);
11159 +
11160 +#else  /* CONFIG_VSERVER_DEBUG */
11161 +
11162 +#define vx_debug_switch 0
11163 +#define vx_debug_xid   0
11164 +#define vx_debug_nid   0
11165 +#define vx_debug_tag   0
11166 +#define vx_debug_net   0
11167 +#define vx_debug_limit 0
11168 +#define vx_debug_cres  0
11169 +#define vx_debug_dlim  0
11170 +#define vx_debug_cvirt 0
11171 +
11172 +#define vxdprintk(x...) do { } while (0)
11173 +#define vxlprintk(x...) do { } while (0)
11174 +#define vxfprintk(x...) do { } while (0)
11175 +
11176 +#endif /* CONFIG_VSERVER_DEBUG */
11177 +
11178 +
11179 +#ifdef CONFIG_VSERVER_WARN
11180 +
11181 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11182 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11183 +#define VX_WARN_XID    "[xid #%u] "
11184 +#define VX_WARN_NID    "[nid #%u] "
11185 +#define VX_WARN_TAG    "[tag #%u] "
11186 +
11187 +#define vxwprintk(c, f, x...)                                  \
11188 +       do {                                                    \
11189 +               if (c)                                          \
11190 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11191 +       } while (0)
11192 +
11193 +#else  /* CONFIG_VSERVER_WARN */
11194 +
11195 +#define vxwprintk(x...) do { } while (0)
11196 +
11197 +#endif /* CONFIG_VSERVER_WARN */
11198 +
11199 +#define vxwprintk_task(c, f, x...)                             \
11200 +       vxwprintk(c, VX_WARN_TASK f,                            \
11201 +               current->comm, current->pid,                    \
11202 +               current->xid, current->nid, current->tag, ##x)
11203 +#define vxwprintk_xid(c, f, x...)                              \
11204 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11205 +#define vxwprintk_nid(c, f, x...)                              \
11206 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11207 +#define vxwprintk_tag(c, f, x...)                              \
11208 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11209 +
11210 +#ifdef CONFIG_VSERVER_DEBUG
11211 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11212 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11213 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11214 +#else
11215 +#define vxd_assert_lock(l)     do { } while (0)
11216 +#define vxd_assert(c, f, x...) do { } while (0)
11217 +#endif
11218 +
11219 +
11220 +#endif /* _VX_DEBUG_H */
11221 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/device_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/device_cmd.h
11222 --- linux-2.6.35.4/include/linux/vserver/device_cmd.h   1970-01-01 01:00:00.000000000 +0100
11223 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/device_cmd.h     2010-08-02 17:05:06.000000000 +0200
11224 @@ -0,0 +1,44 @@
11225 +#ifndef _VX_DEVICE_CMD_H
11226 +#define _VX_DEVICE_CMD_H
11227 +
11228 +
11229 +/*  device vserver commands */
11230 +
11231 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11232 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11233 +
11234 +struct vcmd_set_mapping_v0 {
11235 +       const char __user *device;
11236 +       const char __user *target;
11237 +       uint32_t flags;
11238 +};
11239 +
11240 +
11241 +#ifdef __KERNEL__
11242 +
11243 +#ifdef CONFIG_COMPAT
11244 +
11245 +#include <asm/compat.h>
11246 +
11247 +struct vcmd_set_mapping_v0_x32 {
11248 +       compat_uptr_t device_ptr;
11249 +       compat_uptr_t target_ptr;
11250 +       uint32_t flags;
11251 +};
11252 +
11253 +#endif /* CONFIG_COMPAT */
11254 +
11255 +#include <linux/compiler.h>
11256 +
11257 +extern int vc_set_mapping(struct vx_info *, void __user *);
11258 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11259 +
11260 +#ifdef CONFIG_COMPAT
11261 +
11262 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11263 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11264 +
11265 +#endif /* CONFIG_COMPAT */
11266 +
11267 +#endif /* __KERNEL__ */
11268 +#endif /* _VX_DEVICE_CMD_H */
11269 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/device_def.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/device_def.h
11270 --- linux-2.6.35.4/include/linux/vserver/device_def.h   1970-01-01 01:00:00.000000000 +0100
11271 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/device_def.h     2010-08-02 17:05:06.000000000 +0200
11272 @@ -0,0 +1,17 @@
11273 +#ifndef _VX_DEVICE_DEF_H
11274 +#define _VX_DEVICE_DEF_H
11275 +
11276 +#include <linux/types.h>
11277 +
11278 +struct vx_dmap_target {
11279 +       dev_t target;
11280 +       uint32_t flags;
11281 +};
11282 +
11283 +struct _vx_device {
11284 +#ifdef CONFIG_VSERVER_DEVICE
11285 +       struct vx_dmap_target targets[2];
11286 +#endif
11287 +};
11288 +
11289 +#endif /* _VX_DEVICE_DEF_H */
11290 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/device.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/device.h
11291 --- linux-2.6.35.4/include/linux/vserver/device.h       1970-01-01 01:00:00.000000000 +0100
11292 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/device.h 2010-08-02 17:05:06.000000000 +0200
11293 @@ -0,0 +1,15 @@
11294 +#ifndef _VX_DEVICE_H
11295 +#define _VX_DEVICE_H
11296 +
11297 +
11298 +#define DATTR_CREATE   0x00000001
11299 +#define DATTR_OPEN     0x00000002
11300 +
11301 +#define DATTR_REMAP    0x00000010
11302 +
11303 +#define DATTR_MASK     0x00000013
11304 +
11305 +
11306 +#else  /* _VX_DEVICE_H */
11307 +#warning duplicate inclusion
11308 +#endif /* _VX_DEVICE_H */
11309 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/dlimit_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/dlimit_cmd.h
11310 --- linux-2.6.35.4/include/linux/vserver/dlimit_cmd.h   1970-01-01 01:00:00.000000000 +0100
11311 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/dlimit_cmd.h     2010-08-02 17:05:06.000000000 +0200
11312 @@ -0,0 +1,109 @@
11313 +#ifndef _VX_DLIMIT_CMD_H
11314 +#define _VX_DLIMIT_CMD_H
11315 +
11316 +
11317 +/*  dlimit vserver commands */
11318 +
11319 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11320 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11321 +
11322 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11323 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11324 +
11325 +struct vcmd_ctx_dlimit_base_v0 {
11326 +       const char __user *name;
11327 +       uint32_t flags;
11328 +};
11329 +
11330 +struct vcmd_ctx_dlimit_v0 {
11331 +       const char __user *name;
11332 +       uint32_t space_used;                    /* used space in kbytes */
11333 +       uint32_t space_total;                   /* maximum space in kbytes */
11334 +       uint32_t inodes_used;                   /* used inodes */
11335 +       uint32_t inodes_total;                  /* maximum inodes */
11336 +       uint32_t reserved;                      /* reserved for root in % */
11337 +       uint32_t flags;
11338 +};
11339 +
11340 +#define CDLIM_UNSET            ((uint32_t)0UL)
11341 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11342 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11343 +
11344 +#define DLIME_UNIT     0
11345 +#define DLIME_KILO     1
11346 +#define DLIME_MEGA     2
11347 +#define DLIME_GIGA     3
11348 +
11349 +#define DLIMF_SHIFT    0x10
11350 +
11351 +#define DLIMS_USED     0
11352 +#define DLIMS_TOTAL    2
11353 +
11354 +static inline
11355 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11356 +{
11357 +       int exp = (flags & DLIMF_SHIFT) ?
11358 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11359 +       return ((uint64_t)val) << (10 * exp);
11360 +}
11361 +
11362 +static inline
11363 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11364 +{
11365 +       int exp = 0;
11366 +
11367 +       if (*flags & DLIMF_SHIFT) {
11368 +               while (val > (1LL << 32) && (exp < 3)) {
11369 +                       val >>= 10;
11370 +                       exp++;
11371 +               }
11372 +               *flags &= ~(DLIME_GIGA << shift);
11373 +               *flags |= exp << shift;
11374 +       } else
11375 +               val >>= 10;
11376 +       return val;
11377 +}
11378 +
11379 +#ifdef __KERNEL__
11380 +
11381 +#ifdef CONFIG_COMPAT
11382 +
11383 +#include <asm/compat.h>
11384 +
11385 +struct vcmd_ctx_dlimit_base_v0_x32 {
11386 +       compat_uptr_t name_ptr;
11387 +       uint32_t flags;
11388 +};
11389 +
11390 +struct vcmd_ctx_dlimit_v0_x32 {
11391 +       compat_uptr_t name_ptr;
11392 +       uint32_t space_used;                    /* used space in kbytes */
11393 +       uint32_t space_total;                   /* maximum space in kbytes */
11394 +       uint32_t inodes_used;                   /* used inodes */
11395 +       uint32_t inodes_total;                  /* maximum inodes */
11396 +       uint32_t reserved;                      /* reserved for root in % */
11397 +       uint32_t flags;
11398 +};
11399 +
11400 +#endif /* CONFIG_COMPAT */
11401 +
11402 +#include <linux/compiler.h>
11403 +
11404 +extern int vc_add_dlimit(uint32_t, void __user *);
11405 +extern int vc_rem_dlimit(uint32_t, void __user *);
11406 +
11407 +extern int vc_set_dlimit(uint32_t, void __user *);
11408 +extern int vc_get_dlimit(uint32_t, void __user *);
11409 +
11410 +#ifdef CONFIG_COMPAT
11411 +
11412 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11413 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11414 +
11415 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11416 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11417 +
11418 +#endif /* CONFIG_COMPAT */
11419 +
11420 +#endif /* __KERNEL__ */
11421 +#endif /* _VX_DLIMIT_CMD_H */
11422 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/dlimit.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/dlimit.h
11423 --- linux-2.6.35.4/include/linux/vserver/dlimit.h       1970-01-01 01:00:00.000000000 +0100
11424 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/dlimit.h 2010-08-02 17:05:06.000000000 +0200
11425 @@ -0,0 +1,54 @@
11426 +#ifndef _VX_DLIMIT_H
11427 +#define _VX_DLIMIT_H
11428 +
11429 +#include "switch.h"
11430 +
11431 +
11432 +#ifdef __KERNEL__
11433 +
11434 +/*      keep in sync with CDLIM_INFINITY       */
11435 +
11436 +#define DLIM_INFINITY          (~0ULL)
11437 +
11438 +#include <linux/spinlock.h>
11439 +#include <linux/rcupdate.h>
11440 +
11441 +struct super_block;
11442 +
11443 +struct dl_info {
11444 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11445 +       struct rcu_head dl_rcu;                 /* the rcu head */
11446 +       tag_t dl_tag;                           /* context tag */
11447 +       atomic_t dl_usecnt;                     /* usage count */
11448 +       atomic_t dl_refcnt;                     /* reference count */
11449 +
11450 +       struct super_block *dl_sb;              /* associated superblock */
11451 +
11452 +       spinlock_t dl_lock;                     /* protect the values */
11453 +
11454 +       unsigned long long dl_space_used;       /* used space in bytes */
11455 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11456 +       unsigned long dl_inodes_used;           /* used inodes */
11457 +       unsigned long dl_inodes_total;          /* maximum inodes */
11458 +
11459 +       unsigned int dl_nrlmult;                /* non root limit mult */
11460 +};
11461 +
11462 +struct rcu_head;
11463 +
11464 +extern void rcu_free_dl_info(struct rcu_head *);
11465 +extern void unhash_dl_info(struct dl_info *);
11466 +
11467 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11468 +
11469 +
11470 +struct kstatfs;
11471 +
11472 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11473 +
11474 +typedef uint64_t dlsize_t;
11475 +
11476 +#endif /* __KERNEL__ */
11477 +#else  /* _VX_DLIMIT_H */
11478 +#warning duplicate inclusion
11479 +#endif /* _VX_DLIMIT_H */
11480 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/global.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/global.h
11481 --- linux-2.6.35.4/include/linux/vserver/global.h       1970-01-01 01:00:00.000000000 +0100
11482 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/global.h 2010-08-02 17:05:06.000000000 +0200
11483 @@ -0,0 +1,19 @@
11484 +#ifndef _VX_GLOBAL_H
11485 +#define _VX_GLOBAL_H
11486 +
11487 +
11488 +extern atomic_t vx_global_ctotal;
11489 +extern atomic_t vx_global_cactive;
11490 +
11491 +extern atomic_t nx_global_ctotal;
11492 +extern atomic_t nx_global_cactive;
11493 +
11494 +extern atomic_t vs_global_nsproxy;
11495 +extern atomic_t vs_global_fs;
11496 +extern atomic_t vs_global_mnt_ns;
11497 +extern atomic_t vs_global_uts_ns;
11498 +extern atomic_t vs_global_user_ns;
11499 +extern atomic_t vs_global_pid_ns;
11500 +
11501 +
11502 +#endif /* _VX_GLOBAL_H */
11503 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/history.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/history.h
11504 --- linux-2.6.35.4/include/linux/vserver/history.h      1970-01-01 01:00:00.000000000 +0100
11505 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/history.h        2010-08-02 17:05:06.000000000 +0200
11506 @@ -0,0 +1,197 @@
11507 +#ifndef _VX_HISTORY_H
11508 +#define _VX_HISTORY_H
11509 +
11510 +
11511 +enum {
11512 +       VXH_UNUSED = 0,
11513 +       VXH_THROW_OOPS = 1,
11514 +
11515 +       VXH_GET_VX_INFO,
11516 +       VXH_PUT_VX_INFO,
11517 +       VXH_INIT_VX_INFO,
11518 +       VXH_SET_VX_INFO,
11519 +       VXH_CLR_VX_INFO,
11520 +       VXH_CLAIM_VX_INFO,
11521 +       VXH_RELEASE_VX_INFO,
11522 +       VXH_ALLOC_VX_INFO,
11523 +       VXH_DEALLOC_VX_INFO,
11524 +       VXH_HASH_VX_INFO,
11525 +       VXH_UNHASH_VX_INFO,
11526 +       VXH_LOC_VX_INFO,
11527 +       VXH_LOOKUP_VX_INFO,
11528 +       VXH_CREATE_VX_INFO,
11529 +};
11530 +
11531 +struct _vxhe_vxi {
11532 +       struct vx_info *ptr;
11533 +       unsigned xid;
11534 +       unsigned usecnt;
11535 +       unsigned tasks;
11536 +};
11537 +
11538 +struct _vxhe_set_clr {
11539 +       void *data;
11540 +};
11541 +
11542 +struct _vxhe_loc_lookup {
11543 +       unsigned arg;
11544 +};
11545 +
11546 +struct _vx_hist_entry {
11547 +       void *loc;
11548 +       unsigned short seq;
11549 +       unsigned short type;
11550 +       struct _vxhe_vxi vxi;
11551 +       union {
11552 +               struct _vxhe_set_clr sc;
11553 +               struct _vxhe_loc_lookup ll;
11554 +       };
11555 +};
11556 +
11557 +#ifdef CONFIG_VSERVER_HISTORY
11558 +
11559 +extern unsigned volatile int vxh_active;
11560 +
11561 +struct _vx_hist_entry *vxh_advance(void *loc);
11562 +
11563 +
11564 +static inline
11565 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11566 +{
11567 +       entry->vxi.ptr = vxi;
11568 +       if (vxi) {
11569 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11570 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11571 +               entry->vxi.xid = vxi->vx_id;
11572 +       }
11573 +}
11574 +
11575 +
11576 +#define        __HERE__ current_text_addr()
11577 +
11578 +#define __VXH_BODY(__type, __data, __here)     \
11579 +       struct _vx_hist_entry *entry;           \
11580 +                                               \
11581 +       preempt_disable();                      \
11582 +       entry = vxh_advance(__here);            \
11583 +       __data;                                 \
11584 +       entry->type = __type;                   \
11585 +       preempt_enable();
11586 +
11587 +
11588 +       /* pass vxi only */
11589 +
11590 +#define __VXH_SMPL                             \
11591 +       __vxh_copy_vxi(entry, vxi)
11592 +
11593 +static inline
11594 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11595 +{
11596 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11597 +}
11598 +
11599 +       /* pass vxi and data (void *) */
11600 +
11601 +#define __VXH_DATA                             \
11602 +       __vxh_copy_vxi(entry, vxi);             \
11603 +       entry->sc.data = data
11604 +
11605 +static inline
11606 +void   __vxh_data(struct vx_info *vxi, void *data,
11607 +                       int __type, void *__here)
11608 +{
11609 +       __VXH_BODY(__type, __VXH_DATA, __here)
11610 +}
11611 +
11612 +       /* pass vxi and arg (long) */
11613 +
11614 +#define __VXH_LONG                             \
11615 +       __vxh_copy_vxi(entry, vxi);             \
11616 +       entry->ll.arg = arg
11617 +
11618 +static inline
11619 +void   __vxh_long(struct vx_info *vxi, long arg,
11620 +                       int __type, void *__here)
11621 +{
11622 +       __VXH_BODY(__type, __VXH_LONG, __here)
11623 +}
11624 +
11625 +
11626 +static inline
11627 +void   __vxh_throw_oops(void *__here)
11628 +{
11629 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11630 +       /* prevent further acquisition */
11631 +       vxh_active = 0;
11632 +}
11633 +
11634 +
11635 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11636 +
11637 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11638 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11639 +
11640 +#define __vxh_init_vx_info(v, d, h) \
11641 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11642 +#define __vxh_set_vx_info(v, d, h) \
11643 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11644 +#define __vxh_clr_vx_info(v, d, h) \
11645 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11646 +
11647 +#define __vxh_claim_vx_info(v, d, h) \
11648 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11649 +#define __vxh_release_vx_info(v, d, h) \
11650 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11651 +
11652 +#define vxh_alloc_vx_info(v) \
11653 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11654 +#define vxh_dealloc_vx_info(v) \
11655 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11656 +
11657 +#define vxh_hash_vx_info(v) \
11658 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11659 +#define vxh_unhash_vx_info(v) \
11660 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11661 +
11662 +#define vxh_loc_vx_info(v, l) \
11663 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11664 +#define vxh_lookup_vx_info(v, l) \
11665 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11666 +#define vxh_create_vx_info(v, l) \
11667 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11668 +
11669 +extern void vxh_dump_history(void);
11670 +
11671 +
11672 +#else  /* CONFIG_VSERVER_HISTORY */
11673 +
11674 +#define        __HERE__        0
11675 +
11676 +#define vxh_throw_oops()               do { } while (0)
11677 +
11678 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11679 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11680 +
11681 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11682 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11683 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11684 +
11685 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11686 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11687 +
11688 +#define vxh_alloc_vx_info(v)           do { } while (0)
11689 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11690 +
11691 +#define vxh_hash_vx_info(v)            do { } while (0)
11692 +#define vxh_unhash_vx_info(v)          do { } while (0)
11693 +
11694 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11695 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11696 +#define vxh_create_vx_info(v, l)       do { } while (0)
11697 +
11698 +#define vxh_dump_history()             do { } while (0)
11699 +
11700 +
11701 +#endif /* CONFIG_VSERVER_HISTORY */
11702 +
11703 +#endif /* _VX_HISTORY_H */
11704 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/inode_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/inode_cmd.h
11705 --- linux-2.6.35.4/include/linux/vserver/inode_cmd.h    1970-01-01 01:00:00.000000000 +0100
11706 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/inode_cmd.h      2010-08-02 17:05:06.000000000 +0200
11707 @@ -0,0 +1,59 @@
11708 +#ifndef _VX_INODE_CMD_H
11709 +#define _VX_INODE_CMD_H
11710 +
11711 +
11712 +/*  inode vserver commands */
11713 +
11714 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11715 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11716 +
11717 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11718 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11719 +
11720 +struct vcmd_ctx_iattr_v1 {
11721 +       const char __user *name;
11722 +       uint32_t tag;
11723 +       uint32_t flags;
11724 +       uint32_t mask;
11725 +};
11726 +
11727 +struct vcmd_ctx_fiattr_v0 {
11728 +       uint32_t tag;
11729 +       uint32_t flags;
11730 +       uint32_t mask;
11731 +};
11732 +
11733 +
11734 +#ifdef __KERNEL__
11735 +
11736 +
11737 +#ifdef CONFIG_COMPAT
11738 +
11739 +#include <asm/compat.h>
11740 +
11741 +struct vcmd_ctx_iattr_v1_x32 {
11742 +       compat_uptr_t name_ptr;
11743 +       uint32_t tag;
11744 +       uint32_t flags;
11745 +       uint32_t mask;
11746 +};
11747 +
11748 +#endif /* CONFIG_COMPAT */
11749 +
11750 +#include <linux/compiler.h>
11751 +
11752 +extern int vc_get_iattr(void __user *);
11753 +extern int vc_set_iattr(void __user *);
11754 +
11755 +extern int vc_fget_iattr(uint32_t, void __user *);
11756 +extern int vc_fset_iattr(uint32_t, void __user *);
11757 +
11758 +#ifdef CONFIG_COMPAT
11759 +
11760 +extern int vc_get_iattr_x32(void __user *);
11761 +extern int vc_set_iattr_x32(void __user *);
11762 +
11763 +#endif /* CONFIG_COMPAT */
11764 +
11765 +#endif /* __KERNEL__ */
11766 +#endif /* _VX_INODE_CMD_H */
11767 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/inode.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/inode.h
11768 --- linux-2.6.35.4/include/linux/vserver/inode.h        1970-01-01 01:00:00.000000000 +0100
11769 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/inode.h  2010-08-02 17:05:06.000000000 +0200
11770 @@ -0,0 +1,39 @@
11771 +#ifndef _VX_INODE_H
11772 +#define _VX_INODE_H
11773 +
11774 +
11775 +#define IATTR_TAG      0x01000000
11776 +
11777 +#define IATTR_ADMIN    0x00000001
11778 +#define IATTR_WATCH    0x00000002
11779 +#define IATTR_HIDE     0x00000004
11780 +#define IATTR_FLAGS    0x00000007
11781 +
11782 +#define IATTR_BARRIER  0x00010000
11783 +#define IATTR_IXUNLINK 0x00020000
11784 +#define IATTR_IMMUTABLE 0x00040000
11785 +#define IATTR_COW      0x00080000
11786 +
11787 +#ifdef __KERNEL__
11788 +
11789 +
11790 +#ifdef CONFIG_VSERVER_PROC_SECURE
11791 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11792 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11793 +#else
11794 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11795 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11796 +#endif
11797 +
11798 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11799 +
11800 +#endif /* __KERNEL__ */
11801 +
11802 +/* inode ioctls */
11803 +
11804 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11805 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11806 +
11807 +#else  /* _VX_INODE_H */
11808 +#warning duplicate inclusion
11809 +#endif /* _VX_INODE_H */
11810 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/Kbuild linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/Kbuild
11811 --- linux-2.6.35.4/include/linux/vserver/Kbuild 1970-01-01 01:00:00.000000000 +0100
11812 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/Kbuild   2010-08-02 17:05:06.000000000 +0200
11813 @@ -0,0 +1,8 @@
11814 +
11815 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11816 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11817 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11818 +       debug_cmd.h device_cmd.h
11819 +
11820 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11821 +
11822 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/limit_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/limit_cmd.h
11823 --- linux-2.6.35.4/include/linux/vserver/limit_cmd.h    1970-01-01 01:00:00.000000000 +0100
11824 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/limit_cmd.h      2010-08-02 17:05:06.000000000 +0200
11825 @@ -0,0 +1,71 @@
11826 +#ifndef _VX_LIMIT_CMD_H
11827 +#define _VX_LIMIT_CMD_H
11828 +
11829 +
11830 +/*  rlimit vserver commands */
11831 +
11832 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11833 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11834 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11835 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11836 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11837 +
11838 +struct vcmd_ctx_rlimit_v0 {
11839 +       uint32_t id;
11840 +       uint64_t minimum;
11841 +       uint64_t softlimit;
11842 +       uint64_t maximum;
11843 +};
11844 +
11845 +struct vcmd_ctx_rlimit_mask_v0 {
11846 +       uint32_t minimum;
11847 +       uint32_t softlimit;
11848 +       uint32_t maximum;
11849 +};
11850 +
11851 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11852 +
11853 +struct vcmd_rlimit_stat_v0 {
11854 +       uint32_t id;
11855 +       uint32_t hits;
11856 +       uint64_t value;
11857 +       uint64_t minimum;
11858 +       uint64_t maximum;
11859 +};
11860 +
11861 +#define CRLIM_UNSET            (0ULL)
11862 +#define CRLIM_INFINITY         (~0ULL)
11863 +#define CRLIM_KEEP             (~1ULL)
11864 +
11865 +#ifdef __KERNEL__
11866 +
11867 +#ifdef CONFIG_IA32_EMULATION
11868 +
11869 +struct vcmd_ctx_rlimit_v0_x32 {
11870 +       uint32_t id;
11871 +       uint64_t minimum;
11872 +       uint64_t softlimit;
11873 +       uint64_t maximum;
11874 +} __attribute__ ((packed));
11875 +
11876 +#endif /* CONFIG_IA32_EMULATION */
11877 +
11878 +#include <linux/compiler.h>
11879 +
11880 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11881 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11882 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11883 +extern int vc_reset_hits(struct vx_info *, void __user *);
11884 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11885 +
11886 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11887 +
11888 +#ifdef CONFIG_IA32_EMULATION
11889 +
11890 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11891 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11892 +
11893 +#endif /* CONFIG_IA32_EMULATION */
11894 +
11895 +#endif /* __KERNEL__ */
11896 +#endif /* _VX_LIMIT_CMD_H */
11897 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/limit_def.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/limit_def.h
11898 --- linux-2.6.35.4/include/linux/vserver/limit_def.h    1970-01-01 01:00:00.000000000 +0100
11899 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/limit_def.h      2010-08-02 17:05:06.000000000 +0200
11900 @@ -0,0 +1,47 @@
11901 +#ifndef _VX_LIMIT_DEF_H
11902 +#define _VX_LIMIT_DEF_H
11903 +
11904 +#include <asm/atomic.h>
11905 +#include <asm/resource.h>
11906 +
11907 +#include "limit.h"
11908 +
11909 +
11910 +struct _vx_res_limit {
11911 +       rlim_t soft;            /* Context soft limit */
11912 +       rlim_t hard;            /* Context hard limit */
11913 +
11914 +       rlim_atomic_t rcur;     /* Current value */
11915 +       rlim_t rmin;            /* Context minimum */
11916 +       rlim_t rmax;            /* Context maximum */
11917 +
11918 +       atomic_t lhit;          /* Limit hits */
11919 +};
11920 +
11921 +/* context sub struct */
11922 +
11923 +struct _vx_limit {
11924 +       struct _vx_res_limit res[NUM_LIMITS];
11925 +};
11926 +
11927 +#ifdef CONFIG_VSERVER_DEBUG
11928 +
11929 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11930 +{
11931 +       int i;
11932 +
11933 +       printk("\t_vx_limit:");
11934 +       for (i = 0; i < NUM_LIMITS; i++) {
11935 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11936 +                       i, (unsigned long)__rlim_get(limit, i),
11937 +                       (unsigned long)__rlim_rmin(limit, i),
11938 +                       (unsigned long)__rlim_rmax(limit, i),
11939 +                       (long)__rlim_soft(limit, i),
11940 +                       (long)__rlim_hard(limit, i),
11941 +                       atomic_read(&__rlim_lhit(limit, i)));
11942 +       }
11943 +}
11944 +
11945 +#endif
11946 +
11947 +#endif /* _VX_LIMIT_DEF_H */
11948 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/limit.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/limit.h
11949 --- linux-2.6.35.4/include/linux/vserver/limit.h        1970-01-01 01:00:00.000000000 +0100
11950 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/limit.h  2010-08-02 17:05:06.000000000 +0200
11951 @@ -0,0 +1,71 @@
11952 +#ifndef _VX_LIMIT_H
11953 +#define _VX_LIMIT_H
11954 +
11955 +#define VLIMIT_NSOCK   16
11956 +#define VLIMIT_OPENFD  17
11957 +#define VLIMIT_ANON    18
11958 +#define VLIMIT_SHMEM   19
11959 +#define VLIMIT_SEMARY  20
11960 +#define VLIMIT_NSEMS   21
11961 +#define VLIMIT_DENTRY  22
11962 +#define VLIMIT_MAPPED  23
11963 +
11964 +
11965 +#ifdef __KERNEL__
11966 +
11967 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11968 +
11969 +/*     keep in sync with CRLIM_INFINITY */
11970 +
11971 +#define        VLIM_INFINITY   (~0ULL)
11972 +
11973 +#include <asm/atomic.h>
11974 +#include <asm/resource.h>
11975 +
11976 +#ifndef RLIM_INFINITY
11977 +#warning RLIM_INFINITY is undefined
11978 +#endif
11979 +
11980 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11981 +
11982 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11983 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11984 +
11985 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11986 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11987 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11988 +
11989 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11990 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11991 +
11992 +typedef atomic_long_t rlim_atomic_t;
11993 +typedef unsigned long rlim_t;
11994 +
11995 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11996 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11997 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11998 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11999 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12000 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12001 +
12002 +
12003 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12004 +#define        VX_VLIM(r) ((long long)(long)(r))
12005 +#define        VX_RLIM(v) ((rlim_t)(v))
12006 +#else
12007 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12008 +               ? VLIM_INFINITY : (long long)(r))
12009 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12010 +               ? RLIM_INFINITY : (rlim_t)(v))
12011 +#endif
12012 +
12013 +struct sysinfo;
12014 +
12015 +void vx_vsi_meminfo(struct sysinfo *);
12016 +void vx_vsi_swapinfo(struct sysinfo *);
12017 +long vx_vsi_cached(struct sysinfo *);
12018 +
12019 +#define NUM_LIMITS     24
12020 +
12021 +#endif /* __KERNEL__ */
12022 +#endif /* _VX_LIMIT_H */
12023 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/limit_int.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/limit_int.h
12024 --- linux-2.6.35.4/include/linux/vserver/limit_int.h    1970-01-01 01:00:00.000000000 +0100
12025 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/limit_int.h      2010-08-02 17:05:06.000000000 +0200
12026 @@ -0,0 +1,198 @@
12027 +#ifndef _VX_LIMIT_INT_H
12028 +#define _VX_LIMIT_INT_H
12029 +
12030 +#include "context.h"
12031 +
12032 +#ifdef __KERNEL__
12033 +
12034 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12035 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12036 +
12037 +extern const char *vlimit_name[NUM_LIMITS];
12038 +
12039 +static inline void __vx_acc_cres(struct vx_info *vxi,
12040 +       int res, int dir, void *_data, char *_file, int _line)
12041 +{
12042 +       if (VXD_RCRES_COND(res))
12043 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12044 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12045 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12046 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12047 +       if (!vxi)
12048 +               return;
12049 +
12050 +       if (dir > 0)
12051 +               __rlim_inc(&vxi->limit, res);
12052 +       else
12053 +               __rlim_dec(&vxi->limit, res);
12054 +}
12055 +
12056 +static inline void __vx_add_cres(struct vx_info *vxi,
12057 +       int res, int amount, void *_data, char *_file, int _line)
12058 +{
12059 +       if (VXD_RCRES_COND(res))
12060 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12061 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12062 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12063 +                       amount, _data, _file, _line);
12064 +       if (amount == 0)
12065 +               return;
12066 +       if (!vxi)
12067 +               return;
12068 +       __rlim_add(&vxi->limit, res, amount);
12069 +}
12070 +
12071 +static inline
12072 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12073 +{
12074 +       int cond = (value > __rlim_rmax(limit, res));
12075 +
12076 +       if (cond)
12077 +               __rlim_rmax(limit, res) = value;
12078 +       return cond;
12079 +}
12080 +
12081 +static inline
12082 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12083 +{
12084 +       int cond = (value < __rlim_rmin(limit, res));
12085 +
12086 +       if (cond)
12087 +               __rlim_rmin(limit, res) = value;
12088 +       return cond;
12089 +}
12090 +
12091 +static inline
12092 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12093 +{
12094 +       if (!__vx_cres_adjust_max(limit, res, value))
12095 +               __vx_cres_adjust_min(limit, res, value);
12096 +}
12097 +
12098 +
12099 +/*     return values:
12100 +        +1 ... no limit hit
12101 +        -1 ... over soft limit
12102 +         0 ... over hard limit         */
12103 +
12104 +static inline int __vx_cres_avail(struct vx_info *vxi,
12105 +       int res, int num, char *_file, int _line)
12106 +{
12107 +       struct _vx_limit *limit;
12108 +       rlim_t value;
12109 +
12110 +       if (VXD_RLIMIT_COND(res))
12111 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12112 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12113 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12114 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12115 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12116 +                       num, _file, _line);
12117 +       if (!vxi)
12118 +               return 1;
12119 +
12120 +       limit = &vxi->limit;
12121 +       value = __rlim_get(limit, res);
12122 +
12123 +       if (!__vx_cres_adjust_max(limit, res, value))
12124 +               __vx_cres_adjust_min(limit, res, value);
12125 +
12126 +       if (num == 0)
12127 +               return 1;
12128 +
12129 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12130 +               return -1;
12131 +       if (value + num <= __rlim_soft(limit, res))
12132 +               return -1;
12133 +
12134 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12135 +               return 1;
12136 +       if (value + num <= __rlim_hard(limit, res))
12137 +               return 1;
12138 +
12139 +       __rlim_hit(limit, res);
12140 +       return 0;
12141 +}
12142 +
12143 +
12144 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12145 +
12146 +static inline
12147 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12148 +{
12149 +       rlim_t value, sum = 0;
12150 +       int res;
12151 +
12152 +       while ((res = *array++)) {
12153 +               value = __rlim_get(limit, res);
12154 +               __vx_cres_fixup(limit, res, value);
12155 +               sum += value;
12156 +       }
12157 +       return sum;
12158 +}
12159 +
12160 +static inline
12161 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12162 +{
12163 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12164 +       int res = *array;
12165 +
12166 +       if (value == __rlim_get(limit, res))
12167 +               return value;
12168 +
12169 +       __rlim_set(limit, res, value);
12170 +       /* now adjust min/max */
12171 +       if (!__vx_cres_adjust_max(limit, res, value))
12172 +               __vx_cres_adjust_min(limit, res, value);
12173 +
12174 +       return value;
12175 +}
12176 +
12177 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12178 +       const int *array, int num, char *_file, int _line)
12179 +{
12180 +       struct _vx_limit *limit;
12181 +       rlim_t value = 0;
12182 +       int res;
12183 +
12184 +       if (num == 0)
12185 +               return 1;
12186 +       if (!vxi)
12187 +               return 1;
12188 +
12189 +       limit = &vxi->limit;
12190 +       res = *array;
12191 +       value = __vx_cres_array_sum(limit, array + 1);
12192 +
12193 +       __rlim_set(limit, res, value);
12194 +       __vx_cres_fixup(limit, res, value);
12195 +
12196 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12197 +}
12198 +
12199 +
12200 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12201 +{
12202 +       rlim_t value;
12203 +       int res;
12204 +
12205 +       /* complex resources first */
12206 +       if ((id < 0) || (id == RLIMIT_RSS))
12207 +               __vx_cres_array_fixup(limit, VLA_RSS);
12208 +
12209 +       for (res = 0; res < NUM_LIMITS; res++) {
12210 +               if ((id > 0) && (res != id))
12211 +                       continue;
12212 +
12213 +               value = __rlim_get(limit, res);
12214 +               __vx_cres_fixup(limit, res, value);
12215 +
12216 +               /* not supposed to happen, maybe warn? */
12217 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12218 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12219 +       }
12220 +}
12221 +
12222 +
12223 +#endif /* __KERNEL__ */
12224 +#endif /* _VX_LIMIT_INT_H */
12225 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/monitor.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/monitor.h
12226 --- linux-2.6.35.4/include/linux/vserver/monitor.h      1970-01-01 01:00:00.000000000 +0100
12227 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/monitor.h        2010-08-02 17:05:06.000000000 +0200
12228 @@ -0,0 +1,96 @@
12229 +#ifndef _VX_MONITOR_H
12230 +#define _VX_MONITOR_H
12231 +
12232 +#include <linux/types.h>
12233 +
12234 +enum {
12235 +       VXM_UNUSED = 0,
12236 +
12237 +       VXM_SYNC = 0x10,
12238 +
12239 +       VXM_UPDATE = 0x20,
12240 +       VXM_UPDATE_1,
12241 +       VXM_UPDATE_2,
12242 +
12243 +       VXM_RQINFO_1 = 0x24,
12244 +       VXM_RQINFO_2,
12245 +
12246 +       VXM_ACTIVATE = 0x40,
12247 +       VXM_DEACTIVATE,
12248 +       VXM_IDLE,
12249 +
12250 +       VXM_HOLD = 0x44,
12251 +       VXM_UNHOLD,
12252 +
12253 +       VXM_MIGRATE = 0x48,
12254 +       VXM_RESCHED,
12255 +
12256 +       /* all other bits are flags */
12257 +       VXM_SCHED = 0x80,
12258 +};
12259 +
12260 +struct _vxm_update_1 {
12261 +       uint32_t tokens_max;
12262 +       uint32_t fill_rate;
12263 +       uint32_t interval;
12264 +};
12265 +
12266 +struct _vxm_update_2 {
12267 +       uint32_t tokens_min;
12268 +       uint32_t fill_rate;
12269 +       uint32_t interval;
12270 +};
12271 +
12272 +struct _vxm_rqinfo_1 {
12273 +       uint16_t running;
12274 +       uint16_t onhold;
12275 +       uint16_t iowait;
12276 +       uint16_t uintr;
12277 +       uint32_t idle_tokens;
12278 +};
12279 +
12280 +struct _vxm_rqinfo_2 {
12281 +       uint32_t norm_time;
12282 +       uint32_t idle_time;
12283 +       uint32_t idle_skip;
12284 +};
12285 +
12286 +struct _vxm_sched {
12287 +       uint32_t tokens;
12288 +       uint32_t norm_time;
12289 +       uint32_t idle_time;
12290 +};
12291 +
12292 +struct _vxm_task {
12293 +       uint16_t pid;
12294 +       uint16_t state;
12295 +};
12296 +
12297 +struct _vxm_event {
12298 +       uint32_t jif;
12299 +       union {
12300 +               uint32_t seq;
12301 +               uint32_t sec;
12302 +       };
12303 +       union {
12304 +               uint32_t tokens;
12305 +               uint32_t nsec;
12306 +               struct _vxm_task tsk;
12307 +       };
12308 +};
12309 +
12310 +struct _vx_mon_entry {
12311 +       uint16_t type;
12312 +       uint16_t xid;
12313 +       union {
12314 +               struct _vxm_event ev;
12315 +               struct _vxm_sched sd;
12316 +               struct _vxm_update_1 u1;
12317 +               struct _vxm_update_2 u2;
12318 +               struct _vxm_rqinfo_1 q1;
12319 +               struct _vxm_rqinfo_2 q2;
12320 +       };
12321 +};
12322 +
12323 +
12324 +#endif /* _VX_MONITOR_H */
12325 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/network_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/network_cmd.h
12326 --- linux-2.6.35.4/include/linux/vserver/network_cmd.h  1970-01-01 01:00:00.000000000 +0100
12327 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/network_cmd.h    2010-08-02 17:05:06.000000000 +0200
12328 @@ -0,0 +1,150 @@
12329 +#ifndef _VX_NETWORK_CMD_H
12330 +#define _VX_NETWORK_CMD_H
12331 +
12332 +
12333 +/* vinfo commands */
12334 +
12335 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12336 +
12337 +#ifdef __KERNEL__
12338 +extern int vc_task_nid(uint32_t);
12339 +
12340 +#endif /* __KERNEL__ */
12341 +
12342 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12343 +
12344 +struct vcmd_nx_info_v0 {
12345 +       uint32_t nid;
12346 +       /* more to come */
12347 +};
12348 +
12349 +#ifdef __KERNEL__
12350 +extern int vc_nx_info(struct nx_info *, void __user *);
12351 +
12352 +#endif /* __KERNEL__ */
12353 +
12354 +#include <linux/in.h>
12355 +#include <linux/in6.h>
12356 +
12357 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12358 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12359 +
12360 +struct  vcmd_net_create {
12361 +       uint64_t flagword;
12362 +};
12363 +
12364 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12365 +
12366 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12367 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12368 +
12369 +struct vcmd_net_addr_v0 {
12370 +       uint16_t type;
12371 +       uint16_t count;
12372 +       struct in_addr ip[4];
12373 +       struct in_addr mask[4];
12374 +};
12375 +
12376 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12377 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12378 +
12379 +struct vcmd_net_addr_ipv4_v1 {
12380 +       uint16_t type;
12381 +       uint16_t flags;
12382 +       struct in_addr ip;
12383 +       struct in_addr mask;
12384 +};
12385 +
12386 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12387 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12388 +
12389 +struct vcmd_net_addr_ipv6_v1 {
12390 +       uint16_t type;
12391 +       uint16_t flags;
12392 +       uint32_t prefix;
12393 +       struct in6_addr ip;
12394 +       struct in6_addr mask;
12395 +};
12396 +
12397 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12398 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12399 +
12400 +struct vcmd_match_ipv4_v0 {
12401 +       uint16_t type;
12402 +       uint16_t flags;
12403 +       uint16_t parent;
12404 +       uint16_t prefix;
12405 +       struct in_addr ip;
12406 +       struct in_addr ip2;
12407 +       struct in_addr mask;
12408 +};
12409 +
12410 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12411 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12412 +
12413 +struct vcmd_match_ipv6_v0 {
12414 +       uint16_t type;
12415 +       uint16_t flags;
12416 +       uint16_t parent;
12417 +       uint16_t prefix;
12418 +       struct in6_addr ip;
12419 +       struct in6_addr ip2;
12420 +       struct in6_addr mask;
12421 +};
12422 +
12423 +
12424 +#ifdef __KERNEL__
12425 +extern int vc_net_create(uint32_t, void __user *);
12426 +extern int vc_net_migrate(struct nx_info *, void __user *);
12427 +
12428 +extern int vc_net_add(struct nx_info *, void __user *);
12429 +extern int vc_net_remove(struct nx_info *, void __user *);
12430 +
12431 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12432 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12433 +
12434 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12435 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12436 +
12437 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12438 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12439 +
12440 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12441 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12442 +
12443 +#endif /* __KERNEL__ */
12444 +
12445 +
12446 +/* flag commands */
12447 +
12448 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12449 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12450 +
12451 +struct vcmd_net_flags_v0 {
12452 +       uint64_t flagword;
12453 +       uint64_t mask;
12454 +};
12455 +
12456 +#ifdef __KERNEL__
12457 +extern int vc_get_nflags(struct nx_info *, void __user *);
12458 +extern int vc_set_nflags(struct nx_info *, void __user *);
12459 +
12460 +#endif /* __KERNEL__ */
12461 +
12462 +
12463 +/* network caps commands */
12464 +
12465 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12466 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12467 +
12468 +struct vcmd_net_caps_v0 {
12469 +       uint64_t ncaps;
12470 +       uint64_t cmask;
12471 +};
12472 +
12473 +#ifdef __KERNEL__
12474 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12475 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12476 +
12477 +#endif /* __KERNEL__ */
12478 +#endif /* _VX_CONTEXT_CMD_H */
12479 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/network.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/network.h
12480 --- linux-2.6.35.4/include/linux/vserver/network.h      1970-01-01 01:00:00.000000000 +0100
12481 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/network.h        2010-08-02 17:05:06.000000000 +0200
12482 @@ -0,0 +1,146 @@
12483 +#ifndef _VX_NETWORK_H
12484 +#define _VX_NETWORK_H
12485 +
12486 +#include <linux/types.h>
12487 +
12488 +
12489 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12490 +
12491 +
12492 +/* network flags */
12493 +
12494 +#define NXF_INFO_PRIVATE       0x00000008
12495 +
12496 +#define NXF_SINGLE_IP          0x00000100
12497 +#define NXF_LBACK_REMAP                0x00000200
12498 +#define NXF_LBACK_ALLOW                0x00000400
12499 +
12500 +#define NXF_HIDE_NETIF         0x02000000
12501 +#define NXF_HIDE_LBACK         0x04000000
12502 +
12503 +#define NXF_STATE_SETUP                (1ULL << 32)
12504 +#define NXF_STATE_ADMIN                (1ULL << 34)
12505 +
12506 +#define NXF_SC_HELPER          (1ULL << 36)
12507 +#define NXF_PERSISTENT         (1ULL << 38)
12508 +
12509 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12510 +
12511 +
12512 +#define        NXF_INIT_SET            (__nxf_init_set())
12513 +
12514 +static inline uint64_t __nxf_init_set(void) {
12515 +       return    NXF_STATE_ADMIN
12516 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12517 +               | NXF_LBACK_REMAP
12518 +               | NXF_HIDE_LBACK
12519 +#endif
12520 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12521 +               | NXF_SINGLE_IP
12522 +#endif
12523 +               | NXF_HIDE_NETIF;
12524 +}
12525 +
12526 +
12527 +/* network caps */
12528 +
12529 +#define NXC_TUN_CREATE         0x00000001
12530 +
12531 +#define NXC_RAW_ICMP           0x00000100
12532 +
12533 +
12534 +/* address types */
12535 +
12536 +#define NXA_TYPE_IPV4          0x0001
12537 +#define NXA_TYPE_IPV6          0x0002
12538 +
12539 +#define NXA_TYPE_NONE          0x0000
12540 +#define NXA_TYPE_ANY           0x00FF
12541 +
12542 +#define NXA_TYPE_ADDR          0x0010
12543 +#define NXA_TYPE_MASK          0x0020
12544 +#define NXA_TYPE_RANGE         0x0040
12545 +
12546 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12547 +
12548 +#define NXA_MOD_BCAST          0x0100
12549 +#define NXA_MOD_LBACK          0x0200
12550 +
12551 +#define NXA_LOOPBACK           0x1000
12552 +
12553 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12554 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12555 +
12556 +#ifdef __KERNEL__
12557 +
12558 +#include <linux/list.h>
12559 +#include <linux/spinlock.h>
12560 +#include <linux/rcupdate.h>
12561 +#include <linux/in.h>
12562 +#include <linux/in6.h>
12563 +#include <asm/atomic.h>
12564 +
12565 +struct nx_addr_v4 {
12566 +       struct nx_addr_v4 *next;
12567 +       struct in_addr ip[2];
12568 +       struct in_addr mask;
12569 +       uint16_t type;
12570 +       uint16_t flags;
12571 +};
12572 +
12573 +struct nx_addr_v6 {
12574 +       struct nx_addr_v6 *next;
12575 +       struct in6_addr ip;
12576 +       struct in6_addr mask;
12577 +       uint32_t prefix;
12578 +       uint16_t type;
12579 +       uint16_t flags;
12580 +};
12581 +
12582 +struct nx_info {
12583 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12584 +       nid_t nx_id;                    /* vnet id */
12585 +       atomic_t nx_usecnt;             /* usage count */
12586 +       atomic_t nx_tasks;              /* tasks count */
12587 +       int nx_state;                   /* context state */
12588 +
12589 +       uint64_t nx_flags;              /* network flag word */
12590 +       uint64_t nx_ncaps;              /* network capabilities */
12591 +
12592 +       struct in_addr v4_lback;        /* Loopback address */
12593 +       struct in_addr v4_bcast;        /* Broadcast address */
12594 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12595 +#ifdef CONFIG_IPV6
12596 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12597 +#endif
12598 +       char nx_name[65];               /* network context name */
12599 +};
12600 +
12601 +
12602 +/* status flags */
12603 +
12604 +#define NXS_HASHED      0x0001
12605 +#define NXS_SHUTDOWN    0x0100
12606 +#define NXS_RELEASED    0x8000
12607 +
12608 +extern struct nx_info *lookup_nx_info(int);
12609 +
12610 +extern int get_nid_list(int, unsigned int *, int);
12611 +extern int nid_is_hashed(nid_t);
12612 +
12613 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12614 +
12615 +extern long vs_net_change(struct nx_info *, unsigned int);
12616 +
12617 +struct sock;
12618 +
12619 +
12620 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12621 +#ifdef  CONFIG_IPV6
12622 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12623 +#else
12624 +#define NX_IPV6(n)     (0)
12625 +#endif
12626 +
12627 +#endif /* __KERNEL__ */
12628 +#endif /* _VX_NETWORK_H */
12629 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/percpu.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/percpu.h
12630 --- linux-2.6.35.4/include/linux/vserver/percpu.h       1970-01-01 01:00:00.000000000 +0100
12631 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/percpu.h 2010-08-02 17:05:06.000000000 +0200
12632 @@ -0,0 +1,14 @@
12633 +#ifndef _VX_PERCPU_H
12634 +#define _VX_PERCPU_H
12635 +
12636 +#include "cvirt_def.h"
12637 +#include "sched_def.h"
12638 +
12639 +struct _vx_percpu {
12640 +       struct _vx_cvirt_pc cvirt;
12641 +       struct _vx_sched_pc sched;
12642 +};
12643 +
12644 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12645 +
12646 +#endif /* _VX_PERCPU_H */
12647 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/pid.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/pid.h
12648 --- linux-2.6.35.4/include/linux/vserver/pid.h  1970-01-01 01:00:00.000000000 +0100
12649 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/pid.h    2010-08-02 17:05:06.000000000 +0200
12650 @@ -0,0 +1,51 @@
12651 +#ifndef _VSERVER_PID_H
12652 +#define _VSERVER_PID_H
12653 +
12654 +/* pid faking stuff */
12655 +
12656 +#define vx_info_map_pid(v, p) \
12657 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12658 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12659 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12660 +#define vx_map_tgid(p) vx_map_pid(p)
12661 +
12662 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12663 +       const char *func, const char *file, int line)
12664 +{
12665 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12666 +               vxfprintk(VXD_CBIT(cvirt, 2),
12667 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12668 +                       vxi, (long long)vxi->vx_flags, pid,
12669 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12670 +                       func, file, line);
12671 +               if (pid == 0)
12672 +                       return 0;
12673 +               if (pid == vxi->vx_initpid)
12674 +                       return 1;
12675 +       }
12676 +       return pid;
12677 +}
12678 +
12679 +#define vx_info_rmap_pid(v, p) \
12680 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12681 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12682 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12683 +
12684 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12685 +       const char *func, const char *file, int line)
12686 +{
12687 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12688 +               vxfprintk(VXD_CBIT(cvirt, 2),
12689 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12690 +                       vxi, (long long)vxi->vx_flags, pid,
12691 +                       (pid == 1) ? vxi->vx_initpid : pid,
12692 +                       func, file, line);
12693 +               if ((pid == 1) && vxi->vx_initpid)
12694 +                       return vxi->vx_initpid;
12695 +               if (pid == vxi->vx_initpid)
12696 +                       return ~0U;
12697 +       }
12698 +       return pid;
12699 +}
12700 +
12701 +#endif
12702 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/sched_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/sched_cmd.h
12703 --- linux-2.6.35.4/include/linux/vserver/sched_cmd.h    1970-01-01 01:00:00.000000000 +0100
12704 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/sched_cmd.h      2010-08-02 17:05:06.000000000 +0200
12705 @@ -0,0 +1,108 @@
12706 +#ifndef _VX_SCHED_CMD_H
12707 +#define _VX_SCHED_CMD_H
12708 +
12709 +
12710 +/*  sched vserver commands */
12711 +
12712 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12713 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12714 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12715 +
12716 +struct vcmd_set_sched_v2 {
12717 +       int32_t fill_rate;
12718 +       int32_t interval;
12719 +       int32_t tokens;
12720 +       int32_t tokens_min;
12721 +       int32_t tokens_max;
12722 +       uint64_t cpu_mask;
12723 +};
12724 +
12725 +struct vcmd_set_sched_v3 {
12726 +       uint32_t set_mask;
12727 +       int32_t fill_rate;
12728 +       int32_t interval;
12729 +       int32_t tokens;
12730 +       int32_t tokens_min;
12731 +       int32_t tokens_max;
12732 +       int32_t priority_bias;
12733 +};
12734 +
12735 +struct vcmd_set_sched_v4 {
12736 +       uint32_t set_mask;
12737 +       int32_t fill_rate;
12738 +       int32_t interval;
12739 +       int32_t tokens;
12740 +       int32_t tokens_min;
12741 +       int32_t tokens_max;
12742 +       int32_t prio_bias;
12743 +       int32_t cpu_id;
12744 +       int32_t bucket_id;
12745 +};
12746 +
12747 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12748 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12749 +
12750 +struct vcmd_sched_v5 {
12751 +       uint32_t mask;
12752 +       int32_t cpu_id;
12753 +       int32_t bucket_id;
12754 +       int32_t fill_rate[2];
12755 +       int32_t interval[2];
12756 +       int32_t tokens;
12757 +       int32_t tokens_min;
12758 +       int32_t tokens_max;
12759 +       int32_t prio_bias;
12760 +};
12761 +
12762 +#define VXSM_FILL_RATE         0x0001
12763 +#define VXSM_INTERVAL          0x0002
12764 +#define VXSM_FILL_RATE2                0x0004
12765 +#define VXSM_INTERVAL2         0x0008
12766 +#define VXSM_TOKENS            0x0010
12767 +#define VXSM_TOKENS_MIN                0x0020
12768 +#define VXSM_TOKENS_MAX                0x0040
12769 +#define VXSM_PRIO_BIAS         0x0100
12770 +
12771 +#define VXSM_IDLE_TIME         0x0200
12772 +#define VXSM_FORCE             0x0400
12773 +
12774 +#define        VXSM_V3_MASK            0x0173
12775 +#define        VXSM_SET_MASK           0x01FF
12776 +
12777 +#define VXSM_CPU_ID            0x1000
12778 +#define VXSM_BUCKET_ID         0x2000
12779 +
12780 +#define VXSM_MSEC              0x4000
12781 +
12782 +#define SCHED_KEEP             (-2)    /* only for v2 */
12783 +
12784 +#ifdef __KERNEL__
12785 +
12786 +#include <linux/compiler.h>
12787 +
12788 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12789 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12790 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12791 +extern int vc_set_sched(struct vx_info *, void __user *);
12792 +extern int vc_get_sched(struct vx_info *, void __user *);
12793 +
12794 +#endif /* __KERNEL__ */
12795 +
12796 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12797 +
12798 +struct vcmd_sched_info {
12799 +       int32_t cpu_id;
12800 +       int32_t bucket_id;
12801 +       uint64_t user_msec;
12802 +       uint64_t sys_msec;
12803 +       uint64_t hold_msec;
12804 +       uint32_t token_usec;
12805 +       int32_t vavavoom;
12806 +};
12807 +
12808 +#ifdef __KERNEL__
12809 +
12810 +extern int vc_sched_info(struct vx_info *, void __user *);
12811 +
12812 +#endif /* __KERNEL__ */
12813 +#endif /* _VX_SCHED_CMD_H */
12814 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/sched_def.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/sched_def.h
12815 --- linux-2.6.35.4/include/linux/vserver/sched_def.h    1970-01-01 01:00:00.000000000 +0100
12816 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/sched_def.h      2010-08-02 17:05:06.000000000 +0200
12817 @@ -0,0 +1,68 @@
12818 +#ifndef _VX_SCHED_DEF_H
12819 +#define _VX_SCHED_DEF_H
12820 +
12821 +#include <linux/spinlock.h>
12822 +#include <linux/jiffies.h>
12823 +#include <linux/cpumask.h>
12824 +#include <asm/atomic.h>
12825 +#include <asm/param.h>
12826 +
12827 +
12828 +/* context sub struct */
12829 +
12830 +struct _vx_sched {
12831 +       spinlock_t tokens_lock;         /* lock for token bucket */
12832 +
12833 +       int tokens;                     /* number of CPU tokens */
12834 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12835 +       int interval[2];                /* Divisor:   per Y jiffies   */
12836 +       int tokens_min;                 /* Limit:     minimum for unhold */
12837 +       int tokens_max;                 /* Limit:     no more than N tokens */
12838 +
12839 +       int prio_bias;                  /* bias offset for priority */
12840 +
12841 +       unsigned update_mask;           /* which features should be updated */
12842 +       cpumask_t update;               /* CPUs which should update */
12843 +};
12844 +
12845 +struct _vx_sched_pc {
12846 +       int tokens;                     /* number of CPU tokens */
12847 +       int flags;                      /* bucket flags */
12848 +
12849 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12850 +       int interval[2];                /* Divisor:   per Y jiffies   */
12851 +       int tokens_min;                 /* Limit:     minimum for unhold */
12852 +       int tokens_max;                 /* Limit:     no more than N tokens */
12853 +
12854 +       int prio_bias;                  /* bias offset for priority */
12855 +       int vavavoom;                   /* last calculated vavavoom */
12856 +
12857 +       unsigned long norm_time;        /* last time accounted */
12858 +       unsigned long idle_time;        /* non linear time for fair sched */
12859 +       unsigned long token_time;       /* token time for accounting */
12860 +       unsigned long onhold;           /* jiffies when put on hold */
12861 +
12862 +       uint64_t user_ticks;            /* token tick events */
12863 +       uint64_t sys_ticks;             /* token tick events */
12864 +       uint64_t hold_ticks;            /* token ticks paused */
12865 +};
12866 +
12867 +
12868 +#define VXSF_ONHOLD    0x0001
12869 +#define VXSF_IDLE_TIME 0x0100
12870 +
12871 +#ifdef CONFIG_VSERVER_DEBUG
12872 +
12873 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12874 +{
12875 +       printk("\t_vx_sched:\n");
12876 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12877 +               sched->fill_rate[0], sched->interval[0],
12878 +               sched->fill_rate[1], sched->interval[1],
12879 +               sched->tokens_min, sched->tokens_max);
12880 +       printk("\t priority = %4d\n", sched->prio_bias);
12881 +}
12882 +
12883 +#endif
12884 +
12885 +#endif /* _VX_SCHED_DEF_H */
12886 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/sched.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/sched.h
12887 --- linux-2.6.35.4/include/linux/vserver/sched.h        1970-01-01 01:00:00.000000000 +0100
12888 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/sched.h  2010-08-02 17:05:06.000000000 +0200
12889 @@ -0,0 +1,26 @@
12890 +#ifndef _VX_SCHED_H
12891 +#define _VX_SCHED_H
12892 +
12893 +
12894 +#ifdef __KERNEL__
12895 +
12896 +struct timespec;
12897 +
12898 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12899 +
12900 +
12901 +struct vx_info;
12902 +
12903 +void vx_update_load(struct vx_info *);
12904 +
12905 +
12906 +int vx_tokens_recalc(struct _vx_sched_pc *,
12907 +       unsigned long *, unsigned long *, int [2]);
12908 +
12909 +void vx_update_sched_param(struct _vx_sched *sched,
12910 +       struct _vx_sched_pc *sched_pc);
12911 +
12912 +#endif /* __KERNEL__ */
12913 +#else  /* _VX_SCHED_H */
12914 +#warning duplicate inclusion
12915 +#endif /* _VX_SCHED_H */
12916 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/signal_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/signal_cmd.h
12917 --- linux-2.6.35.4/include/linux/vserver/signal_cmd.h   1970-01-01 01:00:00.000000000 +0100
12918 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/signal_cmd.h     2010-08-02 17:05:06.000000000 +0200
12919 @@ -0,0 +1,43 @@
12920 +#ifndef _VX_SIGNAL_CMD_H
12921 +#define _VX_SIGNAL_CMD_H
12922 +
12923 +
12924 +/*  signalling vserver commands */
12925 +
12926 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12927 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12928 +
12929 +struct vcmd_ctx_kill_v0 {
12930 +       int32_t pid;
12931 +       int32_t sig;
12932 +};
12933 +
12934 +struct vcmd_wait_exit_v0 {
12935 +       int32_t reboot_cmd;
12936 +       int32_t exit_code;
12937 +};
12938 +
12939 +#ifdef __KERNEL__
12940 +
12941 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12942 +extern int vc_wait_exit(struct vx_info *, void __user *);
12943 +
12944 +#endif /* __KERNEL__ */
12945 +
12946 +/*  process alteration commands */
12947 +
12948 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12949 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12950 +
12951 +struct vcmd_pflags_v0 {
12952 +       uint32_t flagword;
12953 +       uint32_t mask;
12954 +};
12955 +
12956 +#ifdef __KERNEL__
12957 +
12958 +extern int vc_get_pflags(uint32_t pid, void __user *);
12959 +extern int vc_set_pflags(uint32_t pid, void __user *);
12960 +
12961 +#endif /* __KERNEL__ */
12962 +#endif /* _VX_SIGNAL_CMD_H */
12963 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/signal.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/signal.h
12964 --- linux-2.6.35.4/include/linux/vserver/signal.h       1970-01-01 01:00:00.000000000 +0100
12965 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/signal.h 2010-08-02 17:05:06.000000000 +0200
12966 @@ -0,0 +1,14 @@
12967 +#ifndef _VX_SIGNAL_H
12968 +#define _VX_SIGNAL_H
12969 +
12970 +
12971 +#ifdef __KERNEL__
12972 +
12973 +struct vx_info;
12974 +
12975 +int vx_info_kill(struct vx_info *, int, int);
12976 +
12977 +#endif /* __KERNEL__ */
12978 +#else  /* _VX_SIGNAL_H */
12979 +#warning duplicate inclusion
12980 +#endif /* _VX_SIGNAL_H */
12981 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/space_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/space_cmd.h
12982 --- linux-2.6.35.4/include/linux/vserver/space_cmd.h    1970-01-01 01:00:00.000000000 +0100
12983 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/space_cmd.h      2010-08-02 17:05:06.000000000 +0200
12984 @@ -0,0 +1,38 @@
12985 +#ifndef _VX_SPACE_CMD_H
12986 +#define _VX_SPACE_CMD_H
12987 +
12988 +
12989 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12990 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12991 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12992 +
12993 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12994 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12995 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12996 +
12997 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12998 +
12999 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13000 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13001 +
13002 +
13003 +struct vcmd_space_mask_v1 {
13004 +       uint64_t mask;
13005 +};
13006 +
13007 +struct vcmd_space_mask_v2 {
13008 +       uint64_t mask;
13009 +       uint32_t index;
13010 +};
13011 +
13012 +
13013 +#ifdef __KERNEL__
13014 +
13015 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13016 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13017 +extern int vc_enter_space(struct vx_info *, void __user *);
13018 +extern int vc_set_space(struct vx_info *, void __user *);
13019 +extern int vc_get_space_mask(void __user *, int);
13020 +
13021 +#endif /* __KERNEL__ */
13022 +#endif /* _VX_SPACE_CMD_H */
13023 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/space.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/space.h
13024 --- linux-2.6.35.4/include/linux/vserver/space.h        1970-01-01 01:00:00.000000000 +0100
13025 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/space.h  2010-08-02 17:05:06.000000000 +0200
13026 @@ -0,0 +1,12 @@
13027 +#ifndef _VX_SPACE_H
13028 +#define _VX_SPACE_H
13029 +
13030 +#include <linux/types.h>
13031 +
13032 +struct vx_info;
13033 +
13034 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13035 +
13036 +#else  /* _VX_SPACE_H */
13037 +#warning duplicate inclusion
13038 +#endif /* _VX_SPACE_H */
13039 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/switch.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/switch.h
13040 --- linux-2.6.35.4/include/linux/vserver/switch.h       1970-01-01 01:00:00.000000000 +0100
13041 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/switch.h 2010-08-02 17:05:06.000000000 +0200
13042 @@ -0,0 +1,98 @@
13043 +#ifndef _VX_SWITCH_H
13044 +#define _VX_SWITCH_H
13045 +
13046 +#include <linux/types.h>
13047 +
13048 +
13049 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13050 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13051 +#define VC_VERSION(c)          ((c) & 0xFFF)
13052 +
13053 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13054 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13055 +
13056 +/*
13057 +
13058 +  Syscall Matrix V2.8
13059 +
13060 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13061 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13062 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13063 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13064 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13065 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13066 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13067 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13068 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13069 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13070 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13071 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13072 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13073 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13074 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13075 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13076 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13077 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13078 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13079 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13080 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13081 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13082 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13083 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13084 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13085 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13086 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13087 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13088 +
13089 +*/
13090 +
13091 +#define VC_CAT_VERSION         0
13092 +
13093 +#define VC_CAT_VSETUP          1
13094 +#define VC_CAT_VHOST           2
13095 +
13096 +#define VC_CAT_DEVICE          6
13097 +
13098 +#define VC_CAT_VPROC           9
13099 +#define VC_CAT_PROCALT         10
13100 +#define VC_CAT_PROCMIG         11
13101 +#define VC_CAT_PROCTRL         12
13102 +
13103 +#define VC_CAT_SCHED           14
13104 +#define VC_CAT_MEMCTRL         20
13105 +
13106 +#define VC_CAT_VNET            25
13107 +#define VC_CAT_NETALT          26
13108 +#define VC_CAT_NETMIG          27
13109 +#define VC_CAT_NETCTRL         28
13110 +
13111 +#define VC_CAT_TAGMIG          35
13112 +#define VC_CAT_DLIMIT          36
13113 +#define VC_CAT_INODE           38
13114 +
13115 +#define VC_CAT_VSTAT           40
13116 +#define VC_CAT_VINFO           46
13117 +#define VC_CAT_EVENT           48
13118 +
13119 +#define VC_CAT_FLAGS           52
13120 +#define VC_CAT_VSPACE          54
13121 +#define VC_CAT_DEBUG           56
13122 +#define VC_CAT_RLIMIT          60
13123 +
13124 +#define VC_CAT_SYSTEST         61
13125 +#define VC_CAT_COMPAT          63
13126 +
13127 +/*  query version */
13128 +
13129 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13130 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13131 +
13132 +
13133 +#ifdef __KERNEL__
13134 +
13135 +#include <linux/errno.h>
13136 +
13137 +#endif /* __KERNEL__ */
13138 +
13139 +#endif /* _VX_SWITCH_H */
13140 +
13141 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/tag_cmd.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/tag_cmd.h
13142 --- linux-2.6.35.4/include/linux/vserver/tag_cmd.h      1970-01-01 01:00:00.000000000 +0100
13143 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/tag_cmd.h        2010-08-02 17:05:06.000000000 +0200
13144 @@ -0,0 +1,22 @@
13145 +#ifndef _VX_TAG_CMD_H
13146 +#define _VX_TAG_CMD_H
13147 +
13148 +
13149 +/* vinfo commands */
13150 +
13151 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13152 +
13153 +#ifdef __KERNEL__
13154 +extern int vc_task_tag(uint32_t);
13155 +
13156 +#endif /* __KERNEL__ */
13157 +
13158 +/* context commands */
13159 +
13160 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13161 +
13162 +#ifdef __KERNEL__
13163 +extern int vc_tag_migrate(uint32_t);
13164 +
13165 +#endif /* __KERNEL__ */
13166 +#endif /* _VX_TAG_CMD_H */
13167 diff -NurpP --minimal linux-2.6.35.4/include/linux/vserver/tag.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/tag.h
13168 --- linux-2.6.35.4/include/linux/vserver/tag.h  1970-01-01 01:00:00.000000000 +0100
13169 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vserver/tag.h    2010-08-02 17:05:06.000000000 +0200
13170 @@ -0,0 +1,143 @@
13171 +#ifndef _DX_TAG_H
13172 +#define _DX_TAG_H
13173 +
13174 +#include <linux/types.h>
13175 +
13176 +
13177 +#define DX_TAG(in)     (IS_TAGGED(in))
13178 +
13179 +
13180 +#ifdef CONFIG_TAG_NFSD
13181 +#define DX_TAG_NFSD    1
13182 +#else
13183 +#define DX_TAG_NFSD    0
13184 +#endif
13185 +
13186 +
13187 +#ifdef CONFIG_TAGGING_NONE
13188 +
13189 +#define MAX_UID                0xFFFFFFFF
13190 +#define MAX_GID                0xFFFFFFFF
13191 +
13192 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13193 +
13194 +#define TAGINO_UID(cond, uid, tag)     (uid)
13195 +#define TAGINO_GID(cond, gid, tag)     (gid)
13196 +
13197 +#endif
13198 +
13199 +
13200 +#ifdef CONFIG_TAGGING_GID16
13201 +
13202 +#define MAX_UID                0xFFFFFFFF
13203 +#define MAX_GID                0x0000FFFF
13204 +
13205 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13206 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13207 +
13208 +#define TAGINO_UID(cond, uid, tag)     (uid)
13209 +#define TAGINO_GID(cond, gid, tag)     \
13210 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13211 +
13212 +#endif
13213 +
13214 +
13215 +#ifdef CONFIG_TAGGING_ID24
13216 +
13217 +#define MAX_UID                0x00FFFFFF
13218 +#define MAX_GID                0x00FFFFFF
13219 +
13220 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13221 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13222 +
13223 +#define TAGINO_UID(cond, uid, tag)     \
13224 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13225 +#define TAGINO_GID(cond, gid, tag)     \
13226 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13227 +
13228 +#endif
13229 +
13230 +
13231 +#ifdef CONFIG_TAGGING_UID16
13232 +
13233 +#define MAX_UID                0x0000FFFF
13234 +#define MAX_GID                0xFFFFFFFF
13235 +
13236 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13237 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13238 +
13239 +#define TAGINO_UID(cond, uid, tag)     \
13240 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13241 +#define TAGINO_GID(cond, gid, tag)     (gid)
13242 +
13243 +#endif
13244 +
13245 +
13246 +#ifdef CONFIG_TAGGING_INTERN
13247 +
13248 +#define MAX_UID                0xFFFFFFFF
13249 +#define MAX_GID                0xFFFFFFFF
13250 +
13251 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13252 +       ((cond) ? (tag) : 0)
13253 +
13254 +#define TAGINO_UID(cond, uid, tag)     (uid)
13255 +#define TAGINO_GID(cond, gid, tag)     (gid)
13256 +
13257 +#endif
13258 +
13259 +
13260 +#ifndef CONFIG_TAGGING_NONE
13261 +#define dx_current_fstag(sb)   \
13262 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13263 +#else
13264 +#define dx_current_fstag(sb)   (0)
13265 +#endif
13266 +
13267 +#ifndef CONFIG_TAGGING_INTERN
13268 +#define TAGINO_TAG(cond, tag)  (0)
13269 +#else
13270 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13271 +#endif
13272 +
13273 +#define INOTAG_UID(cond, uid, gid)     \
13274 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13275 +#define INOTAG_GID(cond, uid, gid)     \
13276 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13277 +
13278 +
13279 +static inline uid_t dx_map_uid(uid_t uid)
13280 +{
13281 +       if ((uid > MAX_UID) && (uid != -1))
13282 +               uid = -2;
13283 +       return (uid & MAX_UID);
13284 +}
13285 +
13286 +static inline gid_t dx_map_gid(gid_t gid)
13287 +{
13288 +       if ((gid > MAX_GID) && (gid != -1))
13289 +               gid = -2;
13290 +       return (gid & MAX_GID);
13291 +}
13292 +
13293 +struct peer_tag {
13294 +       int32_t xid;
13295 +       int32_t nid;
13296 +};
13297 +
13298 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13299 +
13300 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13301 +                unsigned long *flags);
13302 +
13303 +#ifdef CONFIG_PROPAGATE
13304 +
13305 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13306 +
13307 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13308 +
13309 +#else
13310 +#define dx_propagate_tag(n, i) do { } while (0)
13311 +#endif
13312 +
13313 +#endif /* _DX_TAG_H */
13314 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_inet6.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_inet6.h
13315 --- linux-2.6.35.4/include/linux/vs_inet6.h     1970-01-01 01:00:00.000000000 +0100
13316 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_inet6.h       2010-08-02 17:05:06.000000000 +0200
13317 @@ -0,0 +1,246 @@
13318 +#ifndef _VS_INET6_H
13319 +#define _VS_INET6_H
13320 +
13321 +#include "vserver/base.h"
13322 +#include "vserver/network.h"
13323 +#include "vserver/debug.h"
13324 +
13325 +#include <net/ipv6.h>
13326 +
13327 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13328 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13329 +
13330 +
13331 +#ifdef CONFIG_IPV6
13332 +
13333 +static inline
13334 +int v6_addr_match(struct nx_addr_v6 *nxa,
13335 +       const struct in6_addr *addr, uint16_t mask)
13336 +{
13337 +       int ret = 0;
13338 +
13339 +       switch (nxa->type & mask) {
13340 +       case NXA_TYPE_MASK:
13341 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13342 +               break;
13343 +       case NXA_TYPE_ADDR:
13344 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13345 +               break;
13346 +       case NXA_TYPE_ANY:
13347 +               ret = 1;
13348 +               break;
13349 +       }
13350 +       vxdprintk(VXD_CBIT(net, 0),
13351 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13352 +               nxa, NXAV6(nxa), addr, mask, ret);
13353 +       return ret;
13354 +}
13355 +
13356 +static inline
13357 +int v6_addr_in_nx_info(struct nx_info *nxi,
13358 +       const struct in6_addr *addr, uint16_t mask)
13359 +{
13360 +       struct nx_addr_v6 *nxa;
13361 +       int ret = 1;
13362 +
13363 +       if (!nxi)
13364 +               goto out;
13365 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13366 +               if (v6_addr_match(nxa, addr, mask))
13367 +                       goto out;
13368 +       ret = 0;
13369 +out:
13370 +       vxdprintk(VXD_CBIT(net, 0),
13371 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13372 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13373 +       return ret;
13374 +}
13375 +
13376 +static inline
13377 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13378 +{
13379 +       /* FIXME: needs full range checks */
13380 +       return v6_addr_match(nxa, &addr->ip, mask);
13381 +}
13382 +
13383 +static inline
13384 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13385 +{
13386 +       struct nx_addr_v6 *ptr;
13387 +
13388 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13389 +               if (v6_nx_addr_match(ptr, nxa, mask))
13390 +                       return 1;
13391 +       return 0;
13392 +}
13393 +
13394 +
13395 +/*
13396 + *     Check if a given address matches for a socket
13397 + *
13398 + *     nxi:            the socket's nx_info if any
13399 + *     addr:           to be verified address
13400 + */
13401 +static inline
13402 +int v6_sock_addr_match (
13403 +       struct nx_info *nxi,
13404 +       struct inet_sock *inet,
13405 +       struct in6_addr *addr)
13406 +{
13407 +       struct sock *sk = &inet->sk;
13408 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13409 +
13410 +       if (!ipv6_addr_any(addr) &&
13411 +               ipv6_addr_equal(saddr, addr))
13412 +               return 1;
13413 +       if (ipv6_addr_any(saddr))
13414 +               return v6_addr_in_nx_info(nxi, addr, -1);
13415 +       return 0;
13416 +}
13417 +
13418 +/*
13419 + *     check if address is covered by socket
13420 + *
13421 + *     sk:     the socket to check against
13422 + *     addr:   the address in question (must be != 0)
13423 + */
13424 +
13425 +static inline
13426 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13427 +{
13428 +       struct nx_info *nxi = sk->sk_nx_info;
13429 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13430 +
13431 +       vxdprintk(VXD_CBIT(net, 5),
13432 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13433 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13434 +               (sk->sk_socket?sk->sk_socket->flags:0));
13435 +
13436 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13437 +               return v6_addr_match(nxa, saddr, -1);
13438 +       } else if (nxi) {               /* match against nx_info */
13439 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13440 +       } else {                        /* unrestricted any socket */
13441 +               return 1;
13442 +       }
13443 +}
13444 +
13445 +
13446 +/* inet related checks and helpers */
13447 +
13448 +
13449 +struct in_ifaddr;
13450 +struct net_device;
13451 +struct sock;
13452 +
13453 +
13454 +#include <linux/netdevice.h>
13455 +#include <linux/inetdevice.h>
13456 +#include <net/inet_timewait_sock.h>
13457 +
13458 +
13459 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13460 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13461 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13462 +
13463 +
13464 +
13465 +static inline
13466 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13467 +{
13468 +       if (!nxi)
13469 +               return 1;
13470 +       if (!ifa)
13471 +               return 0;
13472 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13473 +}
13474 +
13475 +static inline
13476 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13477 +{
13478 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13479 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13480 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13481 +
13482 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13483 +               return 1;
13484 +       if (v6_ifa_in_nx_info(ifa, nxi))
13485 +               return 1;
13486 +       return 0;
13487 +}
13488 +
13489 +
13490 +struct nx_v6_sock_addr {
13491 +       struct in6_addr saddr;  /* Address used for validation */
13492 +       struct in6_addr baddr;  /* Address used for socket bind */
13493 +};
13494 +
13495 +static inline
13496 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13497 +       struct nx_v6_sock_addr *nsa)
13498 +{
13499 +       // struct sock *sk = &inet->sk;
13500 +       // struct nx_info *nxi = sk->sk_nx_info;
13501 +       struct in6_addr saddr = addr->sin6_addr;
13502 +       struct in6_addr baddr = saddr;
13503 +
13504 +       nsa->saddr = saddr;
13505 +       nsa->baddr = baddr;
13506 +       return 0;
13507 +}
13508 +
13509 +static inline
13510 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13511 +{
13512 +       // struct sock *sk = &inet->sk;
13513 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13514 +
13515 +       // *saddr = nsa->baddr;
13516 +       // inet->inet_saddr = nsa->baddr;
13517 +}
13518 +
13519 +static inline
13520 +int nx_info_has_v6(struct nx_info *nxi)
13521 +{
13522 +       if (!nxi)
13523 +               return 1;
13524 +       if (NX_IPV6(nxi))
13525 +               return 1;
13526 +       return 0;
13527 +}
13528 +
13529 +#else /* CONFIG_IPV6 */
13530 +
13531 +static inline
13532 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13533 +{
13534 +       return 1;
13535 +}
13536 +
13537 +
13538 +static inline
13539 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13540 +{
13541 +       return 1;
13542 +}
13543 +
13544 +static inline
13545 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13546 +{
13547 +       return 1;
13548 +}
13549 +
13550 +static inline
13551 +int nx_info_has_v6(struct nx_info *nxi)
13552 +{
13553 +       return 0;
13554 +}
13555 +
13556 +#endif /* CONFIG_IPV6 */
13557 +
13558 +#define current_nx_info_has_v6() \
13559 +       nx_info_has_v6(current_nx_info())
13560 +
13561 +#else
13562 +#warning duplicate inclusion
13563 +#endif
13564 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_inet.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_inet.h
13565 --- linux-2.6.35.4/include/linux/vs_inet.h      1970-01-01 01:00:00.000000000 +0100
13566 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_inet.h        2010-08-02 17:05:06.000000000 +0200
13567 @@ -0,0 +1,342 @@
13568 +#ifndef _VS_INET_H
13569 +#define _VS_INET_H
13570 +
13571 +#include "vserver/base.h"
13572 +#include "vserver/network.h"
13573 +#include "vserver/debug.h"
13574 +
13575 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13576 +
13577 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13578 +                       NIPQUAD((a)->mask), (a)->type
13579 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13580 +
13581 +
13582 +static inline
13583 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13584 +{
13585 +       __be32 ip = nxa->ip[0].s_addr;
13586 +       __be32 mask = nxa->mask.s_addr;
13587 +       __be32 bcast = ip | ~mask;
13588 +       int ret = 0;
13589 +
13590 +       switch (nxa->type & tmask) {
13591 +       case NXA_TYPE_MASK:
13592 +               ret = (ip == (addr & mask));
13593 +               break;
13594 +       case NXA_TYPE_ADDR:
13595 +               ret = 3;
13596 +               if (addr == ip)
13597 +                       break;
13598 +               /* fall through to broadcast */
13599 +       case NXA_MOD_BCAST:
13600 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13601 +               break;
13602 +       case NXA_TYPE_RANGE:
13603 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13604 +                       (nxa->ip[1].s_addr > addr));
13605 +               break;
13606 +       case NXA_TYPE_ANY:
13607 +               ret = 2;
13608 +               break;
13609 +       }
13610 +
13611 +       vxdprintk(VXD_CBIT(net, 0),
13612 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13613 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13614 +       return ret;
13615 +}
13616 +
13617 +static inline
13618 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13619 +{
13620 +       struct nx_addr_v4 *nxa;
13621 +       int ret = 1;
13622 +
13623 +       if (!nxi)
13624 +               goto out;
13625 +
13626 +       ret = 2;
13627 +       /* allow 127.0.0.1 when remapping lback */
13628 +       if ((tmask & NXA_LOOPBACK) &&
13629 +               (addr == IPI_LOOPBACK) &&
13630 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13631 +               goto out;
13632 +       ret = 3;
13633 +       /* check for lback address */
13634 +       if ((tmask & NXA_MOD_LBACK) &&
13635 +               (nxi->v4_lback.s_addr == addr))
13636 +               goto out;
13637 +       ret = 4;
13638 +       /* check for broadcast address */
13639 +       if ((tmask & NXA_MOD_BCAST) &&
13640 +               (nxi->v4_bcast.s_addr == addr))
13641 +               goto out;
13642 +       ret = 5;
13643 +       /* check for v4 addresses */
13644 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13645 +               if (v4_addr_match(nxa, addr, tmask))
13646 +                       goto out;
13647 +       ret = 0;
13648 +out:
13649 +       vxdprintk(VXD_CBIT(net, 0),
13650 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13651 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13652 +       return ret;
13653 +}
13654 +
13655 +static inline
13656 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13657 +{
13658 +       /* FIXME: needs full range checks */
13659 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13660 +}
13661 +
13662 +static inline
13663 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13664 +{
13665 +       struct nx_addr_v4 *ptr;
13666 +
13667 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13668 +               if (v4_nx_addr_match(ptr, nxa, mask))
13669 +                       return 1;
13670 +       return 0;
13671 +}
13672 +
13673 +#include <net/inet_sock.h>
13674 +
13675 +/*
13676 + *     Check if a given address matches for a socket
13677 + *
13678 + *     nxi:            the socket's nx_info if any
13679 + *     addr:           to be verified address
13680 + */
13681 +static inline
13682 +int v4_sock_addr_match (
13683 +       struct nx_info *nxi,
13684 +       struct inet_sock *inet,
13685 +       __be32 addr)
13686 +{
13687 +       __be32 saddr = inet->inet_rcv_saddr;
13688 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13689 +
13690 +       if (addr && (saddr == addr || bcast == addr))
13691 +               return 1;
13692 +       if (!saddr)
13693 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13694 +       return 0;
13695 +}
13696 +
13697 +
13698 +/* inet related checks and helpers */
13699 +
13700 +
13701 +struct in_ifaddr;
13702 +struct net_device;
13703 +struct sock;
13704 +
13705 +#ifdef CONFIG_INET
13706 +
13707 +#include <linux/netdevice.h>
13708 +#include <linux/inetdevice.h>
13709 +#include <net/inet_sock.h>
13710 +#include <net/inet_timewait_sock.h>
13711 +
13712 +
13713 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13714 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13715 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13716 +
13717 +
13718 +/*
13719 + *     check if address is covered by socket
13720 + *
13721 + *     sk:     the socket to check against
13722 + *     addr:   the address in question (must be != 0)
13723 + */
13724 +
13725 +static inline
13726 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13727 +{
13728 +       struct nx_info *nxi = sk->sk_nx_info;
13729 +       __be32 saddr = inet_rcv_saddr(sk);
13730 +
13731 +       vxdprintk(VXD_CBIT(net, 5),
13732 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13733 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13734 +               (sk->sk_socket?sk->sk_socket->flags:0));
13735 +
13736 +       if (saddr) {            /* direct address match */
13737 +               return v4_addr_match(nxa, saddr, -1);
13738 +       } else if (nxi) {       /* match against nx_info */
13739 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13740 +       } else {                /* unrestricted any socket */
13741 +               return 1;
13742 +       }
13743 +}
13744 +
13745 +
13746 +
13747 +static inline
13748 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13749 +{
13750 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13751 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13752 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13753 +
13754 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13755 +               return 1;
13756 +       if (dev_in_nx_info(dev, nxi))
13757 +               return 1;
13758 +       return 0;
13759 +}
13760 +
13761 +
13762 +static inline
13763 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13764 +{
13765 +       if (!nxi)
13766 +               return 1;
13767 +       if (!ifa)
13768 +               return 0;
13769 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13770 +}
13771 +
13772 +static inline
13773 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13774 +{
13775 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13776 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13777 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13778 +
13779 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13780 +               return 1;
13781 +       if (v4_ifa_in_nx_info(ifa, nxi))
13782 +               return 1;
13783 +       return 0;
13784 +}
13785 +
13786 +
13787 +struct nx_v4_sock_addr {
13788 +       __be32 saddr;   /* Address used for validation */
13789 +       __be32 baddr;   /* Address used for socket bind */
13790 +};
13791 +
13792 +static inline
13793 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13794 +       struct nx_v4_sock_addr *nsa)
13795 +{
13796 +       struct sock *sk = &inet->sk;
13797 +       struct nx_info *nxi = sk->sk_nx_info;
13798 +       __be32 saddr = addr->sin_addr.s_addr;
13799 +       __be32 baddr = saddr;
13800 +
13801 +       vxdprintk(VXD_CBIT(net, 3),
13802 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13803 +               sk, sk->sk_nx_info, sk->sk_socket,
13804 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13805 +               NIPQUAD(saddr));
13806 +
13807 +       if (nxi) {
13808 +               if (saddr == INADDR_ANY) {
13809 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13810 +                               baddr = nxi->v4.ip[0].s_addr;
13811 +               } else if (saddr == IPI_LOOPBACK) {
13812 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13813 +                               baddr = nxi->v4_lback.s_addr;
13814 +               } else {        /* normal address bind */
13815 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13816 +                               return -EADDRNOTAVAIL;
13817 +               }
13818 +       }
13819 +
13820 +       vxdprintk(VXD_CBIT(net, 3),
13821 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13822 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13823 +
13824 +       nsa->saddr = saddr;
13825 +       nsa->baddr = baddr;
13826 +       return 0;
13827 +}
13828 +
13829 +static inline
13830 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13831 +{
13832 +       inet->inet_saddr = nsa->baddr;
13833 +       inet->inet_rcv_saddr = nsa->baddr;
13834 +}
13835 +
13836 +
13837 +/*
13838 + *      helper to simplify inet_lookup_listener
13839 + *
13840 + *      nxi:   the socket's nx_info if any
13841 + *      addr:  to be verified address
13842 + *      saddr: socket address
13843 + */
13844 +static inline int v4_inet_addr_match (
13845 +       struct nx_info *nxi,
13846 +       __be32 addr,
13847 +       __be32 saddr)
13848 +{
13849 +       if (addr && (saddr == addr))
13850 +               return 1;
13851 +       if (!saddr)
13852 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13853 +       return 0;
13854 +}
13855 +
13856 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13857 +{
13858 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13859 +               (addr == nxi->v4_lback.s_addr))
13860 +               return IPI_LOOPBACK;
13861 +       return addr;
13862 +}
13863 +
13864 +static inline
13865 +int nx_info_has_v4(struct nx_info *nxi)
13866 +{
13867 +       if (!nxi)
13868 +               return 1;
13869 +       if (NX_IPV4(nxi))
13870 +               return 1;
13871 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13872 +               return 1;
13873 +       return 0;
13874 +}
13875 +
13876 +#else /* CONFIG_INET */
13877 +
13878 +static inline
13879 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13880 +{
13881 +       return 1;
13882 +}
13883 +
13884 +static inline
13885 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13886 +{
13887 +       return 1;
13888 +}
13889 +
13890 +static inline
13891 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13892 +{
13893 +       return 1;
13894 +}
13895 +
13896 +static inline
13897 +int nx_info_has_v4(struct nx_info *nxi)
13898 +{
13899 +       return 0;
13900 +}
13901 +
13902 +#endif /* CONFIG_INET */
13903 +
13904 +#define current_nx_info_has_v4() \
13905 +       nx_info_has_v4(current_nx_info())
13906 +
13907 +#else
13908 +// #warning duplicate inclusion
13909 +#endif
13910 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_limit.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_limit.h
13911 --- linux-2.6.35.4/include/linux/vs_limit.h     1970-01-01 01:00:00.000000000 +0100
13912 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_limit.h       2010-08-02 17:05:06.000000000 +0200
13913 @@ -0,0 +1,140 @@
13914 +#ifndef _VS_LIMIT_H
13915 +#define _VS_LIMIT_H
13916 +
13917 +#include "vserver/limit.h"
13918 +#include "vserver/base.h"
13919 +#include "vserver/context.h"
13920 +#include "vserver/debug.h"
13921 +#include "vserver/context.h"
13922 +#include "vserver/limit_int.h"
13923 +
13924 +
13925 +#define vx_acc_cres(v, d, p, r) \
13926 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13927 +
13928 +#define vx_acc_cres_cond(x, d, p, r) \
13929 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13930 +       r, d, p, __FILE__, __LINE__)
13931 +
13932 +
13933 +#define vx_add_cres(v, a, p, r) \
13934 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13935 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13936 +
13937 +#define vx_add_cres_cond(x, a, p, r) \
13938 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13939 +       r, a, p, __FILE__, __LINE__)
13940 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13941 +
13942 +
13943 +/* process and file limits */
13944 +
13945 +#define vx_nproc_inc(p) \
13946 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13947 +
13948 +#define vx_nproc_dec(p) \
13949 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13950 +
13951 +#define vx_files_inc(f) \
13952 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13953 +
13954 +#define vx_files_dec(f) \
13955 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13956 +
13957 +#define vx_locks_inc(l) \
13958 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13959 +
13960 +#define vx_locks_dec(l) \
13961 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13962 +
13963 +#define vx_openfd_inc(f) \
13964 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13965 +
13966 +#define vx_openfd_dec(f) \
13967 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
13968 +
13969 +
13970 +#define vx_cres_avail(v, n, r) \
13971 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13972 +
13973 +
13974 +#define vx_nproc_avail(n) \
13975 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
13976 +
13977 +#define vx_files_avail(n) \
13978 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
13979 +
13980 +#define vx_locks_avail(n) \
13981 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
13982 +
13983 +#define vx_openfd_avail(n) \
13984 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
13985 +
13986 +
13987 +/* dentry limits */
13988 +
13989 +#define vx_dentry_inc(d) do {                                          \
13990 +       if (atomic_read(&d->d_count) == 1)                              \
13991 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
13992 +       } while (0)
13993 +
13994 +#define vx_dentry_dec(d) do {                                          \
13995 +       if (atomic_read(&d->d_count) == 0)                              \
13996 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
13997 +       } while (0)
13998 +
13999 +#define vx_dentry_avail(n) \
14000 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
14001 +
14002 +
14003 +/* socket limits */
14004 +
14005 +#define vx_sock_inc(s) \
14006 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
14007 +
14008 +#define vx_sock_dec(s) \
14009 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
14010 +
14011 +#define vx_sock_avail(n) \
14012 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
14013 +
14014 +
14015 +/* ipc resource limits */
14016 +
14017 +#define vx_ipcmsg_add(v, u, a) \
14018 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
14019 +
14020 +#define vx_ipcmsg_sub(v, u, a) \
14021 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
14022 +
14023 +#define vx_ipcmsg_avail(v, a) \
14024 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
14025 +
14026 +
14027 +#define vx_ipcshm_add(v, k, a) \
14028 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14029 +
14030 +#define vx_ipcshm_sub(v, k, a) \
14031 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14032 +
14033 +#define vx_ipcshm_avail(v, a) \
14034 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14035 +
14036 +
14037 +#define vx_semary_inc(a) \
14038 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
14039 +
14040 +#define vx_semary_dec(a) \
14041 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
14042 +
14043 +
14044 +#define vx_nsems_add(a,n) \
14045 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14046 +
14047 +#define vx_nsems_sub(a,n) \
14048 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14049 +
14050 +
14051 +#else
14052 +#warning duplicate inclusion
14053 +#endif
14054 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_memory.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_memory.h
14055 --- linux-2.6.35.4/include/linux/vs_memory.h    1970-01-01 01:00:00.000000000 +0100
14056 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_memory.h      2010-08-02 17:05:06.000000000 +0200
14057 @@ -0,0 +1,58 @@
14058 +#ifndef _VS_MEMORY_H
14059 +#define _VS_MEMORY_H
14060 +
14061 +#include "vserver/limit.h"
14062 +#include "vserver/base.h"
14063 +#include "vserver/context.h"
14064 +#include "vserver/debug.h"
14065 +#include "vserver/context.h"
14066 +#include "vserver/limit_int.h"
14067 +
14068 +enum {
14069 +       VXPT_UNKNOWN = 0,
14070 +       VXPT_ANON,
14071 +       VXPT_NONE,
14072 +       VXPT_FILE,
14073 +       VXPT_SWAP,
14074 +       VXPT_WRITE
14075 +};
14076 +
14077 +#if 0
14078 +#define        vx_page_fault(mm, vma, type, ret)
14079 +#else
14080 +
14081 +static inline
14082 +void __vx_page_fault(struct mm_struct *mm,
14083 +       struct vm_area_struct *vma, int type, int ret)
14084 +{
14085 +       struct vx_info *vxi = mm->mm_vx_info;
14086 +       int what;
14087 +/*
14088 +       static char *page_type[6] =
14089 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14090 +       static char *page_what[4] =
14091 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14092 +*/
14093 +
14094 +       if (!vxi)
14095 +               return;
14096 +
14097 +       what = (ret & 0x3);
14098 +
14099 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14100 +               type, what, ret, page_type[type], page_what[what]);
14101 +*/
14102 +       if (ret & VM_FAULT_WRITE)
14103 +               what |= 0x4;
14104 +       atomic_inc(&vxi->cacct.page[type][what]);
14105 +}
14106 +
14107 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14108 +#endif
14109 +
14110 +
14111 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14112 +
14113 +#else
14114 +#warning duplicate inclusion
14115 +#endif
14116 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_network.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_network.h
14117 --- linux-2.6.35.4/include/linux/vs_network.h   1970-01-01 01:00:00.000000000 +0100
14118 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_network.h     2010-08-02 17:05:06.000000000 +0200
14119 @@ -0,0 +1,169 @@
14120 +#ifndef _NX_VS_NETWORK_H
14121 +#define _NX_VS_NETWORK_H
14122 +
14123 +#include "vserver/context.h"
14124 +#include "vserver/network.h"
14125 +#include "vserver/base.h"
14126 +#include "vserver/check.h"
14127 +#include "vserver/debug.h"
14128 +
14129 +#include <linux/sched.h>
14130 +
14131 +
14132 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14133 +
14134 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14135 +       const char *_file, int _line)
14136 +{
14137 +       if (!nxi)
14138 +               return NULL;
14139 +
14140 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14141 +               nxi, nxi ? nxi->nx_id : 0,
14142 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14143 +               _file, _line);
14144 +
14145 +       atomic_inc(&nxi->nx_usecnt);
14146 +       return nxi;
14147 +}
14148 +
14149 +
14150 +extern void free_nx_info(struct nx_info *);
14151 +
14152 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14153 +
14154 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14155 +{
14156 +       if (!nxi)
14157 +               return;
14158 +
14159 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14160 +               nxi, nxi ? nxi->nx_id : 0,
14161 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14162 +               _file, _line);
14163 +
14164 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14165 +               free_nx_info(nxi);
14166 +}
14167 +
14168 +
14169 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14170 +
14171 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14172 +               const char *_file, int _line)
14173 +{
14174 +       if (nxi) {
14175 +               vxlprintk(VXD_CBIT(nid, 3),
14176 +                       "init_nx_info(%p[#%d.%d])",
14177 +                       nxi, nxi ? nxi->nx_id : 0,
14178 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14179 +                       _file, _line);
14180 +
14181 +               atomic_inc(&nxi->nx_usecnt);
14182 +       }
14183 +       *nxp = nxi;
14184 +}
14185 +
14186 +
14187 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14188 +
14189 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14190 +       const char *_file, int _line)
14191 +{
14192 +       struct nx_info *nxo;
14193 +
14194 +       if (!nxi)
14195 +               return;
14196 +
14197 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14198 +               nxi, nxi ? nxi->nx_id : 0,
14199 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14200 +               _file, _line);
14201 +
14202 +       atomic_inc(&nxi->nx_usecnt);
14203 +       nxo = xchg(nxp, nxi);
14204 +       BUG_ON(nxo);
14205 +}
14206 +
14207 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14208 +
14209 +static inline void __clr_nx_info(struct nx_info **nxp,
14210 +       const char *_file, int _line)
14211 +{
14212 +       struct nx_info *nxo;
14213 +
14214 +       nxo = xchg(nxp, NULL);
14215 +       if (!nxo)
14216 +               return;
14217 +
14218 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14219 +               nxo, nxo ? nxo->nx_id : 0,
14220 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14221 +               _file, _line);
14222 +
14223 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14224 +               free_nx_info(nxo);
14225 +}
14226 +
14227 +
14228 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14229 +
14230 +static inline void __claim_nx_info(struct nx_info *nxi,
14231 +       struct task_struct *task, const char *_file, int _line)
14232 +{
14233 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14234 +               nxi, nxi ? nxi->nx_id : 0,
14235 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14236 +               nxi?atomic_read(&nxi->nx_tasks):0,
14237 +               task, _file, _line);
14238 +
14239 +       atomic_inc(&nxi->nx_tasks);
14240 +}
14241 +
14242 +
14243 +extern void unhash_nx_info(struct nx_info *);
14244 +
14245 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14246 +
14247 +static inline void __release_nx_info(struct nx_info *nxi,
14248 +       struct task_struct *task, const char *_file, int _line)
14249 +{
14250 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14251 +               nxi, nxi ? nxi->nx_id : 0,
14252 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14253 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14254 +               task, _file, _line);
14255 +
14256 +       might_sleep();
14257 +
14258 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14259 +               unhash_nx_info(nxi);
14260 +}
14261 +
14262 +
14263 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14264 +
14265 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14266 +       const char *_file, int _line)
14267 +{
14268 +       struct nx_info *nxi;
14269 +
14270 +       task_lock(p);
14271 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14272 +               p, _file, _line);
14273 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14274 +       task_unlock(p);
14275 +       return nxi;
14276 +}
14277 +
14278 +
14279 +static inline void exit_nx_info(struct task_struct *p)
14280 +{
14281 +       if (p->nx_info)
14282 +               release_nx_info(p->nx_info, p);
14283 +}
14284 +
14285 +
14286 +#else
14287 +#warning duplicate inclusion
14288 +#endif
14289 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_pid.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_pid.h
14290 --- linux-2.6.35.4/include/linux/vs_pid.h       1970-01-01 01:00:00.000000000 +0100
14291 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_pid.h 2010-08-02 17:05:06.000000000 +0200
14292 @@ -0,0 +1,95 @@
14293 +#ifndef _VS_PID_H
14294 +#define _VS_PID_H
14295 +
14296 +#include "vserver/base.h"
14297 +#include "vserver/check.h"
14298 +#include "vserver/context.h"
14299 +#include "vserver/debug.h"
14300 +#include "vserver/pid.h"
14301 +#include <linux/pid_namespace.h>
14302 +
14303 +
14304 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14305 +
14306 +static inline
14307 +int vx_proc_task_visible(struct task_struct *task)
14308 +{
14309 +       if ((task->pid == 1) &&
14310 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14311 +               /* show a blend through init */
14312 +               goto visible;
14313 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14314 +               goto visible;
14315 +       return 0;
14316 +visible:
14317 +       return 1;
14318 +}
14319 +
14320 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14321 +
14322 +#if 0
14323 +
14324 +static inline
14325 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14326 +{
14327 +       struct task_struct *task = find_task_by_real_pid(pid);
14328 +
14329 +       if (task && !vx_proc_task_visible(task)) {
14330 +               vxdprintk(VXD_CBIT(misc, 6),
14331 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14332 +                       task, task->xid, task->pid,
14333 +                       current, current->xid, current->pid);
14334 +               task = NULL;
14335 +       }
14336 +       return task;
14337 +}
14338 +
14339 +#endif
14340 +
14341 +static inline
14342 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14343 +{
14344 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14345 +
14346 +       if (task && !vx_proc_task_visible(task)) {
14347 +               vxdprintk(VXD_CBIT(misc, 6),
14348 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14349 +                       task, task->xid, task->pid,
14350 +                       current, current->xid, current->pid);
14351 +               put_task_struct(task);
14352 +               task = NULL;
14353 +       }
14354 +       return task;
14355 +}
14356 +
14357 +#if 0
14358 +
14359 +static inline
14360 +struct task_struct *vx_child_reaper(struct task_struct *p)
14361 +{
14362 +       struct vx_info *vxi = p->vx_info;
14363 +       struct task_struct *reaper = child_reaper(p);
14364 +
14365 +       if (!vxi)
14366 +               goto out;
14367 +
14368 +       BUG_ON(!p->vx_info->vx_reaper);
14369 +
14370 +       /* child reaper for the guest reaper */
14371 +       if (vxi->vx_reaper == p)
14372 +               goto out;
14373 +
14374 +       reaper = vxi->vx_reaper;
14375 +out:
14376 +       vxdprintk(VXD_CBIT(xid, 7),
14377 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14378 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14379 +       return reaper;
14380 +}
14381 +
14382 +#endif
14383 +
14384 +
14385 +#else
14386 +#warning duplicate inclusion
14387 +#endif
14388 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_sched.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_sched.h
14389 --- linux-2.6.35.4/include/linux/vs_sched.h     1970-01-01 01:00:00.000000000 +0100
14390 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_sched.h       2010-08-02 17:05:06.000000000 +0200
14391 @@ -0,0 +1,110 @@
14392 +#ifndef _VS_SCHED_H
14393 +#define _VS_SCHED_H
14394 +
14395 +#include "vserver/base.h"
14396 +#include "vserver/context.h"
14397 +#include "vserver/sched.h"
14398 +
14399 +
14400 +#define VAVAVOOM_RATIO          50
14401 +
14402 +#define MAX_PRIO_BIAS           20
14403 +#define MIN_PRIO_BIAS          -20
14404 +
14405 +
14406 +#ifdef CONFIG_VSERVER_HARDCPU
14407 +
14408 +/*
14409 + * effective_prio - return the priority that is based on the static
14410 + * priority but is modified by bonuses/penalties.
14411 + *
14412 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14413 + * into a -4 ... 0 ... +4 bonus/penalty range.
14414 + *
14415 + * Additionally, we scale another amount based on the number of
14416 + * CPU tokens currently held by the context, if the process is
14417 + * part of a context (and the appropriate SCHED flag is set).
14418 + * This ranges from -5 ... 0 ... +15, quadratically.
14419 + *
14420 + * So, the total bonus is -9 .. 0 .. +19
14421 + * We use ~50% of the full 0...39 priority range so that:
14422 + *
14423 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14424 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14425 + *    unless that context is far exceeding its CPU allocation.
14426 + *
14427 + * Both properties are important to certain workloads.
14428 + */
14429 +static inline
14430 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14431 +{
14432 +       int vavavoom, max;
14433 +
14434 +       /* lots of tokens = lots of vavavoom
14435 +        *      no tokens = no vavavoom      */
14436 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14437 +               max = sched_pc->tokens_max;
14438 +               vavavoom = max - vavavoom;
14439 +               max = max * max;
14440 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14441 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14442 +               return vavavoom;
14443 +       }
14444 +       return 0;
14445 +}
14446 +
14447 +
14448 +static inline
14449 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14450 +{
14451 +       struct vx_info *vxi = p->vx_info;
14452 +       struct _vx_sched_pc *sched_pc;
14453 +
14454 +       if (!vxi)
14455 +               return prio;
14456 +
14457 +       sched_pc = &vx_cpu(vxi, sched_pc);
14458 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14459 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14460 +
14461 +               sched_pc->vavavoom = vavavoom;
14462 +               prio += vavavoom;
14463 +       }
14464 +       prio += sched_pc->prio_bias;
14465 +       return prio;
14466 +}
14467 +
14468 +#else /* !CONFIG_VSERVER_HARDCPU */
14469 +
14470 +static inline
14471 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14472 +{
14473 +       struct vx_info *vxi = p->vx_info;
14474 +
14475 +       if (vxi)
14476 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14477 +       return prio;
14478 +}
14479 +
14480 +#endif /* CONFIG_VSERVER_HARDCPU */
14481 +
14482 +
14483 +static inline void vx_account_user(struct vx_info *vxi,
14484 +       cputime_t cputime, int nice)
14485 +{
14486 +       if (!vxi)
14487 +               return;
14488 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14489 +}
14490 +
14491 +static inline void vx_account_system(struct vx_info *vxi,
14492 +       cputime_t cputime, int idle)
14493 +{
14494 +       if (!vxi)
14495 +               return;
14496 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14497 +}
14498 +
14499 +#else
14500 +#warning duplicate inclusion
14501 +#endif
14502 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_socket.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_socket.h
14503 --- linux-2.6.35.4/include/linux/vs_socket.h    1970-01-01 01:00:00.000000000 +0100
14504 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_socket.h      2010-08-02 17:05:06.000000000 +0200
14505 @@ -0,0 +1,67 @@
14506 +#ifndef _VS_SOCKET_H
14507 +#define _VS_SOCKET_H
14508 +
14509 +#include "vserver/debug.h"
14510 +#include "vserver/base.h"
14511 +#include "vserver/cacct.h"
14512 +#include "vserver/context.h"
14513 +#include "vserver/tag.h"
14514 +
14515 +
14516 +/* socket accounting */
14517 +
14518 +#include <linux/socket.h>
14519 +
14520 +static inline int vx_sock_type(int family)
14521 +{
14522 +       switch (family) {
14523 +       case PF_UNSPEC:
14524 +               return VXA_SOCK_UNSPEC;
14525 +       case PF_UNIX:
14526 +               return VXA_SOCK_UNIX;
14527 +       case PF_INET:
14528 +               return VXA_SOCK_INET;
14529 +       case PF_INET6:
14530 +               return VXA_SOCK_INET6;
14531 +       case PF_PACKET:
14532 +               return VXA_SOCK_PACKET;
14533 +       default:
14534 +               return VXA_SOCK_OTHER;
14535 +       }
14536 +}
14537 +
14538 +#define vx_acc_sock(v, f, p, s) \
14539 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14540 +
14541 +static inline void __vx_acc_sock(struct vx_info *vxi,
14542 +       int family, int pos, int size, char *file, int line)
14543 +{
14544 +       if (vxi) {
14545 +               int type = vx_sock_type(family);
14546 +
14547 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14548 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14549 +       }
14550 +}
14551 +
14552 +#define vx_sock_recv(sk, s) \
14553 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14554 +#define vx_sock_send(sk, s) \
14555 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14556 +#define vx_sock_fail(sk, s) \
14557 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14558 +
14559 +
14560 +#define sock_vx_init(s) do {           \
14561 +       (s)->sk_xid = 0;                \
14562 +       (s)->sk_vx_info = NULL;         \
14563 +       } while (0)
14564 +
14565 +#define sock_nx_init(s) do {           \
14566 +       (s)->sk_nid = 0;                \
14567 +       (s)->sk_nx_info = NULL;         \
14568 +       } while (0)
14569 +
14570 +#else
14571 +#warning duplicate inclusion
14572 +#endif
14573 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_tag.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_tag.h
14574 --- linux-2.6.35.4/include/linux/vs_tag.h       1970-01-01 01:00:00.000000000 +0100
14575 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_tag.h 2010-08-02 17:05:06.000000000 +0200
14576 @@ -0,0 +1,47 @@
14577 +#ifndef _VS_TAG_H
14578 +#define _VS_TAG_H
14579 +
14580 +#include <linux/vserver/tag.h>
14581 +
14582 +/* check conditions */
14583 +
14584 +#define DX_ADMIN       0x0001
14585 +#define DX_WATCH       0x0002
14586 +#define DX_HOSTID      0x0008
14587 +
14588 +#define DX_IDENT       0x0010
14589 +
14590 +#define DX_ARG_MASK    0x0010
14591 +
14592 +
14593 +#define dx_task_tag(t) ((t)->tag)
14594 +
14595 +#define dx_current_tag() dx_task_tag(current)
14596 +
14597 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14598 +
14599 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14600 +
14601 +
14602 +/*
14603 + * check current context for ADMIN/WATCH and
14604 + * optionally against supplied argument
14605 + */
14606 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14607 +{
14608 +       if (mode & DX_ARG_MASK) {
14609 +               if ((mode & DX_IDENT) && (id == cid))
14610 +                       return 1;
14611 +       }
14612 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14613 +               ((mode & DX_WATCH) && (cid == 1)) ||
14614 +               ((mode & DX_HOSTID) && (id == 0)));
14615 +}
14616 +
14617 +struct inode;
14618 +int dx_permission(const struct inode *inode, int mask);
14619 +
14620 +
14621 +#else
14622 +#warning duplicate inclusion
14623 +#endif
14624 diff -NurpP --minimal linux-2.6.35.4/include/linux/vs_time.h linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_time.h
14625 --- linux-2.6.35.4/include/linux/vs_time.h      1970-01-01 01:00:00.000000000 +0100
14626 +++ linux-2.6.35.4-vs2.3.0.36.32/include/linux/vs_time.h        2010-08-02 17:05:06.000000000 +0200
14627 @@ -0,0 +1,19 @@
14628 +#ifndef _VS_TIME_H
14629 +#define _VS_TIME_H
14630 +
14631 +
14632 +/* time faking stuff */
14633 +
14634 +#ifdef CONFIG_VSERVER_VTIME
14635 +
14636 +extern void vx_gettimeofday(struct timeval *tv);
14637 +extern int vx_settimeofday(struct timespec *ts);
14638 +
14639 +#else
14640 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14641 +#define        vx_settimeofday(t)      do_settimeofday(t)
14642 +#endif
14643 +
14644 +#else
14645 +#warning duplicate inclusion
14646 +#endif
14647 diff -NurpP --minimal linux-2.6.35.4/include/net/addrconf.h linux-2.6.35.4-vs2.3.0.36.32/include/net/addrconf.h
14648 --- linux-2.6.35.4/include/net/addrconf.h       2010-07-07 18:31:56.000000000 +0200
14649 +++ linux-2.6.35.4-vs2.3.0.36.32/include/net/addrconf.h 2010-08-02 17:05:06.000000000 +0200
14650 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14651                                                struct net_device *dev,
14652                                                const struct in6_addr *daddr,
14653                                                unsigned int srcprefs,
14654 -                                              struct in6_addr *saddr);
14655 +                                              struct in6_addr *saddr,
14656 +                                              struct nx_info *nxi);
14657  extern int                     ipv6_get_lladdr(struct net_device *dev,
14658                                                 struct in6_addr *addr,
14659                                                 unsigned char banned_flags);
14660 diff -NurpP --minimal linux-2.6.35.4/include/net/af_unix.h linux-2.6.35.4-vs2.3.0.36.32/include/net/af_unix.h
14661 --- linux-2.6.35.4/include/net/af_unix.h        2010-08-02 16:52:56.000000000 +0200
14662 +++ linux-2.6.35.4-vs2.3.0.36.32/include/net/af_unix.h  2010-08-02 17:05:06.000000000 +0200
14663 @@ -4,6 +4,7 @@
14664  #include <linux/socket.h>
14665  #include <linux/un.h>
14666  #include <linux/mutex.h>
14667 +#include <linux/vs_base.h>
14668  #include <net/sock.h>
14669  
14670  extern void unix_inflight(struct file *fp);
14671 diff -NurpP --minimal linux-2.6.35.4/include/net/inet_timewait_sock.h linux-2.6.35.4-vs2.3.0.36.32/include/net/inet_timewait_sock.h
14672 --- linux-2.6.35.4/include/net/inet_timewait_sock.h     2010-08-02 16:52:56.000000000 +0200
14673 +++ linux-2.6.35.4-vs2.3.0.36.32/include/net/inet_timewait_sock.h       2010-08-02 17:05:06.000000000 +0200
14674 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14675  #define tw_hash                        __tw_common.skc_hash
14676  #define tw_prot                        __tw_common.skc_prot
14677  #define tw_net                 __tw_common.skc_net
14678 +#define tw_xid                 __tw_common.skc_xid
14679 +#define tw_vx_info             __tw_common.skc_vx_info
14680 +#define tw_nid                 __tw_common.skc_nid
14681 +#define tw_nx_info             __tw_common.skc_nx_info
14682         int                     tw_timeout;
14683         volatile unsigned char  tw_substate;
14684         /* 3 bits hole, try to pack */
14685 diff -NurpP --minimal linux-2.6.35.4/include/net/route.h linux-2.6.35.4-vs2.3.0.36.32/include/net/route.h
14686 --- linux-2.6.35.4/include/net/route.h  2010-08-02 16:52:57.000000000 +0200
14687 +++ linux-2.6.35.4-vs2.3.0.36.32/include/net/route.h    2010-08-02 17:05:06.000000000 +0200
14688 @@ -147,6 +147,9 @@ static inline void ip_rt_put(struct rtab
14689                 dst_release(&rt->u.dst);
14690  }
14691  
14692 +#include <linux/vs_base.h>
14693 +#include <linux/vs_inet.h>
14694 +
14695  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14696  
14697  extern const __u8 ip_tos2prio[16];
14698 @@ -156,6 +159,9 @@ static inline char rt_tos2priority(u8 to
14699         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14700  }
14701  
14702 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14703 +       struct rtable **, struct flowi *);
14704 +
14705  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14706                                    __be32 src, u32 tos, int oif, u8 protocol,
14707                                    __be16 sport, __be16 dport, struct sock *sk,
14708 @@ -173,11 +179,24 @@ static inline int ip_route_connect(struc
14709  
14710         int err;
14711         struct net *net = sock_net(sk);
14712 +       struct nx_info *nx_info = current_nx_info();
14713  
14714         if (inet_sk(sk)->transparent)
14715                 fl.flags |= FLOWI_FLAG_ANYSRC;
14716  
14717 -       if (!dst || !src) {
14718 +       if (sk)
14719 +               nx_info = sk->sk_nx_info;
14720 +
14721 +       vxdprintk(VXD_CBIT(net, 4),
14722 +               "ip_route_connect(%p) %p,%p;%lx",
14723 +               sk, nx_info, sk->sk_socket,
14724 +               (sk->sk_socket?sk->sk_socket->flags:0));
14725 +
14726 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14727 +       if (err)
14728 +               return err;
14729 +
14730 +       if (!fl.fl4_dst || !fl.fl4_src) {
14731                 err = __ip_route_output_key(net, rp, &fl);
14732                 if (err)
14733                         return err;
14734 diff -NurpP --minimal linux-2.6.35.4/include/net/sock.h linux-2.6.35.4-vs2.3.0.36.32/include/net/sock.h
14735 --- linux-2.6.35.4/include/net/sock.h   2010-08-02 16:52:57.000000000 +0200
14736 +++ linux-2.6.35.4-vs2.3.0.36.32/include/net/sock.h     2010-08-02 17:05:06.000000000 +0200
14737 @@ -150,6 +150,10 @@ struct sock_common {
14738  #ifdef CONFIG_NET_NS
14739         struct net              *skc_net;
14740  #endif
14741 +       xid_t                   skc_xid;
14742 +       struct vx_info          *skc_vx_info;
14743 +       nid_t                   skc_nid;
14744 +       struct nx_info          *skc_nx_info;
14745  };
14746  
14747  /**
14748 @@ -239,6 +243,10 @@ struct sock {
14749  #define sk_bind_node           __sk_common.skc_bind_node
14750  #define sk_prot                        __sk_common.skc_prot
14751  #define sk_net                 __sk_common.skc_net
14752 +#define sk_xid                 __sk_common.skc_xid
14753 +#define sk_vx_info             __sk_common.skc_vx_info
14754 +#define sk_nid                 __sk_common.skc_nid
14755 +#define sk_nx_info             __sk_common.skc_nx_info
14756         kmemcheck_bitfield_begin(flags);
14757         unsigned int            sk_shutdown  : 2,
14758                                 sk_no_check  : 2,
14759 diff -NurpP --minimal linux-2.6.35.4/init/Kconfig linux-2.6.35.4-vs2.3.0.36.32/init/Kconfig
14760 --- linux-2.6.35.4/init/Kconfig 2010-08-02 16:52:57.000000000 +0200
14761 +++ linux-2.6.35.4-vs2.3.0.36.32/init/Kconfig   2010-08-02 17:05:06.000000000 +0200
14762 @@ -472,6 +472,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14763  menuconfig CGROUPS
14764         boolean "Control Group support"
14765         depends on EVENTFD
14766 +       default y
14767         help
14768           This option adds support for grouping sets of processes together, for
14769           use with process control subsystems such as Cpusets, CFS, memory
14770 @@ -499,6 +500,7 @@ config CGROUP_DEBUG
14771  config CGROUP_NS
14772         bool "Namespace cgroup subsystem"
14773         depends on CGROUPS
14774 +       default n
14775         help
14776           Provides a simple namespace cgroup subsystem to
14777           provide hierarchical naming of sets of namespaces,
14778 diff -NurpP --minimal linux-2.6.35.4/init/main.c linux-2.6.35.4-vs2.3.0.36.32/init/main.c
14779 --- linux-2.6.35.4/init/main.c  2010-08-02 16:52:57.000000000 +0200
14780 +++ linux-2.6.35.4-vs2.3.0.36.32/init/main.c    2010-08-02 17:05:06.000000000 +0200
14781 @@ -71,6 +71,7 @@
14782  #include <linux/shmem_fs.h>
14783  #include <linux/slab.h>
14784  #include <trace/boot.h>
14785 +#include <linux/vserver/percpu.h>
14786  
14787  #include <asm/io.h>
14788  #include <asm/bugs.h>
14789 diff -NurpP --minimal linux-2.6.35.4/ipc/mqueue.c linux-2.6.35.4-vs2.3.0.36.32/ipc/mqueue.c
14790 --- linux-2.6.35.4/ipc/mqueue.c 2010-08-02 16:52:57.000000000 +0200
14791 +++ linux-2.6.35.4-vs2.3.0.36.32/ipc/mqueue.c   2010-08-02 17:05:06.000000000 +0200
14792 @@ -33,6 +33,8 @@
14793  #include <linux/pid.h>
14794  #include <linux/ipc_namespace.h>
14795  #include <linux/slab.h>
14796 +#include <linux/vs_context.h>
14797 +#include <linux/vs_limit.h>
14798  
14799  #include <net/sock.h>
14800  #include "util.h"
14801 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14802         struct sigevent notify;
14803         struct pid* notify_owner;
14804         struct user_struct *user;       /* user who created, for accounting */
14805 +       struct vx_info *vxi;
14806         struct sock *notify_sock;
14807         struct sk_buff *notify_cookie;
14808  
14809 @@ -125,6 +128,7 @@ static struct inode *mqueue_get_inode(st
14810                 if (S_ISREG(mode)) {
14811                         struct mqueue_inode_info *info;
14812                         struct task_struct *p = current;
14813 +                       struct vx_info *vxi = p->vx_info;
14814                         unsigned long mq_bytes, mq_msg_tblsz;
14815  
14816                         inode->i_fop = &mqueue_file_operations;
14817 @@ -138,6 +142,7 @@ static struct inode *mqueue_get_inode(st
14818                         info->notify_owner = NULL;
14819                         info->qsize = 0;
14820                         info->user = NULL;      /* set when all is ok */
14821 +                       info->vxi = NULL;
14822                         memset(&info->attr, 0, sizeof(info->attr));
14823                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14824                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14825 @@ -156,16 +161,19 @@ static struct inode *mqueue_get_inode(st
14826                         spin_lock(&mq_lock);
14827                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14828                             u->mq_bytes + mq_bytes >
14829 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
14830 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
14831 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14832                                 spin_unlock(&mq_lock);
14833                                 /* mqueue_delete_inode() releases info->messages */
14834                                 goto out_inode;
14835                         }
14836                         u->mq_bytes += mq_bytes;
14837 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14838                         spin_unlock(&mq_lock);
14839  
14840                         /* all is ok */
14841                         info->user = get_uid(u);
14842 +                       info->vxi = get_vx_info(vxi);
14843                 } else if (S_ISDIR(mode)) {
14844                         inc_nlink(inode);
14845                         /* Some things misbehave if size == 0 on a directory */
14846 @@ -268,8 +276,11 @@ static void mqueue_delete_inode(struct i
14847             + info->attr.mq_msgsize);
14848         user = info->user;
14849         if (user) {
14850 +               struct vx_info *vxi = info->vxi;
14851 +
14852                 spin_lock(&mq_lock);
14853                 user->mq_bytes -= mq_bytes;
14854 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14855                 /*
14856                  * get_ns_from_inode() ensures that the
14857                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14858 @@ -279,6 +290,7 @@ static void mqueue_delete_inode(struct i
14859                 if (ipc_ns)
14860                         ipc_ns->mq_queues_count--;
14861                 spin_unlock(&mq_lock);
14862 +               put_vx_info(vxi);
14863                 free_uid(user);
14864         }
14865         if (ipc_ns)
14866 diff -NurpP --minimal linux-2.6.35.4/ipc/msg.c linux-2.6.35.4-vs2.3.0.36.32/ipc/msg.c
14867 --- linux-2.6.35.4/ipc/msg.c    2010-08-02 16:52:57.000000000 +0200
14868 +++ linux-2.6.35.4-vs2.3.0.36.32/ipc/msg.c      2010-08-02 17:05:06.000000000 +0200
14869 @@ -37,6 +37,7 @@
14870  #include <linux/rwsem.h>
14871  #include <linux/nsproxy.h>
14872  #include <linux/ipc_namespace.h>
14873 +#include <linux/vs_base.h>
14874  
14875  #include <asm/current.h>
14876  #include <asm/uaccess.h>
14877 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14878  
14879         msq->q_perm.mode = msgflg & S_IRWXUGO;
14880         msq->q_perm.key = key;
14881 +       msq->q_perm.xid = vx_current_xid();
14882  
14883         msq->q_perm.security = NULL;
14884         retval = security_msg_queue_alloc(msq);
14885 diff -NurpP --minimal linux-2.6.35.4/ipc/namespace.c linux-2.6.35.4-vs2.3.0.36.32/ipc/namespace.c
14886 --- linux-2.6.35.4/ipc/namespace.c      2009-09-10 15:26:27.000000000 +0200
14887 +++ linux-2.6.35.4-vs2.3.0.36.32/ipc/namespace.c        2010-08-02 17:05:06.000000000 +0200
14888 @@ -11,6 +11,8 @@
14889  #include <linux/slab.h>
14890  #include <linux/fs.h>
14891  #include <linux/mount.h>
14892 +#include <linux/vs_base.h>
14893 +#include <linux/vserver/global.h>
14894  
14895  #include "util.h"
14896  
14897 diff -NurpP --minimal linux-2.6.35.4/ipc/sem.c linux-2.6.35.4-vs2.3.0.36.32/ipc/sem.c
14898 --- linux-2.6.35.4/ipc/sem.c    2010-08-02 16:52:57.000000000 +0200
14899 +++ linux-2.6.35.4-vs2.3.0.36.32/ipc/sem.c      2010-08-02 17:05:06.000000000 +0200
14900 @@ -86,6 +86,8 @@
14901  #include <linux/rwsem.h>
14902  #include <linux/nsproxy.h>
14903  #include <linux/ipc_namespace.h>
14904 +#include <linux/vs_base.h>
14905 +#include <linux/vs_limit.h>
14906  
14907  #include <asm/uaccess.h>
14908  #include "util.h"
14909 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14910  
14911         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14912         sma->sem_perm.key = key;
14913 +       sma->sem_perm.xid = vx_current_xid();
14914  
14915         sma->sem_perm.security = NULL;
14916         retval = security_sem_alloc(sma);
14917 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14918                 return id;
14919         }
14920         ns->used_sems += nsems;
14921 +       /* FIXME: obsoleted? */
14922 +       vx_semary_inc(sma);
14923 +       vx_nsems_add(sma, nsems);
14924  
14925         sma->sem_base = (struct sem *) &sma[1];
14926  
14927 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
14928  
14929         wake_up_sem_queue_do(&tasks);
14930         ns->used_sems -= sma->sem_nsems;
14931 +       /* FIXME: obsoleted? */
14932 +       vx_nsems_sub(sma, sma->sem_nsems);
14933 +       vx_semary_dec(sma);
14934         security_sem_free(sma);
14935         ipc_rcu_putref(sma);
14936  }
14937 diff -NurpP --minimal linux-2.6.35.4/ipc/shm.c linux-2.6.35.4-vs2.3.0.36.32/ipc/shm.c
14938 --- linux-2.6.35.4/ipc/shm.c    2010-08-02 16:52:57.000000000 +0200
14939 +++ linux-2.6.35.4-vs2.3.0.36.32/ipc/shm.c      2010-08-02 17:05:06.000000000 +0200
14940 @@ -39,6 +39,8 @@
14941  #include <linux/nsproxy.h>
14942  #include <linux/mount.h>
14943  #include <linux/ipc_namespace.h>
14944 +#include <linux/vs_context.h>
14945 +#include <linux/vs_limit.h>
14946  
14947  #include <asm/uaccess.h>
14948  
14949 @@ -169,7 +171,12 @@ static void shm_open(struct vm_area_stru
14950   */
14951  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14952  {
14953 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14954 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14955 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14956 +
14957 +       vx_ipcshm_sub(vxi, shp, numpages);
14958 +       ns->shm_tot -= numpages;
14959 +
14960         shm_rmid(ns, shp);
14961         shm_unlock(shp);
14962         if (!is_file_hugepages(shp->shm_file))
14963 @@ -179,6 +186,7 @@ static void shm_destroy(struct ipc_names
14964                                                 shp->mlock_user);
14965         fput (shp->shm_file);
14966         security_shm_free(shp);
14967 +       put_vx_info(vxi);
14968         ipc_rcu_putref(shp);
14969  }
14970  
14971 @@ -349,11 +357,15 @@ static int newseg(struct ipc_namespace *
14972         if (ns->shm_tot + numpages > ns->shm_ctlall)
14973                 return -ENOSPC;
14974  
14975 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14976 +               return -ENOSPC;
14977 +
14978         shp = ipc_rcu_alloc(sizeof(*shp));
14979         if (!shp)
14980                 return -ENOMEM;
14981  
14982         shp->shm_perm.key = key;
14983 +       shp->shm_perm.xid = vx_current_xid();
14984         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14985         shp->mlock_user = NULL;
14986  
14987 @@ -407,6 +419,7 @@ static int newseg(struct ipc_namespace *
14988         ns->shm_tot += numpages;
14989         error = shp->shm_perm.id;
14990         shm_unlock(shp);
14991 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14992         return error;
14993  
14994  no_id:
14995 diff -NurpP --minimal linux-2.6.35.4/kernel/capability.c linux-2.6.35.4-vs2.3.0.36.32/kernel/capability.c
14996 --- linux-2.6.35.4/kernel/capability.c  2010-08-02 16:52:57.000000000 +0200
14997 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/capability.c    2010-08-02 17:05:06.000000000 +0200
14998 @@ -14,6 +14,7 @@
14999  #include <linux/security.h>
15000  #include <linux/syscalls.h>
15001  #include <linux/pid_namespace.h>
15002 +#include <linux/vs_context.h>
15003  #include <asm/uaccess.h>
15004  
15005  /*
15006 @@ -119,6 +120,7 @@ static int cap_validate_magic(cap_user_h
15007         return 0;
15008  }
15009  
15010 +
15011  /*
15012   * The only thing that can change the capabilities of the current
15013   * process is the current process. As such, we can't be in this code
15014 @@ -289,6 +291,8 @@ error:
15015         return ret;
15016  }
15017  
15018 +#include <linux/vserver/base.h>
15019 +
15020  /**
15021   * capable - Determine if the current task has a superior capability in effect
15022   * @cap: The capability to be tested for
15023 @@ -301,6 +305,9 @@ error:
15024   */
15025  int capable(int cap)
15026  {
15027 +       /* here for now so we don't require task locking */
15028 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15029 +               return 0;
15030         if (unlikely(!cap_valid(cap))) {
15031                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15032                 BUG();
15033 diff -NurpP --minimal linux-2.6.35.4/kernel/compat.c linux-2.6.35.4-vs2.3.0.36.32/kernel/compat.c
15034 --- linux-2.6.35.4/kernel/compat.c      2010-08-02 16:52:57.000000000 +0200
15035 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/compat.c        2010-08-02 17:05:06.000000000 +0200
15036 @@ -900,7 +900,7 @@ asmlinkage long compat_sys_time(compat_t
15037         compat_time_t i;
15038         struct timeval tv;
15039  
15040 -       do_gettimeofday(&tv);
15041 +       vx_gettimeofday(&tv);
15042         i = tv.tv_sec;
15043  
15044         if (tloc) {
15045 @@ -925,7 +925,7 @@ asmlinkage long compat_sys_stime(compat_
15046         if (err)
15047                 return err;
15048  
15049 -       do_settimeofday(&tv);
15050 +       vx_settimeofday(&tv);
15051         return 0;
15052  }
15053  
15054 diff -NurpP --minimal linux-2.6.35.4/kernel/exit.c linux-2.6.35.4-vs2.3.0.36.32/kernel/exit.c
15055 --- linux-2.6.35.4/kernel/exit.c        2010-08-02 16:52:57.000000000 +0200
15056 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/exit.c  2010-08-02 17:05:06.000000000 +0200
15057 @@ -48,6 +48,10 @@
15058  #include <linux/fs_struct.h>
15059  #include <linux/init_task.h>
15060  #include <linux/perf_event.h>
15061 +#include <linux/vs_limit.h>
15062 +#include <linux/vs_context.h>
15063 +#include <linux/vs_network.h>
15064 +#include <linux/vs_pid.h>
15065  #include <trace/events/sched.h>
15066  #include <linux/hw_breakpoint.h>
15067  
15068 @@ -487,9 +491,11 @@ static void close_files(struct files_str
15069                                         filp_close(file, files);
15070                                         cond_resched();
15071                                 }
15072 +                               vx_openfd_dec(i);
15073                         }
15074                         i++;
15075                         set >>= 1;
15076 +                       cond_resched();
15077                 }
15078         }
15079  }
15080 @@ -1020,11 +1026,16 @@ NORET_TYPE void do_exit(long code)
15081  
15082         validate_creds_for_do_exit(tsk);
15083  
15084 +       /* needs to stay after exit_notify() */
15085 +       exit_vx_info(tsk, code);
15086 +       exit_nx_info(tsk);
15087 +
15088         preempt_disable();
15089         exit_rcu();
15090         /* causes final put_task_struct in finish_task_switch(). */
15091         tsk->state = TASK_DEAD;
15092         schedule();
15093 +       printk("bad task: %p [%lx]\n", current, current->state);
15094         BUG();
15095         /* Avoid "noreturn function does return".  */
15096         for (;;)
15097 diff -NurpP --minimal linux-2.6.35.4/kernel/fork.c linux-2.6.35.4-vs2.3.0.36.32/kernel/fork.c
15098 --- linux-2.6.35.4/kernel/fork.c        2010-09-05 01:41:57.000000000 +0200
15099 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/fork.c  2010-09-06 02:59:52.000000000 +0200
15100 @@ -65,6 +65,10 @@
15101  #include <linux/perf_event.h>
15102  #include <linux/posix-timers.h>
15103  #include <linux/user-return-notifier.h>
15104 +#include <linux/vs_context.h>
15105 +#include <linux/vs_network.h>
15106 +#include <linux/vs_limit.h>
15107 +#include <linux/vs_memory.h>
15108  
15109  #include <asm/pgtable.h>
15110  #include <asm/pgalloc.h>
15111 @@ -160,6 +164,8 @@ void free_task(struct task_struct *tsk)
15112         account_kernel_stack(tsk->stack, -1);
15113         free_thread_info(tsk->stack);
15114         rt_mutex_debug_task_free(tsk);
15115 +       clr_vx_info(&tsk->vx_info);
15116 +       clr_nx_info(&tsk->nx_info);
15117         ftrace_graph_exit_task(tsk);
15118         free_task_struct(tsk);
15119  }
15120 @@ -492,6 +498,7 @@ static struct mm_struct * mm_init(struct
15121         if (likely(!mm_alloc_pgd(mm))) {
15122                 mm->def_flags = 0;
15123                 mmu_notifier_mm_init(mm);
15124 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15125                 return mm;
15126         }
15127  
15128 @@ -525,6 +532,7 @@ void __mmdrop(struct mm_struct *mm)
15129         mm_free_pgd(mm);
15130         destroy_context(mm);
15131         mmu_notifier_mm_destroy(mm);
15132 +       clr_vx_info(&mm->mm_vx_info);
15133         free_mm(mm);
15134  }
15135  EXPORT_SYMBOL_GPL(__mmdrop);
15136 @@ -660,6 +668,7 @@ struct mm_struct *dup_mm(struct task_str
15137                 goto fail_nomem;
15138  
15139         memcpy(mm, oldmm, sizeof(*mm));
15140 +       mm->mm_vx_info = NULL;
15141  
15142         /* Initializing for Swap token stuff */
15143         mm->token_priority = 0;
15144 @@ -698,6 +707,7 @@ fail_nocontext:
15145          * If init_new_context() failed, we cannot use mmput() to free the mm
15146          * because it calls destroy_context()
15147          */
15148 +       clr_vx_info(&mm->mm_vx_info);
15149         mm_free_pgd(mm);
15150         free_mm(mm);
15151         return NULL;
15152 @@ -972,6 +982,8 @@ static struct task_struct *copy_process(
15153         int retval;
15154         struct task_struct *p;
15155         int cgroup_callbacks_done = 0;
15156 +       struct vx_info *vxi;
15157 +       struct nx_info *nxi;
15158  
15159         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15160                 return ERR_PTR(-EINVAL);
15161 @@ -1018,7 +1030,12 @@ static struct task_struct *copy_process(
15162         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15163         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15164  #endif
15165 +       init_vx_info(&p->vx_info, current_vx_info());
15166 +       init_nx_info(&p->nx_info, current_nx_info());
15167 +
15168         retval = -EAGAIN;
15169 +       if (!vx_nproc_avail(1))
15170 +               goto bad_fork_free;
15171         if (atomic_read(&p->real_cred->user->processes) >=
15172                         task_rlimit(p, RLIMIT_NPROC)) {
15173                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15174 @@ -1283,6 +1300,18 @@ static struct task_struct *copy_process(
15175  
15176         total_forks++;
15177         spin_unlock(&current->sighand->siglock);
15178 +
15179 +       /* p is copy of current */
15180 +       vxi = p->vx_info;
15181 +       if (vxi) {
15182 +               claim_vx_info(vxi, p);
15183 +               atomic_inc(&vxi->cvirt.nr_threads);
15184 +               atomic_inc(&vxi->cvirt.total_forks);
15185 +               vx_nproc_inc(p);
15186 +       }
15187 +       nxi = p->nx_info;
15188 +       if (nxi)
15189 +               claim_nx_info(nxi, p);
15190         write_unlock_irq(&tasklist_lock);
15191         proc_fork_connector(p);
15192         cgroup_post_fork(p);
15193 diff -NurpP --minimal linux-2.6.35.4/kernel/kthread.c linux-2.6.35.4-vs2.3.0.36.32/kernel/kthread.c
15194 --- linux-2.6.35.4/kernel/kthread.c     2010-07-07 18:31:57.000000000 +0200
15195 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/kthread.c       2010-08-02 17:05:06.000000000 +0200
15196 @@ -14,6 +14,7 @@
15197  #include <linux/file.h>
15198  #include <linux/module.h>
15199  #include <linux/mutex.h>
15200 +#include <linux/vs_pid.h>
15201  #include <trace/events/sched.h>
15202  
15203  static DEFINE_SPINLOCK(kthread_create_lock);
15204 diff -NurpP --minimal linux-2.6.35.4/kernel/Makefile linux-2.6.35.4-vs2.3.0.36.32/kernel/Makefile
15205 --- linux-2.6.35.4/kernel/Makefile      2010-08-02 16:52:57.000000000 +0200
15206 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/Makefile        2010-08-02 17:05:06.000000000 +0200
15207 @@ -25,6 +25,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
15208  CFLAGS_REMOVE_perf_event.o = -pg
15209  endif
15210  
15211 +obj-y += vserver/
15212  obj-$(CONFIG_FREEZER) += freezer.o
15213  obj-$(CONFIG_PROFILING) += profile.o
15214  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15215 diff -NurpP --minimal linux-2.6.35.4/kernel/nsproxy.c linux-2.6.35.4-vs2.3.0.36.32/kernel/nsproxy.c
15216 --- linux-2.6.35.4/kernel/nsproxy.c     2010-07-07 18:31:57.000000000 +0200
15217 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/nsproxy.c       2010-08-02 17:05:06.000000000 +0200
15218 @@ -20,6 +20,8 @@
15219  #include <linux/mnt_namespace.h>
15220  #include <linux/utsname.h>
15221  #include <linux/pid_namespace.h>
15222 +#include <linux/vserver/global.h>
15223 +#include <linux/vserver/debug.h>
15224  #include <net/net_namespace.h>
15225  #include <linux/ipc_namespace.h>
15226  
15227 @@ -43,8 +45,11 @@ static inline struct nsproxy *create_nsp
15228         struct nsproxy *nsproxy;
15229  
15230         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15231 -       if (nsproxy)
15232 +       if (nsproxy) {
15233                 atomic_set(&nsproxy->count, 1);
15234 +               atomic_inc(&vs_global_nsproxy);
15235 +       }
15236 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15237         return nsproxy;
15238  }
15239  
15240 @@ -53,41 +58,52 @@ static inline struct nsproxy *create_nsp
15241   * Return the newly created nsproxy.  Do not attach this to the task,
15242   * leave it to the caller to do proper locking and attach it to task.
15243   */
15244 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15245 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15246 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15247 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15248  {
15249         struct nsproxy *new_nsp;
15250         int err;
15251  
15252 +       vxdprintk(VXD_CBIT(space, 4),
15253 +               "unshare_namespaces(0x%08lx,%p,%p)",
15254 +               flags, orig, new_fs);
15255 +
15256         new_nsp = create_nsproxy();
15257         if (!new_nsp)
15258                 return ERR_PTR(-ENOMEM);
15259  
15260 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15261 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15262         if (IS_ERR(new_nsp->mnt_ns)) {
15263                 err = PTR_ERR(new_nsp->mnt_ns);
15264                 goto out_ns;
15265         }
15266  
15267 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15268 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15269         if (IS_ERR(new_nsp->uts_ns)) {
15270                 err = PTR_ERR(new_nsp->uts_ns);
15271                 goto out_uts;
15272         }
15273  
15274 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15275 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15276         if (IS_ERR(new_nsp->ipc_ns)) {
15277                 err = PTR_ERR(new_nsp->ipc_ns);
15278                 goto out_ipc;
15279         }
15280  
15281 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15282 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15283         if (IS_ERR(new_nsp->pid_ns)) {
15284                 err = PTR_ERR(new_nsp->pid_ns);
15285                 goto out_pid;
15286         }
15287  
15288 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15289 +       /* disabled now?
15290 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15291 +       if (IS_ERR(new_nsp->user_ns)) {
15292 +               err = PTR_ERR(new_nsp->user_ns);
15293 +               goto out_user;
15294 +       } */
15295 +
15296 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15297         if (IS_ERR(new_nsp->net_ns)) {
15298                 err = PTR_ERR(new_nsp->net_ns);
15299                 goto out_net;
15300 @@ -112,6 +128,38 @@ out_ns:
15301         return ERR_PTR(err);
15302  }
15303  
15304 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15305 +                       struct fs_struct *new_fs)
15306 +{
15307 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15308 +}
15309 +
15310 +/*
15311 + * copies the nsproxy, setting refcount to 1, and grabbing a
15312 + * reference to all contained namespaces.
15313 + */
15314 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15315 +{
15316 +       struct nsproxy *ns = create_nsproxy();
15317 +
15318 +       if (ns) {
15319 +               memcpy(ns, orig, sizeof(struct nsproxy));
15320 +               atomic_set(&ns->count, 1);
15321 +
15322 +               if (ns->mnt_ns)
15323 +                       get_mnt_ns(ns->mnt_ns);
15324 +               if (ns->uts_ns)
15325 +                       get_uts_ns(ns->uts_ns);
15326 +               if (ns->ipc_ns)
15327 +                       get_ipc_ns(ns->ipc_ns);
15328 +               if (ns->pid_ns)
15329 +                       get_pid_ns(ns->pid_ns);
15330 +               if (ns->net_ns)
15331 +                       get_net(ns->net_ns);
15332 +       }
15333 +       return ns;
15334 +}
15335 +
15336  /*
15337   * called from clone.  This now handles copy for nsproxy and all
15338   * namespaces therein.
15339 @@ -119,9 +167,12 @@ out_ns:
15340  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15341  {
15342         struct nsproxy *old_ns = tsk->nsproxy;
15343 -       struct nsproxy *new_ns;
15344 +       struct nsproxy *new_ns = NULL;
15345         int err = 0;
15346  
15347 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15348 +               flags, tsk, old_ns);
15349 +
15350         if (!old_ns)
15351                 return 0;
15352  
15353 @@ -131,7 +182,7 @@ int copy_namespaces(unsigned long flags,
15354                                 CLONE_NEWPID | CLONE_NEWNET)))
15355                 return 0;
15356  
15357 -       if (!capable(CAP_SYS_ADMIN)) {
15358 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15359                 err = -EPERM;
15360                 goto out;
15361         }
15362 @@ -158,6 +209,9 @@ int copy_namespaces(unsigned long flags,
15363  
15364  out:
15365         put_nsproxy(old_ns);
15366 +       vxdprintk(VXD_CBIT(space, 3),
15367 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15368 +               flags, tsk, old_ns, err, new_ns);
15369         return err;
15370  }
15371  
15372 @@ -171,7 +225,9 @@ void free_nsproxy(struct nsproxy *ns)
15373                 put_ipc_ns(ns->ipc_ns);
15374         if (ns->pid_ns)
15375                 put_pid_ns(ns->pid_ns);
15376 -       put_net(ns->net_ns);
15377 +       if (ns->net_ns)
15378 +               put_net(ns->net_ns);
15379 +       atomic_dec(&vs_global_nsproxy);
15380         kmem_cache_free(nsproxy_cachep, ns);
15381  }
15382  
15383 @@ -184,11 +240,15 @@ int unshare_nsproxy_namespaces(unsigned 
15384  {
15385         int err = 0;
15386  
15387 +       vxdprintk(VXD_CBIT(space, 4),
15388 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15389 +               unshare_flags, current->nsproxy);
15390 +
15391         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15392                                CLONE_NEWNET)))
15393                 return 0;
15394  
15395 -       if (!capable(CAP_SYS_ADMIN))
15396 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15397                 return -EPERM;
15398  
15399         *new_nsp = create_new_namespaces(unshare_flags, current,
15400 diff -NurpP --minimal linux-2.6.35.4/kernel/pid.c linux-2.6.35.4-vs2.3.0.36.32/kernel/pid.c
15401 --- linux-2.6.35.4/kernel/pid.c 2010-08-02 16:52:57.000000000 +0200
15402 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/pid.c   2010-08-02 17:05:06.000000000 +0200
15403 @@ -36,6 +36,7 @@
15404  #include <linux/pid_namespace.h>
15405  #include <linux/init_task.h>
15406  #include <linux/syscalls.h>
15407 +#include <linux/vs_pid.h>
15408  
15409  #define pid_hashfn(nr, ns)     \
15410         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15411 @@ -305,7 +306,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15412  
15413  struct pid *find_vpid(int nr)
15414  {
15415 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15416 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15417  }
15418  EXPORT_SYMBOL_GPL(find_vpid);
15419  
15420 @@ -365,6 +366,9 @@ void transfer_pid(struct task_struct *ol
15421  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15422  {
15423         struct task_struct *result = NULL;
15424 +
15425 +       if (type == PIDTYPE_REALPID)
15426 +               type = PIDTYPE_PID;
15427         if (pid) {
15428                 struct hlist_node *first;
15429                 first = rcu_dereference_check(pid->tasks[type].first,
15430 @@ -382,7 +386,7 @@ EXPORT_SYMBOL(pid_task);
15431   */
15432  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15433  {
15434 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15435 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15436  }
15437  
15438  struct task_struct *find_task_by_vpid(pid_t vnr)
15439 @@ -424,7 +428,7 @@ struct pid *find_get_pid(pid_t nr)
15440  }
15441  EXPORT_SYMBOL_GPL(find_get_pid);
15442  
15443 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15444 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15445  {
15446         struct upid *upid;
15447         pid_t nr = 0;
15448 @@ -437,6 +441,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15449         return nr;
15450  }
15451  
15452 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15453 +{
15454 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15455 +}
15456 +
15457  pid_t pid_vnr(struct pid *pid)
15458  {
15459         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15460 diff -NurpP --minimal linux-2.6.35.4/kernel/pid_namespace.c linux-2.6.35.4-vs2.3.0.36.32/kernel/pid_namespace.c
15461 --- linux-2.6.35.4/kernel/pid_namespace.c       2010-07-07 18:31:57.000000000 +0200
15462 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/pid_namespace.c 2010-08-02 17:05:06.000000000 +0200
15463 @@ -14,6 +14,7 @@
15464  #include <linux/err.h>
15465  #include <linux/acct.h>
15466  #include <linux/slab.h>
15467 +#include <linux/vserver/global.h>
15468  
15469  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15470  
15471 @@ -87,6 +88,7 @@ static struct pid_namespace *create_pid_
15472                 goto out_free_map;
15473  
15474         kref_init(&ns->kref);
15475 +       atomic_inc(&vs_global_pid_ns);
15476         ns->level = level;
15477         ns->parent = get_pid_ns(parent_pid_ns);
15478  
15479 @@ -112,6 +114,7 @@ static void destroy_pid_namespace(struct
15480  
15481         for (i = 0; i < PIDMAP_ENTRIES; i++)
15482                 kfree(ns->pidmap[i].page);
15483 +       atomic_dec(&vs_global_pid_ns);
15484         kmem_cache_free(pid_ns_cachep, ns);
15485  }
15486  
15487 diff -NurpP --minimal linux-2.6.35.4/kernel/posix-timers.c linux-2.6.35.4-vs2.3.0.36.32/kernel/posix-timers.c
15488 --- linux-2.6.35.4/kernel/posix-timers.c        2010-08-02 16:52:57.000000000 +0200
15489 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/posix-timers.c  2010-08-02 17:05:06.000000000 +0200
15490 @@ -46,6 +46,7 @@
15491  #include <linux/wait.h>
15492  #include <linux/workqueue.h>
15493  #include <linux/module.h>
15494 +#include <linux/vs_context.h>
15495  
15496  /*
15497   * Management arrays for POSIX timers.  Timers are kept in slab memory
15498 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15499  {
15500         struct task_struct *task;
15501         int shared, ret = -1;
15502 +
15503         /*
15504          * FIXME: if ->sigq is queued we can race with
15505          * dequeue_signal()->do_schedule_next_timer().
15506 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15507         rcu_read_lock();
15508         task = pid_task(timr->it_pid, PIDTYPE_PID);
15509         if (task) {
15510 +               struct vx_info_save vxis;
15511 +               struct vx_info *vxi;
15512 +
15513 +               vxi = get_vx_info(task->vx_info);
15514 +               enter_vx_info(vxi, &vxis);
15515                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15516                 ret = send_sigqueue(timr->sigq, task, shared);
15517 +               leave_vx_info(&vxis);
15518 +               put_vx_info(vxi);
15519         }
15520         rcu_read_unlock();
15521 +
15522         /* If we failed to send the signal the timer stops. */
15523         return ret > 0;
15524  }
15525 diff -NurpP --minimal linux-2.6.35.4/kernel/printk.c linux-2.6.35.4-vs2.3.0.36.32/kernel/printk.c
15526 --- linux-2.6.35.4/kernel/printk.c      2010-08-02 16:52:57.000000000 +0200
15527 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/printk.c        2010-08-02 17:05:06.000000000 +0200
15528 @@ -37,6 +37,7 @@
15529  #include <linux/ratelimit.h>
15530  #include <linux/kmsg_dump.h>
15531  #include <linux/syslog.h>
15532 +#include <linux/vs_cvirt.h>
15533  
15534  #include <asm/uaccess.h>
15535  
15536 @@ -264,18 +265,15 @@ int do_syslog(int type, char __user *buf
15537         unsigned i, j, limit, count;
15538         int do_clear = 0;
15539         char c;
15540 -       int error = 0;
15541 +       int error;
15542  
15543         error = security_syslog(type, from_file);
15544         if (error)
15545                 return error;
15546  
15547 -       switch (type) {
15548 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15549 -               break;
15550 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15551 -               break;
15552 -       case SYSLOG_ACTION_READ:        /* Read from log */
15553 +       if ((type == SYSLOG_ACTION_READ) ||
15554 +           (type == SYSLOG_ACTION_READ_ALL) ||
15555 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15556                 error = -EINVAL;
15557                 if (!buf || len < 0)
15558                         goto out;
15559 @@ -286,6 +284,16 @@ int do_syslog(int type, char __user *buf
15560                         error = -EFAULT;
15561                         goto out;
15562                 }
15563 +       }
15564 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15565 +               return vx_do_syslog(type, buf, len);
15566 +
15567 +       switch (type) {
15568 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15569 +               break;
15570 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15571 +               break;
15572 +       case SYSLOG_ACTION_READ:        /* Read from log */
15573                 error = wait_event_interruptible(log_wait,
15574                                                         (log_start - log_end));
15575                 if (error)
15576 @@ -312,16 +320,6 @@ int do_syslog(int type, char __user *buf
15577                 /* FALL THRU */
15578         /* Read last kernel messages */
15579         case SYSLOG_ACTION_READ_ALL:
15580 -               error = -EINVAL;
15581 -               if (!buf || len < 0)
15582 -                       goto out;
15583 -               error = 0;
15584 -               if (!len)
15585 -                       goto out;
15586 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15587 -                       error = -EFAULT;
15588 -                       goto out;
15589 -               }
15590                 count = len;
15591                 if (count > log_buf_len)
15592                         count = log_buf_len;
15593 diff -NurpP --minimal linux-2.6.35.4/kernel/ptrace.c linux-2.6.35.4-vs2.3.0.36.32/kernel/ptrace.c
15594 --- linux-2.6.35.4/kernel/ptrace.c      2010-08-02 16:52:57.000000000 +0200
15595 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/ptrace.c        2010-08-02 17:05:06.000000000 +0200
15596 @@ -22,6 +22,7 @@
15597  #include <linux/syscalls.h>
15598  #include <linux/uaccess.h>
15599  #include <linux/regset.h>
15600 +#include <linux/vs_context.h>
15601  
15602  
15603  /*
15604 @@ -150,6 +151,11 @@ int __ptrace_may_access(struct task_stru
15605                 dumpable = get_dumpable(task->mm);
15606         if (!dumpable && !capable(CAP_SYS_PTRACE))
15607                 return -EPERM;
15608 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15609 +               return -EPERM;
15610 +       if (!vx_check(task->xid, VS_IDENT) &&
15611 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15612 +               return -EACCES;
15613  
15614         return security_ptrace_access_check(task, mode);
15615  }
15616 @@ -703,6 +709,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15617                 goto out;
15618         }
15619  
15620 +       ret = -EPERM;
15621 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15622 +               goto out_put_task_struct;
15623 +
15624         if (request == PTRACE_ATTACH) {
15625                 ret = ptrace_attach(child);
15626                 /*
15627 diff -NurpP --minimal linux-2.6.35.4/kernel/sched.c linux-2.6.35.4-vs2.3.0.36.32/kernel/sched.c
15628 --- linux-2.6.35.4/kernel/sched.c       2010-09-05 01:41:57.000000000 +0200
15629 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/sched.c 2010-09-06 02:59:52.000000000 +0200
15630 @@ -72,6 +72,8 @@
15631  #include <linux/ctype.h>
15632  #include <linux/ftrace.h>
15633  #include <linux/slab.h>
15634 +#include <linux/vs_sched.h>
15635 +#include <linux/vs_cvirt.h>
15636  
15637  #include <asm/tlb.h>
15638  #include <asm/irq_regs.h>
15639 @@ -2947,9 +2949,17 @@ static inline long calc_load_fold_idle(v
15640   */
15641  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15642  {
15643 -       loads[0] = (avenrun[0] + offset) << shift;
15644 -       loads[1] = (avenrun[1] + offset) << shift;
15645 -       loads[2] = (avenrun[2] + offset) << shift;
15646 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15647 +               struct vx_info *vxi = current_vx_info();
15648 +
15649 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15650 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15651 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15652 +       } else {
15653 +               loads[0] = (avenrun[0] + offset) << shift;
15654 +               loads[1] = (avenrun[1] + offset) << shift;
15655 +               loads[2] = (avenrun[2] + offset) << shift;
15656 +       }
15657  }
15658  
15659  static unsigned long
15660 @@ -3157,16 +3167,19 @@ void account_user_time(struct task_struc
15661                        cputime_t cputime_scaled)
15662  {
15663         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15664 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15665         cputime64_t tmp;
15666 +       int nice = (TASK_NICE(p) > 0);
15667  
15668         /* Add user time to process. */
15669         p->utime = cputime_add(p->utime, cputime);
15670         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15671 +       vx_account_user(vxi, cputime, nice);
15672         account_group_user_time(p, cputime);
15673  
15674         /* Add user time to cpustat. */
15675         tmp = cputime_to_cputime64(cputime);
15676 -       if (TASK_NICE(p) > 0)
15677 +       if (nice)
15678                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15679         else
15680                 cpustat->user = cputime64_add(cpustat->user, tmp);
15681 @@ -3217,6 +3230,7 @@ void account_system_time(struct task_str
15682                          cputime_t cputime, cputime_t cputime_scaled)
15683  {
15684         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15685 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15686         cputime64_t tmp;
15687  
15688         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15689 @@ -3227,6 +3241,7 @@ void account_system_time(struct task_str
15690         /* Add system time to process. */
15691         p->stime = cputime_add(p->stime, cputime);
15692         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15693 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15694         account_group_system_time(p, cputime);
15695  
15696         /* Add system time to cpustat. */
15697 @@ -4300,7 +4315,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15698                 nice = 19;
15699  
15700         if (increment < 0 && !can_nice(current, nice))
15701 -               return -EPERM;
15702 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15703  
15704         retval = security_task_setnice(current, nice);
15705         if (retval)
15706 diff -NurpP --minimal linux-2.6.35.4/kernel/sched_fair.c linux-2.6.35.4-vs2.3.0.36.32/kernel/sched_fair.c
15707 --- linux-2.6.35.4/kernel/sched_fair.c  2010-08-02 16:52:57.000000000 +0200
15708 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/sched_fair.c    2010-08-02 17:05:06.000000000 +0200
15709 @@ -782,6 +782,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15710         check_spread(cfs_rq, se);
15711         if (se != cfs_rq->curr)
15712                 __enqueue_entity(cfs_rq, se);
15713 +
15714 +       if (entity_is_task(se))
15715 +               vx_activate_task(task_of(se));
15716  }
15717  
15718  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
15719 @@ -825,6 +828,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15720  
15721         if (se != cfs_rq->curr)
15722                 __dequeue_entity(cfs_rq, se);
15723 +       if (entity_is_task(se))
15724 +               vx_deactivate_task(task_of(se));
15725         account_entity_dequeue(cfs_rq, se);
15726         update_min_vruntime(cfs_rq);
15727  
15728 diff -NurpP --minimal linux-2.6.35.4/kernel/signal.c linux-2.6.35.4-vs2.3.0.36.32/kernel/signal.c
15729 --- linux-2.6.35.4/kernel/signal.c      2010-09-05 01:41:57.000000000 +0200
15730 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/signal.c        2010-08-14 18:19:32.000000000 +0200
15731 @@ -28,6 +28,8 @@
15732  #include <linux/freezer.h>
15733  #include <linux/pid_namespace.h>
15734  #include <linux/nsproxy.h>
15735 +#include <linux/vs_context.h>
15736 +#include <linux/vs_pid.h>
15737  #define CREATE_TRACE_POINTS
15738  #include <trace/events/signal.h>
15739  
15740 @@ -646,9 +648,18 @@ static int check_kill_permission(int sig
15741         struct pid *sid;
15742         int error;
15743  
15744 +       vxdprintk(VXD_CBIT(misc, 7),
15745 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15746 +               sig, info, t, vx_task_xid(t), t->pid);
15747 +
15748         if (!valid_signal(sig))
15749                 return -EINVAL;
15750  
15751 +/*     FIXME: needed? if so, why?
15752 +       if ((info != SEND_SIG_NOINFO) &&
15753 +               (is_si_special(info) || !si_fromuser(info)))
15754 +               goto skip;      */
15755 +
15756         if (!si_fromuser(info))
15757                 return 0;
15758  
15759 @@ -678,6 +689,20 @@ static int check_kill_permission(int sig
15760                 }
15761         }
15762  
15763 +       error = -EPERM;
15764 +       if (t->pid == 1 && current->xid)
15765 +               return error;
15766 +
15767 +       error = -ESRCH;
15768 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15769 +                 loops, maybe ENOENT or EACCES? */
15770 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15771 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15772 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15773 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15774 +               return error;
15775 +       }
15776 +/* skip: */
15777         return security_task_kill(t, info, sig, 0);
15778  }
15779  
15780 @@ -1170,7 +1195,7 @@ int kill_pid_info(int sig, struct siginf
15781         rcu_read_lock();
15782  retry:
15783         p = pid_task(pid, PIDTYPE_PID);
15784 -       if (p) {
15785 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15786                 error = group_send_sig_info(sig, info, p);
15787                 if (unlikely(error == -ESRCH))
15788                         /*
15789 @@ -1210,7 +1235,7 @@ int kill_pid_info_as_uid(int sig, struct
15790  
15791         rcu_read_lock();
15792         p = pid_task(pid, PIDTYPE_PID);
15793 -       if (!p) {
15794 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15795                 ret = -ESRCH;
15796                 goto out_unlock;
15797         }
15798 @@ -1265,8 +1290,10 @@ static int kill_something_info(int sig, 
15799                 struct task_struct * p;
15800  
15801                 for_each_process(p) {
15802 -                       if (task_pid_vnr(p) > 1 &&
15803 -                                       !same_thread_group(p, current)) {
15804 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15805 +                               task_pid_vnr(p) > 1 &&
15806 +                               !same_thread_group(p, current) &&
15807 +                               !vx_current_initpid(p->pid)) {
15808                                 int err = group_send_sig_info(sig, info, p);
15809                                 ++count;
15810                                 if (err != -EPERM)
15811 @@ -1933,6 +1960,11 @@ relock:
15812                                 !sig_kernel_only(signr))
15813                         continue;
15814  
15815 +               /* virtual init is protected against user signals */
15816 +               if ((info->si_code == SI_USER) &&
15817 +                       vx_current_initpid(current->pid))
15818 +                       continue;
15819 +
15820                 if (sig_kernel_stop(signr)) {
15821                         /*
15822                          * The default action is to stop all threads in
15823 diff -NurpP --minimal linux-2.6.35.4/kernel/softirq.c linux-2.6.35.4-vs2.3.0.36.32/kernel/softirq.c
15824 --- linux-2.6.35.4/kernel/softirq.c     2010-08-02 16:52:57.000000000 +0200
15825 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/softirq.c       2010-08-02 17:05:06.000000000 +0200
15826 @@ -24,6 +24,7 @@
15827  #include <linux/ftrace.h>
15828  #include <linux/smp.h>
15829  #include <linux/tick.h>
15830 +#include <linux/vs_context.h>
15831  
15832  #define CREATE_TRACE_POINTS
15833  #include <trace/events/irq.h>
15834 diff -NurpP --minimal linux-2.6.35.4/kernel/sys.c linux-2.6.35.4-vs2.3.0.36.32/kernel/sys.c
15835 --- linux-2.6.35.4/kernel/sys.c 2010-08-02 16:52:57.000000000 +0200
15836 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/sys.c   2010-08-02 17:48:19.000000000 +0200
15837 @@ -42,6 +42,7 @@
15838  #include <linux/syscalls.h>
15839  #include <linux/kprobes.h>
15840  #include <linux/user_namespace.h>
15841 +#include <linux/vs_pid.h>
15842  
15843  #include <asm/uaccess.h>
15844  #include <asm/io.h>
15845 @@ -131,7 +132,10 @@ static int set_one_prio(struct task_stru
15846                 goto out;
15847         }
15848         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15849 -               error = -EACCES;
15850 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15851 +                       error = 0;
15852 +               else
15853 +                       error = -EACCES;
15854                 goto out;
15855         }
15856         no_nice = security_task_setnice(p, niceval);
15857 @@ -181,6 +185,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15858                         else
15859                                 pgrp = task_pgrp(current);
15860                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15861 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15862 +                                       continue;
15863                                 error = set_one_prio(p, niceval, error);
15864                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15865                         break;
15866 @@ -244,6 +250,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15867                         else
15868                                 pgrp = task_pgrp(current);
15869                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15870 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15871 +                                       continue;
15872                                 niceval = 20 - task_nice(p);
15873                                 if (niceval > retval)
15874                                         retval = niceval;
15875 @@ -357,6 +365,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15876  
15877  static DEFINE_MUTEX(reboot_mutex);
15878  
15879 +long vs_reboot(unsigned int, void __user *);
15880 +
15881  /*
15882   * Reboot system call: for obvious reasons only root may call it,
15883   * and even root needs to set up some magic numbers in the registers
15884 @@ -389,6 +399,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15885         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15886                 cmd = LINUX_REBOOT_CMD_HALT;
15887  
15888 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15889 +               return vs_reboot(cmd, arg);
15890 +
15891         mutex_lock(&reboot_mutex);
15892         switch (cmd) {
15893         case LINUX_REBOOT_CMD_RESTART:
15894 @@ -1167,7 +1180,7 @@ SYSCALL_DEFINE2(sethostname, char __user
15895         int errno;
15896         char tmp[__NEW_UTS_LEN];
15897  
15898 -       if (!capable(CAP_SYS_ADMIN))
15899 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15900                 return -EPERM;
15901         if (len < 0 || len > __NEW_UTS_LEN)
15902                 return -EINVAL;
15903 @@ -1216,7 +1229,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
15904         int errno;
15905         char tmp[__NEW_UTS_LEN];
15906  
15907 -       if (!capable(CAP_SYS_ADMIN))
15908 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15909                 return -EPERM;
15910         if (len < 0 || len > __NEW_UTS_LEN)
15911                 return -EINVAL;
15912 @@ -1285,7 +1298,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
15913                 return -EINVAL;
15914         old_rlim = current->signal->rlim + resource;
15915         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
15916 -           !capable(CAP_SYS_RESOURCE))
15917 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15918                 return -EPERM;
15919         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
15920                 return -EPERM;
15921 diff -NurpP --minimal linux-2.6.35.4/kernel/sysctl_binary.c linux-2.6.35.4-vs2.3.0.36.32/kernel/sysctl_binary.c
15922 --- linux-2.6.35.4/kernel/sysctl_binary.c       2010-08-02 16:52:57.000000000 +0200
15923 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/sysctl_binary.c 2010-08-02 17:05:06.000000000 +0200
15924 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15925  
15926         { CTL_INT,      KERN_PANIC,                     "panic" },
15927         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15928 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15929  
15930         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15931         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15932 diff -NurpP --minimal linux-2.6.35.4/kernel/sysctl.c linux-2.6.35.4-vs2.3.0.36.32/kernel/sysctl.c
15933 --- linux-2.6.35.4/kernel/sysctl.c      2010-08-02 16:52:57.000000000 +0200
15934 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/sysctl.c        2010-08-02 17:05:06.000000000 +0200
15935 @@ -72,6 +72,7 @@
15936  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15937  #include <linux/lockdep.h>
15938  #endif
15939 +extern char vshelper_path[];
15940  #ifdef CONFIG_CHR_DEV_SG
15941  #include <scsi/sg.h>
15942  #endif
15943 @@ -571,6 +572,13 @@ static struct ctl_table kern_table[] = {
15944                 .proc_handler   = proc_dostring,
15945         },
15946  #endif
15947 +       {
15948 +               .procname       = "vshelper",
15949 +               .data           = &vshelper_path,
15950 +               .maxlen         = 256,
15951 +               .mode           = 0644,
15952 +               .proc_handler   = &proc_dostring,
15953 +       },
15954  #ifdef CONFIG_CHR_DEV_SG
15955         {
15956                 .procname       = "sg-big-buff",
15957 diff -NurpP --minimal linux-2.6.35.4/kernel/time.c linux-2.6.35.4-vs2.3.0.36.32/kernel/time.c
15958 --- linux-2.6.35.4/kernel/time.c        2010-08-02 16:52:57.000000000 +0200
15959 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/time.c  2010-08-02 17:05:06.000000000 +0200
15960 @@ -62,6 +62,7 @@ EXPORT_SYMBOL(sys_tz);
15961  SYSCALL_DEFINE1(time, time_t __user *, tloc)
15962  {
15963         time_t i = get_seconds();
15964 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
15965  
15966         if (tloc) {
15967                 if (put_user(i,tloc))
15968 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15969         if (err)
15970                 return err;
15971  
15972 -       do_settimeofday(&tv);
15973 +       vx_settimeofday(&tv);
15974         return 0;
15975  }
15976  
15977 @@ -103,7 +104,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
15978  {
15979         if (likely(tv != NULL)) {
15980                 struct timeval ktv;
15981 -               do_gettimeofday(&ktv);
15982 +               vx_gettimeofday(&ktv);
15983                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
15984                         return -EFAULT;
15985         }
15986 @@ -177,7 +178,7 @@ int do_sys_settimeofday(struct timespec 
15987                 /* SMP safe, again the code in arch/foo/time.c should
15988                  * globally block out interrupts when it runs.
15989                  */
15990 -               return do_settimeofday(tv);
15991 +               return vx_settimeofday(tv);
15992         }
15993         return 0;
15994  }
15995 @@ -309,7 +310,7 @@ void getnstimeofday(struct timespec *tv)
15996  {
15997         struct timeval x;
15998  
15999 -       do_gettimeofday(&x);
16000 +       vx_gettimeofday(&x);
16001         tv->tv_sec = x.tv_sec;
16002         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
16003  }
16004 diff -NurpP --minimal linux-2.6.35.4/kernel/timer.c linux-2.6.35.4-vs2.3.0.36.32/kernel/timer.c
16005 --- linux-2.6.35.4/kernel/timer.c       2010-08-02 16:52:58.000000000 +0200
16006 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/timer.c 2010-08-02 17:05:06.000000000 +0200
16007 @@ -40,6 +40,10 @@
16008  #include <linux/perf_event.h>
16009  #include <linux/sched.h>
16010  #include <linux/slab.h>
16011 +#include <linux/vs_base.h>
16012 +#include <linux/vs_cvirt.h>
16013 +#include <linux/vs_pid.h>
16014 +#include <linux/vserver/sched.h>
16015  
16016  #include <asm/uaccess.h>
16017  #include <asm/unistd.h>
16018 @@ -1318,12 +1322,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
16019  
16020  #endif
16021  
16022 -#ifndef __alpha__
16023 -
16024 -/*
16025 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
16026 - * should be moved into arch/i386 instead?
16027 - */
16028  
16029  /**
16030   * sys_getpid - return the thread group id of the current process
16031 @@ -1352,10 +1350,23 @@ SYSCALL_DEFINE0(getppid)
16032         rcu_read_lock();
16033         pid = task_tgid_vnr(current->real_parent);
16034         rcu_read_unlock();
16035 +       return vx_map_pid(pid);
16036 +}
16037  
16038 -       return pid;
16039 +#ifdef __alpha__
16040 +
16041 +/*
16042 + * The Alpha uses getxpid, getxuid, and getxgid instead.
16043 + */
16044 +
16045 +asmlinkage long do_getxpid(long *ppid)
16046 +{
16047 +       *ppid = sys_getppid();
16048 +       return sys_getpid();
16049  }
16050  
16051 +#else /* _alpha_ */
16052 +
16053  SYSCALL_DEFINE0(getuid)
16054  {
16055         /* Only we change this so SMP safe */
16056 diff -NurpP --minimal linux-2.6.35.4/kernel/user_namespace.c linux-2.6.35.4-vs2.3.0.36.32/kernel/user_namespace.c
16057 --- linux-2.6.35.4/kernel/user_namespace.c      2010-08-02 16:52:58.000000000 +0200
16058 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/user_namespace.c        2010-08-02 17:05:06.000000000 +0200
16059 @@ -10,6 +10,7 @@
16060  #include <linux/slab.h>
16061  #include <linux/user_namespace.h>
16062  #include <linux/cred.h>
16063 +#include <linux/vserver/global.h>
16064  
16065  /*
16066   * Create a new user namespace, deriving the creator from the user in the
16067 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
16068                 return -ENOMEM;
16069  
16070         kref_init(&ns->kref);
16071 +       atomic_inc(&vs_global_user_ns);
16072  
16073         for (n = 0; n < UIDHASH_SZ; ++n)
16074                 INIT_HLIST_HEAD(ns->uidhash_table + n);
16075 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
16076         struct user_namespace *ns =
16077                 container_of(kref, struct user_namespace, kref);
16078  
16079 +       /* FIXME: maybe move into destroyer? */
16080 +       atomic_dec(&vs_global_user_ns);
16081         INIT_WORK(&ns->destroyer, free_user_ns_work);
16082         schedule_work(&ns->destroyer);
16083  }
16084 diff -NurpP --minimal linux-2.6.35.4/kernel/utsname.c linux-2.6.35.4-vs2.3.0.36.32/kernel/utsname.c
16085 --- linux-2.6.35.4/kernel/utsname.c     2009-09-10 15:26:28.000000000 +0200
16086 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/utsname.c       2010-08-02 17:05:06.000000000 +0200
16087 @@ -14,14 +14,17 @@
16088  #include <linux/utsname.h>
16089  #include <linux/err.h>
16090  #include <linux/slab.h>
16091 +#include <linux/vserver/global.h>
16092  
16093  static struct uts_namespace *create_uts_ns(void)
16094  {
16095         struct uts_namespace *uts_ns;
16096  
16097         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
16098 -       if (uts_ns)
16099 +       if (uts_ns) {
16100                 kref_init(&uts_ns->kref);
16101 +               atomic_inc(&vs_global_uts_ns);
16102 +       }
16103         return uts_ns;
16104  }
16105  
16106 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
16107         struct uts_namespace *ns;
16108  
16109         ns = container_of(kref, struct uts_namespace, kref);
16110 +       atomic_dec(&vs_global_uts_ns);
16111         kfree(ns);
16112  }
16113 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/cacct.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cacct.c
16114 --- linux-2.6.35.4/kernel/vserver/cacct.c       1970-01-01 01:00:00.000000000 +0100
16115 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cacct.c 2010-08-02 17:05:06.000000000 +0200
16116 @@ -0,0 +1,42 @@
16117 +/*
16118 + *  linux/kernel/vserver/cacct.c
16119 + *
16120 + *  Virtual Server: Context Accounting
16121 + *
16122 + *  Copyright (C) 2006-2007 Herbert Pötzl
16123 + *
16124 + *  V0.01  added accounting stats
16125 + *
16126 + */
16127 +
16128 +#include <linux/types.h>
16129 +#include <linux/vs_context.h>
16130 +#include <linux/vserver/cacct_cmd.h>
16131 +#include <linux/vserver/cacct_int.h>
16132 +
16133 +#include <asm/errno.h>
16134 +#include <asm/uaccess.h>
16135 +
16136 +
16137 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16138 +{
16139 +       struct vcmd_sock_stat_v0 vc_data;
16140 +       int j, field;
16141 +
16142 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16143 +               return -EFAULT;
16144 +
16145 +       field = vc_data.field;
16146 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16147 +               return -EINVAL;
16148 +
16149 +       for (j = 0; j < 3; j++) {
16150 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16151 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16152 +       }
16153 +
16154 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16155 +               return -EFAULT;
16156 +       return 0;
16157 +}
16158 +
16159 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/cacct_init.h linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cacct_init.h
16160 --- linux-2.6.35.4/kernel/vserver/cacct_init.h  1970-01-01 01:00:00.000000000 +0100
16161 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cacct_init.h    2010-08-02 17:05:06.000000000 +0200
16162 @@ -0,0 +1,25 @@
16163 +
16164 +
16165 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16166 +{
16167 +       int i, j;
16168 +
16169 +
16170 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16171 +               for (j = 0; j < 3; j++) {
16172 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16173 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16174 +               }
16175 +       }
16176 +       for (i = 0; i < 8; i++)
16177 +               atomic_set(&cacct->slab[i], 0);
16178 +       for (i = 0; i < 5; i++)
16179 +               for (j = 0; j < 4; j++)
16180 +                       atomic_set(&cacct->page[i][j], 0);
16181 +}
16182 +
16183 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16184 +{
16185 +       return;
16186 +}
16187 +
16188 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/cacct_proc.h linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cacct_proc.h
16189 --- linux-2.6.35.4/kernel/vserver/cacct_proc.h  1970-01-01 01:00:00.000000000 +0100
16190 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cacct_proc.h    2010-08-02 17:05:06.000000000 +0200
16191 @@ -0,0 +1,53 @@
16192 +#ifndef _VX_CACCT_PROC_H
16193 +#define _VX_CACCT_PROC_H
16194 +
16195 +#include <linux/vserver/cacct_int.h>
16196 +
16197 +
16198 +#define VX_SOCKA_TOP   \
16199 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16200 +
16201 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16202 +{
16203 +       int i, j, length = 0;
16204 +       static char *type[VXA_SOCK_SIZE] = {
16205 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16206 +       };
16207 +
16208 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16209 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16210 +               length += sprintf(buffer + length, "%s:", type[i]);
16211 +               for (j = 0; j < 3; j++) {
16212 +                       length += sprintf(buffer + length,
16213 +                               "\t%10lu/%-10lu",
16214 +                               vx_sock_count(cacct, i, j),
16215 +                               vx_sock_total(cacct, i, j));
16216 +               }
16217 +               buffer[length++] = '\n';
16218 +       }
16219 +
16220 +       length += sprintf(buffer + length, "\n");
16221 +       length += sprintf(buffer + length,
16222 +               "slab:\t %8u %8u %8u %8u\n",
16223 +               atomic_read(&cacct->slab[1]),
16224 +               atomic_read(&cacct->slab[4]),
16225 +               atomic_read(&cacct->slab[0]),
16226 +               atomic_read(&cacct->slab[2]));
16227 +
16228 +       length += sprintf(buffer + length, "\n");
16229 +       for (i = 0; i < 5; i++) {
16230 +               length += sprintf(buffer + length,
16231 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16232 +                       atomic_read(&cacct->page[i][0]),
16233 +                       atomic_read(&cacct->page[i][1]),
16234 +                       atomic_read(&cacct->page[i][2]),
16235 +                       atomic_read(&cacct->page[i][3]),
16236 +                       atomic_read(&cacct->page[i][4]),
16237 +                       atomic_read(&cacct->page[i][5]),
16238 +                       atomic_read(&cacct->page[i][6]),
16239 +                       atomic_read(&cacct->page[i][7]));
16240 +       }
16241 +       return length;
16242 +}
16243 +
16244 +#endif /* _VX_CACCT_PROC_H */
16245 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/context.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/context.c
16246 --- linux-2.6.35.4/kernel/vserver/context.c     1970-01-01 01:00:00.000000000 +0100
16247 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/context.c       2010-08-02 17:05:06.000000000 +0200
16248 @@ -0,0 +1,1058 @@
16249 +/*
16250 + *  linux/kernel/vserver/context.c
16251 + *
16252 + *  Virtual Server: Context Support
16253 + *
16254 + *  Copyright (C) 2003-2007  Herbert Pötzl
16255 + *
16256 + *  V0.01  context helper
16257 + *  V0.02  vx_ctx_kill syscall command
16258 + *  V0.03  replaced context_info calls
16259 + *  V0.04  redesign of struct (de)alloc
16260 + *  V0.05  rlimit basic implementation
16261 + *  V0.06  task_xid and info commands
16262 + *  V0.07  context flags and caps
16263 + *  V0.08  switch to RCU based hash
16264 + *  V0.09  revert to non RCU for now
16265 + *  V0.10  and back to working RCU hash
16266 + *  V0.11  and back to locking again
16267 + *  V0.12  referenced context store
16268 + *  V0.13  separate per cpu data
16269 + *  V0.14  changed vcmds to vxi arg
16270 + *  V0.15  added context stat
16271 + *  V0.16  have __create claim() the vxi
16272 + *  V0.17  removed older and legacy stuff
16273 + *
16274 + */
16275 +
16276 +#include <linux/slab.h>
16277 +#include <linux/types.h>
16278 +#include <linux/security.h>
16279 +#include <linux/pid_namespace.h>
16280 +
16281 +#include <linux/vserver/context.h>
16282 +#include <linux/vserver/network.h>
16283 +#include <linux/vserver/debug.h>
16284 +#include <linux/vserver/limit.h>
16285 +#include <linux/vserver/limit_int.h>
16286 +#include <linux/vserver/space.h>
16287 +#include <linux/init_task.h>
16288 +#include <linux/fs_struct.h>
16289 +
16290 +#include <linux/vs_context.h>
16291 +#include <linux/vs_limit.h>
16292 +#include <linux/vs_pid.h>
16293 +#include <linux/vserver/context_cmd.h>
16294 +
16295 +#include "cvirt_init.h"
16296 +#include "cacct_init.h"
16297 +#include "limit_init.h"
16298 +#include "sched_init.h"
16299 +
16300 +
16301 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16302 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16303 +
16304 +
16305 +/*     now inactive context structures */
16306 +
16307 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16308 +
16309 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
16310 +
16311 +
16312 +/*     __alloc_vx_info()
16313 +
16314 +       * allocate an initialized vx_info struct
16315 +       * doesn't make it visible (hash)                        */
16316 +
16317 +static struct vx_info *__alloc_vx_info(xid_t xid)
16318 +{
16319 +       struct vx_info *new = NULL;
16320 +       int cpu, index;
16321 +
16322 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16323 +
16324 +       /* would this benefit from a slab cache? */
16325 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16326 +       if (!new)
16327 +               return 0;
16328 +
16329 +       memset(new, 0, sizeof(struct vx_info));
16330 +#ifdef CONFIG_SMP
16331 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16332 +       if (!new->ptr_pc)
16333 +               goto error;
16334 +#endif
16335 +       new->vx_id = xid;
16336 +       INIT_HLIST_NODE(&new->vx_hlist);
16337 +       atomic_set(&new->vx_usecnt, 0);
16338 +       atomic_set(&new->vx_tasks, 0);
16339 +       new->vx_parent = NULL;
16340 +       new->vx_state = 0;
16341 +       init_waitqueue_head(&new->vx_wait);
16342 +
16343 +       /* prepare reaper */
16344 +       get_task_struct(init_pid_ns.child_reaper);
16345 +       new->vx_reaper = init_pid_ns.child_reaper;
16346 +       new->vx_badness_bias = 0;
16347 +
16348 +       /* rest of init goes here */
16349 +       vx_info_init_limit(&new->limit);
16350 +       vx_info_init_sched(&new->sched);
16351 +       vx_info_init_cvirt(&new->cvirt);
16352 +       vx_info_init_cacct(&new->cacct);
16353 +
16354 +       /* per cpu data structures */
16355 +       for_each_possible_cpu(cpu) {
16356 +               vx_info_init_sched_pc(
16357 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16358 +               vx_info_init_cvirt_pc(
16359 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16360 +       }
16361 +
16362 +       new->vx_flags = VXF_INIT_SET;
16363 +       cap_set_init_eff(new->vx_bcaps);
16364 +       new->vx_ccaps = 0;
16365 +       new->vx_umask = 0;
16366 +
16367 +       new->reboot_cmd = 0;
16368 +       new->exit_code = 0;
16369 +
16370 +       // preconfig fs entries
16371 +       for (index = 0; index < VX_SPACES; index++) {
16372 +               write_lock(&init_fs.lock);
16373 +               init_fs.users++;
16374 +               write_unlock(&init_fs.lock);
16375 +               new->vx_fs[index] = &init_fs;
16376 +       }
16377 +
16378 +       vxdprintk(VXD_CBIT(xid, 0),
16379 +               "alloc_vx_info(%d) = %p", xid, new);
16380 +       vxh_alloc_vx_info(new);
16381 +       atomic_inc(&vx_global_ctotal);
16382 +       return new;
16383 +#ifdef CONFIG_SMP
16384 +error:
16385 +       kfree(new);
16386 +       return 0;
16387 +#endif
16388 +}
16389 +
16390 +/*     __dealloc_vx_info()
16391 +
16392 +       * final disposal of vx_info                             */
16393 +
16394 +static void __dealloc_vx_info(struct vx_info *vxi)
16395 +{
16396 +#ifdef CONFIG_VSERVER_WARN
16397 +       struct vx_info_save vxis;
16398 +       int cpu;
16399 +#endif
16400 +       vxdprintk(VXD_CBIT(xid, 0),
16401 +               "dealloc_vx_info(%p)", vxi);
16402 +       vxh_dealloc_vx_info(vxi);
16403 +
16404 +#ifdef CONFIG_VSERVER_WARN
16405 +       enter_vx_info(vxi, &vxis);
16406 +       vx_info_exit_limit(&vxi->limit);
16407 +       vx_info_exit_sched(&vxi->sched);
16408 +       vx_info_exit_cvirt(&vxi->cvirt);
16409 +       vx_info_exit_cacct(&vxi->cacct);
16410 +
16411 +       for_each_possible_cpu(cpu) {
16412 +               vx_info_exit_sched_pc(
16413 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16414 +               vx_info_exit_cvirt_pc(
16415 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16416 +       }
16417 +       leave_vx_info(&vxis);
16418 +#endif
16419 +
16420 +       vxi->vx_id = -1;
16421 +       vxi->vx_state |= VXS_RELEASED;
16422 +
16423 +#ifdef CONFIG_SMP
16424 +       free_percpu(vxi->ptr_pc);
16425 +#endif
16426 +       kfree(vxi);
16427 +       atomic_dec(&vx_global_ctotal);
16428 +}
16429 +
16430 +static void __shutdown_vx_info(struct vx_info *vxi)
16431 +{
16432 +       struct nsproxy *nsproxy;
16433 +       struct fs_struct *fs;
16434 +       int index, kill;
16435 +
16436 +       might_sleep();
16437 +
16438 +       vxi->vx_state |= VXS_SHUTDOWN;
16439 +       vs_state_change(vxi, VSC_SHUTDOWN);
16440 +
16441 +       for (index = 0; index < VX_SPACES; index++) {
16442 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
16443 +               if (nsproxy)
16444 +                       put_nsproxy(nsproxy);
16445 +
16446 +               fs = xchg(&vxi->vx_fs[index], NULL);
16447 +               write_lock(&fs->lock);
16448 +               kill = !--fs->users;
16449 +               write_unlock(&fs->lock);
16450 +               if (kill)
16451 +                       free_fs_struct(fs);
16452 +       }
16453 +}
16454 +
16455 +/* exported stuff */
16456 +
16457 +void free_vx_info(struct vx_info *vxi)
16458 +{
16459 +       unsigned long flags;
16460 +       unsigned index;
16461 +
16462 +       /* check for reference counts first */
16463 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16464 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16465 +
16466 +       /* context must not be hashed */
16467 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16468 +
16469 +       /* context shutdown is mandatory */
16470 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16471 +
16472 +       /* nsproxy and fs check */
16473 +       for (index = 0; index < VX_SPACES; index++) {
16474 +               BUG_ON(vxi->vx_nsproxy[index]);
16475 +               BUG_ON(vxi->vx_fs[index]);
16476 +       }
16477 +
16478 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16479 +       hlist_del(&vxi->vx_hlist);
16480 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16481 +
16482 +       __dealloc_vx_info(vxi);
16483 +}
16484 +
16485 +
16486 +/*     hash table for vx_info hash */
16487 +
16488 +#define VX_HASH_SIZE   13
16489 +
16490 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16491 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16492 +
16493 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
16494 +
16495 +
16496 +static inline unsigned int __hashval(xid_t xid)
16497 +{
16498 +       return (xid % VX_HASH_SIZE);
16499 +}
16500 +
16501 +
16502 +
16503 +/*     __hash_vx_info()
16504 +
16505 +       * add the vxi to the global hash table
16506 +       * requires the hash_lock to be held                     */
16507 +
16508 +static inline void __hash_vx_info(struct vx_info *vxi)
16509 +{
16510 +       struct hlist_head *head;
16511 +
16512 +       vxd_assert_lock(&vx_info_hash_lock);
16513 +       vxdprintk(VXD_CBIT(xid, 4),
16514 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16515 +       vxh_hash_vx_info(vxi);
16516 +
16517 +       /* context must not be hashed */
16518 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16519 +
16520 +       vxi->vx_state |= VXS_HASHED;
16521 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16522 +       hlist_add_head(&vxi->vx_hlist, head);
16523 +       atomic_inc(&vx_global_cactive);
16524 +}
16525 +
16526 +/*     __unhash_vx_info()
16527 +
16528 +       * remove the vxi from the global hash table
16529 +       * requires the hash_lock to be held                     */
16530 +
16531 +static inline void __unhash_vx_info(struct vx_info *vxi)
16532 +{
16533 +       unsigned long flags;
16534 +
16535 +       vxd_assert_lock(&vx_info_hash_lock);
16536 +       vxdprintk(VXD_CBIT(xid, 4),
16537 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16538 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16539 +       vxh_unhash_vx_info(vxi);
16540 +
16541 +       /* context must be hashed */
16542 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16543 +       /* but without tasks */
16544 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16545 +
16546 +       vxi->vx_state &= ~VXS_HASHED;
16547 +       hlist_del_init(&vxi->vx_hlist);
16548 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16549 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16550 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16551 +       atomic_dec(&vx_global_cactive);
16552 +}
16553 +
16554 +
16555 +/*     __lookup_vx_info()
16556 +
16557 +       * requires the hash_lock to be held
16558 +       * doesn't increment the vx_refcnt                       */
16559 +
16560 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16561 +{
16562 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16563 +       struct hlist_node *pos;
16564 +       struct vx_info *vxi;
16565 +
16566 +       vxd_assert_lock(&vx_info_hash_lock);
16567 +       hlist_for_each(pos, head) {
16568 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16569 +
16570 +               if (vxi->vx_id == xid)
16571 +                       goto found;
16572 +       }
16573 +       vxi = NULL;
16574 +found:
16575 +       vxdprintk(VXD_CBIT(xid, 0),
16576 +               "__lookup_vx_info(#%u): %p[#%u]",
16577 +               xid, vxi, vxi ? vxi->vx_id : 0);
16578 +       vxh_lookup_vx_info(vxi, xid);
16579 +       return vxi;
16580 +}
16581 +
16582 +
16583 +/*     __create_vx_info()
16584 +
16585 +       * create the requested context
16586 +       * get(), claim() and hash it                            */
16587 +
16588 +static struct vx_info *__create_vx_info(int id)
16589 +{
16590 +       struct vx_info *new, *vxi = NULL;
16591 +
16592 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16593 +
16594 +       if (!(new = __alloc_vx_info(id)))
16595 +               return ERR_PTR(-ENOMEM);
16596 +
16597 +       /* required to make dynamic xids unique */
16598 +       spin_lock(&vx_info_hash_lock);
16599 +
16600 +       /* static context requested */
16601 +       if ((vxi = __lookup_vx_info(id))) {
16602 +               vxdprintk(VXD_CBIT(xid, 0),
16603 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16604 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16605 +                       vxi = ERR_PTR(-EBUSY);
16606 +               else
16607 +                       vxi = ERR_PTR(-EEXIST);
16608 +               goto out_unlock;
16609 +       }
16610 +       /* new context */
16611 +       vxdprintk(VXD_CBIT(xid, 0),
16612 +               "create_vx_info(%d) = %p (new)", id, new);
16613 +       claim_vx_info(new, NULL);
16614 +       __hash_vx_info(get_vx_info(new));
16615 +       vxi = new, new = NULL;
16616 +
16617 +out_unlock:
16618 +       spin_unlock(&vx_info_hash_lock);
16619 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16620 +       if (new)
16621 +               __dealloc_vx_info(new);
16622 +       return vxi;
16623 +}
16624 +
16625 +
16626 +/*     exported stuff                                          */
16627 +
16628 +
16629 +void unhash_vx_info(struct vx_info *vxi)
16630 +{
16631 +       __shutdown_vx_info(vxi);
16632 +       spin_lock(&vx_info_hash_lock);
16633 +       __unhash_vx_info(vxi);
16634 +       spin_unlock(&vx_info_hash_lock);
16635 +       __wakeup_vx_info(vxi);
16636 +}
16637 +
16638 +
16639 +/*     lookup_vx_info()
16640 +
16641 +       * search for a vx_info and get() it
16642 +       * negative id means current                             */
16643 +
16644 +struct vx_info *lookup_vx_info(int id)
16645 +{
16646 +       struct vx_info *vxi = NULL;
16647 +
16648 +       if (id < 0) {
16649 +               vxi = get_vx_info(current_vx_info());
16650 +       } else if (id > 1) {
16651 +               spin_lock(&vx_info_hash_lock);
16652 +               vxi = get_vx_info(__lookup_vx_info(id));
16653 +               spin_unlock(&vx_info_hash_lock);
16654 +       }
16655 +       return vxi;
16656 +}
16657 +
16658 +/*     xid_is_hashed()
16659 +
16660 +       * verify that xid is still hashed                       */
16661 +
16662 +int xid_is_hashed(xid_t xid)
16663 +{
16664 +       int hashed;
16665 +
16666 +       spin_lock(&vx_info_hash_lock);
16667 +       hashed = (__lookup_vx_info(xid) != NULL);
16668 +       spin_unlock(&vx_info_hash_lock);
16669 +       return hashed;
16670 +}
16671 +
16672 +#ifdef CONFIG_PROC_FS
16673 +
16674 +/*     get_xid_list()
16675 +
16676 +       * get a subset of hashed xids for proc
16677 +       * assumes size is at least one                          */
16678 +
16679 +int get_xid_list(int index, unsigned int *xids, int size)
16680 +{
16681 +       int hindex, nr_xids = 0;
16682 +
16683 +       /* only show current and children */
16684 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16685 +               if (index > 0)
16686 +                       return 0;
16687 +               xids[nr_xids] = vx_current_xid();
16688 +               return 1;
16689 +       }
16690 +
16691 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16692 +               struct hlist_head *head = &vx_info_hash[hindex];
16693 +               struct hlist_node *pos;
16694 +
16695 +               spin_lock(&vx_info_hash_lock);
16696 +               hlist_for_each(pos, head) {
16697 +                       struct vx_info *vxi;
16698 +
16699 +                       if (--index > 0)
16700 +                               continue;
16701 +
16702 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16703 +                       xids[nr_xids] = vxi->vx_id;
16704 +                       if (++nr_xids >= size) {
16705 +                               spin_unlock(&vx_info_hash_lock);
16706 +                               goto out;
16707 +                       }
16708 +               }
16709 +               /* keep the lock time short */
16710 +               spin_unlock(&vx_info_hash_lock);
16711 +       }
16712 +out:
16713 +       return nr_xids;
16714 +}
16715 +#endif
16716 +
16717 +#ifdef CONFIG_VSERVER_DEBUG
16718 +
16719 +void   dump_vx_info_inactive(int level)
16720 +{
16721 +       struct hlist_node *entry, *next;
16722 +
16723 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16724 +               struct vx_info *vxi =
16725 +                       list_entry(entry, struct vx_info, vx_hlist);
16726 +
16727 +               dump_vx_info(vxi, level);
16728 +       }
16729 +}
16730 +
16731 +#endif
16732 +
16733 +#if 0
16734 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16735 +{
16736 +       struct user_struct *new_user, *old_user;
16737 +
16738 +       if (!p || !vxi)
16739 +               BUG();
16740 +
16741 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16742 +               return -EACCES;
16743 +
16744 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16745 +       if (!new_user)
16746 +               return -ENOMEM;
16747 +
16748 +       old_user = p->user;
16749 +       if (new_user != old_user) {
16750 +               atomic_inc(&new_user->processes);
16751 +               atomic_dec(&old_user->processes);
16752 +               p->user = new_user;
16753 +       }
16754 +       free_uid(old_user);
16755 +       return 0;
16756 +}
16757 +#endif
16758 +
16759 +#if 0
16760 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16761 +{
16762 +       // p->cap_effective &= vxi->vx_cap_bset;
16763 +       p->cap_effective =
16764 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16765 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16766 +       p->cap_inheritable =
16767 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16768 +       // p->cap_permitted &= vxi->vx_cap_bset;
16769 +       p->cap_permitted =
16770 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16771 +}
16772 +#endif
16773 +
16774 +
16775 +#include <linux/file.h>
16776 +#include <linux/fdtable.h>
16777 +
16778 +static int vx_openfd_task(struct task_struct *tsk)
16779 +{
16780 +       struct files_struct *files = tsk->files;
16781 +       struct fdtable *fdt;
16782 +       const unsigned long *bptr;
16783 +       int count, total;
16784 +
16785 +       /* no rcu_read_lock() because of spin_lock() */
16786 +       spin_lock(&files->file_lock);
16787 +       fdt = files_fdtable(files);
16788 +       bptr = fdt->open_fds->fds_bits;
16789 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16790 +       for (total = 0; count > 0; count--) {
16791 +               if (*bptr)
16792 +                       total += hweight_long(*bptr);
16793 +               bptr++;
16794 +       }
16795 +       spin_unlock(&files->file_lock);
16796 +       return total;
16797 +}
16798 +
16799 +
16800 +/*     for *space compatibility */
16801 +
16802 +asmlinkage long sys_unshare(unsigned long);
16803 +
16804 +/*
16805 + *     migrate task to new context
16806 + *     gets vxi, puts old_vxi on change
16807 + *     optionally unshares namespaces (hack)
16808 + */
16809 +
16810 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16811 +{
16812 +       struct vx_info *old_vxi;
16813 +       int ret = 0;
16814 +
16815 +       if (!p || !vxi)
16816 +               BUG();
16817 +
16818 +       vxdprintk(VXD_CBIT(xid, 5),
16819 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16820 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16821 +
16822 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16823 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16824 +               return -EACCES;
16825 +
16826 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16827 +               return -EFAULT;
16828 +
16829 +       old_vxi = task_get_vx_info(p);
16830 +       if (old_vxi == vxi)
16831 +               goto out;
16832 +
16833 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16834 +       {
16835 +               int openfd;
16836 +
16837 +               task_lock(p);
16838 +               openfd = vx_openfd_task(p);
16839 +
16840 +               if (old_vxi) {
16841 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16842 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16843 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16844 +                       /* FIXME: what about the struct files here? */
16845 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16846 +                       /* account for the executable */
16847 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16848 +               }
16849 +               atomic_inc(&vxi->cvirt.nr_threads);
16850 +               atomic_inc(&vxi->cvirt.nr_running);
16851 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16852 +               /* FIXME: what about the struct files here? */
16853 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16854 +               /* account for the executable */
16855 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16856 +
16857 +               if (old_vxi) {
16858 +                       release_vx_info(old_vxi, p);
16859 +                       clr_vx_info(&p->vx_info);
16860 +               }
16861 +               claim_vx_info(vxi, p);
16862 +               set_vx_info(&p->vx_info, vxi);
16863 +               p->xid = vxi->vx_id;
16864 +
16865 +               vxdprintk(VXD_CBIT(xid, 5),
16866 +                       "moved task %p into vxi:%p[#%d]",
16867 +                       p, vxi, vxi->vx_id);
16868 +
16869 +               // vx_mask_cap_bset(vxi, p);
16870 +               task_unlock(p);
16871 +
16872 +               /* hack for *spaces to provide compatibility */
16873 +               if (unshare) {
16874 +                       struct nsproxy *old_nsp, *new_nsp;
16875 +
16876 +                       ret = unshare_nsproxy_namespaces(
16877 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16878 +                               &new_nsp, NULL);
16879 +                       if (ret)
16880 +                               goto out;
16881 +
16882 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16883 +                       vx_set_space(vxi,
16884 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16885 +                       put_nsproxy(old_nsp);
16886 +               }
16887 +       }
16888 +out:
16889 +       put_vx_info(old_vxi);
16890 +       return ret;
16891 +}
16892 +
16893 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16894 +{
16895 +       struct task_struct *old_reaper;
16896 +
16897 +       if (!vxi)
16898 +               return -EINVAL;
16899 +
16900 +       vxdprintk(VXD_CBIT(xid, 6),
16901 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16902 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16903 +
16904 +       old_reaper = vxi->vx_reaper;
16905 +       if (old_reaper == p)
16906 +               return 0;
16907 +
16908 +       /* set new child reaper */
16909 +       get_task_struct(p);
16910 +       vxi->vx_reaper = p;
16911 +       put_task_struct(old_reaper);
16912 +       return 0;
16913 +}
16914 +
16915 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16916 +{
16917 +       if (!vxi)
16918 +               return -EINVAL;
16919 +
16920 +       vxdprintk(VXD_CBIT(xid, 6),
16921 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16922 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16923 +
16924 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16925 +       // vxi->vx_initpid = p->tgid;
16926 +       vxi->vx_initpid = p->pid;
16927 +       return 0;
16928 +}
16929 +
16930 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16931 +{
16932 +       vxdprintk(VXD_CBIT(xid, 6),
16933 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16934 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16935 +
16936 +       vxi->exit_code = code;
16937 +       vxi->vx_initpid = 0;
16938 +}
16939 +
16940 +
16941 +void vx_set_persistent(struct vx_info *vxi)
16942 +{
16943 +       vxdprintk(VXD_CBIT(xid, 6),
16944 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16945 +
16946 +       get_vx_info(vxi);
16947 +       claim_vx_info(vxi, NULL);
16948 +}
16949 +
16950 +void vx_clear_persistent(struct vx_info *vxi)
16951 +{
16952 +       vxdprintk(VXD_CBIT(xid, 6),
16953 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16954 +
16955 +       release_vx_info(vxi, NULL);
16956 +       put_vx_info(vxi);
16957 +}
16958 +
16959 +void vx_update_persistent(struct vx_info *vxi)
16960 +{
16961 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16962 +               vx_set_persistent(vxi);
16963 +       else
16964 +               vx_clear_persistent(vxi);
16965 +}
16966 +
16967 +
16968 +/*     task must be current or locked          */
16969 +
16970 +void   exit_vx_info(struct task_struct *p, int code)
16971 +{
16972 +       struct vx_info *vxi = p->vx_info;
16973 +
16974 +       if (vxi) {
16975 +               atomic_dec(&vxi->cvirt.nr_threads);
16976 +               vx_nproc_dec(p);
16977 +
16978 +               vxi->exit_code = code;
16979 +               release_vx_info(vxi, p);
16980 +       }
16981 +}
16982 +
16983 +void   exit_vx_info_early(struct task_struct *p, int code)
16984 +{
16985 +       struct vx_info *vxi = p->vx_info;
16986 +
16987 +       if (vxi) {
16988 +               if (vxi->vx_initpid == p->pid)
16989 +                       vx_exit_init(vxi, p, code);
16990 +               if (vxi->vx_reaper == p)
16991 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16992 +       }
16993 +}
16994 +
16995 +
16996 +/* vserver syscall commands below here */
16997 +
16998 +/* taks xid and vx_info functions */
16999 +
17000 +#include <asm/uaccess.h>
17001 +
17002 +
17003 +int vc_task_xid(uint32_t id)
17004 +{
17005 +       xid_t xid;
17006 +
17007 +       if (id) {
17008 +               struct task_struct *tsk;
17009 +
17010 +               read_lock(&tasklist_lock);
17011 +               tsk = find_task_by_real_pid(id);
17012 +               xid = (tsk) ? tsk->xid : -ESRCH;
17013 +               read_unlock(&tasklist_lock);
17014 +       } else
17015 +               xid = vx_current_xid();
17016 +       return xid;
17017 +}
17018 +
17019 +
17020 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17021 +{
17022 +       struct vcmd_vx_info_v0 vc_data;
17023 +
17024 +       vc_data.xid = vxi->vx_id;
17025 +       vc_data.initpid = vxi->vx_initpid;
17026 +
17027 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17028 +               return -EFAULT;
17029 +       return 0;
17030 +}
17031 +
17032 +
17033 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17034 +{
17035 +       struct vcmd_ctx_stat_v0 vc_data;
17036 +
17037 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17038 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17039 +
17040 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17041 +               return -EFAULT;
17042 +       return 0;
17043 +}
17044 +
17045 +
17046 +/* context functions */
17047 +
17048 +int vc_ctx_create(uint32_t xid, void __user *data)
17049 +{
17050 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17051 +       struct vx_info *new_vxi;
17052 +       int ret;
17053 +
17054 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17055 +               return -EFAULT;
17056 +
17057 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
17058 +               return -EINVAL;
17059 +
17060 +       new_vxi = __create_vx_info(xid);
17061 +       if (IS_ERR(new_vxi))
17062 +               return PTR_ERR(new_vxi);
17063 +
17064 +       /* initial flags */
17065 +       new_vxi->vx_flags = vc_data.flagword;
17066 +
17067 +       ret = -ENOEXEC;
17068 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17069 +               goto out;
17070 +
17071 +       ret = vx_migrate_task(current, new_vxi, (!data));
17072 +       if (ret)
17073 +               goto out;
17074 +
17075 +       /* return context id on success */
17076 +       ret = new_vxi->vx_id;
17077 +
17078 +       /* get a reference for persistent contexts */
17079 +       if ((vc_data.flagword & VXF_PERSISTENT))
17080 +               vx_set_persistent(new_vxi);
17081 +out:
17082 +       release_vx_info(new_vxi, NULL);
17083 +       put_vx_info(new_vxi);
17084 +       return ret;
17085 +}
17086 +
17087 +
17088 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17089 +{
17090 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17091 +       int ret;
17092 +
17093 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17094 +               return -EFAULT;
17095 +
17096 +       ret = vx_migrate_task(current, vxi, 0);
17097 +       if (ret)
17098 +               return ret;
17099 +       if (vc_data.flagword & VXM_SET_INIT)
17100 +               ret = vx_set_init(vxi, current);
17101 +       if (ret)
17102 +               return ret;
17103 +       if (vc_data.flagword & VXM_SET_REAPER)
17104 +               ret = vx_set_reaper(vxi, current);
17105 +       return ret;
17106 +}
17107 +
17108 +
17109 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17110 +{
17111 +       struct vcmd_ctx_flags_v0 vc_data;
17112 +
17113 +       vc_data.flagword = vxi->vx_flags;
17114 +
17115 +       /* special STATE flag handling */
17116 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17117 +
17118 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17119 +               return -EFAULT;
17120 +       return 0;
17121 +}
17122 +
17123 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17124 +{
17125 +       struct vcmd_ctx_flags_v0 vc_data;
17126 +       uint64_t mask, trigger;
17127 +
17128 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17129 +               return -EFAULT;
17130 +
17131 +       /* special STATE flag handling */
17132 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17133 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17134 +
17135 +       if (vxi == current_vx_info()) {
17136 +               /* if (trigger & VXF_STATE_SETUP)
17137 +                       vx_mask_cap_bset(vxi, current); */
17138 +               if (trigger & VXF_STATE_INIT) {
17139 +                       int ret;
17140 +
17141 +                       ret = vx_set_init(vxi, current);
17142 +                       if (ret)
17143 +                               return ret;
17144 +                       ret = vx_set_reaper(vxi, current);
17145 +                       if (ret)
17146 +                               return ret;
17147 +               }
17148 +       }
17149 +
17150 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17151 +               vc_data.flagword, mask);
17152 +       if (trigger & VXF_PERSISTENT)
17153 +               vx_update_persistent(vxi);
17154 +
17155 +       return 0;
17156 +}
17157 +
17158 +
17159 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17160 +{
17161 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17162 +
17163 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17164 +       return v;
17165 +}
17166 +
17167 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17168 +{
17169 +       kernel_cap_t c = __cap_empty_set;
17170 +
17171 +       c.cap[0] = v & 0xFFFFFFFF;
17172 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17173 +
17174 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17175 +       return c;
17176 +}
17177 +
17178 +
17179 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17180 +{
17181 +       if (bcaps)
17182 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17183 +       if (ccaps)
17184 +               *ccaps = vxi->vx_ccaps;
17185 +
17186 +       return 0;
17187 +}
17188 +
17189 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17190 +{
17191 +       struct vcmd_ctx_caps_v1 vc_data;
17192 +       int ret;
17193 +
17194 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17195 +       if (ret)
17196 +               return ret;
17197 +       vc_data.cmask = ~0ULL;
17198 +
17199 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17200 +               return -EFAULT;
17201 +       return 0;
17202 +}
17203 +
17204 +static int do_set_caps(struct vx_info *vxi,
17205 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17206 +{
17207 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17208 +
17209 +#if 0
17210 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17211 +               bcaps, bmask, ccaps, cmask);
17212 +#endif
17213 +       vxi->vx_bcaps = cap_t_from_caps(
17214 +               vs_mask_flags(bcold, bcaps, bmask));
17215 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17216 +
17217 +       return 0;
17218 +}
17219 +
17220 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17221 +{
17222 +       struct vcmd_ctx_caps_v1 vc_data;
17223 +
17224 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17225 +               return -EFAULT;
17226 +
17227 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17228 +}
17229 +
17230 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17231 +{
17232 +       struct vcmd_bcaps vc_data;
17233 +       int ret;
17234 +
17235 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17236 +       if (ret)
17237 +               return ret;
17238 +       vc_data.bmask = ~0ULL;
17239 +
17240 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17241 +               return -EFAULT;
17242 +       return 0;
17243 +}
17244 +
17245 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17246 +{
17247 +       struct vcmd_bcaps vc_data;
17248 +
17249 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17250 +               return -EFAULT;
17251 +
17252 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17253 +}
17254 +
17255 +
17256 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17257 +{
17258 +       struct vcmd_umask vc_data;
17259 +
17260 +       vc_data.umask = vxi->vx_umask;
17261 +       vc_data.mask = ~0ULL;
17262 +
17263 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17264 +               return -EFAULT;
17265 +       return 0;
17266 +}
17267 +
17268 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17269 +{
17270 +       struct vcmd_umask vc_data;
17271 +
17272 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17273 +               return -EFAULT;
17274 +
17275 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17276 +               vc_data.umask, vc_data.mask);
17277 +       return 0;
17278 +}
17279 +
17280 +
17281 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17282 +{
17283 +       struct vcmd_badness_v0 vc_data;
17284 +
17285 +       vc_data.bias = vxi->vx_badness_bias;
17286 +
17287 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17288 +               return -EFAULT;
17289 +       return 0;
17290 +}
17291 +
17292 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17293 +{
17294 +       struct vcmd_badness_v0 vc_data;
17295 +
17296 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17297 +               return -EFAULT;
17298 +
17299 +       vxi->vx_badness_bias = vc_data.bias;
17300 +       return 0;
17301 +}
17302 +
17303 +#include <linux/module.h>
17304 +
17305 +EXPORT_SYMBOL_GPL(free_vx_info);
17306 +
17307 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/cvirt.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cvirt.c
17308 --- linux-2.6.35.4/kernel/vserver/cvirt.c       1970-01-01 01:00:00.000000000 +0100
17309 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cvirt.c 2010-08-02 17:05:06.000000000 +0200
17310 @@ -0,0 +1,304 @@
17311 +/*
17312 + *  linux/kernel/vserver/cvirt.c
17313 + *
17314 + *  Virtual Server: Context Virtualization
17315 + *
17316 + *  Copyright (C) 2004-2007  Herbert Pötzl
17317 + *
17318 + *  V0.01  broken out from limit.c
17319 + *  V0.02  added utsname stuff
17320 + *  V0.03  changed vcmds to vxi arg
17321 + *
17322 + */
17323 +
17324 +#include <linux/types.h>
17325 +#include <linux/utsname.h>
17326 +#include <linux/vs_cvirt.h>
17327 +#include <linux/vserver/switch.h>
17328 +#include <linux/vserver/cvirt_cmd.h>
17329 +
17330 +#include <asm/uaccess.h>
17331 +
17332 +
17333 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17334 +{
17335 +       struct vx_info *vxi = current_vx_info();
17336 +
17337 +       set_normalized_timespec(uptime,
17338 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17339 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17340 +       if (!idle)
17341 +               return;
17342 +       set_normalized_timespec(idle,
17343 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17344 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17345 +       return;
17346 +}
17347 +
17348 +uint64_t vx_idle_jiffies(void)
17349 +{
17350 +       return init_task.utime + init_task.stime;
17351 +}
17352 +
17353 +
17354 +
17355 +static inline uint32_t __update_loadavg(uint32_t load,
17356 +       int wsize, int delta, int n)
17357 +{
17358 +       unsigned long long calc, prev;
17359 +
17360 +       /* just set it to n */
17361 +       if (unlikely(delta >= wsize))
17362 +               return (n << FSHIFT);
17363 +
17364 +       calc = delta * n;
17365 +       calc <<= FSHIFT;
17366 +       prev = (wsize - delta);
17367 +       prev *= load;
17368 +       calc += prev;
17369 +       do_div(calc, wsize);
17370 +       return calc;
17371 +}
17372 +
17373 +
17374 +void vx_update_load(struct vx_info *vxi)
17375 +{
17376 +       uint32_t now, last, delta;
17377 +       unsigned int nr_running, nr_uninterruptible;
17378 +       unsigned int total;
17379 +       unsigned long flags;
17380 +
17381 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17382 +
17383 +       now = jiffies;
17384 +       last = vxi->cvirt.load_last;
17385 +       delta = now - last;
17386 +
17387 +       if (delta < 5*HZ)
17388 +               goto out;
17389 +
17390 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17391 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17392 +       total = nr_running + nr_uninterruptible;
17393 +
17394 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17395 +               60*HZ, delta, total);
17396 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17397 +               5*60*HZ, delta, total);
17398 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17399 +               15*60*HZ, delta, total);
17400 +
17401 +       vxi->cvirt.load_last = now;
17402 +out:
17403 +       atomic_inc(&vxi->cvirt.load_updates);
17404 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17405 +}
17406 +
17407 +
17408 +/*
17409 + * Commands to do_syslog:
17410 + *
17411 + *      0 -- Close the log.  Currently a NOP.
17412 + *      1 -- Open the log. Currently a NOP.
17413 + *      2 -- Read from the log.
17414 + *      3 -- Read all messages remaining in the ring buffer.
17415 + *      4 -- Read and clear all messages remaining in the ring buffer
17416 + *      5 -- Clear ring buffer.
17417 + *      6 -- Disable printk's to console
17418 + *      7 -- Enable printk's to console
17419 + *      8 -- Set level of messages printed to console
17420 + *      9 -- Return number of unread characters in the log buffer
17421 + *     10 -- Return size of the log buffer
17422 + */
17423 +int vx_do_syslog(int type, char __user *buf, int len)
17424 +{
17425 +       int error = 0;
17426 +       int do_clear = 0;
17427 +       struct vx_info *vxi = current_vx_info();
17428 +       struct _vx_syslog *log;
17429 +
17430 +       if (!vxi)
17431 +               return -EINVAL;
17432 +       log = &vxi->cvirt.syslog;
17433 +
17434 +       switch (type) {
17435 +       case 0:         /* Close log */
17436 +       case 1:         /* Open log */
17437 +               break;
17438 +       case 2:         /* Read from log */
17439 +               error = wait_event_interruptible(log->log_wait,
17440 +                       (log->log_start - log->log_end));
17441 +               if (error)
17442 +                       break;
17443 +               spin_lock_irq(&log->logbuf_lock);
17444 +               spin_unlock_irq(&log->logbuf_lock);
17445 +               break;
17446 +       case 4:         /* Read/clear last kernel messages */
17447 +               do_clear = 1;
17448 +               /* fall through */
17449 +       case 3:         /* Read last kernel messages */
17450 +               return 0;
17451 +
17452 +       case 5:         /* Clear ring buffer */
17453 +               return 0;
17454 +
17455 +       case 6:         /* Disable logging to console */
17456 +       case 7:         /* Enable logging to console */
17457 +       case 8:         /* Set level of messages printed to console */
17458 +               break;
17459 +
17460 +       case 9:         /* Number of chars in the log buffer */
17461 +               return 0;
17462 +       case 10:        /* Size of the log buffer */
17463 +               return 0;
17464 +       default:
17465 +               error = -EINVAL;
17466 +               break;
17467 +       }
17468 +       return error;
17469 +}
17470 +
17471 +
17472 +/* virtual host info names */
17473 +
17474 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17475 +{
17476 +       struct nsproxy *nsproxy;
17477 +       struct uts_namespace *uts;
17478 +
17479 +       if (id == VHIN_CONTEXT)
17480 +               return vxi->vx_name;
17481 +
17482 +       nsproxy = vxi->vx_nsproxy[0];
17483 +       if (!nsproxy)
17484 +               return NULL;
17485 +
17486 +       uts = nsproxy->uts_ns;
17487 +       if (!uts)
17488 +               return NULL;
17489 +
17490 +       switch (id) {
17491 +       case VHIN_SYSNAME:
17492 +               return uts->name.sysname;
17493 +       case VHIN_NODENAME:
17494 +               return uts->name.nodename;
17495 +       case VHIN_RELEASE:
17496 +               return uts->name.release;
17497 +       case VHIN_VERSION:
17498 +               return uts->name.version;
17499 +       case VHIN_MACHINE:
17500 +               return uts->name.machine;
17501 +       case VHIN_DOMAINNAME:
17502 +               return uts->name.domainname;
17503 +       default:
17504 +               return NULL;
17505 +       }
17506 +       return NULL;
17507 +}
17508 +
17509 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17510 +{
17511 +       struct vcmd_vhi_name_v0 vc_data;
17512 +       char *name;
17513 +
17514 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17515 +               return -EFAULT;
17516 +
17517 +       name = vx_vhi_name(vxi, vc_data.field);
17518 +       if (!name)
17519 +               return -EINVAL;
17520 +
17521 +       memcpy(name, vc_data.name, 65);
17522 +       return 0;
17523 +}
17524 +
17525 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17526 +{
17527 +       struct vcmd_vhi_name_v0 vc_data;
17528 +       char *name;
17529 +
17530 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17531 +               return -EFAULT;
17532 +
17533 +       name = vx_vhi_name(vxi, vc_data.field);
17534 +       if (!name)
17535 +               return -EINVAL;
17536 +
17537 +       memcpy(vc_data.name, name, 65);
17538 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17539 +               return -EFAULT;
17540 +       return 0;
17541 +}
17542 +
17543 +
17544 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17545 +{
17546 +       struct vcmd_virt_stat_v0 vc_data;
17547 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17548 +       struct timespec uptime;
17549 +
17550 +       do_posix_clock_monotonic_gettime(&uptime);
17551 +       set_normalized_timespec(&uptime,
17552 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17553 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17554 +
17555 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
17556 +       vc_data.uptime = timespec_to_ns(&uptime);
17557 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17558 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17559 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17560 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17561 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17562 +       vc_data.load[0] = cvirt->load[0];
17563 +       vc_data.load[1] = cvirt->load[1];
17564 +       vc_data.load[2] = cvirt->load[2];
17565 +
17566 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17567 +               return -EFAULT;
17568 +       return 0;
17569 +}
17570 +
17571 +
17572 +#ifdef CONFIG_VSERVER_VTIME
17573 +
17574 +/* virtualized time base */
17575 +
17576 +void vx_gettimeofday(struct timeval *tv)
17577 +{
17578 +       struct vx_info *vxi;
17579 +
17580 +       do_gettimeofday(tv);
17581 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17582 +               return;
17583 +
17584 +       vxi = current_vx_info();
17585 +       tv->tv_sec += vxi->cvirt.bias_tv.tv_sec;
17586 +       tv->tv_usec += vxi->cvirt.bias_tv.tv_usec;
17587 +
17588 +       if (tv->tv_usec >= USEC_PER_SEC) {
17589 +               tv->tv_sec++;
17590 +               tv->tv_usec -= USEC_PER_SEC;
17591 +       } else if (tv->tv_usec < 0) {
17592 +               tv->tv_sec--;
17593 +               tv->tv_usec += USEC_PER_SEC;
17594 +       }
17595 +}
17596 +
17597 +int vx_settimeofday(struct timespec *ts)
17598 +{
17599 +       struct timeval tv;
17600 +       struct vx_info *vxi;
17601 +
17602 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17603 +               return do_settimeofday(ts);
17604 +
17605 +       do_gettimeofday(&tv);
17606 +       vxi = current_vx_info();
17607 +       vxi->cvirt.bias_tv.tv_sec = ts->tv_sec - tv.tv_sec;
17608 +       vxi->cvirt.bias_tv.tv_usec =
17609 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
17610 +       return 0;
17611 +}
17612 +
17613 +#endif
17614 +
17615 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/cvirt_init.h linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cvirt_init.h
17616 --- linux-2.6.35.4/kernel/vserver/cvirt_init.h  1970-01-01 01:00:00.000000000 +0100
17617 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cvirt_init.h    2010-08-02 17:05:06.000000000 +0200
17618 @@ -0,0 +1,69 @@
17619 +
17620 +
17621 +extern uint64_t vx_idle_jiffies(void);
17622 +
17623 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17624 +{
17625 +       uint64_t idle_jiffies = vx_idle_jiffies();
17626 +       uint64_t nsuptime;
17627 +
17628 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17629 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17630 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17631 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17632 +       cvirt->bias_tv.tv_sec = 0;
17633 +       cvirt->bias_tv.tv_usec = 0;
17634 +
17635 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17636 +       atomic_set(&cvirt->nr_threads, 0);
17637 +       atomic_set(&cvirt->nr_running, 0);
17638 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17639 +       atomic_set(&cvirt->nr_onhold, 0);
17640 +
17641 +       spin_lock_init(&cvirt->load_lock);
17642 +       cvirt->load_last = jiffies;
17643 +       atomic_set(&cvirt->load_updates, 0);
17644 +       cvirt->load[0] = 0;
17645 +       cvirt->load[1] = 0;
17646 +       cvirt->load[2] = 0;
17647 +       atomic_set(&cvirt->total_forks, 0);
17648 +
17649 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17650 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17651 +       cvirt->syslog.log_start = 0;
17652 +       cvirt->syslog.log_end = 0;
17653 +       cvirt->syslog.con_start = 0;
17654 +       cvirt->syslog.logged_chars = 0;
17655 +}
17656 +
17657 +static inline
17658 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17659 +{
17660 +       // cvirt_pc->cpustat = { 0 };
17661 +}
17662 +
17663 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17664 +{
17665 +       int value;
17666 +
17667 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17668 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17669 +               cvirt, value);
17670 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17671 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17672 +               cvirt, value);
17673 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17674 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17675 +               cvirt, value);
17676 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17677 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17678 +               cvirt, value);
17679 +       return;
17680 +}
17681 +
17682 +static inline
17683 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17684 +{
17685 +       return;
17686 +}
17687 +
17688 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/cvirt_proc.h linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cvirt_proc.h
17689 --- linux-2.6.35.4/kernel/vserver/cvirt_proc.h  1970-01-01 01:00:00.000000000 +0100
17690 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/cvirt_proc.h    2010-08-02 17:05:06.000000000 +0200
17691 @@ -0,0 +1,135 @@
17692 +#ifndef _VX_CVIRT_PROC_H
17693 +#define _VX_CVIRT_PROC_H
17694 +
17695 +#include <linux/nsproxy.h>
17696 +#include <linux/mnt_namespace.h>
17697 +#include <linux/ipc_namespace.h>
17698 +#include <linux/utsname.h>
17699 +#include <linux/ipc.h>
17700 +
17701 +
17702 +static inline
17703 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17704 +{
17705 +       struct mnt_namespace *ns;
17706 +       struct uts_namespace *uts;
17707 +       struct ipc_namespace *ipc;
17708 +       struct path path;
17709 +       char *pstr, *root;
17710 +       int length = 0;
17711 +
17712 +       if (!nsproxy)
17713 +               goto out;
17714 +
17715 +       length += sprintf(buffer + length,
17716 +               "NSProxy:\t%p [%p,%p,%p]\n",
17717 +               nsproxy, nsproxy->mnt_ns,
17718 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17719 +
17720 +       ns = nsproxy->mnt_ns;
17721 +       if (!ns)
17722 +               goto skip_ns;
17723 +
17724 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17725 +       if (!pstr)
17726 +               goto skip_ns;
17727 +
17728 +       path.mnt = ns->root;
17729 +       path.dentry = ns->root->mnt_root;
17730 +       root = d_path(&path, pstr, PATH_MAX - 2);
17731 +       length += sprintf(buffer + length,
17732 +               "Namespace:\t%p [#%u]\n"
17733 +               "RootPath:\t%s\n",
17734 +               ns, atomic_read(&ns->count),
17735 +               root);
17736 +       kfree(pstr);
17737 +skip_ns:
17738 +
17739 +       uts = nsproxy->uts_ns;
17740 +       if (!uts)
17741 +               goto skip_uts;
17742 +
17743 +       length += sprintf(buffer + length,
17744 +               "SysName:\t%.*s\n"
17745 +               "NodeName:\t%.*s\n"
17746 +               "Release:\t%.*s\n"
17747 +               "Version:\t%.*s\n"
17748 +               "Machine:\t%.*s\n"
17749 +               "DomainName:\t%.*s\n",
17750 +               __NEW_UTS_LEN, uts->name.sysname,
17751 +               __NEW_UTS_LEN, uts->name.nodename,
17752 +               __NEW_UTS_LEN, uts->name.release,
17753 +               __NEW_UTS_LEN, uts->name.version,
17754 +               __NEW_UTS_LEN, uts->name.machine,
17755 +               __NEW_UTS_LEN, uts->name.domainname);
17756 +skip_uts:
17757 +
17758 +       ipc = nsproxy->ipc_ns;
17759 +       if (!ipc)
17760 +               goto skip_ipc;
17761 +
17762 +       length += sprintf(buffer + length,
17763 +               "SEMS:\t\t%d %d %d %d  %d\n"
17764 +               "MSG:\t\t%d %d %d\n"
17765 +               "SHM:\t\t%lu %lu  %d %d\n",
17766 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17767 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17768 +               ipc->used_sems,
17769 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17770 +               (unsigned long)ipc->shm_ctlmax,
17771 +               (unsigned long)ipc->shm_ctlall,
17772 +               ipc->shm_ctlmni, ipc->shm_tot);
17773 +skip_ipc:
17774 +out:
17775 +       return length;
17776 +}
17777 +
17778 +
17779 +#include <linux/sched.h>
17780 +
17781 +#define LOAD_INT(x) ((x) >> FSHIFT)
17782 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17783 +
17784 +static inline
17785 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17786 +{
17787 +       int length = 0;
17788 +       int a, b, c;
17789 +
17790 +       length += sprintf(buffer + length,
17791 +               "BiasUptime:\t%lu.%02lu\n",
17792 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17793 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17794 +
17795 +       a = cvirt->load[0] + (FIXED_1 / 200);
17796 +       b = cvirt->load[1] + (FIXED_1 / 200);
17797 +       c = cvirt->load[2] + (FIXED_1 / 200);
17798 +       length += sprintf(buffer + length,
17799 +               "nr_threads:\t%d\n"
17800 +               "nr_running:\t%d\n"
17801 +               "nr_unintr:\t%d\n"
17802 +               "nr_onhold:\t%d\n"
17803 +               "load_updates:\t%d\n"
17804 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17805 +               "total_forks:\t%d\n",
17806 +               atomic_read(&cvirt->nr_threads),
17807 +               atomic_read(&cvirt->nr_running),
17808 +               atomic_read(&cvirt->nr_uninterruptible),
17809 +               atomic_read(&cvirt->nr_onhold),
17810 +               atomic_read(&cvirt->load_updates),
17811 +               LOAD_INT(a), LOAD_FRAC(a),
17812 +               LOAD_INT(b), LOAD_FRAC(b),
17813 +               LOAD_INT(c), LOAD_FRAC(c),
17814 +               atomic_read(&cvirt->total_forks));
17815 +       return length;
17816 +}
17817 +
17818 +static inline
17819 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17820 +       char *buffer, int cpu)
17821 +{
17822 +       int length = 0;
17823 +       return length;
17824 +}
17825 +
17826 +#endif /* _VX_CVIRT_PROC_H */
17827 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/debug.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/debug.c
17828 --- linux-2.6.35.4/kernel/vserver/debug.c       1970-01-01 01:00:00.000000000 +0100
17829 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/debug.c 2010-08-02 17:05:06.000000000 +0200
17830 @@ -0,0 +1,32 @@
17831 +/*
17832 + *  kernel/vserver/debug.c
17833 + *
17834 + *  Copyright (C) 2005-2007 Herbert Pötzl
17835 + *
17836 + *  V0.01  vx_info dump support
17837 + *
17838 + */
17839 +
17840 +#include <linux/module.h>
17841 +
17842 +#include <linux/vserver/context.h>
17843 +
17844 +
17845 +void   dump_vx_info(struct vx_info *vxi, int level)
17846 +{
17847 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17848 +               atomic_read(&vxi->vx_usecnt),
17849 +               atomic_read(&vxi->vx_tasks),
17850 +               vxi->vx_state);
17851 +       if (level > 0) {
17852 +               __dump_vx_limit(&vxi->limit);
17853 +               __dump_vx_sched(&vxi->sched);
17854 +               __dump_vx_cvirt(&vxi->cvirt);
17855 +               __dump_vx_cacct(&vxi->cacct);
17856 +       }
17857 +       printk("---\n");
17858 +}
17859 +
17860 +
17861 +EXPORT_SYMBOL_GPL(dump_vx_info);
17862 +
17863 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/device.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/device.c
17864 --- linux-2.6.35.4/kernel/vserver/device.c      1970-01-01 01:00:00.000000000 +0100
17865 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/device.c        2010-08-02 17:05:06.000000000 +0200
17866 @@ -0,0 +1,443 @@
17867 +/*
17868 + *  linux/kernel/vserver/device.c
17869 + *
17870 + *  Linux-VServer: Device Support
17871 + *
17872 + *  Copyright (C) 2006  Herbert Pötzl
17873 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17874 + *
17875 + *  V0.01  device mapping basics
17876 + *  V0.02  added defaults
17877 + *
17878 + */
17879 +
17880 +#include <linux/slab.h>
17881 +#include <linux/rcupdate.h>
17882 +#include <linux/fs.h>
17883 +#include <linux/namei.h>
17884 +#include <linux/hash.h>
17885 +
17886 +#include <asm/errno.h>
17887 +#include <asm/uaccess.h>
17888 +#include <linux/vserver/base.h>
17889 +#include <linux/vserver/debug.h>
17890 +#include <linux/vserver/context.h>
17891 +#include <linux/vserver/device.h>
17892 +#include <linux/vserver/device_cmd.h>
17893 +
17894 +
17895 +#define DMAP_HASH_BITS 4
17896 +
17897 +
17898 +struct vs_mapping {
17899 +       union {
17900 +               struct hlist_node hlist;
17901 +               struct list_head list;
17902 +       } u;
17903 +#define dm_hlist       u.hlist
17904 +#define dm_list                u.list
17905 +       xid_t xid;
17906 +       dev_t device;
17907 +       struct vx_dmap_target target;
17908 +};
17909 +
17910 +
17911 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17912 +
17913 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
17914 +
17915 +static struct vx_dmap_target dmap_defaults[2] = {
17916 +       { .flags = DATTR_OPEN },
17917 +       { .flags = DATTR_OPEN },
17918 +};
17919 +
17920 +
17921 +struct kmem_cache *dmap_cachep __read_mostly;
17922 +
17923 +int __init dmap_cache_init(void)
17924 +{
17925 +       dmap_cachep = kmem_cache_create("dmap_cache",
17926 +               sizeof(struct vs_mapping), 0,
17927 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17928 +       return 0;
17929 +}
17930 +
17931 +__initcall(dmap_cache_init);
17932 +
17933 +
17934 +static inline unsigned int __hashval(dev_t dev, int bits)
17935 +{
17936 +       return hash_long((unsigned long)dev, bits);
17937 +}
17938 +
17939 +
17940 +/*     __hash_mapping()
17941 + *     add the mapping to the hash table
17942 + */
17943 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17944 +{
17945 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17946 +       struct hlist_head *head, *hash = dmap_main_hash;
17947 +       int device = vdm->device;
17948 +
17949 +       spin_lock(hash_lock);
17950 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17951 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17952 +
17953 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17954 +       hlist_add_head(&vdm->dm_hlist, head);
17955 +       spin_unlock(hash_lock);
17956 +}
17957 +
17958 +
17959 +static inline int __mode_to_default(umode_t mode)
17960 +{
17961 +       switch (mode) {
17962 +       case S_IFBLK:
17963 +               return 0;
17964 +       case S_IFCHR:
17965 +               return 1;
17966 +       default:
17967 +               BUG();
17968 +       }
17969 +}
17970 +
17971 +
17972 +/*     __set_default()
17973 + *     set a default
17974 + */
17975 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17976 +       struct vx_dmap_target *vdmt)
17977 +{
17978 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17979 +       spin_lock(hash_lock);
17980 +
17981 +       if (vxi)
17982 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17983 +       else
17984 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17985 +
17986 +
17987 +       spin_unlock(hash_lock);
17988 +
17989 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17990 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17991 +}
17992 +
17993 +
17994 +/*     __remove_default()
17995 + *     remove a default
17996 + */
17997 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17998 +{
17999 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18000 +       spin_lock(hash_lock);
18001 +
18002 +       if (vxi)
18003 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18004 +       else    /* remove == reset */
18005 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18006 +
18007 +       spin_unlock(hash_lock);
18008 +       return 0;
18009 +}
18010 +
18011 +
18012 +/*     __find_mapping()
18013 + *     find a mapping in the hash table
18014 + *
18015 + *     caller must hold hash_lock
18016 + */
18017 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18018 +       struct vs_mapping **local, struct vs_mapping **global)
18019 +{
18020 +       struct hlist_head *hash = dmap_main_hash;
18021 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18022 +       struct hlist_node *pos;
18023 +       struct vs_mapping *vdm;
18024 +
18025 +       *local = NULL;
18026 +       if (global)
18027 +               *global = NULL;
18028 +
18029 +       hlist_for_each(pos, head) {
18030 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18031 +
18032 +               if ((vdm->device == device) &&
18033 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18034 +                       if (vdm->xid == xid) {
18035 +                               *local = vdm;
18036 +                               return 1;
18037 +                       } else if (global && vdm->xid == 0)
18038 +                               *global = vdm;
18039 +               }
18040 +       }
18041 +
18042 +       if (global && *global)
18043 +               return 0;
18044 +       else
18045 +               return -ENOENT;
18046 +}
18047 +
18048 +
18049 +/*     __lookup_mapping()
18050 + *     find a mapping and store the result in target and flags
18051 + */
18052 +static inline int __lookup_mapping(struct vx_info *vxi,
18053 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18054 +{
18055 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18056 +       struct vs_mapping *vdm, *global;
18057 +       struct vx_dmap_target *vdmt;
18058 +       int ret = 0;
18059 +       xid_t xid = vxi->vx_id;
18060 +       int index;
18061 +
18062 +       spin_lock(hash_lock);
18063 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18064 +               ret = 1;
18065 +               vdmt = &vdm->target;
18066 +               goto found;
18067 +       }
18068 +
18069 +       index = __mode_to_default(mode);
18070 +       if (vxi && vxi->dmap.targets[index].flags) {
18071 +               ret = 2;
18072 +               vdmt = &vxi->dmap.targets[index];
18073 +       } else if (global) {
18074 +               ret = 3;
18075 +               vdmt = &global->target;
18076 +               goto found;
18077 +       } else {
18078 +               ret = 4;
18079 +               vdmt = &dmap_defaults[index];
18080 +       }
18081 +
18082 +found:
18083 +       if (target && (vdmt->flags & DATTR_REMAP))
18084 +               *target = vdmt->target;
18085 +       else if (target)
18086 +               *target = device;
18087 +       if (flags)
18088 +               *flags = vdmt->flags;
18089 +
18090 +       spin_unlock(hash_lock);
18091 +
18092 +       return ret;
18093 +}
18094 +
18095 +
18096 +/*     __remove_mapping()
18097 + *     remove a mapping from the hash table
18098 + */
18099 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18100 +       umode_t mode)
18101 +{
18102 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18103 +       struct vs_mapping *vdm = NULL;
18104 +       int ret = 0;
18105 +
18106 +       spin_lock(hash_lock);
18107 +
18108 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18109 +               NULL);
18110 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18111 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18112 +       if (ret < 0)
18113 +               goto out;
18114 +       hlist_del(&vdm->dm_hlist);
18115 +
18116 +out:
18117 +       spin_unlock(hash_lock);
18118 +       if (vdm)
18119 +               kmem_cache_free(dmap_cachep, vdm);
18120 +       return ret;
18121 +}
18122 +
18123 +
18124 +
18125 +int vs_map_device(struct vx_info *vxi,
18126 +       dev_t device, dev_t *target, umode_t mode)
18127 +{
18128 +       int ret, flags = DATTR_MASK;
18129 +
18130 +       if (!vxi) {
18131 +               if (target)
18132 +                       *target = device;
18133 +               goto out;
18134 +       }
18135 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18136 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18137 +               device, target ? *target : 0, flags, mode, ret);
18138 +out:
18139 +       return (flags & DATTR_MASK);
18140 +}
18141 +
18142 +
18143 +
18144 +static int do_set_mapping(struct vx_info *vxi,
18145 +       dev_t device, dev_t target, int flags, umode_t mode)
18146 +{
18147 +       if (device) {
18148 +               struct vs_mapping *new;
18149 +
18150 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18151 +               if (!new)
18152 +                       return -ENOMEM;
18153 +
18154 +               INIT_HLIST_NODE(&new->dm_hlist);
18155 +               new->device = device;
18156 +               new->target.target = target;
18157 +               new->target.flags = flags | mode;
18158 +               new->xid = (vxi ? vxi->vx_id : 0);
18159 +
18160 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18161 +               __hash_mapping(vxi, new);
18162 +       } else {
18163 +               struct vx_dmap_target new = {
18164 +                       .target = target,
18165 +                       .flags = flags | mode,
18166 +               };
18167 +               __set_default(vxi, mode, &new);
18168 +       }
18169 +       return 0;
18170 +}
18171 +
18172 +
18173 +static int do_unset_mapping(struct vx_info *vxi,
18174 +       dev_t device, dev_t target, int flags, umode_t mode)
18175 +{
18176 +       int ret = -EINVAL;
18177 +
18178 +       if (device) {
18179 +               ret = __remove_mapping(vxi, device, mode);
18180 +               if (ret < 0)
18181 +                       goto out;
18182 +       } else {
18183 +               ret = __remove_default(vxi, mode);
18184 +               if (ret < 0)
18185 +                       goto out;
18186 +       }
18187 +
18188 +out:
18189 +       return ret;
18190 +}
18191 +
18192 +
18193 +static inline int __user_device(const char __user *name, dev_t *dev,
18194 +       umode_t *mode)
18195 +{
18196 +       struct nameidata nd;
18197 +       int ret;
18198 +
18199 +       if (!name) {
18200 +               *dev = 0;
18201 +               return 0;
18202 +       }
18203 +       ret = user_lpath(name, &nd.path);
18204 +       if (ret)
18205 +               return ret;
18206 +       if (nd.path.dentry->d_inode) {
18207 +               *dev = nd.path.dentry->d_inode->i_rdev;
18208 +               *mode = nd.path.dentry->d_inode->i_mode;
18209 +       }
18210 +       path_put(&nd.path);
18211 +       return 0;
18212 +}
18213 +
18214 +static inline int __mapping_mode(dev_t device, dev_t target,
18215 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18216 +{
18217 +       if (device)
18218 +               *mode = device_mode & S_IFMT;
18219 +       else if (target)
18220 +               *mode = target_mode & S_IFMT;
18221 +       else
18222 +               return -EINVAL;
18223 +
18224 +       /* if both given, device and target mode have to match */
18225 +       if (device && target &&
18226 +               ((device_mode ^ target_mode) & S_IFMT))
18227 +               return -EINVAL;
18228 +       return 0;
18229 +}
18230 +
18231 +
18232 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18233 +       const char __user *target_path, int flags, int set)
18234 +{
18235 +       dev_t device = ~0, target = ~0;
18236 +       umode_t device_mode = 0, target_mode = 0, mode;
18237 +       int ret;
18238 +
18239 +       ret = __user_device(device_path, &device, &device_mode);
18240 +       if (ret)
18241 +               return ret;
18242 +       ret = __user_device(target_path, &target, &target_mode);
18243 +       if (ret)
18244 +               return ret;
18245 +
18246 +       ret = __mapping_mode(device, target,
18247 +               device_mode, target_mode, &mode);
18248 +       if (ret)
18249 +               return ret;
18250 +
18251 +       if (set)
18252 +               return do_set_mapping(vxi, device, target,
18253 +                       flags, mode);
18254 +       else
18255 +               return do_unset_mapping(vxi, device, target,
18256 +                       flags, mode);
18257 +}
18258 +
18259 +
18260 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18261 +{
18262 +       struct vcmd_set_mapping_v0 vc_data;
18263 +
18264 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18265 +               return -EFAULT;
18266 +
18267 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18268 +               vc_data.flags, 1);
18269 +}
18270 +
18271 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18272 +{
18273 +       struct vcmd_set_mapping_v0 vc_data;
18274 +
18275 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18276 +               return -EFAULT;
18277 +
18278 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18279 +               vc_data.flags, 0);
18280 +}
18281 +
18282 +
18283 +#ifdef CONFIG_COMPAT
18284 +
18285 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18286 +{
18287 +       struct vcmd_set_mapping_v0_x32 vc_data;
18288 +
18289 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18290 +               return -EFAULT;
18291 +
18292 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18293 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18294 +}
18295 +
18296 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18297 +{
18298 +       struct vcmd_set_mapping_v0_x32 vc_data;
18299 +
18300 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18301 +               return -EFAULT;
18302 +
18303 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18304 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18305 +}
18306 +
18307 +#endif /* CONFIG_COMPAT */
18308 +
18309 +
18310 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/dlimit.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/dlimit.c
18311 --- linux-2.6.35.4/kernel/vserver/dlimit.c      1970-01-01 01:00:00.000000000 +0100
18312 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/dlimit.c        2010-08-02 17:05:06.000000000 +0200
18313 @@ -0,0 +1,531 @@
18314 +/*
18315 + *  linux/kernel/vserver/dlimit.c
18316 + *
18317 + *  Virtual Server: Context Disk Limits
18318 + *
18319 + *  Copyright (C) 2004-2009  Herbert Pötzl
18320 + *
18321 + *  V0.01  initial version
18322 + *  V0.02  compat32 splitup
18323 + *  V0.03  extended interface
18324 + *
18325 + */
18326 +
18327 +#include <linux/statfs.h>
18328 +#include <linux/sched.h>
18329 +#include <linux/namei.h>
18330 +#include <linux/vs_tag.h>
18331 +#include <linux/vs_dlimit.h>
18332 +#include <linux/vserver/dlimit_cmd.h>
18333 +#include <linux/slab.h>
18334 +// #include <linux/gfp.h>
18335 +
18336 +#include <asm/uaccess.h>
18337 +
18338 +/*     __alloc_dl_info()
18339 +
18340 +       * allocate an initialized dl_info struct
18341 +       * doesn't make it visible (hash)                        */
18342 +
18343 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18344 +{
18345 +       struct dl_info *new = NULL;
18346 +
18347 +       vxdprintk(VXD_CBIT(dlim, 5),
18348 +               "alloc_dl_info(%p,%d)*", sb, tag);
18349 +
18350 +       /* would this benefit from a slab cache? */
18351 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18352 +       if (!new)
18353 +               return 0;
18354 +
18355 +       memset(new, 0, sizeof(struct dl_info));
18356 +       new->dl_tag = tag;
18357 +       new->dl_sb = sb;
18358 +       INIT_RCU_HEAD(&new->dl_rcu);
18359 +       INIT_HLIST_NODE(&new->dl_hlist);
18360 +       spin_lock_init(&new->dl_lock);
18361 +       atomic_set(&new->dl_refcnt, 0);
18362 +       atomic_set(&new->dl_usecnt, 0);
18363 +
18364 +       /* rest of init goes here */
18365 +
18366 +       vxdprintk(VXD_CBIT(dlim, 4),
18367 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18368 +       return new;
18369 +}
18370 +
18371 +/*     __dealloc_dl_info()
18372 +
18373 +       * final disposal of dl_info                             */
18374 +
18375 +static void __dealloc_dl_info(struct dl_info *dli)
18376 +{
18377 +       vxdprintk(VXD_CBIT(dlim, 4),
18378 +               "dealloc_dl_info(%p)", dli);
18379 +
18380 +       dli->dl_hlist.next = LIST_POISON1;
18381 +       dli->dl_tag = -1;
18382 +       dli->dl_sb = 0;
18383 +
18384 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18385 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18386 +
18387 +       kfree(dli);
18388 +}
18389 +
18390 +
18391 +/*     hash table for dl_info hash */
18392 +
18393 +#define DL_HASH_SIZE   13
18394 +
18395 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18396 +
18397 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
18398 +
18399 +
18400 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18401 +{
18402 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18403 +}
18404 +
18405 +
18406 +
18407 +/*     __hash_dl_info()
18408 +
18409 +       * add the dli to the global hash table
18410 +       * requires the hash_lock to be held                     */
18411 +
18412 +static inline void __hash_dl_info(struct dl_info *dli)
18413 +{
18414 +       struct hlist_head *head;
18415 +
18416 +       vxdprintk(VXD_CBIT(dlim, 6),
18417 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18418 +       get_dl_info(dli);
18419 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18420 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18421 +}
18422 +
18423 +/*     __unhash_dl_info()
18424 +
18425 +       * remove the dli from the global hash table
18426 +       * requires the hash_lock to be held                     */
18427 +
18428 +static inline void __unhash_dl_info(struct dl_info *dli)
18429 +{
18430 +       vxdprintk(VXD_CBIT(dlim, 6),
18431 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18432 +       hlist_del_rcu(&dli->dl_hlist);
18433 +       put_dl_info(dli);
18434 +}
18435 +
18436 +
18437 +/*     __lookup_dl_info()
18438 +
18439 +       * requires the rcu_read_lock()
18440 +       * doesn't increment the dl_refcnt                       */
18441 +
18442 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18443 +{
18444 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18445 +       struct hlist_node *pos;
18446 +       struct dl_info *dli;
18447 +
18448 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18449 +
18450 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18451 +                       return dli;
18452 +               }
18453 +       }
18454 +       return NULL;
18455 +}
18456 +
18457 +
18458 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18459 +{
18460 +       struct dl_info *dli;
18461 +
18462 +       rcu_read_lock();
18463 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18464 +       vxdprintk(VXD_CBIT(dlim, 7),
18465 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18466 +       rcu_read_unlock();
18467 +       return dli;
18468 +}
18469 +
18470 +void rcu_free_dl_info(struct rcu_head *head)
18471 +{
18472 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18473 +       int usecnt, refcnt;
18474 +
18475 +       BUG_ON(!dli || !head);
18476 +
18477 +       usecnt = atomic_read(&dli->dl_usecnt);
18478 +       BUG_ON(usecnt < 0);
18479 +
18480 +       refcnt = atomic_read(&dli->dl_refcnt);
18481 +       BUG_ON(refcnt < 0);
18482 +
18483 +       vxdprintk(VXD_CBIT(dlim, 3),
18484 +               "rcu_free_dl_info(%p)", dli);
18485 +       if (!usecnt)
18486 +               __dealloc_dl_info(dli);
18487 +       else
18488 +               printk("!!! rcu didn't free\n");
18489 +}
18490 +
18491 +
18492 +
18493 +
18494 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18495 +       uint32_t flags, int add)
18496 +{
18497 +       struct path path;
18498 +       int ret;
18499 +
18500 +       ret = user_lpath(name, &path);
18501 +       if (!ret) {
18502 +               struct super_block *sb;
18503 +               struct dl_info *dli;
18504 +
18505 +               ret = -EINVAL;
18506 +               if (!path.dentry->d_inode)
18507 +                       goto out_release;
18508 +               if (!(sb = path.dentry->d_inode->i_sb))
18509 +                       goto out_release;
18510 +
18511 +               if (add) {
18512 +                       dli = __alloc_dl_info(sb, id);
18513 +                       spin_lock(&dl_info_hash_lock);
18514 +
18515 +                       ret = -EEXIST;
18516 +                       if (__lookup_dl_info(sb, id))
18517 +                               goto out_unlock;
18518 +                       __hash_dl_info(dli);
18519 +                       dli = NULL;
18520 +               } else {
18521 +                       spin_lock(&dl_info_hash_lock);
18522 +                       dli = __lookup_dl_info(sb, id);
18523 +
18524 +                       ret = -ESRCH;
18525 +                       if (!dli)
18526 +                               goto out_unlock;
18527 +                       __unhash_dl_info(dli);
18528 +               }
18529 +               ret = 0;
18530 +       out_unlock:
18531 +               spin_unlock(&dl_info_hash_lock);
18532 +               if (add && dli)
18533 +                       __dealloc_dl_info(dli);
18534 +       out_release:
18535 +               path_put(&path);
18536 +       }
18537 +       return ret;
18538 +}
18539 +
18540 +int vc_add_dlimit(uint32_t id, void __user *data)
18541 +{
18542 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18543 +
18544 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18545 +               return -EFAULT;
18546 +
18547 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18548 +}
18549 +
18550 +int vc_rem_dlimit(uint32_t id, void __user *data)
18551 +{
18552 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18553 +
18554 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18555 +               return -EFAULT;
18556 +
18557 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18558 +}
18559 +
18560 +#ifdef CONFIG_COMPAT
18561 +
18562 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18563 +{
18564 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18565 +
18566 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18567 +               return -EFAULT;
18568 +
18569 +       return do_addrem_dlimit(id,
18570 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18571 +}
18572 +
18573 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18574 +{
18575 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18576 +
18577 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18578 +               return -EFAULT;
18579 +
18580 +       return do_addrem_dlimit(id,
18581 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18582 +}
18583 +
18584 +#endif /* CONFIG_COMPAT */
18585 +
18586 +
18587 +static inline
18588 +int do_set_dlimit(uint32_t id, const char __user *name,
18589 +       uint32_t space_used, uint32_t space_total,
18590 +       uint32_t inodes_used, uint32_t inodes_total,
18591 +       uint32_t reserved, uint32_t flags)
18592 +{
18593 +       struct path path;
18594 +       int ret;
18595 +
18596 +       ret = user_lpath(name, &path);
18597 +       if (!ret) {
18598 +               struct super_block *sb;
18599 +               struct dl_info *dli;
18600 +
18601 +               ret = -EINVAL;
18602 +               if (!path.dentry->d_inode)
18603 +                       goto out_release;
18604 +               if (!(sb = path.dentry->d_inode->i_sb))
18605 +                       goto out_release;
18606 +
18607 +               /* sanity checks */
18608 +               if ((reserved != CDLIM_KEEP &&
18609 +                       reserved > 100) ||
18610 +                       (inodes_used != CDLIM_KEEP &&
18611 +                       inodes_used > inodes_total) ||
18612 +                       (space_used != CDLIM_KEEP &&
18613 +                       space_used > space_total))
18614 +                       goto out_release;
18615 +
18616 +               ret = -ESRCH;
18617 +               dli = locate_dl_info(sb, id);
18618 +               if (!dli)
18619 +                       goto out_release;
18620 +
18621 +               spin_lock(&dli->dl_lock);
18622 +
18623 +               if (inodes_used != CDLIM_KEEP)
18624 +                       dli->dl_inodes_used = inodes_used;
18625 +               if (inodes_total != CDLIM_KEEP)
18626 +                       dli->dl_inodes_total = inodes_total;
18627 +               if (space_used != CDLIM_KEEP)
18628 +                       dli->dl_space_used = dlimit_space_32to64(
18629 +                               space_used, flags, DLIMS_USED);
18630 +
18631 +               if (space_total == CDLIM_INFINITY)
18632 +                       dli->dl_space_total = DLIM_INFINITY;
18633 +               else if (space_total != CDLIM_KEEP)
18634 +                       dli->dl_space_total = dlimit_space_32to64(
18635 +                               space_total, flags, DLIMS_TOTAL);
18636 +
18637 +               if (reserved != CDLIM_KEEP)
18638 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18639 +
18640 +               spin_unlock(&dli->dl_lock);
18641 +
18642 +               put_dl_info(dli);
18643 +               ret = 0;
18644 +
18645 +       out_release:
18646 +               path_put(&path);
18647 +       }
18648 +       return ret;
18649 +}
18650 +
18651 +int vc_set_dlimit(uint32_t id, void __user *data)
18652 +{
18653 +       struct vcmd_ctx_dlimit_v0 vc_data;
18654 +
18655 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18656 +               return -EFAULT;
18657 +
18658 +       return do_set_dlimit(id, vc_data.name,
18659 +               vc_data.space_used, vc_data.space_total,
18660 +               vc_data.inodes_used, vc_data.inodes_total,
18661 +               vc_data.reserved, vc_data.flags);
18662 +}
18663 +
18664 +#ifdef CONFIG_COMPAT
18665 +
18666 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18667 +{
18668 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18669 +
18670 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18671 +               return -EFAULT;
18672 +
18673 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18674 +               vc_data.space_used, vc_data.space_total,
18675 +               vc_data.inodes_used, vc_data.inodes_total,
18676 +               vc_data.reserved, vc_data.flags);
18677 +}
18678 +
18679 +#endif /* CONFIG_COMPAT */
18680 +
18681 +
18682 +static inline
18683 +int do_get_dlimit(uint32_t id, const char __user *name,
18684 +       uint32_t *space_used, uint32_t *space_total,
18685 +       uint32_t *inodes_used, uint32_t *inodes_total,
18686 +       uint32_t *reserved, uint32_t *flags)
18687 +{
18688 +       struct path path;
18689 +       int ret;
18690 +
18691 +       ret = user_lpath(name, &path);
18692 +       if (!ret) {
18693 +               struct super_block *sb;
18694 +               struct dl_info *dli;
18695 +
18696 +               ret = -EINVAL;
18697 +               if (!path.dentry->d_inode)
18698 +                       goto out_release;
18699 +               if (!(sb = path.dentry->d_inode->i_sb))
18700 +                       goto out_release;
18701 +
18702 +               ret = -ESRCH;
18703 +               dli = locate_dl_info(sb, id);
18704 +               if (!dli)
18705 +                       goto out_release;
18706 +
18707 +               spin_lock(&dli->dl_lock);
18708 +               *inodes_used = dli->dl_inodes_used;
18709 +               *inodes_total = dli->dl_inodes_total;
18710 +
18711 +               *space_used = dlimit_space_64to32(
18712 +                       dli->dl_space_used, flags, DLIMS_USED);
18713 +
18714 +               if (dli->dl_space_total == DLIM_INFINITY)
18715 +                       *space_total = CDLIM_INFINITY;
18716 +               else
18717 +                       *space_total = dlimit_space_64to32(
18718 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18719 +
18720 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18721 +               spin_unlock(&dli->dl_lock);
18722 +
18723 +               put_dl_info(dli);
18724 +               ret = -EFAULT;
18725 +
18726 +               ret = 0;
18727 +       out_release:
18728 +               path_put(&path);
18729 +       }
18730 +       return ret;
18731 +}
18732 +
18733 +
18734 +int vc_get_dlimit(uint32_t id, void __user *data)
18735 +{
18736 +       struct vcmd_ctx_dlimit_v0 vc_data;
18737 +       int ret;
18738 +
18739 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18740 +               return -EFAULT;
18741 +
18742 +       ret = do_get_dlimit(id, vc_data.name,
18743 +               &vc_data.space_used, &vc_data.space_total,
18744 +               &vc_data.inodes_used, &vc_data.inodes_total,
18745 +               &vc_data.reserved, &vc_data.flags);
18746 +       if (ret)
18747 +               return ret;
18748 +
18749 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18750 +               return -EFAULT;
18751 +       return 0;
18752 +}
18753 +
18754 +#ifdef CONFIG_COMPAT
18755 +
18756 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18757 +{
18758 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18759 +       int ret;
18760 +
18761 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18762 +               return -EFAULT;
18763 +
18764 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18765 +               &vc_data.space_used, &vc_data.space_total,
18766 +               &vc_data.inodes_used, &vc_data.inodes_total,
18767 +               &vc_data.reserved, &vc_data.flags);
18768 +       if (ret)
18769 +               return ret;
18770 +
18771 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18772 +               return -EFAULT;
18773 +       return 0;
18774 +}
18775 +
18776 +#endif /* CONFIG_COMPAT */
18777 +
18778 +
18779 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18780 +{
18781 +       struct dl_info *dli;
18782 +       __u64 blimit, bfree, bavail;
18783 +       __u32 ifree;
18784 +
18785 +       dli = locate_dl_info(sb, dx_current_tag());
18786 +       if (!dli)
18787 +               return;
18788 +
18789 +       spin_lock(&dli->dl_lock);
18790 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18791 +               goto no_ilim;
18792 +
18793 +       /* reduce max inodes available to limit */
18794 +       if (buf->f_files > dli->dl_inodes_total)
18795 +               buf->f_files = dli->dl_inodes_total;
18796 +
18797 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18798 +       /* reduce free inodes to min */
18799 +       if (ifree < buf->f_ffree)
18800 +               buf->f_ffree = ifree;
18801 +
18802 +no_ilim:
18803 +       if (dli->dl_space_total == DLIM_INFINITY)
18804 +               goto no_blim;
18805 +
18806 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18807 +
18808 +       if (dli->dl_space_total < dli->dl_space_used)
18809 +               bfree = 0;
18810 +       else
18811 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18812 +                       >> sb->s_blocksize_bits;
18813 +
18814 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18815 +       if (bavail < dli->dl_space_used)
18816 +               bavail = 0;
18817 +       else
18818 +               bavail = (bavail - dli->dl_space_used)
18819 +                       >> sb->s_blocksize_bits;
18820 +
18821 +       /* reduce max space available to limit */
18822 +       if (buf->f_blocks > blimit)
18823 +               buf->f_blocks = blimit;
18824 +
18825 +       /* reduce free space to min */
18826 +       if (bfree < buf->f_bfree)
18827 +               buf->f_bfree = bfree;
18828 +
18829 +       /* reduce avail space to min */
18830 +       if (bavail < buf->f_bavail)
18831 +               buf->f_bavail = bavail;
18832 +
18833 +no_blim:
18834 +       spin_unlock(&dli->dl_lock);
18835 +       put_dl_info(dli);
18836 +
18837 +       return;
18838 +}
18839 +
18840 +#include <linux/module.h>
18841 +
18842 +EXPORT_SYMBOL_GPL(locate_dl_info);
18843 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18844 +
18845 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/helper.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/helper.c
18846 --- linux-2.6.35.4/kernel/vserver/helper.c      1970-01-01 01:00:00.000000000 +0100
18847 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/helper.c        2010-08-02 17:05:06.000000000 +0200
18848 @@ -0,0 +1,223 @@
18849 +/*
18850 + *  linux/kernel/vserver/helper.c
18851 + *
18852 + *  Virtual Context Support
18853 + *
18854 + *  Copyright (C) 2004-2007  Herbert Pötzl
18855 + *
18856 + *  V0.01  basic helper
18857 + *
18858 + */
18859 +
18860 +#include <linux/kmod.h>
18861 +#include <linux/reboot.h>
18862 +#include <linux/vs_context.h>
18863 +#include <linux/vs_network.h>
18864 +#include <linux/vserver/signal.h>
18865 +
18866 +
18867 +char vshelper_path[255] = "/sbin/vshelper";
18868 +
18869 +
18870 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18871 +{
18872 +       int ret;
18873 +
18874 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18875 +               printk( KERN_WARNING
18876 +                       "%s: (%s %s) returned %s with %d\n",
18877 +                       name, argv[1], argv[2],
18878 +                       sync ? "sync" : "async", ret);
18879 +       }
18880 +       vxdprintk(VXD_CBIT(switch, 4),
18881 +               "%s: (%s %s) returned %s with %d",
18882 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18883 +       return ret;
18884 +}
18885 +
18886 +/*
18887 + *      vshelper path is set via /proc/sys
18888 + *      invoked by vserver sys_reboot(), with
18889 + *      the following arguments
18890 + *
18891 + *      argv [0] = vshelper_path;
18892 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18893 + *      argv [2] = context identifier
18894 + *
18895 + *      envp [*] = type-specific parameters
18896 + */
18897 +
18898 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18899 +{
18900 +       char id_buf[8], cmd_buf[16];
18901 +       char uid_buf[16], pid_buf[16];
18902 +       int ret;
18903 +
18904 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18905 +       char *envp[] = {"HOME=/", "TERM=linux",
18906 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18907 +                       uid_buf, pid_buf, cmd_buf, 0};
18908 +
18909 +       if (vx_info_state(vxi, VXS_HELPER))
18910 +               return -EAGAIN;
18911 +       vxi->vx_state |= VXS_HELPER;
18912 +
18913 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18914 +
18915 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18916 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18917 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18918 +
18919 +       switch (cmd) {
18920 +       case LINUX_REBOOT_CMD_RESTART:
18921 +               argv[1] = "restart";
18922 +               break;
18923 +
18924 +       case LINUX_REBOOT_CMD_HALT:
18925 +               argv[1] = "halt";
18926 +               break;
18927 +
18928 +       case LINUX_REBOOT_CMD_POWER_OFF:
18929 +               argv[1] = "poweroff";
18930 +               break;
18931 +
18932 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18933 +               argv[1] = "swsusp";
18934 +               break;
18935 +
18936 +       case LINUX_REBOOT_CMD_OOM:
18937 +               argv[1] = "oom";
18938 +               break;
18939 +
18940 +       default:
18941 +               vxi->vx_state &= ~VXS_HELPER;
18942 +               return 0;
18943 +       }
18944 +
18945 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18946 +       vxi->vx_state &= ~VXS_HELPER;
18947 +       __wakeup_vx_info(vxi);
18948 +       return (ret) ? -EPERM : 0;
18949 +}
18950 +
18951 +
18952 +long vs_reboot(unsigned int cmd, void __user *arg)
18953 +{
18954 +       struct vx_info *vxi = current_vx_info();
18955 +       long ret = 0;
18956 +
18957 +       vxdprintk(VXD_CBIT(misc, 5),
18958 +               "vs_reboot(%p[#%d],%u)",
18959 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18960 +
18961 +       ret = vs_reboot_helper(vxi, cmd, arg);
18962 +       if (ret)
18963 +               return ret;
18964 +
18965 +       vxi->reboot_cmd = cmd;
18966 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18967 +               switch (cmd) {
18968 +               case LINUX_REBOOT_CMD_RESTART:
18969 +               case LINUX_REBOOT_CMD_HALT:
18970 +               case LINUX_REBOOT_CMD_POWER_OFF:
18971 +                       vx_info_kill(vxi, 0, SIGKILL);
18972 +                       vx_info_kill(vxi, 1, SIGKILL);
18973 +               default:
18974 +                       break;
18975 +               }
18976 +       }
18977 +       return 0;
18978 +}
18979 +
18980 +long vs_oom_action(unsigned int cmd)
18981 +{
18982 +       struct vx_info *vxi = current_vx_info();
18983 +       long ret = 0;
18984 +
18985 +       vxdprintk(VXD_CBIT(misc, 5),
18986 +               "vs_oom_action(%p[#%d],%u)",
18987 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18988 +
18989 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18990 +       if (ret)
18991 +               return ret;
18992 +
18993 +       vxi->reboot_cmd = cmd;
18994 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18995 +               vx_info_kill(vxi, 0, SIGKILL);
18996 +               vx_info_kill(vxi, 1, SIGKILL);
18997 +       }
18998 +       return 0;
18999 +}
19000 +
19001 +/*
19002 + *      argv [0] = vshelper_path;
19003 + *      argv [1] = action: "startup", "shutdown"
19004 + *      argv [2] = context identifier
19005 + *
19006 + *      envp [*] = type-specific parameters
19007 + */
19008 +
19009 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19010 +{
19011 +       char id_buf[8], cmd_buf[16];
19012 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19013 +       char *envp[] = {"HOME=/", "TERM=linux",
19014 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19015 +
19016 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19017 +               return 0;
19018 +
19019 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19020 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19021 +
19022 +       switch (cmd) {
19023 +       case VSC_STARTUP:
19024 +               argv[1] = "startup";
19025 +               break;
19026 +       case VSC_SHUTDOWN:
19027 +               argv[1] = "shutdown";
19028 +               break;
19029 +       default:
19030 +               return 0;
19031 +       }
19032 +
19033 +       return do_vshelper(vshelper_path, argv, envp, 1);
19034 +}
19035 +
19036 +
19037 +/*
19038 + *      argv [0] = vshelper_path;
19039 + *      argv [1] = action: "netup", "netdown"
19040 + *      argv [2] = context identifier
19041 + *
19042 + *      envp [*] = type-specific parameters
19043 + */
19044 +
19045 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19046 +{
19047 +       char id_buf[8], cmd_buf[16];
19048 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19049 +       char *envp[] = {"HOME=/", "TERM=linux",
19050 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19051 +
19052 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19053 +               return 0;
19054 +
19055 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19056 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19057 +
19058 +       switch (cmd) {
19059 +       case VSC_NETUP:
19060 +               argv[1] = "netup";
19061 +               break;
19062 +       case VSC_NETDOWN:
19063 +               argv[1] = "netdown";
19064 +               break;
19065 +       default:
19066 +               return 0;
19067 +       }
19068 +
19069 +       return do_vshelper(vshelper_path, argv, envp, 1);
19070 +}
19071 +
19072 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/history.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/history.c
19073 --- linux-2.6.35.4/kernel/vserver/history.c     1970-01-01 01:00:00.000000000 +0100
19074 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/history.c       2010-08-02 17:05:06.000000000 +0200
19075 @@ -0,0 +1,258 @@
19076 +/*
19077 + *  kernel/vserver/history.c
19078 + *
19079 + *  Virtual Context History Backtrace
19080 + *
19081 + *  Copyright (C) 2004-2007  Herbert Pötzl
19082 + *
19083 + *  V0.01  basic structure
19084 + *  V0.02  hash/unhash and trace
19085 + *  V0.03  preemption fixes
19086 + *
19087 + */
19088 +
19089 +#include <linux/module.h>
19090 +#include <asm/uaccess.h>
19091 +
19092 +#include <linux/vserver/context.h>
19093 +#include <linux/vserver/debug.h>
19094 +#include <linux/vserver/debug_cmd.h>
19095 +#include <linux/vserver/history.h>
19096 +
19097 +
19098 +#ifdef CONFIG_VSERVER_HISTORY
19099 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19100 +#else
19101 +#define VXH_SIZE       64
19102 +#endif
19103 +
19104 +struct _vx_history {
19105 +       unsigned int counter;
19106 +
19107 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19108 +};
19109 +
19110 +
19111 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19112 +
19113 +unsigned volatile int vxh_active = 1;
19114 +
19115 +static atomic_t sequence = ATOMIC_INIT(0);
19116 +
19117 +
19118 +/*     vxh_advance()
19119 +
19120 +       * requires disabled preemption                          */
19121 +
19122 +struct _vx_hist_entry *vxh_advance(void *loc)
19123 +{
19124 +       unsigned int cpu = smp_processor_id();
19125 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19126 +       struct _vx_hist_entry *entry;
19127 +       unsigned int index;
19128 +
19129 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19130 +       entry = &hist->entry[index];
19131 +
19132 +       entry->seq = atomic_inc_return(&sequence);
19133 +       entry->loc = loc;
19134 +       return entry;
19135 +}
19136 +
19137 +EXPORT_SYMBOL_GPL(vxh_advance);
19138 +
19139 +
19140 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19141 +
19142 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19143 +
19144 +
19145 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19146 +
19147 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19148 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19149 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19150 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19151 +
19152 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19153 +{
19154 +       switch (e->type) {
19155 +       case VXH_THROW_OOPS:
19156 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19157 +               break;
19158 +
19159 +       case VXH_GET_VX_INFO:
19160 +       case VXH_PUT_VX_INFO:
19161 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19162 +                       VXH_LOC_ARGS(e),
19163 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19164 +                       VXH_VXI_ARGS(e));
19165 +               break;
19166 +
19167 +       case VXH_INIT_VX_INFO:
19168 +       case VXH_SET_VX_INFO:
19169 +       case VXH_CLR_VX_INFO:
19170 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19171 +                       VXH_LOC_ARGS(e),
19172 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19173 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19174 +                       VXH_VXI_ARGS(e), e->sc.data);
19175 +               break;
19176 +
19177 +       case VXH_CLAIM_VX_INFO:
19178 +       case VXH_RELEASE_VX_INFO:
19179 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19180 +                       VXH_LOC_ARGS(e),
19181 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19182 +                       VXH_VXI_ARGS(e), e->sc.data);
19183 +               break;
19184 +
19185 +       case VXH_ALLOC_VX_INFO:
19186 +       case VXH_DEALLOC_VX_INFO:
19187 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19188 +                       VXH_LOC_ARGS(e),
19189 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19190 +                       VXH_VXI_ARGS(e));
19191 +               break;
19192 +
19193 +       case VXH_HASH_VX_INFO:
19194 +       case VXH_UNHASH_VX_INFO:
19195 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19196 +                       VXH_LOC_ARGS(e),
19197 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19198 +                       VXH_VXI_ARGS(e));
19199 +               break;
19200 +
19201 +       case VXH_LOC_VX_INFO:
19202 +       case VXH_LOOKUP_VX_INFO:
19203 +       case VXH_CREATE_VX_INFO:
19204 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19205 +                       VXH_LOC_ARGS(e),
19206 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19207 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19208 +                       e->ll.arg, VXH_VXI_ARGS(e));
19209 +               break;
19210 +       }
19211 +}
19212 +
19213 +static void __vxh_dump_history(void)
19214 +{
19215 +       unsigned int i, cpu;
19216 +
19217 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19218 +               atomic_read(&sequence), NR_CPUS);
19219 +
19220 +       for (i = 0; i < VXH_SIZE; i++) {
19221 +               for_each_online_cpu(cpu) {
19222 +                       struct _vx_history *hist =
19223 +                               &per_cpu(vx_history_buffer, cpu);
19224 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19225 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19226 +
19227 +                       vxh_dump_entry(entry, cpu);
19228 +               }
19229 +       }
19230 +}
19231 +
19232 +void   vxh_dump_history(void)
19233 +{
19234 +       vxh_active = 0;
19235 +#ifdef CONFIG_SMP
19236 +       local_irq_enable();
19237 +       smp_send_stop();
19238 +       local_irq_disable();
19239 +#endif
19240 +       __vxh_dump_history();
19241 +}
19242 +
19243 +
19244 +/* vserver syscall commands below here */
19245 +
19246 +
19247 +int vc_dump_history(uint32_t id)
19248 +{
19249 +       vxh_active = 0;
19250 +       __vxh_dump_history();
19251 +       vxh_active = 1;
19252 +
19253 +       return 0;
19254 +}
19255 +
19256 +
19257 +int do_read_history(struct __user _vx_hist_entry *data,
19258 +       int cpu, uint32_t *index, uint32_t *count)
19259 +{
19260 +       int pos, ret = 0;
19261 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19262 +       int end = hist->counter;
19263 +       int start = end - VXH_SIZE + 2;
19264 +       int idx = *index;
19265 +
19266 +       /* special case: get current pos */
19267 +       if (!*count) {
19268 +               *index = end;
19269 +               return 0;
19270 +       }
19271 +
19272 +       /* have we lost some data? */
19273 +       if (idx < start)
19274 +               idx = start;
19275 +
19276 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19277 +               struct _vx_hist_entry *entry =
19278 +                       &hist->entry[idx % VXH_SIZE];
19279 +
19280 +               /* send entry to userspace */
19281 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19282 +               if (ret)
19283 +                       break;
19284 +       }
19285 +       /* save new index and count */
19286 +       *index = idx;
19287 +       *count = pos;
19288 +       return ret ? ret : (*index < end);
19289 +}
19290 +
19291 +int vc_read_history(uint32_t id, void __user *data)
19292 +{
19293 +       struct vcmd_read_history_v0 vc_data;
19294 +       int ret;
19295 +
19296 +       if (id >= NR_CPUS)
19297 +               return -EINVAL;
19298 +
19299 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19300 +               return -EFAULT;
19301 +
19302 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19303 +               id, &vc_data.index, &vc_data.count);
19304 +
19305 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19306 +               return -EFAULT;
19307 +       return ret;
19308 +}
19309 +
19310 +#ifdef CONFIG_COMPAT
19311 +
19312 +int vc_read_history_x32(uint32_t id, void __user *data)
19313 +{
19314 +       struct vcmd_read_history_v0_x32 vc_data;
19315 +       int ret;
19316 +
19317 +       if (id >= NR_CPUS)
19318 +               return -EINVAL;
19319 +
19320 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19321 +               return -EFAULT;
19322 +
19323 +       ret = do_read_history((struct __user _vx_hist_entry *)
19324 +               compat_ptr(vc_data.data_ptr),
19325 +               id, &vc_data.index, &vc_data.count);
19326 +
19327 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19328 +               return -EFAULT;
19329 +       return ret;
19330 +}
19331 +
19332 +#endif /* CONFIG_COMPAT */
19333 +
19334 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/inet.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/inet.c
19335 --- linux-2.6.35.4/kernel/vserver/inet.c        1970-01-01 01:00:00.000000000 +0100
19336 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/inet.c  2010-08-02 18:54:03.000000000 +0200
19337 @@ -0,0 +1,224 @@
19338 +
19339 +#include <linux/in.h>
19340 +#include <linux/inetdevice.h>
19341 +#include <linux/vs_inet.h>
19342 +#include <linux/vs_inet6.h>
19343 +#include <linux/vserver/debug.h>
19344 +#include <net/route.h>
19345 +#include <net/addrconf.h>
19346 +
19347 +
19348 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19349 +{
19350 +       int ret = 0;
19351 +
19352 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19353 +               ret = 1;
19354 +       else {
19355 +               struct nx_addr_v4 *ptr;
19356 +
19357 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19358 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19359 +                               ret = 1;
19360 +                               break;
19361 +                       }
19362 +               }
19363 +       }
19364 +
19365 +       vxdprintk(VXD_CBIT(net, 2),
19366 +               "nx_v4_addr_conflict(%p,%p): %d",
19367 +               nxi1, nxi2, ret);
19368 +
19369 +       return ret;
19370 +}
19371 +
19372 +
19373 +#ifdef CONFIG_IPV6
19374 +
19375 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19376 +{
19377 +       int ret = 0;
19378 +
19379 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19380 +               ret = 1;
19381 +       else {
19382 +               struct nx_addr_v6 *ptr;
19383 +
19384 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19385 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19386 +                               ret = 1;
19387 +                               break;
19388 +                       }
19389 +               }
19390 +       }
19391 +
19392 +       vxdprintk(VXD_CBIT(net, 2),
19393 +               "nx_v6_addr_conflict(%p,%p): %d",
19394 +               nxi1, nxi2, ret);
19395 +
19396 +       return ret;
19397 +}
19398 +
19399 +#endif
19400 +
19401 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19402 +{
19403 +       struct in_device *in_dev;
19404 +       struct in_ifaddr **ifap;
19405 +       struct in_ifaddr *ifa;
19406 +       int ret = 0;
19407 +
19408 +       if (!dev)
19409 +               goto out;
19410 +       in_dev = in_dev_get(dev);
19411 +       if (!in_dev)
19412 +               goto out;
19413 +
19414 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19415 +               ifap = &ifa->ifa_next) {
19416 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19417 +                       ret = 1;
19418 +                       break;
19419 +               }
19420 +       }
19421 +       in_dev_put(in_dev);
19422 +out:
19423 +       return ret;
19424 +}
19425 +
19426 +
19427 +#ifdef CONFIG_IPV6
19428 +
19429 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19430 +{
19431 +       struct inet6_dev *in_dev;
19432 +       struct inet6_ifaddr *ifa;
19433 +       int ret = 0;
19434 +
19435 +       if (!dev)
19436 +               goto out;
19437 +       in_dev = in6_dev_get(dev);
19438 +       if (!in_dev)
19439 +               goto out;
19440 +
19441 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19442 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19443 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19444 +                       ret = 1;
19445 +                       break;
19446 +               }
19447 +       }
19448 +       in6_dev_put(in_dev);
19449 +out:
19450 +       return ret;
19451 +}
19452 +
19453 +#endif
19454 +
19455 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19456 +{
19457 +       int ret = 1;
19458 +
19459 +       if (!nxi)
19460 +               goto out;
19461 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19462 +               goto out;
19463 +#ifdef CONFIG_IPV6
19464 +       ret = 2;
19465 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19466 +               goto out;
19467 +#endif
19468 +       ret = 0;
19469 +out:
19470 +       vxdprintk(VXD_CBIT(net, 3),
19471 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19472 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19473 +       return ret;
19474 +}
19475 +
19476 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
19477 +       struct rtable **rp, struct flowi *fl)
19478 +{
19479 +       if (!nxi)
19480 +               return 0;
19481 +
19482 +       /* FIXME: handle lback only case */
19483 +       if (!NX_IPV4(nxi))
19484 +               return -EPERM;
19485 +
19486 +       vxdprintk(VXD_CBIT(net, 4),
19487 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19488 +               nxi, nxi ? nxi->nx_id : 0,
19489 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
19490 +
19491 +       /* single IP is unconditional */
19492 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19493 +               (fl->fl4_src == INADDR_ANY))
19494 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
19495 +
19496 +       if (fl->fl4_src == INADDR_ANY) {
19497 +               struct nx_addr_v4 *ptr;
19498 +               __be32 found = 0;
19499 +               int err;
19500 +
19501 +               err = __ip_route_output_key(net, rp, fl);
19502 +               if (!err) {
19503 +                       found = (*rp)->rt_src;
19504 +                       ip_rt_put(*rp);
19505 +                       vxdprintk(VXD_CBIT(net, 4),
19506 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19507 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
19508 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19509 +                               goto found;
19510 +               }
19511 +
19512 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19513 +                       __be32 primary = ptr->ip[0].s_addr;
19514 +                       __be32 mask = ptr->mask.s_addr;
19515 +                       __be32 neta = primary & mask;
19516 +
19517 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19518 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19519 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19520 +                               NIPQUAD(mask), NIPQUAD(neta));
19521 +                       if ((found & mask) != neta)
19522 +                               continue;
19523 +
19524 +                       fl->fl4_src = primary;
19525 +                       err = __ip_route_output_key(net, rp, fl);
19526 +                       vxdprintk(VXD_CBIT(net, 4),
19527 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19528 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
19529 +                       if (!err) {
19530 +                               found = (*rp)->rt_src;
19531 +                               ip_rt_put(*rp);
19532 +                               if (found == primary)
19533 +                                       goto found;
19534 +                       }
19535 +               }
19536 +               /* still no source ip? */
19537 +               found = ipv4_is_loopback(fl->fl4_dst)
19538 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19539 +       found:
19540 +               /* assign src ip to flow */
19541 +               fl->fl4_src = found;
19542 +
19543 +       } else {
19544 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
19545 +                       return -EPERM;
19546 +       }
19547 +
19548 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19549 +               if (ipv4_is_loopback(fl->fl4_dst))
19550 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
19551 +               if (ipv4_is_loopback(fl->fl4_src))
19552 +                       fl->fl4_src = nxi->v4_lback.s_addr;
19553 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
19554 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19555 +               return -EPERM;
19556 +
19557 +       return 0;
19558 +}
19559 +
19560 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19561 +
19562 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/init.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/init.c
19563 --- linux-2.6.35.4/kernel/vserver/init.c        1970-01-01 01:00:00.000000000 +0100
19564 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/init.c  2010-08-02 17:05:06.000000000 +0200
19565 @@ -0,0 +1,45 @@
19566 +/*
19567 + *  linux/kernel/init.c
19568 + *
19569 + *  Virtual Server Init
19570 + *
19571 + *  Copyright (C) 2004-2007  Herbert Pötzl
19572 + *
19573 + *  V0.01  basic structure
19574 + *
19575 + */
19576 +
19577 +#include <linux/init.h>
19578 +
19579 +int    vserver_register_sysctl(void);
19580 +void   vserver_unregister_sysctl(void);
19581 +
19582 +
19583 +static int __init init_vserver(void)
19584 +{
19585 +       int ret = 0;
19586 +
19587 +#ifdef CONFIG_VSERVER_DEBUG
19588 +       vserver_register_sysctl();
19589 +#endif
19590 +       return ret;
19591 +}
19592 +
19593 +
19594 +static void __exit exit_vserver(void)
19595 +{
19596 +
19597 +#ifdef CONFIG_VSERVER_DEBUG
19598 +       vserver_unregister_sysctl();
19599 +#endif
19600 +       return;
19601 +}
19602 +
19603 +/* FIXME: GFP_ZONETYPES gone
19604 +long vx_slab[GFP_ZONETYPES]; */
19605 +long vx_area;
19606 +
19607 +
19608 +module_init(init_vserver);
19609 +module_exit(exit_vserver);
19610 +
19611 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/inode.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/inode.c
19612 --- linux-2.6.35.4/kernel/vserver/inode.c       1970-01-01 01:00:00.000000000 +0100
19613 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/inode.c 2010-08-02 17:05:06.000000000 +0200
19614 @@ -0,0 +1,433 @@
19615 +/*
19616 + *  linux/kernel/vserver/inode.c
19617 + *
19618 + *  Virtual Server: File System Support
19619 + *
19620 + *  Copyright (C) 2004-2007  Herbert Pötzl
19621 + *
19622 + *  V0.01  separated from vcontext V0.05
19623 + *  V0.02  moved to tag (instead of xid)
19624 + *
19625 + */
19626 +
19627 +#include <linux/tty.h>
19628 +#include <linux/proc_fs.h>
19629 +#include <linux/devpts_fs.h>
19630 +#include <linux/fs.h>
19631 +#include <linux/file.h>
19632 +#include <linux/mount.h>
19633 +#include <linux/parser.h>
19634 +#include <linux/namei.h>
19635 +#include <linux/vserver/inode.h>
19636 +#include <linux/vserver/inode_cmd.h>
19637 +#include <linux/vs_base.h>
19638 +#include <linux/vs_tag.h>
19639 +
19640 +#include <asm/uaccess.h>
19641 +
19642 +
19643 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19644 +{
19645 +       struct proc_dir_entry *entry;
19646 +
19647 +       if (!in || !in->i_sb)
19648 +               return -ESRCH;
19649 +
19650 +       *flags = IATTR_TAG
19651 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19652 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19653 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19654 +               | (IS_COW(in) ? IATTR_COW : 0);
19655 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19656 +
19657 +       if (S_ISDIR(in->i_mode))
19658 +               *mask |= IATTR_BARRIER;
19659 +
19660 +       if (IS_TAGGED(in)) {
19661 +               *tag = in->i_tag;
19662 +               *mask |= IATTR_TAG;
19663 +       }
19664 +
19665 +       switch (in->i_sb->s_magic) {
19666 +       case PROC_SUPER_MAGIC:
19667 +               entry = PROC_I(in)->pde;
19668 +
19669 +               /* check for specific inodes? */
19670 +               if (entry)
19671 +                       *mask |= IATTR_FLAGS;
19672 +               if (entry)
19673 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19674 +               else
19675 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19676 +               break;
19677 +
19678 +       case DEVPTS_SUPER_MAGIC:
19679 +               *tag = in->i_tag;
19680 +               *mask |= IATTR_TAG;
19681 +               break;
19682 +
19683 +       default:
19684 +               break;
19685 +       }
19686 +       return 0;
19687 +}
19688 +
19689 +int vc_get_iattr(void __user *data)
19690 +{
19691 +       struct path path;
19692 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19693 +       int ret;
19694 +
19695 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19696 +               return -EFAULT;
19697 +
19698 +       ret = user_lpath(vc_data.name, &path);
19699 +       if (!ret) {
19700 +               ret = __vc_get_iattr(path.dentry->d_inode,
19701 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19702 +               path_put(&path);
19703 +       }
19704 +       if (ret)
19705 +               return ret;
19706 +
19707 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19708 +               ret = -EFAULT;
19709 +       return ret;
19710 +}
19711 +
19712 +#ifdef CONFIG_COMPAT
19713 +
19714 +int vc_get_iattr_x32(void __user *data)
19715 +{
19716 +       struct path path;
19717 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19718 +       int ret;
19719 +
19720 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19721 +               return -EFAULT;
19722 +
19723 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19724 +       if (!ret) {
19725 +               ret = __vc_get_iattr(path.dentry->d_inode,
19726 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19727 +               path_put(&path);
19728 +       }
19729 +       if (ret)
19730 +               return ret;
19731 +
19732 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19733 +               ret = -EFAULT;
19734 +       return ret;
19735 +}
19736 +
19737 +#endif /* CONFIG_COMPAT */
19738 +
19739 +
19740 +int vc_fget_iattr(uint32_t fd, void __user *data)
19741 +{
19742 +       struct file *filp;
19743 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19744 +       int ret;
19745 +
19746 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19747 +               return -EFAULT;
19748 +
19749 +       filp = fget(fd);
19750 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19751 +               return -EBADF;
19752 +
19753 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19754 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19755 +
19756 +       fput(filp);
19757 +
19758 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19759 +               ret = -EFAULT;
19760 +       return ret;
19761 +}
19762 +
19763 +
19764 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19765 +{
19766 +       struct inode *in = de->d_inode;
19767 +       int error = 0, is_proc = 0, has_tag = 0;
19768 +       struct iattr attr = { 0 };
19769 +
19770 +       if (!in || !in->i_sb)
19771 +               return -ESRCH;
19772 +
19773 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19774 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19775 +               return -EINVAL;
19776 +
19777 +       has_tag = IS_TAGGED(in) ||
19778 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19779 +       if ((*mask & IATTR_TAG) && !has_tag)
19780 +               return -EINVAL;
19781 +
19782 +       mutex_lock(&in->i_mutex);
19783 +       if (*mask & IATTR_TAG) {
19784 +               attr.ia_tag = *tag;
19785 +               attr.ia_valid |= ATTR_TAG;
19786 +       }
19787 +
19788 +       if (*mask & IATTR_FLAGS) {
19789 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19790 +               unsigned int iflags = PROC_I(in)->vx_flags;
19791 +
19792 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19793 +                       | (*flags & IATTR_FLAGS);
19794 +               PROC_I(in)->vx_flags = iflags;
19795 +               if (entry)
19796 +                       entry->vx_flags = iflags;
19797 +       }
19798 +
19799 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19800 +               IATTR_BARRIER | IATTR_COW)) {
19801 +               int iflags = in->i_flags;
19802 +               int vflags = in->i_vflags;
19803 +
19804 +               if (*mask & IATTR_IMMUTABLE) {
19805 +                       if (*flags & IATTR_IMMUTABLE)
19806 +                               iflags |= S_IMMUTABLE;
19807 +                       else
19808 +                               iflags &= ~S_IMMUTABLE;
19809 +               }
19810 +               if (*mask & IATTR_IXUNLINK) {
19811 +                       if (*flags & IATTR_IXUNLINK)
19812 +                               iflags |= S_IXUNLINK;
19813 +                       else
19814 +                               iflags &= ~S_IXUNLINK;
19815 +               }
19816 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19817 +                       if (*flags & IATTR_BARRIER)
19818 +                               vflags |= V_BARRIER;
19819 +                       else
19820 +                               vflags &= ~V_BARRIER;
19821 +               }
19822 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19823 +                       if (*flags & IATTR_COW)
19824 +                               vflags |= V_COW;
19825 +                       else
19826 +                               vflags &= ~V_COW;
19827 +               }
19828 +               if (in->i_op && in->i_op->sync_flags) {
19829 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19830 +                       if (error)
19831 +                               goto out;
19832 +               }
19833 +       }
19834 +
19835 +       if (attr.ia_valid) {
19836 +               if (in->i_op && in->i_op->setattr)
19837 +                       error = in->i_op->setattr(de, &attr);
19838 +               else {
19839 +                       error = inode_change_ok(in, &attr);
19840 +                       if (!error)
19841 +                               error = inode_setattr(in, &attr);
19842 +               }
19843 +       }
19844 +
19845 +out:
19846 +       mutex_unlock(&in->i_mutex);
19847 +       return error;
19848 +}
19849 +
19850 +int vc_set_iattr(void __user *data)
19851 +{
19852 +       struct path path;
19853 +       struct vcmd_ctx_iattr_v1 vc_data;
19854 +       int ret;
19855 +
19856 +       if (!capable(CAP_LINUX_IMMUTABLE))
19857 +               return -EPERM;
19858 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19859 +               return -EFAULT;
19860 +
19861 +       ret = user_lpath(vc_data.name, &path);
19862 +       if (!ret) {
19863 +               ret = __vc_set_iattr(path.dentry,
19864 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19865 +               path_put(&path);
19866 +       }
19867 +
19868 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19869 +               ret = -EFAULT;
19870 +       return ret;
19871 +}
19872 +
19873 +#ifdef CONFIG_COMPAT
19874 +
19875 +int vc_set_iattr_x32(void __user *data)
19876 +{
19877 +       struct path path;
19878 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19879 +       int ret;
19880 +
19881 +       if (!capable(CAP_LINUX_IMMUTABLE))
19882 +               return -EPERM;
19883 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19884 +               return -EFAULT;
19885 +
19886 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19887 +       if (!ret) {
19888 +               ret = __vc_set_iattr(path.dentry,
19889 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19890 +               path_put(&path);
19891 +       }
19892 +
19893 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19894 +               ret = -EFAULT;
19895 +       return ret;
19896 +}
19897 +
19898 +#endif /* CONFIG_COMPAT */
19899 +
19900 +int vc_fset_iattr(uint32_t fd, void __user *data)
19901 +{
19902 +       struct file *filp;
19903 +       struct vcmd_ctx_fiattr_v0 vc_data;
19904 +       int ret;
19905 +
19906 +       if (!capable(CAP_LINUX_IMMUTABLE))
19907 +               return -EPERM;
19908 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19909 +               return -EFAULT;
19910 +
19911 +       filp = fget(fd);
19912 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19913 +               return -EBADF;
19914 +
19915 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19916 +               &vc_data.flags, &vc_data.mask);
19917 +
19918 +       fput(filp);
19919 +
19920 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19921 +               return -EFAULT;
19922 +       return ret;
19923 +}
19924 +
19925 +
19926 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19927 +
19928 +static match_table_t tokens = {
19929 +       {Opt_notagcheck, "notagcheck"},
19930 +#ifdef CONFIG_PROPAGATE
19931 +       {Opt_notag, "notag"},
19932 +       {Opt_tag, "tag"},
19933 +       {Opt_tagid, "tagid=%u"},
19934 +#endif
19935 +       {Opt_err, NULL}
19936 +};
19937 +
19938 +
19939 +static void __dx_parse_remove(char *string, char *opt)
19940 +{
19941 +       char *p = strstr(string, opt);
19942 +       char *q = p;
19943 +
19944 +       if (p) {
19945 +               while (*q != '\0' && *q != ',')
19946 +                       q++;
19947 +               while (*q)
19948 +                       *p++ = *q++;
19949 +               while (*p)
19950 +                       *p++ = '\0';
19951 +       }
19952 +}
19953 +
19954 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19955 +                unsigned long *flags)
19956 +{
19957 +       int set = 0;
19958 +       substring_t args[MAX_OPT_ARGS];
19959 +       int token, option = 0;
19960 +       char *s, *p, *opts;
19961 +
19962 +       if (!string)
19963 +               return 0;
19964 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19965 +       if (!s)
19966 +               return 0;
19967 +
19968 +       opts = s;
19969 +       while ((p = strsep(&opts, ",")) != NULL) {
19970 +               token = match_token(p, tokens, args);
19971 +
19972 +               vxdprintk(VXD_CBIT(tag, 7),
19973 +                       "dx_parse_tag(»%s«): %d:#%d",
19974 +                       p, token, option);
19975 +
19976 +               switch (token) {
19977 +#ifdef CONFIG_PROPAGATE
19978 +               case Opt_tag:
19979 +                       if (tag)
19980 +                               *tag = 0;
19981 +                       if (remove)
19982 +                               __dx_parse_remove(s, "tag");
19983 +                       *mnt_flags |= MNT_TAGID;
19984 +                       set |= MNT_TAGID;
19985 +                       break;
19986 +               case Opt_notag:
19987 +                       if (remove)
19988 +                               __dx_parse_remove(s, "notag");
19989 +                       *mnt_flags |= MNT_NOTAG;
19990 +                       set |= MNT_NOTAG;
19991 +                       break;
19992 +               case Opt_tagid:
19993 +                       if (tag && !match_int(args, &option))
19994 +                               *tag = option;
19995 +                       if (remove)
19996 +                               __dx_parse_remove(s, "tagid");
19997 +                       *mnt_flags |= MNT_TAGID;
19998 +                       set |= MNT_TAGID;
19999 +                       break;
20000 +#endif
20001 +               case Opt_notagcheck:
20002 +                       if (remove)
20003 +                               __dx_parse_remove(s, "notagcheck");
20004 +                       *flags |= MS_NOTAGCHECK;
20005 +                       set |= MS_NOTAGCHECK;
20006 +                       break;
20007 +               }
20008 +       }
20009 +       if (set)
20010 +               strcpy(string, s);
20011 +       kfree(s);
20012 +       return set;
20013 +}
20014 +
20015 +#ifdef CONFIG_PROPAGATE
20016 +
20017 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20018 +{
20019 +       tag_t new_tag = 0;
20020 +       struct vfsmount *mnt;
20021 +       int propagate;
20022 +
20023 +       if (!nd)
20024 +               return;
20025 +       mnt = nd->path.mnt;
20026 +       if (!mnt)
20027 +               return;
20028 +
20029 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20030 +       if (propagate)
20031 +               new_tag = mnt->mnt_tag;
20032 +
20033 +       vxdprintk(VXD_CBIT(tag, 7),
20034 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20035 +               inode, inode->i_ino, inode->i_tag,
20036 +               new_tag, (propagate) ? 1 : 0);
20037 +
20038 +       if (propagate)
20039 +               inode->i_tag = new_tag;
20040 +}
20041 +
20042 +#include <linux/module.h>
20043 +
20044 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20045 +
20046 +#endif /* CONFIG_PROPAGATE */
20047 +
20048 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/Kconfig linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/Kconfig
20049 --- linux-2.6.35.4/kernel/vserver/Kconfig       1970-01-01 01:00:00.000000000 +0100
20050 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/Kconfig 2010-08-02 17:05:06.000000000 +0200
20051 @@ -0,0 +1,260 @@
20052 +#
20053 +# Linux VServer configuration
20054 +#
20055 +
20056 +menu "Linux VServer"
20057 +
20058 +config VSERVER_AUTO_LBACK
20059 +       bool    "Automatically Assign Loopback IP"
20060 +       default y
20061 +       help
20062 +         Automatically assign a guest specific loopback
20063 +         IP and add it to the kernel network stack on
20064 +         startup.
20065 +
20066 +config VSERVER_AUTO_SINGLE
20067 +       bool    "Automatic Single IP Special Casing"
20068 +       depends on EXPERIMENTAL
20069 +       default y
20070 +       help
20071 +         This allows network contexts with a single IP to
20072 +         automatically remap 0.0.0.0 bindings to that IP,
20073 +         avoiding further network checks and improving
20074 +         performance.
20075 +
20076 +         (note: such guests do not allow to change the ip
20077 +          on the fly and do not show loopback addresses)
20078 +
20079 +config VSERVER_COWBL
20080 +       bool    "Enable COW Immutable Link Breaking"
20081 +       default y
20082 +       help
20083 +         This enables the COW (Copy-On-Write) link break code.
20084 +         It allows you to treat unified files like normal files
20085 +         when writing to them (which will implicitely break the
20086 +         link and create a copy of the unified file)
20087 +
20088 +config VSERVER_VTIME
20089 +       bool    "Enable Virtualized Guest Time"
20090 +       depends on EXPERIMENTAL
20091 +       default n
20092 +       help
20093 +         This enables per guest time offsets to allow for
20094 +         adjusting the system clock individually per guest.
20095 +         this adds some overhead to the time functions and
20096 +         therefore should not be enabled without good reason.
20097 +
20098 +config VSERVER_DEVICE
20099 +       bool    "Enable Guest Device Mapping"
20100 +       depends on EXPERIMENTAL
20101 +       default n
20102 +       help
20103 +         This enables generic device remapping.
20104 +
20105 +config VSERVER_PROC_SECURE
20106 +       bool    "Enable Proc Security"
20107 +       depends on PROC_FS
20108 +       default y
20109 +       help
20110 +         This configures ProcFS security to initially hide
20111 +         non-process entries for all contexts except the main and
20112 +         spectator context (i.e. for all guests), which is a secure
20113 +         default.
20114 +
20115 +         (note: on 1.2x the entries were visible by default)
20116 +
20117 +config VSERVER_HARDCPU
20118 +       bool    "Enable Hard CPU Limits"
20119 +       default y
20120 +       help
20121 +         Activate the Hard CPU Limits
20122 +
20123 +         This will compile in code that allows the Token Bucket
20124 +         Scheduler to put processes on hold when a context's
20125 +         tokens are depleted (provided that its per-context
20126 +         sched_hard flag is set).
20127 +
20128 +         Processes belonging to that context will not be able
20129 +         to consume CPU resources again until a per-context
20130 +         configured minimum of tokens has been reached.
20131 +
20132 +config VSERVER_IDLETIME
20133 +       bool    "Avoid idle CPUs by skipping Time"
20134 +       depends on VSERVER_HARDCPU
20135 +       default y
20136 +       help
20137 +         This option allows the scheduler to artificially
20138 +         advance time (per cpu) when otherwise the idle
20139 +         task would be scheduled, thus keeping the cpu
20140 +         busy and sharing the available resources among
20141 +         certain contexts.
20142 +
20143 +config VSERVER_IDLELIMIT
20144 +       bool    "Limit the IDLE task"
20145 +       depends on VSERVER_HARDCPU
20146 +       default n
20147 +       help
20148 +         Limit the idle slices, so the the next context
20149 +         will be scheduled as soon as possible.
20150 +
20151 +         This might improve interactivity and latency, but
20152 +         will also marginally increase scheduling overhead.
20153 +
20154 +choice
20155 +       prompt  "Persistent Inode Tagging"
20156 +       default TAGGING_ID24
20157 +       help
20158 +         This adds persistent context information to filesystems
20159 +         mounted with the tagxid option. Tagging is a requirement
20160 +         for per-context disk limits and per-context quota.
20161 +
20162 +
20163 +config TAGGING_NONE
20164 +       bool    "Disabled"
20165 +       help
20166 +         do not store per-context information in inodes.
20167 +
20168 +config TAGGING_UID16
20169 +       bool    "UID16/GID32"
20170 +       help
20171 +         reduces UID to 16 bit, but leaves GID at 32 bit.
20172 +
20173 +config TAGGING_GID16
20174 +       bool    "UID32/GID16"
20175 +       help
20176 +         reduces GID to 16 bit, but leaves UID at 32 bit.
20177 +
20178 +config TAGGING_ID24
20179 +       bool    "UID24/GID24"
20180 +       help
20181 +         uses the upper 8bit from UID and GID for XID tagging
20182 +         which leaves 24bit for UID/GID each, which should be
20183 +         more than sufficient for normal use.
20184 +
20185 +config TAGGING_INTERN
20186 +       bool    "UID32/GID32"
20187 +       help
20188 +         this uses otherwise reserved inode fields in the on
20189 +         disk representation, which limits the use to a few
20190 +         filesystems (currently ext2 and ext3)
20191 +
20192 +endchoice
20193 +
20194 +config TAG_NFSD
20195 +       bool    "Tag NFSD User Auth and Files"
20196 +       default n
20197 +       help
20198 +         Enable this if you do want the in-kernel NFS
20199 +         Server to use the tagging specified above.
20200 +         (will require patched clients too)
20201 +
20202 +config VSERVER_PRIVACY
20203 +       bool    "Honor Privacy Aspects of Guests"
20204 +       default n
20205 +       help
20206 +         When enabled, most context checks will disallow
20207 +         access to structures assigned to a specific context,
20208 +         like ptys or loop devices.
20209 +
20210 +config VSERVER_CONTEXTS
20211 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
20212 +       range 1 65533
20213 +       default "768"   if 64BIT
20214 +       default "256"
20215 +       help
20216 +         This setting will optimize certain data structures
20217 +         and memory allocations according to the expected
20218 +         maximum.
20219 +
20220 +         note: this is not a strict upper limit.
20221 +
20222 +config VSERVER_WARN
20223 +       bool    "VServer Warnings"
20224 +       default y
20225 +       help
20226 +         This enables various runtime warnings, which will
20227 +         notify about potential manipulation attempts or
20228 +         resource shortage. It is generally considered to
20229 +         be a good idea to have that enabled.
20230 +
20231 +config VSERVER_DEBUG
20232 +       bool    "VServer Debugging Code"
20233 +       default n
20234 +       help
20235 +         Set this to yes if you want to be able to activate
20236 +         debugging output at runtime. It adds a very small
20237 +         overhead to all vserver related functions and
20238 +         increases the kernel size by about 20k.
20239 +
20240 +config VSERVER_HISTORY
20241 +       bool    "VServer History Tracing"
20242 +       depends on VSERVER_DEBUG
20243 +       default n
20244 +       help
20245 +         Set this to yes if you want to record the history of
20246 +         linux-vserver activities, so they can be replayed in
20247 +         the event of a kernel panic or oops.
20248 +
20249 +config VSERVER_HISTORY_SIZE
20250 +       int     "Per-CPU History Size (32-65536)"
20251 +       depends on VSERVER_HISTORY
20252 +       range 32 65536
20253 +       default 64
20254 +       help
20255 +         This allows you to specify the number of entries in
20256 +         the per-CPU history buffer.
20257 +
20258 +config VSERVER_MONITOR
20259 +       bool    "VServer Scheduling Monitor"
20260 +       depends on VSERVER_DISABLED
20261 +       default n
20262 +       help
20263 +         Set this to yes if you want to record the scheduling
20264 +         decisions, so that they can be relayed to userspace
20265 +         for detailed analysis.
20266 +
20267 +config VSERVER_MONITOR_SIZE
20268 +       int     "Per-CPU Monitor Queue Size (32-65536)"
20269 +       depends on VSERVER_MONITOR
20270 +       range 32 65536
20271 +       default 1024
20272 +       help
20273 +         This allows you to specify the number of entries in
20274 +         the per-CPU scheduling monitor buffer.
20275 +
20276 +config VSERVER_MONITOR_SYNC
20277 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
20278 +       depends on VSERVER_MONITOR
20279 +       range 0 65536
20280 +       default 256
20281 +       help
20282 +         This allows you to specify the interval in ticks
20283 +         when a time sync entry is inserted.
20284 +
20285 +config VSERVER_LEGACY_MEM
20286 +       bool    "Legacy Memory Limits"
20287 +       default n
20288 +       help
20289 +         This provides fake memory limits to keep
20290 +         older tools happy in the face of memory
20291 +         cgroups
20292 +
20293 +
20294 +endmenu
20295 +
20296 +
20297 +config VSERVER
20298 +       bool
20299 +       default y
20300 +       select NAMESPACES
20301 +       select UTS_NS
20302 +       select IPC_NS
20303 +       select USER_NS
20304 +       select SYSVIPC
20305 +
20306 +config VSERVER_SECURITY
20307 +       bool
20308 +       depends on SECURITY
20309 +       default y
20310 +       select SECURITY_CAPABILITIES
20311 +
20312 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/limit.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/limit.c
20313 --- linux-2.6.35.4/kernel/vserver/limit.c       1970-01-01 01:00:00.000000000 +0100
20314 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/limit.c 2010-08-02 17:05:06.000000000 +0200
20315 @@ -0,0 +1,354 @@
20316 +/*
20317 + *  linux/kernel/vserver/limit.c
20318 + *
20319 + *  Virtual Server: Context Limits
20320 + *
20321 + *  Copyright (C) 2004-2010  Herbert Pötzl
20322 + *
20323 + *  V0.01  broken out from vcontext V0.05
20324 + *  V0.02  changed vcmds to vxi arg
20325 + *  V0.03  added memory cgroup support
20326 + *
20327 + */
20328 +
20329 +#include <linux/sched.h>
20330 +#include <linux/module.h>
20331 +#include <linux/memcontrol.h>
20332 +#include <linux/res_counter.h>
20333 +#include <linux/vs_limit.h>
20334 +#include <linux/vserver/limit.h>
20335 +#include <linux/vserver/limit_cmd.h>
20336 +
20337 +#include <asm/uaccess.h>
20338 +
20339 +
20340 +const char *vlimit_name[NUM_LIMITS] = {
20341 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20342 +       [RLIMIT_RSS]            = "RSS",
20343 +       [RLIMIT_AS]             = "VM",
20344 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20345 +       [RLIMIT_CPU]            = "CPU",
20346 +       [RLIMIT_NPROC]          = "NPROC",
20347 +       [RLIMIT_NOFILE]         = "NOFILE",
20348 +       [RLIMIT_LOCKS]          = "LOCKS",
20349 +       [RLIMIT_SIGPENDING]     = "SIGP",
20350 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20351 +
20352 +       [VLIMIT_NSOCK]          = "NSOCK",
20353 +       [VLIMIT_OPENFD]         = "OPENFD",
20354 +       [VLIMIT_SHMEM]          = "SHMEM",
20355 +       [VLIMIT_DENTRY]         = "DENTRY",
20356 +};
20357 +
20358 +EXPORT_SYMBOL_GPL(vlimit_name);
20359 +
20360 +#define MASK_ENTRY(x)  (1 << (x))
20361 +
20362 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20363 +               /* minimum */
20364 +       0
20365 +       ,       /* softlimit */
20366 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20367 +       MASK_ENTRY( RLIMIT_RSS          ) |
20368 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20369 +       0
20370 +       ,       /* maximum */
20371 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20372 +       MASK_ENTRY( RLIMIT_RSS          ) |
20373 +       MASK_ENTRY( RLIMIT_AS           ) |
20374 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20375 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20376 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20377 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20378 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20379 +
20380 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20381 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20382 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20383 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20384 +       0
20385 +};
20386 +               /* accounting only */
20387 +uint32_t account_mask =
20388 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20389 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20390 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20391 +       0;
20392 +
20393 +
20394 +static int is_valid_vlimit(int id)
20395 +{
20396 +       uint32_t mask = vlimit_mask.minimum |
20397 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20398 +       return mask & (1 << id);
20399 +}
20400 +
20401 +static int is_accounted_vlimit(int id)
20402 +{
20403 +       if (is_valid_vlimit(id))
20404 +               return 1;
20405 +       return account_mask & (1 << id);
20406 +}
20407 +
20408 +
20409 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20410 +{
20411 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20412 +       return VX_VLIM(limit);
20413 +}
20414 +
20415 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20416 +{
20417 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20418 +       return VX_VLIM(limit);
20419 +}
20420 +
20421 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20422 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20423 +{
20424 +       if (!is_valid_vlimit(id))
20425 +               return -EINVAL;
20426 +
20427 +       if (minimum)
20428 +               *minimum = CRLIM_UNSET;
20429 +       if (softlimit)
20430 +               *softlimit = vc_get_soft(vxi, id);
20431 +       if (maximum)
20432 +               *maximum = vc_get_hard(vxi, id);
20433 +       return 0;
20434 +}
20435 +
20436 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20437 +{
20438 +       struct vcmd_ctx_rlimit_v0 vc_data;
20439 +       int ret;
20440 +
20441 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20442 +               return -EFAULT;
20443 +
20444 +       ret = do_get_rlimit(vxi, vc_data.id,
20445 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20446 +       if (ret)
20447 +               return ret;
20448 +
20449 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20450 +               return -EFAULT;
20451 +       return 0;
20452 +}
20453 +
20454 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20455 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20456 +{
20457 +       if (!is_valid_vlimit(id))
20458 +               return -EINVAL;
20459 +
20460 +       if (maximum != CRLIM_KEEP)
20461 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20462 +       if (softlimit != CRLIM_KEEP)
20463 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20464 +
20465 +       /* clamp soft limit */
20466 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20467 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20468 +
20469 +       return 0;
20470 +}
20471 +
20472 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20473 +{
20474 +       struct vcmd_ctx_rlimit_v0 vc_data;
20475 +
20476 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20477 +               return -EFAULT;
20478 +
20479 +       return do_set_rlimit(vxi, vc_data.id,
20480 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20481 +}
20482 +
20483 +#ifdef CONFIG_IA32_EMULATION
20484 +
20485 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20486 +{
20487 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20488 +
20489 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20490 +               return -EFAULT;
20491 +
20492 +       return do_set_rlimit(vxi, vc_data.id,
20493 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20494 +}
20495 +
20496 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20497 +{
20498 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20499 +       int ret;
20500 +
20501 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20502 +               return -EFAULT;
20503 +
20504 +       ret = do_get_rlimit(vxi, vc_data.id,
20505 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20506 +       if (ret)
20507 +               return ret;
20508 +
20509 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20510 +               return -EFAULT;
20511 +       return 0;
20512 +}
20513 +
20514 +#endif /* CONFIG_IA32_EMULATION */
20515 +
20516 +
20517 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20518 +{
20519 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20520 +               return -EFAULT;
20521 +       return 0;
20522 +}
20523 +
20524 +
20525 +static inline void vx_reset_hits(struct _vx_limit *limit)
20526 +{
20527 +       int lim;
20528 +
20529 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20530 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20531 +       }
20532 +}
20533 +
20534 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20535 +{
20536 +       vx_reset_hits(&vxi->limit);
20537 +       return 0;
20538 +}
20539 +
20540 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20541 +{
20542 +       rlim_t value;
20543 +       int lim;
20544 +
20545 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20546 +               value = __rlim_get(limit, lim);
20547 +               __rlim_rmax(limit, lim) = value;
20548 +               __rlim_rmin(limit, lim) = value;
20549 +       }
20550 +}
20551 +
20552 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20553 +{
20554 +       vx_reset_minmax(&vxi->limit);
20555 +       return 0;
20556 +}
20557 +
20558 +
20559 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20560 +{
20561 +       struct vcmd_rlimit_stat_v0 vc_data;
20562 +       struct _vx_limit *limit = &vxi->limit;
20563 +       int id;
20564 +
20565 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20566 +               return -EFAULT;
20567 +
20568 +       id = vc_data.id;
20569 +       if (!is_accounted_vlimit(id))
20570 +               return -EINVAL;
20571 +
20572 +       vx_limit_fixup(limit, id);
20573 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20574 +       vc_data.value = __rlim_get(limit, id);
20575 +       vc_data.minimum = __rlim_rmin(limit, id);
20576 +       vc_data.maximum = __rlim_rmax(limit, id);
20577 +
20578 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20579 +               return -EFAULT;
20580 +       return 0;
20581 +}
20582 +
20583 +
20584 +void vx_vsi_meminfo(struct sysinfo *val)
20585 +{
20586 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20587 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20588 +       u64 res_limit, res_usage;
20589 +
20590 +       if (!mcg)
20591 +               return;
20592 +
20593 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20594 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20595 +
20596 +       if (res_limit != RESOURCE_MAX)
20597 +               val->totalram = (res_limit >> PAGE_SHIFT);
20598 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20599 +       val->bufferram = 0;
20600 +       val->totalhigh = 0;
20601 +       val->freehigh = 0;
20602 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20603 +       return;
20604 +}
20605 +
20606 +void vx_vsi_swapinfo(struct sysinfo *val)
20607 +{
20608 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20609 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20610 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20611 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20612 +       s64 swap_limit, swap_usage;
20613 +
20614 +       if (!mcg)
20615 +               return;
20616 +
20617 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20618 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20619 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20620 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20621 +
20622 +       if (res_limit == RESOURCE_MAX)
20623 +               return;
20624 +
20625 +       swap_limit = memsw_limit - res_limit;
20626 +       if (memsw_limit != RESOURCE_MAX)
20627 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20628 +
20629 +       swap_usage = memsw_usage - res_usage;
20630 +       val->freeswap = (swap_usage < swap_limit) ?
20631 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20632 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20633 +       val->totalswap = 0;
20634 +       val->freeswap = 0;
20635 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20636 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20637 +       return;
20638 +}
20639 +
20640 +long vx_vsi_cached(struct sysinfo *val)
20641 +{
20642 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20643 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20644 +
20645 +       return mem_cgroup_stat_read_cache(mcg);
20646 +#else
20647 +       return 0;
20648 +#endif
20649 +}
20650 +
20651 +
20652 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20653 +{
20654 +       struct vx_info *vxi = mm->mm_vx_info;
20655 +       unsigned long points;
20656 +       rlim_t v, w;
20657 +
20658 +       if (!vxi)
20659 +               return 0;
20660 +
20661 +       points = vxi->vx_badness_bias;
20662 +
20663 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20664 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20665 +       points += (v > w) ? (v - w) : 0;
20666 +
20667 +       return points;
20668 +}
20669 +
20670 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/limit_init.h linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/limit_init.h
20671 --- linux-2.6.35.4/kernel/vserver/limit_init.h  1970-01-01 01:00:00.000000000 +0100
20672 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/limit_init.h    2010-08-02 17:05:06.000000000 +0200
20673 @@ -0,0 +1,31 @@
20674 +
20675 +
20676 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20677 +{
20678 +       int lim;
20679 +
20680 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20681 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20682 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20683 +               __rlim_set(limit, lim, 0);
20684 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20685 +               __rlim_rmin(limit, lim) = 0;
20686 +               __rlim_rmax(limit, lim) = 0;
20687 +       }
20688 +}
20689 +
20690 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20691 +{
20692 +       rlim_t value;
20693 +       int lim;
20694 +
20695 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20696 +               if ((1 << lim) & VLIM_NOCHECK)
20697 +                       continue;
20698 +               value = __rlim_get(limit, lim);
20699 +               vxwprintk_xid(value,
20700 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20701 +                       limit, vlimit_name[lim], lim, (long)value);
20702 +       }
20703 +}
20704 +
20705 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/limit_proc.h linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/limit_proc.h
20706 --- linux-2.6.35.4/kernel/vserver/limit_proc.h  1970-01-01 01:00:00.000000000 +0100
20707 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/limit_proc.h    2010-08-02 17:05:06.000000000 +0200
20708 @@ -0,0 +1,57 @@
20709 +#ifndef _VX_LIMIT_PROC_H
20710 +#define _VX_LIMIT_PROC_H
20711 +
20712 +#include <linux/vserver/limit_int.h>
20713 +
20714 +
20715 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20716 +#define VX_LIMIT_TOP   \
20717 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20718 +
20719 +#define VX_LIMIT_ARG(r)                                \
20720 +       (unsigned long)__rlim_get(limit, r),    \
20721 +       (unsigned long)__rlim_rmin(limit, r),   \
20722 +       (unsigned long)__rlim_rmax(limit, r),   \
20723 +       VX_VLIM(__rlim_soft(limit, r)),         \
20724 +       VX_VLIM(__rlim_hard(limit, r)),         \
20725 +       atomic_read(&__rlim_lhit(limit, r))
20726 +
20727 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20728 +{
20729 +       vx_limit_fixup(limit, -1);
20730 +       return sprintf(buffer, VX_LIMIT_TOP
20731 +               "PROC"  VX_LIMIT_FMT
20732 +               "VM"    VX_LIMIT_FMT
20733 +               "VML"   VX_LIMIT_FMT
20734 +               "RSS"   VX_LIMIT_FMT
20735 +               "ANON"  VX_LIMIT_FMT
20736 +               "RMAP"  VX_LIMIT_FMT
20737 +               "FILES" VX_LIMIT_FMT
20738 +               "OFD"   VX_LIMIT_FMT
20739 +               "LOCKS" VX_LIMIT_FMT
20740 +               "SOCK"  VX_LIMIT_FMT
20741 +               "MSGQ"  VX_LIMIT_FMT
20742 +               "SHM"   VX_LIMIT_FMT
20743 +               "SEMA"  VX_LIMIT_FMT
20744 +               "SEMS"  VX_LIMIT_FMT
20745 +               "DENT"  VX_LIMIT_FMT,
20746 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20747 +               VX_LIMIT_ARG(RLIMIT_AS),
20748 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20749 +               VX_LIMIT_ARG(RLIMIT_RSS),
20750 +               VX_LIMIT_ARG(VLIMIT_ANON),
20751 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20752 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20753 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20754 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20755 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20756 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20757 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20758 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20759 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20760 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20761 +}
20762 +
20763 +#endif /* _VX_LIMIT_PROC_H */
20764 +
20765 +
20766 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/Makefile linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/Makefile
20767 --- linux-2.6.35.4/kernel/vserver/Makefile      1970-01-01 01:00:00.000000000 +0100
20768 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/Makefile        2010-08-02 17:05:06.000000000 +0200
20769 @@ -0,0 +1,18 @@
20770 +#
20771 +# Makefile for the Linux vserver routines.
20772 +#
20773 +
20774 +
20775 +obj-y          += vserver.o
20776 +
20777 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
20778 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
20779 +                  dlimit.o tag.o
20780 +
20781 +vserver-$(CONFIG_INET) += inet.o
20782 +vserver-$(CONFIG_PROC_FS) += proc.o
20783 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
20784 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
20785 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
20786 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
20787 +
20788 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/monitor.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/monitor.c
20789 --- linux-2.6.35.4/kernel/vserver/monitor.c     1970-01-01 01:00:00.000000000 +0100
20790 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/monitor.c       2010-08-02 17:05:06.000000000 +0200
20791 @@ -0,0 +1,138 @@
20792 +/*
20793 + *  kernel/vserver/monitor.c
20794 + *
20795 + *  Virtual Context Scheduler Monitor
20796 + *
20797 + *  Copyright (C) 2006-2007 Herbert Pötzl
20798 + *
20799 + *  V0.01  basic design
20800 + *
20801 + */
20802 +
20803 +#include <linux/module.h>
20804 +#include <linux/jiffies.h>
20805 +#include <asm/uaccess.h>
20806 +#include <asm/atomic.h>
20807 +
20808 +#include <linux/vserver/monitor.h>
20809 +#include <linux/vserver/debug_cmd.h>
20810 +
20811 +
20812 +#ifdef CONFIG_VSERVER_MONITOR
20813 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
20814 +#else
20815 +#define VXM_SIZE       64
20816 +#endif
20817 +
20818 +struct _vx_monitor {
20819 +       unsigned int counter;
20820 +
20821 +       struct _vx_mon_entry entry[VXM_SIZE+1];
20822 +};
20823 +
20824 +
20825 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
20826 +
20827 +unsigned volatile int vxm_active = 1;
20828 +
20829 +static atomic_t sequence = ATOMIC_INIT(0);
20830 +
20831 +
20832 +/*     vxm_advance()
20833 +
20834 +       * requires disabled preemption                          */
20835 +
20836 +struct _vx_mon_entry *vxm_advance(int cpu)
20837 +{
20838 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
20839 +       struct _vx_mon_entry *entry;
20840 +       unsigned int index;
20841 +
20842 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
20843 +       entry = &mon->entry[index];
20844 +
20845 +       entry->ev.seq = atomic_inc_return(&sequence);
20846 +       entry->ev.jif = jiffies;
20847 +       return entry;
20848 +}
20849 +
20850 +EXPORT_SYMBOL_GPL(vxm_advance);
20851 +
20852 +
20853 +int do_read_monitor(struct __user _vx_mon_entry *data,
20854 +       int cpu, uint32_t *index, uint32_t *count)
20855 +{
20856 +       int pos, ret = 0;
20857 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
20858 +       int end = mon->counter;
20859 +       int start = end - VXM_SIZE + 2;
20860 +       int idx = *index;
20861 +
20862 +       /* special case: get current pos */
20863 +       if (!*count) {
20864 +               *index = end;
20865 +               return 0;
20866 +       }
20867 +
20868 +       /* have we lost some data? */
20869 +       if (idx < start)
20870 +               idx = start;
20871 +
20872 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20873 +               struct _vx_mon_entry *entry =
20874 +                       &mon->entry[idx % VXM_SIZE];
20875 +
20876 +               /* send entry to userspace */
20877 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20878 +               if (ret)
20879 +                       break;
20880 +       }
20881 +       /* save new index and count */
20882 +       *index = idx;
20883 +       *count = pos;
20884 +       return ret ? ret : (*index < end);
20885 +}
20886 +
20887 +int vc_read_monitor(uint32_t id, void __user *data)
20888 +{
20889 +       struct vcmd_read_monitor_v0 vc_data;
20890 +       int ret;
20891 +
20892 +       if (id >= NR_CPUS)
20893 +               return -EINVAL;
20894 +
20895 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20896 +               return -EFAULT;
20897 +
20898 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
20899 +               id, &vc_data.index, &vc_data.count);
20900 +
20901 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20902 +               return -EFAULT;
20903 +       return ret;
20904 +}
20905 +
20906 +#ifdef CONFIG_COMPAT
20907 +
20908 +int vc_read_monitor_x32(uint32_t id, void __user *data)
20909 +{
20910 +       struct vcmd_read_monitor_v0_x32 vc_data;
20911 +       int ret;
20912 +
20913 +       if (id >= NR_CPUS)
20914 +               return -EINVAL;
20915 +
20916 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20917 +               return -EFAULT;
20918 +
20919 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
20920 +               compat_ptr(vc_data.data_ptr),
20921 +               id, &vc_data.index, &vc_data.count);
20922 +
20923 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20924 +               return -EFAULT;
20925 +       return ret;
20926 +}
20927 +
20928 +#endif /* CONFIG_COMPAT */
20929 +
20930 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/network.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/network.c
20931 --- linux-2.6.35.4/kernel/vserver/network.c     1970-01-01 01:00:00.000000000 +0100
20932 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/network.c       2010-08-02 17:05:06.000000000 +0200
20933 @@ -0,0 +1,864 @@
20934 +/*
20935 + *  linux/kernel/vserver/network.c
20936 + *
20937 + *  Virtual Server: Network Support
20938 + *
20939 + *  Copyright (C) 2003-2007  Herbert Pötzl
20940 + *
20941 + *  V0.01  broken out from vcontext V0.05
20942 + *  V0.02  cleaned up implementation
20943 + *  V0.03  added equiv nx commands
20944 + *  V0.04  switch to RCU based hash
20945 + *  V0.05  and back to locking again
20946 + *  V0.06  changed vcmds to nxi arg
20947 + *  V0.07  have __create claim() the nxi
20948 + *
20949 + */
20950 +
20951 +#include <linux/err.h>
20952 +#include <linux/slab.h>
20953 +#include <linux/rcupdate.h>
20954 +
20955 +#include <linux/vs_network.h>
20956 +#include <linux/vs_pid.h>
20957 +#include <linux/vserver/network_cmd.h>
20958 +
20959 +
20960 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20961 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20962 +
20963 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20964 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20965 +
20966 +
20967 +static int __init init_network(void)
20968 +{
20969 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20970 +               sizeof(struct nx_addr_v4), 0,
20971 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20972 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20973 +               sizeof(struct nx_addr_v6), 0,
20974 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20975 +       return 0;
20976 +}
20977 +
20978 +
20979 +/*     __alloc_nx_addr_v4()                                    */
20980 +
20981 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20982 +{
20983 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20984 +               nx_addr_v4_cachep, GFP_KERNEL);
20985 +
20986 +       if (!IS_ERR(nxa))
20987 +               memset(nxa, 0, sizeof(*nxa));
20988 +       return nxa;
20989 +}
20990 +
20991 +/*     __dealloc_nx_addr_v4()                                  */
20992 +
20993 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20994 +{
20995 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20996 +}
20997 +
20998 +/*     __dealloc_nx_addr_v4_all()                              */
20999 +
21000 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
21001 +{
21002 +       while (nxa) {
21003 +               struct nx_addr_v4 *next = nxa->next;
21004 +
21005 +               __dealloc_nx_addr_v4(nxa);
21006 +               nxa = next;
21007 +       }
21008 +}
21009 +
21010 +
21011 +#ifdef CONFIG_IPV6
21012 +
21013 +/*     __alloc_nx_addr_v6()                                    */
21014 +
21015 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
21016 +{
21017 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
21018 +               nx_addr_v6_cachep, GFP_KERNEL);
21019 +
21020 +       if (!IS_ERR(nxa))
21021 +               memset(nxa, 0, sizeof(*nxa));
21022 +       return nxa;
21023 +}
21024 +
21025 +/*     __dealloc_nx_addr_v6()                                  */
21026 +
21027 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
21028 +{
21029 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
21030 +}
21031 +
21032 +/*     __dealloc_nx_addr_v6_all()                              */
21033 +
21034 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
21035 +{
21036 +       while (nxa) {
21037 +               struct nx_addr_v6 *next = nxa->next;
21038 +
21039 +               __dealloc_nx_addr_v6(nxa);
21040 +               nxa = next;
21041 +       }
21042 +}
21043 +
21044 +#endif /* CONFIG_IPV6 */
21045 +
21046 +/*     __alloc_nx_info()
21047 +
21048 +       * allocate an initialized nx_info struct
21049 +       * doesn't make it visible (hash)                        */
21050 +
21051 +static struct nx_info *__alloc_nx_info(nid_t nid)
21052 +{
21053 +       struct nx_info *new = NULL;
21054 +
21055 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
21056 +
21057 +       /* would this benefit from a slab cache? */
21058 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
21059 +       if (!new)
21060 +               return 0;
21061 +
21062 +       memset(new, 0, sizeof(struct nx_info));
21063 +       new->nx_id = nid;
21064 +       INIT_HLIST_NODE(&new->nx_hlist);
21065 +       atomic_set(&new->nx_usecnt, 0);
21066 +       atomic_set(&new->nx_tasks, 0);
21067 +       new->nx_state = 0;
21068 +
21069 +       new->nx_flags = NXF_INIT_SET;
21070 +
21071 +       /* rest of init goes here */
21072 +
21073 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
21074 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
21075 +
21076 +       vxdprintk(VXD_CBIT(nid, 0),
21077 +               "alloc_nx_info(%d) = %p", nid, new);
21078 +       atomic_inc(&nx_global_ctotal);
21079 +       return new;
21080 +}
21081 +
21082 +/*     __dealloc_nx_info()
21083 +
21084 +       * final disposal of nx_info                             */
21085 +
21086 +static void __dealloc_nx_info(struct nx_info *nxi)
21087 +{
21088 +       vxdprintk(VXD_CBIT(nid, 0),
21089 +               "dealloc_nx_info(%p)", nxi);
21090 +
21091 +       nxi->nx_hlist.next = LIST_POISON1;
21092 +       nxi->nx_id = -1;
21093 +
21094 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21095 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21096 +
21097 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
21098 +
21099 +       nxi->nx_state |= NXS_RELEASED;
21100 +       kfree(nxi);
21101 +       atomic_dec(&nx_global_ctotal);
21102 +}
21103 +
21104 +static void __shutdown_nx_info(struct nx_info *nxi)
21105 +{
21106 +       nxi->nx_state |= NXS_SHUTDOWN;
21107 +       vs_net_change(nxi, VSC_NETDOWN);
21108 +}
21109 +
21110 +/*     exported stuff                                          */
21111 +
21112 +void free_nx_info(struct nx_info *nxi)
21113 +{
21114 +       /* context shutdown is mandatory */
21115 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
21116 +
21117 +       /* context must not be hashed */
21118 +       BUG_ON(nxi->nx_state & NXS_HASHED);
21119 +
21120 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21121 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21122 +
21123 +       __dealloc_nx_info(nxi);
21124 +}
21125 +
21126 +
21127 +void __nx_set_lback(struct nx_info *nxi)
21128 +{
21129 +       int nid = nxi->nx_id;
21130 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
21131 +
21132 +       nxi->v4_lback.s_addr = lback;
21133 +}
21134 +
21135 +extern int __nx_inet_add_lback(__be32 addr);
21136 +extern int __nx_inet_del_lback(__be32 addr);
21137 +
21138 +
21139 +/*     hash table for nx_info hash */
21140 +
21141 +#define NX_HASH_SIZE   13
21142 +
21143 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
21144 +
21145 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
21146 +
21147 +
21148 +static inline unsigned int __hashval(nid_t nid)
21149 +{
21150 +       return (nid % NX_HASH_SIZE);
21151 +}
21152 +
21153 +
21154 +
21155 +/*     __hash_nx_info()
21156 +
21157 +       * add the nxi to the global hash table
21158 +       * requires the hash_lock to be held                     */
21159 +
21160 +static inline void __hash_nx_info(struct nx_info *nxi)
21161 +{
21162 +       struct hlist_head *head;
21163 +
21164 +       vxd_assert_lock(&nx_info_hash_lock);
21165 +       vxdprintk(VXD_CBIT(nid, 4),
21166 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
21167 +
21168 +       /* context must not be hashed */
21169 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
21170 +
21171 +       nxi->nx_state |= NXS_HASHED;
21172 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
21173 +       hlist_add_head(&nxi->nx_hlist, head);
21174 +       atomic_inc(&nx_global_cactive);
21175 +}
21176 +
21177 +/*     __unhash_nx_info()
21178 +
21179 +       * remove the nxi from the global hash table
21180 +       * requires the hash_lock to be held                     */
21181 +
21182 +static inline void __unhash_nx_info(struct nx_info *nxi)
21183 +{
21184 +       vxd_assert_lock(&nx_info_hash_lock);
21185 +       vxdprintk(VXD_CBIT(nid, 4),
21186 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
21187 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
21188 +
21189 +       /* context must be hashed */
21190 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
21191 +       /* but without tasks */
21192 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21193 +
21194 +       nxi->nx_state &= ~NXS_HASHED;
21195 +       hlist_del(&nxi->nx_hlist);
21196 +       atomic_dec(&nx_global_cactive);
21197 +}
21198 +
21199 +
21200 +/*     __lookup_nx_info()
21201 +
21202 +       * requires the hash_lock to be held
21203 +       * doesn't increment the nx_refcnt                       */
21204 +
21205 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
21206 +{
21207 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
21208 +       struct hlist_node *pos;
21209 +       struct nx_info *nxi;
21210 +
21211 +       vxd_assert_lock(&nx_info_hash_lock);
21212 +       hlist_for_each(pos, head) {
21213 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21214 +
21215 +               if (nxi->nx_id == nid)
21216 +                       goto found;
21217 +       }
21218 +       nxi = NULL;
21219 +found:
21220 +       vxdprintk(VXD_CBIT(nid, 0),
21221 +               "__lookup_nx_info(#%u): %p[#%u]",
21222 +               nid, nxi, nxi ? nxi->nx_id : 0);
21223 +       return nxi;
21224 +}
21225 +
21226 +
21227 +/*     __create_nx_info()
21228 +
21229 +       * create the requested context
21230 +       * get(), claim() and hash it                            */
21231 +
21232 +static struct nx_info *__create_nx_info(int id)
21233 +{
21234 +       struct nx_info *new, *nxi = NULL;
21235 +
21236 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21237 +
21238 +       if (!(new = __alloc_nx_info(id)))
21239 +               return ERR_PTR(-ENOMEM);
21240 +
21241 +       /* required to make dynamic xids unique */
21242 +       spin_lock(&nx_info_hash_lock);
21243 +
21244 +       /* static context requested */
21245 +       if ((nxi = __lookup_nx_info(id))) {
21246 +               vxdprintk(VXD_CBIT(nid, 0),
21247 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21248 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21249 +                       nxi = ERR_PTR(-EBUSY);
21250 +               else
21251 +                       nxi = ERR_PTR(-EEXIST);
21252 +               goto out_unlock;
21253 +       }
21254 +       /* new context */
21255 +       vxdprintk(VXD_CBIT(nid, 0),
21256 +               "create_nx_info(%d) = %p (new)", id, new);
21257 +       claim_nx_info(new, NULL);
21258 +       __nx_set_lback(new);
21259 +       __hash_nx_info(get_nx_info(new));
21260 +       nxi = new, new = NULL;
21261 +
21262 +out_unlock:
21263 +       spin_unlock(&nx_info_hash_lock);
21264 +       if (new)
21265 +               __dealloc_nx_info(new);
21266 +       return nxi;
21267 +}
21268 +
21269 +
21270 +
21271 +/*     exported stuff                                          */
21272 +
21273 +
21274 +void unhash_nx_info(struct nx_info *nxi)
21275 +{
21276 +       __shutdown_nx_info(nxi);
21277 +       spin_lock(&nx_info_hash_lock);
21278 +       __unhash_nx_info(nxi);
21279 +       spin_unlock(&nx_info_hash_lock);
21280 +}
21281 +
21282 +/*     lookup_nx_info()
21283 +
21284 +       * search for a nx_info and get() it
21285 +       * negative id means current                             */
21286 +
21287 +struct nx_info *lookup_nx_info(int id)
21288 +{
21289 +       struct nx_info *nxi = NULL;
21290 +
21291 +       if (id < 0) {
21292 +               nxi = get_nx_info(current_nx_info());
21293 +       } else if (id > 1) {
21294 +               spin_lock(&nx_info_hash_lock);
21295 +               nxi = get_nx_info(__lookup_nx_info(id));
21296 +               spin_unlock(&nx_info_hash_lock);
21297 +       }
21298 +       return nxi;
21299 +}
21300 +
21301 +/*     nid_is_hashed()
21302 +
21303 +       * verify that nid is still hashed                       */
21304 +
21305 +int nid_is_hashed(nid_t nid)
21306 +{
21307 +       int hashed;
21308 +
21309 +       spin_lock(&nx_info_hash_lock);
21310 +       hashed = (__lookup_nx_info(nid) != NULL);
21311 +       spin_unlock(&nx_info_hash_lock);
21312 +       return hashed;
21313 +}
21314 +
21315 +
21316 +#ifdef CONFIG_PROC_FS
21317 +
21318 +/*     get_nid_list()
21319 +
21320 +       * get a subset of hashed nids for proc
21321 +       * assumes size is at least one                          */
21322 +
21323 +int get_nid_list(int index, unsigned int *nids, int size)
21324 +{
21325 +       int hindex, nr_nids = 0;
21326 +
21327 +       /* only show current and children */
21328 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
21329 +               if (index > 0)
21330 +                       return 0;
21331 +               nids[nr_nids] = nx_current_nid();
21332 +               return 1;
21333 +       }
21334 +
21335 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
21336 +               struct hlist_head *head = &nx_info_hash[hindex];
21337 +               struct hlist_node *pos;
21338 +
21339 +               spin_lock(&nx_info_hash_lock);
21340 +               hlist_for_each(pos, head) {
21341 +                       struct nx_info *nxi;
21342 +
21343 +                       if (--index > 0)
21344 +                               continue;
21345 +
21346 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21347 +                       nids[nr_nids] = nxi->nx_id;
21348 +                       if (++nr_nids >= size) {
21349 +                               spin_unlock(&nx_info_hash_lock);
21350 +                               goto out;
21351 +                       }
21352 +               }
21353 +               /* keep the lock time short */
21354 +               spin_unlock(&nx_info_hash_lock);
21355 +       }
21356 +out:
21357 +       return nr_nids;
21358 +}
21359 +#endif
21360 +
21361 +
21362 +/*
21363 + *     migrate task to new network
21364 + *     gets nxi, puts old_nxi on change
21365 + */
21366 +
21367 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
21368 +{
21369 +       struct nx_info *old_nxi;
21370 +       int ret = 0;
21371 +
21372 +       if (!p || !nxi)
21373 +               BUG();
21374 +
21375 +       vxdprintk(VXD_CBIT(nid, 5),
21376 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21377 +               p, nxi, nxi->nx_id,
21378 +               atomic_read(&nxi->nx_usecnt),
21379 +               atomic_read(&nxi->nx_tasks));
21380 +
21381 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21382 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21383 +               return -EACCES;
21384 +
21385 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21386 +               return -EFAULT;
21387 +
21388 +       /* maybe disallow this completely? */
21389 +       old_nxi = task_get_nx_info(p);
21390 +       if (old_nxi == nxi)
21391 +               goto out;
21392 +
21393 +       task_lock(p);
21394 +       if (old_nxi)
21395 +               clr_nx_info(&p->nx_info);
21396 +       claim_nx_info(nxi, p);
21397 +       set_nx_info(&p->nx_info, nxi);
21398 +       p->nid = nxi->nx_id;
21399 +       task_unlock(p);
21400 +
21401 +       vxdprintk(VXD_CBIT(nid, 5),
21402 +               "moved task %p into nxi:%p[#%d]",
21403 +               p, nxi, nxi->nx_id);
21404 +
21405 +       if (old_nxi)
21406 +               release_nx_info(old_nxi, p);
21407 +       ret = 0;
21408 +out:
21409 +       put_nx_info(old_nxi);
21410 +       return ret;
21411 +}
21412 +
21413 +
21414 +void nx_set_persistent(struct nx_info *nxi)
21415 +{
21416 +       vxdprintk(VXD_CBIT(nid, 6),
21417 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21418 +
21419 +       get_nx_info(nxi);
21420 +       claim_nx_info(nxi, NULL);
21421 +}
21422 +
21423 +void nx_clear_persistent(struct nx_info *nxi)
21424 +{
21425 +       vxdprintk(VXD_CBIT(nid, 6),
21426 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21427 +
21428 +       release_nx_info(nxi, NULL);
21429 +       put_nx_info(nxi);
21430 +}
21431 +
21432 +void nx_update_persistent(struct nx_info *nxi)
21433 +{
21434 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21435 +               nx_set_persistent(nxi);
21436 +       else
21437 +               nx_clear_persistent(nxi);
21438 +}
21439 +
21440 +/* vserver syscall commands below here */
21441 +
21442 +/* taks nid and nx_info functions */
21443 +
21444 +#include <asm/uaccess.h>
21445 +
21446 +
21447 +int vc_task_nid(uint32_t id)
21448 +{
21449 +       nid_t nid;
21450 +
21451 +       if (id) {
21452 +               struct task_struct *tsk;
21453 +
21454 +               read_lock(&tasklist_lock);
21455 +               tsk = find_task_by_real_pid(id);
21456 +               nid = (tsk) ? tsk->nid : -ESRCH;
21457 +               read_unlock(&tasklist_lock);
21458 +       } else
21459 +               nid = nx_current_nid();
21460 +       return nid;
21461 +}
21462 +
21463 +
21464 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21465 +{
21466 +       struct vcmd_nx_info_v0 vc_data;
21467 +
21468 +       vc_data.nid = nxi->nx_id;
21469 +
21470 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21471 +               return -EFAULT;
21472 +       return 0;
21473 +}
21474 +
21475 +
21476 +/* network functions */
21477 +
21478 +int vc_net_create(uint32_t nid, void __user *data)
21479 +{
21480 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21481 +       struct nx_info *new_nxi;
21482 +       int ret;
21483 +
21484 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21485 +               return -EFAULT;
21486 +
21487 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21488 +               return -EINVAL;
21489 +
21490 +       new_nxi = __create_nx_info(nid);
21491 +       if (IS_ERR(new_nxi))
21492 +               return PTR_ERR(new_nxi);
21493 +
21494 +       /* initial flags */
21495 +       new_nxi->nx_flags = vc_data.flagword;
21496 +
21497 +       ret = -ENOEXEC;
21498 +       if (vs_net_change(new_nxi, VSC_NETUP))
21499 +               goto out;
21500 +
21501 +       ret = nx_migrate_task(current, new_nxi);
21502 +       if (ret)
21503 +               goto out;
21504 +
21505 +       /* return context id on success */
21506 +       ret = new_nxi->nx_id;
21507 +
21508 +       /* get a reference for persistent contexts */
21509 +       if ((vc_data.flagword & NXF_PERSISTENT))
21510 +               nx_set_persistent(new_nxi);
21511 +out:
21512 +       release_nx_info(new_nxi, NULL);
21513 +       put_nx_info(new_nxi);
21514 +       return ret;
21515 +}
21516 +
21517 +
21518 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21519 +{
21520 +       return nx_migrate_task(current, nxi);
21521 +}
21522 +
21523 +
21524 +
21525 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21526 +       uint16_t type, uint16_t flags)
21527 +{
21528 +       struct nx_addr_v4 *nxa = &nxi->v4;
21529 +
21530 +       if (NX_IPV4(nxi)) {
21531 +               /* locate last entry */
21532 +               for (; nxa->next; nxa = nxa->next);
21533 +               nxa->next = __alloc_nx_addr_v4();
21534 +               nxa = nxa->next;
21535 +
21536 +               if (IS_ERR(nxa))
21537 +                       return PTR_ERR(nxa);
21538 +       }
21539 +
21540 +       if (nxi->v4.next)
21541 +               /* remove single ip for ip list */
21542 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21543 +
21544 +       nxa->ip[0].s_addr = ip;
21545 +       nxa->ip[1].s_addr = ip2;
21546 +       nxa->mask.s_addr = mask;
21547 +       nxa->type = type;
21548 +       nxa->flags = flags;
21549 +       return 0;
21550 +}
21551 +
21552 +
21553 +int vc_net_add(struct nx_info *nxi, void __user *data)
21554 +{
21555 +       struct vcmd_net_addr_v0 vc_data;
21556 +       int index, ret = 0;
21557 +
21558 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21559 +               return -EFAULT;
21560 +
21561 +       switch (vc_data.type) {
21562 +       case NXA_TYPE_IPV4:
21563 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21564 +                       return -EINVAL;
21565 +
21566 +               index = 0;
21567 +               while (index < vc_data.count) {
21568 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21569 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21570 +                       if (ret)
21571 +                               return ret;
21572 +                       index++;
21573 +               }
21574 +               ret = index;
21575 +               break;
21576 +
21577 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21578 +               nxi->v4_bcast = vc_data.ip[0];
21579 +               ret = 1;
21580 +               break;
21581 +
21582 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21583 +               nxi->v4_lback = vc_data.ip[0];
21584 +               ret = 1;
21585 +               break;
21586 +
21587 +       default:
21588 +               ret = -EINVAL;
21589 +               break;
21590 +       }
21591 +       return ret;
21592 +}
21593 +
21594 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21595 +{
21596 +       struct vcmd_net_addr_v0 vc_data;
21597 +
21598 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21599 +               return -EFAULT;
21600 +
21601 +       switch (vc_data.type) {
21602 +       case NXA_TYPE_ANY:
21603 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21604 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21605 +               break;
21606 +
21607 +       default:
21608 +               return -EINVAL;
21609 +       }
21610 +       return 0;
21611 +}
21612 +
21613 +
21614 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21615 +{
21616 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21617 +
21618 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21619 +               return -EFAULT;
21620 +
21621 +       switch (vc_data.type) {
21622 +       case NXA_TYPE_ADDR:
21623 +       case NXA_TYPE_RANGE:
21624 +       case NXA_TYPE_MASK:
21625 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21626 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21627 +
21628 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21629 +               nxi->v4_bcast = vc_data.ip;
21630 +               break;
21631 +
21632 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21633 +               nxi->v4_lback = vc_data.ip;
21634 +               break;
21635 +
21636 +       default:
21637 +               return -EINVAL;
21638 +       }
21639 +       return 0;
21640 +}
21641 +
21642 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
21643 +{
21644 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21645 +
21646 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21647 +               return -EFAULT;
21648 +
21649 +       switch (vc_data.type) {
21650 +/*     case NXA_TYPE_ADDR:
21651 +               break;          */
21652 +
21653 +       case NXA_TYPE_ANY:
21654 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21655 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21656 +               break;
21657 +
21658 +       default:
21659 +               return -EINVAL;
21660 +       }
21661 +       return 0;
21662 +}
21663 +
21664 +
21665 +#ifdef CONFIG_IPV6
21666 +
21667 +int do_add_v6_addr(struct nx_info *nxi,
21668 +       struct in6_addr *ip, struct in6_addr *mask,
21669 +       uint32_t prefix, uint16_t type, uint16_t flags)
21670 +{
21671 +       struct nx_addr_v6 *nxa = &nxi->v6;
21672 +
21673 +       if (NX_IPV6(nxi)) {
21674 +               /* locate last entry */
21675 +               for (; nxa->next; nxa = nxa->next);
21676 +               nxa->next = __alloc_nx_addr_v6();
21677 +               nxa = nxa->next;
21678 +
21679 +               if (IS_ERR(nxa))
21680 +                       return PTR_ERR(nxa);
21681 +       }
21682 +
21683 +       nxa->ip = *ip;
21684 +       nxa->mask = *mask;
21685 +       nxa->prefix = prefix;
21686 +       nxa->type = type;
21687 +       nxa->flags = flags;
21688 +       return 0;
21689 +}
21690 +
21691 +
21692 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21693 +{
21694 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21695 +
21696 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21697 +               return -EFAULT;
21698 +
21699 +       switch (vc_data.type) {
21700 +       case NXA_TYPE_ADDR:
21701 +       case NXA_TYPE_MASK:
21702 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21703 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21704 +       default:
21705 +               return -EINVAL;
21706 +       }
21707 +       return 0;
21708 +}
21709 +
21710 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21711 +{
21712 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21713 +
21714 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21715 +               return -EFAULT;
21716 +
21717 +       switch (vc_data.type) {
21718 +       case NXA_TYPE_ANY:
21719 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21720 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21721 +               break;
21722 +
21723 +       default:
21724 +               return -EINVAL;
21725 +       }
21726 +       return 0;
21727 +}
21728 +
21729 +#endif /* CONFIG_IPV6 */
21730 +
21731 +
21732 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21733 +{
21734 +       struct vcmd_net_flags_v0 vc_data;
21735 +
21736 +       vc_data.flagword = nxi->nx_flags;
21737 +
21738 +       /* special STATE flag handling */
21739 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21740 +
21741 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21742 +               return -EFAULT;
21743 +       return 0;
21744 +}
21745 +
21746 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21747 +{
21748 +       struct vcmd_net_flags_v0 vc_data;
21749 +       uint64_t mask, trigger;
21750 +
21751 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21752 +               return -EFAULT;
21753 +
21754 +       /* special STATE flag handling */
21755 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21756 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21757 +
21758 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21759 +               vc_data.flagword, mask);
21760 +       if (trigger & NXF_PERSISTENT)
21761 +               nx_update_persistent(nxi);
21762 +
21763 +       return 0;
21764 +}
21765 +
21766 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21767 +{
21768 +       struct vcmd_net_caps_v0 vc_data;
21769 +
21770 +       vc_data.ncaps = nxi->nx_ncaps;
21771 +       vc_data.cmask = ~0ULL;
21772 +
21773 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21774 +               return -EFAULT;
21775 +       return 0;
21776 +}
21777 +
21778 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21779 +{
21780 +       struct vcmd_net_caps_v0 vc_data;
21781 +
21782 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21783 +               return -EFAULT;
21784 +
21785 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21786 +               vc_data.ncaps, vc_data.cmask);
21787 +       return 0;
21788 +}
21789 +
21790 +
21791 +#include <linux/module.h>
21792 +
21793 +module_init(init_network);
21794 +
21795 +EXPORT_SYMBOL_GPL(free_nx_info);
21796 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21797 +
21798 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/proc.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/proc.c
21799 --- linux-2.6.35.4/kernel/vserver/proc.c        1970-01-01 01:00:00.000000000 +0100
21800 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/proc.c  2010-08-02 17:05:06.000000000 +0200
21801 @@ -0,0 +1,1098 @@
21802 +/*
21803 + *  linux/kernel/vserver/proc.c
21804 + *
21805 + *  Virtual Context Support
21806 + *
21807 + *  Copyright (C) 2003-2007  Herbert Pötzl
21808 + *
21809 + *  V0.01  basic structure
21810 + *  V0.02  adaptation vs1.3.0
21811 + *  V0.03  proc permissions
21812 + *  V0.04  locking/generic
21813 + *  V0.05  next generation procfs
21814 + *  V0.06  inode validation
21815 + *  V0.07  generic rewrite vid
21816 + *  V0.08  remove inode type
21817 + *
21818 + */
21819 +
21820 +#include <linux/proc_fs.h>
21821 +#include <linux/fs_struct.h>
21822 +#include <linux/mount.h>
21823 +#include <asm/unistd.h>
21824 +
21825 +#include <linux/vs_context.h>
21826 +#include <linux/vs_network.h>
21827 +#include <linux/vs_cvirt.h>
21828 +
21829 +#include <linux/in.h>
21830 +#include <linux/inetdevice.h>
21831 +#include <linux/vs_inet.h>
21832 +#include <linux/vs_inet6.h>
21833 +
21834 +#include <linux/vserver/global.h>
21835 +
21836 +#include "cvirt_proc.h"
21837 +#include "cacct_proc.h"
21838 +#include "limit_proc.h"
21839 +#include "sched_proc.h"
21840 +#include "vci_config.h"
21841 +
21842 +
21843 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21844 +{
21845 +       unsigned __capi;
21846 +
21847 +       CAP_FOR_EACH_U32(__capi) {
21848 +               buffer += sprintf(buffer, "%08x",
21849 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21850 +       }
21851 +       return buffer;
21852 +}
21853 +
21854 +
21855 +static struct proc_dir_entry *proc_virtual;
21856 +
21857 +static struct proc_dir_entry *proc_virtnet;
21858 +
21859 +
21860 +/* first the actual feeds */
21861 +
21862 +
21863 +static int proc_vci(char *buffer)
21864 +{
21865 +       return sprintf(buffer,
21866 +               "VCIVersion:\t%04x:%04x\n"
21867 +               "VCISyscall:\t%d\n"
21868 +               "VCIKernel:\t%08x\n",
21869 +               VCI_VERSION >> 16,
21870 +               VCI_VERSION & 0xFFFF,
21871 +               __NR_vserver,
21872 +               vci_kernel_config());
21873 +}
21874 +
21875 +static int proc_virtual_info(char *buffer)
21876 +{
21877 +       return proc_vci(buffer);
21878 +}
21879 +
21880 +static int proc_virtual_status(char *buffer)
21881 +{
21882 +       return sprintf(buffer,
21883 +               "#CTotal:\t%d\n"
21884 +               "#CActive:\t%d\n"
21885 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21886 +               "#InitTask:\t%d\t%d %d\n",
21887 +               atomic_read(&vx_global_ctotal),
21888 +               atomic_read(&vx_global_cactive),
21889 +               atomic_read(&vs_global_nsproxy),
21890 +               atomic_read(&vs_global_fs),
21891 +               atomic_read(&vs_global_mnt_ns),
21892 +               atomic_read(&vs_global_uts_ns),
21893 +               atomic_read(&nr_ipc_ns),
21894 +               atomic_read(&vs_global_user_ns),
21895 +               atomic_read(&vs_global_pid_ns),
21896 +               atomic_read(&init_task.usage),
21897 +               atomic_read(&init_task.nsproxy->count),
21898 +               init_task.fs->users);
21899 +}
21900 +
21901 +
21902 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21903 +{
21904 +       int length;
21905 +
21906 +       length = sprintf(buffer,
21907 +               "ID:\t%d\n"
21908 +               "Info:\t%p\n"
21909 +               "Init:\t%d\n"
21910 +               "OOM:\t%lld\n",
21911 +               vxi->vx_id,
21912 +               vxi,
21913 +               vxi->vx_initpid,
21914 +               vxi->vx_badness_bias);
21915 +       return length;
21916 +}
21917 +
21918 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21919 +{
21920 +       char *orig = buffer;
21921 +
21922 +       buffer += sprintf(buffer,
21923 +               "UseCnt:\t%d\n"
21924 +               "Tasks:\t%d\n"
21925 +               "Flags:\t%016llx\n",
21926 +               atomic_read(&vxi->vx_usecnt),
21927 +               atomic_read(&vxi->vx_tasks),
21928 +               (unsigned long long)vxi->vx_flags);
21929 +
21930 +       buffer += sprintf(buffer, "BCaps:\t");
21931 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21932 +       buffer += sprintf(buffer, "\n");
21933 +
21934 +       buffer += sprintf(buffer,
21935 +               "CCaps:\t%016llx\n"
21936 +               "Spaces:\t%08lx %08lx\n",
21937 +               (unsigned long long)vxi->vx_ccaps,
21938 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
21939 +       return buffer - orig;
21940 +}
21941 +
21942 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21943 +{
21944 +       return vx_info_proc_limit(&vxi->limit, buffer);
21945 +}
21946 +
21947 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21948 +{
21949 +       int cpu, length;
21950 +
21951 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21952 +       for_each_online_cpu(cpu) {
21953 +               length += vx_info_proc_sched_pc(
21954 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21955 +                       buffer + length, cpu);
21956 +       }
21957 +       return length;
21958 +}
21959 +
21960 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21961 +{
21962 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
21963 +}
21964 +
21965 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21966 +{
21967 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
21968 +}
21969 +
21970 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21971 +{
21972 +       int cpu, length;
21973 +
21974 +       vx_update_load(vxi);
21975 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21976 +       for_each_online_cpu(cpu) {
21977 +               length += vx_info_proc_cvirt_pc(
21978 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21979 +                       buffer + length, cpu);
21980 +       }
21981 +       return length;
21982 +}
21983 +
21984 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21985 +{
21986 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21987 +}
21988 +
21989 +
21990 +static int proc_virtnet_info(char *buffer)
21991 +{
21992 +       return proc_vci(buffer);
21993 +}
21994 +
21995 +static int proc_virtnet_status(char *buffer)
21996 +{
21997 +       return sprintf(buffer,
21998 +               "#CTotal:\t%d\n"
21999 +               "#CActive:\t%d\n",
22000 +               atomic_read(&nx_global_ctotal),
22001 +               atomic_read(&nx_global_cactive));
22002 +}
22003 +
22004 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22005 +{
22006 +       struct nx_addr_v4 *v4a;
22007 +#ifdef CONFIG_IPV6
22008 +       struct nx_addr_v6 *v6a;
22009 +#endif
22010 +       int length, i;
22011 +
22012 +       length = sprintf(buffer,
22013 +               "ID:\t%d\n"
22014 +               "Info:\t%p\n"
22015 +               "Bcast:\t" NIPQUAD_FMT "\n"
22016 +               "Lback:\t" NIPQUAD_FMT "\n",
22017 +               nxi->nx_id,
22018 +               nxi,
22019 +               NIPQUAD(nxi->v4_bcast.s_addr),
22020 +               NIPQUAD(nxi->v4_lback.s_addr));
22021 +
22022 +       if (!NX_IPV4(nxi))
22023 +               goto skip_v4;
22024 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22025 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
22026 +                       i, NXAV4(v4a));
22027 +skip_v4:
22028 +#ifdef CONFIG_IPV6
22029 +       if (!NX_IPV6(nxi))
22030 +               goto skip_v6;
22031 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22032 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
22033 +                       i, NXAV6(v6a));
22034 +skip_v6:
22035 +#endif
22036 +       return length;
22037 +}
22038 +
22039 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22040 +{
22041 +       int length;
22042 +
22043 +       length = sprintf(buffer,
22044 +               "UseCnt:\t%d\n"
22045 +               "Tasks:\t%d\n"
22046 +               "Flags:\t%016llx\n"
22047 +               "NCaps:\t%016llx\n",
22048 +               atomic_read(&nxi->nx_usecnt),
22049 +               atomic_read(&nxi->nx_tasks),
22050 +               (unsigned long long)nxi->nx_flags,
22051 +               (unsigned long long)nxi->nx_ncaps);
22052 +       return length;
22053 +}
22054 +
22055 +
22056 +
22057 +/* here the inode helpers */
22058 +
22059 +struct vs_entry {
22060 +       int len;
22061 +       char *name;
22062 +       mode_t mode;
22063 +       struct inode_operations *iop;
22064 +       struct file_operations *fop;
22065 +       union proc_op op;
22066 +};
22067 +
22068 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
22069 +{
22070 +       struct inode *inode = new_inode(sb);
22071 +
22072 +       if (!inode)
22073 +               goto out;
22074 +
22075 +       inode->i_mode = p->mode;
22076 +       if (p->iop)
22077 +               inode->i_op = p->iop;
22078 +       if (p->fop)
22079 +               inode->i_fop = p->fop;
22080 +
22081 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
22082 +       inode->i_flags |= S_IMMUTABLE;
22083 +
22084 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
22085 +
22086 +       inode->i_uid = 0;
22087 +       inode->i_gid = 0;
22088 +       inode->i_tag = 0;
22089 +out:
22090 +       return inode;
22091 +}
22092 +
22093 +static struct dentry *vs_proc_instantiate(struct inode *dir,
22094 +       struct dentry *dentry, int id, void *ptr)
22095 +{
22096 +       struct vs_entry *p = ptr;
22097 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
22098 +       struct dentry *error = ERR_PTR(-EINVAL);
22099 +
22100 +       if (!inode)
22101 +               goto out;
22102 +
22103 +       PROC_I(inode)->op = p->op;
22104 +       PROC_I(inode)->fd = id;
22105 +       d_add(dentry, inode);
22106 +       error = NULL;
22107 +out:
22108 +       return error;
22109 +}
22110 +
22111 +/* Lookups */
22112 +
22113 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
22114 +
22115 +/*
22116 + * Fill a directory entry.
22117 + *
22118 + * If possible create the dcache entry and derive our inode number and
22119 + * file type from dcache entry.
22120 + *
22121 + * Since all of the proc inode numbers are dynamically generated, the inode
22122 + * numbers do not exist until the inode is cache.  This means creating the
22123 + * the dcache entry in readdir is necessary to keep the inode numbers
22124 + * reported by readdir in sync with the inode numbers reported
22125 + * by stat.
22126 + */
22127 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
22128 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
22129 +{
22130 +       struct dentry *child, *dir = filp->f_dentry;
22131 +       struct inode *inode;
22132 +       struct qstr qname;
22133 +       ino_t ino = 0;
22134 +       unsigned type = DT_UNKNOWN;
22135 +
22136 +       qname.name = name;
22137 +       qname.len  = len;
22138 +       qname.hash = full_name_hash(name, len);
22139 +
22140 +       child = d_lookup(dir, &qname);
22141 +       if (!child) {
22142 +               struct dentry *new;
22143 +               new = d_alloc(dir, &qname);
22144 +               if (new) {
22145 +                       child = instantiate(dir->d_inode, new, id, ptr);
22146 +                       if (child)
22147 +                               dput(new);
22148 +                       else
22149 +                               child = new;
22150 +               }
22151 +       }
22152 +       if (!child || IS_ERR(child) || !child->d_inode)
22153 +               goto end_instantiate;
22154 +       inode = child->d_inode;
22155 +       if (inode) {
22156 +               ino = inode->i_ino;
22157 +               type = inode->i_mode >> 12;
22158 +       }
22159 +       dput(child);
22160 +end_instantiate:
22161 +       if (!ino)
22162 +               ino = find_inode_number(dir, &qname);
22163 +       if (!ino)
22164 +               ino = 1;
22165 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
22166 +}
22167 +
22168 +
22169 +
22170 +/* get and revalidate vx_info/xid */
22171 +
22172 +static inline
22173 +struct vx_info *get_proc_vx_info(struct inode *inode)
22174 +{
22175 +       return lookup_vx_info(PROC_I(inode)->fd);
22176 +}
22177 +
22178 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
22179 +{
22180 +       struct inode *inode = dentry->d_inode;
22181 +       xid_t xid = PROC_I(inode)->fd;
22182 +
22183 +       if (!xid || xid_is_hashed(xid))
22184 +               return 1;
22185 +       d_drop(dentry);
22186 +       return 0;
22187 +}
22188 +
22189 +
22190 +/* get and revalidate nx_info/nid */
22191 +
22192 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
22193 +{
22194 +       struct inode *inode = dentry->d_inode;
22195 +       nid_t nid = PROC_I(inode)->fd;
22196 +
22197 +       if (!nid || nid_is_hashed(nid))
22198 +               return 1;
22199 +       d_drop(dentry);
22200 +       return 0;
22201 +}
22202 +
22203 +
22204 +
22205 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22206 +
22207 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22208 +                         size_t count, loff_t *ppos)
22209 +{
22210 +       struct inode *inode = file->f_dentry->d_inode;
22211 +       unsigned long page;
22212 +       ssize_t length = 0;
22213 +
22214 +       if (count > PROC_BLOCK_SIZE)
22215 +               count = PROC_BLOCK_SIZE;
22216 +
22217 +       /* fade that out as soon as stable */
22218 +       WARN_ON(PROC_I(inode)->fd);
22219 +
22220 +       if (!(page = __get_free_page(GFP_KERNEL)))
22221 +               return -ENOMEM;
22222 +
22223 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22224 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22225 +
22226 +       if (length >= 0)
22227 +               length = simple_read_from_buffer(buf, count, ppos,
22228 +                       (char *)page, length);
22229 +
22230 +       free_page(page);
22231 +       return length;
22232 +}
22233 +
22234 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22235 +                         size_t count, loff_t *ppos)
22236 +{
22237 +       struct inode *inode = file->f_dentry->d_inode;
22238 +       struct vx_info *vxi = NULL;
22239 +       xid_t xid = PROC_I(inode)->fd;
22240 +       unsigned long page;
22241 +       ssize_t length = 0;
22242 +
22243 +       if (count > PROC_BLOCK_SIZE)
22244 +               count = PROC_BLOCK_SIZE;
22245 +
22246 +       /* fade that out as soon as stable */
22247 +       WARN_ON(!xid);
22248 +       vxi = lookup_vx_info(xid);
22249 +       if (!vxi)
22250 +               goto out;
22251 +
22252 +       length = -ENOMEM;
22253 +       if (!(page = __get_free_page(GFP_KERNEL)))
22254 +               goto out_put;
22255 +
22256 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22257 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22258 +
22259 +       if (length >= 0)
22260 +               length = simple_read_from_buffer(buf, count, ppos,
22261 +                       (char *)page, length);
22262 +
22263 +       free_page(page);
22264 +out_put:
22265 +       put_vx_info(vxi);
22266 +out:
22267 +       return length;
22268 +}
22269 +
22270 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22271 +                         size_t count, loff_t *ppos)
22272 +{
22273 +       struct inode *inode = file->f_dentry->d_inode;
22274 +       struct nx_info *nxi = NULL;
22275 +       nid_t nid = PROC_I(inode)->fd;
22276 +       unsigned long page;
22277 +       ssize_t length = 0;
22278 +
22279 +       if (count > PROC_BLOCK_SIZE)
22280 +               count = PROC_BLOCK_SIZE;
22281 +
22282 +       /* fade that out as soon as stable */
22283 +       WARN_ON(!nid);
22284 +       nxi = lookup_nx_info(nid);
22285 +       if (!nxi)
22286 +               goto out;
22287 +
22288 +       length = -ENOMEM;
22289 +       if (!(page = __get_free_page(GFP_KERNEL)))
22290 +               goto out_put;
22291 +
22292 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22293 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22294 +
22295 +       if (length >= 0)
22296 +               length = simple_read_from_buffer(buf, count, ppos,
22297 +                       (char *)page, length);
22298 +
22299 +       free_page(page);
22300 +out_put:
22301 +       put_nx_info(nxi);
22302 +out:
22303 +       return length;
22304 +}
22305 +
22306 +
22307 +
22308 +/* here comes the lower level */
22309 +
22310 +
22311 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22312 +       .len  = sizeof(NAME) - 1,       \
22313 +       .name = (NAME),                 \
22314 +       .mode = MODE,                   \
22315 +       .iop  = IOP,                    \
22316 +       .fop  = FOP,                    \
22317 +       .op   = OP,                     \
22318 +}
22319 +
22320 +
22321 +#define DIR(NAME, MODE, OTYPE)                         \
22322 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22323 +               &proc_ ## OTYPE ## _inode_operations,   \
22324 +               &proc_ ## OTYPE ## _file_operations, { } )
22325 +
22326 +#define INF(NAME, MODE, OTYPE)                         \
22327 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22328 +               &proc_vs_info_file_operations,          \
22329 +               { .proc_vs_read = &proc_##OTYPE } )
22330 +
22331 +#define VINF(NAME, MODE, OTYPE)                                \
22332 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22333 +               &proc_vx_info_file_operations,          \
22334 +               { .proc_vxi_read = &proc_##OTYPE } )
22335 +
22336 +#define NINF(NAME, MODE, OTYPE)                                \
22337 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22338 +               &proc_nx_info_file_operations,          \
22339 +               { .proc_nxi_read = &proc_##OTYPE } )
22340 +
22341 +
22342 +static struct file_operations proc_vs_info_file_operations = {
22343 +       .read =         proc_vs_info_read,
22344 +};
22345 +
22346 +static struct file_operations proc_vx_info_file_operations = {
22347 +       .read =         proc_vx_info_read,
22348 +};
22349 +
22350 +static struct dentry_operations proc_xid_dentry_operations = {
22351 +       .d_revalidate = proc_xid_revalidate,
22352 +};
22353 +
22354 +static struct vs_entry vx_base_stuff[] = {
22355 +       VINF("info",    S_IRUGO, vxi_info),
22356 +       VINF("status",  S_IRUGO, vxi_status),
22357 +       VINF("limit",   S_IRUGO, vxi_limit),
22358 +       VINF("sched",   S_IRUGO, vxi_sched),
22359 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
22360 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
22361 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22362 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22363 +       {}
22364 +};
22365 +
22366 +
22367 +
22368 +
22369 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22370 +       struct dentry *dentry, int id, void *ptr)
22371 +{
22372 +       dentry->d_op = &proc_xid_dentry_operations;
22373 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22374 +}
22375 +
22376 +static struct dentry *proc_xid_lookup(struct inode *dir,
22377 +       struct dentry *dentry, struct nameidata *nd)
22378 +{
22379 +       struct vs_entry *p = vx_base_stuff;
22380 +       struct dentry *error = ERR_PTR(-ENOENT);
22381 +
22382 +       for (; p->name; p++) {
22383 +               if (p->len != dentry->d_name.len)
22384 +                       continue;
22385 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22386 +                       break;
22387 +       }
22388 +       if (!p->name)
22389 +               goto out;
22390 +
22391 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22392 +out:
22393 +       return error;
22394 +}
22395 +
22396 +static int proc_xid_readdir(struct file *filp,
22397 +       void *dirent, filldir_t filldir)
22398 +{
22399 +       struct dentry *dentry = filp->f_dentry;
22400 +       struct inode *inode = dentry->d_inode;
22401 +       struct vs_entry *p = vx_base_stuff;
22402 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22403 +       int pos, index;
22404 +       u64 ino;
22405 +
22406 +       pos = filp->f_pos;
22407 +       switch (pos) {
22408 +       case 0:
22409 +               ino = inode->i_ino;
22410 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22411 +                       goto out;
22412 +               pos++;
22413 +               /* fall through */
22414 +       case 1:
22415 +               ino = parent_ino(dentry);
22416 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22417 +                       goto out;
22418 +               pos++;
22419 +               /* fall through */
22420 +       default:
22421 +               index = pos - 2;
22422 +               if (index >= size)
22423 +                       goto out;
22424 +               for (p += index; p->name; p++) {
22425 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22426 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22427 +                               goto out;
22428 +                       pos++;
22429 +               }
22430 +       }
22431 +out:
22432 +       filp->f_pos = pos;
22433 +       return 1;
22434 +}
22435 +
22436 +
22437 +
22438 +static struct file_operations proc_nx_info_file_operations = {
22439 +       .read =         proc_nx_info_read,
22440 +};
22441 +
22442 +static struct dentry_operations proc_nid_dentry_operations = {
22443 +       .d_revalidate = proc_nid_revalidate,
22444 +};
22445 +
22446 +static struct vs_entry nx_base_stuff[] = {
22447 +       NINF("info",    S_IRUGO, nxi_info),
22448 +       NINF("status",  S_IRUGO, nxi_status),
22449 +       {}
22450 +};
22451 +
22452 +
22453 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22454 +       struct dentry *dentry, int id, void *ptr)
22455 +{
22456 +       dentry->d_op = &proc_nid_dentry_operations;
22457 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22458 +}
22459 +
22460 +static struct dentry *proc_nid_lookup(struct inode *dir,
22461 +       struct dentry *dentry, struct nameidata *nd)
22462 +{
22463 +       struct vs_entry *p = nx_base_stuff;
22464 +       struct dentry *error = ERR_PTR(-ENOENT);
22465 +
22466 +       for (; p->name; p++) {
22467 +               if (p->len != dentry->d_name.len)
22468 +                       continue;
22469 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22470 +                       break;
22471 +       }
22472 +       if (!p->name)
22473 +               goto out;
22474 +
22475 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22476 +out:
22477 +       return error;
22478 +}
22479 +
22480 +static int proc_nid_readdir(struct file *filp,
22481 +       void *dirent, filldir_t filldir)
22482 +{
22483 +       struct dentry *dentry = filp->f_dentry;
22484 +       struct inode *inode = dentry->d_inode;
22485 +       struct vs_entry *p = nx_base_stuff;
22486 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22487 +       int pos, index;
22488 +       u64 ino;
22489 +
22490 +       pos = filp->f_pos;
22491 +       switch (pos) {
22492 +       case 0:
22493 +               ino = inode->i_ino;
22494 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22495 +                       goto out;
22496 +               pos++;
22497 +               /* fall through */
22498 +       case 1:
22499 +               ino = parent_ino(dentry);
22500 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22501 +                       goto out;
22502 +               pos++;
22503 +               /* fall through */
22504 +       default:
22505 +               index = pos - 2;
22506 +               if (index >= size)
22507 +                       goto out;
22508 +               for (p += index; p->name; p++) {
22509 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22510 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22511 +                               goto out;
22512 +                       pos++;
22513 +               }
22514 +       }
22515 +out:
22516 +       filp->f_pos = pos;
22517 +       return 1;
22518 +}
22519 +
22520 +
22521 +#define MAX_MULBY10    ((~0U - 9) / 10)
22522 +
22523 +static inline int atovid(const char *str, int len)
22524 +{
22525 +       int vid, c;
22526 +
22527 +       vid = 0;
22528 +       while (len-- > 0) {
22529 +               c = *str - '0';
22530 +               str++;
22531 +               if (c > 9)
22532 +                       return -1;
22533 +               if (vid >= MAX_MULBY10)
22534 +                       return -1;
22535 +               vid *= 10;
22536 +               vid += c;
22537 +               if (!vid)
22538 +                       return -1;
22539 +       }
22540 +       return vid;
22541 +}
22542 +
22543 +/* now the upper level (virtual) */
22544 +
22545 +
22546 +static struct file_operations proc_xid_file_operations = {
22547 +       .read =         generic_read_dir,
22548 +       .readdir =      proc_xid_readdir,
22549 +};
22550 +
22551 +static struct inode_operations proc_xid_inode_operations = {
22552 +       .lookup =       proc_xid_lookup,
22553 +};
22554 +
22555 +static struct vs_entry vx_virtual_stuff[] = {
22556 +       INF("info",     S_IRUGO, virtual_info),
22557 +       INF("status",   S_IRUGO, virtual_status),
22558 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22559 +};
22560 +
22561 +
22562 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22563 +       struct dentry *dentry, struct nameidata *nd)
22564 +{
22565 +       struct vs_entry *p = vx_virtual_stuff;
22566 +       struct dentry *error = ERR_PTR(-ENOENT);
22567 +       int id = 0;
22568 +
22569 +       for (; p->name; p++) {
22570 +               if (p->len != dentry->d_name.len)
22571 +                       continue;
22572 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22573 +                       break;
22574 +       }
22575 +       if (p->name)
22576 +               goto instantiate;
22577 +
22578 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22579 +       if ((id < 0) || !xid_is_hashed(id))
22580 +               goto out;
22581 +
22582 +instantiate:
22583 +       error = proc_xid_instantiate(dir, dentry, id, p);
22584 +out:
22585 +       return error;
22586 +}
22587 +
22588 +static struct file_operations proc_nid_file_operations = {
22589 +       .read =         generic_read_dir,
22590 +       .readdir =      proc_nid_readdir,
22591 +};
22592 +
22593 +static struct inode_operations proc_nid_inode_operations = {
22594 +       .lookup =       proc_nid_lookup,
22595 +};
22596 +
22597 +static struct vs_entry nx_virtnet_stuff[] = {
22598 +       INF("info",     S_IRUGO, virtnet_info),
22599 +       INF("status",   S_IRUGO, virtnet_status),
22600 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22601 +};
22602 +
22603 +
22604 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22605 +       struct dentry *dentry, struct nameidata *nd)
22606 +{
22607 +       struct vs_entry *p = nx_virtnet_stuff;
22608 +       struct dentry *error = ERR_PTR(-ENOENT);
22609 +       int id = 0;
22610 +
22611 +       for (; p->name; p++) {
22612 +               if (p->len != dentry->d_name.len)
22613 +                       continue;
22614 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22615 +                       break;
22616 +       }
22617 +       if (p->name)
22618 +               goto instantiate;
22619 +
22620 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22621 +       if ((id < 0) || !nid_is_hashed(id))
22622 +               goto out;
22623 +
22624 +instantiate:
22625 +       error = proc_nid_instantiate(dir, dentry, id, p);
22626 +out:
22627 +       return error;
22628 +}
22629 +
22630 +
22631 +#define PROC_MAXVIDS 32
22632 +
22633 +int proc_virtual_readdir(struct file *filp,
22634 +       void *dirent, filldir_t filldir)
22635 +{
22636 +       struct dentry *dentry = filp->f_dentry;
22637 +       struct inode *inode = dentry->d_inode;
22638 +       struct vs_entry *p = vx_virtual_stuff;
22639 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22640 +       int pos, index;
22641 +       unsigned int xid_array[PROC_MAXVIDS];
22642 +       char buf[PROC_NUMBUF];
22643 +       unsigned int nr_xids, i;
22644 +       u64 ino;
22645 +
22646 +       pos = filp->f_pos;
22647 +       switch (pos) {
22648 +       case 0:
22649 +               ino = inode->i_ino;
22650 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22651 +                       goto out;
22652 +               pos++;
22653 +               /* fall through */
22654 +       case 1:
22655 +               ino = parent_ino(dentry);
22656 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22657 +                       goto out;
22658 +               pos++;
22659 +               /* fall through */
22660 +       default:
22661 +               index = pos - 2;
22662 +               if (index >= size)
22663 +                       goto entries;
22664 +               for (p += index; p->name; p++) {
22665 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22666 +                               vs_proc_instantiate, 0, p))
22667 +                               goto out;
22668 +                       pos++;
22669 +               }
22670 +       entries:
22671 +               index = pos - size;
22672 +               p = &vx_virtual_stuff[size - 1];
22673 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22674 +               for (i = 0; i < nr_xids; i++) {
22675 +                       int n, xid = xid_array[i];
22676 +                       unsigned int j = PROC_NUMBUF;
22677 +
22678 +                       n = xid;
22679 +                       do
22680 +                               buf[--j] = '0' + (n % 10);
22681 +                       while (n /= 10);
22682 +
22683 +                       if (proc_fill_cache(filp, dirent, filldir,
22684 +                               buf + j, PROC_NUMBUF - j,
22685 +                               vs_proc_instantiate, xid, p))
22686 +                               goto out;
22687 +                       pos++;
22688 +               }
22689 +       }
22690 +out:
22691 +       filp->f_pos = pos;
22692 +       return 0;
22693 +}
22694 +
22695 +static int proc_virtual_getattr(struct vfsmount *mnt,
22696 +       struct dentry *dentry, struct kstat *stat)
22697 +{
22698 +       struct inode *inode = dentry->d_inode;
22699 +
22700 +       generic_fillattr(inode, stat);
22701 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22702 +       return 0;
22703 +}
22704 +
22705 +static struct file_operations proc_virtual_dir_operations = {
22706 +       .read =         generic_read_dir,
22707 +       .readdir =      proc_virtual_readdir,
22708 +};
22709 +
22710 +static struct inode_operations proc_virtual_dir_inode_operations = {
22711 +       .getattr =      proc_virtual_getattr,
22712 +       .lookup =       proc_virtual_lookup,
22713 +};
22714 +
22715 +
22716 +
22717 +
22718 +
22719 +int proc_virtnet_readdir(struct file *filp,
22720 +       void *dirent, filldir_t filldir)
22721 +{
22722 +       struct dentry *dentry = filp->f_dentry;
22723 +       struct inode *inode = dentry->d_inode;
22724 +       struct vs_entry *p = nx_virtnet_stuff;
22725 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22726 +       int pos, index;
22727 +       unsigned int nid_array[PROC_MAXVIDS];
22728 +       char buf[PROC_NUMBUF];
22729 +       unsigned int nr_nids, i;
22730 +       u64 ino;
22731 +
22732 +       pos = filp->f_pos;
22733 +       switch (pos) {
22734 +       case 0:
22735 +               ino = inode->i_ino;
22736 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22737 +                       goto out;
22738 +               pos++;
22739 +               /* fall through */
22740 +       case 1:
22741 +               ino = parent_ino(dentry);
22742 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22743 +                       goto out;
22744 +               pos++;
22745 +               /* fall through */
22746 +       default:
22747 +               index = pos - 2;
22748 +               if (index >= size)
22749 +                       goto entries;
22750 +               for (p += index; p->name; p++) {
22751 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22752 +                               vs_proc_instantiate, 0, p))
22753 +                               goto out;
22754 +                       pos++;
22755 +               }
22756 +       entries:
22757 +               index = pos - size;
22758 +               p = &nx_virtnet_stuff[size - 1];
22759 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22760 +               for (i = 0; i < nr_nids; i++) {
22761 +                       int n, nid = nid_array[i];
22762 +                       unsigned int j = PROC_NUMBUF;
22763 +
22764 +                       n = nid;
22765 +                       do
22766 +                               buf[--j] = '0' + (n % 10);
22767 +                       while (n /= 10);
22768 +
22769 +                       if (proc_fill_cache(filp, dirent, filldir,
22770 +                               buf + j, PROC_NUMBUF - j,
22771 +                               vs_proc_instantiate, nid, p))
22772 +                               goto out;
22773 +                       pos++;
22774 +               }
22775 +       }
22776 +out:
22777 +       filp->f_pos = pos;
22778 +       return 0;
22779 +}
22780 +
22781 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22782 +       struct dentry *dentry, struct kstat *stat)
22783 +{
22784 +       struct inode *inode = dentry->d_inode;
22785 +
22786 +       generic_fillattr(inode, stat);
22787 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22788 +       return 0;
22789 +}
22790 +
22791 +static struct file_operations proc_virtnet_dir_operations = {
22792 +       .read =         generic_read_dir,
22793 +       .readdir =      proc_virtnet_readdir,
22794 +};
22795 +
22796 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22797 +       .getattr =      proc_virtnet_getattr,
22798 +       .lookup =       proc_virtnet_lookup,
22799 +};
22800 +
22801 +
22802 +
22803 +void proc_vx_init(void)
22804 +{
22805 +       struct proc_dir_entry *ent;
22806 +
22807 +       ent = proc_mkdir("virtual", 0);
22808 +       if (ent) {
22809 +               ent->proc_fops = &proc_virtual_dir_operations;
22810 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22811 +       }
22812 +       proc_virtual = ent;
22813 +
22814 +       ent = proc_mkdir("virtnet", 0);
22815 +       if (ent) {
22816 +               ent->proc_fops = &proc_virtnet_dir_operations;
22817 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22818 +       }
22819 +       proc_virtnet = ent;
22820 +}
22821 +
22822 +
22823 +
22824 +
22825 +/* per pid info */
22826 +
22827 +
22828 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22829 +{
22830 +       struct vx_info *vxi;
22831 +       char *orig = buffer;
22832 +
22833 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22834 +
22835 +       vxi = task_get_vx_info(p);
22836 +       if (!vxi)
22837 +               goto out;
22838 +
22839 +       buffer += sprintf(buffer, "BCaps:\t");
22840 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22841 +       buffer += sprintf(buffer, "\n");
22842 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22843 +               (unsigned long long)vxi->vx_ccaps);
22844 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22845 +               (unsigned long long)vxi->vx_flags);
22846 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22847 +
22848 +       put_vx_info(vxi);
22849 +out:
22850 +       return buffer - orig;
22851 +}
22852 +
22853 +
22854 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22855 +{
22856 +       struct nx_info *nxi;
22857 +       struct nx_addr_v4 *v4a;
22858 +#ifdef CONFIG_IPV6
22859 +       struct nx_addr_v6 *v6a;
22860 +#endif
22861 +       char *orig = buffer;
22862 +       int i;
22863 +
22864 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22865 +
22866 +       nxi = task_get_nx_info(p);
22867 +       if (!nxi)
22868 +               goto out;
22869 +
22870 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22871 +               (unsigned long long)nxi->nx_ncaps);
22872 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22873 +               (unsigned long long)nxi->nx_flags);
22874 +
22875 +       buffer += sprintf(buffer,
22876 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22877 +               NIPQUAD(nxi->v4_bcast.s_addr));
22878 +       buffer += sprintf (buffer,
22879 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22880 +               NIPQUAD(nxi->v4_lback.s_addr));
22881 +       if (!NX_IPV4(nxi))
22882 +               goto skip_v4;
22883 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22884 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22885 +                       i, NXAV4(v4a));
22886 +skip_v4:
22887 +#ifdef CONFIG_IPV6
22888 +       if (!NX_IPV6(nxi))
22889 +               goto skip_v6;
22890 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22891 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22892 +                       i, NXAV6(v6a));
22893 +skip_v6:
22894 +#endif
22895 +       put_nx_info(nxi);
22896 +out:
22897 +       return buffer - orig;
22898 +}
22899 +
22900 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/sched.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/sched.c
22901 --- linux-2.6.35.4/kernel/vserver/sched.c       1970-01-01 01:00:00.000000000 +0100
22902 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/sched.c 2010-08-02 17:05:06.000000000 +0200
22903 @@ -0,0 +1,414 @@
22904 +/*
22905 + *  linux/kernel/vserver/sched.c
22906 + *
22907 + *  Virtual Server: Scheduler Support
22908 + *
22909 + *  Copyright (C) 2004-2007  Herbert Pötzl
22910 + *
22911 + *  V0.01  adapted Sam Vilains version to 2.6.3
22912 + *  V0.02  removed legacy interface
22913 + *  V0.03  changed vcmds to vxi arg
22914 + *  V0.04  removed older and legacy interfaces
22915 + *
22916 + */
22917 +
22918 +#include <linux/vs_context.h>
22919 +#include <linux/vs_sched.h>
22920 +#include <linux/vserver/sched_cmd.h>
22921 +
22922 +#include <asm/uaccess.h>
22923 +
22924 +
22925 +#define vxd_check_range(val, min, max) do {            \
22926 +       vxlprintk((val < min) || (val > max),           \
22927 +               "check_range(%ld,%ld,%ld)",             \
22928 +               (long)val, (long)min, (long)max,        \
22929 +               __FILE__, __LINE__);                    \
22930 +       } while (0)
22931 +
22932 +
22933 +void vx_update_sched_param(struct _vx_sched *sched,
22934 +       struct _vx_sched_pc *sched_pc)
22935 +{
22936 +       unsigned int set_mask = sched->update_mask;
22937 +
22938 +       if (set_mask & VXSM_FILL_RATE)
22939 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
22940 +       if (set_mask & VXSM_INTERVAL)
22941 +               sched_pc->interval[0] = sched->interval[0];
22942 +       if (set_mask & VXSM_FILL_RATE2)
22943 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
22944 +       if (set_mask & VXSM_INTERVAL2)
22945 +               sched_pc->interval[1] = sched->interval[1];
22946 +       if (set_mask & VXSM_TOKENS)
22947 +               sched_pc->tokens = sched->tokens;
22948 +       if (set_mask & VXSM_TOKENS_MIN)
22949 +               sched_pc->tokens_min = sched->tokens_min;
22950 +       if (set_mask & VXSM_TOKENS_MAX)
22951 +               sched_pc->tokens_max = sched->tokens_max;
22952 +       if (set_mask & VXSM_PRIO_BIAS)
22953 +               sched_pc->prio_bias = sched->prio_bias;
22954 +
22955 +       if (set_mask & VXSM_IDLE_TIME)
22956 +               sched_pc->flags |= VXSF_IDLE_TIME;
22957 +       else
22958 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
22959 +
22960 +       /* reset time */
22961 +       sched_pc->norm_time = jiffies;
22962 +}
22963 +
22964 +
22965 +/*
22966 + * recalculate the context's scheduling tokens
22967 + *
22968 + * ret > 0 : number of tokens available
22969 + * ret < 0 : on hold, check delta_min[]
22970 + *          -1 only jiffies
22971 + *          -2 also idle time
22972 + *
22973 + */
22974 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
22975 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
22976 +{
22977 +       long delta;
22978 +       long tokens = 0;
22979 +       int flags = sched_pc->flags;
22980 +
22981 +       /* how much time did pass? */
22982 +       delta = *norm_time - sched_pc->norm_time;
22983 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
22984 +       vxd_check_range(delta, 0, INT_MAX);
22985 +
22986 +       if (delta >= sched_pc->interval[0]) {
22987 +               long tokens, integral;
22988 +
22989 +               /* calc integral token part */
22990 +               tokens = delta / sched_pc->interval[0];
22991 +               integral = tokens * sched_pc->interval[0];
22992 +               tokens *= sched_pc->fill_rate[0];
22993 +#ifdef CONFIG_VSERVER_HARDCPU
22994 +               delta_min[0] = delta - integral;
22995 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
22996 +#endif
22997 +               /* advance time */
22998 +               sched_pc->norm_time += delta;
22999 +
23000 +               /* add tokens */
23001 +               sched_pc->tokens += tokens;
23002 +               sched_pc->token_time += tokens;
23003 +       } else
23004 +               delta_min[0] = delta;
23005 +
23006 +#ifdef CONFIG_VSERVER_IDLETIME
23007 +       if (!(flags & VXSF_IDLE_TIME))
23008 +               goto skip_idle;
23009 +
23010 +       /* how much was the idle skip? */
23011 +       delta = *idle_time - sched_pc->idle_time;
23012 +       vxd_check_range(delta, 0, INT_MAX);
23013 +
23014 +       if (delta >= sched_pc->interval[1]) {
23015 +               long tokens, integral;
23016 +
23017 +               /* calc fair share token part */
23018 +               tokens = delta / sched_pc->interval[1];
23019 +               integral = tokens * sched_pc->interval[1];
23020 +               tokens *= sched_pc->fill_rate[1];
23021 +               delta_min[1] = delta - integral;
23022 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23023 +
23024 +               /* advance idle time */
23025 +               sched_pc->idle_time += integral;
23026 +
23027 +               /* add tokens */
23028 +               sched_pc->tokens += tokens;
23029 +               sched_pc->token_time += tokens;
23030 +       } else
23031 +               delta_min[1] = delta;
23032 +skip_idle:
23033 +#endif
23034 +
23035 +       /* clip at maximum */
23036 +       if (sched_pc->tokens > sched_pc->tokens_max)
23037 +               sched_pc->tokens = sched_pc->tokens_max;
23038 +       tokens = sched_pc->tokens;
23039 +
23040 +       if ((flags & VXSF_ONHOLD)) {
23041 +               /* can we unhold? */
23042 +               if (tokens >= sched_pc->tokens_min) {
23043 +                       flags &= ~VXSF_ONHOLD;
23044 +                       sched_pc->hold_ticks +=
23045 +                               *norm_time - sched_pc->onhold;
23046 +               } else
23047 +                       goto on_hold;
23048 +       } else {
23049 +               /* put on hold? */
23050 +               if (tokens <= 0) {
23051 +                       flags |= VXSF_ONHOLD;
23052 +                       sched_pc->onhold = *norm_time;
23053 +                       goto on_hold;
23054 +               }
23055 +       }
23056 +       sched_pc->flags = flags;
23057 +       return tokens;
23058 +
23059 +on_hold:
23060 +       tokens = sched_pc->tokens_min - tokens;
23061 +       sched_pc->flags = flags;
23062 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
23063 +
23064 +#ifdef CONFIG_VSERVER_HARDCPU
23065 +       /* next interval? */
23066 +       if (!sched_pc->fill_rate[0])
23067 +               delta_min[0] = HZ;
23068 +       else if (tokens > sched_pc->fill_rate[0])
23069 +               delta_min[0] += sched_pc->interval[0] *
23070 +                       tokens / sched_pc->fill_rate[0];
23071 +       else
23072 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
23073 +       vxd_check_range(delta_min[0], 0, INT_MAX);
23074 +
23075 +#ifdef CONFIG_VSERVER_IDLETIME
23076 +       if (!(flags & VXSF_IDLE_TIME))
23077 +               return -1;
23078 +
23079 +       /* next interval? */
23080 +       if (!sched_pc->fill_rate[1])
23081 +               delta_min[1] = HZ;
23082 +       else if (tokens > sched_pc->fill_rate[1])
23083 +               delta_min[1] += sched_pc->interval[1] *
23084 +                       tokens / sched_pc->fill_rate[1];
23085 +       else
23086 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
23087 +       vxd_check_range(delta_min[1], 0, INT_MAX);
23088 +
23089 +       return -2;
23090 +#else
23091 +       return -1;
23092 +#endif /* CONFIG_VSERVER_IDLETIME */
23093 +#else
23094 +       return 0;
23095 +#endif /* CONFIG_VSERVER_HARDCPU */
23096 +}
23097 +
23098 +static inline unsigned long msec_to_ticks(unsigned long msec)
23099 +{
23100 +       return msecs_to_jiffies(msec);
23101 +}
23102 +
23103 +static inline unsigned long ticks_to_msec(unsigned long ticks)
23104 +{
23105 +       return jiffies_to_msecs(ticks);
23106 +}
23107 +
23108 +static inline unsigned long ticks_to_usec(unsigned long ticks)
23109 +{
23110 +       return jiffies_to_usecs(ticks);
23111 +}
23112 +
23113 +
23114 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
23115 +{
23116 +       unsigned int set_mask = data->mask;
23117 +       unsigned int update_mask;
23118 +       int i, cpu;
23119 +
23120 +       /* Sanity check data values */
23121 +       if (data->tokens_max <= 0)
23122 +               data->tokens_max = HZ;
23123 +       if (data->tokens_min < 0)
23124 +               data->tokens_min = HZ / 3;
23125 +       if (data->tokens_min >= data->tokens_max)
23126 +               data->tokens_min = data->tokens_max;
23127 +
23128 +       if (data->prio_bias > MAX_PRIO_BIAS)
23129 +               data->prio_bias = MAX_PRIO_BIAS;
23130 +       if (data->prio_bias < MIN_PRIO_BIAS)
23131 +               data->prio_bias = MIN_PRIO_BIAS;
23132 +
23133 +       spin_lock(&vxi->sched.tokens_lock);
23134 +
23135 +       /* sync up on delayed updates */
23136 +       for_each_cpu_mask(cpu, vxi->sched.update)
23137 +               vx_update_sched_param(&vxi->sched,
23138 +                       &vx_per_cpu(vxi, sched_pc, cpu));
23139 +
23140 +       if (set_mask & VXSM_FILL_RATE)
23141 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
23142 +       if (set_mask & VXSM_FILL_RATE2)
23143 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
23144 +       if (set_mask & VXSM_INTERVAL)
23145 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
23146 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
23147 +       if (set_mask & VXSM_INTERVAL2)
23148 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
23149 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
23150 +       if (set_mask & VXSM_TOKENS)
23151 +               vxi->sched.tokens = data->tokens;
23152 +       if (set_mask & VXSM_TOKENS_MIN)
23153 +               vxi->sched.tokens_min = data->tokens_min;
23154 +       if (set_mask & VXSM_TOKENS_MAX)
23155 +               vxi->sched.tokens_max = data->tokens_max;
23156 +       if (set_mask & VXSM_PRIO_BIAS)
23157 +               vxi->sched.prio_bias = data->prio_bias;
23158 +
23159 +       /* Sanity check rate/interval */
23160 +       for (i = 0; i < 2; i++) {
23161 +               if (data->fill_rate[i] < 0)
23162 +                       data->fill_rate[i] = 0;
23163 +               if (data->interval[i] <= 0)
23164 +                       data->interval[i] = HZ;
23165 +       }
23166 +
23167 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
23168 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
23169 +       vxi->sched.update_mask = update_mask;
23170 +
23171 +#ifdef CONFIG_SMP
23172 +       rmb();
23173 +       if (set_mask & VXSM_CPU_ID) {
23174 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
23175 +               cpus_and(vxi->sched.update, cpu_online_map,
23176 +                       vxi->sched.update);
23177 +       } else
23178 +               vxi->sched.update = cpu_online_map;
23179 +
23180 +       /* forced reload? */
23181 +       if (set_mask & VXSM_FORCE) {
23182 +               for_each_cpu_mask(cpu, vxi->sched.update)
23183 +                       vx_update_sched_param(&vxi->sched,
23184 +                               &vx_per_cpu(vxi, sched_pc, cpu));
23185 +               vxi->sched.update = CPU_MASK_NONE;
23186 +       }
23187 +#else
23188 +       /* on UP we update immediately */
23189 +       vx_update_sched_param(&vxi->sched,
23190 +               &vx_per_cpu(vxi, sched_pc, 0));
23191 +#endif
23192 +
23193 +       spin_unlock(&vxi->sched.tokens_lock);
23194 +       return 0;
23195 +}
23196 +
23197 +
23198 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
23199 +#define COPY_PRI(C) C(prio_bias)
23200 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23201 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
23202 +                   C(fill_rate[1]); C(interval[1]);
23203 +
23204 +#define COPY_VALUE(name) vc_data.name = data->name
23205 +
23206 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
23207 +{
23208 +       struct vcmd_sched_v5 vc_data;
23209 +
23210 +       vc_data.mask = data->set_mask;
23211 +       COPY_IDS(COPY_VALUE);
23212 +       COPY_PRI(COPY_VALUE);
23213 +       COPY_TOK(COPY_VALUE);
23214 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
23215 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
23216 +       return do_set_sched(vxi, &vc_data);
23217 +}
23218 +
23219 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
23220 +{
23221 +       struct vcmd_set_sched_v4 vc_data;
23222 +
23223 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23224 +               return -EFAULT;
23225 +
23226 +       return do_set_sched_v4(vxi, &vc_data);
23227 +}
23228 +
23229 +       /* latest interface is v5 */
23230 +
23231 +int vc_set_sched(struct vx_info *vxi, void __user *data)
23232 +{
23233 +       struct vcmd_sched_v5 vc_data;
23234 +
23235 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23236 +               return -EFAULT;
23237 +
23238 +       return do_set_sched(vxi, &vc_data);
23239 +}
23240 +
23241 +
23242 +#define COPY_PRI(C) C(prio_bias)
23243 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23244 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
23245 +                   C(fill_rate[1]); C(interval[1]);
23246 +
23247 +#define COPY_VALUE(name) vc_data.name = data->name
23248 +
23249 +
23250 +int vc_get_sched(struct vx_info *vxi, void __user *data)
23251 +{
23252 +       struct vcmd_sched_v5 vc_data;
23253 +
23254 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23255 +               return -EFAULT;
23256 +
23257 +       if (vc_data.mask & VXSM_CPU_ID) {
23258 +               int cpu = vc_data.cpu_id;
23259 +               struct _vx_sched_pc *data;
23260 +
23261 +               if (!cpu_possible(cpu))
23262 +                       return -EINVAL;
23263 +
23264 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
23265 +               COPY_TOK(COPY_VALUE);
23266 +               COPY_PRI(COPY_VALUE);
23267 +               COPY_FRI(COPY_VALUE);
23268 +
23269 +               if (data->flags & VXSF_IDLE_TIME)
23270 +                       vc_data.mask |= VXSM_IDLE_TIME;
23271 +       } else {
23272 +               struct _vx_sched *data = &vxi->sched;
23273 +
23274 +               COPY_TOK(COPY_VALUE);
23275 +               COPY_PRI(COPY_VALUE);
23276 +               COPY_FRI(COPY_VALUE);
23277 +       }
23278 +
23279 +       if (vc_data.mask & VXSM_MSEC) {
23280 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
23281 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
23282 +       }
23283 +
23284 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23285 +               return -EFAULT;
23286 +       return 0;
23287 +}
23288 +
23289 +
23290 +int vc_sched_info(struct vx_info *vxi, void __user *data)
23291 +{
23292 +       struct vcmd_sched_info vc_data;
23293 +       int cpu;
23294 +
23295 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23296 +               return -EFAULT;
23297 +
23298 +       cpu = vc_data.cpu_id;
23299 +       if (!cpu_possible(cpu))
23300 +               return -EINVAL;
23301 +
23302 +       if (vxi) {
23303 +               struct _vx_sched_pc *sched_pc =
23304 +                       &vx_per_cpu(vxi, sched_pc, cpu);
23305 +
23306 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
23307 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
23308 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
23309 +               vc_data.vavavoom = sched_pc->vavavoom;
23310 +       }
23311 +       vc_data.token_usec = ticks_to_usec(1);
23312 +
23313 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23314 +               return -EFAULT;
23315 +       return 0;
23316 +}
23317 +
23318 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/sched_init.h linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/sched_init.h
23319 --- linux-2.6.35.4/kernel/vserver/sched_init.h  1970-01-01 01:00:00.000000000 +0100
23320 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/sched_init.h    2010-08-02 17:05:06.000000000 +0200
23321 @@ -0,0 +1,50 @@
23322 +
23323 +static inline void vx_info_init_sched(struct _vx_sched *sched)
23324 +{
23325 +       static struct lock_class_key tokens_lock_key;
23326 +
23327 +       /* scheduling; hard code starting values as constants */
23328 +       sched->fill_rate[0]     = 1;
23329 +       sched->interval[0]      = 4;
23330 +       sched->fill_rate[1]     = 1;
23331 +       sched->interval[1]      = 8;
23332 +       sched->tokens           = HZ >> 2;
23333 +       sched->tokens_min       = HZ >> 4;
23334 +       sched->tokens_max       = HZ >> 1;
23335 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
23336 +       sched->prio_bias        = 0;
23337 +
23338 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
23339 +}
23340 +
23341 +static inline
23342 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
23343 +{
23344 +       sched_pc->fill_rate[0]  = 1;
23345 +       sched_pc->interval[0]   = 4;
23346 +       sched_pc->fill_rate[1]  = 1;
23347 +       sched_pc->interval[1]   = 8;
23348 +       sched_pc->tokens        = HZ >> 2;
23349 +       sched_pc->tokens_min    = HZ >> 4;
23350 +       sched_pc->tokens_max    = HZ >> 1;
23351 +       sched_pc->prio_bias     = 0;
23352 +       sched_pc->vavavoom      = 0;
23353 +       sched_pc->token_time    = 0;
23354 +       sched_pc->idle_time     = 0;
23355 +       sched_pc->norm_time     = jiffies;
23356 +
23357 +       sched_pc->user_ticks = 0;
23358 +       sched_pc->sys_ticks = 0;
23359 +       sched_pc->hold_ticks = 0;
23360 +}
23361 +
23362 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
23363 +{
23364 +       return;
23365 +}
23366 +
23367 +static inline
23368 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
23369 +{
23370 +       return;
23371 +}
23372 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/sched_proc.h linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/sched_proc.h
23373 --- linux-2.6.35.4/kernel/vserver/sched_proc.h  1970-01-01 01:00:00.000000000 +0100
23374 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/sched_proc.h    2010-08-02 17:05:06.000000000 +0200
23375 @@ -0,0 +1,57 @@
23376 +#ifndef _VX_SCHED_PROC_H
23377 +#define _VX_SCHED_PROC_H
23378 +
23379 +
23380 +static inline
23381 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
23382 +{
23383 +       int length = 0;
23384 +
23385 +       length += sprintf(buffer,
23386 +               "FillRate:\t%8d,%d\n"
23387 +               "Interval:\t%8d,%d\n"
23388 +               "TokensMin:\t%8d\n"
23389 +               "TokensMax:\t%8d\n"
23390 +               "PrioBias:\t%8d\n",
23391 +               sched->fill_rate[0],
23392 +               sched->fill_rate[1],
23393 +               sched->interval[0],
23394 +               sched->interval[1],
23395 +               sched->tokens_min,
23396 +               sched->tokens_max,
23397 +               sched->prio_bias);
23398 +       return length;
23399 +}
23400 +
23401 +static inline
23402 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
23403 +       char *buffer, int cpu)
23404 +{
23405 +       int length = 0;
23406 +
23407 +       length += sprintf(buffer + length,
23408 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
23409 +               (unsigned long long)sched_pc->user_ticks,
23410 +               (unsigned long long)sched_pc->sys_ticks,
23411 +               (unsigned long long)sched_pc->hold_ticks,
23412 +               sched_pc->token_time,
23413 +               sched_pc->idle_time);
23414 +       length += sprintf(buffer + length,
23415 +               " %c%c %d %d %d %d/%d %d/%d",
23416 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
23417 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
23418 +               sched_pc->tokens,
23419 +               sched_pc->tokens_min,
23420 +               sched_pc->tokens_max,
23421 +               sched_pc->fill_rate[0],
23422 +               sched_pc->interval[0],
23423 +               sched_pc->fill_rate[1],
23424 +               sched_pc->interval[1]);
23425 +       length += sprintf(buffer + length,
23426 +               " %d %d\n",
23427 +               sched_pc->prio_bias,
23428 +               sched_pc->vavavoom);
23429 +       return length;
23430 +}
23431 +
23432 +#endif /* _VX_SCHED_PROC_H */
23433 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/signal.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/signal.c
23434 --- linux-2.6.35.4/kernel/vserver/signal.c      1970-01-01 01:00:00.000000000 +0100
23435 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/signal.c        2010-08-02 17:05:06.000000000 +0200
23436 @@ -0,0 +1,132 @@
23437 +/*
23438 + *  linux/kernel/vserver/signal.c
23439 + *
23440 + *  Virtual Server: Signal Support
23441 + *
23442 + *  Copyright (C) 2003-2007  Herbert Pötzl
23443 + *
23444 + *  V0.01  broken out from vcontext V0.05
23445 + *  V0.02  changed vcmds to vxi arg
23446 + *  V0.03  adjusted siginfo for kill
23447 + *
23448 + */
23449 +
23450 +#include <asm/uaccess.h>
23451 +
23452 +#include <linux/vs_context.h>
23453 +#include <linux/vs_pid.h>
23454 +#include <linux/vserver/signal_cmd.h>
23455 +
23456 +
23457 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
23458 +{
23459 +       int retval, count = 0;
23460 +       struct task_struct *p;
23461 +       struct siginfo *sip = SEND_SIG_PRIV;
23462 +
23463 +       retval = -ESRCH;
23464 +       vxdprintk(VXD_CBIT(misc, 4),
23465 +               "vx_info_kill(%p[#%d],%d,%d)*",
23466 +               vxi, vxi->vx_id, pid, sig);
23467 +       read_lock(&tasklist_lock);
23468 +       switch (pid) {
23469 +       case  0:
23470 +       case -1:
23471 +               for_each_process(p) {
23472 +                       int err = 0;
23473 +
23474 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
23475 +                               (pid && vxi->vx_initpid == p->pid))
23476 +                               continue;
23477 +
23478 +                       err = group_send_sig_info(sig, sip, p);
23479 +                       ++count;
23480 +                       if (err != -EPERM)
23481 +                               retval = err;
23482 +               }
23483 +               break;
23484 +
23485 +       case 1:
23486 +               if (vxi->vx_initpid) {
23487 +                       pid = vxi->vx_initpid;
23488 +                       /* for now, only SIGINT to private init ... */
23489 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
23490 +                               /* ... as long as there are tasks left */
23491 +                               (atomic_read(&vxi->vx_tasks) > 1))
23492 +                               sig = SIGINT;
23493 +               }
23494 +               /* fallthrough */
23495 +       default:
23496 +               p = find_task_by_real_pid(pid);
23497 +               if (p) {
23498 +                       if (vx_task_xid(p) == vxi->vx_id)
23499 +                               retval = group_send_sig_info(sig, sip, p);
23500 +               }
23501 +               break;
23502 +       }
23503 +       read_unlock(&tasklist_lock);
23504 +       vxdprintk(VXD_CBIT(misc, 4),
23505 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
23506 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
23507 +       return retval;
23508 +}
23509 +
23510 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
23511 +{
23512 +       struct vcmd_ctx_kill_v0 vc_data;
23513 +
23514 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23515 +               return -EFAULT;
23516 +
23517 +       /* special check to allow guest shutdown */
23518 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
23519 +               /* forbid killall pid=0 when init is present */
23520 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
23521 +               (vc_data.pid > 1)))
23522 +               return -EACCES;
23523 +
23524 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
23525 +}
23526 +
23527 +
23528 +static int __wait_exit(struct vx_info *vxi)
23529 +{
23530 +       DECLARE_WAITQUEUE(wait, current);
23531 +       int ret = 0;
23532 +
23533 +       add_wait_queue(&vxi->vx_wait, &wait);
23534 +       set_current_state(TASK_INTERRUPTIBLE);
23535 +
23536 +wait:
23537 +       if (vx_info_state(vxi,
23538 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
23539 +               goto out;
23540 +       if (signal_pending(current)) {
23541 +               ret = -ERESTARTSYS;
23542 +               goto out;
23543 +       }
23544 +       schedule();
23545 +       goto wait;
23546 +
23547 +out:
23548 +       set_current_state(TASK_RUNNING);
23549 +       remove_wait_queue(&vxi->vx_wait, &wait);
23550 +       return ret;
23551 +}
23552 +
23553 +
23554 +
23555 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
23556 +{
23557 +       struct vcmd_wait_exit_v0 vc_data;
23558 +       int ret;
23559 +
23560 +       ret = __wait_exit(vxi);
23561 +       vc_data.reboot_cmd = vxi->reboot_cmd;
23562 +       vc_data.exit_code = vxi->exit_code;
23563 +
23564 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23565 +               ret = -EFAULT;
23566 +       return ret;
23567 +}
23568 +
23569 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/space.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/space.c
23570 --- linux-2.6.35.4/kernel/vserver/space.c       1970-01-01 01:00:00.000000000 +0100
23571 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/space.c 2010-08-02 17:05:06.000000000 +0200
23572 @@ -0,0 +1,375 @@
23573 +/*
23574 + *  linux/kernel/vserver/space.c
23575 + *
23576 + *  Virtual Server: Context Space Support
23577 + *
23578 + *  Copyright (C) 2003-2007  Herbert Pötzl
23579 + *
23580 + *  V0.01  broken out from context.c 0.07
23581 + *  V0.02  added task locking for namespace
23582 + *  V0.03  broken out vx_enter_namespace
23583 + *  V0.04  added *space support and commands
23584 + *
23585 + */
23586 +
23587 +#include <linux/utsname.h>
23588 +#include <linux/nsproxy.h>
23589 +#include <linux/err.h>
23590 +#include <linux/fs_struct.h>
23591 +#include <asm/uaccess.h>
23592 +
23593 +#include <linux/vs_context.h>
23594 +#include <linux/vserver/space.h>
23595 +#include <linux/vserver/space_cmd.h>
23596 +
23597 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
23598 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
23599 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
23600 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
23601 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
23602 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
23603 +
23604 +
23605 +/* namespace functions */
23606 +
23607 +#include <linux/mnt_namespace.h>
23608 +#include <linux/user_namespace.h>
23609 +#include <linux/pid_namespace.h>
23610 +#include <linux/ipc_namespace.h>
23611 +#include <net/net_namespace.h>
23612 +
23613 +
23614 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
23615 +       .mask = CLONE_FS |
23616 +               CLONE_NEWNS |
23617 +               CLONE_NEWUTS |
23618 +               CLONE_NEWIPC |
23619 +               CLONE_NEWUSER |
23620 +               0
23621 +};
23622 +
23623 +static const struct vcmd_space_mask_v1 space_mask = {
23624 +       .mask = CLONE_FS |
23625 +               CLONE_NEWNS |
23626 +               CLONE_NEWUTS |
23627 +               CLONE_NEWIPC |
23628 +               CLONE_NEWUSER |
23629 +#ifdef CONFIG_PID_NS
23630 +               CLONE_NEWPID |
23631 +#endif
23632 +#ifdef CONFIG_NET_NS
23633 +               CLONE_NEWNET |
23634 +#endif
23635 +               0
23636 +};
23637 +
23638 +static const struct vcmd_space_mask_v1 default_space_mask = {
23639 +       .mask = CLONE_FS |
23640 +               CLONE_NEWNS |
23641 +               CLONE_NEWUTS |
23642 +               CLONE_NEWIPC |
23643 +               CLONE_NEWUSER |
23644 +#ifdef CONFIG_PID_NS
23645 +//             CLONE_NEWPID |
23646 +#endif
23647 +               0
23648 +};
23649 +
23650 +/*
23651 + *     build a new nsproxy mix
23652 + *      assumes that both proxies are 'const'
23653 + *     does not touch nsproxy refcounts
23654 + *     will hold a reference on the result.
23655 + */
23656 +
23657 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
23658 +       struct nsproxy *new_nsproxy, unsigned long mask)
23659 +{
23660 +       struct mnt_namespace *old_ns;
23661 +       struct uts_namespace *old_uts;
23662 +       struct ipc_namespace *old_ipc;
23663 +#ifdef CONFIG_PID_NS
23664 +       struct pid_namespace *old_pid;
23665 +#endif
23666 +#ifdef CONFIG_NET_NS
23667 +       struct net *old_net;
23668 +#endif
23669 +       struct nsproxy *nsproxy;
23670 +
23671 +       nsproxy = copy_nsproxy(old_nsproxy);
23672 +       if (!nsproxy)
23673 +               goto out;
23674 +
23675 +       if (mask & CLONE_NEWNS) {
23676 +               old_ns = nsproxy->mnt_ns;
23677 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
23678 +               if (nsproxy->mnt_ns)
23679 +                       get_mnt_ns(nsproxy->mnt_ns);
23680 +       } else
23681 +               old_ns = NULL;
23682 +
23683 +       if (mask & CLONE_NEWUTS) {
23684 +               old_uts = nsproxy->uts_ns;
23685 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
23686 +               if (nsproxy->uts_ns)
23687 +                       get_uts_ns(nsproxy->uts_ns);
23688 +       } else
23689 +               old_uts = NULL;
23690 +
23691 +       if (mask & CLONE_NEWIPC) {
23692 +               old_ipc = nsproxy->ipc_ns;
23693 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
23694 +               if (nsproxy->ipc_ns)
23695 +                       get_ipc_ns(nsproxy->ipc_ns);
23696 +       } else
23697 +               old_ipc = NULL;
23698 +
23699 +#ifdef CONFIG_PID_NS
23700 +       if (mask & CLONE_NEWPID) {
23701 +               old_pid = nsproxy->pid_ns;
23702 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23703 +               if (nsproxy->pid_ns)
23704 +                       get_pid_ns(nsproxy->pid_ns);
23705 +       } else
23706 +               old_pid = NULL;
23707 +#endif
23708 +#ifdef CONFIG_NET_NS
23709 +       if (mask & CLONE_NEWNET) {
23710 +               old_net = nsproxy->net_ns;
23711 +               nsproxy->net_ns = new_nsproxy->net_ns;
23712 +               if (nsproxy->net_ns)
23713 +                       get_net(nsproxy->net_ns);
23714 +       } else
23715 +               old_net = NULL;
23716 +#endif
23717 +       if (old_ns)
23718 +               put_mnt_ns(old_ns);
23719 +       if (old_uts)
23720 +               put_uts_ns(old_uts);
23721 +       if (old_ipc)
23722 +               put_ipc_ns(old_ipc);
23723 +#ifdef CONFIG_PID_NS
23724 +       if (old_pid)
23725 +               put_pid_ns(old_pid);
23726 +#endif
23727 +#ifdef CONFIG_NET_NS
23728 +       if (old_net)
23729 +               put_net(old_net);
23730 +#endif
23731 +out:
23732 +       return nsproxy;
23733 +}
23734 +
23735 +
23736 +/*
23737 + *     merge two nsproxy structs into a new one.
23738 + *     will hold a reference on the result.
23739 + */
23740 +
23741 +static inline
23742 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
23743 +       struct nsproxy *proxy, unsigned long mask)
23744 +{
23745 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
23746 +
23747 +       if (!proxy)
23748 +               return NULL;
23749 +
23750 +       if (mask) {
23751 +               /* vs_mix_nsproxy returns with reference */
23752 +               return vs_mix_nsproxy(old ? old : &null_proxy,
23753 +                       proxy, mask);
23754 +       }
23755 +       get_nsproxy(proxy);
23756 +       return proxy;
23757 +}
23758 +
23759 +
23760 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23761 +{
23762 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
23763 +       struct fs_struct *fs_cur, *fs = NULL;
23764 +       int ret, kill = 0;
23765 +
23766 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
23767 +               vxi, vxi->vx_id, mask, index);
23768 +
23769 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
23770 +               return -EACCES;
23771 +
23772 +       if (!mask)
23773 +               mask = vxi->vx_nsmask[index];
23774 +
23775 +       if ((mask & vxi->vx_nsmask[index]) != mask)
23776 +               return -EINVAL;
23777 +
23778 +       if (mask & CLONE_FS) {
23779 +               fs = copy_fs_struct(vxi->vx_fs[index]);
23780 +               if (!fs)
23781 +                       return -ENOMEM;
23782 +       }
23783 +       proxy = vxi->vx_nsproxy[index];
23784 +
23785 +       vxdprintk(VXD_CBIT(space, 9),
23786 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23787 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23788 +
23789 +       task_lock(current);
23790 +       fs_cur = current->fs;
23791 +
23792 +       if (mask & CLONE_FS) {
23793 +               write_lock(&fs_cur->lock);
23794 +               current->fs = fs;
23795 +               kill = !--fs_cur->users;
23796 +               write_unlock(&fs_cur->lock);
23797 +       }
23798 +
23799 +       proxy_cur = current->nsproxy;
23800 +       get_nsproxy(proxy_cur);
23801 +       task_unlock(current);
23802 +
23803 +       if (kill)
23804 +               free_fs_struct(fs_cur);
23805 +
23806 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23807 +       if (IS_ERR(proxy_new)) {
23808 +               ret = PTR_ERR(proxy_new);
23809 +               goto out_put;
23810 +       }
23811 +
23812 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23813 +       ret = 0;
23814 +
23815 +       if (proxy_new)
23816 +               put_nsproxy(proxy_new);
23817 +out_put:
23818 +       if (proxy_cur)
23819 +               put_nsproxy(proxy_cur);
23820 +       return ret;
23821 +}
23822 +
23823 +
23824 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23825 +{
23826 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23827 +       struct fs_struct *fs_vxi, *fs;
23828 +       int ret, kill = 0;
23829 +
23830 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23831 +               vxi, vxi->vx_id, mask, index);
23832 +#if 0
23833 +       if (!mask)
23834 +               mask = default_space_mask.mask;
23835 +#endif
23836 +       if ((mask & space_mask.mask) != mask)
23837 +               return -EINVAL;
23838 +
23839 +       proxy_vxi = vxi->vx_nsproxy[index];
23840 +       fs_vxi = vxi->vx_fs[index];
23841 +
23842 +       if (mask & CLONE_FS) {
23843 +               fs = copy_fs_struct(current->fs);
23844 +               if (!fs)
23845 +                       return -ENOMEM;
23846 +       }
23847 +
23848 +       task_lock(current);
23849 +
23850 +       if (mask & CLONE_FS) {
23851 +               write_lock(&fs_vxi->lock);
23852 +               vxi->vx_fs[index] = fs;
23853 +               kill = !--fs_vxi->users;
23854 +               write_unlock(&fs_vxi->lock);
23855 +       }
23856 +
23857 +       proxy_cur = current->nsproxy;
23858 +       get_nsproxy(proxy_cur);
23859 +       task_unlock(current);
23860 +
23861 +       if (kill)
23862 +               free_fs_struct(fs_vxi);
23863 +
23864 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23865 +       if (IS_ERR(proxy_new)) {
23866 +               ret = PTR_ERR(proxy_new);
23867 +               goto out_put;
23868 +       }
23869 +
23870 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
23871 +       vxi->vx_nsmask[index] |= mask;
23872 +       ret = 0;
23873 +
23874 +       if (proxy_new)
23875 +               put_nsproxy(proxy_new);
23876 +out_put:
23877 +       if (proxy_cur)
23878 +               put_nsproxy(proxy_cur);
23879 +       return ret;
23880 +}
23881 +
23882 +
23883 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23884 +{
23885 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23886 +
23887 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23888 +               return -EFAULT;
23889 +
23890 +       return vx_enter_space(vxi, vc_data.mask, 0);
23891 +}
23892 +
23893 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23894 +{
23895 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23896 +
23897 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23898 +               return -EFAULT;
23899 +
23900 +       if (vc_data.index >= VX_SPACES)
23901 +               return -EINVAL;
23902 +
23903 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23904 +}
23905 +
23906 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23907 +{
23908 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23909 +
23910 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23911 +               return -EFAULT;
23912 +
23913 +       return vx_set_space(vxi, vc_data.mask, 0);
23914 +}
23915 +
23916 +int vc_set_space(struct vx_info *vxi, void __user *data)
23917 +{
23918 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23919 +
23920 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23921 +               return -EFAULT;
23922 +
23923 +       if (vc_data.index >= VX_SPACES)
23924 +               return -EINVAL;
23925 +
23926 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23927 +}
23928 +
23929 +int vc_get_space_mask(void __user *data, int type)
23930 +{
23931 +       const struct vcmd_space_mask_v1 *mask;
23932 +
23933 +       if (type == 0)
23934 +               mask = &space_mask_v0;
23935 +       else if (type == 1)
23936 +               mask = &space_mask;
23937 +       else
23938 +               mask = &default_space_mask;
23939 +
23940 +       vxdprintk(VXD_CBIT(space, 10),
23941 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23942 +
23943 +       if (copy_to_user(data, mask, sizeof(*mask)))
23944 +               return -EFAULT;
23945 +       return 0;
23946 +}
23947 +
23948 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/switch.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/switch.c
23949 --- linux-2.6.35.4/kernel/vserver/switch.c      1970-01-01 01:00:00.000000000 +0100
23950 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/switch.c        2010-08-02 17:05:06.000000000 +0200
23951 @@ -0,0 +1,546 @@
23952 +/*
23953 + *  linux/kernel/vserver/switch.c
23954 + *
23955 + *  Virtual Server: Syscall Switch
23956 + *
23957 + *  Copyright (C) 2003-2007  Herbert Pötzl
23958 + *
23959 + *  V0.01  syscall switch
23960 + *  V0.02  added signal to context
23961 + *  V0.03  added rlimit functions
23962 + *  V0.04  added iattr, task/xid functions
23963 + *  V0.05  added debug/history stuff
23964 + *  V0.06  added compat32 layer
23965 + *  V0.07  vcmd args and perms
23966 + *  V0.08  added status commands
23967 + *  V0.09  added tag commands
23968 + *  V0.10  added oom bias
23969 + *  V0.11  added device commands
23970 + *
23971 + */
23972 +
23973 +#include <linux/vs_context.h>
23974 +#include <linux/vs_network.h>
23975 +#include <linux/vserver/switch.h>
23976 +
23977 +#include "vci_config.h"
23978 +
23979 +
23980 +static inline
23981 +int vc_get_version(uint32_t id)
23982 +{
23983 +       return VCI_VERSION;
23984 +}
23985 +
23986 +static inline
23987 +int vc_get_vci(uint32_t id)
23988 +{
23989 +       return vci_kernel_config();
23990 +}
23991 +
23992 +#include <linux/vserver/context_cmd.h>
23993 +#include <linux/vserver/cvirt_cmd.h>
23994 +#include <linux/vserver/cacct_cmd.h>
23995 +#include <linux/vserver/limit_cmd.h>
23996 +#include <linux/vserver/network_cmd.h>
23997 +#include <linux/vserver/sched_cmd.h>
23998 +#include <linux/vserver/debug_cmd.h>
23999 +#include <linux/vserver/inode_cmd.h>
24000 +#include <linux/vserver/dlimit_cmd.h>
24001 +#include <linux/vserver/signal_cmd.h>
24002 +#include <linux/vserver/space_cmd.h>
24003 +#include <linux/vserver/tag_cmd.h>
24004 +#include <linux/vserver/device_cmd.h>
24005 +
24006 +#include <linux/vserver/inode.h>
24007 +#include <linux/vserver/dlimit.h>
24008 +
24009 +
24010 +#ifdef CONFIG_COMPAT
24011 +#define __COMPAT(name, id, data, compat)       \
24012 +       (compat) ? name ## _x32(id, data) : name(id, data)
24013 +#define __COMPAT_NO_ID(name, data, compat)     \
24014 +       (compat) ? name ## _x32(data) : name(data)
24015 +#else
24016 +#define __COMPAT(name, id, data, compat)       \
24017 +       name(id, data)
24018 +#define __COMPAT_NO_ID(name, data, compat)     \
24019 +       name(data)
24020 +#endif
24021 +
24022 +
24023 +static inline
24024 +long do_vcmd(uint32_t cmd, uint32_t id,
24025 +       struct vx_info *vxi, struct nx_info *nxi,
24026 +       void __user *data, int compat)
24027 +{
24028 +       switch (cmd) {
24029 +
24030 +       case VCMD_get_version:
24031 +               return vc_get_version(id);
24032 +       case VCMD_get_vci:
24033 +               return vc_get_vci(id);
24034 +
24035 +       case VCMD_task_xid:
24036 +               return vc_task_xid(id);
24037 +       case VCMD_vx_info:
24038 +               return vc_vx_info(vxi, data);
24039 +
24040 +       case VCMD_task_nid:
24041 +               return vc_task_nid(id);
24042 +       case VCMD_nx_info:
24043 +               return vc_nx_info(nxi, data);
24044 +
24045 +       case VCMD_task_tag:
24046 +               return vc_task_tag(id);
24047 +
24048 +       case VCMD_set_space_v1:
24049 +               return vc_set_space_v1(vxi, data);
24050 +       /* this is version 2 */
24051 +       case VCMD_set_space:
24052 +               return vc_set_space(vxi, data);
24053 +
24054 +       case VCMD_get_space_mask_v0:
24055 +               return vc_get_space_mask(data, 0);
24056 +       /* this is version 1 */
24057 +       case VCMD_get_space_mask:
24058 +               return vc_get_space_mask(data, 1);
24059 +
24060 +       case VCMD_get_space_default:
24061 +               return vc_get_space_mask(data, -1);
24062 +
24063 +#ifdef CONFIG_IA32_EMULATION
24064 +       case VCMD_get_rlimit:
24065 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
24066 +       case VCMD_set_rlimit:
24067 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
24068 +#else
24069 +       case VCMD_get_rlimit:
24070 +               return vc_get_rlimit(vxi, data);
24071 +       case VCMD_set_rlimit:
24072 +               return vc_set_rlimit(vxi, data);
24073 +#endif
24074 +       case VCMD_get_rlimit_mask:
24075 +               return vc_get_rlimit_mask(id, data);
24076 +       case VCMD_reset_hits:
24077 +               return vc_reset_hits(vxi, data);
24078 +       case VCMD_reset_minmax:
24079 +               return vc_reset_minmax(vxi, data);
24080 +
24081 +       case VCMD_get_vhi_name:
24082 +               return vc_get_vhi_name(vxi, data);
24083 +       case VCMD_set_vhi_name:
24084 +               return vc_set_vhi_name(vxi, data);
24085 +
24086 +       case VCMD_ctx_stat:
24087 +               return vc_ctx_stat(vxi, data);
24088 +       case VCMD_virt_stat:
24089 +               return vc_virt_stat(vxi, data);
24090 +       case VCMD_sock_stat:
24091 +               return vc_sock_stat(vxi, data);
24092 +       case VCMD_rlimit_stat:
24093 +               return vc_rlimit_stat(vxi, data);
24094 +
24095 +       case VCMD_set_cflags:
24096 +               return vc_set_cflags(vxi, data);
24097 +       case VCMD_get_cflags:
24098 +               return vc_get_cflags(vxi, data);
24099 +
24100 +       /* this is version 1 */
24101 +       case VCMD_set_ccaps:
24102 +               return vc_set_ccaps(vxi, data);
24103 +       /* this is version 1 */
24104 +       case VCMD_get_ccaps:
24105 +               return vc_get_ccaps(vxi, data);
24106 +       case VCMD_set_bcaps:
24107 +               return vc_set_bcaps(vxi, data);
24108 +       case VCMD_get_bcaps:
24109 +               return vc_get_bcaps(vxi, data);
24110 +
24111 +       case VCMD_set_badness:
24112 +               return vc_set_badness(vxi, data);
24113 +       case VCMD_get_badness:
24114 +               return vc_get_badness(vxi, data);
24115 +
24116 +       case VCMD_set_nflags:
24117 +               return vc_set_nflags(nxi, data);
24118 +       case VCMD_get_nflags:
24119 +               return vc_get_nflags(nxi, data);
24120 +
24121 +       case VCMD_set_ncaps:
24122 +               return vc_set_ncaps(nxi, data);
24123 +       case VCMD_get_ncaps:
24124 +               return vc_get_ncaps(nxi, data);
24125 +
24126 +       case VCMD_set_sched_v4:
24127 +               return vc_set_sched_v4(vxi, data);
24128 +       /* this is version 5 */
24129 +       case VCMD_set_sched:
24130 +               return vc_set_sched(vxi, data);
24131 +       case VCMD_get_sched:
24132 +               return vc_get_sched(vxi, data);
24133 +       case VCMD_sched_info:
24134 +               return vc_sched_info(vxi, data);
24135 +
24136 +       case VCMD_add_dlimit:
24137 +               return __COMPAT(vc_add_dlimit, id, data, compat);
24138 +       case VCMD_rem_dlimit:
24139 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
24140 +       case VCMD_set_dlimit:
24141 +               return __COMPAT(vc_set_dlimit, id, data, compat);
24142 +       case VCMD_get_dlimit:
24143 +               return __COMPAT(vc_get_dlimit, id, data, compat);
24144 +
24145 +       case VCMD_ctx_kill:
24146 +               return vc_ctx_kill(vxi, data);
24147 +
24148 +       case VCMD_wait_exit:
24149 +               return vc_wait_exit(vxi, data);
24150 +
24151 +       case VCMD_get_iattr:
24152 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
24153 +       case VCMD_set_iattr:
24154 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
24155 +
24156 +       case VCMD_fget_iattr:
24157 +               return vc_fget_iattr(id, data);
24158 +       case VCMD_fset_iattr:
24159 +               return vc_fset_iattr(id, data);
24160 +
24161 +       case VCMD_enter_space_v0:
24162 +               return vc_enter_space_v1(vxi, NULL);
24163 +       case VCMD_enter_space_v1:
24164 +               return vc_enter_space_v1(vxi, data);
24165 +       /* this is version 2 */
24166 +       case VCMD_enter_space:
24167 +               return vc_enter_space(vxi, data);
24168 +
24169 +       case VCMD_ctx_create_v0:
24170 +               return vc_ctx_create(id, NULL);
24171 +       case VCMD_ctx_create:
24172 +               return vc_ctx_create(id, data);
24173 +       case VCMD_ctx_migrate_v0:
24174 +               return vc_ctx_migrate(vxi, NULL);
24175 +       case VCMD_ctx_migrate:
24176 +               return vc_ctx_migrate(vxi, data);
24177 +
24178 +       case VCMD_net_create_v0:
24179 +               return vc_net_create(id, NULL);
24180 +       case VCMD_net_create:
24181 +               return vc_net_create(id, data);
24182 +       case VCMD_net_migrate:
24183 +               return vc_net_migrate(nxi, data);
24184 +
24185 +       case VCMD_tag_migrate:
24186 +               return vc_tag_migrate(id);
24187 +
24188 +       case VCMD_net_add:
24189 +               return vc_net_add(nxi, data);
24190 +       case VCMD_net_remove:
24191 +               return vc_net_remove(nxi, data);
24192 +
24193 +       case VCMD_net_add_ipv4:
24194 +               return vc_net_add_ipv4(nxi, data);
24195 +       case VCMD_net_remove_ipv4:
24196 +               return vc_net_remove_ipv4(nxi, data);
24197 +#ifdef CONFIG_IPV6
24198 +       case VCMD_net_add_ipv6:
24199 +               return vc_net_add_ipv6(nxi, data);
24200 +       case VCMD_net_remove_ipv6:
24201 +               return vc_net_remove_ipv6(nxi, data);
24202 +#endif
24203 +/*     case VCMD_add_match_ipv4:
24204 +               return vc_add_match_ipv4(nxi, data);
24205 +       case VCMD_get_match_ipv4:
24206 +               return vc_get_match_ipv4(nxi, data);
24207 +#ifdef CONFIG_IPV6
24208 +       case VCMD_add_match_ipv6:
24209 +               return vc_add_match_ipv6(nxi, data);
24210 +       case VCMD_get_match_ipv6:
24211 +               return vc_get_match_ipv6(nxi, data);
24212 +#endif */
24213 +
24214 +#ifdef CONFIG_VSERVER_DEVICE
24215 +       case VCMD_set_mapping:
24216 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
24217 +       case VCMD_unset_mapping:
24218 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
24219 +#endif
24220 +#ifdef CONFIG_VSERVER_HISTORY
24221 +       case VCMD_dump_history:
24222 +               return vc_dump_history(id);
24223 +       case VCMD_read_history:
24224 +               return __COMPAT(vc_read_history, id, data, compat);
24225 +#endif
24226 +#ifdef CONFIG_VSERVER_MONITOR
24227 +       case VCMD_read_monitor:
24228 +               return __COMPAT(vc_read_monitor, id, data, compat);
24229 +#endif
24230 +       default:
24231 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
24232 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
24233 +       }
24234 +       return -ENOSYS;
24235 +}
24236 +
24237 +
24238 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
24239 +       case VCMD_ ## vcmd: perm = _perm;               \
24240 +               args = _args; flags = _flags; break
24241 +
24242 +
24243 +#define VCA_NONE       0x00
24244 +#define VCA_VXI                0x01
24245 +#define VCA_NXI                0x02
24246 +
24247 +#define VCF_NONE       0x00
24248 +#define VCF_INFO       0x01
24249 +#define VCF_ADMIN      0x02
24250 +#define VCF_ARES       0x06    /* includes admin */
24251 +#define VCF_SETUP      0x08
24252 +
24253 +#define VCF_ZIDOK      0x10    /* zero id okay */
24254 +
24255 +
24256 +static inline
24257 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
24258 +{
24259 +       long ret;
24260 +       int permit = -1, state = 0;
24261 +       int perm = -1, args = 0, flags = 0;
24262 +       struct vx_info *vxi = NULL;
24263 +       struct nx_info *nxi = NULL;
24264 +
24265 +       switch (cmd) {
24266 +       /* unpriviledged commands */
24267 +       __VCMD(get_version,      0, VCA_NONE,   0);
24268 +       __VCMD(get_vci,          0, VCA_NONE,   0);
24269 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
24270 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
24271 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
24272 +       __VCMD(get_space_default,0, VCA_NONE,   0);
24273 +
24274 +       /* info commands */
24275 +       __VCMD(task_xid,         2, VCA_NONE,   0);
24276 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
24277 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
24278 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
24279 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
24280 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
24281 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
24282 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
24283 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
24284 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
24285 +
24286 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
24287 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
24288 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
24289 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
24290 +
24291 +       __VCMD(task_nid,         2, VCA_NONE,   0);
24292 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
24293 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
24294 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
24295 +
24296 +       __VCMD(task_tag,         2, VCA_NONE,   0);
24297 +
24298 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
24299 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
24300 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
24301 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
24302 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
24303 +
24304 +       /* lower admin commands */
24305 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
24306 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
24307 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
24308 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
24309 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
24310 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
24311 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
24312 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
24313 +
24314 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
24315 +       __VCMD(net_create,       5, VCA_NONE,   0);
24316 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
24317 +
24318 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
24319 +
24320 +       /* higher admin commands */
24321 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
24322 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24323 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24324 +
24325 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24326 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24327 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24328 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24329 +
24330 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24331 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24332 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24333 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24334 +
24335 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24336 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24337 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24338 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24339 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24340 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24341 +#ifdef CONFIG_IPV6
24342 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24343 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24344 +#endif
24345 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
24346 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
24347 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
24348 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
24349 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
24350 +
24351 +#ifdef CONFIG_VSERVER_DEVICE
24352 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
24353 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
24354 +#endif
24355 +       /* debug level admin commands */
24356 +#ifdef CONFIG_VSERVER_HISTORY
24357 +       __VCMD(dump_history,     9, VCA_NONE,   0);
24358 +       __VCMD(read_history,     9, VCA_NONE,   0);
24359 +#endif
24360 +#ifdef CONFIG_VSERVER_MONITOR
24361 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
24362 +#endif
24363 +
24364 +       default:
24365 +               perm = -1;
24366 +       }
24367 +
24368 +       vxdprintk(VXD_CBIT(switch, 0),
24369 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
24370 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24371 +               VC_VERSION(cmd), id, data, compat,
24372 +               perm, args, flags);
24373 +
24374 +       ret = -ENOSYS;
24375 +       if (perm < 0)
24376 +               goto out;
24377 +
24378 +       state = 1;
24379 +       if (!capable(CAP_CONTEXT))
24380 +               goto out;
24381 +
24382 +       state = 2;
24383 +       /* moved here from the individual commands */
24384 +       ret = -EPERM;
24385 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
24386 +               goto out;
24387 +
24388 +       state = 3;
24389 +       /* vcmd involves resource management  */
24390 +       ret = -EPERM;
24391 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
24392 +               goto out;
24393 +
24394 +       state = 4;
24395 +       /* various legacy exceptions */
24396 +       switch (cmd) {
24397 +       /* will go away when spectator is a cap */
24398 +       case VCMD_ctx_migrate_v0:
24399 +       case VCMD_ctx_migrate:
24400 +               if (id == 1) {
24401 +                       current->xid = 1;
24402 +                       ret = 1;
24403 +                       goto out;
24404 +               }
24405 +               break;
24406 +
24407 +       /* will go away when spectator is a cap */
24408 +       case VCMD_net_migrate:
24409 +               if (id == 1) {
24410 +                       current->nid = 1;
24411 +                       ret = 1;
24412 +                       goto out;
24413 +               }
24414 +               break;
24415 +       }
24416 +
24417 +       /* vcmds are fine by default */
24418 +       permit = 1;
24419 +
24420 +       /* admin type vcmds require admin ... */
24421 +       if (flags & VCF_ADMIN)
24422 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
24423 +
24424 +       /* ... but setup type vcmds override that */
24425 +       if (!permit && (flags & VCF_SETUP))
24426 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
24427 +
24428 +       state = 5;
24429 +       ret = -EPERM;
24430 +       if (!permit)
24431 +               goto out;
24432 +
24433 +       state = 6;
24434 +       if (!id && (flags & VCF_ZIDOK))
24435 +               goto skip_id;
24436 +
24437 +       ret = -ESRCH;
24438 +       if (args & VCA_VXI) {
24439 +               vxi = lookup_vx_info(id);
24440 +               if (!vxi)
24441 +                       goto out;
24442 +
24443 +               if ((flags & VCF_ADMIN) &&
24444 +                       /* special case kill for shutdown */
24445 +                       (cmd != VCMD_ctx_kill) &&
24446 +                       /* can context be administrated? */
24447 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
24448 +                       ret = -EACCES;
24449 +                       goto out_vxi;
24450 +               }
24451 +       }
24452 +       state = 7;
24453 +       if (args & VCA_NXI) {
24454 +               nxi = lookup_nx_info(id);
24455 +               if (!nxi)
24456 +                       goto out_vxi;
24457 +
24458 +               if ((flags & VCF_ADMIN) &&
24459 +                       /* can context be administrated? */
24460 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
24461 +                       ret = -EACCES;
24462 +                       goto out_nxi;
24463 +               }
24464 +       }
24465 +skip_id:
24466 +       state = 8;
24467 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
24468 +
24469 +out_nxi:
24470 +       if ((args & VCA_NXI) && nxi)
24471 +               put_nx_info(nxi);
24472 +out_vxi:
24473 +       if ((args & VCA_VXI) && vxi)
24474 +               put_vx_info(vxi);
24475 +out:
24476 +       vxdprintk(VXD_CBIT(switch, 1),
24477 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
24478 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24479 +               VC_VERSION(cmd), ret, ret, state, permit);
24480 +       return ret;
24481 +}
24482 +
24483 +asmlinkage long
24484 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
24485 +{
24486 +       return do_vserver(cmd, id, data, 0);
24487 +}
24488 +
24489 +#ifdef CONFIG_COMPAT
24490 +
24491 +asmlinkage long
24492 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
24493 +{
24494 +       return do_vserver(cmd, id, data, 1);
24495 +}
24496 +
24497 +#endif /* CONFIG_COMPAT */
24498 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/sysctl.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/sysctl.c
24499 --- linux-2.6.35.4/kernel/vserver/sysctl.c      1970-01-01 01:00:00.000000000 +0100
24500 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/sysctl.c        2010-08-02 17:05:06.000000000 +0200
24501 @@ -0,0 +1,241 @@
24502 +/*
24503 + *  kernel/vserver/sysctl.c
24504 + *
24505 + *  Virtual Context Support
24506 + *
24507 + *  Copyright (C) 2004-2007  Herbert Pötzl
24508 + *
24509 + *  V0.01  basic structure
24510 + *
24511 + */
24512 +
24513 +#include <linux/module.h>
24514 +#include <linux/ctype.h>
24515 +#include <linux/sysctl.h>
24516 +#include <linux/parser.h>
24517 +#include <asm/uaccess.h>
24518 +
24519 +enum {
24520 +       CTL_DEBUG_ERROR         = 0,
24521 +       CTL_DEBUG_SWITCH        = 1,
24522 +       CTL_DEBUG_XID,
24523 +       CTL_DEBUG_NID,
24524 +       CTL_DEBUG_TAG,
24525 +       CTL_DEBUG_NET,
24526 +       CTL_DEBUG_LIMIT,
24527 +       CTL_DEBUG_CRES,
24528 +       CTL_DEBUG_DLIM,
24529 +       CTL_DEBUG_QUOTA,
24530 +       CTL_DEBUG_CVIRT,
24531 +       CTL_DEBUG_SPACE,
24532 +       CTL_DEBUG_MISC,
24533 +};
24534 +
24535 +
24536 +unsigned int vx_debug_switch   = 0;
24537 +unsigned int vx_debug_xid      = 0;
24538 +unsigned int vx_debug_nid      = 0;
24539 +unsigned int vx_debug_tag      = 0;
24540 +unsigned int vx_debug_net      = 0;
24541 +unsigned int vx_debug_limit    = 0;
24542 +unsigned int vx_debug_cres     = 0;
24543 +unsigned int vx_debug_dlim     = 0;
24544 +unsigned int vx_debug_quota    = 0;
24545 +unsigned int vx_debug_cvirt    = 0;
24546 +unsigned int vx_debug_space    = 0;
24547 +unsigned int vx_debug_misc     = 0;
24548 +
24549 +
24550 +static struct ctl_table_header *vserver_table_header;
24551 +static ctl_table vserver_root_table[];
24552 +
24553 +
24554 +void vserver_register_sysctl(void)
24555 +{
24556 +       if (!vserver_table_header) {
24557 +               vserver_table_header = register_sysctl_table(vserver_root_table);
24558 +       }
24559 +
24560 +}
24561 +
24562 +void vserver_unregister_sysctl(void)
24563 +{
24564 +       if (vserver_table_header) {
24565 +               unregister_sysctl_table(vserver_table_header);
24566 +               vserver_table_header = NULL;
24567 +       }
24568 +}
24569 +
24570 +
24571 +static int proc_dodebug(ctl_table *table, int write,
24572 +       void __user *buffer, size_t *lenp, loff_t *ppos)
24573 +{
24574 +       char            tmpbuf[20], *p, c;
24575 +       unsigned int    value;
24576 +       size_t          left, len;
24577 +
24578 +       if ((*ppos && !write) || !*lenp) {
24579 +               *lenp = 0;
24580 +               return 0;
24581 +       }
24582 +
24583 +       left = *lenp;
24584 +
24585 +       if (write) {
24586 +               if (!access_ok(VERIFY_READ, buffer, left))
24587 +                       return -EFAULT;
24588 +               p = (char *)buffer;
24589 +               while (left && __get_user(c, p) >= 0 && isspace(c))
24590 +                       left--, p++;
24591 +               if (!left)
24592 +                       goto done;
24593 +
24594 +               if (left > sizeof(tmpbuf) - 1)
24595 +                       return -EINVAL;
24596 +               if (copy_from_user(tmpbuf, p, left))
24597 +                       return -EFAULT;
24598 +               tmpbuf[left] = '\0';
24599 +
24600 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
24601 +                       value = 10 * value + (*p - '0');
24602 +               if (*p && !isspace(*p))
24603 +                       return -EINVAL;
24604 +               while (left && isspace(*p))
24605 +                       left--, p++;
24606 +               *(unsigned int *)table->data = value;
24607 +       } else {
24608 +               if (!access_ok(VERIFY_WRITE, buffer, left))
24609 +                       return -EFAULT;
24610 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
24611 +               if (len > left)
24612 +                       len = left;
24613 +               if (__copy_to_user(buffer, tmpbuf, len))
24614 +                       return -EFAULT;
24615 +               if ((left -= len) > 0) {
24616 +                       if (put_user('\n', (char *)buffer + len))
24617 +                               return -EFAULT;
24618 +                       left--;
24619 +               }
24620 +       }
24621 +
24622 +done:
24623 +       *lenp -= left;
24624 +       *ppos += *lenp;
24625 +       return 0;
24626 +}
24627 +
24628 +static int zero;
24629 +
24630 +#define        CTL_ENTRY(ctl, name)                            \
24631 +       {                                               \
24632 +               .procname       = #name,                \
24633 +               .data           = &vx_ ## name,         \
24634 +               .maxlen         = sizeof(int),          \
24635 +               .mode           = 0644,                 \
24636 +               .proc_handler   = &proc_dodebug,        \
24637 +               .extra1         = &zero,                \
24638 +               .extra2         = &zero,                \
24639 +       }
24640 +
24641 +static ctl_table vserver_debug_table[] = {
24642 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
24643 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
24644 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
24645 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
24646 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
24647 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
24648 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
24649 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
24650 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
24651 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
24652 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
24653 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
24654 +       { 0 }
24655 +};
24656 +
24657 +static ctl_table vserver_root_table[] = {
24658 +       {
24659 +               .procname       = "vserver",
24660 +               .mode           = 0555,
24661 +               .child          = vserver_debug_table
24662 +       },
24663 +       { 0 }
24664 +};
24665 +
24666 +
24667 +static match_table_t tokens = {
24668 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24669 +       { CTL_DEBUG_XID,        "xid=%x"        },
24670 +       { CTL_DEBUG_NID,        "nid=%x"        },
24671 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24672 +       { CTL_DEBUG_NET,        "net=%x"        },
24673 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24674 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24675 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24676 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24677 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24678 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24679 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24680 +       { CTL_DEBUG_ERROR,      NULL            }
24681 +};
24682 +
24683 +#define        HANDLE_CASE(id, name, val)                              \
24684 +       case CTL_DEBUG_ ## id:                                  \
24685 +               vx_debug_ ## name = val;                        \
24686 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24687 +               break
24688 +
24689 +
24690 +static int __init vs_debug_setup(char *str)
24691 +{
24692 +       char *p;
24693 +       int token;
24694 +
24695 +       printk("vs_debug_setup(%s)\n", str);
24696 +       while ((p = strsep(&str, ",")) != NULL) {
24697 +               substring_t args[MAX_OPT_ARGS];
24698 +               unsigned int value;
24699 +
24700 +               if (!*p)
24701 +                       continue;
24702 +
24703 +               token = match_token(p, tokens, args);
24704 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24705 +
24706 +               switch (token) {
24707 +               HANDLE_CASE(SWITCH, switch, value);
24708 +               HANDLE_CASE(XID,    xid,    value);
24709 +               HANDLE_CASE(NID,    nid,    value);
24710 +               HANDLE_CASE(TAG,    tag,    value);
24711 +               HANDLE_CASE(NET,    net,    value);
24712 +               HANDLE_CASE(LIMIT,  limit,  value);
24713 +               HANDLE_CASE(CRES,   cres,   value);
24714 +               HANDLE_CASE(DLIM,   dlim,   value);
24715 +               HANDLE_CASE(QUOTA,  quota,  value);
24716 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24717 +               HANDLE_CASE(SPACE,  space,  value);
24718 +               HANDLE_CASE(MISC,   misc,   value);
24719 +               default:
24720 +                       return -EINVAL;
24721 +                       break;
24722 +               }
24723 +       }
24724 +       return 1;
24725 +}
24726 +
24727 +__setup("vsdebug=", vs_debug_setup);
24728 +
24729 +
24730 +
24731 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24732 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24733 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24734 +EXPORT_SYMBOL_GPL(vx_debug_net);
24735 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24736 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24737 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24738 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24739 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24740 +EXPORT_SYMBOL_GPL(vx_debug_space);
24741 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24742 +
24743 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/tag.c linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/tag.c
24744 --- linux-2.6.35.4/kernel/vserver/tag.c 1970-01-01 01:00:00.000000000 +0100
24745 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/tag.c   2010-08-02 17:05:06.000000000 +0200
24746 @@ -0,0 +1,63 @@
24747 +/*
24748 + *  linux/kernel/vserver/tag.c
24749 + *
24750 + *  Virtual Server: Shallow Tag Space
24751 + *
24752 + *  Copyright (C) 2007  Herbert Pötzl
24753 + *
24754 + *  V0.01  basic implementation
24755 + *
24756 + */
24757 +
24758 +#include <linux/sched.h>
24759 +#include <linux/vserver/debug.h>
24760 +#include <linux/vs_pid.h>
24761 +#include <linux/vs_tag.h>
24762 +
24763 +#include <linux/vserver/tag_cmd.h>
24764 +
24765 +
24766 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24767 +{
24768 +       if (!p)
24769 +               BUG();
24770 +
24771 +       vxdprintk(VXD_CBIT(tag, 5),
24772 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24773 +
24774 +       task_lock(p);
24775 +       p->tag = tag;
24776 +       task_unlock(p);
24777 +
24778 +       vxdprintk(VXD_CBIT(tag, 5),
24779 +               "moved task %p into [#%d]", p, tag);
24780 +       return 0;
24781 +}
24782 +
24783 +/* vserver syscall commands below here */
24784 +
24785 +/* taks xid and vx_info functions */
24786 +
24787 +
24788 +int vc_task_tag(uint32_t id)
24789 +{
24790 +       tag_t tag;
24791 +
24792 +       if (id) {
24793 +               struct task_struct *tsk;
24794 +               read_lock(&tasklist_lock);
24795 +               tsk = find_task_by_real_pid(id);
24796 +               tag = (tsk) ? tsk->tag : -ESRCH;
24797 +               read_unlock(&tasklist_lock);
24798 +       } else
24799 +               tag = dx_current_tag();
24800 +       return tag;
24801 +}
24802 +
24803 +
24804 +int vc_tag_migrate(uint32_t tag)
24805 +{
24806 +       return dx_migrate_task(current, tag & 0xFFFF);
24807 +}
24808 +
24809 +
24810 diff -NurpP --minimal linux-2.6.35.4/kernel/vserver/vci_config.h linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/vci_config.h
24811 --- linux-2.6.35.4/kernel/vserver/vci_config.h  1970-01-01 01:00:00.000000000 +0100
24812 +++ linux-2.6.35.4-vs2.3.0.36.32/kernel/vserver/vci_config.h    2010-08-02 17:05:06.000000000 +0200
24813 @@ -0,0 +1,85 @@
24814 +
24815 +/*  interface version */
24816 +
24817 +#define VCI_VERSION            0x00020306
24818 +
24819 +
24820 +enum {
24821 +       VCI_KCBIT_NO_DYNAMIC = 0,
24822 +
24823 +       VCI_KCBIT_PROC_SECURE = 4,
24824 +       VCI_KCBIT_HARDCPU = 5,
24825 +       VCI_KCBIT_IDLELIMIT = 6,
24826 +       VCI_KCBIT_IDLETIME = 7,
24827 +
24828 +       VCI_KCBIT_COWBL = 8,
24829 +       VCI_KCBIT_FULLCOWBL = 9,
24830 +       VCI_KCBIT_SPACES = 10,
24831 +       VCI_KCBIT_NETV2 = 11,
24832 +       VCI_KCBIT_MEMCG = 12,
24833 +
24834 +       VCI_KCBIT_DEBUG = 16,
24835 +       VCI_KCBIT_HISTORY = 20,
24836 +       VCI_KCBIT_TAGGED = 24,
24837 +       VCI_KCBIT_PPTAG = 28,
24838 +
24839 +       VCI_KCBIT_MORE = 31,
24840 +};
24841 +
24842 +
24843 +static inline uint32_t vci_kernel_config(void)
24844 +{
24845 +       return
24846 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24847 +
24848 +       /* configured features */
24849 +#ifdef CONFIG_VSERVER_PROC_SECURE
24850 +       (1 << VCI_KCBIT_PROC_SECURE) |
24851 +#endif
24852 +#ifdef CONFIG_VSERVER_HARDCPU
24853 +       (1 << VCI_KCBIT_HARDCPU) |
24854 +#endif
24855 +#ifdef CONFIG_VSERVER_IDLELIMIT
24856 +       (1 << VCI_KCBIT_IDLELIMIT) |
24857 +#endif
24858 +#ifdef CONFIG_VSERVER_IDLETIME
24859 +       (1 << VCI_KCBIT_IDLETIME) |
24860 +#endif
24861 +#ifdef CONFIG_VSERVER_COWBL
24862 +       (1 << VCI_KCBIT_COWBL) |
24863 +       (1 << VCI_KCBIT_FULLCOWBL) |
24864 +#endif
24865 +       (1 << VCI_KCBIT_SPACES) |
24866 +       (1 << VCI_KCBIT_NETV2) |
24867 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24868 +       (1 << VCI_KCBIT_MEMCG) |
24869 +#endif
24870 +
24871 +       /* debug options */
24872 +#ifdef CONFIG_VSERVER_DEBUG
24873 +       (1 << VCI_KCBIT_DEBUG) |
24874 +#endif
24875 +#ifdef CONFIG_VSERVER_HISTORY
24876 +       (1 << VCI_KCBIT_HISTORY) |
24877 +#endif
24878 +
24879 +       /* inode context tagging */
24880 +#if    defined(CONFIG_TAGGING_NONE)
24881 +       (0 << VCI_KCBIT_TAGGED) |
24882 +#elif  defined(CONFIG_TAGGING_UID16)
24883 +       (1 << VCI_KCBIT_TAGGED) |
24884 +#elif  defined(CONFIG_TAGGING_GID16)
24885 +       (2 << VCI_KCBIT_TAGGED) |
24886 +#elif  defined(CONFIG_TAGGING_ID24)
24887 +       (3 << VCI_KCBIT_TAGGED) |
24888 +#elif  defined(CONFIG_TAGGING_INTERN)
24889 +       (4 << VCI_KCBIT_TAGGED) |
24890 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24891 +       (5 << VCI_KCBIT_TAGGED) |
24892 +#else
24893 +       (7 << VCI_KCBIT_TAGGED) |
24894 +#endif
24895 +       (1 << VCI_KCBIT_PPTAG) |
24896 +       0;
24897 +}
24898 +
24899 diff -NurpP --minimal linux-2.6.35.4/mm/filemap_xip.c linux-2.6.35.4-vs2.3.0.36.32/mm/filemap_xip.c
24900 --- linux-2.6.35.4/mm/filemap_xip.c     2010-07-07 18:31:58.000000000 +0200
24901 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/filemap_xip.c       2010-08-02 17:05:06.000000000 +0200
24902 @@ -18,6 +18,7 @@
24903  #include <linux/seqlock.h>
24904  #include <linux/mutex.h>
24905  #include <linux/gfp.h>
24906 +#include <linux/vs_memory.h>
24907  #include <asm/tlbflush.h>
24908  #include <asm/io.h>
24909  
24910 diff -NurpP --minimal linux-2.6.35.4/mm/fremap.c linux-2.6.35.4-vs2.3.0.36.32/mm/fremap.c
24911 --- linux-2.6.35.4/mm/fremap.c  2010-07-07 18:31:58.000000000 +0200
24912 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/fremap.c    2010-08-02 17:05:06.000000000 +0200
24913 @@ -16,6 +16,7 @@
24914  #include <linux/module.h>
24915  #include <linux/syscalls.h>
24916  #include <linux/mmu_notifier.h>
24917 +#include <linux/vs_memory.h>
24918  
24919  #include <asm/mmu_context.h>
24920  #include <asm/cacheflush.h>
24921 diff -NurpP --minimal linux-2.6.35.4/mm/hugetlb.c linux-2.6.35.4-vs2.3.0.36.32/mm/hugetlb.c
24922 --- linux-2.6.35.4/mm/hugetlb.c 2010-08-02 16:52:58.000000000 +0200
24923 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/hugetlb.c   2010-08-02 17:05:06.000000000 +0200
24924 @@ -25,6 +25,7 @@
24925  
24926  #include <linux/hugetlb.h>
24927  #include <linux/node.h>
24928 +#include <linux/vs_memory.h>
24929  #include "internal.h"
24930  
24931  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24932 diff -NurpP --minimal linux-2.6.35.4/mm/memcontrol.c linux-2.6.35.4-vs2.3.0.36.32/mm/memcontrol.c
24933 --- linux-2.6.35.4/mm/memcontrol.c      2010-08-02 16:52:58.000000000 +0200
24934 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/memcontrol.c        2010-08-02 17:05:06.000000000 +0200
24935 @@ -635,6 +635,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24936                                 struct mem_cgroup, css);
24937  }
24938  
24939 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24940 +{
24941 +       return res_counter_read_u64(&mem->res, member);
24942 +}
24943 +
24944 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24945 +{
24946 +       return res_counter_read_u64(&mem->memsw, member);
24947 +}
24948 +
24949 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24950 +{
24951 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24952 +}
24953 +
24954 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24955 +{
24956 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24957 +}
24958 +
24959 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24960 +{
24961 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24962 +}
24963 +
24964  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24965  {
24966         struct mem_cgroup *mem = NULL;
24967 diff -NurpP --minimal linux-2.6.35.4/mm/memory.c linux-2.6.35.4-vs2.3.0.36.32/mm/memory.c
24968 --- linux-2.6.35.4/mm/memory.c  2010-09-05 01:41:57.000000000 +0200
24969 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/memory.c    2010-09-06 02:59:52.000000000 +0200
24970 @@ -3107,6 +3107,7 @@ static inline int handle_pte_fault(struc
24971  {
24972         pte_t entry;
24973         spinlock_t *ptl;
24974 +       int ret = 0, type = VXPT_UNKNOWN;
24975  
24976         entry = *pte;
24977         if (!pte_present(entry)) {
24978 @@ -3131,9 +3132,12 @@ static inline int handle_pte_fault(struc
24979         if (unlikely(!pte_same(*pte, entry)))
24980                 goto unlock;
24981         if (flags & FAULT_FLAG_WRITE) {
24982 -               if (!pte_write(entry))
24983 -                       return do_wp_page(mm, vma, address,
24984 +               if (!pte_write(entry)) {
24985 +                       ret = do_wp_page(mm, vma, address,
24986                                         pte, pmd, ptl, entry);
24987 +                       type = VXPT_WRITE;
24988 +                       goto out;
24989 +               }
24990                 entry = pte_mkdirty(entry);
24991         }
24992         entry = pte_mkyoung(entry);
24993 @@ -3151,7 +3155,10 @@ static inline int handle_pte_fault(struc
24994         }
24995  unlock:
24996         pte_unmap_unlock(pte, ptl);
24997 -       return 0;
24998 +       ret = 0;
24999 +out:
25000 +       vx_page_fault(mm, vma, type, ret);
25001 +       return ret;
25002  }
25003  
25004  /*
25005 diff -NurpP --minimal linux-2.6.35.4/mm/mlock.c linux-2.6.35.4-vs2.3.0.36.32/mm/mlock.c
25006 --- linux-2.6.35.4/mm/mlock.c   2010-09-05 01:41:57.000000000 +0200
25007 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/mlock.c     2010-09-06 02:59:52.000000000 +0200
25008 @@ -18,6 +18,7 @@
25009  #include <linux/rmap.h>
25010  #include <linux/mmzone.h>
25011  #include <linux/hugetlb.h>
25012 +#include <linux/vs_memory.h>
25013  
25014  #include "internal.h"
25015  
25016 @@ -490,7 +491,7 @@ static int do_mlock(unsigned long start,
25017  
25018  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
25019  {
25020 -       unsigned long locked;
25021 +       unsigned long locked, grow;
25022         unsigned long lock_limit;
25023         int error = -ENOMEM;
25024  
25025 @@ -512,6 +513,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25026         /* check against resource limits */
25027         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
25028                 error = do_mlock(start, len, 1);
25029 +out:
25030         up_write(&current->mm->mmap_sem);
25031         return error;
25032  }
25033 diff -NurpP --minimal linux-2.6.35.4/mm/mremap.c linux-2.6.35.4-vs2.3.0.36.32/mm/mremap.c
25034 --- linux-2.6.35.4/mm/mremap.c  2010-07-07 18:31:58.000000000 +0200
25035 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/mremap.c    2010-08-02 17:05:06.000000000 +0200
25036 @@ -19,6 +19,7 @@
25037  #include <linux/security.h>
25038  #include <linux/syscalls.h>
25039  #include <linux/mmu_notifier.h>
25040 +#include <linux/vs_memory.h>
25041  
25042  #include <asm/uaccess.h>
25043  #include <asm/cacheflush.h>
25044 diff -NurpP --minimal linux-2.6.35.4/mm/oom_kill.c linux-2.6.35.4-vs2.3.0.36.32/mm/oom_kill.c
25045 --- linux-2.6.35.4/mm/oom_kill.c        2010-08-02 16:52:58.000000000 +0200
25046 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/oom_kill.c  2010-08-02 17:05:06.000000000 +0200
25047 @@ -28,6 +28,9 @@
25048  #include <linux/notifier.h>
25049  #include <linux/memcontrol.h>
25050  #include <linux/security.h>
25051 +#include <linux/reboot.h>
25052 +#include <linux/vs_memory.h>
25053 +#include <linux/vs_context.h>
25054  
25055  int sysctl_panic_on_oom;
25056  int sysctl_oom_kill_allocating_task;
25057 @@ -187,9 +190,21 @@ unsigned long badness(struct task_struct
25058                         points >>= -(oom_adj);
25059         }
25060  
25061 +       /*
25062 +        * add points for context badness and
25063 +        * reduce badness for processes belonging to
25064 +        * a different context
25065 +        */
25066 +
25067 +       points += vx_badness(p, mm);
25068 +
25069 +       if ((vx_current_xid() > 1) &&
25070 +               vx_current_xid() != vx_task_xid(p))
25071 +               points /= 16;
25072 +
25073  #ifdef DEBUG
25074 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
25075 -       p->pid, p->comm, points);
25076 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
25077 +               task_pid_nr(p), p->xid, p->comm, points);
25078  #endif
25079         return points;
25080  }
25081 @@ -250,6 +265,7 @@ static struct task_struct *select_bad_pr
25082         struct task_struct *p;
25083         struct task_struct *chosen = NULL;
25084         struct timespec uptime;
25085 +       unsigned xid = vx_current_xid();
25086         *ppoints = 0;
25087  
25088         do_posix_clock_monotonic_gettime(&uptime);
25089 @@ -262,11 +278,14 @@ static struct task_struct *select_bad_pr
25090                  */
25091                 if (!p->mm)
25092                         continue;
25093 -               /* skip the init task */
25094 -               if (is_global_init(p))
25095 +               /* skip the init task, global and per guest */
25096 +               if (task_is_init(p))
25097                         continue;
25098                 if (mem && !task_in_mem_cgroup(p, mem))
25099                         continue;
25100 +               /* skip other guest and host processes if oom in guest */
25101 +               if (xid && vx_task_xid(p) != xid)
25102 +                       continue;
25103  
25104                 /*
25105                  * This task already has access to memory reserves and is
25106 @@ -398,9 +417,9 @@ static void __oom_kill_task(struct task_
25107         }
25108  
25109         if (verbose)
25110 -               printk(KERN_ERR "Killed process %d (%s) "
25111 +               printk(KERN_ERR "Killed process %s(%d:#%u) "
25112                        "vsz:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
25113 -                      task_pid_nr(p), p->comm,
25114 +                      p->comm, task_pid_nr(p), p->xid,
25115                        K(p->mm->total_vm),
25116                        K(get_mm_counter(p->mm, MM_ANONPAGES)),
25117                        K(get_mm_counter(p->mm, MM_FILEPAGES)));
25118 @@ -453,8 +472,8 @@ static int oom_kill_process(struct task_
25119                 return 0;
25120         }
25121  
25122 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
25123 -                                       message, task_pid_nr(p), p->comm, points);
25124 +       printk(KERN_ERR "%s: kill process %s(%d:#%u) score %li or a child\n",
25125 +               message, p->comm, task_pid_nr(p), p->xid, points);
25126  
25127         /* Try to kill a child first */
25128         list_for_each_entry(c, &p->children, sibling) {
25129 @@ -554,6 +573,8 @@ void clear_zonelist_oom(struct zonelist 
25130         spin_unlock(&zone_scan_lock);
25131  }
25132  
25133 +long vs_oom_action(unsigned int);
25134 +
25135  /*
25136   * Must be called with tasklist_lock held for read.
25137   */
25138 @@ -580,7 +601,11 @@ retry:
25139         if (!p) {
25140                 read_unlock(&tasklist_lock);
25141                 dump_header(NULL, gfp_mask, order, NULL);
25142 -               panic("Out of memory and no killable processes...\n");
25143 +               /* avoid panic for guest OOM */
25144 +               if (current->xid)
25145 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
25146 +               else
25147 +                       panic("Out of memory and no killable processes...\n");
25148         }
25149  
25150         if (oom_kill_process(p, gfp_mask, order, points, NULL,
25151 diff -NurpP --minimal linux-2.6.35.4/mm/page_alloc.c linux-2.6.35.4-vs2.3.0.36.32/mm/page_alloc.c
25152 --- linux-2.6.35.4/mm/page_alloc.c      2010-08-02 16:52:58.000000000 +0200
25153 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/page_alloc.c        2010-08-02 17:46:11.000000000 +0200
25154 @@ -52,6 +52,8 @@
25155  #include <linux/compaction.h>
25156  #include <trace/events/kmem.h>
25157  #include <linux/ftrace_event.h>
25158 +#include <linux/vs_base.h>
25159 +#include <linux/vs_limit.h>
25160  
25161  #include <asm/tlbflush.h>
25162  #include <asm/div64.h>
25163 @@ -2305,6 +2307,9 @@ void si_meminfo(struct sysinfo *val)
25164         val->totalhigh = totalhigh_pages;
25165         val->freehigh = nr_free_highpages();
25166         val->mem_unit = PAGE_SIZE;
25167 +
25168 +       if (vx_flags(VXF_VIRT_MEM, 0))
25169 +               vx_vsi_meminfo(val);
25170  }
25171  
25172  EXPORT_SYMBOL(si_meminfo);
25173 @@ -2325,6 +2330,9 @@ void si_meminfo_node(struct sysinfo *val
25174         val->freehigh = 0;
25175  #endif
25176         val->mem_unit = PAGE_SIZE;
25177 +
25178 +       if (vx_flags(VXF_VIRT_MEM, 0))
25179 +               vx_vsi_meminfo(val);
25180  }
25181  #endif
25182  
25183 diff -NurpP --minimal linux-2.6.35.4/mm/rmap.c linux-2.6.35.4-vs2.3.0.36.32/mm/rmap.c
25184 --- linux-2.6.35.4/mm/rmap.c    2010-08-02 16:52:58.000000000 +0200
25185 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/rmap.c      2010-08-02 17:05:06.000000000 +0200
25186 @@ -56,6 +56,7 @@
25187  #include <linux/memcontrol.h>
25188  #include <linux/mmu_notifier.h>
25189  #include <linux/migrate.h>
25190 +#include <linux/vs_memory.h>
25191  
25192  #include <asm/tlbflush.h>
25193  
25194 diff -NurpP --minimal linux-2.6.35.4/mm/shmem.c linux-2.6.35.4-vs2.3.0.36.32/mm/shmem.c
25195 --- linux-2.6.35.4/mm/shmem.c   2010-08-02 16:52:58.000000000 +0200
25196 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/shmem.c     2010-08-02 17:05:06.000000000 +0200
25197 @@ -1788,7 +1788,7 @@ static int shmem_statfs(struct dentry *d
25198  {
25199         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
25200  
25201 -       buf->f_type = TMPFS_MAGIC;
25202 +       buf->f_type = TMPFS_SUPER_MAGIC;
25203         buf->f_bsize = PAGE_CACHE_SIZE;
25204         buf->f_namelen = NAME_MAX;
25205         spin_lock(&sbinfo->stat_lock);
25206 @@ -2350,7 +2350,7 @@ int shmem_fill_super(struct super_block 
25207         sb->s_maxbytes = SHMEM_MAX_BYTES;
25208         sb->s_blocksize = PAGE_CACHE_SIZE;
25209         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
25210 -       sb->s_magic = TMPFS_MAGIC;
25211 +       sb->s_magic = TMPFS_SUPER_MAGIC;
25212         sb->s_op = &shmem_ops;
25213         sb->s_time_gran = 1;
25214  #ifdef CONFIG_TMPFS_POSIX_ACL
25215 diff -NurpP --minimal linux-2.6.35.4/mm/slab.c linux-2.6.35.4-vs2.3.0.36.32/mm/slab.c
25216 --- linux-2.6.35.4/mm/slab.c    2010-09-05 01:41:57.000000000 +0200
25217 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/slab.c      2010-09-06 02:59:52.000000000 +0200
25218 @@ -408,6 +408,8 @@ static void kmem_list3_init(struct kmem_
25219  #define STATS_INC_FREEMISS(x)  do { } while (0)
25220  #endif
25221  
25222 +#include "slab_vs.h"
25223 +
25224  #if DEBUG
25225  
25226  /*
25227 @@ -3347,6 +3349,7 @@ retry:
25228  
25229         obj = slab_get_obj(cachep, slabp, nodeid);
25230         check_slabp(cachep, slabp);
25231 +       vx_slab_alloc(cachep, flags);
25232         l3->free_objects--;
25233         /* move slabp to correct slabp list: */
25234         list_del(&slabp->list);
25235 @@ -3424,6 +3427,7 @@ __cache_alloc_node(struct kmem_cache *ca
25236         /* ___cache_alloc_node can fall back to other nodes */
25237         ptr = ____cache_alloc_node(cachep, flags, nodeid);
25238    out:
25239 +       vx_slab_alloc(cachep, flags);
25240         local_irq_restore(save_flags);
25241         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
25242         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
25243 @@ -3610,6 +3614,7 @@ static inline void __cache_free(struct k
25244         check_irq_off();
25245         kmemleak_free_recursive(objp, cachep->flags);
25246         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
25247 +       vx_slab_free(cachep);
25248  
25249         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
25250  
25251 diff -NurpP --minimal linux-2.6.35.4/mm/slab_vs.h linux-2.6.35.4-vs2.3.0.36.32/mm/slab_vs.h
25252 --- linux-2.6.35.4/mm/slab_vs.h 1970-01-01 01:00:00.000000000 +0100
25253 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/slab_vs.h   2010-08-02 17:05:06.000000000 +0200
25254 @@ -0,0 +1,29 @@
25255 +
25256 +#include <linux/vserver/context.h>
25257 +
25258 +#include <linux/vs_context.h>
25259 +
25260 +static inline
25261 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
25262 +{
25263 +       int what = gfp_zone(cachep->gfpflags);
25264 +       struct vx_info *vxi = current_vx_info();
25265 +
25266 +       if (!vxi)
25267 +               return;
25268 +
25269 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
25270 +}
25271 +
25272 +static inline
25273 +void vx_slab_free(struct kmem_cache *cachep)
25274 +{
25275 +       int what = gfp_zone(cachep->gfpflags);
25276 +       struct vx_info *vxi = current_vx_info();
25277 +
25278 +       if (!vxi)
25279 +               return;
25280 +
25281 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
25282 +}
25283 +
25284 diff -NurpP --minimal linux-2.6.35.4/mm/swapfile.c linux-2.6.35.4-vs2.3.0.36.32/mm/swapfile.c
25285 --- linux-2.6.35.4/mm/swapfile.c        2010-09-05 01:41:57.000000000 +0200
25286 +++ linux-2.6.35.4-vs2.3.0.36.32/mm/swapfile.c  2010-08-14 18:19:32.000000000 +0200
25287 @@ -35,6 +35,8 @@
25288  #include <asm/tlbflush.h>
25289  #include <linux/swapops.h>
25290  #include <linux/page_cgroup.h>
25291 +#include <linux/vs_base.h>
25292 +#include <linux/vs_memory.h>
25293  
25294  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
25295                                  unsigned char);
25296 @@ -1734,6 +1736,16 @@ static int swap_show(struct seq_file *sw
25297  
25298         if (si == SEQ_START_TOKEN) {
25299                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
25300 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
25301 +                       struct sysinfo si;
25302 +
25303 +                       vx_vsi_swapinfo(&si);
25304 +                       if (si.totalswap < (1 << 10))
25305 +                               return 0;
25306 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
25307 +                               "hdv0", "partition", si.totalswap >> 10,
25308 +                               (si.totalswap - si.freeswap) >> 10, -1);
25309 +               }
25310                 return 0;
25311         }
25312  
25313 @@ -2118,6 +2130,8 @@ void si_swapinfo(struct sysinfo *val)
25314         val->freeswap = nr_swap_pages + nr_to_be_unused;
25315         val->totalswap = total_swap_pages + nr_to_be_unused;
25316         spin_unlock(&swap_lock);
25317 +       if (vx_flags(VXF_VIRT_MEM, 0))
25318 +               vx_vsi_swapinfo(val);
25319  }
25320  
25321  /*
25322 diff -NurpP --minimal linux-2.6.35.4/net/core/dev.c linux-2.6.35.4-vs2.3.0.36.32/net/core/dev.c
25323 --- linux-2.6.35.4/net/core/dev.c       2010-09-05 01:41:57.000000000 +0200
25324 +++ linux-2.6.35.4-vs2.3.0.36.32/net/core/dev.c 2010-09-06 02:59:52.000000000 +0200
25325 @@ -129,6 +129,7 @@
25326  #include <linux/in.h>
25327  #include <linux/jhash.h>
25328  #include <linux/random.h>
25329 +#include <linux/vs_inet.h>
25330  #include <trace/events/napi.h>
25331  #include <linux/pci.h>
25332  
25333 @@ -609,7 +610,8 @@ struct net_device *__dev_get_by_name(str
25334         struct hlist_head *head = dev_name_hash(net, name);
25335  
25336         hlist_for_each_entry(dev, p, head, name_hlist)
25337 -               if (!strncmp(dev->name, name, IFNAMSIZ))
25338 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
25339 +                   nx_dev_visible(current_nx_info(), dev))
25340                         return dev;
25341  
25342         return NULL;
25343 @@ -635,7 +637,8 @@ struct net_device *dev_get_by_name_rcu(s
25344         struct hlist_head *head = dev_name_hash(net, name);
25345  
25346         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
25347 -               if (!strncmp(dev->name, name, IFNAMSIZ))
25348 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
25349 +                   nx_dev_visible(current_nx_info(), dev))
25350                         return dev;
25351  
25352         return NULL;
25353 @@ -686,7 +689,8 @@ struct net_device *__dev_get_by_index(st
25354         struct hlist_head *head = dev_index_hash(net, ifindex);
25355  
25356         hlist_for_each_entry(dev, p, head, index_hlist)
25357 -               if (dev->ifindex == ifindex)
25358 +               if ((dev->ifindex == ifindex) &&
25359 +                   nx_dev_visible(current_nx_info(), dev))
25360                         return dev;
25361  
25362         return NULL;
25363 @@ -711,7 +715,8 @@ struct net_device *dev_get_by_index_rcu(
25364         struct hlist_head *head = dev_index_hash(net, ifindex);
25365  
25366         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
25367 -               if (dev->ifindex == ifindex)
25368 +               if ((dev->ifindex == ifindex) &&
25369 +                   nx_dev_visible(current_nx_info(), dev))
25370                         return dev;
25371  
25372         return NULL;
25373 @@ -764,10 +769,12 @@ struct net_device *dev_getbyhwaddr(struc
25374  
25375         ASSERT_RTNL();
25376  
25377 -       for_each_netdev(net, dev)
25378 +       for_each_netdev(net, dev) {
25379                 if (dev->type == type &&
25380 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
25381 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
25382 +                   nx_dev_visible(current_nx_info(), dev))
25383                         return dev;
25384 +       }
25385  
25386         return NULL;
25387  }
25388 @@ -778,9 +785,11 @@ struct net_device *__dev_getfirstbyhwtyp
25389         struct net_device *dev;
25390  
25391         ASSERT_RTNL();
25392 -       for_each_netdev(net, dev)
25393 -               if (dev->type == type)
25394 +       for_each_netdev(net, dev) {
25395 +               if ((dev->type == type) &&
25396 +                   nx_dev_visible(current_nx_info(), dev))
25397                         return dev;
25398 +       }
25399  
25400         return NULL;
25401  }
25402 @@ -902,6 +911,8 @@ static int __dev_alloc_name(struct net *
25403                                 continue;
25404                         if (i < 0 || i >= max_netdevices)
25405                                 continue;
25406 +                       if (!nx_dev_visible(current_nx_info(), d))
25407 +                               continue;
25408  
25409                         /*  avoid cases where sscanf is not exact inverse of printf */
25410                         snprintf(buf, IFNAMSIZ, name, i);
25411 @@ -3650,6 +3661,8 @@ static int dev_ifconf(struct net *net, c
25412  
25413         total = 0;
25414         for_each_netdev(net, dev) {
25415 +               if (!nx_dev_visible(current_nx_info(), dev))
25416 +                       continue;
25417                 for (i = 0; i < NPROTO; i++) {
25418                         if (gifconf_list[i]) {
25419                                 int done;
25420 @@ -3720,6 +3733,9 @@ static void dev_seq_printf_stats(struct 
25421  {
25422         const struct net_device_stats *stats = dev_get_stats(dev);
25423  
25424 +       if (!nx_dev_visible(current_nx_info(), dev))
25425 +               return;
25426 +
25427         seq_printf(seq, "%6s: %7lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
25428                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
25429                    dev->name, stats->rx_bytes, stats->rx_packets,
25430 diff -NurpP --minimal linux-2.6.35.4/net/core/rtnetlink.c linux-2.6.35.4-vs2.3.0.36.32/net/core/rtnetlink.c
25431 --- linux-2.6.35.4/net/core/rtnetlink.c 2010-08-02 16:52:59.000000000 +0200
25432 +++ linux-2.6.35.4-vs2.3.0.36.32/net/core/rtnetlink.c   2010-08-02 17:05:06.000000000 +0200
25433 @@ -926,6 +926,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
25434                 hlist_for_each_entry(dev, node, head, index_hlist) {
25435                         if (idx < s_idx)
25436                                 goto cont;
25437 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
25438 +                               continue;
25439                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
25440                                              NETLINK_CB(cb->skb).pid,
25441                                              cb->nlh->nlmsg_seq, 0,
25442 @@ -1642,6 +1644,9 @@ void rtmsg_ifinfo(int type, struct net_d
25443         struct sk_buff *skb;
25444         int err = -ENOBUFS;
25445  
25446 +       if (!nx_dev_visible(current_nx_info(), dev))
25447 +               return;
25448 +
25449         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
25450         if (skb == NULL)
25451                 goto errout;
25452 diff -NurpP --minimal linux-2.6.35.4/net/core/sock.c linux-2.6.35.4-vs2.3.0.36.32/net/core/sock.c
25453 --- linux-2.6.35.4/net/core/sock.c      2010-08-02 16:52:59.000000000 +0200
25454 +++ linux-2.6.35.4-vs2.3.0.36.32/net/core/sock.c        2010-08-02 17:05:06.000000000 +0200
25455 @@ -126,6 +126,10 @@
25456  #include <net/cls_cgroup.h>
25457  
25458  #include <linux/filter.h>
25459 +#include <linux/vs_socket.h>
25460 +#include <linux/vs_limit.h>
25461 +#include <linux/vs_context.h>
25462 +#include <linux/vs_network.h>
25463  
25464  #ifdef CONFIG_INET
25465  #include <net/tcp.h>
25466 @@ -1027,6 +1031,8 @@ static struct sock *sk_prot_alloc(struct
25467                         goto out_free_sec;
25468                 sk_tx_queue_clear(sk);
25469         }
25470 +               sock_vx_init(sk);
25471 +               sock_nx_init(sk);
25472  
25473         return sk;
25474  
25475 @@ -1120,6 +1126,11 @@ static void __sk_free(struct sock *sk)
25476                        __func__, atomic_read(&sk->sk_omem_alloc));
25477  
25478         put_net(sock_net(sk));
25479 +       vx_sock_dec(sk);
25480 +       clr_vx_info(&sk->sk_vx_info);
25481 +       sk->sk_xid = -1;
25482 +       clr_nx_info(&sk->sk_nx_info);
25483 +       sk->sk_nid = -1;
25484         sk_prot_free(sk->sk_prot_creator, sk);
25485  }
25486  
25487 @@ -1167,6 +1178,8 @@ struct sock *sk_clone(const struct sock 
25488  
25489                 /* SANITY */
25490                 get_net(sock_net(newsk));
25491 +               sock_vx_init(newsk);
25492 +               sock_nx_init(newsk);
25493                 sk_node_init(&newsk->sk_node);
25494                 sock_lock_init(newsk);
25495                 bh_lock_sock(newsk);
25496 @@ -1222,6 +1235,12 @@ struct sock *sk_clone(const struct sock 
25497                 smp_wmb();
25498                 atomic_set(&newsk->sk_refcnt, 2);
25499  
25500 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
25501 +               newsk->sk_xid = sk->sk_xid;
25502 +               vx_sock_inc(newsk);
25503 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
25504 +               newsk->sk_nid = sk->sk_nid;
25505 +
25506                 /*
25507                  * Increment the counter in the same struct proto as the master
25508                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
25509 @@ -1964,6 +1983,12 @@ void sock_init_data(struct socket *sock,
25510  
25511         sk->sk_stamp = ktime_set(-1L, 0);
25512  
25513 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
25514 +       sk->sk_xid = vx_current_xid();
25515 +       vx_sock_inc(sk);
25516 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
25517 +       sk->sk_nid = nx_current_nid();
25518 +
25519         /*
25520          * Before updating sk_refcnt, we must commit prior changes to memory
25521          * (Documentation/RCU/rculist_nulls.txt for details)
25522 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/af_inet.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/af_inet.c
25523 --- linux-2.6.35.4/net/ipv4/af_inet.c   2010-08-02 16:52:59.000000000 +0200
25524 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/af_inet.c     2010-08-02 17:05:06.000000000 +0200
25525 @@ -116,6 +116,7 @@
25526  #ifdef CONFIG_IP_MROUTE
25527  #include <linux/mroute.h>
25528  #endif
25529 +#include <linux/vs_limit.h>
25530  
25531  
25532  /* The inetsw table contains everything that inet_create needs to
25533 @@ -327,9 +328,13 @@ lookup_protocol:
25534         }
25535  
25536         err = -EPERM;
25537 +       if ((protocol == IPPROTO_ICMP) &&
25538 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25539 +               goto override;
25540 +
25541         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25542                 goto out_rcu_unlock;
25543 -
25544 +override:
25545         err = -EAFNOSUPPORT;
25546         if (!inet_netns_ok(net, protocol))
25547                 goto out_rcu_unlock;
25548 @@ -451,6 +456,7 @@ int inet_bind(struct socket *sock, struc
25549         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
25550         struct sock *sk = sock->sk;
25551         struct inet_sock *inet = inet_sk(sk);
25552 +       struct nx_v4_sock_addr nsa;
25553         unsigned short snum;
25554         int chk_addr_ret;
25555         int err;
25556 @@ -464,7 +470,11 @@ int inet_bind(struct socket *sock, struc
25557         if (addr_len < sizeof(struct sockaddr_in))
25558                 goto out;
25559  
25560 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25561 +       err = v4_map_sock_addr(inet, addr, &nsa);
25562 +       if (err)
25563 +               goto out;
25564 +
25565 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25566  
25567         /* Not specified by any standard per-se, however it breaks too
25568          * many applications when removed.  It is unfortunate since
25569 @@ -476,7 +486,7 @@ int inet_bind(struct socket *sock, struc
25570         err = -EADDRNOTAVAIL;
25571         if (!sysctl_ip_nonlocal_bind &&
25572             !(inet->freebind || inet->transparent) &&
25573 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
25574 +           nsa.saddr != htonl(INADDR_ANY) &&
25575             chk_addr_ret != RTN_LOCAL &&
25576             chk_addr_ret != RTN_MULTICAST &&
25577             chk_addr_ret != RTN_BROADCAST)
25578 @@ -501,7 +511,7 @@ int inet_bind(struct socket *sock, struc
25579         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
25580                 goto out_release_sock;
25581  
25582 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25583 +       v4_set_sock_addr(inet, &nsa);
25584         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25585                 inet->inet_saddr = 0;  /* Use device */
25586  
25587 @@ -703,11 +713,13 @@ int inet_getname(struct socket *sock, st
25588                      peer == 1))
25589                         return -ENOTCONN;
25590                 sin->sin_port = inet->inet_dport;
25591 -               sin->sin_addr.s_addr = inet->inet_daddr;
25592 +               sin->sin_addr.s_addr =
25593 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
25594         } else {
25595                 __be32 addr = inet->inet_rcv_saddr;
25596                 if (!addr)
25597                         addr = inet->inet_saddr;
25598 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
25599                 sin->sin_port = inet->inet_sport;
25600                 sin->sin_addr.s_addr = addr;
25601         }
25602 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/devinet.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/devinet.c
25603 --- linux-2.6.35.4/net/ipv4/devinet.c   2010-09-05 01:41:57.000000000 +0200
25604 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/devinet.c     2010-08-14 18:19:32.000000000 +0200
25605 @@ -417,6 +417,7 @@ struct in_device *inetdev_by_index(struc
25606  }
25607  EXPORT_SYMBOL(inetdev_by_index);
25608  
25609 +
25610  /* Called only from RTNL semaphored context. No locks. */
25611  
25612  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
25613 @@ -659,6 +660,8 @@ int devinet_ioctl(struct net *net, unsig
25614  
25615         in_dev = __in_dev_get_rtnl(dev);
25616         if (in_dev) {
25617 +               struct nx_info *nxi = current_nx_info();
25618 +
25619                 if (tryaddrmatch) {
25620                         /* Matthias Andree */
25621                         /* compare label and address (4.4BSD style) */
25622 @@ -667,6 +670,8 @@ int devinet_ioctl(struct net *net, unsig
25623                            This is checked above. */
25624                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25625                              ifap = &ifa->ifa_next) {
25626 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25627 +                                       continue;
25628                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
25629                                     sin_orig.sin_addr.s_addr ==
25630                                                         ifa->ifa_address) {
25631 @@ -679,9 +684,12 @@ int devinet_ioctl(struct net *net, unsig
25632                    comparing just the label */
25633                 if (!ifa) {
25634                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25635 -                            ifap = &ifa->ifa_next)
25636 +                            ifap = &ifa->ifa_next) {
25637 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25638 +                                       continue;
25639                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
25640                                         break;
25641 +                       }
25642                 }
25643         }
25644  
25645 @@ -833,6 +841,8 @@ static int inet_gifconf(struct net_devic
25646                 goto out;
25647  
25648         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
25649 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
25650 +                       continue;
25651                 if (!buf) {
25652                         done += sizeof(ifr);
25653                         continue;
25654 @@ -1182,6 +1192,7 @@ static int inet_dump_ifaddr(struct sk_bu
25655         struct net_device *dev;
25656         struct in_device *in_dev;
25657         struct in_ifaddr *ifa;
25658 +       struct sock *sk = skb->sk;
25659         struct hlist_head *head;
25660         struct hlist_node *node;
25661  
25662 @@ -1204,6 +1215,8 @@ static int inet_dump_ifaddr(struct sk_bu
25663  
25664                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
25665                              ifa = ifa->ifa_next, ip_idx++) {
25666 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
25667 +                               continue;
25668                                 if (ip_idx < s_ip_idx)
25669                                         continue;
25670                                 if (inet_fill_ifaddr(skb, ifa,
25671 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/fib_hash.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/fib_hash.c
25672 --- linux-2.6.35.4/net/ipv4/fib_hash.c  2010-07-07 18:31:59.000000000 +0200
25673 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/fib_hash.c    2010-08-02 17:05:06.000000000 +0200
25674 @@ -1017,7 +1017,7 @@ static int fib_seq_show(struct seq_file 
25675         prefix  = f->fn_key;
25676         mask    = FZ_MASK(iter->zone);
25677         flags   = fib_flag_trans(fa->fa_type, mask, fi);
25678 -       if (fi)
25679 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
25680                 seq_printf(seq,
25681                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
25682                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
25683 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/inet_connection_sock.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/inet_connection_sock.c
25684 --- linux-2.6.35.4/net/ipv4/inet_connection_sock.c      2010-08-02 16:52:59.000000000 +0200
25685 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/inet_connection_sock.c        2010-08-02 17:05:06.000000000 +0200
25686 @@ -52,10 +52,40 @@ void inet_get_local_port_range(int *low,
25687  }
25688  EXPORT_SYMBOL(inet_get_local_port_range);
25689  
25690 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25691 +{
25692 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
25693 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
25694 +
25695 +       if (inet_v6_ipv6only(sk2))
25696 +               return 0;
25697 +
25698 +       if (sk1_rcv_saddr &&
25699 +           sk2_rcv_saddr &&
25700 +           sk1_rcv_saddr == sk2_rcv_saddr)
25701 +               return 1;
25702 +
25703 +       if (sk1_rcv_saddr &&
25704 +           !sk2_rcv_saddr &&
25705 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
25706 +               return 1;
25707 +
25708 +       if (sk2_rcv_saddr &&
25709 +           !sk1_rcv_saddr &&
25710 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
25711 +               return 1;
25712 +
25713 +       if (!sk1_rcv_saddr &&
25714 +           !sk2_rcv_saddr &&
25715 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
25716 +               return 1;
25717 +
25718 +       return 0;
25719 +}
25720 +
25721  int inet_csk_bind_conflict(const struct sock *sk,
25722                            const struct inet_bind_bucket *tb)
25723  {
25724 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
25725         struct sock *sk2;
25726         struct hlist_node *node;
25727         int reuse = sk->sk_reuse;
25728 @@ -75,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25729                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25730                         if (!reuse || !sk2->sk_reuse ||
25731                             sk2->sk_state == TCP_LISTEN) {
25732 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
25733 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
25734 -                                   sk2_rcv_saddr == sk_rcv_saddr)
25735 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25736                                         break;
25737                         }
25738                 }
25739 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/inet_diag.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/inet_diag.c
25740 --- linux-2.6.35.4/net/ipv4/inet_diag.c 2010-07-07 18:31:59.000000000 +0200
25741 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/inet_diag.c   2010-08-02 17:05:06.000000000 +0200
25742 @@ -33,6 +33,8 @@
25743  #include <linux/stddef.h>
25744  
25745  #include <linux/inet_diag.h>
25746 +#include <linux/vs_network.h>
25747 +#include <linux/vs_inet.h>
25748  
25749  static const struct inet_diag_handler **inet_diag_table;
25750  
25751 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25752  
25753         r->id.idiag_sport = inet->inet_sport;
25754         r->id.idiag_dport = inet->inet_dport;
25755 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25756 -       r->id.idiag_dst[0] = inet->inet_daddr;
25757 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25758 +               inet->inet_rcv_saddr);
25759 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25760 +               inet->inet_daddr);
25761  
25762  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25763         if (r->idiag_family == AF_INET6) {
25764 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25765         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25766         r->id.idiag_sport     = tw->tw_sport;
25767         r->id.idiag_dport     = tw->tw_dport;
25768 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25769 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25770 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25771 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25772         r->idiag_state        = tw->tw_substate;
25773         r->idiag_timer        = 3;
25774         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25775 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25776         err = -EINVAL;
25777  
25778         if (req->idiag_family == AF_INET) {
25779 +               /* TODO: lback */
25780                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25781                                  req->id.idiag_dport, req->id.idiag_src[0],
25782                                  req->id.idiag_sport, req->id.idiag_if);
25783 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
25784                 } else
25785  #endif
25786                 {
25787 +                       /* TODO: lback */
25788                         entry.saddr = &inet->inet_rcv_saddr;
25789                         entry.daddr = &inet->inet_daddr;
25790                 }
25791 @@ -541,6 +547,7 @@ static int inet_twsk_diag_dump(struct in
25792                 } else
25793  #endif
25794                 {
25795 +                       /* TODO: lback */
25796                         entry.saddr = &tw->tw_rcv_saddr;
25797                         entry.daddr = &tw->tw_daddr;
25798                 }
25799 @@ -587,8 +594,8 @@ static int inet_diag_fill_req(struct sk_
25800  
25801         r->id.idiag_sport = inet->inet_sport;
25802         r->id.idiag_dport = ireq->rmt_port;
25803 -       r->id.idiag_src[0] = ireq->loc_addr;
25804 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25805 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25806 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25807         r->idiag_expires = jiffies_to_msecs(tmo);
25808         r->idiag_rqueue = 0;
25809         r->idiag_wqueue = 0;
25810 @@ -658,6 +665,7 @@ static int inet_diag_dump_reqs(struct sk
25811                                 continue;
25812  
25813                         if (bc) {
25814 +                               /* TODO: lback */
25815                                 entry.saddr =
25816  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25817                                         (entry.family == AF_INET6) ?
25818 @@ -728,6 +736,8 @@ static int inet_diag_dump(struct sk_buff
25819                         sk_nulls_for_each(sk, node, &ilb->head) {
25820                                 struct inet_sock *inet = inet_sk(sk);
25821  
25822 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25823 +                                       continue;
25824                                 if (num < s_num) {
25825                                         num++;
25826                                         continue;
25827 @@ -794,6 +804,8 @@ skip_listen_ht:
25828                 sk_nulls_for_each(sk, node, &head->chain) {
25829                         struct inet_sock *inet = inet_sk(sk);
25830  
25831 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25832 +                               continue;
25833                         if (num < s_num)
25834                                 goto next_normal;
25835                         if (!(r->idiag_states & (1 << sk->sk_state)))
25836 @@ -818,6 +830,8 @@ next_normal:
25837                         inet_twsk_for_each(tw, node,
25838                                     &head->twchain) {
25839  
25840 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25841 +                                       continue;
25842                                 if (num < s_num)
25843                                         goto next_dying;
25844                                 if (r->id.idiag_sport != tw->tw_sport &&
25845 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/inet_hashtables.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/inet_hashtables.c
25846 --- linux-2.6.35.4/net/ipv4/inet_hashtables.c   2010-08-02 16:52:59.000000000 +0200
25847 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/inet_hashtables.c     2010-08-02 17:05:06.000000000 +0200
25848 @@ -21,6 +21,7 @@
25849  
25850  #include <net/inet_connection_sock.h>
25851  #include <net/inet_hashtables.h>
25852 +#include <net/route.h>
25853  #include <net/ip.h>
25854  
25855  /*
25856 @@ -134,6 +135,11 @@ static inline int compute_score(struct s
25857                         if (rcv_saddr != daddr)
25858                                 return -1;
25859                         score += 2;
25860 +               } else {
25861 +                       /* block non nx_info ips */
25862 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25863 +                               daddr, NXA_MASK_BIND))
25864 +                               return -1;
25865                 }
25866                 if (sk->sk_bound_dev_if) {
25867                         if (sk->sk_bound_dev_if != dif)
25868 @@ -151,7 +157,6 @@ static inline int compute_score(struct s
25869   * wildcarded during the search since they can never be otherwise.
25870   */
25871  
25872 -
25873  struct sock *__inet_lookup_listener(struct net *net,
25874                                     struct inet_hashinfo *hashinfo,
25875                                     const __be32 daddr, const unsigned short hnum,
25876 @@ -174,6 +179,7 @@ begin:
25877                         hiscore = score;
25878                 }
25879         }
25880 +
25881         /*
25882          * if the nulls value we got at the end of this lookup is
25883          * not the expected one, we must restart lookup.
25884 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/netfilter/nf_nat_helper.c
25885 --- linux-2.6.35.4/net/ipv4/netfilter/nf_nat_helper.c   2010-07-07 18:31:59.000000000 +0200
25886 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/netfilter/nf_nat_helper.c     2010-08-02 17:05:06.000000000 +0200
25887 @@ -20,6 +20,7 @@
25888  #include <net/route.h>
25889  
25890  #include <linux/netfilter_ipv4.h>
25891 +#include <net/route.h>
25892  #include <net/netfilter/nf_conntrack.h>
25893  #include <net/netfilter/nf_conntrack_helper.h>
25894  #include <net/netfilter/nf_conntrack_ecache.h>
25895 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/netfilter.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/netfilter.c
25896 --- linux-2.6.35.4/net/ipv4/netfilter.c 2010-08-02 16:52:59.000000000 +0200
25897 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/netfilter.c   2010-08-02 17:05:06.000000000 +0200
25898 @@ -5,7 +5,7 @@
25899  #include <linux/ip.h>
25900  #include <linux/skbuff.h>
25901  #include <linux/gfp.h>
25902 -#include <net/route.h>
25903 +// #include <net/route.h>
25904  #include <net/xfrm.h>
25905  #include <net/ip.h>
25906  #include <net/netfilter/nf_queue.h>
25907 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/raw.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/raw.c
25908 --- linux-2.6.35.4/net/ipv4/raw.c       2010-08-02 16:52:59.000000000 +0200
25909 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/raw.c 2010-08-02 18:19:23.000000000 +0200
25910 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
25911  
25912                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25913                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25914 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25915 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25916                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25917                         goto found; /* gotcha */
25918         }
25919 @@ -381,6 +381,12 @@ static int raw_send_hdrinc(struct sock *
25920                 icmp_out_count(net, ((struct icmphdr *)
25921                         skb_transport_header(skb))->type);
25922  
25923 +       err = -EPERM;
25924 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25925 +               sk->sk_nx_info &&
25926 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25927 +               goto error_free;
25928 +
25929         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25930                       rt->u.dst.dev, dst_output);
25931         if (err > 0)
25932 @@ -561,6 +567,13 @@ static int raw_sendmsg(struct kiocb *ioc
25933                 }
25934  
25935                 security_sk_classify_flow(sk, &fl);
25936 +               if (sk->sk_nx_info) {
25937 +                       err = ip_v4_find_src(sock_net(sk),
25938 +                               sk->sk_nx_info, &rt, &fl);
25939 +
25940 +                       if (err)
25941 +                               goto done;
25942 +               }
25943                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
25944         }
25945         if (err)
25946 @@ -633,17 +646,19 @@ static int raw_bind(struct sock *sk, str
25947  {
25948         struct inet_sock *inet = inet_sk(sk);
25949         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25950 +       struct nx_v4_sock_addr nsa = { 0 };
25951         int ret = -EINVAL;
25952         int chk_addr_ret;
25953  
25954         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25955                 goto out;
25956 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25957 +       v4_map_sock_addr(inet, addr, &nsa);
25958 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25959         ret = -EADDRNOTAVAIL;
25960 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25961 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25962             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25963                 goto out;
25964 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25965 +       v4_set_sock_addr(inet, &nsa);
25966         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25967                 inet->inet_saddr = 0;  /* Use device */
25968         sk_dst_reset(sk);
25969 @@ -695,7 +710,8 @@ static int raw_recvmsg(struct kiocb *ioc
25970         /* Copy the address. */
25971         if (sin) {
25972                 sin->sin_family = AF_INET;
25973 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25974 +               sin->sin_addr.s_addr =
25975 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25976                 sin->sin_port = 0;
25977                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25978         }
25979 @@ -873,7 +889,8 @@ static struct sock *raw_get_first(struct
25980                 struct hlist_node *node;
25981  
25982                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25983 -                       if (sock_net(sk) == seq_file_net(seq))
25984 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25985 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25986                                 goto found;
25987         }
25988         sk = NULL;
25989 @@ -889,7 +906,8 @@ static struct sock *raw_get_next(struct 
25990                 sk = sk_next(sk);
25991  try_again:
25992                 ;
25993 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25994 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25995 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25996  
25997         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25998                 sk = sk_head(&state->h->ht[state->bucket]);
25999 @@ -948,7 +966,10 @@ static void raw_sock_seq_show(struct seq
26000  
26001         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
26002                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
26003 -               i, src, srcp, dest, destp, sp->sk_state,
26004 +               i,
26005 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26006 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26007 +               sp->sk_state,
26008                 sk_wmem_alloc_get(sp),
26009                 sk_rmem_alloc_get(sp),
26010                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26011 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/tcp.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/tcp.c
26012 --- linux-2.6.35.4/net/ipv4/tcp.c       2010-09-05 01:41:57.000000000 +0200
26013 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/tcp.c 2010-09-06 02:59:52.000000000 +0200
26014 @@ -266,6 +266,7 @@
26015  #include <linux/crypto.h>
26016  #include <linux/time.h>
26017  #include <linux/slab.h>
26018 +#include <linux/in.h>
26019  
26020  #include <net/icmp.h>
26021  #include <net/tcp.h>
26022 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/tcp_ipv4.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/tcp_ipv4.c
26023 --- linux-2.6.35.4/net/ipv4/tcp_ipv4.c  2010-08-02 16:52:59.000000000 +0200
26024 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/tcp_ipv4.c    2010-08-02 17:05:06.000000000 +0200
26025 @@ -2004,6 +2004,12 @@ static void *listening_get_next(struct s
26026                 req = req->dl_next;
26027                 while (1) {
26028                         while (req) {
26029 +                               vxdprintk(VXD_CBIT(net, 6),
26030 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
26031 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
26032 +                               if (req->sk &&
26033 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
26034 +                                       continue;
26035                                 if (req->rsk_ops->family == st->family) {
26036                                         cur = req;
26037                                         goto out;
26038 @@ -2028,6 +2034,10 @@ get_req:
26039         }
26040  get_sk:
26041         sk_nulls_for_each_from(sk, node) {
26042 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
26043 +                       sk, sk->sk_nid, nx_current_nid());
26044 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26045 +                       continue;
26046                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
26047                         cur = sk;
26048                         goto out;
26049 @@ -2091,6 +2101,11 @@ static void *established_get_first(struc
26050  
26051                 spin_lock_bh(lock);
26052                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
26053 +                       vxdprintk(VXD_CBIT(net, 6),
26054 +                               "sk,egf: %p [#%d] (from %d)",
26055 +                               sk, sk->sk_nid, nx_current_nid());
26056 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26057 +                               continue;
26058                         if (sk->sk_family != st->family ||
26059                             !net_eq(sock_net(sk), net)) {
26060                                 continue;
26061 @@ -2101,6 +2116,11 @@ static void *established_get_first(struc
26062                 st->state = TCP_SEQ_STATE_TIME_WAIT;
26063                 inet_twsk_for_each(tw, node,
26064                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
26065 +                       vxdprintk(VXD_CBIT(net, 6),
26066 +                               "tw: %p [#%d] (from %d)",
26067 +                               tw, tw->tw_nid, nx_current_nid());
26068 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26069 +                               continue;
26070                         if (tw->tw_family != st->family ||
26071                             !net_eq(twsk_net(tw), net)) {
26072                                 continue;
26073 @@ -2129,7 +2149,9 @@ static void *established_get_next(struct
26074                 tw = cur;
26075                 tw = tw_next(tw);
26076  get_tw:
26077 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
26078 +               while (tw && (tw->tw_family != st->family ||
26079 +                       !net_eq(twsk_net(tw), net) ||
26080 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
26081                         tw = tw_next(tw);
26082                 }
26083                 if (tw) {
26084 @@ -2152,6 +2174,11 @@ get_tw:
26085                 sk = sk_nulls_next(sk);
26086  
26087         sk_nulls_for_each_from(sk, node) {
26088 +               vxdprintk(VXD_CBIT(net, 6),
26089 +                       "sk,egn: %p [#%d] (from %d)",
26090 +                       sk, sk->sk_nid, nx_current_nid());
26091 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26092 +                       continue;
26093                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
26094                         goto found;
26095         }
26096 @@ -2303,9 +2330,9 @@ static void get_openreq4(struct sock *sk
26097         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26098                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
26099                 i,
26100 -               ireq->loc_addr,
26101 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
26102                 ntohs(inet_sk(sk)->inet_sport),
26103 -               ireq->rmt_addr,
26104 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
26105                 ntohs(ireq->rmt_port),
26106                 TCP_SYN_RECV,
26107                 0, 0, /* could print option size, but that is af dependent. */
26108 @@ -2357,7 +2384,10 @@ static void get_tcp4_sock(struct sock *s
26109  
26110         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
26111                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
26112 -               i, src, srcp, dest, destp, sk->sk_state,
26113 +               i,
26114 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26115 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26116 +               sk->sk_state,
26117                 tp->write_seq - tp->snd_una,
26118                 rx_queue,
26119                 timer_active,
26120 @@ -2392,7 +2422,10 @@ static void get_timewait4_sock(struct in
26121  
26122         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26123                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
26124 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
26125 +               i,
26126 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26127 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26128 +               tw->tw_substate, 0, 0,
26129                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
26130                 atomic_read(&tw->tw_refcnt), tw, len);
26131  }
26132 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/tcp_minisocks.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/tcp_minisocks.c
26133 --- linux-2.6.35.4/net/ipv4/tcp_minisocks.c     2010-08-02 16:52:59.000000000 +0200
26134 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/tcp_minisocks.c       2010-08-02 17:05:06.000000000 +0200
26135 @@ -23,6 +23,9 @@
26136  #include <linux/slab.h>
26137  #include <linux/sysctl.h>
26138  #include <linux/workqueue.h>
26139 +#include <linux/vs_limit.h>
26140 +#include <linux/vs_socket.h>
26141 +#include <linux/vs_context.h>
26142  #include <net/tcp.h>
26143  #include <net/inet_common.h>
26144  #include <net/xfrm.h>
26145 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int 
26146                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
26147                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
26148  
26149 +               tw->tw_xid              = sk->sk_xid;
26150 +               tw->tw_vx_info          = NULL;
26151 +               tw->tw_nid              = sk->sk_nid;
26152 +               tw->tw_nx_info          = NULL;
26153 +
26154  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
26155                 if (tw->tw_family == PF_INET6) {
26156                         struct ipv6_pinfo *np = inet6_sk(sk);
26157 diff -NurpP --minimal linux-2.6.35.4/net/ipv4/udp.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/udp.c
26158 --- linux-2.6.35.4/net/ipv4/udp.c       2010-08-02 16:52:59.000000000 +0200
26159 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv4/udp.c 2010-08-02 17:05:06.000000000 +0200
26160 @@ -296,14 +296,7 @@ fail:
26161  }
26162  EXPORT_SYMBOL(udp_lib_get_port);
26163  
26164 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26165 -{
26166 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
26167 -
26168 -       return  (!ipv6_only_sock(sk2)  &&
26169 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
26170 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
26171 -}
26172 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
26173  
26174  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
26175                                        unsigned int port)
26176 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
26177                         if (inet->inet_rcv_saddr != daddr)
26178                                 return -1;
26179                         score += 2;
26180 +               } else {
26181 +                       /* block non nx_info ips */
26182 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
26183 +                               daddr, NXA_MASK_BIND))
26184 +                               return -1;
26185                 }
26186                 if (inet->inet_daddr) {
26187                         if (inet->inet_daddr != saddr)
26188 @@ -441,6 +439,7 @@ exact_match:
26189         return result;
26190  }
26191  
26192 +
26193  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
26194   * harder than this. -DaveM
26195   */
26196 @@ -486,6 +485,11 @@ begin:
26197         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
26198                 score = compute_score(sk, net, saddr, hnum, sport,
26199                                       daddr, dport, dif);
26200 +               /* FIXME: disabled?
26201 +               if (score == 9) {
26202 +                       result = sk;
26203 +                       break;
26204 +               } else */
26205                 if (score > badness) {
26206                         result = sk;
26207                         badness = score;
26208 @@ -499,6 +503,7 @@ begin:
26209         if (get_nulls_value(node) != slot)
26210                 goto begin;
26211  
26212 +
26213         if (result) {
26214                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
26215                         result = NULL;
26216 @@ -508,6 +513,7 @@ begin:
26217                         goto begin;
26218                 }
26219         }
26220 +
26221         rcu_read_unlock();
26222         return result;
26223  }
26224 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
26225                     udp_sk(s)->udp_port_hash != hnum ||
26226                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
26227                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
26228 -                   (inet->inet_rcv_saddr &&
26229 -                    inet->inet_rcv_saddr != loc_addr) ||
26230 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
26231                     ipv6_only_sock(s) ||
26232                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
26233                         continue;
26234 @@ -900,8 +905,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
26235                                                { .sport = inet->inet_sport,
26236                                                  .dport = dport } } };
26237                 struct net *net = sock_net(sk);
26238 +               struct nx_info *nxi = sk->sk_nx_info;
26239  
26240                 security_sk_classify_flow(sk, &fl);
26241 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
26242 +               if (err)
26243 +                       goto out;
26244 +
26245                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
26246                 if (err) {
26247                         if (err == -ENETUNREACH)
26248 @@ -1183,7 +1193,8 @@ try_again:
26249         if (sin) {
26250                 sin->sin_family = AF_INET;
26251                 sin->sin_port = udp_hdr(skb)->source;
26252 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26253 +               sin->sin_addr.s_addr = nx_map_sock_lback(
26254 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
26255                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
26256         }
26257         if (inet->cmsg_flags)
26258 @@ -1879,6 +1890,8 @@ static struct sock *udp_get_first(struct
26259                 sk_nulls_for_each(sk, node, &hslot->head) {
26260                         if (!net_eq(sock_net(sk), net))
26261                                 continue;
26262 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26263 +                               continue;
26264                         if (sk->sk_family == state->family)
26265                                 goto found;
26266                 }
26267 @@ -1896,7 +1909,9 @@ static struct sock *udp_get_next(struct 
26268  
26269         do {
26270                 sk = sk_nulls_next(sk);
26271 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
26272 +       } while (sk && (!net_eq(sock_net(sk), net) ||
26273 +               sk->sk_family != state->family ||
26274 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26275  
26276         if (!sk) {
26277                 if (state->bucket <= state->udp_table->mask)
26278 @@ -2003,7 +2018,10 @@ static void udp4_format_sock(struct sock
26279  
26280         seq_printf(f, "%5d: %08X:%04X %08X:%04X"
26281                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
26282 -               bucket, src, srcp, dest, destp, sp->sk_state,
26283 +               bucket,
26284 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26285 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26286 +               sp->sk_state,
26287                 sk_wmem_alloc_get(sp),
26288                 sk_rmem_alloc_get(sp),
26289                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26290 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/addrconf.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/addrconf.c
26291 --- linux-2.6.35.4/net/ipv6/addrconf.c  2010-08-02 16:52:59.000000000 +0200
26292 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/addrconf.c    2010-08-02 17:05:06.000000000 +0200
26293 @@ -87,6 +87,8 @@
26294  
26295  #include <linux/proc_fs.h>
26296  #include <linux/seq_file.h>
26297 +#include <linux/vs_network.h>
26298 +#include <linux/vs_inet6.h>
26299  
26300  /* Set to 3 to get tracing... */
26301  #define ACONF_DEBUG 2
26302 @@ -1117,7 +1119,7 @@ out:
26303  
26304  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
26305                        const struct in6_addr *daddr, unsigned int prefs,
26306 -                      struct in6_addr *saddr)
26307 +                      struct in6_addr *saddr, struct nx_info *nxi)
26308  {
26309         struct ipv6_saddr_score scores[2],
26310                                 *score = &scores[0], *hiscore = &scores[1];
26311 @@ -1189,6 +1191,8 @@ int ipv6_dev_get_saddr(struct net *net, 
26312                                                dev->name);
26313                                 continue;
26314                         }
26315 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
26316 +                               continue;
26317  
26318                         score->rule = -1;
26319                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
26320 @@ -3074,7 +3078,10 @@ static void if6_seq_stop(struct seq_file
26321  static int if6_seq_show(struct seq_file *seq, void *v)
26322  {
26323         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
26324 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
26325 +
26326 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
26327 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
26328 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
26329                    &ifp->addr,
26330                    ifp->idev->dev->ifindex,
26331                    ifp->prefix_len,
26332 @@ -3578,6 +3585,11 @@ static int in6_dump_addrs(struct inet6_d
26333         struct ifacaddr6 *ifaca;
26334         int err = 1;
26335         int ip_idx = *p_ip_idx;
26336 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
26337 +
26338 +       /* disable ipv6 on non v6 guests */
26339 +       if (nxi && !nx_info_has_v6(nxi))
26340 +               return skb->len;
26341  
26342         read_lock_bh(&idev->lock);
26343         switch (type) {
26344 @@ -3588,6 +3600,8 @@ static int in6_dump_addrs(struct inet6_d
26345                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
26346                         if (++ip_idx < s_ip_idx)
26347                                 continue;
26348 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
26349 +                                       continue;
26350                         err = inet6_fill_ifaddr(skb, ifa,
26351                                                 NETLINK_CB(cb->skb).pid,
26352                                                 cb->nlh->nlmsg_seq,
26353 @@ -3604,6 +3618,8 @@ static int in6_dump_addrs(struct inet6_d
26354                      ifmca = ifmca->next, ip_idx++) {
26355                         if (ip_idx < s_ip_idx)
26356                                 continue;
26357 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
26358 +                                       continue;
26359                         err = inet6_fill_ifmcaddr(skb, ifmca,
26360                                                   NETLINK_CB(cb->skb).pid,
26361                                                   cb->nlh->nlmsg_seq,
26362 @@ -3619,6 +3635,8 @@ static int in6_dump_addrs(struct inet6_d
26363                      ifaca = ifaca->aca_next, ip_idx++) {
26364                         if (ip_idx < s_ip_idx)
26365                                 continue;
26366 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
26367 +                                       continue;
26368                         err = inet6_fill_ifacaddr(skb, ifaca,
26369                                                   NETLINK_CB(cb->skb).pid,
26370                                                   cb->nlh->nlmsg_seq,
26371 @@ -3950,6 +3968,11 @@ static int inet6_dump_ifinfo(struct sk_b
26372         struct inet6_dev *idev;
26373         struct hlist_head *head;
26374         struct hlist_node *node;
26375 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
26376 +
26377 +       /* FIXME: maybe disable ipv6 on non v6 guests?
26378 +       if (skb->sk && skb->sk->sk_vx_info)
26379 +               return skb->len; */
26380  
26381         s_h = cb->args[0];
26382         s_idx = cb->args[1];
26383 @@ -3961,6 +3984,8 @@ static int inet6_dump_ifinfo(struct sk_b
26384                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
26385                         if (idx < s_idx)
26386                                 goto cont;
26387 +                       if (!v6_dev_in_nx_info(dev, nxi))
26388 +                               goto cont;
26389                         idev = __in6_dev_get(dev);
26390                         if (!idev)
26391                                 goto cont;
26392 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/af_inet6.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/af_inet6.c
26393 --- linux-2.6.35.4/net/ipv6/af_inet6.c  2010-08-02 16:52:59.000000000 +0200
26394 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/af_inet6.c    2010-08-02 17:05:06.000000000 +0200
26395 @@ -42,6 +42,8 @@
26396  #include <linux/netdevice.h>
26397  #include <linux/icmpv6.h>
26398  #include <linux/netfilter_ipv6.h>
26399 +#include <linux/vs_inet.h>
26400 +#include <linux/vs_inet6.h>
26401  
26402  #include <net/ip.h>
26403  #include <net/ipv6.h>
26404 @@ -160,9 +162,12 @@ lookup_protocol:
26405         }
26406  
26407         err = -EPERM;
26408 +       if ((protocol == IPPROTO_ICMPV6) &&
26409 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
26410 +               goto override;
26411         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
26412                 goto out_rcu_unlock;
26413 -
26414 +override:
26415         sock->ops = answer->ops;
26416         answer_prot = answer->prot;
26417         answer_no_check = answer->no_check;
26418 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
26419         struct inet_sock *inet = inet_sk(sk);
26420         struct ipv6_pinfo *np = inet6_sk(sk);
26421         struct net *net = sock_net(sk);
26422 +       struct nx_v6_sock_addr nsa;
26423         __be32 v4addr = 0;
26424         unsigned short snum;
26425         int addr_type = 0;
26426 @@ -272,6 +278,11 @@ int inet6_bind(struct socket *sock, stru
26427  
26428         if (addr_len < SIN6_LEN_RFC2133)
26429                 return -EINVAL;
26430 +
26431 +       err = v6_map_sock_addr(inet, addr, &nsa);
26432 +       if (err)
26433 +               return err;
26434 +
26435         addr_type = ipv6_addr_type(&addr->sin6_addr);
26436         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
26437                 return -EINVAL;
26438 @@ -303,6 +314,7 @@ int inet6_bind(struct socket *sock, stru
26439                 /* Reproduce AF_INET checks to make the bindings consitant */
26440                 v4addr = addr->sin6_addr.s6_addr32[3];
26441                 chk_addr_ret = inet_addr_type(net, v4addr);
26442 +
26443                 if (!sysctl_ip_nonlocal_bind &&
26444                     !(inet->freebind || inet->transparent) &&
26445                     v4addr != htonl(INADDR_ANY) &&
26446 @@ -312,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
26447                         err = -EADDRNOTAVAIL;
26448                         goto out;
26449                 }
26450 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
26451 +                       err = -EADDRNOTAVAIL;
26452 +                       goto out;
26453 +               }
26454         } else {
26455                 if (addr_type != IPV6_ADDR_ANY) {
26456                         struct net_device *dev = NULL;
26457 @@ -338,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
26458                                 }
26459                         }
26460  
26461 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
26462 +                               err = -EADDRNOTAVAIL;
26463 +                               goto out;
26464 +                       }
26465 +
26466                         /* ipv4 addr of the socket is invalid.  Only the
26467                          * unspecified and mapped address have a v4 equivalent.
26468                          */
26469 @@ -353,6 +374,9 @@ int inet6_bind(struct socket *sock, stru
26470                 }
26471         }
26472  
26473 +       /* what's that for? */
26474 +       v6_set_sock_addr(inet, &nsa);
26475 +
26476         inet->inet_rcv_saddr = v4addr;
26477         inet->inet_saddr = v4addr;
26478  
26479 @@ -454,9 +478,11 @@ int inet6_getname(struct socket *sock, s
26480                         return -ENOTCONN;
26481                 sin->sin6_port = inet->inet_dport;
26482                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
26483 +               /* FIXME: remap lback? */
26484                 if (np->sndflow)
26485                         sin->sin6_flowinfo = np->flow_label;
26486         } else {
26487 +               /* FIXME: remap lback? */
26488                 if (ipv6_addr_any(&np->rcv_saddr))
26489                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
26490                 else
26491 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/fib6_rules.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/fib6_rules.c
26492 --- linux-2.6.35.4/net/ipv6/fib6_rules.c        2010-08-02 16:52:59.000000000 +0200
26493 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/fib6_rules.c  2010-08-02 17:05:06.000000000 +0200
26494 @@ -89,7 +89,7 @@ static int fib6_rule_action(struct fib_r
26495                                                ip6_dst_idev(&rt->u.dst)->dev,
26496                                                &flp->fl6_dst,
26497                                                rt6_flags2srcprefs(flags),
26498 -                                              &saddr))
26499 +                                              &saddr, NULL))
26500                                 goto again;
26501                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
26502                                                r->src.plen))
26503 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/inet6_hashtables.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/inet6_hashtables.c
26504 --- linux-2.6.35.4/net/ipv6/inet6_hashtables.c  2010-02-25 11:52:10.000000000 +0100
26505 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/inet6_hashtables.c    2010-08-02 17:05:06.000000000 +0200
26506 @@ -16,6 +16,7 @@
26507  
26508  #include <linux/module.h>
26509  #include <linux/random.h>
26510 +#include <linux/vs_inet6.h>
26511  
26512  #include <net/inet_connection_sock.h>
26513  #include <net/inet_hashtables.h>
26514 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
26515         unsigned int slot = hash & hashinfo->ehash_mask;
26516         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
26517  
26518 -
26519         rcu_read_lock();
26520  begin:
26521         sk_nulls_for_each_rcu(sk, node, &head->chain) {
26522 @@ -94,7 +94,7 @@ begin:
26523                                 sock_put(sk);
26524                                 goto begin;
26525                         }
26526 -               goto out;
26527 +                       goto out;
26528                 }
26529         }
26530         if (get_nulls_value(node) != slot)
26531 @@ -140,6 +140,9 @@ static int inline compute_score(struct s
26532                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26533                                 return -1;
26534                         score++;
26535 +               } else {
26536 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26537 +                               return -1;
26538                 }
26539                 if (sk->sk_bound_dev_if) {
26540                         if (sk->sk_bound_dev_if != dif)
26541 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/ip6_output.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/ip6_output.c
26542 --- linux-2.6.35.4/net/ipv6/ip6_output.c        2010-08-02 16:52:59.000000000 +0200
26543 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/ip6_output.c  2010-08-02 17:05:06.000000000 +0200
26544 @@ -930,7 +930,7 @@ static int ip6_dst_lookup_tail(struct so
26545                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
26546                                          &fl->fl6_dst,
26547                                          sk ? inet6_sk(sk)->srcprefs : 0,
26548 -                                        &fl->fl6_src);
26549 +                                        &fl->fl6_src, sk->sk_nx_info);
26550                 if (err)
26551                         goto out_err_release;
26552         }
26553 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/Kconfig linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/Kconfig
26554 --- linux-2.6.35.4/net/ipv6/Kconfig     2010-08-02 16:52:59.000000000 +0200
26555 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/Kconfig       2010-08-02 17:05:06.000000000 +0200
26556 @@ -4,8 +4,8 @@
26557  
26558  #   IPv6 as module will cause a CRASH if you try to unload it
26559  menuconfig IPV6
26560 -       tristate "The IPv6 protocol"
26561 -       default m
26562 +       bool "The IPv6 protocol"
26563 +       default n
26564         ---help---
26565           This is complemental support for the IP version 6.
26566           You will still be able to do traditional IPv4 networking as well.
26567 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/ndisc.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/ndisc.c
26568 --- linux-2.6.35.4/net/ipv6/ndisc.c     2010-08-02 16:53:00.000000000 +0200
26569 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/ndisc.c       2010-08-02 17:05:06.000000000 +0200
26570 @@ -591,7 +591,7 @@ static void ndisc_send_na(struct net_dev
26571         } else {
26572                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
26573                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
26574 -                                      &tmpaddr))
26575 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
26576                         return;
26577                 src_addr = &tmpaddr;
26578         }
26579 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/raw.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/raw.c
26580 --- linux-2.6.35.4/net/ipv6/raw.c       2010-08-02 16:53:00.000000000 +0200
26581 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/raw.c 2010-08-02 17:05:06.000000000 +0200
26582 @@ -30,6 +30,7 @@
26583  #include <linux/icmpv6.h>
26584  #include <linux/netfilter.h>
26585  #include <linux/netfilter_ipv6.h>
26586 +#include <linux/vs_inet6.h>
26587  #include <linux/skbuff.h>
26588  #include <asm/uaccess.h>
26589  #include <asm/ioctls.h>
26590 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
26591                                 goto out_unlock;
26592                 }
26593  
26594 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
26595 +                       err = -EADDRNOTAVAIL;
26596 +                       if (dev)
26597 +                               dev_put(dev);
26598 +                       goto out;
26599 +               }
26600 +
26601                 /* ipv4 addr of the socket is invalid.  Only the
26602                  * unspecified and mapped address have a v4 equivalent.
26603                  */
26604 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/route.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/route.c
26605 --- linux-2.6.35.4/net/ipv6/route.c     2010-08-02 16:53:00.000000000 +0200
26606 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/route.c       2010-08-02 17:05:06.000000000 +0200
26607 @@ -2255,7 +2255,8 @@ static int rt6_fill_node(struct net *net
26608                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
26609                 struct in6_addr saddr_buf;
26610                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
26611 -                                      dst, 0, &saddr_buf) == 0)
26612 +                       dst, 0, &saddr_buf,
26613 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
26614                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
26615         }
26616  
26617 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/tcp_ipv6.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/tcp_ipv6.c
26618 --- linux-2.6.35.4/net/ipv6/tcp_ipv6.c  2010-08-02 16:53:00.000000000 +0200
26619 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/tcp_ipv6.c    2010-08-02 17:05:06.000000000 +0200
26620 @@ -69,6 +69,7 @@
26621  
26622  #include <linux/crypto.h>
26623  #include <linux/scatterlist.h>
26624 +#include <linux/vs_inet6.h>
26625  
26626  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
26627  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
26628 @@ -160,8 +161,15 @@ static int tcp_v6_connect(struct sock *s
26629          *      connect() to INADDR_ANY means loopback (BSD'ism).
26630          */
26631  
26632 -       if(ipv6_addr_any(&usin->sin6_addr))
26633 -               usin->sin6_addr.s6_addr[15] = 0x1;
26634 +       if(ipv6_addr_any(&usin->sin6_addr)) {
26635 +               struct nx_info *nxi =  sk->sk_nx_info;
26636 +
26637 +               if (nxi && nx_info_has_v6(nxi))
26638 +                       /* FIXME: remap lback? */
26639 +                       usin->sin6_addr = nxi->v6.ip;
26640 +               else
26641 +                       usin->sin6_addr.s6_addr[15] = 0x1;
26642 +       }
26643  
26644         addr_type = ipv6_addr_type(&usin->sin6_addr);
26645  
26646 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/udp.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/udp.c
26647 --- linux-2.6.35.4/net/ipv6/udp.c       2010-08-02 16:53:00.000000000 +0200
26648 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/udp.c 2010-08-02 17:05:06.000000000 +0200
26649 @@ -48,13 +48,14 @@
26650  
26651  #include <linux/proc_fs.h>
26652  #include <linux/seq_file.h>
26653 +#include <linux/vs_inet6.h>
26654  #include "udp_impl.h"
26655  
26656  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
26657  {
26658         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
26659         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
26660 -       __be32 sk1_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
26661 +       __be32 sk_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
26662         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26663         int sk_ipv6only = ipv6_only_sock(sk);
26664         int sk2_ipv6only = inet_v6_ipv6only(sk2);
26665 @@ -62,24 +63,49 @@ int ipv6_rcv_saddr_equal(const struct so
26666         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
26667  
26668         /* if both are mapped, treat as IPv4 */
26669 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
26670 -               return (!sk2_ipv6only &&
26671 -                       (!sk1_rcv_saddr || !sk2_rcv_saddr ||
26672 -                         sk1_rcv_saddr == sk2_rcv_saddr));
26673 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
26674 +               if (!sk2_ipv6only &&
26675 +                       (!sk_rcv_saddr || !sk2_rcv_saddr ||
26676 +                         sk_rcv_saddr == sk2_rcv_saddr))
26677 +                       goto vs_v4;
26678 +               else
26679 +                       return 0;
26680 +       }
26681  
26682         if (addr_type2 == IPV6_ADDR_ANY &&
26683             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26684 -               return 1;
26685 +               goto vs;
26686  
26687         if (addr_type == IPV6_ADDR_ANY &&
26688             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26689 -               return 1;
26690 +               goto vs;
26691  
26692         if (sk2_rcv_saddr6 &&
26693             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26694 -               return 1;
26695 +               goto vs;
26696  
26697         return 0;
26698 +
26699 +vs_v4:
26700 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
26701 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26702 +       if (!sk2_rcv_saddr)
26703 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
26704 +       if (!sk_rcv_saddr)
26705 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
26706 +       return 1;
26707 +vs:
26708 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
26709 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26710 +       else if (addr_type2 == IPV6_ADDR_ANY)
26711 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
26712 +       else if (addr_type == IPV6_ADDR_ANY) {
26713 +               if (addr_type2 == IPV6_ADDR_MAPPED)
26714 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26715 +               else
26716 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
26717 +       }
26718 +       return 1;
26719  }
26720  
26721  static unsigned int udp6_portaddr_hash(struct net *net,
26722 @@ -134,6 +160,10 @@ static inline int compute_score(struct s
26723                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26724                                 return -1;
26725                         score++;
26726 +               } else {
26727 +                       /* block non nx_info ips */
26728 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26729 +                               return -1;
26730                 }
26731                 if (!ipv6_addr_any(&np->daddr)) {
26732                         if (!ipv6_addr_equal(&np->daddr, saddr))
26733 diff -NurpP --minimal linux-2.6.35.4/net/ipv6/xfrm6_policy.c linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/xfrm6_policy.c
26734 --- linux-2.6.35.4/net/ipv6/xfrm6_policy.c      2010-08-02 16:53:00.000000000 +0200
26735 +++ linux-2.6.35.4-vs2.3.0.36.32/net/ipv6/xfrm6_policy.c        2010-08-02 17:05:06.000000000 +0200
26736 @@ -62,7 +62,7 @@ static int xfrm6_get_saddr(struct net *n
26737         dev = ip6_dst_idev(dst)->dev;
26738         ipv6_dev_get_saddr(dev_net(dev), dev,
26739                            (struct in6_addr *)&daddr->a6, 0,
26740 -                          (struct in6_addr *)&saddr->a6);
26741 +                          (struct in6_addr *)&saddr->a6, NULL);
26742         dst_release(dst);
26743         return 0;
26744  }
26745 diff -NurpP --minimal linux-2.6.35.4/net/netlink/af_netlink.c linux-2.6.35.4-vs2.3.0.36.32/net/netlink/af_netlink.c
26746 --- linux-2.6.35.4/net/netlink/af_netlink.c     2010-09-05 01:41:57.000000000 +0200
26747 +++ linux-2.6.35.4-vs2.3.0.36.32/net/netlink/af_netlink.c       2010-09-06 02:59:52.000000000 +0200
26748 @@ -55,6 +55,9 @@
26749  #include <linux/types.h>
26750  #include <linux/audit.h>
26751  #include <linux/mutex.h>
26752 +#include <linux/vs_context.h>
26753 +#include <linux/vs_network.h>
26754 +#include <linux/vs_limit.h>
26755  
26756  #include <net/net_namespace.h>
26757  #include <net/sock.h>
26758 @@ -1922,6 +1925,8 @@ static struct sock *netlink_seq_socket_i
26759                         sk_for_each(s, node, &hash->table[j]) {
26760                                 if (sock_net(s) != seq_file_net(seq))
26761                                         continue;
26762 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26763 +                                       continue;
26764                                 if (off == pos) {
26765                                         iter->link = i;
26766                                         iter->hash_idx = j;
26767 @@ -1956,7 +1961,8 @@ static void *netlink_seq_next(struct seq
26768         s = v;
26769         do {
26770                 s = sk_next(s);
26771 -       } while (s && sock_net(s) != seq_file_net(seq));
26772 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26773 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26774         if (s)
26775                 return s;
26776  
26777 @@ -1968,7 +1974,8 @@ static void *netlink_seq_next(struct seq
26778  
26779                 for (; j <= hash->mask; j++) {
26780                         s = sk_head(&hash->table[j]);
26781 -                       while (s && sock_net(s) != seq_file_net(seq))
26782 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26783 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26784                                 s = sk_next(s);
26785                         if (s) {
26786                                 iter->link = i;
26787 diff -NurpP --minimal linux-2.6.35.4/net/sctp/ipv6.c linux-2.6.35.4-vs2.3.0.36.32/net/sctp/ipv6.c
26788 --- linux-2.6.35.4/net/sctp/ipv6.c      2010-08-02 16:53:01.000000000 +0200
26789 +++ linux-2.6.35.4-vs2.3.0.36.32/net/sctp/ipv6.c        2010-08-02 17:05:06.000000000 +0200
26790 @@ -304,7 +304,8 @@ static void sctp_v6_get_saddr(struct sct
26791                                    dst ? ip6_dst_idev(dst)->dev : NULL,
26792                                    &daddr->v6.sin6_addr,
26793                                    inet6_sk(&sk->inet.sk)->srcprefs,
26794 -                                  &saddr->v6.sin6_addr);
26795 +                                  &saddr->v6.sin6_addr,
26796 +                                  asoc->base.sk->sk_nx_info);
26797                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
26798                                   &saddr->v6.sin6_addr);
26799                 return;
26800 diff -NurpP --minimal linux-2.6.35.4/net/socket.c linux-2.6.35.4-vs2.3.0.36.32/net/socket.c
26801 --- linux-2.6.35.4/net/socket.c 2010-08-02 16:53:02.000000000 +0200
26802 +++ linux-2.6.35.4-vs2.3.0.36.32/net/socket.c   2010-08-02 17:05:06.000000000 +0200
26803 @@ -98,6 +98,10 @@
26804  
26805  #include <net/sock.h>
26806  #include <linux/netfilter.h>
26807 +#include <linux/vs_base.h>
26808 +#include <linux/vs_socket.h>
26809 +#include <linux/vs_inet.h>
26810 +#include <linux/vs_inet6.h>
26811  
26812  #include <linux/if_tun.h>
26813  #include <linux/ipv6_route.h>
26814 @@ -557,7 +561,7 @@ static inline int __sock_sendmsg(struct 
26815                                  struct msghdr *msg, size_t size)
26816  {
26817         struct sock_iocb *si = kiocb_to_siocb(iocb);
26818 -       int err;
26819 +       int err, len;
26820  
26821         sock_update_classid(sock->sk);
26822  
26823 @@ -570,7 +574,22 @@ static inline int __sock_sendmsg(struct 
26824         if (err)
26825                 return err;
26826  
26827 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26828 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26829 +       if (sock->sk) {
26830 +               if (len == size)
26831 +                       vx_sock_send(sock->sk, size);
26832 +               else
26833 +                       vx_sock_fail(sock->sk, size);
26834 +       }
26835 +       vxdprintk(VXD_CBIT(net, 7),
26836 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26837 +               sock, sock->sk,
26838 +               (sock->sk)?sock->sk->sk_nx_info:0,
26839 +               (sock->sk)?sock->sk->sk_vx_info:0,
26840 +               (sock->sk)?sock->sk->sk_xid:0,
26841 +               (sock->sk)?sock->sk->sk_nid:0,
26842 +               (unsigned int)size, len);
26843 +       return len;
26844  }
26845  
26846  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
26847 @@ -686,6 +705,7 @@ static inline int __sock_recvmsg_nosec(s
26848                                        struct msghdr *msg, size_t size, int flags)
26849  {
26850         struct sock_iocb *si = kiocb_to_siocb(iocb);
26851 +       int len;
26852  
26853         sock_update_classid(sock->sk);
26854  
26855 @@ -695,7 +715,18 @@ static inline int __sock_recvmsg_nosec(s
26856         si->size = size;
26857         si->flags = flags;
26858  
26859 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26860 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26861 +       if ((len >= 0) && sock->sk)
26862 +               vx_sock_recv(sock->sk, len);
26863 +       vxdprintk(VXD_CBIT(net, 7),
26864 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26865 +               sock, sock->sk,
26866 +               (sock->sk)?sock->sk->sk_nx_info:0,
26867 +               (sock->sk)?sock->sk->sk_vx_info:0,
26868 +               (sock->sk)?sock->sk->sk_xid:0,
26869 +               (sock->sk)?sock->sk->sk_nid:0,
26870 +               (unsigned int)size, len);
26871 +       return len;
26872  }
26873  
26874  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26875 @@ -1163,6 +1194,13 @@ static int __sock_create(struct net *net
26876         if (type < 0 || type >= SOCK_MAX)
26877                 return -EINVAL;
26878  
26879 +       if (!nx_check(0, VS_ADMIN)) {
26880 +               if (family == PF_INET && !current_nx_info_has_v4())
26881 +                       return -EAFNOSUPPORT;
26882 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26883 +                       return -EAFNOSUPPORT;
26884 +       }
26885 +
26886         /* Compatibility.
26887  
26888            This uglymoron is moved from INET layer to here to avoid
26889 @@ -1295,6 +1333,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26890         if (retval < 0)
26891                 goto out;
26892  
26893 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26894         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26895         if (retval < 0)
26896                 goto out_release;
26897 @@ -1336,10 +1375,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26898         err = sock_create(family, type, protocol, &sock1);
26899         if (err < 0)
26900                 goto out;
26901 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26902  
26903         err = sock_create(family, type, protocol, &sock2);
26904         if (err < 0)
26905                 goto out_release_1;
26906 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26907  
26908         err = sock1->ops->socketpair(sock1, sock2);
26909         if (err < 0)
26910 diff -NurpP --minimal linux-2.6.35.4/net/sunrpc/auth.c linux-2.6.35.4-vs2.3.0.36.32/net/sunrpc/auth.c
26911 --- linux-2.6.35.4/net/sunrpc/auth.c    2010-08-02 16:53:02.000000000 +0200
26912 +++ linux-2.6.35.4-vs2.3.0.36.32/net/sunrpc/auth.c      2010-08-02 17:05:06.000000000 +0200
26913 @@ -14,6 +14,7 @@
26914  #include <linux/hash.h>
26915  #include <linux/sunrpc/clnt.h>
26916  #include <linux/spinlock.h>
26917 +#include <linux/vs_tag.h>
26918  
26919  #ifdef RPC_DEBUG
26920  # define RPCDBG_FACILITY       RPCDBG_AUTH
26921 @@ -366,6 +367,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26922         memset(&acred, 0, sizeof(acred));
26923         acred.uid = cred->fsuid;
26924         acred.gid = cred->fsgid;
26925 +       acred.tag = dx_current_tag();
26926         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26927  
26928         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26929 @@ -406,6 +408,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26930         struct auth_cred acred = {
26931                 .uid = 0,
26932                 .gid = 0,
26933 +               .tag = dx_current_tag(),
26934         };
26935         struct rpc_cred *ret;
26936  
26937 diff -NurpP --minimal linux-2.6.35.4/net/sunrpc/auth_unix.c linux-2.6.35.4-vs2.3.0.36.32/net/sunrpc/auth_unix.c
26938 --- linux-2.6.35.4/net/sunrpc/auth_unix.c       2010-07-07 18:32:01.000000000 +0200
26939 +++ linux-2.6.35.4-vs2.3.0.36.32/net/sunrpc/auth_unix.c 2010-08-02 17:05:06.000000000 +0200
26940 @@ -12,12 +12,14 @@
26941  #include <linux/module.h>
26942  #include <linux/sunrpc/clnt.h>
26943  #include <linux/sunrpc/auth.h>
26944 +#include <linux/vs_tag.h>
26945  
26946  #define NFS_NGROUPS    16
26947  
26948  struct unx_cred {
26949         struct rpc_cred         uc_base;
26950         gid_t                   uc_gid;
26951 +       tag_t                   uc_tag;
26952         gid_t                   uc_gids[NFS_NGROUPS];
26953  };
26954  #define uc_uid                 uc_base.cr_uid
26955 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
26956                 groups = NFS_NGROUPS;
26957  
26958         cred->uc_gid = acred->gid;
26959 +       cred->uc_tag = acred->tag;
26960         for (i = 0; i < groups; i++)
26961                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26962         if (i < NFS_NGROUPS)
26963 @@ -120,7 +123,9 @@ unx_match(struct auth_cred *acred, struc
26964         unsigned int i;
26965  
26966  
26967 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26968 +       if (cred->uc_uid != acred->uid ||
26969 +               cred->uc_gid != acred->gid ||
26970 +               cred->uc_tag != acred->tag)
26971                 return 0;
26972  
26973         if (acred->group_info != NULL)
26974 @@ -143,7 +148,7 @@ unx_marshal(struct rpc_task *task, __be3
26975         struct rpc_clnt *clnt = task->tk_client;
26976         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
26977         __be32          *base, *hold;
26978 -       int             i;
26979 +       int             i, tag;
26980  
26981         *p++ = htonl(RPC_AUTH_UNIX);
26982         base = p++;
26983 @@ -153,9 +158,12 @@ unx_marshal(struct rpc_task *task, __be3
26984          * Copy the UTS nodename captured when the client was created.
26985          */
26986         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26987 +       tag = task->tk_client->cl_tag;
26988  
26989 -       *p++ = htonl((u32) cred->uc_uid);
26990 -       *p++ = htonl((u32) cred->uc_gid);
26991 +       *p++ = htonl((u32) TAGINO_UID(tag,
26992 +               cred->uc_uid, cred->uc_tag));
26993 +       *p++ = htonl((u32) TAGINO_GID(tag,
26994 +               cred->uc_gid, cred->uc_tag));
26995         hold = p++;
26996         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26997                 *p++ = htonl((u32) cred->uc_gids[i]);
26998 diff -NurpP --minimal linux-2.6.35.4/net/sunrpc/clnt.c linux-2.6.35.4-vs2.3.0.36.32/net/sunrpc/clnt.c
26999 --- linux-2.6.35.4/net/sunrpc/clnt.c    2010-08-02 16:53:02.000000000 +0200
27000 +++ linux-2.6.35.4-vs2.3.0.36.32/net/sunrpc/clnt.c      2010-08-02 17:05:06.000000000 +0200
27001 @@ -33,6 +33,7 @@
27002  #include <linux/utsname.h>
27003  #include <linux/workqueue.h>
27004  #include <linux/in6.h>
27005 +#include <linux/vs_cvirt.h>
27006  
27007  #include <linux/sunrpc/clnt.h>
27008  #include <linux/sunrpc/rpc_pipe_fs.h>
27009 @@ -358,6 +359,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27010         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
27011                 clnt->cl_chatty = 1;
27012  
27013 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27014 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27015 +               clnt->cl_tag = 1; */
27016         return clnt;
27017  }
27018  EXPORT_SYMBOL_GPL(rpc_create);
27019 diff -NurpP --minimal linux-2.6.35.4/net/unix/af_unix.c linux-2.6.35.4-vs2.3.0.36.32/net/unix/af_unix.c
27020 --- linux-2.6.35.4/net/unix/af_unix.c   2010-08-02 16:53:02.000000000 +0200
27021 +++ linux-2.6.35.4-vs2.3.0.36.32/net/unix/af_unix.c     2010-08-02 17:05:06.000000000 +0200
27022 @@ -114,6 +114,8 @@
27023  #include <linux/mount.h>
27024  #include <net/checksum.h>
27025  #include <linux/security.h>
27026 +#include <linux/vs_context.h>
27027 +#include <linux/vs_limit.h>
27028  
27029  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
27030  static DEFINE_SPINLOCK(unix_table_lock);
27031 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
27032                 if (!net_eq(sock_net(s), net))
27033                         continue;
27034  
27035 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27036 +                       continue;
27037                 if (u->addr->len == len &&
27038                     !memcmp(u->addr->name, sunname, len))
27039                         goto found;
27040 @@ -2114,6 +2118,8 @@ static struct sock *unix_seq_idx(struct 
27041         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
27042                 if (sock_net(s) != seq_file_net(seq))
27043                         continue;
27044 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27045 +                       continue;
27046                 if (off == pos)
27047                         return s;
27048                 ++off;
27049 @@ -2138,7 +2144,8 @@ static void *unix_seq_next(struct seq_fi
27050                 sk = first_unix_socket(&iter->i);
27051         else
27052                 sk = next_unix_socket(&iter->i, sk);
27053 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
27054 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
27055 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
27056                 sk = next_unix_socket(&iter->i, sk);
27057         return sk;
27058  }
27059 diff -NurpP --minimal linux-2.6.35.4/scripts/checksyscalls.sh linux-2.6.35.4-vs2.3.0.36.32/scripts/checksyscalls.sh
27060 --- linux-2.6.35.4/scripts/checksyscalls.sh     2009-09-10 15:26:31.000000000 +0200
27061 +++ linux-2.6.35.4-vs2.3.0.36.32/scripts/checksyscalls.sh       2010-08-02 17:05:06.000000000 +0200
27062 @@ -194,7 +194,6 @@ cat << EOF
27063  #define __IGNORE_afs_syscall
27064  #define __IGNORE_getpmsg
27065  #define __IGNORE_putpmsg
27066 -#define __IGNORE_vserver
27067  EOF
27068  }
27069  
27070 diff -NurpP --minimal linux-2.6.35.4/security/commoncap.c linux-2.6.35.4-vs2.3.0.36.32/security/commoncap.c
27071 --- linux-2.6.35.4/security/commoncap.c 2010-08-02 16:53:03.000000000 +0200
27072 +++ linux-2.6.35.4-vs2.3.0.36.32/security/commoncap.c   2010-08-02 17:05:06.000000000 +0200
27073 @@ -28,6 +28,7 @@
27074  #include <linux/prctl.h>
27075  #include <linux/securebits.h>
27076  #include <linux/syslog.h>
27077 +#include <linux/vs_context.h>
27078  
27079  /*
27080   * If a non-root user executes a setuid-root binary in
27081 @@ -53,7 +54,7 @@ static void warn_setuid_and_fcaps_mixed(
27082  
27083  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
27084  {
27085 -       NETLINK_CB(skb).eff_cap = current_cap();
27086 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
27087         return 0;
27088  }
27089  
27090 @@ -63,6 +64,7 @@ int cap_netlink_recv(struct sk_buff *skb
27091                 return -EPERM;
27092         return 0;
27093  }
27094 +
27095  EXPORT_SYMBOL(cap_netlink_recv);
27096  
27097  /**
27098 @@ -83,7 +85,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
27099  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
27100                 int audit)
27101  {
27102 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
27103 +       struct vx_info *vxi = tsk->vx_info;
27104 +
27105 +#if 0
27106 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
27107 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
27108 +               cap_raised(tsk->cap_effective, cap),
27109 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
27110 +#endif
27111 +
27112 +       /* special case SETUP */
27113 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
27114 +               /* FIXME: maybe use cred instead? */
27115 +               cap_raised(tsk->cred->cap_effective, cap))
27116 +               return 0;
27117 +
27118 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
27119  }
27120  
27121  /**
27122 @@ -571,7 +588,7 @@ int cap_inode_setxattr(struct dentry *de
27123  
27124         if (!strncmp(name, XATTR_SECURITY_PREFIX,
27125                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
27126 -           !capable(CAP_SYS_ADMIN))
27127 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
27128                 return -EPERM;
27129         return 0;
27130  }
27131 @@ -597,7 +614,7 @@ int cap_inode_removexattr(struct dentry 
27132  
27133         if (!strncmp(name, XATTR_SECURITY_PREFIX,
27134                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
27135 -           !capable(CAP_SYS_ADMIN))
27136 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
27137                 return -EPERM;
27138         return 0;
27139  }
27140 @@ -899,7 +916,8 @@ int cap_syslog(int type, bool from_file)
27141         if (type != SYSLOG_ACTION_OPEN && from_file)
27142                 return 0;
27143         if ((type != SYSLOG_ACTION_READ_ALL &&
27144 -            type != SYSLOG_ACTION_SIZE_BUFFER) && !capable(CAP_SYS_ADMIN))
27145 +            type != SYSLOG_ACTION_SIZE_BUFFER) &&
27146 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
27147                 return -EPERM;
27148         return 0;
27149  }
27150 @@ -951,3 +969,4 @@ int cap_file_mmap(struct file *file, uns
27151         }
27152         return ret;
27153  }
27154 +
27155 diff -NurpP --minimal linux-2.6.35.4/security/selinux/av_permissions.h linux-2.6.35.4-vs2.3.0.36.32/security/selinux/av_permissions.h
27156 --- linux-2.6.35.4/security/selinux/av_permissions.h    1970-01-01 01:00:00.000000000 +0100
27157 +++ linux-2.6.35.4-vs2.3.0.36.32/security/selinux/av_permissions.h      2010-08-02 17:05:06.000000000 +0200
27158 @@ -0,0 +1,827 @@
27159 +/* This file is automatically generated.  Do not edit. */
27160 +#ifndef _SELINUX_AV_PERMISSIONS_H_
27161 +#define _SELINUX_AV_PERMISSIONS_H_
27162 +
27163 +#define SECURITY__COMPUTE_AV                      0x00000001UL
27164 +#define SECURITY__COMPUTE_CREATE                  0x00000002UL
27165 +#define SECURITY__COMPUTE_MEMBER                  0x00000004UL
27166 +#define SECURITY__CHECK_CONTEXT                   0x00000008UL
27167 +#define SECURITY__LOAD_POLICY                     0x00000010UL
27168 +#define SECURITY__COMPUTE_RELABEL                 0x00000020UL
27169 +#define SECURITY__COMPUTE_USER                    0x00000040UL
27170 +#define SECURITY__SETENFORCE                      0x00000080UL
27171 +#define SECURITY__SETBOOL                         0x00000100UL
27172 +#define SECURITY__SETSECPARAM                     0x00000200UL
27173 +#define SECURITY__SETCHECKREQPROT                 0x00000400UL
27174 +#define PROCESS__FORK                             0x00000001UL
27175 +#define PROCESS__TRANSITION                       0x00000002UL
27176 +#define PROCESS__SIGCHLD                          0x00000004UL
27177 +#define PROCESS__SIGKILL                          0x00000008UL
27178 +#define PROCESS__SIGSTOP                          0x00000010UL
27179 +#define PROCESS__SIGNULL                          0x00000020UL
27180 +#define PROCESS__SIGNAL                           0x00000040UL
27181 +#define PROCESS__PTRACE                           0x00000080UL
27182 +#define PROCESS__GETSCHED                         0x00000100UL
27183 +#define PROCESS__SETSCHED                         0x00000200UL
27184 +#define PROCESS__GETSESSION                       0x00000400UL
27185 +#define PROCESS__GETPGID                          0x00000800UL
27186 +#define PROCESS__SETPGID                          0x00001000UL
27187 +#define PROCESS__GETCAP                           0x00002000UL
27188 +#define PROCESS__SETCAP                           0x00004000UL
27189 +#define PROCESS__SHARE                            0x00008000UL
27190 +#define PROCESS__GETATTR                          0x00010000UL
27191 +#define PROCESS__SETEXEC                          0x00020000UL
27192 +#define PROCESS__SETFSCREATE                      0x00040000UL
27193 +#define PROCESS__NOATSECURE                       0x00080000UL
27194 +#define PROCESS__SIGINH                           0x00100000UL
27195 +#define PROCESS__SETRLIMIT                        0x00200000UL
27196 +#define PROCESS__RLIMITINH                        0x00400000UL
27197 +#define PROCESS__DYNTRANSITION                    0x00800000UL
27198 +#define PROCESS__SETCURRENT                       0x01000000UL
27199 +#define PROCESS__EXECMEM                          0x02000000UL
27200 +#define PROCESS__EXECSTACK                        0x04000000UL
27201 +#define PROCESS__EXECHEAP                         0x08000000UL
27202 +#define PROCESS__SETKEYCREATE                     0x10000000UL
27203 +#define PROCESS__SETSOCKCREATE                    0x20000000UL
27204 +#define SYSTEM__IPC_INFO                          0x00000001UL
27205 +#define SYSTEM__SYSLOG_READ                       0x00000002UL
27206 +#define SYSTEM__SYSLOG_MOD                        0x00000004UL
27207 +#define SYSTEM__SYSLOG_CONSOLE                    0x00000008UL
27208 +#define SYSTEM__MODULE_REQUEST                    0x00000010UL
27209 +#define CAPABILITY__CHOWN                         0x00000001UL
27210 +#define CAPABILITY__DAC_OVERRIDE                  0x00000002UL
27211 +#define CAPABILITY__DAC_READ_SEARCH               0x00000004UL
27212 +#define CAPABILITY__FOWNER                        0x00000008UL
27213 +#define CAPABILITY__FSETID                        0x00000010UL
27214 +#define CAPABILITY__KILL                          0x00000020UL
27215 +#define CAPABILITY__SETGID                        0x00000040UL
27216 +#define CAPABILITY__SETUID                        0x00000080UL
27217 +#define CAPABILITY__SETPCAP                       0x00000100UL
27218 +#define CAPABILITY__LINUX_IMMUTABLE               0x00000200UL
27219 +#define CAPABILITY__NET_BIND_SERVICE              0x00000400UL
27220 +#define CAPABILITY__NET_BROADCAST                 0x00000800UL
27221 +#define CAPABILITY__NET_ADMIN                     0x00001000UL
27222 +#define CAPABILITY__NET_RAW                       0x00002000UL
27223 +#define CAPABILITY__IPC_LOCK                      0x00004000UL
27224 +#define CAPABILITY__IPC_OWNER                     0x00008000UL
27225 +#define CAPABILITY__SYS_MODULE                    0x00010000UL
27226 +#define CAPABILITY__SYS_RAWIO                     0x00020000UL
27227 +#define CAPABILITY__SYS_CHROOT                    0x00040000UL
27228 +#define CAPABILITY__SYS_PTRACE                    0x00080000UL
27229 +#define CAPABILITY__SYS_PACCT                     0x00100000UL
27230 +#define CAPABILITY__SYS_ADMIN                     0x00200000UL
27231 +#define CAPABILITY__SYS_BOOT                      0x00400000UL
27232 +#define CAPABILITY__SYS_NICE                      0x00800000UL
27233 +#define CAPABILITY__SYS_RESOURCE                  0x01000000UL
27234 +#define CAPABILITY__SYS_TIME                      0x02000000UL
27235 +#define CAPABILITY__SYS_TTY_CONFIG                0x04000000UL
27236 +#define CAPABILITY__MKNOD                         0x08000000UL
27237 +#define CAPABILITY__LEASE                         0x10000000UL
27238 +#define CAPABILITY__AUDIT_WRITE                   0x20000000UL
27239 +#define CAPABILITY__AUDIT_CONTROL                 0x40000000UL
27240 +#define CAPABILITY__SETFCAP                       0x80000000UL
27241 +#define FILESYSTEM__MOUNT                         0x00000001UL
27242 +#define FILESYSTEM__REMOUNT                       0x00000002UL
27243 +#define FILESYSTEM__UNMOUNT                       0x00000004UL
27244 +#define FILESYSTEM__GETATTR                       0x00000008UL
27245 +#define FILESYSTEM__RELABELFROM                   0x00000010UL
27246 +#define FILESYSTEM__RELABELTO                     0x00000020UL
27247 +#define FILESYSTEM__TRANSITION                    0x00000040UL
27248 +#define FILESYSTEM__ASSOCIATE                     0x00000080UL
27249 +#define FILESYSTEM__QUOTAMOD                      0x00000100UL
27250 +#define FILESYSTEM__QUOTAGET                      0x00000200UL
27251 +#define FILE__IOCTL                               0x00000001UL
27252 +#define FILE__READ                                0x00000002UL
27253 +#define FILE__WRITE                               0x00000004UL
27254 +#define FILE__CREATE                              0x00000008UL
27255 +#define FILE__GETATTR                             0x00000010UL
27256 +#define FILE__SETATTR                             0x00000020UL
27257 +#define FILE__LOCK                                0x00000040UL
27258 +#define FILE__RELABELFROM                         0x00000080UL
27259 +#define FILE__RELABELTO                           0x00000100UL
27260 +#define FILE__APPEND                              0x00000200UL
27261 +#define FILE__UNLINK                              0x00000400UL
27262 +#define FILE__LINK                                0x00000800UL
27263 +#define FILE__RENAME                              0x00001000UL
27264 +#define FILE__EXECUTE                             0x00002000UL
27265 +#define FILE__SWAPON                              0x00004000UL
27266 +#define FILE__QUOTAON                             0x00008000UL
27267 +#define FILE__MOUNTON                             0x00010000UL
27268 +#define FILE__EXECUTE_NO_TRANS                    0x00020000UL
27269 +#define FILE__ENTRYPOINT                          0x00040000UL
27270 +#define FILE__EXECMOD                             0x00080000UL
27271 +#define FILE__OPEN                                0x00100000UL
27272 +#define DIR__IOCTL                                0x00000001UL
27273 +#define DIR__READ                                 0x00000002UL
27274 +#define DIR__WRITE                                0x00000004UL
27275 +#define DIR__CREATE                               0x00000008UL
27276 +#define DIR__GETATTR                              0x00000010UL
27277 +#define DIR__SETATTR                              0x00000020UL
27278 +#define DIR__LOCK                                 0x00000040UL
27279 +#define DIR__RELABELFROM                          0x00000080UL
27280 +#define DIR__RELABELTO                            0x00000100UL
27281 +#define DIR__APPEND                               0x00000200UL
27282 +#define DIR__UNLINK                               0x00000400UL
27283 +#define DIR__LINK                                 0x00000800UL
27284 +#define DIR__RENAME                               0x00001000UL
27285 +#define DIR__EXECUTE                              0x00002000UL
27286 +#define DIR__SWAPON                               0x00004000UL
27287 +#define DIR__QUOTAON                              0x00008000UL
27288 +#define DIR__MOUNTON                              0x00010000UL
27289 +#define DIR__ADD_NAME                             0x00020000UL
27290 +#define DIR__REMOVE_NAME                          0x00040000UL
27291 +#define DIR__REPARENT                             0x00080000UL
27292 +#define DIR__SEARCH                               0x00100000UL
27293 +#define DIR__RMDIR                                0x00200000UL
27294 +#define DIR__OPEN                                 0x00400000UL
27295 +#define FD__USE                                   0x00000001UL
27296 +#define LNK_FILE__IOCTL                           0x00000001UL
27297 +#define LNK_FILE__READ                            0x00000002UL
27298 +#define LNK_FILE__WRITE                           0x00000004UL
27299 +#define LNK_FILE__CREATE                          0x00000008UL
27300 +#define LNK_FILE__GETATTR                         0x00000010UL
27301 +#define LNK_FILE__SETATTR                         0x00000020UL
27302 +#define LNK_FILE__LOCK                            0x00000040UL
27303 +#define LNK_FILE__RELABELFROM                     0x00000080UL
27304 +#define LNK_FILE__RELABELTO                       0x00000100UL
27305 +#define LNK_FILE__APPEND                          0x00000200UL
27306 +#define LNK_FILE__UNLINK                          0x00000400UL
27307 +#define LNK_FILE__LINK                            0x00000800UL
27308 +#define LNK_FILE__RENAME                          0x00001000UL
27309 +#define LNK_FILE__EXECUTE                         0x00002000UL
27310 +#define LNK_FILE__SWAPON                          0x00004000UL
27311 +#define LNK_FILE__QUOTAON                         0x00008000UL
27312 +#define LNK_FILE__MOUNTON                         0x00010000UL
27313 +#define CHR_FILE__IOCTL                           0x00000001UL
27314 +#define CHR_FILE__READ                            0x00000002UL
27315 +#define CHR_FILE__WRITE                           0x00000004UL
27316 +#define CHR_FILE__CREATE                          0x00000008UL
27317 +#define CHR_FILE__GETATTR                         0x00000010UL
27318 +#define CHR_FILE__SETATTR                         0x00000020UL
27319 +#define CHR_FILE__LOCK                            0x00000040UL
27320 +#define CHR_FILE__RELABELFROM                     0x00000080UL
27321 +#define CHR_FILE__RELABELTO                       0x00000100UL
27322 +#define CHR_FILE__APPEND                          0x00000200UL
27323 +#define CHR_FILE__UNLINK                          0x00000400UL
27324 +#define CHR_FILE__LINK                            0x00000800UL
27325 +#define CHR_FILE__RENAME                          0x00001000UL
27326 +#define CHR_FILE__EXECUTE                         0x00002000UL
27327 +#define CHR_FILE__SWAPON                          0x00004000UL
27328 +#define CHR_FILE__QUOTAON                         0x00008000UL
27329 +#define CHR_FILE__MOUNTON                         0x00010000UL
27330 +#define CHR_FILE__EXECUTE_NO_TRANS                0x00020000UL
27331 +#define CHR_FILE__ENTRYPOINT                      0x00040000UL
27332 +#define CHR_FILE__EXECMOD                         0x00080000UL
27333 +#define CHR_FILE__OPEN                            0x00100000UL
27334 +#define BLK_FILE__IOCTL                           0x00000001UL
27335 +#define BLK_FILE__READ                            0x00000002UL
27336 +#define BLK_FILE__WRITE                           0x00000004UL
27337 +#define BLK_FILE__CREATE                          0x00000008UL
27338 +#define BLK_FILE__GETATTR                         0x00000010UL
27339 +#define BLK_FILE__SETATTR                         0x00000020UL
27340 +#define BLK_FILE__LOCK                            0x00000040UL
27341 +#define BLK_FILE__RELABELFROM                     0x00000080UL
27342 +#define BLK_FILE__RELABELTO                       0x00000100UL
27343 +#define BLK_FILE__APPEND                          0x00000200UL
27344 +#define BLK_FILE__UNLINK                          0x00000400UL
27345 +#define BLK_FILE__LINK                            0x00000800UL
27346 +#define BLK_FILE__RENAME                          0x00001000UL
27347 +#define BLK_FILE__EXECUTE                         0x00002000UL
27348 +#define BLK_FILE__SWAPON                          0x00004000UL
27349 +#define BLK_FILE__QUOTAON                         0x00008000UL
27350 +#define BLK_FILE__MOUNTON                         0x00010000UL
27351 +#define BLK_FILE__OPEN                            0x00020000UL
27352 +#define SOCK_FILE__IOCTL                          0x00000001UL
27353 +#define SOCK_FILE__READ                           0x00000002UL
27354 +#define SOCK_FILE__WRITE                          0x00000004UL
27355 +#define SOCK_FILE__CREATE                         0x00000008UL
27356 +#define SOCK_FILE__GETATTR                        0x00000010UL
27357 +#define SOCK_FILE__SETATTR                        0x00000020UL
27358 +#define SOCK_FILE__LOCK                           0x00000040UL
27359 +#define SOCK_FILE__RELABELFROM                    0x00000080UL
27360 +#define SOCK_FILE__RELABELTO                      0x00000100UL
27361 +#define SOCK_FILE__APPEND                         0x00000200UL
27362 +#define SOCK_FILE__UNLINK                         0x00000400UL
27363 +#define SOCK_FILE__LINK                           0x00000800UL
27364 +#define SOCK_FILE__RENAME                         0x00001000UL
27365 +#define SOCK_FILE__EXECUTE                        0x00002000UL
27366 +#define SOCK_FILE__SWAPON                         0x00004000UL
27367 +#define SOCK_FILE__QUOTAON                        0x00008000UL
27368 +#define SOCK_FILE__MOUNTON                        0x00010000UL
27369 +#define SOCK_FILE__OPEN                           0x00020000UL
27370 +#define FIFO_FILE__IOCTL                          0x00000001UL
27371 +#define FIFO_FILE__READ                           0x00000002UL
27372 +#define FIFO_FILE__WRITE                          0x00000004UL
27373 +#define FIFO_FILE__CREATE                         0x00000008UL
27374 +#define FIFO_FILE__GETATTR                        0x00000010UL
27375 +#define FIFO_FILE__SETATTR                        0x00000020UL
27376 +#define FIFO_FILE__LOCK                           0x00000040UL
27377 +#define FIFO_FILE__RELABELFROM                    0x00000080UL
27378 +#define FIFO_FILE__RELABELTO                      0x00000100UL
27379 +#define FIFO_FILE__APPEND                         0x00000200UL
27380 +#define FIFO_FILE__UNLINK                         0x00000400UL
27381 +#define FIFO_FILE__LINK                           0x00000800UL
27382 +#define FIFO_FILE__RENAME                         0x00001000UL
27383 +#define FIFO_FILE__EXECUTE                        0x00002000UL
27384 +#define FIFO_FILE__SWAPON                         0x00004000UL
27385 +#define FIFO_FILE__QUOTAON                        0x00008000UL
27386 +#define FIFO_FILE__MOUNTON                        0x00010000UL
27387 +#define FIFO_FILE__OPEN                           0x00020000UL
27388 +#define SOCKET__IOCTL                             0x00000001UL
27389 +#define SOCKET__READ                              0x00000002UL
27390 +#define SOCKET__WRITE                             0x00000004UL
27391 +#define SOCKET__CREATE                            0x00000008UL
27392 +#define SOCKET__GETATTR                           0x00000010UL
27393 +#define SOCKET__SETATTR                           0x00000020UL
27394 +#define SOCKET__LOCK                              0x00000040UL
27395 +#define SOCKET__RELABELFROM                       0x00000080UL
27396 +#define SOCKET__RELABELTO                         0x00000100UL
27397 +#define SOCKET__APPEND                            0x00000200UL
27398 +#define SOCKET__BIND                              0x00000400UL
27399 +#define SOCKET__CONNECT                           0x00000800UL
27400 +#define SOCKET__LISTEN                            0x00001000UL
27401 +#define SOCKET__ACCEPT                            0x00002000UL
27402 +#define SOCKET__GETOPT                            0x00004000UL
27403 +#define SOCKET__SETOPT                            0x00008000UL
27404 +#define SOCKET__SHUTDOWN                          0x00010000UL
27405 +#define SOCKET__RECVFROM                          0x00020000UL
27406 +#define SOCKET__SENDTO                            0x00040000UL
27407 +#define SOCKET__RECV_MSG                          0x00080000UL
27408 +#define SOCKET__SEND_MSG                          0x00100000UL
27409 +#define SOCKET__NAME_BIND                         0x00200000UL
27410 +#define TCP_SOCKET__IOCTL                         0x00000001UL
27411 +#define TCP_SOCKET__READ                          0x00000002UL
27412 +#define TCP_SOCKET__WRITE                         0x00000004UL
27413 +#define TCP_SOCKET__CREATE                        0x00000008UL
27414 +#define TCP_SOCKET__GETATTR                       0x00000010UL
27415 +#define TCP_SOCKET__SETATTR                       0x00000020UL
27416 +#define TCP_SOCKET__LOCK                          0x00000040UL
27417 +#define TCP_SOCKET__RELABELFROM                   0x00000080UL
27418 +#define TCP_SOCKET__RELABELTO                     0x00000100UL
27419 +#define TCP_SOCKET__APPEND                        0x00000200UL
27420 +#define TCP_SOCKET__BIND                          0x00000400UL
27421 +#define TCP_SOCKET__CONNECT                       0x00000800UL
27422 +#define TCP_SOCKET__LISTEN                        0x00001000UL
27423 +#define TCP_SOCKET__ACCEPT                        0x00002000UL
27424 +#define TCP_SOCKET__GETOPT                        0x00004000UL
27425 +#define TCP_SOCKET__SETOPT                        0x00008000UL
27426 +#define TCP_SOCKET__SHUTDOWN                      0x00010000UL
27427 +#define TCP_SOCKET__RECVFROM                      0x00020000UL
27428 +#define TCP_SOCKET__SENDTO                        0x00040000UL
27429 +#define TCP_SOCKET__RECV_MSG                      0x00080000UL
27430 +#define TCP_SOCKET__SEND_MSG                      0x00100000UL
27431 +#define TCP_SOCKET__NAME_BIND                     0x00200000UL
27432 +#define TCP_SOCKET__CONNECTTO                     0x00400000UL
27433 +#define TCP_SOCKET__NEWCONN                       0x00800000UL
27434 +#define TCP_SOCKET__ACCEPTFROM                    0x01000000UL
27435 +#define TCP_SOCKET__NODE_BIND                     0x02000000UL
27436 +#define TCP_SOCKET__NAME_CONNECT                  0x04000000UL
27437 +#define UDP_SOCKET__IOCTL                         0x00000001UL
27438 +#define UDP_SOCKET__READ                          0x00000002UL
27439 +#define UDP_SOCKET__WRITE                         0x00000004UL
27440 +#define UDP_SOCKET__CREATE                        0x00000008UL
27441 +#define UDP_SOCKET__GETATTR                       0x00000010UL
27442 +#define UDP_SOCKET__SETATTR                       0x00000020UL
27443 +#define UDP_SOCKET__LOCK                          0x00000040UL
27444 +#define UDP_SOCKET__RELABELFROM                   0x00000080UL
27445 +#define UDP_SOCKET__RELABELTO                     0x00000100UL
27446 +#define UDP_SOCKET__APPEND                        0x00000200UL
27447 +#define UDP_SOCKET__BIND                          0x00000400UL
27448 +#define UDP_SOCKET__CONNECT                       0x00000800UL
27449 +#define UDP_SOCKET__LISTEN                        0x00001000UL
27450 +#define UDP_SOCKET__ACCEPT                        0x00002000UL
27451 +#define UDP_SOCKET__GETOPT                        0x00004000UL
27452 +#define UDP_SOCKET__SETOPT                        0x00008000UL
27453 +#define UDP_SOCKET__SHUTDOWN                      0x00010000UL
27454 +#define UDP_SOCKET__RECVFROM                      0x00020000UL
27455 +#define UDP_SOCKET__SENDTO                        0x00040000UL
27456 +#define UDP_SOCKET__RECV_MSG                      0x00080000UL
27457 +#define UDP_SOCKET__SEND_MSG                      0x00100000UL
27458 +#define UDP_SOCKET__NAME_BIND                     0x00200000UL
27459 +#define UDP_SOCKET__NODE_BIND                     0x00400000UL
27460 +#define RAWIP_SOCKET__IOCTL                       0x00000001UL
27461 +#define RAWIP_SOCKET__READ                        0x00000002UL
27462 +#define RAWIP_SOCKET__WRITE                       0x00000004UL
27463 +#define RAWIP_SOCKET__CREATE                      0x00000008UL
27464 +#define RAWIP_SOCKET__GETATTR                     0x00000010UL
27465 +#define RAWIP_SOCKET__SETATTR                     0x00000020UL
27466 +#define RAWIP_SOCKET__LOCK                        0x00000040UL
27467 +#define RAWIP_SOCKET__RELABELFROM                 0x00000080UL
27468 +#define RAWIP_SOCKET__RELABELTO                   0x00000100UL
27469 +#define RAWIP_SOCKET__APPEND                      0x00000200UL
27470 +#define RAWIP_SOCKET__BIND                        0x00000400UL
27471 +#define RAWIP_SOCKET__CONNECT                     0x00000800UL
27472 +#define RAWIP_SOCKET__LISTEN                      0x00001000UL
27473 +#define RAWIP_SOCKET__ACCEPT                      0x00002000UL
27474 +#define RAWIP_SOCKET__GETOPT                      0x00004000UL
27475 +#define RAWIP_SOCKET__SETOPT                      0x00008000UL
27476 +#define RAWIP_SOCKET__SHUTDOWN                    0x00010000UL
27477 +#define RAWIP_SOCKET__RECVFROM                    0x00020000UL
27478 +#define RAWIP_SOCKET__SENDTO                      0x00040000UL
27479 +#define RAWIP_SOCKET__RECV_MSG                    0x00080000UL
27480 +#define RAWIP_SOCKET__SEND_MSG                    0x00100000UL
27481 +#define RAWIP_SOCKET__NAME_BIND                   0x00200000UL
27482 +#define RAWIP_SOCKET__NODE_BIND                   0x00400000UL
27483 +#define NODE__TCP_RECV                            0x00000001UL
27484 +#define NODE__TCP_SEND                            0x00000002UL
27485 +#define NODE__UDP_RECV                            0x00000004UL
27486 +#define NODE__UDP_SEND                            0x00000008UL
27487 +#define NODE__RAWIP_RECV                          0x00000010UL
27488 +#define NODE__RAWIP_SEND                          0x00000020UL
27489 +#define NODE__ENFORCE_DEST                        0x00000040UL
27490 +#define NODE__DCCP_RECV                           0x00000080UL
27491 +#define NODE__DCCP_SEND                           0x00000100UL
27492 +#define NODE__RECVFROM                            0x00000200UL
27493 +#define NODE__SENDTO                              0x00000400UL
27494 +#define NETIF__TCP_RECV                           0x00000001UL
27495 +#define NETIF__TCP_SEND                           0x00000002UL
27496 +#define NETIF__UDP_RECV                           0x00000004UL
27497 +#define NETIF__UDP_SEND                           0x00000008UL
27498 +#define NETIF__RAWIP_RECV                         0x00000010UL
27499 +#define NETIF__RAWIP_SEND                         0x00000020UL
27500 +#define NETIF__DCCP_RECV                          0x00000040UL
27501 +#define NETIF__DCCP_SEND                          0x00000080UL
27502 +#define NETIF__INGRESS                            0x00000100UL
27503 +#define NETIF__EGRESS                             0x00000200UL
27504 +#define NETLINK_SOCKET__IOCTL                     0x00000001UL
27505 +#define NETLINK_SOCKET__READ                      0x00000002UL
27506 +#define NETLINK_SOCKET__WRITE                     0x00000004UL
27507 +#define NETLINK_SOCKET__CREATE                    0x00000008UL
27508 +#define NETLINK_SOCKET__GETATTR                   0x00000010UL
27509 +#define NETLINK_SOCKET__SETATTR                   0x00000020UL
27510 +#define NETLINK_SOCKET__LOCK                      0x00000040UL
27511 +#define NETLINK_SOCKET__RELABELFROM               0x00000080UL
27512 +#define NETLINK_SOCKET__RELABELTO                 0x00000100UL
27513 +#define NETLINK_SOCKET__APPEND                    0x00000200UL
27514 +#define NETLINK_SOCKET__BIND                      0x00000400UL
27515 +#define NETLINK_SOCKET__CONNECT                   0x00000800UL
27516 +#define NETLINK_SOCKET__LISTEN                    0x00001000UL
27517 +#define NETLINK_SOCKET__ACCEPT                    0x00002000UL
27518 +#define NETLINK_SOCKET__GETOPT                    0x00004000UL
27519 +#define NETLINK_SOCKET__SETOPT                    0x00008000UL
27520 +#define NETLINK_SOCKET__SHUTDOWN                  0x00010000UL
27521 +#define NETLINK_SOCKET__RECVFROM                  0x00020000UL
27522 +#define NETLINK_SOCKET__SENDTO                    0x00040000UL
27523 +#define NETLINK_SOCKET__RECV_MSG                  0x00080000UL
27524 +#define NETLINK_SOCKET__SEND_MSG                  0x00100000UL
27525 +#define NETLINK_SOCKET__NAME_BIND                 0x00200000UL
27526 +#define PACKET_SOCKET__IOCTL                      0x00000001UL
27527 +#define PACKET_SOCKET__READ                       0x00000002UL
27528 +#define PACKET_SOCKET__WRITE                      0x00000004UL
27529 +#define PACKET_SOCKET__CREATE                     0x00000008UL
27530 +#define PACKET_SOCKET__GETATTR                    0x00000010UL
27531 +#define PACKET_SOCKET__SETATTR                    0x00000020UL
27532 +#define PACKET_SOCKET__LOCK                       0x00000040UL
27533 +#define PACKET_SOCKET__RELABELFROM                0x00000080UL
27534 +#define PACKET_SOCKET__RELABELTO                  0x00000100UL
27535 +#define PACKET_SOCKET__APPEND                     0x00000200UL
27536 +#define PACKET_SOCKET__BIND                       0x00000400UL
27537 +#define PACKET_SOCKET__CONNECT                    0x00000800UL
27538 +#define PACKET_SOCKET__LISTEN                     0x00001000UL
27539 +#define PACKET_SOCKET__ACCEPT                     0x00002000UL
27540 +#define PACKET_SOCKET__GETOPT                     0x00004000UL
27541 +#define PACKET_SOCKET__SETOPT                     0x00008000UL
27542 +#define PACKET_SOCKET__SHUTDOWN                   0x00010000UL
27543 +#define PACKET_SOCKET__RECVFROM                   0x00020000UL
27544 +#define PACKET_SOCKET__SENDTO                     0x00040000UL
27545 +#define PACKET_SOCKET__RECV_MSG                   0x00080000UL
27546 +#define PACKET_SOCKET__SEND_MSG                   0x00100000UL
27547 +#define PACKET_SOCKET__NAME_BIND                  0x00200000UL
27548 +#define KEY_SOCKET__IOCTL                         0x00000001UL
27549 +#define KEY_SOCKET__READ                          0x00000002UL
27550 +#define KEY_SOCKET__WRITE                         0x00000004UL
27551 +#define KEY_SOCKET__CREATE                        0x00000008UL
27552 +#define KEY_SOCKET__GETATTR                       0x00000010UL
27553 +#define KEY_SOCKET__SETATTR                       0x00000020UL
27554 +#define KEY_SOCKET__LOCK                          0x00000040UL
27555 +#define KEY_SOCKET__RELABELFROM                   0x00000080UL
27556 +#define KEY_SOCKET__RELABELTO                     0x00000100UL
27557 +#define KEY_SOCKET__APPEND                        0x00000200UL
27558 +#define KEY_SOCKET__BIND                          0x00000400UL
27559 +#define KEY_SOCKET__CONNECT                       0x00000800UL
27560 +#define KEY_SOCKET__LISTEN                        0x00001000UL
27561 +#define KEY_SOCKET__ACCEPT                        0x00002000UL
27562 +#define KEY_SOCKET__GETOPT                        0x00004000UL
27563 +#define KEY_SOCKET__SETOPT                        0x00008000UL
27564 +#define KEY_SOCKET__SHUTDOWN                      0x00010000UL
27565 +#define KEY_SOCKET__RECVFROM                      0x00020000UL
27566 +#define KEY_SOCKET__SENDTO                        0x00040000UL
27567 +#define KEY_SOCKET__RECV_MSG                      0x00080000UL
27568 +#define KEY_SOCKET__SEND_MSG                      0x00100000UL
27569 +#define KEY_SOCKET__NAME_BIND                     0x00200000UL
27570 +#define UNIX_STREAM_SOCKET__IOCTL                 0x00000001UL
27571 +#define UNIX_STREAM_SOCKET__READ                  0x00000002UL
27572 +#define UNIX_STREAM_SOCKET__WRITE                 0x00000004UL
27573 +#define UNIX_STREAM_SOCKET__CREATE                0x00000008UL
27574 +#define UNIX_STREAM_SOCKET__GETATTR               0x00000010UL
27575 +#define UNIX_STREAM_SOCKET__SETATTR               0x00000020UL
27576 +#define UNIX_STREAM_SOCKET__LOCK                  0x00000040UL
27577 +#define UNIX_STREAM_SOCKET__RELABELFROM           0x00000080UL
27578 +#define UNIX_STREAM_SOCKET__RELABELTO             0x00000100UL
27579 +#define UNIX_STREAM_SOCKET__APPEND                0x00000200UL
27580 +#define UNIX_STREAM_SOCKET__BIND                  0x00000400UL
27581 +#define UNIX_STREAM_SOCKET__CONNECT               0x00000800UL
27582 +#define UNIX_STREAM_SOCKET__LISTEN                0x00001000UL
27583 +#define UNIX_STREAM_SOCKET__ACCEPT                0x00002000UL
27584 +#define UNIX_STREAM_SOCKET__GETOPT                0x00004000UL
27585 +#define UNIX_STREAM_SOCKET__SETOPT                0x00008000UL
27586 +#define UNIX_STREAM_SOCKET__SHUTDOWN              0x00010000UL
27587 +#define UNIX_STREAM_SOCKET__RECVFROM              0x00020000UL
27588 +#define UNIX_STREAM_SOCKET__SENDTO                0x00040000UL
27589 +#define UNIX_STREAM_SOCKET__RECV_MSG              0x00080000UL
27590 +#define UNIX_STREAM_SOCKET__SEND_MSG              0x00100000UL
27591 +#define UNIX_STREAM_SOCKET__NAME_BIND             0x00200000UL
27592 +#define UNIX_STREAM_SOCKET__CONNECTTO             0x00400000UL
27593 +#define UNIX_STREAM_SOCKET__NEWCONN               0x00800000UL
27594 +#define UNIX_STREAM_SOCKET__ACCEPTFROM            0x01000000UL
27595 +#define UNIX_DGRAM_SOCKET__IOCTL                  0x00000001UL
27596 +#define UNIX_DGRAM_SOCKET__READ                   0x00000002UL
27597 +#define UNIX_DGRAM_SOCKET__WRITE                  0x00000004UL
27598 +#define UNIX_DGRAM_SOCKET__CREATE                 0x00000008UL
27599 +#define UNIX_DGRAM_SOCKET__GETATTR                0x00000010UL
27600 +#define UNIX_DGRAM_SOCKET__SETATTR                0x00000020UL
27601 +#define UNIX_DGRAM_SOCKET__LOCK                   0x00000040UL
27602 +#define UNIX_DGRAM_SOCKET__RELABELFROM            0x00000080UL
27603 +#define UNIX_DGRAM_SOCKET__RELABELTO              0x00000100UL
27604 +#define UNIX_DGRAM_SOCKET__APPEND                 0x00000200UL
27605 +#define UNIX_DGRAM_SOCKET__BIND                   0x00000400UL
27606 +#define UNIX_DGRAM_SOCKET__CONNECT                0x00000800UL
27607 +#define UNIX_DGRAM_SOCKET__LISTEN                 0x00001000UL
27608 +#define UNIX_DGRAM_SOCKET__ACCEPT                 0x00002000UL
27609 +#define UNIX_DGRAM_SOCKET__GETOPT                 0x00004000UL
27610 +#define UNIX_DGRAM_SOCKET__SETOPT                 0x00008000UL
27611 +#define UNIX_DGRAM_SOCKET__SHUTDOWN               0x00010000UL
27612 +#define UNIX_DGRAM_SOCKET__RECVFROM               0x00020000UL
27613 +#define UNIX_DGRAM_SOCKET__SENDTO                 0x00040000UL
27614 +#define UNIX_DGRAM_SOCKET__RECV_MSG               0x00080000UL
27615 +#define UNIX_DGRAM_SOCKET__SEND_MSG               0x00100000UL
27616 +#define UNIX_DGRAM_SOCKET__NAME_BIND              0x00200000UL
27617 +#define SEM__CREATE                               0x00000001UL
27618 +#define SEM__DESTROY                              0x00000002UL
27619 +#define SEM__GETATTR                              0x00000004UL
27620 +#define SEM__SETATTR                              0x00000008UL
27621 +#define SEM__READ                                 0x00000010UL
27622 +#define SEM__WRITE                                0x00000020UL
27623 +#define SEM__ASSOCIATE                            0x00000040UL
27624 +#define SEM__UNIX_READ                            0x00000080UL
27625 +#define SEM__UNIX_WRITE                           0x00000100UL
27626 +#define MSG__SEND                                 0x00000001UL
27627 +#define MSG__RECEIVE                              0x00000002UL
27628 +#define MSGQ__CREATE                              0x00000001UL
27629 +#define MSGQ__DESTROY                             0x00000002UL
27630 +#define MSGQ__GETATTR                             0x00000004UL
27631 +#define MSGQ__SETATTR                             0x00000008UL
27632 +#define MSGQ__READ                                0x00000010UL
27633 +#define MSGQ__WRITE                               0x00000020UL
27634 +#define MSGQ__ASSOCIATE                           0x00000040UL
27635 +#define MSGQ__UNIX_READ                           0x00000080UL
27636 +#define MSGQ__UNIX_WRITE                          0x00000100UL
27637 +#define MSGQ__ENQUEUE                             0x00000200UL
27638 +#define SHM__CREATE                               0x00000001UL
27639 +#define SHM__DESTROY                              0x00000002UL
27640 +#define SHM__GETATTR                              0x00000004UL
27641 +#define SHM__SETATTR                              0x00000008UL
27642 +#define SHM__READ                                 0x00000010UL
27643 +#define SHM__WRITE                                0x00000020UL
27644 +#define SHM__ASSOCIATE                            0x00000040UL
27645 +#define SHM__UNIX_READ                            0x00000080UL
27646 +#define SHM__UNIX_WRITE                           0x00000100UL
27647 +#define SHM__LOCK                                 0x00000200UL
27648 +#define IPC__CREATE                               0x00000001UL
27649 +#define IPC__DESTROY                              0x00000002UL
27650 +#define IPC__GETATTR                              0x00000004UL
27651 +#define IPC__SETATTR                              0x00000008UL
27652 +#define IPC__READ                                 0x00000010UL
27653 +#define IPC__WRITE                                0x00000020UL
27654 +#define IPC__ASSOCIATE                            0x00000040UL
27655 +#define IPC__UNIX_READ                            0x00000080UL
27656 +#define IPC__UNIX_WRITE                           0x00000100UL
27657 +#define NETLINK_ROUTE_SOCKET__IOCTL               0x00000001UL
27658 +#define NETLINK_ROUTE_SOCKET__READ                0x00000002UL
27659 +#define NETLINK_ROUTE_SOCKET__WRITE               0x00000004UL
27660 +#define NETLINK_ROUTE_SOCKET__CREATE              0x00000008UL
27661 +#define NETLINK_ROUTE_SOCKET__GETATTR             0x00000010UL
27662 +#define NETLINK_ROUTE_SOCKET__SETATTR             0x00000020UL
27663 +#define NETLINK_ROUTE_SOCKET__LOCK                0x00000040UL
27664 +#define NETLINK_ROUTE_SOCKET__RELABELFROM         0x00000080UL
27665 +#define NETLINK_ROUTE_SOCKET__RELABELTO           0x00000100UL
27666 +#define NETLINK_ROUTE_SOCKET__APPEND              0x00000200UL
27667 +#define NETLINK_ROUTE_SOCKET__BIND                0x00000400UL
27668 +#define NETLINK_ROUTE_SOCKET__CONNECT             0x00000800UL
27669 +#define NETLINK_ROUTE_SOCKET__LISTEN              0x00001000UL
27670 +#define NETLINK_ROUTE_SOCKET__ACCEPT              0x00002000UL
27671 +#define NETLINK_ROUTE_SOCKET__GETOPT              0x00004000UL
27672 +#define NETLINK_ROUTE_SOCKET__SETOPT              0x00008000UL
27673 +#define NETLINK_ROUTE_SOCKET__SHUTDOWN            0x00010000UL
27674 +#define NETLINK_ROUTE_SOCKET__RECVFROM            0x00020000UL
27675 +#define NETLINK_ROUTE_SOCKET__SENDTO              0x00040000UL
27676 +#define NETLINK_ROUTE_SOCKET__RECV_MSG            0x00080000UL
27677 +#define NETLINK_ROUTE_SOCKET__SEND_MSG            0x00100000UL
27678 +#define NETLINK_ROUTE_SOCKET__NAME_BIND           0x00200000UL
27679 +#define NETLINK_ROUTE_SOCKET__NLMSG_READ          0x00400000UL
27680 +#define NETLINK_ROUTE_SOCKET__NLMSG_WRITE         0x00800000UL
27681 +#define NETLINK_FIREWALL_SOCKET__IOCTL            0x00000001UL
27682 +#define NETLINK_FIREWALL_SOCKET__READ             0x00000002UL
27683 +#define NETLINK_FIREWALL_SOCKET__WRITE            0x00000004UL
27684 +#define NETLINK_FIREWALL_SOCKET__CREATE           0x00000008UL
27685 +#define NETLINK_FIREWALL_SOCKET__GETATTR          0x00000010UL
27686 +#define NETLINK_FIREWALL_SOCKET__SETATTR          0x00000020UL
27687 +#define NETLINK_FIREWALL_SOCKET__LOCK             0x00000040UL
27688 +#define NETLINK_FIREWALL_SOCKET__RELABELFROM      0x00000080UL
27689 +#define NETLINK_FIREWALL_SOCKET__RELABELTO        0x00000100UL
27690 +#define NETLINK_FIREWALL_SOCKET__APPEND           0x00000200UL
27691 +#define NETLINK_FIREWALL_SOCKET__BIND             0x00000400UL
27692 +#define NETLINK_FIREWALL_SOCKET__CONNECT          0x00000800UL
27693 +#define NETLINK_FIREWALL_SOCKET__LISTEN           0x00001000UL
27694 +#define NETLINK_FIREWALL_SOCKET__ACCEPT           0x00002000UL
27695 +#define NETLINK_FIREWALL_SOCKET__GETOPT           0x00004000UL
27696 +#define NETLINK_FIREWALL_SOCKET__SETOPT           0x00008000UL
27697 +#define NETLINK_FIREWALL_SOCKET__SHUTDOWN         0x00010000UL
27698 +#define NETLINK_FIREWALL_SOCKET__RECVFROM         0x00020000UL
27699 +#define NETLINK_FIREWALL_SOCKET__SENDTO           0x00040000UL
27700 +#define NETLINK_FIREWALL_SOCKET__RECV_MSG         0x00080000UL
27701 +#define NETLINK_FIREWALL_SOCKET__SEND_MSG         0x00100000UL
27702 +#define NETLINK_FIREWALL_SOCKET__NAME_BIND        0x00200000UL
27703 +#define NETLINK_FIREWALL_SOCKET__NLMSG_READ       0x00400000UL
27704 +#define NETLINK_FIREWALL_SOCKET__NLMSG_WRITE      0x00800000UL
27705 +#define NETLINK_TCPDIAG_SOCKET__IOCTL             0x00000001UL
27706 +#define NETLINK_TCPDIAG_SOCKET__READ              0x00000002UL
27707 +#define NETLINK_TCPDIAG_SOCKET__WRITE             0x00000004UL
27708 +#define NETLINK_TCPDIAG_SOCKET__CREATE            0x00000008UL
27709 +#define NETLINK_TCPDIAG_SOCKET__GETATTR           0x00000010UL
27710 +#define NETLINK_TCPDIAG_SOCKET__SETATTR           0x00000020UL
27711 +#define NETLINK_TCPDIAG_SOCKET__LOCK              0x00000040UL
27712 +#define NETLINK_TCPDIAG_SOCKET__RELABELFROM       0x00000080UL
27713 +#define NETLINK_TCPDIAG_SOCKET__RELABELTO         0x00000100UL
27714 +#define NETLINK_TCPDIAG_SOCKET__APPEND            0x00000200UL
27715 +#define NETLINK_TCPDIAG_SOCKET__BIND              0x00000400UL
27716 +#define NETLINK_TCPDIAG_SOCKET__CONNECT           0x00000800UL
27717 +#define NETLINK_TCPDIAG_SOCKET__LISTEN            0x00001000UL
27718 +#define NETLINK_TCPDIAG_SOCKET__ACCEPT            0x00002000UL
27719 +#define NETLINK_TCPDIAG_SOCKET__GETOPT            0x00004000UL
27720 +#define NETLINK_TCPDIAG_SOCKET__SETOPT            0x00008000UL
27721 +#define NETLINK_TCPDIAG_SOCKET__SHUTDOWN          0x00010000UL
27722 +#define NETLINK_TCPDIAG_SOCKET__RECVFROM          0x00020000UL
27723 +#define NETLINK_TCPDIAG_SOCKET__SENDTO            0x00040000UL
27724 +#define NETLINK_TCPDIAG_SOCKET__RECV_MSG          0x00080000UL
27725 +#define NETLINK_TCPDIAG_SOCKET__SEND_MSG          0x00100000UL
27726 +#define NETLINK_TCPDIAG_SOCKET__NAME_BIND         0x00200000UL
27727 +#define NETLINK_TCPDIAG_SOCKET__NLMSG_READ        0x00400000UL
27728 +#define NETLINK_TCPDIAG_SOCKET__NLMSG_WRITE       0x00800000UL
27729 +#define NETLINK_NFLOG_SOCKET__IOCTL               0x00000001UL
27730 +#define NETLINK_NFLOG_SOCKET__READ                0x00000002UL
27731 +#define NETLINK_NFLOG_SOCKET__WRITE               0x00000004UL
27732 +#define NETLINK_NFLOG_SOCKET__CREATE              0x00000008UL
27733 +#define NETLINK_NFLOG_SOCKET__GETATTR             0x00000010UL
27734 +#define NETLINK_NFLOG_SOCKET__SETATTR             0x00000020UL
27735 +#define NETLINK_NFLOG_SOCKET__LOCK                0x00000040UL
27736 +#define NETLINK_NFLOG_SOCKET__RELABELFROM         0x00000080UL
27737 +#define NETLINK_NFLOG_SOCKET__RELABELTO           0x00000100UL
27738 +#define NETLINK_NFLOG_SOCKET__APPEND              0x00000200UL
27739 +#define NETLINK_NFLOG_SOCKET__BIND                0x00000400UL
27740 +#define NETLINK_NFLOG_SOCKET__CONNECT             0x00000800UL
27741 +#define NETLINK_NFLOG_SOCKET__LISTEN              0x00001000UL
27742 +#define NETLINK_NFLOG_SOCKET__ACCEPT              0x00002000UL
27743 +#define NETLINK_NFLOG_SOCKET__GETOPT              0x00004000UL
27744 +#define NETLINK_NFLOG_SOCKET__SETOPT              0x00008000UL
27745 +#define NETLINK_NFLOG_SOCKET__SHUTDOWN            0x00010000UL
27746 +#define NETLINK_NFLOG_SOCKET__RECVFROM            0x00020000UL
27747 +#define NETLINK_NFLOG_SOCKET__SENDTO              0x00040000UL
27748 +#define NETLINK_NFLOG_SOCKET__RECV_MSG            0x00080000UL
27749 +#define NETLINK_NFLOG_SOCKET__SEND_MSG            0x00100000UL
27750 +#define NETLINK_NFLOG_SOCKET__NAME_BIND           0x00200000UL
27751 +#define NETLINK_XFRM_SOCKET__IOCTL                0x00000001UL
27752 +#define NETLINK_XFRM_SOCKET__READ                 0x00000002UL
27753 +#define NETLINK_XFRM_SOCKET__WRITE                0x00000004UL
27754 +#define NETLINK_XFRM_SOCKET__CREATE               0x00000008UL
27755 +#define NETLINK_XFRM_SOCKET__GETATTR              0x00000010UL
27756 +#define NETLINK_XFRM_SOCKET__SETATTR              0x00000020UL
27757 +#define NETLINK_XFRM_SOCKET__LOCK                 0x00000040UL
27758 +#define NETLINK_XFRM_SOCKET__RELABELFROM          0x00000080UL
27759 +#define NETLINK_XFRM_SOCKET__RELABELTO            0x00000100UL
27760 +#define NETLINK_XFRM_SOCKET__APPEND               0x00000200UL
27761 +#define NETLINK_XFRM_SOCKET__BIND                 0x00000400UL
27762 +#define NETLINK_XFRM_SOCKET__CONNECT              0x00000800UL
27763 +#define NETLINK_XFRM_SOCKET__LISTEN               0x00001000UL
27764 +#define NETLINK_XFRM_SOCKET__ACCEPT               0x00002000UL
27765 +#define NETLINK_XFRM_SOCKET__GETOPT               0x00004000UL
27766 +#define NETLINK_XFRM_SOCKET__SETOPT               0x00008000UL
27767 +#define NETLINK_XFRM_SOCKET__SHUTDOWN             0x00010000UL
27768 +#define NETLINK_XFRM_SOCKET__RECVFROM             0x00020000UL
27769 +#define NETLINK_XFRM_SOCKET__SENDTO               0x00040000UL
27770 +#define NETLINK_XFRM_SOCKET__RECV_MSG             0x00080000UL
27771 +#define NETLINK_XFRM_SOCKET__SEND_MSG             0x00100000UL
27772 +#define NETLINK_XFRM_SOCKET__NAME_BIND            0x00200000UL
27773 +#define NETLINK_XFRM_SOCKET__NLMSG_READ           0x00400000UL
27774 +#define NETLINK_XFRM_SOCKET__NLMSG_WRITE          0x00800000UL
27775 +#define NETLINK_SELINUX_SOCKET__IOCTL             0x00000001UL
27776 +#define NETLINK_SELINUX_SOCKET__READ              0x00000002UL
27777 +#define NETLINK_SELINUX_SOCKET__WRITE             0x00000004UL
27778 +#define NETLINK_SELINUX_SOCKET__CREATE            0x00000008UL
27779 +#define NETLINK_SELINUX_SOCKET__GETATTR           0x00000010UL
27780 +#define NETLINK_SELINUX_SOCKET__SETATTR           0x00000020UL
27781 +#define NETLINK_SELINUX_SOCKET__LOCK              0x00000040UL
27782 +#define NETLINK_SELINUX_SOCKET__RELABELFROM       0x00000080UL
27783 +#define NETLINK_SELINUX_SOCKET__RELABELTO         0x00000100UL
27784 +#define NETLINK_SELINUX_SOCKET__APPEND            0x00000200UL
27785 +#define NETLINK_SELINUX_SOCKET__BIND              0x00000400UL
27786 +#define NETLINK_SELINUX_SOCKET__CONNECT           0x00000800UL
27787 +#define NETLINK_SELINUX_SOCKET__LISTEN            0x00001000UL
27788 +#define NETLINK_SELINUX_SOCKET__ACCEPT            0x00002000UL
27789 +#define NETLINK_SELINUX_SOCKET__GETOPT            0x00004000UL
27790 +#define NETLINK_SELINUX_SOCKET__SETOPT            0x00008000UL
27791 +#define NETLINK_SELINUX_SOCKET__SHUTDOWN          0x00010000UL
27792 +#define NETLINK_SELINUX_SOCKET__RECVFROM          0x00020000UL
27793 +#define NETLINK_SELINUX_SOCKET__SENDTO            0x00040000UL
27794 +#define NETLINK_SELINUX_SOCKET__RECV_MSG          0x00080000UL
27795 +#define NETLINK_SELINUX_SOCKET__SEND_MSG          0x00100000UL
27796 +#define NETLINK_SELINUX_SOCKET__NAME_BIND         0x00200000UL
27797 +#define NETLINK_AUDIT_SOCKET__IOCTL               0x00000001UL
27798 +#define NETLINK_AUDIT_SOCKET__READ                0x00000002UL
27799 +#define NETLINK_AUDIT_SOCKET__WRITE               0x00000004UL
27800 +#define NETLINK_AUDIT_SOCKET__CREATE              0x00000008UL
27801 +#define NETLINK_AUDIT_SOCKET__GETATTR             0x00000010UL
27802 +#define NETLINK_AUDIT_SOCKET__SETATTR             0x00000020UL
27803 +#define NETLINK_AUDIT_SOCKET__LOCK                0x00000040UL
27804 +#define NETLINK_AUDIT_SOCKET__RELABELFROM         0x00000080UL
27805 +#define NETLINK_AUDIT_SOCKET__RELABELTO           0x00000100UL
27806 +#define NETLINK_AUDIT_SOCKET__APPEND              0x00000200UL
27807 +#define NETLINK_AUDIT_SOCKET__BIND                0x00000400UL
27808 +#define NETLINK_AUDIT_SOCKET__CONNECT             0x00000800UL
27809 +#define NETLINK_AUDIT_SOCKET__LISTEN              0x00001000UL
27810 +#define NETLINK_AUDIT_SOCKET__ACCEPT              0x00002000UL
27811 +#define NETLINK_AUDIT_SOCKET__GETOPT              0x00004000UL
27812 +#define NETLINK_AUDIT_SOCKET__SETOPT              0x00008000UL
27813 +#define NETLINK_AUDIT_SOCKET__SHUTDOWN            0x00010000UL
27814 +#define NETLINK_AUDIT_SOCKET__RECVFROM            0x00020000UL
27815 +#define NETLINK_AUDIT_SOCKET__SENDTO              0x00040000UL
27816 +#define NETLINK_AUDIT_SOCKET__RECV_MSG            0x00080000UL
27817 +#define NETLINK_AUDIT_SOCKET__SEND_MSG            0x00100000UL
27818 +#define NETLINK_AUDIT_SOCKET__NAME_BIND           0x00200000UL
27819 +#define NETLINK_AUDIT_SOCKET__NLMSG_READ          0x00400000UL
27820 +#define NETLINK_AUDIT_SOCKET__NLMSG_WRITE         0x00800000UL
27821 +#define NETLINK_AUDIT_SOCKET__NLMSG_RELAY         0x01000000UL
27822 +#define NETLINK_AUDIT_SOCKET__NLMSG_READPRIV      0x02000000UL
27823 +#define NETLINK_AUDIT_SOCKET__NLMSG_TTY_AUDIT     0x04000000UL
27824 +#define NETLINK_IP6FW_SOCKET__IOCTL               0x00000001UL
27825 +#define NETLINK_IP6FW_SOCKET__READ                0x00000002UL
27826 +#define NETLINK_IP6FW_SOCKET__WRITE               0x00000004UL
27827 +#define NETLINK_IP6FW_SOCKET__CREATE              0x00000008UL
27828 +#define NETLINK_IP6FW_SOCKET__GETATTR             0x00000010UL
27829 +#define NETLINK_IP6FW_SOCKET__SETATTR             0x00000020UL
27830 +#define NETLINK_IP6FW_SOCKET__LOCK                0x00000040UL
27831 +#define NETLINK_IP6FW_SOCKET__RELABELFROM         0x00000080UL
27832 +#define NETLINK_IP6FW_SOCKET__RELABELTO           0x00000100UL
27833 +#define NETLINK_IP6FW_SOCKET__APPEND              0x00000200UL
27834 +#define NETLINK_IP6FW_SOCKET__BIND                0x00000400UL
27835 +#define NETLINK_IP6FW_SOCKET__CONNECT             0x00000800UL
27836 +#define NETLINK_IP6FW_SOCKET__LISTEN              0x00001000UL
27837 +#define NETLINK_IP6FW_SOCKET__ACCEPT              0x00002000UL
27838 +#define NETLINK_IP6FW_SOCKET__GETOPT              0x00004000UL
27839 +#define NETLINK_IP6FW_SOCKET__SETOPT              0x00008000UL
27840 +#define NETLINK_IP6FW_SOCKET__SHUTDOWN            0x00010000UL
27841 +#define NETLINK_IP6FW_SOCKET__RECVFROM            0x00020000UL
27842 +#define NETLINK_IP6FW_SOCKET__SENDTO              0x00040000UL
27843 +#define NETLINK_IP6FW_SOCKET__RECV_MSG            0x00080000UL
27844 +#define NETLINK_IP6FW_SOCKET__SEND_MSG            0x00100000UL
27845 +#define NETLINK_IP6FW_SOCKET__NAME_BIND           0x00200000UL
27846 +#define NETLINK_IP6FW_SOCKET__NLMSG_READ          0x00400000UL
27847 +#define NETLINK_IP6FW_SOCKET__NLMSG_WRITE         0x00800000UL
27848 +#define NETLINK_DNRT_SOCKET__IOCTL                0x00000001UL
27849 +#define NETLINK_DNRT_SOCKET__READ                 0x00000002UL
27850 +#define NETLINK_DNRT_SOCKET__WRITE                0x00000004UL
27851 +#define NETLINK_DNRT_SOCKET__CREATE               0x00000008UL
27852 +#define NETLINK_DNRT_SOCKET__GETATTR              0x00000010UL
27853 +#define NETLINK_DNRT_SOCKET__SETATTR              0x00000020UL
27854 +#define NETLINK_DNRT_SOCKET__LOCK                 0x00000040UL
27855 +#define NETLINK_DNRT_SOCKET__RELABELFROM          0x00000080UL
27856 +#define NETLINK_DNRT_SOCKET__RELABELTO            0x00000100UL
27857 +#define NETLINK_DNRT_SOCKET__APPEND               0x00000200UL
27858 +#define NETLINK_DNRT_SOCKET__BIND                 0x00000400UL
27859 +#define NETLINK_DNRT_SOCKET__CONNECT              0x00000800UL
27860 +#define NETLINK_DNRT_SOCKET__LISTEN               0x00001000UL
27861 +#define NETLINK_DNRT_SOCKET__ACCEPT               0x00002000UL
27862 +#define NETLINK_DNRT_SOCKET__GETOPT               0x00004000UL
27863 +#define NETLINK_DNRT_SOCKET__SETOPT               0x00008000UL
27864 +#define NETLINK_DNRT_SOCKET__SHUTDOWN             0x00010000UL
27865 +#define NETLINK_DNRT_SOCKET__RECVFROM             0x00020000UL
27866 +#define NETLINK_DNRT_SOCKET__SENDTO               0x00040000UL
27867 +#define NETLINK_DNRT_SOCKET__RECV_MSG             0x00080000UL
27868 +#define NETLINK_DNRT_SOCKET__SEND_MSG             0x00100000UL
27869 +#define NETLINK_DNRT_SOCKET__NAME_BIND            0x00200000UL
27870 +#define ASSOCIATION__SENDTO                       0x00000001UL
27871 +#define ASSOCIATION__RECVFROM                     0x00000002UL
27872 +#define ASSOCIATION__SETCONTEXT                   0x00000004UL
27873 +#define ASSOCIATION__POLMATCH                     0x00000008UL
27874 +#define NETLINK_KOBJECT_UEVENT_SOCKET__IOCTL      0x00000001UL
27875 +#define NETLINK_KOBJECT_UEVENT_SOCKET__READ       0x00000002UL
27876 +#define NETLINK_KOBJECT_UEVENT_SOCKET__WRITE      0x00000004UL
27877 +#define NETLINK_KOBJECT_UEVENT_SOCKET__CREATE     0x00000008UL
27878 +#define NETLINK_KOBJECT_UEVENT_SOCKET__GETATTR    0x00000010UL
27879 +#define NETLINK_KOBJECT_UEVENT_SOCKET__SETATTR    0x00000020UL
27880 +#define NETLINK_KOBJECT_UEVENT_SOCKET__LOCK       0x00000040UL
27881 +#define NETLINK_KOBJECT_UEVENT_SOCKET__RELABELFROM 0x00000080UL
27882 +#define NETLINK_KOBJECT_UEVENT_SOCKET__RELABELTO  0x00000100UL
27883 +#define NETLINK_KOBJECT_UEVENT_SOCKET__APPEND     0x00000200UL
27884 +#define NETLINK_KOBJECT_UEVENT_SOCKET__BIND       0x00000400UL
27885 +#define NETLINK_KOBJECT_UEVENT_SOCKET__CONNECT    0x00000800UL
27886 +#define NETLINK_KOBJECT_UEVENT_SOCKET__LISTEN     0x00001000UL
27887 +#define NETLINK_KOBJECT_UEVENT_SOCKET__ACCEPT     0x00002000UL
27888 +#define NETLINK_KOBJECT_UEVENT_SOCKET__GETOPT     0x00004000UL
27889 +#define NETLINK_KOBJECT_UEVENT_SOCKET__SETOPT     0x00008000UL
27890 +#define NETLINK_KOBJECT_UEVENT_SOCKET__SHUTDOWN   0x00010000UL
27891 +#define NETLINK_KOBJECT_UEVENT_SOCKET__RECVFROM   0x00020000UL
27892 +#define NETLINK_KOBJECT_UEVENT_SOCKET__SENDTO     0x00040000UL
27893 +#define NETLINK_KOBJECT_UEVENT_SOCKET__RECV_MSG   0x00080000UL
27894 +#define NETLINK_KOBJECT_UEVENT_SOCKET__SEND_MSG   0x00100000UL
27895 +#define NETLINK_KOBJECT_UEVENT_SOCKET__NAME_BIND  0x00200000UL
27896 +#define APPLETALK_SOCKET__IOCTL                   0x00000001UL
27897 +#define APPLETALK_SOCKET__READ                    0x00000002UL
27898 +#define APPLETALK_SOCKET__WRITE                   0x00000004UL
27899 +#define APPLETALK_SOCKET__CREATE                  0x00000008UL
27900 +#define APPLETALK_SOCKET__GETATTR                 0x00000010UL
27901 +#define APPLETALK_SOCKET__SETATTR                 0x00000020UL
27902 +#define APPLETALK_SOCKET__LOCK                    0x00000040UL
27903 +#define APPLETALK_SOCKET__RELABELFROM             0x00000080UL
27904 +#define APPLETALK_SOCKET__RELABELTO               0x00000100UL
27905 +#define APPLETALK_SOCKET__APPEND                  0x00000200UL
27906 +#define APPLETALK_SOCKET__BIND                    0x00000400UL
27907 +#define APPLETALK_SOCKET__CONNECT                 0x00000800UL
27908 +#define APPLETALK_SOCKET__LISTEN                  0x00001000UL
27909 +#define APPLETALK_SOCKET__ACCEPT                  0x00002000UL
27910 +#define APPLETALK_SOCKET__GETOPT                  0x00004000UL
27911 +#define APPLETALK_SOCKET__SETOPT                  0x00008000UL
27912 +#define APPLETALK_SOCKET__SHUTDOWN                0x00010000UL
27913 +#define APPLETALK_SOCKET__RECVFROM                0x00020000UL
27914 +#define APPLETALK_SOCKET__SENDTO                  0x00040000UL
27915 +#define APPLETALK_SOCKET__RECV_MSG                0x00080000UL
27916 +#define APPLETALK_SOCKET__SEND_MSG                0x00100000UL
27917 +#define APPLETALK_SOCKET__NAME_BIND               0x00200000UL
27918 +#define PACKET__SEND                              0x00000001UL
27919 +#define PACKET__RECV                              0x00000002UL
27920 +#define PACKET__RELABELTO                         0x00000004UL
27921 +#define PACKET__FLOW_IN                           0x00000008UL
27922 +#define PACKET__FLOW_OUT                          0x00000010UL
27923 +#define PACKET__FORWARD_IN                        0x00000020UL
27924 +#define PACKET__FORWARD_OUT                       0x00000040UL
27925 +#define KEY__VIEW                                 0x00000001UL
27926 +#define KEY__READ                                 0x00000002UL
27927 +#define KEY__WRITE                                0x00000004UL
27928 +#define KEY__SEARCH                               0x00000008UL
27929 +#define KEY__LINK                                 0x00000010UL
27930 +#define KEY__SETATTR                              0x00000020UL
27931 +#define KEY__CREATE                               0x00000040UL
27932 +#define DCCP_SOCKET__IOCTL                        0x00000001UL
27933 +#define DCCP_SOCKET__READ                         0x00000002UL
27934 +#define DCCP_SOCKET__WRITE                        0x00000004UL
27935 +#define DCCP_SOCKET__CREATE                       0x00000008UL
27936 +#define DCCP_SOCKET__GETATTR                      0x00000010UL
27937 +#define DCCP_SOCKET__SETATTR                      0x00000020UL
27938 +#define DCCP_SOCKET__LOCK                         0x00000040UL
27939 +#define DCCP_SOCKET__RELABELFROM                  0x00000080UL
27940 +#define DCCP_SOCKET__RELABELTO                    0x00000100UL
27941 +#define DCCP_SOCKET__APPEND                       0x00000200UL
27942 +#define DCCP_SOCKET__BIND                         0x00000400UL
27943 +#define DCCP_SOCKET__CONNECT                      0x00000800UL
27944 +#define DCCP_SOCKET__LISTEN                       0x00001000UL
27945 +#define DCCP_SOCKET__ACCEPT                       0x00002000UL
27946 +#define DCCP_SOCKET__GETOPT                       0x00004000UL
27947 +#define DCCP_SOCKET__SETOPT                       0x00008000UL
27948 +#define DCCP_SOCKET__SHUTDOWN                     0x00010000UL
27949 +#define DCCP_SOCKET__RECVFROM                     0x00020000UL
27950 +#define DCCP_SOCKET__SENDTO                       0x00040000UL
27951 +#define DCCP_SOCKET__RECV_MSG                     0x00080000UL
27952 +#define DCCP_SOCKET__SEND_MSG                     0x00100000UL
27953 +#define DCCP_SOCKET__NAME_BIND                    0x00200000UL
27954 +#define DCCP_SOCKET__NODE_BIND                    0x00400000UL
27955 +#define DCCP_SOCKET__NAME_CONNECT                 0x00800000UL
27956 +#define MEMPROTECT__MMAP_ZERO                     0x00000001UL
27957 +#define PEER__RECV                                0x00000001UL
27958 +#define CAPABILITY2__MAC_OVERRIDE                 0x00000001UL
27959 +#define CAPABILITY2__MAC_ADMIN                    0x00000002UL
27960 +#define KERNEL_SERVICE__USE_AS_OVERRIDE           0x00000001UL
27961 +#define KERNEL_SERVICE__CREATE_FILES_AS           0x00000002UL
27962 +#define TUN_SOCKET__IOCTL                         0x00000001UL
27963 +#define TUN_SOCKET__READ                          0x00000002UL
27964 +#define TUN_SOCKET__WRITE                         0x00000004UL
27965 +#define TUN_SOCKET__CREATE                        0x00000008UL
27966 +#define TUN_SOCKET__GETATTR                       0x00000010UL
27967 +#define TUN_SOCKET__SETATTR                       0x00000020UL
27968 +#define TUN_SOCKET__LOCK                          0x00000040UL
27969 +#define TUN_SOCKET__RELABELFROM                   0x00000080UL
27970 +#define TUN_SOCKET__RELABELTO                     0x00000100UL
27971 +#define TUN_SOCKET__APPEND                        0x00000200UL
27972 +#define TUN_SOCKET__BIND                          0x00000400UL
27973 +#define TUN_SOCKET__CONNECT                       0x00000800UL
27974 +#define TUN_SOCKET__LISTEN                        0x00001000UL
27975 +#define TUN_SOCKET__ACCEPT                        0x00002000UL
27976 +#define TUN_SOCKET__GETOPT                        0x00004000UL
27977 +#define TUN_SOCKET__SETOPT                        0x00008000UL
27978 +#define TUN_SOCKET__SHUTDOWN                      0x00010000UL
27979 +#define TUN_SOCKET__RECVFROM                      0x00020000UL
27980 +#define TUN_SOCKET__SENDTO                        0x00040000UL
27981 +#define TUN_SOCKET__RECV_MSG                      0x00080000UL
27982 +#define TUN_SOCKET__SEND_MSG                      0x00100000UL
27983 +#define TUN_SOCKET__NAME_BIND                     0x00200000UL
27984 +
27985 +#endif
27986 diff -NurpP --minimal linux-2.6.35.4/security/selinux/hooks.c linux-2.6.35.4-vs2.3.0.36.32/security/selinux/hooks.c
27987 --- linux-2.6.35.4/security/selinux/hooks.c     2010-08-02 16:53:03.000000000 +0200
27988 +++ linux-2.6.35.4-vs2.3.0.36.32/security/selinux/hooks.c       2010-08-02 17:05:06.000000000 +0200
27989 @@ -64,7 +64,6 @@
27990  #include <linux/dccp.h>
27991  #include <linux/quota.h>
27992  #include <linux/un.h>          /* for Unix socket types */
27993 -#include <net/af_unix.h>       /* for Unix socket types */
27994  #include <linux/parser.h>
27995  #include <linux/nfs_mount.h>
27996  #include <net/ipv6.h>
This page took 5.215488 seconds and 4 git commands to generate.